@tearleads/client-sdk 0.1.236 → 0.1.238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/persistence/organizations/organizationReadModelDirectoryPersistence.js +88 -0
- package/data/persistence/organizations/organizationReadModelDirectoryPersistence.js.map +1 -0
- package/data/persistence/organizations/organizationReadModelPersistence.js +8 -46
- package/data/persistence/organizations/organizationReadModelPersistence.js.map +1 -1
- package/data/persistence/organizations/organizationReadModelProjection.js +0 -4
- package/data/persistence/organizations/organizationReadModelProjection.js.map +1 -1
- package/data/sqlite/migrations/localSchemaMigrations.js +16 -1
- package/data/sqlite/migrations/localSchemaMigrations.js.map +1 -1
- package/data/sqlite/schema/documentRecordSchema.js +7 -0
- package/data/sqlite/schema/documentRecordSchema.js.map +1 -1
- package/data/sqlite/schema/index.d.ts +0 -38
- package/data/sqlite/schema/organizationReadModelSchema.js +4 -3
- package/data/sqlite/schema/organizationReadModelSchema.js.map +1 -1
- package/data/sqlite/schema/organizationReadModelTableRegistry.d.ts +0 -38
- package/internal/api-client/ApiClient.d.ts +0 -6
- package/internal/api-client/client/organizations.d.ts +0 -6
- package/internal/validators/operation/organizations.d.ts +0 -32
- package/internal/validators/response/organization.d.ts +5 -63
- package/internal/validators/response/organization.js +5 -7
- package/internal/validators/response/organization.js.map +1 -1
- package/internal/validators/response/organizationReadModel.d.ts +3 -23
- package/internal/validators/response/organizationReadModel.js +4 -7
- package/internal/validators/response/organizationReadModel.js.map +1 -1
- package/package.json +1 -1
- package/workflows/container-contents/pendingWrites/deferredTails.js +4 -0
- package/workflows/container-contents/pendingWrites/deferredTails.js.map +1 -1
|
@@ -13,23 +13,25 @@ const OrganizationContainerGrantSubjectTypeSchema = z.literal([
|
|
|
13
13
|
"group",
|
|
14
14
|
"user",
|
|
15
15
|
]);
|
|
16
|
+
/**
|
|
17
|
+
* A roster row carries each key's fingerprint, not the key: a client takes
|
|
18
|
+
* public keys only from its trusted identity store, never from the directory.
|
|
19
|
+
*/
|
|
16
20
|
export const OrganizationDirectoryUserResponseShape = {
|
|
17
21
|
createdAt: z.string(),
|
|
18
22
|
disabledAt: z.string().nullable(),
|
|
19
23
|
disabledByUserId: z.string().nullable(),
|
|
20
24
|
encapsulationKeyFingerprint: z.string(),
|
|
21
|
-
encapsulationPublicKey: z.string(),
|
|
22
25
|
isPersonalOrganizationOwner: z.boolean(),
|
|
23
26
|
isSelf: z.boolean(),
|
|
24
27
|
joinedAt: z.string(),
|
|
25
28
|
/**
|
|
26
29
|
* The member's pending signed request to leave, which an administrator
|
|
27
|
-
* verifies against
|
|
30
|
+
* verifies against the member's trusted signing key before acting on it.
|
|
28
31
|
*/
|
|
29
32
|
leaveRequest: OrganizationLeaveRequestSchema.nullable(),
|
|
30
33
|
profileDocumentId: z.string().nullable(),
|
|
31
34
|
signingKeyFingerprint: z.string(),
|
|
32
|
-
signingPublicKey: z.string(),
|
|
33
35
|
status: OrganizationRosterStatusSchema,
|
|
34
36
|
updatedAt: z.string(),
|
|
35
37
|
userId: z.string(),
|
|
@@ -81,11 +83,7 @@ export const ListOrganizationGroupsResponseSchema = loosePlainObject({
|
|
|
81
83
|
organizationId: z.string(),
|
|
82
84
|
});
|
|
83
85
|
export const OrganizationGroupMemberResponseShape = {
|
|
84
|
-
encapsulationKeyFingerprint: z.string().nullable(),
|
|
85
|
-
encapsulationPublicKey: z.string().nullable(),
|
|
86
86
|
role: OrganizationRoleSchema,
|
|
87
|
-
signingKeyFingerprint: z.string().nullable(),
|
|
88
|
-
signingPublicKey: z.string().nullable(),
|
|
89
87
|
userId: z.string(),
|
|
90
88
|
};
|
|
91
89
|
export const OrganizationGroupMemberResponseSchema = loosePlainObject(OrganizationGroupMemberResponseShape);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organization.js","sourceRoot":"","sources":["organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL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C,KAAc;IAEd,OAAO,oCAAoC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n arraySchema,\n boundedPositiveIntegerSchema,\n loosePlainObject,\n nonEmptyStringSchema,\n nonNegativeIntegerSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport { OrganizationLeaveRequestSchema } from \"../util/organizationLeaveRequest\";\nimport { PrincipalPolicyMutationResponseSchema } from \"./principal\";\n\nconst OrganizationRoleSchema = z.literal([\"member\", \"admin\"]);\nconst OrganizationRosterStatusSchema = z.literal([\"active\", \"disabled\"]);\nconst OrganizationGroupContainerAccessLevelSchema = z.literal([\n \"admin\",\n \"read\",\n \"write\",\n]);\nconst OrganizationContainerGrantSubjectTypeSchema = z.literal([\n \"group\",\n \"user\",\n]);\n\nexport type OrganizationRole = z.infer<typeof OrganizationRoleSchema>;\nexport type OrganizationRosterStatus = z.infer<\n typeof OrganizationRosterStatusSchema\n>;\nexport type OrganizationGroupContainerAccessLevel = z.infer<\n typeof OrganizationGroupContainerAccessLevelSchema\n>;\nexport type OrganizationContainerGrantSubjectType = z.infer<\n typeof OrganizationContainerGrantSubjectTypeSchema\n>;\n\nexport const OrganizationDirectoryUserResponseShape = {\n createdAt: z.string(),\n disabledAt: z.string().nullable(),\n disabledByUserId: z.string().nullable(),\n encapsulationKeyFingerprint: z.string(),\n encapsulationPublicKey: z.string(),\n isPersonalOrganizationOwner: z.boolean(),\n isSelf: z.boolean(),\n joinedAt: z.string(),\n /**\n * The member's pending signed request to leave, which an administrator\n * verifies against `signingPublicKey` before acting on it.\n */\n leaveRequest: OrganizationLeaveRequestSchema.nullable(),\n profileDocumentId: z.string().nullable(),\n signingKeyFingerprint: z.string(),\n signingPublicKey: z.string(),\n status: OrganizationRosterStatusSchema,\n updatedAt: z.string(),\n userId: z.string(),\n};\n\nexport const OrganizationDirectoryUserResponseSchema = loosePlainObject(\n OrganizationDirectoryUserResponseShape,\n);\n\nexport type OrganizationDirectoryUserResponse = z.infer<\n typeof OrganizationDirectoryUserResponseSchema\n>;\n\nexport const OrganizationDirectoryCurrentUserResponseShape = {\n isOrgAdmin: z.boolean(),\n};\n\nconst OrganizationDirectoryCurrentUserResponseSchema = loosePlainObject(\n OrganizationDirectoryCurrentUserResponseShape,\n);\n\nexport const OrganizationDirectoryResponseSchema = loosePlainObject({\n currentUser: OrganizationDirectoryCurrentUserResponseSchema,\n organizationId: z.string(),\n profileDocumentId: z.string().nullable(),\n users: arraySchema(OrganizationDirectoryUserResponseSchema),\n});\n\nexport type OrganizationDirectoryResponse = z.infer<\n typeof OrganizationDirectoryResponseSchema\n>;\n\nexport const OrganizationProfileResponseSchema = loosePlainObject({\n organizationId: z.string(),\n profileDocumentId: z.string().nullable(),\n});\n\nexport type OrganizationProfileResponse = z.infer<\n typeof OrganizationProfileResponseSchema\n>;\n\nexport const OrganizationGroupCurrentStateResponseShape = {\n keyEpoch: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n keyFingerprint: nonEmptyStringSchema,\n memberCount: nonNegativeIntegerSchema,\n stateHash: z.string(),\n version: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n};\n\nexport const OrganizationGroupCurrentStateResponseSchema = loosePlainObject(\n OrganizationGroupCurrentStateResponseShape,\n);\n\nexport type OrganizationGroupCurrentStateResponse = z.infer<\n typeof OrganizationGroupCurrentStateResponseSchema\n>;\n\nexport const OrganizationGroupSummaryResponseShape = {\n createdAt: z.string(),\n currentState: OrganizationGroupCurrentStateResponseSchema.nullable(),\n groupId: z.string(),\n isBuiltin: z.boolean(),\n organizationId: z.string(),\n};\n\nexport const OrganizationGroupSummaryResponseSchema = loosePlainObject(\n OrganizationGroupSummaryResponseShape,\n);\n\nexport type OrganizationGroupSummaryResponse = z.infer<\n typeof OrganizationGroupSummaryResponseSchema\n>;\n\nexport const CreateOrganizationGroupResponseSchema = loosePlainObject({\n group: OrganizationGroupSummaryResponseSchema,\n organizationPolicy: PrincipalPolicyMutationResponseSchema,\n});\n\nexport type CreateOrganizationGroupResponse = z.infer<\n typeof CreateOrganizationGroupResponseSchema\n>;\n\nexport const DeleteOrganizationGroupResponseSchema = loosePlainObject({\n deleted: z.literal(true),\n groupId: z.string(),\n organizationPolicy: PrincipalPolicyMutationResponseSchema,\n organizationId: z.string(),\n});\n\nexport type DeleteOrganizationGroupResponse = z.infer<\n typeof DeleteOrganizationGroupResponseSchema\n>;\n\nexport const ListOrganizationGroupsResponseSchema = loosePlainObject({\n groups: arraySchema(OrganizationGroupSummaryResponseSchema),\n memberGroupId: z.string(),\n organizationId: z.string(),\n});\n\nexport type ListOrganizationGroupsResponse = z.infer<\n typeof ListOrganizationGroupsResponseSchema\n>;\n\nexport const OrganizationGroupMemberResponseShape = {\n encapsulationKeyFingerprint: z.string().nullable(),\n encapsulationPublicKey: z.string().nullable(),\n role: OrganizationRoleSchema,\n signingKeyFingerprint: z.string().nullable(),\n signingPublicKey: z.string().nullable(),\n userId: z.string(),\n};\n\nexport const OrganizationGroupMemberResponseSchema = loosePlainObject(\n OrganizationGroupMemberResponseShape,\n);\n\nexport type OrganizationGroupMemberResponse = z.infer<\n typeof OrganizationGroupMemberResponseSchema\n>;\n\nexport const OrganizationGroupMembersResponseSchema = loosePlainObject({\n groupId: z.string(),\n members: arraySchema(OrganizationGroupMemberResponseSchema),\n organizationId: z.string(),\n});\n\nexport type OrganizationGroupMembersResponse = z.infer<\n typeof OrganizationGroupMembersResponseSchema\n>;\n\nconst OrganizationGroupContainerResponseShape = {\n accessLevel: OrganizationGroupContainerAccessLevelSchema,\n containerId: z.string(),\n createdAt: z.string(),\n depth: nonNegativeIntegerSchema,\n isBuiltin: z.boolean(),\n metadataAccessEpoch: positiveIntegerSchema,\n metadataAccessStateHash: nonEmptyStringSchema,\n metadataDocumentId: z.string().nullable(),\n parentId: z.string().nullable(),\n updatedAt: z.string(),\n};\n\nexport const OrganizationGroupContainerResponseSchema = loosePlainObject(\n OrganizationGroupContainerResponseShape,\n);\n\nexport type OrganizationGroupContainerResponse = z.infer<\n typeof OrganizationGroupContainerResponseSchema\n>;\n\nexport const OrganizationGroupContainersResponseSchema = loosePlainObject({\n containers: arraySchema(OrganizationGroupContainerResponseSchema),\n groupId: z.string(),\n organizationId: z.string(),\n});\n\nexport type OrganizationGroupContainersResponse = z.infer<\n typeof OrganizationGroupContainersResponseSchema\n>;\n\nexport const OrganizationContainerGrantResponseShape = {\n ...OrganizationGroupContainerResponseShape,\n groupId: z.string().nullable(),\n signingKeyFingerprint: z.string().nullable(),\n subjectId: z.string(),\n subjectType: OrganizationContainerGrantSubjectTypeSchema,\n userId: z.string().nullable(),\n};\n\nexport const OrganizationContainerGrantResponseSchema = loosePlainObject(\n OrganizationContainerGrantResponseShape,\n);\n\nexport type OrganizationContainerGrantResponse = z.infer<\n typeof OrganizationContainerGrantResponseSchema\n>;\n\nexport const OrganizationContainerGrantsResponseSchema = loosePlainObject({\n grants: arraySchema(OrganizationContainerGrantResponseSchema),\n organizationId: z.string(),\n});\n\nexport type OrganizationContainerGrantsResponse = z.infer<\n typeof OrganizationContainerGrantsResponseSchema\n>;\n\nexport const OrganizationUserDetailGrantsResponseSchema = loosePlainObject({\n directGrants: arraySchema(OrganizationContainerGrantResponseSchema),\n groupGrants: arraySchema(OrganizationContainerGrantResponseSchema),\n});\n\nexport type OrganizationUserDetailGrantsResponse = z.infer<\n typeof OrganizationUserDetailGrantsResponseSchema\n>;\n\nexport const OrganizationUserDetailResponseSchema = loosePlainObject({\n grants: OrganizationUserDetailGrantsResponseSchema,\n groups: arraySchema(OrganizationGroupSummaryResponseSchema),\n organizationId: z.string(),\n user: OrganizationDirectoryUserResponseSchema,\n});\n\nexport type OrganizationUserDetailResponse = z.infer<\n typeof OrganizationUserDetailResponseSchema\n>;\n\nexport function isOrganizationGroupContainerAccessLevel(\n value: string,\n): value is OrganizationGroupContainerAccessLevel {\n return OrganizationGroupContainerAccessLevelSchema.safeParse(value).success;\n}\n\nexport function isOrganizationContainerGrantSubjectType(\n value: string,\n): value is OrganizationContainerGrantSubjectType {\n return OrganizationContainerGrantSubjectTypeSchema.safeParse(value).success;\n}\n\nexport function isOrganizationDirectoryUserResponse(\n value: unknown,\n): value is OrganizationDirectoryUserResponse {\n return OrganizationDirectoryUserResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationDirectoryResponse(\n value: unknown,\n): value is OrganizationDirectoryResponse {\n return OrganizationDirectoryResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationProfileResponse(\n value: unknown,\n): value is OrganizationProfileResponse {\n return OrganizationProfileResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupCurrentStateResponse(\n value: unknown,\n): value is OrganizationGroupCurrentStateResponse {\n return OrganizationGroupCurrentStateResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupSummaryResponse(\n value: unknown,\n): value is OrganizationGroupSummaryResponse {\n return OrganizationGroupSummaryResponseSchema.safeParse(value).success;\n}\n\nexport function isListOrganizationGroupsResponse(\n value: unknown,\n): value is ListOrganizationGroupsResponse {\n return ListOrganizationGroupsResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupMemberResponse(\n value: unknown,\n): value is OrganizationGroupMemberResponse {\n return OrganizationGroupMemberResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupMembersResponse(\n value: unknown,\n): value is OrganizationGroupMembersResponse {\n return OrganizationGroupMembersResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupContainerResponse(\n value: unknown,\n): value is OrganizationGroupContainerResponse {\n return OrganizationGroupContainerResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupContainersResponse(\n value: unknown,\n): value is OrganizationGroupContainersResponse {\n return OrganizationGroupContainersResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationContainerGrantResponse(\n value: unknown,\n): value is OrganizationContainerGrantResponse {\n return OrganizationContainerGrantResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationContainerGrantsResponse(\n value: unknown,\n): value is OrganizationContainerGrantsResponse {\n return OrganizationContainerGrantsResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationUserDetailGrantsResponse(\n value: unknown,\n): value is OrganizationUserDetailGrantsResponse {\n return OrganizationUserDetailGrantsResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationUserDetailResponse(\n value: unknown,\n): value is OrganizationUserDetailResponse {\n return OrganizationUserDetailResponseSchema.safeParse(value).success;\n}\n\nexport function isCreateOrganizationGroupResponse(\n value: unknown,\n): value is CreateOrganizationGroupResponse {\n return CreateOrganizationGroupResponseSchema.safeParse(value).success;\n}\n\nexport function isDeleteOrganizationGroupResponse(\n value: unknown,\n): value is DeleteOrganizationGroupResponse {\n return DeleteOrganizationGroupResponseSchema.safeParse(value).success;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"organization.js","sourceRoot":"","sources":["organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,4BAA4B,EAC5B,gBAAgB,EAChB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,qCAAqC,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,sBAAsB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC9D,MAAM,8BAA8B,GAAG,CAAC,CAAC,O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AAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,qCAAqC,CACnD,KAAc;IAEd,OAAO,yCAAyC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,oCAAoC,CAClD,KAAc;IAEd,OAAO,wCAAwC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,qCAAqC,CACnD,KAAc;IAEd,OAAO,yCAAyC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,sCAAsC,CACpD,KAAc;IAEd,OAAO,0CAA0C,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,KAAc;IAEd,OAAO,oCAAoC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n arraySchema,\n boundedPositiveIntegerSchema,\n loosePlainObject,\n nonEmptyStringSchema,\n nonNegativeIntegerSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport { OrganizationLeaveRequestSchema } from \"../util/organizationLeaveRequest\";\nimport { PrincipalPolicyMutationResponseSchema } from \"./principal\";\n\nconst OrganizationRoleSchema = z.literal([\"member\", \"admin\"]);\nconst OrganizationRosterStatusSchema = z.literal([\"active\", \"disabled\"]);\nconst OrganizationGroupContainerAccessLevelSchema = z.literal([\n \"admin\",\n \"read\",\n \"write\",\n]);\nconst OrganizationContainerGrantSubjectTypeSchema = z.literal([\n \"group\",\n \"user\",\n]);\n\nexport type OrganizationRole = z.infer<typeof OrganizationRoleSchema>;\nexport type OrganizationRosterStatus = z.infer<\n typeof OrganizationRosterStatusSchema\n>;\nexport type OrganizationGroupContainerAccessLevel = z.infer<\n typeof OrganizationGroupContainerAccessLevelSchema\n>;\nexport type OrganizationContainerGrantSubjectType = z.infer<\n typeof OrganizationContainerGrantSubjectTypeSchema\n>;\n\n/**\n * A roster row carries each key's fingerprint, not the key: a client takes\n * public keys only from its trusted identity store, never from the directory.\n */\nexport const OrganizationDirectoryUserResponseShape = {\n createdAt: z.string(),\n disabledAt: z.string().nullable(),\n disabledByUserId: z.string().nullable(),\n encapsulationKeyFingerprint: z.string(),\n isPersonalOrganizationOwner: z.boolean(),\n isSelf: z.boolean(),\n joinedAt: z.string(),\n /**\n * The member's pending signed request to leave, which an administrator\n * verifies against the member's trusted signing key before acting on it.\n */\n leaveRequest: OrganizationLeaveRequestSchema.nullable(),\n profileDocumentId: z.string().nullable(),\n signingKeyFingerprint: z.string(),\n status: OrganizationRosterStatusSchema,\n updatedAt: z.string(),\n userId: z.string(),\n};\n\nexport const OrganizationDirectoryUserResponseSchema = loosePlainObject(\n OrganizationDirectoryUserResponseShape,\n);\n\nexport type OrganizationDirectoryUserResponse = z.infer<\n typeof OrganizationDirectoryUserResponseSchema\n>;\n\nexport const OrganizationDirectoryCurrentUserResponseShape = {\n isOrgAdmin: z.boolean(),\n};\n\nconst OrganizationDirectoryCurrentUserResponseSchema = loosePlainObject(\n OrganizationDirectoryCurrentUserResponseShape,\n);\n\nexport const OrganizationDirectoryResponseSchema = loosePlainObject({\n currentUser: OrganizationDirectoryCurrentUserResponseSchema,\n organizationId: z.string(),\n profileDocumentId: z.string().nullable(),\n users: arraySchema(OrganizationDirectoryUserResponseSchema),\n});\n\nexport type OrganizationDirectoryResponse = z.infer<\n typeof OrganizationDirectoryResponseSchema\n>;\n\nexport const OrganizationProfileResponseSchema = loosePlainObject({\n organizationId: z.string(),\n profileDocumentId: z.string().nullable(),\n});\n\nexport type OrganizationProfileResponse = z.infer<\n typeof OrganizationProfileResponseSchema\n>;\n\nexport const OrganizationGroupCurrentStateResponseShape = {\n keyEpoch: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n keyFingerprint: nonEmptyStringSchema,\n memberCount: nonNegativeIntegerSchema,\n stateHash: z.string(),\n version: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n};\n\nexport const OrganizationGroupCurrentStateResponseSchema = loosePlainObject(\n OrganizationGroupCurrentStateResponseShape,\n);\n\nexport type OrganizationGroupCurrentStateResponse = z.infer<\n typeof OrganizationGroupCurrentStateResponseSchema\n>;\n\nexport const OrganizationGroupSummaryResponseShape = {\n createdAt: z.string(),\n currentState: OrganizationGroupCurrentStateResponseSchema.nullable(),\n groupId: z.string(),\n isBuiltin: z.boolean(),\n organizationId: z.string(),\n};\n\nexport const OrganizationGroupSummaryResponseSchema = loosePlainObject(\n OrganizationGroupSummaryResponseShape,\n);\n\nexport type OrganizationGroupSummaryResponse = z.infer<\n typeof OrganizationGroupSummaryResponseSchema\n>;\n\nexport const CreateOrganizationGroupResponseSchema = loosePlainObject({\n group: OrganizationGroupSummaryResponseSchema,\n organizationPolicy: PrincipalPolicyMutationResponseSchema,\n});\n\nexport type CreateOrganizationGroupResponse = z.infer<\n typeof CreateOrganizationGroupResponseSchema\n>;\n\nexport const DeleteOrganizationGroupResponseSchema = loosePlainObject({\n deleted: z.literal(true),\n groupId: z.string(),\n organizationPolicy: PrincipalPolicyMutationResponseSchema,\n organizationId: z.string(),\n});\n\nexport type DeleteOrganizationGroupResponse = z.infer<\n typeof DeleteOrganizationGroupResponseSchema\n>;\n\nexport const ListOrganizationGroupsResponseSchema = loosePlainObject({\n groups: arraySchema(OrganizationGroupSummaryResponseSchema),\n memberGroupId: z.string(),\n organizationId: z.string(),\n});\n\nexport type ListOrganizationGroupsResponse = z.infer<\n typeof ListOrganizationGroupsResponseSchema\n>;\n\nexport const OrganizationGroupMemberResponseShape = {\n role: OrganizationRoleSchema,\n userId: z.string(),\n};\n\nexport const OrganizationGroupMemberResponseSchema = loosePlainObject(\n OrganizationGroupMemberResponseShape,\n);\n\nexport type OrganizationGroupMemberResponse = z.infer<\n typeof OrganizationGroupMemberResponseSchema\n>;\n\nexport const OrganizationGroupMembersResponseSchema = loosePlainObject({\n groupId: z.string(),\n members: arraySchema(OrganizationGroupMemberResponseSchema),\n organizationId: z.string(),\n});\n\nexport type OrganizationGroupMembersResponse = z.infer<\n typeof OrganizationGroupMembersResponseSchema\n>;\n\nconst OrganizationGroupContainerResponseShape = {\n accessLevel: OrganizationGroupContainerAccessLevelSchema,\n containerId: z.string(),\n createdAt: z.string(),\n depth: nonNegativeIntegerSchema,\n isBuiltin: z.boolean(),\n metadataAccessEpoch: positiveIntegerSchema,\n metadataAccessStateHash: nonEmptyStringSchema,\n metadataDocumentId: z.string().nullable(),\n parentId: z.string().nullable(),\n updatedAt: z.string(),\n};\n\nexport const OrganizationGroupContainerResponseSchema = loosePlainObject(\n OrganizationGroupContainerResponseShape,\n);\n\nexport type OrganizationGroupContainerResponse = z.infer<\n typeof OrganizationGroupContainerResponseSchema\n>;\n\nexport const OrganizationGroupContainersResponseSchema = loosePlainObject({\n containers: arraySchema(OrganizationGroupContainerResponseSchema),\n groupId: z.string(),\n organizationId: z.string(),\n});\n\nexport type OrganizationGroupContainersResponse = z.infer<\n typeof OrganizationGroupContainersResponseSchema\n>;\n\nexport const OrganizationContainerGrantResponseShape = {\n ...OrganizationGroupContainerResponseShape,\n groupId: z.string().nullable(),\n signingKeyFingerprint: z.string().nullable(),\n subjectId: z.string(),\n subjectType: OrganizationContainerGrantSubjectTypeSchema,\n userId: z.string().nullable(),\n};\n\nexport const OrganizationContainerGrantResponseSchema = loosePlainObject(\n OrganizationContainerGrantResponseShape,\n);\n\nexport type OrganizationContainerGrantResponse = z.infer<\n typeof OrganizationContainerGrantResponseSchema\n>;\n\nexport const OrganizationContainerGrantsResponseSchema = loosePlainObject({\n grants: arraySchema(OrganizationContainerGrantResponseSchema),\n organizationId: z.string(),\n});\n\nexport type OrganizationContainerGrantsResponse = z.infer<\n typeof OrganizationContainerGrantsResponseSchema\n>;\n\nexport const OrganizationUserDetailGrantsResponseSchema = loosePlainObject({\n directGrants: arraySchema(OrganizationContainerGrantResponseSchema),\n groupGrants: arraySchema(OrganizationContainerGrantResponseSchema),\n});\n\nexport type OrganizationUserDetailGrantsResponse = z.infer<\n typeof OrganizationUserDetailGrantsResponseSchema\n>;\n\nexport const OrganizationUserDetailResponseSchema = loosePlainObject({\n grants: OrganizationUserDetailGrantsResponseSchema,\n groups: arraySchema(OrganizationGroupSummaryResponseSchema),\n organizationId: z.string(),\n user: OrganizationDirectoryUserResponseSchema,\n});\n\nexport type OrganizationUserDetailResponse = z.infer<\n typeof OrganizationUserDetailResponseSchema\n>;\n\nexport function isOrganizationGroupContainerAccessLevel(\n value: string,\n): value is OrganizationGroupContainerAccessLevel {\n return OrganizationGroupContainerAccessLevelSchema.safeParse(value).success;\n}\n\nexport function isOrganizationContainerGrantSubjectType(\n value: string,\n): value is OrganizationContainerGrantSubjectType {\n return OrganizationContainerGrantSubjectTypeSchema.safeParse(value).success;\n}\n\nexport function isOrganizationDirectoryUserResponse(\n value: unknown,\n): value is OrganizationDirectoryUserResponse {\n return OrganizationDirectoryUserResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationDirectoryResponse(\n value: unknown,\n): value is OrganizationDirectoryResponse {\n return OrganizationDirectoryResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationProfileResponse(\n value: unknown,\n): value is OrganizationProfileResponse {\n return OrganizationProfileResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupCurrentStateResponse(\n value: unknown,\n): value is OrganizationGroupCurrentStateResponse {\n return OrganizationGroupCurrentStateResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupSummaryResponse(\n value: unknown,\n): value is OrganizationGroupSummaryResponse {\n return OrganizationGroupSummaryResponseSchema.safeParse(value).success;\n}\n\nexport function isListOrganizationGroupsResponse(\n value: unknown,\n): value is ListOrganizationGroupsResponse {\n return ListOrganizationGroupsResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupMemberResponse(\n value: unknown,\n): value is OrganizationGroupMemberResponse {\n return OrganizationGroupMemberResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupMembersResponse(\n value: unknown,\n): value is OrganizationGroupMembersResponse {\n return OrganizationGroupMembersResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupContainerResponse(\n value: unknown,\n): value is OrganizationGroupContainerResponse {\n return OrganizationGroupContainerResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationGroupContainersResponse(\n value: unknown,\n): value is OrganizationGroupContainersResponse {\n return OrganizationGroupContainersResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationContainerGrantResponse(\n value: unknown,\n): value is OrganizationContainerGrantResponse {\n return OrganizationContainerGrantResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationContainerGrantsResponse(\n value: unknown,\n): value is OrganizationContainerGrantsResponse {\n return OrganizationContainerGrantsResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationUserDetailGrantsResponse(\n value: unknown,\n): value is OrganizationUserDetailGrantsResponse {\n return OrganizationUserDetailGrantsResponseSchema.safeParse(value).success;\n}\n\nexport function isOrganizationUserDetailResponse(\n value: unknown,\n): value is OrganizationUserDetailResponse {\n return OrganizationUserDetailResponseSchema.safeParse(value).success;\n}\n\nexport function isCreateOrganizationGroupResponse(\n value: unknown,\n): value is CreateOrganizationGroupResponse {\n return CreateOrganizationGroupResponseSchema.safeParse(value).success;\n}\n\nexport function isDeleteOrganizationGroupResponse(\n value: unknown,\n): value is DeleteOrganizationGroupResponse {\n return DeleteOrganizationGroupResponseSchema.safeParse(value).success;\n}\n"]}
|
|
@@ -7,7 +7,6 @@ declare const OrganizationReadModelDirectoryResponseSchema: z.ZodObject<{
|
|
|
7
7
|
disabledAt: string | null;
|
|
8
8
|
disabledByUserId: string | null;
|
|
9
9
|
encapsulationKeyFingerprint: string;
|
|
10
|
-
encapsulationPublicKey: string;
|
|
11
10
|
isPersonalOrganizationOwner: boolean;
|
|
12
11
|
isSelf: boolean;
|
|
13
12
|
joinedAt: string;
|
|
@@ -26,7 +25,6 @@ declare const OrganizationReadModelDirectoryResponseSchema: z.ZodObject<{
|
|
|
26
25
|
} | null;
|
|
27
26
|
profileDocumentId: string | null;
|
|
28
27
|
signingKeyFingerprint: string;
|
|
29
|
-
signingPublicKey: string;
|
|
30
28
|
status: "active" | "disabled";
|
|
31
29
|
updatedAt: string;
|
|
32
30
|
userId: string;
|
|
@@ -35,7 +33,6 @@ declare const OrganizationReadModelDirectoryResponseSchema: z.ZodObject<{
|
|
|
35
33
|
disabledAt: string | null;
|
|
36
34
|
disabledByUserId: string | null;
|
|
37
35
|
encapsulationKeyFingerprint: string;
|
|
38
|
-
encapsulationPublicKey: string;
|
|
39
36
|
isPersonalOrganizationOwner: boolean;
|
|
40
37
|
isSelf: boolean;
|
|
41
38
|
joinedAt: string;
|
|
@@ -54,7 +51,6 @@ declare const OrganizationReadModelDirectoryResponseSchema: z.ZodObject<{
|
|
|
54
51
|
} | null;
|
|
55
52
|
profileDocumentId: string | null;
|
|
56
53
|
signingKeyFingerprint: string;
|
|
57
|
-
signingPublicKey: string;
|
|
58
54
|
status: "active" | "disabled";
|
|
59
55
|
updatedAt: string;
|
|
60
56
|
userId: string;
|
|
@@ -99,9 +95,9 @@ declare const OrganizationReadModelGrantsResponseSchema: z.ZodObject<{
|
|
|
99
95
|
}, z.core.$strict>;
|
|
100
96
|
export type OrganizationReadModelGrantsResponse = z.infer<typeof OrganizationReadModelGrantsResponseSchema>;
|
|
101
97
|
/**
|
|
102
|
-
* A projected member names only the user and role.
|
|
103
|
-
*
|
|
104
|
-
*
|
|
98
|
+
* A projected member names only the user and role. The read model carries no
|
|
99
|
+
* public keys: directory rows carry key fingerprints, and keying takes keys
|
|
100
|
+
* from the trusted identity store.
|
|
105
101
|
*/
|
|
106
102
|
declare const OrganizationReadModelGroupMemberResponseSchema: z.ZodObject<{
|
|
107
103
|
role: z.ZodLiteral<"member" | "admin">;
|
|
@@ -162,7 +158,6 @@ declare const OrganizationReadModelSnapshotResponseSchema: z.ZodObject<{
|
|
|
162
158
|
disabledAt: string | null;
|
|
163
159
|
disabledByUserId: string | null;
|
|
164
160
|
encapsulationKeyFingerprint: string;
|
|
165
|
-
encapsulationPublicKey: string;
|
|
166
161
|
isPersonalOrganizationOwner: boolean;
|
|
167
162
|
isSelf: boolean;
|
|
168
163
|
joinedAt: string;
|
|
@@ -181,7 +176,6 @@ declare const OrganizationReadModelSnapshotResponseSchema: z.ZodObject<{
|
|
|
181
176
|
} | null;
|
|
182
177
|
profileDocumentId: string | null;
|
|
183
178
|
signingKeyFingerprint: string;
|
|
184
|
-
signingPublicKey: string;
|
|
185
179
|
status: "active" | "disabled";
|
|
186
180
|
updatedAt: string;
|
|
187
181
|
userId: string;
|
|
@@ -190,7 +184,6 @@ declare const OrganizationReadModelSnapshotResponseSchema: z.ZodObject<{
|
|
|
190
184
|
disabledAt: string | null;
|
|
191
185
|
disabledByUserId: string | null;
|
|
192
186
|
encapsulationKeyFingerprint: string;
|
|
193
|
-
encapsulationPublicKey: string;
|
|
194
187
|
isPersonalOrganizationOwner: boolean;
|
|
195
188
|
isSelf: boolean;
|
|
196
189
|
joinedAt: string;
|
|
@@ -209,7 +202,6 @@ declare const OrganizationReadModelSnapshotResponseSchema: z.ZodObject<{
|
|
|
209
202
|
} | null;
|
|
210
203
|
profileDocumentId: string | null;
|
|
211
204
|
signingKeyFingerprint: string;
|
|
212
|
-
signingPublicKey: string;
|
|
213
205
|
status: "active" | "disabled";
|
|
214
206
|
updatedAt: string;
|
|
215
207
|
userId: string;
|
|
@@ -329,7 +321,6 @@ declare const OrganizationReadModelDeltaResponseSchema: z.ZodObject<{
|
|
|
329
321
|
disabledAt: string | null;
|
|
330
322
|
disabledByUserId: string | null;
|
|
331
323
|
encapsulationKeyFingerprint: string;
|
|
332
|
-
encapsulationPublicKey: string;
|
|
333
324
|
isPersonalOrganizationOwner: boolean;
|
|
334
325
|
isSelf: boolean;
|
|
335
326
|
joinedAt: string;
|
|
@@ -348,7 +339,6 @@ declare const OrganizationReadModelDeltaResponseSchema: z.ZodObject<{
|
|
|
348
339
|
} | null;
|
|
349
340
|
profileDocumentId: string | null;
|
|
350
341
|
signingKeyFingerprint: string;
|
|
351
|
-
signingPublicKey: string;
|
|
352
342
|
status: "active" | "disabled";
|
|
353
343
|
updatedAt: string;
|
|
354
344
|
userId: string;
|
|
@@ -357,7 +347,6 @@ declare const OrganizationReadModelDeltaResponseSchema: z.ZodObject<{
|
|
|
357
347
|
disabledAt: string | null;
|
|
358
348
|
disabledByUserId: string | null;
|
|
359
349
|
encapsulationKeyFingerprint: string;
|
|
360
|
-
encapsulationPublicKey: string;
|
|
361
350
|
isPersonalOrganizationOwner: boolean;
|
|
362
351
|
isSelf: boolean;
|
|
363
352
|
joinedAt: string;
|
|
@@ -376,7 +365,6 @@ declare const OrganizationReadModelDeltaResponseSchema: z.ZodObject<{
|
|
|
376
365
|
} | null;
|
|
377
366
|
profileDocumentId: string | null;
|
|
378
367
|
signingKeyFingerprint: string;
|
|
379
|
-
signingPublicKey: string;
|
|
380
368
|
status: "active" | "disabled";
|
|
381
369
|
updatedAt: string;
|
|
382
370
|
userId: string;
|
|
@@ -497,7 +485,6 @@ export declare const OrganizationReadModelResponseSchema: z.ZodDiscriminatedUnio
|
|
|
497
485
|
disabledAt: string | null;
|
|
498
486
|
disabledByUserId: string | null;
|
|
499
487
|
encapsulationKeyFingerprint: string;
|
|
500
|
-
encapsulationPublicKey: string;
|
|
501
488
|
isPersonalOrganizationOwner: boolean;
|
|
502
489
|
isSelf: boolean;
|
|
503
490
|
joinedAt: string;
|
|
@@ -516,7 +503,6 @@ export declare const OrganizationReadModelResponseSchema: z.ZodDiscriminatedUnio
|
|
|
516
503
|
} | null;
|
|
517
504
|
profileDocumentId: string | null;
|
|
518
505
|
signingKeyFingerprint: string;
|
|
519
|
-
signingPublicKey: string;
|
|
520
506
|
status: "active" | "disabled";
|
|
521
507
|
updatedAt: string;
|
|
522
508
|
userId: string;
|
|
@@ -525,7 +511,6 @@ export declare const OrganizationReadModelResponseSchema: z.ZodDiscriminatedUnio
|
|
|
525
511
|
disabledAt: string | null;
|
|
526
512
|
disabledByUserId: string | null;
|
|
527
513
|
encapsulationKeyFingerprint: string;
|
|
528
|
-
encapsulationPublicKey: string;
|
|
529
514
|
isPersonalOrganizationOwner: boolean;
|
|
530
515
|
isSelf: boolean;
|
|
531
516
|
joinedAt: string;
|
|
@@ -544,7 +529,6 @@ export declare const OrganizationReadModelResponseSchema: z.ZodDiscriminatedUnio
|
|
|
544
529
|
} | null;
|
|
545
530
|
profileDocumentId: string | null;
|
|
546
531
|
signingKeyFingerprint: string;
|
|
547
|
-
signingPublicKey: string;
|
|
548
532
|
status: "active" | "disabled";
|
|
549
533
|
updatedAt: string;
|
|
550
534
|
userId: string;
|
|
@@ -664,7 +648,6 @@ export declare const OrganizationReadModelResponseSchema: z.ZodDiscriminatedUnio
|
|
|
664
648
|
disabledAt: string | null;
|
|
665
649
|
disabledByUserId: string | null;
|
|
666
650
|
encapsulationKeyFingerprint: string;
|
|
667
|
-
encapsulationPublicKey: string;
|
|
668
651
|
isPersonalOrganizationOwner: boolean;
|
|
669
652
|
isSelf: boolean;
|
|
670
653
|
joinedAt: string;
|
|
@@ -683,7 +666,6 @@ export declare const OrganizationReadModelResponseSchema: z.ZodDiscriminatedUnio
|
|
|
683
666
|
} | null;
|
|
684
667
|
profileDocumentId: string | null;
|
|
685
668
|
signingKeyFingerprint: string;
|
|
686
|
-
signingPublicKey: string;
|
|
687
669
|
status: "active" | "disabled";
|
|
688
670
|
updatedAt: string;
|
|
689
671
|
userId: string;
|
|
@@ -692,7 +674,6 @@ export declare const OrganizationReadModelResponseSchema: z.ZodDiscriminatedUnio
|
|
|
692
674
|
disabledAt: string | null;
|
|
693
675
|
disabledByUserId: string | null;
|
|
694
676
|
encapsulationKeyFingerprint: string;
|
|
695
|
-
encapsulationPublicKey: string;
|
|
696
677
|
isPersonalOrganizationOwner: boolean;
|
|
697
678
|
isSelf: boolean;
|
|
698
679
|
joinedAt: string;
|
|
@@ -711,7 +692,6 @@ export declare const OrganizationReadModelResponseSchema: z.ZodDiscriminatedUnio
|
|
|
711
692
|
} | null;
|
|
712
693
|
profileDocumentId: string | null;
|
|
713
694
|
signingKeyFingerprint: string;
|
|
714
|
-
signingPublicKey: string;
|
|
715
695
|
status: "active" | "disabled";
|
|
716
696
|
updatedAt: string;
|
|
717
697
|
userId: string;
|
|
@@ -15,14 +15,11 @@ const OrganizationReadModelGrantsResponseSchema = z.strictObject({
|
|
|
15
15
|
organizationId: z.string(),
|
|
16
16
|
});
|
|
17
17
|
/**
|
|
18
|
-
* A projected member names only the user and role.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* A projected member names only the user and role. The read model carries no
|
|
19
|
+
* public keys: directory rows carry key fingerprints, and keying takes keys
|
|
20
|
+
* from the trusted identity store.
|
|
21
21
|
*/
|
|
22
|
-
const OrganizationReadModelGroupMemberResponseSchema = z.strictObject(
|
|
23
|
-
role: OrganizationGroupMemberResponseShape.role,
|
|
24
|
-
userId: OrganizationGroupMemberResponseShape.userId,
|
|
25
|
-
});
|
|
22
|
+
const OrganizationReadModelGroupMemberResponseSchema = z.strictObject(OrganizationGroupMemberResponseShape);
|
|
26
23
|
const OrganizationReadModelGroupMembershipResponseSchema = z.strictObject({
|
|
27
24
|
groupId: z.string(),
|
|
28
25
|
members: arraySchema(OrganizationReadModelGroupMemberResponseSchema),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationReadModel.js","sourceRoot":"","sources":["organ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,CACnD,CAAC,CAAC;QACP,CAAC,KAAK,CAAC,kBAAkB,KAAK,SAAS;YACrC,KAAK,CAAC,kBAAkB,CAAC,cAAc,KAAK,cAAc,CAAC,CAC9D,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B,CACjC,KAAwC;IAExC,IACE,CAAC,sBAAsB,CAAC,KAAK,CAAC;QAC9B,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS;YAC/B,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,KAAK,SAAS;YACzC,CAAC,wBAAwB,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,EAC1D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,KAAK,CAAC,IAAI,KAAK,OAAO;QACtB,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC,CAC1D,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,mCAAmC,GAC9C,oCAAoC,CAClC,sBAAsB,CACpB,uCAAuC,CAAC,MAAM,CAC5C,0BAA0B,CAC3B,EACD,uCAAuC,CACxC,EACD,+CAA+C,CAChD,CAAC;AAMJ,MAAM,UAAU,+BAA+B,CAC7C,KAAc;IAEd,OAAO,mCAAmC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACtE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n registerJsonSchemaRuntimeRefinements,\n registerJsonSchemaView,\n} from \"../jsonSchema\";\nimport { organizationReadModelResponseRuntimeRefinements } from \"../organizationReadModelRefinements\";\nimport { arraySchema } from \"../schema\";\nimport {\n OrganizationContainerGrantResponseShape,\n OrganizationDirectoryCurrentUserResponseShape,\n OrganizationDirectoryUserResponseShape,\n OrganizationGroupCurrentStateResponseShape,\n OrganizationGroupMemberResponseShape,\n OrganizationGroupSummaryResponseShape,\n} from \"./organization\";\n\nconst OrganizationReadModelDirectoryUserResponseSchema = z.strictObject(\n OrganizationDirectoryUserResponseShape,\n);\n\nconst OrganizationReadModelDirectoryResponseSchema = z.strictObject({\n organizationId: z.string(),\n profileDocumentId: z.string().nullable(),\n users: arraySchema(OrganizationReadModelDirectoryUserResponseSchema),\n});\n\nexport type OrganizationReadModelDirectoryResponse = z.infer<\n typeof OrganizationReadModelDirectoryResponseSchema\n>;\n\nconst OrganizationReadModelGrantResponseSchema = z.strictObject(\n OrganizationContainerGrantResponseShape,\n);\n\nconst OrganizationReadModelGrantsResponseSchema = z.strictObject({\n grants: arraySchema(OrganizationReadModelGrantResponseSchema),\n organizationId: z.string(),\n});\n\nexport type OrganizationReadModelGrantsResponse = z.infer<\n typeof OrganizationReadModelGrantsResponseSchema\n>;\n\n/**\n * A projected member names only the user and role. Public keys live once per\n * user in the directory lane; keying never reads either copy from the read\n * model.\n */\nconst OrganizationReadModelGroupMemberResponseSchema = z.strictObject({\n role: OrganizationGroupMemberResponseShape.role,\n userId: OrganizationGroupMemberResponseShape.userId,\n});\n\nexport type OrganizationReadModelGroupMemberResponse = z.infer<\n typeof OrganizationReadModelGroupMemberResponseSchema\n>;\n\nconst OrganizationReadModelGroupMembershipResponseSchema = z.strictObject({\n groupId: z.string(),\n members: arraySchema(OrganizationReadModelGroupMemberResponseSchema),\n stateHash: z.string().min(1),\n});\n\nexport type OrganizationReadModelGroupMembershipResponse = z.infer<\n typeof OrganizationReadModelGroupMembershipResponseSchema\n>;\n\nconst OrganizationReadModelGroupMembershipsResponseSchema = z.strictObject({\n deletedGroupIds: arraySchema(z.string().min(1)),\n groups: arraySchema(OrganizationReadModelGroupMembershipResponseSchema),\n organizationId: z.string(),\n});\n\nexport type OrganizationReadModelGroupMembershipsResponse = z.infer<\n typeof OrganizationReadModelGroupMembershipsResponseSchema\n>;\n\nconst OrganizationReadModelGroupCurrentStateResponseSchema = z.strictObject(\n OrganizationGroupCurrentStateResponseShape,\n);\n\nconst OrganizationReadModelGroupSummaryResponseSchema = z.strictObject({\n ...OrganizationGroupSummaryResponseShape,\n currentState: OrganizationReadModelGroupCurrentStateResponseSchema.nullable(),\n});\n\nconst OrganizationReadModelGroupsResponseSchema = z.strictObject({\n groups: arraySchema(OrganizationReadModelGroupSummaryResponseSchema),\n memberGroupId: z.string(),\n organizationId: z.string(),\n});\n\nconst OrganizationReadModelOrganizationPolicyResponseSchema = z.strictObject({\n currentState: z.strictObject({\n ...OrganizationGroupCurrentStateResponseShape,\n stateHash: z.string().min(1),\n }),\n organizationId: z.string(),\n});\n\nexport type OrganizationReadModelOrganizationPolicyResponse = z.infer<\n typeof OrganizationReadModelOrganizationPolicyResponseSchema\n>;\n\nconst OrganizationReadModelCurrentUserResponseSchema = z.strictObject(\n OrganizationDirectoryCurrentUserResponseShape,\n);\n\nconst OrganizationReadModelResponseBaseShape = {\n currentUser: OrganizationReadModelCurrentUserResponseSchema,\n hasMore: z.boolean(),\n nextCursor: z.string().min(1),\n organizationId: z.string(),\n version: z.literal(6),\n};\n\nconst OrganizationReadModelSnapshotResponseSchema = z.strictObject({\n ...OrganizationReadModelResponseBaseShape,\n hasMore: z.literal(false),\n lanes: z.strictObject({\n directory: OrganizationReadModelDirectoryResponseSchema,\n grants: OrganizationReadModelGrantsResponseSchema,\n groupMemberships: OrganizationReadModelGroupMembershipsResponseSchema,\n groups: OrganizationReadModelGroupsResponseSchema,\n organizationPolicy: OrganizationReadModelOrganizationPolicyResponseSchema,\n }),\n mode: z.literal(\"snapshot\"),\n});\n\nexport type OrganizationReadModelSnapshotResponse = z.infer<\n typeof OrganizationReadModelSnapshotResponseSchema\n>;\n\nconst OrganizationReadModelDeltaResponseSchema = z.strictObject({\n ...OrganizationReadModelResponseBaseShape,\n lanes: z.strictObject({\n directory: OrganizationReadModelDirectoryResponseSchema.optional(),\n grants: OrganizationReadModelGrantsResponseSchema.optional(),\n groupMemberships:\n OrganizationReadModelGroupMembershipsResponseSchema.optional(),\n groups: OrganizationReadModelGroupsResponseSchema.optional(),\n organizationPolicy:\n OrganizationReadModelOrganizationPolicyResponseSchema.optional(),\n }),\n mode: z.literal(\"delta\"),\n});\n\nexport type OrganizationReadModelDeltaResponse = z.infer<\n typeof OrganizationReadModelDeltaResponseSchema\n>;\n\nconst OrganizationReadModelResponseSchemaView = z.discriminatedUnion(\"mode\", [\n OrganizationReadModelDeltaResponseSchema,\n OrganizationReadModelSnapshotResponseSchema,\n]);\n\ntype OrganizationReadModelResponseView = z.infer<\n typeof OrganizationReadModelResponseSchemaView\n>;\n\nfunction hasValidGrantSubjectFields(\n grant: z.infer<typeof OrganizationReadModelGrantResponseSchema>,\n): boolean {\n if (grant.subjectType === \"user\") {\n return grant.userId === grant.subjectId && grant.groupId === null;\n }\n if (grant.subjectType === \"group\") {\n return (\n grant.userId === null &&\n grant.signingKeyFingerprint === null &&\n grant.groupId === grant.subjectId\n );\n }\n return false;\n}\n\nfunction hasValidGrants(\n grants: OrganizationReadModelGrantsResponse[\"grants\"],\n): boolean {\n const keys = new Set<string>();\n return grants.every((grant) => {\n const key = `${grant.subjectType}:${grant.subjectId}:${grant.containerId}`;\n if (!hasValidGrantSubjectFields(grant) || keys.has(key)) {\n return false;\n }\n keys.add(key);\n return true;\n });\n}\n\nfunction hasValidGroupMemberships(\n lane: OrganizationReadModelGroupMembershipsResponse,\n): boolean {\n const groupIds = new Set<string>();\n const validGroups = lane.groups.every((group) => {\n if (groupIds.has(group.groupId)) {\n return false;\n }\n groupIds.add(group.groupId);\n const memberIds = new Set<string>();\n return group.members.every((member) => {\n if (memberIds.has(member.userId)) {\n return false;\n }\n memberIds.add(member.userId);\n return true;\n });\n });\n if (!validGroups) {\n return false;\n }\n\n const deletedGroupIds = new Set<string>();\n return lane.deletedGroupIds.every((groupId) => {\n if (groupIds.has(groupId) || deletedGroupIds.has(groupId)) {\n return false;\n }\n deletedGroupIds.add(groupId);\n return true;\n });\n}\n\nfunction laneOrganizationsMatch(\n value: OrganizationReadModelResponseView,\n): boolean {\n const { lanes, organizationId } = value;\n return (\n (lanes.directory === undefined ||\n lanes.directory.organizationId === organizationId) &&\n (lanes.grants === undefined ||\n lanes.grants.organizationId === organizationId) &&\n (lanes.groupMemberships === undefined ||\n lanes.groupMemberships.organizationId === organizationId) &&\n (lanes.groups === undefined ||\n (lanes.groups.organizationId === organizationId &&\n lanes.groups.groups.every(\n (group) => group.organizationId === organizationId,\n ))) &&\n (lanes.organizationPolicy === undefined ||\n lanes.organizationPolicy.organizationId === organizationId)\n );\n}\n\nfunction hasValidReadModelSemantics(\n value: OrganizationReadModelResponseView,\n): boolean {\n if (\n !laneOrganizationsMatch(value) ||\n (value.lanes.grants !== undefined &&\n !hasValidGrants(value.lanes.grants.grants)) ||\n (value.lanes.groupMemberships !== undefined &&\n !hasValidGroupMemberships(value.lanes.groupMemberships))\n ) {\n return false;\n }\n\n return (\n value.mode === \"delta\" ||\n value.lanes.groupMemberships.deletedGroupIds.length === 0\n );\n}\n\nexport const OrganizationReadModelResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n registerJsonSchemaView(\n OrganizationReadModelResponseSchemaView.refine(\n hasValidReadModelSemantics,\n ),\n OrganizationReadModelResponseSchemaView,\n ),\n organizationReadModelResponseRuntimeRefinements,\n );\n\nexport type OrganizationReadModelResponse = z.infer<\n typeof OrganizationReadModelResponseSchema\n>;\n\nexport function isOrganizationReadModelResponse(\n value: unknown,\n): value is OrganizationReadModelResponse {\n return OrganizationReadModelResponseSchema.safeParse(value).success;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"organizationReadModel.js","sourceRoot":"","sources":["organizationReadModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,oCAAoC,EACpC,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,+CAA+C,EAAE,MAAM,qCAAqC,CAAC;AACtG,OAAO,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/B,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,KAAK,SAAS;YACzC,CAAC,wBAAwB,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,EAC1D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,KAAK,CAAC,IAAI,KAAK,OAAO;QACtB,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC,CAC1D,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,mCAAmC,GAC9C,oCAAoC,CAClC,sBAAsB,CACpB,uCAAuC,CAAC,MAAM,CAC5C,0BAA0B,CAC3B,EACD,uCAAuC,CACxC,EACD,+CAA+C,CAChD,CAAC;AAMJ,MAAM,UAAU,+BAA+B,CAC7C,KAAc;IAEd,OAAO,mCAAmC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACtE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n registerJsonSchemaRuntimeRefinements,\n registerJsonSchemaView,\n} from \"../jsonSchema\";\nimport { organizationReadModelResponseRuntimeRefinements } from \"../organizationReadModelRefinements\";\nimport { arraySchema } from \"../schema\";\nimport {\n OrganizationContainerGrantResponseShape,\n OrganizationDirectoryCurrentUserResponseShape,\n OrganizationDirectoryUserResponseShape,\n OrganizationGroupCurrentStateResponseShape,\n OrganizationGroupMemberResponseShape,\n OrganizationGroupSummaryResponseShape,\n} from \"./organization\";\n\nconst OrganizationReadModelDirectoryUserResponseSchema = z.strictObject(\n OrganizationDirectoryUserResponseShape,\n);\n\nconst OrganizationReadModelDirectoryResponseSchema = z.strictObject({\n organizationId: z.string(),\n profileDocumentId: z.string().nullable(),\n users: arraySchema(OrganizationReadModelDirectoryUserResponseSchema),\n});\n\nexport type OrganizationReadModelDirectoryResponse = z.infer<\n typeof OrganizationReadModelDirectoryResponseSchema\n>;\n\nconst OrganizationReadModelGrantResponseSchema = z.strictObject(\n OrganizationContainerGrantResponseShape,\n);\n\nconst OrganizationReadModelGrantsResponseSchema = z.strictObject({\n grants: arraySchema(OrganizationReadModelGrantResponseSchema),\n organizationId: z.string(),\n});\n\nexport type OrganizationReadModelGrantsResponse = z.infer<\n typeof OrganizationReadModelGrantsResponseSchema\n>;\n\n/**\n * A projected member names only the user and role. The read model carries no\n * public keys: directory rows carry key fingerprints, and keying takes keys\n * from the trusted identity store.\n */\nconst OrganizationReadModelGroupMemberResponseSchema = z.strictObject(\n OrganizationGroupMemberResponseShape,\n);\n\nexport type OrganizationReadModelGroupMemberResponse = z.infer<\n typeof OrganizationReadModelGroupMemberResponseSchema\n>;\n\nconst OrganizationReadModelGroupMembershipResponseSchema = z.strictObject({\n groupId: z.string(),\n members: arraySchema(OrganizationReadModelGroupMemberResponseSchema),\n stateHash: z.string().min(1),\n});\n\nexport type OrganizationReadModelGroupMembershipResponse = z.infer<\n typeof OrganizationReadModelGroupMembershipResponseSchema\n>;\n\nconst OrganizationReadModelGroupMembershipsResponseSchema = z.strictObject({\n deletedGroupIds: arraySchema(z.string().min(1)),\n groups: arraySchema(OrganizationReadModelGroupMembershipResponseSchema),\n organizationId: z.string(),\n});\n\nexport type OrganizationReadModelGroupMembershipsResponse = z.infer<\n typeof OrganizationReadModelGroupMembershipsResponseSchema\n>;\n\nconst OrganizationReadModelGroupCurrentStateResponseSchema = z.strictObject(\n OrganizationGroupCurrentStateResponseShape,\n);\n\nconst OrganizationReadModelGroupSummaryResponseSchema = z.strictObject({\n ...OrganizationGroupSummaryResponseShape,\n currentState: OrganizationReadModelGroupCurrentStateResponseSchema.nullable(),\n});\n\nconst OrganizationReadModelGroupsResponseSchema = z.strictObject({\n groups: arraySchema(OrganizationReadModelGroupSummaryResponseSchema),\n memberGroupId: z.string(),\n organizationId: z.string(),\n});\n\nconst OrganizationReadModelOrganizationPolicyResponseSchema = z.strictObject({\n currentState: z.strictObject({\n ...OrganizationGroupCurrentStateResponseShape,\n stateHash: z.string().min(1),\n }),\n organizationId: z.string(),\n});\n\nexport type OrganizationReadModelOrganizationPolicyResponse = z.infer<\n typeof OrganizationReadModelOrganizationPolicyResponseSchema\n>;\n\nconst OrganizationReadModelCurrentUserResponseSchema = z.strictObject(\n OrganizationDirectoryCurrentUserResponseShape,\n);\n\nconst OrganizationReadModelResponseBaseShape = {\n currentUser: OrganizationReadModelCurrentUserResponseSchema,\n hasMore: z.boolean(),\n nextCursor: z.string().min(1),\n organizationId: z.string(),\n version: z.literal(6),\n};\n\nconst OrganizationReadModelSnapshotResponseSchema = z.strictObject({\n ...OrganizationReadModelResponseBaseShape,\n hasMore: z.literal(false),\n lanes: z.strictObject({\n directory: OrganizationReadModelDirectoryResponseSchema,\n grants: OrganizationReadModelGrantsResponseSchema,\n groupMemberships: OrganizationReadModelGroupMembershipsResponseSchema,\n groups: OrganizationReadModelGroupsResponseSchema,\n organizationPolicy: OrganizationReadModelOrganizationPolicyResponseSchema,\n }),\n mode: z.literal(\"snapshot\"),\n});\n\nexport type OrganizationReadModelSnapshotResponse = z.infer<\n typeof OrganizationReadModelSnapshotResponseSchema\n>;\n\nconst OrganizationReadModelDeltaResponseSchema = z.strictObject({\n ...OrganizationReadModelResponseBaseShape,\n lanes: z.strictObject({\n directory: OrganizationReadModelDirectoryResponseSchema.optional(),\n grants: OrganizationReadModelGrantsResponseSchema.optional(),\n groupMemberships:\n OrganizationReadModelGroupMembershipsResponseSchema.optional(),\n groups: OrganizationReadModelGroupsResponseSchema.optional(),\n organizationPolicy:\n OrganizationReadModelOrganizationPolicyResponseSchema.optional(),\n }),\n mode: z.literal(\"delta\"),\n});\n\nexport type OrganizationReadModelDeltaResponse = z.infer<\n typeof OrganizationReadModelDeltaResponseSchema\n>;\n\nconst OrganizationReadModelResponseSchemaView = z.discriminatedUnion(\"mode\", [\n OrganizationReadModelDeltaResponseSchema,\n OrganizationReadModelSnapshotResponseSchema,\n]);\n\ntype OrganizationReadModelResponseView = z.infer<\n typeof OrganizationReadModelResponseSchemaView\n>;\n\nfunction hasValidGrantSubjectFields(\n grant: z.infer<typeof OrganizationReadModelGrantResponseSchema>,\n): boolean {\n if (grant.subjectType === \"user\") {\n return grant.userId === grant.subjectId && grant.groupId === null;\n }\n if (grant.subjectType === \"group\") {\n return (\n grant.userId === null &&\n grant.signingKeyFingerprint === null &&\n grant.groupId === grant.subjectId\n );\n }\n return false;\n}\n\nfunction hasValidGrants(\n grants: OrganizationReadModelGrantsResponse[\"grants\"],\n): boolean {\n const keys = new Set<string>();\n return grants.every((grant) => {\n const key = `${grant.subjectType}:${grant.subjectId}:${grant.containerId}`;\n if (!hasValidGrantSubjectFields(grant) || keys.has(key)) {\n return false;\n }\n keys.add(key);\n return true;\n });\n}\n\nfunction hasValidGroupMemberships(\n lane: OrganizationReadModelGroupMembershipsResponse,\n): boolean {\n const groupIds = new Set<string>();\n const validGroups = lane.groups.every((group) => {\n if (groupIds.has(group.groupId)) {\n return false;\n }\n groupIds.add(group.groupId);\n const memberIds = new Set<string>();\n return group.members.every((member) => {\n if (memberIds.has(member.userId)) {\n return false;\n }\n memberIds.add(member.userId);\n return true;\n });\n });\n if (!validGroups) {\n return false;\n }\n\n const deletedGroupIds = new Set<string>();\n return lane.deletedGroupIds.every((groupId) => {\n if (groupIds.has(groupId) || deletedGroupIds.has(groupId)) {\n return false;\n }\n deletedGroupIds.add(groupId);\n return true;\n });\n}\n\nfunction laneOrganizationsMatch(\n value: OrganizationReadModelResponseView,\n): boolean {\n const { lanes, organizationId } = value;\n return (\n (lanes.directory === undefined ||\n lanes.directory.organizationId === organizationId) &&\n (lanes.grants === undefined ||\n lanes.grants.organizationId === organizationId) &&\n (lanes.groupMemberships === undefined ||\n lanes.groupMemberships.organizationId === organizationId) &&\n (lanes.groups === undefined ||\n (lanes.groups.organizationId === organizationId &&\n lanes.groups.groups.every(\n (group) => group.organizationId === organizationId,\n ))) &&\n (lanes.organizationPolicy === undefined ||\n lanes.organizationPolicy.organizationId === organizationId)\n );\n}\n\nfunction hasValidReadModelSemantics(\n value: OrganizationReadModelResponseView,\n): boolean {\n if (\n !laneOrganizationsMatch(value) ||\n (value.lanes.grants !== undefined &&\n !hasValidGrants(value.lanes.grants.grants)) ||\n (value.lanes.groupMemberships !== undefined &&\n !hasValidGroupMemberships(value.lanes.groupMemberships))\n ) {\n return false;\n }\n\n return (\n value.mode === \"delta\" ||\n value.lanes.groupMemberships.deletedGroupIds.length === 0\n );\n}\n\nexport const OrganizationReadModelResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n registerJsonSchemaView(\n OrganizationReadModelResponseSchemaView.refine(\n hasValidReadModelSemantics,\n ),\n OrganizationReadModelResponseSchemaView,\n ),\n organizationReadModelResponseRuntimeRefinements,\n );\n\nexport type OrganizationReadModelResponse = z.infer<\n typeof OrganizationReadModelResponseSchema\n>;\n\nexport function isOrganizationReadModelResponse(\n value: unknown,\n): value is OrganizationReadModelResponse {\n return OrganizationReadModelResponseSchema.safeParse(value).success;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -47,6 +47,10 @@ const DEFERRED_TAIL_CANDIDATE_SQL = `
|
|
|
47
47
|
ON stored.app_kind = 'container-metadata'
|
|
48
48
|
AND metadata_container.id = stored.local_id
|
|
49
49
|
WHERE stored.snapshot_end_version <> ''
|
|
50
|
+
-- A marker equal to the content frontier covers it, so a settled record
|
|
51
|
+
-- is never a candidate. With the term above this matches
|
|
52
|
+
-- documents_deferred_tail_idx, so the scan reads only unsettled records.
|
|
53
|
+
AND stored.pending_base_version IS NOT stored.snapshot_end_version
|
|
50
54
|
-- Dormant retained metadata (row 4, access_revoked) has no containers
|
|
51
55
|
-- row; keep it out of deferred-tail candidates until re-attach, matching
|
|
52
56
|
-- the pending-write sources guard.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deferredTails.js","sourceRoot":"","sources":["deferredTails.ts"],"names":[],"mappings":"AA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,CAAC,CAAC,EAAE,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsB/B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAgB,EAChB,KAA2C;IAE3C,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,uBAAuB,EAAE;QAClD,KAAK,CAAC,OAAO;QACb,KAAK,CAAC,OAAO;KACd,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC;IAC/D,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,gBAAgB,CAAC;QACtB,cAAc;QACd,uBAAuB,EAAE,UAAU,CAAC,GAAG,EAAE,4BAA4B,CAAC;QACtE,kBAAkB,EAAE,UAAU,CAAC,GAAG,EAAE,sBAAsB,CAAC;KAC5D,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { mergeVersionVectors, satisfiesVersionVector } from \"@tearleads/loro\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n getContainerDisplayNameSql,\n getContainerOrganizationAttributionSql,\n} from \"../documentQueries/sql\";\nimport type { PendingWriteCandidate } from \"./aggregation\";\nimport type { PendingWriteQueueObjectKind } from \"./pendingWritesTypes\";\nimport { readString } from \"./rowReaders\";\n\n// Deliberately never loads document content: the diagnostic listing runs\n// repeatedly while sync drains, and materializing every content blob would\n// make the scan O(total document content). `snapshot_end_version` is the\n// write-time-derived end version vector of the persisted content.\nconst DEFERRED_TAIL_CANDIDATE_SQL = `\n SELECT\n stored.app_kind AS app_kind,\n stored.local_id AS local_id,\n stored.document_id AS stored_remote_id,\n stored.snapshot_end_version AS snapshot_end_version,\n stored.pending_base_version AS pending_base_version,\n stored.updated_at AS updated_at,\n (\n SELECT pending.partial_end_version_vector\n FROM document_history_updates pending\n WHERE pending.app_kind = stored.app_kind\n AND pending.local_id = stored.local_id\n AND pending.update_id IS NOT NULL\n ORDER BY pending.created_at DESC, pending.rowid DESC\n LIMIT 1\n ) AS latest_pending_end_version,\n document_projection.title AS document_name,\n document_projection.container_id AS document_container_id,\n ${getContainerOrganizationAttributionSql({\n containerAlias: \"document_container\",\n projectionAlias: \"document_projection\",\n })} AS document_organization_id,\n CASE\n WHEN metadata_container.server_created_at IS NULL THEN NULL\n ELSE metadata_container.id\n END AS container_remote_id,\n ${getContainerDisplayNameSql(\"metadata_container\")} AS container_name,\n metadata_container.id AS metadata_container_id,\n NULLIF(metadata_container.organization_id, '') AS metadata_organization_id,\n stored.sync_failure_message AS failure_message,\n stored.sync_failure_attempted_at AS failure_attempted_at\n FROM documents stored\n LEFT JOIN document_projection\n ON stored.app_kind = 'documents'\n AND document_projection.local_id = stored.local_id\n LEFT JOIN containers document_container\n ON document_container.id = document_projection.container_id\n LEFT JOIN containers metadata_container\n ON stored.app_kind = 'container-metadata'\n AND metadata_container.id = stored.local_id\n WHERE stored.snapshot_end_version <> ''\n -- Dormant retained metadata (row 4, access_revoked) has no containers\n -- row; keep it out of deferred-tail candidates until re-attach, matching\n -- the pending-write sources guard.\n AND (stored.app_kind <> 'container-metadata'\n OR metadata_container.id IS NOT NULL)\n AND (\n stored.pending_base_version IS NOT NULL\n OR EXISTS (\n SELECT 1\n FROM document_history_updates pending\n WHERE pending.app_kind = stored.app_kind\n AND pending.local_id = stored.local_id\n AND pending.update_id IS NOT NULL\n )\n )\n`;\n\nfunction hasUncoveredTail(input: {\n currentVersion: string;\n latestPendingEndVersion: string | null;\n pendingBaseVersion: string | null;\n}): boolean {\n const coverageVersions = [\n input.latestPendingEndVersion,\n input.pendingBaseVersion,\n ].filter((value): value is string => value !== null);\n const validCoverageVersions: string[] = [];\n for (const coverageVersion of coverageVersions) {\n try {\n validCoverageVersions.push(mergeVersionVectors([coverageVersion]));\n } catch {\n // Corrupt coverage must not make the diagnostic claim an uncovered write.\n return false;\n }\n }\n if (validCoverageVersions.length === 0) {\n return false;\n }\n\n try {\n const mergedCoverage = mergeVersionVectors(validCoverageVersions);\n return !satisfiesVersionVector(mergedCoverage, input.currentVersion);\n } catch {\n // Corrupt coverage must not make the diagnostic claim an uncovered write.\n return false;\n }\n}\n\nfunction getObjectKind(appKind: string): PendingWriteQueueObjectKind {\n if (appKind === \"documents\") return \"document\";\n if (appKind === \"container-metadata\") return \"container\";\n return \"unknown\";\n}\n\nfunction mapDeferredTailCandidate(\n row: Record<string, unknown>,\n): PendingWriteCandidate | null {\n const appKind = readString(row, \"app_kind\");\n const localId = readString(row, \"local_id\");\n const currentVersion = readString(row, \"snapshot_end_version\");\n if (!appKind || !localId || !currentVersion) {\n return null;\n }\n if (\n !hasUncoveredTail({\n currentVersion,\n latestPendingEndVersion: readString(row, \"latest_pending_end_version\"),\n pendingBaseVersion: readString(row, \"pending_base_version\"),\n })\n ) {\n return null;\n }\n\n const objectKind = getObjectKind(appKind);\n const updatedAt = readString(row, \"updated_at\");\n return {\n byteLength: 0,\n containerId:\n objectKind === \"container\"\n ? readString(row, \"metadata_container_id\")\n : objectKind === \"document\"\n ? readString(row, \"document_container_id\")\n : null,\n count: 1,\n createdAt: updatedAt,\n inclusion: \"always\",\n kind: \"deferred-update\",\n // Carry the scope's recorded sync failure so a covering deferred-update\n // candidate never hides the diagnostic a suppressed failure-only item\n // would have shown.\n lastAttemptedAt: readString(row, \"failure_attempted_at\"),\n lastError: readString(row, \"failure_message\"),\n localId,\n name:\n objectKind === \"container\"\n ? readString(row, \"container_name\")\n : objectKind === \"document\"\n ? readString(row, \"document_name\")\n : null,\n namespace: objectKind === \"unknown\" ? appKind : null,\n objectKind,\n organizationId:\n objectKind === \"container\"\n ? readString(row, \"metadata_organization_id\")\n : objectKind === \"document\"\n ? readString(row, \"document_organization_id\")\n : null,\n remoteId:\n objectKind === \"container\"\n ? readString(row, \"container_remote_id\")\n : readString(row, \"stored_remote_id\"),\n status: \"pending\",\n targetContainerId: null,\n updatedAt,\n };\n}\n\nexport async function listDeferredPendingWriteCandidates(\n execSql: ExecSql,\n): Promise<PendingWriteCandidate[]> {\n const rows = await execSql(DEFERRED_TAIL_CANDIDATE_SQL);\n return rows.flatMap((row) => {\n const candidate = mapDeferredTailCandidate(row);\n return candidate ? [candidate] : [];\n });\n}\n\nconst DEFERRED_TAIL_SCOPE_SQL = `\n SELECT\n stored.snapshot_end_version AS snapshot_end_version,\n stored.pending_base_version AS pending_base_version,\n (\n SELECT pending.partial_end_version_vector\n FROM document_history_updates pending\n WHERE pending.app_kind = stored.app_kind\n AND pending.local_id = stored.local_id\n AND pending.update_id IS NOT NULL\n ORDER BY pending.created_at DESC, pending.rowid DESC\n LIMIT 1\n ) AS latest_pending_end_version\n FROM documents stored\n WHERE stored.app_kind = ? AND stored.local_id = ?\n AND stored.snapshot_end_version <> ''\n -- Dormant retained metadata (row 4, access_revoked) has no containers\n -- row; it is not queued work until re-attach, matching the candidate\n -- scan's guard.\n AND (stored.app_kind <> 'container-metadata'\n OR EXISTS (SELECT 1 FROM containers WHERE containers.id = stored.local_id))\n LIMIT 1\n`;\n\n/**\n * Whether this one scope has a deferred write: durable-tail content ahead of\n * its covered frontier, possibly with no queued update rows at all. The same\n * coverage check as the candidate scan, narrowed to a single scope, so\n * \"queued work\" classifications agree with the item the panel rendered.\n */\nexport async function hasDeferredTailScopeWork(\n execSql: ExecSql,\n scope: { appKind: string; localId: string },\n): Promise<boolean> {\n const rows = await execSql(DEFERRED_TAIL_SCOPE_SQL, [\n scope.appKind,\n scope.localId,\n ]);\n const row = rows[0];\n if (!row) {\n return false;\n }\n const currentVersion = readString(row, \"snapshot_end_version\");\n if (!currentVersion) {\n return false;\n }\n return hasUncoveredTail({\n currentVersion,\n latestPendingEndVersion: readString(row, \"latest_pending_end_version\"),\n pendingBaseVersion: readString(row, \"pending_base_version\"),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"deferredTails.js","sourceRoot":"","sources":["deferredTails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9E,OAAO,EACL,0BAA0B,EAC1B,sCAAsC,GACvC,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,yEAAyE;AACzE,2EAA2E;AAC3E,yEAAyE;AACzE,kEAAkE;AAClE,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;MAmB9B,sCAAsC,CAAC;IACvC,cAAc,EAAE,oBAAoB;IACpC,eAAe,EAAE,qBAAqB;CACvC,CAAC;;;;;MAKA,0BAA0B,CAAC,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCrD,CAAC;AAEF,SAAS,gBAAgB,CAAC,KAIzB;IACC,MAAM,gBAAgB,GAAG;QACvB,KAAK,CAAC,uBAAuB;QAC7B,KAAK,CAAC,kBAAkB;KACzB,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;IACrD,MAAM,qBAAqB,GAAa,EAAE,CAAC;IAC3C,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE,CAAC;QAC/C,IAAI,CAAC;YACH,qBAAqB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACrE,CAAC;QAAC,MAAM,CAAC;YACP,0EAA0E;YAC1E,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,IAAI,qBAAqB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,MAAM,cAAc,G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CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1B,MAAM,SAAS,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;QAChD,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsB/B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAgB,EAChB,KAA2C;IAE3C,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,uBAAuB,EAAE;QAClD,KAAK,CAAC,OAAO;QACb,KAAK,CAAC,OAAO;KACd,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC;IAC/D,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,gBAAgB,CAAC;QACtB,cAAc;QACd,uBAAuB,EAAE,UAAU,CAAC,GAAG,EAAE,4BAA4B,CAAC;QACtE,kBAAkB,EAAE,UAAU,CAAC,GAAG,EAAE,sBAAsB,CAAC;KAC5D,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { mergeVersionVectors, satisfiesVersionVector } from \"@tearleads/loro\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n getContainerDisplayNameSql,\n getContainerOrganizationAttributionSql,\n} from \"../documentQueries/sql\";\nimport type { PendingWriteCandidate } from \"./aggregation\";\nimport type { PendingWriteQueueObjectKind } from \"./pendingWritesTypes\";\nimport { readString } from \"./rowReaders\";\n\n// Deliberately never loads document content: the diagnostic listing runs\n// repeatedly while sync drains, and materializing every content blob would\n// make the scan O(total document content). `snapshot_end_version` is the\n// write-time-derived end version vector of the persisted content.\nconst DEFERRED_TAIL_CANDIDATE_SQL = `\n SELECT\n stored.app_kind AS app_kind,\n stored.local_id AS local_id,\n stored.document_id AS stored_remote_id,\n stored.snapshot_end_version AS snapshot_end_version,\n stored.pending_base_version AS pending_base_version,\n stored.updated_at AS updated_at,\n (\n SELECT pending.partial_end_version_vector\n FROM document_history_updates pending\n WHERE pending.app_kind = stored.app_kind\n AND pending.local_id = stored.local_id\n AND pending.update_id IS NOT NULL\n ORDER BY pending.created_at DESC, pending.rowid DESC\n LIMIT 1\n ) AS latest_pending_end_version,\n document_projection.title AS document_name,\n document_projection.container_id AS document_container_id,\n ${getContainerOrganizationAttributionSql({\n containerAlias: \"document_container\",\n projectionAlias: \"document_projection\",\n })} AS document_organization_id,\n CASE\n WHEN metadata_container.server_created_at IS NULL THEN NULL\n ELSE metadata_container.id\n END AS container_remote_id,\n ${getContainerDisplayNameSql(\"metadata_container\")} AS container_name,\n metadata_container.id AS metadata_container_id,\n NULLIF(metadata_container.organization_id, '') AS metadata_organization_id,\n stored.sync_failure_message AS failure_message,\n stored.sync_failure_attempted_at AS failure_attempted_at\n FROM documents stored\n LEFT JOIN document_projection\n ON stored.app_kind = 'documents'\n AND document_projection.local_id = stored.local_id\n LEFT JOIN containers document_container\n ON document_container.id = document_projection.container_id\n LEFT JOIN containers metadata_container\n ON stored.app_kind = 'container-metadata'\n AND metadata_container.id = stored.local_id\n WHERE stored.snapshot_end_version <> ''\n -- A marker equal to the content frontier covers it, so a settled record\n -- is never a candidate. With the term above this matches\n -- documents_deferred_tail_idx, so the scan reads only unsettled records.\n AND stored.pending_base_version IS NOT stored.snapshot_end_version\n -- Dormant retained metadata (row 4, access_revoked) has no containers\n -- row; keep it out of deferred-tail candidates until re-attach, matching\n -- the pending-write sources guard.\n AND (stored.app_kind <> 'container-metadata'\n OR metadata_container.id IS NOT NULL)\n AND (\n stored.pending_base_version IS NOT NULL\n OR EXISTS (\n SELECT 1\n FROM document_history_updates pending\n WHERE pending.app_kind = stored.app_kind\n AND pending.local_id = stored.local_id\n AND pending.update_id IS NOT NULL\n )\n )\n`;\n\nfunction hasUncoveredTail(input: {\n currentVersion: string;\n latestPendingEndVersion: string | null;\n pendingBaseVersion: string | null;\n}): boolean {\n const coverageVersions = [\n input.latestPendingEndVersion,\n input.pendingBaseVersion,\n ].filter((value): value is string => value !== null);\n const validCoverageVersions: string[] = [];\n for (const coverageVersion of coverageVersions) {\n try {\n validCoverageVersions.push(mergeVersionVectors([coverageVersion]));\n } catch {\n // Corrupt coverage must not make the diagnostic claim an uncovered write.\n return false;\n }\n }\n if (validCoverageVersions.length === 0) {\n return false;\n }\n\n try {\n const mergedCoverage = mergeVersionVectors(validCoverageVersions);\n return !satisfiesVersionVector(mergedCoverage, input.currentVersion);\n } catch {\n // Corrupt coverage must not make the diagnostic claim an uncovered write.\n return false;\n }\n}\n\nfunction getObjectKind(appKind: string): PendingWriteQueueObjectKind {\n if (appKind === \"documents\") return \"document\";\n if (appKind === \"container-metadata\") return \"container\";\n return \"unknown\";\n}\n\nfunction mapDeferredTailCandidate(\n row: Record<string, unknown>,\n): PendingWriteCandidate | null {\n const appKind = readString(row, \"app_kind\");\n const localId = readString(row, \"local_id\");\n const currentVersion = readString(row, \"snapshot_end_version\");\n if (!appKind || !localId || !currentVersion) {\n return null;\n }\n if (\n !hasUncoveredTail({\n currentVersion,\n latestPendingEndVersion: readString(row, \"latest_pending_end_version\"),\n pendingBaseVersion: readString(row, \"pending_base_version\"),\n })\n ) {\n return null;\n }\n\n const objectKind = getObjectKind(appKind);\n const updatedAt = readString(row, \"updated_at\");\n return {\n byteLength: 0,\n containerId:\n objectKind === \"container\"\n ? readString(row, \"metadata_container_id\")\n : objectKind === \"document\"\n ? readString(row, \"document_container_id\")\n : null,\n count: 1,\n createdAt: updatedAt,\n inclusion: \"always\",\n kind: \"deferred-update\",\n // Carry the scope's recorded sync failure so a covering deferred-update\n // candidate never hides the diagnostic a suppressed failure-only item\n // would have shown.\n lastAttemptedAt: readString(row, \"failure_attempted_at\"),\n lastError: readString(row, \"failure_message\"),\n localId,\n name:\n objectKind === \"container\"\n ? readString(row, \"container_name\")\n : objectKind === \"document\"\n ? readString(row, \"document_name\")\n : null,\n namespace: objectKind === \"unknown\" ? appKind : null,\n objectKind,\n organizationId:\n objectKind === \"container\"\n ? readString(row, \"metadata_organization_id\")\n : objectKind === \"document\"\n ? readString(row, \"document_organization_id\")\n : null,\n remoteId:\n objectKind === \"container\"\n ? readString(row, \"container_remote_id\")\n : readString(row, \"stored_remote_id\"),\n status: \"pending\",\n targetContainerId: null,\n updatedAt,\n };\n}\n\nexport async function listDeferredPendingWriteCandidates(\n execSql: ExecSql,\n): Promise<PendingWriteCandidate[]> {\n const rows = await execSql(DEFERRED_TAIL_CANDIDATE_SQL);\n return rows.flatMap((row) => {\n const candidate = mapDeferredTailCandidate(row);\n return candidate ? [candidate] : [];\n });\n}\n\nconst DEFERRED_TAIL_SCOPE_SQL = `\n SELECT\n stored.snapshot_end_version AS snapshot_end_version,\n stored.pending_base_version AS pending_base_version,\n (\n SELECT pending.partial_end_version_vector\n FROM document_history_updates pending\n WHERE pending.app_kind = stored.app_kind\n AND pending.local_id = stored.local_id\n AND pending.update_id IS NOT NULL\n ORDER BY pending.created_at DESC, pending.rowid DESC\n LIMIT 1\n ) AS latest_pending_end_version\n FROM documents stored\n WHERE stored.app_kind = ? AND stored.local_id = ?\n AND stored.snapshot_end_version <> ''\n -- Dormant retained metadata (row 4, access_revoked) has no containers\n -- row; it is not queued work until re-attach, matching the candidate\n -- scan's guard.\n AND (stored.app_kind <> 'container-metadata'\n OR EXISTS (SELECT 1 FROM containers WHERE containers.id = stored.local_id))\n LIMIT 1\n`;\n\n/**\n * Whether this one scope has a deferred write: durable-tail content ahead of\n * its covered frontier, possibly with no queued update rows at all. The same\n * coverage check as the candidate scan, narrowed to a single scope, so\n * \"queued work\" classifications agree with the item the panel rendered.\n */\nexport async function hasDeferredTailScopeWork(\n execSql: ExecSql,\n scope: { appKind: string; localId: string },\n): Promise<boolean> {\n const rows = await execSql(DEFERRED_TAIL_SCOPE_SQL, [\n scope.appKind,\n scope.localId,\n ]);\n const row = rows[0];\n if (!row) {\n return false;\n }\n const currentVersion = readString(row, \"snapshot_end_version\");\n if (!currentVersion) {\n return false;\n }\n return hasUncoveredTail({\n currentVersion,\n latestPendingEndVersion: readString(row, \"latest_pending_end_version\"),\n pendingBaseVersion: readString(row, \"pending_base_version\"),\n });\n}\n"]}
|