@inixiative/json-rules 2.6.0 → 2.8.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
@@ -187,6 +187,7 @@ type OrderBy = {
187
187
  dir: SortDir;
188
188
  }[];
189
189
  type WindowFields = {
190
+ filter?: Condition;
190
191
  orderBy?: OrderBy;
191
192
  take?: number;
192
193
  skip?: number;
@@ -434,17 +435,6 @@ type CreateLensInput = {
434
435
  };
435
436
  declare const createLens: (input: CreateLensInput) => Lens;
436
437
 
437
- declare const validateNarrowing: (narrowing: LensNarrowing) => void;
438
-
439
- type ProjectedVisit = {
440
- mapName: string;
441
- modelName: string;
442
- fields: Record<string, FieldMapEntry>;
443
- whereClauses: Condition[];
444
- };
445
- type PathProjection = Map<string, ProjectedVisit>;
446
- declare const projectByPath: (lensOrNarrowing: Lens | LensNarrowing) => PathProjection;
447
-
448
438
  declare const FieldKind: {
449
439
  readonly String: "String";
450
440
  readonly Boolean: "Boolean";
@@ -479,6 +469,7 @@ declare const ValueShape: {
479
469
  readonly range: "range";
480
470
  readonly dateValue: "dateValue";
481
471
  readonly dateRange: "dateRange";
472
+ readonly dateWindow: "dateWindow";
482
473
  readonly dayList: "dayList";
483
474
  readonly count: "count";
484
475
  readonly predicate: "predicate";
@@ -488,6 +479,7 @@ type CatalogEntry = {
488
479
  kinds: readonly FieldKind[];
489
480
  targets: readonly RuleTarget[];
490
481
  valueShape: ValueShape;
482
+ acceptsExpr?: boolean;
491
483
  };
492
484
  declare const FIELD_OPERATOR_CATALOG: Record<Operator, CatalogEntry>;
493
485
  declare const DATE_OPERATOR_CATALOG: Record<DateOperator, CatalogEntry>;
@@ -496,6 +488,30 @@ type ArrayCatalogEntry = {
496
488
  valueShape: ValueShape;
497
489
  };
498
490
  declare const ARRAY_OPERATOR_CATALOG: Record<ArrayOperator, ArrayCatalogEntry>;
491
+ declare const WindowSupport: {
492
+ readonly full: "full";
493
+ readonly extremal: "extremal";
494
+ readonly none: "none";
495
+ };
496
+ type WindowSupport = (typeof WindowSupport)[keyof typeof WindowSupport];
497
+ declare const WINDOW_SELECTOR: {
498
+ readonly fields: readonly ["filter", "orderBy", "take", "skip"];
499
+ readonly sortDirs: readonly ["asc", "desc"];
500
+ readonly support: {
501
+ readonly array: {
502
+ readonly check: "full";
503
+ readonly toPrisma: "extremal";
504
+ readonly toSql: "none";
505
+ };
506
+ readonly aggregate: {
507
+ readonly check: "full";
508
+ readonly toPrisma: "none";
509
+ readonly toSql: "none";
510
+ };
511
+ };
512
+ };
513
+ type WindowRuleType = keyof typeof WINDOW_SELECTOR.support;
514
+ declare const getWindowSupport: (ruleType: WindowRuleType, target: RuleTarget) => WindowSupport;
499
515
  declare const AGGREGATE_OPERATORS: readonly Operator[];
500
516
  declare const isAggregateSingleOperator: (operator: Operator) => boolean;
501
517
  declare const isAggregateRangeOperator: (operator: Operator) => boolean;
@@ -507,6 +523,61 @@ declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget) => {
507
523
  };
508
524
  declare const getArrayOperators: (target?: RuleTarget) => ArrayOperator[];
509
525
 
526
+ type RuleDescription = {
527
+ /** Map (source) names the rule's fields touch, sorted. */
528
+ sources: string[];
529
+ /** True if any field/path crosses a bridge into another source. */
530
+ bridgesCrossed: boolean;
531
+ /** Execution targets that can run this rule, in canonical order. */
532
+ supportedTargets: RuleTarget[];
533
+ /** Field paths that don't resolve through the lens. */
534
+ violations: string[];
535
+ };
536
+ /**
537
+ * Classifies a rule against a lens: which sources it touches, whether it crosses
538
+ * a bridge, and which execution targets can run it. A bridge-crossing rule is
539
+ * `check()`-only — `toPrisma`/`toSql` can't join across sources, so the host must
540
+ * hydrate foreign rows (see `buildBridgeDictionary`) and evaluate in memory.
541
+ * Windowing further restricts targets (`toSql` never; `toPrisma` only the
542
+ * extremal array rewrite). `violations` lists field paths that don't resolve
543
+ * through the lens — use `checkRuleAgainstLens` for the full security gate.
544
+ */
545
+ declare const describeRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => RuleDescription;
546
+
547
+ /**
548
+ * Produces the total exposed surface of a (possibly narrowed) lens as a **Lens**
549
+ * (maps intact — the navigable graph), NOT a projection (path-keyed view). This
550
+ * is the leak-safe server→client surface: every model reachable from the anchor
551
+ * through visible relation/bridge edges, with the FULL narrowing applied — root
552
+ * at the anchor, path-specific narrowing along declared relation paths,
553
+ * model-default (`mapDefaults`) everywhere else — then unioned per model. A field
554
+ * appears iff it is visible on at least one reachable, narrowed path; fields
555
+ * hidden on every path (including those hidden only by `root`) are absent, so it
556
+ * never exposes the raw, un-narrowed lens.
557
+ *
558
+ * `where` (data-scope) narrowing is dropped — this is the client schema surface.
559
+ * For a server→subtenant handoff that must preserve `where` and per-path
560
+ * narrowing, use `seal` (planned) instead. Per-path divergence (a model that
561
+ * looks different at two sibling paths) is not represented here; pair with
562
+ * `projectByPath` when that distinction matters.
563
+ *
564
+ * Cycle-safe: declared-path visits are keyed by path (the declared tree is
565
+ * finite) and off-path visits by model (visited once), so recursive schemas
566
+ * (User → Org → members(User) → …) terminate.
567
+ */
568
+ declare const exposedSurface: (lensOrNarrowing: Lens | LensNarrowing) => Lens;
569
+
570
+ declare const validateNarrowing: (narrowing: LensNarrowing) => void;
571
+
572
+ type ProjectedVisit = {
573
+ mapName: string;
574
+ modelName: string;
575
+ fields: Record<string, FieldMapEntry>;
576
+ whereClauses: Condition[];
577
+ };
578
+ type PathProjection = Map<string, ProjectedVisit>;
579
+ declare const projectByPath: (lensOrNarrowing: Lens | LensNarrowing) => PathProjection;
580
+
510
581
  /**
511
582
  * Execute a Prisma query plan produced by toPrisma().
512
583
  *
@@ -592,4 +663,4 @@ declare const assertValidRule: (condition: unknown, options?: {
592
663
  target?: RuleTarget;
593
664
  }) => asserts condition is Condition;
594
665
 
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 };
666
+ 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 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, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
package/dist/index.d.ts CHANGED
@@ -187,6 +187,7 @@ type OrderBy = {
187
187
  dir: SortDir;
188
188
  }[];
189
189
  type WindowFields = {
190
+ filter?: Condition;
190
191
  orderBy?: OrderBy;
191
192
  take?: number;
192
193
  skip?: number;
@@ -434,17 +435,6 @@ type CreateLensInput = {
434
435
  };
435
436
  declare const createLens: (input: CreateLensInput) => Lens;
436
437
 
437
- declare const validateNarrowing: (narrowing: LensNarrowing) => void;
438
-
439
- type ProjectedVisit = {
440
- mapName: string;
441
- modelName: string;
442
- fields: Record<string, FieldMapEntry>;
443
- whereClauses: Condition[];
444
- };
445
- type PathProjection = Map<string, ProjectedVisit>;
446
- declare const projectByPath: (lensOrNarrowing: Lens | LensNarrowing) => PathProjection;
447
-
448
438
  declare const FieldKind: {
449
439
  readonly String: "String";
450
440
  readonly Boolean: "Boolean";
@@ -479,6 +469,7 @@ declare const ValueShape: {
479
469
  readonly range: "range";
480
470
  readonly dateValue: "dateValue";
481
471
  readonly dateRange: "dateRange";
472
+ readonly dateWindow: "dateWindow";
482
473
  readonly dayList: "dayList";
483
474
  readonly count: "count";
484
475
  readonly predicate: "predicate";
@@ -488,6 +479,7 @@ type CatalogEntry = {
488
479
  kinds: readonly FieldKind[];
489
480
  targets: readonly RuleTarget[];
490
481
  valueShape: ValueShape;
482
+ acceptsExpr?: boolean;
491
483
  };
492
484
  declare const FIELD_OPERATOR_CATALOG: Record<Operator, CatalogEntry>;
493
485
  declare const DATE_OPERATOR_CATALOG: Record<DateOperator, CatalogEntry>;
@@ -496,6 +488,30 @@ type ArrayCatalogEntry = {
496
488
  valueShape: ValueShape;
497
489
  };
498
490
  declare const ARRAY_OPERATOR_CATALOG: Record<ArrayOperator, ArrayCatalogEntry>;
491
+ declare const WindowSupport: {
492
+ readonly full: "full";
493
+ readonly extremal: "extremal";
494
+ readonly none: "none";
495
+ };
496
+ type WindowSupport = (typeof WindowSupport)[keyof typeof WindowSupport];
497
+ declare const WINDOW_SELECTOR: {
498
+ readonly fields: readonly ["filter", "orderBy", "take", "skip"];
499
+ readonly sortDirs: readonly ["asc", "desc"];
500
+ readonly support: {
501
+ readonly array: {
502
+ readonly check: "full";
503
+ readonly toPrisma: "extremal";
504
+ readonly toSql: "none";
505
+ };
506
+ readonly aggregate: {
507
+ readonly check: "full";
508
+ readonly toPrisma: "none";
509
+ readonly toSql: "none";
510
+ };
511
+ };
512
+ };
513
+ type WindowRuleType = keyof typeof WINDOW_SELECTOR.support;
514
+ declare const getWindowSupport: (ruleType: WindowRuleType, target: RuleTarget) => WindowSupport;
499
515
  declare const AGGREGATE_OPERATORS: readonly Operator[];
500
516
  declare const isAggregateSingleOperator: (operator: Operator) => boolean;
501
517
  declare const isAggregateRangeOperator: (operator: Operator) => boolean;
@@ -507,6 +523,61 @@ declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget) => {
507
523
  };
508
524
  declare const getArrayOperators: (target?: RuleTarget) => ArrayOperator[];
509
525
 
526
+ type RuleDescription = {
527
+ /** Map (source) names the rule's fields touch, sorted. */
528
+ sources: string[];
529
+ /** True if any field/path crosses a bridge into another source. */
530
+ bridgesCrossed: boolean;
531
+ /** Execution targets that can run this rule, in canonical order. */
532
+ supportedTargets: RuleTarget[];
533
+ /** Field paths that don't resolve through the lens. */
534
+ violations: string[];
535
+ };
536
+ /**
537
+ * Classifies a rule against a lens: which sources it touches, whether it crosses
538
+ * a bridge, and which execution targets can run it. A bridge-crossing rule is
539
+ * `check()`-only — `toPrisma`/`toSql` can't join across sources, so the host must
540
+ * hydrate foreign rows (see `buildBridgeDictionary`) and evaluate in memory.
541
+ * Windowing further restricts targets (`toSql` never; `toPrisma` only the
542
+ * extremal array rewrite). `violations` lists field paths that don't resolve
543
+ * through the lens — use `checkRuleAgainstLens` for the full security gate.
544
+ */
545
+ declare const describeRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => RuleDescription;
546
+
547
+ /**
548
+ * Produces the total exposed surface of a (possibly narrowed) lens as a **Lens**
549
+ * (maps intact — the navigable graph), NOT a projection (path-keyed view). This
550
+ * is the leak-safe server→client surface: every model reachable from the anchor
551
+ * through visible relation/bridge edges, with the FULL narrowing applied — root
552
+ * at the anchor, path-specific narrowing along declared relation paths,
553
+ * model-default (`mapDefaults`) everywhere else — then unioned per model. A field
554
+ * appears iff it is visible on at least one reachable, narrowed path; fields
555
+ * hidden on every path (including those hidden only by `root`) are absent, so it
556
+ * never exposes the raw, un-narrowed lens.
557
+ *
558
+ * `where` (data-scope) narrowing is dropped — this is the client schema surface.
559
+ * For a server→subtenant handoff that must preserve `where` and per-path
560
+ * narrowing, use `seal` (planned) instead. Per-path divergence (a model that
561
+ * looks different at two sibling paths) is not represented here; pair with
562
+ * `projectByPath` when that distinction matters.
563
+ *
564
+ * Cycle-safe: declared-path visits are keyed by path (the declared tree is
565
+ * finite) and off-path visits by model (visited once), so recursive schemas
566
+ * (User → Org → members(User) → …) terminate.
567
+ */
568
+ declare const exposedSurface: (lensOrNarrowing: Lens | LensNarrowing) => Lens;
569
+
570
+ declare const validateNarrowing: (narrowing: LensNarrowing) => void;
571
+
572
+ type ProjectedVisit = {
573
+ mapName: string;
574
+ modelName: string;
575
+ fields: Record<string, FieldMapEntry>;
576
+ whereClauses: Condition[];
577
+ };
578
+ type PathProjection = Map<string, ProjectedVisit>;
579
+ declare const projectByPath: (lensOrNarrowing: Lens | LensNarrowing) => PathProjection;
580
+
510
581
  /**
511
582
  * Execute a Prisma query plan produced by toPrisma().
512
583
  *
@@ -592,4 +663,4 @@ declare const assertValidRule: (condition: unknown, options?: {
592
663
  target?: RuleTarget;
593
664
  }) => asserts condition is Condition;
594
665
 
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 };
666
+ 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 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, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };