foldkit-remote-server 0.17.0 → 0.19.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 +442 -149
- package/dist/fetch.d.mts +30 -3
- package/dist/fetch.d.mts.map +1 -1
- package/dist/fetch.mjs +52 -16
- package/dist/fetch.mjs.map +1 -1
- package/dist/index-BnaRbvjr.d.mts +937 -0
- package/dist/index-BnaRbvjr.d.mts.map +1 -0
- package/dist/index.d.mts +2 -638
- package/dist/index.mjs +1 -1
- package/dist/{src-ErnDxcWe.mjs → src-ZV9pARkU.mjs} +478 -59
- package/dist/src-ZV9pARkU.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/index.d.mts.map +0 -1
- package/dist/src-ErnDxcWe.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BnaRbvjr.d.mts","names":[],"sources":["../src/diagnostics.ts","../src/index.ts"],"mappings":";;;;UAaiB,qBAAqB;WAC3B;WACA,OAAO,MAAM;;;UAIP,qBAAqB;WAC3B;WACA;;WAEA;;;UAIM,sBAAsB;WAC5B;WACA;WACA,OAAO,MAAM;;;;;;;UAQP,oBAAoB;WAC1B;WACA;;WAEA;;WAEA;;WAEA;;;KAIC,yBAAyB,eAAe,eAAe,gBAAgB;;;;cC+CtE,0BAA0B;;;;;;;;;cAY1B,oBAAoB;;;;;;;;;;cAUpB,oBAAoB;;;;;;;;;;;;cAUpB,sBAAsB;;UAOlB;WACN,MAAM;WACN,OAAO,SAAS;;;;;;;;;;;;;;cAQd,wBAAwB;UAQpB;WACN;WACA,QAAQ,SAAS;;UAGX,oBAAoB;WAC1B;WACA;;WAEA,UAAU,SAAS,eAAe;WAClC,WAAW;;;;;;;WAOX,SAAS,OAAO,OAAO;;UAGjB,aAAa,GAAG;WACtB;;WAEA,SAAS;WACT,OACP,SAAS,oBAAoB,OAC1B,OAAO,OAAO,cAAc,eAAe,mBAAmB;;WAE1D,aAAa,WA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;;;;EAsBhC,aAAA,GAAG,GAAC,QACP,iBAAiB,GAAG,IAAE,WACnB,GAAC,SACH,eAAe,GAAG,IAAE,UACnB,cAAc,iBACvB,OAAO;aAEG,UAAU;eACR;eACA;eACA,QAAQ;;aAEV,SAAS;eACP;eACA;eACA,QAAQ;;KAGrB,iBACA;;;;;;;;;;;;;EAmJO,SAAA,GAAC,UACE,gBAAgB,IAAE,kBAE3B,OAAO;aAEG;aACA,MAAM;YAGjB;;;;;;;;EAiES,WAAA,GAAG,GAAG,WAAS,QAChB,iBAAiB,GAAG,IAAE,WACnB,IAAI,QAAQ,IAAI,GAAG,IAAE,UACvB,eAAe,GAAG,OAC1B,gBAAgB,IAAI"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,638 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { Boundary, ConnectionChangeSchema, ConnectionIdentity, LiveChange, MutationDescriptor, NormalizedPatch, QueryDescriptor, QueryWindow, RelationRequirement, RemoteClient, RemoteDescriptor, RemoteForbidden, RemoteJsonAnswer, RemoteReadError, RemoteRpcClient, RemoteUnauthenticated, Requirement } from "foldkit-remote";
|
|
4
|
-
declare const RemoteServerError_base: Schema.Class<RemoteServerError, Schema.TaggedStruct<"RemoteServerError", {
|
|
5
|
-
readonly message: Schema.String;
|
|
6
|
-
}>, import("effect/Cause").YieldableError>;
|
|
7
|
-
export declare class RemoteServerError extends RemoteServerError_base {}
|
|
8
|
-
declare const RemoteUnmet_base: Schema.Class<RemoteUnmet, Schema.TaggedStruct<"RemoteUnmet", {
|
|
9
|
-
readonly message: Schema.String;
|
|
10
|
-
}>, import("effect/Cause").YieldableError>;
|
|
11
|
-
/**
|
|
12
|
-
* A writer's word that the row does not hold what the write's `when` asks of
|
|
13
|
-
* it, where the write would commit: `RemoteServer.write` answers it as the
|
|
14
|
-
* mutation's `Unmet` refusal.
|
|
15
|
-
*/
|
|
16
|
-
export declare class RemoteUnmet extends RemoteUnmet_base {}
|
|
17
|
-
declare const RemoteInvalid_base: Schema.Class<RemoteInvalid, Schema.TaggedStruct<"RemoteInvalid", {
|
|
18
|
-
readonly message: Schema.String;
|
|
19
|
-
readonly rule: Schema.Option<Schema.String>;
|
|
20
|
-
readonly path: Schema.$Array<Schema.String>;
|
|
21
|
-
}>, import("effect/Cause").YieldableError>;
|
|
22
|
-
/**
|
|
23
|
-
* A writer's word that the row a write would leave breaks one of its Entity's
|
|
24
|
-
* invariants: `RemoteServer.write` answers it as the mutation's `Invalid`
|
|
25
|
-
* refusal. `rule` and `path` are none and empty when saying them would tell
|
|
26
|
-
* the caller what a member hidden from them holds.
|
|
27
|
-
*/
|
|
28
|
-
export declare class RemoteInvalid extends RemoteInvalid_base {}
|
|
29
|
-
/** A write's precondition as a writer is handed it: the body, and the input encoded. */
|
|
30
|
-
export interface WriteWhen {
|
|
31
|
-
readonly body: AnyQuery;
|
|
32
|
-
readonly input: Readonly<Record<string, unknown>>;
|
|
33
|
-
}
|
|
34
|
-
declare const MutationRefused_base: Schema.Class<MutationRefused, Schema.TaggedStruct<"MutationRefused", {
|
|
35
|
-
/** The mutation the refusal was made for: a Source refusing as another is a bug. */
|
|
36
|
-
readonly mutation: Schema.String;
|
|
37
|
-
readonly refusal: Schema.Unknown;
|
|
38
|
-
/** What a person reads: the error's message beside the refusal. */
|
|
39
|
-
readonly message: Schema.String;
|
|
40
|
-
}>, import("effect/Cause").YieldableError>;
|
|
41
|
-
/**
|
|
42
|
-
* A mutation Source's refusal, as the value its descriptor's `Refusal`
|
|
43
|
-
* declares: made with `RemoteServer.refuse`, which checks the value's type
|
|
44
|
-
* against the mutation, and sent to the client encoded, beside a message.
|
|
45
|
-
*/
|
|
46
|
-
export declare class MutationRefused extends MutationRefused_base {}
|
|
47
|
-
export interface EntityRecord {
|
|
48
|
-
readonly id: string;
|
|
49
|
-
readonly values: Readonly<Record<string, unknown>>;
|
|
50
|
-
}
|
|
51
|
-
export interface EntitySourceContext<P> {
|
|
52
|
-
readonly ids: readonly string[];
|
|
53
|
-
readonly fields: readonly string[];
|
|
54
|
-
/** A pagination window per requested relation field. */
|
|
55
|
-
readonly windows?: Readonly<Record<string, QueryWindow>> | undefined;
|
|
56
|
-
readonly principal: P;
|
|
57
|
-
}
|
|
58
|
-
export interface EntitySource<P, R = never> {
|
|
59
|
-
readonly entity: string;
|
|
60
|
-
/** The fields the entity declares; a request for any other never reaches `read`. */
|
|
61
|
-
readonly fields?: ReadonlySet<string> | undefined;
|
|
62
|
-
readonly read: (context: EntitySourceContext<P>) => Effect.Effect<ReadonlyArray<EntityRecord>, RemoteServerError, R>;
|
|
63
|
-
/** Returns the fields this principal may read; omitted means all requested. */
|
|
64
|
-
readonly authorize?: (principal: P, fields: readonly string[]) => readonly string[];
|
|
65
|
-
/**
|
|
66
|
-
* Decides, per record, what a principal sees of the fields `authorize`
|
|
67
|
-
* allowed: run once per read, before `read`. A member it drops from a
|
|
68
|
-
* record is settled unread, as one the source did not return.
|
|
69
|
-
*/
|
|
70
|
-
readonly filter?: (principal: P, fields: readonly string[]) => Effect.Effect<ReadPlan, RemoteServerError, R>;
|
|
71
|
-
/**
|
|
72
|
-
* The rule that decides which rows this source returns, as it was given one
|
|
73
|
-
* (a Drizzle binding's `visible`, `RemoteServer.memory`'s `readable`). The
|
|
74
|
-
* server never runs it: it is here so a check at startup, such as
|
|
75
|
-
* `GuardServer.validate`, can confirm a source applies the rule its Entity
|
|
76
|
-
* requires.
|
|
77
|
-
*/
|
|
78
|
-
readonly visible?: unknown;
|
|
79
|
-
/**
|
|
80
|
-
* The fields every principal reads alike, of every row: no rule about who
|
|
81
|
-
* is asking hides the row or the field, or changes its value. A promise the
|
|
82
|
-
* server keeps by trusting it: the live hub sends a declared write's value
|
|
83
|
-
* of one to every subscriber as it is, with no read per principal.
|
|
84
|
-
*/
|
|
85
|
-
readonly shared?: ReadonlySet<string> | undefined;
|
|
86
|
-
}
|
|
87
|
-
/** What `EntitySource.filter` decides for one read. */
|
|
88
|
-
export interface ReadPlan {
|
|
89
|
-
/** The fields to read: those allowed, and any the decision itself needs. */
|
|
90
|
-
readonly fields: readonly string[];
|
|
91
|
-
/** One record as the principal sees it: a member dropped, or its value replaced. */
|
|
92
|
-
readonly apply: (record: EntityRecord) => EntityRecord;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Where a declared write lands: one row's new values, encoded as the store holds
|
|
96
|
-
* them. With `expect`, the row is written only while its revision is still that
|
|
97
|
-
* value, and the revision moves on with the write. With `when`, only while the
|
|
98
|
-
* row holds its body, checked in the statement that writes it; a row there at
|
|
99
|
-
* the expected revision that does not hold it fails with `RemoteUnmet`. The row
|
|
100
|
-
* as written answers; none when no row matched.
|
|
101
|
-
*/
|
|
102
|
-
export interface EntityWriter<P, R = never> {
|
|
103
|
-
readonly entity: string;
|
|
104
|
-
/**
|
|
105
|
-
* Whether `update` and `delete` honour `when`. `RemoteServer.write` refuses
|
|
106
|
-
* a write with a precondition over a writer without it, which would write
|
|
107
|
-
* whatever the row held.
|
|
108
|
-
*/
|
|
109
|
-
readonly preconditions?: true;
|
|
110
|
-
/**
|
|
111
|
-
* Whether `update` adds `increments` to their fields where it writes.
|
|
112
|
-
* `RemoteServer.write` refuses a write with an increment over a writer
|
|
113
|
-
* without it, which would leave the fields where they were.
|
|
114
|
-
*/
|
|
115
|
-
readonly increments?: true;
|
|
116
|
-
/**
|
|
117
|
-
* Whether `update` records each write it lands under its `operation`, in
|
|
118
|
-
* the transaction that writes, and answers a retry of it from that record
|
|
119
|
-
* rather than writing again. An increment that expects no revision needs one.
|
|
120
|
-
*/
|
|
121
|
-
readonly ledger?: true;
|
|
122
|
-
/**
|
|
123
|
-
* Whether `update` and `insert` refuse a row, or a change, that would break
|
|
124
|
-
* one of its Entity's invariants (`Entity.invariant`), with `RemoteInvalid`,
|
|
125
|
-
* judged over the rows they write; an insert judges the state invariants
|
|
126
|
-
* alone. `RemoteServer.write` refuses a write the Entity holds to any through
|
|
127
|
-
* a writer without it.
|
|
128
|
-
*/
|
|
129
|
-
readonly invariants?: true;
|
|
130
|
-
/**
|
|
131
|
-
* Why this writer cannot land `write`, each a sentence; none when it can.
|
|
132
|
-
* `RemoteServer.write` asks once, where the write is registered, for what
|
|
133
|
-
* only the store knows: a column's type, say, which the Entity does not say.
|
|
134
|
-
*/
|
|
135
|
-
readonly refuses?: (write: AnyWrite) => ReadonlyArray<string>;
|
|
136
|
-
/**
|
|
137
|
-
* The answer recorded for `operation`, when this writer has a ledger and
|
|
138
|
-
* holds one: what a wrapping writer (a guard) answers a retry with, without
|
|
139
|
-
* deciding again over a row that has moved since.
|
|
140
|
-
*/
|
|
141
|
-
readonly recorded?: (context: {
|
|
142
|
-
readonly operation: string;
|
|
143
|
-
/** The row the operation writes: one operation may write several rows. */
|
|
144
|
-
readonly id: string;
|
|
145
|
-
readonly principal: P;
|
|
146
|
-
}) => Effect.Effect<Option.Option<Readonly<Record<string, unknown>>>, RemoteServerError, R>;
|
|
147
|
-
readonly update: (context: {
|
|
148
|
-
readonly id: string;
|
|
149
|
-
/** The operation's identity across clients, when the client sent one: a ledger's key. */
|
|
150
|
-
readonly operation: Option.Option<string>;
|
|
151
|
-
readonly values: Readonly<Record<string, unknown>>;
|
|
152
|
-
/**
|
|
153
|
-
* Each field to move, by the amount, encoded: added to the stored value in
|
|
154
|
-
* the statement that writes, never computed from a value read before it.
|
|
155
|
-
*/
|
|
156
|
-
readonly increments: Readonly<Record<string, number>>;
|
|
157
|
-
/** Each `one` relation it points, by the relation's key: the row, or none. */
|
|
158
|
-
readonly links: Readonly<Record<string, Option.Option<EntityRef>>>;
|
|
159
|
-
readonly expect: Option.Option<{
|
|
160
|
-
readonly field: string;
|
|
161
|
-
readonly revision: unknown;
|
|
162
|
-
}>;
|
|
163
|
-
readonly when: Option.Option<WriteWhen>;
|
|
164
|
-
readonly principal: P;
|
|
165
|
-
}) => Effect.Effect<Option.Option<Readonly<Record<string, unknown>>>, RemoteServerError | RemoteForbidden | RemoteUnmet | RemoteInvalid, R>;
|
|
166
|
-
/**
|
|
167
|
-
* Inserts the row, or finds one already there under that id holding what
|
|
168
|
-
* it writes (a retry); answers the row as it is. Fails when the id holds
|
|
169
|
-
* any other row.
|
|
170
|
-
*/
|
|
171
|
-
readonly insert: (context: {
|
|
172
|
-
readonly id: string;
|
|
173
|
-
readonly values: Readonly<Record<string, unknown>>;
|
|
174
|
-
readonly links: Readonly<Record<string, Option.Option<EntityRef>>>;
|
|
175
|
-
readonly principal: P;
|
|
176
|
-
}) => Effect.Effect<Readonly<Record<string, unknown>>, RemoteServerError | RemoteForbidden | RemoteInvalid, R>;
|
|
177
|
-
/**
|
|
178
|
-
* Deletes the row, while it is still at the revision when one is expected:
|
|
179
|
-
* `deleted`, `absent` (no row, so nothing to delete; a retry's case), or
|
|
180
|
-
* `moved` (the row is there at another revision, and stays).
|
|
181
|
-
*/
|
|
182
|
-
readonly delete: (context: {
|
|
183
|
-
readonly id: string;
|
|
184
|
-
readonly expect: Option.Option<{
|
|
185
|
-
readonly field: string;
|
|
186
|
-
readonly revision: unknown;
|
|
187
|
-
}>;
|
|
188
|
-
readonly when: Option.Option<WriteWhen>;
|
|
189
|
-
readonly principal: P;
|
|
190
|
-
}) => Effect.Effect<'deleted' | 'absent' | 'moved', RemoteServerError | RemoteForbidden | RemoteUnmet, R>;
|
|
191
|
-
/**
|
|
192
|
-
* The row as `principal` may see it, under the read rule its Source applies:
|
|
193
|
-
* none when there is no such row, or it is hidden. Given, a write's answer
|
|
194
|
-
* is read back through it, so an answer never shows its writer a row it may
|
|
195
|
-
* not read, and a row the write hid from them answers as deleted.
|
|
196
|
-
*/
|
|
197
|
-
readonly read?: (context: {
|
|
198
|
-
readonly id: string;
|
|
199
|
-
readonly fields: ReadonlyArray<string>;
|
|
200
|
-
readonly principal: P;
|
|
201
|
-
}) => Effect.Effect<Option.Option<Readonly<Record<string, unknown>>>, RemoteServerError, R>;
|
|
202
|
-
/**
|
|
203
|
-
* Each of `relations`' links as stored, by ref key (`'Project:p1'`) or
|
|
204
|
-
* `null`, whatever a reader may see of the row it points at; none when there
|
|
205
|
-
* is no such row. A guard reads it to tell a write that unlinks a row hidden
|
|
206
|
-
* from its writer from one that changes nothing.
|
|
207
|
-
*/
|
|
208
|
-
readonly linked?: (context: {
|
|
209
|
-
readonly id: string;
|
|
210
|
-
readonly relations: ReadonlyArray<string>;
|
|
211
|
-
}) => Effect.Effect<Option.Option<Readonly<Record<string, unknown>>>, RemoteServerError, R>;
|
|
212
|
-
}
|
|
213
|
-
/** A connection change a mutation made, as the wire carries it. */
|
|
214
|
-
export type ConnectionChange = Schema.Schema.Type<typeof ConnectionChangeSchema>;
|
|
215
|
-
export interface MutationOutcome<Output> {
|
|
216
|
-
readonly output: Output;
|
|
217
|
-
readonly entities?: ReadonlyArray<NormalizedPatch>;
|
|
218
|
-
/** Connection changes the mutation made; the client settles them with its patches. */
|
|
219
|
-
readonly connections?: ReadonlyArray<ConnectionChange>;
|
|
220
|
-
/**
|
|
221
|
-
* Entities the mutation deleted. The client knows them absent from then on:
|
|
222
|
-
* they leave every connection and read `NotFound`, with no connection to name.
|
|
223
|
-
*/
|
|
224
|
-
readonly deleted?: ReadonlyArray<{
|
|
225
|
-
readonly entity: string;
|
|
226
|
-
readonly id: string;
|
|
227
|
-
}>;
|
|
228
|
-
}
|
|
229
|
-
export interface MutationSource<P, R = never> {
|
|
230
|
-
readonly mutation: string;
|
|
231
|
-
/**
|
|
232
|
-
* For a declared write (`RemoteServer.write`), the Entity it writes, the
|
|
233
|
-
* writer it lands through, as it was given one, and the write itself. The
|
|
234
|
-
* server never reads it; a startup check such as `GuardServer.validate` does.
|
|
235
|
-
*/
|
|
236
|
-
readonly writes?: {
|
|
237
|
-
readonly entity: string;
|
|
238
|
-
readonly writer: unknown;
|
|
239
|
-
readonly write: AnyWrite;
|
|
240
|
-
};
|
|
241
|
-
readonly Input: Schema.Codec<unknown>;
|
|
242
|
-
readonly Output: Schema.Codec<unknown>;
|
|
243
|
-
readonly Refusal: Schema.Codec<unknown, unknown>;
|
|
244
|
-
readonly run: (context: {
|
|
245
|
-
readonly input: unknown;
|
|
246
|
-
readonly principal: P;
|
|
247
|
-
/**
|
|
248
|
-
* The client's id for this request, the same on every retry of it. It is
|
|
249
|
-
* unique within that client only: two clients' first requests can share
|
|
250
|
-
* it. Key a record of the write by `operation`, never by this.
|
|
251
|
-
*/
|
|
252
|
-
readonly requestId: string;
|
|
253
|
-
/**
|
|
254
|
-
* The operation's identity across clients, the same on every retry of it,
|
|
255
|
-
* when the client sent one (Remote's does); none from an older client.
|
|
256
|
-
*/
|
|
257
|
-
readonly operation: Option.Option<string>;
|
|
258
|
-
/** For a declared write: the input keys to write, when the client named only some. */
|
|
259
|
-
readonly keys?: ReadonlyArray<string> | undefined;
|
|
260
|
-
}) => Effect.Effect<{
|
|
261
|
-
readonly output: unknown;
|
|
262
|
-
readonly entities: ReadonlyArray<NormalizedPatch>;
|
|
263
|
-
readonly connections: ReadonlyArray<ConnectionChange>;
|
|
264
|
-
readonly deleted: ReadonlyArray<{
|
|
265
|
-
readonly entity: string;
|
|
266
|
-
readonly id: string;
|
|
267
|
-
}>;
|
|
268
|
-
}, RemoteServerError | MutationRefused | RemoteForbidden, R>;
|
|
269
|
-
}
|
|
270
|
-
export interface QueryPage {
|
|
271
|
-
readonly edges: ReadonlyArray<{
|
|
272
|
-
readonly entity: string;
|
|
273
|
-
readonly id: string;
|
|
274
|
-
readonly key: string;
|
|
275
|
-
}>;
|
|
276
|
-
readonly start: Boundary;
|
|
277
|
-
readonly end: Boundary;
|
|
278
|
-
}
|
|
279
|
-
export interface QuerySource<P, R = never> {
|
|
280
|
-
readonly query: string;
|
|
281
|
-
readonly Input: Schema.Codec<unknown>;
|
|
282
|
-
readonly run: (context: {
|
|
283
|
-
readonly input: unknown;
|
|
284
|
-
readonly window: QueryWindow;
|
|
285
|
-
readonly principal: P;
|
|
286
|
-
/**
|
|
287
|
-
* What the client reads of each item. A source may use it to answer
|
|
288
|
-
* fields with the page, or ignore it: the handlers fetch what the page
|
|
289
|
-
* leaves out through the entity sources, so one response still carries
|
|
290
|
-
* both either way.
|
|
291
|
-
*/
|
|
292
|
-
readonly select?: RelationRequirement | undefined;
|
|
293
|
-
}) => Effect.Effect<QueryPage, RemoteServerError, R>;
|
|
294
|
-
/** The rule that decides which rows the query lists. See `EntitySource.visible`. */
|
|
295
|
-
readonly visible?: unknown;
|
|
296
|
-
}
|
|
297
|
-
export interface LiveSource<P, R = never> {
|
|
298
|
-
readonly entity: string;
|
|
299
|
-
readonly subscribe: (context: {
|
|
300
|
-
readonly requirements: ReadonlyArray<Requirement>;
|
|
301
|
-
readonly after: number;
|
|
302
|
-
readonly principal: P;
|
|
303
|
-
}) => Stream.Stream<Schema.Schema.Type<typeof LiveChange>, RemoteServerError, R>;
|
|
304
|
-
}
|
|
305
|
-
export interface ServerDefinition<P, R = never> {
|
|
306
|
-
readonly entities: ReadonlyMap<string, EntitySource<P, R>>;
|
|
307
|
-
readonly mutations: ReadonlyMap<string, MutationSource<P, R>>;
|
|
308
|
-
readonly queries: ReadonlyMap<string, QuerySource<P, R>>;
|
|
309
|
-
readonly live: ReadonlyMap<string, LiveSource<P, R>>;
|
|
310
|
-
}
|
|
311
|
-
export interface HandlerOptions<P, R = never> {
|
|
312
|
-
/** A read or live subscription may not name more ids of one entity than this; default 1000. */
|
|
313
|
-
readonly maxIdsPerEntity?: number | undefined;
|
|
314
|
-
/** A nested selection may not reach further than this many relation levels; default 8. */
|
|
315
|
-
readonly maxDepth?: number | undefined;
|
|
316
|
-
/** A hub whose `changed`/`deleted` signals reach the subscribers this handler registers. */
|
|
317
|
-
readonly live?: LiveHub<P, R> | undefined;
|
|
318
|
-
}
|
|
319
|
-
type LiveChangeValue = Schema.Schema.Type<typeof LiveChange>;
|
|
320
|
-
interface LiveRef {
|
|
321
|
-
readonly entity: string;
|
|
322
|
-
readonly id: string;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* The server-side "these fields changed" signal. A hub tracks each live
|
|
326
|
-
* subscriber's requirements (entity, id, fields) and principal; `changed`
|
|
327
|
-
* re-reads the changed fields a subscriber selects through the entity's own
|
|
328
|
-
* source, under that subscriber's principal, and streams the patch to it.
|
|
329
|
-
* Subscribers that select none of the changed fields do no work. Cursors
|
|
330
|
-
* continue from the cursor each subscriber resumed at, so the client's
|
|
331
|
-
* duplicate and gap handling is unchanged.
|
|
332
|
-
*/
|
|
333
|
-
export interface LiveHub<P, R = never> {
|
|
334
|
-
/**
|
|
335
|
-
* `values`, when given, are the row's stored values of `fields` (a declared
|
|
336
|
-
* write's answer): a field of them the source declares `shared` is sent as
|
|
337
|
-
* it is, and only the rest are re-read.
|
|
338
|
-
*/
|
|
339
|
-
readonly changed: (ref: LiveRef, fields: ReadonlyArray<string>, values?: Readonly<Record<string, unknown>> | undefined) => Effect.Effect<void, RemoteServerError, R>;
|
|
340
|
-
/**
|
|
341
|
-
* `ref` may be gone: each subscriber's selection of it is read again, and
|
|
342
|
-
* one it is no longer there to is sent a deletion. A row deleted for one
|
|
343
|
-
* writer may only be hidden from them, and still there to others.
|
|
344
|
-
*/
|
|
345
|
-
readonly deleted: (ref: LiveRef) => Effect.Effect<void, RemoteServerError, R>;
|
|
346
|
-
/** Registers a subscriber for the stream's lifetime; `handlers` calls this. */
|
|
347
|
-
readonly subscribe: (context: {
|
|
348
|
-
readonly requirements: ReadonlyArray<Requirement>;
|
|
349
|
-
readonly after: number;
|
|
350
|
-
readonly principal: P;
|
|
351
|
-
/** Refuses a subscription naming more ids of one entity than this. */
|
|
352
|
-
readonly maxIdsPerEntity?: number | undefined;
|
|
353
|
-
}) => Stream.Stream<LiveChangeValue, RemoteServerError>;
|
|
354
|
-
/** How many subscribers are registered now. */
|
|
355
|
-
readonly size: Effect.Effect<number>;
|
|
356
|
-
}
|
|
357
|
-
declare const liveHub: <P, R>(entities: ReadonlyArray<EntitySource<P, R>>, options?: {
|
|
358
|
-
/**
|
|
359
|
-
* Who a principal is, for sharing re-reads: subscribers whose principals
|
|
360
|
-
* have one key share one read, under the first one's principal. Default:
|
|
361
|
-
* the principal itself, so only the same value shares.
|
|
362
|
-
*/
|
|
363
|
-
readonly key?: ((principal: P) => unknown) | undefined;
|
|
364
|
-
}) => Effect.Effect<LiveHub<P, R>>;
|
|
365
|
-
/**
|
|
366
|
-
* A descriptor's name and, when it declares them, its readable members: an
|
|
367
|
-
* Entity's `members` (its fields, relations and derived members), or a plain
|
|
368
|
-
* descriptor's `fields`.
|
|
369
|
-
*/
|
|
370
|
-
interface EntityName {
|
|
371
|
-
readonly name: string;
|
|
372
|
-
readonly fields?: Readonly<Record<string, unknown>> | undefined;
|
|
373
|
-
readonly members?: Readonly<Record<string, unknown>> | undefined;
|
|
374
|
-
}
|
|
375
|
-
/** One entity's rows in their wire shape: a relation is its ref key, `'User:u1'`. */
|
|
376
|
-
export type MemoryRows = Readonly<Record<string, ReadonlyArray<Readonly<Record<string, unknown>> & {
|
|
377
|
-
readonly id: string;
|
|
378
|
-
}>>>;
|
|
379
|
-
/**
|
|
380
|
-
* The rows a memory backend holds, which its mutations write through. A
|
|
381
|
-
* change is what the next read sees; nothing is pushed to a client.
|
|
382
|
-
*/
|
|
383
|
-
export interface MemoryStore {
|
|
384
|
-
/** The rows of one entity, in insertion order. */
|
|
385
|
-
readonly rows: (entity: string) => ReadonlyArray<Readonly<Record<string, unknown>>>;
|
|
386
|
-
/** Writes these values onto a row, creating it if it is new. */
|
|
387
|
-
readonly write: (entity: string, id: string, values: Readonly<Record<string, unknown>>) => void;
|
|
388
|
-
readonly remove: (entity: string, id: string) => void;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* A memory backend made without a `principal`: its rows and the server over
|
|
392
|
-
* them, answered as whoever its caller names per request (`serveFetch`,
|
|
393
|
-
* `RemoteServer.handlers(served.server, principal)`).
|
|
394
|
-
*/
|
|
395
|
-
export interface MemoryServed<P> extends MemoryStore {
|
|
396
|
-
/**
|
|
397
|
-
* The rows' server, for serving them over a real transport, or as any
|
|
398
|
-
* principal: `RemoteRpc.toLayer(RemoteServer.handlers(backend.server, principal))`.
|
|
399
|
-
*/
|
|
400
|
-
readonly server: ServerDefinition<P>;
|
|
401
|
-
}
|
|
402
|
-
export interface MemoryBackend<P = undefined> extends MemoryServed<P> {
|
|
403
|
-
/**
|
|
404
|
-
* A `RemoteClient` answering from the rows as the configured `principal`.
|
|
405
|
-
* Provide it where the real one would go.
|
|
406
|
-
*/
|
|
407
|
-
readonly layer: Layer.Layer<RemoteClient>;
|
|
408
|
-
}
|
|
409
|
-
/** What `RemoteServer.memory` is made from. See `memory`. */
|
|
410
|
-
export type MemoryConfig<P> = {
|
|
411
|
-
readonly domain: Pick<RemoteDescriptor, 'registry'>;
|
|
412
|
-
readonly rows: MemoryRows;
|
|
413
|
-
/**
|
|
414
|
-
* How the bodies' primitive operators are run: every query body is checked
|
|
415
|
-
* against it where the server is built, and one calling an operator it lacks
|
|
416
|
-
* is refused there. `Operators.kernel` when not given.
|
|
417
|
-
*/
|
|
418
|
-
readonly operators?: MemoryOperators | undefined;
|
|
419
|
-
/**
|
|
420
|
-
* Sources for entities the domain does not declare, which no row backs (a
|
|
421
|
-
* `Me` row answered from the principal, `GuardServer.me`), served beside
|
|
422
|
-
* the rows. One for a declared entity is refused: the rows serve it.
|
|
423
|
-
*/
|
|
424
|
-
readonly entities?: ReadonlyArray<EntitySource<P>>;
|
|
425
|
-
/** Sources for queries, beside the domain's: one named as a declared query answers it instead of its body. */
|
|
426
|
-
readonly queries?: ReadonlyArray<QuerySource<P>>;
|
|
427
|
-
readonly mutations?: (store: MemoryStore) => ReadonlyArray<MutationSource<P>>;
|
|
428
|
-
/** Per entity name, the fields a principal may read, as `RemoteServer.entity` takes it. */
|
|
429
|
-
readonly authorize?: Readonly<Record<string, NonNullable<EntitySource<P>['authorize']>>>;
|
|
430
|
-
/** Per entity name, what a principal sees of each record, as `RemoteServer.entity` takes it. */
|
|
431
|
-
readonly filter?: Readonly<Record<string, NonNullable<EntitySource<P>['filter']>>>;
|
|
432
|
-
/** Per entity name, the fields every principal reads alike: see `EntitySource.shared`. */
|
|
433
|
-
readonly shared?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
434
|
-
/**
|
|
435
|
-
* Which stored rows a principal may read, decided once per read. A row it
|
|
436
|
-
* may not read is absent from a read by id and from every query, and a ref
|
|
437
|
-
* to one is dropped from a relation (a `one` ref reads as `null`). `row`
|
|
438
|
-
* looks another stored row up, for a decision that follows a relation.
|
|
439
|
-
*/
|
|
440
|
-
readonly readable?: (principal: P, row: (entity: string, id: string) => Option.Option<Readonly<Record<string, unknown>>>) => Effect.Effect<MemoryReadable, RemoteServerError>;
|
|
441
|
-
/** Who the `layer` answers as. Without it there is no `layer`, unless `P` admits `undefined`. */
|
|
442
|
-
readonly principal?: P;
|
|
443
|
-
};
|
|
444
|
-
/** What a backend needs to give a `layer`: a principal to answer as, or one `undefined` can be. */
|
|
445
|
-
export type MemoryAnswering<P> = undefined extends P ? unknown : {
|
|
446
|
-
readonly principal: P;
|
|
447
|
-
};
|
|
448
|
-
/** Whether a stored row of `entity` may be read, given its whole stored values. */
|
|
449
|
-
export type MemoryReadable = (entity: string, row: Readonly<Record<string, unknown>>) => boolean;
|
|
450
|
-
/**
|
|
451
|
-
* A backend held in memory: the rows you give it, served through the same
|
|
452
|
-
* handlers a real server uses. For a first run, a test, a story or a demo, with
|
|
453
|
-
* no database and no network.
|
|
454
|
-
*
|
|
455
|
-
* Reads go through `handlers`, so field filtering and nested relations behave
|
|
456
|
-
* as they do in production. A query declared with `Query.define` is answered
|
|
457
|
-
* by running its body over the rows with the reference interpreter, the one
|
|
458
|
-
* every interpreter is held to by the conformance suite. A query with no body
|
|
459
|
-
* has nothing to run and is refused when the backend is made, unless `queries`
|
|
460
|
-
* supplies a source for it. Mutations are yours to give: each one writes
|
|
461
|
-
* through the store it is handed, and the next read sees the change.
|
|
462
|
-
*
|
|
463
|
-
* Every field of every row is readable unless `authorize` names the entity:
|
|
464
|
-
* then its function decides, per principal, as `RemoteServer.entity`'s does.
|
|
465
|
-
* `entities` adds Sources for entities no row backs, which the domain must not
|
|
466
|
-
* declare. The `layer` answers as `principal`, and is absent without one
|
|
467
|
-
* (unless `P` admits `undefined`); `server` answers as any. It does not push
|
|
468
|
-
* live changes. It is not a server to deploy.
|
|
469
|
-
*/
|
|
470
|
-
declare function memory<P = undefined>(config: MemoryConfig<P> & MemoryAnswering<P>): MemoryBackend<P>;
|
|
471
|
-
declare function memory<P = undefined>(config: MemoryConfig<P>): MemoryServed<P>;
|
|
472
|
-
export declare const RemoteServer: {
|
|
473
|
-
/** A backend held in memory, for a first run, a test or a demo. See `memory`. */
|
|
474
|
-
memory: typeof memory;
|
|
475
|
-
/** A mutation outcome's report that `ref` now heads the connection. */
|
|
476
|
-
prepend: (connection: ConnectionIdentity, ref: {
|
|
477
|
-
readonly entity: string;
|
|
478
|
-
readonly id: string;
|
|
479
|
-
}) => ConnectionChange;
|
|
480
|
-
/** A mutation outcome's report that `ref` now ends the connection. */
|
|
481
|
-
append: (connection: ConnectionIdentity, ref: {
|
|
482
|
-
readonly entity: string;
|
|
483
|
-
readonly id: string;
|
|
484
|
-
}) => ConnectionChange;
|
|
485
|
-
/** A mutation outcome's report that `ref` left the connection. */
|
|
486
|
-
remove: (connection: ConnectionIdentity, ref: {
|
|
487
|
-
readonly entity: string;
|
|
488
|
-
readonly id: string;
|
|
489
|
-
}) => ConnectionChange;
|
|
490
|
-
/**
|
|
491
|
-
* An entity source. Given the Entity, every member it declares (fields,
|
|
492
|
-
* relations, derived members) may be requested; given anything with a
|
|
493
|
-
* `name` and `fields`, those fields. A request for anything else never
|
|
494
|
-
* reaches `read` or `authorize`. Given only a `name`, every field passes.
|
|
495
|
-
*/
|
|
496
|
-
entity: <P = unknown, R = never>(entity: EntityName, options: {
|
|
497
|
-
readonly read: EntitySource<P, R>['read'];
|
|
498
|
-
readonly authorize?: EntitySource<P, R>['authorize'];
|
|
499
|
-
readonly filter?: EntitySource<P, R>['filter'];
|
|
500
|
-
/** See `EntitySource.shared`: each must be a member the source serves. */
|
|
501
|
-
readonly shared?: ReadonlyArray<string> | undefined;
|
|
502
|
-
}) => EntitySource<P, R>;
|
|
503
|
-
mutation: <P = unknown, R = never, Name extends string = string, Input = unknown, Output = unknown, Refused = unknown>(mutation: MutationDescriptor<Name, Input, Output, Refused>, run: (context: {
|
|
504
|
-
readonly input: Input;
|
|
505
|
-
readonly principal: P;
|
|
506
|
-
/** The client's id for this request, unique within that client only. */
|
|
507
|
-
readonly requestId: string;
|
|
508
|
-
/** The operation's identity across clients, for a record of the write; see `MutationSource`. */
|
|
509
|
-
readonly operation: Option.Option<string>;
|
|
510
|
-
}) => Effect.Effect<MutationOutcome<Output>, RemoteServerError | MutationRefused | RemoteForbidden, R>) => MutationSource<P, R>;
|
|
511
|
-
/**
|
|
512
|
-
* A refusal of `mutation`, as a value of its declared `Refusal`: fail a
|
|
513
|
-
* Source with it (`yield* RemoteServer.refuse(SavePost, { _tag: 'Field', ... })`)
|
|
514
|
-
* and the client reads it, decoded, with `Data.refusal`. `message` is what a
|
|
515
|
-
* person reads, beside it.
|
|
516
|
-
*/
|
|
517
|
-
refuse: <Refused>(mutation: MutationDescriptor<string, any, any, Refused>, refusal: NoInfer<Refused>, message?: string) => MutationRefused;
|
|
518
|
-
/**
|
|
519
|
-
* A writer's refusal of a row that does not hold the write's `when`: fail
|
|
520
|
-
* `update` or `delete` with it (`yield* RemoteServer.unmet()`), and
|
|
521
|
-
* `RemoteServer.write` answers the mutation's `Unmet` refusal.
|
|
522
|
-
*/
|
|
523
|
-
unmet: (message?: string) => RemoteUnmet;
|
|
524
|
-
/**
|
|
525
|
-
* A writer's refusal of a row that would break an invariant: fail `update`
|
|
526
|
-
* or `insert` with it, naming the invariant's id and path when the caller
|
|
527
|
-
* may be told them, and `RemoteServer.write` answers the mutation's
|
|
528
|
-
* `Invalid` refusal.
|
|
529
|
-
*/
|
|
530
|
-
invalid: (message: string, rule?: Option.Option<string>, path?: ReadonlyArray<string>) => RemoteInvalid;
|
|
531
|
-
/**
|
|
532
|
-
* A refusal of who is asking: fail a Source with it
|
|
533
|
-
* (`yield* RemoteServer.forbid()`) and the write never runs. `reason`, when
|
|
534
|
-
* given, is what the person who asked reads; without it the refusal says
|
|
535
|
-
* nothing of why. `answer` sends it as a 403, and the client's mutation
|
|
536
|
-
* fails with `_tag: 'Forbidden'`.
|
|
537
|
-
*/
|
|
538
|
-
forbid: (reason?: string) => RemoteForbidden;
|
|
539
|
-
/**
|
|
540
|
-
* A refusal of a caller who could not be told: a `serveFetch` or
|
|
541
|
-
* `defineDocumentHost` resolver fails with it (`RemoteServer.unauthenticated()`)
|
|
542
|
-
* when the credential it was sent no longer holds. It answers 401, with
|
|
543
|
-
* `reason`, when given, for the person who asked.
|
|
544
|
-
*/
|
|
545
|
-
unauthenticated: (reason?: string) => RemoteUnauthenticated;
|
|
546
|
-
/**
|
|
547
|
-
* The Source of a mutation that is a declared `Write`, with no handler: the
|
|
548
|
-
* input bound to the write lands through `writer`, and the row as written
|
|
549
|
-
* answers as a patch (a deletion as `deleted`). An update writes only the
|
|
550
|
-
* keys the client named, when it named some, and fails for a row that is not
|
|
551
|
-
* there; an insert of an id already holding what it writes (a retry)
|
|
552
|
-
* answers with that row, and of one holding anything else fails; a delete of
|
|
553
|
-
* a row already gone succeeds. A row that moved past the revision the write
|
|
554
|
-
* `expect`s is refused as a conflict, and one that does not hold its `when`
|
|
555
|
-
* as unmet; a write with a `when` needs a writer that checks it
|
|
556
|
-
* (`preconditions`), and is refused here without one.
|
|
557
|
-
*/
|
|
558
|
-
write: <P = unknown, R = never, Name extends string = string, Input = unknown, Refused extends {
|
|
559
|
-
readonly _tag: 'Conflict' | 'Unmet' | 'Invalid';
|
|
560
|
-
} = {
|
|
561
|
-
readonly _tag: 'Conflict';
|
|
562
|
-
}>(mutation: MutationDescriptor<Name, Input, {}, Refused> & {
|
|
563
|
-
readonly write: AnyWrite;
|
|
564
|
-
}, writer: EntityWriter<P, R>) => MutationSource<P, R>;
|
|
565
|
-
query: <P = unknown, R = never, Input = unknown>(query: QueryDescriptor<string, Input, unknown>, run: (context: {
|
|
566
|
-
readonly input: Input;
|
|
567
|
-
readonly window: QueryWindow;
|
|
568
|
-
readonly principal: P;
|
|
569
|
-
readonly select?: RelationRequirement | undefined;
|
|
570
|
-
}) => Effect.Effect<QueryPage, RemoteServerError, R>) => QuerySource<P, R>;
|
|
571
|
-
/** Streams live entity patches for a client's live requirements. */
|
|
572
|
-
live: <P = unknown, R = never>(entity: EntityName, options: {
|
|
573
|
-
readonly subscribe: LiveSource<P, R>['subscribe'];
|
|
574
|
-
}) => LiveSource<P, R>;
|
|
575
|
-
/**
|
|
576
|
-
* A `LiveHub` over entity sources. Pass it to `handlers` as `live`, and every
|
|
577
|
-
* mutation's answered patches and deletions are published to it; call
|
|
578
|
-
* `hub.changed(ref, fields)` yourself only for a write that is not a
|
|
579
|
-
* mutation (a database trigger, a job). Each subscriber that selects any of
|
|
580
|
-
* those fields receives them, re-read through the entity source under its
|
|
581
|
-
* own principal.
|
|
582
|
-
*/
|
|
583
|
-
liveHub: typeof liveHub;
|
|
584
|
-
make: <P = unknown, R = never>(config: {
|
|
585
|
-
readonly entities: readonly EntitySource<P, R>[];
|
|
586
|
-
readonly mutations?: readonly MutationSource<P, R>[];
|
|
587
|
-
readonly queries?: readonly QuerySource<P, R>[];
|
|
588
|
-
readonly live?: readonly LiveSource<P, R>[];
|
|
589
|
-
}) => ServerDefinition<P, R>;
|
|
590
|
-
/**
|
|
591
|
-
* Checks every source name against the declared domain, so an undeclared
|
|
592
|
-
* entity/query/mutation fails at startup rather than returning nothing at
|
|
593
|
-
* call time.
|
|
594
|
-
*/
|
|
595
|
-
validate: (domain: RemoteDescriptor, server: ServerDefinition<any, any>) => void;
|
|
596
|
-
/**
|
|
597
|
-
* Reads entity requirements through the entity sources, level by level,
|
|
598
|
-
* following relations as `FoldkitRemoteRead` does. Shared by the read
|
|
599
|
-
* handler and the query handler's payload: a query page's items are just
|
|
600
|
-
* requirements the page names, so one response carries both.
|
|
601
|
-
*/
|
|
602
|
-
readHelper: <P, R>(server: ServerDefinition<P, R>, principal: P, options: HandlerOptions<P, R>, requests: ReadonlyArray<Requirement>) => Effect.Effect<{
|
|
603
|
-
readonly entities: Array<{
|
|
604
|
-
readonly entity: string;
|
|
605
|
-
readonly id: string;
|
|
606
|
-
readonly values: Record<string, unknown>;
|
|
607
|
-
}>;
|
|
608
|
-
readonly settled: Array<{
|
|
609
|
-
readonly entity: string;
|
|
610
|
-
readonly id: string;
|
|
611
|
-
readonly fields: Array<string>;
|
|
612
|
-
}>;
|
|
613
|
-
}, RemoteReadError, R>;
|
|
614
|
-
/**
|
|
615
|
-
* Answers one JSON request through `handlers`: what an HTTP endpoint, a
|
|
616
|
-
* worker or a server in the page calls with the body it received, parsed.
|
|
617
|
-
* The request and its payload are decoded by the protocol's own schemas
|
|
618
|
-
* before a handler sees them, so an operation name is one of Remote's three
|
|
619
|
-
* and nothing else. A body that is not a request is a 400; a caller who
|
|
620
|
-
* could not be told a 401; a refusal of who is asking a 403; a handler's
|
|
621
|
-
* failure a 500 with its message; a defect a 500 that says nothing of it.
|
|
622
|
-
* `Remote.json` and `Remote.http` are the other end.
|
|
623
|
-
*/
|
|
624
|
-
answer: <R>(handlers: RemoteRpcClient<R>, body: unknown) => Effect.Effect<{
|
|
625
|
-
readonly status: 200 | 400 | 401 | 403 | 422 | 500;
|
|
626
|
-
readonly body: RemoteJsonAnswer;
|
|
627
|
-
}, never, R>;
|
|
628
|
-
/**
|
|
629
|
-
* Compiles the server into Remote's RPC handlers, answering as `principal`:
|
|
630
|
-
* a value, or a Context key (`G.Principal`) read on each call, which
|
|
631
|
-
* authentication provides per request. Unknown entities, entities with no
|
|
632
|
-
* allowed fields, and unknown mutations return an error or nothing rather
|
|
633
|
-
* than leaking existence.
|
|
634
|
-
*/
|
|
635
|
-
handlers: <P, R, I = never>(server: ServerDefinition<P, R>, principal: P | Context.Key<I, P>, options?: HandlerOptions<P, R>) => RemoteRpcClient<R | I>;
|
|
636
|
-
};
|
|
637
|
-
export { QueryEvaluateError, type Row, assertSupported, evaluate, supported };
|
|
638
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { A as WriteRequirement, B as assertSupported, C as RemoteInvalid, D as RemoteUnmet, E as RemoteTaken, F as PublishFailed, H as supported, I as RemoteServerDiagnostic, L as ServerDefect, M as exprContext, N as AnswerUnread, O as RowRequirement, P as ClockSkewed, R as QueryEvaluateError, S as ReadPlan, T as RemoteServerError, V as evaluate, _ as MutationOutcome, a as EntityWriter, b as QueryPage, c as LiveQuery, d as MemoryBackend, f as MemoryConfig, g as MemoryStore, h as MemoryServed, i as EntitySourceContext, j as WriteWhen, k as ServerDefinition, l as LiveSource, m as MemoryRows, n as EntityRecord, o as HandlerOptions, p as MemoryReadable, r as EntitySource, s as LiveHub, t as ConnectionChange, u as MemoryAnswering, v as MutationRefused, w as RemoteServer, x as QuerySource, y as MutationSource, z as Row } from "./index-BnaRbvjr.mjs";
|
|
2
|
+
export { type AnswerUnread, type ClockSkewed, ConnectionChange, EntityRecord, EntitySource, EntitySourceContext, EntityWriter, HandlerOptions, LiveHub, LiveQuery, LiveSource, MemoryAnswering, MemoryBackend, MemoryConfig, MemoryReadable, MemoryRows, MemoryServed, MemoryStore, MutationOutcome, MutationRefused, MutationSource, type PublishFailed, QueryEvaluateError, QueryPage, QuerySource, ReadPlan, RemoteInvalid, RemoteServer, type RemoteServerDiagnostic, RemoteServerError, RemoteTaken, RemoteUnmet, type Row, RowRequirement, type ServerDefect, ServerDefinition, WriteRequirement, WriteWhen, assertSupported, evaluate, exprContext, supported };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as MutationRefused,
|
|
1
|
+
export { t as MutationRefused, l as QueryEvaluateError, n as RemoteInvalid, r as RemoteServer, i as RemoteServerError, a as RemoteTaken, o as RemoteUnmet, s as RowRequirement, u as assertSupported, d as evaluate, c as exprContext, f as supported } from "./src-ZV9pARkU.mjs";
|