@inixiative/json-rules 4.1.0 → 4.3.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 +31 -7
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +204 -51
- package/dist/index.d.ts +204 -51
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ModelEntry, FieldEntry, FieldMap, ScalarPath, RelationPath, RelationPathTarget, ScalarFieldNameOf, RelationFieldNameOf, RelationTargetOf } from '@inixiative/field-map';
|
|
2
|
+
|
|
1
3
|
declare const Operator: {
|
|
2
4
|
readonly equals: "equals";
|
|
3
5
|
readonly notEquals: "notEquals";
|
|
@@ -58,61 +60,70 @@ type SourceOption = {
|
|
|
58
60
|
label?: string;
|
|
59
61
|
groups?: string[];
|
|
60
62
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
fromFields?: string[];
|
|
72
|
-
toFields?: string[];
|
|
73
|
-
relationName?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Per-field allowed values, primarily for enum fields. Takes precedence over
|
|
76
|
-
* `FieldMap.enums[type]` if both are set. Pass-through from codegen
|
|
77
|
-
* (e.g. prisma-map's `EnumField.values`). Consumed by `validateRuleInLens`.
|
|
78
|
-
*/
|
|
79
|
-
values?: readonly string[];
|
|
63
|
+
/** A relation across sources that `stitchFieldMaps` adds to each bridge endpoint's model, named
|
|
64
|
+
* after the other endpoint (`<fieldMap>:<Model>`). */
|
|
65
|
+
type BridgeEntry = {
|
|
66
|
+
readonly kind: 'bridge';
|
|
67
|
+
readonly type: string;
|
|
68
|
+
readonly isList?: boolean;
|
|
69
|
+
readonly isRequired?: boolean;
|
|
70
|
+
};
|
|
71
|
+
/** What projection and surface output add to a field. */
|
|
72
|
+
type ProjectedFields = {
|
|
80
73
|
/**
|
|
81
74
|
* A field's selectable option set as `{ value, label? }` pairs — the display
|
|
82
75
|
* shape a picker consumes. On projection/surface output this is populated for
|
|
83
76
|
* every value-gated field (enum members normalized to `{ value, label: value }`)
|
|
84
77
|
* and for sourced fields (the fetched pairs from a materialized `SourceValues`).
|
|
85
78
|
*/
|
|
86
|
-
options?: readonly SourceOption[];
|
|
79
|
+
readonly options?: readonly SourceOption[];
|
|
87
80
|
/**
|
|
88
81
|
* Present on projection/surface output when the field's source partitions its
|
|
89
82
|
* options: the dotted to-one axes (relative to this model) whose values are
|
|
90
83
|
* each option's `groups`, index-aligned.
|
|
91
84
|
*/
|
|
92
|
-
groupBy?: readonly string[];
|
|
93
|
-
};
|
|
94
|
-
type
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
readonly groupBy?: readonly string[];
|
|
86
|
+
};
|
|
87
|
+
type ReadableFields = {
|
|
88
|
+
readonly values?: readonly string[];
|
|
89
|
+
readonly fromFields?: readonly string[];
|
|
90
|
+
readonly toFields?: readonly string[];
|
|
91
|
+
readonly relationName?: string;
|
|
92
|
+
};
|
|
93
|
+
/** A field as a lens reads it: a schema field (`@inixiative/field-map`), or a bridge
|
|
94
|
+
* `stitchFieldMaps` added, with what a projection adds. */
|
|
95
|
+
type FieldMapEntry = (FieldEntry | BridgeEntry) & ProjectedFields & ReadableFields;
|
|
96
|
+
/** A model as a lens reads it. */
|
|
97
|
+
type LensModelEntry = Omit<ModelEntry, 'fields'> & {
|
|
98
|
+
readonly fields: {
|
|
99
|
+
readonly [field: string]: FieldMapEntry;
|
|
100
|
+
};
|
|
97
101
|
};
|
|
98
102
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* carries its own enums so namespaces don't collide
|
|
103
|
+
* The field map a lens reads: a schema map (`@inixiative/field-map`'s `FieldMap`, which is one),
|
|
104
|
+
* with its bridges stitched in and, on projection output, its options. In multi-source setups
|
|
105
|
+
* (Prisma + Salesforce + CRM) each map carries its own enums, so namespaces don't collide.
|
|
102
106
|
*/
|
|
103
|
-
type
|
|
104
|
-
models:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
type LensFieldMap = {
|
|
108
|
+
readonly models: {
|
|
109
|
+
readonly [model: string]: LensModelEntry;
|
|
110
|
+
};
|
|
111
|
+
readonly enums?: {
|
|
112
|
+
readonly [enumName: string]: readonly string[];
|
|
113
|
+
};
|
|
107
114
|
};
|
|
115
|
+
/** One end of a bridge: a model of a map, named `map:Model` (`endpointKey`). */
|
|
108
116
|
type BridgeEndpoint = {
|
|
109
117
|
fieldMap: string;
|
|
110
118
|
model: string;
|
|
119
|
+
};
|
|
120
|
+
/** One end of a joined bridge: the endpoint and the field its rows join on. */
|
|
121
|
+
type JoinedBridgeEndpoint = BridgeEndpoint & {
|
|
111
122
|
on: string;
|
|
112
123
|
};
|
|
113
124
|
type BridgeCardinality = 'oneToOne' | 'oneToMany';
|
|
114
125
|
/**
|
|
115
|
-
* A cross-source edge
|
|
126
|
+
* A cross-source edge joined on a field of each side.
|
|
116
127
|
*
|
|
117
128
|
* Endpoint ordering convention for `oneToMany`:
|
|
118
129
|
* - `endpoints[0]` is the "one" side — its `on` field must be unique per row
|
|
@@ -126,12 +137,22 @@ type BridgeCardinality = 'oneToOne' | 'oneToMany';
|
|
|
126
137
|
*
|
|
127
138
|
* For `oneToOne`, both `on` fields must be unique; endpoint order is symmetric.
|
|
128
139
|
*/
|
|
129
|
-
type
|
|
130
|
-
endpoints: [
|
|
140
|
+
type JoinedBridge = {
|
|
141
|
+
endpoints: [JoinedBridgeEndpoint, JoinedBridgeEndpoint];
|
|
131
142
|
cardinality: BridgeCardinality;
|
|
132
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* A cross-source edge with no join: the caller supplies the far row on the record under its
|
|
146
|
+
* endpoint key (`map:Model`), as it would after `indexBridges` for a joined one. For data that is
|
|
147
|
+
* not found by a key, such as who is acting. One row each way.
|
|
148
|
+
*/
|
|
149
|
+
type SuppliedBridge = {
|
|
150
|
+
endpoints: [BridgeEndpoint, BridgeEndpoint];
|
|
151
|
+
cardinality: 'oneToOne';
|
|
152
|
+
};
|
|
153
|
+
type Bridge = JoinedBridge | SuppliedBridge;
|
|
133
154
|
type FieldMapSet = {
|
|
134
|
-
maps: Record<string,
|
|
155
|
+
maps: Record<string, LensFieldMap>;
|
|
135
156
|
bridges?: Bridge[];
|
|
136
157
|
};
|
|
137
158
|
|
|
@@ -292,12 +313,27 @@ type OperatorFamily = 'field' | 'date' | 'array';
|
|
|
292
313
|
* Throws on an operator the family doesn't have. */
|
|
293
314
|
declare const getValueShape: (operator: string, family: OperatorFamily) => ValueShape;
|
|
294
315
|
/** The field and date operators a field kind takes, narrowed to one target when given. */
|
|
295
|
-
declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget
|
|
316
|
+
declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget, options?: {
|
|
317
|
+
positive?: boolean;
|
|
318
|
+
}) => {
|
|
296
319
|
field: Operator[];
|
|
297
320
|
date: DateOperator[];
|
|
298
321
|
};
|
|
299
322
|
/** The array operators, narrowed to one target when given. */
|
|
300
323
|
declare const getArrayOperators: (target?: RuleTarget) => ArrayOperator[];
|
|
324
|
+
/** The kinds `min` / `max` order: numbers and dates. A string column orders through `coerceType`,
|
|
325
|
+
* never by character code. */
|
|
326
|
+
declare const ORDERED_VALUE_KINDS: readonly FieldKind[];
|
|
327
|
+
/** The kinds `distinct` lists: strings, enums, dates, booleans and numbers — each compared as
|
|
328
|
+
* stored, so `1` and `Decimal('1')` stay two values unless `coerceType` reads them as one. */
|
|
329
|
+
declare const DISTINCT_VALUE_KINDS: readonly FieldKind[];
|
|
330
|
+
/** The aggregate modes that read values of `kind`; `{ comparable: true }` keeps the ones an
|
|
331
|
+
* aggregate rule compares. */
|
|
332
|
+
declare const aggregateModesForKind: (kind: FieldKind, options?: {
|
|
333
|
+
comparable?: boolean;
|
|
334
|
+
}) => ValueAggregateMode[];
|
|
335
|
+
/** The modes an aggregate rule compares (`sum`, `avg`). */
|
|
336
|
+
declare const AGGREGATE_MODES: readonly AggregateMode[];
|
|
301
337
|
/** Every mode a value expression's aggregate takes. */
|
|
302
338
|
declare const VALUE_AGGREGATE_MODES: readonly ValueAggregateMode[];
|
|
303
339
|
/** The comparisons an aggregate rule takes; every target compiles all of them. */
|
|
@@ -587,12 +623,12 @@ type StrictIfThenElse<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
|
|
|
587
623
|
type StrictCondition<TRuleValue = RuleValue, TDateValue = DateRuleValue> = StrictRule<TRuleValue> | StrictAggregateRule<TRuleValue, TDateValue> | StrictArrayRule<TRuleValue, TDateValue> | StrictDateRule | StrictAll<TRuleValue, TDateValue> | StrictAny<TRuleValue, TDateValue> | StrictIfThenElse<TRuleValue, TDateValue> | boolean;
|
|
588
624
|
/** A row as a rule reads it: a record of fields. */
|
|
589
625
|
type Row = Record<string, unknown>;
|
|
590
|
-
/** What both compilers take: the schema (a
|
|
626
|
+
/** What both compilers take: the schema (a LensFieldMap, or a FieldMapSet with `mapName`), the
|
|
591
627
|
* model the rule reads, and the clock. `lens` compiles the
|
|
592
628
|
* rule under a lens instead — narrowed (`narrowRule`), against the base lens's maps, map and
|
|
593
629
|
* model — and can't be passed with `map` / `mapName` / `model`. */
|
|
594
630
|
type CompileOptions = {
|
|
595
|
-
map?:
|
|
631
|
+
map?: LensFieldMap | FieldMapSet;
|
|
596
632
|
mapName?: string;
|
|
597
633
|
model?: string;
|
|
598
634
|
lens?: Lens | LensNarrowing;
|
|
@@ -649,10 +685,17 @@ type ListValue = ValueExpression[] | {
|
|
|
649
685
|
};
|
|
650
686
|
/** A scalar written as itself, as a stored value is: `5`, `'gold'`, `true`, `null`, a Date. */
|
|
651
687
|
type BareLiteral = string | number | boolean | bigint | Date | null;
|
|
652
|
-
/** A
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
type
|
|
688
|
+
/** A literal read as a kind, with the field rule's own key: `{ value: '2027-01-01', coerceType:
|
|
689
|
+
* 'DateTime' }` evaluates to a Date. Its kind is stamped by whoever knows it (the editor, from
|
|
690
|
+
* the caller's target); json-rules never guesses it. */
|
|
691
|
+
type CoercedLiteral = {
|
|
692
|
+
value: RuleValue;
|
|
693
|
+
coerceType: FieldKind;
|
|
694
|
+
} & Never<'path' | 'bind' | 'bindOptional'>;
|
|
695
|
+
/** A value computed from a row: a literal (bare, `{ value }` — an object literal needs the
|
|
696
|
+
* wrapper — or a `CoercedLiteral`), a path read (`{ path }`), a binding (`{ bind }`), an
|
|
697
|
+
* aggregate over a relation's rows, if / then / else, or a list. */
|
|
698
|
+
type ValueExpression = BareLiteral | ValueSourceOf<RuleValue> | CoercedLiteral | AggregateValue | IfThenElseValue | ListValue;
|
|
656
699
|
/** What a value expression returns: its kind (null when it can only be null), whether it is a
|
|
657
700
|
* list, and whether it can be null. */
|
|
658
701
|
type ValueType = {
|
|
@@ -807,6 +850,9 @@ declare class UsageError extends Error {
|
|
|
807
850
|
name: string;
|
|
808
851
|
}
|
|
809
852
|
|
|
853
|
+
/** Whether a bridge joins on a field of each side, or its far row is supplied on the record. */
|
|
854
|
+
declare const isJoinedBridge: (bridge: Bridge) => bridge is JoinedBridge;
|
|
855
|
+
|
|
810
856
|
type BridgeDictionary = Record<string, // map name
|
|
811
857
|
Record<string, // model name
|
|
812
858
|
Record<string, Record<string, Row | Row[]>>>>;
|
|
@@ -816,7 +862,8 @@ Record<string, Record<string, Row | Row[]>>>>;
|
|
|
816
862
|
declare const indexBridges: (set: FieldMapSet, rawData: Record<string, Row[]>) => BridgeDictionary;
|
|
817
863
|
|
|
818
864
|
/** A copy of the set where each bridge's endpoint models gain a `kind: 'bridge'` field named
|
|
819
|
-
* after the other endpoint (`<fieldMap>:<Model>`). Throws on a missing endpoint
|
|
865
|
+
* after the other endpoint (`<fieldMap>:<Model>`). Throws on a missing endpoint, a joined bridge's
|
|
866
|
+
* missing `on` field, an `on` on one side only, a supplied bridge that is not one-to-one, a
|
|
820
867
|
* self-bridge, or a bridge stitched twice. */
|
|
821
868
|
declare const stitchFieldMaps: (set: FieldMapSet) => FieldMapSet;
|
|
822
869
|
|
|
@@ -830,11 +877,11 @@ type ValidationResult = {
|
|
|
830
877
|
errors: ValidationIssue[];
|
|
831
878
|
};
|
|
832
879
|
/** Which engine a rule must compile for; `check` (the default) accepts every rule. The schema
|
|
833
|
-
* (`map` — a
|
|
880
|
+
* (`map` — a LensFieldMap, or a FieldMapSet with `mapName` — and `model`) lets the Prisma target
|
|
834
881
|
* accept a column compared with a column it can compile. */
|
|
835
882
|
type ValidateRuleOptions = {
|
|
836
883
|
target?: RuleTarget;
|
|
837
|
-
map?:
|
|
884
|
+
map?: LensFieldMap | FieldMapSet;
|
|
838
885
|
mapName?: string;
|
|
839
886
|
model?: string;
|
|
840
887
|
/** Refuse every shape that can hold on a value the row doesn't carry: `if`/`then`/`else`,
|
|
@@ -898,8 +945,11 @@ declare const clampLens: (lens: Lens | LensNarrowing, clamps: LensClamps) => Len
|
|
|
898
945
|
* names its coercion are left as they are. */
|
|
899
946
|
declare const coerceRule: (condition: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
|
|
900
947
|
|
|
901
|
-
/** A lens over field maps, its bridges stitched into the maps as fields.
|
|
902
|
-
|
|
948
|
+
/** A lens over field maps, its bridges stitched into the maps as fields. Over a literal map
|
|
949
|
+
* (`typeof prismaMap`), `model` must be one of `mapName`'s models. */
|
|
950
|
+
declare const createLens: <const L extends Lens>({ maps, bridges, mapName, model, }: L & {
|
|
951
|
+
model: Extract<keyof L["maps"][L["mapName"]]["models"], string>;
|
|
952
|
+
}) => Lens;
|
|
903
953
|
|
|
904
954
|
type RuleDescription = {
|
|
905
955
|
sources: string[];
|
|
@@ -1443,7 +1493,7 @@ type WhereSqlOptions = {
|
|
|
1443
1493
|
tables?: Record<string, string>;
|
|
1444
1494
|
/** The schema the condition reads: it types each literal by its column, finds a relation's key,
|
|
1445
1495
|
* and refuses what has no form here (a date, Json or list value, a bridge, a to-many hop). */
|
|
1446
|
-
map:
|
|
1496
|
+
map: LensFieldMap | FieldMapSet;
|
|
1447
1497
|
mapName?: string;
|
|
1448
1498
|
model: string;
|
|
1449
1499
|
};
|
|
@@ -1477,6 +1527,99 @@ type ConditionShapeKeys = {
|
|
|
1477
1527
|
};
|
|
1478
1528
|
/** The keys a node of one shape takes: those it must have and those it may. */
|
|
1479
1529
|
declare const getConditionShapeKeys: (shape: ConditionShape) => ConditionShapeKeys;
|
|
1530
|
+
declare const ValueExpressionShape: {
|
|
1531
|
+
readonly literal: "literal";
|
|
1532
|
+
readonly list: "list";
|
|
1533
|
+
readonly if: "if";
|
|
1534
|
+
readonly aggregate: "aggregate";
|
|
1535
|
+
readonly source: "source";
|
|
1536
|
+
};
|
|
1537
|
+
type ValueExpressionShape = (typeof ValueExpressionShape)[keyof typeof ValueExpressionShape];
|
|
1538
|
+
/** A list's items: a bare array, or the `list` of `{ list, distinct }`. */
|
|
1539
|
+
declare const listItems: (expr: unknown) => unknown[];
|
|
1540
|
+
/** What a value expression node is — a bare literal, a list, if / then / else, an aggregate, or a
|
|
1541
|
+
* value source — or null when it is none of them or names more than one. */
|
|
1542
|
+
declare const valueExpressionShape: (expr: unknown) => ValueExpressionShape | null;
|
|
1543
|
+
|
|
1544
|
+
/**
|
|
1545
|
+
* The path spellings `ConditionOn` passes through as `string`, unchecked: a scope ref into an
|
|
1546
|
+
* enclosing row (`$.x`, `$$.x`), a bridge into another map (`map:Model.field`), the actor
|
|
1547
|
+
* (`__actor.x`), and a bracket spelling (`a[0].b`). The lens gate (`validateRuleInLens`) still
|
|
1548
|
+
* reads them at run time.
|
|
1549
|
+
*/
|
|
1550
|
+
type UncheckedPath = `$.${string}` | `$$.${string}` | `${string}:${string}` | `__actor.${string}` | `${string}[${string}`;
|
|
1551
|
+
type FieldOn<M extends FieldMap, Model extends string> = ScalarPath<M, Model> | UncheckedPath;
|
|
1552
|
+
type Window<M extends FieldMap, Target extends string, Root extends string, TR, TD> = {
|
|
1553
|
+
filter?: ConditionOn<M, Target, Root, TR, TD>;
|
|
1554
|
+
orderBy?: {
|
|
1555
|
+
field: FieldOn<M, Target>;
|
|
1556
|
+
dir: SortDir;
|
|
1557
|
+
}[];
|
|
1558
|
+
};
|
|
1559
|
+
type RuleOn<M extends FieldMap, Model extends string, Root extends string, TR> = Omit<Rule<TR>, 'field' | 'path'> & {
|
|
1560
|
+
field: FieldOn<M, Model>;
|
|
1561
|
+
path?: FieldOn<M, Root>;
|
|
1562
|
+
};
|
|
1563
|
+
type DateRuleOn<M extends FieldMap, Model extends string, Root extends string, TD> = Omit<DateRule<TD>, 'field' | 'path'> & {
|
|
1564
|
+
field: FieldOn<M, Model>;
|
|
1565
|
+
path?: FieldOn<M, Root>;
|
|
1566
|
+
};
|
|
1567
|
+
type RelationArrayOn<M extends FieldMap, Model extends string, Root extends string, TR, TD> = {
|
|
1568
|
+
[P in RelationPath<M, Model>]: Omit<ArrayRule<TR, TD>, 'field' | 'condition' | 'filter' | 'orderBy'> & Window<M, RelationPathTarget<M, Model, P>, Root, TR, TD> & {
|
|
1569
|
+
field: P;
|
|
1570
|
+
condition?: ConditionOn<M, RelationPathTarget<M, Model, P>, Root, TR, TD>;
|
|
1571
|
+
};
|
|
1572
|
+
}[RelationPath<M, Model>];
|
|
1573
|
+
type ValueArrayOn<M extends FieldMap, Model extends string, TR, TD> = Omit<ArrayRule<TR, TD>, 'field'> & {
|
|
1574
|
+
field: FieldOn<M, Model>;
|
|
1575
|
+
};
|
|
1576
|
+
type AggregateOn<M extends FieldMap, Model extends string, Root extends string, TR, TD> = {
|
|
1577
|
+
[P in RelationPath<M, Model>]: Omit<AggregateRule<TR, TD>, 'field' | 'aggregate' | 'condition' | 'filter' | 'orderBy'> & Window<M, RelationPathTarget<M, Model, P>, Root, TR, TD> & {
|
|
1578
|
+
field: P;
|
|
1579
|
+
aggregate: AggregateRule['aggregate'] & {
|
|
1580
|
+
field?: FieldOn<M, RelationPathTarget<M, Model, P>>;
|
|
1581
|
+
};
|
|
1582
|
+
condition?: ConditionOn<M, RelationPathTarget<M, Model, P>, Root, TR, TD>;
|
|
1583
|
+
};
|
|
1584
|
+
}[RelationPath<M, Model>];
|
|
1585
|
+
/**
|
|
1586
|
+
* A `Condition` whose paths are checked against a literal map at compile time: a field rule or
|
|
1587
|
+
* date rule names a `ScalarPath` of `Model` (through to-one relations, into Json); an array or
|
|
1588
|
+
* aggregate rule names a `RelationPath` and its `condition`, `filter`, `orderBy` and
|
|
1589
|
+
* `aggregate.field` read the related model; a `{ path }` value source reads the root row
|
|
1590
|
+
* (`Root`, the model the rule is checked on). `all` / `any` / `if` nest as themselves.
|
|
1591
|
+
* `UncheckedPath` spellings pass through. Assignable to `Condition`.
|
|
1592
|
+
*/
|
|
1593
|
+
type ConditionOn<M extends FieldMap, Model extends string, Root extends string = Model, TRuleValue = RuleValue, TDateValue = DateRuleValue> = RuleOn<M, Model, Root, TRuleValue> | DateRuleOn<M, Model, Root, TDateValue> | RelationArrayOn<M, Model, Root, TRuleValue, TDateValue> | ValueArrayOn<M, Model, TRuleValue, TDateValue> | AggregateOn<M, Model, Root, TRuleValue, TDateValue> | {
|
|
1594
|
+
all: ConditionOn<M, Model, Root, TRuleValue, TDateValue>[];
|
|
1595
|
+
error?: string;
|
|
1596
|
+
} | {
|
|
1597
|
+
any: ConditionOn<M, Model, Root, TRuleValue, TDateValue>[];
|
|
1598
|
+
error?: string;
|
|
1599
|
+
} | {
|
|
1600
|
+
if: ConditionOn<M, Model, Root, TRuleValue, TDateValue>;
|
|
1601
|
+
then: ConditionOn<M, Model, Root, TRuleValue, TDateValue>;
|
|
1602
|
+
else?: ConditionOn<M, Model, Root, TRuleValue, TDateValue>;
|
|
1603
|
+
error?: string;
|
|
1604
|
+
} | boolean;
|
|
1605
|
+
/**
|
|
1606
|
+
* A `ModelNarrowing` checked against a literal map: `picks` / `omits` name the model's columns,
|
|
1607
|
+
* `relations` its relation fields (each narrowing the related model in turn), and `where` is a
|
|
1608
|
+
* `ConditionOn` the model. Assignable to `ModelNarrowing`.
|
|
1609
|
+
*/
|
|
1610
|
+
type ModelNarrowingOn<M extends FieldMap, Model extends string> = Omit<ModelNarrowing, 'picks' | 'omits' | 'where' | 'relations'> & {
|
|
1611
|
+
picks?: ScalarFieldNameOf<M, Model>[];
|
|
1612
|
+
omits?: ScalarFieldNameOf<M, Model>[];
|
|
1613
|
+
where?: ConditionOn<M, Model>;
|
|
1614
|
+
relations?: {
|
|
1615
|
+
[F in RelationFieldNameOf<M, Model>]?: ModelNarrowingOn<M, RelationTargetOf<M, Model, F>>;
|
|
1616
|
+
};
|
|
1617
|
+
};
|
|
1618
|
+
/** A `LensNarrowing` whose `root` is a `ModelNarrowingOn` the lens's anchor model. Assignable to
|
|
1619
|
+
* `LensNarrowing`. */
|
|
1620
|
+
type LensNarrowingOn<M extends FieldMap, Model extends string> = Omit<LensNarrowing, 'root'> & {
|
|
1621
|
+
root?: ModelNarrowingOn<M, Model>;
|
|
1622
|
+
};
|
|
1480
1623
|
|
|
1481
1624
|
/**
|
|
1482
1625
|
* A row's category: the value of the first case whose `if` holds (`match: 'first'`, the default;
|
|
@@ -1507,9 +1650,19 @@ type ValueDescription = {
|
|
|
1507
1650
|
};
|
|
1508
1651
|
declare const describeValue: (expression: ValueExpression, lensOrNarrowing: Lens | LensNarrowing) => ValueDescription;
|
|
1509
1652
|
|
|
1653
|
+
/** What `describeCategorization` reports: as `describeValue` does, for the value `categorize` gives. */
|
|
1654
|
+
type CategorizationDescription = ValueDescription;
|
|
1655
|
+
/** A categorization under a lens: the type `categorize` returns (every case's value and the
|
|
1656
|
+
* default unified; a list of them under `match: 'all'`; nullable when nothing may hold and there
|
|
1657
|
+
* is no default), the dotted paths its conditions and values read, its clock unit, and every
|
|
1658
|
+
* problem the validator, the lens gate and type inference find, at the case it was found in.
|
|
1659
|
+
* Never throws on a bad categorization. */
|
|
1660
|
+
declare const describeCategorization: (categorization: Categorization, lensOrNarrowing: Lens | LensNarrowing) => CategorizationDescription;
|
|
1661
|
+
|
|
1510
1662
|
/**
|
|
1511
1663
|
* The value an expression computes from a row, in memory, with what check() takes (`bindings`,
|
|
1512
|
-
* `now`, `timeZone`, `weekStart`, `absent`): a literal (bare
|
|
1664
|
+
* `now`, `timeZone`, `weekStart`, `absent`): a literal (bare, `{ value }`, or `{ value, coerceType }`
|
|
1665
|
+
* read as that kind), a path read (null when absent), a bound
|
|
1513
1666
|
* value, an aggregate over a relation's rows (`count`, `sum`, `avg`, `min`, `max`, through its
|
|
1514
1667
|
* window and condition; `avg` and `min` / `max` over no values are null), the branch an `if` picks,
|
|
1515
1668
|
* or a list (`distinct: true` drops repeats). Throws on a malformed expression,
|
|
@@ -1561,4 +1714,4 @@ declare const valueClockUnit: (expression: ValueExpression) => ClockUnit | null;
|
|
|
1561
1714
|
*/
|
|
1562
1715
|
declare const orderRecords: <T>(items: readonly T[], orderBy: OrderBy) => T[];
|
|
1563
1716
|
|
|
1564
|
-
export { ALL_KINDS, type Absent, type AggregateMode, type AggregateRule, type AggregateValue, type All, type Any, ArrayOperator, type ArrayRule, type BareLiteral, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, CATEGORIZATION_MATCHES, CLOCK_UNITS, type Categorization, type CategorizationMatch, type Category, type CheckData, type CheckOptions, type ClockUnit, type CompileOptions, type Condition, ConditionShape, type ConditionShapeKeys, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, type DateOffset, DateOperator, type DateRule, type DateRuleValue, type EdgeExpr, type EngineGlobalDefaults, type EngineGlobalPath, type EngineGlobalValues, type EngineGlobalsState, type EnumNarrowing, FieldKind, type
|
|
1717
|
+
export { AGGREGATE_MODES, ALL_KINDS, type Absent, type AggregateMode, type AggregateRule, type AggregateValue, type All, type Any, ArrayOperator, type ArrayRule, type BareLiteral, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BridgeEntry, CATEGORIZATION_MATCHES, CLOCK_UNITS, type Categorization, type CategorizationDescription, type CategorizationMatch, type Category, type CheckData, type CheckOptions, type ClockUnit, type CoercedLiteral, type CompileOptions, type Condition, type ConditionOn, ConditionShape, type ConditionShapeKeys, DISTINCT_VALUE_KINDS, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, type DateOffset, DateOperator, type DateRule, type DateRuleValue, type EdgeExpr, type EngineGlobalDefaults, type EngineGlobalPath, type EngineGlobalValues, type EngineGlobalsState, type EnumNarrowing, FieldKind, type FieldMapEntry, type FieldMapSet, type FuzzyConfig, type GroupByStep, type IfThenElse, type IfThenElseValue, type JoinedBridge, type JoinedBridgeEndpoint, type Lens, type LensClamps, type LensFieldMap, type LensModelEntry, type LensNarrowing, type LensNarrowingOn, type LensPathHop, type LensPathResolution, LensRefusal, type LensRelationSelect, type LensSelect, type LensSelectOptions, type LensValue, type LensWhereSql, type LensWhereSqlOptions, type ListBindingsOptions, type ListValue, type Magnitude, type MaterializeSourceQueryOptions, type ModelDefaultNarrowing, type ModelNarrowing, type ModelNarrowingOn, NUMERIC_KINDS, type NarrowingDefaults, type NumberOffset, ORDERED_VALUE_KINDS, 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 RelativeUnit, 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, SourceOptionOrder, type SourcePrismaQuery, type SourceQuery, type SourceRowShape, type SourceSelect, type SourceSpec, type SourceSqlQuery, type SourceValues, SqlDialect, 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 SuppliedBridge, type TimeZoneConfig, type ToPrismaOptions, type ToPrismaResult, type ToSqlOptions, type ToSqlResult, type UncheckedPath, UsageError, VALUE_AGGREGATE_MODES, type ValidateRuleOptions, type ValidationIssue, type ValidationResult, type ValueAggregateMode, type ValueDescription, type ValueExpression, ValueExpressionShape, ValueShape, type ValueSourceFields, type ValueSourceOf, type ValueType, type WeekStart, type WhereSqlOptions, type WhereStep, type WindowFields, aggregateModesForKind, andWhere, assertValidCategorization, assertValidFieldMaps, assertValidNarrowing, assertValidRule, assertValidValue, bindLens, bindRule, categorize, check, clampLens, clockUnit, coerceRule, coerceValue, composeLens, createLens, describeCategorization, describeRule, describeRuleSources, describeValue, engineGlobals, evaluateValue, executePrismaPlan, getAggregateOperators, getArrayOperators, getConditionShapeKeys, getLensRoot, getOperatorsForKind, getValueShape, indexBridges, inferValueType, isJoinedBridge, lensVisit, listBindings, listFields, listItems, listLensBindings, matchAll, matchNothing, materializeSourceQuery, materializeSources, narrowRule, orWhere, orderRecords, parseScopeRef, pathSegments, prefixConditionFields, projectLens, projectRows, readLensValue, readScopeRef, registerEngineGlobals, stitchFieldMaps, storeLens, toLensSelect, toLensWhereSql, toPrisma, toSourceQueries, toSql, toWhereSql, validateCategorization, validateFieldMaps, validateNarrowing, validateRule, validateRuleInLens, validateValue, valueClockUnit, valueExpressionShape, walkLensPath };
|