Skip to content

Commit

Permalink
Update JsonApiConditionSchema to match lingo
Browse files Browse the repository at this point in the history
Update `JsonApiConditionSchema` to match lingo
  • Loading branch information
theref committed Jul 19, 2024
1 parent 87b88c5 commit 758488d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/taco/src/conditions/base/json-api.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import { JSONPath } from 'jsonpath-plus';
import { z } from 'zod';

import { Condition } from '../condition';
import {
EthAddressOrUserAddressSchema,
OmitConditionType,
paramOrContextParamSchema,
returnValueTestSchema,
} from '../shared';

export const JsonApiConditionType = 'json';
export const JsonApiConditionType = 'json-api';

export const JsonApiConditionSchema = z.object({
conditionType: z.literal(JsonApiConditionType).default(JsonApiConditionType),
parameters: z.union([
z.array(EthAddressOrUserAddressSchema).nonempty(),
// Using tuple here because ordering matters
z.tuple([EthAddressOrUserAddressSchema, paramOrContextParamSchema]),
]),
endpoint: z.string().url(),
parameters: z.array(paramOrContextParamSchema),
query: z.string().refine(
(path) => {
try {
JSONPath.toPathArray(path);
return true;
} catch (error) {
return false;
}
},
{
message: "Invalid JSON path",
}
),
returnValueTest: returnValueTestSchema, // Update to allow multiple return values after expanding supported methods
});

Expand Down

0 comments on commit 758488d

Please sign in to comment.