@interop/was-client 0.52.0 → 0.54.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 +54 -12
- package/dist/Collection.d.ts +11 -7
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +21 -23
- package/dist/Collection.js.map +1 -1
- package/dist/Resource.d.ts +15 -0
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +4 -15
- package/dist/Resource.js.map +1 -1
- package/dist/Space.d.ts +54 -0
- package/dist/Space.d.ts.map +1 -1
- package/dist/Space.js +89 -7
- package/dist/Space.js.map +1 -1
- package/dist/edv/acquire.d.ts +98 -0
- package/dist/edv/acquire.d.ts.map +1 -0
- package/dist/edv/acquire.js +130 -0
- package/dist/edv/acquire.js.map +1 -0
- package/dist/edv/index.d.ts +35 -2
- package/dist/edv/index.d.ts.map +1 -1
- package/dist/edv/index.js +34 -2
- package/dist/edv/index.js.map +1 -1
- package/dist/edv/logGovernedDescriptorStore.d.ts.map +1 -1
- package/dist/edv/logGovernedDescriptorStore.js +4 -3
- package/dist/edv/logGovernedDescriptorStore.js.map +1 -1
- package/dist/edv/refresh.d.ts +62 -0
- package/dist/edv/refresh.d.ts.map +1 -0
- package/dist/edv/refresh.js +69 -0
- package/dist/edv/refresh.js.map +1 -0
- package/dist/edv/refreshingDocCipher.d.ts +70 -0
- package/dist/edv/refreshingDocCipher.d.ts.map +1 -0
- package/dist/edv/refreshingDocCipher.js +110 -0
- package/dist/edv/refreshingDocCipher.js.map +1 -0
- package/dist/errors.d.ts +4 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +4 -3
- package/dist/errors.js.map +1 -1
- package/dist/internal/content.d.ts +13 -0
- package/dist/internal/content.d.ts.map +1 -1
- package/dist/internal/content.js +16 -0
- package/dist/internal/content.js.map +1 -1
- package/dist/internal/describe.d.ts +16 -21
- package/dist/internal/describe.d.ts.map +1 -1
- package/dist/internal/describe.js +17 -25
- package/dist/internal/describe.js.map +1 -1
- package/dist/internal/request.d.ts +19 -0
- package/dist/internal/request.d.ts.map +1 -1
- package/dist/internal/request.js +26 -0
- package/dist/internal/request.js.map +1 -1
- package/dist/log/logStore.d.ts.map +1 -1
- package/dist/log/logStore.js +8 -20
- package/dist/log/logStore.js.map +1 -1
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +1 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/port.d.ts +5 -1
- package/dist/sync/port.d.ts.map +1 -1
- package/dist/sync/port.js +27 -11
- package/dist/sync/port.js.map +1 -1
- package/dist/sync/predicates.d.ts +21 -4
- package/dist/sync/predicates.d.ts.map +1 -1
- package/dist/sync/predicates.js +23 -4
- package/dist/sync/predicates.js.map +1 -1
- package/dist/sync/provisioning.d.ts +54 -18
- package/dist/sync/provisioning.d.ts.map +1 -1
- package/dist/sync/provisioning.js +123 -43
- package/dist/sync/provisioning.js.map +1 -1
- package/dist/sync/types.d.ts +23 -14
- package/dist/sync/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { EDV_SCHEME_VERSION } from '../edv/constants.js';
|
|
4
4
|
import { ValidationError, WasError } from '../errors.js';
|
|
5
5
|
import { compareAndSwap } from '../internal/cas.js';
|
|
6
|
+
import { isGovernedDescriptor } from '../internal/describe.js';
|
|
6
7
|
/**
|
|
7
8
|
* The Space display name applied at creation when the caller names none.
|
|
8
9
|
*/
|
|
@@ -32,10 +33,60 @@ function rethrowProvisioningFailure(err, context) {
|
|
|
32
33
|
}
|
|
33
34
|
throw new Error(context, { cause: err });
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* The read-then-guarded-create both ensures share: the value is read and, when
|
|
38
|
+
* present, kept as-is; when absent, `create` runs the `If-None-Match: *` write,
|
|
39
|
+
* and when that fails for ANY reason the value is re-read, and a value now
|
|
40
|
+
* present is adopted as the winner of a create race instead of failing. The race is detected by the re-read rather than by the
|
|
41
|
+
* failure's status because the server answers a lost race with whatever check
|
|
42
|
+
* the rival's description trips first: a 412 from the precondition, but also
|
|
43
|
+
* a 400 or 409 from the encryption-descriptor transition rules when the rival
|
|
44
|
+
* already installed key epochs. When nothing can be read back, the create's
|
|
45
|
+
* own failure is rethrown, so a genuine failure keeps its type.
|
|
46
|
+
*
|
|
47
|
+
* A `create` that resolves `undefined` (a server that answered the create with
|
|
48
|
+
* no body) also falls through to the re-read; that value being unreadable is
|
|
49
|
+
* the one case reported as its own error.
|
|
50
|
+
*
|
|
51
|
+
* @param options {object}
|
|
52
|
+
* @param options.read {function} reads the value; `null` when absent
|
|
53
|
+
* @param options.create {function} the guarded write; resolves the created
|
|
54
|
+
* value, or `undefined` when the server echoed none
|
|
55
|
+
* @param options.unreadable {string} the error message when a create
|
|
56
|
+
* succeeded but the value cannot be read back
|
|
57
|
+
* @returns {Promise<{ value: T; created: boolean }>} the value now present
|
|
58
|
+
* and whether this call created it
|
|
59
|
+
*/
|
|
60
|
+
async function readOrCreate({ read, create, unreadable }) {
|
|
61
|
+
const current = await read();
|
|
62
|
+
if (current !== null) {
|
|
63
|
+
return { value: current, created: false };
|
|
64
|
+
}
|
|
65
|
+
let created = false;
|
|
66
|
+
let failure;
|
|
67
|
+
try {
|
|
68
|
+
const value = await create();
|
|
69
|
+
created = true;
|
|
70
|
+
if (value !== undefined) {
|
|
71
|
+
return { value, created };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
failure = err;
|
|
76
|
+
}
|
|
77
|
+
const latest = await read();
|
|
78
|
+
if (latest !== null) {
|
|
79
|
+
return { value: latest, created };
|
|
80
|
+
}
|
|
81
|
+
if (created) {
|
|
82
|
+
throw new ValidationError(unreadable);
|
|
83
|
+
}
|
|
84
|
+
throw failure;
|
|
85
|
+
}
|
|
35
86
|
/**
|
|
36
87
|
* Ensures the controller's Space exists and one synced collection is
|
|
37
88
|
* configured, without overwriting anything already there. The Space is
|
|
38
|
-
* described first and
|
|
89
|
+
* described first and created only when absent -- an existing Space keeps
|
|
39
90
|
* its name AND its controller, so `controllerDid` is used only at creation
|
|
40
91
|
* (a joined client re-running this never rewrites the description). The
|
|
41
92
|
* collection likewise: when absent, an `'edv'` collection is created with the
|
|
@@ -43,16 +94,29 @@ function rethrowProvisioningFailure(err, context) {
|
|
|
43
94
|
* the server stores only ciphertext it can never decrypt and validates every
|
|
44
95
|
* write against the declared envelope wire format -- the same version the
|
|
45
96
|
* cipher binds into each envelope's AEAD-protected header, so descriptor and
|
|
46
|
-
* envelopes cannot drift; a `'plaintext'` collection is created
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
97
|
+
* envelopes cannot drift; a `'plaintext'` or `'governed'` collection is created
|
|
98
|
+
* without one. Both creates are guarded (`If-None-Match: *`), so two clients
|
|
99
|
+
* booting at once cannot both create, and the loser adopts the winner's
|
|
100
|
+
* description instead of failing. Against a server that ignores the
|
|
101
|
+
* precondition the create is an unconditional upsert, and the loser of a race
|
|
102
|
+
* can overwrite the winner's display name; the server merges the rest of the
|
|
103
|
+
* winner's description forward.
|
|
104
|
+
*
|
|
105
|
+
* An existing collection that lacks the descriptor an `'edv'` spec calls for
|
|
50
106
|
* gets the late in-place declaration (set-once on the server); one that
|
|
51
107
|
* already carries a descriptor -- possibly with appended key epochs -- is
|
|
52
|
-
* left untouched, epochs and display name included.
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
108
|
+
* left untouched, epochs and display name included. An existing `'governed'`
|
|
109
|
+
* collection is never written to: the server refuses to govern a Description
|
|
110
|
+
* that carries a client-written descriptor (`encryption-immutable`), and a
|
|
111
|
+
* governed Collection's served `encryption` is the derived member, which a
|
|
112
|
+
* Description PUT may not carry (`encryption-history-log-governed`). So an
|
|
113
|
+
* existing collection whose descriptor is client-written (no `history`
|
|
114
|
+
* member) cannot become governed, and a `'governed'` spec over it throws
|
|
115
|
+
* `ValidationError` here rather than letting the caller's log create fail
|
|
116
|
+
* with the server's 409. A public collection gets the collection-level
|
|
117
|
+
* world-read grant (`setPublic`, what makes a resource URL in it resolve for
|
|
118
|
+
* anyone) only when its policy does not already say so. Every request invokes
|
|
119
|
+
* the root capability, or `capability` when the caller holds a delegated one.
|
|
56
120
|
*
|
|
57
121
|
* @param options {object}
|
|
58
122
|
* @param options.was {WasClient}
|
|
@@ -60,7 +124,14 @@ function rethrowProvisioningFailure(err, context) {
|
|
|
60
124
|
* @param options.controllerDid {string} the Space controller (e.g. `did:key`);
|
|
61
125
|
* used only when the Space does not exist yet
|
|
62
126
|
* @param options.collectionId {string} the WAS collection id
|
|
63
|
-
* @param [options.encryption] {'edv' | 'plaintext'
|
|
127
|
+
* @param [options.encryption] {'edv' | 'plaintext' | 'governed'} how the
|
|
128
|
+
* collection's `encryption` member is settled; defaults to `'edv'`.
|
|
129
|
+
* `'edv'` declares the descriptor here, `'plaintext'` declares none, and
|
|
130
|
+
* `'governed'` leaves the member to the server, which derives it from the
|
|
131
|
+
* collection's history log. Declaring that governance is the caller's next
|
|
132
|
+
* step, through the log's guarded create --
|
|
133
|
+
* `logGovernedDescriptorStore(...).create` or
|
|
134
|
+
* `resourceLogStore({ collection }).create`
|
|
64
135
|
* @param [options.isPublic] {boolean} grant collection-level world read
|
|
65
136
|
* @param [options.spaceName] {string} the Space display name, applied only at
|
|
66
137
|
* Space creation; defaults to `'WAS Space'`
|
|
@@ -74,12 +145,16 @@ function rethrowProvisioningFailure(err, context) {
|
|
|
74
145
|
* be `spaceId` -- a description of some other Space throws
|
|
75
146
|
* `ValidationError`, since skipping the ensure would leave that Space
|
|
76
147
|
* unprovisioned
|
|
148
|
+
* @param [options.capability] {IZcap} an invocation capability every
|
|
149
|
+
* request rides (a delegated Space-subtree zcap, say); the root capability
|
|
150
|
+
* is invoked otherwise. A capability scoped below the bare Space URL cannot
|
|
151
|
+
* reach the Space half, so a caller holding one supplies `spaceDescription`
|
|
77
152
|
* @returns {Promise<void>}
|
|
78
153
|
*/
|
|
79
|
-
export async function ensureSpaceAndCollection({ was, spaceId, controllerDid, collectionId, encryption = 'edv', isPublic = false, spaceName = DEFAULT_SPACE_NAME, collectionName = collectionId, spaceDescription }) {
|
|
80
|
-
const space = was.space(spaceId);
|
|
154
|
+
export async function ensureSpaceAndCollection({ was, spaceId, controllerDid, collectionId, encryption = 'edv', isPublic = false, spaceName = DEFAULT_SPACE_NAME, collectionName = collectionId, spaceDescription, capability }) {
|
|
155
|
+
const space = was.space(spaceId, { capability });
|
|
81
156
|
if (spaceDescription === undefined) {
|
|
82
|
-
await ensureSpace({ was, spaceId, controllerDid, spaceName });
|
|
157
|
+
await ensureSpace({ was, spaceId, controllerDid, spaceName, capability });
|
|
83
158
|
}
|
|
84
159
|
else if (spaceDescription.id !== spaceId) {
|
|
85
160
|
// Supplying a description skips the Space half entirely, so a caller
|
|
@@ -92,20 +167,25 @@ export async function ensureSpaceAndCollection({ was, spaceId, controllerDid, co
|
|
|
92
167
|
}
|
|
93
168
|
try {
|
|
94
169
|
const collection = space.collection(collectionId);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// yet, so the re-read inside `configure` is the narrowest window
|
|
101
|
-
// available against a rival create landing in between (it would lose
|
|
102
|
-
// its `backend` to a merge from a stale `null`). This branch runs once
|
|
103
|
-
// per collection, so the extra request is a cold-path cost only.
|
|
104
|
-
await collection.configure(encryption === 'edv'
|
|
170
|
+
// A `'governed'` or `'plaintext'` collection takes the descriptor-less
|
|
171
|
+
// create: a governed `encryption` member is the server's to derive.
|
|
172
|
+
const { value: read, created } = await readOrCreate({
|
|
173
|
+
read: () => collection.describeWithEtag(),
|
|
174
|
+
create: () => collection.replaceDescription(encryption === 'edv'
|
|
105
175
|
? { name: collectionName, encryption: EDV_DESCRIPTOR }
|
|
106
|
-
: { name: collectionName,
|
|
176
|
+
: { name: collectionName }, { ifNoneMatch: true }),
|
|
177
|
+
unreadable: `Collection "${collectionId}" in space "${spaceId}" was ` +
|
|
178
|
+
'created but cannot be read back.'
|
|
179
|
+
});
|
|
180
|
+
const current = read.description;
|
|
181
|
+
if (encryption === 'governed' &&
|
|
182
|
+
current.encryption !== undefined &&
|
|
183
|
+
!isGovernedDescriptor(current.encryption)) {
|
|
184
|
+
throw new ValidationError(`Collection "${collectionId}" in space "${spaceId}" carries a ` +
|
|
185
|
+
'client-written encryption descriptor, so it cannot be governed by ' +
|
|
186
|
+
'a history log: the server keeps a declared descriptor immutable.');
|
|
107
187
|
}
|
|
108
|
-
|
|
188
|
+
if (!created && encryption === 'edv' && current.encryption === undefined) {
|
|
109
189
|
// The late in-place declaration: adding a descriptor to a collection
|
|
110
190
|
// that lacks one is allowed (set-once), while re-sending one over an
|
|
111
191
|
// existing descriptor would drop its appended key epochs -- which is
|
|
@@ -144,7 +224,9 @@ export async function ensureSpaceAndCollection({ was, spaceId, controllerDid, co
|
|
|
144
224
|
: null
|
|
145
225
|
});
|
|
146
226
|
}
|
|
147
|
-
|
|
227
|
+
// A collection this call just created has no policy document yet, so the
|
|
228
|
+
// read that would find it non-public is skipped.
|
|
229
|
+
if (isPublic && (created || !(await collection.isPublic()))) {
|
|
148
230
|
await collection.setPublic();
|
|
149
231
|
}
|
|
150
232
|
}
|
|
@@ -157,11 +239,13 @@ export async function ensureSpaceAndCollection({ was, spaceId, controllerDid, co
|
|
|
157
239
|
* there -- the Space half of {@link ensureSpaceAndCollection}, split out so a
|
|
158
240
|
* caller provisioning SEVERAL collections into one Space pays for it once
|
|
159
241
|
* rather than once per collection. An existing Space keeps its name AND its
|
|
160
|
-
* controller, so `controllerDid` is used only at creation.
|
|
242
|
+
* controller, so `controllerDid` is used only at creation. The create is
|
|
243
|
+
* guarded (`If-None-Match: *`), so a Space created concurrently keeps its
|
|
244
|
+
* `type` array (accepted at creation only) and is adopted by the loser.
|
|
161
245
|
*
|
|
162
|
-
* Costs one `GET` on a settled Space, and one `GET` plus one `PUT`
|
|
163
|
-
*
|
|
164
|
-
*
|
|
246
|
+
* Costs one `GET` on a settled Space, and one `GET` plus one guarded `PUT`
|
|
247
|
+
* (`If-None-Match: *`) on a fresh one; a lost create race costs one more `GET`
|
|
248
|
+
* to adopt the winner.
|
|
165
249
|
*
|
|
166
250
|
* @param options {object}
|
|
167
251
|
* @param options.was {WasClient}
|
|
@@ -170,25 +254,21 @@ export async function ensureSpaceAndCollection({ was, spaceId, controllerDid, co
|
|
|
170
254
|
* `did:key`); used only when the Space does not exist yet
|
|
171
255
|
* @param [options.spaceName] {string} the Space display name, applied only at
|
|
172
256
|
* Space creation; defaults to `'WAS Space'`
|
|
257
|
+
* @param [options.capability] {IZcap} an invocation capability both
|
|
258
|
+
* requests ride; the root capability is invoked otherwise
|
|
173
259
|
* @returns {Promise<SpaceDescription>} the Space's description, existing or
|
|
174
260
|
* just written -- pass it to {@link ensureSpaceAndCollection} as
|
|
175
261
|
* `spaceDescription` so each collection skips the Space ensure
|
|
176
262
|
*/
|
|
177
|
-
export async function ensureSpace({ was, spaceId, controllerDid, spaceName = DEFAULT_SPACE_NAME }) {
|
|
178
|
-
const space = was.space(spaceId);
|
|
263
|
+
export async function ensureSpace({ was, spaceId, controllerDid, spaceName = DEFAULT_SPACE_NAME, capability }) {
|
|
264
|
+
const space = was.space(spaceId, { capability });
|
|
179
265
|
try {
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
// The create does not thread the `null` just read into `configure` (same
|
|
185
|
-
// reasoning as the collection create in `ensureSpaceAndCollection`): a
|
|
186
|
-
// Space created concurrently in the window would lose its `type` array,
|
|
187
|
-
// which the server accepts at creation only. Once per Space, cold path.
|
|
188
|
-
return await space.configure({
|
|
189
|
-
name: spaceName,
|
|
190
|
-
controller: controllerDid
|
|
266
|
+
const { value } = await readOrCreate({
|
|
267
|
+
read: () => space.describe(),
|
|
268
|
+
create: async () => (await space.replaceDescription({ name: spaceName, controller: controllerDid }, { ifNoneMatch: true })).description,
|
|
269
|
+
unreadable: `Space "${spaceId}" was created but cannot be read back.`
|
|
191
270
|
});
|
|
271
|
+
return value;
|
|
192
272
|
}
|
|
193
273
|
catch (err) {
|
|
194
274
|
rethrowProvisioningFailure(err, `Failed to configure WAS space "${spaceId}" for "${controllerDid}".`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provisioning.js","sourceRoot":"","sources":["../../src/sync/provisioning.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provisioning.js","sourceRoot":"","sources":["../../src/sync/provisioning.ts"],"names":[],"mappings":"AA8BA,6EAA6E;AAC7E,iEAAiE;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAE9D;;GAEG;AACH,MAAM,kBAAkB,GAAG,WAAW,CAAA;AAEtC;;;GAGG;AACH,MAAM,cAAc,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAW,CAAA;AAE9E;;;;;;;;;;;;;GAaG;AACH,SAAS,0BAA0B,CAAC,GAAY,EAAE,OAAe;IAC/D,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;QAC5B,MAAM,GAAG,CAAA;IACX,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,KAAK,UAAU,YAAY,CAAI,EAC7B,IAAI,EACJ,MAAM,EACN,UAAU,EAKX;IACC,MAAM,OAAO,GAAG,MAAM,IAAI,EAAE,CAAA;IAC5B,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QAC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AyE;QACzE,iDAAiD;QACjD,IAAI,QAAQ,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC;YAC5D,MAAM,UAAU,CAAC,SAAS,EAAE,CAAA;QAC9B,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,0BAA0B,CACxB,GAAG,EACH,mCAAmC,YAAY,eAAe,OAAO,IAAI,CAC1E,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAChC,GAAG,EACH,OAAO,EACP,aAAa,EACb,SAAS,GAAG,kBAAkB,EAC9B,UAAU,EAOX;IACC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IAChD,IAAI,CAAC;QACH,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,YAAY,CAAC;YACnC,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE;YAC5B,MAAM,EAAE,KAAK,IAAI,EAAE,CACjB,CACE,MAAM,KAAK,CAAC,kBAAkB,CAC5B,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,EAC9C,EAAE,WAAW,EAAE,IAAI,EAAE,CACtB,CACF,CAAC,WAAW;YACf,UAAU,EAAE,UAAU,OAAO,wCAAwC;SACtE,CAAC,CAAA;QACF,OAAO,KAAK,CAAA;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,0BAA0B,CACxB,GAAG,EACH,kCAAkC,OAAO,UAAU,aAAa,IAAI,CACrE,CAAA;IACH,CAAC;AACH,CAAC"}
|
package/dist/sync/types.d.ts
CHANGED
|
@@ -33,17 +33,25 @@ export type SyncCheckpoint = ChangesCheckpoint;
|
|
|
33
33
|
* exactly as the server emits them, so a puller passes one back verbatim as a
|
|
34
34
|
* conditional write's `ifMatch` without a {@link WasSyncPort.get} first. A
|
|
35
35
|
* tombstone carries `_deleted: true` with no `data`. This is the shared
|
|
36
|
-
* `ChangeDocument` from `@interop/storage-core
|
|
37
|
-
* `
|
|
38
|
-
*
|
|
36
|
+
* `ChangeDocument` from `@interop/storage-core` with its two bodies typed as
|
|
37
|
+
* `Json`, the parsed JSON they always are on the wire (the shared type leaves
|
|
38
|
+
* them `unknown`); on an encrypted collection `data`/`custom` are the opaque
|
|
39
|
+
* stored envelope, moved verbatim (decrypt is a projection-time concern the
|
|
40
|
+
* engine's `DocCipher` handles, never the port).
|
|
39
41
|
*/
|
|
40
|
-
export
|
|
42
|
+
export interface WireDoc extends Omit<ChangeDocument, 'data' | 'custom'> {
|
|
43
|
+
data?: Json;
|
|
44
|
+
custom?: Json;
|
|
45
|
+
}
|
|
41
46
|
/**
|
|
42
47
|
* One page of the `changes` feed -- the return shape of {@link
|
|
43
|
-
* WasSyncPort.query} (the shared `ChangesPage
|
|
44
|
-
*
|
|
48
|
+
* WasSyncPort.query} (the shared `ChangesPage`, its documents typed as
|
|
49
|
+
* {@link WireDoc}): the page's `documents` and its resume `checkpoint`, or
|
|
50
|
+
* `checkpoint: null` for an empty (no-change) page.
|
|
45
51
|
*/
|
|
46
|
-
export
|
|
52
|
+
export interface SyncPage extends Omit<ChangesPage, 'documents'> {
|
|
53
|
+
documents: WireDoc[];
|
|
54
|
+
}
|
|
47
55
|
/**
|
|
48
56
|
* The current master state of a single resource, read back for the 412-conflict
|
|
49
57
|
* path ({@link WasSyncPort.get}). An absent or tombstoned resource surfaces as
|
|
@@ -87,10 +95,8 @@ export interface WriteAck {
|
|
|
87
95
|
* The injected WAS-access seam. `createWasSyncPort` implements this over
|
|
88
96
|
* `@interop/was-client`'s `was.request()` and the `Collection.changes()` feed;
|
|
89
97
|
* a change engine depends only on this interface. Every method moves the stored
|
|
90
|
-
* body verbatim -- no codec, no key handling.
|
|
91
|
-
*
|
|
92
|
-
* `putMeta` is optional: a replica that syncs only content (never the user-
|
|
93
|
-
* writable `/meta` `custom`) may omit it. All other methods are required.
|
|
98
|
+
* body verbatim -- no codec, no key handling. Every method is required,
|
|
99
|
+
* `putMeta` included: a replica that syncs content only simply never calls it.
|
|
94
100
|
*/
|
|
95
101
|
export interface WasSyncPort {
|
|
96
102
|
/**
|
|
@@ -135,14 +141,17 @@ export interface WasSyncPort {
|
|
|
135
141
|
}): Promise<WriteAck | undefined>;
|
|
136
142
|
/**
|
|
137
143
|
* Conditionally writes the user-writable metadata `custom` (`PUT /:id/meta`).
|
|
138
|
-
*
|
|
144
|
+
* The write fully
|
|
139
145
|
* replaces `custom`, so omitting it writes the CLEARED state (the server
|
|
140
146
|
* clears every property the body leaves out) -- that is how a metadata clear
|
|
141
147
|
* replicates. Returns the new metadata {@link WriteAck}, or `undefined` when
|
|
142
148
|
* the response carried no `ETag`. Throws {@link WasSyncConflictError} on
|
|
143
|
-
* `412
|
|
149
|
+
* `412`, and {@link WasSyncNotFoundError} on `404` (the resource is gone: a
|
|
150
|
+
* delete race the caller corroborates). A port built with
|
|
151
|
+
* `mapAuthErrors: true` raises {@link WasSyncAuthError} with `status: 404`
|
|
152
|
+
* there instead, since the masked `404` is ambiguous.
|
|
144
153
|
*/
|
|
145
|
-
putMeta
|
|
154
|
+
putMeta(options: {
|
|
146
155
|
id: string;
|
|
147
156
|
custom?: Json;
|
|
148
157
|
ifMatch?: string;
|
package/dist/sync/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sync/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,WAAW,EACZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,YAAY,EAAE,IAAI,EAAE,C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AA;IAC3D,aAAa,CAAC,CAAC,OAAO,EAAE;QACtB,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,IAAI,CAAA;QACV,OAAO,EAAE,IAAI,CAAA;KACd,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC3D,OAAO,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACpD;AAED;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interop/was-client",
|
|
3
3
|
"description": "A developer-friendly client for Wallet Attached Storage (WAS) servers.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.54.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "pnpm run clear && tsc",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@interop/http-client": "^1.0.5",
|
|
69
69
|
"@interop/minimal-cipher": "^7.10.0",
|
|
70
70
|
"@interop/storage-core": "^0.11.0",
|
|
71
|
-
"@interop/vh-resource-log": "^0.
|
|
71
|
+
"@interop/vh-resource-log": "^0.5.0",
|
|
72
72
|
"@interop/x25519-key-agreement-key": "^5.3.0",
|
|
73
73
|
"@noble/hashes": "^2.3.0",
|
|
74
74
|
"@scure/base": "^2.3.0",
|