@interop/was-client 0.35.1 → 0.37.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 +22 -5
- package/dist/Collection.d.ts +5 -0
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +37 -4
- package/dist/Collection.js.map +1 -1
- package/dist/Resource.d.ts +4 -3
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +31 -20
- package/dist/Resource.js.map +1 -1
- package/dist/codec.d.ts +91 -4
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +10 -1
- package/dist/codec.js.map +1 -1
- package/dist/edv/EdvCodec.d.ts +29 -9
- package/dist/edv/EdvCodec.d.ts.map +1 -1
- package/dist/edv/EdvCodec.js +421 -40
- package/dist/edv/EdvCodec.js.map +1 -1
- package/dist/edv/WasTransport.d.ts +39 -2
- package/dist/edv/WasTransport.d.ts.map +1 -1
- package/dist/edv/WasTransport.js +82 -26
- package/dist/edv/WasTransport.js.map +1 -1
- package/dist/edv/docCipher.d.ts +55 -4
- package/dist/edv/docCipher.d.ts.map +1 -1
- package/dist/edv/docCipher.js +51 -5
- package/dist/edv/docCipher.js.map +1 -1
- package/dist/edv/epochRoster.d.ts +53 -0
- package/dist/edv/epochRoster.d.ts.map +1 -0
- package/dist/edv/epochRoster.js +49 -0
- package/dist/edv/epochRoster.js.map +1 -0
- package/dist/edv/index.d.ts +6 -1
- package/dist/edv/index.d.ts.map +1 -1
- package/dist/edv/index.js +5 -0
- package/dist/edv/index.js.map +1 -1
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/features.d.ts +44 -1
- package/dist/internal/features.d.ts.map +1 -1
- package/dist/internal/features.js +39 -0
- package/dist/internal/features.js.map +1 -1
- package/dist/internal/write.d.ts +65 -12
- package/dist/internal/write.d.ts.map +1 -1
- package/dist/internal/write.js +71 -9
- package/dist/internal/write.js.map +1 -1
- package/package.json +1 -1
package/dist/internal/write.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isChunkedWrite } from '../codec.js';
|
|
1
2
|
import { PreconditionFailedError, ValidationError } from '../errors.js';
|
|
2
3
|
import { send } from './request.js';
|
|
3
4
|
import { encodedPrecondition, writeHeaders } from './conditional.js';
|
|
@@ -31,11 +32,47 @@ export async function sendEncodedWrite(context, { path, method, encoded, capabil
|
|
|
31
32
|
});
|
|
32
33
|
return response;
|
|
33
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds the {@link CodecRequestContext} core hands a codec that drives its own
|
|
37
|
+
* I/O: the signed-request primitive bound to this handle's capability, plus the
|
|
38
|
+
* handle's memoized backend-feature probe. The codec never sees the zcap
|
|
39
|
+
* machinery, and the raw `HttpResponse` it gets back matches the
|
|
40
|
+
* `was.request()` escape hatch, which is what `WasTransport` consumes.
|
|
41
|
+
*
|
|
42
|
+
* Requests go through the same mapped `send` path the core write paths use, so
|
|
43
|
+
* a codec-driven write fails with the typed `WasError` subclasses the calling
|
|
44
|
+
* method documents (a document `PUT` that 404s is a `NotFoundError`, not a raw
|
|
45
|
+
* ky/ezcap error). The typed errors carry the HTTP `status`, so a consumer that
|
|
46
|
+
* dispatches on status keeps working.
|
|
47
|
+
*
|
|
48
|
+
* @param context {ClientContext}
|
|
49
|
+
* @param options {object}
|
|
50
|
+
* @param options.features {FeatureProbe} the handle's memoized backend-feature
|
|
51
|
+
* probe
|
|
52
|
+
* @param [options.capability] {IZcap} capability attached to each request
|
|
53
|
+
* @returns {CodecRequestContext}
|
|
54
|
+
*/
|
|
55
|
+
export function codecRequestContext(context, { features, capability }) {
|
|
56
|
+
return {
|
|
57
|
+
async request(input) {
|
|
58
|
+
// `send` only resolves `null` for the `read`/`idempotent` flags, which
|
|
59
|
+
// this surface never sets, so the response is always present.
|
|
60
|
+
const response = await send(context, { capability, ...input });
|
|
61
|
+
return response;
|
|
62
|
+
},
|
|
63
|
+
features
|
|
64
|
+
};
|
|
65
|
+
}
|
|
34
66
|
/**
|
|
35
67
|
* Creates a resource with a codec-minted or server-minted id (insert) through
|
|
36
68
|
* its codec, owning the create orchestration in one place: the encode, the
|
|
37
69
|
* `PUT`-vs-`POST` branch, and the precondition selection.
|
|
38
70
|
*
|
|
71
|
+
* A codec may also answer the encode with a multi-request plan (the EDV codec's
|
|
72
|
+
* chunked blob write). The plan is then executed over the handle's signed
|
|
73
|
+
* request context instead of being sent as one request; it owns its own
|
|
74
|
+
* preconditions and feature gating.
|
|
75
|
+
*
|
|
39
76
|
* A codec that mints its own id (e.g. the encrypting codec's EDV id) writes it
|
|
40
77
|
* by `PUT` to that id's path; a codec that mints none (the identity codec)
|
|
41
78
|
* `POST`s to the items path and lets the server mint one. As in
|
|
@@ -55,14 +92,28 @@ export async function sendEncodedWrite(context, { path, method, encoded, capabil
|
|
|
55
92
|
* codec-minted id
|
|
56
93
|
* @param options.codec {ResourceCodec} the collection's resolved codec
|
|
57
94
|
* @param options.data {ResourceData} the plaintext value
|
|
95
|
+
* @param options.features {FeatureProbe} the handle's shared backend-feature
|
|
96
|
+
* probe, handed to a codec's multi-request plan so its affordance gate costs
|
|
97
|
+
* no extra round trip
|
|
58
98
|
* @param [options.contentType] {string} caller-supplied content type
|
|
59
99
|
* @param [options.capability] {IZcap}
|
|
60
100
|
* @param [options.precondition] {WritePrecondition} the caller's explicit
|
|
61
101
|
* precondition (used only for a non-conditional codec)
|
|
62
|
-
* @returns {Promise<
|
|
102
|
+
* @returns {Promise<InsertOutcome>}
|
|
63
103
|
*/
|
|
64
|
-
export async function insertResource(context, { itemsPath, pathForId, codec, data, contentType, capability, precondition }) {
|
|
65
|
-
const
|
|
104
|
+
export async function insertResource(context, { itemsPath, pathForId, codec, data, features, contentType, capability, precondition }) {
|
|
105
|
+
const write = await codec.encode({ data, contentType });
|
|
106
|
+
if (isChunkedWrite(write)) {
|
|
107
|
+
const { id, etag } = await write.execute(codecRequestContext(context, { features, capability }));
|
|
108
|
+
return {
|
|
109
|
+
chunked: true,
|
|
110
|
+
id,
|
|
111
|
+
path: pathForId(id),
|
|
112
|
+
contentType: write.resourceContentType,
|
|
113
|
+
...(etag !== undefined && { etag })
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const encoded = write;
|
|
66
117
|
const chosen = codec.conditionalWrites
|
|
67
118
|
? encodedPrecondition(encoded)
|
|
68
119
|
: precondition;
|
|
@@ -104,9 +155,9 @@ export async function insertResource(context, { itemsPath, pathForId, codec, dat
|
|
|
104
155
|
* @param options.codec {ResourceCodec} the collection's resolved codec
|
|
105
156
|
* @param options.id {string} the resource id
|
|
106
157
|
* @param options.data {ResourceData} the plaintext value
|
|
107
|
-
* @param options.features {
|
|
108
|
-
*
|
|
109
|
-
*
|
|
158
|
+
* @param options.features {FeatureProbe} the handle's shared
|
|
159
|
+
* `BackendFeatures` probe; consulted only for a conditional codec's
|
|
160
|
+
* insert-after-null-pre-read
|
|
110
161
|
* @param [options.contentType] {string} caller-supplied content type
|
|
111
162
|
* @param [options.capability] {IZcap}
|
|
112
163
|
* @param [options.precondition] {WritePrecondition} the caller's explicit
|
|
@@ -122,8 +173,7 @@ export async function upsertResource(context, { path, codec, id, data, features,
|
|
|
122
173
|
capability,
|
|
123
174
|
read: true
|
|
124
175
|
});
|
|
125
|
-
if (current === null &&
|
|
126
|
-
!(await features()).includes('conditional-writes')) {
|
|
176
|
+
if (current === null && !(await features.has('conditional-writes'))) {
|
|
127
177
|
// The write would be encoded as a fresh insert guarded only by
|
|
128
178
|
// `If-None-Match: *`, which this backend ignores -- so if the document in
|
|
129
179
|
// fact exists but is unreadable with this capability (the masked-404
|
|
@@ -140,7 +190,19 @@ export async function upsertResource(context, { path, codec, id, data, features,
|
|
|
140
190
|
'descriptor, or add() to mint a fresh document id.');
|
|
141
191
|
}
|
|
142
192
|
}
|
|
143
|
-
const
|
|
193
|
+
const write = await codec.encode({ id, data, contentType, current });
|
|
194
|
+
if (isChunkedWrite(write)) {
|
|
195
|
+
// Auto-routing is an insert-path affordance: a write by id would have to
|
|
196
|
+
// reconcile the existing stored parts (and the codec's sequence) with the
|
|
197
|
+
// new payload, which this path does not do. Refuse instead of
|
|
198
|
+
// half-performing the update. The codec supplies the scheme-specific
|
|
199
|
+
// recovery advice; this layer knows nothing about how it stores things.
|
|
200
|
+
throw new ValidationError(`Cannot write this payload to "${path}": the collection's codec ` +
|
|
201
|
+
'answered with a multi-request write plan, which is only auto-routed ' +
|
|
202
|
+
'on the insert path (add()). Add it as a new resource' +
|
|
203
|
+
(write.guidance === undefined ? '.' : `. ${write.guidance}`));
|
|
204
|
+
}
|
|
205
|
+
const encoded = write;
|
|
144
206
|
// A conditional codec computes the precondition itself (from the sequence /
|
|
145
207
|
// ETag); a plaintext codec defers to the caller's explicit options.
|
|
146
208
|
const chosen = codec.conditionalWrites
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../src/internal/write.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../src/internal/write.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAGvE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAGpE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAsB,EACtB,EACE,IAAI,EACJ,MAAM,EACN,OAAO,EACP,UAAU,EACV,YAAY,EAOb;IAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE;QAC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