simetra 0.2.0 → 0.3.0-next.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/dist/channel-grant-BATD6oQu.js +15 -0
- package/dist/compiler/index.d.ts +684 -77
- package/dist/compiler/index.js +24598 -13501
- package/dist/data/centrifugo/index.d.ts +24 -0
- package/dist/data/centrifugo/index.js +173 -0
- package/dist/data/index.d.ts +27 -0
- package/dist/data/index.js +9779 -0
- package/dist/data/react/index.d.ts +103 -0
- package/dist/data/react/index.js +214 -0
- package/dist/grant-Zg0hmqK7.d.ts +11 -0
- package/dist/handle-C6PFsnUX.js +44 -0
- package/dist/holder-CkR-qRYU.d.ts +585 -0
- package/dist/model/index.d.ts +4118 -476
- package/dist/model/index.js +4267 -380
- package/dist/schema/index.d.ts +1523 -572
- package/dist/schema/index.js +11698 -7402
- package/dist/server/index.d.ts +665 -21
- package/dist/server/index.js +4279 -426
- package/dist/server/signals/index.d.ts +92 -0
- package/dist/server/signals/index.js +140 -0
- package/dist/shell/index.d.ts +100 -0
- package/dist/shell/index.js +148 -0
- package/dist/ui/index.d.ts +213 -0
- package/dist/ui/index.js +1075 -0
- package/package.json +74 -3
- package/schemas/accumulation-registers.schema.json +46 -5
- package/schemas/catalogs.schema.json +110 -7
- package/schemas/constants.schema.json +31 -5
- package/schemas/custom-tables.schema.json +24 -0
- package/schemas/documents.schema.json +83 -5
- package/schemas/functions.schema.json +129 -0
- package/schemas/information-registers.schema.json +47 -5
- package/schemas/project.schema.json +11 -1
- package/schemas/rights-sets.schema.json +3 -1
- package/schemas/roles.schema.json +6 -2
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import { CatalogEntry, CatalogEntryAttribute, CatalogIndex, CommandError, DataRequest, DataTransport, Filter, MetadataRef, Operation, OrderBy, ReadQuery, RightsSnapshot, SignalTransport, SourceAdapter, WireReadPart, WireReadParts } from "simetra/model";
|
|
2
|
+
/**
|
|
3
|
+
* Codes of a developer error in T4 (P4-B spec §6, §7): a misuse of the data
|
|
4
|
+
* runtime, not a refusal of the server — those come as `CommandFailure`.
|
|
5
|
+
*/
|
|
6
|
+
type DataErrorCode = "data.unsupported-predicate" | "data.version-required" | "data.tabular-incomplete" | "data.full-too-large" | "data.views-limit" | "data.journal-full" | "data.mutation-pending";
|
|
7
|
+
/** A developer error of the data runtime; `message` defaults to the code. */
|
|
8
|
+
declare class DataError extends Error {
|
|
9
|
+
readonly code: DataErrorCode;
|
|
10
|
+
constructor(code: DataErrorCode, message?: string);
|
|
11
|
+
}
|
|
12
|
+
/** Logical object name: `"<kind>.<name>"`. */
|
|
13
|
+
type ObjectName = string;
|
|
14
|
+
/** Row key: a UUID string. */
|
|
15
|
+
type Key = string;
|
|
16
|
+
/** Column values of a row, by logical field name. */
|
|
17
|
+
type Values = Readonly<Record<string, unknown>>;
|
|
18
|
+
/** A confirmed server row: key and version are taken from its values. */
|
|
19
|
+
interface ServerRow {
|
|
20
|
+
readonly key: Key;
|
|
21
|
+
readonly version: number;
|
|
22
|
+
/**
|
|
23
|
+
* The row version epoch of the database that answered (P4-B spec §6.2);
|
|
24
|
+
* absent or `null` — the database has none, so versions compare as usual.
|
|
25
|
+
*/
|
|
26
|
+
readonly versionEpoch?: string | null;
|
|
27
|
+
readonly values: Values;
|
|
28
|
+
/**
|
|
29
|
+
* Set on a row a `known` marker stands for (P4-B spec §6.7): the held row
|
|
30
|
+
* the request was built from. Such a row confirms the held one — the
|
|
31
|
+
* store applies it as a marker, never as new values.
|
|
32
|
+
*/
|
|
33
|
+
readonly marker?: ServerRow;
|
|
34
|
+
}
|
|
35
|
+
/** A row of a tabular section of an owner. */
|
|
36
|
+
interface SectionLine {
|
|
37
|
+
readonly key: Key;
|
|
38
|
+
readonly values: Values;
|
|
39
|
+
}
|
|
40
|
+
/** What a view reads (P4-B spec §6.2). */
|
|
41
|
+
type ViewSpec = {
|
|
42
|
+
kind: "keys";
|
|
43
|
+
object: ObjectName;
|
|
44
|
+
keys: readonly Key[];
|
|
45
|
+
} | {
|
|
46
|
+
kind: "card";
|
|
47
|
+
object: ObjectName;
|
|
48
|
+
key: Key;
|
|
49
|
+
/** Single-target `Ref` attributes whose target rows are read with the card. */
|
|
50
|
+
include?: readonly string[];
|
|
51
|
+
} | {
|
|
52
|
+
kind: "section";
|
|
53
|
+
object: ObjectName;
|
|
54
|
+
owner: Key;
|
|
55
|
+
section: string;
|
|
56
|
+
} | {
|
|
57
|
+
kind: "full";
|
|
58
|
+
object: ObjectName;
|
|
59
|
+
where?: Filter;
|
|
60
|
+
orderBy?: OrderBy;
|
|
61
|
+
include?: readonly string[];
|
|
62
|
+
} | {
|
|
63
|
+
kind: "window";
|
|
64
|
+
object: ObjectName;
|
|
65
|
+
where?: Filter;
|
|
66
|
+
orderBy?: OrderBy;
|
|
67
|
+
include?: readonly string[];
|
|
68
|
+
};
|
|
69
|
+
/** Row state vocabulary (P4-B spec §6.5). */
|
|
70
|
+
type RowState = "synced" | "pending" | "failed" | "conflict" | "unknown" | "stale" | "removed";
|
|
71
|
+
/** The state of an own mutation in the journal (P4-B spec §6.5). */
|
|
72
|
+
type MutationState = "pending" | "failed" | "conflict" | "unknown";
|
|
73
|
+
/** What a mutation settled with (P4-B spec §7.1); `settled` never rejects. */
|
|
74
|
+
type MutationResult = {
|
|
75
|
+
readonly ok: true;
|
|
76
|
+
/**
|
|
77
|
+
* One row per operation: the confirmed row, or `undefined` when the
|
|
78
|
+
* answer carried none that could be shown — no `rows`, a key with a
|
|
79
|
+
* tombstone or a mark newer than the attempt, a re-read that failed.
|
|
80
|
+
*/
|
|
81
|
+
readonly rows: readonly (ServerRow | undefined)[];
|
|
82
|
+
} |
|
|
83
|
+
/**
|
|
84
|
+
* A refusal: of the server or the transport (`CommandError`), or of the
|
|
85
|
+
* write state before the transport — `DataError` `data.mutation-pending`,
|
|
86
|
+
* `data.journal-full` (P4-B spec §7.1).
|
|
87
|
+
*/
|
|
88
|
+
{
|
|
89
|
+
readonly ok: false;
|
|
90
|
+
readonly error: CommandError | DataError;
|
|
91
|
+
};
|
|
92
|
+
/** One logical mutation of the data writer (P4-B spec §7.1). */
|
|
93
|
+
interface Mutation {
|
|
94
|
+
/** A local id of this attempt, not the `mutationId` of the envelope. */
|
|
95
|
+
readonly id: string;
|
|
96
|
+
readonly settled: Promise<MutationResult>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The own mutation of a row with the actions its state allows (P4-B spec
|
|
100
|
+
* §6.5): `failed` — `retry`, `cancel`; `conflict` — `cancel`; `unknown` —
|
|
101
|
+
* `dismiss`; a `removed` row — `cancel` (`dismiss` for `unknown`). `retry`
|
|
102
|
+
* is absent while the values are hidden and after a purge or `removed`
|
|
103
|
+
* erased the fields of the mutation.
|
|
104
|
+
*/
|
|
105
|
+
interface RowMutation {
|
|
106
|
+
readonly id: string;
|
|
107
|
+
readonly state: MutationState;
|
|
108
|
+
readonly error?: CommandError;
|
|
109
|
+
/**
|
|
110
|
+
* A new attempt with the same fields and base; `undefined` when the
|
|
111
|
+
* mutation is no longer the one this view showed.
|
|
112
|
+
*/
|
|
113
|
+
readonly retry?: () => Mutation | undefined;
|
|
114
|
+
/** Drops the mutation: the row shows the confirmed values again. */
|
|
115
|
+
readonly cancel?: () => void;
|
|
116
|
+
/** Drops an `unknown` mutation from the row. */
|
|
117
|
+
readonly dismiss?: () => void;
|
|
118
|
+
}
|
|
119
|
+
/** A row as a view shows it; `removed` keeps the place without values. */
|
|
120
|
+
type RowView = {
|
|
121
|
+
readonly key: Key;
|
|
122
|
+
readonly state: "removed";
|
|
123
|
+
readonly mutation?: RowMutation;
|
|
124
|
+
} | {
|
|
125
|
+
readonly key: Key;
|
|
126
|
+
readonly version: number;
|
|
127
|
+
readonly values: Values;
|
|
128
|
+
readonly state: Exclude<RowState, "removed">;
|
|
129
|
+
readonly staleFields: readonly string[];
|
|
130
|
+
/**
|
|
131
|
+
* The values are hidden by a mark (the eviction horizon or `Writer.hide`)
|
|
132
|
+
* until a read that started after it; a form shows no draft meanwhile.
|
|
133
|
+
* A row hydrated from an SSR snapshot has no facts of the row: its
|
|
134
|
+
* `version` is the sentinel 0 and it carries no `stale`; the UI must not
|
|
135
|
+
* read either while `hidden` is set.
|
|
136
|
+
*/
|
|
137
|
+
readonly hidden?: true;
|
|
138
|
+
/**
|
|
139
|
+
* The stored row carries a stale mark — a version below the known one,
|
|
140
|
+
* a version epoch switch not proved since, or a signal gap — whatever
|
|
141
|
+
* `state` shows: a mutation state takes precedence over `stale` (§6.5),
|
|
142
|
+
* the fact stays here. A `hide` is the separate fact `hidden`.
|
|
143
|
+
*/
|
|
144
|
+
readonly stale?: true;
|
|
145
|
+
/** The own mutation of the row; its state is `state` unless hidden. */
|
|
146
|
+
readonly mutation?: RowMutation;
|
|
147
|
+
readonly refs?: Readonly<Record<string, RowView | null>>;
|
|
148
|
+
};
|
|
149
|
+
/** Why a session or view was closed. */
|
|
150
|
+
type CloseReason = "connection-refused" | "disposed" | "session-changed" | "signed-out" | "subject-changed";
|
|
151
|
+
/** The immutable snapshot of one view. */
|
|
152
|
+
interface ViewSnapshot {
|
|
153
|
+
readonly status: "loading" | "ready" | "refreshing" | "error" | "purged";
|
|
154
|
+
/** A server refusal, or a developer error found while loading (`data.full-too-large`). */
|
|
155
|
+
readonly error?: CommandError | DataError;
|
|
156
|
+
readonly reason?: CloseReason | "access-changed";
|
|
157
|
+
readonly rows: readonly RowView[];
|
|
158
|
+
readonly hasNewRows: boolean;
|
|
159
|
+
readonly needsRefresh: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* The object of the view is marked stale (P4-B spec §10): the server
|
|
162
|
+
* contract of its kernel differs from this build, no write to it passes.
|
|
163
|
+
* Sticky until the page reloads. Present only while true; not to be
|
|
164
|
+
* confused with a `stale` row.
|
|
165
|
+
*/
|
|
166
|
+
readonly isStale?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* The composition of the view is not confirmed (P4-B spec §6.5, §8.4): a
|
|
169
|
+
* create, a delete or an edit may have been missed — after a gap of a
|
|
170
|
+
* channel of its object (cleared by the first successful read that started
|
|
171
|
+
* at or after the channel's next join), or while the requirement «not
|
|
172
|
+
* confirmed since e» stands (cleared only by a successful read with
|
|
173
|
+
* `readEpoch ≥ e`). Any view kind, visible or not. Present only while
|
|
174
|
+
* true; not a row's `stale`.
|
|
175
|
+
*/
|
|
176
|
+
readonly staleComposition?: true;
|
|
177
|
+
readonly section?: {
|
|
178
|
+
readonly ownerVersion: number | undefined;
|
|
179
|
+
readonly complete: boolean;
|
|
180
|
+
readonly lines: readonly SectionLine[];
|
|
181
|
+
/**
|
|
182
|
+
* The state of the owner header, from the row state vocabulary: `removed`
|
|
183
|
+
* (no lines shown), `stale`, `unknown` when the store has no header.
|
|
184
|
+
*/
|
|
185
|
+
readonly ownerState: RowState;
|
|
186
|
+
};
|
|
187
|
+
readonly strategy?: "full" | "window";
|
|
188
|
+
readonly truncated?: boolean;
|
|
189
|
+
readonly atEnd?: boolean;
|
|
190
|
+
/** Window only: the list starts at the first row of the sort order. */
|
|
191
|
+
readonly atStart?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Window only: the number of the composition. It changes only together
|
|
194
|
+
* with a new composition (P4-B spec §6.4), so a list host remounts by it.
|
|
195
|
+
*/
|
|
196
|
+
readonly chain?: number;
|
|
197
|
+
/** Window only: where the host scrolls when a new chain replaces the old one. */
|
|
198
|
+
readonly target?: "start" | "end" | "keep";
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* A row of a core snapshot (P4-B spec §6.6). A row with values is a tuple
|
|
202
|
+
* `[values, extra?]`: its key and version are the key and version fields of
|
|
203
|
+
* `values`, so nothing is repeated. A `removed` or `hidden` slot carries no
|
|
204
|
+
* values and no facts of the row (a slot keeps the place, nothing more):
|
|
205
|
+
* the HTML and the first client frame show the same composition without a
|
|
206
|
+
* value leaving the server.
|
|
207
|
+
*/
|
|
208
|
+
type RowSlot = readonly [values: Values] | readonly [values: Values, extra: RowSlotExtra] | {
|
|
209
|
+
readonly key: Key;
|
|
210
|
+
readonly state: "removed";
|
|
211
|
+
readonly scope: string | null;
|
|
212
|
+
} | {
|
|
213
|
+
readonly key: Key;
|
|
214
|
+
readonly state: "hidden";
|
|
215
|
+
readonly scope: string | null;
|
|
216
|
+
};
|
|
217
|
+
/** What a row slot adds to its values; absent when it is all the default. */
|
|
218
|
+
interface RowSlotExtra {
|
|
219
|
+
/** The version epoch of the row, when it is not the object's `epoch`. */
|
|
220
|
+
readonly epoch?: string | null;
|
|
221
|
+
/** The row version each lazy field was read with. */
|
|
222
|
+
readonly lazy?: Readonly<Record<string, number>>;
|
|
223
|
+
/** The version epoch of a lazy field, when it is not the row's. */
|
|
224
|
+
readonly lazyIn?: Readonly<Record<string, string | null>>;
|
|
225
|
+
/** The row carries a stale mark (the epochs of the marks stay on the server). */
|
|
226
|
+
readonly stale?: true;
|
|
227
|
+
}
|
|
228
|
+
/** The rows of one object in a core snapshot. */
|
|
229
|
+
interface ObjectSnapshot {
|
|
230
|
+
/** The version epoch most rows are in; a slot names its own when it differs. */
|
|
231
|
+
readonly epoch: string | null;
|
|
232
|
+
readonly slots: readonly RowSlot[];
|
|
233
|
+
}
|
|
234
|
+
/** One tabular section of one owner in a core snapshot. */
|
|
235
|
+
interface SectionSnapshot {
|
|
236
|
+
readonly owner: Key;
|
|
237
|
+
readonly section: string;
|
|
238
|
+
/** The values of the lines, in order; a line key is the section's key field. */
|
|
239
|
+
readonly lines: readonly Values[];
|
|
240
|
+
readonly ownerVersion: number;
|
|
241
|
+
readonly epoch: string | null;
|
|
242
|
+
readonly complete: boolean;
|
|
243
|
+
/** The scope of the owner when the lines were read; `"unknown"` — no header then. */
|
|
244
|
+
readonly scope: string | null;
|
|
245
|
+
/** A `null` answer after an epoch switch was not ordered with the lines. */
|
|
246
|
+
readonly stale?: true;
|
|
247
|
+
}
|
|
248
|
+
/** The cursor of a window page edge: the sort columns and the key of a row. */
|
|
249
|
+
interface CursorSnapshot {
|
|
250
|
+
readonly values: Values;
|
|
251
|
+
readonly key: Key;
|
|
252
|
+
}
|
|
253
|
+
/** The lower bound a window page was read with (P4-B spec §6.4). */
|
|
254
|
+
type LowerSnapshot = {
|
|
255
|
+
readonly kind: "start";
|
|
256
|
+
} | {
|
|
257
|
+
readonly kind: "after" | "from";
|
|
258
|
+
readonly cursor: CursorSnapshot;
|
|
259
|
+
};
|
|
260
|
+
/** The pages of a window in a core snapshot: counts of rows, not keys. */
|
|
261
|
+
interface WindowSnapshot {
|
|
262
|
+
readonly pages: readonly {
|
|
263
|
+
readonly size: number;
|
|
264
|
+
readonly lower: LowerSnapshot;
|
|
265
|
+
readonly generation: number;
|
|
266
|
+
}[];
|
|
267
|
+
readonly chain: number;
|
|
268
|
+
readonly target: "start" | "end" | "keep";
|
|
269
|
+
readonly atStart: boolean;
|
|
270
|
+
readonly generation: number;
|
|
271
|
+
readonly frontier: {
|
|
272
|
+
readonly after?: CursorSnapshot;
|
|
273
|
+
readonly before?: CursorSnapshot;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* A ready held view in a core snapshot. `layout` and `unshown` are runs
|
|
278
|
+
* `[start, length, …]` of indices into `objects[spec.object].slots`: the
|
|
279
|
+
* rows of the composition in list order, and the rows the view owns without
|
|
280
|
+
* showing (a `full` filter drops them locally). The `include` targets are not
|
|
281
|
+
* listed: they follow from the values of the rows.
|
|
282
|
+
*/
|
|
283
|
+
interface SubsetSnapshot {
|
|
284
|
+
readonly spec: ViewSpec;
|
|
285
|
+
readonly layout?: readonly number[];
|
|
286
|
+
readonly unshown?: readonly number[];
|
|
287
|
+
readonly window?: WindowSnapshot;
|
|
288
|
+
/** `full` and `window` forms: the list reached the end of the order. */
|
|
289
|
+
readonly atEnd?: boolean;
|
|
290
|
+
readonly truncated?: true;
|
|
291
|
+
/**
|
|
292
|
+
* Section views only: the state of the owner header when the store holds
|
|
293
|
+
* it but no row of the snapshot carries it (the header belongs to a view
|
|
294
|
+
* that is not ready), so `ownerState` is the same on both sides.
|
|
295
|
+
*/
|
|
296
|
+
readonly ownerState?: RowState;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The state of a core a client takes over before its first render (P4-B spec
|
|
300
|
+
* §6.6): only what ready held views show — never the journal of mutations,
|
|
301
|
+
* the listeners, the rows nobody owns or the epochs of the session.
|
|
302
|
+
*/
|
|
303
|
+
interface CoreSnapshot {
|
|
304
|
+
readonly format: 1;
|
|
305
|
+
readonly objects: Readonly<Record<ObjectName, ObjectSnapshot>>;
|
|
306
|
+
readonly sections: Readonly<Record<ObjectName, readonly SectionSnapshot[]>>;
|
|
307
|
+
readonly subsets: readonly SubsetSnapshot[];
|
|
308
|
+
}
|
|
309
|
+
/** Limits of the core; defaults in `DEFAULT_CORE_LIMITS`. */
|
|
310
|
+
interface CoreLimits {
|
|
311
|
+
readonly seenMax: number;
|
|
312
|
+
readonly tombstonesMax: number;
|
|
313
|
+
readonly horizonBuckets: number;
|
|
314
|
+
readonly viewsMax: number;
|
|
315
|
+
readonly readParallel: number;
|
|
316
|
+
readonly keysPerRequest: number;
|
|
317
|
+
readonly fullPageSize: number;
|
|
318
|
+
/**
|
|
319
|
+
* The rows of a window page (P4-B spec §6.4: 100). A knob of the core for
|
|
320
|
+
* the model test, which needs small pages; hosts keep the default.
|
|
321
|
+
*/
|
|
322
|
+
readonly windowPage: number;
|
|
323
|
+
readonly fullLimit: number;
|
|
324
|
+
readonly releaseDelayMs: number;
|
|
325
|
+
readonly preloadTtlMs: number;
|
|
326
|
+
/**
|
|
327
|
+
* After a version epoch switch, visible views are re-read at a moment
|
|
328
|
+
* uniform on `[0, revalidateIntervalMs)` (P4-B spec §6.2): a primary
|
|
329
|
+
* restart switches every client at once. It is also the interval of the
|
|
330
|
+
* freshness tick: a visible view is re-read this long after its last read
|
|
331
|
+
* (P4-B spec §6.7).
|
|
332
|
+
*/
|
|
333
|
+
readonly revalidateIntervalMs: number;
|
|
334
|
+
/**
|
|
335
|
+
* The least age of a view's freshness mark for `resume()` to re-read it
|
|
336
|
+
* (P4-B spec §6.3 «Частота»). The default is 15 s, but not above
|
|
337
|
+
* `revalidateIntervalMs`; an explicit value above it is a `TypeError`.
|
|
338
|
+
*/
|
|
339
|
+
readonly resumeMinIntervalMs: number;
|
|
340
|
+
}
|
|
341
|
+
/** Diagnostic events of the core. */
|
|
342
|
+
type CoreLogEntry = {
|
|
343
|
+
kind: "full-truncated";
|
|
344
|
+
object: ObjectName;
|
|
345
|
+
limit: number;
|
|
346
|
+
} | {
|
|
347
|
+
kind: "late-response";
|
|
348
|
+
what: string;
|
|
349
|
+
} | {
|
|
350
|
+
kind: "listener-failed";
|
|
351
|
+
error: unknown;
|
|
352
|
+
} | {
|
|
353
|
+
kind: "removed-restored";
|
|
354
|
+
object: ObjectName;
|
|
355
|
+
count: number;
|
|
356
|
+
} | {
|
|
357
|
+
kind: "horizon-hidden";
|
|
358
|
+
object: ObjectName;
|
|
359
|
+
count: number;
|
|
360
|
+
} |
|
|
361
|
+
/** The `rights` part failed; the old snapshot stays (P4-B spec §9.3). */
|
|
362
|
+
{
|
|
363
|
+
kind: "rights-failed";
|
|
364
|
+
} |
|
|
365
|
+
/**
|
|
366
|
+
* The age of the oldest own mark of the signal receiver (`minVersion` or a
|
|
367
|
+
* disconnect gap), written on a tick while a mark exists (P4-B spec §8.4).
|
|
368
|
+
* No keys, no values.
|
|
369
|
+
*/
|
|
370
|
+
{
|
|
371
|
+
kind: "stale-age";
|
|
372
|
+
ageMs: number;
|
|
373
|
+
object?: ObjectName;
|
|
374
|
+
} |
|
|
375
|
+
/**
|
|
376
|
+
* A batch or a rejoin wave re-read: counts of objects and of their visible
|
|
377
|
+
* views, the ones actually read (an invisible view only gets `needsRefresh`).
|
|
378
|
+
*/
|
|
379
|
+
{
|
|
380
|
+
kind: "revalidate-burst";
|
|
381
|
+
objects: number;
|
|
382
|
+
views: number;
|
|
383
|
+
};
|
|
384
|
+
/** The data runtime of one user session (P4-B spec §6.1). */
|
|
385
|
+
interface DataRuntime {
|
|
386
|
+
/** The session `sub`; every request of this runtime carries it. */
|
|
387
|
+
readonly subject: string;
|
|
388
|
+
/** Closes the runtime; later requests are refused without the transport. */
|
|
389
|
+
dispose(): void;
|
|
390
|
+
/**
|
|
391
|
+
* Holds the view `spec` until its first subscription or `ttlMs` (default
|
|
392
|
+
* 5 s) and resolves after its first load: for a router loader (P4-B spec
|
|
393
|
+
* §6.1, §6.6). Throws synchronously on a refused spec (`TypeError`, `DataError`).
|
|
394
|
+
*/
|
|
395
|
+
preload(spec: ViewSpec, options?: {
|
|
396
|
+
ttlMs?: number;
|
|
397
|
+
}): Promise<void>;
|
|
398
|
+
/** The list strategy of `object` (`"<kind>.<name>"`): `window` unless the settings name it. */
|
|
399
|
+
residencyOf(object: string): "full" | "window";
|
|
400
|
+
readonly disposed: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* The snapshot of the ready held views for the client (P4-B spec §6.6):
|
|
403
|
+
* `meta` names the subject the rows were read for. Throws
|
|
404
|
+
* `TypeError` once the runtime is disposed, and while a write is in the
|
|
405
|
+
* journal. The server calls it, then `dispose()`.
|
|
406
|
+
*/
|
|
407
|
+
dehydrate(): DataSnapshot;
|
|
408
|
+
/**
|
|
409
|
+
* Takes a snapshot before the first render: every view of it is held,
|
|
410
|
+
* loaded and ready. Throws `TypeError`, writing nothing, when the `format`
|
|
411
|
+
* is unknown, `meta.subject` is not this runtime's, the runtime was already
|
|
412
|
+
* hydrated or holds views. Does nothing after `dispose()`. A snapshot of
|
|
413
|
+
* another subject never enters this runtime.
|
|
414
|
+
*/
|
|
415
|
+
hydrate(snapshot: DataSnapshot): void;
|
|
416
|
+
/**
|
|
417
|
+
* Ends the hydration, once: reconciles with the server (the catalog
|
|
418
|
+
* version, one re-read of every visible view) in one microtask. A repeat
|
|
419
|
+
* does nothing, so StrictMode is safe.
|
|
420
|
+
*/
|
|
421
|
+
endHydration(): void;
|
|
422
|
+
/** Whether the host shows the application; starts as `options.visible`. */
|
|
423
|
+
readonly visible: boolean;
|
|
424
|
+
/**
|
|
425
|
+
* Marks the application hidden; the host calls it on `visibilitychange`
|
|
426
|
+
* to `hidden`. Idempotent, sends nothing, and does nothing after
|
|
427
|
+
* `dispose()`.
|
|
428
|
+
*/
|
|
429
|
+
suspend(): void;
|
|
430
|
+
/**
|
|
431
|
+
* Marks the application visible again; the host calls it on
|
|
432
|
+
* `visibilitychange` to `visible` and on `focus`. Does nothing after
|
|
433
|
+
* `dispose()`. A call less than a second after the
|
|
434
|
+
* last accepted one only sets `visible`. An accepted call asks for the
|
|
435
|
+
* catalog version and re-reads the visible views last refreshed longer ago
|
|
436
|
+
* than `limits.resumeMinIntervalMs` (or never), in one microtask.
|
|
437
|
+
*/
|
|
438
|
+
resume(): void;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* What the server hands to the client runtime (P4-B spec §6.6): plain JSON,
|
|
442
|
+
* the same after `JSON.parse(JSON.stringify(...))`.
|
|
443
|
+
*/
|
|
444
|
+
interface DataSnapshot {
|
|
445
|
+
readonly meta: SnapshotMeta;
|
|
446
|
+
readonly core: CoreSnapshot;
|
|
447
|
+
}
|
|
448
|
+
/** Who a {@link DataSnapshot} was taken for. */
|
|
449
|
+
interface SnapshotMeta {
|
|
450
|
+
/** The session `sub` of the runtime that took it. */
|
|
451
|
+
readonly subject: string;
|
|
452
|
+
}
|
|
453
|
+
interface DataRuntimeOptions {
|
|
454
|
+
/** The client catalog (`client-catalog.json`); validated on creation. */
|
|
455
|
+
catalog: unknown;
|
|
456
|
+
transport: DataTransport;
|
|
457
|
+
/** The session `sub`. */
|
|
458
|
+
subject: string;
|
|
459
|
+
/**
|
|
460
|
+
* Called once when the server, or an override adapter, reports
|
|
461
|
+
* `session-changed`; the runtime is already closed by then.
|
|
462
|
+
*/
|
|
463
|
+
onSessionChanged?: () => void;
|
|
464
|
+
/**
|
|
465
|
+
* Called once per object, on its transition to stale (its kernel differs
|
|
466
|
+
* from the server's or a part of a read or write is refused
|
|
467
|
+
* `command.stale-client`; P4-B spec §10). It only offers a reload: the runtime never reloads itself,
|
|
468
|
+
* so unsaved forms of other objects are not lost.
|
|
469
|
+
*/
|
|
470
|
+
onStaleClient?: (object: string) => void;
|
|
471
|
+
/** The initial `visible` of the runtime (default `true`). */
|
|
472
|
+
visible?: boolean;
|
|
473
|
+
/** The runtime journal (default `console.warn`); see {@link DataLogEntry}. */
|
|
474
|
+
log?: (entry: DataLogEntry) => void;
|
|
475
|
+
/**
|
|
476
|
+
* Source adapters (P4-B spec §5.1). `override` maps a logical object name
|
|
477
|
+
* `"<kind>.<name>"` to a factory of its adapter; a name outside the catalog
|
|
478
|
+
* is a `TypeError`. Each factory is called once on creation with this
|
|
479
|
+
* runtime's `subject` and transport wrapper `send`: the adapter either
|
|
480
|
+
* reads through `send` (it sets `subject`) or checks the `sub` of its own
|
|
481
|
+
* credentials against `subject` itself (PostgREST adapter, §5.3). A
|
|
482
|
+
* `CommandFailure` `command.unauthenticated` `session-changed` from an
|
|
483
|
+
* override closes the runtime and calls `onSessionChanged` once, as the
|
|
484
|
+
* same response of the transport does.
|
|
485
|
+
*/
|
|
486
|
+
sources?: {
|
|
487
|
+
override?: Readonly<Record<string, (context: {
|
|
488
|
+
subject: string;
|
|
489
|
+
send: (request: DataRequest["request"]) => Promise<unknown>;
|
|
490
|
+
}) => SourceAdapter>>;
|
|
491
|
+
};
|
|
492
|
+
/**
|
|
493
|
+
* The list strategy per object (P4-B spec §5.1, Рд19): a map of logical
|
|
494
|
+
* names `"<kind>.<name>"` to `full` or `window`; an object not named is
|
|
495
|
+
* `window`. A name outside the catalog is a `TypeError`.
|
|
496
|
+
*/
|
|
497
|
+
residency?: Readonly<Record<string, "full" | "window">>;
|
|
498
|
+
/** The row limit of a `full` view (default 5 000); overrides `limits.fullLimit`. */
|
|
499
|
+
fullLimit?: number;
|
|
500
|
+
/** `full` over its limit fails with `data.full-too-large` (default `false`). */
|
|
501
|
+
strict?: boolean;
|
|
502
|
+
/** Memory and request limits of the core (P4-B spec §6.2); positive integers. */
|
|
503
|
+
limits?: Partial<CoreLimits>;
|
|
504
|
+
/**
|
|
505
|
+
* The signal transport of this runtime's `subject` (P4-B spec §6.1, §8.5):
|
|
506
|
+
* called once on creation, only when the catalog has `rightsSnapshot`. The
|
|
507
|
+
* runtime owns the transport: every way of closing it calls `close()`
|
|
508
|
+
* synchronously, before `onSessionChanged`. A transport of another subject
|
|
509
|
+
* is never reused.
|
|
510
|
+
*/
|
|
511
|
+
signals?: (subject: string) => SignalTransport;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* An entry of the runtime journal (P4-B spec §6.1). `transport-failed`: the
|
|
515
|
+
* transport threw or rejected; the caller saw `command.unavailable`. The
|
|
516
|
+
* other kinds come from the data core.
|
|
517
|
+
*/
|
|
518
|
+
type DataLogEntry = {
|
|
519
|
+
kind: "transport-failed";
|
|
520
|
+
error: unknown;
|
|
521
|
+
} | CoreLogEntry;
|
|
522
|
+
/** Creates the data runtime of one user session (P4-B spec §6.1). */
|
|
523
|
+
declare function createDataRuntime(options: DataRuntimeOptions): DataRuntime;
|
|
524
|
+
/** The options of `update`; `expectedVersion` is the base (§7.1). */
|
|
525
|
+
interface UpdateOptions {
|
|
526
|
+
readonly expectedVersion: number;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* The write API of the data runtime (P4-B spec §7.1). Each call is one
|
|
530
|
+
* mutation in the journal and one `run`; the thin M3 slice has `update`
|
|
531
|
+
* with the `await` policy only.
|
|
532
|
+
*/
|
|
533
|
+
interface DataWriter {
|
|
534
|
+
/**
|
|
535
|
+
* Sends the changed attributes of one row with `expectedVersion`, the
|
|
536
|
+
* confirmed version the edit is based on. The shown row keeps its values
|
|
537
|
+
* until the answer and has the state `pending`; `settled` resolves when
|
|
538
|
+
* the attempt settles and never rejects. Throws synchronously, before the
|
|
539
|
+
* transport, only for a caller error: `TypeError` for a name outside the
|
|
540
|
+
* catalog, `DataError` `data.version-required`. A refusal by the write
|
|
541
|
+
* state settles failed with its `DataError`, without the transport and
|
|
542
|
+
* with the journal unchanged: `data.mutation-pending` (the key has a
|
|
543
|
+
* `pending` mutation), `data.journal-full`. An update of a key with a
|
|
544
|
+
* `failed`, `conflict` or `unknown` mutation replaces it.
|
|
545
|
+
*/
|
|
546
|
+
update(object: ObjectName, id: Key, values: Values, options: UpdateOptions): Mutation;
|
|
547
|
+
}
|
|
548
|
+
/** The writer of a runtime made by `createDataRuntime`. */
|
|
549
|
+
declare function writerOf(runtime: DataRuntime): DataWriter;
|
|
550
|
+
/**
|
|
551
|
+
* The public holder of the runtime a host's hooks read (P4-B spec §6.4). It
|
|
552
|
+
* lives outside `react`, so a server consumer builds and swaps runtimes
|
|
553
|
+
* without the peer.
|
|
554
|
+
*/
|
|
555
|
+
interface RuntimeHolder {
|
|
556
|
+
/** The held runtime; `undefined` before the first one and after a close. */
|
|
557
|
+
current(): DataRuntime | undefined;
|
|
558
|
+
/**
|
|
559
|
+
* Why the holder holds no runtime (`replace(undefined, reason)`); `undefined`
|
|
560
|
+
* while it holds one, or before the first.
|
|
561
|
+
*/
|
|
562
|
+
closed(): CloseReason | undefined;
|
|
563
|
+
/**
|
|
564
|
+
* Swaps the runtime (sign-out, subject change, an SSR snapshot of another
|
|
565
|
+
* `subject`): the previous one is disposed if still alive, then the
|
|
566
|
+
* listeners run, so a mounted hook moves to `next` without the rows of the
|
|
567
|
+
* previous runtime. `next === undefined` leaves the holder closed with
|
|
568
|
+
* `reason` (default `signed-out`); with a runtime `reason` is ignored.
|
|
569
|
+
*/
|
|
570
|
+
replace(next: DataRuntime | undefined, reason?: CloseReason): void;
|
|
571
|
+
/**
|
|
572
|
+
* Builds the runtime of the snapshot's subject with `create`, hydrates it
|
|
573
|
+
* and swaps it in (P4-B spec §6.6). The runtime `create` returns must have
|
|
574
|
+
* that `subject` and must be a new live runtime (not the held one, not a
|
|
575
|
+
* disposed one): otherwise `TypeError` and the held runtime is untouched.
|
|
576
|
+
* On any refusal after `create` the new runtime is disposed before the
|
|
577
|
+
* error leaves. The host then calls `endHydration()` of the new runtime.
|
|
578
|
+
*/
|
|
579
|
+
hydrateFrom(snapshot: DataSnapshot, create: (subject: string) => DataRuntime): void;
|
|
580
|
+
/** Subscribes to swaps; returns the unsubscribe function. */
|
|
581
|
+
subscribe(listener: () => void): () => void;
|
|
582
|
+
}
|
|
583
|
+
/** Creates a runtime holder, optionally with its first runtime. */
|
|
584
|
+
declare function createRuntimeHolder(initial?: DataRuntime): RuntimeHolder;
|
|
585
|
+
export { DataError as C, ViewSnapshot as S, RowMutation as _, UpdateOptions as a, SectionLine as b, DataRuntimeOptions as c, createDataRuntime as d, CloseReason as f, MutationState as g, MutationResult as h, writerOf as i, DataSnapshot as l, Mutation as m, createRuntimeHolder as n, DataLogEntry as o, CoreSnapshot as p, DataWriter as r, DataRuntime as s, RuntimeHolder as t, SnapshotMeta as u, RowState as v, DataErrorCode as w, ServerRow as x, RowView as y };
|