forked from nucypher/taco-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split JsonAPICondition into its schema and its condition.
Include jsonApiConditionSchema in anyConditionSchema.
- Loading branch information
1 parent
e908e24
commit 92e5d73
Showing
5 changed files
with
51 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { JSONPath } from '@astronautlabs/jsonpath'; | ||
import { z } from 'zod'; | ||
|
||
import { returnValueTestSchema } from './return-value-test'; | ||
|
||
export const JsonApiConditionType = 'json-api'; | ||
|
||
const validateJSONPath = (jsonPath: string): boolean => { | ||
try { | ||
JSONPath.parse(jsonPath); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; | ||
|
||
export const jsonPathSchema = z | ||
.string() | ||
.refine((val) => validateJSONPath(val), { | ||
message: 'Invalid JSONPath expression', | ||
}); | ||
|
||
export const jsonApiConditionSchema = z.object({ | ||
conditionType: z.literal(JsonApiConditionType).default(JsonApiConditionType), | ||
endpoint: z.string().url(), | ||
parameters: z.record(z.string(), z.unknown()).optional(), | ||
query: jsonPathSchema.optional(), | ||
returnValueTest: returnValueTestSchema, // Update to allow multiple return values after expanding supported methods | ||
}); | ||
|
||
export type JsonApiConditionProps = z.infer<typeof jsonApiConditionSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters