@tearleads/client-sdk 0.1.41 → 0.1.43

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 (235) hide show
  1. package/client/Tearleads.js +3 -0
  2. package/client/Tearleads.js.map +1 -1
  3. package/data/blobs/transferPool.js +35 -8
  4. package/data/blobs/transferPool.js.map +1 -1
  5. package/data/containers/shared/projection.js +12 -0
  6. package/data/containers/shared/projection.js.map +1 -1
  7. package/data/documents/blob/shared/types.d.ts +2 -3
  8. package/data/documents/blob/shared/types.js.map +1 -1
  9. package/data/documents/shared/events.js +0 -1
  10. package/data/documents/shared/events.js.map +1 -1
  11. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js +2 -0
  12. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js.map +1 -1
  13. package/data/keyingProjectionVerification/checkpointContext.d.ts +12 -0
  14. package/data/keyingProjectionVerification/checkpointContext.js +16 -0
  15. package/data/keyingProjectionVerification/checkpointContext.js.map +1 -1
  16. package/data/keyingProjectionVerification/containerDestinationVerification.js +3 -1
  17. package/data/keyingProjectionVerification/containerDestinationVerification.js.map +1 -1
  18. package/data/keyingProjectionVerification/containerProjectionVerification.js +12 -6
  19. package/data/keyingProjectionVerification/containerProjectionVerification.js.map +1 -1
  20. package/data/keyingProjectionVerification/documentProjectionVerification.js +10 -4
  21. package/data/keyingProjectionVerification/documentProjectionVerification.js.map +1 -1
  22. package/data/persistence/container-contents/containerContentsPersistence.js +6 -22
  23. package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
  24. package/data/persistence/container-contents/containerMetadataMutationPersistence.js +5 -15
  25. package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
  26. package/data/persistence/container-contents/containerPendingUpdatePersistence.js +6 -15
  27. package/data/persistence/container-contents/containerPendingUpdatePersistence.js.map +1 -1
  28. package/data/persistence/container-contents/containerRecoveryPersistence.js +3 -4
  29. package/data/persistence/container-contents/containerRecoveryPersistence.js.map +1 -1
  30. package/data/persistence/container-contents/containerRemovalWork.js +3 -5
  31. package/data/persistence/container-contents/containerRemovalWork.js.map +1 -1
  32. package/data/persistence/container-contents/dormantContainerMetadata.js +1 -5
  33. package/data/persistence/container-contents/dormantContainerMetadata.js.map +1 -1
  34. package/data/persistence/documents/documentsPersistence.js +4 -9
  35. package/data/persistence/documents/documentsPersistence.js.map +1 -1
  36. package/data/persistence/documents/internal/discardDocument.js +1 -2
  37. package/data/persistence/documents/internal/discardDocument.js.map +1 -1
  38. package/data/persistence/documents/internal/documentDeletionPersistence.js +1 -2
  39. package/data/persistence/documents/internal/documentDeletionPersistence.js.map +1 -1
  40. package/data/persistence/documents/internal/documentMutationPersistence.js +17 -25
  41. package/data/persistence/documents/internal/documentMutationPersistence.js.map +1 -1
  42. package/data/persistence/documents/internal/orphanSideRows.js +2 -14
  43. package/data/persistence/documents/internal/orphanSideRows.js.map +1 -1
  44. package/data/persistence/documents/internal/syncQueuePersistence.js +3 -3
  45. package/data/persistence/documents/internal/syncQueuePersistence.js.map +1 -1
  46. package/data/persistence/keyingCheckpointAdvancePersistence.js +27 -8
  47. package/data/persistence/keyingCheckpointAdvancePersistence.js.map +1 -1
  48. package/data/persistence/verifiedManifestBundlePersistence.d.ts +45 -0
  49. package/data/persistence/verifiedManifestBundlePersistence.js +282 -0
  50. package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -0
  51. package/data/sqlite/documentHistoryPersistence.d.ts +9 -3
  52. package/data/sqlite/documentHistoryPersistence.js +31 -8
  53. package/data/sqlite/documentHistoryPersistence.js.map +1 -1
  54. package/data/sqlite/documentPendingUpdatePersistence.d.ts +58 -11
  55. package/data/sqlite/documentPendingUpdatePersistence.js +137 -63
  56. package/data/sqlite/documentPendingUpdatePersistence.js.map +1 -1
  57. package/data/sqlite/documentPersistence.d.ts +1 -1
  58. package/data/sqlite/documentPersistence.js +1 -1
  59. package/data/sqlite/documentPersistence.js.map +1 -1
  60. package/data/sqlite/documentPersistenceTypes.d.ts +2 -2
  61. package/data/sqlite/documentPersistenceTypes.js.map +1 -1
  62. package/data/sqlite/documentRecordPersistence.js +5 -4
  63. package/data/sqlite/documentRecordPersistence.js.map +1 -1
  64. package/data/sqlite/schema.d.ts +350 -443
  65. package/data/sqlite/schema.js +49 -47
  66. package/data/sqlite/schema.js.map +1 -1
  67. package/data/sqlite/verifiedManifestBundleSchema.d.ts +174 -0
  68. package/data/sqlite/verifiedManifestBundleSchema.js +36 -0
  69. package/data/sqlite/verifiedManifestBundleSchema.js.map +1 -0
  70. package/internal/api-client/ApiClient.d.ts +17 -19
  71. package/internal/api-client/ApiClient.js +10 -11
  72. package/internal/api-client/ApiClient.js.map +1 -1
  73. package/internal/api-client/binaryRequestOperationTransport.d.ts +18 -0
  74. package/internal/api-client/index.d.ts +2 -1
  75. package/internal/api-client/index.js +1 -1
  76. package/internal/api-client/index.js.map +1 -1
  77. package/internal/api-client/operationTransportFactory.d.ts +6 -0
  78. package/internal/api-client/principalHistoryRequest.js +8 -2
  79. package/internal/api-client/principalHistoryRequest.js.map +1 -1
  80. package/internal/api-client/principalHistoryRequestContext.js +15 -5
  81. package/internal/api-client/principalHistoryRequestContext.js.map +1 -1
  82. package/internal/api-client/routes/blobs/get.d.ts +7 -0
  83. package/internal/api-client/routes/blobs/get.js.map +1 -1
  84. package/internal/api-client/routes/blobs/multipart.js +1 -11
  85. package/internal/api-client/routes/blobs/multipart.js.map +1 -1
  86. package/internal/api-client/routes/blobs/multipartUpload.d.ts +14 -0
  87. package/internal/api-client/routes/blobs/multipartUpload.js +94 -43
  88. package/internal/api-client/routes/blobs/multipartUpload.js.map +1 -1
  89. package/internal/api-client/routes/writerProjections.js +6 -3
  90. package/internal/api-client/routes/writerProjections.js.map +1 -1
  91. package/internal/api-client/verifiedManifestCitations.d.ts +23 -0
  92. package/internal/api-client/verifiedManifestCitations.js +60 -0
  93. package/internal/api-client/verifiedManifestCitations.js.map +1 -0
  94. package/internal/api-client/writerProjectionRequests.js +75 -14
  95. package/internal/api-client/writerProjectionRequests.js.map +1 -1
  96. package/internal/crypto/index.d.ts +0 -1
  97. package/internal/crypto/index.js +0 -1
  98. package/internal/crypto/index.js.map +1 -1
  99. package/internal/validators/knownManifestsRefinements.js +5 -0
  100. package/internal/validators/knownManifestsRefinements.js.map +1 -0
  101. package/internal/validators/operation/attachments.d.ts +80 -160
  102. package/internal/validators/operation/auth.d.ts +760 -1664
  103. package/internal/validators/operation/blobDownloads.js +1 -1
  104. package/internal/validators/operation/blobDownloads.js.map +1 -1
  105. package/internal/validators/operation/containerMutations.d.ts +416 -856
  106. package/internal/validators/operation/documentMutations.d.ts +120 -264
  107. package/internal/validators/operation/documentSync.d.ts +40 -80
  108. package/internal/validators/operation/index.d.ts +1 -1
  109. package/internal/validators/operation/index.js +1 -1
  110. package/internal/validators/operation/index.js.map +1 -1
  111. package/internal/validators/operation/multipartBlobs.d.ts +70 -190
  112. package/internal/validators/operation/multipartBlobs.js +2 -24
  113. package/internal/validators/operation/multipartBlobs.js.map +1 -1
  114. package/internal/validators/operation/multipartPartUploads.d.ts +5 -5
  115. package/internal/validators/operation/multipartPartUploads.js +6 -20
  116. package/internal/validators/operation/multipartPartUploads.js.map +1 -1
  117. package/internal/validators/operation/organizations.d.ts +882 -1906
  118. package/internal/validators/operation/principals.d.ts +120 -240
  119. package/internal/validators/operation/registry.d.ts +1 -2
  120. package/internal/validators/operation/registry.js +1 -2
  121. package/internal/validators/operation/registry.js.map +1 -1
  122. package/internal/validators/operation/writerProjections.d.ts +85 -319
  123. package/internal/validators/operation/writerProjections.js +11 -11
  124. package/internal/validators/operation/writerProjections.js.map +1 -1
  125. package/internal/validators/request/blob.d.ts +100 -201
  126. package/internal/validators/request/blob.js +6 -13
  127. package/internal/validators/request/blob.js.map +1 -1
  128. package/internal/validators/request/container.d.ts +136 -272
  129. package/internal/validators/request/container.js +16 -10
  130. package/internal/validators/request/container.js.map +1 -1
  131. package/internal/validators/request/containerManifestRef.d.ts +54 -0
  132. package/internal/validators/request/containerManifestRef.js +28 -0
  133. package/internal/validators/request/containerManifestRef.js.map +1 -0
  134. package/internal/validators/request/containerMetadata.d.ts +160 -368
  135. package/internal/validators/request/document.d.ts +100 -245
  136. package/internal/validators/request/document.js +1 -2
  137. package/internal/validators/request/document.js.map +1 -1
  138. package/internal/validators/request/documentSyncSchema.d.ts +42 -109
  139. package/internal/validators/request/documentSyncSchema.js +8 -25
  140. package/internal/validators/request/documentSyncSchema.js.map +1 -1
  141. package/internal/validators/request/index.d.ts +1 -1
  142. package/internal/validators/request/index.js +1 -1
  143. package/internal/validators/request/index.js.map +1 -1
  144. package/internal/validators/request/organization.d.ts +160 -320
  145. package/internal/validators/request/organizationProvisioning.d.ts +2424 -5312
  146. package/internal/validators/request/principal.d.ts +160 -320
  147. package/internal/validators/request/registration.d.ts +760 -1664
  148. package/internal/validators/response/blob.d.ts +48 -27
  149. package/internal/validators/response/blob.js +3 -10
  150. package/internal/validators/response/blob.js.map +1 -1
  151. package/internal/validators/response/container.d.ts +429 -20
  152. package/internal/validators/response/container.js +40 -5
  153. package/internal/validators/response/container.js.map +1 -1
  154. package/internal/validators/response/documentMutation.d.ts +440 -20
  155. package/internal/validators/response/documentMutation.js +33 -3
  156. package/internal/validators/response/documentMutation.js.map +1 -1
  157. package/internal/validators/response/index.d.ts +4 -3
  158. package/internal/validators/response/index.js +4 -3
  159. package/internal/validators/response/index.js.map +1 -1
  160. package/internal/validators/response/manifestBundleReferences.js +79 -0
  161. package/internal/validators/response/manifestBundleReferences.js.map +1 -0
  162. package/internal/validators/response/writerProjectionWire.d.ts +19 -0
  163. package/internal/validators/response/writerProjectionWire.js +132 -0
  164. package/internal/validators/response/writerProjectionWire.js.map +1 -0
  165. package/internal/validators/schema.js +20 -0
  166. package/internal/validators/schema.js.map +1 -1
  167. package/internal/validators/util/blob.d.ts +7 -0
  168. package/internal/validators/util/blob.js +7 -0
  169. package/internal/validators/util/blob.js.map +1 -1
  170. package/internal/validators/util/blobTransferSchemas.d.ts +41 -0
  171. package/internal/validators/util/blobTransferSchemas.js +39 -0
  172. package/internal/validators/util/blobTransferSchemas.js.map +1 -0
  173. package/internal/validators/util/containerLimits.d.ts +7 -0
  174. package/internal/validators/util/containerLimits.js +7 -0
  175. package/internal/validators/util/containerLimits.js.map +1 -1
  176. package/internal/validators/util/index.d.ts +3 -2
  177. package/internal/validators/util/index.js +3 -2
  178. package/internal/validators/util/index.js.map +1 -1
  179. package/internal/validators/util/knownManifestWire.d.ts +11 -0
  180. package/internal/validators/util/knownManifestWire.js +28 -0
  181. package/internal/validators/util/knownManifestWire.js.map +1 -0
  182. package/internal/validators/writerProjectionRefinements.js +5 -0
  183. package/internal/validators/writerProjectionRefinements.js.map +1 -1
  184. package/package.json +1 -1
  185. package/workflows/blobs/multipartFirstParts.js +82 -0
  186. package/workflows/blobs/multipartFirstParts.js.map +1 -0
  187. package/workflows/blobs/multipartStageResolution.js +83 -0
  188. package/workflows/blobs/multipartStageResolution.js.map +1 -0
  189. package/workflows/blobs/multipartUpload.js +45 -89
  190. package/workflows/blobs/multipartUpload.js.map +1 -1
  191. package/workflows/container-contents/documentPriming.js +2 -1
  192. package/workflows/container-contents/documentPriming.js.map +1 -1
  193. package/workflows/container-contents/documentQueries/sql.js +4 -4
  194. package/workflows/container-contents/documentQueries/sql.js.map +1 -1
  195. package/workflows/container-contents/pendingWrites/deferredTails.js +6 -3
  196. package/workflows/container-contents/pendingWrites/deferredTails.js.map +1 -1
  197. package/workflows/container-contents/pendingWrites/sources.js +2 -1
  198. package/workflows/container-contents/pendingWrites/sources.js.map +1 -1
  199. package/workflows/container-contents/pendingWrites.js +2 -1
  200. package/workflows/container-contents/pendingWrites.js.map +1 -1
  201. package/workflows/containers/child/create.js +3 -3
  202. package/workflows/containers/child/create.js.map +1 -1
  203. package/workflows/containers/child/move.js +2 -2
  204. package/workflows/containers/child/move.js.map +1 -1
  205. package/workflows/containers/child/mutationRequestCore.js +5 -4
  206. package/workflows/containers/child/mutationRequestCore.js.map +1 -1
  207. package/workflows/containers/child/recitePlan.js +3 -2
  208. package/workflows/containers/child/recitePlan.js.map +1 -1
  209. package/workflows/containers/child/sharePlanCore.js +2 -2
  210. package/workflows/containers/child/sharePlanCore.js.map +1 -1
  211. package/workflows/containers/root/create.js +2 -2
  212. package/workflows/containers/root/create.js.map +1 -1
  213. package/workflows/registration/provisioningBootstrapBuilders.d.ts +20 -51
  214. package/workflows/sync/remoteReset.js +11 -9
  215. package/workflows/sync/remoteReset.js.map +1 -1
  216. package/workflows/sync/remoteResetPlans.js +6 -3
  217. package/workflows/sync/remoteResetPlans.js.map +1 -1
  218. package/internal/api-client/projectionHistoryTransport.js +0 -107
  219. package/internal/api-client/projectionHistoryTransport.js.map +0 -1
  220. package/internal/api-client/verifiedProjectionHistory.d.ts +0 -4
  221. package/internal/api-client/verifiedProjectionHistory.js +0 -12
  222. package/internal/api-client/verifiedProjectionHistory.js.map +0 -1
  223. package/internal/crypto/projectionHistory.d.ts +0 -14
  224. package/internal/crypto/projectionHistory.js +0 -90
  225. package/internal/crypto/projectionHistory.js.map +0 -1
  226. package/internal/crypto/projectionHistorySlots.d.ts +0 -13
  227. package/internal/crypto/projectionHistorySlots.js +0 -81
  228. package/internal/crypto/projectionHistorySlots.js.map +0 -1
  229. package/internal/validators/operation/blobTransferSchemas.js +0 -11
  230. package/internal/validators/operation/blobTransferSchemas.js.map +0 -1
  231. package/internal/validators/projectionHistoryRefinements.js +0 -5
  232. package/internal/validators/projectionHistoryRefinements.js.map +0 -1
  233. package/internal/validators/util/projectionHistoryWire.d.ts +0 -23
  234. package/internal/validators/util/projectionHistoryWire.js +0 -33
  235. package/internal/validators/util/projectionHistoryWire.js.map +0 -1
@@ -131,6 +131,26 @@ maxItems) {
131
131
  type: "array",
132
132
  });
133
133
  }
134
+ /**
135
+ * Validates a plain-object map's values without rebuilding it, like
136
+ * arraySchema. Callers read entries with Object.entries or Object.hasOwn so a
137
+ * wire key such as "__proto__" is only ever an own data property.
138
+ */
139
+ export function plainRecordSchema(valueSchema) {
140
+ const viewSchema = z.record(z.string(), valueSchema);
141
+ const runtimeSchema = registerJsonSchemaView(z.custom(isPlainObject), viewSchema).superRefine((value, context) => {
142
+ for (const [key, entry] of Object.entries(value)) {
143
+ const result = valueSchema.safeParse(entry);
144
+ if (result.success) {
145
+ continue;
146
+ }
147
+ for (const issue of result.error.issues) {
148
+ context.addIssue({ ...issue, path: [key, ...issue.path] });
149
+ }
150
+ }
151
+ });
152
+ return registerJsonSchemaView(runtimeSchema, viewSchema);
153
+ }
134
154
  export function nonEmptyArraySchema(itemSchema) {
135
155
  return registerJsonSchemaView(arraySchema(itemSchema).refine((values) => values.length > 0), z.array(itemSchema).min(1));
136
156
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,qBAAqB,GAAG,aAAa,CAAC;AAC5C,MAAM,YAAY,GAChB,4FAA4F,CAAC;AAE/F,MAAM,CAAC,MAAM,qBAAqB,GAAG,0BAA0B,CAC7D,CAAC,CAAC,MAAM,CAAS,iBAAiB,CAAC,EACnC;IACE,SAAS,EAAE,iBAAiB;IAC5B,SAAS,EAAE,iBAAiB;IAC5B,OAAO,EAAE,qBAAqB;IAC9B,IAAI,EAAE,QAAQ;CACf,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,0BAA0B,CACpE,CAAC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,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { isPlainObject } from \"./isPlainObject\";\nimport {\n registerJsonSchemaFragment,\n registerJsonSchemaView,\n toJsonSchema,\n} from \"./jsonSchema\";\nimport {\n AUTH_CHALLENGE_HEX_LENGTH,\n isAuthChallengeHexString,\n isByteArrayOfLength,\n isSha256HexString,\n SHA256_HEX_LENGTH,\n} from \"./util/protocol\";\nimport { isUuidV4String, UUID_V4_PATTERN } from \"./util/uuid\";\n\nconst LOWERCASE_HEX_PATTERN = \"^[0-9a-f]+$\";\nconst UUID_PATTERN =\n \"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$\";\n\nexport const sha256HexStringSchema = registerJsonSchemaFragment(\n z.custom<string>(isSha256HexString),\n {\n maxLength: SHA256_HEX_LENGTH,\n minLength: SHA256_HEX_LENGTH,\n pattern: LOWERCASE_HEX_PATTERN,\n type: \"string\",\n },\n);\n\nexport const authChallengeHexStringSchema = registerJsonSchemaFragment(\n z.custom<string>(isAuthChallengeHexString),\n {\n maxLength: AUTH_CHALLENGE_HEX_LENGTH,\n minLength: AUTH_CHALLENGE_HEX_LENGTH,\n pattern: LOWERCASE_HEX_PATTERN,\n type: \"string\",\n },\n);\n\nexport const uuidV4StringSchema = registerJsonSchemaFragment(\n z.custom<string>(\n (value) => typeof value === \"string\" && isUuidV4String(value),\n ),\n {\n pattern: UUID_V4_PATTERN.source,\n type: \"string\",\n },\n);\n\n/** Accepts RFC 4122 UUID versions 1-5, matching the API route UUID contract. */\nexport const uuidStringSchema = registerJsonSchemaFragment(\n z.string().regex(new RegExp(UUID_PATTERN, \"u\")),\n {\n pattern: UUID_PATTERN,\n type: \"string\",\n },\n);\n\nexport function fixedLengthByteArraySchema(length: number) {\n return registerJsonSchemaFragment(\n z.custom<number[]>((value) => isByteArrayOfLength(value, length)),\n {\n items: {\n maximum: 255,\n minimum: 0,\n type: \"integer\",\n },\n maxItems: length,\n minItems: length,\n type: \"array\",\n },\n );\n}\n\nexport const plainObjectSchema = registerJsonSchemaView(\n z.custom<Record<string, unknown>>(isPlainObject),\n z.looseObject({}),\n);\n\nexport const positiveIntegerSchema = registerJsonSchemaFragment(\n z.number().positive().refine(Number.isInteger),\n {\n exclusiveMinimum: 0,\n maximum: Number.MAX_VALUE,\n type: \"integer\",\n },\n);\n\nexport const nonNegativeIntegerSchema = registerJsonSchemaFragment(\n z.custom<number>(\n (value) =>\n typeof value === \"number\" && Number.isInteger(value) && value >= 0,\n ),\n {\n maximum: Number.MAX_VALUE,\n minimum: 0,\n type: \"integer\",\n },\n);\n\nexport const safeNonNegativeIntegerSchema = registerJsonSchemaFragment(\n z.custom<number>(\n (value) =>\n typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0,\n ),\n {\n maximum: Number.MAX_SAFE_INTEGER,\n minimum: 0,\n type: \"integer\",\n },\n);\n\nexport const safeIntegerSchema = registerJsonSchemaFragment(\n z.custom<number>(\n (value) => typeof value === \"number\" && Number.isSafeInteger(value),\n ),\n {\n maximum: Number.MAX_SAFE_INTEGER,\n minimum: Number.MIN_SAFE_INTEGER,\n type: \"integer\",\n },\n);\n\nexport function boundedPositiveIntegerSchema(maximum: number) {\n return registerJsonSchemaFragment(\n z.custom<number>(\n (value) =>\n typeof value === \"number\" &&\n Number.isInteger(value) &&\n value > 0 &&\n value <= maximum,\n ),\n {\n maximum,\n minimum: 1,\n type: \"integer\",\n },\n );\n}\n\nexport const requiredUnknownSchema = registerJsonSchemaView(\n z.custom<unknown>((value) => value !== undefined),\n z.unknown(),\n);\n\nexport const nonEmptyStringSchema = z.string().min(1);\n\nexport function boundedStringSchema(maxLength: number) {\n return registerJsonSchemaFragment(\n z.custom<string>(\n (value) => typeof value === \"string\" && value.length <= maxLength,\n ),\n {\n maxLength,\n type: \"string\",\n },\n );\n}\n\nexport function boundedNonEmptyStringSchema(maxLength: number) {\n return registerJsonSchemaFragment(\n z.custom<string>(\n (value) =>\n typeof value === \"string\" &&\n value.length > 0 &&\n value.length <= maxLength,\n ),\n {\n maxLength,\n minLength: 1,\n type: \"string\",\n },\n );\n}\n\n/**\n * Validates array items without rebuilding the array. This preserves signed\n * input identity and the runtime contract's treatment of sparse array holes.\n */\nexport function arraySchema<ItemSchema extends z.ZodType>(\n itemSchema: ItemSchema,\n /** Optional item ceiling, reflected in the generated JSON Schema. */\n maxItems?: number,\n) {\n const viewSchema = z.array(itemSchema);\n const runtimeSchema = registerJsonSchemaView(\n z.custom<z.output<ItemSchema>[]>(Array.isArray),\n viewSchema,\n ).superRefine((values, context) => {\n if (maxItems !== undefined && values.length > maxItems) {\n context.addIssue({\n code: \"custom\",\n continue: false,\n message: `array exceeds ${maxItems} items`,\n });\n // The cardinality error already makes the value invalid. Stop here so a\n // small request body containing a very large array cannot force us to\n // parse every item and allocate an issue for each one.\n return;\n }\n values.forEach((value, index) => {\n const result = itemSchema.safeParse(value);\n if (result.success) {\n return;\n }\n\n for (const issue of result.error.issues) {\n context.addIssue({ ...issue, path: [index, ...issue.path] });\n }\n });\n });\n\n if (maxItems === undefined) {\n return registerJsonSchemaView(runtimeSchema, viewSchema);\n }\n // The projector rejects checks on a registered view, so the advertised\n // ceiling is attached as an explicit fragment instead — the generated\n // OpenAPI carries maxItems, and the runtime refinement above enforces it.\n return registerJsonSchemaFragment(runtimeSchema, {\n // Project the item through this package's own projector so the emitted\n // item schema — and the types generated from it — stay identical to the\n // unbounded case; only maxItems is added.\n items: toJsonSchema(itemSchema),\n maxItems,\n type: \"array\",\n });\n}\n\nexport function nonEmptyArraySchema<ItemSchema extends z.ZodType>(\n itemSchema: ItemSchema,\n) {\n return registerJsonSchemaView(\n arraySchema(itemSchema).refine((values) => values.length > 0),\n z.array(itemSchema).min(1),\n );\n}\n\nexport function boundedNonEmptyArraySchema<ItemSchema extends z.ZodType>(\n itemSchema: ItemSchema,\n maxItems: number,\n) {\n return registerJsonSchemaFragment(\n arraySchema(itemSchema, maxItems).refine((values) => values.length > 0),\n {\n items: toJsonSchema(itemSchema),\n maxItems,\n minItems: 1,\n type: \"array\",\n },\n );\n}\n\n/**\n * Validates a shaped plain object without returning Zod's reconstructed\n * loose-object output. Extension keys, prototypes, and signed input identity\n * remain untouched. A separate structural view describes the JSON wire shape\n * for OpenAPI without changing the value returned by runtime validation.\n */\nexport function loosePlainObject<Shape extends z.ZodRawShape>(\n shape: Shape,\n): z.ZodType<z.output<z.ZodObject<Shape>>, z.input<z.ZodObject<Shape>>>;\nexport function loosePlainObject(\n shape: z.ZodRawShape,\n): z.ZodType<Record<string, unknown>> {\n const shapeSchema = z.looseObject(shape);\n\n const runtimeSchema = registerJsonSchemaView(\n z.custom<Record<string, unknown>>((value) => isPlainObject(value)),\n shapeSchema,\n ).superRefine((value, context) => {\n const result = shapeSchema.safeParse(value);\n if (result.success) {\n return;\n }\n\n for (const issue of result.error.issues) {\n context.addIssue({ ...issue });\n }\n });\n\n return registerJsonSchemaView(runtimeSchema, shapeSchema);\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,qBAAqB,GAAG,aAAa,CAAC;AAC5C,MAAM,YAAY,GAChB,4FAA4F,CAAC;AAE/F,MAAM,CAAC,MAAM,qBAAqB,GAAG,0BAA0B,CAC7D,CAAC,CAAC,MAAM,CAAS,iBAAiB,CAAC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C,GAAG,CAAC,CAAC,CAAC,CAC3B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,UAAsB,EACtB,QAAgB;IAEhB,OAAO,0BAA0B,CAC/B,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EACvE;QACE,KAAK,EAAE,YAAY,CAAC,UAAU,CAAC;QAC/B,QAAQ;QACR,QAAQ,EAAE,CAAC;QACX,IAAI,EAAE,OAAO;KACd,CACF,CAAC;AACJ,CAAC;AAWD,MAAM,UAAU,gBAAgB,CAC9B,KAAoB;IAEpB,MAAM,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAEzC,MAAM,aAAa,GAAG,sBAAsB,CAC1C,CAAC,CAAC,MAAM,CAA0B,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAClE,WAAW,CACZ,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACxC,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QACjC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,sBAAsB,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { isPlainObject } from \"./isPlainObject\";\nimport {\n registerJsonSchemaFragment,\n registerJsonSchemaView,\n toJsonSchema,\n} from \"./jsonSchema\";\nimport {\n AUTH_CHALLENGE_HEX_LENGTH,\n isAuthChallengeHexString,\n isByteArrayOfLength,\n isSha256HexString,\n SHA256_HEX_LENGTH,\n} from \"./util/protocol\";\nimport { isUuidV4String, UUID_V4_PATTERN } from \"./util/uuid\";\n\nconst LOWERCASE_HEX_PATTERN = \"^[0-9a-f]+$\";\nconst UUID_PATTERN =\n \"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$\";\n\nexport const sha256HexStringSchema = registerJsonSchemaFragment(\n z.custom<string>(isSha256HexString),\n {\n maxLength: SHA256_HEX_LENGTH,\n minLength: SHA256_HEX_LENGTH,\n pattern: LOWERCASE_HEX_PATTERN,\n type: \"string\",\n },\n);\n\nexport const authChallengeHexStringSchema = registerJsonSchemaFragment(\n z.custom<string>(isAuthChallengeHexString),\n {\n maxLength: AUTH_CHALLENGE_HEX_LENGTH,\n minLength: AUTH_CHALLENGE_HEX_LENGTH,\n pattern: LOWERCASE_HEX_PATTERN,\n type: \"string\",\n },\n);\n\nexport const uuidV4StringSchema = registerJsonSchemaFragment(\n z.custom<string>(\n (value) => typeof value === \"string\" && isUuidV4String(value),\n ),\n {\n pattern: UUID_V4_PATTERN.source,\n type: \"string\",\n },\n);\n\n/** Accepts RFC 4122 UUID versions 1-5, matching the API route UUID contract. */\nexport const uuidStringSchema = registerJsonSchemaFragment(\n z.string().regex(new RegExp(UUID_PATTERN, \"u\")),\n {\n pattern: UUID_PATTERN,\n type: \"string\",\n },\n);\n\nexport function fixedLengthByteArraySchema(length: number) {\n return registerJsonSchemaFragment(\n z.custom<number[]>((value) => isByteArrayOfLength(value, length)),\n {\n items: {\n maximum: 255,\n minimum: 0,\n type: \"integer\",\n },\n maxItems: length,\n minItems: length,\n type: \"array\",\n },\n );\n}\n\nexport const plainObjectSchema = registerJsonSchemaView(\n z.custom<Record<string, unknown>>(isPlainObject),\n z.looseObject({}),\n);\n\nexport const positiveIntegerSchema = registerJsonSchemaFragment(\n z.number().positive().refine(Number.isInteger),\n {\n exclusiveMinimum: 0,\n maximum: Number.MAX_VALUE,\n type: \"integer\",\n },\n);\n\nexport const nonNegativeIntegerSchema = registerJsonSchemaFragment(\n z.custom<number>(\n (value) =>\n typeof value === \"number\" && Number.isInteger(value) && value >= 0,\n ),\n {\n maximum: Number.MAX_VALUE,\n minimum: 0,\n type: \"integer\",\n },\n);\n\nexport const safeNonNegativeIntegerSchema = registerJsonSchemaFragment(\n z.custom<number>(\n (value) =>\n typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0,\n ),\n {\n maximum: Number.MAX_SAFE_INTEGER,\n minimum: 0,\n type: \"integer\",\n },\n);\n\nexport const safeIntegerSchema = registerJsonSchemaFragment(\n z.custom<number>(\n (value) => typeof value === \"number\" && Number.isSafeInteger(value),\n ),\n {\n maximum: Number.MAX_SAFE_INTEGER,\n minimum: Number.MIN_SAFE_INTEGER,\n type: \"integer\",\n },\n);\n\nexport function boundedPositiveIntegerSchema(maximum: number) {\n return registerJsonSchemaFragment(\n z.custom<number>(\n (value) =>\n typeof value === \"number\" &&\n Number.isInteger(value) &&\n value > 0 &&\n value <= maximum,\n ),\n {\n maximum,\n minimum: 1,\n type: \"integer\",\n },\n );\n}\n\nexport const requiredUnknownSchema = registerJsonSchemaView(\n z.custom<unknown>((value) => value !== undefined),\n z.unknown(),\n);\n\nexport const nonEmptyStringSchema = z.string().min(1);\n\nexport function boundedStringSchema(maxLength: number) {\n return registerJsonSchemaFragment(\n z.custom<string>(\n (value) => typeof value === \"string\" && value.length <= maxLength,\n ),\n {\n maxLength,\n type: \"string\",\n },\n );\n}\n\nexport function boundedNonEmptyStringSchema(maxLength: number) {\n return registerJsonSchemaFragment(\n z.custom<string>(\n (value) =>\n typeof value === \"string\" &&\n value.length > 0 &&\n value.length <= maxLength,\n ),\n {\n maxLength,\n minLength: 1,\n type: \"string\",\n },\n );\n}\n\n/**\n * Validates array items without rebuilding the array. This preserves signed\n * input identity and the runtime contract's treatment of sparse array holes.\n */\nexport function arraySchema<ItemSchema extends z.ZodType>(\n itemSchema: ItemSchema,\n /** Optional item ceiling, reflected in the generated JSON Schema. */\n maxItems?: number,\n) {\n const viewSchema = z.array(itemSchema);\n const runtimeSchema = registerJsonSchemaView(\n z.custom<z.output<ItemSchema>[]>(Array.isArray),\n viewSchema,\n ).superRefine((values, context) => {\n if (maxItems !== undefined && values.length > maxItems) {\n context.addIssue({\n code: \"custom\",\n continue: false,\n message: `array exceeds ${maxItems} items`,\n });\n // The cardinality error already makes the value invalid. Stop here so a\n // small request body containing a very large array cannot force us to\n // parse every item and allocate an issue for each one.\n return;\n }\n values.forEach((value, index) => {\n const result = itemSchema.safeParse(value);\n if (result.success) {\n return;\n }\n\n for (const issue of result.error.issues) {\n context.addIssue({ ...issue, path: [index, ...issue.path] });\n }\n });\n });\n\n if (maxItems === undefined) {\n return registerJsonSchemaView(runtimeSchema, viewSchema);\n }\n // The projector rejects checks on a registered view, so the advertised\n // ceiling is attached as an explicit fragment instead — the generated\n // OpenAPI carries maxItems, and the runtime refinement above enforces it.\n return registerJsonSchemaFragment(runtimeSchema, {\n // Project the item through this package's own projector so the emitted\n // item schema — and the types generated from it — stay identical to the\n // unbounded case; only maxItems is added.\n items: toJsonSchema(itemSchema),\n maxItems,\n type: \"array\",\n });\n}\n\n/**\n * Validates a plain-object map's values without rebuilding it, like\n * arraySchema. Callers read entries with Object.entries or Object.hasOwn so a\n * wire key such as \"__proto__\" is only ever an own data property.\n */\nexport function plainRecordSchema<ValueSchema extends z.ZodType>(\n valueSchema: ValueSchema,\n) {\n const viewSchema = z.record(z.string(), valueSchema);\n const runtimeSchema = registerJsonSchemaView(\n z.custom<Record<string, z.output<ValueSchema>>>(isPlainObject),\n viewSchema,\n ).superRefine((value, context) => {\n for (const [key, entry] of Object.entries(value)) {\n const result = valueSchema.safeParse(entry);\n if (result.success) {\n continue;\n }\n for (const issue of result.error.issues) {\n context.addIssue({ ...issue, path: [key, ...issue.path] });\n }\n }\n });\n\n return registerJsonSchemaView(runtimeSchema, viewSchema);\n}\n\nexport function nonEmptyArraySchema<ItemSchema extends z.ZodType>(\n itemSchema: ItemSchema,\n) {\n return registerJsonSchemaView(\n arraySchema(itemSchema).refine((values) => values.length > 0),\n z.array(itemSchema).min(1),\n );\n}\n\nexport function boundedNonEmptyArraySchema<ItemSchema extends z.ZodType>(\n itemSchema: ItemSchema,\n maxItems: number,\n) {\n return registerJsonSchemaFragment(\n arraySchema(itemSchema, maxItems).refine((values) => values.length > 0),\n {\n items: toJsonSchema(itemSchema),\n maxItems,\n minItems: 1,\n type: \"array\",\n },\n );\n}\n\n/**\n * Validates a shaped plain object without returning Zod's reconstructed\n * loose-object output. Extension keys, prototypes, and signed input identity\n * remain untouched. A separate structural view describes the JSON wire shape\n * for OpenAPI without changing the value returned by runtime validation.\n */\nexport function loosePlainObject<Shape extends z.ZodRawShape>(\n shape: Shape,\n): z.ZodType<z.output<z.ZodObject<Shape>>, z.input<z.ZodObject<Shape>>>;\nexport function loosePlainObject(\n shape: z.ZodRawShape,\n): z.ZodType<Record<string, unknown>> {\n const shapeSchema = z.looseObject(shape);\n\n const runtimeSchema = registerJsonSchemaView(\n z.custom<Record<string, unknown>>((value) => isPlainObject(value)),\n shapeSchema,\n ).superRefine((value, context) => {\n const result = shapeSchema.safeParse(value);\n if (result.success) {\n return;\n }\n\n for (const issue of result.error.issues) {\n context.addIssue({ ...issue });\n }\n });\n\n return registerJsonSchemaView(runtimeSchema, shapeSchema);\n}\n"]}
@@ -3,3 +3,10 @@
3
3
  * HTTP bridge buffers for direct uploads, and API buffers for non-signing stores.
4
4
  */
5
5
  export declare const MAX_MULTIPART_BLOB_PART_BYTES: number;
6
+ /**
7
+ * Parts a stage initiation may describe and receive upload sources for in its
8
+ * own response: the SDK's upload concurrency, so every part it starts first
9
+ * needs no separate authorization request. Later parts and retries authorize
10
+ * one at a time, just before they are sent.
11
+ */
12
+ export declare const MAX_INITIATE_PART_UPLOADS = 4;
@@ -3,4 +3,11 @@
3
3
  * HTTP bridge buffers for direct uploads, and API buffers for non-signing stores.
4
4
  */
5
5
  export const MAX_MULTIPART_BLOB_PART_BYTES = 32 * 1024 * 1024;
6
+ /**
7
+ * Parts a stage initiation may describe and receive upload sources for in its
8
+ * own response: the SDK's upload concurrency, so every part it starts first
9
+ * needs no separate authorization request. Later parts and retries authorize
10
+ * one at a time, just before they are sent.
11
+ */
12
+ export const MAX_INITIATE_PART_UPLOADS = 4;
6
13
  //# sourceMappingURL=blob.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"blob.js","sourceRoot":"","sources":["blob.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC","sourcesContent":["/**\n * Protocol ceiling for a multipart blob part. Bounds client hashing and native\n * HTTP bridge buffers for direct uploads, and API buffers for non-signing stores.\n */\nexport const MAX_MULTIPART_BLOB_PART_BYTES = 32 * 1024 * 1024;\n"]}
1
+ {"version":3,"file":"blob.js","sourceRoot":"","sources":["blob.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC","sourcesContent":["/**\n * Protocol ceiling for a multipart blob part. Bounds client hashing and native\n * HTTP bridge buffers for direct uploads, and API buffers for non-signing stores.\n */\nexport const MAX_MULTIPART_BLOB_PART_BYTES = 32 * 1024 * 1024;\n\n/**\n * Parts a stage initiation may describe and receive upload sources for in its\n * own response: the SDK's upload concurrency, so every part it starts first\n * needs no separate authorization request. Later parts and retries authorize\n * one at a time, just before they are sent.\n */\nexport const MAX_INITIATE_PART_UPLOADS = 4;\n"]}
@@ -0,0 +1,41 @@
1
+ import { z } from "zod";
2
+ export declare const signedBlobUrlSchema: z.ZodCustom<string, string>;
3
+ export declare const signedBlobUrlExpirySchema: z.ZodCustom<string, string>;
4
+ export declare const blobPartContentMd5Schema: z.ZodCustom<string, string>;
5
+ /** S3/R2 multipart part numbers run from 1 through 10,000. */
6
+ export declare const MAX_MULTIPART_BLOB_PART_NUMBER = 10000;
7
+ /**
8
+ * One encrypted part as the client will send it: its number, exact length, and
9
+ * the transport Content-MD5 a signed upload URL binds.
10
+ */
11
+ export declare const MultipartBlobPartDescriptorSchema: z.ZodObject<{
12
+ byteLength: z.ZodCustom<number, number>;
13
+ contentMd5: z.ZodCustom<string, string>;
14
+ partNumber: z.ZodCustom<number, number>;
15
+ }, z.core.$strict>;
16
+ export type MultipartBlobPartDescriptor = z.infer<typeof MultipartBlobPartDescriptorSchema>;
17
+ /**
18
+ * Where a part's bytes go: the API byte route for stores that cannot sign, or
19
+ * a short-lived URL that signs exactly one part of one upload.
20
+ */
21
+ export declare const MultipartBlobPartUploadSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
22
+ kind: z.ZodLiteral<"api">;
23
+ }, z.core.$strict>, z.ZodObject<{
24
+ kind: z.ZodLiteral<"signed-url">;
25
+ url: z.ZodCustom<string, string>;
26
+ expiresAt: z.ZodCustom<string, string>;
27
+ }, z.core.$strict>], "kind">;
28
+ export type MultipartBlobPartUploadSource = z.infer<typeof MultipartBlobPartUploadSourceSchema>;
29
+ export declare const MultipartBlobPartUploadSchema: z.ZodObject<{
30
+ byteLength: z.ZodCustom<number, number>;
31
+ contentMd5: z.ZodCustom<string, string>;
32
+ partNumber: z.ZodCustom<number, number>;
33
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
34
+ kind: z.ZodLiteral<"api">;
35
+ }, z.core.$strict>, z.ZodObject<{
36
+ kind: z.ZodLiteral<"signed-url">;
37
+ url: z.ZodCustom<string, string>;
38
+ expiresAt: z.ZodCustom<string, string>;
39
+ }, z.core.$strict>], "kind">;
40
+ }, z.core.$strict>;
41
+ export type MultipartBlobPartUpload = z.infer<typeof MultipartBlobPartUploadSchema>;
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ import { registerJsonSchemaFragment } from "../jsonSchema.js";
3
+ import { boundedPositiveIntegerSchema } from "../schema.js";
4
+ import { MAX_MULTIPART_BLOB_PART_BYTES } from "./blob.js";
5
+ function stringSchemaFragment(schema) {
6
+ const { $schema: _dialect, ...fragment } = z.toJSONSchema(schema);
7
+ return registerJsonSchemaFragment(z.custom((value) => schema.safeParse(value).success), fragment);
8
+ }
9
+ export const signedBlobUrlSchema = stringSchemaFragment(z.url().regex(/^https?:\/\//u));
10
+ export const signedBlobUrlExpirySchema = stringSchemaFragment(z.iso.datetime());
11
+ // R2 transport checksum; assembled SHA-256 remains the application authority.
12
+ export const blobPartContentMd5Schema = stringSchemaFragment(z.string().regex(/^[A-Za-z0-9+/]{21}[AQgw]==$/u));
13
+ /** S3/R2 multipart part numbers run from 1 through 10,000. */
14
+ export const MAX_MULTIPART_BLOB_PART_NUMBER = 10_000;
15
+ /**
16
+ * One encrypted part as the client will send it: its number, exact length, and
17
+ * the transport Content-MD5 a signed upload URL binds.
18
+ */
19
+ export const MultipartBlobPartDescriptorSchema = z.strictObject({
20
+ byteLength: boundedPositiveIntegerSchema(MAX_MULTIPART_BLOB_PART_BYTES),
21
+ contentMd5: blobPartContentMd5Schema,
22
+ partNumber: boundedPositiveIntegerSchema(MAX_MULTIPART_BLOB_PART_NUMBER),
23
+ });
24
+ /**
25
+ * Where a part's bytes go: the API byte route for stores that cannot sign, or
26
+ * a short-lived URL that signs exactly one part of one upload.
27
+ */
28
+ export const MultipartBlobPartUploadSourceSchema = z.discriminatedUnion("kind", [
29
+ z.strictObject({ kind: z.literal("api") }),
30
+ z.strictObject({
31
+ kind: z.literal("signed-url"),
32
+ url: signedBlobUrlSchema,
33
+ expiresAt: signedBlobUrlExpirySchema,
34
+ }),
35
+ ]);
36
+ export const MultipartBlobPartUploadSchema = MultipartBlobPartDescriptorSchema.extend({
37
+ source: MultipartBlobPartUploadSourceSchema,
38
+ });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,UAAU,EAAE,4BAA4B,CAAC,8BAA8B,CAAC;CACzE,CAAC,CAAC;AAMH;;;GAGG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC,kBAAkB,CACrE,MAAM,EACN;IACE,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;IAC1C,CAAC,CAAC,YAAY,CAAC;QACb,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;QAC7B,GAAG,EAAE,mBAAmB;QACxB,SAAS,EAAE,yBAAyB;KACrC,CAAC;CACH,CACF,CAAC;AAMF,MAAM,CAAC,MAAM,6BAA6B,GACxC,iCAAiC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,mCAAmC;CAC5C,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { registerJsonSchemaFragment } from \"../jsonSchema\";\nimport { boundedPositiveIntegerSchema } from \"../schema\";\nimport { MAX_MULTIPART_BLOB_PART_BYTES } from \"./blob\";\n\nfunction stringSchemaFragment(schema: z.ZodType<string>) {\n const { $schema: _dialect, ...fragment } = z.toJSONSchema(schema);\n return registerJsonSchemaFragment(\n z.custom<string>((value) => schema.safeParse(value).success),\n fragment,\n );\n}\n\nexport const signedBlobUrlSchema = stringSchemaFragment(\n z.url().regex(/^https?:\\/\\//u),\n);\nexport const signedBlobUrlExpirySchema = stringSchemaFragment(z.iso.datetime());\n\n// R2 transport checksum; assembled SHA-256 remains the application authority.\nexport const blobPartContentMd5Schema = stringSchemaFragment(\n z.string().regex(/^[A-Za-z0-9+/]{21}[AQgw]==$/u),\n);\n\n/** S3/R2 multipart part numbers run from 1 through 10,000. */\nexport const MAX_MULTIPART_BLOB_PART_NUMBER = 10_000;\n\n/**\n * One encrypted part as the client will send it: its number, exact length, and\n * the transport Content-MD5 a signed upload URL binds.\n */\nexport const MultipartBlobPartDescriptorSchema = z.strictObject({\n byteLength: boundedPositiveIntegerSchema(MAX_MULTIPART_BLOB_PART_BYTES),\n contentMd5: blobPartContentMd5Schema,\n partNumber: boundedPositiveIntegerSchema(MAX_MULTIPART_BLOB_PART_NUMBER),\n});\n\nexport type MultipartBlobPartDescriptor = z.infer<\n typeof MultipartBlobPartDescriptorSchema\n>;\n\n/**\n * Where a part's bytes go: the API byte route for stores that cannot sign, or\n * a short-lived URL that signs exactly one part of one upload.\n */\nexport const MultipartBlobPartUploadSourceSchema = z.discriminatedUnion(\n \"kind\",\n [\n z.strictObject({ kind: z.literal(\"api\") }),\n z.strictObject({\n kind: z.literal(\"signed-url\"),\n url: signedBlobUrlSchema,\n expiresAt: signedBlobUrlExpirySchema,\n }),\n ],\n);\n\nexport type MultipartBlobPartUploadSource = z.infer<\n typeof MultipartBlobPartUploadSourceSchema\n>;\n\nexport const MultipartBlobPartUploadSchema =\n MultipartBlobPartDescriptorSchema.extend({\n source: MultipartBlobPartUploadSourceSchema,\n });\n\nexport type MultipartBlobPartUpload = z.infer<\n typeof MultipartBlobPartUploadSchema\n>;\n"]}
@@ -1,2 +1,9 @@
1
1
  /** Maximum number of containers in a root-to-leaf path, including both ends. */
2
2
  export declare const MAX_CONTAINER_PATH_LENGTH = 100;
3
+ /**
4
+ * Maximum number of stored manifests one container mutation may cite as the
5
+ * mutated container's history. Inline bundles (8-14 KiB each) fit about this
6
+ * many under the 32 MiB request ceiling; a reference is ~150 bytes, so the
7
+ * bound keeps that capacity instead of letting a small body cite ~50x more.
8
+ */
9
+ export declare const MAX_CONTAINER_MANIFEST_HISTORY_REFS = 4096;
@@ -1,3 +1,10 @@
1
1
  /** Maximum number of containers in a root-to-leaf path, including both ends. */
2
2
  export const MAX_CONTAINER_PATH_LENGTH = 100;
3
+ /**
4
+ * Maximum number of stored manifests one container mutation may cite as the
5
+ * mutated container's history. Inline bundles (8-14 KiB each) fit about this
6
+ * many under the 32 MiB request ceiling; a reference is ~150 bytes, so the
7
+ * bound keeps that capacity instead of letting a small body cite ~50x more.
8
+ */
9
+ export const MAX_CONTAINER_MANIFEST_HISTORY_REFS = 4096;
3
10
  //# sourceMappingURL=containerLimits.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"containerLimits.js","sourceRoot":"","sources":["containerLimits.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC","sourcesContent":["/** Maximum number of containers in a root-to-leaf path, including both ends. */\nexport const MAX_CONTAINER_PATH_LENGTH = 100;\n"]}
1
+ {"version":3,"file":"containerLimits.js","sourceRoot":"","sources":["containerLimits.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,IAAI,CAAC","sourcesContent":["/** Maximum number of containers in a root-to-leaf path, including both ends. */\nexport const MAX_CONTAINER_PATH_LENGTH = 100;\n\n/**\n * Maximum number of stored manifests one container mutation may cite as the\n * mutated container's history. Inline bundles (8-14 KiB each) fit about this\n * many under the 32 MiB request ceiling; a reference is ~150 bytes, so the\n * bound keeps that capacity instead of letting a small body cite ~50x more.\n */\nexport const MAX_CONTAINER_MANIFEST_HISTORY_REFS = 4096;\n"]}
@@ -1,12 +1,13 @@
1
1
  export { type AccessEventBundleWireResponse, AccessEventBundleWireResponseSchema, type AccessManifestBundleWire, type AccessManifestBundleWireResponse, AccessManifestBundleWireResponseSchema, AccessManifestBundleWireSchema, isAccessEventBundleWireResponse, isAccessManifestBundleWire, isAccessManifestBundleWireArray, isAccessManifestBundleWireResponse, isOptionalAccessManifestBundleWireArray, } from "./accessManifestBundle.js";
2
- export { MAX_MULTIPART_BLOB_PART_BYTES } from "./blob.js";
2
+ export { MAX_INITIATE_PART_UPLOADS, MAX_MULTIPART_BLOB_PART_BYTES, } from "./blob.js";
3
+ export { blobPartContentMd5Schema, MAX_MULTIPART_BLOB_PART_NUMBER, type MultipartBlobPartDescriptor, MultipartBlobPartDescriptorSchema, type MultipartBlobPartUpload, MultipartBlobPartUploadSchema, type MultipartBlobPartUploadSource, MultipartBlobPartUploadSourceSchema, signedBlobUrlExpirySchema, signedBlobUrlSchema, } from "./blobTransferSchemas.js";
3
4
  export { CONTAINER_KEK_LOG_PAGE_LIMIT, CONTAINER_KEK_LOG_PRINCIPAL_SCOPE_LIMIT, CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT, ContainerKekKeyringWireRecordSchema, isContainerKekKeyringWireRecord, MAX_CONTAINER_KEY_EPOCH, MAX_INLINE_CONTAINER_REKEYS, MAX_ROTATION_CONTAINER_REKEYS, MAX_SEALED_CONTAINER_KEK_KEYRING_BASE64_LENGTH, SEALED_CONTAINER_KEK_KEYRING_AEAD_OVERHEAD_BYTES, SEALED_CONTAINER_KEK_KEYRING_ENTRY_BYTES, SEALED_CONTAINER_KEK_KEYRING_HEADER_BYTES, sealedContainerKekKeyringBytes, } from "./containerKekKeyringWire.js";
4
5
  export { MAX_CONTAINER_PATH_LENGTH } from "./containerLimits.js";
5
6
  export { MAX_DOCUMENT_SYNC_AUTHORIZATION_PATH_REFS, MAX_DOCUMENT_SYNC_AUTHORIZATION_PATHS, MAX_DOCUMENT_SYNC_CONTENT_KEY_TARGETS, MAX_DOCUMENT_SYNC_OUTGOING_UPDATES, MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH, MAX_DOCUMENT_SYNC_REQUEST_BYTES, MAX_DOCUMENT_SYNC_RESPONSE_ENVELOPE_BYTES, MAX_DOCUMENT_SYNC_RESPONSE_PAGE_BYTES, MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES, MAX_DOCUMENT_SYNC_RESPONSE_UPDATE_PAGE_BYTES, } from "./documentSyncLimits.js";
6
7
  export { isSerializedKeyEnvelope, isSerializedKeyEnvelopeArray, type SerializedKeyEnvelope, } from "./keyEnvelope.js";
8
+ export { KNOWN_MANIFEST_HINT_LIMIT, KnownManifestsHeadersSchema, parseKnownManifestHints, } from "./knownManifestWire.js";
7
9
  export { isOrganizationReplacementAuthorization, type OrganizationReplacementAuthorization, OrganizationReplacementAuthorizationSchema, } from "./organizationReplacement.js";
8
10
  export { PRINCIPAL_POLICY_HISTORY_PAGE_LIMIT, PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT, } from "./principalHistoryWire.js";
9
- export { PROJECTION_HISTORY_HINT_CHARACTERS, ProjectionHistoryHeadersSchema, type ProjectionHistoryPrefix, ProjectionHistoryPrefixesSchema, parseProjectionHistoryHints, } from "./projectionHistoryWire.js";
10
11
  export { hasArrayProperty, hasBooleanProperty, hasNonEmptyStringProperty, hasNullableNumberProperty, hasNullableStringProperty, hasNumberProperty, hasObjectProperty, hasOptionalStringProperty, hasPositiveIntegerProperty, hasPropertyValue, hasStringProperty, isNonEmptyStringArray, isOptionalRecordArray, isOptionalRecordArrayArray, isRecordArray, isRecordArrayArray, isStringArray, } from "./properties.js";
11
12
  export { AUTH_CHALLENGE_HEX_LENGTH, isAuthChallengeHexString, isByteArray, isByteArrayOfLength, isSha256HexString, ML_DSA87_PUBLIC_KEY_BYTES, ML_DSA87_SIGNATURE_BYTES, ML_KEM1024_PUBLIC_KEY_BYTES, SHA256_HEX_LENGTH, } from "./protocol.js";
12
13
  export { CANONICAL_SIGNED_AT_PATTERN, isCanonicalSignedAt, MAX_SIGNED_AT_YEAR, MIN_SIGNED_AT_YEAR, SIGNED_AT_CONTRACT, } from "./signedAt.js";
@@ -1,12 +1,13 @@
1
1
  export { AccessEventBundleWireResponseSchema, AccessManifestBundleWireResponseSchema, AccessManifestBundleWireSchema, isAccessEventBundleWireResponse, isAccessManifestBundleWire, isAccessManifestBundleWireArray, isAccessManifestBundleWireResponse, isOptionalAccessManifestBundleWireArray, } from "./accessManifestBundle.js";
2
- export { MAX_MULTIPART_BLOB_PART_BYTES } from "./blob.js";
2
+ export { MAX_INITIATE_PART_UPLOADS, MAX_MULTIPART_BLOB_PART_BYTES, } from "./blob.js";
3
+ export { blobPartContentMd5Schema, MAX_MULTIPART_BLOB_PART_NUMBER, MultipartBlobPartDescriptorSchema, MultipartBlobPartUploadSchema, MultipartBlobPartUploadSourceSchema, signedBlobUrlExpirySchema, signedBlobUrlSchema, } from "./blobTransferSchemas.js";
3
4
  export { CONTAINER_KEK_LOG_PAGE_LIMIT, CONTAINER_KEK_LOG_PRINCIPAL_SCOPE_LIMIT, CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT, ContainerKekKeyringWireRecordSchema, isContainerKekKeyringWireRecord, MAX_CONTAINER_KEY_EPOCH, MAX_INLINE_CONTAINER_REKEYS, MAX_ROTATION_CONTAINER_REKEYS, MAX_SEALED_CONTAINER_KEK_KEYRING_BASE64_LENGTH, SEALED_CONTAINER_KEK_KEYRING_AEAD_OVERHEAD_BYTES, SEALED_CONTAINER_KEK_KEYRING_ENTRY_BYTES, SEALED_CONTAINER_KEK_KEYRING_HEADER_BYTES, sealedContainerKekKeyringBytes, } from "./containerKekKeyringWire.js";
4
5
  export { MAX_CONTAINER_PATH_LENGTH } from "./containerLimits.js";
5
6
  export { MAX_DOCUMENT_SYNC_AUTHORIZATION_PATH_REFS, MAX_DOCUMENT_SYNC_AUTHORIZATION_PATHS, MAX_DOCUMENT_SYNC_CONTENT_KEY_TARGETS, MAX_DOCUMENT_SYNC_OUTGOING_UPDATES, MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH, MAX_DOCUMENT_SYNC_REQUEST_BYTES, MAX_DOCUMENT_SYNC_RESPONSE_ENVELOPE_BYTES, MAX_DOCUMENT_SYNC_RESPONSE_PAGE_BYTES, MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES, MAX_DOCUMENT_SYNC_RESPONSE_UPDATE_PAGE_BYTES, } from "./documentSyncLimits.js";
6
7
  export { isSerializedKeyEnvelope, isSerializedKeyEnvelopeArray, } from "./keyEnvelope.js";
8
+ export { KNOWN_MANIFEST_HINT_LIMIT, KnownManifestsHeadersSchema, parseKnownManifestHints, } from "./knownManifestWire.js";
7
9
  export { isOrganizationReplacementAuthorization, OrganizationReplacementAuthorizationSchema, } from "./organizationReplacement.js";
8
10
  export { PRINCIPAL_POLICY_HISTORY_PAGE_LIMIT, PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT, } from "./principalHistoryWire.js";
9
- export { PROJECTION_HISTORY_HINT_CHARACTERS, ProjectionHistoryHeadersSchema, ProjectionHistoryPrefixesSchema, parseProjectionHistoryHints, } from "./projectionHistoryWire.js";
10
11
  export { hasArrayProperty, hasBooleanProperty, hasNonEmptyStringProperty, hasNullableNumberProperty, hasNullableStringProperty, hasNumberProperty, hasObjectProperty, hasOptionalStringProperty, hasPositiveIntegerProperty, hasPropertyValue, hasStringProperty, isNonEmptyStringArray, isOptionalRecordArray, isOptionalRecordArrayArray, isRecordArray, isRecordArrayArray, isStringArray, } from "./properties.js";
11
12
  export { AUTH_CHALLENGE_HEX_LENGTH, isAuthChallengeHexString, isByteArray, isByteArrayOfLength, isSha256HexString, ML_DSA87_PUBLIC_KEY_BYTES, ML_DSA87_SIGNATURE_BYTES, ML_KEM1024_PUBLIC_KEY_BYTES, SHA256_HEX_LENGTH, } from "./protocol.js";
12
13
  export { CANONICAL_SIGNED_AT_PATTERN, isCanonicalSignedAt, MAX_SIGNED_AT_YEAR, MIN_SIGNED_AT_YEAR, SIGNED_AT_CONTRACT, } from "./signedAt.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mCAAmC,EAGnC,sCAAsC,EACtC,8BAA8B,EAC9B,+BAA+B,EAC/B,0BAA0B,EAC1B,+BAA+B,EAC/B,kCAAkC,EAClC,uCAAuC,GACxC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,6BAA6B,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,EACL,4BAA4B,EAC5B,uCAAuC,EACvC,mCAAmC,EACnC,mCAAmC,EACnC,+BAA+B,EAC/B,uBAAuB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AE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export {\n type AccessEventBundleWireResponse,\n AccessEventBundleWireResponseSchema,\n type AccessManifestBundleWire,\n type AccessManifestBundleWireResponse,\n AccessManifestBundleWireResponseSchema,\n AccessManifestBundleWireSchema,\n isAccessEventBundleWireResponse,\n isAccessManifestBundleWire,\n isAccessManifestBundleWireArray,\n isAccessManifestBundleWireResponse,\n isOptionalAccessManifestBundleWireArray,\n} from \"./accessManifestBundle\";\nexport { MAX_MULTIPART_BLOB_PART_BYTES } from \"./blob\";\nexport {\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n CONTAINER_KEK_LOG_PRINCIPAL_SCOPE_LIMIT,\n CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT,\n ContainerKekKeyringWireRecordSchema,\n isContainerKekKeyringWireRecord,\n MAX_CONTAINER_KEY_EPOCH,\n MAX_INLINE_CONTAINER_REKEYS,\n MAX_ROTATION_CONTAINER_REKEYS,\n MAX_SEALED_CONTAINER_KEK_KEYRING_BASE64_LENGTH,\n SEALED_CONTAINER_KEK_KEYRING_AEAD_OVERHEAD_BYTES,\n SEALED_CONTAINER_KEK_KEYRING_ENTRY_BYTES,\n SEALED_CONTAINER_KEK_KEYRING_HEADER_BYTES,\n sealedContainerKekKeyringBytes,\n} from \"./containerKekKeyringWire\";\nexport { MAX_CONTAINER_PATH_LENGTH } from \"./containerLimits\";\nexport {\n MAX_DOCUMENT_SYNC_AUTHORIZATION_PATH_REFS,\n MAX_DOCUMENT_SYNC_AUTHORIZATION_PATHS,\n MAX_DOCUMENT_SYNC_CONTENT_KEY_TARGETS,\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n MAX_DOCUMENT_SYNC_REQUEST_BYTES,\n MAX_DOCUMENT_SYNC_RESPONSE_ENVELOPE_BYTES,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_BYTES,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n MAX_DOCUMENT_SYNC_RESPONSE_UPDATE_PAGE_BYTES,\n} from \"./documentSyncLimits\";\nexport {\n isSerializedKeyEnvelope,\n isSerializedKeyEnvelopeArray,\n type SerializedKeyEnvelope,\n} from \"./keyEnvelope\";\nexport {\n isOrganizationReplacementAuthorization,\n type OrganizationReplacementAuthorization,\n OrganizationReplacementAuthorizationSchema,\n} from \"./organizationReplacement\";\nexport {\n PRINCIPAL_POLICY_HISTORY_PAGE_LIMIT,\n PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT,\n} from \"./principalHistoryWire\";\nexport {\n PROJECTION_HISTORY_HINT_CHARACTERS,\n ProjectionHistoryHeadersSchema,\n type ProjectionHistoryPrefix,\n ProjectionHistoryPrefixesSchema,\n parseProjectionHistoryHints,\n} from \"./projectionHistoryWire\";\nexport {\n hasArrayProperty,\n hasBooleanProperty,\n hasNonEmptyStringProperty,\n hasNullableNumberProperty,\n hasNullableStringProperty,\n hasNumberProperty,\n hasObjectProperty,\n hasOptionalStringProperty,\n hasPositiveIntegerProperty,\n hasPropertyValue,\n hasStringProperty,\n isNonEmptyStringArray,\n isOptionalRecordArray,\n isOptionalRecordArrayArray,\n isRecordArray,\n isRecordArrayArray,\n isStringArray,\n} from \"./properties\";\nexport {\n AUTH_CHALLENGE_HEX_LENGTH,\n isAuthChallengeHexString,\n isByteArray,\n isByteArrayOfLength,\n isSha256HexString,\n ML_DSA87_PUBLIC_KEY_BYTES,\n ML_DSA87_SIGNATURE_BYTES,\n ML_KEM1024_PUBLIC_KEY_BYTES,\n SHA256_HEX_LENGTH,\n} from \"./protocol\";\nexport {\n CANONICAL_SIGNED_AT_PATTERN,\n isCanonicalSignedAt,\n MAX_SIGNED_AT_YEAR,\n MIN_SIGNED_AT_YEAR,\n SIGNED_AT_CONTRACT,\n} from \"./signedAt\";\nexport { isUuidV4String } from \"./uuid\";\nexport { isWalLsnString, parseWalLsn } from \"./walLsn\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mCAAmC,EAGnC,sCAAsC,EACtC,8BAA8B,EAC9B,+BAA+B,EAC/B,0BAA0B,EAC1B,+BAA+B,EAC/B,kCAAkC,EAClC,uCAAuC,GACxC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAE9B,iCAAiC,EAEjC,6BAA6B,EAE7B,mCAAmC,EACnC,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,4BAA4B,EAC5B,uCAAuC,EACvC,mCAAmC,EACnC,mCAAmC,EACnC,+BAA+B,EAC/B,uBAAuB,EACvB,2BAA2B,EAC3B,6BAA6B,EAC7B,8CAA8C,EAC9C,gDAAgD,EAChD,wCAAwC,EACxC,yCAAyC,EACzC,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EACL,yCAAyC,EACzC,qCAAqC,EACrC,qCAAqC,EACrC,kCAAkC,EAClC,oCAAoC,EACpC,+BAA+B,EAC/B,yCAAyC,EACzC,qCAAqC,EACrC,uCAAuC,EACvC,4CAA4C,GAC7C,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,uBAAuB,EACvB,4BAA4B,GAE7B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,sCAAsC,EAEtC,0CAA0C,GAC3C,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,mCAAmC,EACnC,kCAAkC,GACnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,0BAA0B,EAC1B,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,aAAa,EACb,kBAAkB,EAClB,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EACxB,2BAA2B,EAC3B,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export {\n type AccessEventBundleWireResponse,\n AccessEventBundleWireResponseSchema,\n type AccessManifestBundleWire,\n type AccessManifestBundleWireResponse,\n AccessManifestBundleWireResponseSchema,\n AccessManifestBundleWireSchema,\n isAccessEventBundleWireResponse,\n isAccessManifestBundleWire,\n isAccessManifestBundleWireArray,\n isAccessManifestBundleWireResponse,\n isOptionalAccessManifestBundleWireArray,\n} from \"./accessManifestBundle\";\nexport {\n MAX_INITIATE_PART_UPLOADS,\n MAX_MULTIPART_BLOB_PART_BYTES,\n} from \"./blob\";\nexport {\n blobPartContentMd5Schema,\n MAX_MULTIPART_BLOB_PART_NUMBER,\n type MultipartBlobPartDescriptor,\n MultipartBlobPartDescriptorSchema,\n type MultipartBlobPartUpload,\n MultipartBlobPartUploadSchema,\n type MultipartBlobPartUploadSource,\n MultipartBlobPartUploadSourceSchema,\n signedBlobUrlExpirySchema,\n signedBlobUrlSchema,\n} from \"./blobTransferSchemas\";\nexport {\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n CONTAINER_KEK_LOG_PRINCIPAL_SCOPE_LIMIT,\n CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT,\n ContainerKekKeyringWireRecordSchema,\n isContainerKekKeyringWireRecord,\n MAX_CONTAINER_KEY_EPOCH,\n MAX_INLINE_CONTAINER_REKEYS,\n MAX_ROTATION_CONTAINER_REKEYS,\n MAX_SEALED_CONTAINER_KEK_KEYRING_BASE64_LENGTH,\n SEALED_CONTAINER_KEK_KEYRING_AEAD_OVERHEAD_BYTES,\n SEALED_CONTAINER_KEK_KEYRING_ENTRY_BYTES,\n SEALED_CONTAINER_KEK_KEYRING_HEADER_BYTES,\n sealedContainerKekKeyringBytes,\n} from \"./containerKekKeyringWire\";\nexport { MAX_CONTAINER_PATH_LENGTH } from \"./containerLimits\";\nexport {\n MAX_DOCUMENT_SYNC_AUTHORIZATION_PATH_REFS,\n MAX_DOCUMENT_SYNC_AUTHORIZATION_PATHS,\n MAX_DOCUMENT_SYNC_CONTENT_KEY_TARGETS,\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n MAX_DOCUMENT_SYNC_REQUEST_BYTES,\n MAX_DOCUMENT_SYNC_RESPONSE_ENVELOPE_BYTES,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_BYTES,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n MAX_DOCUMENT_SYNC_RESPONSE_UPDATE_PAGE_BYTES,\n} from \"./documentSyncLimits\";\nexport {\n isSerializedKeyEnvelope,\n isSerializedKeyEnvelopeArray,\n type SerializedKeyEnvelope,\n} from \"./keyEnvelope\";\nexport {\n KNOWN_MANIFEST_HINT_LIMIT,\n KnownManifestsHeadersSchema,\n parseKnownManifestHints,\n} from \"./knownManifestWire\";\nexport {\n isOrganizationReplacementAuthorization,\n type OrganizationReplacementAuthorization,\n OrganizationReplacementAuthorizationSchema,\n} from \"./organizationReplacement\";\nexport {\n PRINCIPAL_POLICY_HISTORY_PAGE_LIMIT,\n PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT,\n} from \"./principalHistoryWire\";\nexport {\n hasArrayProperty,\n hasBooleanProperty,\n hasNonEmptyStringProperty,\n hasNullableNumberProperty,\n hasNullableStringProperty,\n hasNumberProperty,\n hasObjectProperty,\n hasOptionalStringProperty,\n hasPositiveIntegerProperty,\n hasPropertyValue,\n hasStringProperty,\n isNonEmptyStringArray,\n isOptionalRecordArray,\n isOptionalRecordArrayArray,\n isRecordArray,\n isRecordArrayArray,\n isStringArray,\n} from \"./properties\";\nexport {\n AUTH_CHALLENGE_HEX_LENGTH,\n isAuthChallengeHexString,\n isByteArray,\n isByteArrayOfLength,\n isSha256HexString,\n ML_DSA87_PUBLIC_KEY_BYTES,\n ML_DSA87_SIGNATURE_BYTES,\n ML_KEM1024_PUBLIC_KEY_BYTES,\n SHA256_HEX_LENGTH,\n} from \"./protocol\";\nexport {\n CANONICAL_SIGNED_AT_PATTERN,\n isCanonicalSignedAt,\n MAX_SIGNED_AT_YEAR,\n MIN_SIGNED_AT_YEAR,\n SIGNED_AT_CONTRACT,\n} from \"./signedAt\";\nexport { isUuidV4String } from \"./uuid\";\nexport { isWalLsnString, parseWalLsn } from \"./walLsn\";\n"]}
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Hints bound the omission a request can ask for, never the history a reader
4
+ * receives: an uncited manifest always travels.
5
+ */
6
+ export declare const KNOWN_MANIFEST_HINT_LIMIT = 48;
7
+ /** Null unless the header is 1–48 unique lowercase SHA-256 manifest hashes. */
8
+ export declare function parseKnownManifestHints(value: string): string[] | null;
9
+ export declare const KnownManifestsHeadersSchema: z.ZodObject<{
10
+ "x-known-manifests": z.ZodOptional<z.ZodString>;
11
+ }, z.core.$strip>;
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ import { registerJsonSchemaFragment, registerJsonSchemaRuntimeRefinements, } from "../jsonSchema.js";
3
+ import { knownManifestsHeaderRefinement } from "../knownManifestsRefinements.js";
4
+ import { isSha256HexString, SHA256_HEX_LENGTH } from "./protocol.js";
5
+ /**
6
+ * Hints bound the omission a request can ask for, never the history a reader
7
+ * receives: an uncited manifest always travels.
8
+ */
9
+ export const KNOWN_MANIFEST_HINT_LIMIT = 48;
10
+ const KNOWN_MANIFEST_HINT_CHARACTERS = KNOWN_MANIFEST_HINT_LIMIT * (SHA256_HEX_LENGTH + 1) - 1;
11
+ /** Null unless the header is 1–48 unique lowercase SHA-256 manifest hashes. */
12
+ export function parseKnownManifestHints(value) {
13
+ const hashes = value.split(",");
14
+ return hashes.length <= KNOWN_MANIFEST_HINT_LIMIT &&
15
+ new Set(hashes).size === hashes.length &&
16
+ hashes.every(isSha256HexString)
17
+ ? hashes
18
+ : null;
19
+ }
20
+ const hintHeader = registerJsonSchemaFragment(z.string().max(KNOWN_MANIFEST_HINT_CHARACTERS), {
21
+ type: "string",
22
+ maxLength: KNOWN_MANIFEST_HINT_CHARACTERS,
23
+ description: `Comma-separated manifest hashes whose verified bundles the device already holds; at most ${KNOWN_MANIFEST_HINT_LIMIT}, unique`,
24
+ });
25
+ export const KnownManifestsHeadersSchema = z.object({
26
+ "x-known-manifests": registerJsonSchemaRuntimeRefinements(hintHeader.refine((value) => parseKnownManifestHints(value) !== null), [knownManifestsHeaderRefinement]).optional(),
27
+ });
28
+ //# sourceMappingURL=knownManifestWire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knownManifestWire.js","sourceRoot":"","sources":["knownManifestWire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,0BAA0B,EAC1B,oCAAoC,GACrC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAElE;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,MAAM,8BAA8B,GAClC,yBAAyB,GAAG,CAAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAE1D,+EAA+E;AAC/E,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,MAAM,IAAI,yBAAyB;QAC/C,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,MAAM;QACtC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC;QAC/B,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,MAAM,UAAU,GAAG,0BAA0B,CAC3C,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,8BAA8B,CAAC,EAC9C;IACE,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,8BAA8B;IACzC,WAAW,EAAE,4FAA4F,yBAAyB,UAAU;CAC7I,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,mBAAmB,EAAE,oCAAoC,CACvD,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,uBAAuB,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,EACrE,CAAC,8BAA8B,CAAC,CACjC,CAAC,QAAQ,EAAE;CACb,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n registerJsonSchemaFragment,\n registerJsonSchemaRuntimeRefinements,\n} from \"../jsonSchema\";\nimport { knownManifestsHeaderRefinement } from \"../knownManifestsRefinements\";\nimport { isSha256HexString, SHA256_HEX_LENGTH } from \"./protocol\";\n\n/**\n * Hints bound the omission a request can ask for, never the history a reader\n * receives: an uncited manifest always travels.\n */\nexport const KNOWN_MANIFEST_HINT_LIMIT = 48;\nconst KNOWN_MANIFEST_HINT_CHARACTERS =\n KNOWN_MANIFEST_HINT_LIMIT * (SHA256_HEX_LENGTH + 1) - 1;\n\n/** Null unless the header is 1–48 unique lowercase SHA-256 manifest hashes. */\nexport function parseKnownManifestHints(value: string): string[] | null {\n const hashes = value.split(\",\");\n return hashes.length <= KNOWN_MANIFEST_HINT_LIMIT &&\n new Set(hashes).size === hashes.length &&\n hashes.every(isSha256HexString)\n ? hashes\n : null;\n}\n\nconst hintHeader = registerJsonSchemaFragment(\n z.string().max(KNOWN_MANIFEST_HINT_CHARACTERS),\n {\n type: \"string\",\n maxLength: KNOWN_MANIFEST_HINT_CHARACTERS,\n description: `Comma-separated manifest hashes whose verified bundles the device already holds; at most ${KNOWN_MANIFEST_HINT_LIMIT}, unique`,\n },\n);\n\nexport const KnownManifestsHeadersSchema = z.object({\n \"x-known-manifests\": registerJsonSchemaRuntimeRefinements(\n hintHeader.refine((value) => parseKnownManifestHints(value) !== null),\n [knownManifestsHeaderRefinement],\n ).optional(),\n});\n"]}
@@ -2,9 +2,14 @@ export const containerWriterProjectionPathKekCountRefinement = {
2
2
  description: "containerKeks must contain exactly one entry for every manifest in path",
3
3
  id: "response.container-writer-projection-path-kek-count",
4
4
  };
5
+ export const writerProjectionManifestBundlesRefinement = {
6
+ description: "every cited manifest hash names one bundles entry, every bundles key equals its bundle's manifestHash, and every bundle is cited",
7
+ id: "response.writer-projection-manifest-bundles",
8
+ };
5
9
  export const writerProjectionResponseRuntimeRefinements = [
6
10
  containerWriterProjectionPathKekCountRefinement,
7
11
  organizationProvisioningContainerKeyringRefinement,
12
+ writerProjectionManifestBundlesRefinement,
8
13
  ];
9
14
  import { organizationProvisioningContainerKeyringRefinement } from "./organizationProvisioningRefinements.js";
10
15
  //# sourceMappingURL=writerProjectionRefinements.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"writerProjectionRefinements.js","sourceRoot":"","sources":["writerProjectionRefinements.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,+CAA+C,GAAG;IAC7D,WAAW,EACT,yEAAyE;IAC3E,EAAE,EAAE,qDAAqD;CACjD,CAAC;AAEX,MAAM,CAAC,MAAM,0CAA0C,GAAG;IACxD,+CAA+C;IAC/C,kDAAkD;CAC1C,CAAC;AAEX,OAAO,EAAE,kDAAkD,EAAE,MAAM,uCAAuC,CAAC","sourcesContent":["export const containerWriterProjectionPathKekCountRefinement = {\n description:\n \"containerKeks must contain exactly one entry for every manifest in path\",\n id: \"response.container-writer-projection-path-kek-count\",\n} as const;\n\nexport const writerProjectionResponseRuntimeRefinements = [\n containerWriterProjectionPathKekCountRefinement,\n organizationProvisioningContainerKeyringRefinement,\n] as const;\n\nimport { organizationProvisioningContainerKeyringRefinement } from \"./organizationProvisioningRefinements\";\n"]}
1
+ {"version":3,"file":"writerProjectionRefinements.js","sourceRoot":"","sources":["writerProjectionRefinements.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,+CAA+C,GAAG;IAC7D,WAAW,EACT,yEAAyE;IAC3E,EAAE,EAAE,qDAAqD;CACjD,CAAC;AAEX,MAAM,CAAC,MAAM,yCAAyC,GAAG;IACvD,WAAW,EACT,kIAAkI;IACpI,EAAE,EAAE,6CAA6C;CACzC,CAAC;AAEX,MAAM,CAAC,MAAM,0CAA0C,GAAG;IACxD,+CAA+C;IAC/C,kDAAkD;IAClD,yCAAyC;CACjC,CAAC;AAEX,OAAO,EAAE,kDAAkD,EAAE,MAAM,uCAAuC,CAAC","sourcesContent":["export const containerWriterProjectionPathKekCountRefinement = {\n description:\n \"containerKeks must contain exactly one entry for every manifest in path\",\n id: \"response.container-writer-projection-path-kek-count\",\n} as const;\n\nexport const writerProjectionManifestBundlesRefinement = {\n description:\n \"every cited manifest hash names one bundles entry, every bundles key equals its bundle's manifestHash, and every bundle is cited\",\n id: \"response.writer-projection-manifest-bundles\",\n} as const;\n\nexport const writerProjectionResponseRuntimeRefinements = [\n containerWriterProjectionPathKekCountRefinement,\n organizationProvisioningContainerKeyringRefinement,\n writerProjectionManifestBundlesRefinement,\n] as const;\n\nimport { organizationProvisioningContainerKeyringRefinement } from \"./organizationProvisioningRefinements\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/client-sdk",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "description": "React-free Tearleads client runtime: local SQLite persistence, keys, sync, encrypted blobs, and domain workflows.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -0,0 +1,82 @@
1
+ import { describeMultipartBlobPart } from "../../internal/api-client/index.js";
2
+ import { bytesToHex } from "../../internal/crypto/index.js";
3
+ import { MAX_INITIATE_PART_UPLOADS, } from "../../internal/validators/util/index.js";
4
+ import { acquireBlobTransferPermit, tryAcquireBlobTransferPermit, } from "../../data/blobs/transferPool.js";
5
+ /** Return the pool slots of first parts no upload consumed. */
6
+ export function releasePreparedParts(prepared) {
7
+ for (const part of prepared.values()) {
8
+ part.permit.release();
9
+ }
10
+ prepared.clear();
11
+ }
12
+ /**
13
+ * One permit is awaited; more are taken only if free right now. Two uploads
14
+ * each waiting for a second slot while holding a first could otherwise
15
+ * deadlock the pool, since a held slot frees only when its part uploads.
16
+ */
17
+ async function acquireFirstPartPermits(client, limit) {
18
+ const permits = [await acquireBlobTransferPermit(client)];
19
+ while (permits.length < limit) {
20
+ const permit = tryAcquireBlobTransferPermit(client);
21
+ if (!permit)
22
+ break;
23
+ permits.push(permit);
24
+ }
25
+ return permits;
26
+ }
27
+ export async function sha256BytesHex(bytes) {
28
+ return bytesToHex(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)));
29
+ }
30
+ export async function prepareFirstMultipartParts(client, encryption, concurrency) {
31
+ const permits = await acquireFirstPartPermits(client, Math.min(encryption.partCount, concurrency, MAX_INITIATE_PART_UPLOADS));
32
+ const descriptors = [];
33
+ const prepared = new Map();
34
+ try {
35
+ for (const [partIndex, permit] of permits.entries()) {
36
+ const bytes = await encryption.encryptPart(partIndex);
37
+ if (bytes.byteLength !== encryption.getPartByteLength(partIndex)) {
38
+ throw new Error(`Encrypted blob part ${partIndex + 1} byte length mismatch: expected ${encryption.getPartByteLength(partIndex).toLocaleString()}, received ${bytes.byteLength.toLocaleString()}.`);
39
+ }
40
+ const sha256 = await sha256BytesHex(bytes);
41
+ prepared.set(partIndex, { bytes, permit, sha256 });
42
+ descriptors.push(describeMultipartBlobPart(partIndex + 1, bytes));
43
+ }
44
+ }
45
+ catch (error) {
46
+ for (const permit of permits)
47
+ permit.release();
48
+ throw error;
49
+ }
50
+ return { descriptors, prepared };
51
+ }
52
+ /**
53
+ * The initiation must return exactly one source per described part, for that
54
+ * part's number, length, and checksum, and every source of one stage must use
55
+ * the same transport.
56
+ */
57
+ export function readIssuedPartSources(descriptors, stage) {
58
+ const issued = new Map();
59
+ const kinds = new Set(stage.partUploads.map((upload) => upload.source.kind));
60
+ const matches = stage.partUploads.length === descriptors.length &&
61
+ kinds.size === 1 &&
62
+ descriptors.every((descriptor, index) => {
63
+ const upload = stage.partUploads[index];
64
+ return (upload?.partNumber === descriptor.partNumber &&
65
+ upload.byteLength === descriptor.byteLength &&
66
+ upload.contentMd5 === descriptor.contentMd5);
67
+ });
68
+ if (!matches) {
69
+ throw new Error("Multipart blob stage initiation part uploads do not match its request.");
70
+ }
71
+ for (const upload of stage.partUploads) {
72
+ issued.set(upload.partNumber, upload.source);
73
+ }
74
+ return { apiTransport: kinds.has("api"), issued };
75
+ }
76
+ /** Use each issued source once; retries and later parts authorize anew. */
77
+ export function takePartSource(sources, partNumber) {
78
+ const issued = sources.issued.get(partNumber);
79
+ sources.issued.delete(partNumber);
80
+ return issued ?? (sources.apiTransport ? { kind: "api" } : undefined);
81
+ }
82
+ //# sourceMappingURL=multipartFirstParts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multipartFirstParts.js","sourceRoot":"","sources":["multipartFirstParts.ts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xE,CAAC","sourcesContent":["import { describeMultipartBlobPart } from \"@tearleads/api-client\";\nimport { bytesToHex } from \"@tearleads/crypto\";\nimport type { InitiateMultipartBlobStageResponse } from \"@tearleads/validators/response\";\nimport {\n MAX_INITIATE_PART_UPLOADS,\n type MultipartBlobPartDescriptor,\n type MultipartBlobPartUploadSource,\n} from \"@tearleads/validators/util\";\nimport type { BlobBytes } from \"../../data/blobContracts\";\nimport {\n acquireBlobTransferPermit,\n type BlobTransferPermit,\n tryAcquireBlobTransferPermit,\n} from \"../../data/blobs/transferPool\";\nimport type { BlobEncryptionPlan } from \"../../data/documents/blob/shared/crypto\";\n\nexport interface PreparedMultipartPart {\n readonly bytes: BlobBytes;\n readonly sha256: string;\n}\n\n/**\n * A first part's bytes and the transfer-pool permit that pays for them: the\n * bytes exist before their upload can start, so they hold a slot of the\n * client's byte-I/O bound until the upload that sends them releases it.\n */\nexport interface PreparedFirstPart extends PreparedMultipartPart {\n readonly permit: BlobTransferPermit;\n}\n\n/**\n * The parts a new stage's upload starts with, encrypted once up front: their\n * descriptors ride on the stage initiation, and their bytes are handed to the\n * upload workers instead of being encrypted a second time.\n */\nexport interface MultipartFirstParts {\n readonly descriptors: readonly MultipartBlobPartDescriptor[];\n readonly prepared: Map<number, PreparedFirstPart>;\n}\n\n/** Return the pool slots of first parts no upload consumed. */\nexport function releasePreparedParts(\n prepared: Map<number, PreparedFirstPart>,\n): void {\n for (const part of prepared.values()) {\n part.permit.release();\n }\n prepared.clear();\n}\n\n/**\n * One permit is awaited; more are taken only if free right now. Two uploads\n * each waiting for a second slot while holding a first could otherwise\n * deadlock the pool, since a held slot frees only when its part uploads.\n */\nasync function acquireFirstPartPermits(\n client: object,\n limit: number,\n): Promise<BlobTransferPermit[]> {\n const permits = [await acquireBlobTransferPermit(client)];\n while (permits.length < limit) {\n const permit = tryAcquireBlobTransferPermit(client);\n if (!permit) break;\n permits.push(permit);\n }\n return permits;\n}\n\n/**\n * Where each part's bytes go. Sources the stage initiation issued are used\n * once; a store that cannot sign (`api`) needs no per-part authorization at\n * all, and a part with no source authorizes just before it is sent.\n */\nexport interface MultipartPartSources {\n readonly apiTransport: boolean;\n readonly issued: Map<number, MultipartBlobPartUploadSource>;\n}\n\nexport async function sha256BytesHex(bytes: BlobBytes): Promise<string> {\n return bytesToHex(\n new Uint8Array(await crypto.subtle.digest(\"SHA-256\", bytes)),\n );\n}\n\nexport async function prepareFirstMultipartParts(\n client: object,\n encryption: BlobEncryptionPlan,\n concurrency: number,\n): Promise<MultipartFirstParts> {\n const permits = await acquireFirstPartPermits(\n client,\n Math.min(encryption.partCount, concurrency, MAX_INITIATE_PART_UPLOADS),\n );\n const descriptors: MultipartBlobPartDescriptor[] = [];\n const prepared = new Map<number, PreparedFirstPart>();\n try {\n for (const [partIndex, permit] of permits.entries()) {\n const bytes = await encryption.encryptPart(partIndex);\n if (bytes.byteLength !== encryption.getPartByteLength(partIndex)) {\n throw new Error(\n `Encrypted blob part ${partIndex + 1} byte length mismatch: expected ${encryption.getPartByteLength(partIndex).toLocaleString()}, received ${bytes.byteLength.toLocaleString()}.`,\n );\n }\n const sha256 = await sha256BytesHex(bytes);\n prepared.set(partIndex, { bytes, permit, sha256 });\n descriptors.push(describeMultipartBlobPart(partIndex + 1, bytes));\n }\n } catch (error) {\n for (const permit of permits) permit.release();\n throw error;\n }\n return { descriptors, prepared };\n}\n\n/**\n * The initiation must return exactly one source per described part, for that\n * part's number, length, and checksum, and every source of one stage must use\n * the same transport.\n */\nexport function readIssuedPartSources(\n descriptors: readonly MultipartBlobPartDescriptor[],\n stage: Pick<InitiateMultipartBlobStageResponse, \"partUploads\">,\n): MultipartPartSources {\n const issued = new Map<number, MultipartBlobPartUploadSource>();\n const kinds = new Set(stage.partUploads.map((upload) => upload.source.kind));\n const matches =\n stage.partUploads.length === descriptors.length &&\n kinds.size === 1 &&\n descriptors.every((descriptor, index) => {\n const upload = stage.partUploads[index];\n return (\n upload?.partNumber === descriptor.partNumber &&\n upload.byteLength === descriptor.byteLength &&\n upload.contentMd5 === descriptor.contentMd5\n );\n });\n if (!matches) {\n throw new Error(\n \"Multipart blob stage initiation part uploads do not match its request.\",\n );\n }\n for (const upload of stage.partUploads) {\n issued.set(upload.partNumber, upload.source);\n }\n return { apiTransport: kinds.has(\"api\"), issued };\n}\n\n/** Use each issued source once; retries and later parts authorize anew. */\nexport function takePartSource(\n sources: MultipartPartSources,\n partNumber: number,\n): MultipartBlobPartUploadSource | undefined {\n const issued = sources.issued.get(partNumber);\n sources.issued.delete(partNumber);\n return issued ?? (sources.apiTransport ? { kind: \"api\" } : undefined);\n}\n"]}
@@ -0,0 +1,83 @@
1
+ import { prepareFirstMultipartParts, readIssuedPartSources, releasePreparedParts, } from "./multipartFirstParts.js";
2
+ import { assertMultipartStageReplaceable, multipartApiFailureMessage, } from "./multipartStageFailures.js";
3
+ function isMultipartStageStatus(stage) {
4
+ return "completed" in stage && typeof stage.completed === "boolean";
5
+ }
6
+ async function resumeMultipartStage(input, resumeStageId) {
7
+ const resumed = await input.apiClient.getMultipartBlobStage(resumeStageId);
8
+ if (!resumed) {
9
+ await assertMultipartStageReplaceable({
10
+ apiClient: input.apiClient,
11
+ onStageUnavailable: input.onStageUnavailable,
12
+ stageId: resumeStageId,
13
+ });
14
+ return null;
15
+ }
16
+ if (resumed.stageId !== resumeStageId) {
17
+ throw new Error(`Multipart blob resume response does not match stage ${resumeStageId}.`);
18
+ }
19
+ // A successful lookup is authoritative: a metadata mismatch indicates
20
+ // inconsistent persisted state or a bad server response, not proof that
21
+ // the existing stage is safe to abandon.
22
+ if (resumed.organizationId !== input.organizationId ||
23
+ resumed.byteLength !== input.encryption.byteLength ||
24
+ resumed.sha256 !== input.encryption.sha256) {
25
+ throw new Error(`Multipart blob resume stage ${resumeStageId} does not match the requested organization or bytes.`);
26
+ }
27
+ return resumed;
28
+ }
29
+ async function initiateWithFirstParts(input, firstParts) {
30
+ const { byteLength, sha256 } = input.encryption;
31
+ const stage = await input.apiClient.initiateMultipartBlobStage({
32
+ organizationId: input.organizationId,
33
+ byteLength,
34
+ firstParts: [...firstParts.descriptors],
35
+ sha256,
36
+ });
37
+ if (!stage) {
38
+ throw new Error(multipartApiFailureMessage({
39
+ apiClient: input.apiClient,
40
+ fallback: `Multipart blob stage initiation failed for ${byteLength.toLocaleString()} bytes.`,
41
+ request: { method: "POST", path: "/blobs/stages/multipart" },
42
+ }));
43
+ }
44
+ if (stage.organizationId !== input.organizationId ||
45
+ stage.byteLength !== byteLength ||
46
+ stage.sha256 !== sha256) {
47
+ throw new Error("Multipart blob stage initiation response does not match its request.");
48
+ }
49
+ return {
50
+ prepared: firstParts.prepared,
51
+ sources: readIssuedPartSources(firstParts.descriptors, stage),
52
+ status: isMultipartStageStatus(stage)
53
+ ? stage
54
+ : { ...stage, completed: false },
55
+ };
56
+ }
57
+ // A new stage carries the parts the upload starts with, so their upload
58
+ // sources come back with the stage instead of one authorization each. Their
59
+ // bytes hold transfer-pool slots until uploaded, or until initiation fails.
60
+ async function initiateMultipartStage(input) {
61
+ const firstParts = await prepareFirstMultipartParts(input.apiClient, input.encryption, input.concurrency);
62
+ try {
63
+ return await initiateWithFirstParts(input, firstParts);
64
+ }
65
+ catch (error) {
66
+ releasePreparedParts(firstParts.prepared);
67
+ throw error;
68
+ }
69
+ }
70
+ export async function resolveMultipartStage(input) {
71
+ const resumeStageId = input.multipart.resumeStageId;
72
+ const resumed = resumeStageId
73
+ ? await resumeMultipartStage(input, resumeStageId)
74
+ : null;
75
+ return resumed
76
+ ? {
77
+ prepared: new Map(),
78
+ sources: { apiTransport: false, issued: new Map() },
79
+ status: resumed,
80
+ }
81
+ : initiateMultipartStage(input);
82
+ }
83
+ //# sourceMappingURL=multipartStageResolution.js.map