@inixiative/json-rules 2.10.0 → 2.11.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
@@ -95,9 +95,15 @@ type DateConfig = {
95
95
  type ValueSource<TValue> = {
96
96
  value: TValue;
97
97
  path?: never;
98
+ bind?: never;
98
99
  } | {
99
100
  path: string;
100
101
  value?: never;
102
+ bind?: never;
103
+ } | {
104
+ bind: string;
105
+ value?: never;
106
+ path?: never;
101
107
  };
102
108
  type NoValueSource = {
103
109
  value?: never;
@@ -202,6 +208,7 @@ type AggregateRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowF
202
208
  operator: Operator;
203
209
  value?: number | [number, number];
204
210
  path?: string;
211
+ bind?: string;
205
212
  error?: string;
206
213
  };
207
214
  type Rule<TValue = RuleValue> = {
@@ -209,6 +216,7 @@ type Rule<TValue = RuleValue> = {
209
216
  operator: Operator;
210
217
  value?: TValue;
211
218
  path?: string;
219
+ bind?: string;
212
220
  error?: string;
213
221
  };
214
222
  type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowFields & {
@@ -223,6 +231,7 @@ type DateRule<TValue = DateRuleValue> = {
223
231
  dateOperator: DateOperator;
224
232
  value?: TValue;
225
233
  path?: string;
234
+ bind?: string;
226
235
  error?: string;
227
236
  };
228
237
  type All<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
@@ -256,10 +265,24 @@ type StrictIfThenElse<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
256
265
  };
257
266
  type StrictCondition<TRuleValue = RuleValue, TDateValue = DateRuleValue> = StrictRule<TRuleValue> | StrictAggregateRule<TRuleValue, TDateValue> | StrictArrayRule<TRuleValue, TDateValue> | StrictDateRule | StrictAll<TRuleValue, TDateValue> | StrictAny<TRuleValue, TDateValue> | StrictIfThenElse<TRuleValue, TDateValue> | boolean;
258
267
 
268
+ /**
269
+ * Names of every `{ bind }` token reachable in a condition tree. The flat-set
270
+ * shorthand a caller validates a bindings map against (`keys(bindings) ⊇ requiredBindings`).
271
+ */
272
+ declare const requiredBindings: (condition: Condition) => Set<string>;
273
+ /**
274
+ * Replace each `{ bind }` token the map covers with its `{ value }`, leaving uncovered
275
+ * tokens in place (partial / progressive resolution — `requiredBindings` shrinks). A node
276
+ * may carry both its own value-bind and a nested condition (aggregate/array), so both are
277
+ * handled. Does not mutate the input.
278
+ */
279
+ declare const resolveBindings: (condition: Condition, bindings: Record<string, RuleValue>) => Condition;
280
+
259
281
  type Row$1 = Record<string, unknown>;
260
282
  type CheckData = Row$1 | unknown[];
261
283
  type CheckOptions = {
262
284
  context?: CheckData;
285
+ bindings?: Record<string, RuleValue>;
263
286
  } & DateConfig;
264
287
  declare const check: <TData extends CheckData>(conditions: Condition, data: TData, options?: CheckOptions) => boolean | string;
265
288
 
@@ -424,6 +447,31 @@ type LensNarrowing = {
424
447
 
425
448
  declare const applyLens: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
426
449
 
450
+ /**
451
+ * Every bind name a lens (its whole narrowing chain) needs supplied to execute.
452
+ * `parent:` references collapse to their base name — the caller supplies one value
453
+ * per name and an inherited reference draws the same one. This is the "what does
454
+ * this lens require" answer; pass `narrowing.parent` to see the names a child must
455
+ * not collide with.
456
+ */
457
+ declare const lensRequiredBindings: (lensOrNarrowing: Lens | LensNarrowing) => Set<string>;
458
+ /**
459
+ * Preprocess a lens: resolve every `{ bind }` token the map covers in the chain's
460
+ * `where`/`sources`, returning a structurally-new lens with concrete conditions.
461
+ * Partial — uncovered tokens stay, so stages bind progressively. Once resolved,
462
+ * `applyLens` / `toPrisma` / `toSql` / `sourceQueries` / `projectByPath` consume the
463
+ * lens unchanged: a bind needs nothing new downstream. `parent:name` draws the same
464
+ * value as the ancestor's `name`. Does not mutate the input.
465
+ */
466
+ declare const resolveLensBindings: (lensOrNarrowing: Lens | LensNarrowing, bindings: Record<string, RuleValue>) => Lens | LensNarrowing;
467
+ /**
468
+ * Bind names are unique across a composed chain: a layer may not re-declare a name
469
+ * an ancestor already declares — rename it, or reference the inherited one read-only
470
+ * as `parent:name`. A `parent:name` reference must point at a name some ancestor
471
+ * actually declares. Returns the violation messages (folded into `validateNarrowing`).
472
+ */
473
+ declare const validateBindNames: (narrowing: LensNarrowing) => string[];
474
+
427
475
  type RuleLensViolation = {
428
476
  path: string;
429
477
  reason: string;
@@ -687,4 +735,4 @@ declare const assertValidRule: (condition: unknown, options?: {
687
735
  target?: RuleTarget;
688
736
  }) => asserts condition is Condition;
689
737
 
690
- 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 ProjectOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleDescription, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SourcePrismaQuery, type SourceQuery, type SourceSqlQuery, type SourceValues, 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, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, executePrismaQueryPlan, exposedSurface, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, sourceQueries, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
738
+ 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 ProjectOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleDescription, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SourcePrismaQuery, type SourceQuery, type SourceSqlQuery, type SourceValues, 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, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, executePrismaQueryPlan, exposedSurface, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, lensRequiredBindings, projectByPath, requiredBindings, resolveBindings, resolveLensBindings, sourceQueries, stitchFieldMaps, toPrisma, toSql, validateBindNames, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
package/dist/index.d.ts CHANGED
@@ -95,9 +95,15 @@ type DateConfig = {
95
95
  type ValueSource<TValue> = {
96
96
  value: TValue;
97
97
  path?: never;
98
+ bind?: never;
98
99
  } | {
99
100
  path: string;
100
101
  value?: never;
102
+ bind?: never;
103
+ } | {
104
+ bind: string;
105
+ value?: never;
106
+ path?: never;
101
107
  };
102
108
  type NoValueSource = {
103
109
  value?: never;
@@ -202,6 +208,7 @@ type AggregateRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowF
202
208
  operator: Operator;
203
209
  value?: number | [number, number];
204
210
  path?: string;
211
+ bind?: string;
205
212
  error?: string;
206
213
  };
207
214
  type Rule<TValue = RuleValue> = {
@@ -209,6 +216,7 @@ type Rule<TValue = RuleValue> = {
209
216
  operator: Operator;
210
217
  value?: TValue;
211
218
  path?: string;
219
+ bind?: string;
212
220
  error?: string;
213
221
  };
214
222
  type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowFields & {
@@ -223,6 +231,7 @@ type DateRule<TValue = DateRuleValue> = {
223
231
  dateOperator: DateOperator;
224
232
  value?: TValue;
225
233
  path?: string;
234
+ bind?: string;
226
235
  error?: string;
227
236
  };
228
237
  type All<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
@@ -256,10 +265,24 @@ type StrictIfThenElse<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
256
265
  };
257
266
  type StrictCondition<TRuleValue = RuleValue, TDateValue = DateRuleValue> = StrictRule<TRuleValue> | StrictAggregateRule<TRuleValue, TDateValue> | StrictArrayRule<TRuleValue, TDateValue> | StrictDateRule | StrictAll<TRuleValue, TDateValue> | StrictAny<TRuleValue, TDateValue> | StrictIfThenElse<TRuleValue, TDateValue> | boolean;
258
267
 
268
+ /**
269
+ * Names of every `{ bind }` token reachable in a condition tree. The flat-set
270
+ * shorthand a caller validates a bindings map against (`keys(bindings) ⊇ requiredBindings`).
271
+ */
272
+ declare const requiredBindings: (condition: Condition) => Set<string>;
273
+ /**
274
+ * Replace each `{ bind }` token the map covers with its `{ value }`, leaving uncovered
275
+ * tokens in place (partial / progressive resolution — `requiredBindings` shrinks). A node
276
+ * may carry both its own value-bind and a nested condition (aggregate/array), so both are
277
+ * handled. Does not mutate the input.
278
+ */
279
+ declare const resolveBindings: (condition: Condition, bindings: Record<string, RuleValue>) => Condition;
280
+
259
281
  type Row$1 = Record<string, unknown>;
260
282
  type CheckData = Row$1 | unknown[];
261
283
  type CheckOptions = {
262
284
  context?: CheckData;
285
+ bindings?: Record<string, RuleValue>;
263
286
  } & DateConfig;
264
287
  declare const check: <TData extends CheckData>(conditions: Condition, data: TData, options?: CheckOptions) => boolean | string;
265
288
 
@@ -424,6 +447,31 @@ type LensNarrowing = {
424
447
 
425
448
  declare const applyLens: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
426
449
 
450
+ /**
451
+ * Every bind name a lens (its whole narrowing chain) needs supplied to execute.
452
+ * `parent:` references collapse to their base name — the caller supplies one value
453
+ * per name and an inherited reference draws the same one. This is the "what does
454
+ * this lens require" answer; pass `narrowing.parent` to see the names a child must
455
+ * not collide with.
456
+ */
457
+ declare const lensRequiredBindings: (lensOrNarrowing: Lens | LensNarrowing) => Set<string>;
458
+ /**
459
+ * Preprocess a lens: resolve every `{ bind }` token the map covers in the chain's
460
+ * `where`/`sources`, returning a structurally-new lens with concrete conditions.
461
+ * Partial — uncovered tokens stay, so stages bind progressively. Once resolved,
462
+ * `applyLens` / `toPrisma` / `toSql` / `sourceQueries` / `projectByPath` consume the
463
+ * lens unchanged: a bind needs nothing new downstream. `parent:name` draws the same
464
+ * value as the ancestor's `name`. Does not mutate the input.
465
+ */
466
+ declare const resolveLensBindings: (lensOrNarrowing: Lens | LensNarrowing, bindings: Record<string, RuleValue>) => Lens | LensNarrowing;
467
+ /**
468
+ * Bind names are unique across a composed chain: a layer may not re-declare a name
469
+ * an ancestor already declares — rename it, or reference the inherited one read-only
470
+ * as `parent:name`. A `parent:name` reference must point at a name some ancestor
471
+ * actually declares. Returns the violation messages (folded into `validateNarrowing`).
472
+ */
473
+ declare const validateBindNames: (narrowing: LensNarrowing) => string[];
474
+
427
475
  type RuleLensViolation = {
428
476
  path: string;
429
477
  reason: string;
@@ -687,4 +735,4 @@ declare const assertValidRule: (condition: unknown, options?: {
687
735
  target?: RuleTarget;
688
736
  }) => asserts condition is Condition;
689
737
 
690
- 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 ProjectOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleDescription, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SourcePrismaQuery, type SourceQuery, type SourceSqlQuery, type SourceValues, 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, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, executePrismaQueryPlan, exposedSurface, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, sourceQueries, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
738
+ 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 ProjectOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleDescription, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SourcePrismaQuery, type SourceQuery, type SourceSqlQuery, type SourceValues, 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, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, executePrismaQueryPlan, exposedSurface, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, lensRequiredBindings, projectByPath, requiredBindings, resolveBindings, resolveLensBindings, sourceQueries, stitchFieldMaps, toPrisma, toSql, validateBindNames, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };