@tearleads/client-sdk 0.1.244 → 0.1.247
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/persistence/container-contents/containerContentsPersistence.js +2 -0
- package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerContentsPersistenceTypes.d.ts +2 -1
- package/data/persistence/container-contents/containerContentsPersistenceTypes.js.map +1 -1
- package/data/persistence/container-contents/containerMetadataRevalidations.d.ts +22 -0
- package/data/persistence/container-contents/containerMetadataRevalidations.js +52 -0
- package/data/persistence/container-contents/containerMetadataRevalidations.js.map +1 -0
- package/data/sqlite/schema/containerSchema.d.ts +173 -0
- package/data/sqlite/schema/containerSchema.js +18 -0
- package/data/sqlite/schema/containerSchema.js.map +1 -1
- package/data/sqlite/schema/index.d.ts +84 -1
- package/data/sqlite/schema/index.js +1 -1
- package/data/sqlite/schema/index.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +3 -8
- package/internal/api-client/client/apiClientContext.d.ts +1 -0
- package/internal/api-client/client/containerReads.d.ts +1 -0
- package/internal/api-client/client/session.d.ts +2 -0
- package/internal/crypto/keying/accessManifestVerificationTypes.d.ts +8 -2
- package/internal/crypto/keying/accessManifestVerificationTypes.js.map +1 -1
- package/internal/crypto/keying/containerAccess.js +1 -1
- package/internal/crypto/keying/containerAccess.js.map +1 -1
- package/internal/crypto/keying/documentAccess.js +1 -1
- package/internal/crypto/keying/documentAccess.js.map +1 -1
- package/internal/crypto/organizationReplacement.js +5 -6
- package/internal/crypto/organizationReplacement.js.map +1 -1
- package/internal/loro/document.d.ts +5 -0
- package/internal/loro/document.js +17 -0
- package/internal/loro/document.js.map +1 -1
- package/internal/loro/index.d.ts +1 -1
- package/internal/loro/index.js +1 -1
- package/internal/loro/index.js.map +1 -1
- package/internal/validators/operation/attachments.d.ts +0 -12
- package/internal/validators/operation/auth.d.ts +14 -76
- package/internal/validators/operation/auth.js +2 -1
- package/internal/validators/operation/auth.js.map +1 -1
- package/internal/validators/operation/containerMutations.d.ts +1 -49
- package/internal/validators/operation/containerMutations.js +1 -1
- package/internal/validators/operation/containerMutations.js.map +1 -1
- package/internal/validators/operation/containerReads.d.ts +2 -0
- package/internal/validators/operation/documentMutations.d.ts +0 -24
- package/internal/validators/operation/documentSync.d.ts +0 -4
- package/internal/validators/operation/organizations.d.ts +0 -88
- package/internal/validators/operation/principals.d.ts +0 -16
- package/internal/validators/request/blob.d.ts +0 -12
- package/internal/validators/request/container.d.ts +0 -16
- package/internal/validators/request/container.js +0 -2
- package/internal/validators/request/container.js.map +1 -1
- package/internal/validators/request/containerMetadata.d.ts +0 -20
- package/internal/validators/request/document.d.ts +0 -22
- package/internal/validators/request/document.js +0 -1
- package/internal/validators/request/document.js.map +1 -1
- package/internal/validators/request/documentSyncSchema.d.ts +0 -4
- package/internal/validators/request/documentSyncSchema.js +0 -1
- package/internal/validators/request/documentSyncSchema.js.map +1 -1
- package/internal/validators/request/organization.d.ts +0 -16
- package/internal/validators/request/organizationProvisioning.d.ts +0 -242
- package/internal/validators/request/principal.d.ts +0 -20
- package/internal/validators/request/registration.d.ts +0 -76
- package/internal/validators/response/areas/auth.d.ts +1 -1
- package/internal/validators/response/areas/auth.js +1 -1
- package/internal/validators/response/areas/auth.js.map +1 -1
- package/internal/validators/response/container.d.ts +8 -0
- package/internal/validators/response/container.js +1 -0
- package/internal/validators/response/container.js.map +1 -1
- package/internal/validators/response/containerParentLanes.d.ts +2 -0
- package/internal/validators/response/documentSyncSchema.d.ts +5 -0
- package/internal/validators/response/documentSyncSchema.js +1 -1
- package/internal/validators/response/documentSyncSchema.js.map +1 -1
- package/internal/validators/response/registration.d.ts +17 -1
- package/internal/validators/response/registration.js +31 -2
- package/internal/validators/response/registration.js.map +1 -1
- package/package.json +1 -1
- package/stores/container-contents/containerContentsStore.js +2 -0
- package/stores/container-contents/containerContentsStore.js.map +1 -1
- package/stores/container-contents/hydration/startupHydration.js +6 -2
- package/stores/container-contents/hydration/startupHydration.js.map +1 -1
- package/stores/container-contents/state.js +5 -1
- package/stores/container-contents/state.js.map +1 -1
- package/stores/container-contents/syncAgent/metadataRevalidation.js +79 -0
- package/stores/container-contents/syncAgent/metadataRevalidation.js.map +1 -0
- package/stores/container-contents/syncAgent/syncAgentTypes.d.ts +6 -0
- package/stores/container-contents/syncAgent/syncAgentTypes.js.map +1 -1
- package/stores/container-contents/syncAgent/syncLaneIteration.js +110 -23
- package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -1
- package/workflows/container-contents/container-state/move/acceptedMoveSettlement.js +3 -0
- package/workflows/container-contents/container-state/move/acceptedMoveSettlement.js.map +1 -1
- package/workflows/container-contents/container-state/remote.js +3 -0
- package/workflows/container-contents/container-state/remote.js.map +1 -1
- package/workflows/container-contents/containerPersistence.d.ts +1 -0
- package/workflows/container-contents/containerPersistence.js.map +1 -1
- package/workflows/container-contents/metadata/index.js +4 -1
- package/workflows/container-contents/metadata/index.js.map +1 -1
- package/workflows/container-contents/metadata/metadataSyncFollowup.js +9 -0
- package/workflows/container-contents/metadata/metadataSyncFollowup.js.map +1 -1
- package/workflows/container-contents/metadata/metadataTypes.d.ts +2 -0
- package/workflows/container-contents/metadata/metadataTypes.js.map +1 -1
- package/workflows/container-contents/remoteHydration/index.js +9 -0
- package/workflows/container-contents/remoteHydration/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js +31 -0
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/types.d.ts +9 -1
- package/workflows/container-contents/remoteHydration/types.js.map +1 -1
- package/workflows/containers/child/mutationRequestCore.js +1 -1
- package/workflows/containers/child/mutationRequestCore.js.map +1 -1
- package/workflows/containers/child/recitePlan.js +0 -1
- package/workflows/containers/child/recitePlan.js.map +1 -1
- package/workflows/containers/root/create.js +0 -1
- package/workflows/containers/root/create.js.map +1 -1
- package/workflows/documents/linkSet/index.js +0 -1
- package/workflows/documents/linkSet/index.js.map +1 -1
- package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js +17 -10
- package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js.map +1 -1
- package/workflows/registration/organizationCreation/createOrganization.js +3 -0
- package/workflows/registration/organizationCreation/createOrganization.js.map +1 -1
- package/workflows/registration/organizationProvisioningPersistence.d.ts +7 -0
- package/workflows/registration/organizationProvisioningPersistence.js +1 -0
- package/workflows/registration/organizationProvisioningPersistence.js.map +1 -1
- package/workflows/registration/persistRegistrationBootstrap.d.ts +7 -0
- package/workflows/registration/persistRegistrationBootstrap.js +6 -2
- package/workflows/registration/persistRegistrationBootstrap.js.map +1 -1
- package/workflows/registration/provisioningBootstrapBuilders.d.ts +0 -2
- package/workflows/registration/registerIdentity.js +1 -0
- package/workflows/registration/registerIdentity.js.map +1 -1
|
@@ -1728,6 +1728,7 @@ export declare const ContainerSummaryResponseSchema: z.ZodType<{
|
|
|
1728
1728
|
stateHash: string;
|
|
1729
1729
|
version: number;
|
|
1730
1730
|
}[];
|
|
1731
|
+
metadataVersionVector: string;
|
|
1731
1732
|
organizationId: string;
|
|
1732
1733
|
parentId: string | null;
|
|
1733
1734
|
updatedAt: string;
|
|
@@ -1748,6 +1749,7 @@ export declare const ContainerSummaryResponseSchema: z.ZodType<{
|
|
|
1748
1749
|
stateHash: string;
|
|
1749
1750
|
version: number;
|
|
1750
1751
|
}[];
|
|
1752
|
+
metadataVersionVector: string;
|
|
1751
1753
|
organizationId: string;
|
|
1752
1754
|
parentId: string | null;
|
|
1753
1755
|
updatedAt: string;
|
|
@@ -1768,6 +1770,7 @@ export declare const ContainerSummaryResponseSchema: z.ZodType<{
|
|
|
1768
1770
|
stateHash: string;
|
|
1769
1771
|
version: number;
|
|
1770
1772
|
}[];
|
|
1773
|
+
metadataVersionVector: string;
|
|
1771
1774
|
organizationId: string;
|
|
1772
1775
|
parentId: string | null;
|
|
1773
1776
|
updatedAt: string;
|
|
@@ -1788,6 +1791,7 @@ export declare const ContainerSummaryResponseSchema: z.ZodType<{
|
|
|
1788
1791
|
stateHash: string;
|
|
1789
1792
|
version: number;
|
|
1790
1793
|
}[];
|
|
1794
|
+
metadataVersionVector: string;
|
|
1791
1795
|
organizationId: string;
|
|
1792
1796
|
parentId: string | null;
|
|
1793
1797
|
updatedAt: string;
|
|
@@ -1838,6 +1842,7 @@ export declare const ListContainersResponseSchema: z.ZodType<{
|
|
|
1838
1842
|
stateHash: string;
|
|
1839
1843
|
version: number;
|
|
1840
1844
|
}[];
|
|
1845
|
+
metadataVersionVector: string;
|
|
1841
1846
|
organizationId: string;
|
|
1842
1847
|
parentId: string | null;
|
|
1843
1848
|
updatedAt: string;
|
|
@@ -1872,6 +1877,7 @@ export declare const ListContainersResponseSchema: z.ZodType<{
|
|
|
1872
1877
|
stateHash: string;
|
|
1873
1878
|
version: number;
|
|
1874
1879
|
}[];
|
|
1880
|
+
metadataVersionVector: string;
|
|
1875
1881
|
organizationId: string;
|
|
1876
1882
|
parentId: string | null;
|
|
1877
1883
|
updatedAt: string;
|
|
@@ -1906,6 +1912,7 @@ export declare const ListContainersResponseSchema: z.ZodType<{
|
|
|
1906
1912
|
stateHash: string;
|
|
1907
1913
|
version: number;
|
|
1908
1914
|
}[];
|
|
1915
|
+
metadataVersionVector: string;
|
|
1909
1916
|
organizationId: string;
|
|
1910
1917
|
parentId: string | null;
|
|
1911
1918
|
updatedAt: string;
|
|
@@ -1940,6 +1947,7 @@ export declare const ListContainersResponseSchema: z.ZodType<{
|
|
|
1940
1947
|
stateHash: string;
|
|
1941
1948
|
version: number;
|
|
1942
1949
|
}[];
|
|
1950
|
+
metadataVersionVector: string;
|
|
1943
1951
|
organizationId: string;
|
|
1944
1952
|
parentId: string | null;
|
|
1945
1953
|
updatedAt: string;
|
|
@@ -225,6 +225,7 @@ export const ContainerSummaryResponseSchema = loosePlainObject({
|
|
|
225
225
|
metadataAccessStateHash: nonEmptyStringSchema,
|
|
226
226
|
metadataDocumentId: z.string(),
|
|
227
227
|
metadataReferencedPrincipals: arraySchema(ReferencedPrincipalStateResponseSchema),
|
|
228
|
+
metadataVersionVector: z.string(),
|
|
228
229
|
organizationId: z.string(),
|
|
229
230
|
parentId: z.string().nullable(),
|
|
230
231
|
systemSlot: ContainerSystemSlotSchema.nullable().optional(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,sCAAsC,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,kDAAkD,EAAE,MAAM,wCAAwC,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,sCAAsC,EACtC,4BAA4B,EAC5B,mCAAmC,EACnC,mCAAmC,GACpC,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,+CAA+C,EAC/C,yCAAyC,GAC1C,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EACrB,2BAA2B,EAC3B,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,sCAAsC,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,sCAAsC,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,qCAAqC,GAC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AAC1E,CAAC;AAED,MAAM,UAAU,uCAAuC,CACrD,KAAc;IAEd,OAAO,2CAA2C,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC9E,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { containerKekLogSingleKeyringRefinement } from \"../containerReadRefinements\";\nimport { ContainerSystemSlotSchema } from \"../containerSystemSlot\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport { organizationProvisioningContainerKeyringRefinement } from \"../organizationProvisioningRefinements\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n nonNegativeIntegerSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n sha256HexStringSchema,\n} from \"../schema\";\nimport {\n AccessManifestBundleWireResponseSchema,\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT,\n ContainerKekKeyringWireRecordSchema,\n} from \"../util\";\nimport {\n containerWriterProjectionPathKekCountRefinement,\n writerProjectionManifestBundlesRefinement,\n} from \"../writerProjectionRefinements\";\nimport { EffectiveAccessLevelSchema } from \"./accessLevel\";\nimport {\n containerKeyingPathReferences,\n ManifestBundlesSchema,\n ManifestHashReferenceSchema,\n OmittedManifestBundlesSchema,\n refineManifestBundleReferences,\n} from \"./manifestBundleReferences\";\nimport { ReferencedPrincipalStateResponseSchema } from \"./principalReference\";\nimport { ProjectionPolicyEvidenceResponseSchema } from \"./projectionPolicyEvidence\";\nimport { SyncWatermarkSchema } from \"./syncWatermark\";\n\n/**\n * The container's sealed predecessor key history. Opening it under the\n * current KEK yields every retained historical KEK in one decrypt; the\n * bridge log behind it is served only by the rebuild read path.\n */\nconst ContainerKekKeyringWireResponseSchema =\n ContainerKekKeyringWireRecordSchema;\n\nexport type ContainerKekKeyringWireResponse = z.infer<\n typeof ContainerKekKeyringWireResponseSchema\n>;\n\nconst containerKekResponseShape = {\n accessManifestHash: nonEmptyStringSchema,\n containerId: z.string(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHistory: arraySchema(AccessManifestBundleWireResponseSchema),\n keyEpoch: plainObjectSchema,\n keyEpochHash: nonEmptyStringSchema,\n keyring: ContainerKekKeyringWireResponseSchema.nullable(),\n keyTargetHash: nonEmptyStringSchema,\n parentContainerKeyEpochId: z.string().nullable(),\n recipientTargets: nonEmptyArraySchema(plainObjectSchema),\n wraps: nonEmptyArraySchema(plainObjectSchema),\n};\n\nfunction refineContainerKekKeyring(\n value: { readonly containerKeyEpoch: number; readonly keyring: unknown },\n context: z.RefinementCtx,\n) {\n if ((value.keyring === null) !== (value.containerKeyEpoch === 1)) {\n context.addIssue({\n code: \"custom\",\n message: \"container keyring must be null exactly at epoch 1\",\n path: [\"keyring\"],\n });\n }\n}\n\nconst ContainerKekResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKekResponseShape).superRefine(\n refineContainerKekKeyring,\n ),\n [organizationProvisioningContainerKeyringRefinement],\n);\n\n/** On the writer-projection wire, KEK history cites manifests by hash. */\nconst ContainerKekWireResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...containerKekResponseShape,\n containerManifestHistory: arraySchema(ManifestHashReferenceSchema),\n }).superRefine(refineContainerKekKeyring),\n [organizationProvisioningContainerKeyringRefinement],\n);\n\nexport type ContainerKekResponse = z.infer<typeof ContainerKekResponseSchema>;\n\n/** One KEK level as served in full, its manifest history cited by hash. */\nexport type ContainerKekWireLevel = z.infer<\n typeof ContainerKekWireResponseSchema\n>;\n\nexport function isContainerKekWireLevel(\n value: unknown,\n): value is ContainerKekWireLevel {\n return (\n ContainerKekWireResponseSchema.safeParse(value).success &&\n !Object.hasOwn(Object(value), \"levelDigest\")\n );\n}\n\n/**\n * A KEK level the request declared held (`k:` hint), replaced by the\n * domain-separated digest of its canonical wire bytes. It keeps the level's manifest citations, so\n * the response's bundle bookkeeping stays exact; the client refills the\n * level from those exact held bytes before anything reads it.\n */\nexport const CitedContainerKekLevelSchema = z.strictObject({\n levelDigest: sha256HexStringSchema,\n containerManifestHistory: arraySchema(ManifestHashReferenceSchema),\n});\n\nexport type CitedContainerKekLevel = z.infer<\n typeof CitedContainerKekLevelSchema\n>;\n\nexport function isCitedContainerKekLevel(\n value: unknown,\n): value is CitedContainerKekLevel {\n return CitedContainerKekLevelSchema.safeParse(value).success;\n}\n\nconst ServedContainerKekLevelSchema = z.union([\n CitedContainerKekLevelSchema,\n ContainerKekWireResponseSchema,\n]);\n\n/**\n * The append-only rotation log for one container: every epoch with its\n * write-once bridge and sealed keyring. This is the rebuild/repair read\n * path — hot reads use the projection keyring instead.\n */\nexport const ContainerKekLogEpochResponseSchema = loosePlainObject({\n accessManifestHash: nonEmptyStringSchema,\n bridge: plainObjectSchema.nullable(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n keyring: ContainerKekKeyringWireResponseSchema.nullable(),\n parentContainerKeyEpochId: z.string().nullable(),\n /**\n * Retained recipient envelopes are the recovery backstop when a bridge is\n * severed. The server and response guard apply this bound per epoch.\n */\n wraps: arraySchema(plainObjectSchema, CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT),\n});\n\nexport type ContainerKekLogEpochResponse = z.infer<\n typeof ContainerKekLogEpochResponseSchema\n>;\n\nexport const ContainerKekLogResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n containerId: nonEmptyStringSchema,\n epochs: arraySchema(\n ContainerKekLogEpochResponseSchema,\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n ),\n /** True when epochs above this page's last remain unserved. */\n hasMore: z.boolean(),\n }).superRefine(({ epochs }, context) => {\n if (epochs.filter((epoch) => epoch.keyring !== null).length > 1) {\n context.addIssue({\n code: \"custom\",\n message: \"container KEK log pages contain at most one keyring\",\n path: [\"epochs\"],\n });\n }\n }),\n [containerKekLogSingleKeyringRefinement],\n );\n\nexport type ContainerKekLogResponse = z.infer<\n typeof ContainerKekLogResponseSchema\n>;\n\nexport function isContainerKekLogResponse(\n value: unknown,\n): value is ContainerKekLogResponse {\n return ContainerKekLogResponseSchema.safeParse(value).success;\n}\n\n/**\n * A container mutation's acknowledgement names what the server committed by\n * hash and adds only the fields it assigned (timestamps). The client compares\n * the hashes with its own signed plan and persists state built from the plan,\n * so the signed event, manifest, state, key epoch, and wraps are never echoed.\n * `bundleDigest` names the bundle a writer projection would serve for the new\n * head, so the author can hold exactly those bytes for later citation.\n */\nconst ContainerManifestMutationResponseShape = {\n bundleDigest: sha256HexStringSchema,\n containerId: z.string(),\n createdAt: z.string(),\n eventHash: nonEmptyStringSchema,\n manifestHead: loosePlainObject({\n epoch: z.number(),\n manifestHash: z.string(),\n }),\n organizationId: z.string(),\n parentId: z.string().nullable(),\n systemSlot: ContainerSystemSlotSchema.nullable().optional(),\n updatedAt: z.string(),\n};\n\n/** The committed key epoch, by hash: no epoch, wrap, or keyring bytes. */\nconst ContainerMutationKekAcknowledgementSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n keyEpochHash: nonEmptyStringSchema,\n keyringHash: nonEmptyStringSchema.nullable(),\n keyTargetHash: nonEmptyStringSchema,\n parentContainerKeyEpochId: z.string().nullable(),\n }).superRefine((value, context) => {\n if ((value.keyringHash === null) !== (value.containerKeyEpoch === 1)) {\n context.addIssue({\n code: \"custom\",\n message: \"container keyring hash must be null exactly at epoch 1\",\n path: [\"keyringHash\"],\n });\n }\n }),\n [organizationProvisioningContainerKeyringRefinement],\n );\n\nconst containerMutationResponseShape = {\n ...ContainerManifestMutationResponseShape,\n containerKek: ContainerMutationKekAcknowledgementSchema,\n};\n\nexport const ContainerMutationResponseSchema = loosePlainObject(\n containerMutationResponseShape,\n);\n\nexport type ContainerMutationResponse = z.infer<\n typeof ContainerMutationResponseSchema\n>;\n\n/** A rotation's acknowledgement, plus one per carried rekey in request order. */\nexport const ContainerRotationResponseSchema = loosePlainObject({\n ...containerMutationResponseShape,\n containerRekeys: arraySchema(ContainerMutationResponseSchema).optional(),\n});\n\nexport type ContainerRotationResponse = z.infer<\n typeof ContainerRotationResponseSchema\n>;\n\nexport function isContainerRotationResponse(\n value: unknown,\n): value is ContainerRotationResponse {\n return ContainerRotationResponseSchema.safeParse(value).success;\n}\n\nexport const ContainerReciteResponseSchema = loosePlainObject(\n ContainerManifestMutationResponseShape,\n);\nexport type ContainerReciteResponse = z.infer<\n typeof ContainerReciteResponseSchema\n>;\n\nexport function isContainerReciteResponse(\n value: unknown,\n): value is ContainerReciteResponse {\n return ContainerReciteResponseSchema.safeParse(value).success;\n}\n\nexport const ContainerDeleteResponseSchema = loosePlainObject({\n containerId: z.string(),\n deletedAt: z.string(),\n});\n\nexport type ContainerDeleteResponse = z.infer<\n typeof ContainerDeleteResponseSchema\n>;\n\nexport const CONTAINER_PROJECTION_STATE_INVALID_ERROR_CODE =\n \"container_projection_state_invalid\";\nexport const ContainerWriterProjectionErrorResponseSchema = loosePlainObject({\n code: z.literal(CONTAINER_PROJECTION_STATE_INVALID_ERROR_CODE),\n error: z.string(),\n});\n\nconst containerKeyingPathShape = {\n containerId: z.string(),\n containerKeks: arraySchema(ContainerKekResponseSchema),\n organizationId: z.string(),\n path: nonEmptyArraySchema(AccessManifestBundleWireResponseSchema),\n};\nfunction refineContainerKeyingPath(\n projection: { containerKeks: unknown[]; path: unknown[] },\n context: z.RefinementCtx,\n) {\n // loosePlainObject can continue refinements after reporting malformed fields.\n if (\n Array.isArray(projection.containerKeks) &&\n Array.isArray(projection.path) &&\n projection.containerKeks.length !== projection.path.length\n )\n context.addIssue({\n code: \"custom\",\n message: \"container KEK count must match the manifest path length\",\n path: [\"containerKeks\"],\n });\n}\nexport const ContainerKeyingPathResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKeyingPathShape).superRefine(\n refineContainerKeyingPath,\n ),\n [containerWriterProjectionPathKekCountRefinement],\n );\nexport type ContainerKeyingPathResponse = z.infer<\n typeof ContainerKeyingPathResponseSchema\n>;\n/**\n * The decoded projection a client verifies: every manifest position holds\n * its bundle. `decodeContainerWriterProjection` builds it from the wire.\n */\nexport const ContainerWriterProjectionResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...containerKeyingPathShape,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n }).superRefine(refineContainerKeyingPath),\n [containerWriterProjectionPathKekCountRefinement],\n );\n\nexport type ContainerWriterProjectionResponse = z.infer<\n typeof ContainerWriterProjectionResponseSchema\n>;\n\nconst containerKeyingPathWireShape = {\n containerId: z.string(),\n containerKeks: arraySchema(ServedContainerKekLevelSchema),\n organizationId: z.string(),\n path: nonEmptyArraySchema(ManifestHashReferenceSchema),\n};\nexport const ContainerKeyingPathWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKeyingPathWireShape).superRefine(\n refineContainerKeyingPath,\n ),\n [containerWriterProjectionPathKekCountRefinement],\n );\nexport type ContainerKeyingPathWireResponse = z.infer<\n typeof ContainerKeyingPathWireResponseSchema\n>;\n\n/**\n * The served shape: manifest positions cite `bundles` by hash, except hashes\n * the request declared already held, which `omittedBundles` lists instead.\n */\nexport const ContainerWriterProjectionWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n bundles: ManifestBundlesSchema,\n omittedBundles: OmittedManifestBundlesSchema,\n ...containerKeyingPathWireShape,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n }).superRefine((projection, context) => {\n refineContainerKeyingPath(projection, context);\n refineManifestBundleReferences(\n projection,\n containerKeyingPathReferences(projection),\n context,\n );\n }),\n [\n containerWriterProjectionPathKekCountRefinement,\n writerProjectionManifestBundlesRefinement,\n ],\n );\n\nexport type ContainerWriterProjectionWireResponse = z.infer<\n typeof ContainerWriterProjectionWireResponseSchema\n>;\n\nexport const ContainerSummaryResponseSchema = loosePlainObject({\n createdAt: z.string(),\n depth: nonNegativeIntegerSchema,\n effectiveAccessLevel: EffectiveAccessLevelSchema,\n id: z.string(),\n metadataAccessEpoch: z.number(),\n metadataAccessStateHash: nonEmptyStringSchema,\n metadataDocumentId: z.string(),\n metadataReferencedPrincipals: arraySchema(\n ReferencedPrincipalStateResponseSchema,\n ),\n organizationId: z.string(),\n parentId: z.string().nullable(),\n systemSlot: ContainerSystemSlotSchema.nullable().optional(),\n updatedAt: z.string(),\n});\n\nexport type ContainerSummary = z.infer<typeof ContainerSummaryResponseSchema>;\n\nexport const ContainerSyncTombstoneResponseSchema = loosePlainObject({\n containerId: z.string(),\n depth: nonNegativeIntegerSchema,\n parentId: z.string().nullable(),\n reason: z.literal([\"access_revoked\", \"deleted\"]),\n updatedAt: z.string(),\n});\n\nexport type ContainerSyncTombstone = z.infer<\n typeof ContainerSyncTombstoneResponseSchema\n>;\n\nexport const ListContainersResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n items: arraySchema(ContainerSummaryResponseSchema),\n nextWatermark: SyncWatermarkSchema.nullable(),\n tombstones: arraySchema(ContainerSyncTombstoneResponseSchema),\n});\n\nexport type ListContainersResponse = z.infer<\n typeof ListContainersResponseSchema\n>;\n\nexport function isListContainersResponse(\n value: unknown,\n): value is ListContainersResponse {\n return ListContainersResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerMutationResponse(\n value: unknown,\n): value is ContainerMutationResponse {\n return ContainerMutationResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerDeleteResponse(\n value: unknown,\n): value is ContainerDeleteResponse {\n return ContainerDeleteResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerWriterProjectionResponse(\n value: unknown,\n): value is ContainerWriterProjectionResponse {\n return ContainerWriterProjectionResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerWriterProjectionWireResponse(\n value: unknown,\n): value is ContainerWriterProjectionWireResponse {\n return ContainerWriterProjectionWireResponseSchema.safeParse(value).success;\n}\n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"../containerReadRefinements\";\nimport { ContainerSystemSlotSchema } from \"../containerSystemSlot\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport { organizationProvisioningContainerKeyringRefinement } from \"../organizationProvisioningRefinements\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n nonNegativeIntegerSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n sha256HexStringSchema,\n} from \"../schema\";\nimport {\n AccessManifestBundleWireResponseSchema,\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT,\n ContainerKekKeyringWireRecordSchema,\n} from \"../util\";\nimport {\n containerWriterProjectionPathKekCountRefinement,\n writerProjectionManifestBundlesRefinement,\n} from \"../writerProjectionRefinements\";\nimport { EffectiveAccessLevelSchema } from \"./accessLevel\";\nimport {\n containerKeyingPathReferences,\n ManifestBundlesSchema,\n ManifestHashReferenceSchema,\n OmittedManifestBundlesSchema,\n refineManifestBundleReferences,\n} from \"./manifestBundleReferences\";\nimport { ReferencedPrincipalStateResponseSchema } from \"./principalReference\";\nimport { ProjectionPolicyEvidenceResponseSchema } from \"./projectionPolicyEvidence\";\nimport { SyncWatermarkSchema } from \"./syncWatermark\";\n\n/**\n * The container's sealed predecessor key history. Opening it under the\n * current KEK yields every retained historical KEK in one decrypt; the\n * bridge log behind it is served only by the rebuild read path.\n */\nconst ContainerKekKeyringWireResponseSchema =\n ContainerKekKeyringWireRecordSchema;\n\nexport type ContainerKekKeyringWireResponse = z.infer<\n typeof ContainerKekKeyringWireResponseSchema\n>;\n\nconst containerKekResponseShape = {\n accessManifestHash: nonEmptyStringSchema,\n containerId: z.string(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHistory: arraySchema(AccessManifestBundleWireResponseSchema),\n keyEpoch: plainObjectSchema,\n keyEpochHash: nonEmptyStringSchema,\n keyring: ContainerKekKeyringWireResponseSchema.nullable(),\n keyTargetHash: nonEmptyStringSchema,\n parentContainerKeyEpochId: z.string().nullable(),\n recipientTargets: nonEmptyArraySchema(plainObjectSchema),\n wraps: nonEmptyArraySchema(plainObjectSchema),\n};\n\nfunction refineContainerKekKeyring(\n value: { readonly containerKeyEpoch: number; readonly keyring: unknown },\n context: z.RefinementCtx,\n) {\n if ((value.keyring === null) !== (value.containerKeyEpoch === 1)) {\n context.addIssue({\n code: \"custom\",\n message: \"container keyring must be null exactly at epoch 1\",\n path: [\"keyring\"],\n });\n }\n}\n\nconst ContainerKekResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKekResponseShape).superRefine(\n refineContainerKekKeyring,\n ),\n [organizationProvisioningContainerKeyringRefinement],\n);\n\n/** On the writer-projection wire, KEK history cites manifests by hash. */\nconst ContainerKekWireResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...containerKekResponseShape,\n containerManifestHistory: arraySchema(ManifestHashReferenceSchema),\n }).superRefine(refineContainerKekKeyring),\n [organizationProvisioningContainerKeyringRefinement],\n);\n\nexport type ContainerKekResponse = z.infer<typeof ContainerKekResponseSchema>;\n\n/** One KEK level as served in full, its manifest history cited by hash. */\nexport type ContainerKekWireLevel = z.infer<\n typeof ContainerKekWireResponseSchema\n>;\n\nexport function isContainerKekWireLevel(\n value: unknown,\n): value is ContainerKekWireLevel {\n return (\n ContainerKekWireResponseSchema.safeParse(value).success &&\n !Object.hasOwn(Object(value), \"levelDigest\")\n );\n}\n\n/**\n * A KEK level the request declared held (`k:` hint), replaced by the\n * domain-separated digest of its canonical wire bytes. It keeps the level's manifest citations, so\n * the response's bundle bookkeeping stays exact; the client refills the\n * level from those exact held bytes before anything reads it.\n */\nexport const CitedContainerKekLevelSchema = z.strictObject({\n levelDigest: sha256HexStringSchema,\n containerManifestHistory: arraySchema(ManifestHashReferenceSchema),\n});\n\nexport type CitedContainerKekLevel = z.infer<\n typeof CitedContainerKekLevelSchema\n>;\n\nexport function isCitedContainerKekLevel(\n value: unknown,\n): value is CitedContainerKekLevel {\n return CitedContainerKekLevelSchema.safeParse(value).success;\n}\n\nconst ServedContainerKekLevelSchema = z.union([\n CitedContainerKekLevelSchema,\n ContainerKekWireResponseSchema,\n]);\n\n/**\n * The append-only rotation log for one container: every epoch with its\n * write-once bridge and sealed keyring. This is the rebuild/repair read\n * path — hot reads use the projection keyring instead.\n */\nexport const ContainerKekLogEpochResponseSchema = loosePlainObject({\n accessManifestHash: nonEmptyStringSchema,\n bridge: plainObjectSchema.nullable(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n keyring: ContainerKekKeyringWireResponseSchema.nullable(),\n parentContainerKeyEpochId: z.string().nullable(),\n /**\n * Retained recipient envelopes are the recovery backstop when a bridge is\n * severed. The server and response guard apply this bound per epoch.\n */\n wraps: arraySchema(plainObjectSchema, CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT),\n});\n\nexport type ContainerKekLogEpochResponse = z.infer<\n typeof ContainerKekLogEpochResponseSchema\n>;\n\nexport const ContainerKekLogResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n containerId: nonEmptyStringSchema,\n epochs: arraySchema(\n ContainerKekLogEpochResponseSchema,\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n ),\n /** True when epochs above this page's last remain unserved. */\n hasMore: z.boolean(),\n }).superRefine(({ epochs }, context) => {\n if (epochs.filter((epoch) => epoch.keyring !== null).length > 1) {\n context.addIssue({\n code: \"custom\",\n message: \"container KEK log pages contain at most one keyring\",\n path: [\"epochs\"],\n });\n }\n }),\n [containerKekLogSingleKeyringRefinement],\n );\n\nexport type ContainerKekLogResponse = z.infer<\n typeof ContainerKekLogResponseSchema\n>;\n\nexport function isContainerKekLogResponse(\n value: unknown,\n): value is ContainerKekLogResponse {\n return ContainerKekLogResponseSchema.safeParse(value).success;\n}\n\n/**\n * A container mutation's acknowledgement names what the server committed by\n * hash and adds only the fields it assigned (timestamps). The client compares\n * the hashes with its own signed plan and persists state built from the plan,\n * so the signed event, manifest, state, key epoch, and wraps are never echoed.\n * `bundleDigest` names the bundle a writer projection would serve for the new\n * head, so the author can hold exactly those bytes for later citation.\n */\nconst ContainerManifestMutationResponseShape = {\n bundleDigest: sha256HexStringSchema,\n containerId: z.string(),\n createdAt: z.string(),\n eventHash: nonEmptyStringSchema,\n manifestHead: loosePlainObject({\n epoch: z.number(),\n manifestHash: z.string(),\n }),\n organizationId: z.string(),\n parentId: z.string().nullable(),\n systemSlot: ContainerSystemSlotSchema.nullable().optional(),\n updatedAt: z.string(),\n};\n\n/** The committed key epoch, by hash: no epoch, wrap, or keyring bytes. */\nconst ContainerMutationKekAcknowledgementSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n keyEpochHash: nonEmptyStringSchema,\n keyringHash: nonEmptyStringSchema.nullable(),\n keyTargetHash: nonEmptyStringSchema,\n parentContainerKeyEpochId: z.string().nullable(),\n }).superRefine((value, context) => {\n if ((value.keyringHash === null) !== (value.containerKeyEpoch === 1)) {\n context.addIssue({\n code: \"custom\",\n message: \"container keyring hash must be null exactly at epoch 1\",\n path: [\"keyringHash\"],\n });\n }\n }),\n [organizationProvisioningContainerKeyringRefinement],\n );\n\nconst containerMutationResponseShape = {\n ...ContainerManifestMutationResponseShape,\n containerKek: ContainerMutationKekAcknowledgementSchema,\n};\n\nexport const ContainerMutationResponseSchema = loosePlainObject(\n containerMutationResponseShape,\n);\n\nexport type ContainerMutationResponse = z.infer<\n typeof ContainerMutationResponseSchema\n>;\n\n/** A rotation's acknowledgement, plus one per carried rekey in request order. */\nexport const ContainerRotationResponseSchema = loosePlainObject({\n ...containerMutationResponseShape,\n containerRekeys: arraySchema(ContainerMutationResponseSchema).optional(),\n});\n\nexport type ContainerRotationResponse = z.infer<\n typeof ContainerRotationResponseSchema\n>;\n\nexport function isContainerRotationResponse(\n value: unknown,\n): value is ContainerRotationResponse {\n return ContainerRotationResponseSchema.safeParse(value).success;\n}\n\nexport const ContainerReciteResponseSchema = loosePlainObject(\n ContainerManifestMutationResponseShape,\n);\nexport type ContainerReciteResponse = z.infer<\n typeof ContainerReciteResponseSchema\n>;\n\nexport function isContainerReciteResponse(\n value: unknown,\n): value is ContainerReciteResponse {\n return ContainerReciteResponseSchema.safeParse(value).success;\n}\n\nexport const ContainerDeleteResponseSchema = loosePlainObject({\n containerId: z.string(),\n deletedAt: z.string(),\n});\n\nexport type ContainerDeleteResponse = z.infer<\n typeof ContainerDeleteResponseSchema\n>;\n\nexport const CONTAINER_PROJECTION_STATE_INVALID_ERROR_CODE =\n \"container_projection_state_invalid\";\nexport const ContainerWriterProjectionErrorResponseSchema = loosePlainObject({\n code: z.literal(CONTAINER_PROJECTION_STATE_INVALID_ERROR_CODE),\n error: z.string(),\n});\n\nconst containerKeyingPathShape = {\n containerId: z.string(),\n containerKeks: arraySchema(ContainerKekResponseSchema),\n organizationId: z.string(),\n path: nonEmptyArraySchema(AccessManifestBundleWireResponseSchema),\n};\nfunction refineContainerKeyingPath(\n projection: { containerKeks: unknown[]; path: unknown[] },\n context: z.RefinementCtx,\n) {\n // loosePlainObject can continue refinements after reporting malformed fields.\n if (\n Array.isArray(projection.containerKeks) &&\n Array.isArray(projection.path) &&\n projection.containerKeks.length !== projection.path.length\n )\n context.addIssue({\n code: \"custom\",\n message: \"container KEK count must match the manifest path length\",\n path: [\"containerKeks\"],\n });\n}\nexport const ContainerKeyingPathResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKeyingPathShape).superRefine(\n refineContainerKeyingPath,\n ),\n [containerWriterProjectionPathKekCountRefinement],\n );\nexport type ContainerKeyingPathResponse = z.infer<\n typeof ContainerKeyingPathResponseSchema\n>;\n/**\n * The decoded projection a client verifies: every manifest position holds\n * its bundle. `decodeContainerWriterProjection` builds it from the wire.\n */\nexport const ContainerWriterProjectionResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...containerKeyingPathShape,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n }).superRefine(refineContainerKeyingPath),\n [containerWriterProjectionPathKekCountRefinement],\n );\n\nexport type ContainerWriterProjectionResponse = z.infer<\n typeof ContainerWriterProjectionResponseSchema\n>;\n\nconst containerKeyingPathWireShape = {\n containerId: z.string(),\n containerKeks: arraySchema(ServedContainerKekLevelSchema),\n organizationId: z.string(),\n path: nonEmptyArraySchema(ManifestHashReferenceSchema),\n};\nexport const ContainerKeyingPathWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKeyingPathWireShape).superRefine(\n refineContainerKeyingPath,\n ),\n [containerWriterProjectionPathKekCountRefinement],\n );\nexport type ContainerKeyingPathWireResponse = z.infer<\n typeof ContainerKeyingPathWireResponseSchema\n>;\n\n/**\n * The served shape: manifest positions cite `bundles` by hash, except hashes\n * the request declared already held, which `omittedBundles` lists instead.\n */\nexport const ContainerWriterProjectionWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n bundles: ManifestBundlesSchema,\n omittedBundles: OmittedManifestBundlesSchema,\n ...containerKeyingPathWireShape,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n }).superRefine((projection, context) => {\n refineContainerKeyingPath(projection, context);\n refineManifestBundleReferences(\n projection,\n containerKeyingPathReferences(projection),\n context,\n );\n }),\n [\n containerWriterProjectionPathKekCountRefinement,\n writerProjectionManifestBundlesRefinement,\n ],\n );\n\nexport type ContainerWriterProjectionWireResponse = z.infer<\n typeof ContainerWriterProjectionWireResponseSchema\n>;\n\nexport const ContainerSummaryResponseSchema = loosePlainObject({\n createdAt: z.string(),\n depth: nonNegativeIntegerSchema,\n effectiveAccessLevel: EffectiveAccessLevelSchema,\n id: z.string(),\n metadataAccessEpoch: z.number(),\n metadataAccessStateHash: nonEmptyStringSchema,\n metadataDocumentId: z.string(),\n metadataReferencedPrincipals: arraySchema(\n ReferencedPrincipalStateResponseSchema,\n ),\n metadataVersionVector: z.string(),\n organizationId: z.string(),\n parentId: z.string().nullable(),\n systemSlot: ContainerSystemSlotSchema.nullable().optional(),\n updatedAt: z.string(),\n});\n\nexport type ContainerSummary = z.infer<typeof ContainerSummaryResponseSchema>;\n\nexport const ContainerSyncTombstoneResponseSchema = loosePlainObject({\n containerId: z.string(),\n depth: nonNegativeIntegerSchema,\n parentId: z.string().nullable(),\n reason: z.literal([\"access_revoked\", \"deleted\"]),\n updatedAt: z.string(),\n});\n\nexport type ContainerSyncTombstone = z.infer<\n typeof ContainerSyncTombstoneResponseSchema\n>;\n\nexport const ListContainersResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n items: arraySchema(ContainerSummaryResponseSchema),\n nextWatermark: SyncWatermarkSchema.nullable(),\n tombstones: arraySchema(ContainerSyncTombstoneResponseSchema),\n});\n\nexport type ListContainersResponse = z.infer<\n typeof ListContainersResponseSchema\n>;\n\nexport function isListContainersResponse(\n value: unknown,\n): value is ListContainersResponse {\n return ListContainersResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerMutationResponse(\n value: unknown,\n): value is ContainerMutationResponse {\n return ContainerMutationResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerDeleteResponse(\n value: unknown,\n): value is ContainerDeleteResponse {\n return ContainerDeleteResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerWriterProjectionResponse(\n value: unknown,\n): value is ContainerWriterProjectionResponse {\n return ContainerWriterProjectionResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerWriterProjectionWireResponse(\n value: unknown,\n): value is ContainerWriterProjectionWireResponse {\n return ContainerWriterProjectionWireResponseSchema.safeParse(value).success;\n}\n"]}
|
|
@@ -20,6 +20,7 @@ export declare const ListContainerParentLanesResponseSchema: z.ZodObject<{
|
|
|
20
20
|
stateHash: string;
|
|
21
21
|
version: number;
|
|
22
22
|
}[];
|
|
23
|
+
metadataVersionVector: string;
|
|
23
24
|
organizationId: string;
|
|
24
25
|
parentId: string | null;
|
|
25
26
|
updatedAt: string;
|
|
@@ -57,6 +58,7 @@ export declare const ListContainerParentLanesResponseSchema: z.ZodObject<{
|
|
|
57
58
|
stateHash: string;
|
|
58
59
|
version: number;
|
|
59
60
|
}[];
|
|
61
|
+
metadataVersionVector: string;
|
|
60
62
|
organizationId: string;
|
|
61
63
|
parentId: string | null;
|
|
62
64
|
updatedAt: string;
|
|
@@ -213,6 +213,11 @@ export declare const commitLsnResponseShape: {
|
|
|
213
213
|
commitLsn: z.ZodNullable<z.ZodString>;
|
|
214
214
|
commitLsnMode: z.ZodUnion<readonly [z.ZodLiteral<"tracked">, z.ZodLiteral<"untracked">]>;
|
|
215
215
|
};
|
|
216
|
+
/** The 0/0 sentinel and the untracked mode imply each other. */
|
|
217
|
+
export declare function addCommitLsnIssues(response: {
|
|
218
|
+
readonly commitLsn: string | null;
|
|
219
|
+
readonly commitLsnMode: "tracked" | "untracked";
|
|
220
|
+
}, context: z.RefinementCtx): void;
|
|
216
221
|
export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
217
222
|
contentKeyBundles: {
|
|
218
223
|
contentKeyEpoch: number;
|
|
@@ -100,7 +100,7 @@ export const commitLsnResponseShape = {
|
|
|
100
100
|
commitLsnMode: z.union([z.literal("tracked"), z.literal("untracked")]),
|
|
101
101
|
};
|
|
102
102
|
/** The 0/0 sentinel and the untracked mode imply each other. */
|
|
103
|
-
function addCommitLsnIssues(response, context) {
|
|
103
|
+
export function addCommitLsnIssues(response, context) {
|
|
104
104
|
if (response.commitLsnMode === "untracked" && response.commitLsn !== "0/0") {
|
|
105
105
|
context.addIssue({
|
|
106
106
|
code: "custom",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentSyncSchema.js","sourceRoot":"","sources":["documentSyncSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,oCAAoC,EACpC,gDAA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C,QAAQ,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,KAAK,IAAI,CAAC,EACrE,CAAC;QACD,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,+CAA+C;YACxD,IAAI,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC;SACjC,CAAC,CAAC;IACL,CAAC;IACD,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,mCAAmC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,EACF;IACE,2CAA2C;IAC3C,+CAA+C;IAC/C,sCAAsC;IACtC,+CAA+C;CAChD,CACF,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n classifyDocumentSyncCheckpointFields,\n DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND,\n} from \"../documentSyncCheckpoint\";\nimport {\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseRotationRefinement,\n} from \"../documentSyncRefinements\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n arraySchema,\n boundedNonEmptyStringSchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport {\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n} from \"../util/documentSyncLimits\";\n\nexport const DocumentContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n wrappedKey: nonEmptyStringSchema,\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type DocumentContentKeyTargetEnvelopeResponse = z.infer<\n typeof DocumentContentKeyTargetEnvelopeResponseSchema\n>;\n\nconst DocumentContentKeyTargetResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n});\n\nexport const DocumentKekTargetsResponseSchema = loosePlainObject({\n documentId: z.string(),\n documentKeyTargetHash: nonEmptyStringSchema,\n linkedContainerKeyEpochIds: nonEmptyArraySchema(nonEmptyStringSchema),\n linkedContainerManifestHashes: nonEmptyArraySchema(nonEmptyStringSchema),\n linkSetManifestHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(plainObjectSchema),\n});\n\nexport type DocumentKekTargetsResponse = z.infer<\n typeof DocumentKekTargetsResponseSchema\n>;\n\nexport const DocumentContentKeyBundleResponseSchema = loosePlainObject({\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n linkSetManifestHash: nonEmptyStringSchema,\n targetHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(DocumentContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type DocumentContentKeyBundleResponse = z.infer<\n typeof DocumentContentKeyBundleResponseSchema\n>;\n\nexport const DocumentSyncUpdateResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n accessEpoch: positiveIntegerSchema,\n authorizationTargets: nonEmptyArraySchema(\n DocumentContentKeyTargetResponseSchema,\n ).optional(),\n authorFingerprint: z.string(),\n checkpointKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND)\n .optional(),\n checkpointPayloadKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND)\n .optional(),\n createdAt: z.string(),\n documentId: z.string(),\n encryptedData: z.string(),\n id: z.string(),\n partialEndVersionVector: z.string(),\n partialStartVersionVector: z.string(),\n plaintextHash: nonEmptyStringSchema,\n sourceVersionVector: z.string().min(1).optional(),\n writeHeader: plainObjectSchema,\n }).superRefine((update, context) => {\n if (classifyDocumentSyncCheckpointFields(update) === \"invalid\") {\n context.addIssue({\n code: \"custom\",\n message: DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n });\n }\n }),\n [documentSyncResponseRotationRefinement],\n );\n\nexport type DocumentSyncUpdateResponse = z.infer<\n typeof DocumentSyncUpdateResponseSchema\n>;\n\nexport const DocumentSyncPullPageResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n nextCursor: boundedNonEmptyStringSchema(\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n ).nullable(),\n});\n\nexport type DocumentSyncPullPageResponse = z.infer<\n typeof DocumentSyncPullPageResponseSchema\n>;\n\nfunction contentKeyEpochOf(bundle: unknown): number | null {\n if (typeof bundle !== \"object\" || bundle === null) return null;\n const contentKeyEpoch: unknown = Reflect.get(bundle, \"contentKeyEpoch\");\n return typeof contentKeyEpoch === \"number\" ? contentKeyEpoch : null;\n}\n\n/**\n * The client already holds the current epoch's bundle, so the array holds the\n * distinct older epochs that served updates cite; the client rejects any epoch\n * not older than the one it planned against. Field issues do not stop this\n * object refinement, so it judges only epochs that parsed.\n */\nfunction addHistoricalContentKeyBundleIssues(\n response: { readonly contentKeyBundles: unknown },\n context: z.RefinementCtx,\n): void {\n if (!Array.isArray(response.contentKeyBundles)) return;\n const seenEpochs = new Set<number>();\n // forEach skips holes exactly as arraySchema's item validation does.\n response.contentKeyBundles.forEach((bundle: unknown, index: number) => {\n const contentKeyEpoch = contentKeyEpochOf(bundle);\n if (contentKeyEpoch === null) return;\n if (seenEpochs.has(contentKeyEpoch)) {\n context.addIssue({\n code: \"custom\",\n message: \"content-key bundles must be distinct epochs\",\n path: [\"contentKeyBundles\", index, \"contentKeyEpoch\"],\n });\n }\n seenEpochs.add(contentKeyEpoch);\n });\n}\n\nexport const commitLsnResponseShape = {\n commitLsn: z.string().nullable(),\n commitLsnMode: z.union([z.literal(\"tracked\"), z.literal(\"untracked\")]),\n};\n\n/** The 0/0 sentinel and the untracked mode imply each other. */\nfunction addCommitLsnIssues(\n response: {\n readonly commitLsn: string | null;\n readonly commitLsnMode: \"tracked\" | \"untracked\";\n },\n context: z.RefinementCtx,\n): void {\n if (response.commitLsnMode === \"untracked\" && response.commitLsn !== \"0/0\") {\n context.addIssue({\n code: \"custom\",\n message: \"untracked commit LSN must use the 0/0 sentinel\",\n path: [\"commitLsn\"],\n });\n }\n if (response.commitLsn === \"0/0\" && response.commitLsnMode !== \"untracked\") {\n context.addIssue({\n code: \"custom\",\n message: \"0/0 commit LSN must be declared untracked\",\n path: [\"commitLsnMode\"],\n });\n }\n}\n\nexport const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n acceptedOutgoingUpdateIds: arraySchema(\n z.string(),\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n ),\n ...commitLsnResponseShape,\n contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),\n documentId: z.string(),\n pullPage: DocumentSyncPullPageResponseSchema,\n updates: arraySchema(\n DocumentSyncUpdateResponseSchema,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n ),\n }).superRefine((response, context) => {\n if (\n response.pullPage !== undefined &&\n response.pullPage.hasMore !== (response.pullPage.nextCursor !== null)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"pull page continuation does not match hasMore\",\n path: [\"pullPage\", \"nextCursor\"],\n });\n }\n addCommitLsnIssues(response, context);\n addHistoricalContentKeyBundleIssues(response, context);\n }),\n [\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n ],\n);\n\nexport type DocumentSyncResponse = z.infer<typeof DocumentSyncResponseSchema>;\n"]}
|
|
1
|
+
{"version":3,"file":"documentSyncSchema.js","sourceRoot":"","sources":["documentSyncSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,oCAAoC,EACpC,gDAAgD,EAChD,sCAAsC,EACtC,8CAA8C,GAC/C,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,2CAA2C,EAC3C,+CAA+C,EAC/C,+CAA+C,EAC/C,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,kCAAkC,EAClC,oCAAoC,EACpC,uCAAuC,GACxC,MAAM,4BAA4B,CAAC;AAEpC,MAAM,CAAC,MAAM,8CAA8C,GAAG,gBAAgB,CAAC;IAC7E,WAAW,EAAE,oBAAoB;IACjC,iBAAiB,EAAE,qBAAqB;IACxC,mBAAmB,EAAE,oBAAoB;IACzC,qBAAqB,EAAE,oBAAoB;IAC3C,UAAU,EAAE,oBAAoB;IAChC,gBAAgB,EAAE,iBAAiB;CACpC,CAAC,CAAC;AAMH,MAAM,sCAAsC,GAAG,gBAAgB,CAAC;IAC9D,WAAW,EAAE,oBAAoB;IACjC,iBAAiB,EAAE,qBAAqB;IACxC,mBAAmB,EAAE,oBAAoB;IACzC,qBAAqB,EAAE,oBAAoB;CAC5C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAAG,gBAAgB,CAAC;IAC/D,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,qBAAqB,EAAE,oBAAoB;IAC3C,0BAA0B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AE,CAAC,CAAC,MAAM,EAAE;IACtB,QAAQ,EAAE,kCAAkC;IAC5C,OAAO,EAAE,WAAW,CAClB,gCAAgC,EAChC,uCAAuC,CACxC;CACF,CAAC,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;IACnC,IACE,QAAQ,CAAC,QAAQ,KAAK,SAAS;QAC/B,QAAQ,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,KAAK,IAAI,CAAC,EACrE,CAAC;QACD,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,+CAA+C;YACxD,IAAI,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC;SACjC,CAAC,CAAC;IACL,CAAC;IACD,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,mCAAmC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,EACF;IACE,2CAA2C;IAC3C,+CAA+C;IAC/C,sCAAsC;IACtC,+CAA+C;CAChD,CACF,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n classifyDocumentSyncCheckpointFields,\n DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND,\n} from \"../documentSyncCheckpoint\";\nimport {\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseRotationRefinement,\n} from \"../documentSyncRefinements\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n arraySchema,\n boundedNonEmptyStringSchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport {\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n} from \"../util/documentSyncLimits\";\n\nexport const DocumentContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n wrappedKey: nonEmptyStringSchema,\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type DocumentContentKeyTargetEnvelopeResponse = z.infer<\n typeof DocumentContentKeyTargetEnvelopeResponseSchema\n>;\n\nconst DocumentContentKeyTargetResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n});\n\nexport const DocumentKekTargetsResponseSchema = loosePlainObject({\n documentId: z.string(),\n documentKeyTargetHash: nonEmptyStringSchema,\n linkedContainerKeyEpochIds: nonEmptyArraySchema(nonEmptyStringSchema),\n linkedContainerManifestHashes: nonEmptyArraySchema(nonEmptyStringSchema),\n linkSetManifestHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(plainObjectSchema),\n});\n\nexport type DocumentKekTargetsResponse = z.infer<\n typeof DocumentKekTargetsResponseSchema\n>;\n\nexport const DocumentContentKeyBundleResponseSchema = loosePlainObject({\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n linkSetManifestHash: nonEmptyStringSchema,\n targetHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(DocumentContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type DocumentContentKeyBundleResponse = z.infer<\n typeof DocumentContentKeyBundleResponseSchema\n>;\n\nexport const DocumentSyncUpdateResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n accessEpoch: positiveIntegerSchema,\n authorizationTargets: nonEmptyArraySchema(\n DocumentContentKeyTargetResponseSchema,\n ).optional(),\n authorFingerprint: z.string(),\n checkpointKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND)\n .optional(),\n checkpointPayloadKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND)\n .optional(),\n createdAt: z.string(),\n documentId: z.string(),\n encryptedData: z.string(),\n id: z.string(),\n partialEndVersionVector: z.string(),\n partialStartVersionVector: z.string(),\n plaintextHash: nonEmptyStringSchema,\n sourceVersionVector: z.string().min(1).optional(),\n writeHeader: plainObjectSchema,\n }).superRefine((update, context) => {\n if (classifyDocumentSyncCheckpointFields(update) === \"invalid\") {\n context.addIssue({\n code: \"custom\",\n message: DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n });\n }\n }),\n [documentSyncResponseRotationRefinement],\n );\n\nexport type DocumentSyncUpdateResponse = z.infer<\n typeof DocumentSyncUpdateResponseSchema\n>;\n\nexport const DocumentSyncPullPageResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n nextCursor: boundedNonEmptyStringSchema(\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n ).nullable(),\n});\n\nexport type DocumentSyncPullPageResponse = z.infer<\n typeof DocumentSyncPullPageResponseSchema\n>;\n\nfunction contentKeyEpochOf(bundle: unknown): number | null {\n if (typeof bundle !== \"object\" || bundle === null) return null;\n const contentKeyEpoch: unknown = Reflect.get(bundle, \"contentKeyEpoch\");\n return typeof contentKeyEpoch === \"number\" ? contentKeyEpoch : null;\n}\n\n/**\n * The client already holds the current epoch's bundle, so the array holds the\n * distinct older epochs that served updates cite; the client rejects any epoch\n * not older than the one it planned against. Field issues do not stop this\n * object refinement, so it judges only epochs that parsed.\n */\nfunction addHistoricalContentKeyBundleIssues(\n response: { readonly contentKeyBundles: unknown },\n context: z.RefinementCtx,\n): void {\n if (!Array.isArray(response.contentKeyBundles)) return;\n const seenEpochs = new Set<number>();\n // forEach skips holes exactly as arraySchema's item validation does.\n response.contentKeyBundles.forEach((bundle: unknown, index: number) => {\n const contentKeyEpoch = contentKeyEpochOf(bundle);\n if (contentKeyEpoch === null) return;\n if (seenEpochs.has(contentKeyEpoch)) {\n context.addIssue({\n code: \"custom\",\n message: \"content-key bundles must be distinct epochs\",\n path: [\"contentKeyBundles\", index, \"contentKeyEpoch\"],\n });\n }\n seenEpochs.add(contentKeyEpoch);\n });\n}\n\nexport const commitLsnResponseShape = {\n commitLsn: z.string().nullable(),\n commitLsnMode: z.union([z.literal(\"tracked\"), z.literal(\"untracked\")]),\n};\n\n/** The 0/0 sentinel and the untracked mode imply each other. */\nexport function addCommitLsnIssues(\n response: {\n readonly commitLsn: string | null;\n readonly commitLsnMode: \"tracked\" | \"untracked\";\n },\n context: z.RefinementCtx,\n): void {\n if (response.commitLsnMode === \"untracked\" && response.commitLsn !== \"0/0\") {\n context.addIssue({\n code: \"custom\",\n message: \"untracked commit LSN must use the 0/0 sentinel\",\n path: [\"commitLsn\"],\n });\n }\n if (response.commitLsn === \"0/0\" && response.commitLsnMode !== \"untracked\") {\n context.addIssue({\n code: \"custom\",\n message: \"0/0 commit LSN must be declared untracked\",\n path: [\"commitLsnMode\"],\n });\n }\n}\n\nexport const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n acceptedOutgoingUpdateIds: arraySchema(\n z.string(),\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n ),\n ...commitLsnResponseShape,\n contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),\n documentId: z.string(),\n pullPage: DocumentSyncPullPageResponseSchema,\n updates: arraySchema(\n DocumentSyncUpdateResponseSchema,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n ),\n }).superRefine((response, context) => {\n if (\n response.pullPage !== undefined &&\n response.pullPage.hasMore !== (response.pullPage.nextCursor !== null)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"pull page continuation does not match hasMore\",\n path: [\"pullPage\", \"nextCursor\"],\n });\n }\n addCommitLsnIssues(response, context);\n addHistoricalContentKeyBundleIssues(response, context);\n }),\n [\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n ],\n);\n\nexport type DocumentSyncResponse = z.infer<typeof DocumentSyncResponseSchema>;\n"]}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Runtime refinements the registration response adds to provisioning's. */
|
|
3
|
+
export declare const registrationCommitCheckpointRefinements: readonly [{
|
|
4
|
+
readonly description: "commitLsnMode \"untracked\" requires the commitLsn \"0/0\" sentinel";
|
|
5
|
+
readonly id: "response.untracked-commit-lsn-sentinel";
|
|
6
|
+
}, {
|
|
7
|
+
readonly description: "commitLsn \"0/0\" requires commitLsnMode \"untracked\" in the same response";
|
|
8
|
+
readonly id: "response.untracked-commit-lsn-mode";
|
|
9
|
+
}];
|
|
2
10
|
export declare const RegistrationResponseSchema: z.ZodType<{
|
|
3
11
|
challenge: string;
|
|
12
|
+
commitLsn: string | null;
|
|
13
|
+
commitLsnMode: "tracked" | "untracked";
|
|
4
14
|
committedCoreMetadataUpdateIds: string[];
|
|
5
15
|
committedProfileUpdateIds: string[];
|
|
6
16
|
organizationId: string;
|
|
@@ -172,6 +182,8 @@ export declare const RegistrationResponseSchema: z.ZodType<{
|
|
|
172
182
|
rosterProfileDocumentId?: string | undefined;
|
|
173
183
|
}, {
|
|
174
184
|
challenge: string;
|
|
185
|
+
commitLsn: string | null;
|
|
186
|
+
commitLsnMode: "tracked" | "untracked";
|
|
175
187
|
committedCoreMetadataUpdateIds: string[];
|
|
176
188
|
committedProfileUpdateIds: string[];
|
|
177
189
|
organizationId: string;
|
|
@@ -343,6 +355,8 @@ export declare const RegistrationResponseSchema: z.ZodType<{
|
|
|
343
355
|
rosterProfileDocumentId?: string | undefined;
|
|
344
356
|
}, z.core.$ZodTypeInternals<{
|
|
345
357
|
challenge: string;
|
|
358
|
+
commitLsn: string | null;
|
|
359
|
+
commitLsnMode: "tracked" | "untracked";
|
|
346
360
|
committedCoreMetadataUpdateIds: string[];
|
|
347
361
|
committedProfileUpdateIds: string[];
|
|
348
362
|
organizationId: string;
|
|
@@ -514,6 +528,8 @@ export declare const RegistrationResponseSchema: z.ZodType<{
|
|
|
514
528
|
rosterProfileDocumentId?: string | undefined;
|
|
515
529
|
}, {
|
|
516
530
|
challenge: string;
|
|
531
|
+
commitLsn: string | null;
|
|
532
|
+
commitLsnMode: "tracked" | "untracked";
|
|
517
533
|
committedCoreMetadataUpdateIds: string[];
|
|
518
534
|
committedProfileUpdateIds: string[];
|
|
519
535
|
organizationId: string;
|
|
@@ -1,11 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { documentSyncResponseCommitLsnModeRefinement, documentSyncResponseCommitLsnSentinelRefinement, } from "../documentSyncRefinements.js";
|
|
3
|
+
import { registerJsonSchemaFragment, registerJsonSchemaRuntimeRefinements, } from "../jsonSchema.js";
|
|
2
4
|
import { organizationProvisioningCommittedUpdateIdsRefinement } from "../organizationProvisioningRefinements.js";
|
|
3
5
|
import { authChallengeHexStringSchema, loosePlainObject } from "../schema.js";
|
|
6
|
+
import { isWalLsnString, WAL_LSN_PATTERN } from "../util/walLsn.js";
|
|
7
|
+
import { addCommitLsnIssues } from "./documentSyncSchema.js";
|
|
4
8
|
import { addCommittedUpdateIdIssues, organizationProvisioningResponseShape, } from "./organizationProvisioning.js";
|
|
9
|
+
/**
|
|
10
|
+
* The commit position read after the registration transaction, as a document
|
|
11
|
+
* create's seed reports it, so the client records it for every document the
|
|
12
|
+
* registration seeded: a WAL LSN, or null when it could not be read. Only
|
|
13
|
+
* registration reports one; see `docs/client-sync-ordering.md`.
|
|
14
|
+
*/
|
|
15
|
+
const registrationCommitCheckpointShape = {
|
|
16
|
+
commitLsn: registerJsonSchemaFragment(z.string().refine(isWalLsnString), {
|
|
17
|
+
pattern: WAL_LSN_PATTERN.source,
|
|
18
|
+
type: "string",
|
|
19
|
+
}).nullable(),
|
|
20
|
+
commitLsnMode: z.union([z.literal("tracked"), z.literal("untracked")]),
|
|
21
|
+
};
|
|
22
|
+
/** Runtime refinements the registration response adds to provisioning's. */
|
|
23
|
+
export const registrationCommitCheckpointRefinements = [
|
|
24
|
+
documentSyncResponseCommitLsnModeRefinement,
|
|
25
|
+
documentSyncResponseCommitLsnSentinelRefinement,
|
|
26
|
+
];
|
|
5
27
|
export const RegistrationResponseSchema = registerJsonSchemaRuntimeRefinements(loosePlainObject({
|
|
6
28
|
...organizationProvisioningResponseShape,
|
|
29
|
+
...registrationCommitCheckpointShape,
|
|
7
30
|
challenge: authChallengeHexStringSchema,
|
|
8
|
-
}).superRefine(
|
|
31
|
+
}).superRefine((value, context) => {
|
|
32
|
+
addCommittedUpdateIdIssues(value, context);
|
|
33
|
+
addCommitLsnIssues(value, context);
|
|
34
|
+
}), [
|
|
35
|
+
organizationProvisioningCommittedUpdateIdsRefinement,
|
|
36
|
+
...registrationCommitCheckpointRefinements,
|
|
37
|
+
]);
|
|
9
38
|
export function isRegistrationResponse(value) {
|
|
10
39
|
return RegistrationResponseSchema.safeParse(value).success;
|
|
11
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration.js","sourceRoot":"","sources":["registration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registration.js","sourceRoot":"","sources":["registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,2CAA2C,EAC3C,+CAA+C,GAChD,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,0BAA0B,EAC1B,oCAAoC,GACrC,MAAM,eAAe,CAAC;AACvB,OAAO,EA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,CAAC,OAAO,CAAC;AAC7D,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n} from \"../documentSyncRefinements\";\nimport {\n registerJsonSchemaFragment,\n registerJsonSchemaRuntimeRefinements,\n} from \"../jsonSchema\";\nimport { organizationProvisioningCommittedUpdateIdsRefinement } from \"../organizationProvisioningRefinements\";\nimport { authChallengeHexStringSchema, loosePlainObject } from \"../schema\";\nimport { isWalLsnString, WAL_LSN_PATTERN } from \"../util/walLsn\";\nimport { addCommitLsnIssues } from \"./documentSyncSchema\";\nimport {\n addCommittedUpdateIdIssues,\n organizationProvisioningResponseShape,\n} from \"./organizationProvisioning\";\n\n/**\n * The commit position read after the registration transaction, as a document\n * create's seed reports it, so the client records it for every document the\n * registration seeded: a WAL LSN, or null when it could not be read. Only\n * registration reports one; see `docs/client-sync-ordering.md`.\n */\nconst registrationCommitCheckpointShape = {\n commitLsn: registerJsonSchemaFragment(z.string().refine(isWalLsnString), {\n pattern: WAL_LSN_PATTERN.source,\n type: \"string\",\n }).nullable(),\n commitLsnMode: z.union([z.literal(\"tracked\"), z.literal(\"untracked\")]),\n} satisfies z.ZodRawShape;\n\n/** Runtime refinements the registration response adds to provisioning's. */\nexport const registrationCommitCheckpointRefinements = [\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n] as const;\n\nexport const RegistrationResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...organizationProvisioningResponseShape,\n ...registrationCommitCheckpointShape,\n challenge: authChallengeHexStringSchema,\n }).superRefine((value, context) => {\n addCommittedUpdateIdIssues(value, context);\n addCommitLsnIssues(value, context);\n }),\n [\n organizationProvisioningCommittedUpdateIdsRefinement,\n ...registrationCommitCheckpointRefinements,\n ],\n);\n\nexport type RegistrationResponse = z.infer<typeof RegistrationResponseSchema>;\n\nexport function isRegistrationResponse(\n value: unknown,\n): value is RegistrationResponse {\n return RegistrationResponseSchema.safeParse(value).success;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ import { chainRemoteContainerTask } from "./remoteWrites/remoteWriteQueue.js";
|
|
|
15
15
|
import { captureContainerWriteGeneration } from "./remoteWrites/writeGeneration.js";
|
|
16
16
|
import { createContainerContentsStoreState, subscribeToContainerContentsStore, updateContainerContentsSnapshot, updateContainerContentsStorePersistence, updateContainerContentsStoreRuntime, } from "./state.js";
|
|
17
17
|
import { createContainerContentsStoreSyncAgent, } from "./syncAgent/index.js";
|
|
18
|
+
import { oweContainerMetadataRead } from "./syncAgent/metadataRevalidation.js";
|
|
18
19
|
import { findRootContainerState } from "./systemContainers/systemContainerLookup.js";
|
|
19
20
|
const containerContentsStoresByScope = new WeakMap();
|
|
20
21
|
function applyContainerContentsStoreOptions(state, syncAgent, options) {
|
|
@@ -42,6 +43,7 @@ function createContainerContentsStoreSyncHost(state) {
|
|
|
42
43
|
requestDocumentPriming: () => {
|
|
43
44
|
state.documentStoresNeedPriming = true;
|
|
44
45
|
},
|
|
46
|
+
requestMetadataRevalidation: (request) => oweContainerMetadataRead(state, request),
|
|
45
47
|
updateSnapshot: () => updateContainerContentsSnapshot(state),
|
|
46
48
|
};
|
|
47
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"containerContentsStore.js","sourceRoot":"","sources":["containerContentsStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kCAAkC,EAAE,MAAM,oEAAoE,CAAC;AACxH,OAAO,EAEL,mCAAmC,GACpC,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAA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achedContainerWriterProjection } from \"../../workflows/container-contents/container-state/projectionCache\";\nimport {\n type ContainerContentsPersistence,\n defaultContainerContentsPersistence,\n} from \"../../workflows/container-contents/containerPersistence\";\nimport { persistContainerState } from \"./containerState/containerStatePersistence\";\nimport { createTreeRefreshMethods } from \"./hydration/remoteHydrationRefresh\";\nimport {\n createChildContainer,\n deleteContainer,\n ensureSystemContainer,\n moveContainer,\n renameContainer,\n} from \"./operations\";\nimport { emptyTrash } from \"./operations/emptyTrashOperation\";\nimport {\n prepareContainerGroupRewrap,\n verifyContainerGroupRewrapCurrent,\n} from \"./operations/groupRewrapOperation\";\nimport { purgeContainer } from \"./operations/purgeContainerOperation\";\nimport { chainPurgeAfterScopeMoves } from \"./operations/purgeMoveSettlementOperation\";\nimport { setContainerIcon } from \"./operations/setContainerIconOperation\";\nimport { setContainerPrimaryDocument } from \"./operations/setContainerPrimaryDocumentOperation\";\nimport {\n shareContainerWithGroup,\n shareContainerWithUser,\n} from \"./operations/shareOperations\";\nimport { chainContainerWrite } from \"./remoteWrites/localWriteQueue\";\nimport { chainRemoteContainerTask } from \"./remoteWrites/remoteWriteQueue\";\nimport { captureContainerWriteGeneration } from \"./remoteWrites/writeGeneration\";\nimport {\n createContainerContentsStoreState,\n subscribeToContainerContentsStore,\n updateContainerContentsSnapshot,\n updateContainerContentsStorePersistence,\n updateContainerContentsStoreRuntime,\n} from \"./state\";\nimport {\n type ContainerContentsStoreRuntime,\n type ContainerContentsStoreSyncAgent,\n createContainerContentsStoreSyncAgent,\n} from \"./syncAgent\";\nimport { findRootContainerState } from \"./systemContainers/systemContainerLookup\";\nimport type {\n ContainerContentsStore,\n ContainerContentsStoreOptions,\n ContainerContentsStoreState,\n} from \"./types\";\n\nconst containerContentsStoresByScope = new WeakMap<\n DomainScope,\n ContainerContentsStoreEntry\n>();\n\ninterface ContainerContentsStoreEntry {\n requestDocumentPriming: () => void;\n store: ContainerContentsStore;\n updateOptions: (options: ContainerContentsStoreOptions) => void;\n}\n\nfunction applyContainerContentsStoreOptions(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n options: ContainerContentsStoreOptions,\n): void {\n if (\"logLabel\" in options) {\n state.logLabel = options.logLabel;\n }\n\n if (\"persistence\" in options) {\n updateContainerContentsStorePersistence(\n state,\n options.persistence ?? defaultContainerContentsPersistence,\n syncAgent,\n );\n }\n}\n\nfunction getCachedContainerWriterProjectionForStore(\n state: ContainerContentsStoreState,\n containerId: string,\n) {\n const containerState = state.containersById.get(containerId);\n return containerState\n ? getCachedContainerWriterProjection(containerState)\n : null;\n}\n\nfunction createContainerContentsStoreSyncHost(\n state: ContainerContentsStoreState,\n): Parameters<typeof createContainerContentsStoreSyncAgent>[0][\"host\"] {\n return {\n persistContainerState: (\n containerState,\n patch,\n updateView,\n saveOptions,\n mutationOptions,\n ) =>\n persistContainerState(state, containerState, {\n patch,\n updateView,\n saveOptions,\n ...mutationOptions,\n }),\n requestDocumentPriming: () => {\n state.documentStoresNeedPriming = true;\n },\n updateSnapshot: () => updateContainerContentsSnapshot(state),\n };\n}\n\ntype ContainerWriteMethods = Pick<\n ContainerContentsStore,\n | \"createChild\"\n | \"deleteContainer\"\n | \"emptyTrash\"\n | \"ensureSystemContainer\"\n | \"moveContainer\"\n | \"prepareGroupRewrap\"\n | \"purgeContainer\"\n | \"renameContainer\"\n | \"setContainerIcon\"\n | \"setContainerPrimaryDocument\"\n | \"shareWithGroup\"\n | \"shareWithUser\"\n>;\n\n// The group-rewrap builder verifies any required existing grant before capturing\n// the container KEK, then returns a check/rewrap pair. A verified non-match is\n// distinct from an unavailable preparation so security-critical callers can\n// no-op unrelated groups without failing open for a real grant.\nfunction createPrepareGroupRewrapMethod(\n state: ContainerContentsStoreState,\n syncAgent: ReturnType<typeof createContainerContentsStoreSyncAgent>,\n): ContainerContentsStore[\"prepareGroupRewrap\"] {\n return async (containerId, groupId, accessLevel, options) => {\n const preparation = await chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n (isCurrent) =>\n prepareContainerGroupRewrap(\n state,\n containerId,\n groupId,\n accessLevel,\n options,\n isCurrent,\n ),\n containerId,\n );\n return preparation?.status === \"prepared\"\n ? {\n isCurrent: (\n expectedGroupHead,\n expectedContainerId,\n expectedOrganizationId,\n ) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n verifyContainerGroupRewrapCurrent(\n state,\n containerId,\n groupId,\n accessLevel,\n expectedGroupHead,\n expectedContainerId,\n expectedOrganizationId,\n isCurrent,\n ),\n containerId,\n ),\n rewrap: () =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n shareContainerWithGroup(\n state,\n syncAgent,\n containerId,\n groupId,\n accessLevel,\n {\n ...options,\n knownContainerKeks: preparation.knownContainerKeks,\n // A prepared re-wrap is grant-preserving by definition, so\n // it never mints a grant and never needs the chosen name.\n requireExistingGrant: true,\n },\n isCurrent,\n ),\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n status: \"prepared\" as const,\n }\n : (preparation ?? null);\n };\n}\n\nfunction createContainerSharingMethods(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): Pick<ContainerWriteMethods, \"shareWithUser\" | \"shareWithGroup\"> {\n return {\n shareWithUser: (containerId, userId, accessLevel) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n async (isCurrent) => {\n // Sharing admits the recipient, so a pin observed on first sight is\n // not enough: a verified identity link (or this device's keys) must\n // have established it, or the full-bundle signed roster. The\n // check runs inside the write scope, which must still be current\n // once it returns.\n await state.runtime.requireVerifiedRecipient(userId, accessLevel);\n if (!isCurrent()) return false;\n return shareContainerWithUser(\n state,\n syncAgent,\n containerId,\n userId,\n accessLevel,\n isCurrent,\n );\n },\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n shareWithGroup: (containerId, groupId, accessLevel, options) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n shareContainerWithGroup(\n state,\n syncAgent,\n containerId,\n groupId,\n accessLevel,\n options,\n isCurrent,\n ),\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n };\n}\n\nfunction createDeleteContainerMethod(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): ContainerContentsStore[\"deleteContainer\"] {\n return (containerId) => {\n const current = captureContainerWriteGeneration(state);\n const remoteDelete = () =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n (isCurrent) =>\n deleteContainer(state, syncAgent, containerId, isCurrent),\n containerId,\n ).then((node) => node !== null);\n if (state.containersById.get(containerId)?.record.documentId)\n return remoteDelete();\n let promoted = false;\n return chainContainerWrite(\n state,\n (isCurrent) => {\n // Promotion can win while this local operation was queued. Hand it to\n // the remote queue after releasing the local chain, before any HTTP I/O.\n promoted = Boolean(\n state.containersById.get(containerId)?.record.documentId,\n );\n return promoted\n ? Promise.resolve(null)\n : deleteContainer(state, syncAgent, containerId, isCurrent);\n },\n [containerId],\n ).then((node) => (promoted && current() ? remoteDelete() : node !== null));\n };\n}\n\nfunction createEnsureSystemContainerMethod(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): ContainerContentsStore[\"ensureSystemContainer\"] {\n return (systemSlot, name, options) => {\n const work = (isCurrent: () => boolean) =>\n ensureSystemContainer(\n state,\n syncAgent,\n systemSlot,\n name,\n options,\n isCurrent,\n );\n const rootId = findRootContainerState(state)?.container.id;\n return options?.deferRemoteBootstrap\n ? chainContainerWrite(state, work, [])\n : chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n work,\n rootId ? { rootId, systemSlot } : undefined,\n );\n };\n}\n\nexport function createContainerWriteMethods(\n state: ContainerContentsStoreState,\n syncAgent: ReturnType<typeof createContainerContentsStoreSyncAgent>,\n): ContainerWriteMethods {\n return {\n ...createContainerSharingMethods(state, syncAgent),\n createChild: (parentId, name) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n createChildContainer(state, syncAgent, parentId, name, isCurrent),\n [parentId],\n ),\n deleteContainer: createDeleteContainerMethod(state, syncAgent),\n purgeContainer: (containerId, options) =>\n chainPurgeAfterScopeMoves(\n state,\n syncAgent,\n containerId,\n options,\n (isCurrent) =>\n purgeContainer(state, syncAgent, containerId, options, isCurrent),\n ),\n emptyTrash: (trashContainerId, options) =>\n chainPurgeAfterScopeMoves(\n state,\n syncAgent,\n trashContainerId,\n options,\n (isCurrent) =>\n emptyTrash(state, syncAgent, trashContainerId, options, isCurrent),\n ),\n ensureSystemContainer: createEnsureSystemContainerMethod(state, syncAgent),\n moveContainer: (containerId, parentId) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n moveContainer(state, syncAgent, containerId, parentId, isCurrent),\n [containerId, parentId],\n containerId,\n ),\n prepareGroupRewrap: createPrepareGroupRewrapMethod(state, syncAgent),\n renameContainer: (containerId, name) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n renameContainer(state, syncAgent, containerId, name, isCurrent),\n [containerId],\n ),\n setContainerPrimaryDocument: (containerId, documentId) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n setContainerPrimaryDocument(\n state,\n syncAgent,\n containerId,\n documentId,\n isCurrent,\n ),\n [containerId],\n ),\n setContainerIcon: (containerId, icon) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n setContainerIcon(state, syncAgent, containerId, icon, isCurrent),\n [containerId],\n ),\n };\n}\n\nfunction createContainerContentsStoreEntry(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence = defaultContainerContentsPersistence,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStoreEntry {\n const state = createContainerContentsStoreState(\n initialRuntime,\n options.persistence ?? persistence,\n options.logLabel,\n );\n const syncAgent = createContainerContentsStoreSyncAgent({\n host: createContainerContentsStoreSyncHost(state),\n state,\n });\n const writeMethods = createContainerWriteMethods(state, syncAgent);\n\n return {\n requestDocumentPriming: () => {\n state.documentStoresNeedPriming = true;\n syncAgent.scheduleSync();\n },\n store: {\n ...writeMethods,\n ...createTreeRefreshMethods(state, syncAgent),\n // Force an on-demand local SQLite re-read (see the interface doc): arm the\n // gate refreshLocalContainerStates otherwise requires, which the runtime\n // auto-arms only on a context transition an on-demand caller cannot rely on.\n refreshLocalContainers: () => {\n state.localContainersNeedRefresh = true;\n return syncAgent.refreshLocalContainers();\n },\n requestSync: () => syncAgent.scheduleSync(),\n getCachedContainerWriterProjection: (containerId) =>\n getCachedContainerWriterProjectionForStore(state, containerId),\n getSnapshot: () => state.snapshot,\n subscribe: (listener) =>\n subscribeToContainerContentsStore(state, listener),\n updateRuntime: (runtime) =>\n updateContainerContentsStoreRuntime(state, runtime, syncAgent),\n },\n updateOptions: (nextOptions) =>\n applyContainerContentsStoreOptions(state, syncAgent, nextOptions),\n };\n}\n\nexport function createContainerContentsStore(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence = defaultContainerContentsPersistence,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStore {\n return createContainerContentsStoreEntry(initialRuntime, persistence, options)\n .store;\n}\n\nexport function getOrCreateContainerContentsStore(\n domainScope: DomainScope,\n runtime: ContainerContentsStoreRuntime,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStore {\n const existingEntry = containerContentsStoresByScope.get(domainScope);\n if (existingEntry) {\n existingEntry.updateOptions(options);\n return existingEntry.store;\n }\n\n const nextEntry = createContainerContentsStoreEntry(\n runtime,\n defaultContainerContentsPersistence,\n options,\n );\n containerContentsStoresByScope.set(domainScope, nextEntry);\n return nextEntry.store;\n}\n\n/**\n * Arm the next structural pass's document-priming scan for a domain scope.\n * Priming normally re-arms only on store creation and topology changes, so a\n * caller that just tore down a document's local state uses this to have the\n * still-listed server document re-created without waiting for an app\n * restart. Returns false when the scope has no container-contents store yet;\n * the startup priming pass covers that case.\n */\nexport function requestContainerContentsDocumentPriming(\n domainScope: DomainScope,\n): boolean {\n const entry = containerContentsStoresByScope.get(domainScope);\n if (!entry) {\n return false;\n }\n\n entry.requestDocumentPriming();\n return true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"containerContentsStore.js","sourceRoot":"","sources":["containerContentsStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kCAAkC,EAAE,MAAM,oEAAoE,CAAC;AACxH,OAAO,EAEL,mCAAmC,GACpC,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,2BAA2B,EAC3B,iCAAiC,GAClC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AAChG,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EACL,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,uCAAuC,EACvC,mCAAmC,GACpC,MAAM,SAAS,CAAC;AACjB,OAAO,EAGL,qCAAqC,GACtC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,E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,CAAC;QAClB,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACrC,OAAO,aAAa,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED,MAAM,SAAS,GAAG,iCAAiC,CACjD,OAAO,EACP,mCAAmC,EACnC,OAAO,CACR,CAAC;IACF,8BAA8B,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAC3D,OAAO,SAAS,CAAC,KAAK,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uCAAuC,CACrD,WAAwB;IAExB,MAAM,KAAK,GAAG,8BAA8B,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,sBAAsB,EAAE,CAAC;IAC/B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { DomainScope } from \"../../data/shared/domainScope\";\nimport { getCachedContainerWriterProjection } from \"../../workflows/container-contents/container-state/projectionCache\";\nimport {\n type ContainerContentsPersistence,\n defaultContainerContentsPersistence,\n} from \"../../workflows/container-contents/containerPersistence\";\nimport { persistContainerState } from \"./containerState/containerStatePersistence\";\nimport { createTreeRefreshMethods } from \"./hydration/remoteHydrationRefresh\";\nimport {\n createChildContainer,\n deleteContainer,\n ensureSystemContainer,\n moveContainer,\n renameContainer,\n} from \"./operations\";\nimport { emptyTrash } from \"./operations/emptyTrashOperation\";\nimport {\n prepareContainerGroupRewrap,\n verifyContainerGroupRewrapCurrent,\n} from \"./operations/groupRewrapOperation\";\nimport { purgeContainer } from \"./operations/purgeContainerOperation\";\nimport { chainPurgeAfterScopeMoves } from \"./operations/purgeMoveSettlementOperation\";\nimport { setContainerIcon } from \"./operations/setContainerIconOperation\";\nimport { setContainerPrimaryDocument } from \"./operations/setContainerPrimaryDocumentOperation\";\nimport {\n shareContainerWithGroup,\n shareContainerWithUser,\n} from \"./operations/shareOperations\";\nimport { chainContainerWrite } from \"./remoteWrites/localWriteQueue\";\nimport { chainRemoteContainerTask } from \"./remoteWrites/remoteWriteQueue\";\nimport { captureContainerWriteGeneration } from \"./remoteWrites/writeGeneration\";\nimport {\n createContainerContentsStoreState,\n subscribeToContainerContentsStore,\n updateContainerContentsSnapshot,\n updateContainerContentsStorePersistence,\n updateContainerContentsStoreRuntime,\n} from \"./state\";\nimport {\n type ContainerContentsStoreRuntime,\n type ContainerContentsStoreSyncAgent,\n createContainerContentsStoreSyncAgent,\n} from \"./syncAgent\";\nimport { oweContainerMetadataRead } from \"./syncAgent/metadataRevalidation\";\nimport { findRootContainerState } from \"./systemContainers/systemContainerLookup\";\nimport type {\n ContainerContentsStore,\n ContainerContentsStoreOptions,\n ContainerContentsStoreState,\n} from \"./types\";\n\nconst containerContentsStoresByScope = new WeakMap<\n DomainScope,\n ContainerContentsStoreEntry\n>();\n\ninterface ContainerContentsStoreEntry {\n requestDocumentPriming: () => void;\n store: ContainerContentsStore;\n updateOptions: (options: ContainerContentsStoreOptions) => void;\n}\n\nfunction applyContainerContentsStoreOptions(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n options: ContainerContentsStoreOptions,\n): void {\n if (\"logLabel\" in options) {\n state.logLabel = options.logLabel;\n }\n\n if (\"persistence\" in options) {\n updateContainerContentsStorePersistence(\n state,\n options.persistence ?? defaultContainerContentsPersistence,\n syncAgent,\n );\n }\n}\n\nfunction getCachedContainerWriterProjectionForStore(\n state: ContainerContentsStoreState,\n containerId: string,\n) {\n const containerState = state.containersById.get(containerId);\n return containerState\n ? getCachedContainerWriterProjection(containerState)\n : null;\n}\n\nfunction createContainerContentsStoreSyncHost(\n state: ContainerContentsStoreState,\n): Parameters<typeof createContainerContentsStoreSyncAgent>[0][\"host\"] {\n return {\n persistContainerState: (\n containerState,\n patch,\n updateView,\n saveOptions,\n mutationOptions,\n ) =>\n persistContainerState(state, containerState, {\n patch,\n updateView,\n saveOptions,\n ...mutationOptions,\n }),\n requestDocumentPriming: () => {\n state.documentStoresNeedPriming = true;\n },\n requestMetadataRevalidation: (request) =>\n oweContainerMetadataRead(state, request),\n updateSnapshot: () => updateContainerContentsSnapshot(state),\n };\n}\n\ntype ContainerWriteMethods = Pick<\n ContainerContentsStore,\n | \"createChild\"\n | \"deleteContainer\"\n | \"emptyTrash\"\n | \"ensureSystemContainer\"\n | \"moveContainer\"\n | \"prepareGroupRewrap\"\n | \"purgeContainer\"\n | \"renameContainer\"\n | \"setContainerIcon\"\n | \"setContainerPrimaryDocument\"\n | \"shareWithGroup\"\n | \"shareWithUser\"\n>;\n\n// The group-rewrap builder verifies any required existing grant before capturing\n// the container KEK, then returns a check/rewrap pair. A verified non-match is\n// distinct from an unavailable preparation so security-critical callers can\n// no-op unrelated groups without failing open for a real grant.\nfunction createPrepareGroupRewrapMethod(\n state: ContainerContentsStoreState,\n syncAgent: ReturnType<typeof createContainerContentsStoreSyncAgent>,\n): ContainerContentsStore[\"prepareGroupRewrap\"] {\n return async (containerId, groupId, accessLevel, options) => {\n const preparation = await chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n (isCurrent) =>\n prepareContainerGroupRewrap(\n state,\n containerId,\n groupId,\n accessLevel,\n options,\n isCurrent,\n ),\n containerId,\n );\n return preparation?.status === \"prepared\"\n ? {\n isCurrent: (\n expectedGroupHead,\n expectedContainerId,\n expectedOrganizationId,\n ) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n verifyContainerGroupRewrapCurrent(\n state,\n containerId,\n groupId,\n accessLevel,\n expectedGroupHead,\n expectedContainerId,\n expectedOrganizationId,\n isCurrent,\n ),\n containerId,\n ),\n rewrap: () =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n shareContainerWithGroup(\n state,\n syncAgent,\n containerId,\n groupId,\n accessLevel,\n {\n ...options,\n knownContainerKeks: preparation.knownContainerKeks,\n // A prepared re-wrap is grant-preserving by definition, so\n // it never mints a grant and never needs the chosen name.\n requireExistingGrant: true,\n },\n isCurrent,\n ),\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n status: \"prepared\" as const,\n }\n : (preparation ?? null);\n };\n}\n\nfunction createContainerSharingMethods(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): Pick<ContainerWriteMethods, \"shareWithUser\" | \"shareWithGroup\"> {\n return {\n shareWithUser: (containerId, userId, accessLevel) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n async (isCurrent) => {\n // Sharing admits the recipient, so a pin observed on first sight is\n // not enough: a verified identity link (or this device's keys) must\n // have established it, or the full-bundle signed roster. The\n // check runs inside the write scope, which must still be current\n // once it returns.\n await state.runtime.requireVerifiedRecipient(userId, accessLevel);\n if (!isCurrent()) return false;\n return shareContainerWithUser(\n state,\n syncAgent,\n containerId,\n userId,\n accessLevel,\n isCurrent,\n );\n },\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n shareWithGroup: (containerId, groupId, accessLevel, options) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n shareContainerWithGroup(\n state,\n syncAgent,\n containerId,\n groupId,\n accessLevel,\n options,\n isCurrent,\n ),\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n };\n}\n\nfunction createDeleteContainerMethod(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): ContainerContentsStore[\"deleteContainer\"] {\n return (containerId) => {\n const current = captureContainerWriteGeneration(state);\n const remoteDelete = () =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n (isCurrent) =>\n deleteContainer(state, syncAgent, containerId, isCurrent),\n containerId,\n ).then((node) => node !== null);\n if (state.containersById.get(containerId)?.record.documentId)\n return remoteDelete();\n let promoted = false;\n return chainContainerWrite(\n state,\n (isCurrent) => {\n // Promotion can win while this local operation was queued. Hand it to\n // the remote queue after releasing the local chain, before any HTTP I/O.\n promoted = Boolean(\n state.containersById.get(containerId)?.record.documentId,\n );\n return promoted\n ? Promise.resolve(null)\n : deleteContainer(state, syncAgent, containerId, isCurrent);\n },\n [containerId],\n ).then((node) => (promoted && current() ? remoteDelete() : node !== null));\n };\n}\n\nfunction createEnsureSystemContainerMethod(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): ContainerContentsStore[\"ensureSystemContainer\"] {\n return (systemSlot, name, options) => {\n const work = (isCurrent: () => boolean) =>\n ensureSystemContainer(\n state,\n syncAgent,\n systemSlot,\n name,\n options,\n isCurrent,\n );\n const rootId = findRootContainerState(state)?.container.id;\n return options?.deferRemoteBootstrap\n ? chainContainerWrite(state, work, [])\n : chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n work,\n rootId ? { rootId, systemSlot } : undefined,\n );\n };\n}\n\nexport function createContainerWriteMethods(\n state: ContainerContentsStoreState,\n syncAgent: ReturnType<typeof createContainerContentsStoreSyncAgent>,\n): ContainerWriteMethods {\n return {\n ...createContainerSharingMethods(state, syncAgent),\n createChild: (parentId, name) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n createChildContainer(state, syncAgent, parentId, name, isCurrent),\n [parentId],\n ),\n deleteContainer: createDeleteContainerMethod(state, syncAgent),\n purgeContainer: (containerId, options) =>\n chainPurgeAfterScopeMoves(\n state,\n syncAgent,\n containerId,\n options,\n (isCurrent) =>\n purgeContainer(state, syncAgent, containerId, options, isCurrent),\n ),\n emptyTrash: (trashContainerId, options) =>\n chainPurgeAfterScopeMoves(\n state,\n syncAgent,\n trashContainerId,\n options,\n (isCurrent) =>\n emptyTrash(state, syncAgent, trashContainerId, options, isCurrent),\n ),\n ensureSystemContainer: createEnsureSystemContainerMethod(state, syncAgent),\n moveContainer: (containerId, parentId) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n moveContainer(state, syncAgent, containerId, parentId, isCurrent),\n [containerId, parentId],\n containerId,\n ),\n prepareGroupRewrap: createPrepareGroupRewrapMethod(state, syncAgent),\n renameContainer: (containerId, name) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n renameContainer(state, syncAgent, containerId, name, isCurrent),\n [containerId],\n ),\n setContainerPrimaryDocument: (containerId, documentId) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n setContainerPrimaryDocument(\n state,\n syncAgent,\n containerId,\n documentId,\n isCurrent,\n ),\n [containerId],\n ),\n setContainerIcon: (containerId, icon) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n setContainerIcon(state, syncAgent, containerId, icon, isCurrent),\n [containerId],\n ),\n };\n}\n\nfunction createContainerContentsStoreEntry(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence = defaultContainerContentsPersistence,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStoreEntry {\n const state = createContainerContentsStoreState(\n initialRuntime,\n options.persistence ?? persistence,\n options.logLabel,\n );\n const syncAgent = createContainerContentsStoreSyncAgent({\n host: createContainerContentsStoreSyncHost(state),\n state,\n });\n const writeMethods = createContainerWriteMethods(state, syncAgent);\n\n return {\n requestDocumentPriming: () => {\n state.documentStoresNeedPriming = true;\n syncAgent.scheduleSync();\n },\n store: {\n ...writeMethods,\n ...createTreeRefreshMethods(state, syncAgent),\n // Force an on-demand local SQLite re-read (see the interface doc): arm the\n // gate refreshLocalContainerStates otherwise requires, which the runtime\n // auto-arms only on a context transition an on-demand caller cannot rely on.\n refreshLocalContainers: () => {\n state.localContainersNeedRefresh = true;\n return syncAgent.refreshLocalContainers();\n },\n requestSync: () => syncAgent.scheduleSync(),\n getCachedContainerWriterProjection: (containerId) =>\n getCachedContainerWriterProjectionForStore(state, containerId),\n getSnapshot: () => state.snapshot,\n subscribe: (listener) =>\n subscribeToContainerContentsStore(state, listener),\n updateRuntime: (runtime) =>\n updateContainerContentsStoreRuntime(state, runtime, syncAgent),\n },\n updateOptions: (nextOptions) =>\n applyContainerContentsStoreOptions(state, syncAgent, nextOptions),\n };\n}\n\nexport function createContainerContentsStore(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence = defaultContainerContentsPersistence,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStore {\n return createContainerContentsStoreEntry(initialRuntime, persistence, options)\n .store;\n}\n\nexport function getOrCreateContainerContentsStore(\n domainScope: DomainScope,\n runtime: ContainerContentsStoreRuntime,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStore {\n const existingEntry = containerContentsStoresByScope.get(domainScope);\n if (existingEntry) {\n existingEntry.updateOptions(options);\n return existingEntry.store;\n }\n\n const nextEntry = createContainerContentsStoreEntry(\n runtime,\n defaultContainerContentsPersistence,\n options,\n );\n containerContentsStoresByScope.set(domainScope, nextEntry);\n return nextEntry.store;\n}\n\n/**\n * Arm the next structural pass's document-priming scan for a domain scope.\n * Priming normally re-arms only on store creation and topology changes, so a\n * caller that just tore down a document's local state uses this to have the\n * still-listed server document re-created without waiting for an app\n * restart. Returns false when the scope has no container-contents store yet;\n * the startup priming pass covers that case.\n */\nexport function requestContainerContentsDocumentPriming(\n domainScope: DomainScope,\n): boolean {\n const entry = containerContentsStoresByScope.get(domainScope);\n if (!entry) {\n return false;\n }\n\n entry.requestDocumentPriming();\n return true;\n}\n"]}
|
|
@@ -100,11 +100,15 @@ export async function hasStartupContainerSyncWork(state) {
|
|
|
100
100
|
if (containerIds.length === 0) {
|
|
101
101
|
return false;
|
|
102
102
|
}
|
|
103
|
-
const [containersWithPendingMetadata, containersWithPullContinuations] = await Promise.all([
|
|
103
|
+
const [containersWithPendingMetadata, containersWithPullContinuations, owedMetadataReads,] = await Promise.all([
|
|
104
104
|
state.persistence.listContainerIdsWithPendingUpdates(execSql, containerIds),
|
|
105
105
|
state.persistence.listContainerIdsWithPullContinuations(execSql, containerIds),
|
|
106
|
+
// A read a listing owed before the restart needs a pass even when the
|
|
107
|
+
// cached tree is fresh and no connection is acknowledged.
|
|
108
|
+
state.persistence.listContainerMetadataRevalidations(execSql),
|
|
106
109
|
]);
|
|
107
110
|
return (containersWithPendingMetadata.length > 0 ||
|
|
108
|
-
containersWithPullContinuations.length > 0
|
|
111
|
+
containersWithPullContinuations.length > 0 ||
|
|
112
|
+
owedMetadataReads.length > 0);
|
|
109
113
|
}
|
|
110
114
|
//# sourceMappingURL=startupHydration.js.map
|