@interop/was-client 0.5.0 → 0.7.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 +166 -0
- package/dist/Collection.d.ts +28 -3
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +74 -13
- package/dist/Collection.js.map +1 -1
- package/dist/Resource.d.ts +64 -9
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +110 -26
- package/dist/Resource.js.map +1 -1
- package/dist/Space.d.ts +4 -0
- package/dist/Space.d.ts.map +1 -1
- package/dist/Space.js +4 -0
- package/dist/Space.js.map +1 -1
- package/dist/WasClient.d.ts +10 -2
- package/dist/WasClient.d.ts.map +1 -1
- package/dist/WasClient.js +13 -6
- package/dist/WasClient.js.map +1 -1
- package/dist/codec.d.ts +127 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +2 -0
- package/dist/codec.js.map +1 -0
- package/dist/edv/EdvCodec.d.ts +148 -0
- package/dist/edv/EdvCodec.d.ts.map +1 -0
- package/dist/edv/EdvCodec.js +284 -0
- package/dist/edv/EdvCodec.js.map +1 -0
- package/dist/edv/WasTransport.d.ts +178 -0
- package/dist/edv/WasTransport.d.ts.map +1 -0
- package/dist/edv/WasTransport.js +284 -0
- package/dist/edv/WasTransport.js.map +1 -0
- package/dist/edv/index.d.ts +21 -0
- package/dist/edv/index.d.ts.map +1 -0
- package/dist/edv/index.js +21 -0
- package/dist/edv/index.js.map +1 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +29 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/codec.d.ts +27 -0
- package/dist/internal/codec.d.ts.map +1 -0
- package/dist/internal/codec.js +44 -0
- package/dist/internal/codec.js.map +1 -0
- package/dist/internal/conditional.d.ts +40 -0
- package/dist/internal/conditional.d.ts.map +1 -0
- package/dist/internal/conditional.js +35 -0
- package/dist/internal/conditional.js.map +1 -0
- package/dist/internal/content.d.ts +30 -1
- package/dist/internal/content.d.ts.map +1 -1
- package/dist/internal/content.js +68 -3
- package/dist/internal/content.js.map +1 -1
- package/dist/internal/request.d.ts +5 -1
- package/dist/internal/request.d.ts.map +1 -1
- package/dist/internal/request.js +2 -7
- package/dist/internal/request.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the headers for a write request: the content-type (when present) and
|
|
3
|
+
* the conditional-write precondition headers (`If-Match` / `If-None-Match: *`).
|
|
4
|
+
* Returns `undefined` when no header is needed, matching the request layer's
|
|
5
|
+
* optional `headers`.
|
|
6
|
+
*
|
|
7
|
+
* @param contentType {string | undefined} the body content-type, if any
|
|
8
|
+
* @param [precondition] {WritePrecondition} the conditional-write precondition
|
|
9
|
+
* @returns {Record<string, string> | undefined}
|
|
10
|
+
*/
|
|
11
|
+
export function writeHeaders(contentType, precondition = {}) {
|
|
12
|
+
const headers = {};
|
|
13
|
+
if (contentType) {
|
|
14
|
+
headers['content-type'] = contentType;
|
|
15
|
+
}
|
|
16
|
+
if (precondition.ifMatch !== undefined) {
|
|
17
|
+
headers['if-match'] = precondition.ifMatch;
|
|
18
|
+
}
|
|
19
|
+
if (precondition.ifNoneMatch) {
|
|
20
|
+
headers['if-none-match'] = '*';
|
|
21
|
+
}
|
|
22
|
+
return Object.keys(headers).length > 0 ? headers : undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reads the strong `ETag` validator a write/read response returned, or
|
|
26
|
+
* `undefined` when the backend sent none (it does not advertise the
|
|
27
|
+
* `conditional-writes` feature).
|
|
28
|
+
*
|
|
29
|
+
* @param response {HttpResponse | null}
|
|
30
|
+
* @returns {string | undefined}
|
|
31
|
+
*/
|
|
32
|
+
export function readEtag(response) {
|
|
33
|
+
return response?.headers.get('etag') ?? undefined;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=conditional.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional.js","sourceRoot":"","sources":["../../src/internal/conditional.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC1B,WAA+B,EAC/B,eAAkC,EAAE;IAEpC,MAAM,OAAO,GAA2B,EAAE,CAAA;IAC1C,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,cAAc,CAAC,GAAG,WAAW,CAAA;IACvC,CAAC;IACD,IAAI,YAAY,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,CAAC,UAAU,CAAC,GAAG,YAAY,CAAC,OAAO,CAAA;IAC5C,CAAC;IACD,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC;QAC7B,OAAO,CAAC,eAAe,CAAC,GAAG,GAAG,CAAA;IAChC,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;AAC9D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,QAA6B;IACpD,OAAO,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAA;AACnD,CAAC"}
|
|
@@ -5,11 +5,23 @@
|
|
|
5
5
|
* JSON-vs-binary detection and body coercion for resource writes, plus
|
|
6
6
|
* content-type-aware parsing for resource reads. A plain object/array is sent
|
|
7
7
|
* as JSON; a `Blob`/`Uint8Array`/`Buffer` is sent as binary, with the
|
|
8
|
-
* content-type taken from `options.contentType`, the `Blob.type`,
|
|
8
|
+
* content-type taken from `options.contentType`, the `Blob.type`, a guess from
|
|
9
|
+
* the resource id's file extension (`options.filename`), or
|
|
9
10
|
* `application/octet-stream`.
|
|
10
11
|
*/
|
|
11
12
|
import type { HttpResponse } from '@interop/http-client';
|
|
12
13
|
import type { Json } from '../types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Guesses a content-type from a resource id's file extension, limited to the
|
|
16
|
+
* static-web types in `WEB_CONTENT_TYPES`. Returns `undefined` when the id has
|
|
17
|
+
* no extension, is a leading-dot dotfile (e.g. `.gitignore`), or carries an
|
|
18
|
+
* unrecognized extension -- never a generic fallback, so the caller stays in
|
|
19
|
+
* control of a miss.
|
|
20
|
+
*
|
|
21
|
+
* @param id {string} the resource id (often a filename like `index.html`)
|
|
22
|
+
* @returns {string | undefined}
|
|
23
|
+
*/
|
|
24
|
+
export declare function guessContentTypeFromId(id: string): string | undefined;
|
|
13
25
|
/**
|
|
14
26
|
* A write body resolved into either a JSON payload (passed to ezcap as `json`)
|
|
15
27
|
* or a binary payload with its content-type (passed as `body` + header).
|
|
@@ -22,15 +34,32 @@ export interface PreparedBody {
|
|
|
22
34
|
/**
|
|
23
35
|
* Inspects write data and resolves it to a JSON or binary payload.
|
|
24
36
|
*
|
|
37
|
+
* The binary content-type resolves in precedence order: an explicit
|
|
38
|
+
* `options.contentType`, then a non-empty `Blob.type`, then a guess from
|
|
39
|
+
* `options.filename`'s extension, then `application/octet-stream`. (Coalescing
|
|
40
|
+
* with `||` rather than `??` so an empty-string `Blob.type` -- a typeless Blob
|
|
41
|
+
* -- falls through to the guess instead of becoming an empty content-type.)
|
|
42
|
+
*
|
|
25
43
|
* @param data {Json | Blob | Uint8Array} the resource content
|
|
26
44
|
* @param options {object}
|
|
27
45
|
* @param [options.contentType] {string} overrides the inferred content-type
|
|
28
46
|
* for binary data
|
|
47
|
+
* @param [options.filename] {string} resource id used to guess a
|
|
48
|
+
* content-type by extension when none is given (binary data only)
|
|
29
49
|
* @returns {PreparedBody}
|
|
30
50
|
*/
|
|
31
51
|
export declare function prepareBody(data: Json | Blob | Uint8Array, options?: {
|
|
32
52
|
contentType?: string;
|
|
53
|
+
filename?: string;
|
|
33
54
|
}): PreparedBody;
|
|
55
|
+
/**
|
|
56
|
+
* Reads a JSON response body, preferring the http-client's pre-parsed `data`
|
|
57
|
+
* and falling back to `response.json()` when it is absent.
|
|
58
|
+
*
|
|
59
|
+
* @param response {HttpResponse}
|
|
60
|
+
* @returns {Promise<unknown>}
|
|
61
|
+
*/
|
|
62
|
+
export declare function readJsonData(response: HttpResponse): Promise<unknown>;
|
|
34
63
|
/**
|
|
35
64
|
* Parses a resource GET response: returns the parsed object when the stored
|
|
36
65
|
* content-type is JSON, otherwise a `Blob` whose `.type` carries the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../src/internal/content.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../src/internal/content.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AA+BvC;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOrE;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAoBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,UAAU,EAC9B,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GACxD,YAAY,CA4Bd;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3E;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,YAAY,GAAG,IAAI,GAC5B,OAAO,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAS7B"}
|
package/dist/internal/content.js
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
import { ValidationError } from '../errors.js';
|
|
2
2
|
const OCTET_STREAM = 'application/octet-stream';
|
|
3
|
+
/**
|
|
4
|
+
* Extension-to-content-type fallbacks for the common static-web file types --
|
|
5
|
+
* the only case where guessing a content-type from a resource id pays off
|
|
6
|
+
* (e.g. serving an HTML site out of a public Collection). Deliberately tiny and
|
|
7
|
+
* inline: an explicit `contentType` (or a non-empty `Blob.type`) always wins,
|
|
8
|
+
* and an unknown extension yields no guess -- so this never needs the breadth
|
|
9
|
+
* (or the `mime-db`-sized weight) of a full media-type library. `.js`/`.mjs`
|
|
10
|
+
* are pinned to `text/javascript` (the WHATWG-preferred form).
|
|
11
|
+
*/
|
|
12
|
+
const WEB_CONTENT_TYPES = {
|
|
13
|
+
html: 'text/html',
|
|
14
|
+
css: 'text/css',
|
|
15
|
+
js: 'text/javascript',
|
|
16
|
+
mjs: 'text/javascript',
|
|
17
|
+
json: 'application/json',
|
|
18
|
+
svg: 'image/svg+xml',
|
|
19
|
+
png: 'image/png',
|
|
20
|
+
jpg: 'image/jpeg',
|
|
21
|
+
jpeg: 'image/jpeg',
|
|
22
|
+
gif: 'image/gif',
|
|
23
|
+
webp: 'image/webp',
|
|
24
|
+
ico: 'image/x-icon',
|
|
25
|
+
woff2: 'font/woff2',
|
|
26
|
+
txt: 'text/plain',
|
|
27
|
+
wasm: 'application/wasm'
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Guesses a content-type from a resource id's file extension, limited to the
|
|
31
|
+
* static-web types in `WEB_CONTENT_TYPES`. Returns `undefined` when the id has
|
|
32
|
+
* no extension, is a leading-dot dotfile (e.g. `.gitignore`), or carries an
|
|
33
|
+
* unrecognized extension -- never a generic fallback, so the caller stays in
|
|
34
|
+
* control of a miss.
|
|
35
|
+
*
|
|
36
|
+
* @param id {string} the resource id (often a filename like `index.html`)
|
|
37
|
+
* @returns {string | undefined}
|
|
38
|
+
*/
|
|
39
|
+
export function guessContentTypeFromId(id) {
|
|
40
|
+
const lastDot = id.lastIndexOf('.');
|
|
41
|
+
if (lastDot < 1) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const extension = id.slice(lastDot + 1).toLowerCase();
|
|
45
|
+
return WEB_CONTENT_TYPES[extension];
|
|
46
|
+
}
|
|
3
47
|
function isBlob(value) {
|
|
4
48
|
return typeof Blob !== 'undefined' && value instanceof Blob;
|
|
5
49
|
}
|
|
@@ -19,23 +63,34 @@ function toPlainBytes(bytes) {
|
|
|
19
63
|
/**
|
|
20
64
|
* Inspects write data and resolves it to a JSON or binary payload.
|
|
21
65
|
*
|
|
66
|
+
* The binary content-type resolves in precedence order: an explicit
|
|
67
|
+
* `options.contentType`, then a non-empty `Blob.type`, then a guess from
|
|
68
|
+
* `options.filename`'s extension, then `application/octet-stream`. (Coalescing
|
|
69
|
+
* with `||` rather than `??` so an empty-string `Blob.type` -- a typeless Blob
|
|
70
|
+
* -- falls through to the guess instead of becoming an empty content-type.)
|
|
71
|
+
*
|
|
22
72
|
* @param data {Json | Blob | Uint8Array} the resource content
|
|
23
73
|
* @param options {object}
|
|
24
74
|
* @param [options.contentType] {string} overrides the inferred content-type
|
|
25
75
|
* for binary data
|
|
76
|
+
* @param [options.filename] {string} resource id used to guess a
|
|
77
|
+
* content-type by extension when none is given (binary data only)
|
|
26
78
|
* @returns {PreparedBody}
|
|
27
79
|
*/
|
|
28
80
|
export function prepareBody(data, options = {}) {
|
|
81
|
+
const guessed = options.filename
|
|
82
|
+
? guessContentTypeFromId(options.filename)
|
|
83
|
+
: undefined;
|
|
29
84
|
if (isBlob(data)) {
|
|
30
85
|
return {
|
|
31
86
|
body: data,
|
|
32
|
-
contentType: options.contentType
|
|
87
|
+
contentType: options.contentType || data.type || guessed || OCTET_STREAM
|
|
33
88
|
};
|
|
34
89
|
}
|
|
35
90
|
if (data instanceof Uint8Array) {
|
|
36
91
|
return {
|
|
37
92
|
body: toPlainBytes(data),
|
|
38
|
-
contentType: options.contentType
|
|
93
|
+
contentType: options.contentType || guessed || OCTET_STREAM
|
|
39
94
|
};
|
|
40
95
|
}
|
|
41
96
|
if (data !== null && typeof data === 'object') {
|
|
@@ -45,6 +100,16 @@ export function prepareBody(data, options = {}) {
|
|
|
45
100
|
throw new ValidationError('Resource data must be a plain object/array (JSON) or a ' +
|
|
46
101
|
'Blob/Uint8Array (binary).');
|
|
47
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Reads a JSON response body, preferring the http-client's pre-parsed `data`
|
|
105
|
+
* and falling back to `response.json()` when it is absent.
|
|
106
|
+
*
|
|
107
|
+
* @param response {HttpResponse}
|
|
108
|
+
* @returns {Promise<unknown>}
|
|
109
|
+
*/
|
|
110
|
+
export async function readJsonData(response) {
|
|
111
|
+
return response.data ?? (await response.json());
|
|
112
|
+
}
|
|
48
113
|
/**
|
|
49
114
|
* Parses a resource GET response: returns the parsed object when the stored
|
|
50
115
|
* content-type is JSON, otherwise a `Blob` whose `.type` carries the
|
|
@@ -59,7 +124,7 @@ export async function parseResource(response) {
|
|
|
59
124
|
}
|
|
60
125
|
const contentType = response.headers.get('content-type') ?? '';
|
|
61
126
|
if (contentType.includes('json')) {
|
|
62
|
-
return (
|
|
127
|
+
return (await readJsonData(response));
|
|
63
128
|
}
|
|
64
129
|
return response.blob();
|
|
65
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/internal/content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/internal/content.ts"],"names":[],"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AAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAS,CAAA;IAC/C,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;AACxB,CAAC"}
|
|
@@ -10,15 +10,19 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import type { ZcapClient } from '@interop/ezcap';
|
|
12
12
|
import type { HttpResponse } from '@interop/http-client';
|
|
13
|
+
import type { EncryptionProvider } from '../codec.js';
|
|
13
14
|
import type { IZcap } from '../types.js';
|
|
14
15
|
/**
|
|
15
16
|
* The shared context threaded through every handle: the server base URL, the
|
|
16
|
-
* wrapped ezcap client,
|
|
17
|
+
* wrapped ezcap client, the cached controller DID of its signer, and the
|
|
18
|
+
* optional encryption provider that supplies an encrypting codec for the
|
|
19
|
+
* collections the client holds keys for.
|
|
17
20
|
*/
|
|
18
21
|
export interface ClientContext {
|
|
19
22
|
serverUrl: string;
|
|
20
23
|
zcapClient: ZcapClient;
|
|
21
24
|
controllerDid: string;
|
|
25
|
+
encryption?: EncryptionProvider;
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
28
|
* A single signed request. Either `path` (resolved against `serverUrl`) or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/internal/request.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAGxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/internal/request.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBA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B;AAED;;;;;;;;GAQG;AACH,wBAAsB,IAAI,CACxB,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,SAAS,GACf,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAS9B"}
|
package/dist/internal/request.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mapError } from '../errors.js';
|
|
1
|
+
import { mapError, httpStatus } from '../errors.js';
|
|
2
2
|
import { toUrl } from './paths.js';
|
|
3
3
|
function resolveRequestUrl(context, input) {
|
|
4
4
|
if (input.url !== undefined) {
|
|
@@ -87,12 +87,7 @@ export async function send(context, input) {
|
|
|
87
87
|
return await rawRequest(context, input);
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
|
-
|
|
91
|
-
?.status;
|
|
92
|
-
const responseStatus = err?.response
|
|
93
|
-
?.status;
|
|
94
|
-
if ((input.read || input.idempotent) &&
|
|
95
|
-
(status === 404 || responseStatus === 404)) {
|
|
90
|
+
if ((input.read || input.idempotent) && httpStatus(err) === 404) {
|
|
96
91
|
return null;
|
|
97
92
|
}
|
|
98
93
|
throw mapError(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/internal/request.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/internal/request.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AA2ClC,SAAS,iBAAiB,CAAC,OAAsB,EAAE,KAAgB;IACjE,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,GAAG,CAAA;IAClB,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC7B,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,CAAC;QAC1C,OAAO,IAAI,CAAA;IACb,CAAC;IACD,0EAA0E;IAC1E,IAAI,IAAa,CAAA;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;AAC1E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,OAAsB,EACtB,KAAgB;IAEhB,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;YAChE,OAAO,IAAI,CAAA;QACb,CAAC;QACD,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAA;IACrB,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -34,6 +34,12 @@ export interface AddResult {
|
|
|
34
34
|
id: string;
|
|
35
35
|
url: string;
|
|
36
36
|
contentType?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The created resource's strong `ETag` validator, when the backend advertises
|
|
39
|
+
* the `conditional-writes` feature (absent otherwise). Pass it to a later
|
|
40
|
+
* `put(id, data, { ifMatch })` for a lost-update-safe update.
|
|
41
|
+
*/
|
|
42
|
+
etag?: string;
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* Options accepted by every handle factory (`space()`, `collection()`,
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,CAAA;AAM9C,YAAY,EACV,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,EACtB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAE9B;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AAC5D,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AACD,MAAM,MAAM,SAAS,GAAG,IAAI,EAAE,CAAA;AAC9B,MAAM,MAAM,IAAI,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,CAAA;AAEzD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAA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,CAAA;IACf,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,IAAI,GAAG,UAAU,CAAA;IACxB,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB"}
|
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.7.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "pnpm run clear && tsc",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"test": "pnpm run fix && pnpm run lint && pnpm run test:node && pnpm run test:browser",
|
|
16
16
|
"test:browser": "playwright test",
|
|
17
17
|
"test:node": "vitest run",
|
|
18
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
18
19
|
"test:coverage": "vitest run --coverage"
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
@@ -28,6 +29,12 @@
|
|
|
28
29
|
"react-native": "./dist/index.js",
|
|
29
30
|
"import": "./dist/index.js",
|
|
30
31
|
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./edv": {
|
|
34
|
+
"types": "./dist/edv/index.d.ts",
|
|
35
|
+
"react-native": "./dist/edv/index.js",
|
|
36
|
+
"import": "./dist/edv/index.js",
|
|
37
|
+
"default": "./dist/edv/index.js"
|
|
31
38
|
}
|
|
32
39
|
},
|
|
33
40
|
"module": "dist/index.js",
|
|
@@ -35,14 +42,17 @@
|
|
|
35
42
|
"types": "dist/index.d.ts",
|
|
36
43
|
"sideEffects": false,
|
|
37
44
|
"dependencies": {
|
|
38
|
-
"@interop/data-integrity-core": "^8.
|
|
45
|
+
"@interop/data-integrity-core": "^8.1.0",
|
|
39
46
|
"@interop/ed25519-signature": "^7.1.2",
|
|
47
|
+
"@interop/edv-client": "^17.2.0",
|
|
40
48
|
"@interop/ezcap": "^7.2.1",
|
|
41
49
|
"@interop/http-client": "^1.0.3",
|
|
42
|
-
"@interop/storage-core": "^0.
|
|
50
|
+
"@interop/storage-core": "^0.2.2"
|
|
43
51
|
},
|
|
44
52
|
"devDependencies": {
|
|
45
53
|
"@eslint/js": "^10.0.1",
|
|
54
|
+
"@interop/ed25519-verification-key": "^8.0.0",
|
|
55
|
+
"@interop/x25519-key-agreement-key": "^5.1.0",
|
|
46
56
|
"@playwright/test": "^1.60.0",
|
|
47
57
|
"@types/node": "^25.9.1",
|
|
48
58
|
"@vitest/coverage-v8": "^4.1.7",
|