foldkit-entity 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -6
- package/dist/conformance/index.d.mts +12 -1
- package/dist/conformance/index.d.mts.map +1 -1
- package/dist/conformance/index.mjs +218 -2
- package/dist/conformance/index.mjs.map +1 -1
- package/dist/index-DLz2yED-.d.mts +919 -0
- package/dist/index-DLz2yED-.d.mts.map +1 -0
- package/dist/index.d.mts +2 -642
- package/dist/index.mjs +2 -877
- package/dist/src-BAA6oWw-.mjs +1339 -0
- package/dist/src-BAA6oWw-.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,642 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/expr.d.ts
|
|
4
|
-
/** A constant the query was written with. */
|
|
5
|
-
export interface LiteralExpr<T> {
|
|
6
|
-
readonly _tag: 'Literal';
|
|
7
|
-
readonly value: T;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* One field of one Entity. `owner` is the Entity's identity rather than its
|
|
11
|
-
* name, so two Entities defined with the same name are not one column.
|
|
12
|
-
*/
|
|
13
|
-
export interface FieldExpr<T> {
|
|
14
|
-
readonly _tag: 'Field';
|
|
15
|
-
readonly owner: EntityIdentity<string>;
|
|
16
|
-
readonly key: string;
|
|
17
|
-
readonly schema: Schema.Codec<T, unknown>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* A value the query is given when it runs. A definition's body is built once,
|
|
21
|
-
* so inside it an input is this placeholder and never the value: there is
|
|
22
|
-
* nothing yet to branch on, and a query that wants to depend on what was passed
|
|
23
|
-
* says so with an operation over the placeholder.
|
|
24
|
-
*/
|
|
25
|
-
export interface InputExpr<T> {
|
|
26
|
-
readonly _tag: 'Input';
|
|
27
|
-
readonly key: string;
|
|
28
|
-
readonly schema: Schema.Codec<T, unknown>;
|
|
29
|
-
}
|
|
30
|
-
/** A typed scalar: what a comparison compares. */
|
|
31
|
-
export type Expr<T> = LiteralExpr<T> | FieldExpr<T> | InputExpr<T>;
|
|
32
|
-
/** Any scalar, for the places that hold operands without caring what they are. */
|
|
33
|
-
export type AnyExpr = Expr<unknown>;
|
|
34
|
-
/**
|
|
35
|
-
* `Expr<boolean>`, in the shape the operations that exist can actually take.
|
|
36
|
-
* The design's kernel is all boolean-valued (`eq`, `and`, `isNull`,
|
|
37
|
-
* `contains`, …), so a predicate is its own type rather than a phantom
|
|
38
|
-
* parameter on a general operation node: `Predicate` and `Expr<string>` cannot
|
|
39
|
-
* then be confused, which a structural phantom would allow. A scalar-valued
|
|
40
|
-
* operation, if one is ever needed, joins `Expr` instead.
|
|
41
|
-
*/
|
|
42
|
-
export type Predicate = EqPredicate | NullPredicate | ContainsPredicate;
|
|
43
|
-
/** Two values are the same. */
|
|
44
|
-
export interface EqPredicate {
|
|
45
|
-
readonly _tag: 'Eq';
|
|
46
|
-
readonly left: Operandish;
|
|
47
|
-
readonly right: Operandish;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Whether a value is absent. `present` says which answer absence gives, so one
|
|
51
|
-
* node covers `is null` and `is not null` rather than two that differ by a
|
|
52
|
-
* negation nothing else can express.
|
|
53
|
-
*/
|
|
54
|
-
export interface NullPredicate {
|
|
55
|
-
readonly _tag: 'Null';
|
|
56
|
-
readonly operand: AnyExpr;
|
|
57
|
-
readonly present: boolean;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Whether a text value contains another. Containing the empty string is
|
|
61
|
-
* everything, which is what lets a search box with nothing typed in it be the
|
|
62
|
-
* same query as one with something — see `Expr.contains`.
|
|
63
|
-
*/
|
|
64
|
-
export interface ContainsPredicate {
|
|
65
|
-
readonly _tag: 'Contains';
|
|
66
|
-
readonly value: AnyExpr;
|
|
67
|
-
readonly search: Operandish;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Anything an operation can be given: a scalar, or a predicate where a boolean
|
|
71
|
-
* is wanted. `Expr.eq(Expr.isNotNull(archivedAt), input.archived)` is the
|
|
72
|
-
* second case, and it is how a query depends on an input without branching on
|
|
73
|
-
* it.
|
|
74
|
-
*/
|
|
75
|
-
export type Operandish = AnyExpr | Predicate;
|
|
76
|
-
/** A field, a scalar already built from one, or a predicate used as a boolean. */
|
|
77
|
-
type Operand<T> = EntityField<string, string, Schema.Constraint> | Expr<T> | Predicate;
|
|
78
|
-
/** What an operand is worth, so a comparison's other side is checked against it. */
|
|
79
|
-
export type ValueOf<E> = E extends EntityField<string, string, infer S> ? Schema.Schema.Type<S> : E extends Predicate ? boolean : E extends Expr<infer T> ? T : never;
|
|
80
|
-
/**
|
|
81
|
-
* A field or scalar whose value is text, or absent text.
|
|
82
|
-
*
|
|
83
|
-
* `Expr.contains` is a case-insensitive **text** search that compiles to
|
|
84
|
-
* `lower(column) like lower(?)`. Over a number that is nonsense which reaches
|
|
85
|
-
* the database — SQLite coerces and answers something, Postgres raises — so
|
|
86
|
-
* the operand is constrained here rather than discovered there.
|
|
87
|
-
*
|
|
88
|
-
* Null belongs in the type, because a nullable text column is a real and
|
|
89
|
-
* documented case: a null contains nothing, not even the empty string, so its
|
|
90
|
-
* rows drop out of a search that would otherwise match everything.
|
|
91
|
-
*
|
|
92
|
-
* Written as a **constraint on the type parameter** rather than as a check
|
|
93
|
-
* intersected onto the parameter (the `Invalid` idiom `foldkit-remote` uses for
|
|
94
|
-
* an unregistered descriptor). That idiom compares an already-resolved indexed
|
|
95
|
-
* access; here the check would be a conditional over the type being inferred,
|
|
96
|
-
* and inference falls back to the constraint — whose `Expr<any>` branch makes
|
|
97
|
-
* the check vacuously true, so every operand passes. A constraint cannot be
|
|
98
|
-
* defeated that way.
|
|
99
|
-
*/
|
|
100
|
-
export type TextOperand = EntityField<string, string, Schema.Constraint & Schema.Codec<string | null, any, any, any>> | Expr<string> | Expr<string | null>;
|
|
101
|
-
/** Whether a value is a predicate, and so usable where a boolean is wanted. */
|
|
102
|
-
export declare const isPredicate: (value: unknown) => value is Predicate;
|
|
103
|
-
/**
|
|
104
|
-
* Every operation the kernel has. An interpreter declares which of them it
|
|
105
|
-
* runs, and a body needing one it does not is refused rather than answered
|
|
106
|
-
* wrongly — see `Query.unsupported`.
|
|
107
|
-
*/
|
|
108
|
-
export type Operation = 'eq' | 'isNull' | 'isNotNull' | 'contains';
|
|
109
|
-
/** One field an expression reads: its Entity's name and key, and the identity that owns it. */
|
|
110
|
-
export interface FieldDependency {
|
|
111
|
-
/** The owning Entity's name, for display; two Entities may share one. */
|
|
112
|
-
readonly entity: string;
|
|
113
|
-
readonly key: string;
|
|
114
|
-
/** Which Entity it is. Two defined with the same name are two entries. */
|
|
115
|
-
readonly owner: EntityIdentity<string>;
|
|
116
|
-
}
|
|
117
|
-
/** Which fields and inputs an expression reads, and which operations it uses. */
|
|
118
|
-
export interface Dependencies {
|
|
119
|
-
/** One entry per distinct field of each Entity identity. */
|
|
120
|
-
readonly fields: ReadonlyArray<FieldDependency>;
|
|
121
|
-
/** One entry per distinct input key. */
|
|
122
|
-
readonly inputs: ReadonlyArray<string>;
|
|
123
|
-
/** One entry per distinct operation, so an interpreter can refuse what it cannot run. */
|
|
124
|
-
readonly operations: ReadonlyArray<Operation>;
|
|
125
|
-
}
|
|
126
|
-
export declare const Expr: {
|
|
127
|
-
/** A constant. Comparisons coerce a plain value, so this is rarely written. */
|
|
128
|
-
literal: <T>(value: T) => LiteralExpr<T>;
|
|
129
|
-
/**
|
|
130
|
-
* A value the query is given when it runs. A definition builds these from its
|
|
131
|
-
* `Input` schema; written by hand only when constructing a body directly.
|
|
132
|
-
*/
|
|
133
|
-
input: <T>(key: string, schema: Schema.Codec<T, unknown>) => InputExpr<T>;
|
|
134
|
-
/** One field of one Entity, as a scalar. */
|
|
135
|
-
field: <Name extends string, Key extends string, S extends Schema.Constraint>(field: EntityField<Name, Key, S>) => FieldExpr<Schema.Schema.Type<S>>;
|
|
136
|
-
/**
|
|
137
|
-
* Two scalars are the same value. A field or a plain value on either side is
|
|
138
|
-
* coerced, so the common form reads as it means:
|
|
139
|
-
*
|
|
140
|
-
* ```ts
|
|
141
|
-
* Expr.eq(Post.fields.slug, input.slug)
|
|
142
|
-
* Expr.eq(Post.fields.status, 'active')
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
eq: <L extends Operand<any>>(left: L, right: ValueOf<L> | Expr<ValueOf<L>> | (boolean extends ValueOf<L> ? Predicate : never)) => EqPredicate;
|
|
146
|
-
/**
|
|
147
|
-
* Whether a field holds no value. Its opposite is `isNotNull`; both are the
|
|
148
|
-
* one node, because a query asks which of the two it means and nothing here
|
|
149
|
-
* can negate a predicate.
|
|
150
|
-
*/
|
|
151
|
-
isNull: <L extends Operand<any>>(operand: L) => NullPredicate;
|
|
152
|
-
/** Whether a field holds a value. */
|
|
153
|
-
isNotNull: <L extends Operand<any>>(operand: L) => NullPredicate;
|
|
154
|
-
/**
|
|
155
|
-
* Whether a text value contains `search`, anywhere in it. Containing the
|
|
156
|
-
* empty string is everything, so a search box with nothing typed in it is the
|
|
157
|
-
* same query as one with something — no branch, and no second query.
|
|
158
|
-
*
|
|
159
|
-
* **Case-insensitive**, which is what a search means, and which has to be
|
|
160
|
-
* said rather than left to the interpreter: SQLite's `like` ignores case and
|
|
161
|
-
* Postgres's does not, so a body that left it open would mean two things.
|
|
162
|
-
* Folding is ASCII-only, because that is what `lower` does in SQLite without
|
|
163
|
-
* ICU.
|
|
164
|
-
*
|
|
165
|
-
* **Over a column that can be null this is not the same as no filter.** A
|
|
166
|
-
* null contains nothing, not even the empty string, so its rows drop out. A
|
|
167
|
-
* nullable column that should match everything on an empty search says so:
|
|
168
|
-
* `Expr.or` does not exist yet, so for now such a column needs its own
|
|
169
|
-
* predicate or a native escape hatch.
|
|
170
|
-
*/
|
|
171
|
-
contains: <L extends TextOperand>(value: L, search: string | Expr<string>) => ContainsPredicate;
|
|
172
|
-
/** An expression as readable text; see `showExpr` for what it is and is not. */
|
|
173
|
-
show: (node: Operandish) => string;
|
|
174
|
-
};
|
|
175
|
-
/** One term of an ordering: a scalar and the direction to read it in. */
|
|
176
|
-
export interface OrderTerm {
|
|
177
|
-
readonly direction: 'asc' | 'desc';
|
|
178
|
-
readonly expr: AnyExpr;
|
|
179
|
-
}
|
|
180
|
-
export declare const Order: {
|
|
181
|
-
asc: <E extends Operand<any>>(expr: E) => OrderTerm;
|
|
182
|
-
desc: <E extends Operand<any>>(expr: E) => OrderTerm;
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* What an expression reads and uses, for the planner and for an interpreter
|
|
186
|
-
* deciding whether it can run this query at all. Distinct entries only, in the
|
|
187
|
-
* order first seen, so the answer is stable enough to assert on.
|
|
188
|
-
*/
|
|
189
|
-
export declare const dependenciesOf: (...nodes: ReadonlyArray<AnyExpr | Predicate | OrderTerm>) => Dependencies;
|
|
190
|
-
/**
|
|
191
|
-
* Which rows a query is about, as a value: an Entity to read, the predicates
|
|
192
|
-
* every row must satisfy, and the order to read them in. It says nothing about
|
|
193
|
-
* which fields to return — that is a Selection — and nothing about pagination,
|
|
194
|
-
* liveness, or whether absence is an error, which belong to the consumer's read
|
|
195
|
-
* rather than to the relation.
|
|
196
|
-
*
|
|
197
|
-
* Composing one performs no work. `Query.from(Post)` names no table and opens
|
|
198
|
-
* no connection; an interpreter turns the value into a query when something
|
|
199
|
-
* asks it to.
|
|
200
|
-
*/
|
|
201
|
-
export interface Query<E extends AnyEntity> extends Pipeable.Pipeable {
|
|
202
|
-
readonly _tag: 'Query';
|
|
203
|
-
readonly entity: E;
|
|
204
|
-
/**
|
|
205
|
-
* Every predicate holds: the list *is* the conjunction. Keeping it a list
|
|
206
|
-
* rather than folding it into one `and` is what makes each `where` a reusable
|
|
207
|
-
* fragment, and it means no `Expr.and` exists until a query needs a
|
|
208
|
-
* conjunction nested inside something else.
|
|
209
|
-
*/
|
|
210
|
-
readonly where: ReadonlyArray<Predicate>;
|
|
211
|
-
/** In order of significance; a later `orderBy` appends less significant terms. */
|
|
212
|
-
readonly orderBy: ReadonlyArray<OrderTerm>;
|
|
213
|
-
}
|
|
214
|
-
/** A `Query` over any Entity, for the places that hold one without caring which. */
|
|
215
|
-
export type AnyQuery = Query<AnyEntity>;
|
|
216
|
-
export declare const Query: {
|
|
217
|
-
/** Every row of an Entity: the query each transformation narrows. */
|
|
218
|
-
from: <E extends AnyEntity>(entity: E) => Query<E>;
|
|
219
|
-
/**
|
|
220
|
-
* Narrows to the rows the predicate holds for. Two `where`s conjoin — the
|
|
221
|
-
* second never replaces the first — so a fragment can be written once and
|
|
222
|
-
* piped into any query over the same Entity:
|
|
223
|
-
*
|
|
224
|
-
* ```ts
|
|
225
|
-
* const published = Query.where(Expr.eq(Post.fields.published, true))
|
|
226
|
-
* Query.from(Post).pipe(published, Query.where(byTitle))
|
|
227
|
-
* ```
|
|
228
|
-
*/
|
|
229
|
-
where: (...predicates: ReadonlyArray<Predicate>) => <E extends AnyEntity>(self: Query<E>) => Query<E>;
|
|
230
|
-
/**
|
|
231
|
-
* Reads the rows in this order. Two `orderBy`s append, so an earlier term
|
|
232
|
-
* stays the more significant one and a later call adds a tie-breaker rather
|
|
233
|
-
* than silently winning.
|
|
234
|
-
*/
|
|
235
|
-
orderBy: (...terms: ReadonlyArray<OrderTerm>) => <E extends AnyEntity>(self: Query<E>) => Query<E>;
|
|
236
|
-
/**
|
|
237
|
-
* What the whole query reads: the fields and inputs of every predicate and
|
|
238
|
-
* every ordering term, and the operations it uses.
|
|
239
|
-
*/
|
|
240
|
-
dependencies: (self: AnyQuery) => Dependencies;
|
|
241
|
-
/**
|
|
242
|
-
* The operations this query needs that `supported` does not list, in the
|
|
243
|
-
* order the query uses them. Empty means an interpreter declaring
|
|
244
|
-
* `supported` can answer it.
|
|
245
|
-
*
|
|
246
|
-
* An interpreter declares what it runs and refuses the rest, rather than
|
|
247
|
-
* ignoring an operation it does not implement — which would answer a
|
|
248
|
-
* different question and say nothing. The refusal is the interpreter's to
|
|
249
|
-
* raise: this only says what is missing, because what to do about it differs
|
|
250
|
-
* between one that compiles at registration and one that runs a body
|
|
251
|
-
* directly.
|
|
252
|
-
*
|
|
253
|
-
* ```ts
|
|
254
|
-
* const missing = Query.unsupported(body, ['eq', 'isNull', 'isNotNull'])
|
|
255
|
-
* if (missing.length > 0) throw new Error(`cannot run ${missing.join(', ')}`)
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
unsupported: (self: AnyQuery, supported: ReadonlyArray<Operation>) => ReadonlyArray<Operation>;
|
|
259
|
-
/**
|
|
260
|
-
* The whole query as readable text, one clause per line:
|
|
261
|
-
*
|
|
262
|
-
* ```text
|
|
263
|
-
* FROM Post
|
|
264
|
-
* WHERE Post.slug = $slug
|
|
265
|
-
* AND Post.published = true
|
|
266
|
-
* ORDER BY Post.updatedAt DESC
|
|
267
|
-
* ```
|
|
268
|
-
*
|
|
269
|
-
* For an explanation or a diagnostic, never for an interpreter — see
|
|
270
|
-
* `Expr.show`. A query with no `where` or no `orderBy` omits that line rather
|
|
271
|
-
* than printing an empty one, so what is shown is what was written.
|
|
272
|
-
*/
|
|
273
|
-
show: (self: AnyQuery) => string;
|
|
274
|
-
};
|
|
275
|
-
//#endregion
|
|
276
|
-
//#region src/words.d.ts
|
|
277
|
-
/** What a schema says of itself to a person: its `title` and `description`. */
|
|
278
|
-
export interface SchemaWords {
|
|
279
|
-
readonly title: Option.Option<string>;
|
|
280
|
-
readonly description: Option.Option<string>;
|
|
281
|
-
}
|
|
282
|
-
export declare const Words: {
|
|
283
|
-
/**
|
|
284
|
-
* A schema's words, as a label and its help text. Under Effect 4 a checked
|
|
285
|
-
* schema resolves to its last check's annotations, which say what the check
|
|
286
|
-
* expects and carry no `title`, so a title given before the check is read from
|
|
287
|
-
* the schema's own annotations. Read words through this, never through
|
|
288
|
-
* `Schema.resolveAnnotations` directly.
|
|
289
|
-
*/
|
|
290
|
-
of: (schema: Schema.Top) => SchemaWords;
|
|
291
|
-
};
|
|
292
|
-
//#endregion
|
|
293
|
-
//#region src/shape.d.ts
|
|
294
|
-
/** What a schema's AST holds, read through Effect's own guards. */
|
|
295
|
-
export declare const SchemaShape: {
|
|
296
|
-
/** True for the `null` and `undefined` members that make a schema optional. */
|
|
297
|
-
isNullish: (ast: SchemaAST.AST) => boolean;
|
|
298
|
-
/**
|
|
299
|
-
* The members of a schema with `null` and `undefined` set aside, so optional
|
|
300
|
-
* text is still text; a schema that is not a union is its one member.
|
|
301
|
-
*/
|
|
302
|
-
present: (ast: SchemaAST.AST) => ReadonlyArray<SchemaAST.AST>;
|
|
303
|
-
/** True when every value the schema admits is a string. */
|
|
304
|
-
isText: (ast: SchemaAST.AST) => boolean;
|
|
305
|
-
};
|
|
306
|
-
//#endregion
|
|
307
|
-
//#region src/evaluate.d.ts
|
|
308
|
-
/** A row as this interpreter reads one: values by field key. */
|
|
309
|
-
export type Row = Readonly<Record<string, unknown>>;
|
|
310
|
-
export declare class QueryEvaluateError extends Error {
|
|
311
|
-
constructor(message: string);
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* The operations this interpreter runs. It is the reference, so this is the
|
|
315
|
-
* whole kernel — but it is declared rather than assumed, because an
|
|
316
|
-
* interpreter that gains an operator and forgets to say so is exactly what
|
|
317
|
-
* `Query.unsupported` exists to catch.
|
|
318
|
-
*/
|
|
319
|
-
export declare const supported: ReadonlyArray<Operation>;
|
|
320
|
-
/**
|
|
321
|
-
* Refuses a body needing an operation this interpreter does not run, rather
|
|
322
|
-
* than skipping it and answering a different question. Called by `evaluate`;
|
|
323
|
-
* call it directly to check a body once instead of on every run.
|
|
324
|
-
*/
|
|
325
|
-
export declare const assertSupported: (body: AnyQuery) => void;
|
|
326
|
-
/**
|
|
327
|
-
* The rows the body matches, in the order it asks for. Pure: it reads the rows
|
|
328
|
-
* it is given and nothing else.
|
|
329
|
-
*
|
|
330
|
-
* `input` holds the values this run was given, by the keys the body's
|
|
331
|
-
* placeholders were built with — the same record the query would be called
|
|
332
|
-
* with anywhere else.
|
|
333
|
-
*/
|
|
334
|
-
export declare const evaluate: (body: AnyQuery, input: Row, rows: ReadonlyArray<Row>) => ReadonlyArray<Row>;
|
|
335
|
-
//#endregion
|
|
336
|
-
//#region src/index.d.ts
|
|
337
|
-
export declare const EntityTypeId: unique symbol;
|
|
338
|
-
export type EntityTypeId = typeof EntityTypeId;
|
|
339
|
-
/**
|
|
340
|
-
* What makes two descriptors the same Entity. A pipe step returns a new
|
|
341
|
-
* descriptor with the same identity, so compare `identity`, never the objects.
|
|
342
|
-
*/
|
|
343
|
-
export interface EntityIdentity<Name extends string> {
|
|
344
|
-
readonly name: Name;
|
|
345
|
-
/** Distinguishes two Entities that were defined with the same name. */
|
|
346
|
-
readonly token: symbol;
|
|
347
|
-
}
|
|
348
|
-
/** An intrinsic value of the Entity: one property of `entity.schema`. */
|
|
349
|
-
export interface EntityField<Name extends string, Key extends string, S extends Schema.Constraint> {
|
|
350
|
-
readonly _tag: 'Field';
|
|
351
|
-
readonly owner: EntityIdentity<Name>;
|
|
352
|
-
readonly key: Key;
|
|
353
|
-
readonly schema: S;
|
|
354
|
-
readonly metadata: Metadata;
|
|
355
|
-
}
|
|
356
|
-
export type Cardinality = 'one' | 'many';
|
|
357
|
-
/** What `Relation.one` / `Relation.many` return, before `Entity.relate` binds it to an owner. */
|
|
358
|
-
export interface RelationSpec<Target extends AnyEntity, C extends Cardinality, Optional extends boolean> {
|
|
359
|
-
readonly target: Target;
|
|
360
|
-
readonly cardinality: C;
|
|
361
|
-
readonly optional: Optional;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* A navigation edge as its owner sees it: one or many of `target`. How the edge
|
|
365
|
-
* is stored (a foreign key, a join table, a nested document) is the
|
|
366
|
-
* interpreter's concern.
|
|
367
|
-
*/
|
|
368
|
-
export interface EntityRelation<Name extends string, Key extends string, Target extends AnyEntity, C extends Cardinality, Optional extends boolean> {
|
|
369
|
-
readonly _tag: 'Relation';
|
|
370
|
-
readonly owner: EntityIdentity<Name>;
|
|
371
|
-
readonly key: Key;
|
|
372
|
-
/** The target as `Entity.relate` returned it, so its own relations can be followed. */
|
|
373
|
-
readonly target: () => Target;
|
|
374
|
-
readonly cardinality: C;
|
|
375
|
-
readonly optional: Optional;
|
|
376
|
-
readonly metadata: Metadata;
|
|
377
|
-
}
|
|
378
|
-
/** What `Derived.make` returns, before an Entity owns it. */
|
|
379
|
-
export interface DerivedSpec<S extends Schema.Constraint> {
|
|
380
|
-
readonly schema: S;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* A value consumers may read that is not part of `entity.schema`. It says
|
|
384
|
-
* nothing about how the value is computed; an interpreter supplies it.
|
|
385
|
-
*/
|
|
386
|
-
export interface EntityDerived<Name extends string, Key extends string, S extends Schema.Constraint> {
|
|
387
|
-
readonly _tag: 'Derived';
|
|
388
|
-
readonly owner: EntityIdentity<Name>;
|
|
389
|
-
readonly key: Key;
|
|
390
|
-
readonly schema: S;
|
|
391
|
-
readonly metadata: Metadata;
|
|
392
|
-
}
|
|
393
|
-
export type EntityMember = EntityField<string, string, Schema.Constraint> | EntityRelation<string, string, AnyEntity, Cardinality, boolean> | EntityDerived<string, string, Schema.Constraint>;
|
|
394
|
-
export type RelationSpecs = Readonly<Record<string, RelationSpec<AnyEntity, Cardinality, boolean>>>;
|
|
395
|
-
export type DerivedSpecs = Readonly<Record<string, DerivedSpec<Schema.Constraint>>>;
|
|
396
|
-
type FieldsOf<Name extends string, Fields extends Schema.Struct.Fields> = { readonly [K in keyof Fields & string]: EntityField<Name, K, Fields[K]>; };
|
|
397
|
-
type RelationsOf<Name extends string, Relations extends RelationSpecs> = { readonly [K in keyof Relations & string]: Relations[K] extends RelationSpec<infer Target, infer C, infer Optional> ? EntityRelation<Name, K, Target, C, Optional> : never; };
|
|
398
|
-
type DerivedOf<Name extends string, Derived extends DerivedSpecs> = { readonly [K in keyof Derived & string]: EntityDerived<Name, K, Derived[K]['schema']>; };
|
|
399
|
-
export interface Entity<Name extends string, Fields extends Schema.Struct.Fields, Relations extends RelationSpecs = {}, Derived extends DerivedSpecs = {}> extends Pipeable.Pipeable {
|
|
400
|
-
readonly [EntityTypeId]: EntityTypeId;
|
|
401
|
-
readonly identity: EntityIdentity<Name>;
|
|
402
|
-
readonly name: Name;
|
|
403
|
-
/** The intrinsic value only: no relations, no derived members. */
|
|
404
|
-
readonly schema: Schema.Struct<Fields>;
|
|
405
|
-
readonly fields: FieldsOf<Name, Fields>;
|
|
406
|
-
readonly relations: RelationsOf<Name, Relations>;
|
|
407
|
-
readonly derived: DerivedOf<Name, Derived>;
|
|
408
|
-
/** Every readable member under one namespace; keys never collide. */
|
|
409
|
-
readonly members: FieldsOf<Name, Fields> & RelationsOf<Name, Relations> & DerivedOf<Name, Derived>;
|
|
410
|
-
readonly metadata: Metadata;
|
|
411
|
-
}
|
|
412
|
-
export type AnyEntity = Entity<string, any, any, any>;
|
|
413
|
-
/** Unsatisfiable when a new key is already a member, so the pipe step is the error site. */
|
|
414
|
-
type Free<E extends AnyEntity, New> = keyof New & keyof E['members'] extends never ? unknown : {
|
|
415
|
-
readonly alreadyAMember: keyof New & keyof E['members'];
|
|
416
|
-
};
|
|
417
|
-
type WithDerived<E, New extends DerivedSpecs> = E extends Entity<infer Name, infer Fields, infer R, infer D> ? Entity<Name, Fields, R, D & New> : never;
|
|
418
|
-
export type Entities = Readonly<Record<string, AnyEntity>>;
|
|
419
|
-
export type RelationMap<Es extends Entities> = { readonly [K in keyof Es]?: RelationSpecs; };
|
|
420
|
-
/** The key in `Es` of the Entity a spec targets, matched by name. */
|
|
421
|
-
export type TargetKey<Es extends Entities, Target extends AnyEntity> = { [K in keyof Es]: [Es[K]['name'], Target['name']] extends [Target['name'], Es[K]['name']] ? K : never; }[keyof Es];
|
|
422
|
-
export type RelatedSpecs<Es extends Entities, Rs extends RelationMap<Es>, K extends keyof Es> = { readonly [R in keyof Rs[K]]: Rs[K][R] extends RelationSpec<infer Target, infer C, infer Optional> ? RelationSpec<Related<Es, Rs, TargetKey<Es, Target>>, C, Optional> : never; };
|
|
423
|
-
/**
|
|
424
|
-
* One Entity of an `Entity.relate` result. A relation's target is again a
|
|
425
|
-
* `Related`, so relations can be followed through a cycle; the recursion goes
|
|
426
|
-
* through type arguments, which TypeScript resolves only when asked.
|
|
427
|
-
*/
|
|
428
|
-
export type Related<Es extends Entities, Rs extends RelationMap<Es>, K extends keyof Es> = Es[K] extends Entity<infer Name, infer Fields, infer R, infer D> ? Entity<Name, Fields, R & RelatedSpecs<Es, Rs, K>, D> : never;
|
|
429
|
-
/** Marks a relation key that is already a member of its owner, or an owner that is not listed. */
|
|
430
|
-
type CheckRelations<Es extends Entities, Rs> = { readonly [K in keyof Rs]: K extends keyof Es ? { readonly [R in keyof Rs[K]]: R extends keyof Es[K]['members'] ? `"${R & string}" is already a member of ${Es[K]['name']}` : Rs[K][R]; } : 'not one of the entities being related'; };
|
|
431
|
-
export declare const SelectionTypeId: unique symbol;
|
|
432
|
-
export type SelectionTypeId = typeof SelectionTypeId;
|
|
433
|
-
/**
|
|
434
|
-
* The schema that identifies one of an Entity: its `id` field when that is text
|
|
435
|
-
* (a plain string, a brand, a pattern), and plain text otherwise. An id is text
|
|
436
|
-
* because a ref travels and is stored as text; an Entity keyed by a number still
|
|
437
|
-
* has refs, and their ids are the number as text.
|
|
438
|
-
*/
|
|
439
|
-
export type IdSchemaOf<E> = E extends {
|
|
440
|
-
readonly fields: {
|
|
441
|
-
readonly id: {
|
|
442
|
-
readonly schema: infer S;
|
|
443
|
-
};
|
|
444
|
-
};
|
|
445
|
-
} ? S extends Schema.Constraint ? [S['Type']] extends [string] ? S : Schema.String : Schema.String : Schema.String;
|
|
446
|
-
/** What identifies one of an Entity: `IdOf<typeof Blog.Post>` is `PostId` when its `id` field is one. */
|
|
447
|
-
export type IdOf<E> = IdSchemaOf<E>['Type'];
|
|
448
|
-
/**
|
|
449
|
-
* What a relation selected with `true` yields: which Entity, and which one. `Id`
|
|
450
|
-
* is the target's own id type, so a ref to an Author cannot be used as a Post's.
|
|
451
|
-
*/
|
|
452
|
-
export interface EntityRef<Name extends string = string, Id extends string = string> {
|
|
453
|
-
readonly entity: Name;
|
|
454
|
-
readonly id: Id;
|
|
455
|
-
}
|
|
456
|
-
type RefSchema<Target extends AnyEntity> = Schema.Struct<{
|
|
457
|
-
readonly entity: Schema.Literal<Target['name']>;
|
|
458
|
-
readonly id: IdSchemaOf<Target>;
|
|
459
|
-
}>;
|
|
460
|
-
/**
|
|
461
|
-
* A view of the Entity graph: which members to read, and the schema of the
|
|
462
|
-
* value that results. It says nothing about where the value comes from.
|
|
463
|
-
*/
|
|
464
|
-
export interface Selection<Name extends string, Members, S extends Schema.Constraint, Id extends string = string> {
|
|
465
|
-
readonly [SelectionTypeId]: SelectionTypeId;
|
|
466
|
-
/** Type-only: the id type of the Entity selected, so a reader can ask for the right one. Never set. */
|
|
467
|
-
readonly Id?: Id;
|
|
468
|
-
readonly entity: Entity<Name, any, any, any>;
|
|
469
|
-
/** What was selected, by member key: `true`, or a relation's nested Selection. */
|
|
470
|
-
readonly members: Members;
|
|
471
|
-
readonly schema: S;
|
|
472
|
-
}
|
|
473
|
-
type AnySelection<Name extends string = string> = Selection<Name, any, any>;
|
|
474
|
-
/** The value a Selection reads: `Selected<typeof PostCard>` is one card's fields. */
|
|
475
|
-
export type Selected<S extends Selection<string, unknown, Schema.Constraint>> = S['schema']['Type'];
|
|
476
|
-
/** `true` for any member; a relation also takes a Selection of its target. */
|
|
477
|
-
/**
|
|
478
|
-
* Which part of a `many` relation to read: the first or last so many, from a
|
|
479
|
-
* cursor or from the end. A cursor is whatever the interpreter handed out with an
|
|
480
|
-
* earlier page; nothing here looks inside it.
|
|
481
|
-
*/
|
|
482
|
-
export interface PageWindow {
|
|
483
|
-
readonly first?: number | undefined;
|
|
484
|
-
readonly last?: number | undefined;
|
|
485
|
-
readonly after?: string | undefined;
|
|
486
|
-
readonly before?: string | undefined;
|
|
487
|
-
}
|
|
488
|
-
export declare const SelectionPageTypeId: unique symbol;
|
|
489
|
-
export type SelectionPageTypeId = typeof SelectionPageTypeId;
|
|
490
|
-
/** A Selection of a `many` relation's target, read a page at a time. */
|
|
491
|
-
export interface SelectionPage<Name extends string, S extends Schema.Constraint> {
|
|
492
|
-
readonly [SelectionPageTypeId]: SelectionPageTypeId;
|
|
493
|
-
readonly selection: Selection<Name, any, S>;
|
|
494
|
-
readonly window: PageWindow;
|
|
495
|
-
}
|
|
496
|
-
type PageSchema<S extends Schema.Constraint> = Schema.Struct<{
|
|
497
|
-
readonly items: Schema.$Array<S>;
|
|
498
|
-
readonly hasNext: Schema.Boolean;
|
|
499
|
-
readonly hasPrevious: Schema.Boolean;
|
|
500
|
-
}>;
|
|
501
|
-
type SelectionSpec<E extends AnyEntity, Spec> = { readonly [K in keyof Spec]: K extends keyof E['relations'] ? E['relations'][K] extends EntityRelation<any, any, infer Target, infer C, any> ? true | AnySelection<Target['name']> | (C extends 'many' ? SelectionPage<Target['name'], any> : never) : never : K extends keyof E['members'] ? true : `"${K & string}" is not a member of ${E['name']}`; };
|
|
502
|
-
type RelationShape<C extends Cardinality, Optional extends boolean, S extends Schema.Constraint> = C extends 'many' ? Schema.$Array<S> : Optional extends true ? Schema.NullOr<S> : S;
|
|
503
|
-
type SelectedSchema<Member, Selected> = Member extends EntityField<any, any, infer S> | EntityDerived<any, any, infer S> ? S : Member extends EntityRelation<any, any, infer Target, infer C, infer Optional> ? Selected extends SelectionPage<any, infer S> ? PageSchema<S> : RelationShape<C, Optional, Selected extends Selection<any, any, infer S> ? S : RefSchema<Target>> : never;
|
|
504
|
-
type SelectionSchema<E extends AnyEntity, Spec> = Schema.Struct<{ readonly [K in keyof Spec & keyof E['members']]: SelectedSchema<E['members'][K], Spec[K]>; }>;
|
|
505
|
-
/** An input key that carries a relation's target: the id of a `one`, the ids of a `many`. */
|
|
506
|
-
export interface RelationInput<R extends EntityRelation<any, any, any, any, any>> {
|
|
507
|
-
readonly _tag: 'RelationInput';
|
|
508
|
-
readonly relation: R;
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* An input key that carries the relation's target itself, written through an
|
|
512
|
-
* input of its own: a post created with a new author, an order with its lines.
|
|
513
|
-
* A `one` holds that input's value, a `many` a list of them.
|
|
514
|
-
*/
|
|
515
|
-
export interface NestedInput<R extends EntityRelation<any, any, any, any, any>, I extends EntityInput<any, any, any>> {
|
|
516
|
-
readonly _tag: 'NestedInput';
|
|
517
|
-
readonly relation: R;
|
|
518
|
-
readonly input: I;
|
|
519
|
-
}
|
|
520
|
-
/** An input key that is about the operation, not the Entity: a reason, a flag, a confirmation. */
|
|
521
|
-
export interface Unmapped {
|
|
522
|
-
readonly _tag: 'Unmapped';
|
|
523
|
-
}
|
|
524
|
-
/** What one key of an operation's input means in terms of the Entity. */
|
|
525
|
-
export type InputMember = EntityField<string, string, Schema.Constraint> | RelationInput<EntityRelation<string, string, AnyEntity, Cardinality, boolean>> | NestedInput<EntityRelation<string, string, AnyEntity, Cardinality, boolean>, EntityInput<AnyEntity, any, any>> | Unmapped;
|
|
526
|
-
/** The ids a relation takes as input: one id, a nullable id, or a list of ids. */
|
|
527
|
-
type RelationIds<R> = R extends EntityRelation<any, any, infer Target, infer C, infer Optional> ? C extends 'many' ? ReadonlyArray<IdOf<Target>> : Optional extends true ? IdOf<Target> | null : IdOf<Target> : never;
|
|
528
|
-
/** What a nested input takes: the value of the target's input, or a list of them for a `many`. */
|
|
529
|
-
type NestedValues<R, I> = I extends EntityInput<any, infer Fields, any> ? R extends EntityRelation<any, any, any, 'many', any> ? ReadonlyArray<Schema.Struct.Type<Fields>> : Schema.Struct.Type<Fields> : never;
|
|
530
|
-
/**
|
|
531
|
-
* Only the value that is present has to fit: an input may leave a key out (a
|
|
532
|
-
* partial update) or send `null` to clear it. Whether it may is the input
|
|
533
|
-
* schema's rule; the fit only guards against mapping the wrong member.
|
|
534
|
-
*/
|
|
535
|
-
type Present<T> = Exclude<T, null | undefined>;
|
|
536
|
-
type MappingFor<Name extends string, Input, M> = M extends Unmapped ? M : M extends EntityField<infer Owner, any, any> | RelationInput<EntityRelation<infer Owner, any, any, any, any>> | NestedInput<EntityRelation<infer Owner, any, any, any, any>, any> ? [Owner] extends [Name] ? M extends EntityField<any, any, infer S> ? Present<Input> extends Schema.Schema.Type<S> ? M : 'the input value does not fit this field' : M extends RelationInput<infer R> ? Present<Input> extends RelationIds<R> ? M : 'the input value is not the id shape of this relation' : M extends NestedInput<infer R, infer I> ? R extends EntityRelation<any, any, infer Target, any, any> ? I extends EntityInput<infer Of, any, any> ? [Of['name']] extends [Target['name']] ? Present<Input> extends NestedValues<R, I> ? M : 'the input value is not the value of the nested input' : `the nested input is of ${Of['name']}, not ${Target['name']}` : never : never : never : `this member belongs to ${Owner}` : 'map an input key to a Field, Relation.input(relation), Relation.nested(relation, input), or Entity.unmapped';
|
|
537
|
-
/** A key that names a field whose value it fits maps itself; every other key needs an entry. */
|
|
538
|
-
type SelfMapped<E extends AnyEntity, Fields extends Schema.Struct.Fields> = { [K in keyof Fields]: K extends keyof E['fields'] ? Present<Schema.Schema.Type<Fields[K]>> extends Schema.Schema.Type<E['fields'][K]['schema']> ? K : never : never; }[keyof Fields];
|
|
539
|
-
/**
|
|
540
|
-
* A mapping written as a member's key: `'title'` is that Field, and `'author'` is
|
|
541
|
-
* `Relation.input` of that relation. Nothing is inferred from the input key's own
|
|
542
|
-
* name; the member is still named, only more briefly.
|
|
543
|
-
*/
|
|
544
|
-
type Named<E extends AnyEntity, M> = M extends string ? M extends keyof E['fields'] ? E['fields'][M] : M extends keyof E['relations'] ? RelationInput<E['relations'][M]> : `"${M}" names no field or relation of ${E['name']}` : M;
|
|
545
|
-
type InputMapping<E extends AnyEntity, Fields extends Schema.Struct.Fields, Mapping> = { readonly [K in Exclude<keyof Fields, SelfMapped<E, Fields>>]: unknown; } & { readonly [K in keyof Mapping]: K extends keyof Fields ? Named<E, Mapping[K]> extends (infer Member) ? Member extends string ? Member : MappingFor<E['name'], Schema.Schema.Type<Fields[K]>, Member> extends Member ? Mapping[K] : MappingFor<E['name'], Schema.Schema.Type<Fields[K]>, Member> : never : `"${K & string}" is not a key of the input`; };
|
|
546
|
-
type InputMembers<E extends AnyEntity, Fields extends Schema.Struct.Fields, Mapping> = { readonly [K in keyof Fields]: K extends keyof Mapping ? Named<E, Mapping[K]> : K extends keyof E['fields'] ? E['fields'][K] : never; };
|
|
547
|
-
/**
|
|
548
|
-
* An operation's input read against an Entity: which member each input key
|
|
549
|
-
* writes. The operation decides what may be submitted; the Entity only says
|
|
550
|
-
* what each submitted key means.
|
|
551
|
-
*/
|
|
552
|
-
export interface EntityInput<E extends AnyEntity, Fields extends Schema.Struct.Fields, Members> {
|
|
553
|
-
readonly entity: E;
|
|
554
|
-
readonly schema: Schema.Struct<Fields>;
|
|
555
|
-
readonly members: Members;
|
|
556
|
-
}
|
|
557
|
-
/** The Entity member an input key writes, by its key; nothing for an unmapped key. */
|
|
558
|
-
export type WrittenKey<M> = M extends EntityField<any, infer Key, any> ? Key : M extends RelationInput<EntityRelation<any, infer Key, any, any, any>> | NestedInput<EntityRelation<any, infer Key, any, any, any>, any> ? Key : never;
|
|
559
|
-
/** A nested input reads what it writes of the target; every other member reads as it is. */
|
|
560
|
-
export type WrittenAs<M> = M extends NestedInput<any, EntityInput<infer Of, any, infer Members>> ? Selection<Of['name'], WrittenSpec<Members>, SelectionSchema<Of, WrittenSpec<Members>>> : true;
|
|
561
|
-
/** Every member the input writes: what to read to show the input's current values. */
|
|
562
|
-
export type WrittenSpec<Members> = { readonly [K in keyof Members as WrittenKey<Members[K]>]: WrittenAs<Members[K]>; };
|
|
563
|
-
export declare const Entity: {
|
|
564
|
-
/** Declares an Entity from its intrinsic fields. Each call is a new identity. */
|
|
565
|
-
define: <const Name extends string, Fields extends Schema.Struct.Fields>(name: Name, schema: Schema.Struct<Fields>) => Entity<Name, Fields>;
|
|
566
|
-
/**
|
|
567
|
-
* Declares the relations between a set of Entities in one step, and returns
|
|
568
|
-
* them related. One step, because Entities that point at each other cannot
|
|
569
|
-
* each be declared in terms of the other.
|
|
570
|
-
*/
|
|
571
|
-
relate: <const Es extends Entities, const Rs extends RelationMap<Es>>(entities: Es, relations: Rs & CheckRelations<Es, Rs>) => { readonly [K in keyof Es]: Related<Es, Rs, K>; };
|
|
572
|
-
/**
|
|
573
|
-
* Selects members of an Entity and assembles the schema of the result. A
|
|
574
|
-
* relation selected with `true` yields an `EntityRef`; with a Selection of its
|
|
575
|
-
* target, that Selection's value. `many` yields an array, an optional `one`
|
|
576
|
-
* is nullable.
|
|
577
|
-
*/
|
|
578
|
-
select: <E extends AnyEntity, const Spec>(entity: E, spec: Spec & SelectionSpec<E, Spec>) => Selection<E["name"], Spec, SelectionSchema<E, Spec>, IdOf<E>>;
|
|
579
|
-
/**
|
|
580
|
-
* A `many` relation read a page at a time, in place of its Selection:
|
|
581
|
-
* `comments: Entity.page(CommentSummary, { first: 10 })`. The value is a page
|
|
582
|
-
* of the Selection's values: `items`, `hasNext`, `hasPrevious`. Reading on from a cursor is another window.
|
|
583
|
-
*/
|
|
584
|
-
page: <Name extends string, S extends Schema.Constraint>(selection: Selection<Name, any, S>, window: PageWindow) => SelectionPage<Name, S>;
|
|
585
|
-
/** Adds readable members that are not part of `entity.schema`. */
|
|
586
|
-
derived: <const New extends DerivedSpecs>(specs: New) => <E extends AnyEntity>(entity: E & Free<E, New>) => WithDerived<E, New>;
|
|
587
|
-
/** Attaches an interpreter's metadata to the Entity itself. */
|
|
588
|
-
annotate: (metadata: Metadata) => <E extends AnyEntity>(entity: E) => E;
|
|
589
|
-
/** Attaches an interpreter's metadata to members, by key. */
|
|
590
|
-
annotateMembers: <E extends AnyEntity>(metadata: { readonly [K in keyof E["members"]]?: Metadata; }) => (entity: E) => E;
|
|
591
|
-
/**
|
|
592
|
-
* Reads an operation's input schema against an Entity. A key that names a
|
|
593
|
-
* field maps to it; any other key is mapped explicitly, to a Field, to
|
|
594
|
-
* `Relation.input(relation)`, or to `Entity.unmapped`. Nothing is inferred
|
|
595
|
-
* from a naming convention such as `authorId`.
|
|
596
|
-
*/
|
|
597
|
-
input: <E extends AnyEntity, Fields extends Schema.Struct.Fields, const Mapping = {}>(entity: E, schema: Schema.Struct<Fields>, ...mapping: keyof InputMapping<E, Fields, Mapping> extends never ? [mapping?: Mapping & InputMapping<E, Fields, Mapping>] : [mapping: Mapping & InputMapping<E, Fields, Mapping>]) => EntityInput<E, Fields, InputMembers<E, Fields, Mapping>>;
|
|
598
|
-
/** For an input key that is about the operation rather than the Entity. */
|
|
599
|
-
unmapped: Unmapped;
|
|
600
|
-
/**
|
|
601
|
-
* The schemas of some of an Entity's fields, by key, to spread into an input's
|
|
602
|
-
* struct: `Schema.Struct({ ...Entity.fields(Post, 'id', 'title'), editorId: ... })`.
|
|
603
|
-
* The input then keeps the field's own rules, and its keys map themselves.
|
|
604
|
-
*/
|
|
605
|
-
fields: <E extends AnyEntity, const Keys extends ReadonlyArray<keyof E["fields"] & string>>(entity: E, ...keys: Keys) => { readonly [K in Keys[number]]: E["fields"][K]["schema"]; };
|
|
606
|
-
/**
|
|
607
|
-
* The Selection of every member an input writes, with each relation as refs:
|
|
608
|
-
* what an edit screen loads before it shows the input's current values.
|
|
609
|
-
*/
|
|
610
|
-
selectFor: <E extends AnyEntity, Fields extends Schema.Struct.Fields, Members>(input: EntityInput<E, Fields, Members>) => Selection<E["name"], WrittenSpec<Members>, SelectionSchema<E, WrittenSpec<Members>>, IdOf<E>>;
|
|
611
|
-
/**
|
|
612
|
-
* The input values that reproduce `value`, a value read through `selectFor`
|
|
613
|
-
* (or any Selection with those members): a field as it is, a relation as the
|
|
614
|
-
* id or ids of its refs. A key whose member `value` lacks is left out, as is
|
|
615
|
-
* an unmapped key, which the Entity knows nothing about.
|
|
616
|
-
*/
|
|
617
|
-
valuesFor: <E extends AnyEntity, Fields extends Schema.Struct.Fields, Members>(input: EntityInput<E, Fields, Members>, value: Readonly<Record<string, unknown>>) => Partial<Schema.Struct.Type<Fields>>;
|
|
618
|
-
is: (value: unknown) => value is AnyEntity;
|
|
619
|
-
/** True when both descriptors are versions of one Entity. */
|
|
620
|
-
same: (left: AnyEntity, right: AnyEntity) => boolean;
|
|
621
|
-
};
|
|
622
|
-
declare function one<Target extends AnyEntity>(target: Target): RelationSpec<Target, 'one', false>;
|
|
623
|
-
declare function one<Target extends AnyEntity, const Optional extends boolean>(target: Target, options: {
|
|
624
|
-
readonly optional: Optional;
|
|
625
|
-
}): RelationSpec<Target, 'one', Optional>;
|
|
626
|
-
/** What the owner sees: one or many of `target`. Used inside `Entity.relate`. */
|
|
627
|
-
export declare const Relation: {
|
|
628
|
-
one: typeof one;
|
|
629
|
-
/** For `Entity.input`: the input key holds this relation's target id, or ids for a `many`. */
|
|
630
|
-
input: <R extends EntityRelation<any, any, any, any, any>>(relation: R) => RelationInput<R>;
|
|
631
|
-
/**
|
|
632
|
-
* For `Entity.input`: the input key holds the relation's target itself, written
|
|
633
|
-
* through `input`, an `Entity.input` of the target. A `many` holds a list.
|
|
634
|
-
*/
|
|
635
|
-
nested: <R extends EntityRelation<any, any, any, any, any>, I extends EntityInput<any, any, any>>(relation: R, input: I) => NestedInput<R, I>;
|
|
636
|
-
many: <Target extends AnyEntity>(target: Target) => RelationSpec<Target, "many", false>;
|
|
637
|
-
};
|
|
638
|
-
export declare const Derived: {
|
|
639
|
-
make: <S extends Schema.Constraint>(schema: S) => DerivedSpec<S>;
|
|
640
|
-
};
|
|
641
|
-
//#endregion
|
|
642
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { $ as AnyExpr, A as SelectionPage, B as Write, C as Relation, Ct as TextOperand, D as RelationSpecs, Dt as maxQueryNodes, E as RelationSpec, Et as isPredicate, F as WrittenAs, G as assertSupported, H as WriteSet, I as WrittenKey, J as supported, K as compareRows, L as WrittenSpec, M as SelectionTypeId, N as TargetKey, O as Selected, Ot as Collation, P as Unmapped, Q as ReadFilter, R as AnyWrite, S as RelatedSpecs, St as TermOptions, T as RelationMap, Tt as dependenciesOf, U as QueryEvaluateError, V as WriteLink, W as Row, X as SchemaWords, Y as SchemaShape, Z as Words, _ as IdSchemaOf, _t as Ordering, a as DerivedSpecs, at as EqPredicate, b as PageWindow, bt as Query, c as EntityDerived, ct as FieldExpr, d as EntityInput, dt as LiteralExpr, et as AnyQuery, f as EntityMember, ft as NullPredicate, g as IdOf, gt as OrderTerm, h as EntityTypeId, ht as Order, i as DerivedSpec, it as Dependencies, j as SelectionPageTypeId, k as Selection, l as EntityField, lt as InPredicate, m as EntityRelation, mt as Operation, n as Cardinality, nt as ChosenSort, o as Entities, ot as Expr, p as EntityRef, pt as Operandish, q as evaluate, r as Derived, rt as ContainsPredicate, s as Entity, st as FieldDependency, t as AnyEntity, tt as ChosenOrder, u as EntityIdentity, ut as InputExpr, v as InputMember, vt as Placement, w as RelationInput, wt as ValueOf, x as Related, xt as QueryDependencies, y as NestedInput, yt as Predicate, z as BoundWrite } from "./index-DLz2yED-.mjs";
|
|
2
|
+
export { AnyEntity, AnyExpr, AnyQuery, type AnyWrite, type BoundWrite, Cardinality, ChosenOrder, ChosenSort, Collation, ContainsPredicate, Dependencies, Derived, DerivedSpec, DerivedSpecs, Entities, Entity, EntityDerived, EntityField, EntityIdentity, EntityInput, EntityMember, EntityRef, EntityRelation, EntityTypeId, EqPredicate, Expr, FieldDependency, FieldExpr, IdOf, IdSchemaOf, InPredicate, InputExpr, InputMember, LiteralExpr, NestedInput, NullPredicate, Operandish, Operation, Order, OrderTerm, Ordering, PageWindow, Placement, Predicate, Query, QueryDependencies, QueryEvaluateError, ReadFilter, Related, RelatedSpecs, Relation, RelationInput, RelationMap, RelationSpec, RelationSpecs, Row, SchemaShape, SchemaWords, Selected, Selection, SelectionPage, SelectionPageTypeId, SelectionTypeId, TargetKey, TermOptions, TextOperand, Unmapped, ValueOf, Words, Write, type WriteLink, type WriteSet, WrittenAs, WrittenKey, WrittenSpec, assertSupported, compareRows, dependenciesOf, evaluate, isPredicate, maxQueryNodes, supported };
|