@inixiative/json-rules 3.3.1 → 3.4.1

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
@@ -146,11 +146,11 @@ type Lens = FieldMapSet & {
146
146
  };
147
147
  /**
148
148
  * Narrowing applied wherever a model appears (intrinsic to the model).
149
- * Has no `relations` because relations are path-specific by definition.
150
149
  *
151
150
  * Two kinds of narrowing live here:
152
- * - SCHEMA narrowing (picks/omits/enumPicks/enumOmits): controls what's visible
153
- * in the type surface. AI/SDK consumers can't see narrowed-away fields.
151
+ * - SCHEMA narrowing (picks/omits/enumPicks/enumOmits, relations): controls what's visible in the
152
+ * type surface. AI/SDK consumers can't see narrowed-away fields. `picks` names columns only;
153
+ * a relation is a field turned on through `relations`.
154
154
  * - DATA narrowing (where): controls which ROWS are in scope. Filter-first
155
155
  * semantic, anchored to the model. Under arrayOperator: 'all', it becomes the window filter
156
156
  * (filter-first) — see narrowRule.
@@ -177,6 +177,16 @@ type ModelDefaultNarrowing = {
177
177
  * via `mapDefaults`, path-specific via `root`/`relations`); a later layer's `label` wins.
178
178
  */
179
179
  sources?: Record<string, SourceEntry>;
180
+ /**
181
+ * Relations are fields, off by default. A key here turns that relation on at this node — on a
182
+ * path node, at that visit; on a model default, wherever the model is visited — and its value is
183
+ * that hop's narrowing (`where`, `picks`/`omits` of the target's columns, further `relations`).
184
+ * Only the first narrowing over the base lens turns a relation on; a later layer may only narrow
185
+ * one its parent shows. Model-default turn-ons grow a tree under each spelled node: each model
186
+ * once, at its nearest reach; reach it another way by spelling the path under `root`. The first narrowing's grants (`where`) may read any
187
+ * relation; a later layer's only what its parent shows.
188
+ */
189
+ relations?: Record<string, ModelNarrowing>;
180
190
  };
181
191
  /**
182
192
  * A sourced field's eligibility `where` plus an optional display-label column — a
@@ -213,16 +223,14 @@ type SourceSpec = {
213
223
  };
214
224
  /** A `sources` entry: a bare eligibility `Condition`, or a richer `SourceSpec`. */
215
225
  type SourceEntry = Condition | SourceSpec;
216
- /** Narrowing for a model at a specific traversal path. Adds relations to the default shape. */
217
- type ModelNarrowing = ModelDefaultNarrowing & {
218
- relations?: Record<string, ModelNarrowing>;
219
- };
226
+ /** Narrowing for a model at a specific traversal path: the same shape as a model default. */
227
+ type ModelNarrowing = ModelDefaultNarrowing;
220
228
  /** Narrowing for an enum type (applies anywhere the enum is referenced). */
221
229
  type EnumNarrowing = {
222
230
  picks?: readonly string[];
223
231
  omits?: readonly string[];
224
232
  };
225
- /** Applies-everywhere narrowings for one map — per-model (no relations) + per-enum-type. */
233
+ /** Applies-everywhere narrowings for one map — per-model + per-enum-type. */
226
234
  type NarrowingDefaults = {
227
235
  models?: Record<string, ModelDefaultNarrowing>;
228
236
  enums?: Record<string, EnumNarrowing>;
@@ -230,8 +238,8 @@ type NarrowingDefaults = {
230
238
  type LensNarrowing = {
231
239
  parent: Lens | LensNarrowing;
232
240
  /**
233
- * Path-specific narrowing anchored at (lens.mapName, lens.model). Descends via
234
- * `.relations` and may cross maps through bridge relations.
241
+ * Path-specific narrowing anchored at (lens.mapName, lens.model). Descends via `.relations` —
242
+ * which turns those relations on — and may cross maps through bridge relations.
235
243
  */
236
244
  root?: ModelNarrowing;
237
245
  /**
@@ -509,7 +517,7 @@ type StrictCondition<TRuleValue = RuleValue, TDateValue = DateRuleValue> = Stric
509
517
  /** A row as a rule reads it: a record of fields. */
510
518
  type Row = Record<string, unknown>;
511
519
  /** What both compilers take: the schema (a FieldMap, or a FieldMapSet with `mapName`), the
512
- * model the rule reads, the context bare `path` refs read, and the clock. `lens` compiles the
520
+ * model the rule reads, and the clock. `lens` compiles the
513
521
  * rule under a lens instead — narrowed (`narrowRule`), against the base lens's maps, map and
514
522
  * model — and can't be passed with `map` / `mapName` / `model`. */
515
523
  type CompileOptions = {
@@ -517,7 +525,6 @@ type CompileOptions = {
517
525
  mapName?: string;
518
526
  model?: string;
519
527
  lens?: Lens | LensNarrowing;
520
- context?: Row;
521
528
  } & DateConfig;
522
529
  /** What check() evaluates: one row, or a root array of them. */
523
530
  type CheckData = Row | unknown[];
@@ -539,8 +546,8 @@ declare const listBindings: (condition: Condition, { required }?: ListBindingsOp
539
546
  */
540
547
  declare const bindRule: (condition: Condition, bindings: Record<string, RuleValue>) => Condition;
541
548
 
549
+ /** `bindings`: the caller's values, read by `{ bind }`. The rest is the clock and zone. */
542
550
  type CheckOptions = {
543
- context?: CheckData;
544
551
  bindings?: Record<string, RuleValue>;
545
552
  } & DateConfig;
546
553
  /** Evaluate a rule against one row, or a root array of rows (fieldless array rules under
@@ -575,6 +582,12 @@ declare const engineGlobals: {
575
582
  with: <T>(partial: DeepPartial<EngineGlobalsState>, fn: () => T) => T;
576
583
  };
577
584
 
585
+ /** A caller's input missing or malformed — the clock, the time zone, a bind's value — not the
586
+ * rule's or the lens's shape. */
587
+ declare class UsageError extends Error {
588
+ name: string;
589
+ }
590
+
578
591
  type BridgeDictionary = Record<string, // map name
579
592
  Record<string, // model name
580
593
  Record<string, Record<string, Row | Row[]>>>>;
@@ -597,9 +610,14 @@ type ValidationResult = {
597
610
  ok: boolean;
598
611
  errors: ValidationIssue[];
599
612
  };
600
- /** Which engine a rule must compile for; `check` (the default) accepts every rule. */
613
+ /** Which engine a rule must compile for; `check` (the default) accepts every rule. The schema
614
+ * (`map` — a FieldMap, or a FieldMapSet with `mapName` — and `model`) lets the Prisma target
615
+ * accept a column compared with a column it can compile. */
601
616
  type ValidateRuleOptions = {
602
617
  target?: RuleTarget;
618
+ map?: FieldMap | FieldMapSet;
619
+ mapName?: string;
620
+ model?: string;
603
621
  };
604
622
  /** A rule's shape checked without data: every node well formed, and runnable on `target`
605
623
  * (operators, windows, scope refs, patterns). */
@@ -659,8 +677,7 @@ declare const describeRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrow
659
677
  * The values one rule compares at one declared source — keyed the way `projectPaths`
660
678
  * keys a source (`path` + `field`), so the caller can join it back to the source's
661
679
  * model without spelling a path of its own. A `mapDefaults`-declared source resolves
662
- * wherever its model appears, so `path` may name a relation chain the narrowing never
663
- * spelled under `root.relations`; the dotted format is the same.
680
+ * wherever its model appears on the declared relations; the dotted format is the same.
664
681
  */
665
682
  type RuleSourceDescription = {
666
683
  path: string;
@@ -682,23 +699,36 @@ type RuleSourceDescription = {
682
699
  * vocabulary, so it answers questions about it; callers never spell a path. A leaf reaches a
683
700
  * source by its absolute path through the lens: nested (`{ field: 'orders', arrayOperator,
684
701
  * condition: { field: 'sku' } }`) and dotted (`{ field: 'orders.sku' }`) spellings are one path,
685
- * resolved by `lensPathEnd` — visibility, `mapDefaults`, and the Json boundary all apply, so a
686
- * source declared in `mapDefaults` answers wherever its model appears. Quantifier-blind on
702
+ * resolved by `lensPathEnd` — declared relations, visibility, `mapDefaults`, and the Json boundary
703
+ * all apply, so a source declared in `mapDefaults` answers wherever a declared path reaches its model. Quantifier-blind on
687
704
  * purpose — a `none` relation names its value as much as an `any` one, `notIn` as much as `in` —
688
705
  * but shape-aware via the operator catalog: only literal-naming shapes contribute `values`;
689
706
  * substring / pattern / range / window operators, and operators the catalog does not know, mark
690
707
  * the source `dynamic` instead of inventing values. A relation node's own comparison (an
691
708
  * aggregate's threshold, an array `count`) belongs to the node, not to a source. Paths invisible
692
- * under the lens, unmapped segments, and sub-paths beneath a Json column are silent.
709
+ * or undeclared under the lens, unmapped segments, and sub-paths beneath a Json column are silent.
693
710
  */
694
711
  declare const describeRuleSources: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => RuleSourceDescription[];
695
712
 
713
+ /**
714
+ * The plan's own references — a `{ __step }` (a groupBy step's result) or a `{ __field }` (a
715
+ * column reference) — are objects this compile emitted, and the plan records where each sits.
716
+ * `executePrismaPlan` resolves those locations only: a rule value shaped like one is data, never a
717
+ * reference, and the compile refuses it outright.
718
+ */
719
+ /** Where a step's where (or groupBy args) holds a reference: the keys down to it. */
720
+ type SentinelRef = {
721
+ path: (string | number)[];
722
+ };
723
+
696
724
  type PrismaWhere = Record<string, unknown>;
697
725
  type StepRef = {
698
726
  __step: number;
699
727
  };
700
728
  type GroupByStep = {
701
729
  operation: 'groupBy';
730
+ /** Where `args` holds this plan's own references; only those are resolved. */
731
+ refs?: SentinelRef[];
702
732
  model: string;
703
733
  args: {
704
734
  by: string[];
@@ -710,6 +740,8 @@ type GroupByStep = {
710
740
  type WhereStep = {
711
741
  operation: 'where';
712
742
  where: Record<string, unknown>;
743
+ /** Where `where` holds this plan's own references; only those are resolved. */
744
+ refs?: SentinelRef[];
713
745
  };
714
746
  type PrismaStep = GroupByStep | WhereStep;
715
747
  type ToPrismaResult = {
@@ -721,51 +753,12 @@ type ToPrismaOptions = CompileOptions & {
721
753
  };
722
754
  };
723
755
 
724
- /** A Prisma `select` tree: a column, or a relation with its own `select` and, to-many, `where`. */
725
- type LensSelect = {
726
- [field: string]: true | LensRelationSelect;
727
- };
728
- type LensRelationSelect = {
729
- select?: LensSelect;
730
- where?: PrismaWhere;
731
- };
732
- /** `rules`: the rules the rows will be re-checked with — each relation they read past the declared
733
- * paths opens as a declared one. The rest is what a grant's compile reads: the clock and context,
734
- * never a schema (the lens is it). */
735
- type LensSelectOptions = Omit<ToPrismaOptions, 'map' | 'mapName' | 'model' | 'lens'> & {
736
- rules?: readonly Condition[];
737
- };
738
- /** `keepGrantColumns`: keep the columns the lens's `where`s read, though it hides them. `rules`: as
739
- * `toLensSelect`'s. The rest is what each `where` is checked with. */
740
- type ProjectRowsOptions = CheckOptions & {
741
- keepGrantColumns?: boolean;
742
- rules?: readonly Condition[];
743
- };
744
- /**
745
- * Prisma `findMany` args for the rows a lens shows, at its base model: each projected path's
746
- * visible columns, the relations its declared paths open (a visible relation off them, its columns
747
- * only), the relations `rules` read past them (opened as declared), and the columns every `where`
748
- * on the way reads. A to-many relation carries its visit's grants compiled as its `where`, so
749
- * related rows come pre-narrowed, unless a grant reads that list (it reads it whole); a to-one relation can't (Prisma
750
- * takes no `where` there), so `projectRows` drops one its grant hides. The root's own grants are the
751
- * query's `where`: `toPrisma(rule, { lens })`. Bridges are not selected. A relation grant that needs
752
- * a counting step throws.
753
- */
754
- declare const toLensSelect: (lensOrNarrowing: Lens | LensNarrowing, { rules, ...options }?: LensSelectOptions) => {
755
- select: LensSelect;
756
- };
757
- /**
758
- * Rows cut to what a lens shows, recursively from its base model: hidden columns and relations
759
- * removed, and every row a visit's `where` hides gone — a root or list row dropped, a to-one row
760
- * null. `keepGrantColumns` also keeps the columns those `where`s read (hidden or not), and a hidden to-one row, or a hidden row of a list a grant
761
- * reads, as those columns alone, so a later `check(narrowRule(rule, lens), row)` re-tests the
762
- * grants as the database does — for the rules passed in `rules`, or ones reading only the declared
763
- * paths. Its output carries hidden values: it's for that re-check, never for
764
- * a viewer. The rest of `options` is what each
765
- * `where` is checked with (`now`, `bindings`). Plain JSON in and out; the input is not mutated.
766
- */
767
- declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], { keepGrantColumns, rules, ...options }?: ProjectRowsOptions) => Row[];
768
-
756
+ /** A narrowing the lens refuses to apply: a grant validateNarrowing reports, met at runtime. */
757
+ declare class LensRefusal extends Error {
758
+ readonly code: string;
759
+ name: string;
760
+ constructor(message: string, code: string);
761
+ }
769
762
  type LensPathHop = {
770
763
  field: string;
771
764
  entry: FieldMapEntry;
@@ -776,9 +769,10 @@ type LensPathHop = {
776
769
  };
777
770
  /**
778
771
  * Where a dotted path lands through the lens, hop by hop. `hidden` is a field the model has but
779
- * the narrowing does not expose at this visit; `missing` is a field the model does not have (or a
780
- * model the map does not have); `pastScalar` is a segment after a scalar. A path that continues
781
- * below a Json column resolves at the column with the remainder in `jsonSubPath`.
772
+ * the narrowing does not expose at this visit — a column it doesn't keep, or a relation it doesn't
773
+ * turn on (or omits); `missing` is a field the model does not have (or a model the map does not
774
+ * have); `pastScalar` is a segment after a scalar. A path that continues below a Json column
775
+ * resolves at the column with the remainder in `jsonSubPath`.
782
776
  */
783
777
  type LensPathResolution = {
784
778
  outcome: 'resolved';
@@ -825,6 +819,52 @@ type SourceValues = {
825
819
  type ProjectLensOptions = {
826
820
  sourceValues?: readonly SourceValues[];
827
821
  };
822
+ /**
823
+ * One visit as `projectLens` (by path) gives it, resolved on demand: `relationPath` is the dotted
824
+ * relation path from the lens anchor (`''` for the anchor). Null when a relation on it isn't shown
825
+ * there — off, omitted, or outside the model-default tree. Nothing is
826
+ * enumerated, so it is cheap on any schema.
827
+ */
828
+ declare const lensVisit: (lensOrNarrowing: Lens | LensNarrowing, relationPath: string, opts?: ProjectLensOptions) => ProjectedVisit | null;
829
+
830
+ /** A Prisma `select` tree: a column, or a relation with its own `select` and, to-many, `where`. */
831
+ type LensSelect = {
832
+ [field: string]: true | LensRelationSelect;
833
+ };
834
+ type LensRelationSelect = {
835
+ select?: LensSelect;
836
+ where?: PrismaWhere;
837
+ };
838
+ /** What a grant's compile reads: the clock, never a schema (the lens is it). */
839
+ type LensSelectOptions = Omit<ToPrismaOptions, 'map' | 'mapName' | 'model' | 'lens'>;
840
+ /** `keepGrantColumns`: keep the columns the lens's `where`s read, though it hides them. The rest is
841
+ * what each `where` is checked with. */
842
+ type ProjectRowsOptions = CheckOptions & {
843
+ keepGrantColumns?: boolean;
844
+ };
845
+ /**
846
+ * Prisma `findMany` args for the rows a lens shows, at its base model: each shown visit's visible
847
+ * columns and the relations turned on there (one that is off is not fetched), and the
848
+ * columns every `where` on the way reads, through any relation. A to-many relation carries its visit's grants compiled as its `where`, so
849
+ * related rows come pre-narrowed, unless a grant reads that list (it reads it whole); a to-one relation can't (Prisma
850
+ * takes no `where` there), so `projectRows` drops one its grant hides. The root's own grants are the
851
+ * query's `where`: `toPrisma(rule, { lens })`. Bridges are not selected. A to-many relation's grant
852
+ * that needs a counting step, or has a window toPrisma can't compile, is refused before anything
853
+ * compiles.
854
+ */
855
+ declare const toLensSelect: (lensOrNarrowing: Lens | LensNarrowing, options?: LensSelectOptions) => {
856
+ select: LensSelect;
857
+ };
858
+ /**
859
+ * Rows cut to what a lens shows, recursively from its base model: hidden columns, and relations
860
+ * hidden or off, removed, and every row a visit's `where` hides gone — a root or list row dropped, a to-one row
861
+ * null. `keepGrantColumns` also keeps the columns those `where`s read (hidden or not), and a hidden to-one row, or a hidden row of a list a grant
862
+ * reads, as those columns alone, so a later `check(narrowRule(rule, lens), row)` re-tests the
863
+ * grants as the database does for any rule the lens admits. Its output carries hidden values: it's for that re-check, never for
864
+ * a viewer. The rest of `options` is what each
865
+ * `where` is checked with (`now`, `bindings`). Plain JSON in and out; the input is not mutated.
866
+ */
867
+ declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], { keepGrantColumns, ...options }?: ProjectRowsOptions) => Row[];
828
868
 
829
869
  /** Prisma `select` shape — nested for a grouped source's relation path. */
830
870
  type SourceSelect = {
@@ -834,8 +874,10 @@ type SourceSelect = {
834
874
  };
835
875
  type SourcePrismaQuery = {
836
876
  model: string;
837
- /** Absent for grouped sources — DISTINCT on the value column alone would collapse
838
- * same-value rows across groups; dedup happens in `materializeSourceQuery`. */
877
+ /** The value column, and a sibling label column: one row per value and label, so the least
878
+ * label is there for `materializeSourceQuery` to pick. Absent for grouped sources and a dotted
879
+ * label — DISTINCT on columns alone would collapse rows across groups or labels; dedup happens
880
+ * in `materializeSourceQuery`. */
839
881
  distinct?: string[];
840
882
  select: SourceSelect;
841
883
  where: PrismaWhere;
@@ -857,15 +899,30 @@ type SourceQuery = {
857
899
  field: string;
858
900
  /** Co-selected as each value's display label (from a SourceSpec's `label`): a sibling
859
901
  * column, or a dotted to-one path like a groupBy axis — then selected nested in prisma
860
- * and aliased `__label` in sql. */
902
+ * and aliased `__label` in sql. Across a bridge it is not selected: it is read from the far side
903
+ * the caller loads onto each candidate row. */
861
904
  label?: string;
862
905
  /** Option-partition axes (from a SourceSpec's `groupBy`, normalized); each axis
863
- * column is selected nested in prisma and aliased `__group_i` in sql. */
906
+ * column is selected nested in prisma and aliased `__group_i` in sql — save one across a
907
+ * bridge, read from the far side as a label across one is. */
864
908
  groupBy?: string[];
865
909
  composedWhere: Condition;
866
910
  prisma: SourcePrismaQuery;
867
911
  sql: SourceSqlQuery;
868
- };
912
+ /** Present when the source reads across a bridge (its where, a grant carried across one, its
913
+ * label or an axis); absent otherwise. **If `recheck` is present, the query's rows are
914
+ * candidates, not options:** a database holds one side of a bridge, so the query folds what
915
+ * reads across it to TRUE and over-fetches — it never misses an option, but may return more.
916
+ * `recheck` is the condition the database couldn't decide (the conjuncts of `composedWhere` that
917
+ * read across a bridge; `true` when only the label or an axis does). The query selects the local
918
+ * columns `recheck` reads and each bridge's local `on` key; load the far side onto each candidate
919
+ * row under its bridge field (the `indexBridges` shape) and pass the rows to
920
+ * `materializeSourceQuery(query, rows, { lens })`, which re-checks them and reads the label and
921
+ * axes across the bridge from the far side. */
922
+ recheck?: Condition;
923
+ };
924
+ /** What a source query's compile reads besides the lens: the clock, as the compilers take it. */
925
+ type SourceQueryOptions = DateConfig;
869
926
  /**
870
927
  * Compile a DISTINCT(value) query — Prisma and SQL — per sourced field across
871
928
  * the projected lens. The WHERE is the field's composed eligibility: the model's
@@ -873,15 +930,21 @@ type SourceQuery = {
873
930
  * where(s), the guards of the relations they cross and any allowed values. A
874
931
  * `from: 'mapDefaults'` source reads the model's own source and carries no grant from
875
932
  * its layer on. The app runs these (with its own client) to materialize each field's
876
- * option set — feed the fetched rows to `materializeSourceQuery`.
933
+ * option set — feed the fetched rows to `materializeSourceQuery`. `options` is the clock a
934
+ * relative date in the where compiles with (`now` required for one, as for any compile). A
935
+ * source that reads across a bridge gets an over-fetching query and a `recheck` (see
936
+ * `SourceQuery`): its rows are candidates, not options.
877
937
  */
878
- declare const toSourceQueries: (lensOrNarrowing: Lens | LensNarrowing) => SourceQuery[];
938
+ declare const toSourceQueries: (lensOrNarrowing: Lens | LensNarrowing, options?: SourceQueryOptions) => SourceQuery[];
879
939
 
880
940
  /** Which executor produced the rows — the caller always knows; never guessed. */
881
941
  type SourceRowShape = 'prisma' | 'sql';
882
- /** `rowShape`: how the rows came back — nested Prisma rows (the default) or flat SQL rows. */
883
- type MaterializeSourceQueryOptions = {
942
+ /** `rowShape`: how the rows came back — nested Prisma rows (the default) or flat SQL rows.
943
+ * `lens`: the lens the query was compiled from, required for a query with a `recheck` — it says
944
+ * what each far side must hold. The rest is the clock and bindings the re-check runs with. */
945
+ type MaterializeSourceQueryOptions = CheckOptions & {
884
946
  rowShape?: SourceRowShape;
947
+ lens?: Lens | LensNarrowing;
885
948
  };
886
949
  /**
887
950
  * Materialize one compiled `SourceQuery`'s fetched rows into its `SourceValues` —
@@ -890,6 +953,12 @@ type MaterializeSourceQueryOptions = {
890
953
  * (and a dotted `label`) as related objects; sql rows carry them flat under the
891
954
  * statement's `__group_i` / `__label` aliases. Grouped queries fetch without
892
955
  * DISTINCT, so dedup per (groups, value) happens here.
956
+ *
957
+ * A query with a `recheck` (a source across a bridge) returned candidates: each row must hold the
958
+ * far side inline under its bridge field — one row or a list as the bridge names it, with every
959
+ * key the re-check, the label and the axes read across it — or this throws a `UsageError` rather
960
+ * than offer a wrong set. A candidate offers its value only if `check(recheck, row, options)`
961
+ * holds; a label or axis across the bridge is read from the far side, in either row shape.
893
962
  */
894
963
  declare const materializeSourceQuery: (query: SourceQuery, rows: readonly Row[], opts?: MaterializeSourceQueryOptions) => SourceValues;
895
964
 
@@ -897,21 +966,26 @@ declare const materializeSourceQuery: (query: SourceQuery, rows: readonly Row[],
897
966
  * Materialize each sourced field's option set from an already-fetched collection —
898
967
  * the in-memory executor of `sources` declarations, alongside `toSourceQueries`
899
968
  * (which compiles the same declarations to DISTINCT queries for a DB). Rows are
900
- * the collection fetched under the lens (relations inline). Each row must meet the field's
901
- * eligibility — its source `where`, the grants above it, the guards of the relations it crosses
902
- * and any allowed values — evaluated with `check()` (`options` feeds `{bind}` clauses); its own
903
- * visit's `where` is not re-applied, since the rows were fetched under it. Scalar-list fields
904
- * contribute one option per element, labels take the first non-null value of the label column
905
- * (a sibling, or a dotted to-one path read through the nested rows), and sorting is
906
- * numeric-aware in a fixed locale. Feed the result to `projectLens` as `{ sourceValues }`. A
907
- * `from: 'mapDefaults'` source throws: a fetched collection can't hold unlinked rows.
969
+ * the collection the lens fetches — `toLensSelect`'s rows as fetched, or as
970
+ * `projectRows(…, { keepGrantColumns: true })` keeps them; a viewer's projection drops what
971
+ * the sources read, and a row lacking a key a source or a grant on its path reads throws. The
972
+ * path is walked down the rows, each level's grants met, and each row it reaches must meet its
973
+ * visit's grants, its source `where` narrowed as a rule, the guards of the relations its label
974
+ * and axes cross and any allowed values — evaluated with `check()` (`options`: `now`,
975
+ * `bindings`), so it offers what the database does. Scalar-list fields contribute one option per
976
+ * element, a value takes its least label (a sibling column, or a dotted to-one path read through
977
+ * the nested rows), and sorting is numeric-aware in a fixed locale. Feed the result to
978
+ * `projectLens` as `{ sourceValues }`. A source across a bridge is materialized from rows that
979
+ * hold the far side inline under its bridge field (the fetch selects no bridge); a
980
+ * `from: 'mapDefaults'` source throws: a fetched collection can't hold unlinked rows — query it.
908
981
  */
909
982
  declare const materializeSources: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], options?: CheckOptions) => SourceValues[];
910
983
 
911
- /** A narrowing layer checked against the layers above it: it names only what they still show and
912
- * only narrows. Each problem is an issue with a code (`not_in_lens`, `not_visible`,
913
- * `conflicting_selection`, `wrong_kind`, `value_not_allowed`, `invalid_source`,
914
- * `invalid_binding`, or the lens gate's for a `where`). */
984
+ /** A narrowing layer checked against the layers above it: it names only what they still show —
985
+ * a relation it turns on or narrows included, unless it is the first narrowing over the base
986
+ * lens — and only narrows. `picks` names columns only. Each problem is an issue with a code
987
+ * (`not_in_lens`, `not_visible`, `conflicting_selection`, `wrong_kind`, `value_not_allowed`,
988
+ * `invalid_source`, `invalid_binding`, or the lens gate's for a `where`). */
915
989
  declare const validateNarrowing: (narrowing: LensNarrowing) => ValidationResult;
916
990
  /** `validateNarrowing`, throwing its issues. */
917
991
  declare const assertValidNarrowing: (narrowing: LensNarrowing) => void;
@@ -943,7 +1017,7 @@ type LensValue = {
943
1017
  };
944
1018
  /**
945
1019
  * One value off a row, as the lens shows it: the path walked as `validateRuleInLens` walks a
946
- * field (a hidden, missing or past-scalar segment is refused), each related row checked against
1020
+ * field (a hidden segment — a column it doesn't keep, a relation it doesn't turn on — or a missing or past-scalar one is refused), each related row checked against
947
1021
  * its visit's grants, the row itself included (a row a grant hides, or a missing one, reads `null`), and only the row's own
948
1022
  * properties read, into a Json column too. A path ending on a relation, or crossing a list, names
949
1023
  * rows rather than a value and is refused. `options` is what each grant is checked with.
@@ -1004,11 +1078,15 @@ declare const readScopeRef: <S>(ref: string, scopes: readonly S[]) => ScopedRef<
1004
1078
  * Execute a Prisma query plan produced by toPrisma().
1005
1079
  *
1006
1080
  * The plan is a flat list of steps where all but the last are `groupBy` steps
1007
- * that feed results (via { __step: N } sentinels) into subsequent steps.
1008
- * The final step is always a `where` step whose resolved WHERE clause is returned.
1081
+ * that feed results (via { __step: N } references) into subsequent steps.
1082
+ * The final step is always a `where` step whose resolved WHERE clause is returned. A column
1083
+ * compared with a column is a `{ __field }` reference resolved to the delegate's field reference
1084
+ * (`prisma.user.fields.age`). Each step's `refs` record where its references sit, and only those
1085
+ * locations are resolved: a value shaped like a reference anywhere else stays data. Read a plan's
1086
+ * where only through here — Prisma rejects an unresolved reference.
1009
1087
  *
1010
1088
  * @param result - Result from toPrisma()
1011
- * @param prismaDelegate - Map of camelCase model name → Prisma delegate
1089
+ * @param prismaDelegate - Map of camelCase model name → Prisma delegate (or the client)
1012
1090
  * e.g. { post: prisma.post, user: prisma.user }
1013
1091
  * @returns The resolved WHERE clause (ready for findMany/count/etc.)
1014
1092
  *
@@ -1017,7 +1095,7 @@ declare const readScopeRef: <S>(ref: string, scopes: readonly S[]) => ScopedRef<
1017
1095
  * const where = await executePrismaPlan(plan, { post: prisma.post });
1018
1096
  * await prisma.user.findMany({ where });
1019
1097
  */
1020
- declare const executePrismaPlan: (plan: ToPrismaResult, prismaDelegate: Record<string, Record<string, (...args: unknown[]) => unknown>>) => Promise<Record<string, unknown>>;
1098
+ declare const executePrismaPlan: (plan: ToPrismaResult, prismaDelegate: Record<string, object>) => Promise<Record<string, unknown>>;
1021
1099
 
1022
1100
  /**
1023
1101
  * Compile a condition to a Prisma query plan: `steps`, any groupBy steps (counts and relation
@@ -1035,7 +1113,7 @@ declare const executePrismaPlan: (plan: ToPrismaResult, prismaDelegate: Record<s
1035
1113
  * const where = await executePrismaPlan(plan, prisma);
1036
1114
  * await prisma.user.findMany({ where });
1037
1115
  *
1038
- * toPrisma(rule, { lens: narrowing, now }); // gated, narrowed (a bare value path read as context), compiled against the base lens
1116
+ * toPrisma(rule, { lens: narrowing, now }); // gated, narrowed, compiled against the base lens
1039
1117
  * ```
1040
1118
  */
1041
1119
  declare const toPrisma: (rule: Condition, compileOptions?: ToPrismaOptions) => ToPrismaResult;
@@ -1054,4 +1132,4 @@ type ToSqlOptions = CompileOptions & {
1054
1132
  * base lens. */
1055
1133
  declare const toSql: (rule: Condition, compileOptions?: ToSqlOptions) => ToSqlResult;
1056
1134
 
1057
- export { ALL_KINDS, type AggregateMode, type AggregateRule, type All, type Any, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type CheckData, type CheckOptions, type CompileOptions, type Condition, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, type DateOffset, DateOperator, type DateRule, type DateRuleValue, type EdgeExpr, type EngineGlobalsState, type EnumNarrowing, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type FuzzyConfig, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type LensPathHop, type LensPathResolution, type LensRelationSelect, type LensSelect, type LensSelectOptions, type LensValue, type ListBindingsOptions, type Magnitude, type MaterializeSourceQueryOptions, type ModelDefaultNarrowing, type ModelEntry, type ModelNarrowing, NUMERIC_KINDS, type NarrowingDefaults, type NumberOffset, Operator, type OperatorFamily, type OrderBy, type OrderedRuleValue, type PathProjection, type PeriodExpr, type PeriodUnit, type PrismaProvider, type PrismaStep, type PrismaWhere, type ProjectLensOptions, type ProjectRowsOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Row, type Rule, type RuleDescription, type RuleScalar, type RuleSourceDescription, RuleTarget, type RuleValue, type ScopeOutOfBounds, type ScopeRef, type ScopedRef, type SortDir, type SourceEntry, type SourceOption, type SourcePrismaQuery, type SourceQuery, type SourceRowShape, type SourceSelect, type SourceSpec, type SourceSqlQuery, type SourceValues, type StepRef, type StoredLens, 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 ToPrismaOptions, type ToPrismaResult, type ToSqlOptions, type ToSqlResult, type ValidateRuleOptions, type ValidationIssue, type ValidationResult, ValueShape, type ValueSourceFields, type ValueSourceOf, type WeekStart, type WhereStep, type WindowFields, assertValidFieldMaps, assertValidNarrowing, assertValidRule, bindLens, bindRule, check, coerceRule, composeLens, createLens, describeRule, describeRuleSources, engineGlobals, executePrismaPlan, getAggregateOperators, getArrayOperators, getLensRoot, getOperatorsForKind, getValueShape, indexBridges, listBindings, listLensBindings, materializeSourceQuery, materializeSources, narrowRule, parseScopeRef, projectLens, projectRows, readLensValue, readScopeRef, stitchFieldMaps, storeLens, toLensSelect, toPrisma, toSourceQueries, toSql, validateFieldMaps, validateNarrowing, validateRule, validateRuleInLens, walkLensPath };
1135
+ export { ALL_KINDS, type AggregateMode, type AggregateRule, type All, type Any, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type CheckData, type CheckOptions, type CompileOptions, type Condition, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, type DateOffset, DateOperator, type DateRule, type DateRuleValue, type EdgeExpr, type EngineGlobalsState, type EnumNarrowing, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type FuzzyConfig, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type LensPathHop, type LensPathResolution, LensRefusal, type LensRelationSelect, type LensSelect, type LensSelectOptions, type LensValue, type ListBindingsOptions, type Magnitude, type MaterializeSourceQueryOptions, type ModelDefaultNarrowing, type ModelEntry, type ModelNarrowing, NUMERIC_KINDS, type NarrowingDefaults, type NumberOffset, Operator, type OperatorFamily, type OrderBy, type OrderedRuleValue, type PathProjection, type PeriodExpr, type PeriodUnit, type PrismaProvider, type PrismaStep, type PrismaWhere, type ProjectLensOptions, type ProjectRowsOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Row, type Rule, type RuleDescription, type RuleScalar, type RuleSourceDescription, RuleTarget, type RuleValue, type ScopeOutOfBounds, type ScopeRef, type ScopedRef, type SortDir, type SourceEntry, type SourceOption, type SourcePrismaQuery, type SourceQuery, type SourceRowShape, type SourceSelect, type SourceSpec, type SourceSqlQuery, type SourceValues, type StepRef, type StoredLens, 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 ToPrismaOptions, type ToPrismaResult, type ToSqlOptions, type ToSqlResult, UsageError, type ValidateRuleOptions, type ValidationIssue, type ValidationResult, ValueShape, type ValueSourceFields, type ValueSourceOf, type WeekStart, type WhereStep, type WindowFields, assertValidFieldMaps, assertValidNarrowing, assertValidRule, bindLens, bindRule, check, coerceRule, composeLens, createLens, describeRule, describeRuleSources, engineGlobals, executePrismaPlan, getAggregateOperators, getArrayOperators, getLensRoot, getOperatorsForKind, getValueShape, indexBridges, lensVisit, listBindings, listLensBindings, materializeSourceQuery, materializeSources, narrowRule, parseScopeRef, projectLens, projectRows, readLensValue, readScopeRef, stitchFieldMaps, storeLens, toLensSelect, toPrisma, toSourceQueries, toSql, validateFieldMaps, validateNarrowing, validateRule, validateRuleInLens, walkLensPath };