@inixiative/json-rules 2.11.0 → 2.12.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
@@ -87,9 +87,12 @@ type DateExpr = RollingExpr | PeriodExpr | EdgeExpr;
87
87
  type DateInputOrExpr = DateInputValue | DateExpr;
88
88
  type DateRuleValue = DateInputValue | DateExpr | [DateInputOrExpr, DateInputOrExpr] | string[];
89
89
  type WeekStart = 'monday' | 'sunday';
90
+ type TimeZoneConfig = string | {
91
+ bind: string;
92
+ };
90
93
  type DateConfig = {
91
94
  now?: DateInputValue;
92
- timeZone?: string;
95
+ timeZone?: TimeZoneConfig;
93
96
  weekStart?: WeekStart;
94
97
  };
95
98
  type ValueSource<TValue> = {
@@ -287,6 +290,11 @@ type CheckOptions = {
287
290
  declare const check: <TData extends CheckData>(conditions: Condition, data: TData, options?: CheckOptions) => boolean | string;
288
291
 
289
292
  type PrismaWhere = Record<string, unknown>;
293
+ /** A selectable option — the standard `<select>` shape: a value with an optional display label. */
294
+ type SourceOption = {
295
+ value: string;
296
+ label?: string;
297
+ };
290
298
  type FieldMapEntry = {
291
299
  kind: 'scalar' | 'object' | 'enum' | 'bridge';
292
300
  type: string;
@@ -300,6 +308,13 @@ type FieldMapEntry = {
300
308
  * (e.g. prisma-map's `EnumField.values`). Consumed by `checkRuleAgainstLens`.
301
309
  */
302
310
  values?: readonly string[];
311
+ /**
312
+ * A field's selectable option set as `{ value, label? }` pairs — the display
313
+ * shape a picker consumes. On projection/surface output this is populated for
314
+ * every value-gated field (enum members normalized to `{ value, label: value }`)
315
+ * and for sourced fields (the fetched pairs from a materialized `SourceValues`).
316
+ */
317
+ options?: readonly SourceOption[];
303
318
  };
304
319
  type ModelEntry = {
305
320
  dbName?: string | null;
@@ -410,13 +425,25 @@ type ModelDefaultNarrowing = {
410
425
  */
411
426
  where?: Condition;
412
427
  /**
413
- * Per-field eligibility `where` over THIS model — decorates a field's option
414
- * picker. The field's selectable values = DISTINCT(field) over this model
415
- * filtered by `where` (plus the model's own narrowing). Composes like `where`:
416
- * general via `mapDefaults`, path-specific via `root`/`relations`, AND-only.
428
+ * Per-field eligibility over THIS model — decorates a field's option picker.
429
+ * A bare `Condition` is the eligibility `where`: the field's selectable values =
430
+ * DISTINCT(field) over this model filtered by `where` (plus the model's own
431
+ * narrowing). A `SourceSpec` adds an optional `label` — a sibling column on this
432
+ * same model co-selected as each value's display label. Referenced-model option
433
+ * sets need no special form: declare the source at a relation-traversed narrowing
434
+ * node and it compiles over whatever model that path resolves to. The `where`
435
+ * composes AND-only across layers (general via `mapDefaults`, path-specific via
436
+ * `root`/`relations`); a later layer's `label` wins.
417
437
  */
418
- sources?: Record<string, Condition>;
438
+ sources?: Record<string, SourceValue>;
439
+ };
440
+ /** A sourced field's eligibility `where` plus an optional sibling display-label column. */
441
+ type SourceSpec = {
442
+ where?: Condition;
443
+ label?: string;
419
444
  };
445
+ /** A `sources` entry: a bare eligibility `Condition`, or a richer `SourceSpec`. */
446
+ type SourceValue = Condition | SourceSpec;
420
447
  /** Narrowing for a model at a specific traversal path. Adds relations to the default shape. */
421
448
  type ModelNarrowing = ModelDefaultNarrowing & {
422
449
  relations?: Record<string, ModelNarrowing>;
@@ -508,6 +535,7 @@ declare const ORDERABLE_KINDS: readonly FieldKind[];
508
535
  declare const STRINGY_KINDS: readonly FieldKind[];
509
536
  declare const EQUATABLE_KINDS: readonly FieldKind[];
510
537
  declare const ALL_KINDS: readonly FieldKind[];
538
+ declare const NULLABLE_KINDS: readonly FieldKind[];
511
539
  declare const RuleTarget: {
512
540
  readonly check: "check";
513
541
  readonly toPrisma: "toPrisma";
@@ -593,12 +621,14 @@ type ProjectedVisit = {
593
621
  whereClauses: Condition[];
594
622
  /** Per-field source eligibility wheres, composed across layers (general + path). */
595
623
  sources: Record<string, Condition[]>;
624
+ /** Per-field display-label column for a sourced field (from a SourceSpec's `label`). */
625
+ sourceLabels: Record<string, string>;
596
626
  };
597
627
  type PathProjection = Map<string, ProjectedVisit>;
598
628
  /**
599
629
  * The materialized option set for one sourced field — the fetched companion to a
600
- * serializable lens. Shaped to be exactly what `sourceQueries()` emits plus the
601
- * fetched `values`, so it feeds both projections: `projectByPath` keys by
630
+ * serializable lens. Its `options` are `{ value, label? }` pairs (the standard
631
+ * `<select>` shape); it feeds both projections: `projectByPath` keys by
602
632
  * `path`+`field` (exact), `exposedSurface` by `mapName`+`model`+`field` (union).
603
633
  */
604
634
  type SourceValues = {
@@ -606,7 +636,7 @@ type SourceValues = {
606
636
  mapName: string;
607
637
  model: string;
608
638
  field: string;
609
- values: readonly string[];
639
+ options: readonly SourceOption[];
610
640
  };
611
641
  type ProjectOptions = {
612
642
  sourceValues?: readonly SourceValues[];
@@ -638,6 +668,8 @@ type SourceQuery = {
638
668
  mapName: string;
639
669
  model: string;
640
670
  field: string;
671
+ /** Sibling column co-selected as each value's display label (from a SourceSpec's `label`). */
672
+ label?: string;
641
673
  composedWhere: Condition;
642
674
  prisma: SourcePrismaQuery;
643
675
  sql: SourceSqlQuery;
@@ -735,4 +767,4 @@ declare const assertValidRule: (condition: unknown, options?: {
735
767
  target?: RuleTarget;
736
768
  }) => asserts condition is Condition;
737
769
 
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 };
770
+ 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, NULLABLE_KINDS, 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 SourceOption, type SourcePrismaQuery, type SourceQuery, type SourceSpec, type SourceSqlQuery, type SourceValue, 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 TimeZoneConfig, 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
@@ -87,9 +87,12 @@ type DateExpr = RollingExpr | PeriodExpr | EdgeExpr;
87
87
  type DateInputOrExpr = DateInputValue | DateExpr;
88
88
  type DateRuleValue = DateInputValue | DateExpr | [DateInputOrExpr, DateInputOrExpr] | string[];
89
89
  type WeekStart = 'monday' | 'sunday';
90
+ type TimeZoneConfig = string | {
91
+ bind: string;
92
+ };
90
93
  type DateConfig = {
91
94
  now?: DateInputValue;
92
- timeZone?: string;
95
+ timeZone?: TimeZoneConfig;
93
96
  weekStart?: WeekStart;
94
97
  };
95
98
  type ValueSource<TValue> = {
@@ -287,6 +290,11 @@ type CheckOptions = {
287
290
  declare const check: <TData extends CheckData>(conditions: Condition, data: TData, options?: CheckOptions) => boolean | string;
288
291
 
289
292
  type PrismaWhere = Record<string, unknown>;
293
+ /** A selectable option — the standard `<select>` shape: a value with an optional display label. */
294
+ type SourceOption = {
295
+ value: string;
296
+ label?: string;
297
+ };
290
298
  type FieldMapEntry = {
291
299
  kind: 'scalar' | 'object' | 'enum' | 'bridge';
292
300
  type: string;
@@ -300,6 +308,13 @@ type FieldMapEntry = {
300
308
  * (e.g. prisma-map's `EnumField.values`). Consumed by `checkRuleAgainstLens`.
301
309
  */
302
310
  values?: readonly string[];
311
+ /**
312
+ * A field's selectable option set as `{ value, label? }` pairs — the display
313
+ * shape a picker consumes. On projection/surface output this is populated for
314
+ * every value-gated field (enum members normalized to `{ value, label: value }`)
315
+ * and for sourced fields (the fetched pairs from a materialized `SourceValues`).
316
+ */
317
+ options?: readonly SourceOption[];
303
318
  };
304
319
  type ModelEntry = {
305
320
  dbName?: string | null;
@@ -410,13 +425,25 @@ type ModelDefaultNarrowing = {
410
425
  */
411
426
  where?: Condition;
412
427
  /**
413
- * Per-field eligibility `where` over THIS model — decorates a field's option
414
- * picker. The field's selectable values = DISTINCT(field) over this model
415
- * filtered by `where` (plus the model's own narrowing). Composes like `where`:
416
- * general via `mapDefaults`, path-specific via `root`/`relations`, AND-only.
428
+ * Per-field eligibility over THIS model — decorates a field's option picker.
429
+ * A bare `Condition` is the eligibility `where`: the field's selectable values =
430
+ * DISTINCT(field) over this model filtered by `where` (plus the model's own
431
+ * narrowing). A `SourceSpec` adds an optional `label` — a sibling column on this
432
+ * same model co-selected as each value's display label. Referenced-model option
433
+ * sets need no special form: declare the source at a relation-traversed narrowing
434
+ * node and it compiles over whatever model that path resolves to. The `where`
435
+ * composes AND-only across layers (general via `mapDefaults`, path-specific via
436
+ * `root`/`relations`); a later layer's `label` wins.
417
437
  */
418
- sources?: Record<string, Condition>;
438
+ sources?: Record<string, SourceValue>;
439
+ };
440
+ /** A sourced field's eligibility `where` plus an optional sibling display-label column. */
441
+ type SourceSpec = {
442
+ where?: Condition;
443
+ label?: string;
419
444
  };
445
+ /** A `sources` entry: a bare eligibility `Condition`, or a richer `SourceSpec`. */
446
+ type SourceValue = Condition | SourceSpec;
420
447
  /** Narrowing for a model at a specific traversal path. Adds relations to the default shape. */
421
448
  type ModelNarrowing = ModelDefaultNarrowing & {
422
449
  relations?: Record<string, ModelNarrowing>;
@@ -508,6 +535,7 @@ declare const ORDERABLE_KINDS: readonly FieldKind[];
508
535
  declare const STRINGY_KINDS: readonly FieldKind[];
509
536
  declare const EQUATABLE_KINDS: readonly FieldKind[];
510
537
  declare const ALL_KINDS: readonly FieldKind[];
538
+ declare const NULLABLE_KINDS: readonly FieldKind[];
511
539
  declare const RuleTarget: {
512
540
  readonly check: "check";
513
541
  readonly toPrisma: "toPrisma";
@@ -593,12 +621,14 @@ type ProjectedVisit = {
593
621
  whereClauses: Condition[];
594
622
  /** Per-field source eligibility wheres, composed across layers (general + path). */
595
623
  sources: Record<string, Condition[]>;
624
+ /** Per-field display-label column for a sourced field (from a SourceSpec's `label`). */
625
+ sourceLabels: Record<string, string>;
596
626
  };
597
627
  type PathProjection = Map<string, ProjectedVisit>;
598
628
  /**
599
629
  * The materialized option set for one sourced field — the fetched companion to a
600
- * serializable lens. Shaped to be exactly what `sourceQueries()` emits plus the
601
- * fetched `values`, so it feeds both projections: `projectByPath` keys by
630
+ * serializable lens. Its `options` are `{ value, label? }` pairs (the standard
631
+ * `<select>` shape); it feeds both projections: `projectByPath` keys by
602
632
  * `path`+`field` (exact), `exposedSurface` by `mapName`+`model`+`field` (union).
603
633
  */
604
634
  type SourceValues = {
@@ -606,7 +636,7 @@ type SourceValues = {
606
636
  mapName: string;
607
637
  model: string;
608
638
  field: string;
609
- values: readonly string[];
639
+ options: readonly SourceOption[];
610
640
  };
611
641
  type ProjectOptions = {
612
642
  sourceValues?: readonly SourceValues[];
@@ -638,6 +668,8 @@ type SourceQuery = {
638
668
  mapName: string;
639
669
  model: string;
640
670
  field: string;
671
+ /** Sibling column co-selected as each value's display label (from a SourceSpec's `label`). */
672
+ label?: string;
641
673
  composedWhere: Condition;
642
674
  prisma: SourcePrismaQuery;
643
675
  sql: SourceSqlQuery;
@@ -735,4 +767,4 @@ declare const assertValidRule: (condition: unknown, options?: {
735
767
  target?: RuleTarget;
736
768
  }) => asserts condition is Condition;
737
769
 
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 };
770
+ 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, NULLABLE_KINDS, 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 SourceOption, type SourcePrismaQuery, type SourceQuery, type SourceSpec, type SourceSqlQuery, type SourceValue, 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 TimeZoneConfig, 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 };