@inixiative/json-rules 3.4.1 → 3.5.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
@@ -183,7 +183,7 @@ type ModelDefaultNarrowing = {
183
183
  * that hop's narrowing (`where`, `picks`/`omits` of the target's columns, further `relations`).
184
184
  * Only the first narrowing over the base lens turns a relation on; a later layer may only narrow
185
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
186
+ * once, at its nearest reach; reach it another way by spelling the path under `root`. The first narrowing's clamps (`where`) may read any
187
187
  * relation; a later layer's only what its parent shows.
188
188
  */
189
189
  relations?: Record<string, ModelNarrowing>;
@@ -651,6 +651,24 @@ declare const bindLens: <T extends Lens | LensNarrowing>(lensOrNarrowing: T, bin
651
651
  /** The base lens a narrowing chain is rooted at; a lens is its own. Throws on a cyclic chain. */
652
652
  declare const getLensRoot: (x: Lens | LensNarrowing) => Lens;
653
653
 
654
+ type Clamps = Pick<ModelDefaultNarrowing, 'where' | 'sources'>;
655
+ /** Clamps for {@link clampLens}: a `root` where, and per-map model-default wheres and
656
+ * source wheres. */
657
+ type LensClamps = {
658
+ root?: Pick<ModelDefaultNarrowing, 'where'>;
659
+ mapDefaults?: Record<string, {
660
+ models: Record<string, Clamps>;
661
+ }>;
662
+ };
663
+ /**
664
+ * The lens with `clamps` ANDed into its first narrowing over the base lens (one is added over a
665
+ * bare lens). A clamp that reads what a later layer hides belongs there: only the first layer's
666
+ * clamps read the whole schema. A `where` ANDs with the one in place; a source's `where` ANDs
667
+ * and its `label` / `groupBy` win. Wheres only narrow; a source clamp can add an option set for
668
+ * a field, or relabel or regroup one, but never widens what rows or columns the lens shows.
669
+ */
670
+ declare const clampLens: (lens: Lens | LensNarrowing, clamps: LensClamps) => LensNarrowing;
671
+
654
672
  /** Stamp `coerceType` onto every field rule from the lens's field map: the rule carries its
655
673
  * coercion; `check()` never infers types from values. A relation node's condition / filter stamp
656
674
  * against the relation's model; below a Json boundary the kind is undeclared, so nothing is
@@ -753,7 +771,7 @@ type ToPrismaOptions = CompileOptions & {
753
771
  };
754
772
  };
755
773
 
756
- /** A narrowing the lens refuses to apply: a grant validateNarrowing reports, met at runtime. */
774
+ /** A narrowing the lens refuses to apply: a clamp validateNarrowing reports, met at runtime. */
757
775
  declare class LensRefusal extends Error {
758
776
  readonly code: string;
759
777
  name: string;
@@ -835,20 +853,20 @@ type LensRelationSelect = {
835
853
  select?: LensSelect;
836
854
  where?: PrismaWhere;
837
855
  };
838
- /** What a grant's compile reads: the clock, never a schema (the lens is it). */
856
+ /** What a clamp's compile reads: the clock, never a schema (the lens is it). */
839
857
  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
858
+ /** `keepClampColumns`: keep the columns the lens's `where`s read, though it hides them. The rest is
841
859
  * what each `where` is checked with. */
842
860
  type ProjectRowsOptions = CheckOptions & {
843
- keepGrantColumns?: boolean;
861
+ keepClampColumns?: boolean;
844
862
  };
845
863
  /**
846
864
  * Prisma `findMany` args for the rows a lens shows, at its base model: each shown visit's visible
847
865
  * 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
866
+ * columns every `where` on the way reads, through any relation. A to-many relation carries its visit's clamps compiled as its `where`, so
867
+ * related rows come pre-narrowed, unless a clamp reads that list (it reads it whole); a to-one relation can't (Prisma
868
+ * takes no `where` there), so `projectRows` drops one its clamp hides. The root's own clamps are the
869
+ * query's `where`: `toPrisma(rule, { lens })`. Bridges are not selected. A to-many relation's clamp
852
870
  * that needs a counting step, or has a window toPrisma can't compile, is refused before anything
853
871
  * compiles.
854
872
  */
@@ -858,13 +876,13 @@ declare const toLensSelect: (lensOrNarrowing: Lens | LensNarrowing, options?: Le
858
876
  /**
859
877
  * Rows cut to what a lens shows, recursively from its base model: hidden columns, and relations
860
878
  * 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
879
+ * null. `keepClampColumns` 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 clamp
862
880
  * 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
881
+ * clamps as the database does for any rule the lens admits. Its output carries hidden values: it's for that re-check, never for
864
882
  * a viewer. The rest of `options` is what each
865
883
  * `where` is checked with (`now`, `bindings`). Plain JSON in and out; the input is not mutated.
866
884
  */
867
- declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], { keepGrantColumns, ...options }?: ProjectRowsOptions) => Row[];
885
+ declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], { keepClampColumns, ...options }?: ProjectRowsOptions) => Row[];
868
886
 
869
887
  /** Prisma `select` shape — nested for a grouped source's relation path. */
870
888
  type SourceSelect = {
@@ -881,7 +899,8 @@ type SourcePrismaQuery = {
881
899
  distinct?: string[];
882
900
  select: SourceSelect;
883
901
  where: PrismaWhere;
884
- /** Present only if the composed where used count operators (run via executePrismaPlan). */
902
+ /** Present when the where needs `executePrismaPlan`: a count step, or a column reference to
903
+ * resolve. Run `executePrismaPlan({ steps }, prisma)` and query with the where it returns. */
885
904
  steps?: PrismaStep[];
886
905
  };
887
906
  /** `sql` is null when the composed where uses a predicate SQL can't express
@@ -909,7 +928,7 @@ type SourceQuery = {
909
928
  composedWhere: Condition;
910
929
  prisma: SourcePrismaQuery;
911
930
  sql: SourceSqlQuery;
912
- /** Present when the source reads across a bridge (its where, a grant carried across one, its
931
+ /** Present when the source reads across a bridge (its where, a clamp carried across one, its
913
932
  * label or an axis); absent otherwise. **If `recheck` is present, the query's rows are
914
933
  * candidates, not options:** a database holds one side of a bridge, so the query folds what
915
934
  * reads across it to TRUE and over-fetches — it never misses an option, but may return more.
@@ -926,9 +945,9 @@ type SourceQueryOptions = DateConfig;
926
945
  /**
927
946
  * Compile a DISTINCT(value) query — Prisma and SQL — per sourced field across
928
947
  * the projected lens. The WHERE is the field's composed eligibility: the model's
929
- * own narrowing at that path, the grants above it carried down the path, its source
948
+ * own narrowing at that path, the clamps above it carried down the path, its source
930
949
  * where(s), the guards of the relations they cross and any allowed values. A
931
- * `from: 'mapDefaults'` source reads the model's own source and carries no grant from
950
+ * `from: 'mapDefaults'` source reads the model's own source and carries no clamp from
932
951
  * its layer on. The app runs these (with its own client) to materialize each field's
933
952
  * option set — feed the fetched rows to `materializeSourceQuery`. `options` is the clock a
934
953
  * relative date in the where compiles with (`now` required for one, as for any compile). A
@@ -967,10 +986,10 @@ declare const materializeSourceQuery: (query: SourceQuery, rows: readonly Row[],
967
986
  * the in-memory executor of `sources` declarations, alongside `toSourceQueries`
968
987
  * (which compiles the same declarations to DISTINCT queries for a DB). Rows are
969
988
  * 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
989
+ * `projectRows(…, { keepClampColumns: true })` keeps them; a viewer's projection drops what
990
+ * the sources read, and a row lacking a key a source or a clamp on its path reads throws. The
991
+ * path is walked down the rows, each level's clamps met, and each row it reaches must meet its
992
+ * visit's clamps, its source `where` narrowed as a rule, the guards of the relations its label
974
993
  * and axes cross and any allowed values — evaluated with `check()` (`options`: `now`,
975
994
  * `bindings`), so it offers what the database does. Scalar-list fields contribute one option per
976
995
  * element, a value takes its least label (a sibling column, or a dotted to-one path read through
@@ -990,7 +1009,7 @@ declare const validateNarrowing: (narrowing: LensNarrowing) => ValidationResult;
990
1009
  /** `validateNarrowing`, throwing its issues. */
991
1010
  declare const assertValidNarrowing: (narrowing: LensNarrowing) => void;
992
1011
 
993
- /** A rule with the lens's grants (`where`s) injected at their anchors: the root's around it, each
1012
+ /** A rule with the lens's clamps (`where`s) injected at their anchors: the root's around it, each
994
1013
  * relation's where the rule descends into it — under an `all`, into its window `filter`. */
995
1014
  declare const narrowRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
996
1015
 
@@ -1018,9 +1037,9 @@ type LensValue = {
1018
1037
  /**
1019
1038
  * One value off a row, as the lens shows it: the path walked as `validateRuleInLens` walks a
1020
1039
  * 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
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
1040
+ * its visit's clamps, the row itself included (a row a clamp hides, or a missing one, reads `null`), and only the row's own
1022
1041
  * properties read, into a Json column too. A path ending on a relation, or crossing a list, names
1023
- * rows rather than a value and is refused. `options` is what each grant is checked with.
1042
+ * rows rather than a value and is refused. `options` is what each clamp is checked with.
1024
1043
  */
1025
1044
  declare const readLensValue: (lensOrNarrowing: Lens | LensNarrowing, row: Row, path: string, options?: CheckOptions) => LensValue;
1026
1045
 
@@ -1132,4 +1151,11 @@ type ToSqlOptions = CompileOptions & {
1132
1151
  * base lens. */
1133
1152
  declare const toSql: (rule: Condition, compileOptions?: ToSqlOptions) => ToSqlResult;
1134
1153
 
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 };
1154
+ /**
1155
+ * Records sorted by an `OrderBy`, the way every rail orders a window: each key in turn, read as an
1156
+ * own-property path, `dir` order, a NULL (or absent) value last in either direction; ties keep their
1157
+ * input order. A new array; the input is not mutated.
1158
+ */
1159
+ declare const orderRecords: <T>(items: readonly T[], orderBy: OrderBy) => T[];
1160
+
1161
+ 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 LensClamps, 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, clampLens, coerceRule, composeLens, createLens, describeRule, describeRuleSources, engineGlobals, executePrismaPlan, getAggregateOperators, getArrayOperators, getLensRoot, getOperatorsForKind, getValueShape, indexBridges, lensVisit, listBindings, listLensBindings, materializeSourceQuery, materializeSources, narrowRule, orderRecords, parseScopeRef, projectLens, projectRows, readLensValue, readScopeRef, stitchFieldMaps, storeLens, toLensSelect, toPrisma, toSourceQueries, toSql, validateFieldMaps, validateNarrowing, validateRule, validateRuleInLens, walkLensPath };
package/dist/index.d.ts CHANGED
@@ -183,7 +183,7 @@ type ModelDefaultNarrowing = {
183
183
  * that hop's narrowing (`where`, `picks`/`omits` of the target's columns, further `relations`).
184
184
  * Only the first narrowing over the base lens turns a relation on; a later layer may only narrow
185
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
186
+ * once, at its nearest reach; reach it another way by spelling the path under `root`. The first narrowing's clamps (`where`) may read any
187
187
  * relation; a later layer's only what its parent shows.
188
188
  */
189
189
  relations?: Record<string, ModelNarrowing>;
@@ -651,6 +651,24 @@ declare const bindLens: <T extends Lens | LensNarrowing>(lensOrNarrowing: T, bin
651
651
  /** The base lens a narrowing chain is rooted at; a lens is its own. Throws on a cyclic chain. */
652
652
  declare const getLensRoot: (x: Lens | LensNarrowing) => Lens;
653
653
 
654
+ type Clamps = Pick<ModelDefaultNarrowing, 'where' | 'sources'>;
655
+ /** Clamps for {@link clampLens}: a `root` where, and per-map model-default wheres and
656
+ * source wheres. */
657
+ type LensClamps = {
658
+ root?: Pick<ModelDefaultNarrowing, 'where'>;
659
+ mapDefaults?: Record<string, {
660
+ models: Record<string, Clamps>;
661
+ }>;
662
+ };
663
+ /**
664
+ * The lens with `clamps` ANDed into its first narrowing over the base lens (one is added over a
665
+ * bare lens). A clamp that reads what a later layer hides belongs there: only the first layer's
666
+ * clamps read the whole schema. A `where` ANDs with the one in place; a source's `where` ANDs
667
+ * and its `label` / `groupBy` win. Wheres only narrow; a source clamp can add an option set for
668
+ * a field, or relabel or regroup one, but never widens what rows or columns the lens shows.
669
+ */
670
+ declare const clampLens: (lens: Lens | LensNarrowing, clamps: LensClamps) => LensNarrowing;
671
+
654
672
  /** Stamp `coerceType` onto every field rule from the lens's field map: the rule carries its
655
673
  * coercion; `check()` never infers types from values. A relation node's condition / filter stamp
656
674
  * against the relation's model; below a Json boundary the kind is undeclared, so nothing is
@@ -753,7 +771,7 @@ type ToPrismaOptions = CompileOptions & {
753
771
  };
754
772
  };
755
773
 
756
- /** A narrowing the lens refuses to apply: a grant validateNarrowing reports, met at runtime. */
774
+ /** A narrowing the lens refuses to apply: a clamp validateNarrowing reports, met at runtime. */
757
775
  declare class LensRefusal extends Error {
758
776
  readonly code: string;
759
777
  name: string;
@@ -835,20 +853,20 @@ type LensRelationSelect = {
835
853
  select?: LensSelect;
836
854
  where?: PrismaWhere;
837
855
  };
838
- /** What a grant's compile reads: the clock, never a schema (the lens is it). */
856
+ /** What a clamp's compile reads: the clock, never a schema (the lens is it). */
839
857
  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
858
+ /** `keepClampColumns`: keep the columns the lens's `where`s read, though it hides them. The rest is
841
859
  * what each `where` is checked with. */
842
860
  type ProjectRowsOptions = CheckOptions & {
843
- keepGrantColumns?: boolean;
861
+ keepClampColumns?: boolean;
844
862
  };
845
863
  /**
846
864
  * Prisma `findMany` args for the rows a lens shows, at its base model: each shown visit's visible
847
865
  * 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
866
+ * columns every `where` on the way reads, through any relation. A to-many relation carries its visit's clamps compiled as its `where`, so
867
+ * related rows come pre-narrowed, unless a clamp reads that list (it reads it whole); a to-one relation can't (Prisma
868
+ * takes no `where` there), so `projectRows` drops one its clamp hides. The root's own clamps are the
869
+ * query's `where`: `toPrisma(rule, { lens })`. Bridges are not selected. A to-many relation's clamp
852
870
  * that needs a counting step, or has a window toPrisma can't compile, is refused before anything
853
871
  * compiles.
854
872
  */
@@ -858,13 +876,13 @@ declare const toLensSelect: (lensOrNarrowing: Lens | LensNarrowing, options?: Le
858
876
  /**
859
877
  * Rows cut to what a lens shows, recursively from its base model: hidden columns, and relations
860
878
  * 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
879
+ * null. `keepClampColumns` 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 clamp
862
880
  * 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
881
+ * clamps as the database does for any rule the lens admits. Its output carries hidden values: it's for that re-check, never for
864
882
  * a viewer. The rest of `options` is what each
865
883
  * `where` is checked with (`now`, `bindings`). Plain JSON in and out; the input is not mutated.
866
884
  */
867
- declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], { keepGrantColumns, ...options }?: ProjectRowsOptions) => Row[];
885
+ declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], { keepClampColumns, ...options }?: ProjectRowsOptions) => Row[];
868
886
 
869
887
  /** Prisma `select` shape — nested for a grouped source's relation path. */
870
888
  type SourceSelect = {
@@ -881,7 +899,8 @@ type SourcePrismaQuery = {
881
899
  distinct?: string[];
882
900
  select: SourceSelect;
883
901
  where: PrismaWhere;
884
- /** Present only if the composed where used count operators (run via executePrismaPlan). */
902
+ /** Present when the where needs `executePrismaPlan`: a count step, or a column reference to
903
+ * resolve. Run `executePrismaPlan({ steps }, prisma)` and query with the where it returns. */
885
904
  steps?: PrismaStep[];
886
905
  };
887
906
  /** `sql` is null when the composed where uses a predicate SQL can't express
@@ -909,7 +928,7 @@ type SourceQuery = {
909
928
  composedWhere: Condition;
910
929
  prisma: SourcePrismaQuery;
911
930
  sql: SourceSqlQuery;
912
- /** Present when the source reads across a bridge (its where, a grant carried across one, its
931
+ /** Present when the source reads across a bridge (its where, a clamp carried across one, its
913
932
  * label or an axis); absent otherwise. **If `recheck` is present, the query's rows are
914
933
  * candidates, not options:** a database holds one side of a bridge, so the query folds what
915
934
  * reads across it to TRUE and over-fetches — it never misses an option, but may return more.
@@ -926,9 +945,9 @@ type SourceQueryOptions = DateConfig;
926
945
  /**
927
946
  * Compile a DISTINCT(value) query — Prisma and SQL — per sourced field across
928
947
  * the projected lens. The WHERE is the field's composed eligibility: the model's
929
- * own narrowing at that path, the grants above it carried down the path, its source
948
+ * own narrowing at that path, the clamps above it carried down the path, its source
930
949
  * where(s), the guards of the relations they cross and any allowed values. A
931
- * `from: 'mapDefaults'` source reads the model's own source and carries no grant from
950
+ * `from: 'mapDefaults'` source reads the model's own source and carries no clamp from
932
951
  * its layer on. The app runs these (with its own client) to materialize each field's
933
952
  * option set — feed the fetched rows to `materializeSourceQuery`. `options` is the clock a
934
953
  * relative date in the where compiles with (`now` required for one, as for any compile). A
@@ -967,10 +986,10 @@ declare const materializeSourceQuery: (query: SourceQuery, rows: readonly Row[],
967
986
  * the in-memory executor of `sources` declarations, alongside `toSourceQueries`
968
987
  * (which compiles the same declarations to DISTINCT queries for a DB). Rows are
969
988
  * 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
989
+ * `projectRows(…, { keepClampColumns: true })` keeps them; a viewer's projection drops what
990
+ * the sources read, and a row lacking a key a source or a clamp on its path reads throws. The
991
+ * path is walked down the rows, each level's clamps met, and each row it reaches must meet its
992
+ * visit's clamps, its source `where` narrowed as a rule, the guards of the relations its label
974
993
  * and axes cross and any allowed values — evaluated with `check()` (`options`: `now`,
975
994
  * `bindings`), so it offers what the database does. Scalar-list fields contribute one option per
976
995
  * element, a value takes its least label (a sibling column, or a dotted to-one path read through
@@ -990,7 +1009,7 @@ declare const validateNarrowing: (narrowing: LensNarrowing) => ValidationResult;
990
1009
  /** `validateNarrowing`, throwing its issues. */
991
1010
  declare const assertValidNarrowing: (narrowing: LensNarrowing) => void;
992
1011
 
993
- /** A rule with the lens's grants (`where`s) injected at their anchors: the root's around it, each
1012
+ /** A rule with the lens's clamps (`where`s) injected at their anchors: the root's around it, each
994
1013
  * relation's where the rule descends into it — under an `all`, into its window `filter`. */
995
1014
  declare const narrowRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
996
1015
 
@@ -1018,9 +1037,9 @@ type LensValue = {
1018
1037
  /**
1019
1038
  * One value off a row, as the lens shows it: the path walked as `validateRuleInLens` walks a
1020
1039
  * 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
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
1040
+ * its visit's clamps, the row itself included (a row a clamp hides, or a missing one, reads `null`), and only the row's own
1022
1041
  * properties read, into a Json column too. A path ending on a relation, or crossing a list, names
1023
- * rows rather than a value and is refused. `options` is what each grant is checked with.
1042
+ * rows rather than a value and is refused. `options` is what each clamp is checked with.
1024
1043
  */
1025
1044
  declare const readLensValue: (lensOrNarrowing: Lens | LensNarrowing, row: Row, path: string, options?: CheckOptions) => LensValue;
1026
1045
 
@@ -1132,4 +1151,11 @@ type ToSqlOptions = CompileOptions & {
1132
1151
  * base lens. */
1133
1152
  declare const toSql: (rule: Condition, compileOptions?: ToSqlOptions) => ToSqlResult;
1134
1153
 
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 };
1154
+ /**
1155
+ * Records sorted by an `OrderBy`, the way every rail orders a window: each key in turn, read as an
1156
+ * own-property path, `dir` order, a NULL (or absent) value last in either direction; ties keep their
1157
+ * input order. A new array; the input is not mutated.
1158
+ */
1159
+ declare const orderRecords: <T>(items: readonly T[], orderBy: OrderBy) => T[];
1160
+
1161
+ 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 LensClamps, 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, clampLens, coerceRule, composeLens, createLens, describeRule, describeRuleSources, engineGlobals, executePrismaPlan, getAggregateOperators, getArrayOperators, getLensRoot, getOperatorsForKind, getValueShape, indexBridges, lensVisit, listBindings, listLensBindings, materializeSourceQuery, materializeSources, narrowRule, orderRecords, parseScopeRef, projectLens, projectRows, readLensValue, readScopeRef, stitchFieldMaps, storeLens, toLensSelect, toPrisma, toSourceQueries, toSql, validateFieldMaps, validateNarrowing, validateRule, validateRuleInLens, walkLensPath };