@interop/was-client 0.92.0 → 0.93.1

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.
Files changed (65) hide show
  1. package/README.md +176 -13
  2. package/dist/Collection.d.ts +43 -6
  3. package/dist/Collection.d.ts.map +1 -1
  4. package/dist/Collection.js +96 -21
  5. package/dist/Collection.js.map +1 -1
  6. package/dist/Resource.d.ts +35 -2
  7. package/dist/Resource.d.ts.map +1 -1
  8. package/dist/Resource.js +49 -5
  9. package/dist/Resource.js.map +1 -1
  10. package/dist/Space.d.ts +85 -1
  11. package/dist/Space.d.ts.map +1 -1
  12. package/dist/Space.js +160 -1
  13. package/dist/Space.js.map +1 -1
  14. package/dist/codec.d.ts +26 -0
  15. package/dist/codec.d.ts.map +1 -1
  16. package/dist/edv/EdvCodec.d.ts +20 -1
  17. package/dist/edv/EdvCodec.d.ts.map +1 -1
  18. package/dist/edv/EdvCodec.js +161 -85
  19. package/dist/edv/EdvCodec.js.map +1 -1
  20. package/dist/edv/WasTransport.d.ts.map +1 -1
  21. package/dist/edv/WasTransport.js +10 -7
  22. package/dist/edv/WasTransport.js.map +1 -1
  23. package/dist/errors.d.ts +13 -5
  24. package/dist/errors.d.ts.map +1 -1
  25. package/dist/errors.js +98 -49
  26. package/dist/errors.js.map +1 -1
  27. package/dist/identity/agents.d.ts +8 -0
  28. package/dist/identity/agents.d.ts.map +1 -1
  29. package/dist/identity/agents.js +13 -1
  30. package/dist/identity/agents.js.map +1 -1
  31. package/dist/index.d.ts +3 -3
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal/blob.d.ts +16 -1
  36. package/dist/internal/blob.d.ts.map +1 -1
  37. package/dist/internal/blob.js +34 -1
  38. package/dist/internal/blob.js.map +1 -1
  39. package/dist/internal/codec.d.ts +3 -2
  40. package/dist/internal/codec.d.ts.map +1 -1
  41. package/dist/internal/codec.js +26 -3
  42. package/dist/internal/codec.js.map +1 -1
  43. package/dist/internal/content.d.ts +65 -10
  44. package/dist/internal/content.d.ts.map +1 -1
  45. package/dist/internal/content.js +88 -11
  46. package/dist/internal/content.js.map +1 -1
  47. package/dist/internal/describe.d.ts.map +1 -1
  48. package/dist/internal/describe.js +6 -1
  49. package/dist/internal/describe.js.map +1 -1
  50. package/dist/internal/paths.d.ts +17 -11
  51. package/dist/internal/paths.d.ts.map +1 -1
  52. package/dist/internal/paths.js +23 -11
  53. package/dist/internal/paths.js.map +1 -1
  54. package/dist/sync/envelope.d.ts +11 -3
  55. package/dist/sync/envelope.d.ts.map +1 -1
  56. package/dist/sync/envelope.js +11 -3
  57. package/dist/sync/envelope.js.map +1 -1
  58. package/dist/sync/port.d.ts.map +1 -1
  59. package/dist/sync/port.js +6 -10
  60. package/dist/sync/port.js.map +1 -1
  61. package/dist/sync/types.d.ts +5 -8
  62. package/dist/sync/types.d.ts.map +1 -1
  63. package/dist/types.d.ts +12 -6
  64. package/dist/types.d.ts.map +1 -1
  65. package/package.json +8 -7
@@ -57,13 +57,25 @@ export async function agentsFromSeed({ seed }) {
57
57
  * Passing a string keeps every secret typeable/scannable into a login form
58
58
  * (the cross-wallet linking flow).
59
59
  *
60
+ * The secret is trimmed before derivation, so leading and trailing whitespace
61
+ * (a pasted passphrase, a scanned code) does not change the identity. An
62
+ * empty or whitespace-only secret is rejected with `ValidationError`: the
63
+ * handle and key name are public constants, so the identity such a secret
64
+ * would derive is computable by anyone, and a caller passing an unfilled
65
+ * field would otherwise land silently in that shared account. No minimum
66
+ * length is enforced beyond that.
67
+ *
60
68
  * @param options {object}
61
69
  * @param options.secret {string} the controller secret (see above)
62
70
  * @returns {Promise<ProfileAgents>}
63
71
  */
64
72
  export async function agentsFromSecret({ secret }) {
73
+ const trimmed = secret.trim();
74
+ if (trimmed.length === 0) {
75
+ throw new ValidationError('Expected a non-empty controller secret, got an empty or whitespace-only string.');
76
+ }
65
77
  const keyAgent = await CapabilityAgent.fromSecret({
66
- secret,
78
+ secret: trimmed,
67
79
  handle: BOOTSTRAP_HANDLE,
68
80
  keyName: BOOTSTRAP_KEY_NAME
69
81
  });
@@ -1 +1 @@
1
- {"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/identity/agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAK7E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAA;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAA;AAejD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,IAAI,EAGL;IACC,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACvB,MAAM,IAAI,eAAe,CACvB,gCAAgC,IAAI,CAAC,MAAM,SAAS,CACrD,CAAA;IACH,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC;QAC9C,IAAI;QACJ,MAAM,EAAE,gBAAgB;QACxB,OAAO,EAAE,kBAAkB;KAC5B,CAAC,CAAA;IACF,OAAO,kBAAkB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;AACzC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,EACrC,MAAM,EAGP;IACC,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC;QAChD,MAAM;QAC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AG,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAA;IAE1D,OAAO;QACL,aAAa,EAAE,QAAQ,CAAC,EAAE;QAC1B,QAAQ;QACR,UAAU;QACV,mEAAmE;QACnE,iEAAiE;QACjE,eAAe,EAAE,eAAmC;QACpD,WAAW;KACZ,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -15,12 +15,12 @@ export { parseSpaceTarget } from './internal/paths.js';
15
15
  export type { ParsedSpacePath } from './internal/paths.js';
16
16
  export { readEtag, writeHeaders } from './internal/conditional.js';
17
17
  export { isGovernedDescriptor } from './internal/describe.js';
18
- export { isJsonResourceChange, isResourceChange } from '@interop/storage-core';
18
+ export { isJsonResourceChange, isResourceChange, ProblemTypes } from '@interop/storage-core';
19
19
  export type { WritePrecondition } from './internal/conditional.js';
20
20
  export { WasError, NotFoundError, CapabilityRevokedError, CapabilityExpiredError, ValidationError, AlreadyRevokedError, AuthRequiredError, NotImplementedError, NotSupportedError, IncompatibleServerError, ConflictError, PreconditionFailedError, PayloadTooLargeError, QuotaExceededError, EncryptionError, EncryptOnlyCipherError, UnverifiedDescriptorError, KeyUnwrapError, IntegrityError, WasSyncAuthError, WasSyncCheckpointError, WasSyncConflictError, WasSyncNotFoundError, WasServerError, httpStatus, mapError } from './errors.js';
21
21
  export { isChunkedWrite } from './codec.js';
22
- export type { ResourceCodec, EncryptionProvider, ChunkedWrite, CodecRequestContext, CodecWrite, MetaReadSlot, MetaWriteSlot, EncodedWrite, ResponseLike, BlindedQuery, CodecIndexing, IndexDeclaration, IndexSchema } from './codec.js';
23
- export type { Json, JsonPrimitive, JsonObject, JsonArray, ResourceData, Action, ActionInput, ChangeDocument, ChangesCheckpoint, ChangesPage, ContainerChangeDocument, PolicyChangeDocument, ResourceChangeDocument, SpaceMetadata, CollectionWritableFields, CollectionEncryption, CollectionEncryptionEpoch, CollectionEncryptionRecipient, CollectionEncryptionHmac, EncryptionWithHmac, CollectionSummary, CollectionsList, SpaceSummary, SpaceListing, ResourceSummary, CollectionResourcesList, ResourceMetadata, ResourceMetadataCustom, ResourceMetadataCustomInput, CollectionMetadata, CollectionGenerator, AddResult, FindPage, ImportStats, PolicyDocument, PolicyTombstone, LinkSet, LinkSetEntry, HandleOptions, EncryptionOverride, BackendReference, BackendDescriptor, BackendRegistration, BackendConnectionInput, BackendConnectionPublic, StorageLimit, CollectionUsage, BackendUsage, SpaceQuotaReport, ServiceDescription, ServiceDescriptionVersionEntry, PwsVersionEntry, ServiceInfo, GrantOptions, RequestInput, IZcap, IDelegatedZcap, IRootZcap, IDID, ISigner } from './types.js';
22
+ export type { DecodedStream, ResourceCodec, EncryptionProvider, ChunkedWrite, CodecRequestContext, CodecWrite, MetaReadSlot, MetaWriteSlot, EncodedWrite, ResponseLike, BlindedQuery, CodecIndexing, IndexDeclaration, IndexSchema } from './codec.js';
23
+ export type { Json, JsonPrimitive, JsonObject, JsonArray, ResourceData, Action, ActionInput, ChangeDocument, ChangesCheckpoint, ChangesPage, ContainerChangeDocument, PolicyChangeDocument, ResourceChangeDocument, SpaceMetadata, CollectionWritableFields, CollectionEncryption, CollectionEncryptionEpoch, CollectionEncryptionRecipient, CollectionEncryptionHmac, EncryptionWithHmac, CollectionSummary, CollectionsList, SpaceSummary, SpaceListing, ResourceSummary, CollectionResourcesList, ResourceMetadata, ResourceMetadataCustom, ResourceMetadataCustomInput, CollectionMetadata, CollectionGenerator, AddResult, FindPage, ImportStats, PolicyDocument, PolicyTombstone, LinkSet, LinkSetEntry, HandleOptions, EncryptionOverride, BackendReference, BackendDescriptor, BackendRegistration, BackendConnectionInput, BackendConnectionPublic, StorageLimit, CollectionUsage, BackendUsage, SpaceQuotaReport, ReplicaRegistration, ReplicaSummary, ReplicaRole, ReplicaListing, ReplicaStatus, ReplicaCollectionStatus, ReplicaStallReason, WriteStamp, ServiceDescription, ServiceDescriptionVersionEntry, PwsVersionEntry, ServiceInfo, GrantOptions, RequestInput, IZcap, IDelegatedZcap, IRootZcap, IDID, ISigner } from './types.js';
24
24
  /**
25
25
  * The Collection Metadata `custom` object as the blinded-index code sees it --
26
26
  * the user's own properties plus the `indexSchema` `declareIndex` persists.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAG7D,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC9E,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,EACL,QAAQ,EACR,aAAa,EACb,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,QAAQ,EACT,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,WAAW,EACZ,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,cAAc,EACd,eAAe,EACf,OAAO,EACP,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,8BAA8B,EAC9B,eAAe,EACf,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,cAAc,EACd,SAAS,EACT,IAAI,EACJ,OAAO,EACR,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,YAAY,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;GAGG;AACH,OAAO,EAAE,SAAS,EAA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,WAAW,EACZ,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,cAAc,EACd,eAAe,EACf,OAAO,EACP,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,cAAc,EACd,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EAClB,8BAA8B,EAC9B,eAAe,EACf,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,cAAc,EACd,SAAS,EACT,IAAI,EACJ,OAAO,EACR,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,YAAY,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA"}
package/dist/index.js CHANGED
@@ -15,8 +15,10 @@ export { parseSpaceTarget } from './internal/paths.js';
15
15
  export { readEtag, writeHeaders } from './internal/conditional.js';
16
16
  export { isGovernedDescriptor } from './internal/describe.js';
17
17
  // The `changes` feed guards a consumer filters `Collection.changes()` pages
18
- // with, so a consumer needs no direct `@interop/storage-core` dependency.
19
- export { isJsonResourceChange, isResourceChange } from '@interop/storage-core';
18
+ // with, and the problem-type registry a consumer tells one `ConflictError`
19
+ // kind from another by, so a consumer needs no direct `@interop/storage-core`
20
+ // dependency.
21
+ export { isJsonResourceChange, isResourceChange, ProblemTypes } from '@interop/storage-core';
20
22
  export { WasError, NotFoundError, CapabilityRevokedError, CapabilityExpiredError, ValidationError, AlreadyRevokedError, AuthRequiredError, NotImplementedError, NotSupportedError, IncompatibleServerError, ConflictError, PreconditionFailedError, PayloadTooLargeError, QuotaExceededError, EncryptionError, EncryptOnlyCipherError, UnverifiedDescriptorError, KeyUnwrapError, IntegrityError, WasSyncAuthError, WasSyncCheckpointError, WasSyncConflictError, WasSyncNotFoundError, WasServerError, httpStatus, mapError } from './errors.js';
21
23
  export { isChunkedWrite } from './codec.js';
22
24
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,4EAA4E;AAC5E,0EAA0E;AAC1E,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAG9E,OAAO,EACL,QAAQ,EACR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EACjB,uBAAuB,EACvB,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,QAAQ,EACT,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
@@ -2,7 +2,8 @@
2
2
  * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
3
  */
4
4
  /**
5
- * Portable `Blob` reads.
5
+ * Portable `Blob` reads, plus the one-way conversion of in-hand bytes to a
6
+ * byte stream.
6
7
  *
7
8
  * A `Blob` in a browser or in Node implements `text()` and `arrayBuffer()`, so
8
9
  * reading one is a single await. React Native's built-in `Blob` implements
@@ -32,4 +33,18 @@ export declare function blobText(blob: Blob): Promise<string>;
32
33
  * @returns {Promise<Uint8Array>}
33
34
  */
34
35
  export declare function blobBytes(blob: Blob): Promise<Uint8Array>;
36
+ /**
37
+ * Presents a binary payload as a `ReadableStream<Uint8Array>`. Bytes already
38
+ * in hand become a one-chunk stream over that same buffer (no copy), so a
39
+ * caller whose consumer reads across many awaits snapshots the buffer itself
40
+ * if it may be reused meanwhile. A `Blob` is immutable and streams itself
41
+ * where it implements `stream()`; React Native's built-in `Blob` does not, so
42
+ * there the stream reads the blob's bytes through {@link blobBytes} on first
43
+ * pull. A consumer that re-chunks what it reads (the EDV encrypt stream) is
44
+ * unaffected by the shape of the source stream.
45
+ *
46
+ * @param data {Blob | Uint8Array}
47
+ * @returns {ReadableStream<Uint8Array>}
48
+ */
49
+ export declare function bytesToStream(data: Blob | Uint8Array): ReadableStream<Uint8Array>;
35
50
  //# sourceMappingURL=blob.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/internal/blob.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;GAgBG;AA0EH;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAe1D;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CA0B/D"}
1
+ {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/internal/blob.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;GAiBG;AA0EH;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAe1D;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CA0B/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,GAAG,UAAU,GACtB,cAAc,CAAC,UAAU,CAAC,CAkB5B"}
@@ -2,7 +2,8 @@
2
2
  * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
3
  */
4
4
  /**
5
- * Portable `Blob` reads.
5
+ * Portable `Blob` reads, plus the one-way conversion of in-hand bytes to a
6
+ * byte stream.
6
7
  *
7
8
  * A `Blob` in a browser or in Node implements `text()` and `arrayBuffer()`, so
8
9
  * reading one is a single await. React Native's built-in `Blob` implements
@@ -111,4 +112,36 @@ export async function blobBytes(blob) {
111
112
  }
112
113
  throw new TypeError('FileReader.readAsArrayBuffer did not yield an ArrayBuffer.');
113
114
  }
115
+ /**
116
+ * Presents a binary payload as a `ReadableStream<Uint8Array>`. Bytes already
117
+ * in hand become a one-chunk stream over that same buffer (no copy), so a
118
+ * caller whose consumer reads across many awaits snapshots the buffer itself
119
+ * if it may be reused meanwhile. A `Blob` is immutable and streams itself
120
+ * where it implements `stream()`; React Native's built-in `Blob` does not, so
121
+ * there the stream reads the blob's bytes through {@link blobBytes} on first
122
+ * pull. A consumer that re-chunks what it reads (the EDV encrypt stream) is
123
+ * unaffected by the shape of the source stream.
124
+ *
125
+ * @param data {Blob | Uint8Array}
126
+ * @returns {ReadableStream<Uint8Array>}
127
+ */
128
+ export function bytesToStream(data) {
129
+ if (data instanceof Uint8Array) {
130
+ return new ReadableStream({
131
+ start(controller) {
132
+ controller.enqueue(data);
133
+ controller.close();
134
+ }
135
+ });
136
+ }
137
+ if (typeof data.stream === 'function') {
138
+ return data.stream();
139
+ }
140
+ return new ReadableStream({
141
+ async pull(controller) {
142
+ controller.enqueue(await blobBytes(data));
143
+ controller.close();
144
+ }
145
+ });
146
+ }
114
147
  //# sourceMappingURL=blob.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src/internal/blob.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;GAgBG;AAgBH;;;;;GAKG;AACH,SAAS,qBAAqB;IAC5B,MAAM,IAAI,GAAI,UAAuC,CAAC,UAAU,CAAA;IAChE,OAAO,OAAO,IAAI,KAAK,UAAU;QAC/B,CAAC,CAAE,IAAiC;QACpC,CAAC,CAAC,SAAS,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,kBAAkB,CAAC,EAChC,IAAI,EACJ,IAAI,EACJ,IAAI,EAKL;IACC,MAAM,cAAc,GAAG,qBAAqB,EAAE,CAAA;IAC9C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CACjB,eAAe,IAAI,iDAAiD;YAClE,2DAA2D,CAC9D,CAAA;IACH,CAAC;IACD,OAAO,MAAM,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACpD,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAA;QACnC,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;YACnB,OAAO,CAAC,MAAM,CAAC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ClC,CAAC;QACD,IAAI,EAAE,OAAO;KACd,CAAC,CAAA;IACF,wEAAwE;IACxE,uEAAuE;IACvE,IAAI,MAAM,YAAY,WAAW,EAAE,CAAC;QAClC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,OAAO,IAAI,UAAU,CACnB,MAAM,CAAC,MAAqB,EAC5B,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,CAClB,CAAA;IACH,CAAC;IACD,MAAM,IAAI,SAAS,CACjB,4DAA4D,CAC7D,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAuB;IAEvB,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC/B,OAAO,IAAI,cAAc,CAAa;YACpC,KAAK,CAAC,UAAU;gBACd,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;gBACxB,UAAU,CAAC,KAAK,EAAE,CAAA;YACpB,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IACD,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC,MAAM,EAAgC,CAAA;IACpD,CAAC;IACD,OAAO,IAAI,cAAc,CAAa;QACpC,KAAK,CAAC,IAAI,CAAC,UAAU;YACnB,UAAU,CAAC,OAAO,CAAC,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;YACzC,UAAU,CAAC,KAAK,EAAE,CAAA;QACpB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -91,8 +91,9 @@ export declare function collectionCodecHolder(context: ClientContext, options: C
91
91
  * caller's `id` (so `put(id, ...)` is a `PUT` and `add(...)`, with no id, stays
92
92
  * a server-minting `POST`) and reuses `prepareBody` -- including the
93
93
  * filename-extension content-type guess when an id is present. `decode` reuses
94
- * `parseResource`. `encodeMeta` / `decodeMeta` are the identity transform, so
95
- * metadata round-trips as server-visible plaintext byte-for-byte.
94
+ * `parseResource`, and `decodeStream` hands back the response body itself.
95
+ * `encodeMeta` / `decodeMeta` are the identity transform, so metadata
96
+ * round-trips as server-visible plaintext byte-for-byte.
96
97
  */
97
98
  export declare const identityCodec: ResourceCodec;
98
99
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/internal/codec.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAYjD,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,EAKN,MAAM,aAAa,CAAA;AAEpB;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,aAAa,CAAA;IACpB,IAAI,CAAC,EAAE,CAAC,kBAAkB,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAA;CACvD;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,WAAW;;IAGtB;;;OAGG;gBACS,OAAO,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC;IAInD;;;;;OAKG;IACG,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC;IAMnC;;;;;;;;;OASG;IACG,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC;IAUzC;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;;;;GAKG;AACH,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IAC7B,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,aAAa,EACtB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AO,IAAI,OAAO,CAAC,eAAe,CAAC;IAUzC;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;;;;GAKG;AACH,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IAC7B,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,WAAW,GACnB,WAAW,CAEb;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,EAAE,aAyD3B,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,aAAa,EACtB,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,WAAW,GAC3D,OAAO,CAAC,eAAe,CAAC,CA4E1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,aAAa,EACtB,EACE,OAAO,EACP,YAAY,EACZ,UAAU,EACX,EAAE;IACD,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,oBAAoB,CAAA;CAClC,GACA,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAc/B"}
@@ -1,4 +1,5 @@
1
- import { prepareBody, parseResource } from './content.js';
1
+ import { decodedStream, mediaType, prepareBody, parseResource } from './content.js';
2
+ import { bytesToStream } from './blob.js';
2
3
  import { asCollectionMetadata, storedEncryption, unreadableDescriptionError } from './describe.js';
3
4
  import { readCollectionMetadata } from './meta.js';
4
5
  import { readIndexSchema } from './indexSchema.js';
@@ -86,8 +87,9 @@ export function collectionCodecHolder(context, options) {
86
87
  * caller's `id` (so `put(id, ...)` is a `PUT` and `add(...)`, with no id, stays
87
88
  * a server-minting `POST`) and reuses `prepareBody` -- including the
88
89
  * filename-extension content-type guess when an id is present. `decode` reuses
89
- * `parseResource`. `encodeMeta` / `decodeMeta` are the identity transform, so
90
- * metadata round-trips as server-visible plaintext byte-for-byte.
90
+ * `parseResource`, and `decodeStream` hands back the response body itself.
91
+ * `encodeMeta` / `decodeMeta` are the identity transform, so metadata
92
+ * round-trips as server-visible plaintext byte-for-byte.
91
93
  */
92
94
  export const identityCodec = {
93
95
  async encode({ id, data, contentType }) {
@@ -100,6 +102,27 @@ export const identityCodec = {
100
102
  async decode(response) {
101
103
  return (await parseResource(response));
102
104
  },
105
+ // Narrowed to `HttpResponse` like `decode`. A body the http-client already
106
+ // parsed into `data` (a JSON content type) has a spent stream, so it is
107
+ // re-serialized through `decodedStream`: semantically identical JSON, not
108
+ // guaranteed byte-identical. Any other body is passed on unread, and an
109
+ // absent body (a bodiless response) reads as an empty stream. The reported
110
+ // type is the bare media type (no `; charset=...`), as the seam documents
111
+ // and as an encrypting codec's sealed type is, so a caller sees one shape
112
+ // whichever codec served the read.
113
+ async decodeStream(response) {
114
+ const contentType = mediaType(response.headers.get('content-type') ?? '') || undefined;
115
+ if (response.data !== undefined) {
116
+ return decodedStream({
117
+ value: response.data,
118
+ ...(contentType !== undefined && { contentType })
119
+ });
120
+ }
121
+ const stream = response.body
122
+ ? response.body
123
+ : bytesToStream(new Uint8Array(0));
124
+ return { stream, ...(contentType !== undefined && { contentType }) };
125
+ },
103
126
  async encodeMeta({ custom }) {
104
127
  return { custom };
105
128
  },
@@ -1 +1 @@
1
- {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/internal/codec.ts"],"names":[],"mappings":"AA8BA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE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AC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,KAAK,UAAU,eAAe,CAC5B,OAAsB,EACtB,EACE,OAAO,EACP,YAAY,EACZ,UAAU,EACV,KAAK,EAMN;IAED,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,IAAI,CAAA;IACR,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,sBAAsB,CAAC,OAAO,EAAE;YAC3C,OAAO;YACP,YAAY;YACZ,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,mBAAmB,EAAE,CAAC;YACvC,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;IACD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;AACtC,CAAC"}
@@ -7,10 +7,12 @@
7
7
  * as JSON; a `Blob`/`Uint8Array`/`Buffer` is sent as binary, with the
8
8
  * content-type taken from `options.contentType`, the `Blob.type`, a guess from
9
9
  * the resource id's file extension (`options.filename`), or
10
- * `application/octet-stream`.
10
+ * `application/octet-stream`. A `ReadableStream<Uint8Array>` is classified as
11
+ * a stream, which only an encrypting codec can store; the plaintext path
12
+ * refuses it.
11
13
  */
12
14
  import type { HttpResponse } from '@interop/http-client';
13
- import type { ResponseLike } from '../codec.js';
15
+ import type { DecodedStream, ResponseLike } from '../codec.js';
14
16
  import type { Json, ResourceData } from '../types.js';
15
17
  /**
16
18
  * The content type a resource log is stored under (JSON Lines, not JSON --
@@ -34,6 +36,14 @@ export declare const ENCODER: TextEncoder;
34
36
  * path, protected-header bytes on the read path.
35
37
  */
36
38
  export declare const DECODER: TextDecoder;
39
+ /**
40
+ * The bare media type of a `Content-Type` value: `text/plain; charset=utf-8`
41
+ * is `text/plain`. Case is kept as given.
42
+ *
43
+ * @param contentType {string}
44
+ * @returns {string}
45
+ */
46
+ export declare function mediaType(contentType: string): string;
37
47
  /**
38
48
  * Whether a content type denotes UTF-8-safe text that should be stored inline as
39
49
  * a plain string (legible, no ~33% base64 inflation) rather than as opaque
@@ -67,6 +77,17 @@ export declare function guessContentTypeFromId(id: string): string | undefined;
67
77
  * @returns {boolean}
68
78
  */
69
79
  export declare function isBlob(value: unknown): value is Blob;
80
+ /**
81
+ * Whether a value is a `ReadableStream`. Duck-typed on `getReader` rather
82
+ * than `instanceof`, so a stream from another realm or a polyfill counts (and
83
+ * so it works where the `ReadableStream` global is undefined): no JSON value
84
+ * has a `getReader` method, and classifying such a stream as JSON would
85
+ * silently store `{}`.
86
+ *
87
+ * @param value {unknown}
88
+ * @returns {boolean}
89
+ */
90
+ export declare function isReadableStream(value: unknown): value is ReadableStream<Uint8Array>;
70
91
  /**
71
92
  * Coerces a `Uint8Array` (including a Node `Buffer`, which is a subclass) to a
72
93
  * plain `Uint8Array` view, as ezcap's `body` type expects.
@@ -77,35 +98,45 @@ export declare function isBlob(value: unknown): value is Blob;
77
98
  export declare function toPlainBytes(bytes: Uint8Array): Uint8Array;
78
99
  /**
79
100
  * Write data classified by `resolvePayload`: binary (a `Blob`/`Uint8Array`
80
- * with its resolved content-type), JSON (a plain object/array), or invalid (a
81
- * bare primitive -- the caller throws its own error message).
101
+ * with its resolved content-type), a stream (a `ReadableStream<Uint8Array>`
102
+ * with its resolved content-type, size unknown), JSON (a plain object/array),
103
+ * or invalid (a bare primitive -- the caller throws its own error message).
82
104
  */
83
105
  type ResolvedPayload = {
84
106
  kind: 'binary';
85
107
  data: Blob | Uint8Array;
86
108
  contentType: string;
109
+ } | {
110
+ kind: 'stream';
111
+ data: ReadableStream<Uint8Array>;
112
+ contentType: string;
87
113
  } | {
88
114
  kind: 'json';
89
115
  } | {
90
116
  kind: 'invalid';
91
117
  };
92
118
  /**
93
- * Classifies write data as binary or JSON and resolves the binary
94
- * content-type -- the single source of the detection and precedence rules
95
- * shared by the plaintext `prepareBody` and the EDV codec's document builder.
119
+ * Classifies write data as binary, a stream, or JSON and resolves the binary
120
+ * or stream content-type -- the single source of the detection and precedence
121
+ * rules shared by the plaintext `prepareBody` and the EDV codec's document
122
+ * builder.
96
123
  *
97
124
  * The binary content-type resolves in precedence order: an explicit
98
125
  * `contentType`, then a non-empty `Blob.type`, then a guess from the resource
99
126
  * `id`'s extension, then `application/octet-stream`. (Coalescing with `||`
100
127
  * rather than `??` so an empty-string `Blob.type` -- a typeless Blob -- falls
101
- * through to the guess instead of becoming an empty content-type.)
128
+ * through to the guess instead of becoming an empty content-type.) A stream
129
+ * resolves the same way as a `Uint8Array`, since it has no `Blob.type`: an
130
+ * explicit `contentType`, then the extension guess, then
131
+ * `application/octet-stream`. A stream is tested before the JSON branch, so it
132
+ * is never mistaken for a plain object.
102
133
  *
103
134
  * @param options {object}
104
135
  * @param options.data {ResourceData} the resource content
105
136
  * @param [options.contentType] {string} overrides the inferred content-type
106
- * for binary data
137
+ * for binary or stream data
107
138
  * @param [options.id] {string} resource id used to guess a
108
- * content-type by extension when none is given (binary data only)
139
+ * content-type by extension when none is given (binary or stream data only)
109
140
  * @returns {ResolvedPayload}
110
141
  */
111
142
  export declare function resolvePayload({ data, contentType, id }: {
@@ -117,6 +148,10 @@ export declare function resolvePayload({ data, contentType, id }: {
117
148
  * Inspects write data and resolves it to a JSON or binary payload, using
118
149
  * {@link resolvePayload} for the detection and content-type precedence rules.
119
150
  *
151
+ * A `ReadableStream` is refused with `ValidationError`. A plaintext resource
152
+ * has no chunked representation, and every signed request carries a `Digest`
153
+ * of its whole body, so a stream cannot be sent as one plaintext resource.
154
+ *
120
155
  * @param data {ResourceData} the resource content
121
156
  * @param options {object}
122
157
  * @param [options.contentType] {string} overrides the inferred content-type
@@ -221,5 +256,25 @@ export declare function parseResource(response: HttpResponse | null): Promise<Js
221
256
  * @returns {Promise<string>}
222
257
  */
223
258
  export declare function decodedText(value: Json | Blob): Promise<string>;
259
+ /**
260
+ * Presents a decoded resource value (the `Json | Blob` a codec's `decode`
261
+ * produces) as a byte stream -- the in-memory fallback of a streaming read,
262
+ * for a value that is already buffered. A `Blob` streams its bytes; a parsed
263
+ * JSON value is re-serialized to UTF-8, matching {@link decodedText}
264
+ * (semantically identical JSON, not guaranteed byte-identical).
265
+ *
266
+ * The reported content type is the caller's `contentType` when it knows the
267
+ * resource type (an encrypting codec's sealed plaintext type), else a
268
+ * non-empty `Blob.type` for a blob, or `application/json` for a JSON value.
269
+ *
270
+ * @param options {object}
271
+ * @param options.value {Json | Blob} the decoded value
272
+ * @param [options.contentType] {string} the plaintext resource type
273
+ * @returns {DecodedStream}
274
+ */
275
+ export declare function decodedStream({ value, contentType }: {
276
+ value: Json | Blob;
277
+ contentType?: string;
278
+ }): DecodedStream;
224
279
  export {};
225
280
  //# sourceMappingURL=content.d.ts.map
@@ -1 +1 @@
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,YAAY,EAAE,MAAM,aAAa,CAAA;AAG/C,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAIrD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,eAAe,CAAA;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,OAAO,aAAoB,CAAA;AAExC;;;;;GAKG;AACH,eAAO,MAAM,OAAO,aAAoB,CAAA;AAExC;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAO9D;AA6BD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,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AM,CAAA;CAAE,CA2CnE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,GAAG;IAC9D,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAyCA;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,GAAG,MAAM,CAE/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,CAIrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAM1D;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,YAAY,GAAG,IAAI,GAC5B,OAAO,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAS7B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAErE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,WAAW,EACZ,EAAE;IACD,KAAK,EAAE,IAAI,GAAG,IAAI,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,aAAa,CAYhB"}
@@ -1,5 +1,5 @@
1
1
  import { isJsonContentType } from '@interop/storage-core';
2
- import { blobText } from './blob.js';
2
+ import { blobText, bytesToStream } from './blob.js';
3
3
  import { ValidationError, WasServerError } from '../errors.js';
4
4
  const OCTET_STREAM = 'application/octet-stream';
5
5
  /**
@@ -24,6 +24,16 @@ export const ENCODER = new TextEncoder();
24
24
  * path, protected-header bytes on the read path.
25
25
  */
26
26
  export const DECODER = new TextDecoder();
27
+ /**
28
+ * The bare media type of a `Content-Type` value: `text/plain; charset=utf-8`
29
+ * is `text/plain`. Case is kept as given.
30
+ *
31
+ * @param contentType {string}
32
+ * @returns {string}
33
+ */
34
+ export function mediaType(contentType) {
35
+ return (contentType.split(';')[0] ?? '').trim();
36
+ }
27
37
  /**
28
38
  * Whether a content type denotes UTF-8-safe text that should be stored inline as
29
39
  * a plain string (legible, no ~33% base64 inflation) rather than as opaque
@@ -38,7 +48,7 @@ export const DECODER = new TextDecoder();
38
48
  * @returns {boolean}
39
49
  */
40
50
  export function isTextContentType(contentType) {
41
- const type = (contentType.split(';')[0] ?? '').trim().toLowerCase();
51
+ const type = mediaType(contentType).toLowerCase();
42
52
  return (type.startsWith('text/') ||
43
53
  type === 'application/xml' ||
44
54
  type.endsWith('+xml'));
@@ -97,6 +107,21 @@ export function guessContentTypeFromId(id) {
97
107
  export function isBlob(value) {
98
108
  return typeof Blob !== 'undefined' && value instanceof Blob;
99
109
  }
110
+ /**
111
+ * Whether a value is a `ReadableStream`. Duck-typed on `getReader` rather
112
+ * than `instanceof`, so a stream from another realm or a polyfill counts (and
113
+ * so it works where the `ReadableStream` global is undefined): no JSON value
114
+ * has a `getReader` method, and classifying such a stream as JSON would
115
+ * silently store `{}`.
116
+ *
117
+ * @param value {unknown}
118
+ * @returns {boolean}
119
+ */
120
+ export function isReadableStream(value) {
121
+ return (value !== null &&
122
+ typeof value === 'object' &&
123
+ typeof value.getReader === 'function');
124
+ }
100
125
  /**
101
126
  * Coerces a `Uint8Array` (including a Node `Buffer`, which is a subclass) to a
102
127
  * plain `Uint8Array` view, as ezcap's `body` type expects.
@@ -111,28 +136,33 @@ export function toPlainBytes(bytes) {
111
136
  return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
112
137
  }
113
138
  /**
114
- * Classifies write data as binary or JSON and resolves the binary
115
- * content-type -- the single source of the detection and precedence rules
116
- * shared by the plaintext `prepareBody` and the EDV codec's document builder.
139
+ * Classifies write data as binary, a stream, or JSON and resolves the binary
140
+ * or stream content-type -- the single source of the detection and precedence
141
+ * rules shared by the plaintext `prepareBody` and the EDV codec's document
142
+ * builder.
117
143
  *
118
144
  * The binary content-type resolves in precedence order: an explicit
119
145
  * `contentType`, then a non-empty `Blob.type`, then a guess from the resource
120
146
  * `id`'s extension, then `application/octet-stream`. (Coalescing with `||`
121
147
  * rather than `??` so an empty-string `Blob.type` -- a typeless Blob -- falls
122
- * through to the guess instead of becoming an empty content-type.)
148
+ * through to the guess instead of becoming an empty content-type.) A stream
149
+ * resolves the same way as a `Uint8Array`, since it has no `Blob.type`: an
150
+ * explicit `contentType`, then the extension guess, then
151
+ * `application/octet-stream`. A stream is tested before the JSON branch, so it
152
+ * is never mistaken for a plain object.
123
153
  *
124
154
  * @param options {object}
125
155
  * @param options.data {ResourceData} the resource content
126
156
  * @param [options.contentType] {string} overrides the inferred content-type
127
- * for binary data
157
+ * for binary or stream data
128
158
  * @param [options.id] {string} resource id used to guess a
129
- * content-type by extension when none is given (binary data only)
159
+ * content-type by extension when none is given (binary or stream data only)
130
160
  * @returns {ResolvedPayload}
131
161
  */
132
162
  export function resolvePayload({ data, contentType, id }) {
133
- // Guess lazily: the extension guess is only ever consulted on a binary
134
- // branch (and only when neither an explicit `contentType` nor a non-empty
135
- // `Blob.type` won), so a JSON write never pays for it.
163
+ // Guess lazily: the extension guess is only ever consulted on a binary or
164
+ // stream branch (and only when neither an explicit `contentType` nor a
165
+ // non-empty `Blob.type` won), so a JSON write never pays for it.
136
166
  const guess = () => id ? guessContentTypeFromId(id) : undefined;
137
167
  if (isBlob(data)) {
138
168
  return {
@@ -148,6 +178,13 @@ export function resolvePayload({ data, contentType, id }) {
148
178
  contentType: contentType || guess() || OCTET_STREAM
149
179
  };
150
180
  }
181
+ if (isReadableStream(data)) {
182
+ return {
183
+ kind: 'stream',
184
+ data,
185
+ contentType: contentType || guess() || OCTET_STREAM
186
+ };
187
+ }
151
188
  if (data !== null && typeof data === 'object') {
152
189
  return { kind: 'json' };
153
190
  }
@@ -157,6 +194,10 @@ export function resolvePayload({ data, contentType, id }) {
157
194
  * Inspects write data and resolves it to a JSON or binary payload, using
158
195
  * {@link resolvePayload} for the detection and content-type precedence rules.
159
196
  *
197
+ * A `ReadableStream` is refused with `ValidationError`. A plaintext resource
198
+ * has no chunked representation, and every signed request carries a `Digest`
199
+ * of its whole body, so a stream cannot be sent as one plaintext resource.
200
+ *
160
201
  * @param data {ResourceData} the resource content
161
202
  * @param options {object}
162
203
  * @param [options.contentType] {string} overrides the inferred content-type
@@ -193,6 +234,13 @@ export function prepareBody(data, options = {}) {
193
234
  }
194
235
  return { json: data };
195
236
  }
237
+ if (payload.kind === 'stream') {
238
+ throw new ValidationError('Cannot write a ReadableStream to a plaintext collection: a plaintext ' +
239
+ 'resource has no chunked representation, and every signed request ' +
240
+ 'carries a Digest of its whole body, so a stream cannot be sent as ' +
241
+ 'one resource. Write it to an encrypted collection (which stores it ' +
242
+ 'as a document plus chunk resources), or buffer it into a Blob first.');
243
+ }
196
244
  throw new ValidationError('Resource data must be a plain object/array (JSON) or a ' +
197
245
  'Blob/Uint8Array (binary).');
198
246
  }
@@ -338,4 +386,33 @@ export async function parseResource(response) {
338
386
  export async function decodedText(value) {
339
387
  return isBlob(value) ? blobText(value) : JSON.stringify(value);
340
388
  }
389
+ /**
390
+ * Presents a decoded resource value (the `Json | Blob` a codec's `decode`
391
+ * produces) as a byte stream -- the in-memory fallback of a streaming read,
392
+ * for a value that is already buffered. A `Blob` streams its bytes; a parsed
393
+ * JSON value is re-serialized to UTF-8, matching {@link decodedText}
394
+ * (semantically identical JSON, not guaranteed byte-identical).
395
+ *
396
+ * The reported content type is the caller's `contentType` when it knows the
397
+ * resource type (an encrypting codec's sealed plaintext type), else a
398
+ * non-empty `Blob.type` for a blob, or `application/json` for a JSON value.
399
+ *
400
+ * @param options {object}
401
+ * @param options.value {Json | Blob} the decoded value
402
+ * @param [options.contentType] {string} the plaintext resource type
403
+ * @returns {DecodedStream}
404
+ */
405
+ export function decodedStream({ value, contentType }) {
406
+ if (isBlob(value)) {
407
+ const type = contentType || value.type || undefined;
408
+ return {
409
+ stream: bytesToStream(value),
410
+ ...(type !== undefined && { contentType: type })
411
+ };
412
+ }
413
+ return {
414
+ stream: bytesToStream(ENCODER.encode(JSON.stringify(value))),
415
+ contentType: contentType || 'application/json'
416
+ };
417
+ }
341
418
  //# sourceMappingURL=content.js.map