@inixiative/json-rules 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -37,6 +37,7 @@ declare const DateOperator: {
37
37
  readonly after: "after";
38
38
  readonly onOrBefore: "onOrBefore";
39
39
  readonly onOrAfter: "onOrAfter";
40
+ readonly within: "within";
40
41
  readonly between: "between";
41
42
  readonly notBetween: "notBetween";
42
43
  readonly dayIn: "dayIn";
@@ -54,7 +55,43 @@ type RuleValue = RuleScalar | Date | RegExp | RuleValue[] | {
54
55
  };
55
56
  type OrderedRuleValue = string | number | Date;
56
57
  type DateInputValue = string | number | Date;
57
- type DateRuleValue = DateInputValue | [DateInputValue, DateInputValue] | string[];
58
+ type RelativeUnits = {
59
+ years?: number;
60
+ quarters?: number;
61
+ months?: number;
62
+ weeks?: number;
63
+ days?: number;
64
+ hours?: number;
65
+ minutes?: number;
66
+ seconds?: number;
67
+ };
68
+ type PeriodUnit = 'year' | 'quarter' | 'month' | 'week' | 'isoWeek' | 'day' | 'hour' | 'minute' | 'second';
69
+ type RollingExpr = {
70
+ ago: RelativeUnits;
71
+ } | {
72
+ ahead: RelativeUnits;
73
+ };
74
+ type PeriodExpr = {
75
+ this: PeriodUnit;
76
+ } | {
77
+ last: PeriodUnit;
78
+ } | {
79
+ next: PeriodUnit;
80
+ };
81
+ type EdgeExpr = {
82
+ start: PeriodExpr;
83
+ } | {
84
+ end: PeriodExpr;
85
+ };
86
+ type DateExpr = RollingExpr | PeriodExpr | EdgeExpr;
87
+ type DateInputOrExpr = DateInputValue | DateExpr;
88
+ type DateRuleValue = DateInputValue | DateExpr | [DateInputOrExpr, DateInputOrExpr] | string[];
89
+ type WeekStart = 'monday' | 'sunday';
90
+ type DateConfig = {
91
+ now?: DateInputValue;
92
+ timeZone?: string;
93
+ weekStart?: WeekStart;
94
+ };
58
95
  type ValueSource<TValue> = {
59
96
  value: TValue;
60
97
  path?: never;
@@ -144,7 +181,17 @@ type StrictAggregateRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = (
144
181
  } & ValueSource<number>) | (AggregateRuleBase<TRuleValue, TDateValue> & {
145
182
  operator: AggregateRangeOperator;
146
183
  } & ValueSource<[number, number]>);
147
- type AggregateRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
184
+ type SortDir = 'asc' | 'desc';
185
+ type OrderBy = {
186
+ field: string;
187
+ dir: SortDir;
188
+ }[];
189
+ type WindowFields = {
190
+ orderBy?: OrderBy;
191
+ take?: number;
192
+ skip?: number;
193
+ };
194
+ type AggregateRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowFields & {
148
195
  field: string;
149
196
  aggregate: {
150
197
  mode: AggregateMode;
@@ -163,7 +210,7 @@ type Rule<TValue = RuleValue> = {
163
210
  path?: string;
164
211
  error?: string;
165
212
  };
166
- type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
213
+ type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowFields & {
167
214
  field?: string;
168
215
  arrayOperator: ArrayOperator;
169
216
  condition?: Condition<TRuleValue, TDateValue>;
@@ -212,7 +259,7 @@ type Row$1 = Record<string, unknown>;
212
259
  type CheckData = Row$1 | unknown[];
213
260
  type CheckOptions = {
214
261
  context?: CheckData;
215
- };
262
+ } & DateConfig;
216
263
  declare const check: <TData extends CheckData>(conditions: Condition, data: TData, options?: CheckOptions) => boolean | string;
217
264
 
218
265
  type PrismaWhere = Record<string, unknown>;
@@ -270,7 +317,7 @@ type BuildOptions = {
270
317
  mapName?: string;
271
318
  model?: string;
272
319
  context?: Record<string, unknown>;
273
- };
320
+ } & DateConfig;
274
321
 
275
322
  type BridgeEndpoint = {
276
323
  fieldMap: string;
@@ -526,7 +573,7 @@ type SqlBuildOptions = {
526
573
  model?: string;
527
574
  alias?: string;
528
575
  context?: Record<string, unknown>;
529
- };
576
+ } & DateConfig;
530
577
  declare const toSql: (condition: Condition, options?: SqlBuildOptions) => SqlResult;
531
578
 
532
579
  type ValidationIssue = {
@@ -545,4 +592,4 @@ declare const assertValidRule: (condition: unknown, options?: {
545
592
  target?: RuleTarget;
546
593
  }) => asserts condition is Condition;
547
594
 
548
- export { AGGREGATE_OPERATORS, ALL_KINDS, ARRAY_OPERATOR_CATALOG, type AggregateMode, type AggregateRule, type All, type Any, type ArrayCatalogEntry, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BuildOptions, type CatalogEntry, type CheckOptions, type Condition, type CreateLensInput, DATE_OPERATOR_CATALOG, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderedRuleValue, type PathProjection, type PrismaStep, type PrismaWhere, type ProjectedVisit, type Rule, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SqlResult, type StepRef, type StrictAggregateRule, type StrictAll, type StrictAny, type StrictArrayCountRule, type StrictArrayPredicateRule, type StrictArrayPresenceRule, type StrictArrayRule, type StrictCondition, type StrictContainsRule, type StrictDateComparisonRule, type StrictDateDayRule, type StrictDateRangeRule, type StrictDateRule, type StrictEqualityRule, type StrictIfThenElse, type StrictMembershipRule, type StrictOrderedComparisonRule, type StrictPatternRule, type StrictPresenceRule, type StrictRangeRule, type StrictRule, type StrictStringBoundaryRule, type ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, type WhereStep, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
595
+ export { AGGREGATE_OPERATORS, ALL_KINDS, ARRAY_OPERATOR_CATALOG, type AggregateMode, type AggregateRule, type All, type Any, type ArrayCatalogEntry, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BuildOptions, type CatalogEntry, type CheckOptions, type Condition, type CreateLensInput, DATE_OPERATOR_CATALOG, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EdgeExpr, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderBy, type OrderedRuleValue, type PathProjection, type PeriodExpr, type PeriodUnit, type PrismaStep, type PrismaWhere, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SqlResult, type StepRef, type StrictAggregateRule, type StrictAll, type StrictAny, type StrictArrayCountRule, type StrictArrayPredicateRule, type StrictArrayPresenceRule, type StrictArrayRule, type StrictCondition, type StrictContainsRule, type StrictDateComparisonRule, type StrictDateDayRule, type StrictDateRangeRule, type StrictDateRule, type StrictEqualityRule, type StrictIfThenElse, type StrictMembershipRule, type StrictOrderedComparisonRule, type StrictPatternRule, type StrictPresenceRule, type StrictRangeRule, type StrictRule, type StrictStringBoundaryRule, type ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, type WeekStart, type WhereStep, type WindowFields, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
package/dist/index.d.ts CHANGED
@@ -37,6 +37,7 @@ declare const DateOperator: {
37
37
  readonly after: "after";
38
38
  readonly onOrBefore: "onOrBefore";
39
39
  readonly onOrAfter: "onOrAfter";
40
+ readonly within: "within";
40
41
  readonly between: "between";
41
42
  readonly notBetween: "notBetween";
42
43
  readonly dayIn: "dayIn";
@@ -54,7 +55,43 @@ type RuleValue = RuleScalar | Date | RegExp | RuleValue[] | {
54
55
  };
55
56
  type OrderedRuleValue = string | number | Date;
56
57
  type DateInputValue = string | number | Date;
57
- type DateRuleValue = DateInputValue | [DateInputValue, DateInputValue] | string[];
58
+ type RelativeUnits = {
59
+ years?: number;
60
+ quarters?: number;
61
+ months?: number;
62
+ weeks?: number;
63
+ days?: number;
64
+ hours?: number;
65
+ minutes?: number;
66
+ seconds?: number;
67
+ };
68
+ type PeriodUnit = 'year' | 'quarter' | 'month' | 'week' | 'isoWeek' | 'day' | 'hour' | 'minute' | 'second';
69
+ type RollingExpr = {
70
+ ago: RelativeUnits;
71
+ } | {
72
+ ahead: RelativeUnits;
73
+ };
74
+ type PeriodExpr = {
75
+ this: PeriodUnit;
76
+ } | {
77
+ last: PeriodUnit;
78
+ } | {
79
+ next: PeriodUnit;
80
+ };
81
+ type EdgeExpr = {
82
+ start: PeriodExpr;
83
+ } | {
84
+ end: PeriodExpr;
85
+ };
86
+ type DateExpr = RollingExpr | PeriodExpr | EdgeExpr;
87
+ type DateInputOrExpr = DateInputValue | DateExpr;
88
+ type DateRuleValue = DateInputValue | DateExpr | [DateInputOrExpr, DateInputOrExpr] | string[];
89
+ type WeekStart = 'monday' | 'sunday';
90
+ type DateConfig = {
91
+ now?: DateInputValue;
92
+ timeZone?: string;
93
+ weekStart?: WeekStart;
94
+ };
58
95
  type ValueSource<TValue> = {
59
96
  value: TValue;
60
97
  path?: never;
@@ -144,7 +181,17 @@ type StrictAggregateRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = (
144
181
  } & ValueSource<number>) | (AggregateRuleBase<TRuleValue, TDateValue> & {
145
182
  operator: AggregateRangeOperator;
146
183
  } & ValueSource<[number, number]>);
147
- type AggregateRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
184
+ type SortDir = 'asc' | 'desc';
185
+ type OrderBy = {
186
+ field: string;
187
+ dir: SortDir;
188
+ }[];
189
+ type WindowFields = {
190
+ orderBy?: OrderBy;
191
+ take?: number;
192
+ skip?: number;
193
+ };
194
+ type AggregateRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowFields & {
148
195
  field: string;
149
196
  aggregate: {
150
197
  mode: AggregateMode;
@@ -163,7 +210,7 @@ type Rule<TValue = RuleValue> = {
163
210
  path?: string;
164
211
  error?: string;
165
212
  };
166
- type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
213
+ type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowFields & {
167
214
  field?: string;
168
215
  arrayOperator: ArrayOperator;
169
216
  condition?: Condition<TRuleValue, TDateValue>;
@@ -212,7 +259,7 @@ type Row$1 = Record<string, unknown>;
212
259
  type CheckData = Row$1 | unknown[];
213
260
  type CheckOptions = {
214
261
  context?: CheckData;
215
- };
262
+ } & DateConfig;
216
263
  declare const check: <TData extends CheckData>(conditions: Condition, data: TData, options?: CheckOptions) => boolean | string;
217
264
 
218
265
  type PrismaWhere = Record<string, unknown>;
@@ -270,7 +317,7 @@ type BuildOptions = {
270
317
  mapName?: string;
271
318
  model?: string;
272
319
  context?: Record<string, unknown>;
273
- };
320
+ } & DateConfig;
274
321
 
275
322
  type BridgeEndpoint = {
276
323
  fieldMap: string;
@@ -526,7 +573,7 @@ type SqlBuildOptions = {
526
573
  model?: string;
527
574
  alias?: string;
528
575
  context?: Record<string, unknown>;
529
- };
576
+ } & DateConfig;
530
577
  declare const toSql: (condition: Condition, options?: SqlBuildOptions) => SqlResult;
531
578
 
532
579
  type ValidationIssue = {
@@ -545,4 +592,4 @@ declare const assertValidRule: (condition: unknown, options?: {
545
592
  target?: RuleTarget;
546
593
  }) => asserts condition is Condition;
547
594
 
548
- export { AGGREGATE_OPERATORS, ALL_KINDS, ARRAY_OPERATOR_CATALOG, type AggregateMode, type AggregateRule, type All, type Any, type ArrayCatalogEntry, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BuildOptions, type CatalogEntry, type CheckOptions, type Condition, type CreateLensInput, DATE_OPERATOR_CATALOG, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderedRuleValue, type PathProjection, type PrismaStep, type PrismaWhere, type ProjectedVisit, type Rule, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SqlResult, type StepRef, type StrictAggregateRule, type StrictAll, type StrictAny, type StrictArrayCountRule, type StrictArrayPredicateRule, type StrictArrayPresenceRule, type StrictArrayRule, type StrictCondition, type StrictContainsRule, type StrictDateComparisonRule, type StrictDateDayRule, type StrictDateRangeRule, type StrictDateRule, type StrictEqualityRule, type StrictIfThenElse, type StrictMembershipRule, type StrictOrderedComparisonRule, type StrictPatternRule, type StrictPresenceRule, type StrictRangeRule, type StrictRule, type StrictStringBoundaryRule, type ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, type WhereStep, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
595
+ export { AGGREGATE_OPERATORS, ALL_KINDS, ARRAY_OPERATOR_CATALOG, type AggregateMode, type AggregateRule, type All, type Any, type ArrayCatalogEntry, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BuildOptions, type CatalogEntry, type CheckOptions, type Condition, type CreateLensInput, DATE_OPERATOR_CATALOG, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EdgeExpr, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderBy, type OrderedRuleValue, type PathProjection, type PeriodExpr, type PeriodUnit, type PrismaStep, type PrismaWhere, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SqlResult, type StepRef, type StrictAggregateRule, type StrictAll, type StrictAny, type StrictArrayCountRule, type StrictArrayPredicateRule, type StrictArrayPresenceRule, type StrictArrayRule, type StrictCondition, type StrictContainsRule, type StrictDateComparisonRule, type StrictDateDayRule, type StrictDateRangeRule, type StrictDateRule, type StrictEqualityRule, type StrictIfThenElse, type StrictMembershipRule, type StrictOrderedComparisonRule, type StrictPatternRule, type StrictPresenceRule, type StrictRangeRule, type StrictRule, type StrictStringBoundaryRule, type ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, type WeekStart, type WhereStep, type WindowFields, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };