@inixiative/json-rules 4.0.0 → 4.2.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 +36 -4
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +217 -47
- package/dist/index.d.ts +217 -47
- 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,52 +60,57 @@ 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
|
};
|
|
108
115
|
type BridgeEndpoint = {
|
|
109
116
|
fieldMap: string;
|
|
@@ -131,7 +138,7 @@ type Bridge = {
|
|
|
131
138
|
cardinality: BridgeCardinality;
|
|
132
139
|
};
|
|
133
140
|
type FieldMapSet = {
|
|
134
|
-
maps: Record<string,
|
|
141
|
+
maps: Record<string, LensFieldMap>;
|
|
135
142
|
bridges?: Bridge[];
|
|
136
143
|
};
|
|
137
144
|
|
|
@@ -292,12 +299,27 @@ type OperatorFamily = 'field' | 'date' | 'array';
|
|
|
292
299
|
* Throws on an operator the family doesn't have. */
|
|
293
300
|
declare const getValueShape: (operator: string, family: OperatorFamily) => ValueShape;
|
|
294
301
|
/** The field and date operators a field kind takes, narrowed to one target when given. */
|
|
295
|
-
declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget
|
|
302
|
+
declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget, options?: {
|
|
303
|
+
positive?: boolean;
|
|
304
|
+
}) => {
|
|
296
305
|
field: Operator[];
|
|
297
306
|
date: DateOperator[];
|
|
298
307
|
};
|
|
299
308
|
/** The array operators, narrowed to one target when given. */
|
|
300
309
|
declare const getArrayOperators: (target?: RuleTarget) => ArrayOperator[];
|
|
310
|
+
/** The kinds `min` / `max` order: numbers and dates. A string column orders through `coerceType`,
|
|
311
|
+
* never by character code. */
|
|
312
|
+
declare const ORDERED_VALUE_KINDS: readonly FieldKind[];
|
|
313
|
+
/** The kinds `distinct` lists: strings, enums, dates, booleans and numbers — each compared as
|
|
314
|
+
* stored, so `1` and `Decimal('1')` stay two values unless `coerceType` reads them as one. */
|
|
315
|
+
declare const DISTINCT_VALUE_KINDS: readonly FieldKind[];
|
|
316
|
+
/** The aggregate modes that read values of `kind`; `{ comparable: true }` keeps the ones an
|
|
317
|
+
* aggregate rule compares. */
|
|
318
|
+
declare const aggregateModesForKind: (kind: FieldKind, options?: {
|
|
319
|
+
comparable?: boolean;
|
|
320
|
+
}) => ValueAggregateMode[];
|
|
321
|
+
/** The modes an aggregate rule compares (`sum`, `avg`). */
|
|
322
|
+
declare const AGGREGATE_MODES: readonly AggregateMode[];
|
|
301
323
|
/** Every mode a value expression's aggregate takes. */
|
|
302
324
|
declare const VALUE_AGGREGATE_MODES: readonly ValueAggregateMode[];
|
|
303
325
|
/** The comparisons an aggregate rule takes; every target compiles all of them. */
|
|
@@ -359,6 +381,8 @@ declare const RELATIVE_UNITS: {
|
|
|
359
381
|
};
|
|
360
382
|
};
|
|
361
383
|
type RelativeUnit = keyof typeof RELATIVE_UNITS;
|
|
384
|
+
/** How a categorization picks its cases (`categorize`): `first` (the default) or `all`. */
|
|
385
|
+
declare const CATEGORIZATION_MATCHES: readonly CategorizationMatch[];
|
|
362
386
|
|
|
363
387
|
type OperatorValues = typeof Operator;
|
|
364
388
|
type ArrayOperatorValues = typeof ArrayOperator;
|
|
@@ -585,12 +609,12 @@ type StrictIfThenElse<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
|
|
|
585
609
|
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;
|
|
586
610
|
/** A row as a rule reads it: a record of fields. */
|
|
587
611
|
type Row = Record<string, unknown>;
|
|
588
|
-
/** What both compilers take: the schema (a
|
|
612
|
+
/** What both compilers take: the schema (a LensFieldMap, or a FieldMapSet with `mapName`), the
|
|
589
613
|
* model the rule reads, and the clock. `lens` compiles the
|
|
590
614
|
* rule under a lens instead — narrowed (`narrowRule`), against the base lens's maps, map and
|
|
591
615
|
* model — and can't be passed with `map` / `mapName` / `model`. */
|
|
592
616
|
type CompileOptions = {
|
|
593
|
-
map?:
|
|
617
|
+
map?: LensFieldMap | FieldMapSet;
|
|
594
618
|
mapName?: string;
|
|
595
619
|
model?: string;
|
|
596
620
|
lens?: Lens | LensNarrowing;
|
|
@@ -623,6 +647,21 @@ type IfThenElseValue = {
|
|
|
623
647
|
then: ValueExpression;
|
|
624
648
|
else?: ValueExpression;
|
|
625
649
|
};
|
|
650
|
+
/** One case of a categorization: `then` is its value when `if` holds. */
|
|
651
|
+
type Category = {
|
|
652
|
+
if: Condition;
|
|
653
|
+
then: ValueExpression;
|
|
654
|
+
};
|
|
655
|
+
/** Cases checked in order against one row (`categorize`). `first` (the default) takes the first
|
|
656
|
+
* case that holds; `all` takes every one that holds, in order. `default` is the value when none
|
|
657
|
+
* holds. */
|
|
658
|
+
type Categorization = {
|
|
659
|
+
cases: Category[];
|
|
660
|
+
match?: CategorizationMatch;
|
|
661
|
+
default?: ValueExpression;
|
|
662
|
+
};
|
|
663
|
+
/** How a categorization picks its cases: the first that holds, or every one that holds. */
|
|
664
|
+
type CategorizationMatch = 'first' | 'all';
|
|
626
665
|
/** Experimental. A list of values, each item evaluated in turn; an `if` with no `else` that does not
|
|
627
666
|
* hold adds nothing — match-all, for a multiselect. Items are single values, not lists. A bare
|
|
628
667
|
* array keeps every item; `{ list, distinct: true }` keeps the first of equal items. */
|
|
@@ -632,10 +671,17 @@ type ListValue = ValueExpression[] | {
|
|
|
632
671
|
};
|
|
633
672
|
/** A scalar written as itself, as a stored value is: `5`, `'gold'`, `true`, `null`, a Date. */
|
|
634
673
|
type BareLiteral = string | number | boolean | bigint | Date | null;
|
|
635
|
-
/** A
|
|
636
|
-
*
|
|
637
|
-
*
|
|
638
|
-
type
|
|
674
|
+
/** A literal read as a kind, with the field rule's own key: `{ value: '2027-01-01', coerceType:
|
|
675
|
+
* 'DateTime' }` evaluates to a Date. Its kind is stamped by whoever knows it (the editor, from
|
|
676
|
+
* the caller's target); json-rules never guesses it. */
|
|
677
|
+
type CoercedLiteral = {
|
|
678
|
+
value: RuleValue;
|
|
679
|
+
coerceType: FieldKind;
|
|
680
|
+
} & Never<'path' | 'bind' | 'bindOptional'>;
|
|
681
|
+
/** A value computed from a row: a literal (bare, `{ value }` — an object literal needs the
|
|
682
|
+
* wrapper — or a `CoercedLiteral`), a path read (`{ path }`), a binding (`{ bind }`), an
|
|
683
|
+
* aggregate over a relation's rows, if / then / else, or a list. */
|
|
684
|
+
type ValueExpression = BareLiteral | ValueSourceOf<RuleValue> | CoercedLiteral | AggregateValue | IfThenElseValue | ListValue;
|
|
639
685
|
/** What a value expression returns: its kind (null when it can only be null), whether it is a
|
|
640
686
|
* list, and whether it can be null. */
|
|
641
687
|
type ValueType = {
|
|
@@ -813,11 +859,11 @@ type ValidationResult = {
|
|
|
813
859
|
errors: ValidationIssue[];
|
|
814
860
|
};
|
|
815
861
|
/** Which engine a rule must compile for; `check` (the default) accepts every rule. The schema
|
|
816
|
-
* (`map` — a
|
|
862
|
+
* (`map` — a LensFieldMap, or a FieldMapSet with `mapName` — and `model`) lets the Prisma target
|
|
817
863
|
* accept a column compared with a column it can compile. */
|
|
818
864
|
type ValidateRuleOptions = {
|
|
819
865
|
target?: RuleTarget;
|
|
820
|
-
map?:
|
|
866
|
+
map?: LensFieldMap | FieldMapSet;
|
|
821
867
|
mapName?: string;
|
|
822
868
|
model?: string;
|
|
823
869
|
/** Refuse every shape that can hold on a value the row doesn't carry: `if`/`then`/`else`,
|
|
@@ -881,8 +927,11 @@ declare const clampLens: (lens: Lens | LensNarrowing, clamps: LensClamps) => Len
|
|
|
881
927
|
* names its coercion are left as they are. */
|
|
882
928
|
declare const coerceRule: (condition: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
|
|
883
929
|
|
|
884
|
-
/** A lens over field maps, its bridges stitched into the maps as fields.
|
|
885
|
-
|
|
930
|
+
/** A lens over field maps, its bridges stitched into the maps as fields. Over a literal map
|
|
931
|
+
* (`typeof prismaMap`), `model` must be one of `mapName`'s models. */
|
|
932
|
+
declare const createLens: <const L extends Lens>({ maps, bridges, mapName, model, }: L & {
|
|
933
|
+
model: Extract<keyof L["maps"][L["mapName"]]["models"], string>;
|
|
934
|
+
}) => Lens;
|
|
886
935
|
|
|
887
936
|
type RuleDescription = {
|
|
888
937
|
sources: string[];
|
|
@@ -1426,7 +1475,7 @@ type WhereSqlOptions = {
|
|
|
1426
1475
|
tables?: Record<string, string>;
|
|
1427
1476
|
/** The schema the condition reads: it types each literal by its column, finds a relation's key,
|
|
1428
1477
|
* and refuses what has no form here (a date, Json or list value, a bridge, a to-many hop). */
|
|
1429
|
-
map:
|
|
1478
|
+
map: LensFieldMap | FieldMapSet;
|
|
1430
1479
|
mapName?: string;
|
|
1431
1480
|
model: string;
|
|
1432
1481
|
};
|
|
@@ -1460,6 +1509,110 @@ type ConditionShapeKeys = {
|
|
|
1460
1509
|
};
|
|
1461
1510
|
/** The keys a node of one shape takes: those it must have and those it may. */
|
|
1462
1511
|
declare const getConditionShapeKeys: (shape: ConditionShape) => ConditionShapeKeys;
|
|
1512
|
+
declare const ValueExpressionShape: {
|
|
1513
|
+
readonly literal: "literal";
|
|
1514
|
+
readonly list: "list";
|
|
1515
|
+
readonly if: "if";
|
|
1516
|
+
readonly aggregate: "aggregate";
|
|
1517
|
+
readonly source: "source";
|
|
1518
|
+
};
|
|
1519
|
+
type ValueExpressionShape = (typeof ValueExpressionShape)[keyof typeof ValueExpressionShape];
|
|
1520
|
+
/** A list's items: a bare array, or the `list` of `{ list, distinct }`. */
|
|
1521
|
+
declare const listItems: (expr: unknown) => unknown[];
|
|
1522
|
+
/** What a value expression node is — a bare literal, a list, if / then / else, an aggregate, or a
|
|
1523
|
+
* value source — or null when it is none of them or names more than one. */
|
|
1524
|
+
declare const valueExpressionShape: (expr: unknown) => ValueExpressionShape | null;
|
|
1525
|
+
|
|
1526
|
+
/**
|
|
1527
|
+
* The path spellings `ConditionOn` passes through as `string`, unchecked: a scope ref into an
|
|
1528
|
+
* enclosing row (`$.x`, `$$.x`), a bridge into another map (`map:Model.field`), the actor
|
|
1529
|
+
* (`__actor.x`), and a bracket spelling (`a[0].b`). The lens gate (`validateRuleInLens`) still
|
|
1530
|
+
* reads them at run time.
|
|
1531
|
+
*/
|
|
1532
|
+
type UncheckedPath = `$.${string}` | `$$.${string}` | `${string}:${string}` | `__actor.${string}` | `${string}[${string}`;
|
|
1533
|
+
type FieldOn<M extends FieldMap, Model extends string> = ScalarPath<M, Model> | UncheckedPath;
|
|
1534
|
+
type Window<M extends FieldMap, Target extends string, Root extends string, TR, TD> = {
|
|
1535
|
+
filter?: ConditionOn<M, Target, Root, TR, TD>;
|
|
1536
|
+
orderBy?: {
|
|
1537
|
+
field: FieldOn<M, Target>;
|
|
1538
|
+
dir: SortDir;
|
|
1539
|
+
}[];
|
|
1540
|
+
};
|
|
1541
|
+
type RuleOn<M extends FieldMap, Model extends string, Root extends string, TR> = Omit<Rule<TR>, 'field' | 'path'> & {
|
|
1542
|
+
field: FieldOn<M, Model>;
|
|
1543
|
+
path?: FieldOn<M, Root>;
|
|
1544
|
+
};
|
|
1545
|
+
type DateRuleOn<M extends FieldMap, Model extends string, Root extends string, TD> = Omit<DateRule<TD>, 'field' | 'path'> & {
|
|
1546
|
+
field: FieldOn<M, Model>;
|
|
1547
|
+
path?: FieldOn<M, Root>;
|
|
1548
|
+
};
|
|
1549
|
+
type RelationArrayOn<M extends FieldMap, Model extends string, Root extends string, TR, TD> = {
|
|
1550
|
+
[P in RelationPath<M, Model>]: Omit<ArrayRule<TR, TD>, 'field' | 'condition' | 'filter' | 'orderBy'> & Window<M, RelationPathTarget<M, Model, P>, Root, TR, TD> & {
|
|
1551
|
+
field: P;
|
|
1552
|
+
condition?: ConditionOn<M, RelationPathTarget<M, Model, P>, Root, TR, TD>;
|
|
1553
|
+
};
|
|
1554
|
+
}[RelationPath<M, Model>];
|
|
1555
|
+
type ValueArrayOn<M extends FieldMap, Model extends string, TR, TD> = Omit<ArrayRule<TR, TD>, 'field'> & {
|
|
1556
|
+
field: FieldOn<M, Model>;
|
|
1557
|
+
};
|
|
1558
|
+
type AggregateOn<M extends FieldMap, Model extends string, Root extends string, TR, TD> = {
|
|
1559
|
+
[P in RelationPath<M, Model>]: Omit<AggregateRule<TR, TD>, 'field' | 'aggregate' | 'condition' | 'filter' | 'orderBy'> & Window<M, RelationPathTarget<M, Model, P>, Root, TR, TD> & {
|
|
1560
|
+
field: P;
|
|
1561
|
+
aggregate: AggregateRule['aggregate'] & {
|
|
1562
|
+
field?: FieldOn<M, RelationPathTarget<M, Model, P>>;
|
|
1563
|
+
};
|
|
1564
|
+
condition?: ConditionOn<M, RelationPathTarget<M, Model, P>, Root, TR, TD>;
|
|
1565
|
+
};
|
|
1566
|
+
}[RelationPath<M, Model>];
|
|
1567
|
+
/**
|
|
1568
|
+
* A `Condition` whose paths are checked against a literal map at compile time: a field rule or
|
|
1569
|
+
* date rule names a `ScalarPath` of `Model` (through to-one relations, into Json); an array or
|
|
1570
|
+
* aggregate rule names a `RelationPath` and its `condition`, `filter`, `orderBy` and
|
|
1571
|
+
* `aggregate.field` read the related model; a `{ path }` value source reads the root row
|
|
1572
|
+
* (`Root`, the model the rule is checked on). `all` / `any` / `if` nest as themselves.
|
|
1573
|
+
* `UncheckedPath` spellings pass through. Assignable to `Condition`.
|
|
1574
|
+
*/
|
|
1575
|
+
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> | {
|
|
1576
|
+
all: ConditionOn<M, Model, Root, TRuleValue, TDateValue>[];
|
|
1577
|
+
error?: string;
|
|
1578
|
+
} | {
|
|
1579
|
+
any: ConditionOn<M, Model, Root, TRuleValue, TDateValue>[];
|
|
1580
|
+
error?: string;
|
|
1581
|
+
} | {
|
|
1582
|
+
if: ConditionOn<M, Model, Root, TRuleValue, TDateValue>;
|
|
1583
|
+
then: ConditionOn<M, Model, Root, TRuleValue, TDateValue>;
|
|
1584
|
+
else?: ConditionOn<M, Model, Root, TRuleValue, TDateValue>;
|
|
1585
|
+
error?: string;
|
|
1586
|
+
} | boolean;
|
|
1587
|
+
/**
|
|
1588
|
+
* A `ModelNarrowing` checked against a literal map: `picks` / `omits` name the model's columns,
|
|
1589
|
+
* `relations` its relation fields (each narrowing the related model in turn), and `where` is a
|
|
1590
|
+
* `ConditionOn` the model. Assignable to `ModelNarrowing`.
|
|
1591
|
+
*/
|
|
1592
|
+
type ModelNarrowingOn<M extends FieldMap, Model extends string> = Omit<ModelNarrowing, 'picks' | 'omits' | 'where' | 'relations'> & {
|
|
1593
|
+
picks?: ScalarFieldNameOf<M, Model>[];
|
|
1594
|
+
omits?: ScalarFieldNameOf<M, Model>[];
|
|
1595
|
+
where?: ConditionOn<M, Model>;
|
|
1596
|
+
relations?: {
|
|
1597
|
+
[F in RelationFieldNameOf<M, Model>]?: ModelNarrowingOn<M, RelationTargetOf<M, Model, F>>;
|
|
1598
|
+
};
|
|
1599
|
+
};
|
|
1600
|
+
/** A `LensNarrowing` whose `root` is a `ModelNarrowingOn` the lens's anchor model. Assignable to
|
|
1601
|
+
* `LensNarrowing`. */
|
|
1602
|
+
type LensNarrowingOn<M extends FieldMap, Model extends string> = Omit<LensNarrowing, 'root'> & {
|
|
1603
|
+
root?: ModelNarrowingOn<M, Model>;
|
|
1604
|
+
};
|
|
1605
|
+
|
|
1606
|
+
/**
|
|
1607
|
+
* A row's category: the value of the first case whose `if` holds (`match: 'first'`, the default;
|
|
1608
|
+
* later cases are not checked), or the values of every case that holds, in case order
|
|
1609
|
+
* (`match: 'all'`). When none holds: the `default`, a list of it under `all`; with no default,
|
|
1610
|
+
* null, or `[]` under `all`. Each `if` is checked as check() checks a rule and each value computed
|
|
1611
|
+
* as evaluateValue() computes it, with their options. A case that throws stops the categorization:
|
|
1612
|
+
* it never falls through to a later case or the default, which would give a value its author
|
|
1613
|
+
* ordered below it.
|
|
1614
|
+
*/
|
|
1615
|
+
declare const categorize: (categorization: Categorization, row: Row, options?: CheckOptions) => unknown;
|
|
1463
1616
|
|
|
1464
1617
|
/** Stamp the coercion a value expression's aggregates need from the lens, as `coerceRule` does for
|
|
1465
1618
|
* a rule's field rules: a `distinct` / `min` / `max` over a DateTime column gets
|
|
@@ -1479,9 +1632,19 @@ type ValueDescription = {
|
|
|
1479
1632
|
};
|
|
1480
1633
|
declare const describeValue: (expression: ValueExpression, lensOrNarrowing: Lens | LensNarrowing) => ValueDescription;
|
|
1481
1634
|
|
|
1635
|
+
/** What `describeCategorization` reports: as `describeValue` does, for the value `categorize` gives. */
|
|
1636
|
+
type CategorizationDescription = ValueDescription;
|
|
1637
|
+
/** A categorization under a lens: the type `categorize` returns (every case's value and the
|
|
1638
|
+
* default unified; a list of them under `match: 'all'`; nullable when nothing may hold and there
|
|
1639
|
+
* is no default), the dotted paths its conditions and values read, its clock unit, and every
|
|
1640
|
+
* problem the validator, the lens gate and type inference find, at the case it was found in.
|
|
1641
|
+
* Never throws on a bad categorization. */
|
|
1642
|
+
declare const describeCategorization: (categorization: Categorization, lensOrNarrowing: Lens | LensNarrowing) => CategorizationDescription;
|
|
1643
|
+
|
|
1482
1644
|
/**
|
|
1483
1645
|
* The value an expression computes from a row, in memory, with what check() takes (`bindings`,
|
|
1484
|
-
* `now`, `timeZone`, `weekStart`, `absent`): a literal (bare
|
|
1646
|
+
* `now`, `timeZone`, `weekStart`, `absent`): a literal (bare, `{ value }`, or `{ value, coerceType }`
|
|
1647
|
+
* read as that kind), a path read (null when absent), a bound
|
|
1485
1648
|
* value, an aggregate over a relation's rows (`count`, `sum`, `avg`, `min`, `max`, through its
|
|
1486
1649
|
* window and condition; `avg` and `min` / `max` over no values are null), the branch an `if` picks,
|
|
1487
1650
|
* or a list (`distinct: true` drops repeats). Throws on a malformed expression,
|
|
@@ -1504,6 +1667,13 @@ declare const evaluateValue: (expression: ValueExpression, data: Row, options?:
|
|
|
1504
1667
|
*/
|
|
1505
1668
|
declare const inferValueType: (expression: ValueExpression, lens?: Lens | LensNarrowing) => ValueType;
|
|
1506
1669
|
|
|
1670
|
+
/** A categorization's shape checked without data: `cases` an array of `{ if, then }`, each `if`
|
|
1671
|
+
* valid as `validateRule` sees it and each `then` and the `default` as `validateValue` does,
|
|
1672
|
+
* `match` one of CATEGORIZATION_MATCHES, every key known. */
|
|
1673
|
+
declare const validateCategorization: (categorization: unknown) => ValidationResult;
|
|
1674
|
+
/** validateCategorization's throwing form. */
|
|
1675
|
+
declare const assertValidCategorization: (categorization: unknown) => void;
|
|
1676
|
+
|
|
1507
1677
|
/** A value expression's shape checked without data: each node exactly one kind, every key known,
|
|
1508
1678
|
* aggregate modes from VALUE_AGGREGATE_MODES, and each condition it holds (`if`, an aggregate's
|
|
1509
1679
|
* `filter` / `condition` / window) valid as `validateRule` sees it. */
|
|
@@ -1526,4 +1696,4 @@ declare const valueClockUnit: (expression: ValueExpression) => ClockUnit | null;
|
|
|
1526
1696
|
*/
|
|
1527
1697
|
declare const orderRecords: <T>(items: readonly T[], orderBy: OrderBy) => T[];
|
|
1528
1698
|
|
|
1529
|
-
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, CLOCK_UNITS, 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
|
|
1699
|
+
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 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 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, 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 };
|