@opengeni/db 0.28.9 → 0.36.0

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 (225) hide show
  1. package/dist/attached-browser-devices.d.ts +42 -0
  2. package/dist/attempt-tool-catalogs.d.ts +16 -0
  3. package/dist/browser-auth.d.ts +299 -0
  4. package/dist/browser-downloads.d.ts +51 -0
  5. package/dist/browser-identities.d.ts +137 -0
  6. package/dist/browser-sessions.d.ts +354 -0
  7. package/dist/browser-state-artifacts.d.ts +91 -0
  8. package/dist/canonical-human-identities.d.ts +48 -0
  9. package/dist/canonical-human-identities.js +28 -0
  10. package/dist/canonical-human-identities.js.map +1 -0
  11. package/dist/capability-components.d.ts +37 -0
  12. package/dist/capability-integrations.d.ts +194 -0
  13. package/dist/chunk-5KTIEDX7.js +13200 -0
  14. package/dist/chunk-5KTIEDX7.js.map +1 -0
  15. package/dist/chunk-CQZ4QSP5.js +995 -0
  16. package/dist/chunk-CQZ4QSP5.js.map +1 -0
  17. package/dist/chunk-F32YT7MP.js +117 -0
  18. package/dist/chunk-F32YT7MP.js.map +1 -0
  19. package/dist/chunk-JC5QPLUM.js +666 -0
  20. package/dist/chunk-JC5QPLUM.js.map +1 -0
  21. package/dist/chunk-P3RE4D2B.js +3535 -0
  22. package/dist/chunk-P3RE4D2B.js.map +1 -0
  23. package/dist/chunk-TAUTWOS5.js +259 -0
  24. package/dist/chunk-TAUTWOS5.js.map +1 -0
  25. package/dist/chunk-VKLB2ZGI.js +2389 -0
  26. package/dist/chunk-VKLB2ZGI.js.map +1 -0
  27. package/dist/codemode-operations.d.ts +117 -0
  28. package/dist/codex-token-resolver.d.ts +2 -2
  29. package/dist/company-profile-schema.d.ts +798 -0
  30. package/dist/company-profile.d.ts +268 -0
  31. package/dist/computer-sessions.d.ts +109 -0
  32. package/dist/connection-token-resolver.d.ts +9 -4
  33. package/dist/database.d.ts +57 -3
  34. package/dist/editable-artifact-durable-export.d.ts +153 -0
  35. package/dist/editable-artifact-durable-export.js +788 -0
  36. package/dist/editable-artifact-durable-export.js.map +1 -0
  37. package/dist/editable-artifact-materialization.d.ts +123 -0
  38. package/dist/editable-artifacts-schema.d.ts +4152 -0
  39. package/dist/editable-artifacts.d.ts +610 -0
  40. package/dist/editable-artifacts.js +26 -0
  41. package/dist/editable-artifacts.js.map +1 -0
  42. package/dist/generated-images.d.ts +139 -0
  43. package/dist/index.d.ts +1122 -126
  44. package/dist/index.js +42329 -18407
  45. package/dist/index.js.map +1 -1
  46. package/dist/insights.d.ts +73 -10
  47. package/dist/integration-bindings.d.ts +70 -0
  48. package/dist/integration-facets.d.ts +99 -0
  49. package/dist/interaction-revisions.d.ts +14 -0
  50. package/dist/interaction-schema.d.ts +6036 -0
  51. package/dist/knowledge-source-sync-schema.d.ts +1679 -0
  52. package/dist/knowledge-source-sync.d.ts +274 -0
  53. package/dist/memory-governance.d.ts +2 -2
  54. package/dist/memory-slack-delivery.d.ts +101 -0
  55. package/dist/new-session-drafts.d.ts +2 -2
  56. package/dist/pack-components.d.ts +76 -0
  57. package/dist/pack-installations.d.ts +86 -0
  58. package/dist/persistence-errors.d.ts +3 -3
  59. package/dist/plugin-packages.d.ts +126 -0
  60. package/dist/preference-registry.d.ts +1 -1
  61. package/dist/provision-roles.d.ts +9 -1
  62. package/dist/provision-roles.js +1 -1
  63. package/dist/runtime-posture.d.ts +19 -6
  64. package/dist/schema.d.ts +22654 -9359
  65. package/dist/schema.js +209 -3
  66. package/dist/scoped-knowledge.d.ts +97 -1
  67. package/dist/session-control.d.ts +33 -7
  68. package/dist/session-queue-commands.d.ts +19 -11
  69. package/dist/session-realtime-context.d.ts +2 -2
  70. package/dist/session-realtime-ledger.d.ts +4 -4
  71. package/dist/session-realtime-mirror.d.ts +2 -2
  72. package/dist/session-realtime-state.d.ts +1 -1
  73. package/dist/session-realtime-terminal.d.ts +1 -1
  74. package/dist/session-realtime.d.ts +7 -7
  75. package/dist/session-tenancy.d.ts +44 -0
  76. package/dist/session-tenancy.js +16 -0
  77. package/dist/session-tenancy.js.map +1 -0
  78. package/dist/session-tool-call-settlement.d.ts +1 -1
  79. package/dist/slack-task-policy-schema.d.ts +847 -0
  80. package/dist/slack-task-policy.d.ts +65 -0
  81. package/dist/slack-user-link-access.d.ts +54 -0
  82. package/dist/task-notes-schema.d.ts +924 -0
  83. package/dist/task-notes.d.ts +85 -0
  84. package/dist/transcription-recordings.d.ts +2 -2
  85. package/dist/turn-initiator.d.ts +2 -2
  86. package/dist/video-generation.d.ts +225 -0
  87. package/dist/video-generation.js +68 -0
  88. package/dist/video-generation.js.map +1 -0
  89. package/dist/workspace-artifacts.d.ts +1 -1
  90. package/dist/workspace-instruction-policies.d.ts +1 -1
  91. package/dist/workspace-learning-policy-schema.d.ts +932 -0
  92. package/dist/workspace-learning-policy.d.ts +161 -0
  93. package/dist/xai-subscription.d.ts +326 -0
  94. package/drizzle/0183_model_call_provider_cost_estimates.sql +39 -0
  95. package/drizzle/0184_sandbox_drain_teardown_fence.sql +682 -0
  96. package/drizzle/0185_temporal_schedule_cleanup_outbox.sql +168 -0
  97. package/drizzle/0186_sandbox_capture_provider_contract.sql +400 -0
  98. package/drizzle/0187_generated_image_artifacts.sql +173 -0
  99. package/drizzle/0188_image_generation_retention_failure.sql +25 -0
  100. package/drizzle/0189_retained_session_image_formats.sql +13 -0
  101. package/drizzle/0190_timeline_annotations.sql +31 -0
  102. package/drizzle/0191_editable_artifact_engine.sql +3853 -0
  103. package/drizzle/0192_editable_artifact_live_tickets.sql +338 -0
  104. package/drizzle/0193_editable_artifact_authorization.sql +190 -0
  105. package/drizzle/0194_editable_artifact_durable_exports.sql +160 -0
  106. package/drizzle/0195_editable_artifact_import_authorization.sql +203 -0
  107. package/drizzle/0196_rig_provider_images.sql +152 -0
  108. package/drizzle/0197_knowledge_source_sync_schedules.sql +523 -0
  109. package/drizzle/0198_memory_slack_publication_delivery.sql +393 -0
  110. package/drizzle/0199_workspace_learning_policy.sql +980 -0
  111. package/drizzle/0201_company_profile_authority.sql +849 -0
  112. package/drizzle/0202_document_index_checkpoints.sql +85 -0
  113. package/drizzle/0203_durable_video_generation.sql +353 -0
  114. package/drizzle/0204_video_generation_funding.sql +44 -0
  115. package/drizzle/0205_attempt_tool_catalogs.sql +230 -0
  116. package/drizzle/0206_browser_sessions.sql +646 -0
  117. package/drizzle/0207_browser_identities.sql +379 -0
  118. package/drizzle/0208_attached_browser_devices.sql +165 -0
  119. package/drizzle/0209_computer_sessions.sql +575 -0
  120. package/drizzle/0210_browser_auth_network_interventions.sql +441 -0
  121. package/drizzle/0211_editable_artifact_session_links.sql +58 -0
  122. package/drizzle/0212_browser_state_transfer_hardening.sql +560 -0
  123. package/drizzle/0212_slack_installation_bindings.sql +348 -0
  124. package/drizzle/0213_browser_interaction_authority.sql +67 -0
  125. package/drizzle/0213_slack_user_link_access_requests.sql +177 -0
  126. package/drizzle/0214_browser_download_saves.sql +34 -0
  127. package/drizzle/0214_session_activity_commit_gate.sql +262 -0
  128. package/drizzle/0215_browser_controller_host.sql +385 -0
  129. package/drizzle/0215_capabilities_platform.sql +980 -0
  130. package/drizzle/0216_browser_auth_health_evidence.sql +137 -0
  131. package/drizzle/0216_pack_component_ownership.sql +235 -0
  132. package/drizzle/0217_capability_definition_delete_authority.sql +32 -0
  133. package/drizzle/0217_external_browser_auth_operations.sql +22 -0
  134. package/drizzle/0218_organization_tenancy_foundation.sql +299 -0
  135. package/drizzle/0219_organization_tenancy_managed_human_provisioning.sql +317 -0
  136. package/drizzle/0219_site_auth_maintenance_sessions.sql +234 -0
  137. package/drizzle/0220_memory_slack_append_only_cascade.sql +38 -0
  138. package/drizzle/0220_session_channels.sql +54 -0
  139. package/drizzle/0221_sessions_channel_index.sql +5 -0
  140. package/drizzle/0222_session_visibility_authority_epochs.sql +158 -0
  141. package/drizzle/0222_sessions_channel_fk.sql +89 -0
  142. package/drizzle/0223_pending_tool_event_output.sql +55 -0
  143. package/drizzle/0223_sessions_channel_fk_validate.sql +118 -0
  144. package/drizzle/0224_slack_post_outcome_reconciliation.sql +123 -0
  145. package/drizzle/0225_session_visibility_fork_activation.sql +1363 -0
  146. package/drizzle/0226_personal_codex_authority_foundation.sql +365 -0
  147. package/drizzle/0227_slack_native_actions.sql +145 -0
  148. package/drizzle/0228_interaction_controller_data_plane.sql +14 -0
  149. package/drizzle/0228_slack_task_policy.sql +400 -0
  150. package/drizzle/0229_slack_inbox_file_fact.sql +10 -0
  151. package/drizzle/0230_user_scoped_variable_sets_rigs.sql +84 -0
  152. package/drizzle/0231_integration_definition_identity_cutover.sql +271 -0
  153. package/drizzle/0232_integration_facet_authority_cutover.sql +610 -0
  154. package/drizzle/0233_skill_and_integration_authority_cutover.sql +1162 -0
  155. package/drizzle/0234_xai_subscription_authority.sql +1139 -0
  156. package/drizzle/0235_canonical_human_login_bindings.sql +920 -0
  157. package/drizzle/0236_browser_identity_lifecycle.sql +39 -0
  158. package/drizzle/0236_session_visibility_slack_policy.sql +72 -0
  159. package/drizzle/0237_interaction_transition_reaper.sql +263 -0
  160. package/drizzle/0238_goal_persistence_policy.sql +471 -0
  161. package/drizzle/0238_supergrok_realtime_model.sql +29 -0
  162. package/drizzle/0239_supergrok_video_funding.sql +50 -0
  163. package/drizzle/0239_task_tree_notes.sql +990 -0
  164. package/package.json +26 -5
  165. package/src/attached-browser-devices.ts +371 -0
  166. package/src/attempt-tool-catalogs.ts +131 -0
  167. package/src/browser-auth.ts +4373 -0
  168. package/src/browser-downloads.ts +517 -0
  169. package/src/browser-identities.ts +1385 -0
  170. package/src/browser-sessions.ts +2294 -0
  171. package/src/browser-state-artifacts.ts +449 -0
  172. package/src/canonical-human-identities.ts +317 -0
  173. package/src/capability-components.ts +166 -0
  174. package/src/capability-integrations.ts +1571 -0
  175. package/src/codemode-operations.ts +674 -0
  176. package/src/company-profile-schema.ts +143 -0
  177. package/src/company-profile.ts +968 -0
  178. package/src/computer-sessions.ts +1130 -0
  179. package/src/connection-token-resolver.ts +270 -25
  180. package/src/database.ts +468 -24
  181. package/src/editable-artifact-durable-export.ts +1201 -0
  182. package/src/editable-artifact-materialization.ts +893 -0
  183. package/src/editable-artifacts-schema.ts +879 -0
  184. package/src/editable-artifacts.ts +5404 -0
  185. package/src/generated-images.ts +740 -0
  186. package/src/index.ts +9963 -1465
  187. package/src/insights.ts +251 -23
  188. package/src/integration-bindings.ts +455 -0
  189. package/src/integration-facets.ts +862 -0
  190. package/src/interaction-revisions.ts +70 -0
  191. package/src/interaction-schema.ts +1606 -0
  192. package/src/knowledge-source-sync-schema.ts +192 -0
  193. package/src/knowledge-source-sync.ts +1922 -0
  194. package/src/memory-slack-delivery.ts +801 -0
  195. package/src/pack-components.ts +954 -0
  196. package/src/pack-installations.ts +886 -0
  197. package/src/persistence-errors.ts +4 -7
  198. package/src/plugin-packages.ts +1186 -0
  199. package/src/provision-roles.ts +534 -1
  200. package/src/runtime-posture-cli.ts +9 -0
  201. package/src/runtime-posture.ts +721 -5
  202. package/src/schema.ts +6270 -3159
  203. package/src/scoped-knowledge-schema.ts +1 -1
  204. package/src/scoped-knowledge.ts +655 -3
  205. package/src/session-control.ts +130 -42
  206. package/src/session-queue-commands.ts +265 -15
  207. package/src/session-realtime-context.ts +2 -2
  208. package/src/session-realtime-ledger.ts +3 -3
  209. package/src/session-realtime.ts +7 -7
  210. package/src/session-tenancy.ts +188 -0
  211. package/src/session-tool-call-settlement.ts +18 -3
  212. package/src/slack-task-policy-schema.ts +130 -0
  213. package/src/slack-task-policy.ts +341 -0
  214. package/src/slack-user-link-access.ts +702 -0
  215. package/src/task-notes-schema.ts +135 -0
  216. package/src/task-notes.ts +178 -0
  217. package/src/video-generation.ts +1530 -0
  218. package/src/workspace-artifacts.ts +1 -1
  219. package/src/workspace-learning-policy-schema.ts +139 -0
  220. package/src/workspace-learning-policy.ts +595 -0
  221. package/src/xai-subscription.ts +1887 -0
  222. package/dist/chunk-P6CUHXQZ.js +0 -7248
  223. package/dist/chunk-P6CUHXQZ.js.map +0 -1
  224. package/dist/chunk-VHBFHMPC.js +0 -1219
  225. package/dist/chunk-VHBFHMPC.js.map +0 -1
@@ -0,0 +1,788 @@
1
+ import {
2
+ rawRows,
3
+ withRlsContext
4
+ } from "./chunk-JC5QPLUM.js";
5
+ import "./chunk-5KTIEDX7.js";
6
+ import "./chunk-PZ5AY32C.js";
7
+
8
+ // src/editable-artifact-durable-export.ts
9
+ import { createHash } from "crypto";
10
+ import { sql } from "drizzle-orm";
11
+ var EditableArtifactDurableExportPersistenceError = class extends Error {
12
+ constructor(code, message, options) {
13
+ super(message, options);
14
+ this.code = code;
15
+ this.name = "EditableArtifactDurableExportPersistenceError";
16
+ }
17
+ };
18
+ var PostgresEditableArtifactDurableExportStore = class {
19
+ constructor(db) {
20
+ this.db = db;
21
+ }
22
+ async pinVersion(requestInput) {
23
+ const request = validatePinRequest(requestInput);
24
+ return await withRlsContext(
25
+ this.db,
26
+ request.scope,
27
+ async (tx) => {
28
+ const authorization = await authorize(tx, request);
29
+ if (!authorization.allowed || authorization.revision !== request.expectedAuthorizationRevision) {
30
+ return Object.freeze({ kind: "authorization_stale" });
31
+ }
32
+ await lockIdempotencyRequest(tx, request, "version");
33
+ const replay = await findReceipt(tx, request, "version", request.idempotencyKey);
34
+ if (replay) {
35
+ if (replay.requestHash !== request.requestHash) throw idempotencyConflict();
36
+ const version = await loadVersion(
37
+ tx,
38
+ request.scope,
39
+ request.artifactId,
40
+ replay.resourceId
41
+ );
42
+ if (!version) throw contractViolation("Version receipt points to a missing version");
43
+ return Object.freeze({
44
+ kind: "result",
45
+ value: Object.freeze({ version, replayed: true })
46
+ });
47
+ }
48
+ const artifact = await lockArtifact(tx, request.scope, request.artifactId);
49
+ if (!artifact) throw notFound();
50
+ if (artifact.authorizationRevision !== request.expectedAuthorizationRevision) {
51
+ return Object.freeze({ kind: "authorization_stale" });
52
+ }
53
+ assertSnapshotPinsArtifact(request.snapshot, artifact);
54
+ const inserted = await rawRows(
55
+ tx,
56
+ sql`insert into editable_artifact_versions (
57
+ account_id, workspace_id, artifact_id, id, snapshot_id, head_sequence,
58
+ causal_frontier, native_revision, state_hash, name, pinned, created_by_subject_id
59
+ ) values (
60
+ ${request.scope.accountId}::uuid, ${request.scope.workspaceId}::uuid,
61
+ ${request.artifactId}, ${request.versionId}, ${request.snapshot.snapshotId},
62
+ ${request.snapshot.coveredHeadSequence},
63
+ ${request.snapshot.coveredCausalFrontier === null ? null : JSON.stringify(request.snapshot.coveredCausalFrontier)}::jsonb,
64
+ ${request.snapshot.nativeRevision}, ${request.snapshot.stateHash}, ${request.name},
65
+ true, ${request.actor.subjectId}
66
+ ) returning
67
+ account_id, workspace_id, artifact_id, id,
68
+ ${artifact.modality}::text as modality, snapshot_id, head_sequence,
69
+ causal_frontier, native_revision, state_hash, name, pinned,
70
+ created_by_subject_id, created_at`
71
+ );
72
+ const versionRow = exactRow(inserted, "Version insert");
73
+ await insertReceipt(tx, {
74
+ ...request,
75
+ operationKind: "version",
76
+ resourceType: "artifact_version",
77
+ resourceId: request.versionId,
78
+ result: {
79
+ schemaVersion: 1,
80
+ artifactId: request.artifactId,
81
+ versionId: request.versionId
82
+ }
83
+ });
84
+ return Object.freeze({
85
+ kind: "result",
86
+ value: Object.freeze({ version: versionFromRow(versionRow), replayed: false })
87
+ });
88
+ },
89
+ { isolationLevel: "serializable" }
90
+ );
91
+ }
92
+ async enqueueMaterialization(requestInput) {
93
+ const request = validateEnqueueRequest(requestInput);
94
+ return await withRlsContext(
95
+ this.db,
96
+ request.scope,
97
+ async (tx) => {
98
+ const authorization = await authorize(tx, request);
99
+ if (!authorization.allowed || authorization.revision !== request.expectedAuthorizationRevision) {
100
+ return Object.freeze({ kind: "authorization_stale" });
101
+ }
102
+ await lockIdempotencyRequest(tx, request, "materialize");
103
+ const replay = await findReceipt(tx, request, "materialize", request.idempotencyKey);
104
+ if (replay) {
105
+ if (replay.requestHash !== request.requestHash) throw idempotencyConflict();
106
+ const job = await loadJob(
107
+ tx,
108
+ request.scope,
109
+ request.artifactId,
110
+ replay.resourceId,
111
+ false
112
+ );
113
+ if (!job) throw contractViolation("Materialization receipt points to a missing job");
114
+ return Object.freeze({
115
+ kind: "result",
116
+ value: Object.freeze({ job: job.job, replayed: true })
117
+ });
118
+ }
119
+ const artifact = await lockArtifact(tx, request.scope, request.artifactId);
120
+ if (!artifact) throw notFound();
121
+ if (artifact.authorizationRevision !== request.expectedAuthorizationRevision) {
122
+ return Object.freeze({ kind: "authorization_stale" });
123
+ }
124
+ if (artifact.modality !== request.profile.modality || !formatMatchesModality(artifact.modality, request.profile.format)) {
125
+ throw unsupportedFormat();
126
+ }
127
+ const version = await loadVersion(tx, request.scope, request.artifactId, request.versionId);
128
+ if (!version || version.modality !== artifact.modality) throw notFound();
129
+ const optionsHash = sha256(request.profile.normalizedOptions);
130
+ const inserted = await rawRows(
131
+ tx,
132
+ sql`insert into editable_artifact_materialization_jobs (
133
+ account_id, workspace_id, artifact_id, id, version_id, input_snapshot_id,
134
+ target_head_sequence, state_hash, format, normalized_options, codec_id,
135
+ codec_version, kernel_version, font_registry_hash, policy_hash
136
+ ) values (
137
+ ${request.scope.accountId}::uuid, ${request.scope.workspaceId}::uuid,
138
+ ${request.artifactId}, ${request.jobId}, ${version.id}, ${version.snapshotId},
139
+ ${version.headSequence}, ${version.stateHash}, ${request.profile.format},
140
+ ${request.profile.normalizedOptions}, ${request.profile.codecId},
141
+ ${request.profile.codecVersion}, ${request.profile.kernelVersion},
142
+ ${request.profile.fontRegistryHash}, ${request.profile.policyHash}
143
+ ) on conflict (
144
+ account_id, workspace_id, artifact_id, input_snapshot_id, state_hash, format,
145
+ options_hash, codec_id, codec_version, kernel_version, font_registry_hash, policy_hash
146
+ ) do nothing returning id`
147
+ );
148
+ let selectedJobId;
149
+ if (inserted.length === 1) {
150
+ selectedJobId = text(inserted[0].id, "inserted materialization job id");
151
+ } else if (inserted.length === 0) {
152
+ const cached = await rawRows(
153
+ tx,
154
+ sql`select id from editable_artifact_materialization_jobs
155
+ where account_id = ${request.scope.accountId}::uuid
156
+ and workspace_id = ${request.scope.workspaceId}::uuid
157
+ and artifact_id = ${request.artifactId}
158
+ and input_snapshot_id = ${version.snapshotId}
159
+ and state_hash = ${version.stateHash}
160
+ and format = ${request.profile.format}
161
+ and options_hash = ${optionsHash}
162
+ and codec_id = ${request.profile.codecId}
163
+ and codec_version = ${request.profile.codecVersion}
164
+ and kernel_version = ${request.profile.kernelVersion}
165
+ and font_registry_hash = ${request.profile.fontRegistryHash}
166
+ and policy_hash = ${request.profile.policyHash}`
167
+ );
168
+ selectedJobId = text(exactRow(cached, "Materialization cache read").id, "job id");
169
+ } else {
170
+ throw contractViolation("Materialization insert returned multiple rows");
171
+ }
172
+ await insertReceipt(tx, {
173
+ ...request,
174
+ operationKind: "materialize",
175
+ resourceType: "materialization_job",
176
+ resourceId: selectedJobId,
177
+ result: {
178
+ schemaVersion: 1,
179
+ artifactId: request.artifactId,
180
+ materializationJobId: selectedJobId
181
+ }
182
+ });
183
+ const loaded = await loadJob(tx, request.scope, request.artifactId, selectedJobId, false);
184
+ if (!loaded) throw contractViolation("Inserted materialization job is missing");
185
+ return Object.freeze({
186
+ kind: "result",
187
+ value: Object.freeze({ job: loaded.job, replayed: false })
188
+ });
189
+ },
190
+ { isolationLevel: "serializable" }
191
+ );
192
+ }
193
+ async readVersion(input) {
194
+ const request = validateReadRequest(input, "versionId");
195
+ return await withRlsContext(this.db, request.scope, async (tx) => {
196
+ const authorization = await authorize(tx, request);
197
+ if (!authorization.allowed || authorization.revision !== request.expectedAuthorizationRevision) {
198
+ return Object.freeze({ kind: "authorization_stale" });
199
+ }
200
+ return Object.freeze({
201
+ kind: "result",
202
+ value: await loadVersion(tx, request.scope, request.artifactId, request.versionId)
203
+ });
204
+ });
205
+ }
206
+ async readMaterialization(input) {
207
+ const request = validateReadRequest(input, "jobId");
208
+ return await withRlsContext(this.db, request.scope, async (tx) => {
209
+ const authorization = await authorize(tx, request);
210
+ if (!authorization.allowed || authorization.revision !== request.expectedAuthorizationRevision) {
211
+ return Object.freeze({ kind: "authorization_stale" });
212
+ }
213
+ const loaded = await loadJob(tx, request.scope, request.artifactId, request.jobId, false);
214
+ return Object.freeze({ kind: "result", value: loaded?.job ?? null });
215
+ });
216
+ }
217
+ async readMaterializationDownload(input) {
218
+ const request = validateReadRequest(input, "jobId");
219
+ return await withRlsContext(this.db, request.scope, async (tx) => {
220
+ const authorization = await authorize(tx, request);
221
+ if (!authorization.allowed || authorization.revision !== request.expectedAuthorizationRevision) {
222
+ return Object.freeze({ kind: "authorization_stale" });
223
+ }
224
+ const loaded = await loadJob(tx, request.scope, request.artifactId, request.jobId, true);
225
+ return Object.freeze({
226
+ kind: "result",
227
+ value: Object.freeze({
228
+ job: loaded?.job ?? null,
229
+ objectReference: loaded?.objectReference ?? null
230
+ })
231
+ });
232
+ });
233
+ }
234
+ };
235
+ async function authorize(tx, request) {
236
+ const actor = request.actor;
237
+ const rows = await rawRows(
238
+ tx,
239
+ sql`select * from opengeni_private.authorize_editable_artifact_actor(
240
+ ${request.scope.accountId}::uuid,
241
+ ${request.scope.workspaceId}::uuid,
242
+ ${request.artifactId},
243
+ ${actor.kind},
244
+ ${actor.subjectId},
245
+ ${actor.kind === "agent" ? actor.sessionId : null},
246
+ ${actor.kind === "agent" ? actor.turnId : null},
247
+ ${actor.kind === "agent" ? actor.attemptId : null},
248
+ ${actor.kind === "agent" ? actor.generation : null},
249
+ ${actor.kind === "service" ? actor.service : null},
250
+ 'export',
251
+ current_schema()
252
+ )`
253
+ );
254
+ const row = exactRow(rows, "Editable artifact export authorization");
255
+ return Object.freeze({
256
+ allowed: row.allowed === true,
257
+ revision: integer(row.authorization_revision, "authorization revision", 1)
258
+ });
259
+ }
260
+ async function lockArtifact(tx, scope, artifactId) {
261
+ const rows = await rawRows(
262
+ tx,
263
+ sql`select modality, authorization_revision, head_sequence, state_hash, current_snapshot_id
264
+ from editable_artifacts
265
+ where account_id = ${scope.accountId}::uuid
266
+ and workspace_id = ${scope.workspaceId}::uuid
267
+ and id = ${artifactId}
268
+ for share`
269
+ );
270
+ if (rows.length === 0) return null;
271
+ const row = exactRow(rows, "Editable artifact lock");
272
+ return Object.freeze({
273
+ modality: modality(row.modality),
274
+ authorizationRevision: integer(row.authorization_revision, "authorization revision", 1),
275
+ headSequence: integer(row.head_sequence, "artifact head sequence", 0),
276
+ stateHash: hash(row.state_hash, "artifact state hash"),
277
+ currentSnapshotId: stableId(row.current_snapshot_id, "artifact current snapshot id")
278
+ });
279
+ }
280
+ async function findReceipt(tx, request, operationKind, requestIdempotencyKey) {
281
+ const rows = await rawRows(
282
+ tx,
283
+ sql`select request_hash, resource_id
284
+ from editable_artifact_idempotency_receipts
285
+ where account_id = ${request.scope.accountId}::uuid
286
+ and workspace_id = ${request.scope.workspaceId}::uuid
287
+ and artifact_id = ${request.artifactId}
288
+ and operation_kind = ${operationKind}
289
+ and authority_key_digest = opengeni_private.editable_artifact_text_sha256(${request.authorityKey})
290
+ and authority_key = ${request.authorityKey}
291
+ and idempotency_key = ${requestIdempotencyKey}`
292
+ );
293
+ if (rows.length === 0) return null;
294
+ const row = exactRow(rows, "Editable artifact export receipt read");
295
+ return Object.freeze({
296
+ requestHash: hash(row.request_hash, "receipt request hash"),
297
+ resourceId: stableId(row.resource_id, "receipt resource id")
298
+ });
299
+ }
300
+ async function lockIdempotencyRequest(tx, request, operationKind) {
301
+ await tx.execute(
302
+ sql`select pg_advisory_xact_lock(hashtextextended(
303
+ ${`editable-artifact:${operationKind}:${request.scope.accountId}:${request.scope.workspaceId}:${request.artifactId}:${request.authorityKey}:${request.idempotencyKey}`},
304
+ 0
305
+ ))`
306
+ );
307
+ }
308
+ async function insertReceipt(tx, input) {
309
+ await tx.execute(sql`insert into editable_artifact_idempotency_receipts (
310
+ account_id, workspace_id, id, artifact_id, operation_kind, authority_key,
311
+ idempotency_key, request_hash, resource_type, resource_id, server_transaction_id, result
312
+ ) values (
313
+ ${input.scope.accountId}::uuid, ${input.scope.workspaceId}::uuid,
314
+ ${input.receiptId}, ${input.artifactId}, ${input.operationKind}, ${input.authorityKey},
315
+ ${input.idempotencyKey}, ${input.requestHash}, ${input.resourceType}, ${input.resourceId},
316
+ null, ${JSON.stringify(input.result)}::jsonb
317
+ )`);
318
+ }
319
+ async function loadVersion(tx, scope, artifactId, versionId) {
320
+ const rows = await rawRows(
321
+ tx,
322
+ sql`select
323
+ version.account_id, version.workspace_id, version.artifact_id, version.id,
324
+ artifact.modality, version.snapshot_id, version.head_sequence,
325
+ version.causal_frontier, version.native_revision, version.state_hash,
326
+ version.name, version.pinned, version.created_by_subject_id, version.created_at
327
+ from editable_artifact_versions version
328
+ join editable_artifacts artifact
329
+ on artifact.account_id = version.account_id
330
+ and artifact.workspace_id = version.workspace_id
331
+ and artifact.id = version.artifact_id
332
+ where version.account_id = ${scope.accountId}::uuid
333
+ and version.workspace_id = ${scope.workspaceId}::uuid
334
+ and version.artifact_id = ${artifactId}
335
+ and version.id = ${versionId}`
336
+ );
337
+ if (rows.length === 0) return null;
338
+ return versionFromRow(exactRow(rows, "Editable artifact version read"));
339
+ }
340
+ async function loadJob(tx, scope, artifactId, jobId, includeObjectReference) {
341
+ const rows = await rawRows(
342
+ tx,
343
+ sql`select
344
+ job.account_id, job.workspace_id, job.artifact_id, job.id, job.version_id,
345
+ job.input_snapshot_id, job.target_head_sequence, job.state_hash, job.format,
346
+ job.state, job.attempt_count, job.error_code, job.created_at, job.started_at,
347
+ job.completed_at, result.id as result_id, result.byte_size as result_byte_size,
348
+ result.content_hash as result_content_hash, result.mime_type as result_mime_type,
349
+ result.verified_at as result_verified_at, result.created_at as result_created_at,
350
+ ${includeObjectReference ? sql`blob.object_reference` : sql`null::text`} as object_reference
351
+ from editable_artifact_materialization_jobs job
352
+ left join editable_artifact_materialization_results result
353
+ on result.account_id = job.account_id and result.workspace_id = job.workspace_id
354
+ and result.artifact_id = job.artifact_id and result.job_id = job.id
355
+ left join editable_artifact_blob_refs blob
356
+ on blob.account_id = result.account_id and blob.workspace_id = result.workspace_id
357
+ and blob.artifact_id = result.artifact_id and blob.id = result.blob_ref_id
358
+ where job.account_id = ${scope.accountId}::uuid
359
+ and job.workspace_id = ${scope.workspaceId}::uuid
360
+ and job.artifact_id = ${artifactId}
361
+ and job.id = ${jobId}`
362
+ );
363
+ if (rows.length === 0) return null;
364
+ const row = exactRow(rows, "Editable artifact materialization read");
365
+ const job = jobFromRow(row);
366
+ const objectReference = nullableText(row.object_reference, "materialization object reference");
367
+ if (job.result === null !== (objectReference === null) && includeObjectReference) {
368
+ throw contractViolation("Materialization result object reference is inconsistent");
369
+ }
370
+ return Object.freeze({ job, objectReference });
371
+ }
372
+ function versionFromRow(row) {
373
+ const rowModality = modality(row.modality);
374
+ const causalFrontier = causalFrontierFromRow(row.causal_frontier);
375
+ const nativeRevision = nullableInteger(row.native_revision, "version native revision", 0);
376
+ if (rowModality === "spreadsheet" && (causalFrontier === null || nativeRevision !== null) || rowModality !== "spreadsheet" && (causalFrontier !== null || nativeRevision === null)) {
377
+ throw contractViolation("Version modality state is inconsistent");
378
+ }
379
+ if (row.pinned !== true) throw contractViolation("Public artifact version is not pinned");
380
+ return Object.freeze({
381
+ scope: Object.freeze({
382
+ accountId: uuid(row.account_id, "version account id"),
383
+ workspaceId: uuid(row.workspace_id, "version workspace id")
384
+ }),
385
+ artifactId: stableId(row.artifact_id, "version artifact id"),
386
+ id: stableId(row.id, "version id"),
387
+ modality: rowModality,
388
+ snapshotId: stableId(row.snapshot_id, "version snapshot id"),
389
+ headSequence: integer(row.head_sequence, "version head sequence", 0),
390
+ causalFrontier,
391
+ nativeRevision,
392
+ stateHash: hash(row.state_hash, "version state hash"),
393
+ name: boundedText(row.name, "version name", 256),
394
+ pinned: true,
395
+ createdBySubjectId: boundedText(row.created_by_subject_id, "version creator", 1024),
396
+ createdAt: timestamp(row.created_at, "version creation time")
397
+ });
398
+ }
399
+ function jobFromRow(row) {
400
+ const state = jobState(row.state);
401
+ const format = exportFormat(row.format);
402
+ const resultId = nullableStableId(row.result_id, "materialization result id");
403
+ let result = null;
404
+ if (resultId !== null) {
405
+ result = Object.freeze({
406
+ id: resultId,
407
+ byteSize: integer(row.result_byte_size, "materialization result byte size", 1),
408
+ contentHash: hash(row.result_content_hash, "materialization result hash"),
409
+ mimeType: mimeType(row.result_mime_type, format),
410
+ verifiedAt: timestamp(row.result_verified_at, "materialization verification time"),
411
+ createdAt: timestamp(row.result_created_at, "materialization result creation time")
412
+ });
413
+ } else if (row.result_byte_size !== null || row.result_content_hash !== null || row.result_mime_type !== null || row.result_verified_at !== null || row.result_created_at !== null) {
414
+ throw contractViolation("Materialization result columns are partial");
415
+ }
416
+ if (state === "succeeded" !== (result !== null)) {
417
+ throw contractViolation("Materialization state and result are inconsistent");
418
+ }
419
+ return Object.freeze({
420
+ scope: Object.freeze({
421
+ accountId: uuid(row.account_id, "job account id"),
422
+ workspaceId: uuid(row.workspace_id, "job workspace id")
423
+ }),
424
+ artifactId: stableId(row.artifact_id, "job artifact id"),
425
+ id: stableId(row.id, "job id"),
426
+ versionId: stableId(row.version_id, "job version id"),
427
+ inputSnapshotId: stableId(row.input_snapshot_id, "job snapshot id"),
428
+ targetHeadSequence: integer(row.target_head_sequence, "job target head", 0),
429
+ stateHash: hash(row.state_hash, "job state hash"),
430
+ format,
431
+ state,
432
+ attemptCount: integer(row.attempt_count, "job attempt count", 0),
433
+ errorCode: nullableText(row.error_code, "job error code"),
434
+ createdAt: timestamp(row.created_at, "job creation time"),
435
+ startedAt: nullableTimestamp(row.started_at, "job start time"),
436
+ completedAt: nullableTimestamp(row.completed_at, "job completion time"),
437
+ result
438
+ });
439
+ }
440
+ function assertSnapshotPinsArtifact(snapshot, artifact) {
441
+ if (snapshot.modality !== artifact.modality || snapshot.snapshotId !== artifact.currentSnapshotId || snapshot.coveredHeadSequence !== artifact.headSequence || snapshot.stateHash !== artifact.stateHash || snapshot.modality === "spreadsheet" && (snapshot.coveredCausalFrontier === null || snapshot.nativeRevision !== null) || snapshot.modality !== "spreadsheet" && (snapshot.coveredCausalFrontier !== null || snapshot.nativeRevision === null)) {
442
+ throw new EditableArtifactDurableExportPersistenceError(
443
+ "snapshot_conflict",
444
+ "Pinned version source is no longer the exact current verified snapshot"
445
+ );
446
+ }
447
+ }
448
+ function validatePinRequest(input) {
449
+ const context = validateContext(input);
450
+ const snapshot = validateSnapshot(input.snapshot);
451
+ const request = Object.freeze({
452
+ ...input,
453
+ ...context,
454
+ expectedAuthorizationRevision: integer(
455
+ input.expectedAuthorizationRevision,
456
+ "expected authorization revision",
457
+ 1
458
+ ),
459
+ authorityKey: boundedText(input.authorityKey, "authority key", 8192),
460
+ receiptId: stableId(input.receiptId, "receipt id"),
461
+ versionId: stableId(input.versionId, "version id"),
462
+ idempotencyKey: idempotencyKey(input.idempotencyKey),
463
+ requestHash: hash(input.requestHash, "request hash"),
464
+ name: boundedText(input.name, "version name", 256),
465
+ snapshot
466
+ });
467
+ validateAuthorityKey(request.actor, request.authorityKey);
468
+ return request;
469
+ }
470
+ function validateEnqueueRequest(input) {
471
+ const context = validateContext(input);
472
+ const request = Object.freeze({
473
+ ...input,
474
+ ...context,
475
+ expectedAuthorizationRevision: integer(
476
+ input.expectedAuthorizationRevision,
477
+ "expected authorization revision",
478
+ 1
479
+ ),
480
+ authorityKey: boundedText(input.authorityKey, "authority key", 8192),
481
+ receiptId: stableId(input.receiptId, "receipt id"),
482
+ jobId: stableId(input.jobId, "job id"),
483
+ idempotencyKey: idempotencyKey(input.idempotencyKey),
484
+ requestHash: hash(input.requestHash, "request hash"),
485
+ versionId: stableId(input.versionId, "version id"),
486
+ profile: validateProfile(input.profile)
487
+ });
488
+ validateAuthorityKey(request.actor, request.authorityKey);
489
+ return request;
490
+ }
491
+ function validateReadRequest(input, key) {
492
+ return Object.freeze({
493
+ ...input,
494
+ ...validateContext(input),
495
+ expectedAuthorizationRevision: integer(
496
+ input.expectedAuthorizationRevision,
497
+ "expected authorization revision",
498
+ 1
499
+ ),
500
+ [key]: stableId(input[key], key === "versionId" ? "version id" : "job id")
501
+ });
502
+ }
503
+ function validateContext(input) {
504
+ const scope = Object.freeze({
505
+ accountId: uuid(input.scope.accountId, "account id"),
506
+ workspaceId: uuid(input.scope.workspaceId, "workspace id")
507
+ });
508
+ const artifactId = stableId(input.artifactId, "artifact id");
509
+ const actor = validateActor(input.actor);
510
+ return Object.freeze({ scope, artifactId, actor });
511
+ }
512
+ function validateActor(actor) {
513
+ if (!plainRecord(actor)) throw new TypeError("Editable artifact export actor is invalid");
514
+ const replicaId = text(actor.replicaId, "actor replica id");
515
+ if (!/^[0-9a-f]{16}$/u.test(replicaId) || /^0+$/u.test(replicaId)) {
516
+ throw new TypeError("Editable artifact export actor replica id is invalid");
517
+ }
518
+ const subjectId = boundedText(actor.subjectId, "actor subject id", 1024);
519
+ if (actor.kind === "human") {
520
+ exactKeys(actor, ["kind", "subjectId", "replicaId"]);
521
+ return Object.freeze({ kind: "human", subjectId, replicaId });
522
+ }
523
+ if (actor.kind === "agent") {
524
+ exactKeys(actor, [
525
+ "kind",
526
+ "subjectId",
527
+ "replicaId",
528
+ "sessionId",
529
+ "turnId",
530
+ "attemptId",
531
+ "generation"
532
+ ]);
533
+ return Object.freeze({
534
+ kind: "agent",
535
+ subjectId,
536
+ replicaId,
537
+ sessionId: boundedText(actor.sessionId, "agent session id", 1024),
538
+ turnId: boundedText(actor.turnId, "agent turn id", 1024),
539
+ attemptId: boundedText(actor.attemptId, "agent attempt id", 1024),
540
+ generation: integer(actor.generation, "agent generation", 0)
541
+ });
542
+ }
543
+ if (actor.kind === "service") {
544
+ exactKeys(actor, ["kind", "subjectId", "replicaId", "service"]);
545
+ return Object.freeze({
546
+ kind: "service",
547
+ subjectId,
548
+ replicaId,
549
+ service: boundedText(actor.service, "service name", 1024)
550
+ });
551
+ }
552
+ throw new TypeError("Editable artifact export actor kind is invalid");
553
+ }
554
+ function validateSnapshot(snapshot) {
555
+ const snapshotModality = modality(snapshot.modality);
556
+ const coveredCausalFrontier = causalFrontierFromRow(snapshot.coveredCausalFrontier);
557
+ const nativeRevision = nullableInteger(snapshot.nativeRevision, "snapshot native revision", 0);
558
+ if (snapshotModality === "spreadsheet" && (coveredCausalFrontier === null || nativeRevision !== null) || snapshotModality !== "spreadsheet" && (coveredCausalFrontier !== null || nativeRevision === null)) {
559
+ throw new TypeError("Editable artifact export snapshot modality state is invalid");
560
+ }
561
+ return Object.freeze({
562
+ modality: snapshotModality,
563
+ snapshotId: stableId(snapshot.snapshotId, "snapshot id"),
564
+ coveredHeadSequence: integer(snapshot.coveredHeadSequence, "snapshot head", 0),
565
+ stateHash: hash(snapshot.stateHash, "snapshot state hash"),
566
+ coveredCausalFrontier,
567
+ nativeRevision
568
+ });
569
+ }
570
+ function validateProfile(profile) {
571
+ if (!plainRecord(profile)) throw new TypeError("Materialization profile is invalid");
572
+ const profileModality = modality(profile.modality);
573
+ const format = exportFormat(profile.format);
574
+ if (!formatMatchesModality(profileModality, format)) throw unsupportedFormat();
575
+ const normalizedOptions = boundedText(
576
+ profile.normalizedOptions,
577
+ "normalized materialization options",
578
+ 256 * 1024
579
+ );
580
+ let options;
581
+ try {
582
+ options = JSON.parse(normalizedOptions);
583
+ } catch {
584
+ throw new TypeError("Normalized materialization options are invalid JSON");
585
+ }
586
+ if (!plainRecord(options) || JSON.stringify(sortRecord(options)) !== normalizedOptions) {
587
+ throw new TypeError("Normalized materialization options are not canonical");
588
+ }
589
+ return Object.freeze({
590
+ modality: profileModality,
591
+ format,
592
+ codecId: boundedText(profile.codecId, "codec id", 128),
593
+ codecVersion: boundedText(profile.codecVersion, "codec version", 128),
594
+ kernelVersion: boundedText(profile.kernelVersion, "kernel version", 512),
595
+ fontRegistryHash: hash(profile.fontRegistryHash, "font registry hash"),
596
+ policyHash: hash(profile.policyHash, "policy hash"),
597
+ normalizedOptions
598
+ });
599
+ }
600
+ function formatMatchesModality(artifactModality, format) {
601
+ return artifactModality === "spreadsheet" && ["xlsx", "pdf", "png", "webp"].includes(format) || artifactModality === "presentation" && ["pptx", "pdf", "png", "webp"].includes(format) || artifactModality === "document" && ["docx", "pdf", "png", "webp"].includes(format);
602
+ }
603
+ function persistedActorKey(actor) {
604
+ switch (actor.kind) {
605
+ case "human":
606
+ return JSON.stringify([actor.kind, actor.subjectId]);
607
+ case "agent":
608
+ return JSON.stringify([
609
+ actor.kind,
610
+ actor.subjectId,
611
+ actor.sessionId,
612
+ actor.turnId,
613
+ actor.attemptId,
614
+ actor.generation
615
+ ]);
616
+ case "service":
617
+ return JSON.stringify([actor.kind, actor.subjectId, actor.service]);
618
+ }
619
+ }
620
+ function validateAuthorityKey(actor, authorityKey) {
621
+ if (authorityKey !== persistedActorKey(actor)) {
622
+ throw new TypeError("Editable artifact export authority key does not match its actor");
623
+ }
624
+ }
625
+ function exactRow(rows, label) {
626
+ if (rows.length !== 1 || !rows[0])
627
+ throw contractViolation(`${label} returned an invalid row count`);
628
+ return rows[0];
629
+ }
630
+ function stableId(value, label) {
631
+ const parsed = text(value, label);
632
+ if (!/^[0-9a-f]{32}$/u.test(parsed) || /^0+$/u.test(parsed)) {
633
+ throw new TypeError(`${label} is invalid`);
634
+ }
635
+ return parsed;
636
+ }
637
+ function nullableStableId(value, label) {
638
+ return value === null ? null : stableId(value, label);
639
+ }
640
+ function uuid(value, label) {
641
+ const parsed = text(value, label);
642
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(parsed)) {
643
+ throw new TypeError(`${label} is invalid`);
644
+ }
645
+ return parsed;
646
+ }
647
+ function hash(value, label) {
648
+ const parsed = text(value, label);
649
+ if (!/^sha256:[0-9a-f]{64}$/u.test(parsed)) throw new TypeError(`${label} is invalid`);
650
+ return parsed;
651
+ }
652
+ function idempotencyKey(value) {
653
+ const parsed = text(value, "idempotency key");
654
+ if (!/^[A-Za-z0-9._:-]{1,200}$/u.test(parsed)) throw new TypeError("Idempotency key is invalid");
655
+ return parsed;
656
+ }
657
+ function text(value, label) {
658
+ if (typeof value !== "string") throw new TypeError(`${label} must be text`);
659
+ return value;
660
+ }
661
+ function boundedText(value, label, maximumBytes) {
662
+ const parsed = text(value, label);
663
+ const bytes = new TextEncoder().encode(parsed).byteLength;
664
+ if (bytes < 1 || bytes > maximumBytes || parsed.trim() !== parsed || /[\u0000-\u001f\u007f]/u.test(parsed)) {
665
+ throw new TypeError(`${label} is invalid`);
666
+ }
667
+ return parsed;
668
+ }
669
+ function nullableText(value, label) {
670
+ return value === null ? null : boundedText(value, label, 2048);
671
+ }
672
+ function integer(value, label, minimum) {
673
+ const parsed = typeof value === "bigint" ? Number(value) : typeof value === "string" && /^\d+$/u.test(value) ? Number(value) : value;
674
+ if (!Number.isSafeInteger(parsed) || parsed < minimum) {
675
+ throw new TypeError(`${label} is invalid`);
676
+ }
677
+ return parsed;
678
+ }
679
+ function nullableInteger(value, label, minimum) {
680
+ return value === null ? null : integer(value, label, minimum);
681
+ }
682
+ function timestamp(value, label) {
683
+ const parsed = value instanceof Date ? value.toISOString() : text(value, label);
684
+ const milliseconds = Date.parse(parsed);
685
+ if (!Number.isFinite(milliseconds)) {
686
+ throw new TypeError(`${label} is invalid`);
687
+ }
688
+ return new Date(milliseconds).toISOString();
689
+ }
690
+ function nullableTimestamp(value, label) {
691
+ return value === null ? null : timestamp(value, label);
692
+ }
693
+ function modality(value) {
694
+ if (value !== "spreadsheet" && value !== "document" && value !== "presentation") {
695
+ throw new TypeError("Artifact modality is invalid");
696
+ }
697
+ return value;
698
+ }
699
+ function exportFormat(value) {
700
+ if (!["xlsx", "pptx", "docx", "pdf", "png", "webp"].includes(String(value))) {
701
+ throw new TypeError("Materialization format is invalid");
702
+ }
703
+ return value;
704
+ }
705
+ function jobState(value) {
706
+ if (!["pending", "running", "succeeded", "failed"].includes(String(value))) {
707
+ throw contractViolation("Materialization state is invalid");
708
+ }
709
+ return value;
710
+ }
711
+ function mimeType(value, format) {
712
+ const expected = {
713
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
714
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
715
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
716
+ pdf: "application/pdf",
717
+ png: "image/png",
718
+ webp: "image/webp"
719
+ }[format];
720
+ if (value !== expected) throw contractViolation("Materialization MIME type is inconsistent");
721
+ return expected;
722
+ }
723
+ function causalFrontierFromRow(value) {
724
+ if (value === null) return null;
725
+ if (!Array.isArray(value) || value.length > 1024) {
726
+ throw new TypeError("Causal frontier is invalid");
727
+ }
728
+ let previous = "";
729
+ const result = value.map((entry) => {
730
+ if (!plainRecord(entry)) throw new TypeError("Causal frontier entry is invalid");
731
+ const replicaId = text(entry.replicaId, "causal replica id");
732
+ if (!/^[0-9a-f]{16}$/u.test(replicaId) || /^0+$/u.test(replicaId) || replicaId <= previous) {
733
+ throw new TypeError("Causal frontier is not canonical");
734
+ }
735
+ previous = replicaId;
736
+ return Object.freeze({
737
+ replicaId,
738
+ counter: integer(entry.counter, "causal counter", 1)
739
+ });
740
+ });
741
+ return Object.freeze(result);
742
+ }
743
+ function sha256(value) {
744
+ return `sha256:${createHash("sha256").update(value, "utf8").digest("hex")}`;
745
+ }
746
+ function sortRecord(value) {
747
+ return Object.fromEntries(
748
+ Object.entries(value).sort(([left], [right]) => left < right ? -1 : 1)
749
+ );
750
+ }
751
+ function plainRecord(value) {
752
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
753
+ const prototype = Object.getPrototypeOf(value);
754
+ return prototype === Object.prototype || prototype === null;
755
+ }
756
+ function exactKeys(value, keys) {
757
+ const actual = Object.keys(value).sort();
758
+ const expected = [...keys].sort();
759
+ if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
760
+ throw new TypeError("Editable artifact export actor contains unknown properties");
761
+ }
762
+ }
763
+ function notFound() {
764
+ return new EditableArtifactDurableExportPersistenceError(
765
+ "not_found",
766
+ "Editable artifact export source was not found"
767
+ );
768
+ }
769
+ function idempotencyConflict() {
770
+ return new EditableArtifactDurableExportPersistenceError(
771
+ "idempotency_conflict",
772
+ "Editable artifact export idempotency key was reused with another request"
773
+ );
774
+ }
775
+ function unsupportedFormat() {
776
+ return new EditableArtifactDurableExportPersistenceError(
777
+ "unsupported_format",
778
+ "Editable artifact export format is incompatible"
779
+ );
780
+ }
781
+ function contractViolation(message) {
782
+ return new EditableArtifactDurableExportPersistenceError("database_contract_violation", message);
783
+ }
784
+ export {
785
+ EditableArtifactDurableExportPersistenceError,
786
+ PostgresEditableArtifactDurableExportStore
787
+ };
788
+ //# sourceMappingURL=editable-artifact-durable-export.js.map