diff --git a/.changeset/dry-ducks-sleep.md b/.changeset/dry-ducks-sleep.md new file mode 100644 index 000000000..ae7be4cd3 --- /dev/null +++ b/.changeset/dry-ducks-sleep.md @@ -0,0 +1,5 @@ +--- +"@rabbitholegg/questdk-plugin-utils": minor +--- + +allow any combination of filters in mint params diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 12b42d13c..4ba593955 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -93,6 +93,7 @@ export type { PremintValidationParams, PremintActionDetail, PremintActionForm, + Primitive, } from './types' export { diff --git a/packages/utils/src/types/actions.ts b/packages/utils/src/types/actions.ts index f0e1f9ac5..13b5f0175 100644 --- a/packages/utils/src/types/actions.ts +++ b/packages/utils/src/types/actions.ts @@ -1,20 +1,19 @@ +import { UUID } from 'crypto' import { - type PublicClient, type Address, + type PublicClient, type SimulateContractReturnType, type TransactionRequest, } from 'viem' +import { ZodSchema, z } from 'zod' +import { PluginActionNotImplementedError } from '../errors' +import { EthAddressSchema } from './common' import { - FilterOperatorSchema, - NumericSchema, + FilterSchema, type FilterOperator, type TransactionFilter, } from './filters' -import { PluginActionNotImplementedError } from '../errors' import type { MintIntentParams } from './intents' -import { ZodSchema, z } from 'zod' -import { EthAddressSchema } from './common' -import { UUID } from 'crypto' import { QuestCompletionPayload } from './quests' export type SwapActionParams = { @@ -216,7 +215,7 @@ export const StakeActionFormSchema = BaseStakeActionFormaSchema export const MintActionFormSchema = z.object({ contractAddress: EthAddressSchema, tokenId: z.number().optional(), - amount: z.union([NumericSchema, FilterOperatorSchema]), + amount: FilterSchema, amountOperator: QuestInputActionParamsAmountOperatorEnum.optional(), }) @@ -224,7 +223,7 @@ export const MintActionDetailSchema = z.object({ chainId: z.number(), contractAddress: EthAddressSchema, tokenId: z.number().optional(), - amount: z.union([NumericSchema, FilterOperatorSchema]), + amount: FilterSchema, amountOperator: QuestInputActionParamsAmountOperatorEnum.optional(), }) diff --git a/packages/utils/src/types/filters.ts b/packages/utils/src/types/filters.ts index 5c80ebb3f..be2de3c34 100644 --- a/packages/utils/src/types/filters.ts +++ b/packages/utils/src/types/filters.ts @@ -66,13 +66,13 @@ export type FilterOperator = export type ArrayOperator = | { - $some?: FilterOperator[] + $some?: Filter[] } | { - $first?: FilterOperator + $first?: Filter } | { - $last?: FilterOperator + $last?: Filter } | { $nth?: NthFilter @@ -81,33 +81,33 @@ export type ArrayOperator = export const ArrayOperatorSchema: z.ZodType = z.union([ z.object({ $some: z - .lazy(() => FilterOperatorSchema) + .lazy(() => FilterSchema) .array() .optional(), }), - z.object({ $first: z.lazy(() => FilterOperatorSchema).optional() }), - z.object({ $last: z.lazy(() => FilterOperatorSchema).optional() }), - z.object({ $nth: z.lazy(() => NthFilterSchema).optional() }), + z.object({ $first: z.lazy(() => FilterSchema).optional() }), + z.object({ $last: z.lazy(() => FilterSchema).optional() }), + z.object({ $nth: z.lazy(() => FilterSchema).optional() }), ]) export type LogicalOperator = | { - $and?: FilterOperator[] + $and?: Filter[] } | { - $or?: FilterOperator[] + $or?: Filter[] } export const LogicalOperatorSchema: z.ZodType = z.union([ z.object({ $and: z - .lazy(() => FilterOperatorSchema) + .lazy(() => FilterSchema) .array() .optional(), }), z.object({ $or: z - .lazy(() => FilterOperatorSchema) + .lazy(() => FilterSchema) .array() .optional(), }), @@ -121,16 +121,21 @@ export const FilterOperatorSchema = z.union([ ]) export type TransactionFilter = { - [K in keyof Transaction]: FilterOperator + [K in keyof Partial]: Filter } -export const TransactionFilterSchema = z.record( +export const TransactionFilterSchema: z.ZodType = z.record( z.string(), - FilterOperatorSchema, + z.lazy(() => FilterSchema), ) -type Primitive = string | number | boolean -export const PrimitiveSchema = z.union([z.string(), z.number(), z.boolean()]) +export type Primitive = string | number | boolean | bigint +export const PrimitiveSchema = z.union([ + z.string(), + z.number(), + z.boolean(), + z.bigint(), +]) export type FilterObject = { [key: string]: Filter @@ -171,12 +176,14 @@ export const AbiParamFilterSchema = z export type Filter = | Primitive + | Array | FilterObject | FilterArray | FilterOperator | Abi export const FilterSchema = z.union([ PrimitiveSchema, + PrimitiveSchema.array(), FilterObjectSchema, FilterOperatorSchema, z.lazy(() => FilterSchema.array()), @@ -188,7 +195,7 @@ export const FilterArraySchema = FilterSchema.array() export type NthFilter = { index: bigint | number | string - value: TransactionFilter | FilterObject + value: TransactionFilter | Filter } export const NthFilterSchema = z.object({ index: z.union([z.bigint(), z.number(), z.string()]), diff --git a/packages/utils/src/types/index.ts b/packages/utils/src/types/index.ts index a5c953e32..4369305ae 100644 --- a/packages/utils/src/types/index.ts +++ b/packages/utils/src/types/index.ts @@ -101,6 +101,7 @@ export { export { ActionType, OrderType } from './actions' export type { + Primitive, FilterObject, BitmaskFilter, NthFilter,