@tearleads/client-sdk 0.1.248 → 0.1.249

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/client/organizations/index.js +5 -3
  2. package/client/organizations/index.js.map +1 -1
  3. package/client/organizations/organizationGroupPresentation.d.ts +1 -1
  4. package/client/organizations/organizationGroupPresentation.js.map +1 -1
  5. package/client/organizations/organizationLeaveRequestVerifier.js +21 -0
  6. package/client/organizations/organizationLeaveRequestVerifier.js.map +1 -0
  7. package/client/organizations/{organizationReadModels.d.ts → organizationReadModelCoordinator.d.ts} +18 -16
  8. package/client/organizations/organizationReadModelCoordinator.js +2 -0
  9. package/client/organizations/organizationReadModelCoordinator.js.map +1 -0
  10. package/client/organizations/organizationReadModelPresentation.js +51 -0
  11. package/client/organizations/organizationReadModelPresentation.js.map +1 -0
  12. package/client/organizations/organizationReadModelScopes.js +37 -0
  13. package/client/organizations/organizationReadModelScopes.js.map +1 -0
  14. package/client/organizations/organizationReadModels.js +131 -88
  15. package/client/organizations/organizationReadModels.js.map +1 -1
  16. package/client/organizations/organizationsTypes.d.ts +13 -5
  17. package/client/organizations/organizationsTypes.js.map +1 -1
  18. package/client/organizations/principalMutations.d.ts +18 -2
  19. package/client/organizations/principalMutations.js +29 -15
  20. package/client/organizations/principalMutations.js.map +1 -1
  21. package/client/runtime/principalMutationApi.d.ts +2 -0
  22. package/client/runtime/principalMutationApi.js +2 -0
  23. package/client/runtime/principalMutationApi.js.map +1 -1
  24. package/client/runtime/principalMutationDispatch.js +47 -10
  25. package/client/runtime/principalMutationDispatch.js.map +1 -1
  26. package/client/runtime/workflowRuntime.js +5 -4
  27. package/client/runtime/workflowRuntime.js.map +1 -1
  28. package/data/containers/shared/mutationRequestOptions.d.ts +2 -0
  29. package/data/containers/shared/mutationRequestOptions.js.map +1 -1
  30. package/data/containers/shared/types.d.ts +12 -2
  31. package/data/containers/shared/types.js.map +1 -1
  32. package/data/persistence/organizations/organizationReadModelRepository.js +20 -2
  33. package/data/persistence/organizations/organizationReadModelRepository.js.map +1 -1
  34. package/internal/api-client/ApiClient.d.ts +4 -1
  35. package/internal/api-client/client/containerMutations.d.ts +2 -2
  36. package/internal/api-client/client/containerMutations.js +2 -1
  37. package/internal/api-client/client/containerMutations.js.map +1 -1
  38. package/internal/api-client/client/principalPolicies.d.ts +3 -0
  39. package/internal/api-client/principalPolicyRequests.d.ts +2 -0
  40. package/internal/api-client/principalPolicyRequests.js +6 -4
  41. package/internal/api-client/principalPolicyRequests.js.map +1 -1
  42. package/internal/api-client/routes/containers/mutations.js +3 -3
  43. package/internal/api-client/routes/containers/mutations.js.map +1 -1
  44. package/internal/api-client/routes/organizations/createGroup.js +3 -5
  45. package/internal/api-client/routes/organizations/createGroup.js.map +1 -1
  46. package/internal/api-client/routes/principals/policy.js +2 -5
  47. package/internal/api-client/routes/principals/policy.js.map +1 -1
  48. package/internal/api-client/types.d.ts +6 -0
  49. package/internal/api-client/types.js.map +1 -1
  50. package/internal/validators/operation/containerMutations.d.ts +20 -3
  51. package/internal/validators/operation/containerMutations.js +18 -20
  52. package/internal/validators/operation/containerMutations.js.map +1 -1
  53. package/internal/validators/operation/index.d.ts +1 -1
  54. package/internal/validators/operation/index.js +1 -1
  55. package/internal/validators/operation/index.js.map +1 -1
  56. package/internal/validators/operation/organizations.d.ts +17 -1
  57. package/internal/validators/operation/organizations.js +4 -2
  58. package/internal/validators/operation/organizations.js.map +1 -1
  59. package/internal/validators/operation/principals.d.ts +17 -1
  60. package/internal/validators/operation/principals.js +5 -2
  61. package/internal/validators/operation/principals.js.map +1 -1
  62. package/internal/validators/request/index.d.ts +1 -1
  63. package/internal/validators/request/index.js +1 -1
  64. package/internal/validators/request/index.js.map +1 -1
  65. package/internal/validators/request/organization.d.ts +15 -0
  66. package/internal/validators/request/organization.js +8 -0
  67. package/internal/validators/request/organization.js.map +1 -1
  68. package/internal/validators/response/areas/organizations.d.ts +3 -2
  69. package/internal/validators/response/areas/organizations.js +3 -2
  70. package/internal/validators/response/areas/organizations.js.map +1 -1
  71. package/internal/validators/response/areas/principals.d.ts +1 -1
  72. package/internal/validators/response/areas/principals.js +1 -1
  73. package/internal/validators/response/areas/principals.js.map +1 -1
  74. package/internal/validators/response/committedReadModel.d.ts +697 -0
  75. package/internal/validators/response/committedReadModel.js +52 -0
  76. package/internal/validators/response/committedReadModel.js.map +1 -0
  77. package/internal/validators/response/container.d.ts +52 -0
  78. package/internal/validators/response/container.js +3 -3
  79. package/internal/validators/response/container.js.map +1 -1
  80. package/internal/validators/response/organization.d.ts +0 -191
  81. package/internal/validators/response/organization.js +0 -7
  82. package/internal/validators/response/organization.js.map +1 -1
  83. package/internal/validators/response/organizationReadModel.d.ts +167 -0
  84. package/internal/validators/response/organizationReadModel.js +5 -0
  85. package/internal/validators/response/organizationReadModel.js.map +1 -1
  86. package/internal/validators/response/principal.d.ts +0 -403
  87. package/internal/validators/response/principal.js +0 -8
  88. package/internal/validators/response/principal.js.map +1 -1
  89. package/package.json +1 -1
  90. package/workflows/container-contents/container-state/organizationHost.d.ts +9 -0
  91. package/workflows/container-contents/container-state/organizationHost.js.map +1 -1
  92. package/workflows/container-contents/container-state/remote.js +6 -0
  93. package/workflows/container-contents/container-state/remote.js.map +1 -1
  94. package/workflows/containers/child/share/index.d.ts +4 -2
  95. package/workflows/containers/child/share/index.js +37 -20
  96. package/workflows/containers/child/share/index.js.map +1 -1
  97. package/workflows/organizations/containerContentsHost.js +20 -1
  98. package/workflows/organizations/containerContentsHost.js.map +1 -1
  99. package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js +5 -1
  100. package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js.map +1 -1
  101. package/workflows/organizations/groups/createCurrentOrganizationGroup.js +8 -1
  102. package/workflows/organizations/groups/createCurrentOrganizationGroup.js.map +1 -1
  103. package/workflows/organizations/index.d.ts +1 -0
  104. package/workflows/organizations/index.js +1 -0
  105. package/workflows/organizations/index.js.map +1 -1
  106. package/workflows/organizations/readModel/committedReadModel.d.ts +66 -0
  107. package/workflows/organizations/readModel/committedReadModel.js +150 -0
  108. package/workflows/organizations/readModel/committedReadModel.js.map +1 -0
  109. package/workflows/organizations/readModel/readModelProjection.d.ts +15 -2
  110. package/workflows/organizations/readModel/readModelProjection.js +26 -4
  111. package/workflows/organizations/readModel/readModelProjection.js.map +1 -1
@@ -1,6 +1,6 @@
1
1
  import type { AccessEvent, AccessManifest, ContainerAccessManifestState, ContainerCreateAccessEventBody, ContainerDirectGrant, ContainerGrantAccessEventBody, ContainerGrantPrincipalHead, ContainerKekKeyring, ContainerKekRecipientTarget, ContainerKeyEpoch, ContainerKeyWrap, ContainerMoveAccessEventBody, ContainerRekeyAccessEventBody, ContainerRevokeAccessEventBody, ContainerUserRecipientKey } from "../../../internal/crypto/index.js";
2
2
  import type { AccessManifestBundleWire, ContainerCreateWithMetadataDocumentRequest, ContainerMutationRequest, ContainerRotationRequest } from "../../../internal/validators/request/index.js";
3
- import type { ContainerCreateWithMetadataDocumentResponse, ContainerKekResponse, ContainerMutationResponse, ContainerRotationResponse, ContainerWriterProjectionResponse, ReferencedPrincipalStateResponse } from "../../../internal/validators/response/index.js";
3
+ import type { ContainerCreateWithMetadataDocumentResponse, ContainerKekResponse, ContainerMutationResponse, ContainerRotationResponse, ContainerShareResponse, ContainerWriterProjectionResponse, OrganizationReadModelDeltaResponse, ReferencedPrincipalStateResponse } from "../../../internal/validators/response/index.js";
4
4
  import type { PrincipalPolicyCurrentEvidence } from "../../principalContracts/principalPolicyEvidence.js";
5
5
  import type { ExecSql } from "../../sqlite/sqlSchema.js";
6
6
  import type { ContainerMutationRequestOptions } from "./mutationRequestOptions.js";
@@ -92,9 +92,19 @@ export interface ContainerShareApi extends ContainerReciteApi {
92
92
  getContainerWriterProjection(containerId: string): Promise<ContainerWriterProjectionResponse | null>;
93
93
  shareContainer(containerId: string, input: ContainerMutationRequest, options?: ContainerMutationRequestOptions): Promise<ContainerMutationResponse | null>;
94
94
  /** Tells a stale path, which a fresh projection clears, from a refusal. */
95
- shareContainerResult?(containerId: string, input: ContainerMutationRequest, options?: ContainerMutationRequestOptions): Promise<ContainerMutationSubmitResult<ContainerMutationResponse>>;
95
+ shareContainerResult?(containerId: string, input: ContainerMutationRequest, options?: ContainerMutationRequestOptions): Promise<ContainerMutationSubmitResult<ContainerShareResponse>>;
96
96
  evictContainerWriterProjection?(containerId: string): void;
97
97
  }
98
+ /**
99
+ * Sends the organization read-model cursor a share holds, so its response can
100
+ * carry the delta from it; the share settles the lease once it ends.
101
+ */
102
+ export interface ContainerShareCommittedReadModel {
103
+ begin(): Promise<{
104
+ readonly heldCursor: string | undefined;
105
+ settle(delta: OrganizationReadModelDeltaResponse | undefined): void;
106
+ }>;
107
+ }
98
108
  /**
99
109
  * A status-bearing rotation outcome. A refusal that names
100
110
  * `requiredContainerIds` is answerable: sign those descendant rekeys and
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AccessEvent,\n AccessManifest,\n ContainerAccessManifestState,\n ContainerCreateAccessEventBody,\n ContainerDirectGrant,\n ContainerGrantAccessEventBody,\n ContainerGrantPrincipalHead,\n ContainerKekKeyring,\n ContainerKekRecipientTarget,\n ContainerKeyEpoch,\n ContainerKeyWrap,\n ContainerMoveAccessEventBody,\n ContainerRekeyAccessEventBody,\n ContainerRevokeAccessEventBody,\n ContainerUserRecipientKey,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWire,\n ContainerCreateWithMetadataDocumentRequest,\n ContainerMutationRequest,\n ContainerRotationRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerCreateWithMetadataDocumentResponse,\n ContainerKekResponse,\n ContainerMutationResponse,\n ContainerRotationResponse,\n ContainerWriterProjectionResponse,\n ReferencedPrincipalStateResponse,\n} from \"@tearleads/validators/response\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../principalContracts/principalPolicyEvidence\";\nimport type { ExecSql } from \"../../sqlite/sqlSchema\";\nimport type { ContainerMutationRequestOptions } from \"./mutationRequestOptions\";\nimport type { ContainerReciteApi } from \"./reciteApi\";\n\nexport interface ContainerMutationAuthor {\n organizationId: string;\n signerDeviceId: string;\n signerKeyFingerprint: string;\n signerPrivateKey: Uint8Array;\n signerUserId: string;\n}\n\nexport interface BuildContainerCreatePlanInput {\n author: ContainerMutationAuthor;\n containerId?: string | undefined;\n containerKey: Uint8Array;\n containerKeyEpochId?: string | undefined;\n eventId?: string | undefined;\n /**\n * Optional group grant to bake into the\n * create manifest, wrapping the new container key to that principal in\n * addition to the normal parent-inheritance wrap. Used to birth a child\n * container that is directly readable by a group — e.g. the org public\n * metadata container granted to the reserved Members group. The principal's\n * verified policy must also be supplied via `principalPolicies` so the server\n * can derive the recipient target.\n */\n managedPrincipalGrant?:\n | {\n accessLevel: ContainerDirectGrant[\"accessLevel\"];\n principalEncapsulationPublicKey: string;\n principalHead: ContainerGrantPrincipalHead;\n }\n | undefined;\n metadataDocumentId?: string | undefined;\n systemSlot?: string | null | undefined;\n parentProjection: ContainerWriterProjectionResponse;\n principalPolicies?: readonly PrincipalPolicyCurrentEvidence[] | undefined;\n signedAt?: string | undefined;\n}\n\nexport interface ContainerCreatePlan {\n body: ContainerCreateAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyEpochHash: string;\n keyTargetHash: string;\n manifest: AccessManifest;\n manifestHash: string;\n metadataDocumentId: string;\n parentContainerId: string | null;\n parentManifestHash: string | null;\n recipientTargets: ContainerKekRecipientTarget[];\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerCreatePlan {\n containerKey: Uint8Array;\n plan: ContainerCreatePlan;\n}\n\nexport interface ContainerCreatePlanContext\n extends BuildContainerCreatePlanInput {\n containerKeyPublicKey: string;\n containerId: string;\n containerKeyEpochId: string;\n eventId: string;\n metadataDocumentId: string;\n parent: ParentContainerCreateContext;\n signedAt: string;\n}\n\nexport interface ContainerMutationSubmitFailure {\n readonly code?: string | undefined;\n readonly message: string;\n readonly ok: false;\n readonly report: () => void;\n readonly stalePrincipalHeads?:\n | readonly ReferencedPrincipalStateResponse[]\n | undefined;\n readonly status: number | null;\n}\n\nexport type ContainerMutationSubmitResult<T> =\n | {\n readonly data: T;\n readonly ok: true;\n }\n | ContainerMutationSubmitFailure;\n\nexport interface ContainerCreateApi {\n createContainerResult(\n input: ContainerMutationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerMutationSubmitResult<ContainerMutationResponse>>;\n createContainerWithMetadataDocumentResult(\n input: ContainerCreateWithMetadataDocumentRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<\n ContainerMutationSubmitResult<ContainerCreateWithMetadataDocumentResponse>\n >;\n evictContainerWriterProjection(containerId: string): void;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n}\n\nexport interface ContainerShareApi extends ContainerReciteApi {\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n shareContainer(\n containerId: string,\n input: ContainerMutationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerMutationResponse | null>;\n /** Tells a stale path, which a fresh projection clears, from a refusal. */\n shareContainerResult?(\n containerId: string,\n input: ContainerMutationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerMutationSubmitResult<ContainerMutationResponse>>;\n evictContainerWriterProjection?(containerId: string): void;\n}\n\n/**\n * A status-bearing rotation outcome. A refusal that names\n * `requiredContainerIds` is answerable: sign those descendant rekeys and\n * resubmit with them carried.\n */\nexport type ContainerRotationResult =\n | { readonly ok: true; readonly data: ContainerRotationResponse }\n | {\n readonly ok: false;\n readonly code?: string | undefined;\n /** Surface a failure that was submitted with `reportErrors: false`. */\n readonly report?: (() => void) | undefined;\n readonly requiredContainerIds?: readonly string[] | undefined;\n readonly status: number | null;\n };\n\nexport interface ContainerMoveApi extends ContainerReciteApi {\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n moveContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResponse | null>;\n /** Optional status-bearing variant; without it nothing can be carried. */\n moveContainerResult?(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResult>;\n}\n\nexport interface ContainerRevokeApi extends ContainerReciteApi {\n evictContainerWriterProjection?(containerId: string): void;\n evictWriterProjectionsCiting?(containerIds: readonly string[]): void;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n revokeContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResponse | null>;\n /** Optional status-bearing variant; without it nothing can be carried. */\n revokeContainerResult?(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResult>;\n}\n\nexport interface CreateRemoteContainerResult {\n containerKey: Uint8Array;\n containerId: string;\n metadataDocumentId: string;\n plan: ContainerCreatePlan;\n response: ContainerMutationResponse;\n}\n\nexport interface ContainerSharePlan {\n body: ContainerGrantAccessEventBody;\n /** The unchanged epoch's stored keyring, echoed back by the server. */\n previousKeyring?: Record<string, unknown> | null | undefined;\n containerId: string;\n event: AccessEvent;\n eventHash: string;\n grant: ContainerDirectGrant;\n keyEpoch: ContainerKeyEpoch;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n recipientTarget: ContainerKekRecipientTarget;\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerSharePlan {\n containerKey: Uint8Array;\n plan: ContainerSharePlan;\n}\n\nexport interface ContainerRevokePlan {\n body: ContainerRevokeAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerRevokePlan {\n containerKey: Uint8Array;\n plan: ContainerRevokePlan;\n}\n\nexport interface ContainerRekeyPlan {\n body: ContainerRekeyAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerRekeyPlan {\n containerKey: Uint8Array;\n plan: ContainerRekeyPlan;\n writerProjection: ContainerWriterProjectionResponse;\n}\n\nexport interface ContainerRekeyApi extends ContainerReciteApi {\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n rekeyContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResponse | null>;\n /** Optional status-bearing variant; see DocumentSyncApi. */\n rekeyContainerResult?(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResult>;\n}\n\nexport interface ContainerMovePlan {\n body: ContainerMoveAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerMovePlan {\n containerKey: Uint8Array;\n plan: ContainerMovePlan;\n}\n\nexport interface BuildMaterializedContainerMovePlanInput {\n author: ContainerMutationAuthor;\n containerKeyEpochId?: string | undefined;\n destinationParentProjection: ContainerWriterProjectionResponse;\n eventId?: string | undefined;\n execSql: ExecSql;\n previousProjection: ContainerWriterProjectionResponse;\n signedAt?: string | undefined;\n targetSecretKey: Uint8Array;\n}\n\nexport interface ParentContainerCreateContext {\n manifest: ContainerWriterProjectionResponse[\"path\"][number];\n kek: ContainerKekResponse;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AccessEvent,\n AccessManifest,\n ContainerAccessManifestState,\n ContainerCreateAccessEventBody,\n ContainerDirectGrant,\n ContainerGrantAccessEventBody,\n ContainerGrantPrincipalHead,\n ContainerKekKeyring,\n ContainerKekRecipientTarget,\n ContainerKeyEpoch,\n ContainerKeyWrap,\n ContainerMoveAccessEventBody,\n ContainerRekeyAccessEventBody,\n ContainerRevokeAccessEventBody,\n ContainerUserRecipientKey,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWire,\n ContainerCreateWithMetadataDocumentRequest,\n ContainerMutationRequest,\n ContainerRotationRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerCreateWithMetadataDocumentResponse,\n ContainerKekResponse,\n ContainerMutationResponse,\n ContainerRotationResponse,\n ContainerShareResponse,\n ContainerWriterProjectionResponse,\n OrganizationReadModelDeltaResponse,\n ReferencedPrincipalStateResponse,\n} from \"@tearleads/validators/response\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../principalContracts/principalPolicyEvidence\";\nimport type { ExecSql } from \"../../sqlite/sqlSchema\";\nimport type { ContainerMutationRequestOptions } from \"./mutationRequestOptions\";\nimport type { ContainerReciteApi } from \"./reciteApi\";\n\nexport interface ContainerMutationAuthor {\n organizationId: string;\n signerDeviceId: string;\n signerKeyFingerprint: string;\n signerPrivateKey: Uint8Array;\n signerUserId: string;\n}\n\nexport interface BuildContainerCreatePlanInput {\n author: ContainerMutationAuthor;\n containerId?: string | undefined;\n containerKey: Uint8Array;\n containerKeyEpochId?: string | undefined;\n eventId?: string | undefined;\n /**\n * Optional group grant to bake into the\n * create manifest, wrapping the new container key to that principal in\n * addition to the normal parent-inheritance wrap. Used to birth a child\n * container that is directly readable by a group — e.g. the org public\n * metadata container granted to the reserved Members group. The principal's\n * verified policy must also be supplied via `principalPolicies` so the server\n * can derive the recipient target.\n */\n managedPrincipalGrant?:\n | {\n accessLevel: ContainerDirectGrant[\"accessLevel\"];\n principalEncapsulationPublicKey: string;\n principalHead: ContainerGrantPrincipalHead;\n }\n | undefined;\n metadataDocumentId?: string | undefined;\n systemSlot?: string | null | undefined;\n parentProjection: ContainerWriterProjectionResponse;\n principalPolicies?: readonly PrincipalPolicyCurrentEvidence[] | undefined;\n signedAt?: string | undefined;\n}\n\nexport interface ContainerCreatePlan {\n body: ContainerCreateAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyEpochHash: string;\n keyTargetHash: string;\n manifest: AccessManifest;\n manifestHash: string;\n metadataDocumentId: string;\n parentContainerId: string | null;\n parentManifestHash: string | null;\n recipientTargets: ContainerKekRecipientTarget[];\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerCreatePlan {\n containerKey: Uint8Array;\n plan: ContainerCreatePlan;\n}\n\nexport interface ContainerCreatePlanContext\n extends BuildContainerCreatePlanInput {\n containerKeyPublicKey: string;\n containerId: string;\n containerKeyEpochId: string;\n eventId: string;\n metadataDocumentId: string;\n parent: ParentContainerCreateContext;\n signedAt: string;\n}\n\nexport interface ContainerMutationSubmitFailure {\n readonly code?: string | undefined;\n readonly message: string;\n readonly ok: false;\n readonly report: () => void;\n readonly stalePrincipalHeads?:\n | readonly ReferencedPrincipalStateResponse[]\n | undefined;\n readonly status: number | null;\n}\n\nexport type ContainerMutationSubmitResult<T> =\n | {\n readonly data: T;\n readonly ok: true;\n }\n | ContainerMutationSubmitFailure;\n\nexport interface ContainerCreateApi {\n createContainerResult(\n input: ContainerMutationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerMutationSubmitResult<ContainerMutationResponse>>;\n createContainerWithMetadataDocumentResult(\n input: ContainerCreateWithMetadataDocumentRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<\n ContainerMutationSubmitResult<ContainerCreateWithMetadataDocumentResponse>\n >;\n evictContainerWriterProjection(containerId: string): void;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n}\n\nexport interface ContainerShareApi extends ContainerReciteApi {\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n shareContainer(\n containerId: string,\n input: ContainerMutationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerMutationResponse | null>;\n /** Tells a stale path, which a fresh projection clears, from a refusal. */\n shareContainerResult?(\n containerId: string,\n input: ContainerMutationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerMutationSubmitResult<ContainerShareResponse>>;\n evictContainerWriterProjection?(containerId: string): void;\n}\n\n/**\n * Sends the organization read-model cursor a share holds, so its response can\n * carry the delta from it; the share settles the lease once it ends.\n */\nexport interface ContainerShareCommittedReadModel {\n begin(): Promise<{\n readonly heldCursor: string | undefined;\n settle(delta: OrganizationReadModelDeltaResponse | undefined): void;\n }>;\n}\n\n/**\n * A status-bearing rotation outcome. A refusal that names\n * `requiredContainerIds` is answerable: sign those descendant rekeys and\n * resubmit with them carried.\n */\nexport type ContainerRotationResult =\n | { readonly ok: true; readonly data: ContainerRotationResponse }\n | {\n readonly ok: false;\n readonly code?: string | undefined;\n /** Surface a failure that was submitted with `reportErrors: false`. */\n readonly report?: (() => void) | undefined;\n readonly requiredContainerIds?: readonly string[] | undefined;\n readonly status: number | null;\n };\n\nexport interface ContainerMoveApi extends ContainerReciteApi {\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n moveContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResponse | null>;\n /** Optional status-bearing variant; without it nothing can be carried. */\n moveContainerResult?(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResult>;\n}\n\nexport interface ContainerRevokeApi extends ContainerReciteApi {\n evictContainerWriterProjection?(containerId: string): void;\n evictWriterProjectionsCiting?(containerIds: readonly string[]): void;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n revokeContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResponse | null>;\n /** Optional status-bearing variant; without it nothing can be carried. */\n revokeContainerResult?(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResult>;\n}\n\nexport interface CreateRemoteContainerResult {\n containerKey: Uint8Array;\n containerId: string;\n metadataDocumentId: string;\n plan: ContainerCreatePlan;\n response: ContainerMutationResponse;\n}\n\nexport interface ContainerSharePlan {\n body: ContainerGrantAccessEventBody;\n /** The unchanged epoch's stored keyring, echoed back by the server. */\n previousKeyring?: Record<string, unknown> | null | undefined;\n containerId: string;\n event: AccessEvent;\n eventHash: string;\n grant: ContainerDirectGrant;\n keyEpoch: ContainerKeyEpoch;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n recipientTarget: ContainerKekRecipientTarget;\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerSharePlan {\n containerKey: Uint8Array;\n plan: ContainerSharePlan;\n}\n\nexport interface ContainerRevokePlan {\n body: ContainerRevokeAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerRevokePlan {\n containerKey: Uint8Array;\n plan: ContainerRevokePlan;\n}\n\nexport interface ContainerRekeyPlan {\n body: ContainerRekeyAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerRekeyPlan {\n containerKey: Uint8Array;\n plan: ContainerRekeyPlan;\n writerProjection: ContainerWriterProjectionResponse;\n}\n\nexport interface ContainerRekeyApi extends ContainerReciteApi {\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n rekeyContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResponse | null>;\n /** Optional status-bearing variant; see DocumentSyncApi. */\n rekeyContainerResult?(\n containerId: string,\n input: ContainerRotationRequest,\n options?: ContainerMutationRequestOptions,\n ): Promise<ContainerRotationResult>;\n}\n\nexport interface ContainerMovePlan {\n body: ContainerMoveAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n request: ContainerMutationRequest;\n state: ContainerAccessManifestState;\n wraps: ContainerKeyWrap[];\n}\n\nexport interface MaterializedContainerMovePlan {\n containerKey: Uint8Array;\n plan: ContainerMovePlan;\n}\n\nexport interface BuildMaterializedContainerMovePlanInput {\n author: ContainerMutationAuthor;\n containerKeyEpochId?: string | undefined;\n destinationParentProjection: ContainerWriterProjectionResponse;\n eventId?: string | undefined;\n execSql: ExecSql;\n previousProjection: ContainerWriterProjectionResponse;\n signedAt?: string | undefined;\n targetSecretKey: Uint8Array;\n}\n\nexport interface ParentContainerCreateContext {\n manifest: ContainerWriterProjectionResponse[\"path\"][number];\n kek: ContainerKekResponse;\n}\n"]}
@@ -90,12 +90,17 @@ export class OrganizationReadModelRepository {
90
90
  });
91
91
  // The requester prune also retires pruned users' usage projections.
92
92
  await ensureSqlTables(this.execSql, organizationAccessProjectionTables);
93
- const disposition = await getClientSQLitePersistenceRuntime(this.execSql).transaction((tx) => applyOrganizationReadModelResponseInTransaction(tx, {
93
+ const runtime = getClientSQLitePersistenceRuntime(this.execSql);
94
+ const apply = (tx) => applyOrganizationReadModelResponseInTransaction(tx, {
94
95
  currentUserId: input.currentUserId,
95
96
  now: this.now,
96
97
  requestedCursor: input.requestedCursor,
97
98
  response: input.response,
98
- }));
99
+ });
100
+ const disposition = input.canCommit
101
+ ? ((await runtime.guardedTransaction(apply, input.canCommit)).result ??
102
+ "stale")
103
+ : await runtime.transaction(apply);
99
104
  // An applied change follows an organization hint or mutation; in-flight
100
105
  // operations recover the directory again instead of reusing their memo.
101
106
  if (disposition === "applied")
@@ -147,6 +152,19 @@ export class OrganizationReadModelRepository {
147
152
  // the organization's directory again instead of reusing their memo.
148
153
  getOrCreatePrincipalPolicyCoordinator(this.execSql).invalidateRecovery(input.organizationId);
149
154
  }
155
+ /**
156
+ * The organization's stored projection cursor, shared by every requester on
157
+ * this device: the cursor a reconcile requests from. Null without one.
158
+ */
159
+ async loadOrganizationReadModelCursor(organizationId) {
160
+ await ensureSqlTables(this.execSql, organizationReadModelTables);
161
+ const [row] = await getClientSQLitePersistenceRuntime(this.execSql)
162
+ .db.select({ cursor: organizationReadModelState.cursor })
163
+ .from(organizationReadModelState)
164
+ .where(eq(organizationReadModelState.organizationId, organizationId))
165
+ .limit(1);
166
+ return row?.cursor ?? null;
167
+ }
150
168
  /**
151
169
  * The cursor this requester has applied, or null when it holds none. The
152
170
  * organization row's cursor is shared: another identity on this device may
@@ -1 +1 @@
1
- {"version":3,"file":"organizationReadModelRepository.js","sourceRoot":"","sources":["organizationReadModelRepository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,qCAAqC,EAAE,MAAM,6CAA6C,CAAC;AACpG,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,iDAAiD,CAAC;AAC9F,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAEL,iCAAiC,GAClC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAgB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,iDAAiD,EAAE,MAAM,oCAAoC,CAAC;AAKvG,OAAO,EAAE,sCAAsC,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,EACL,2DAA2D,GAE5D,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAEL,+CAA+C,GAChD,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,gDAAgD,GAEjD,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,iDAAiD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AC,eAAe;oBACtC,UAAU;oBACV,QAAQ;iBACT,CAAC;qBACD,kBAAkB,CAAC;oBAClB,MAAM,EAAE;wBACN,+BAA+B,CAAC,cAAc;wBAC9C,+BAA+B,CAAC,eAAe;wBAC/C,+BAA+B,CAAC,UAAU;qBAC3C;oBACD,GAAG,EAAE,EAAE,QAAQ,EAAE;iBAClB,CAAC;qBACD,GAAG,EAAE,CAAC;YACX,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,iCAAiC,CACrC,KAA0C,EAC1C,UAAoD;QAEpD,MAAM,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,2BAA2B,CAAC,CAAC;QACjE,MAAM,IAAI,GAAG,MAAM,iCAAiC,CAAC,IAAI,CAAC,OAAO,CAAC;aAC/D,EAAE,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,+BAA+B,CAAC,UAAU,EAAE,CAAC;aACrE,IAAI,CAAC,+BAA+B,CAAC;aACrC,KAAK,CACJ,GAAG,CACD,EAAE,CACA,+BAA+B,CAAC,cAAc,EAC9C,KAAK,CAAC,cAAc,CACrB,EACD,EAAE,CACA,+BAA+B,CAAC,eAAe,EAC/C,KAAK,CAAC,eAAe,CACtB,EACD,EAAE,CAAC,+BAA+B,CAAC,UAAU,EAAE,UAAU,CAAC,CAC3D,CACF;aACA,KAAK,CAAC,CAAC,CAAC,CAAC;QACZ,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { OrganizationReadModelResponse } from \"@tearleads/validators/response\";\nimport { and, eq } from \"drizzle-orm\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../principals/principalPolicyCoordinator\";\nimport { organizationReadModelTables } from \"../../sqlite/schema\";\nimport { organizationDataUsageTables } from \"../../sqlite/schema/organizationDataUsageSchema\";\nimport {\n organizationPresentationDenials,\n organizationReadModelGroups,\n organizationReadModelRequesters,\n organizationReadModelState,\n} from \"../../sqlite/schema/organizationReadModelSchema\";\nimport {\n type ClientSQLiteTransactionScope,\n getClientSQLitePersistenceRuntime,\n} from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { type ExecSql, ensureSqlTables } from \"../../sqlite/sqlSchema\";\nimport { purgeOrganizationDataUsageProjectionInTransaction } from \"./organizationDataUsagePersistence\";\nimport type {\n OrganizationPresentationDenialProjection,\n OrganizationPresentationDenialScope,\n} from \"./organizationPresentationDenialPersistence\";\nimport { notifyOrganizationReadModelInvalidated } from \"./organizationReadModelInvalidation\";\nimport {\n loadRequesterOrganizationReadModelGroupMembersInTransaction,\n type OrganizationReadModelGroupMembers,\n} from \"./organizationReadModelMemberLoad\";\nimport {\n type ApplyOrganizationReadModelResponseResult,\n applyOrganizationReadModelResponseInTransaction,\n} from \"./organizationReadModelPersistence\";\nimport {\n loadOrganizationReadModelProjectionInTransaction,\n type OrganizationReadModelProjection,\n} from \"./organizationReadModelProjection\";\nimport { OrganizationReadModelIntegrityError } from \"./organizationReadModelProtocol\";\nimport { purgeOrganizationReadModelProjectionInTransaction } from \"./organizationReadModelPurge\";\nimport { assertOrganizationReadModelResponse } from \"./organizationReadModelResponseAssertions\";\n\nconst organizationAccessProjectionTables = [\n ...organizationReadModelTables,\n ...organizationDataUsageTables,\n];\n\n/**\n * The durable organization read-model projection, its group display names,\n * and its presentation denial markers, over one database. Invalidation\n * notices and recovery invalidation are keyed by the executor this\n * repository was built from.\n */\nexport class OrganizationReadModelRepository {\n constructor(\n private readonly execSql: ExecSql,\n private readonly now: () => Date = () => new Date(),\n ) {}\n\n /**\n * The ONE load shell for the durable read-model projection: run `load` in a\n * transaction and, if a stored row fails integrity validation, purge the\n * organization's projection and report null. The projection is a\n * server-refetchable cache, so the next reconcile requests a cursorless\n * snapshot instead of every read and repair pass failing on the same row.\n */\n private async loadWithOrganizationReadModelIntegrityPurge<T>(input: {\n readonly load: (tx: ClientSQLiteTransactionScope) => Promise<T | null>;\n readonly organizationId: string;\n }): Promise<T | null> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n let purgedInvalidRows = false;\n const result = await getClientSQLitePersistenceRuntime(\n this.execSql,\n ).transaction(async (tx) => {\n try {\n return await input.load(tx);\n } catch (error) {\n if (!(error instanceof OrganizationReadModelIntegrityError)) {\n throw error;\n }\n await purgeOrganizationReadModelProjectionInTransaction({\n organizationId: input.organizationId,\n tx,\n });\n purgedInvalidRows = true;\n return null;\n }\n });\n if (purgedInvalidRows) {\n // Realtime consumers may hold a caught-up lease over rows that no longer\n // exist; the notification lets them drop it and refetch authoritatively.\n notifyOrganizationReadModelInvalidated(\n this.execSql,\n input.organizationId,\n );\n }\n return result;\n }\n\n async loadOrganizationReadModelProjection(\n organizationId: string,\n currentUserId: string,\n ): Promise<OrganizationReadModelProjection | null> {\n return this.loadWithOrganizationReadModelIntegrityPurge({\n organizationId,\n load: (tx) =>\n loadOrganizationReadModelProjectionInTransaction({\n currentUserId,\n organizationId,\n tx,\n }),\n });\n }\n\n async loadOrganizationReadModelGroupMembers(\n organizationId: string,\n groupId: string,\n currentUserId: string,\n ): Promise<OrganizationReadModelGroupMembers | null> {\n return this.loadWithOrganizationReadModelIntegrityPurge({\n organizationId,\n load: (tx) =>\n loadRequesterOrganizationReadModelGroupMembersInTransaction(tx, {\n currentUserId,\n groupId,\n organizationId,\n }),\n });\n }\n\n async applyOrganizationReadModelResponse(input: {\n readonly currentUserId: string;\n readonly requestedCursor: string | null;\n readonly response: OrganizationReadModelResponse;\n }): Promise<ApplyOrganizationReadModelResponseResult> {\n assertOrganizationReadModelResponse({\n currentUserId: input.currentUserId,\n response: input.response,\n });\n // The requester prune also retires pruned users' usage projections.\n await ensureSqlTables(this.execSql, organizationAccessProjectionTables);\n\n const disposition = await getClientSQLitePersistenceRuntime(\n this.execSql,\n ).transaction(\n (tx): Promise<ApplyOrganizationReadModelResponseResult> =>\n applyOrganizationReadModelResponseInTransaction(tx, {\n currentUserId: input.currentUserId,\n now: this.now,\n requestedCursor: input.requestedCursor,\n response: input.response,\n }),\n );\n // An applied change follows an organization hint or mutation; in-flight\n // operations recover the directory again instead of reusing their memo.\n if (disposition === \"applied\")\n getOrCreatePrincipalPolicyCoordinator(this.execSql).invalidateRecovery(\n input.response.organizationId,\n );\n return disposition;\n }\n\n async purgeOrganizationReadModelProjection(\n organizationId: string,\n options: { readonly onlyRequesterUserId?: string } = {},\n ): Promise<void> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n await getClientSQLitePersistenceRuntime(this.execSql).transaction(\n async (tx) => {\n await purgeOrganizationReadModelProjectionInTransaction({\n onlyRequesterUserId: options.onlyRequesterUserId,\n organizationId,\n tx,\n });\n },\n );\n }\n\n /**\n * Purge one requester's access to an organization's presentation projections\n * after the server denied that requester. The denial is requester-scoped: the\n * shared read-model rows stay while another local identity in the same\n * database still holds a requester row, and organization-wide rows fall with\n * the last requester.\n */\n async purgeOrganizationAccessProjection(input: {\n readonly organizationId: string;\n readonly requesterUserId: string;\n }): Promise<void> {\n await ensureSqlTables(this.execSql, organizationAccessProjectionTables);\n await getClientSQLitePersistenceRuntime(this.execSql).transaction(\n async (tx) => {\n await tx\n .delete(organizationReadModelRequesters)\n .where(\n and(\n eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n ),\n eq(organizationReadModelRequesters.userId, input.requesterUserId),\n ),\n )\n .run();\n const [remainingRequester] = await tx\n .select({ userId: organizationReadModelRequesters.userId })\n .from(organizationReadModelRequesters)\n .where(\n eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n ),\n )\n .limit(1);\n if (!remainingRequester) {\n await purgeOrganizationReadModelProjectionInTransaction({\n organizationId: input.organizationId,\n tx,\n });\n }\n await purgeOrganizationDataUsageProjectionInTransaction({\n organizationId: input.organizationId,\n requesterUserId: input.requesterUserId,\n tx,\n });\n },\n );\n // A denial is a realtime-hinted access change: in-flight operations recover\n // the organization's directory again instead of reusing their memo.\n getOrCreatePrincipalPolicyCoordinator(this.execSql).invalidateRecovery(\n input.organizationId,\n );\n }\n\n /**\n * The cursor this requester has applied, or null when it holds none. The\n * organization row's cursor is shared: another identity on this device may\n * have advanced it while this requester's own fields (for example\n * `isOrgAdmin`) still reflect an older response. Only the requester's own\n * applied cursor, while it is still the stored projection's cursor, proves\n * this requester is current. Realtime hints compare against it so a hint for\n * a cursor already applied costs no read.\n */\n async loadAppliedOrganizationReadModelCursor(input: {\n readonly organizationId: string;\n readonly requesterUserId: string;\n }): Promise<string | null> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const [row] = await getClientSQLitePersistenceRuntime(this.execSql)\n .db.select({ cursor: organizationReadModelRequesters.appliedCursor })\n .from(organizationReadModelRequesters)\n .innerJoin(\n organizationReadModelState,\n and(\n eq(\n organizationReadModelState.organizationId,\n organizationReadModelRequesters.organizationId,\n ),\n eq(\n organizationReadModelState.cursor,\n organizationReadModelRequesters.appliedCursor,\n ),\n ),\n )\n .where(\n and(\n eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n ),\n eq(organizationReadModelRequesters.userId, input.requesterUserId),\n ),\n )\n .limit(1);\n return row?.cursor ?? null;\n }\n\n /**\n * Every locally projected organization's pointer to its organization_profile\n * document, keyed by organization id.\n *\n * This is the only container-independent handle on that document. Callers\n * that need an org's display name from local state cannot rely on where the\n * document is linked: the provisioner writes it under a deterministic local\n * alias into the organization-metadata container, while a device that only\n * *synced* it (identity recovery, another member) keys it under the server\n * documentId in whichever container the grant arrived through.\n *\n * The local schema stores only the current read-model contract, so every\n * state row is eligible to provide its profile-document pointer.\n */\n async loadOrganizationProfileDocumentIds(): Promise<Map<string, string>> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const { db } = getClientSQLitePersistenceRuntime(this.execSql);\n const rows = await db\n .select({\n organizationId: organizationReadModelState.organizationId,\n profileDocumentId: organizationReadModelState.profileDocumentId,\n })\n .from(organizationReadModelState);\n\n return new Map(\n rows.flatMap((row) =>\n row.profileDocumentId\n ? [[row.organizationId, row.profileDocumentId]]\n : [],\n ),\n );\n }\n\n async loadOrganizationGroupDisplayNames(\n organizationId: string,\n ): Promise<ReadonlyMap<string, string>> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const { db } = getClientSQLitePersistenceRuntime(this.execSql);\n const rows = await db\n .select({\n groupId: organizationReadModelGroups.groupId,\n name: organizationReadModelGroups.name,\n })\n .from(organizationReadModelGroups)\n .where(eq(organizationReadModelGroups.organizationId, organizationId));\n return new Map(\n rows\n .filter((row) => row.name.length > 0)\n .map((row) => [row.groupId, row.name]),\n );\n }\n\n /** Local display cache only: these labels never enter a server request. */\n async saveOrganizationGroupDisplayNames(input: {\n organizationId: string;\n names: readonly { groupId: string; name: string; stateHash: string }[];\n stillCurrent: () => boolean;\n }): Promise<void> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n await getClientSQLitePersistenceRuntime(this.execSql).guardedTransaction(\n async (tx) => {\n for (const group of input.names) {\n await tx\n .update(organizationReadModelGroups)\n .set({ name: group.name })\n .where(\n and(\n eq(\n organizationReadModelGroups.organizationId,\n input.organizationId,\n ),\n eq(organizationReadModelGroups.groupId, group.groupId),\n eq(organizationReadModelGroups.stateHash, group.stateHash),\n ),\n )\n .run();\n }\n },\n input.stillCurrent,\n );\n }\n\n /**\n * Durably record a server denial before the revoked projection rows are\n * purged. The marker is what keeps a failed purge plus an offline restart\n * from serving the revoked projection; it is cleared only when an\n * authoritative reconcile stores fresh server state for the same scope.\n */\n async recordOrganizationPresentationDenials(\n scope: OrganizationPresentationDenialScope,\n projections: readonly OrganizationPresentationDenialProjection[],\n ): Promise<void> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const deniedAt = this.now().toISOString();\n await getClientSQLitePersistenceRuntime(this.execSql).transaction(\n async (tx) => {\n for (const projection of new Set(projections)) {\n await tx\n .insert(organizationPresentationDenials)\n .values({\n organizationId: scope.organizationId,\n requesterUserId: scope.requesterUserId,\n projection,\n deniedAt,\n })\n .onConflictDoUpdate({\n target: [\n organizationPresentationDenials.organizationId,\n organizationPresentationDenials.requesterUserId,\n organizationPresentationDenials.projection,\n ],\n set: { deniedAt },\n })\n .run();\n }\n },\n );\n }\n\n async hasOrganizationPresentationDenial(\n scope: OrganizationPresentationDenialScope,\n projection: OrganizationPresentationDenialProjection,\n ): Promise<boolean> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const rows = await getClientSQLitePersistenceRuntime(this.execSql)\n .db.select({ projection: organizationPresentationDenials.projection })\n .from(organizationPresentationDenials)\n .where(\n and(\n eq(\n organizationPresentationDenials.organizationId,\n scope.organizationId,\n ),\n eq(\n organizationPresentationDenials.requesterUserId,\n scope.requesterUserId,\n ),\n eq(organizationPresentationDenials.projection, projection),\n ),\n )\n .limit(1);\n return rows.length > 0;\n }\n}\n"]}
1
+ {"version":3,"file":"organizationReadModelRepository.js","sourceRoot":"","sources":["organizationReadModelRepository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,qCAAqC,EAAE,MAAM,6CAA6C,CAAC;AACpG,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,iDAAiD,CAAC;AAC9F,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAEL,iCAAiC,GAClC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAgB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,iDAAiD,EAAE,MAAM,oCAAoC,CAAC;AAKvG,OAAO,EAAE,sCAAsC,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,EACL,2DAA2D,GAE5D,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAEL,+CAA+C,GAChD,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,gDAAgD,GAEjD,MAAM,mCAAmC,CAA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AAC;QACjE,MAAM,IAAI,GAAG,MAAM,iCAAiC,CAAC,IAAI,CAAC,OAAO,CAAC;aAC/D,EAAE,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,+BAA+B,CAAC,UAAU,EAAE,CAAC;aACrE,IAAI,CAAC,+BAA+B,CAAC;aACrC,KAAK,CACJ,GAAG,CACD,EAAE,CACA,+BAA+B,CAAC,cAAc,EAC9C,KAAK,CAAC,cAAc,CACrB,EACD,EAAE,CACA,+BAA+B,CAAC,eAAe,EAC/C,KAAK,CAAC,eAAe,CACtB,EACD,EAAE,CAAC,+BAA+B,CAAC,UAAU,EAAE,UAAU,CAAC,CAC3D,CACF;aACA,KAAK,CAAC,CAAC,CAAC,CAAC;QACZ,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { OrganizationReadModelResponse } from \"@tearleads/validators/response\";\nimport { and, eq } from \"drizzle-orm\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../principals/principalPolicyCoordinator\";\nimport { organizationReadModelTables } from \"../../sqlite/schema\";\nimport { organizationDataUsageTables } from \"../../sqlite/schema/organizationDataUsageSchema\";\nimport {\n organizationPresentationDenials,\n organizationReadModelGroups,\n organizationReadModelRequesters,\n organizationReadModelState,\n} from \"../../sqlite/schema/organizationReadModelSchema\";\nimport {\n type ClientSQLiteTransactionScope,\n getClientSQLitePersistenceRuntime,\n} from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { type ExecSql, ensureSqlTables } from \"../../sqlite/sqlSchema\";\nimport { purgeOrganizationDataUsageProjectionInTransaction } from \"./organizationDataUsagePersistence\";\nimport type {\n OrganizationPresentationDenialProjection,\n OrganizationPresentationDenialScope,\n} from \"./organizationPresentationDenialPersistence\";\nimport { notifyOrganizationReadModelInvalidated } from \"./organizationReadModelInvalidation\";\nimport {\n loadRequesterOrganizationReadModelGroupMembersInTransaction,\n type OrganizationReadModelGroupMembers,\n} from \"./organizationReadModelMemberLoad\";\nimport {\n type ApplyOrganizationReadModelResponseResult,\n applyOrganizationReadModelResponseInTransaction,\n} from \"./organizationReadModelPersistence\";\nimport {\n loadOrganizationReadModelProjectionInTransaction,\n type OrganizationReadModelProjection,\n} from \"./organizationReadModelProjection\";\nimport { OrganizationReadModelIntegrityError } from \"./organizationReadModelProtocol\";\nimport { purgeOrganizationReadModelProjectionInTransaction } from \"./organizationReadModelPurge\";\nimport { assertOrganizationReadModelResponse } from \"./organizationReadModelResponseAssertions\";\n\nconst organizationAccessProjectionTables = [\n ...organizationReadModelTables,\n ...organizationDataUsageTables,\n];\n\n/**\n * The durable organization read-model projection, its group display names,\n * and its presentation denial markers, over one database. Invalidation\n * notices and recovery invalidation are keyed by the executor this\n * repository was built from.\n */\nexport class OrganizationReadModelRepository {\n constructor(\n private readonly execSql: ExecSql,\n private readonly now: () => Date = () => new Date(),\n ) {}\n\n /**\n * The ONE load shell for the durable read-model projection: run `load` in a\n * transaction and, if a stored row fails integrity validation, purge the\n * organization's projection and report null. The projection is a\n * server-refetchable cache, so the next reconcile requests a cursorless\n * snapshot instead of every read and repair pass failing on the same row.\n */\n private async loadWithOrganizationReadModelIntegrityPurge<T>(input: {\n readonly load: (tx: ClientSQLiteTransactionScope) => Promise<T | null>;\n readonly organizationId: string;\n }): Promise<T | null> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n let purgedInvalidRows = false;\n const result = await getClientSQLitePersistenceRuntime(\n this.execSql,\n ).transaction(async (tx) => {\n try {\n return await input.load(tx);\n } catch (error) {\n if (!(error instanceof OrganizationReadModelIntegrityError)) {\n throw error;\n }\n await purgeOrganizationReadModelProjectionInTransaction({\n organizationId: input.organizationId,\n tx,\n });\n purgedInvalidRows = true;\n return null;\n }\n });\n if (purgedInvalidRows) {\n // Realtime consumers may hold a caught-up lease over rows that no longer\n // exist; the notification lets them drop it and refetch authoritatively.\n notifyOrganizationReadModelInvalidated(\n this.execSql,\n input.organizationId,\n );\n }\n return result;\n }\n\n async loadOrganizationReadModelProjection(\n organizationId: string,\n currentUserId: string,\n ): Promise<OrganizationReadModelProjection | null> {\n return this.loadWithOrganizationReadModelIntegrityPurge({\n organizationId,\n load: (tx) =>\n loadOrganizationReadModelProjectionInTransaction({\n currentUserId,\n organizationId,\n tx,\n }),\n });\n }\n\n async loadOrganizationReadModelGroupMembers(\n organizationId: string,\n groupId: string,\n currentUserId: string,\n ): Promise<OrganizationReadModelGroupMembers | null> {\n return this.loadWithOrganizationReadModelIntegrityPurge({\n organizationId,\n load: (tx) =>\n loadRequesterOrganizationReadModelGroupMembersInTransaction(tx, {\n currentUserId,\n groupId,\n organizationId,\n }),\n });\n }\n\n async applyOrganizationReadModelResponse(input: {\n /** Checked in the commit's own synchronous slice; refused rolls back. */\n readonly canCommit?: (() => boolean) | undefined;\n readonly currentUserId: string;\n readonly requestedCursor: string | null;\n readonly response: OrganizationReadModelResponse;\n }): Promise<ApplyOrganizationReadModelResponseResult> {\n assertOrganizationReadModelResponse({\n currentUserId: input.currentUserId,\n response: input.response,\n });\n // The requester prune also retires pruned users' usage projections.\n await ensureSqlTables(this.execSql, organizationAccessProjectionTables);\n\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n const apply = (\n tx: Parameters<Parameters<typeof runtime.transaction>[0]>[0],\n ): Promise<ApplyOrganizationReadModelResponseResult> =>\n applyOrganizationReadModelResponseInTransaction(tx, {\n currentUserId: input.currentUserId,\n now: this.now,\n requestedCursor: input.requestedCursor,\n response: input.response,\n });\n const disposition = input.canCommit\n ? ((await runtime.guardedTransaction(apply, input.canCommit)).result ??\n \"stale\")\n : await runtime.transaction(apply);\n // An applied change follows an organization hint or mutation; in-flight\n // operations recover the directory again instead of reusing their memo.\n if (disposition === \"applied\")\n getOrCreatePrincipalPolicyCoordinator(this.execSql).invalidateRecovery(\n input.response.organizationId,\n );\n return disposition;\n }\n\n async purgeOrganizationReadModelProjection(\n organizationId: string,\n options: { readonly onlyRequesterUserId?: string } = {},\n ): Promise<void> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n await getClientSQLitePersistenceRuntime(this.execSql).transaction(\n async (tx) => {\n await purgeOrganizationReadModelProjectionInTransaction({\n onlyRequesterUserId: options.onlyRequesterUserId,\n organizationId,\n tx,\n });\n },\n );\n }\n\n /**\n * Purge one requester's access to an organization's presentation projections\n * after the server denied that requester. The denial is requester-scoped: the\n * shared read-model rows stay while another local identity in the same\n * database still holds a requester row, and organization-wide rows fall with\n * the last requester.\n */\n async purgeOrganizationAccessProjection(input: {\n readonly organizationId: string;\n readonly requesterUserId: string;\n }): Promise<void> {\n await ensureSqlTables(this.execSql, organizationAccessProjectionTables);\n await getClientSQLitePersistenceRuntime(this.execSql).transaction(\n async (tx) => {\n await tx\n .delete(organizationReadModelRequesters)\n .where(\n and(\n eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n ),\n eq(organizationReadModelRequesters.userId, input.requesterUserId),\n ),\n )\n .run();\n const [remainingRequester] = await tx\n .select({ userId: organizationReadModelRequesters.userId })\n .from(organizationReadModelRequesters)\n .where(\n eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n ),\n )\n .limit(1);\n if (!remainingRequester) {\n await purgeOrganizationReadModelProjectionInTransaction({\n organizationId: input.organizationId,\n tx,\n });\n }\n await purgeOrganizationDataUsageProjectionInTransaction({\n organizationId: input.organizationId,\n requesterUserId: input.requesterUserId,\n tx,\n });\n },\n );\n // A denial is a realtime-hinted access change: in-flight operations recover\n // the organization's directory again instead of reusing their memo.\n getOrCreatePrincipalPolicyCoordinator(this.execSql).invalidateRecovery(\n input.organizationId,\n );\n }\n\n /**\n * The organization's stored projection cursor, shared by every requester on\n * this device: the cursor a reconcile requests from. Null without one.\n */\n async loadOrganizationReadModelCursor(\n organizationId: string,\n ): Promise<string | null> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const [row] = await getClientSQLitePersistenceRuntime(this.execSql)\n .db.select({ cursor: organizationReadModelState.cursor })\n .from(organizationReadModelState)\n .where(eq(organizationReadModelState.organizationId, organizationId))\n .limit(1);\n return row?.cursor ?? null;\n }\n\n /**\n * The cursor this requester has applied, or null when it holds none. The\n * organization row's cursor is shared: another identity on this device may\n * have advanced it while this requester's own fields (for example\n * `isOrgAdmin`) still reflect an older response. Only the requester's own\n * applied cursor, while it is still the stored projection's cursor, proves\n * this requester is current. Realtime hints compare against it so a hint for\n * a cursor already applied costs no read.\n */\n async loadAppliedOrganizationReadModelCursor(input: {\n readonly organizationId: string;\n readonly requesterUserId: string;\n }): Promise<string | null> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const [row] = await getClientSQLitePersistenceRuntime(this.execSql)\n .db.select({ cursor: organizationReadModelRequesters.appliedCursor })\n .from(organizationReadModelRequesters)\n .innerJoin(\n organizationReadModelState,\n and(\n eq(\n organizationReadModelState.organizationId,\n organizationReadModelRequesters.organizationId,\n ),\n eq(\n organizationReadModelState.cursor,\n organizationReadModelRequesters.appliedCursor,\n ),\n ),\n )\n .where(\n and(\n eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n ),\n eq(organizationReadModelRequesters.userId, input.requesterUserId),\n ),\n )\n .limit(1);\n return row?.cursor ?? null;\n }\n\n /**\n * Every locally projected organization's pointer to its organization_profile\n * document, keyed by organization id.\n *\n * This is the only container-independent handle on that document. Callers\n * that need an org's display name from local state cannot rely on where the\n * document is linked: the provisioner writes it under a deterministic local\n * alias into the organization-metadata container, while a device that only\n * *synced* it (identity recovery, another member) keys it under the server\n * documentId in whichever container the grant arrived through.\n *\n * The local schema stores only the current read-model contract, so every\n * state row is eligible to provide its profile-document pointer.\n */\n async loadOrganizationProfileDocumentIds(): Promise<Map<string, string>> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const { db } = getClientSQLitePersistenceRuntime(this.execSql);\n const rows = await db\n .select({\n organizationId: organizationReadModelState.organizationId,\n profileDocumentId: organizationReadModelState.profileDocumentId,\n })\n .from(organizationReadModelState);\n\n return new Map(\n rows.flatMap((row) =>\n row.profileDocumentId\n ? [[row.organizationId, row.profileDocumentId]]\n : [],\n ),\n );\n }\n\n async loadOrganizationGroupDisplayNames(\n organizationId: string,\n ): Promise<ReadonlyMap<string, string>> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const { db } = getClientSQLitePersistenceRuntime(this.execSql);\n const rows = await db\n .select({\n groupId: organizationReadModelGroups.groupId,\n name: organizationReadModelGroups.name,\n })\n .from(organizationReadModelGroups)\n .where(eq(organizationReadModelGroups.organizationId, organizationId));\n return new Map(\n rows\n .filter((row) => row.name.length > 0)\n .map((row) => [row.groupId, row.name]),\n );\n }\n\n /** Local display cache only: these labels never enter a server request. */\n async saveOrganizationGroupDisplayNames(input: {\n organizationId: string;\n names: readonly { groupId: string; name: string; stateHash: string }[];\n stillCurrent: () => boolean;\n }): Promise<void> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n await getClientSQLitePersistenceRuntime(this.execSql).guardedTransaction(\n async (tx) => {\n for (const group of input.names) {\n await tx\n .update(organizationReadModelGroups)\n .set({ name: group.name })\n .where(\n and(\n eq(\n organizationReadModelGroups.organizationId,\n input.organizationId,\n ),\n eq(organizationReadModelGroups.groupId, group.groupId),\n eq(organizationReadModelGroups.stateHash, group.stateHash),\n ),\n )\n .run();\n }\n },\n input.stillCurrent,\n );\n }\n\n /**\n * Durably record a server denial before the revoked projection rows are\n * purged. The marker is what keeps a failed purge plus an offline restart\n * from serving the revoked projection; it is cleared only when an\n * authoritative reconcile stores fresh server state for the same scope.\n */\n async recordOrganizationPresentationDenials(\n scope: OrganizationPresentationDenialScope,\n projections: readonly OrganizationPresentationDenialProjection[],\n ): Promise<void> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const deniedAt = this.now().toISOString();\n await getClientSQLitePersistenceRuntime(this.execSql).transaction(\n async (tx) => {\n for (const projection of new Set(projections)) {\n await tx\n .insert(organizationPresentationDenials)\n .values({\n organizationId: scope.organizationId,\n requesterUserId: scope.requesterUserId,\n projection,\n deniedAt,\n })\n .onConflictDoUpdate({\n target: [\n organizationPresentationDenials.organizationId,\n organizationPresentationDenials.requesterUserId,\n organizationPresentationDenials.projection,\n ],\n set: { deniedAt },\n })\n .run();\n }\n },\n );\n }\n\n async hasOrganizationPresentationDenial(\n scope: OrganizationPresentationDenialScope,\n projection: OrganizationPresentationDenialProjection,\n ): Promise<boolean> {\n await ensureSqlTables(this.execSql, organizationReadModelTables);\n const rows = await getClientSQLitePersistenceRuntime(this.execSql)\n .db.select({ projection: organizationPresentationDenials.projection })\n .from(organizationPresentationDenials)\n .where(\n and(\n eq(\n organizationPresentationDenials.organizationId,\n scope.organizationId,\n ),\n eq(\n organizationPresentationDenials.requesterUserId,\n scope.requesterUserId,\n ),\n eq(organizationPresentationDenials.projection, projection),\n ),\n )\n .limit(1);\n return rows.length > 0;\n }\n}\n"]}
@@ -929,6 +929,7 @@ export declare class ApiClient extends ApiClientAreas {
929
929
  version: number;
930
930
  };
931
931
  } | undefined;
932
+ readModel?: unknown;
932
933
  } | null>;
933
934
  commitOrganizationGroupPolicyResult: (organizationId: string, groupId: string, input: import("../validators/request/index.js").CommitOrganizationGroupPolicyRequest, options?: import("./types.js").RequestResultOptions) => Promise<import("./types.js").RequestResult<import("../validators/response/index.js").CommitOrganizationGroupPolicyResponse>>;
934
935
  getOrganizationPolicyHistoryResult: (organizationId: string, stateHash: string, options?: Parameters<typeof import("./organizationPolicyHistory.js").getOrganizationPolicyHistoryResult>[3]) => Promise<import("./types.js").RequestResult<import("../validators/response/index.js").OrganizationPolicyHistoryResponse>>;
@@ -1165,6 +1166,7 @@ export declare class ApiClient extends ApiClientAreas {
1165
1166
  version: number;
1166
1167
  };
1167
1168
  };
1169
+ readModel?: unknown;
1168
1170
  } | null>;
1169
1171
  createOrganizationGroupResult: (organizationId: string, input: {
1170
1172
  organizationPolicy: {
@@ -1399,6 +1401,7 @@ export declare class ApiClient extends ApiClientAreas {
1399
1401
  version: number;
1400
1402
  };
1401
1403
  };
1404
+ readModel?: unknown;
1402
1405
  }>>;
1403
1406
  deleteOrganizationGroup: (organizationId: string, groupId: string, input: {
1404
1407
  organizationPolicy: {
@@ -2304,7 +2307,7 @@ export declare class ApiClient extends ApiClientAreas {
2304
2307
  updatedAt: string;
2305
2308
  systemSlot?: string | null | undefined;
2306
2309
  } | null>;
2307
- shareContainerResult: (containerId: string, input: import("../validators/request/index.js").ContainerMutationRequest, options?: import("./types.js").RequestResultOptions) => Promise<import("./types.js").RequestResult<import("../validators/response/index.js").ContainerMutationResponse>>;
2310
+ shareContainerResult: (containerId: string, input: import("../validators/request/index.js").ContainerMutationRequest, options?: import("./types.js").RequestResultOptions) => Promise<import("./types.js").RequestResult<import("../validators/response/index.js").ContainerShareResponse>>;
2308
2311
  revokeContainer: (containerId: string, input: import("../validators/request/index.js").ContainerRotationRequest, options?: import("./types.js").RequestResultOptions) => Promise<{
2309
2312
  containerKek: {
2310
2313
  containerKeyEpoch: number;
@@ -1,5 +1,5 @@
1
1
  import type { ContainerCreateWithMetadataDocumentRequest, ContainerMutationRequest, ContainerReciteRequest, ContainerRotationRequest } from "../../validators/request/index.js";
2
- import type { ContainerCreateWithMetadataDocumentResponse, ContainerDeleteResponse, ContainerMutationResponse, ContainerRotationResponse } from "../../validators/response/index.js";
2
+ import type { ContainerCreateWithMetadataDocumentResponse, ContainerDeleteResponse, ContainerMutationResponse, ContainerRotationResponse, ContainerShareResponse } from "../../validators/response/index.js";
3
3
  import type { RequestResult, RequestResultOptions } from "../types.js";
4
4
  import { type ApiClientContext } from "./apiClientContext.js";
5
5
  import type { ApiClientSelf, DeleteContainerOptions } from "./apiClientSelf.js";
@@ -97,7 +97,7 @@ export declare class ContainerMutationArea {
97
97
  systemSlot?: string | null | undefined;
98
98
  } | null>;
99
99
  /** Status-bearing share: a stale path is retryable, a refusal is not. */
100
- shareContainerResult(containerId: string, input: ContainerMutationRequest, options?: RequestResultOptions): Promise<RequestResult<ContainerMutationResponse>>;
100
+ shareContainerResult(containerId: string, input: ContainerMutationRequest, options?: RequestResultOptions): Promise<RequestResult<ContainerShareResponse>>;
101
101
  revokeContainer(containerId: string, input: ContainerRotationRequest, options?: RequestResultOptions): Promise<{
102
102
  containerKek: {
103
103
  containerKeyEpoch: number;
@@ -48,8 +48,9 @@ export class ContainerMutationArea {
48
48
  }
49
49
  /** Status-bearing share: a stale path is retryable, a refusal is not. */
50
50
  async shareContainerResult(containerId, input, options = {}) {
51
+ const { readModelCursor, ...requestOptions } = options;
51
52
  try {
52
- return await this.context.sendResult(containerShare, containerShare.path(containerId), shareContainerOperation, input, options);
53
+ return await this.context.sendResult(containerShare, containerShare.path(containerId, readModelCursor), shareContainerOperation, input, requestOptions);
53
54
  }
54
55
  finally {
55
56
  this.self.clearWriterProjectionCaches();
@@ -1 +1 @@
1
- {"version":3,"file":"containerMutations.js","sourceRoot":"","sources":["containerMutations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AAazC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACL,eAAe,EACf,mCAAmC,EACnC,eAAe,EACf,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAyB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGvE,+EAA+E;AAC/E,MAAM,mBAAmB,GAAG;IAC1B,IAAI,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE,KAAK,EAAE,aAAa,EAAE;IACjE,KAAK,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,KAAK,EAAE,cAAc,EAAE;IACpE,MAAM,EAAE,EAAE,SAAS,EAAE,wBAAwB,EAAE,KAAK,EAAE,eAAe,EAAE;CAC/D,CAAC;AAEX;;;GAGG;AACH,MAAM,OA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O,CAAC,kBAAkB,CAAC,EAC7D,wBAAwB,EACxB,SAAS,EACT,OAAO,CACR;aACA,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;CACF","sourcesContent":["import {\n createContainerOperation,\n createContainerWithMetadataDocumentOperation,\n deleteContainerOperation,\n moveContainerOperation,\n reciteContainerOperation,\n rekeyContainerOperation,\n revokeContainerOperation,\n shareContainerOperation,\n} from \"@tearleads/validators/operation\";\nimport type {\n ContainerCreateWithMetadataDocumentRequest,\n ContainerMutationRequest,\n ContainerReciteRequest,\n ContainerRotationRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerCreateWithMetadataDocumentResponse,\n ContainerDeleteResponse,\n ContainerMutationResponse,\n ContainerRotationResponse,\n} from \"@tearleads/validators/response\";\nimport { bindPrototypeMethods } from \"../requestInternals\";\nimport {\n containerCreate,\n containerCreateWithMetadataDocument,\n containerDelete,\n containerMove,\n containerRecite,\n containerRekey,\n containerRevoke,\n containerShare,\n} from \"../routes/containers/mutations\";\nimport type { RequestResult, RequestResultOptions } from \"../types\";\nimport { type ApiClientContext, dataOrNull } from \"./apiClientContext\";\nimport type { ApiClientSelf, DeleteContainerOptions } from \"./apiClientSelf\";\n\n/** The rotations that may carry descendant rekeys, each with its operation. */\nconst CONTAINER_ROTATIONS = {\n move: { operation: moveContainerOperation, route: containerMove },\n rekey: { operation: rekeyContainerOperation, route: containerRekey },\n revoke: { operation: revokeContainerOperation, route: containerRevoke },\n} as const;\n\n/**\n * Container creates, shares, rotations, recitals, and deletes. Every access\n * change clears the writer-projection caches, whatever its outcome.\n */\nexport class ContainerMutationArea {\n constructor(\n private readonly context: ApiClientContext,\n private readonly self: Pick<\n ApiClientSelf,\n | \"clearWriterProjectionCaches\"\n | \"deleteContainerResult\"\n | \"shareContainerResult\"\n >,\n ) {\n bindPrototypeMethods(this, ContainerMutationArea.prototype);\n }\n\n private async rotationResult(\n rotation: keyof typeof CONTAINER_ROTATIONS,\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions,\n ): Promise<RequestResult<ContainerRotationResponse>> {\n const { operation, route } = CONTAINER_ROTATIONS[rotation];\n try {\n return await this.context.sendResult(\n route,\n route.path(containerId),\n operation,\n input,\n options,\n );\n } finally {\n this.self.clearWriterProjectionCaches();\n }\n }\n\n createContainer(\n input: ContainerMutationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.context.send(\n containerCreate,\n containerCreate.path,\n createContainerOperation,\n input,\n options,\n );\n }\n\n async createContainerResult(\n input: ContainerMutationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerMutationResponse>> {\n return this.context.sendResult(\n containerCreate,\n containerCreate.path,\n createContainerOperation,\n input,\n options,\n );\n }\n\n createContainerWithMetadataDocument(\n input: ContainerCreateWithMetadataDocumentRequest,\n options: RequestResultOptions = {},\n ) {\n return this.context.send(\n containerCreateWithMetadataDocument,\n containerCreateWithMetadataDocument.path,\n createContainerWithMetadataDocumentOperation,\n input,\n options,\n );\n }\n\n createContainerWithMetadataDocumentResult(\n input: ContainerCreateWithMetadataDocumentRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerCreateWithMetadataDocumentResponse>> {\n return this.context.sendResult(\n containerCreateWithMetadataDocument,\n containerCreateWithMetadataDocument.path,\n createContainerWithMetadataDocumentOperation,\n input,\n options,\n );\n }\n\n shareContainer(\n containerId: string,\n input: ContainerMutationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.self\n .shareContainerResult(containerId, input, options)\n .then(dataOrNull);\n }\n\n /** Status-bearing share: a stale path is retryable, a refusal is not. */\n async shareContainerResult(\n containerId: string,\n input: ContainerMutationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerMutationResponse>> {\n try {\n return await this.context.sendResult(\n containerShare,\n containerShare.path(containerId),\n shareContainerOperation,\n input,\n options,\n );\n } finally {\n this.self.clearWriterProjectionCaches();\n }\n }\n\n revokeContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.rotationResult(\"revoke\", containerId, input, options).then(\n dataOrNull,\n );\n }\n\n rekeyContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.rotationResult(\"rekey\", containerId, input, options).then(\n dataOrNull,\n );\n }\n\n /**\n * Status-bearing rotations: a caller that must tell a permanent refusal (403\n * once ancestor write access is revoked, 402) from a transient 5xx or an\n * offline blip cannot do so through the plain methods, which collapse both to\n * null. They are also how a rotation learns which descendant rekeys it must\n * carry.\n */\n rekeyContainerResult(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerRotationResponse>> {\n return this.rotationResult(\"rekey\", containerId, input, options);\n }\n\n revokeContainerResult(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerRotationResponse>> {\n return this.rotationResult(\"revoke\", containerId, input, options);\n }\n\n moveContainerResult(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerRotationResponse>> {\n return this.rotationResult(\"move\", containerId, input, options);\n }\n\n reciteContainer(\n containerId: string,\n input: ContainerReciteRequest,\n options: RequestResultOptions = {},\n ) {\n return this.context\n .send(\n containerRecite,\n containerRecite.path(containerId),\n reciteContainerOperation,\n input,\n options,\n )\n .finally(() => this.self.clearWriterProjectionCaches());\n }\n\n moveContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.rotationResult(\"move\", containerId, input, options).then(\n dataOrNull,\n );\n }\n\n async deleteContainer(\n containerId: string,\n options: DeleteContainerOptions = {},\n ) {\n const result = await this.self.deleteContainerResult(containerId, options);\n return result.ok ? result.data : null;\n }\n\n deleteContainerResult(\n containerId: string,\n options: DeleteContainerOptions = {},\n ): Promise<RequestResult<ContainerDeleteResponse>> {\n return this.context\n .sendResult(\n containerDelete,\n containerDelete.path(containerId, options.requiredAncestorId),\n deleteContainerOperation,\n undefined,\n options,\n )\n .finally(() => {\n this.self.clearWriterProjectionCaches();\n });\n }\n}\n"]}
1
+ {"version":3,"file":"containerMutations.js","sourceRoot":"","sources":["containerMutations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AAczC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACL,eAAe,EACf,mCAAmC,EACnC,eAAe,EACf,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAyB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGvE,+EAA+E;AAC/E,MAAM,mBAAmB,GAAG;IAC1B,IAAI,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE,KAAK,EAAE,aAAa,EAAE;IACjE,KAAK,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,KAAK,EAAE,cAAc,EAAE;IACpE,MAAM,EAAE,EAAE,SAAS,EAAE,wBAAwB,EAAE,KAAK,EAAE,eAAe,EAAE;CAC/D,CAAC;AAEX;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAEb;IACA;IAFnB,YACmB,OAAyB,EACzB,IAKhB;QANgB,YAAO,GAAP,OAAO,CAAkB;QACzB,SAAI,GAAJ,IAAI,CAKpB;QAED,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;IAEO,KAAK,CAAC,cAAc,CAC1B,QAA0C,EAC1C,WAAmB,EACnB,KAA+B,EAC/B,OAA6B;QAE7B,MAAM,EAAE,SAAS,EAAE,KAAK,EAA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;QAElC,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,eAAe,CACb,WAAmB,EACnB,KAA6B,EAC7B,UAAgC,EAAE;QAElC,OAAO,IAAI,CAAC,OAAO;aAChB,IAAI,CACH,eAAe,EACf,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,EACjC,wBAAwB,EACxB,KAAK,EACL,OAAO,CACR;aACA,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,aAAa,CACX,WAAmB,EACnB,KAA+B,EAC/B,UAAgC,EAAE;QAElC,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAClE,UAAU,CACX,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,WAAmB,EACnB,UAAkC,EAAE;QAEpC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC3E,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACxC,CAAC;IAED,qBAAqB,CACnB,WAAmB,EACnB,UAAkC,EAAE;QAEpC,OAAO,IAAI,CAAC,OAAO;aAChB,UAAU,CACT,eAAe,EACf,eAAe,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,kBAAkB,CAAC,EAC7D,wBAAwB,EACxB,SAAS,EACT,OAAO,CACR;aACA,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;CACF","sourcesContent":["import {\n createContainerOperation,\n createContainerWithMetadataDocumentOperation,\n deleteContainerOperation,\n moveContainerOperation,\n reciteContainerOperation,\n rekeyContainerOperation,\n revokeContainerOperation,\n shareContainerOperation,\n} from \"@tearleads/validators/operation\";\nimport type {\n ContainerCreateWithMetadataDocumentRequest,\n ContainerMutationRequest,\n ContainerReciteRequest,\n ContainerRotationRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerCreateWithMetadataDocumentResponse,\n ContainerDeleteResponse,\n ContainerMutationResponse,\n ContainerRotationResponse,\n ContainerShareResponse,\n} from \"@tearleads/validators/response\";\nimport { bindPrototypeMethods } from \"../requestInternals\";\nimport {\n containerCreate,\n containerCreateWithMetadataDocument,\n containerDelete,\n containerMove,\n containerRecite,\n containerRekey,\n containerRevoke,\n containerShare,\n} from \"../routes/containers/mutations\";\nimport type { RequestResult, RequestResultOptions } from \"../types\";\nimport { type ApiClientContext, dataOrNull } from \"./apiClientContext\";\nimport type { ApiClientSelf, DeleteContainerOptions } from \"./apiClientSelf\";\n\n/** The rotations that may carry descendant rekeys, each with its operation. */\nconst CONTAINER_ROTATIONS = {\n move: { operation: moveContainerOperation, route: containerMove },\n rekey: { operation: rekeyContainerOperation, route: containerRekey },\n revoke: { operation: revokeContainerOperation, route: containerRevoke },\n} as const;\n\n/**\n * Container creates, shares, rotations, recitals, and deletes. Every access\n * change clears the writer-projection caches, whatever its outcome.\n */\nexport class ContainerMutationArea {\n constructor(\n private readonly context: ApiClientContext,\n private readonly self: Pick<\n ApiClientSelf,\n | \"clearWriterProjectionCaches\"\n | \"deleteContainerResult\"\n | \"shareContainerResult\"\n >,\n ) {\n bindPrototypeMethods(this, ContainerMutationArea.prototype);\n }\n\n private async rotationResult(\n rotation: keyof typeof CONTAINER_ROTATIONS,\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions,\n ): Promise<RequestResult<ContainerRotationResponse>> {\n const { operation, route } = CONTAINER_ROTATIONS[rotation];\n try {\n return await this.context.sendResult(\n route,\n route.path(containerId),\n operation,\n input,\n options,\n );\n } finally {\n this.self.clearWriterProjectionCaches();\n }\n }\n\n createContainer(\n input: ContainerMutationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.context.send(\n containerCreate,\n containerCreate.path,\n createContainerOperation,\n input,\n options,\n );\n }\n\n async createContainerResult(\n input: ContainerMutationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerMutationResponse>> {\n return this.context.sendResult(\n containerCreate,\n containerCreate.path,\n createContainerOperation,\n input,\n options,\n );\n }\n\n createContainerWithMetadataDocument(\n input: ContainerCreateWithMetadataDocumentRequest,\n options: RequestResultOptions = {},\n ) {\n return this.context.send(\n containerCreateWithMetadataDocument,\n containerCreateWithMetadataDocument.path,\n createContainerWithMetadataDocumentOperation,\n input,\n options,\n );\n }\n\n createContainerWithMetadataDocumentResult(\n input: ContainerCreateWithMetadataDocumentRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerCreateWithMetadataDocumentResponse>> {\n return this.context.sendResult(\n containerCreateWithMetadataDocument,\n containerCreateWithMetadataDocument.path,\n createContainerWithMetadataDocumentOperation,\n input,\n options,\n );\n }\n\n shareContainer(\n containerId: string,\n input: ContainerMutationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.self\n .shareContainerResult(containerId, input, options)\n .then(dataOrNull);\n }\n\n /** Status-bearing share: a stale path is retryable, a refusal is not. */\n async shareContainerResult(\n containerId: string,\n input: ContainerMutationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerShareResponse>> {\n const { readModelCursor, ...requestOptions } = options;\n try {\n return await this.context.sendResult(\n containerShare,\n containerShare.path(containerId, readModelCursor),\n shareContainerOperation,\n input,\n requestOptions,\n );\n } finally {\n this.self.clearWriterProjectionCaches();\n }\n }\n\n revokeContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.rotationResult(\"revoke\", containerId, input, options).then(\n dataOrNull,\n );\n }\n\n rekeyContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.rotationResult(\"rekey\", containerId, input, options).then(\n dataOrNull,\n );\n }\n\n /**\n * Status-bearing rotations: a caller that must tell a permanent refusal (403\n * once ancestor write access is revoked, 402) from a transient 5xx or an\n * offline blip cannot do so through the plain methods, which collapse both to\n * null. They are also how a rotation learns which descendant rekeys it must\n * carry.\n */\n rekeyContainerResult(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerRotationResponse>> {\n return this.rotationResult(\"rekey\", containerId, input, options);\n }\n\n revokeContainerResult(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerRotationResponse>> {\n return this.rotationResult(\"revoke\", containerId, input, options);\n }\n\n moveContainerResult(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<ContainerRotationResponse>> {\n return this.rotationResult(\"move\", containerId, input, options);\n }\n\n reciteContainer(\n containerId: string,\n input: ContainerReciteRequest,\n options: RequestResultOptions = {},\n ) {\n return this.context\n .send(\n containerRecite,\n containerRecite.path(containerId),\n reciteContainerOperation,\n input,\n options,\n )\n .finally(() => this.self.clearWriterProjectionCaches());\n }\n\n moveContainer(\n containerId: string,\n input: ContainerRotationRequest,\n options: RequestResultOptions = {},\n ) {\n return this.rotationResult(\"move\", containerId, input, options).then(\n dataOrNull,\n );\n }\n\n async deleteContainer(\n containerId: string,\n options: DeleteContainerOptions = {},\n ) {\n const result = await this.self.deleteContainerResult(containerId, options);\n return result.ok ? result.data : null;\n }\n\n deleteContainerResult(\n containerId: string,\n options: DeleteContainerOptions = {},\n ): Promise<RequestResult<ContainerDeleteResponse>> {\n return this.context\n .sendResult(\n containerDelete,\n containerDelete.path(containerId, options.requiredAncestorId),\n deleteContainerOperation,\n undefined,\n options,\n )\n .finally(() => {\n this.self.clearWriterProjectionCaches();\n });\n }\n}\n"]}
@@ -516,6 +516,7 @@ export declare class PrincipalPolicyArea {
516
516
  version: number;
517
517
  };
518
518
  } | undefined;
519
+ readModel?: unknown;
519
520
  } | null>;
520
521
  /**
521
522
  * Status-bearing group policy commit. A rematerialized rotation the server
@@ -571,6 +572,7 @@ export declare class PrincipalPolicyArea {
571
572
  version: number;
572
573
  };
573
574
  };
575
+ readModel?: unknown;
574
576
  } | null>;
575
577
  createOrganizationGroupResult(...args: Parameters<PrincipalPolicyRequests["createResult"]>): Promise<RequestResult<{
576
578
  group: {
@@ -619,6 +621,7 @@ export declare class PrincipalPolicyArea {
619
621
  version: number;
620
622
  };
621
623
  };
624
+ readModel?: unknown;
622
625
  }>>;
623
626
  deleteOrganizationGroup(...args: Parameters<PrincipalPolicyRequests["deleteResult"]>): Promise<{
624
627
  deleted: true;
@@ -463,6 +463,7 @@ export declare class PrincipalPolicyRequests {
463
463
  version: number;
464
464
  };
465
465
  };
466
+ readModel?: unknown;
466
467
  }>>;
467
468
  deleteResult(organizationId: string, groupId: string, input: DeleteOrganizationGroupRequest, options?: RequestResultOptions): Promise<RequestResult<{
468
469
  deleted: true;
@@ -603,5 +604,6 @@ export declare class PrincipalPolicyRequests {
603
604
  version: number;
604
605
  };
605
606
  } | undefined;
607
+ readModel?: unknown;
606
608
  }>>;
607
609
  }
@@ -68,14 +68,15 @@ export class PrincipalPolicyRequests {
68
68
  }).finally(() => this.cache.delete(key));
69
69
  }
70
70
  createResult(organizationId, input, options = {}) {
71
+ const { readModelCursor, ...requestOptions } = options;
71
72
  return this.groupMutation(organizationId, input.groupId, () => principalHistoryRequest(this.runtime, {
72
- path: createOrganizationGroup.path(organizationId),
73
+ path: createOrganizationGroup.path(organizationId, readModelCursor),
73
74
  validator: createOrganizationGroup.isResponse,
74
75
  method: createOrganizationGroup.method,
75
76
  body: JSON.stringify(input),
76
77
  options: {
77
78
  expectedPaymentRequiredOrganizationId: organizationId,
78
- ...options,
79
+ ...requestOptions,
79
80
  },
80
81
  operation: createOrganizationGroupOperation,
81
82
  }));
@@ -110,17 +111,18 @@ export class PrincipalPolicyRequests {
110
111
  async commitResult(organizationId, groupId, input, options = {}) {
111
112
  const groupKey = JSON.stringify(["group", groupId]);
112
113
  const organizationKey = JSON.stringify(["organization", organizationId]);
114
+ const { readModelCursor, ...requestOptions } = options;
113
115
  this.cache.delete(groupKey);
114
116
  this.cache.delete(organizationKey);
115
117
  try {
116
118
  return await principalHistoryRequest(this.runtime, {
117
- path: commitOrganizationGroupPolicy.path(organizationId, groupId),
119
+ path: commitOrganizationGroupPolicy.path(organizationId, groupId, readModelCursor),
118
120
  validator: commitOrganizationGroupPolicy.isResponse,
119
121
  method: commitOrganizationGroupPolicy.method,
120
122
  body: JSON.stringify(input),
121
123
  options: {
122
124
  expectedPaymentRequiredOrganizationId: organizationId,
123
- ...options,
125
+ ...requestOptions,
124
126
  },
125
127
  operation: commitOrganizationGroupPolicyOperation,
126
128
  });
@@ -1 +1 @@
1
- {"version":3,"file":"principalPolicyRequests.js","sourceRoot":"","sources":["principalPolicyRequests.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sCAAsC,EACtC,gCAAgC,EAChC,gCAAgC,EAChC,oCAAoC,EACpC,2BAA2B,GAC5B,MAAM,iCAAiC,CAAC;AAazC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,2BAA2B,EAG3B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AAGpC,MAAM,OAAO,uBAAuB;IAEf;IACA;IAGA;IALnB,YACmB,OAA0B,E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BACD,SAAS,EAAE,sCAAsC;aAClD,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;YACnC,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACrC,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n commitOrganizationGroupPolicyOperation,\n createOrganizationGroupOperation,\n deleteOrganizationGroupOperation,\n getPrincipalMemberEnvelopesOperation,\n putPrincipalPolicyOperation,\n} from \"@tearleads/validators/operation\";\nimport type {\n CommitOrganizationGroupPolicyRequest,\n CreateOrganizationGroupWithPolicyRequest,\n DeleteOrganizationGroupRequest,\n OrganizationPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n CurrentPrincipalMemberEnvelopesResponse,\n PrincipalPolicyBundleResponse,\n} from \"@tearleads/validators/response\";\nimport type { BoundedCache } from \"./ApiCache\";\nimport type { ApiRequestRuntime } from \"./apiRequestRuntime\";\nimport { principalHistoryRequest } from \"./principalHistoryRequest\";\nimport {\n collectPrincipalPolicyPages,\n type PrincipalPolicyDiscoveryOptions,\n type PrincipalPolicyPageReadOptions,\n readPrincipalPolicyDiscovery,\n readPrincipalPolicyPages,\n} from \"./principalPolicyPages\";\nimport { readProjectionPolicyHistoryPages } from \"./projectionPolicyHistoryPages\";\nimport { dedupedRequest } from \"./requestInternals\";\nimport { createOrganizationGroup } from \"./routes/organizations/createGroup\";\nimport { deleteOrganizationGroup } from \"./routes/organizations/deleteGroup\";\nimport {\n commitOrganizationGroupPolicy,\n getPrincipalMemberEnvelopes,\n putPrincipalPolicy,\n} from \"./routes/principals/policy\";\nimport type { RequestResult, RequestResultOptions } from \"./types\";\n\nexport class PrincipalPolicyRequests {\n constructor(\n private readonly runtime: ApiRequestRuntime,\n private readonly cache: BoundedCache<\n Promise<PrincipalPolicyBundleResponse | null>\n >,\n private readonly clearWriterProjectionCaches: () => void,\n ) {}\n\n publicPages(\n source: Parameters<typeof readProjectionPolicyHistoryPages>[1],\n options: Parameters<typeof readProjectionPolicyHistoryPages>[2] = {},\n ) {\n return readProjectionPolicyHistoryPages(this.runtime, source, options);\n }\n\n pages(\n principalType: \"group\" | \"organization\",\n principalId: string,\n options: PrincipalPolicyPageReadOptions = {},\n ) {\n return readPrincipalPolicyPages(\n this.runtime,\n principalType,\n principalId,\n options,\n );\n }\n\n discover(\n principalType: \"group\" | \"organization\",\n principalId: string,\n options: PrincipalPolicyDiscoveryOptions = {},\n ) {\n return readPrincipalPolicyDiscovery(\n this.runtime,\n principalType,\n principalId,\n options,\n );\n }\n\n /**\n * Every member envelope of one named state. A response that fails its\n * schema, or names another state, is a `shape` failure the caller can treat\n * as tampering; an unknown state is an HTTP 404.\n */\n memberEnvelopes(\n principalType: \"group\" | \"organization\",\n principalId: string,\n stateHash: string,\n ): Promise<RequestResult<CurrentPrincipalMemberEnvelopesResponse>> {\n return principalHistoryRequest(this.runtime, {\n path: getPrincipalMemberEnvelopes.path(\n principalType,\n principalId,\n stateHash,\n ),\n validator: (value): value is CurrentPrincipalMemberEnvelopesResponse =>\n getPrincipalMemberEnvelopes.isResponse(value) &&\n value.principalType === principalType &&\n value.principalId === principalId &&\n value.stateHash === stateHash,\n method: getPrincipalMemberEnvelopes.method,\n options: { reportErrors: false },\n operation: getPrincipalMemberEnvelopesOperation,\n });\n }\n\n get(\n principalType: \"group\" | \"organization\",\n principalId: string,\n options: RequestResultOptions = {},\n ) {\n const request = () =>\n collectPrincipalPolicyPages(\n this.runtime,\n principalType,\n principalId,\n options,\n );\n const key = JSON.stringify([principalType, principalId]);\n // Cancellation, reporting and renewal preferences belong to their caller.\n return Object.keys(options).length > 0\n ? request()\n : dedupedRequest(this.cache, key, request);\n }\n\n put(...args: Parameters<PrincipalPolicyRequests[\"putResult\"]>) {\n return this.putResult(...args).then((result) =>\n result.ok ? result.data : null,\n );\n }\n\n putResult(\n principalType: \"organization\",\n principalId: string,\n input: OrganizationPrincipalPolicyRequest,\n options: RequestResultOptions = {},\n ) {\n const key = JSON.stringify([principalType, principalId]);\n this.cache.delete(key);\n return principalHistoryRequest(this.runtime, {\n path: putPrincipalPolicy.path(principalType, principalId),\n validator: putPrincipalPolicy.isResponse,\n method: putPrincipalPolicy.method,\n body: JSON.stringify(input),\n options: {\n expectedPaymentRequiredOrganizationId: principalId,\n ...options,\n },\n operation: putPrincipalPolicyOperation,\n }).finally(() => this.cache.delete(key));\n }\n\n createResult(\n organizationId: string,\n input: CreateOrganizationGroupWithPolicyRequest,\n options: RequestResultOptions = {},\n ) {\n return this.groupMutation(organizationId, input.groupId, () =>\n principalHistoryRequest(this.runtime, {\n path: createOrganizationGroup.path(organizationId),\n validator: createOrganizationGroup.isResponse,\n method: createOrganizationGroup.method,\n body: JSON.stringify(input),\n options: {\n expectedPaymentRequiredOrganizationId: organizationId,\n ...options,\n },\n operation: createOrganizationGroupOperation,\n }),\n );\n }\n\n deleteResult(\n organizationId: string,\n groupId: string,\n input: DeleteOrganizationGroupRequest,\n options: RequestResultOptions = {},\n ) {\n return this.groupMutation(organizationId, groupId, () =>\n principalHistoryRequest(this.runtime, {\n path: deleteOrganizationGroup.path(organizationId, groupId),\n validator: deleteOrganizationGroup.isResponse,\n method: deleteOrganizationGroup.method,\n body: JSON.stringify(input),\n options: {\n expectedPaymentRequiredOrganizationId: organizationId,\n ...options,\n },\n operation: deleteOrganizationGroupOperation,\n }),\n );\n }\n\n private async groupMutation<T>(\n organizationId: string,\n groupId: string,\n request: () => Promise<T>,\n ): Promise<T> {\n const groupKey = JSON.stringify([\"group\", groupId]);\n const organizationKey = JSON.stringify([\"organization\", organizationId]);\n this.cache.delete(groupKey);\n this.cache.delete(organizationKey);\n try {\n return await request();\n } finally {\n this.cache.delete(groupKey);\n this.cache.delete(organizationKey);\n this.clearWriterProjectionCaches();\n }\n }\n\n async commitResult(\n organizationId: string,\n groupId: string,\n input: CommitOrganizationGroupPolicyRequest,\n options: RequestResultOptions = {},\n ) {\n const groupKey = JSON.stringify([\"group\", groupId]);\n const organizationKey = JSON.stringify([\"organization\", organizationId]);\n this.cache.delete(groupKey);\n this.cache.delete(organizationKey);\n try {\n return await principalHistoryRequest(this.runtime, {\n path: commitOrganizationGroupPolicy.path(organizationId, groupId),\n validator: commitOrganizationGroupPolicy.isResponse,\n method: commitOrganizationGroupPolicy.method,\n body: JSON.stringify(input),\n options: {\n expectedPaymentRequiredOrganizationId: organizationId,\n ...options,\n },\n operation: commitOrganizationGroupPolicyOperation,\n });\n } finally {\n this.cache.delete(groupKey);\n this.cache.delete(organizationKey);\n this.clearWriterProjectionCaches();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"principalPolicyRequests.js","sourceRoot":"","sources":["principalPolicyRequests.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sCAAsC,EACtC,gCAAgC,EAChC,gCAAgC,EAChC,oCAAoC,EACpC,2BAA2B,GAC5B,MAAM,iCAAiC,CAAC;AAazC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,2BAA2B,EAG3B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AAGpC,MAAM,OAAO,uBAAuB;IAEf;IACA;IAGA;IALnB,YACmB,OAA0B,EAC1B,KAEhB,EACgB,2BAAuC;QAJvC,YAAO,GAAP,OAAO,CAAmB;QAC1B,UAAK,GAAL,KAAK,CAErB;QACgB,gCAA2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ACP,qCAAqC,EAAE,cAAc;oBACrD,GAAG,cAAc;iBAClB;gBACD,SAAS,EAAE,sCAAsC;aAClD,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;YACnC,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACrC,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n commitOrganizationGroupPolicyOperation,\n createOrganizationGroupOperation,\n deleteOrganizationGroupOperation,\n getPrincipalMemberEnvelopesOperation,\n putPrincipalPolicyOperation,\n} from \"@tearleads/validators/operation\";\nimport type {\n CommitOrganizationGroupPolicyRequest,\n CreateOrganizationGroupWithPolicyRequest,\n DeleteOrganizationGroupRequest,\n OrganizationPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n CurrentPrincipalMemberEnvelopesResponse,\n PrincipalPolicyBundleResponse,\n} from \"@tearleads/validators/response\";\nimport type { BoundedCache } from \"./ApiCache\";\nimport type { ApiRequestRuntime } from \"./apiRequestRuntime\";\nimport { principalHistoryRequest } from \"./principalHistoryRequest\";\nimport {\n collectPrincipalPolicyPages,\n type PrincipalPolicyDiscoveryOptions,\n type PrincipalPolicyPageReadOptions,\n readPrincipalPolicyDiscovery,\n readPrincipalPolicyPages,\n} from \"./principalPolicyPages\";\nimport { readProjectionPolicyHistoryPages } from \"./projectionPolicyHistoryPages\";\nimport { dedupedRequest } from \"./requestInternals\";\nimport { createOrganizationGroup } from \"./routes/organizations/createGroup\";\nimport { deleteOrganizationGroup } from \"./routes/organizations/deleteGroup\";\nimport {\n commitOrganizationGroupPolicy,\n getPrincipalMemberEnvelopes,\n putPrincipalPolicy,\n} from \"./routes/principals/policy\";\nimport type { RequestResult, RequestResultOptions } from \"./types\";\n\nexport class PrincipalPolicyRequests {\n constructor(\n private readonly runtime: ApiRequestRuntime,\n private readonly cache: BoundedCache<\n Promise<PrincipalPolicyBundleResponse | null>\n >,\n private readonly clearWriterProjectionCaches: () => void,\n ) {}\n\n publicPages(\n source: Parameters<typeof readProjectionPolicyHistoryPages>[1],\n options: Parameters<typeof readProjectionPolicyHistoryPages>[2] = {},\n ) {\n return readProjectionPolicyHistoryPages(this.runtime, source, options);\n }\n\n pages(\n principalType: \"group\" | \"organization\",\n principalId: string,\n options: PrincipalPolicyPageReadOptions = {},\n ) {\n return readPrincipalPolicyPages(\n this.runtime,\n principalType,\n principalId,\n options,\n );\n }\n\n discover(\n principalType: \"group\" | \"organization\",\n principalId: string,\n options: PrincipalPolicyDiscoveryOptions = {},\n ) {\n return readPrincipalPolicyDiscovery(\n this.runtime,\n principalType,\n principalId,\n options,\n );\n }\n\n /**\n * Every member envelope of one named state. A response that fails its\n * schema, or names another state, is a `shape` failure the caller can treat\n * as tampering; an unknown state is an HTTP 404.\n */\n memberEnvelopes(\n principalType: \"group\" | \"organization\",\n principalId: string,\n stateHash: string,\n ): Promise<RequestResult<CurrentPrincipalMemberEnvelopesResponse>> {\n return principalHistoryRequest(this.runtime, {\n path: getPrincipalMemberEnvelopes.path(\n principalType,\n principalId,\n stateHash,\n ),\n validator: (value): value is CurrentPrincipalMemberEnvelopesResponse =>\n getPrincipalMemberEnvelopes.isResponse(value) &&\n value.principalType === principalType &&\n value.principalId === principalId &&\n value.stateHash === stateHash,\n method: getPrincipalMemberEnvelopes.method,\n options: { reportErrors: false },\n operation: getPrincipalMemberEnvelopesOperation,\n });\n }\n\n get(\n principalType: \"group\" | \"organization\",\n principalId: string,\n options: RequestResultOptions = {},\n ) {\n const request = () =>\n collectPrincipalPolicyPages(\n this.runtime,\n principalType,\n principalId,\n options,\n );\n const key = JSON.stringify([principalType, principalId]);\n // Cancellation, reporting and renewal preferences belong to their caller.\n return Object.keys(options).length > 0\n ? request()\n : dedupedRequest(this.cache, key, request);\n }\n\n put(...args: Parameters<PrincipalPolicyRequests[\"putResult\"]>) {\n return this.putResult(...args).then((result) =>\n result.ok ? result.data : null,\n );\n }\n\n putResult(\n principalType: \"organization\",\n principalId: string,\n input: OrganizationPrincipalPolicyRequest,\n options: RequestResultOptions = {},\n ) {\n const key = JSON.stringify([principalType, principalId]);\n this.cache.delete(key);\n return principalHistoryRequest(this.runtime, {\n path: putPrincipalPolicy.path(principalType, principalId),\n validator: putPrincipalPolicy.isResponse,\n method: putPrincipalPolicy.method,\n body: JSON.stringify(input),\n options: {\n expectedPaymentRequiredOrganizationId: principalId,\n ...options,\n },\n operation: putPrincipalPolicyOperation,\n }).finally(() => this.cache.delete(key));\n }\n\n createResult(\n organizationId: string,\n input: CreateOrganizationGroupWithPolicyRequest,\n options: RequestResultOptions = {},\n ) {\n const { readModelCursor, ...requestOptions } = options;\n return this.groupMutation(organizationId, input.groupId, () =>\n principalHistoryRequest(this.runtime, {\n path: createOrganizationGroup.path(organizationId, readModelCursor),\n validator: createOrganizationGroup.isResponse,\n method: createOrganizationGroup.method,\n body: JSON.stringify(input),\n options: {\n expectedPaymentRequiredOrganizationId: organizationId,\n ...requestOptions,\n },\n operation: createOrganizationGroupOperation,\n }),\n );\n }\n\n deleteResult(\n organizationId: string,\n groupId: string,\n input: DeleteOrganizationGroupRequest,\n options: RequestResultOptions = {},\n ) {\n return this.groupMutation(organizationId, groupId, () =>\n principalHistoryRequest(this.runtime, {\n path: deleteOrganizationGroup.path(organizationId, groupId),\n validator: deleteOrganizationGroup.isResponse,\n method: deleteOrganizationGroup.method,\n body: JSON.stringify(input),\n options: {\n expectedPaymentRequiredOrganizationId: organizationId,\n ...options,\n },\n operation: deleteOrganizationGroupOperation,\n }),\n );\n }\n\n private async groupMutation<T>(\n organizationId: string,\n groupId: string,\n request: () => Promise<T>,\n ): Promise<T> {\n const groupKey = JSON.stringify([\"group\", groupId]);\n const organizationKey = JSON.stringify([\"organization\", organizationId]);\n this.cache.delete(groupKey);\n this.cache.delete(organizationKey);\n try {\n return await request();\n } finally {\n this.cache.delete(groupKey);\n this.cache.delete(organizationKey);\n this.clearWriterProjectionCaches();\n }\n }\n\n async commitResult(\n organizationId: string,\n groupId: string,\n input: CommitOrganizationGroupPolicyRequest,\n options: RequestResultOptions = {},\n ) {\n const groupKey = JSON.stringify([\"group\", groupId]);\n const organizationKey = JSON.stringify([\"organization\", organizationId]);\n const { readModelCursor, ...requestOptions } = options;\n this.cache.delete(groupKey);\n this.cache.delete(organizationKey);\n try {\n return await principalHistoryRequest(this.runtime, {\n path: commitOrganizationGroupPolicy.path(\n organizationId,\n groupId,\n readModelCursor,\n ),\n validator: commitOrganizationGroupPolicy.isResponse,\n method: commitOrganizationGroupPolicy.method,\n body: JSON.stringify(input),\n options: {\n expectedPaymentRequiredOrganizationId: organizationId,\n ...requestOptions,\n },\n operation: commitOrganizationGroupPolicyOperation,\n });\n } finally {\n this.cache.delete(groupKey);\n this.cache.delete(organizationKey);\n this.clearWriterProjectionCaches();\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { createContainerOperation, createContainerWithMetadataDocumentOperation, deleteContainerOperation, isContainerMutationOperationRequest, isContainerMutationOperationResponse, isContainerRotationOperationRequest, isContainerRotationOperationResponse, isCreateContainerWithMetadataDocumentOperationRequest, isCreateContainerWithMetadataDocumentOperationResponse, isDeleteContainerOperationResponse, moveContainerOperation, operationRequestPath, operationRequestPathWithQuery, reciteContainerOperation, rekeyContainerOperation, revokeContainerOperation, shareContainerOperation, } from "../../../validators/operation/index.js";
1
+ import { createContainerOperation, createContainerWithMetadataDocumentOperation, deleteContainerOperation, isContainerMutationOperationRequest, isContainerMutationOperationResponse, isContainerRotationOperationRequest, isContainerRotationOperationResponse, isCreateContainerWithMetadataDocumentOperationRequest, isCreateContainerWithMetadataDocumentOperationResponse, isDeleteContainerOperationResponse, isShareContainerOperationResponse, moveContainerOperation, operationRequestPath, operationRequestPathWithQuery, reciteContainerOperation, rekeyContainerOperation, revokeContainerOperation, shareContainerOperation, } from "../../../validators/operation/index.js";
2
2
  import { isContainerReciteRequest } from "../../../validators/request/index.js";
3
3
  import { isContainerReciteResponse } from "../../../validators/response/index.js";
4
4
  export const containerRecite = {
@@ -24,9 +24,9 @@ function containerMutationPath(operation, containerId) {
24
24
  }
25
25
  export const containerShare = {
26
26
  isRequest: isContainerMutationOperationRequest,
27
- isResponse: isContainerMutationOperationResponse,
27
+ isResponse: isShareContainerOperationResponse,
28
28
  method: shareContainerOperation.method,
29
- path: (containerId) => containerMutationPath(shareContainerOperation, containerId),
29
+ path: (containerId, readModelCursor) => operationRequestPathWithQuery(shareContainerOperation, { containerId }, { readModelCursor }),
30
30
  };
31
31
  export const containerRevoke = {
32
32
  isRequest: isContainerRotationOperationRequest,
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.js","sourceRoot":"","sources":["mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,EACnC,oCAAoC,EACpC,qDAAqD,EACrD,sDAAsD,EACtD,kCAAkC,EAClC,sBAAsB,EACtB,oBAAoB,EACpB,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,wBAAwB;IACnC,UAAU,EAAE,yBAAyB;IACrC,MAAM,EAAE,wBAAwB,CAAC,MAAM;IACvC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,oBAAoB,CAAC,wBAAwB,EAAE,EAAE,WAAW,EAAE,CAAC;CACzD,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,mCAAmC;IAC9C,UAAU,EAAE,oCAAoC;IACh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ChD,MAAM,EAAE,sBAAsB,CAAC,MAAM;IACrC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,sBAAsB,EAAE,WAAW,CAAC;CACpD,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,kCAAkC;IAC9C,MAAM,EAAE,wBAAwB,CAAC,MAAM;IACvC,IAAI,EAAE,CAAC,WAAmB,EAAE,kBAA2B,EAAE,EAAE,CACzD,6BAA6B,CAC3B,wBAAwB,EACxB,EAAE,WAAW,EAAE,EACf,EAAE,kBAAkB,EAAE,CACvB;CACK,CAAC","sourcesContent":["import {\n createContainerOperation,\n createContainerWithMetadataDocumentOperation,\n deleteContainerOperation,\n isContainerMutationOperationRequest,\n isContainerMutationOperationResponse,\n isContainerRotationOperationRequest,\n isContainerRotationOperationResponse,\n isCreateContainerWithMetadataDocumentOperationRequest,\n isCreateContainerWithMetadataDocumentOperationResponse,\n isDeleteContainerOperationResponse,\n moveContainerOperation,\n operationRequestPath,\n operationRequestPathWithQuery,\n reciteContainerOperation,\n rekeyContainerOperation,\n revokeContainerOperation,\n shareContainerOperation,\n} from \"@tearleads/validators/operation\";\nimport { isContainerReciteRequest } from \"@tearleads/validators/request\";\nimport { isContainerReciteResponse } from \"@tearleads/validators/response\";\n\nexport const containerRecite = {\n isRequest: isContainerReciteRequest,\n isResponse: isContainerReciteResponse,\n method: reciteContainerOperation.method,\n path: (containerId: string) =>\n operationRequestPath(reciteContainerOperation, { containerId }),\n} as const;\n\nexport const containerCreate = {\n isRequest: isContainerMutationOperationRequest,\n isResponse: isContainerMutationOperationResponse,\n method: createContainerOperation.method,\n path: operationRequestPath(createContainerOperation, {}),\n} as const;\n\nexport const containerCreateWithMetadataDocument = {\n isRequest: isCreateContainerWithMetadataDocumentOperationRequest,\n isResponse: isCreateContainerWithMetadataDocumentOperationResponse,\n method: createContainerWithMetadataDocumentOperation.method,\n path: operationRequestPath(createContainerWithMetadataDocumentOperation, {}),\n} as const;\n\nfunction containerMutationPath(\n operation:\n | typeof moveContainerOperation\n | typeof rekeyContainerOperation\n | typeof revokeContainerOperation\n | typeof shareContainerOperation,\n containerId: string,\n) {\n return operationRequestPath(operation, { containerId });\n}\n\nexport const containerShare = {\n isRequest: isContainerMutationOperationRequest,\n isResponse: isContainerMutationOperationResponse,\n method: shareContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(shareContainerOperation, containerId),\n} as const;\n\nexport const containerRevoke = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: revokeContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(revokeContainerOperation, containerId),\n} as const;\n\nexport const containerRekey = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: rekeyContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(rekeyContainerOperation, containerId),\n} as const;\n\nexport const containerMove = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: moveContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(moveContainerOperation, containerId),\n} as const;\n\nexport const containerDelete = {\n isResponse: isDeleteContainerOperationResponse,\n method: deleteContainerOperation.method,\n path: (containerId: string, requiredAncestorId?: string) =>\n operationRequestPathWithQuery(\n deleteContainerOperation,\n { containerId },\n { requiredAncestorId },\n ),\n} as const;\n"]}
1
+ {"version":3,"file":"mutations.js","sourceRoot":"","sources":["mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,EACnC,oCAAoC,EACpC,qDAAqD,EACrD,sDAAsD,EACtD,kCAAkC,EAClC,iCAAiC,EACjC,sBAAsB,EACtB,oBAAoB,EACpB,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC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AC9C,UAAU,EAAE,oCAAoC;IAChD,MAAM,EAAE,wBAAwB,CAAC,MAAM;IACvC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,wBAAwB,EAAE,WAAW,CAAC;CACtD,CAAC;AAEX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,SAAS,EAAE,mCAAmC;IAC9C,UAAU,EAAE,oCAAoC;IAChD,MAAM,EAAE,uBAAuB,CAAC,MAAM;IACtC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,uBAAuB,EAAE,WAAW,CAAC;CACrD,CAAC;AAEX,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,SAAS,EAAE,mCAAmC;IAC9C,UAAU,EAAE,oCAAoC;IAChD,MAAM,EAAE,sBAAsB,CAAC,MAAM;IACrC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,sBAAsB,EAAE,WAAW,CAAC;CACpD,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,kCAAkC;IAC9C,MAAM,EAAE,wBAAwB,CAAC,MAAM;IACvC,IAAI,EAAE,CAAC,WAAmB,EAAE,kBAA2B,EAAE,EAAE,CACzD,6BAA6B,CAC3B,wBAAwB,EACxB,EAAE,WAAW,EAAE,EACf,EAAE,kBAAkB,EAAE,CACvB;CACK,CAAC","sourcesContent":["import {\n createContainerOperation,\n createContainerWithMetadataDocumentOperation,\n deleteContainerOperation,\n isContainerMutationOperationRequest,\n isContainerMutationOperationResponse,\n isContainerRotationOperationRequest,\n isContainerRotationOperationResponse,\n isCreateContainerWithMetadataDocumentOperationRequest,\n isCreateContainerWithMetadataDocumentOperationResponse,\n isDeleteContainerOperationResponse,\n isShareContainerOperationResponse,\n moveContainerOperation,\n operationRequestPath,\n operationRequestPathWithQuery,\n reciteContainerOperation,\n rekeyContainerOperation,\n revokeContainerOperation,\n shareContainerOperation,\n} from \"@tearleads/validators/operation\";\nimport { isContainerReciteRequest } from \"@tearleads/validators/request\";\nimport { isContainerReciteResponse } from \"@tearleads/validators/response\";\n\nexport const containerRecite = {\n isRequest: isContainerReciteRequest,\n isResponse: isContainerReciteResponse,\n method: reciteContainerOperation.method,\n path: (containerId: string) =>\n operationRequestPath(reciteContainerOperation, { containerId }),\n} as const;\n\nexport const containerCreate = {\n isRequest: isContainerMutationOperationRequest,\n isResponse: isContainerMutationOperationResponse,\n method: createContainerOperation.method,\n path: operationRequestPath(createContainerOperation, {}),\n} as const;\n\nexport const containerCreateWithMetadataDocument = {\n isRequest: isCreateContainerWithMetadataDocumentOperationRequest,\n isResponse: isCreateContainerWithMetadataDocumentOperationResponse,\n method: createContainerWithMetadataDocumentOperation.method,\n path: operationRequestPath(createContainerWithMetadataDocumentOperation, {}),\n} as const;\n\nfunction containerMutationPath(\n operation:\n | typeof moveContainerOperation\n | typeof rekeyContainerOperation\n | typeof revokeContainerOperation,\n containerId: string,\n) {\n return operationRequestPath(operation, { containerId });\n}\n\nexport const containerShare = {\n isRequest: isContainerMutationOperationRequest,\n isResponse: isShareContainerOperationResponse,\n method: shareContainerOperation.method,\n path: (containerId: string, readModelCursor?: string) =>\n operationRequestPathWithQuery(\n shareContainerOperation,\n { containerId },\n { readModelCursor },\n ),\n} as const;\n\nexport const containerRevoke = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: revokeContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(revokeContainerOperation, containerId),\n} as const;\n\nexport const containerRekey = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: rekeyContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(rekeyContainerOperation, containerId),\n} as const;\n\nexport const containerMove = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: moveContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(moveContainerOperation, containerId),\n} as const;\n\nexport const containerDelete = {\n isResponse: isDeleteContainerOperationResponse,\n method: deleteContainerOperation.method,\n path: (containerId: string, requiredAncestorId?: string) =>\n operationRequestPathWithQuery(\n deleteContainerOperation,\n { containerId },\n { requiredAncestorId },\n ),\n} as const;\n"]}
@@ -1,12 +1,10 @@
1
- import { createOrganizationGroupOperation, isCreateOrganizationGroupOperationRequest, isCreateOrganizationGroupOperationResponse, operationRequestPath, } from "../../../validators/operation/index.js";
1
+ import { createOrganizationGroupOperation, isCreateOrganizationGroupOperationRequest, isCreateOrganizationGroupOperationResponse, operationRequestPathWithQuery, } from "../../../validators/operation/index.js";
2
2
  export const createOrganizationGroup = {
3
3
  isRequest: isCreateOrganizationGroupOperationRequest,
4
4
  isResponse: isCreateOrganizationGroupOperationResponse,
5
5
  method: createOrganizationGroupOperation.method,
6
- path(organizationId) {
7
- return operationRequestPath(createOrganizationGroupOperation, {
8
- organizationId,
9
- });
6
+ path(organizationId, readModelCursor) {
7
+ return operationRequestPathWithQuery(createOrganizationGroupOperation, { organizationId }, { readModelCursor });
10
8
  },
11
9
  };
12
10
  //# sourceMappingURL=createGroup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createGroup.js","sourceRoot":"","sources":["createGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,yCAAyC,EACzC,0CAA0C,EAC1C,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AAEzC,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,SAAS,EAAE,yCAAyC;IACpD,UAAU,EAAE,0CAA0C;IACtD,MAAM,EAAE,gCAAgC,CAAC,MAAM;IAC/C,IAAI,CAAC,cAAsB;QACzB,OAAO,oBAAoB,CAAC,gCAAgC,EAAE;YAC5D,cAAc;SACf,CAAC,CAAC;IACL,CAAC;CACF,CAAC","sourcesContent":["import {\n createOrganizationGroupOperation,\n isCreateOrganizationGroupOperationRequest,\n isCreateOrganizationGroupOperationResponse,\n operationRequestPath,\n} from \"@tearleads/validators/operation\";\n\nexport const createOrganizationGroup = {\n isRequest: isCreateOrganizationGroupOperationRequest,\n isResponse: isCreateOrganizationGroupOperationResponse,\n method: createOrganizationGroupOperation.method,\n path(organizationId: string) {\n return operationRequestPath(createOrganizationGroupOperation, {\n organizationId,\n });\n },\n};\n"]}
1
+ {"version":3,"file":"createGroup.js","sourceRoot":"","sources":["createGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,yCAAyC,EACzC,0CAA0C,EAC1C,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AAEzC,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,SAAS,EAAE,yCAAyC;IACpD,UAAU,EAAE,0CAA0C;IACtD,MAAM,EAAE,gCAAgC,CAAC,MAAM;IAC/C,IAAI,CAAC,cAAsB,EAAE,eAAwB;QACnD,OAAO,6BAA6B,CAClC,gCAAgC,EAChC,EAAE,cAAc,EAAE,EAClB,EAAE,eAAe,EAAE,CACpB,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import {\n createOrganizationGroupOperation,\n isCreateOrganizationGroupOperationRequest,\n isCreateOrganizationGroupOperationResponse,\n operationRequestPathWithQuery,\n} from \"@tearleads/validators/operation\";\n\nexport const createOrganizationGroup = {\n isRequest: isCreateOrganizationGroupOperationRequest,\n isResponse: isCreateOrganizationGroupOperationResponse,\n method: createOrganizationGroupOperation.method,\n path(organizationId: string, readModelCursor?: string) {\n return operationRequestPathWithQuery(\n createOrganizationGroupOperation,\n { organizationId },\n { readModelCursor },\n );\n },\n};\n"]}