@superbee/core 0.2.0-pre.5 → 0.2.0-pre.8
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 +89 -0
- package/dist/bundle-ops.d.ts +1 -1
- package/dist/bundle-ops.d.ts.map +1 -1
- package/dist/bundle-ops.js +2 -2
- package/dist/bundle-ops.js.map +1 -1
- package/dist/document-codec.d.ts +5 -1
- package/dist/document-codec.d.ts.map +1 -1
- package/dist/document-codec.js +7 -4
- package/dist/document-codec.js.map +1 -1
- package/dist/document-write-policy.d.ts.map +1 -1
- package/dist/document-write-policy.js +4 -2
- package/dist/document-write-policy.js.map +1 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +4 -3
- package/dist/engine.js.map +1 -1
- package/dist/file-journaled-backend-internal.d.ts +19 -0
- package/dist/file-journaled-backend-internal.d.ts.map +1 -0
- package/dist/file-journaled-backend-internal.js +10 -0
- package/dist/file-journaled-backend-internal.js.map +1 -0
- package/dist/file-journaled-backend.d.ts +162 -0
- package/dist/file-journaled-backend.d.ts.map +1 -0
- package/dist/file-journaled-backend.js +1113 -0
- package/dist/file-journaled-backend.js.map +1 -0
- package/dist/filesystem-lock.d.ts +10 -0
- package/dist/filesystem-lock.d.ts.map +1 -1
- package/dist/filesystem-lock.js +283 -22
- package/dist/filesystem-lock.js.map +1 -1
- package/dist/filesystem-push-role.d.ts +77 -0
- package/dist/filesystem-push-role.d.ts.map +1 -0
- package/dist/filesystem-push-role.js +165 -0
- package/dist/filesystem-push-role.js.map +1 -0
- package/dist/governed-body-write.d.ts +8 -1
- package/dist/governed-body-write.d.ts.map +1 -1
- package/dist/governed-body-write.js +9 -2
- package/dist/governed-body-write.js.map +1 -1
- package/dist/host-text.d.ts +31 -0
- package/dist/host-text.d.ts.map +1 -0
- package/dist/host-text.js +77 -0
- package/dist/host-text.js.map +1 -0
- package/dist/hosted-transport/answer-rows.d.ts +216 -0
- package/dist/hosted-transport/answer-rows.d.ts.map +1 -0
- package/dist/hosted-transport/answer-rows.js +396 -0
- package/dist/hosted-transport/answer-rows.js.map +1 -0
- package/dist/hosted-transport/carrier.d.ts +142 -0
- package/dist/hosted-transport/carrier.d.ts.map +1 -0
- package/dist/hosted-transport/carrier.js +241 -0
- package/dist/hosted-transport/carrier.js.map +1 -0
- package/dist/hosted-transport/history-pages.d.ts +55 -0
- package/dist/hosted-transport/history-pages.d.ts.map +1 -0
- package/dist/hosted-transport/history-pages.js +69 -0
- package/dist/hosted-transport/history-pages.js.map +1 -0
- package/dist/hosted-transport/index.d.ts +18 -0
- package/dist/hosted-transport/index.d.ts.map +1 -0
- package/dist/hosted-transport/index.js +18 -0
- package/dist/hosted-transport/index.js.map +1 -0
- package/dist/hosted-transport/operations.d.ts +85 -0
- package/dist/hosted-transport/operations.d.ts.map +1 -0
- package/dist/hosted-transport/operations.js +128 -0
- package/dist/hosted-transport/operations.js.map +1 -0
- package/dist/hosted-transport/paged-reads.d.ts +87 -0
- package/dist/hosted-transport/paged-reads.d.ts.map +1 -0
- package/dist/hosted-transport/paged-reads.js +238 -0
- package/dist/hosted-transport/paged-reads.js.map +1 -0
- package/dist/hosted-transport/read-adapter.d.ts +250 -0
- package/dist/hosted-transport/read-adapter.d.ts.map +1 -0
- package/dist/hosted-transport/read-adapter.js +557 -0
- package/dist/hosted-transport/read-adapter.js.map +1 -0
- package/dist/hosted-transport/root-write.d.ts +114 -0
- package/dist/hosted-transport/root-write.d.ts.map +1 -0
- package/dist/hosted-transport/root-write.js +171 -0
- package/dist/hosted-transport/root-write.js.map +1 -0
- package/dist/hosted-transport/whole-document-transport.d.ts +174 -0
- package/dist/hosted-transport/whole-document-transport.d.ts.map +1 -0
- package/dist/hosted-transport/whole-document-transport.js +411 -0
- package/dist/hosted-transport/whole-document-transport.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-backend.d.ts +6 -1
- package/dist/indexeddb-backend.d.ts.map +1 -1
- package/dist/indexeddb-backend.js +77 -6
- package/dist/indexeddb-backend.js.map +1 -1
- package/dist/journaled-backend.d.ts +73 -5
- package/dist/journaled-backend.d.ts.map +1 -1
- package/dist/journaled-backend.js +55 -1
- package/dist/journaled-backend.js.map +1 -1
- package/dist/kinds.d.ts +25 -1
- package/dist/kinds.d.ts.map +1 -1
- package/dist/kinds.js +52 -4
- package/dist/kinds.js.map +1 -1
- package/dist/links.d.ts +1 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +5 -10
- package/dist/links.js.map +1 -1
- package/dist/memory-backend.d.ts.map +1 -1
- package/dist/memory-backend.js +6 -2
- package/dist/memory-backend.js.map +1 -1
- package/dist/platform.d.ts +9 -2
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js.map +1 -1
- package/dist/query-order.d.ts +22 -0
- package/dist/query-order.d.ts.map +1 -0
- package/dist/query-order.js +42 -0
- package/dist/query-order.js.map +1 -0
- package/dist/remote-backend.d.ts +56 -11
- package/dist/remote-backend.d.ts.map +1 -1
- package/dist/remote-backend.js +154 -27
- package/dist/remote-backend.js.map +1 -1
- package/dist/remote-error.d.ts +17 -1
- package/dist/remote-error.d.ts.map +1 -1
- package/dist/remote-error.js +32 -2
- package/dist/remote-error.js.map +1 -1
- package/dist/remote-operations.d.ts +5 -4
- package/dist/remote-operations.d.ts.map +1 -1
- package/dist/remote-operations.js +16 -6
- package/dist/remote-operations.js.map +1 -1
- package/dist/remote-parsers.d.ts +1 -1
- package/dist/remote-parsers.js +1 -1
- package/dist/types.d.ts +9 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/uncertain-write.d.ts +45 -11
- package/dist/uncertain-write.d.ts.map +1 -1
- package/dist/uncertain-write.js +30 -9
- package/dist/uncertain-write.js.map +1 -1
- package/dist/versioning.d.ts +9 -4
- package/dist/versioning.d.ts.map +1 -1
- package/dist/versioning.js +9 -4
- package/dist/versioning.js.map +1 -1
- package/package.json +18 -2
package/dist/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,gEAAgE;AAChE,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAE/D,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAClB;IAAE,KAAK,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,GACtE;IAAE,KAAK,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACrF;IAAE,KAAK,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnH,6DAA6D;AAC7D,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAEhE,6GAA6G;AAC7G,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,uDAAuD;IACvD,cAAc,EAAE,OAAO,CAAC;IACxB,gEAAgE;IAChE,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/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AED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,CAE3H"}
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAkLH,sDAAsD;AACtD,MAAM,UAAU,eAAe,CAAC,UAAsB;IACpD,QAAQ,UAAU,CAAC,KAAK,EAAE,CAAC;QACzB,KAAK,kBAAkB;YACrB,OAAO,QAAQ,CAAC;QAClB,KAAK,eAAe;YAClB,OAAO,SAAS,CAAC;QACnB,KAAK,gBAAgB;YACnB,OAAO,UAAU,CAAC;IACtB,CAAC;AACH,CAAC;AAED,+GAA+G;AAC/G,MAAM,UAAU,iBAAiB,CAAC,UAAsB;IACtD,OAAO,UAAU,CAAC,KAAK,KAAK,kBAAkB,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB,EAAE,eAAwB,OAAO;IAC/E,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,IAAoB,EAAE,SAAiB;IACpF,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAgB,EAAE,IAAoB,EAAE,MAAsB,EAAE,SAAiB;IAC7G,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface MeaningfulChangeOrderKey {
|
|
2
|
+
id: string;
|
|
3
|
+
/** The raw selected clock when it is a string, else `""`. */
|
|
4
|
+
timestamp: string;
|
|
5
|
+
/** The clock parsed under the bundle's OKF edition, or `null` when missing or invalid. */
|
|
6
|
+
timestampMs: number | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function meaningfulChangeOrderKey(id: string, frontmatter: {
|
|
9
|
+
readonly generated?: unknown;
|
|
10
|
+
readonly timestamp?: unknown;
|
|
11
|
+
}, okfVersion?: string | null): MeaningfulChangeOrderKey;
|
|
12
|
+
/** Newest usable meaningful-change time first; canonical ID in code-unit order for all ties. */
|
|
13
|
+
export declare function compareByMeaningfulChange(a: MeaningfulChangeOrderKey, b: MeaningfulChangeOrderKey): number;
|
|
14
|
+
/** Return a new array of `rows` in newest-first order; the input array is left untouched. */
|
|
15
|
+
export declare function sortByMeaningfulChange<T extends {
|
|
16
|
+
id: string;
|
|
17
|
+
frontmatter: {
|
|
18
|
+
readonly generated?: unknown;
|
|
19
|
+
readonly timestamp?: unknown;
|
|
20
|
+
};
|
|
21
|
+
}>(rows: readonly T[], okfVersion?: string | null): T[];
|
|
22
|
+
//# sourceMappingURL=query-order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-order.d.ts","sourceRoot":"","sources":["../src/query-order.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,0FAA0F;IAC1F,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,MAAM,EACV,WAAW,EAAE;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,EAC3E,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GACzB,wBAAwB,CAO1B;AAED,gGAAgG;AAChG,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,wBAAwB,EAAE,CAAC,EAAE,wBAAwB,GAAG,MAAM,CAS1G;AAED,6FAA6F;AAC7F,wBAAgB,sBAAsB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,EAC1I,IAAI,EAAE,SAAS,CAAC,EAAE,EAClB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GACzB,CAAC,EAAE,CAKL"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Newest-first order shared by `list`, `home` and the View Bridge `order: "newest"` query.
|
|
3
|
+
*
|
|
4
|
+
* Rows sort by their parsed meaningful-change time (`generated.at`, else legacy `timestamp`),
|
|
5
|
+
* newest first. Rows with a missing or unparseable time follow every timed row. Every tie,
|
|
6
|
+
* including the untimed tail, breaks on the canonical ID in UTF-16 code-unit order, which every
|
|
7
|
+
* host computes identically; `localeCompare` depends on the platform's ICU data.
|
|
8
|
+
*
|
|
9
|
+
* Browser-safe and pure.
|
|
10
|
+
*/
|
|
11
|
+
import { parseTimestamp } from "./freshness.js";
|
|
12
|
+
import { meaningfulChangeTimeValue } from "./meaningful-change-time.js";
|
|
13
|
+
export function meaningfulChangeOrderKey(id, frontmatter, okfVersion) {
|
|
14
|
+
const value = meaningfulChangeTimeValue(frontmatter);
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
timestamp: typeof value === "string" ? value : "",
|
|
18
|
+
timestampMs: parseTimestamp(value, okfVersion ?? undefined),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Newest usable meaningful-change time first; canonical ID in code-unit order for all ties. */
|
|
22
|
+
export function compareByMeaningfulChange(a, b) {
|
|
23
|
+
if (a.timestampMs !== null && b.timestampMs !== null) {
|
|
24
|
+
if (a.timestampMs !== b.timestampMs)
|
|
25
|
+
return b.timestampMs - a.timestampMs;
|
|
26
|
+
}
|
|
27
|
+
else if (a.timestampMs !== null) {
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
else if (b.timestampMs !== null) {
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
34
|
+
}
|
|
35
|
+
/** Return a new array of `rows` in newest-first order; the input array is left untouched. */
|
|
36
|
+
export function sortByMeaningfulChange(rows, okfVersion) {
|
|
37
|
+
return rows
|
|
38
|
+
.map((row) => ({ row, key: meaningfulChangeOrderKey(row.id, row.frontmatter, okfVersion) }))
|
|
39
|
+
.sort((a, b) => compareByMeaningfulChange(a.key, b.key))
|
|
40
|
+
.map(({ row }) => row);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=query-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-order.js","sourceRoot":"","sources":["../src/query-order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAUxE,MAAM,UAAU,wBAAwB,CACtC,EAAU,EACV,WAA2E,EAC3E,UAA0B;IAE1B,MAAM,KAAK,GAAG,yBAAyB,CAAC,WAAW,CAAC,CAAC;IACrD,OAAO;QACL,EAAE;QACF,SAAS,EAAE,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,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E,EAAE,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/remote-backend.d.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* `RemoteBackend` — a {@link StorageBackend} implemented over the wire-protocol v0
|
|
3
3
|
* reference contract (`docs/WIRE-PROTOCOL.md`, `@superbee/server`).
|
|
4
4
|
*
|
|
5
|
-
* This is the client half of the seam over HTTP: every method maps directly to a wire endpoint
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* This is the client half of the seam over HTTP: every method maps directly to a wire endpoint
|
|
6
|
+
* (a guarded document write may first ask `GET /v0/capabilities` whether the host records
|
|
7
|
+
* outcomes; see {@link RemoteBackendOptions.maxRetries}), and response versions remain the same
|
|
8
|
+
* content-addressed {@link Version} tokens local backends produce. Tri-backend contract tests pin
|
|
9
|
+
* that invariant.
|
|
8
10
|
*
|
|
9
11
|
* Zero new dependencies: it calls an injectable {@link FetchLike} transport
|
|
10
12
|
* (defaulting to the global `fetch`, available on Node >= 20) with a constructed
|
|
@@ -69,9 +71,24 @@ export interface RemoteBackendOptions {
|
|
|
69
71
|
* e.g. a Cloudflare D1 cold-start's 500 "storage caused object to be reset" when a hibernated
|
|
70
72
|
* database is first hit) or a network/transport error. Each retry backs off exponentially with
|
|
71
73
|
* jitter. A 4xx (incl. 412 VersionConflict), 401, or any 2xx is a REAL result, never retried.
|
|
72
|
-
* Default 3; set 0 to disable.
|
|
73
|
-
*
|
|
74
|
-
*
|
|
74
|
+
* Default 3; set 0 to disable. A retried read is idempotent.
|
|
75
|
+
*
|
|
76
|
+
* A guarded document write (`write` with `expectedVersion`, or `delete` with a content-version
|
|
77
|
+
* `expectedVersion`) travels with an `Idempotency-Key`: the caller's `requestId`, or else, when
|
|
78
|
+
* the host's capabilities report `operations`, one minted for that call. Every retry of the
|
|
79
|
+
* request carries the same key, so while the host keeps the record a retry is answered from the
|
|
80
|
+
* recorded outcome and cannot apply the write a second time.
|
|
81
|
+
*
|
|
82
|
+
* Other guarded writes retry as a plain resubmission: a guarded document write sent without a key
|
|
83
|
+
* (to a host without `operations`, after a capability question that ended in a transient status,
|
|
84
|
+
* or resent after the host refused a key minted under a stale answer), a `delete` whose
|
|
85
|
+
* `expectedVersion` is not a content version, and every guarded reserved-file and blob write,
|
|
86
|
+
* none of which the wire identifies. Such a retry lands the same version or a conflict, possibly
|
|
87
|
+
* SPURIOUS if a prior attempt committed before its response was lost. It is not free of lost
|
|
88
|
+
* updates: versions are content hashes, so if another writer returns the document to the exact
|
|
89
|
+
* state the premise names before a retry arrives, the retry applies the write again over that
|
|
90
|
+
* change and reports success. An unconditional write carries no minted key and can simply be
|
|
91
|
+
* repeated.
|
|
75
92
|
*/
|
|
76
93
|
maxRetries?: number;
|
|
77
94
|
}
|
|
@@ -106,6 +123,8 @@ export declare class RemoteBackend implements StorageBackend {
|
|
|
106
123
|
private readonly fetchImpl;
|
|
107
124
|
private readonly authToken?;
|
|
108
125
|
private readonly maxRetries;
|
|
126
|
+
/** The pending or settled answer to whether this host records outcomes; see {@link recordsOutcomes}. */
|
|
127
|
+
private operationsSupport?;
|
|
109
128
|
constructor(options: RemoteBackendOptions);
|
|
110
129
|
/** The authority's base URL as configured, without a trailing slash. */
|
|
111
130
|
get origin(): string;
|
|
@@ -119,12 +138,33 @@ export declare class RemoteBackend implements StorageBackend {
|
|
|
119
138
|
write(id: ConceptId, doc: OkfDocument, options?: WriteOptions): Promise<Version>;
|
|
120
139
|
/**
|
|
121
140
|
* `GET /v0/capabilities`, deployment-scoped: what this authority implements. `operations` says
|
|
122
|
-
* whether it records outcomes by request identity.
|
|
123
|
-
* and
|
|
124
|
-
*
|
|
125
|
-
*
|
|
141
|
+
* whether it records outcomes by request identity. The reference router without it refuses any
|
|
142
|
+
* request carrying `Idempotency-Key`, and the lookup route, with `400 USAGE`; a host that lacks
|
|
143
|
+
* the lookup route altogether answers it with a route-miss `404`, which {@link lookupOperation}
|
|
144
|
+
* cannot tell from "never recorded". A consumer that relies on identity checks this once before
|
|
145
|
+
* it sends any intent. Missing booleans read as `false`.
|
|
126
146
|
*/
|
|
127
147
|
wireCapabilities(): Promise<WireCapabilities>;
|
|
148
|
+
/**
|
|
149
|
+
* Whether this host records outcomes by request identity, asked through `GET /v0/capabilities`
|
|
150
|
+
* and shared by concurrent callers. A host that answers anything but a `2xx` with
|
|
151
|
+
* `operations: true` is treated as not recording them, since a host that does not record them
|
|
152
|
+
* refuses a key with `400`. That answer is kept for the backend's lifetime, except that a
|
|
153
|
+
* transient status still returned after `send`'s retries, or a transport failure, is not kept:
|
|
154
|
+
* the former sends this write unidentified, and the latter rejects the write before it is sent.
|
|
155
|
+
* A kept yes is also dropped when a minted key meets the host's identity refusal; see
|
|
156
|
+
* {@link sendDocWrite}.
|
|
157
|
+
*/
|
|
158
|
+
private recordsOutcomes;
|
|
159
|
+
private probeOperations;
|
|
160
|
+
/**
|
|
161
|
+
* Send a document `PUT` or `DELETE`. When its `Idempotency-Key` was minted here, a kept
|
|
162
|
+
* `operations` answer may be stale: a host that has since lost its outcome store refuses every
|
|
163
|
+
* key with the wire's `400` {@link IDENTITY_UNSUPPORTED} before applying anything. That answer
|
|
164
|
+
* is dropped and the write is sent once more without a key, as to any host without
|
|
165
|
+
* `operations`. A caller's own `requestId` is never dropped, so its refusal is the answer.
|
|
166
|
+
*/
|
|
167
|
+
private sendDocWrite;
|
|
128
168
|
/**
|
|
129
169
|
* `GET /heads`: every document id and version the authority holds, under one digest, or
|
|
130
170
|
* `null` when `ifNoneMatch` named the digest it still holds (a `304`: nothing changed). A
|
|
@@ -174,7 +214,12 @@ export declare class RemoteBackend implements StorageBackend {
|
|
|
174
214
|
* `docs/WIRE-PROTOCOL.md`); the engine's `queryHeads` re-filter covers it, per the
|
|
175
215
|
* seam contract (over-returning is fine; semantics live in core).
|
|
176
216
|
*/
|
|
177
|
-
queryHeads(filter?: QueryFilter
|
|
217
|
+
queryHeads(filter?: QueryFilter, options?: {
|
|
218
|
+
onSkip?: (skip: {
|
|
219
|
+
id: ConceptId;
|
|
220
|
+
reason: string;
|
|
221
|
+
}) => void;
|
|
222
|
+
}): Promise<HeadResult[]>;
|
|
178
223
|
versions(id: ConceptId): Promise<VersionInfo[]>;
|
|
179
224
|
readReserved(dir: string, name: ReservedFilename): Promise<ReservedReadResult | null>;
|
|
180
225
|
writeReserved(dir: string, name: ReservedFilename, content: string, options?: WriteOptions): Promise<Version>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-backend.d.ts","sourceRoot":"","sources":["../src/remote-backend.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"remote-backend.d.ts","sourceRoot":"","sources":["../src/remote-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAOH,OAAO,EAA4D,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEtI,OAAO,EAAoC,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,aAAa,EAEb,UAAU,EACV,WAAW,EACX,WAAW,EACX,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,OAAO,EACP,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAgBpB;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEhE,sDAAsD;AACtD,MAAM,WAAW,oBAAoB;IACnC,yGAAyG;IACzG,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,uGAAuG;IACvG,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;I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ACG,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAkCpE,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAWtD,SAAS,CACb,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,UAAU,EACjB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,OAAO,CAAC;IAmBnB,8FAA8F;IACxF,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAYvE,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ1C,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAiBrD"}
|
package/dist/remote-backend.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* `RemoteBackend` — a {@link StorageBackend} implemented over the wire-protocol v0
|
|
3
3
|
* reference contract (`docs/WIRE-PROTOCOL.md`, `@superbee/server`).
|
|
4
4
|
*
|
|
5
|
-
* This is the client half of the seam over HTTP: every method maps directly to a wire endpoint
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* This is the client half of the seam over HTTP: every method maps directly to a wire endpoint
|
|
6
|
+
* (a guarded document write may first ask `GET /v0/capabilities` whether the host records
|
|
7
|
+
* outcomes; see {@link RemoteBackendOptions.maxRetries}), and response versions remain the same
|
|
8
|
+
* content-addressed {@link Version} tokens local backends produce. Tri-backend contract tests pin
|
|
9
|
+
* that invariant.
|
|
8
10
|
*
|
|
9
11
|
* Zero new dependencies: it calls an injectable {@link FetchLike} transport
|
|
10
12
|
* (defaulting to the global `fetch`, available on Node >= 20) with a constructed
|
|
@@ -42,12 +44,13 @@
|
|
|
42
44
|
*/
|
|
43
45
|
import { DEFAULT_BLOB_CONTENT_TYPE } from "./content-type.js";
|
|
44
46
|
import { InvalidInputError } from "./errors.js";
|
|
47
|
+
import { MalformedDocumentError } from "./frontmatter-contract.js";
|
|
45
48
|
import { encodeRemoteDocument } from "./remote-document-codec.js";
|
|
46
49
|
import { RemoteError, malformed } from "./remote-error.js";
|
|
47
50
|
import { SNAPSHOT_TRUNCATED, parseHeadsAnswer, readSnapshotStream } from "./remote-parsers.js";
|
|
48
51
|
import { assertSafeBlobKey, assertSafeConceptId, assertSafeReservedDir, assertSafeReservedFilename, compareStorageKeys } from "./paths.js";
|
|
49
|
-
import { isRequestIdentity } from "./uncertain-write.js";
|
|
50
|
-
import { VersionConflict, stripETagWrapper } from "./version-transport.js";
|
|
52
|
+
import { isRequestIdentity, mintRequestId } from "./uncertain-write.js";
|
|
53
|
+
import { VersionConflict, isContentVersion, stripETagWrapper } from "./version-transport.js";
|
|
51
54
|
// The typed rejection lives in `remote-error.ts`, shared with the heads and snapshot parsers this
|
|
52
55
|
// backend calls; it stays importable from here for every existing consumer.
|
|
53
56
|
export { RemoteError } from "./remote-error.js";
|
|
@@ -97,6 +100,18 @@ function assertValidExpectedVersion(expectedVersion) {
|
|
|
97
100
|
}
|
|
98
101
|
/** The header that carries a write's durable request identity (`docs/WIRE-PROTOCOL.md`). */
|
|
99
102
|
const IDENTITY_HEADER = "Idempotency-Key";
|
|
103
|
+
/** The wire's `400 USAGE` message from a host that records no outcomes, answering any request that carries a key. */
|
|
104
|
+
const IDENTITY_UNSUPPORTED = "request identity is not supported by this host";
|
|
105
|
+
/** Whether `res` is a host's refusal of request identity itself, as opposed to a recorded or document refusal. */
|
|
106
|
+
async function refusesIdentity(res) {
|
|
107
|
+
try {
|
|
108
|
+
const envelope = (await res.json());
|
|
109
|
+
return envelope?.error?.code === "USAGE" && envelope.error.message === IDENTITY_UNSUPPORTED;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
100
115
|
/**
|
|
101
116
|
* Reject a request identity the wire would refuse before any request is sent, so a malformed
|
|
102
117
|
* key is a caller-side `InvalidInputError` rather than a `400` the caller might mistake for a
|
|
@@ -120,6 +135,18 @@ function etagForm(token) {
|
|
|
120
135
|
* REAL result, never retried; 501/505 are terminal server bugs, not transient, so also excluded.
|
|
121
136
|
*/
|
|
122
137
|
const RETRIABLE_STATUS = new Set([500, 502, 503, 504]);
|
|
138
|
+
/** A `500` naming a stored document that does not parse: a retry reads the same bytes again. */
|
|
139
|
+
async function namesMalformedDocument(res) {
|
|
140
|
+
if (res.status !== 500)
|
|
141
|
+
return false;
|
|
142
|
+
try {
|
|
143
|
+
const envelope = (await res.clone().json());
|
|
144
|
+
return typeof envelope?.error?.details?.malformed?.reason === "string";
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
123
150
|
/** Retry-backoff timing: exponential base doubling, capped, with jitter to avoid a thundering herd. */
|
|
124
151
|
const RETRY_BASE_MS = 150;
|
|
125
152
|
const RETRY_CAP_MS = 2000;
|
|
@@ -165,6 +192,8 @@ export class RemoteBackend {
|
|
|
165
192
|
fetchImpl;
|
|
166
193
|
authToken;
|
|
167
194
|
maxRetries;
|
|
195
|
+
/** The pending or settled answer to whether this host records outcomes; see {@link recordsOutcomes}. */
|
|
196
|
+
operationsSupport;
|
|
168
197
|
constructor(options) {
|
|
169
198
|
this.baseUrl = trimTrailingSlashes(options.baseUrl);
|
|
170
199
|
this.bundle = options.bundle;
|
|
@@ -195,19 +224,23 @@ export class RemoteBackend {
|
|
|
195
224
|
// object reset" when a hibernated database is first hit; also 502/503/504 from the edge) or a
|
|
196
225
|
// network/transport error — with exponential backoff + jitter, so a hibernated-backend hiccup is
|
|
197
226
|
// transparent instead of a hard failure. A REAL result (2xx, or 4xx incl. 412 VersionConflict,
|
|
198
|
-
// or 401) returns/throws immediately, never retried.
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
//
|
|
202
|
-
// strings/bytes, so reusable — no consumed-stream hazard).
|
|
227
|
+
// or 401) returns/throws immediately, never retried. A retried read is idempotent. `send`
|
|
228
|
+
// rebuilds the Request per attempt from the same `init` (bodies are strings/bytes, so reusable —
|
|
229
|
+
// no consumed-stream hazard), so every attempt carries the same headers, `Idempotency-Key`
|
|
230
|
+
// included.
|
|
203
231
|
//
|
|
204
|
-
// A write that carries `Idempotency-Key` is
|
|
205
|
-
//
|
|
232
|
+
// A write that carries `Idempotency-Key` is therefore retried as a true replay, answered from
|
|
233
|
+
// the authority's recorded outcome while it keeps that record: a retry after a lost response
|
|
206
234
|
// can neither apply twice nor surface a spurious conflict against its own earlier application.
|
|
235
|
+
// `write` and `delete` attach one to guarded document writes on a host with `operations` (see
|
|
236
|
+
// `maxRetries` for which). A guarded write without one lands the same version or a conflict
|
|
237
|
+
// (possibly SPURIOUS — a prior attempt may have committed before its response was lost), except
|
|
238
|
+
// that a document returned in between to exactly the state its premise names (the same bytes
|
|
239
|
+
// hash to the same version) lets the retry apply again over that change.
|
|
207
240
|
for (let attempt = 0;; attempt++) {
|
|
208
241
|
try {
|
|
209
242
|
const res = await this.fetchImpl(new Request(url, init));
|
|
210
|
-
if (RETRIABLE_STATUS.has(res.status) && attempt < this.maxRetries) {
|
|
243
|
+
if (RETRIABLE_STATUS.has(res.status) && attempt < this.maxRetries && !(await namesMalformedDocument(res))) {
|
|
211
244
|
await delay(retryDelayMs(attempt));
|
|
212
245
|
continue;
|
|
213
246
|
}
|
|
@@ -236,6 +269,12 @@ export class RemoteBackend {
|
|
|
236
269
|
const actual = envelope?.error?.details?.actual ?? null;
|
|
237
270
|
return new VersionConflict(fallbackId, expected, actual);
|
|
238
271
|
}
|
|
272
|
+
const malformedDoc = envelope?.error?.details?.malformed;
|
|
273
|
+
if (malformedDoc && typeof malformedDoc.reason === "string") {
|
|
274
|
+
// The server could read the request but not the stored document: the same failure a local
|
|
275
|
+
// scan raises, so `onSkip` callers can set this one document aside.
|
|
276
|
+
return new MalformedDocumentError(typeof malformedDoc.id === "string" ? malformedDoc.id : fallbackId, new Error(malformedDoc.reason));
|
|
277
|
+
}
|
|
239
278
|
const message = envelope?.error?.message ?? `wire request failed with status ${res.status}`;
|
|
240
279
|
// The envelope's own `code` wins when present (every route in this repo's servers emits
|
|
241
280
|
// one); a status-derived guess covers a malformed/absent envelope or a conformant-but-
|
|
@@ -300,15 +339,19 @@ export class RemoteBackend {
|
|
|
300
339
|
headers["If-Match"] = options.expectedVersion;
|
|
301
340
|
if (options.actor)
|
|
302
341
|
headers["X-Actor"] = options.actor;
|
|
342
|
+
// Captured before the capability question can yield, so the payload is the document as it
|
|
343
|
+
// stood when `write` was called and an unencodable one is refused before any request.
|
|
344
|
+
const body = encodeRemoteDocument(doc.frontmatter, doc.body ?? "");
|
|
345
|
+
let minted = false;
|
|
303
346
|
if (options.requestId !== undefined) {
|
|
304
347
|
assertRequestIdentity(options.requestId);
|
|
305
348
|
headers[IDENTITY_HEADER] = options.requestId;
|
|
306
349
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
});
|
|
350
|
+
else if (options.expectedVersion !== undefined && (await this.recordsOutcomes())) {
|
|
351
|
+
headers[IDENTITY_HEADER] = mintRequestId();
|
|
352
|
+
minted = true;
|
|
353
|
+
}
|
|
354
|
+
const res = await this.sendDocWrite(`/docs/${encodeId(id)}`, { method: "PUT", headers, body }, minted);
|
|
312
355
|
if (!res.ok)
|
|
313
356
|
throw await this.toError(res, id);
|
|
314
357
|
const payload = (await res.json());
|
|
@@ -316,10 +359,11 @@ export class RemoteBackend {
|
|
|
316
359
|
}
|
|
317
360
|
/**
|
|
318
361
|
* `GET /v0/capabilities`, deployment-scoped: what this authority implements. `operations` says
|
|
319
|
-
* whether it records outcomes by request identity.
|
|
320
|
-
* and
|
|
321
|
-
*
|
|
322
|
-
*
|
|
362
|
+
* whether it records outcomes by request identity. The reference router without it refuses any
|
|
363
|
+
* request carrying `Idempotency-Key`, and the lookup route, with `400 USAGE`; a host that lacks
|
|
364
|
+
* the lookup route altogether answers it with a route-miss `404`, which {@link lookupOperation}
|
|
365
|
+
* cannot tell from "never recorded". A consumer that relies on identity checks this once before
|
|
366
|
+
* it sends any intent. Missing booleans read as `false`.
|
|
323
367
|
*/
|
|
324
368
|
async wireCapabilities() {
|
|
325
369
|
const res = await this.send("/v0/capabilities", { method: "GET" }, "deployment");
|
|
@@ -338,6 +382,56 @@ export class RemoteBackend {
|
|
|
338
382
|
snapshot: flag("snapshot"),
|
|
339
383
|
};
|
|
340
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Whether this host records outcomes by request identity, asked through `GET /v0/capabilities`
|
|
387
|
+
* and shared by concurrent callers. A host that answers anything but a `2xx` with
|
|
388
|
+
* `operations: true` is treated as not recording them, since a host that does not record them
|
|
389
|
+
* refuses a key with `400`. That answer is kept for the backend's lifetime, except that a
|
|
390
|
+
* transient status still returned after `send`'s retries, or a transport failure, is not kept:
|
|
391
|
+
* the former sends this write unidentified, and the latter rejects the write before it is sent.
|
|
392
|
+
* A kept yes is also dropped when a minted key meets the host's identity refusal; see
|
|
393
|
+
* {@link sendDocWrite}.
|
|
394
|
+
*/
|
|
395
|
+
recordsOutcomes() {
|
|
396
|
+
this.operationsSupport ??= this.probeOperations();
|
|
397
|
+
return this.operationsSupport;
|
|
398
|
+
}
|
|
399
|
+
async probeOperations() {
|
|
400
|
+
let res;
|
|
401
|
+
try {
|
|
402
|
+
res = await this.send("/v0/capabilities", { method: "GET" }, "deployment");
|
|
403
|
+
}
|
|
404
|
+
catch (err) {
|
|
405
|
+
this.operationsSupport = undefined;
|
|
406
|
+
throw err;
|
|
407
|
+
}
|
|
408
|
+
if (RETRIABLE_STATUS.has(res.status))
|
|
409
|
+
this.operationsSupport = undefined;
|
|
410
|
+
if (!res.ok)
|
|
411
|
+
return false;
|
|
412
|
+
try {
|
|
413
|
+
const payload = (await res.json());
|
|
414
|
+
return payload?.operations === true;
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Send a document `PUT` or `DELETE`. When its `Idempotency-Key` was minted here, a kept
|
|
422
|
+
* `operations` answer may be stale: a host that has since lost its outcome store refuses every
|
|
423
|
+
* key with the wire's `400` {@link IDENTITY_UNSUPPORTED} before applying anything. That answer
|
|
424
|
+
* is dropped and the write is sent once more without a key, as to any host without
|
|
425
|
+
* `operations`. A caller's own `requestId` is never dropped, so its refusal is the answer.
|
|
426
|
+
*/
|
|
427
|
+
async sendDocWrite(path, init, minted) {
|
|
428
|
+
const res = await this.send(path, init);
|
|
429
|
+
if (!minted || res.status !== 400 || !(await refusesIdentity(res.clone())))
|
|
430
|
+
return res;
|
|
431
|
+
this.operationsSupport = undefined;
|
|
432
|
+
const { [IDENTITY_HEADER]: _refused, ...headers } = init.headers;
|
|
433
|
+
return this.send(path, { ...init, headers });
|
|
434
|
+
}
|
|
341
435
|
/**
|
|
342
436
|
* `GET /heads`: every document id and version the authority holds, under one digest, or
|
|
343
437
|
* `null` when `ifNoneMatch` named the digest it still holds (a `304`: nothing changed). A
|
|
@@ -416,11 +510,14 @@ export class RemoteBackend {
|
|
|
416
510
|
* {@link RemoteBackend.queryHeads} are both thin row-mappings over it, so a wire
|
|
417
511
|
* pagination change cannot make the two scans silently paginate differently.
|
|
418
512
|
*/
|
|
419
|
-
async pageDocs(baseParams, mapRow, errorContext) {
|
|
513
|
+
async pageDocs(baseParams, mapRow, errorContext, skipped) {
|
|
420
514
|
const rows = [];
|
|
421
515
|
let cursor;
|
|
422
516
|
for (;;) {
|
|
423
517
|
const params = new URLSearchParams(baseParams);
|
|
518
|
+
// Ask the server to leave an unparsable document out and name it, rather than fail the page.
|
|
519
|
+
if (skipped)
|
|
520
|
+
params.set("malformed", "skip");
|
|
424
521
|
if (cursor)
|
|
425
522
|
params.set("cursor", cursor);
|
|
426
523
|
const qs = params.toString();
|
|
@@ -430,6 +527,13 @@ export class RemoteBackend {
|
|
|
430
527
|
const payload = (await res.json());
|
|
431
528
|
for (const row of payload.docs)
|
|
432
529
|
rows.push(mapRow(row));
|
|
530
|
+
if (skipped && Array.isArray(payload.skipped)) {
|
|
531
|
+
for (const entry of payload.skipped) {
|
|
532
|
+
if (typeof entry?.id !== "string")
|
|
533
|
+
continue;
|
|
534
|
+
skipped.set(entry.id, typeof entry.reason === "string" ? entry.reason : "malformed frontmatter");
|
|
535
|
+
}
|
|
536
|
+
}
|
|
433
537
|
if (!payload.next_cursor)
|
|
434
538
|
break;
|
|
435
539
|
cursor = payload.next_cursor;
|
|
@@ -440,7 +544,11 @@ export class RemoteBackend {
|
|
|
440
544
|
const params = new URLSearchParams();
|
|
441
545
|
if (prefix)
|
|
442
546
|
params.set("prefix", prefix);
|
|
443
|
-
|
|
547
|
+
// A document the server could not parse still exists: it is listed, and reading it raises
|
|
548
|
+
// the same MalformedDocumentError a local read does.
|
|
549
|
+
const skipped = new Map();
|
|
550
|
+
const ids = await this.pageDocs(params, (row) => row.id, prefix ?? "", skipped);
|
|
551
|
+
return [...new Set([...ids, ...skipped.keys()])].sort(compareStorageKeys);
|
|
444
552
|
}
|
|
445
553
|
/**
|
|
446
554
|
* The seam's OPTIONAL head-projection push-down, over the SAME `GET /docs` route
|
|
@@ -453,7 +561,7 @@ export class RemoteBackend {
|
|
|
453
561
|
* `docs/WIRE-PROTOCOL.md`); the engine's `queryHeads` re-filter covers it, per the
|
|
454
562
|
* seam contract (over-returning is fine; semantics live in core).
|
|
455
563
|
*/
|
|
456
|
-
async queryHeads(filter = {}) {
|
|
564
|
+
async queryHeads(filter = {}, options = {}) {
|
|
457
565
|
const params = new URLSearchParams();
|
|
458
566
|
params.set("fields", "frontmatter");
|
|
459
567
|
if (filter.prefix)
|
|
@@ -462,7 +570,17 @@ export class RemoteBackend {
|
|
|
462
570
|
params.set("type", filter.type);
|
|
463
571
|
for (const tag of filter.tags ?? [])
|
|
464
572
|
params.append("tag", tag);
|
|
465
|
-
|
|
573
|
+
const skipped = new Map();
|
|
574
|
+
const rows = await this.pageDocs(params, (row) => ({ id: row.id, frontmatter: row.frontmatter, version: row.version }), filter.prefix ?? "", skipped);
|
|
575
|
+
// The server leaves a malformed document out of the listing and names it. A caller that
|
|
576
|
+
// asked for no skip report keeps the scan's fail-loud contract.
|
|
577
|
+
const named = [...skipped].sort(([a], [b]) => compareStorageKeys(a, b));
|
|
578
|
+
if (named.length > 0 && !options.onSkip) {
|
|
579
|
+
throw new MalformedDocumentError(named[0][0], new Error(named[0][1]));
|
|
580
|
+
}
|
|
581
|
+
for (const [id, reason] of named)
|
|
582
|
+
options.onSkip?.({ id, reason });
|
|
583
|
+
return rows;
|
|
466
584
|
}
|
|
467
585
|
async versions(id) {
|
|
468
586
|
assertSafeConceptId(id);
|
|
@@ -528,11 +646,20 @@ export class RemoteBackend {
|
|
|
528
646
|
const headers = {};
|
|
529
647
|
if (options.expectedVersion !== undefined)
|
|
530
648
|
headers["If-Match"] = options.expectedVersion;
|
|
649
|
+
let minted = false;
|
|
531
650
|
if (options.requestId !== undefined) {
|
|
532
651
|
assertRequestIdentity(options.requestId);
|
|
533
652
|
headers[IDENTITY_HEADER] = options.requestId;
|
|
534
653
|
}
|
|
535
|
-
|
|
654
|
+
else if (options.expectedVersion !== undefined &&
|
|
655
|
+
isContentVersion(stripETagWrapper(options.expectedVersion)) &&
|
|
656
|
+
(await this.recordsOutcomes())) {
|
|
657
|
+
// The wire identifies a delete only under a content-version premise; any other premise
|
|
658
|
+
// stays an unidentified request rather than becoming a `400`.
|
|
659
|
+
headers[IDENTITY_HEADER] = mintRequestId();
|
|
660
|
+
minted = true;
|
|
661
|
+
}
|
|
662
|
+
const res = await this.sendDocWrite(`/docs/${encodeId(id)}`, { method: "DELETE", headers }, minted);
|
|
536
663
|
if (!res.ok)
|
|
537
664
|
throw await this.toError(res, id);
|
|
538
665
|
const payload = (await res.json());
|