@inixiative/json-rules 3.4.0 → 3.5.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/README.md +69 -41
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -35
- package/dist/index.d.ts +61 -35
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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
|
|
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>;
|
|
@@ -753,7 +753,7 @@ type ToPrismaOptions = CompileOptions & {
|
|
|
753
753
|
};
|
|
754
754
|
};
|
|
755
755
|
|
|
756
|
-
/** A narrowing the lens refuses to apply: a
|
|
756
|
+
/** A narrowing the lens refuses to apply: a clamp validateNarrowing reports, met at runtime. */
|
|
757
757
|
declare class LensRefusal extends Error {
|
|
758
758
|
readonly code: string;
|
|
759
759
|
name: string;
|
|
@@ -835,20 +835,20 @@ type LensRelationSelect = {
|
|
|
835
835
|
select?: LensSelect;
|
|
836
836
|
where?: PrismaWhere;
|
|
837
837
|
};
|
|
838
|
-
/** What a
|
|
838
|
+
/** What a clamp's compile reads: the clock, never a schema (the lens is it). */
|
|
839
839
|
type LensSelectOptions = Omit<ToPrismaOptions, 'map' | 'mapName' | 'model' | 'lens'>;
|
|
840
|
-
/** `
|
|
840
|
+
/** `keepClampColumns`: keep the columns the lens's `where`s read, though it hides them. The rest is
|
|
841
841
|
* what each `where` is checked with. */
|
|
842
842
|
type ProjectRowsOptions = CheckOptions & {
|
|
843
|
-
|
|
843
|
+
keepClampColumns?: boolean;
|
|
844
844
|
};
|
|
845
845
|
/**
|
|
846
846
|
* Prisma `findMany` args for the rows a lens shows, at its base model: each shown visit's visible
|
|
847
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
|
|
849
|
-
* related rows come pre-narrowed, unless a
|
|
850
|
-
* takes no `where` there), so `projectRows` drops one its
|
|
851
|
-
* query's `where`: `toPrisma(rule, { lens })`. Bridges are not selected. A to-many relation's
|
|
848
|
+
* columns every `where` on the way reads, through any relation. A to-many relation carries its visit's clamps compiled as its `where`, so
|
|
849
|
+
* related rows come pre-narrowed, unless a clamp reads that list (it reads it whole); a to-one relation can't (Prisma
|
|
850
|
+
* takes no `where` there), so `projectRows` drops one its clamp hides. The root's own clamps are the
|
|
851
|
+
* query's `where`: `toPrisma(rule, { lens })`. Bridges are not selected. A to-many relation's clamp
|
|
852
852
|
* that needs a counting step, or has a window toPrisma can't compile, is refused before anything
|
|
853
853
|
* compiles.
|
|
854
854
|
*/
|
|
@@ -858,13 +858,13 @@ declare const toLensSelect: (lensOrNarrowing: Lens | LensNarrowing, options?: Le
|
|
|
858
858
|
/**
|
|
859
859
|
* Rows cut to what a lens shows, recursively from its base model: hidden columns, and relations
|
|
860
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. `
|
|
861
|
+
* 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
862
|
* reads, as those columns alone, so a later `check(narrowRule(rule, lens), row)` re-tests the
|
|
863
|
-
*
|
|
863
|
+
* 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
864
|
* a viewer. The rest of `options` is what each
|
|
865
865
|
* `where` is checked with (`now`, `bindings`). Plain JSON in and out; the input is not mutated.
|
|
866
866
|
*/
|
|
867
|
-
declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], {
|
|
867
|
+
declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], { keepClampColumns, ...options }?: ProjectRowsOptions) => Row[];
|
|
868
868
|
|
|
869
869
|
/** Prisma `select` shape — nested for a grouped source's relation path. */
|
|
870
870
|
type SourceSelect = {
|
|
@@ -899,38 +899,52 @@ type SourceQuery = {
|
|
|
899
899
|
field: string;
|
|
900
900
|
/** Co-selected as each value's display label (from a SourceSpec's `label`): a sibling
|
|
901
901
|
* column, or a dotted to-one path like a groupBy axis — then selected nested in prisma
|
|
902
|
-
* 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. */
|
|
903
904
|
label?: string;
|
|
904
905
|
/** Option-partition axes (from a SourceSpec's `groupBy`, normalized); each axis
|
|
905
|
-
* 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. */
|
|
906
908
|
groupBy?: string[];
|
|
907
909
|
composedWhere: Condition;
|
|
908
|
-
|
|
909
|
-
* bridge: a database holds one side of it only, so no query offers the right set — materialize
|
|
910
|
-
* it with `materializeSources` over rows that hold both sides. */
|
|
911
|
-
prisma: SourcePrismaQuery | null;
|
|
910
|
+
prisma: SourcePrismaQuery;
|
|
912
911
|
sql: SourceSqlQuery;
|
|
912
|
+
/** Present when the source reads across a bridge (its where, a clamp 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;
|
|
913
923
|
};
|
|
914
924
|
/** What a source query's compile reads besides the lens: the clock, as the compilers take it. */
|
|
915
925
|
type SourceQueryOptions = DateConfig;
|
|
916
926
|
/**
|
|
917
927
|
* Compile a DISTINCT(value) query — Prisma and SQL — per sourced field across
|
|
918
928
|
* the projected lens. The WHERE is the field's composed eligibility: the model's
|
|
919
|
-
* own narrowing at that path, the
|
|
929
|
+
* own narrowing at that path, the clamps above it carried down the path, its source
|
|
920
930
|
* where(s), the guards of the relations they cross and any allowed values. A
|
|
921
|
-
* `from: 'mapDefaults'` source reads the model's own source and carries no
|
|
931
|
+
* `from: 'mapDefaults'` source reads the model's own source and carries no clamp from
|
|
922
932
|
* its layer on. The app runs these (with its own client) to materialize each field's
|
|
923
933
|
* option set — feed the fetched rows to `materializeSourceQuery`. `options` is the clock a
|
|
924
934
|
* relative date in the where compiles with (`now` required for one, as for any compile). A
|
|
925
|
-
*
|
|
935
|
+
* source that reads across a bridge gets an over-fetching query and a `recheck` (see
|
|
936
|
+
* `SourceQuery`): its rows are candidates, not options.
|
|
926
937
|
*/
|
|
927
938
|
declare const toSourceQueries: (lensOrNarrowing: Lens | LensNarrowing, options?: SourceQueryOptions) => SourceQuery[];
|
|
928
939
|
|
|
929
940
|
/** Which executor produced the rows — the caller always knows; never guessed. */
|
|
930
941
|
type SourceRowShape = 'prisma' | 'sql';
|
|
931
|
-
/** `rowShape`: how the rows came back — nested Prisma rows (the default) or flat SQL rows.
|
|
932
|
-
|
|
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 & {
|
|
933
946
|
rowShape?: SourceRowShape;
|
|
947
|
+
lens?: Lens | LensNarrowing;
|
|
934
948
|
};
|
|
935
949
|
/**
|
|
936
950
|
* Materialize one compiled `SourceQuery`'s fetched rows into its `SourceValues` —
|
|
@@ -939,6 +953,12 @@ type MaterializeSourceQueryOptions = {
|
|
|
939
953
|
* (and a dotted `label`) as related objects; sql rows carry them flat under the
|
|
940
954
|
* statement's `__group_i` / `__label` aliases. Grouped queries fetch without
|
|
941
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.
|
|
942
962
|
*/
|
|
943
963
|
declare const materializeSourceQuery: (query: SourceQuery, rows: readonly Row[], opts?: MaterializeSourceQueryOptions) => SourceValues;
|
|
944
964
|
|
|
@@ -947,18 +967,17 @@ declare const materializeSourceQuery: (query: SourceQuery, rows: readonly Row[],
|
|
|
947
967
|
* the in-memory executor of `sources` declarations, alongside `toSourceQueries`
|
|
948
968
|
* (which compiles the same declarations to DISTINCT queries for a DB). Rows are
|
|
949
969
|
* the collection the lens fetches — `toLensSelect`'s rows as fetched, or as
|
|
950
|
-
* `projectRows(…, {
|
|
951
|
-
* the sources read, and a row lacking a key a source or a
|
|
952
|
-
* path is walked down the rows, each level's
|
|
953
|
-
* visit's
|
|
970
|
+
* `projectRows(…, { keepClampColumns: true })` keeps them; a viewer's projection drops what
|
|
971
|
+
* the sources read, and a row lacking a key a source or a clamp on its path reads throws. The
|
|
972
|
+
* path is walked down the rows, each level's clamps met, and each row it reaches must meet its
|
|
973
|
+
* visit's clamps, its source `where` narrowed as a rule, the guards of the relations its label
|
|
954
974
|
* and axes cross and any allowed values — evaluated with `check()` (`options`: `now`,
|
|
955
975
|
* `bindings`), so it offers what the database does. Scalar-list fields contribute one option per
|
|
956
976
|
* element, a value takes its least label (a sibling column, or a dotted to-one path read through
|
|
957
977
|
* the nested rows), and sorting is numeric-aware in a fixed locale. Feed the result to
|
|
958
|
-
* `projectLens` as `{ sourceValues }`. A source across a bridge is materialized
|
|
959
|
-
*
|
|
960
|
-
* `from: 'mapDefaults'` source throws
|
|
961
|
-
* unlinked rows.
|
|
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.
|
|
962
981
|
*/
|
|
963
982
|
declare const materializeSources: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], options?: CheckOptions) => SourceValues[];
|
|
964
983
|
|
|
@@ -971,7 +990,7 @@ declare const validateNarrowing: (narrowing: LensNarrowing) => ValidationResult;
|
|
|
971
990
|
/** `validateNarrowing`, throwing its issues. */
|
|
972
991
|
declare const assertValidNarrowing: (narrowing: LensNarrowing) => void;
|
|
973
992
|
|
|
974
|
-
/** A rule with the lens's
|
|
993
|
+
/** A rule with the lens's clamps (`where`s) injected at their anchors: the root's around it, each
|
|
975
994
|
* relation's where the rule descends into it — under an `all`, into its window `filter`. */
|
|
976
995
|
declare const narrowRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
|
|
977
996
|
|
|
@@ -999,9 +1018,9 @@ type LensValue = {
|
|
|
999
1018
|
/**
|
|
1000
1019
|
* One value off a row, as the lens shows it: the path walked as `validateRuleInLens` walks a
|
|
1001
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
|
|
1002
|
-
* its visit's
|
|
1021
|
+
* 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
|
|
1003
1022
|
* properties read, into a Json column too. A path ending on a relation, or crossing a list, names
|
|
1004
|
-
* rows rather than a value and is refused. `options` is what each
|
|
1023
|
+
* rows rather than a value and is refused. `options` is what each clamp is checked with.
|
|
1005
1024
|
*/
|
|
1006
1025
|
declare const readLensValue: (lensOrNarrowing: Lens | LensNarrowing, row: Row, path: string, options?: CheckOptions) => LensValue;
|
|
1007
1026
|
|
|
@@ -1113,4 +1132,11 @@ type ToSqlOptions = CompileOptions & {
|
|
|
1113
1132
|
* base lens. */
|
|
1114
1133
|
declare const toSql: (rule: Condition, compileOptions?: ToSqlOptions) => ToSqlResult;
|
|
1115
1134
|
|
|
1116
|
-
|
|
1135
|
+
/**
|
|
1136
|
+
* Records sorted by an `OrderBy`, the way every rail orders a window: each key in turn, read as an
|
|
1137
|
+
* own-property path, `dir` order, a NULL (or absent) value last in either direction; ties keep their
|
|
1138
|
+
* input order. A new array; the input is not mutated.
|
|
1139
|
+
*/
|
|
1140
|
+
declare const orderRecords: <T>(items: readonly T[], orderBy: OrderBy) => T[];
|
|
1141
|
+
|
|
1142
|
+
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, 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
|
|
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>;
|
|
@@ -753,7 +753,7 @@ type ToPrismaOptions = CompileOptions & {
|
|
|
753
753
|
};
|
|
754
754
|
};
|
|
755
755
|
|
|
756
|
-
/** A narrowing the lens refuses to apply: a
|
|
756
|
+
/** A narrowing the lens refuses to apply: a clamp validateNarrowing reports, met at runtime. */
|
|
757
757
|
declare class LensRefusal extends Error {
|
|
758
758
|
readonly code: string;
|
|
759
759
|
name: string;
|
|
@@ -835,20 +835,20 @@ type LensRelationSelect = {
|
|
|
835
835
|
select?: LensSelect;
|
|
836
836
|
where?: PrismaWhere;
|
|
837
837
|
};
|
|
838
|
-
/** What a
|
|
838
|
+
/** What a clamp's compile reads: the clock, never a schema (the lens is it). */
|
|
839
839
|
type LensSelectOptions = Omit<ToPrismaOptions, 'map' | 'mapName' | 'model' | 'lens'>;
|
|
840
|
-
/** `
|
|
840
|
+
/** `keepClampColumns`: keep the columns the lens's `where`s read, though it hides them. The rest is
|
|
841
841
|
* what each `where` is checked with. */
|
|
842
842
|
type ProjectRowsOptions = CheckOptions & {
|
|
843
|
-
|
|
843
|
+
keepClampColumns?: boolean;
|
|
844
844
|
};
|
|
845
845
|
/**
|
|
846
846
|
* Prisma `findMany` args for the rows a lens shows, at its base model: each shown visit's visible
|
|
847
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
|
|
849
|
-
* related rows come pre-narrowed, unless a
|
|
850
|
-
* takes no `where` there), so `projectRows` drops one its
|
|
851
|
-
* query's `where`: `toPrisma(rule, { lens })`. Bridges are not selected. A to-many relation's
|
|
848
|
+
* columns every `where` on the way reads, through any relation. A to-many relation carries its visit's clamps compiled as its `where`, so
|
|
849
|
+
* related rows come pre-narrowed, unless a clamp reads that list (it reads it whole); a to-one relation can't (Prisma
|
|
850
|
+
* takes no `where` there), so `projectRows` drops one its clamp hides. The root's own clamps are the
|
|
851
|
+
* query's `where`: `toPrisma(rule, { lens })`. Bridges are not selected. A to-many relation's clamp
|
|
852
852
|
* that needs a counting step, or has a window toPrisma can't compile, is refused before anything
|
|
853
853
|
* compiles.
|
|
854
854
|
*/
|
|
@@ -858,13 +858,13 @@ declare const toLensSelect: (lensOrNarrowing: Lens | LensNarrowing, options?: Le
|
|
|
858
858
|
/**
|
|
859
859
|
* Rows cut to what a lens shows, recursively from its base model: hidden columns, and relations
|
|
860
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. `
|
|
861
|
+
* 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
862
|
* reads, as those columns alone, so a later `check(narrowRule(rule, lens), row)` re-tests the
|
|
863
|
-
*
|
|
863
|
+
* 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
864
|
* a viewer. The rest of `options` is what each
|
|
865
865
|
* `where` is checked with (`now`, `bindings`). Plain JSON in and out; the input is not mutated.
|
|
866
866
|
*/
|
|
867
|
-
declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], {
|
|
867
|
+
declare const projectRows: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], { keepClampColumns, ...options }?: ProjectRowsOptions) => Row[];
|
|
868
868
|
|
|
869
869
|
/** Prisma `select` shape — nested for a grouped source's relation path. */
|
|
870
870
|
type SourceSelect = {
|
|
@@ -899,38 +899,52 @@ type SourceQuery = {
|
|
|
899
899
|
field: string;
|
|
900
900
|
/** Co-selected as each value's display label (from a SourceSpec's `label`): a sibling
|
|
901
901
|
* column, or a dotted to-one path like a groupBy axis — then selected nested in prisma
|
|
902
|
-
* 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. */
|
|
903
904
|
label?: string;
|
|
904
905
|
/** Option-partition axes (from a SourceSpec's `groupBy`, normalized); each axis
|
|
905
|
-
* 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. */
|
|
906
908
|
groupBy?: string[];
|
|
907
909
|
composedWhere: Condition;
|
|
908
|
-
|
|
909
|
-
* bridge: a database holds one side of it only, so no query offers the right set — materialize
|
|
910
|
-
* it with `materializeSources` over rows that hold both sides. */
|
|
911
|
-
prisma: SourcePrismaQuery | null;
|
|
910
|
+
prisma: SourcePrismaQuery;
|
|
912
911
|
sql: SourceSqlQuery;
|
|
912
|
+
/** Present when the source reads across a bridge (its where, a clamp 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;
|
|
913
923
|
};
|
|
914
924
|
/** What a source query's compile reads besides the lens: the clock, as the compilers take it. */
|
|
915
925
|
type SourceQueryOptions = DateConfig;
|
|
916
926
|
/**
|
|
917
927
|
* Compile a DISTINCT(value) query — Prisma and SQL — per sourced field across
|
|
918
928
|
* the projected lens. The WHERE is the field's composed eligibility: the model's
|
|
919
|
-
* own narrowing at that path, the
|
|
929
|
+
* own narrowing at that path, the clamps above it carried down the path, its source
|
|
920
930
|
* where(s), the guards of the relations they cross and any allowed values. A
|
|
921
|
-
* `from: 'mapDefaults'` source reads the model's own source and carries no
|
|
931
|
+
* `from: 'mapDefaults'` source reads the model's own source and carries no clamp from
|
|
922
932
|
* its layer on. The app runs these (with its own client) to materialize each field's
|
|
923
933
|
* option set — feed the fetched rows to `materializeSourceQuery`. `options` is the clock a
|
|
924
934
|
* relative date in the where compiles with (`now` required for one, as for any compile). A
|
|
925
|
-
*
|
|
935
|
+
* source that reads across a bridge gets an over-fetching query and a `recheck` (see
|
|
936
|
+
* `SourceQuery`): its rows are candidates, not options.
|
|
926
937
|
*/
|
|
927
938
|
declare const toSourceQueries: (lensOrNarrowing: Lens | LensNarrowing, options?: SourceQueryOptions) => SourceQuery[];
|
|
928
939
|
|
|
929
940
|
/** Which executor produced the rows — the caller always knows; never guessed. */
|
|
930
941
|
type SourceRowShape = 'prisma' | 'sql';
|
|
931
|
-
/** `rowShape`: how the rows came back — nested Prisma rows (the default) or flat SQL rows.
|
|
932
|
-
|
|
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 & {
|
|
933
946
|
rowShape?: SourceRowShape;
|
|
947
|
+
lens?: Lens | LensNarrowing;
|
|
934
948
|
};
|
|
935
949
|
/**
|
|
936
950
|
* Materialize one compiled `SourceQuery`'s fetched rows into its `SourceValues` —
|
|
@@ -939,6 +953,12 @@ type MaterializeSourceQueryOptions = {
|
|
|
939
953
|
* (and a dotted `label`) as related objects; sql rows carry them flat under the
|
|
940
954
|
* statement's `__group_i` / `__label` aliases. Grouped queries fetch without
|
|
941
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.
|
|
942
962
|
*/
|
|
943
963
|
declare const materializeSourceQuery: (query: SourceQuery, rows: readonly Row[], opts?: MaterializeSourceQueryOptions) => SourceValues;
|
|
944
964
|
|
|
@@ -947,18 +967,17 @@ declare const materializeSourceQuery: (query: SourceQuery, rows: readonly Row[],
|
|
|
947
967
|
* the in-memory executor of `sources` declarations, alongside `toSourceQueries`
|
|
948
968
|
* (which compiles the same declarations to DISTINCT queries for a DB). Rows are
|
|
949
969
|
* the collection the lens fetches — `toLensSelect`'s rows as fetched, or as
|
|
950
|
-
* `projectRows(…, {
|
|
951
|
-
* the sources read, and a row lacking a key a source or a
|
|
952
|
-
* path is walked down the rows, each level's
|
|
953
|
-
* visit's
|
|
970
|
+
* `projectRows(…, { keepClampColumns: true })` keeps them; a viewer's projection drops what
|
|
971
|
+
* the sources read, and a row lacking a key a source or a clamp on its path reads throws. The
|
|
972
|
+
* path is walked down the rows, each level's clamps met, and each row it reaches must meet its
|
|
973
|
+
* visit's clamps, its source `where` narrowed as a rule, the guards of the relations its label
|
|
954
974
|
* and axes cross and any allowed values — evaluated with `check()` (`options`: `now`,
|
|
955
975
|
* `bindings`), so it offers what the database does. Scalar-list fields contribute one option per
|
|
956
976
|
* element, a value takes its least label (a sibling column, or a dotted to-one path read through
|
|
957
977
|
* the nested rows), and sorting is numeric-aware in a fixed locale. Feed the result to
|
|
958
|
-
* `projectLens` as `{ sourceValues }`. A source across a bridge is materialized
|
|
959
|
-
*
|
|
960
|
-
* `from: 'mapDefaults'` source throws
|
|
961
|
-
* unlinked rows.
|
|
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.
|
|
962
981
|
*/
|
|
963
982
|
declare const materializeSources: (lensOrNarrowing: Lens | LensNarrowing, rows: readonly Row[], options?: CheckOptions) => SourceValues[];
|
|
964
983
|
|
|
@@ -971,7 +990,7 @@ declare const validateNarrowing: (narrowing: LensNarrowing) => ValidationResult;
|
|
|
971
990
|
/** `validateNarrowing`, throwing its issues. */
|
|
972
991
|
declare const assertValidNarrowing: (narrowing: LensNarrowing) => void;
|
|
973
992
|
|
|
974
|
-
/** A rule with the lens's
|
|
993
|
+
/** A rule with the lens's clamps (`where`s) injected at their anchors: the root's around it, each
|
|
975
994
|
* relation's where the rule descends into it — under an `all`, into its window `filter`. */
|
|
976
995
|
declare const narrowRule: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
|
|
977
996
|
|
|
@@ -999,9 +1018,9 @@ type LensValue = {
|
|
|
999
1018
|
/**
|
|
1000
1019
|
* One value off a row, as the lens shows it: the path walked as `validateRuleInLens` walks a
|
|
1001
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
|
|
1002
|
-
* its visit's
|
|
1021
|
+
* 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
|
|
1003
1022
|
* properties read, into a Json column too. A path ending on a relation, or crossing a list, names
|
|
1004
|
-
* rows rather than a value and is refused. `options` is what each
|
|
1023
|
+
* rows rather than a value and is refused. `options` is what each clamp is checked with.
|
|
1005
1024
|
*/
|
|
1006
1025
|
declare const readLensValue: (lensOrNarrowing: Lens | LensNarrowing, row: Row, path: string, options?: CheckOptions) => LensValue;
|
|
1007
1026
|
|
|
@@ -1113,4 +1132,11 @@ type ToSqlOptions = CompileOptions & {
|
|
|
1113
1132
|
* base lens. */
|
|
1114
1133
|
declare const toSql: (rule: Condition, compileOptions?: ToSqlOptions) => ToSqlResult;
|
|
1115
1134
|
|
|
1116
|
-
|
|
1135
|
+
/**
|
|
1136
|
+
* Records sorted by an `OrderBy`, the way every rail orders a window: each key in turn, read as an
|
|
1137
|
+
* own-property path, `dir` order, a NULL (or absent) value last in either direction; ties keep their
|
|
1138
|
+
* input order. A new array; the input is not mutated.
|
|
1139
|
+
*/
|
|
1140
|
+
declare const orderRecords: <T>(items: readonly T[], orderBy: OrderBy) => T[];
|
|
1141
|
+
|
|
1142
|
+
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, orderRecords, parseScopeRef, projectLens, projectRows, readLensValue, readScopeRef, stitchFieldMaps, storeLens, toLensSelect, toPrisma, toSourceQueries, toSql, validateFieldMaps, validateNarrowing, validateRule, validateRuleInLens, walkLensPath };
|