foldkit-remote-server 0.20.0 → 0.22.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 +323 -29
- package/dist/fetch.d.mts +62 -5
- package/dist/fetch.d.mts.map +1 -1
- package/dist/fetch.mjs +261 -16
- package/dist/fetch.mjs.map +1 -1
- package/dist/{index-B85UhEfk.d.mts → index-lJvjBBDL.d.mts} +78 -6
- package/dist/index-lJvjBBDL.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{src-D8azLxgd.mjs → src-B1JAs_gH.mjs} +57 -7
- package/dist/src-B1JAs_gH.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/index-B85UhEfk.d.mts.map +0 -1
- package/dist/src-D8azLxgd.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cause, Context, Data, Duration, Effect, Layer, Option, Schema, Stream } from "effect";
|
|
2
2
|
import { AnyQuery, AnyWrite, Computation, EntityRef, ExprContext, MemoryOperators, QueryEvaluateError, Row, WriteAssignment, assertSupported as assertSupported$1, evaluate as evaluate$1, supported } from "foldkit-entity";
|
|
3
|
-
import { Boundary, ConnectionChangeSchema, ConnectionIdentity, ConnectionSpec, Diagnostic, LiveChange, MutationDescriptor, NormalizedPatch, QueryDescriptor, QueryWindow, RelationRequirement, RemoteClient, RemoteDescriptor, RemoteForbidden, RemoteJsonAnswer, RemoteReadError, RemoteRpcClient, RemoteUnauthenticated, Requirement } from "foldkit-remote";
|
|
3
|
+
import { Boundary, CachePolicy, ConnectionChangeSchema, ConnectionIdentity, ConnectionSpec, Diagnostic, LiveChange, MutationDescriptor, NormalizedPatch, QueryDescriptor, QueryWindow, RelationRequirement, RemoteClient, RemoteDescriptor, RemoteForbidden, RemoteJsonAnswer, RemoteReadError, RemoteRpcClient, RemoteUnauthenticated, Requirement } from "foldkit-remote";
|
|
4
4
|
import { HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
5
5
|
/**
|
|
6
6
|
* Effect HTTP middleware refusing a request body over `maxBytes` (default
|
|
@@ -52,8 +52,19 @@ interface ClockSkewed extends Diagnostic {
|
|
|
52
52
|
/** The bound, in milliseconds. */
|
|
53
53
|
readonly bound: number;
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* A read the server judged public answered otherwise for who asked than for
|
|
57
|
+
* the visitor (`serveFetch`'s `cache.check`): its declaration or a source's
|
|
58
|
+
* `read` depends on who asks, so it must not be cached. The asker was given
|
|
59
|
+
* their own answer.
|
|
60
|
+
*/
|
|
61
|
+
interface CachedReadDiffers extends Diagnostic {
|
|
62
|
+
readonly _tag: 'CachedReadDiffers';
|
|
63
|
+
/** The request, as the JSON it was sent as. */
|
|
64
|
+
readonly request: string;
|
|
65
|
+
}
|
|
55
66
|
/** Every diagnostic a Remote server reports. */
|
|
56
|
-
type RemoteServerDiagnostic = ServerDefect | AnswerUnread | PublishFailed | ClockSkewed;
|
|
67
|
+
type RemoteServerDiagnostic = ServerDefect | AnswerUnread | PublishFailed | ClockSkewed | CachedReadDiffers;
|
|
57
68
|
declare const RemoteServerError_base: Schema.Class<RemoteServerError, Schema.TaggedStruct<"RemoteServerError", {
|
|
58
69
|
readonly message: Schema.String;
|
|
59
70
|
}>, Cause.YieldableError>;
|
|
@@ -159,6 +170,12 @@ interface EntitySource<P, R = never> {
|
|
|
159
170
|
* without one.
|
|
160
171
|
*/
|
|
161
172
|
readonly perViewer?: ReadonlyArray<string> | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* How long a read of these rows stays fresh, from the Entity's declaration
|
|
175
|
+
* (`EdgeCache.of`). It never makes a read public: `serveFetch` caches one
|
|
176
|
+
* only where nothing about it depends on who asks.
|
|
177
|
+
*/
|
|
178
|
+
readonly cache?: CachePolicy | undefined;
|
|
162
179
|
}
|
|
163
180
|
/** What `EntitySource.filter` decides for one read. */
|
|
164
181
|
interface ReadPlan {
|
|
@@ -218,6 +235,17 @@ interface WriteRequirement {
|
|
|
218
235
|
readonly holds: RowRequirement;
|
|
219
236
|
readonly reason: Option.Option<string>;
|
|
220
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* What each row of `entity` a cascading delete would take must hold (#348):
|
|
240
|
+
* that Entity's `Delete` rule for the person deleting. A writer with
|
|
241
|
+
* `cascades` refuses the whole delete as `Forbidden` when any such row does
|
|
242
|
+
* not, and removes nothing. Only rows reached through a relation whose
|
|
243
|
+
* `authorizedBy` is `child` are held to it.
|
|
244
|
+
*/
|
|
245
|
+
interface CascadeRequirement {
|
|
246
|
+
readonly entity: string;
|
|
247
|
+
readonly requires: WriteRequirement;
|
|
248
|
+
}
|
|
221
249
|
/** A row a delete removed with the row it was asked to delete (`onDelete: 'cascade'`). */
|
|
222
250
|
interface CascadedRow {
|
|
223
251
|
readonly entity: string;
|
|
@@ -228,23 +256,36 @@ interface CascadedRow {
|
|
|
228
256
|
/**
|
|
229
257
|
* What a writer's `delete` did. `Deleted`: the row is gone, with `cascaded`,
|
|
230
258
|
* the rows declared to go with it (`Relation.one(…, { onDelete: 'cascade' })`)
|
|
231
|
-
* that the principal may see
|
|
259
|
+
* that the principal may see, and `cleared`, those whose link to it was
|
|
260
|
+
* cleared (`onDelete: 'setNull'`), which stay. `Absent`: no row, so nothing to delete (a
|
|
232
261
|
* retry's case). `Moved`: the row is there at another revision, and stays.
|
|
262
|
+
* `Referenced`: rows still point at it through `relation` (`Like.post`),
|
|
263
|
+
* declared `onDelete: 'restrict'`, so it stays; which rows is not said.
|
|
233
264
|
*/
|
|
234
265
|
type DeleteOutcome = Data.TaggedEnum<{
|
|
235
266
|
Deleted: {
|
|
236
267
|
readonly cascaded: ReadonlyArray<CascadedRow>;
|
|
268
|
+
readonly cleared: ReadonlyArray<EntityRef>;
|
|
237
269
|
};
|
|
238
270
|
Absent: {};
|
|
239
271
|
Moved: {};
|
|
272
|
+
Referenced: {
|
|
273
|
+
readonly entity: string;
|
|
274
|
+
readonly relation: string;
|
|
275
|
+
};
|
|
240
276
|
}>;
|
|
241
277
|
declare const DeleteOutcome: Data.TaggedEnum.Constructor<{
|
|
242
278
|
readonly _tag: "Absent";
|
|
243
279
|
} | {
|
|
244
280
|
readonly _tag: "Deleted";
|
|
245
281
|
readonly cascaded: ReadonlyArray<CascadedRow>;
|
|
282
|
+
readonly cleared: ReadonlyArray<EntityRef>;
|
|
246
283
|
} | {
|
|
247
284
|
readonly _tag: "Moved";
|
|
285
|
+
} | {
|
|
286
|
+
readonly _tag: "Referenced";
|
|
287
|
+
readonly entity: string;
|
|
288
|
+
readonly relation: string;
|
|
248
289
|
}>;
|
|
249
290
|
interface EntityWriter<P, R = never> {
|
|
250
291
|
readonly entity: string;
|
|
@@ -312,10 +353,29 @@ interface EntityWriter<P, R = never> {
|
|
|
312
353
|
/**
|
|
313
354
|
* Whether `delete` removes, in the transaction that deletes the row, every
|
|
314
355
|
* row declared to go with it (`Entity.cascading`), and answers them as
|
|
315
|
-
* `cascaded
|
|
356
|
+
* `cascaded`; and holds those rows to the `cascading` requirements it is
|
|
357
|
+
* given, judged before anything is removed, refusing the whole delete
|
|
358
|
+
* where one fails. `RemoteServer.write` refuses a delete of an Entity that
|
|
316
359
|
* cascades through a writer without it.
|
|
317
360
|
*/
|
|
318
361
|
readonly cascades?: true;
|
|
362
|
+
/**
|
|
363
|
+
* Whether `delete` refuses, in the statement that deletes, a row that rows
|
|
364
|
+
* point at through a relation declared `onDelete: 'restrict'`
|
|
365
|
+
* (`Entity.restricting`), answering `Referenced`. `RemoteServer.write`
|
|
366
|
+
* refuses a delete of an Entity something restricts through a writer
|
|
367
|
+
* without it.
|
|
368
|
+
*/
|
|
369
|
+
readonly restricts?: true;
|
|
370
|
+
/**
|
|
371
|
+
* Whether `delete` clears, in the transaction that deletes the row, the link
|
|
372
|
+
* of every row pointing at it through a relation declared `onDelete:
|
|
373
|
+
* 'setNull'` (`Entity.clearing`), answers the rows the principal may see as
|
|
374
|
+
* `cleared`, and holds them to the `clearing` requirements it is given,
|
|
375
|
+
* refusing the whole delete where one fails. `RemoteServer.write` refuses a
|
|
376
|
+
* delete of an Entity something clears through a writer without it.
|
|
377
|
+
*/
|
|
378
|
+
readonly clears?: true;
|
|
319
379
|
/**
|
|
320
380
|
* Why this writer cannot land `write`, each a sentence; none when it can.
|
|
321
381
|
* `RemoteServer.write` asks once, where the write is registered, for what
|
|
@@ -407,6 +467,16 @@ interface EntityWriter<P, R = never> {
|
|
|
407
467
|
readonly when: Option.Option<WriteWhen>;
|
|
408
468
|
/** What the row must hold, judged where it is deleted; only a writer with `requires` is given one. */
|
|
409
469
|
readonly requires?: WriteRequirement | undefined;
|
|
470
|
+
/**
|
|
471
|
+
* What the rows a cascade takes must hold, by Entity; only a writer with
|
|
472
|
+
* `cascades` is given them.
|
|
473
|
+
*/
|
|
474
|
+
readonly cascading?: ReadonlyArray<CascadeRequirement> | undefined;
|
|
475
|
+
/**
|
|
476
|
+
* What each row whose link the delete clears must hold, by Entity: its
|
|
477
|
+
* `Update` rules over the link. Only a writer with `clears` is given them.
|
|
478
|
+
*/
|
|
479
|
+
readonly clearing?: ReadonlyArray<CascadeRequirement> | undefined;
|
|
410
480
|
readonly principal: P;
|
|
411
481
|
}) => Effect.Effect<DeleteOutcome, RemoteServerError | RemoteForbidden | RemoteUnauthenticated | RemoteUnmet, R>;
|
|
412
482
|
/**
|
|
@@ -551,6 +621,8 @@ interface QuerySource<P, R = never> {
|
|
|
551
621
|
}) => Effect.Effect<QueryPage, RemoteServerError, R>;
|
|
552
622
|
/** The rule that decides which rows the query lists. See `EntitySource.visible`. */
|
|
553
623
|
readonly visible?: unknown;
|
|
624
|
+
/** How long an answer stays fresh, from the Query's declaration. See `EntitySource.cache`. */
|
|
625
|
+
readonly cache?: CachePolicy | undefined;
|
|
554
626
|
}
|
|
555
627
|
/**
|
|
556
628
|
* A list a subscriber reads live (`liveQuery(Data, …)`), admitted
|
|
@@ -994,5 +1066,5 @@ declare const RemoteServer: {
|
|
|
994
1066
|
*/
|
|
995
1067
|
handlers: <P, R, I = never>(server: ServerDefinition<P, R>, principal: P | Context.Key<I, P>, options?: HandlerOptions<P, R>) => RemoteRpcClient<R | I>;
|
|
996
1068
|
};
|
|
997
|
-
export {
|
|
998
|
-
//# sourceMappingURL=index-
|
|
1069
|
+
export { RemoteUnmet as A, RemoteServerDiagnostic as B, QueryPage as C, RemoteServer as D, RemoteInvalid as E, exprContext as F, assertSupported$1 as G, bodyLimit as H, AnswerUnread as I, evaluate$1 as K, CachedReadDiffers as L, ServerDefinition as M, WriteRequirement as N, RemoteServerError as O, WriteWhen as P, ClockSkewed as R, MutationSource as S, ReadPlan as T, QueryEvaluateError as U, ServerDefect as V, Row as W, MemoryRows as _, EntityRecord as a, MutationOutcome as b, EntityWriter as c, LiveQuery as d, LiveSource as f, MemoryReadable as g, MemoryConfig as h, DeleteOutcome as i, RowRequirement as j, RemoteTaken as k, HandlerOptions as l, MemoryBackend as m, CascadedRow as n, EntitySource as o, MemoryAnswering as p, supported as q, ConnectionChange as r, EntitySourceContext as s, CascadeRequirement as t, LiveHub as u, MemoryServed as v, QuerySource as w, MutationRefused as x, MemoryStore as y, PublishFailed as z };
|
|
1070
|
+
//# sourceMappingURL=index-lJvjBBDL.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-lJvjBBDL.d.mts","names":[],"sources":["../src/body.ts","../src/diagnostics.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;cAmIa,YAAS,uBAEnB,GAAG,GAAC,UACO,OAAO,OAAO,mBAAmB,oBAAoB,GAAG,OACjE,OAAO,OACR,mBAAmB,oBACnB,GACA,IAAI,kBAAkB;;UC7HT,qBAAqB;WAC3B;WACA,OAAO,MAAM;;;;;;UAOP,qBAAqB;WAC3B;WACA;;WAEA;;;UAIM,sBAAsB;WAC5B;WACA;WACA,OAAO,MAAM;;;;;;;UAQP,oBAAoB;WAC1B;WACA;;WAEA;;WAEA;;WAEA;;;;;;;;U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;;;EA2ES,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,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { type AnswerUnread, CascadedRow, type ClockSkewed, ConnectionChange, DeleteOutcome, 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, bodyLimit, evaluate, exprContext, supported };
|
|
1
|
+
import { A as RemoteUnmet, B as RemoteServerDiagnostic, C as QueryPage, D as RemoteServer, E as RemoteInvalid, F as exprContext, G as assertSupported, H as bodyLimit, I as AnswerUnread, K as evaluate, L as CachedReadDiffers, M as ServerDefinition, N as WriteRequirement, O as RemoteServerError, P as WriteWhen, R as ClockSkewed, S as MutationSource, T as ReadPlan, U as QueryEvaluateError, V as ServerDefect, W as Row, _ as MemoryRows, a as EntityRecord, b as MutationOutcome, c as EntityWriter, d as LiveQuery, f as LiveSource, g as MemoryReadable, h as MemoryConfig, i as DeleteOutcome, j as RowRequirement, k as RemoteTaken, l as HandlerOptions, m as MemoryBackend, n as CascadedRow, o as EntitySource, p as MemoryAnswering, q as supported, r as ConnectionChange, s as EntitySourceContext, t as CascadeRequirement, u as LiveHub, v as MemoryServed, w as QuerySource, x as MutationRefused, y as MemoryStore, z as PublishFailed } from "./index-lJvjBBDL.mjs";
|
|
2
|
+
export { type AnswerUnread, type CachedReadDiffers, CascadeRequirement, CascadedRow, type ClockSkewed, ConnectionChange, DeleteOutcome, 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, bodyLimit, evaluate, exprContext, supported };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as DeleteOutcome, n as MutationRefused,
|
|
1
|
+
export { t as DeleteOutcome, n as MutationRefused, h as QueryEvaluateError, r as RemoteInvalid, i as RemoteServer, a as RemoteServerError, o as RemoteTaken, s as RemoteUnmet, c as RowRequirement, g as assertSupported, u as bodyLimit, _ as evaluate, l as exprContext, v as supported } from "./src-B1JAs_gH.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cause, Clock, Context, Data, Duration, Effect, Match, Option, Queue, Schema, Stream } from "effect";
|
|
2
2
|
import { Derivation, Entity, Held, Operators, Query, QueryEvaluateError, SchemaShape, Write, assertSupported, assertSupported as assertSupported$1, evaluate, evaluate as evaluate$1, supported } from "foldkit-entity";
|
|
3
|
-
import { DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_IDS_PER_ENTITY, Diagnostics, MutationRequest, QueryRequest, RELATION_ALIAS, REMOTE_PROTOCOL_VERSION, ReadBatch, Refusal, Remote, RemoteForbidden, RemoteJsonRequest, RemoteLiveError, RemoteLiveRefused, RemoteMutationError, RemotePrincipalChanged, RemoteProtocolError, RemoteQueryError, RemoteReadError, RemoteUnauthenticated, Requirement, aliasedField, connectionIdentity, entityKey, queryIdentity, refParts, refsIn, relationShape, stableStringify } from "foldkit-remote";
|
|
3
|
+
import { DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_IDS_PER_ENTITY, Diagnostics, EdgeCache, MutationRequest, QueryRequest, RELATION_ALIAS, REMOTE_PROTOCOL_VERSION, ReadBatch, Refusal, Remote, RemoteForbidden, RemoteJsonRequest, RemoteLiveError, RemoteLiveRefused, RemoteMutationError, RemotePrincipalChanged, RemoteProtocolError, RemoteQueryError, RemoteReadError, RemoteUnauthenticated, Requirement, aliasedField, connectionIdentity, entityKey, queryIdentity, refParts, refsIn, relationShape, stableStringify } from "foldkit-remote";
|
|
4
4
|
import { HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
5
5
|
// src/diagnostics.ts
|
|
6
6
|
/**
|
|
@@ -41,6 +41,13 @@ const clockSkewed = (facts) => ({
|
|
|
41
41
|
message: `${facts.mutation} was sent at ${facts.sent}, ${Math.abs(facts.sent - facts.own)} ms from this server's clock (${facts.own}), past its clockSkew of ${facts.bound} ms: it was written at the server's time, so the client's prediction of it moves when the answer lands. The client's clock is off, or the request waited that long.`,
|
|
42
42
|
...facts
|
|
43
43
|
});
|
|
44
|
+
const cachedReadDiffers = (request) => ({
|
|
45
|
+
_tag: "CachedReadDiffers",
|
|
46
|
+
source,
|
|
47
|
+
level: "error",
|
|
48
|
+
message: `a read judged public was answered otherwise for who asked than for a visitor, so it is not the same for everyone and must not be cached; find what in its sources depends on who asks: ${request}`,
|
|
49
|
+
request
|
|
50
|
+
});
|
|
44
51
|
// src/refusal.ts
|
|
45
52
|
/** A caller who could not be told, as a 401 body: the twin of `answer`'s 403. */
|
|
46
53
|
const unauthenticatedAnswer = (refusal) => ({
|
|
@@ -71,6 +78,28 @@ const declaresTooLarge = (request, limit) => {
|
|
|
71
78
|
return Number.isFinite(length) && length > limit;
|
|
72
79
|
};
|
|
73
80
|
/**
|
|
81
|
+
* Consumes a body nobody read, before a refusal is answered: workerd drops the
|
|
82
|
+
* connection the next request shares when an answer leaves a body unread, and
|
|
83
|
+
* cancelling it is not enough. Read up to `limit` bytes and discarded, then
|
|
84
|
+
* cancelled, so a refusal never reads more than a request may carry.
|
|
85
|
+
*/
|
|
86
|
+
const discardBody = async (request, limit) => {
|
|
87
|
+
if (request.body === null || request.bodyUsed) return;
|
|
88
|
+
const reader = request.body.getReader();
|
|
89
|
+
let total = 0;
|
|
90
|
+
try {
|
|
91
|
+
for (;;) {
|
|
92
|
+
const { done, value } = await reader.read();
|
|
93
|
+
if (done) return;
|
|
94
|
+
total += value.byteLength;
|
|
95
|
+
if (total > limit) break;
|
|
96
|
+
}
|
|
97
|
+
} catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
await reader.cancel().catch(() => {});
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
74
103
|
* `request`'s body, at most `limit` bytes of it. Rejects with `BodyTooLarge`
|
|
75
104
|
* once more arrive, having cancelled the rest, or with the stream's own error.
|
|
76
105
|
*/
|
|
@@ -85,7 +114,7 @@ const readBounded = async (request, limit) => {
|
|
|
85
114
|
if (done) break;
|
|
86
115
|
total += value.byteLength;
|
|
87
116
|
if (total > limit) {
|
|
88
|
-
|
|
117
|
+
reader.cancel().catch(() => {});
|
|
89
118
|
throw new BodyTooLarge();
|
|
90
119
|
}
|
|
91
120
|
chunks.push(value);
|
|
@@ -801,6 +830,10 @@ function memory(config) {
|
|
|
801
830
|
const visible = config.readable === void 0 ? {} : { visible: config.readable };
|
|
802
831
|
const entities = [...config.domain.registry.entities.keys()].map((name) => ({
|
|
803
832
|
...visible,
|
|
833
|
+
...Option.match(Option.fromUndefinedOr(config.domain.registry.cached.get(name)), {
|
|
834
|
+
onNone: () => ({}),
|
|
835
|
+
onSome: (cache) => ({ cache })
|
|
836
|
+
}),
|
|
804
837
|
...RemoteServer.entity({ name }, {
|
|
805
838
|
...Object.hasOwn(authorize, name) ? { authorize: authorize[name] } : {},
|
|
806
839
|
...Object.hasOwn(filter, name) ? { filter: filter[name] } : {},
|
|
@@ -1038,6 +1071,7 @@ const RemoteServer = {
|
|
|
1038
1071
|
entity: (entity, options) => {
|
|
1039
1072
|
const declared = entity.members ?? entity.fields;
|
|
1040
1073
|
const fields = declared === void 0 ? void 0 : new Set(Object.keys(declared));
|
|
1074
|
+
const cache = EdgeCache.policyOf(entity);
|
|
1041
1075
|
const unserved = (options.shared ?? []).filter((field) => fields !== void 0 && !fields.has(field));
|
|
1042
1076
|
if (unserved.length > 0) throw new Error(`[foldkit-remote-server] ${entity.name}'s shared fields name no member: ${unserved.join(", ")}`);
|
|
1043
1077
|
return {
|
|
@@ -1046,7 +1080,8 @@ const RemoteServer = {
|
|
|
1046
1080
|
read: options.read,
|
|
1047
1081
|
...options.authorize === void 0 ? {} : { authorize: options.authorize },
|
|
1048
1082
|
...options.filter === void 0 ? {} : { filter: options.filter },
|
|
1049
|
-
...options.shared === void 0 ? {} : { shared: new Set(options.shared) }
|
|
1083
|
+
...options.shared === void 0 ? {} : { shared: new Set(options.shared) },
|
|
1084
|
+
...Option.isSome(cache) ? { cache: cache.value } : {}
|
|
1050
1085
|
};
|
|
1051
1086
|
},
|
|
1052
1087
|
mutation: (mutation, run) => ({
|
|
@@ -1198,15 +1233,21 @@ const RemoteServer = {
|
|
|
1198
1233
|
const pointers = pointersOf(write.input.entity);
|
|
1199
1234
|
const cascadePointers = /* @__PURE__ */ new Map();
|
|
1200
1235
|
if (kind.deletes) {
|
|
1236
|
+
const named = (entity) => Entity.restricting(entity).map(({ relation, owner }) => `${owner.name}.${relation.key}`).join(", ");
|
|
1201
1237
|
const reach = (entity) => {
|
|
1202
1238
|
for (const { owner } of Entity.cascading(entity)) {
|
|
1203
1239
|
if (cascadePointers.has(owner.name)) continue;
|
|
1240
|
+
if (Entity.clearing(owner).length > 0) throw new Error(`[foldkit-remote-server] delete "${mutation.name}" removes ${write.input.entity.name}, whose cascade takes ${owner.name} rows, whose links ${Entity.clearing(owner).map(({ relation, owner: from }) => `${from.name}.${relation.key}`).join(", ")} clear (onDelete: 'setNull'); a cascade into such an Entity is not supported`);
|
|
1241
|
+
if (Entity.restricting(owner).length > 0) throw new Error(`[foldkit-remote-server] delete "${mutation.name}" removes ${write.input.entity.name}, whose cascade takes ${owner.name} rows, which ${named(owner)} restricts (onDelete: 'restrict'); a cascade into a restricted Entity is not supported: restrict ${write.input.entity.name} instead, or cascade ${owner.name}'s pointers too`);
|
|
1204
1242
|
cascadePointers.set(owner.name, pointersOf(owner));
|
|
1205
1243
|
reach(owner);
|
|
1206
1244
|
}
|
|
1207
1245
|
};
|
|
1208
1246
|
reach(write.input.entity);
|
|
1209
1247
|
if (cascadePointers.size > 0 && writer.cascades !== true) throw new Error(`[foldkit-remote-server] delete "${mutation.name}" removes ${write.input.entity.name}, whose rows take ${[...cascadePointers.keys()].join(", ")} with them (onDelete: 'cascade'), but its writer does not remove them (cascades)`);
|
|
1248
|
+
if (Entity.restricting(write.input.entity).length > 0 && writer.restricts !== true) throw new Error(`[foldkit-remote-server] delete "${mutation.name}" removes ${write.input.entity.name}, which ${named(write.input.entity)} restricts (onDelete: 'restrict'), but its writer does not refuse a row they point at (restricts)`);
|
|
1249
|
+
const cleared = Entity.clearing(write.input.entity);
|
|
1250
|
+
if (cleared.length > 0 && writer.clears !== true) throw new Error(`[foldkit-remote-server] delete "${mutation.name}" removes ${write.input.entity.name}, whose rows ${cleared.map(({ relation, owner }) => `${owner.name}.${relation.key}`).join(", ")} point at (onDelete: 'setNull'), but its writer does not clear them (clears)`);
|
|
1210
1251
|
}
|
|
1211
1252
|
/** What a removed row pointed at that its removal moves, as refs. */
|
|
1212
1253
|
const pointedBy = (row) => (cascadePointers.get(row.entity) ?? []).flatMap((key) => Option.match(Option.flatten(Option.fromUndefinedOr(row.links[key])), {
|
|
@@ -1384,8 +1425,16 @@ const RemoteServer = {
|
|
|
1384
1425
|
});
|
|
1385
1426
|
return yield* DeleteOutcome.$match(outcome, {
|
|
1386
1427
|
Moved: () => Effect.fail(conflict(bound)),
|
|
1428
|
+
Referenced: ({ entity, relation }) => Effect.fail(RemoteServer.refuse(mutation, Refusal.referenced.make({
|
|
1429
|
+
entity,
|
|
1430
|
+
relation
|
|
1431
|
+
}), `${bound.entity} ${bound.id} is still pointed at through ${entity}.${relation}`)),
|
|
1387
1432
|
Absent: () => Effect.succeed(gone([])),
|
|
1388
|
-
Deleted: ({ cascaded }) => Effect.succeed(naming(gone(cascaded), [
|
|
1433
|
+
Deleted: ({ cascaded, cleared }) => Effect.succeed(naming(gone(cascaded), [
|
|
1434
|
+
...before,
|
|
1435
|
+
...cascaded.flatMap(pointedBy),
|
|
1436
|
+
...cleared
|
|
1437
|
+
]))
|
|
1389
1438
|
});
|
|
1390
1439
|
})
|
|
1391
1440
|
}));
|
|
@@ -1396,6 +1445,7 @@ const RemoteServer = {
|
|
|
1396
1445
|
query: query.name,
|
|
1397
1446
|
entity: query.Result.entity,
|
|
1398
1447
|
Input: query.Input,
|
|
1448
|
+
...query.cache === void 0 ? {} : { cache: query.cache },
|
|
1399
1449
|
run: (context) => run({
|
|
1400
1450
|
input: context.input,
|
|
1401
1451
|
window: context.window,
|
|
@@ -1633,7 +1683,7 @@ const RemoteServer = {
|
|
|
1633
1683
|
status: 500,
|
|
1634
1684
|
body: { error: error.message }
|
|
1635
1685
|
} : {
|
|
1636
|
-
status: Refusal.isTaken(error.refusal) ? 409 : 422,
|
|
1686
|
+
status: Refusal.isTaken(error.refusal) || Refusal.isReferenced(error.refusal) ? 409 : 422,
|
|
1637
1687
|
body: {
|
|
1638
1688
|
error: error.message,
|
|
1639
1689
|
refusal: error.refusal
|
|
@@ -1770,6 +1820,6 @@ const RemoteServer = {
|
|
|
1770
1820
|
};
|
|
1771
1821
|
}
|
|
1772
1822
|
};
|
|
1773
|
-
export {
|
|
1823
|
+
export { evaluate$1 as _, RemoteServerError as a, cachedReadDiffers as b, RowRequirement as c, declaresTooLarge as d, discardBody as f, assertSupported$1 as g, QueryEvaluateError as h, RemoteServer as i, exprContext as l, tooLargeAnswer as m, MutationRefused as n, RemoteTaken as o, readJson as p, RemoteInvalid as r, RemoteUnmet as s, DeleteOutcome as t, bodyLimit as u, supported as v, serverDefect as x, unauthenticatedAnswer as y };
|
|
1774
1824
|
|
|
1775
|
-
//# sourceMappingURL=src-
|
|
1825
|
+
//# sourceMappingURL=src-B1JAs_gH.mjs.map
|