foldkit-entity 0.13.0 → 0.15.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 +962 -512
- package/dist/collation.d.ts +33 -0
- package/dist/collation.d.ts.map +1 -0
- package/dist/collation.js +46 -0
- package/dist/collation.js.map +1 -0
- package/dist/conformance/index.d.ts +66 -0
- package/dist/conformance/index.d.ts.map +1 -0
- package/dist/conformance/{index.mjs → index.js} +22 -360
- package/dist/conformance/index.js.map +1 -0
- package/dist/conformance/operator.d.ts +115 -0
- package/dist/conformance/operator.d.ts.map +1 -0
- package/dist/conformance/operator.js +354 -0
- package/dist/conformance/operator.js.map +1 -0
- package/dist/conformance/relational.d.ts +240 -0
- package/dist/conformance/relational.d.ts.map +1 -0
- package/dist/conformance/relational.js +425 -0
- package/dist/conformance/relational.js.map +1 -0
- package/dist/conformance/tuples.d.ts +8 -0
- package/dist/conformance/tuples.d.ts.map +1 -0
- package/dist/conformance/tuples.js +43 -0
- package/dist/conformance/tuples.js.map +1 -0
- package/dist/conformance/variants.d.ts +47 -0
- package/dist/conformance/variants.d.ts.map +1 -0
- package/dist/conformance/variants.js +126 -0
- package/dist/conformance/variants.js.map +1 -0
- package/dist/context.d.ts +60 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +36 -0
- package/dist/context.js.map +1 -0
- package/dist/descriptor.d.ts +33 -0
- package/dist/descriptor.d.ts.map +1 -0
- package/dist/descriptor.js +137 -0
- package/dist/descriptor.js.map +1 -0
- package/dist/entity.d.ts +231 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/entity.js +435 -0
- package/dist/entity.js.map +1 -0
- package/dist/evaluate.d.ts +204 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +765 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/expr.d.ts +915 -0
- package/dist/expr.d.ts.map +1 -0
- package/dist/expr.js +1630 -0
- package/dist/expr.js.map +1 -0
- package/dist/held.d.ts +112 -0
- package/dist/held.d.ts.map +1 -0
- package/dist/held.js +155 -0
- package/dist/held.js.map +1 -0
- package/dist/ids.d.ts +8 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +8 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +380 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/dist/invariant.d.ts +123 -0
- package/dist/invariant.d.ts.map +1 -0
- package/dist/invariant.js +236 -0
- package/dist/invariant.js.map +1 -0
- package/dist/jsonSchema.d.ts +3 -0
- package/dist/jsonSchema.d.ts.map +1 -0
- package/dist/jsonSchema.js +17 -0
- package/dist/jsonSchema.js.map +1 -0
- package/dist/law.d.ts +264 -0
- package/dist/law.d.ts.map +1 -0
- package/dist/law.js +111 -0
- package/dist/law.js.map +1 -0
- package/dist/operators.d.ts +170 -0
- package/dist/operators.d.ts.map +1 -0
- package/dist/operators.js +207 -0
- package/dist/operators.js.map +1 -0
- package/dist/readFilter.d.ts +8 -0
- package/dist/readFilter.d.ts.map +1 -0
- package/dist/readFilter.js +23 -0
- package/dist/readFilter.js.map +1 -0
- package/dist/record.d.ts +11 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +21 -0
- package/dist/record.js.map +1 -0
- package/dist/sets.d.ts +18 -0
- package/dist/sets.d.ts.map +1 -0
- package/dist/sets.js +57 -0
- package/dist/sets.js.map +1 -0
- package/dist/shape.d.ts +23 -0
- package/dist/shape.d.ts.map +1 -0
- package/dist/shape.js +30 -0
- package/dist/shape.js.map +1 -0
- package/dist/tested.d.ts +8 -0
- package/dist/tested.d.ts.map +1 -0
- package/dist/tested.js +25 -0
- package/dist/tested.js.map +1 -0
- package/dist/text.d.ts +27 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +39 -0
- package/dist/text.js.map +1 -0
- package/dist/variants.d.ts +72 -0
- package/dist/variants.d.ts.map +1 -0
- package/dist/variants.js +76 -0
- package/dist/variants.js.map +1 -0
- package/dist/words.d.ts +17 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +22 -0
- package/dist/words.js.map +1 -0
- package/dist/write.d.ts +312 -0
- package/dist/write.d.ts.map +1 -0
- package/dist/write.js +520 -0
- package/dist/write.js.map +1 -0
- package/package.json +8 -8
- package/dist/conformance/index.d.mts +0 -274
- package/dist/conformance/index.d.mts.map +0 -1
- package/dist/conformance/index.mjs.map +0 -1
- package/dist/index-hu8IYlNc.d.mts +0 -2228
- package/dist/index-hu8IYlNc.d.mts.map +0 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -1
- package/dist/src-DBAilaDV.mjs +0 -3061
- package/dist/src-DBAilaDV.mjs.map +0 -1
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
import { Collation } from "./collation.js";
|
|
3
|
+
import { AnyQuery, Operandish, Operation, OperatorDescriptor, OperatorTable, OrderTerm, Predicate } from "./expr.js";
|
|
4
|
+
import { HeldRow, HeldRows, Pinned } from "./held.js";
|
|
5
|
+
import { MemoryOperators } from "./operators.js";
|
|
6
|
+
import { ExprContext, NowExpr, ViewerExpr } from "./context.js";
|
|
7
|
+
/** A row as this interpreter reads one: values by field key. */
|
|
8
|
+
export type Row = Readonly<Record<string, unknown>>;
|
|
9
|
+
export declare class QueryEvaluateError extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A call of a primitive operator the table does not implement. Its own class,
|
|
14
|
+
* because a form judging an invariant reads it as a judgement it cannot make
|
|
15
|
+
* (`Undecided`), not as a failure.
|
|
16
|
+
*/
|
|
17
|
+
export declare class OperatorMissingError extends QueryEvaluateError {
|
|
18
|
+
readonly operator: OperatorDescriptor;
|
|
19
|
+
/** The operator by its id, and its version past the first. */
|
|
20
|
+
readonly named: string;
|
|
21
|
+
/** `operators`, the table that lacks it, names the versions of it that it does hold. */
|
|
22
|
+
constructor(operator: OperatorDescriptor, operators?: OperatorTable);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A run that reads `Expr.viewer` or `Expr.now` and was given no context. No
|
|
26
|
+
* row causes it, so `evaluateEach` refuses the run rather than each row.
|
|
27
|
+
*/
|
|
28
|
+
export declare class ContextMissingError extends QueryEvaluateError {
|
|
29
|
+
constructor(term: ViewerExpr<unknown> | NowExpr<unknown>, why: string);
|
|
30
|
+
}
|
|
31
|
+
/** What a conjunction fixes by field, and whether that is all it says (`Judge.pins`). */
|
|
32
|
+
export interface Pins {
|
|
33
|
+
readonly pins: Pinned;
|
|
34
|
+
readonly whole: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What a run given one row could not decide without another: a path's or an
|
|
38
|
+
* exists' row. It refuses rather than read the others as absent, which would
|
|
39
|
+
* drop a row from a list on no evidence. `Judge` reads them from a holder.
|
|
40
|
+
*/
|
|
41
|
+
export declare class RowsMissingError extends QueryEvaluateError {
|
|
42
|
+
constructor(reason: string);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A primitive operator over stored values, as a call of it is run: what a
|
|
46
|
+
* computed assignment comes to (`Write.apply`). Refused, as a call is, when
|
|
47
|
+
* `operators` does not implement it.
|
|
48
|
+
*/
|
|
49
|
+
export declare const applyOperator: (operator: OperatorDescriptor, values: ReadonlyArray<unknown>, options: {
|
|
50
|
+
readonly collation: Option.Option<Collation>;
|
|
51
|
+
readonly operators: MemoryOperators;
|
|
52
|
+
}) => unknown;
|
|
53
|
+
/** SQL's unknown: neither true nor false, and a row is kept only on true. */
|
|
54
|
+
type Truth = boolean | 'unknown';
|
|
55
|
+
/**
|
|
56
|
+
* What an operand comes to over no row: a call of literals and inputs, run by
|
|
57
|
+
* `operators` (the kernel's when not given), a predicate as its truth with
|
|
58
|
+
* unknown as null. How a conformance check asks an implementation one
|
|
59
|
+
* question; refuses what `evaluate` refuses (an operator the table lacks,
|
|
60
|
+
* text holding NUL).
|
|
61
|
+
*/
|
|
62
|
+
export declare const valueOfOperand: (node: Operandish, options?: {
|
|
63
|
+
readonly input?: Row | undefined;
|
|
64
|
+
readonly operators?: MemoryOperators | undefined;
|
|
65
|
+
readonly context?: ExprContext | undefined;
|
|
66
|
+
}) => unknown;
|
|
67
|
+
/** What a predicate comes to: SQL's three values, of which a row is kept only on `true`. */
|
|
68
|
+
export type PredicateTruth = Truth;
|
|
69
|
+
/**
|
|
70
|
+
* A predicate's truth from the input (and the context, when given) alone,
|
|
71
|
+
* when it reads no field; none when it reads one, or reads the context and
|
|
72
|
+
* none is given. An interpreter that runs per request decides such a
|
|
73
|
+
* predicate before it builds anything: `isNull($status)` is known before any
|
|
74
|
+
* row is. Refuses what `evaluate` refuses (text holding a NUL).
|
|
75
|
+
*/
|
|
76
|
+
export declare const decided: (node: Predicate, input: Row, operators?: MemoryOperators, context?: ExprContext) => Option.Option<PredicateTruth>;
|
|
77
|
+
/** A predicate's truth over one row (and, for an invariant, the row after a write): SQL's three values. */
|
|
78
|
+
export declare const truthOver: (node: Predicate, row: Row, input?: Row, next?: Row, operators?: MemoryOperators) => PredicateTruth;
|
|
79
|
+
/**
|
|
80
|
+
* What `Judge` comes to: known, or unknown because it rests on something the
|
|
81
|
+
* holder lacks. A known predicate's truth is SQL's three values, its
|
|
82
|
+
* `'unknown'` being SQL's null, which is decided: a row is not kept on it.
|
|
83
|
+
*/
|
|
84
|
+
export type Verdict<T = PredicateTruth> = {
|
|
85
|
+
readonly _tag: 'Known';
|
|
86
|
+
readonly truth: T;
|
|
87
|
+
} | {
|
|
88
|
+
readonly _tag: 'Unknown';
|
|
89
|
+
readonly reason: string;
|
|
90
|
+
};
|
|
91
|
+
/** What a verdict reads over, besides the row judged. */
|
|
92
|
+
interface JudgeOptions {
|
|
93
|
+
readonly input?: Row | undefined;
|
|
94
|
+
readonly operators?: MemoryOperators | undefined;
|
|
95
|
+
/** What `Expr.viewer` and `Expr.now` read; a predicate reading one refuses a run without it. */
|
|
96
|
+
readonly context?: ExprContext | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* The holder's rows, where a path from the viewer starts. Without them the
|
|
99
|
+
* viewer's row is not held, and such a path is unknown.
|
|
100
|
+
*/
|
|
101
|
+
readonly rows?: HeldRows | undefined;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The reference interpreter over what a holder has (`HeldRow`), three-valued:
|
|
105
|
+
* where an answer rests on a row or field the holder lacks or may not see, or
|
|
106
|
+
* on an operator only the server runs, it is unknown, and is never guessed.
|
|
107
|
+
* Where it is known, it is what SQL answers over the same rows: the law the
|
|
108
|
+
* conformance suite checks.
|
|
109
|
+
*/
|
|
110
|
+
export declare const Judge: {
|
|
111
|
+
/** A predicate over one held row, and, for an invariant, the row a write would leave. */
|
|
112
|
+
predicate: (predicate: Predicate, row: HeldRow, options?: JudgeOptions & {
|
|
113
|
+
readonly next?: HeldRow | undefined;
|
|
114
|
+
}) => Verdict;
|
|
115
|
+
/**
|
|
116
|
+
* Whether a held row is in a query's result: known when every predicate
|
|
117
|
+
* holds (in) or one fails or is null (out), unknown otherwise. `serverOnly`
|
|
118
|
+
* names a filter the server conjoins that this holder does not run (a Read
|
|
119
|
+
* rule, a source's own `where`): a row the body admits is then unknown, and
|
|
120
|
+
* one it refuses is still out. Refuses, as `evaluate` does, a given value
|
|
121
|
+
* holding a NUL.
|
|
122
|
+
*/
|
|
123
|
+
query: (body: AnyQuery, input: Row, row: HeldRow, options?: Omit<JudgeOptions, 'input'> & {
|
|
124
|
+
readonly serverOnly?: string | undefined;
|
|
125
|
+
}) => Verdict<boolean>;
|
|
126
|
+
/**
|
|
127
|
+
* What a conjunction fixes by field: each `eq` of a field and a literal, an
|
|
128
|
+
* input or the viewer, by the field's key, and whether that is all it says
|
|
129
|
+
* (`whole`), so every row holding those values satisfies it. A holder holding
|
|
130
|
+
* every row a `whole` list's body fixes this way holds every row an exists
|
|
131
|
+
* whose filter fixes the same values counts.
|
|
132
|
+
*/
|
|
133
|
+
pins: (predicates: ReadonlyArray<Predicate>, options?: {
|
|
134
|
+
readonly input?: Row | undefined;
|
|
135
|
+
readonly context?: ExprContext | undefined;
|
|
136
|
+
}) => Pins;
|
|
137
|
+
match: <T, A>(verdict: Verdict<T>, cases: {
|
|
138
|
+
readonly onKnown: (truth: T) => A;
|
|
139
|
+
readonly onUnknown: (reason: string) => A;
|
|
140
|
+
}) => A;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Where `left` sorts against `right` under these terms (`Query.orderFor`'s),
|
|
144
|
+
* as `evaluate` sorts: negative when it comes first. A call among them runs
|
|
145
|
+
* over each row with `input` and `operators` (the kernel's when not given).
|
|
146
|
+
* Refuses what `evaluate` refuses, for these two rows: a term over neither a
|
|
147
|
+
* field nor a call, a locale collation, keys of different kinds, or an
|
|
148
|
+
* operator the table lacks. For a client placing one row among others it
|
|
149
|
+
* holds.
|
|
150
|
+
*/
|
|
151
|
+
export declare const compareRows: (terms: ReadonlyArray<OrderTerm>, left: Row, right: Row, query: string, options?: {
|
|
152
|
+
readonly input?: Row | undefined;
|
|
153
|
+
readonly operators?: MemoryOperators | undefined;
|
|
154
|
+
readonly context?: ExprContext | undefined;
|
|
155
|
+
}) => number;
|
|
156
|
+
/**
|
|
157
|
+
* The operations this interpreter runs. It is the reference, so this is the
|
|
158
|
+
* whole kernel — but it is declared rather than assumed, because an
|
|
159
|
+
* interpreter that gains an operator and forgets to say so is exactly what
|
|
160
|
+
* `Query.unsupported` exists to catch.
|
|
161
|
+
*/
|
|
162
|
+
export declare const supported: ReadonlyArray<Operation>;
|
|
163
|
+
/**
|
|
164
|
+
* Refuses a body needing an operation this interpreter does not run, rather
|
|
165
|
+
* than skipping it and answering a different question. Called by `evaluate`;
|
|
166
|
+
* call it directly to check a body once instead of on every run.
|
|
167
|
+
*/
|
|
168
|
+
export declare const assertSupported: (body: AnyQuery, operators?: MemoryOperators) => void;
|
|
169
|
+
/**
|
|
170
|
+
* The rows the body matches, in the order it asks for. Pure: it reads the rows
|
|
171
|
+
* it is given and nothing else.
|
|
172
|
+
*
|
|
173
|
+
* `input` holds the values this run was given, by the keys the body's
|
|
174
|
+
* placeholders were built with — the same record the query would be called
|
|
175
|
+
* with anywhere else.
|
|
176
|
+
*/
|
|
177
|
+
export declare const evaluate: (body: AnyQuery, input: Row, rows: ReadonlyArray<Row>, options?: {
|
|
178
|
+
readonly operators?: MemoryOperators | undefined;
|
|
179
|
+
/** What `Expr.viewer` and `Expr.now` read; a body reading one refuses a run without it. */
|
|
180
|
+
readonly context?: ExprContext | undefined;
|
|
181
|
+
}) => ReadonlyArray<Row>;
|
|
182
|
+
/** What `evaluateEach` made of each row: those it matched, in order, and those it refused. */
|
|
183
|
+
export interface Evaluated {
|
|
184
|
+
readonly matched: ReadonlyArray<Row>;
|
|
185
|
+
readonly refused: ReadonlyArray<Row>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* As `evaluate`, with each row judged alone: a row whose own values are
|
|
189
|
+
* refused (text holding a NUL, a value an operator fails on) is set aside in
|
|
190
|
+
* `refused` and the others are still answered. A client judging the rows it
|
|
191
|
+
* holds wants this, since one bad stored row says nothing about the rest.
|
|
192
|
+
*
|
|
193
|
+
* What no single row causes still refuses the run: an operation or operator
|
|
194
|
+
* the table lacks, an order by a locale collation, an input the body reads
|
|
195
|
+
* holding a NUL (every row would refuse, and no row is the cause), and order
|
|
196
|
+
* keys of different kinds across rows.
|
|
197
|
+
*/
|
|
198
|
+
export declare const evaluateEach: (body: AnyQuery, input: Row, rows: ReadonlyArray<Row>, options?: {
|
|
199
|
+
readonly operators?: MemoryOperators | undefined;
|
|
200
|
+
/** As `evaluate`'s. */
|
|
201
|
+
readonly context?: ExprContext | undefined;
|
|
202
|
+
}) => Evaluated;
|
|
203
|
+
export {};
|
|
204
|
+
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","names":[],"sources":["../src/evaluate.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