Skip to content

Commit

Permalink
make time window a discriminated union (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptroger authored Sep 5, 2024
1 parent 4ed9fa0 commit ca7ddc7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/policy-engine-shared/src/lib/schema/policy.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,23 @@ export const approvalConditionSchema = z.object({
entityIds: z.array(z.string().min(1))
})

export const timeWindowSchema = z.object({
type: timeWindowTypeSchema.optional(),
period: timeWindowPeriodSchema.optional(),
value: z.number().optional(),
const fixedTimeWindowSchema = z.object({
type: z.literal('rolling'),
value: z.number().int(),
startDate: z.number().int().optional(),
endDate: z.number().int().optional()
})

const rollingTimeWindowSchema = z.object({
type: z.literal('fixed'),
period: timeWindowPeriodSchema,
startDate: z.number().int().optional(),
endDate: z.number().int().optional()
})


export const timeWindowSchema = z.discriminatedUnion('type', [rollingTimeWindowSchema, fixedTimeWindowSchema])

export const transferFiltersSchema = z.object({
perPrincipal: z.boolean().optional(),
tokens: z.array(z.string()).min(1).optional(),
Expand Down

0 comments on commit ca7ddc7

Please sign in to comment.