@inixiative/json-rules 2.7.0 → 2.9.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
@@ -386,6 +386,13 @@ type ModelDefaultNarrowing = {
386
386
  * Composes via filter-first semantic at every visit of this model.
387
387
  */
388
388
  where?: Condition;
389
+ /**
390
+ * Per-field eligibility `where` over THIS model — decorates a field's option
391
+ * picker. The field's selectable values = DISTINCT(field) over this model
392
+ * filtered by `where` (plus the model's own narrowing). Composes like `where`:
393
+ * general via `mapDefaults`, path-specific via `root`/`relations`, AND-only.
394
+ */
395
+ sources?: Record<string, Condition>;
389
396
  };
390
397
  /** Narrowing for a model at a specific traversal path. Adds relations to the default shape. */
391
398
  type ModelNarrowing = ModelDefaultNarrowing & {
@@ -435,17 +442,6 @@ type CreateLensInput = {
435
442
  };
436
443
  declare const createLens: (input: CreateLensInput) => Lens;
437
444
 
438
- declare const validateNarrowing: (narrowing: LensNarrowing) => void;
439
-
440
- type ProjectedVisit = {
441
- mapName: string;
442
- modelName: string;
443
- fields: Record<string, FieldMapEntry>;
444
- whereClauses: Condition[];
445
- };
446
- type PathProjection = Map<string, ProjectedVisit>;
447
- declare const projectByPath: (lensOrNarrowing: Lens | LensNarrowing) => PathProjection;
448
-
449
445
  declare const FieldKind: {
450
446
  readonly String: "String";
451
447
  readonly Boolean: "Boolean";
@@ -534,6 +530,75 @@ declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget) => {
534
530
  };
535
531
  declare const getArrayOperators: (target?: RuleTarget) => ArrayOperator[];
536
532
 
533
+ type RuleDescription = {
534
+ sources: string[];
535
+ bridgesCrossed: boolean;
536
+ supportedTargets: RuleTarget[];
537
+ violations: string[];
538
+ };
539
+ declare const describeRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => RuleDescription;
540
+
541
+ declare const exposedSurface: (lensOrNarrowing: Lens | LensNarrowing) => Lens;
542
+
543
+ declare const validateNarrowing: (narrowing: LensNarrowing) => void;
544
+
545
+ type ProjectedVisit = {
546
+ mapName: string;
547
+ modelName: string;
548
+ fields: Record<string, FieldMapEntry>;
549
+ whereClauses: Condition[];
550
+ /** Per-field source eligibility wheres, composed across layers (general + path). */
551
+ sources: Record<string, Condition[]>;
552
+ };
553
+ type PathProjection = Map<string, ProjectedVisit>;
554
+ declare const projectByPath: (lensOrNarrowing: Lens | LensNarrowing) => PathProjection;
555
+
556
+ type SourcePrismaQuery = {
557
+ model: string;
558
+ distinct: string[];
559
+ select: Record<string, true>;
560
+ where: PrismaWhere;
561
+ /** Present only if the composed where used count operators (run via executePrismaQueryPlan). */
562
+ steps?: PrismaStep[];
563
+ };
564
+ /** `sql` is null when the composed where uses a predicate SQL can't express
565
+ * (e.g. array-condition operators); `error` then carries why. Prisma still
566
+ * compiles — run that, or fall back to fetch + `check()`. */
567
+ type SourceSqlQuery = {
568
+ sql: string | null;
569
+ params: unknown[];
570
+ error?: string;
571
+ };
572
+ type SourceQuery = {
573
+ path: string;
574
+ mapName: string;
575
+ model: string;
576
+ field: string;
577
+ composedWhere: Condition;
578
+ prisma: SourcePrismaQuery;
579
+ sql: SourceSqlQuery;
580
+ };
581
+ /**
582
+ * Compile a DISTINCT(value) query — Prisma and SQL — per sourced field across
583
+ * the projected lens. The WHERE is the field's composed eligibility: the model's
584
+ * own narrowing at that path AND its source where(s). The app runs these (with
585
+ * its own client) to materialize each field's option set.
586
+ */
587
+ declare const sourceQueries: (lensOrNarrowing: Lens | LensNarrowing) => SourceQuery[];
588
+ type SourceValues = {
589
+ path: string;
590
+ field: string;
591
+ values: readonly string[];
592
+ };
593
+ /**
594
+ * Decorate fetched DISTINCT values back onto the projected lens. Each result's
595
+ * values land on `projection.get(path).fields[field].values` — the existing
596
+ * pseudo-enum primitive the builder reads. Per-path, so the same model at two
597
+ * paths can carry different option sets. Pure: returns a new projection;
598
+ * results for unknown paths or fields are ignored.
599
+ */
600
+ declare const applySourceValues: (projection: PathProjection, results: readonly SourceValues[]) => PathProjection;
601
+
537
602
  /**
538
603
  * Execute a Prisma query plan produced by toPrisma().
539
604
  *
@@ -619,4 +684,4 @@ declare const assertValidRule: (condition: unknown, options?: {
619
684
  target?: RuleTarget;
620
685
  }) => asserts condition is Condition;
621
686
 
622
- 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, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
687
+ 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 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, applySourceValues, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, executePrismaQueryPlan, exposedSurface, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, sourceQueries, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
package/dist/index.d.ts CHANGED
@@ -386,6 +386,13 @@ type ModelDefaultNarrowing = {
386
386
  * Composes via filter-first semantic at every visit of this model.
387
387
  */
388
388
  where?: Condition;
389
+ /**
390
+ * Per-field eligibility `where` over THIS model — decorates a field's option
391
+ * picker. The field's selectable values = DISTINCT(field) over this model
392
+ * filtered by `where` (plus the model's own narrowing). Composes like `where`:
393
+ * general via `mapDefaults`, path-specific via `root`/`relations`, AND-only.
394
+ */
395
+ sources?: Record<string, Condition>;
389
396
  };
390
397
  /** Narrowing for a model at a specific traversal path. Adds relations to the default shape. */
391
398
  type ModelNarrowing = ModelDefaultNarrowing & {
@@ -435,17 +442,6 @@ type CreateLensInput = {
435
442
  };
436
443
  declare const createLens: (input: CreateLensInput) => Lens;
437
444
 
438
- declare const validateNarrowing: (narrowing: LensNarrowing) => void;
439
-
440
- type ProjectedVisit = {
441
- mapName: string;
442
- modelName: string;
443
- fields: Record<string, FieldMapEntry>;
444
- whereClauses: Condition[];
445
- };
446
- type PathProjection = Map<string, ProjectedVisit>;
447
- declare const projectByPath: (lensOrNarrowing: Lens | LensNarrowing) => PathProjection;
448
-
449
445
  declare const FieldKind: {
450
446
  readonly String: "String";
451
447
  readonly Boolean: "Boolean";
@@ -534,6 +530,75 @@ declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget) => {
534
530
  };
535
531
  declare const getArrayOperators: (target?: RuleTarget) => ArrayOperator[];
536
532
 
533
+ type RuleDescription = {
534
+ sources: string[];
535
+ bridgesCrossed: boolean;
536
+ supportedTargets: RuleTarget[];
537
+ violations: string[];
538
+ };
539
+ declare const describeRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => RuleDescription;
540
+
541
+ declare const exposedSurface: (lensOrNarrowing: Lens | LensNarrowing) => Lens;
542
+
543
+ declare const validateNarrowing: (narrowing: LensNarrowing) => void;
544
+
545
+ type ProjectedVisit = {
546
+ mapName: string;
547
+ modelName: string;
548
+ fields: Record<string, FieldMapEntry>;
549
+ whereClauses: Condition[];
550
+ /** Per-field source eligibility wheres, composed across layers (general + path). */
551
+ sources: Record<string, Condition[]>;
552
+ };
553
+ type PathProjection = Map<string, ProjectedVisit>;
554
+ declare const projectByPath: (lensOrNarrowing: Lens | LensNarrowing) => PathProjection;
555
+
556
+ type SourcePrismaQuery = {
557
+ model: string;
558
+ distinct: string[];
559
+ select: Record<string, true>;
560
+ where: PrismaWhere;
561
+ /** Present only if the composed where used count operators (run via executePrismaQueryPlan). */
562
+ steps?: PrismaStep[];
563
+ };
564
+ /** `sql` is null when the composed where uses a predicate SQL can't express
565
+ * (e.g. array-condition operators); `error` then carries why. Prisma still
566
+ * compiles — run that, or fall back to fetch + `check()`. */
567
+ type SourceSqlQuery = {
568
+ sql: string | null;
569
+ params: unknown[];
570
+ error?: string;
571
+ };
572
+ type SourceQuery = {
573
+ path: string;
574
+ mapName: string;
575
+ model: string;
576
+ field: string;
577
+ composedWhere: Condition;
578
+ prisma: SourcePrismaQuery;
579
+ sql: SourceSqlQuery;
580
+ };
581
+ /**
582
+ * Compile a DISTINCT(value) query — Prisma and SQL — per sourced field across
583
+ * the projected lens. The WHERE is the field's composed eligibility: the model's
584
+ * own narrowing at that path AND its source where(s). The app runs these (with
585
+ * its own client) to materialize each field's option set.
586
+ */
587
+ declare const sourceQueries: (lensOrNarrowing: Lens | LensNarrowing) => SourceQuery[];
588
+ type SourceValues = {
589
+ path: string;
590
+ field: string;
591
+ values: readonly string[];
592
+ };
593
+ /**
594
+ * Decorate fetched DISTINCT values back onto the projected lens. Each result's
595
+ * values land on `projection.get(path).fields[field].values` — the existing
596
+ * pseudo-enum primitive the builder reads. Per-path, so the same model at two
597
+ * paths can carry different option sets. Pure: returns a new projection;
598
+ * results for unknown paths or fields are ignored.
599
+ */
600
+ declare const applySourceValues: (projection: PathProjection, results: readonly SourceValues[]) => PathProjection;
601
+
537
602
  /**
538
603
  * Execute a Prisma query plan produced by toPrisma().
539
604
  *
@@ -619,4 +684,4 @@ declare const assertValidRule: (condition: unknown, options?: {
619
684
  target?: RuleTarget;
620
685
  }) => asserts condition is Condition;
621
686
 
622
- 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, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
687
+ 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 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, applySourceValues, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, executePrismaQueryPlan, exposedSurface, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectByPath, sourceQueries, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };