gencow 0.1.299 → 0.2.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 (149) hide show
  1. package/bin/gencow.mjs +0 -6
  2. package/core/package.json +1 -1
  3. package/docs/packaging.md +14 -4
  4. package/lib/cli-artifact-guard.mjs +53 -3
  5. package/lib/cli-dev-runtime.mjs +1 -0
  6. package/lib/cli-project-runtime.mjs +26 -14
  7. package/lib/codegen-command.mjs +16 -0
  8. package/lib/coding-guardrails.mjs +2 -0
  9. package/lib/dashboard-artifact.mjs +65 -0
  10. package/lib/dashboard-assets.mjs +20 -0
  11. package/lib/db-command.mjs +121 -80
  12. package/lib/db-migration-command-steps.mjs +19 -16
  13. package/lib/db-push-command.mjs +1 -1
  14. package/lib/deploy-codegen-preflight.mjs +1 -0
  15. package/lib/dev-cloud-command.mjs +1 -1
  16. package/lib/dev-local-command.mjs +19 -56
  17. package/lib/document-local-converter.mjs +11 -0
  18. package/lib/local-dashboard-plan.mjs +60 -0
  19. package/lib/local-database-commands.mjs +127 -0
  20. package/lib/local-development-migrations.mjs +157 -0
  21. package/lib/local-drizzle-database.config.mjs +10 -0
  22. package/lib/local-runtime-features.mjs +12 -0
  23. package/lib/rag-selection.mjs +7 -0
  24. package/lib/runtime-local-worker.mjs +116 -0
  25. package/lib/runtime-mode.mjs +3 -0
  26. package/lib/standalone-codegen-adapter.mjs +91 -0
  27. package/lib/ts-codegen-import-extension.mjs +228 -19
  28. package/package.json +16 -9
  29. package/runtime/config.mjs +218 -2
  30. package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
  31. package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
  32. package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
  33. package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
  34. package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
  35. package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
  36. package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
  37. package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
  38. package/runtime/engine/chunk-5575APCJ.mjs +215 -0
  39. package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
  40. package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
  41. package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
  42. package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
  43. package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
  44. package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
  45. package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
  46. package/runtime/engine/chunk-6W653LXI.mjs +13 -0
  47. package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
  48. package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
  49. package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
  50. package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
  51. package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
  52. package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
  53. package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
  54. package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
  55. package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
  56. package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
  57. package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
  58. package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
  59. package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
  60. package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
  61. package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
  62. package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
  63. package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
  64. package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
  65. package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
  66. package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
  67. package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
  68. package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
  69. package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
  70. package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
  71. package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
  72. package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
  73. package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
  74. package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
  75. package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
  76. package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
  77. package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
  78. package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
  79. package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
  80. package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
  81. package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
  82. package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
  83. package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
  84. package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
  85. package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
  86. package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
  87. package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
  88. package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
  89. package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
  90. package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
  91. package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
  92. package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
  93. package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
  94. package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
  95. package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
  96. package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
  97. package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
  98. package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
  99. package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
  100. package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
  101. package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
  102. package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
  103. package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
  104. package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
  105. package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
  106. package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
  107. package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
  108. package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
  109. package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
  110. package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
  111. package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
  112. package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
  113. package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
  114. package/runtime/engine/chunk-YRHM272W.mjs +528 -0
  115. package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
  116. package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
  117. package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
  118. package/runtime/engine/composition.mjs +325 -0
  119. package/runtime/engine/document-local.mjs +504 -0
  120. package/runtime/engine/graph.json +4134 -0
  121. package/runtime/engine/index.mjs +265 -0
  122. package/runtime/engine/local-postgres-support.mjs +69 -0
  123. package/runtime/engine/local.mjs +3275 -0
  124. package/runtime/engine/pglite-directory-lock.mjs +8 -0
  125. package/runtime/engine/rag.mjs +11 -0
  126. package/runtime/engine/search.mjs +18 -0
  127. package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
  128. package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
  129. package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
  130. package/runtime/framework-migrations/manifest.json +56 -0
  131. package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
  132. package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
  133. package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
  134. package/runtime/runtime-metadata.json +27 -0
  135. package/runtime/tooling.mjs +10399 -8951
  136. package/scripts/bundle-runtime-config.mjs +23 -0
  137. package/scripts/bundle-runtime.mjs +100 -0
  138. package/scripts/bundle-runtime.test.mjs +33 -0
  139. package/scripts/bundle-shared.mjs +3 -0
  140. package/scripts/copy-dashboard.mjs +16 -0
  141. package/scripts/pre-publish-check.mjs +23 -11
  142. package/templateFeature/sso/sso-auth-callback.tsx +37 -5
  143. package/templateFeature/tools/manifest.json +2 -1
  144. package/templateFeature/tools/tools.ts +3 -3
  145. package/runtime/server.mjs +0 -14389
  146. package/scripts/bundle-server.mjs +0 -223
  147. package/server/config.js +0 -1
  148. package/server/index.js +0 -1
  149. package/server/package.json +0 -6
@@ -0,0 +1,23 @@
1
+ import {
2
+ RuntimeDiagnosticError
3
+ } from "./chunk-AEBW7XZJ.mjs";
4
+
5
+ // ../runtime/dist/adapters/storage/file-size-limit.js
6
+ function assertRuntimeFileSize(size, limit) {
7
+ if (Number.isSafeInteger(size) && size >= 0 && size <= limit)
8
+ return;
9
+ throw new RuntimeDiagnosticError({
10
+ code: "RUNTIME_STORAGE_FILE_TOO_LARGE",
11
+ stage: "request",
12
+ capability: "storage",
13
+ servingStarted: "unchanged",
14
+ dataImpact: "none",
15
+ retryable: false,
16
+ retryPrecondition: `Submit a file of at most ${limit} bytes only if the operation is still intended.`,
17
+ nextAction: `This file was not stored. Reduce its size to at most ${limit} bytes; CLI projects may configure localFeatures.storage.maxFileSizeBytes; direct Runtime hosts configure the storage selection on their startup input. Restart after changing the selected limit. Hosted limits require trusted host configuration.`
18
+ });
19
+ }
20
+
21
+ export {
22
+ assertRuntimeFileSize
23
+ };
@@ -0,0 +1,53 @@
1
+ import {
2
+ validateRuntimeRagSchema
3
+ } from "./chunk-J6SDRCG4.mjs";
4
+ import {
5
+ ragManagedTableNames
6
+ } from "./chunk-N6GCLOUX.mjs";
7
+ import {
8
+ ragRows,
9
+ ragSchemaStatements
10
+ } from "./chunk-RW65MPVY.mjs";
11
+ import {
12
+ ragSchemaError
13
+ } from "./chunk-P5IIXAIE.mjs";
14
+ import "./chunk-IFMOTJNU.mjs";
15
+ import {
16
+ runtimeDiagnostic
17
+ } from "./chunk-AEBW7XZJ.mjs";
18
+
19
+ // ../runtime/dist/adapters/rag/pgvector/schema-initializer.js
20
+ import { drizzle } from "drizzle-orm/pglite";
21
+ import { sql } from "drizzle-orm";
22
+ async function initializePgliteRagSchema(client, operationalRoles) {
23
+ try {
24
+ await drizzle({ client }).transaction(async (transaction) => {
25
+ for (const name of ["vector", "pg_trgm"]) {
26
+ const available = ragRows(await transaction.execute(sql`SELECT EXISTS (SELECT 1 FROM pg_available_extensions WHERE name = ${name}) AS present`));
27
+ if (!available[0]?.present)
28
+ throw ragSchemaError(name === "vector" ? "RAG_VECTOR_UNAVAILABLE" : "RAG_TRIGRAM_UNAVAILABLE");
29
+ await transaction.execute(sql.raw(`CREATE EXTENSION IF NOT EXISTS ${name} WITH SCHEMA public`));
30
+ }
31
+ if (!await validateRuntimeRagSchema(transaction, {
32
+ allowCompatibleMissing: true,
33
+ setupOwner: true,
34
+ operationalRoles
35
+ })) {
36
+ for (const statement of ragSchemaStatements)
37
+ await transaction.execute(sql.raw(statement));
38
+ await validateRuntimeRagSchema(transaction, { setupOwner: true, operationalRoles });
39
+ }
40
+ const roles = operationalRoles.map((role) => `"${role.replaceAll('"', '""')}"`).join(", ");
41
+ if (!roles)
42
+ throw ragSchemaError("RAG_SCHEMA_AUTHORITY_UNAVAILABLE");
43
+ await transaction.execute(sql.raw(`GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE ${ragManagedTableNames.map((name) => `public.${name}`).join(", ")} TO ${roles}`));
44
+ });
45
+ } catch (error) {
46
+ if (runtimeDiagnostic(error)?.code.startsWith("RAG_"))
47
+ throw error;
48
+ throw ragSchemaError("RAG_SCHEMA_INCOMPATIBLE", "unknown");
49
+ }
50
+ }
51
+ export {
52
+ initializePgliteRagSchema
53
+ };
@@ -0,0 +1,340 @@
1
+ // ../runtime/dist/workflow/schema-contract.js
2
+ var workflowSchemaIndexes = [
3
+ {
4
+ name: "idx__gencow_workflows_status",
5
+ table: "_gencow_workflows",
6
+ keys: ["status", "started_at"],
7
+ descending: ["started_at"]
8
+ },
9
+ {
10
+ name: "idx__gencow_workflow_steps_lookup",
11
+ table: "_gencow_workflow_steps",
12
+ keys: ["workflow_id", "step_name"]
13
+ },
14
+ {
15
+ name: "idx__gencow_workflow_events_lookup",
16
+ table: "_gencow_workflow_events",
17
+ keys: ["workflow_id", "event_name", "received_at"]
18
+ },
19
+ {
20
+ name: "idx__gencow_job_admission_buckets_updated",
21
+ table: "_gencow_job_admission_buckets",
22
+ keys: ["updated_at"]
23
+ },
24
+ {
25
+ name: "idx__gencow_workflow_runs_v2_claim",
26
+ table: "_gencow_workflow_runs_v2",
27
+ keys: ["status", "runnable_at", "priority", "created_at"],
28
+ descending: ["priority"],
29
+ predicate: "completed_at is null"
30
+ },
31
+ {
32
+ name: "idx__gencow_workflow_runs_v2_lease",
33
+ table: "_gencow_workflow_runs_v2",
34
+ keys: ["lease_expires_at"],
35
+ predicate: "status = 'running' and completed_at is null"
36
+ },
37
+ {
38
+ name: "idx__gencow_workflow_steps_v2_lookup",
39
+ table: "_gencow_workflow_steps_v2",
40
+ keys: ["run_id", "step_key"]
41
+ },
42
+ {
43
+ name: "idx__gencow_workflow_timers_v2_due",
44
+ table: "_gencow_workflow_timers_v2",
45
+ keys: ["status", "fire_at"]
46
+ },
47
+ {
48
+ name: "idx__gencow_workflow_signals_v2_wait",
49
+ table: "_gencow_workflow_signals_v2",
50
+ keys: ["run_id", "event_name", "received_at"],
51
+ predicate: "consumed_at is null"
52
+ },
53
+ {
54
+ name: "idx__gencow_workflow_outbox_v2_due",
55
+ table: "_gencow_workflow_outbox_v2",
56
+ keys: ["status", "available_at"]
57
+ },
58
+ {
59
+ name: "idx__gencow_workflow_events_v2_timeline",
60
+ table: "_gencow_workflow_events_v2",
61
+ keys: ["run_id", "created_at", "id"]
62
+ },
63
+ {
64
+ name: "idx__gencow_workflow_steps_v2_scope_seq",
65
+ table: "_gencow_workflow_steps_v2",
66
+ keys: ["run_id", "command_scope", "command_seq"],
67
+ predicate: "command_seq IS NOT NULL",
68
+ unique: true
69
+ },
70
+ {
71
+ name: "idx__gencow_workflow_outbox_v2_run",
72
+ table: "_gencow_workflow_outbox_v2",
73
+ keys: ["run_id"]
74
+ },
75
+ {
76
+ name: "idx__gencow_workflow_outbox_v2_due_pending",
77
+ table: "_gencow_workflow_outbox_v2",
78
+ keys: ["available_at"],
79
+ predicate: "status IN ('pending', 'sending')"
80
+ },
81
+ {
82
+ name: "idx__gencow_workflow_timers_v2_due_pending",
83
+ table: "_gencow_workflow_timers_v2",
84
+ keys: ["fire_at"],
85
+ predicate: "status = 'pending'"
86
+ },
87
+ {
88
+ name: "idx__gencow_workflow_runs_v2_active_deadline",
89
+ table: "_gencow_workflow_runs_v2",
90
+ keys: ["active_deadline_at"],
91
+ predicate: "completed_at IS NULL AND active_deadline_at IS NOT NULL"
92
+ },
93
+ {
94
+ name: "idx__gencow_workflow_runs_v2_lifecycle_deadline",
95
+ table: "_gencow_workflow_runs_v2",
96
+ keys: ["lifecycle_deadline_at"],
97
+ predicate: "completed_at IS NULL AND lifecycle_deadline_at IS NOT NULL"
98
+ },
99
+ {
100
+ name: "idx__gencow_workflow_runs_v2_cancel",
101
+ table: "_gencow_workflow_runs_v2",
102
+ keys: ["cancel_requested_at"],
103
+ predicate: "completed_at IS NULL AND cancel_requested_at IS NOT NULL"
104
+ },
105
+ {
106
+ name: "idx__gencow_workflow_runs_v2_admission",
107
+ table: "_gencow_workflow_runs_v2",
108
+ keys: ["workflow_name", "status"],
109
+ predicate: "completed_at IS NULL"
110
+ }
111
+ ];
112
+ var workflowSchemaTables = [
113
+ {
114
+ name: "_gencow_workflows",
115
+ columns: [
116
+ ["id", "text", false, null, false],
117
+ ["name", "text", false, null, false],
118
+ ["args", "jsonb", false, "'{}'::jsonb", false],
119
+ ["status", "text", false, "'pending'::text", false],
120
+ ["current_step", "text", true, null, false],
121
+ ["result", "jsonb", true, null, false],
122
+ ["error", "text", true, null, false],
123
+ ["error_code", "text", true, null, true],
124
+ ["realtime_token", "text", false, "''::text", true],
125
+ ["retry_count", "int4", false, "0", false],
126
+ ["max_retries", "int4", false, "3", false],
127
+ ["max_duration_ms", "int8", false, "1800000", false],
128
+ ["first_claimed_at", "timestamptz", true, null, true],
129
+ ["handler_started_at", "timestamptz", true, null, true],
130
+ ["last_resume_attempt_at", "timestamptz", true, null, true],
131
+ ["runnable_at", "timestamptz", true, null, true],
132
+ ["started_at", "timestamptz", false, "now()", false],
133
+ ["updated_at", "timestamptz", false, "now()", false],
134
+ ["completed_at", "timestamptz", true, null, false],
135
+ ["user_id", "text", true, null, false]
136
+ ],
137
+ primary: ["id"],
138
+ unique: [],
139
+ foreign: []
140
+ },
141
+ {
142
+ name: "_gencow_workflow_steps",
143
+ columns: [
144
+ ["id", "int4", false, "sequence", false],
145
+ ["workflow_id", "text", false, null, false],
146
+ ["step_name", "text", false, null, false],
147
+ ["status", "text", false, "'pending'::text", false],
148
+ ["output", "jsonb", true, null, false],
149
+ ["error", "text", true, null, false],
150
+ ["started_at", "timestamptz", true, null, false],
151
+ ["updated_at", "timestamptz", false, "now()", false],
152
+ ["completed_at", "timestamptz", true, null, false]
153
+ ],
154
+ primary: ["id"],
155
+ unique: [["workflow_id", "step_name"]],
156
+ foreign: [["workflow_id", "_gencow_workflows"]]
157
+ },
158
+ {
159
+ name: "_gencow_workflow_events",
160
+ columns: [
161
+ ["id", "text", false, "gen_random_uuid()::text", false],
162
+ ["workflow_id", "text", false, null, false],
163
+ ["event_name", "text", false, null, false],
164
+ ["payload", "jsonb", true, null, false],
165
+ ["received_at", "timestamptz", false, "now()", true],
166
+ ["consumed_at", "timestamptz", true, null, true]
167
+ ],
168
+ primary: ["id"],
169
+ unique: [],
170
+ foreign: [["workflow_id", "_gencow_workflows"]]
171
+ },
172
+ {
173
+ name: "_gencow_job_admission_buckets",
174
+ columns: [
175
+ ["scope", "text", false, null, false],
176
+ ["bucket_start", "timestamptz", false, null, false],
177
+ ["count", "int4", false, "0", false],
178
+ ["updated_at", "timestamptz", false, "now()", false]
179
+ ],
180
+ primary: ["scope", "bucket_start"],
181
+ unique: [],
182
+ foreign: []
183
+ },
184
+ {
185
+ name: "_gencow_workflow_runs_v2",
186
+ columns: [
187
+ ["id", "text", false, null, false],
188
+ ["workflow_name", "text", false, null, false],
189
+ ["workflow_version", "text", true, null, false],
190
+ ["status", "text", false, "'queued'::text", false],
191
+ ["args_json", "jsonb", false, "'{}'::jsonb", false],
192
+ ["user_id", "text", true, null, true],
193
+ ["capacity_defer_count", "int4", false, "0", true],
194
+ ["capacity_deferred_at", "timestamptz", true, null, true],
195
+ ["command_protocol", "int2", false, "1", true],
196
+ ["definition_missing_since", "timestamptz", true, null, true],
197
+ ["result_json", "jsonb", true, null, false],
198
+ ["error_json", "jsonb", true, null, false],
199
+ ["error_code", "text", true, null, false],
200
+ ["current_step_key", "text", true, null, false],
201
+ ["priority", "int4", false, "0", false],
202
+ ["runnable_at", "timestamptz", false, "now()", false],
203
+ ["lease_owner", "text", true, null, false],
204
+ ["lease_epoch", "int4", false, "0", false],
205
+ ["lease_expires_at", "timestamptz", true, null, false],
206
+ ["heartbeat_at", "timestamptz", true, null, false],
207
+ ["attempt_count", "int4", false, "0", false],
208
+ ["max_attempts", "int4", false, "3", false],
209
+ ["retry_count", "int4", false, "0", true],
210
+ ["max_retries", "int4", false, "3", true],
211
+ ["max_active_duration_ms", "int8", false, "1800000", true],
212
+ ["active_started_at", "timestamptz", true, null, false],
213
+ ["active_deadline_at", "timestamptz", true, null, false],
214
+ ["lifecycle_deadline_at", "timestamptz", true, null, false],
215
+ ["cancel_requested_at", "timestamptz", true, null, false],
216
+ ["idempotency_key", "text", true, null, false],
217
+ ["created_at", "timestamptz", false, "now()", false],
218
+ ["updated_at", "timestamptz", false, "now()", false],
219
+ ["completed_at", "timestamptz", true, null, false]
220
+ ],
221
+ primary: ["id"],
222
+ unique: [["idempotency_key"]],
223
+ foreign: []
224
+ },
225
+ {
226
+ name: "_gencow_workflow_steps_v2",
227
+ columns: [
228
+ ["id", "int8", false, "sequence", false],
229
+ ["run_id", "text", false, null, false],
230
+ ["step_key", "text", false, null, false],
231
+ ["step_index", "int4", false, "0", false],
232
+ ["status", "text", false, "'pending'::text", false],
233
+ ["input_hash", "text", true, null, false],
234
+ ["output_json", "jsonb", true, null, false],
235
+ ["error_json", "jsonb", true, null, false],
236
+ ["error_code", "text", true, null, false],
237
+ ["attempt_count", "int4", false, "0", false],
238
+ ["max_attempts", "int4", false, "3", false],
239
+ ["runnable_at", "timestamptz", false, "now()", false],
240
+ ["lease_owner", "text", true, null, false],
241
+ ["lease_epoch", "int4", false, "0", false],
242
+ ["lease_expires_at", "timestamptz", true, null, false],
243
+ ["started_at", "timestamptz", true, null, false],
244
+ ["heartbeat_at", "timestamptz", true, null, false],
245
+ ["completed_at", "timestamptz", true, null, false],
246
+ ["updated_at", "timestamptz", false, "now()", false],
247
+ ["command_kind", "text", true, null, true],
248
+ ["command_name", "text", true, null, true],
249
+ ["command_scope", "text", false, "''::text", true],
250
+ ["command_seq", "int4", true, null, true],
251
+ ["output_codec", "text", true, null, true],
252
+ ["failure_final", "bool", false, "false", true],
253
+ ["signal_id", "text", true, null, true]
254
+ ],
255
+ primary: ["id"],
256
+ unique: [["run_id", "step_key"]],
257
+ foreign: [["run_id", "_gencow_workflow_runs_v2"]]
258
+ },
259
+ {
260
+ name: "_gencow_workflow_timers_v2",
261
+ columns: [
262
+ ["id", "text", false, null, false],
263
+ ["run_id", "text", false, null, false],
264
+ ["kind", "text", false, null, false],
265
+ ["fire_at", "timestamptz", false, null, false],
266
+ ["status", "text", false, "'pending'::text", false],
267
+ ["dedupe_key", "text", true, null, false],
268
+ ["created_at", "timestamptz", false, "now()", false],
269
+ ["updated_at", "timestamptz", false, "now()", false],
270
+ ["command_key", "text", true, null, true]
271
+ ],
272
+ primary: ["id"],
273
+ unique: [["run_id", "dedupe_key"]],
274
+ foreign: [["run_id", "_gencow_workflow_runs_v2"]]
275
+ },
276
+ {
277
+ name: "_gencow_workflow_signals_v2",
278
+ columns: [
279
+ ["id", "text", false, null, false],
280
+ ["run_id", "text", false, null, false],
281
+ ["event_name", "text", false, null, false],
282
+ ["payload_json", "jsonb", true, null, false],
283
+ ["idempotency_key", "text", true, null, false],
284
+ ["received_at", "timestamptz", false, "now()", false],
285
+ ["consumed_at", "timestamptz", true, null, false],
286
+ ["consumed_by_command", "text", true, null, true]
287
+ ],
288
+ primary: ["id"],
289
+ unique: [["run_id", "event_name", "idempotency_key"]],
290
+ foreign: [["run_id", "_gencow_workflow_runs_v2"]]
291
+ },
292
+ {
293
+ name: "_gencow_workflow_outbox_v2",
294
+ columns: [
295
+ ["id", "text", false, null, false],
296
+ ["run_id", "text", false, null, false],
297
+ ["kind", "text", false, null, false],
298
+ ["available_at", "timestamptz", false, "now()", false],
299
+ ["status", "text", false, "'pending'::text", false],
300
+ ["attempt_count", "int4", false, "0", false],
301
+ ["created_at", "timestamptz", false, "now()", false],
302
+ ["updated_at", "timestamptz", false, "now()", false]
303
+ ],
304
+ primary: ["id"],
305
+ unique: [],
306
+ foreign: [["run_id", "_gencow_workflow_runs_v2"]]
307
+ },
308
+ {
309
+ name: "_gencow_workflow_capacity_locks_v2",
310
+ columns: [
311
+ ["scope", "text", false, null, false],
312
+ ["updated_at", "timestamptz", false, "now()", false]
313
+ ],
314
+ primary: ["scope"],
315
+ unique: [],
316
+ foreign: []
317
+ },
318
+ {
319
+ name: "_gencow_workflow_events_v2",
320
+ columns: [
321
+ ["id", "int8", false, "sequence", false],
322
+ ["run_id", "text", false, null, false],
323
+ ["event_type", "text", false, null, false],
324
+ ["event_json", "jsonb", true, null, false],
325
+ ["created_at", "timestamptz", false, "now()", false]
326
+ ],
327
+ primary: ["id"],
328
+ unique: [],
329
+ foreign: [["run_id", "_gencow_workflow_runs_v2"]]
330
+ }
331
+ ];
332
+ function workflowSchemaDefaultMatches(table, column, expected, actual) {
333
+ return expected === actual || table === "_gencow_workflow_events" && column === "id" && expected === "gen_random_uuid()::text" && actual === "(gen_random_uuid())::text";
334
+ }
335
+
336
+ export {
337
+ workflowSchemaIndexes,
338
+ workflowSchemaTables,
339
+ workflowSchemaDefaultMatches
340
+ };
@@ -0,0 +1,242 @@
1
+ import {
2
+ runtimeDatabaseSetupError
3
+ } from "./chunk-SVJCOUI3.mjs";
4
+
5
+ // ../runtime/dist/framework-schema/drizzle-projection.js
6
+ import { SQL } from "drizzle-orm";
7
+ import { getTableConfig, PgDialect } from "drizzle-orm/pg-core";
8
+ var dialect = new PgDialect();
9
+ var fail = () => {
10
+ throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_COMPONENT_INVALID");
11
+ };
12
+ function freeze(value, seen = /* @__PURE__ */ new WeakSet()) {
13
+ if (value && typeof value === "object" && !seen.has(value)) {
14
+ seen.add(value);
15
+ for (const child of Object.values(value))
16
+ freeze(child, seen);
17
+ Object.freeze(value);
18
+ }
19
+ return value;
20
+ }
21
+ function pgName(name) {
22
+ const bytes = Buffer.from(name, "utf8");
23
+ return bytes.length <= 63 ? name : bytes.subarray(0, 63).toString("utf8");
24
+ }
25
+ function render(sql) {
26
+ const query = dialect.sqlToQuery(sql);
27
+ if (query.params.length)
28
+ return fail();
29
+ return query.sql;
30
+ }
31
+ function normalizeFrameworkSqlExpression(source, relation) {
32
+ const parts = [];
33
+ let position = 0;
34
+ while (position < source.length) {
35
+ const char = source[position];
36
+ if (char === "'" || char === '"') {
37
+ const quote = char;
38
+ const start2 = position++;
39
+ while (position < source.length) {
40
+ if (source[position] === quote) {
41
+ if (source[position + 1] === quote) {
42
+ position += 2;
43
+ continue;
44
+ }
45
+ position++;
46
+ break;
47
+ }
48
+ position++;
49
+ }
50
+ const token = source.slice(start2, position);
51
+ if (quote === "'") {
52
+ parts.push({ kind: "literal", value: token });
53
+ continue;
54
+ }
55
+ const identifier = token.slice(1, -1).replaceAll('""', '"');
56
+ const canonicalIdentifier = /^[a-z_][a-z0-9_$]*$/u.test(identifier) ? identifier : `"${identifier.replaceAll('"', '""')}"`;
57
+ const previous2 = parts.at(-1);
58
+ if (previous2?.kind === "sql")
59
+ previous2.value += canonicalIdentifier;
60
+ else
61
+ parts.push({ kind: "sql", value: canonicalIdentifier });
62
+ continue;
63
+ }
64
+ const start = position;
65
+ position++;
66
+ while (position < source.length && source[position] !== "'" && source[position] !== '"')
67
+ position++;
68
+ const sql = source.slice(start, position).replace(/[\t\r\n ]+/gu, " ").toLowerCase();
69
+ const previous = parts.at(-1);
70
+ if (previous?.kind === "sql")
71
+ previous.value += sql;
72
+ else
73
+ parts.push({ kind: "sql", value: sql });
74
+ }
75
+ const escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
76
+ const relationPrefixes = relation ? [
77
+ new RegExp(`(^|[^a-z0-9_$.])${escape(relation.schema.toLowerCase())}\\.${escape(relation.table.toLowerCase())}\\.`, "gu"),
78
+ new RegExp(`(^|[^a-z0-9_$.])${escape(relation.table.toLowerCase())}\\.`, "gu")
79
+ ] : [];
80
+ return parts.map((part) => part.kind === "sql" ? relationPrefixes.reduce((value, prefix) => value.replace(prefix, "$1"), part.value) : part.value).join("").trim();
81
+ }
82
+ function defaultValue(column) {
83
+ const type = column.getSQLType();
84
+ if (type === "serial" || type === "bigserial")
85
+ return "sequence";
86
+ const value = column.default;
87
+ if (value === void 0)
88
+ return null;
89
+ if (value instanceof SQL)
90
+ return normalizeFrameworkSqlExpression(render(value));
91
+ if (typeof value === "boolean" || typeof value === "number")
92
+ return String(value);
93
+ if (typeof value === "string") {
94
+ if (!/^(?:public\.)?text$/u.test(type))
95
+ return fail();
96
+ return `'${value.replaceAll("'", "''")}'::text`;
97
+ }
98
+ if (type !== "jsonb" || value === null || typeof value !== "object")
99
+ return fail();
100
+ const json = JSON.stringify(value);
101
+ return `'${json.replaceAll("'", "''")}'::jsonb`;
102
+ }
103
+ function columnType(column) {
104
+ const type = column.getSQLType();
105
+ return type === "serial" ? "integer" : type === "bigserial" ? "bigint" : type;
106
+ }
107
+ function referentialAction(action) {
108
+ switch (action ?? "no action") {
109
+ case "no action":
110
+ return "a";
111
+ case "restrict":
112
+ return "r";
113
+ case "cascade":
114
+ return "c";
115
+ case "set null":
116
+ return "n";
117
+ case "set default":
118
+ return "d";
119
+ default:
120
+ return fail();
121
+ }
122
+ }
123
+ function columnNames(columns) {
124
+ if (!columns.length || columns.some((column) => !column || typeof column.name !== "string"))
125
+ return fail();
126
+ return columns.map((column) => column.name);
127
+ }
128
+ function explicitExpressionOperatorClass(value) {
129
+ const match = /^(.*)\s+([a-z_][a-z0-9_]*)\.([a-z_][a-z0-9_]*_ops)$/iu.exec(value);
130
+ if (match)
131
+ return { expression: match[1], operatorClass: { schema: match[2], name: match[3] } };
132
+ const unqualified = /^(.*)\s+(gin_trgm_ops)$/iu.exec(value);
133
+ if (unqualified)
134
+ return fail();
135
+ return { expression: value };
136
+ }
137
+ function projectDrizzleTables(tables) {
138
+ if (!Array.isArray(tables) || !tables.length)
139
+ return fail();
140
+ const seen = /* @__PURE__ */ new Set();
141
+ const projections = tables.map((table) => {
142
+ let config;
143
+ try {
144
+ config = getTableConfig(table);
145
+ } catch {
146
+ return fail();
147
+ }
148
+ const schema = config.schema ?? "public";
149
+ if (!/^[a-z_][a-z0-9_]*$/u.test(config.name) || !/^[a-z_][a-z0-9_]*$/u.test(schema))
150
+ return fail();
151
+ const relationKey = `${schema}.${config.name}`;
152
+ if (seen.has(relationKey))
153
+ return fail();
154
+ seen.add(relationKey);
155
+ const columns = config.columns.map((column) => ({
156
+ name: column.name,
157
+ type: columnType(column),
158
+ nullable: !column.notNull,
159
+ defaultValue: defaultValue(column),
160
+ identity: column.generatedIdentity?.type ?? "",
161
+ generated: column.generated?.type ?? "",
162
+ ownedSequence: column.getSQLType() === "serial" || column.getSQLType() === "bigserial"
163
+ }));
164
+ const primary = [
165
+ ...config.columns.filter((column) => column.primary).map((column) => [column.name]),
166
+ ...config.primaryKeys.map((constraint) => columnNames(constraint.columns))
167
+ ];
168
+ if (primary.length > 1)
169
+ return fail();
170
+ const constraints = [];
171
+ if (primary[0])
172
+ constraints.push({
173
+ name: pgName(config.primaryKeys[0]?.getName() ?? `${config.name}_pkey`),
174
+ kind: "primary",
175
+ columns: [...primary[0]]
176
+ });
177
+ constraints.push(...config.uniqueConstraints.map((constraint) => ({
178
+ name: pgName(constraint.getName() ?? fail()),
179
+ kind: "unique",
180
+ columns: [...columnNames(constraint.columns)],
181
+ nullsNotDistinct: constraint.nullsNotDistinct
182
+ })), ...config.foreignKeys.map((foreign) => {
183
+ const reference = foreign.reference();
184
+ return {
185
+ name: pgName(foreign.getName()),
186
+ kind: "foreign",
187
+ columns: [...columnNames(reference.columns)],
188
+ target: {
189
+ schema: getTableConfig(reference.foreignTable).schema ?? "public",
190
+ table: getTableConfig(reference.foreignTable).name,
191
+ columns: [...columnNames(reference.foreignColumns)],
192
+ deleteAction: referentialAction(foreign.onDelete),
193
+ updateAction: referentialAction(foreign.onUpdate)
194
+ }
195
+ };
196
+ }), ...config.checks.map((check) => ({
197
+ name: pgName(check.name),
198
+ kind: "check",
199
+ columns: [],
200
+ expression: normalizeFrameworkSqlExpression(render(check.value), { schema, table: config.name })
201
+ })));
202
+ const indexes = config.indexes.map((index) => ({
203
+ name: pgName(index.config.name ?? fail()),
204
+ table: config.name,
205
+ method: index.config.method ?? "btree",
206
+ unique: index.config.unique,
207
+ predicate: index.config.where ? normalizeFrameworkSqlExpression(render(index.config.where), { schema, table: config.name }) : null,
208
+ keys: index.config.columns.map((entry) => {
209
+ const column = entry;
210
+ const expression = column?.name ? column.name : column instanceof SQL ? render(column) : void 0;
211
+ if (!expression)
212
+ return fail();
213
+ const explicit = column?.name ? void 0 : explicitExpressionOperatorClass(expression);
214
+ const operatorClass = column?.indexConfig?.opClass ? { name: column.indexConfig.opClass } : explicit?.operatorClass;
215
+ return {
216
+ expression: normalizeFrameworkSqlExpression(explicit ? explicit.expression : expression, {
217
+ schema,
218
+ table: config.name
219
+ }),
220
+ order: column?.indexConfig?.order === "desc" ? "desc" : "asc",
221
+ nulls: column?.indexConfig?.nulls === "first" ? "first" : "last",
222
+ ...operatorClass ? { operatorClass } : {},
223
+ defaultOperatorClass: operatorClass === void 0
224
+ };
225
+ })
226
+ }));
227
+ return freeze({
228
+ schema,
229
+ name: config.name,
230
+ rowSecurity: config.enableRLS,
231
+ columns,
232
+ constraints,
233
+ indexes
234
+ });
235
+ });
236
+ return freeze(projections);
237
+ }
238
+
239
+ export {
240
+ normalizeFrameworkSqlExpression,
241
+ projectDrizzleTables
242
+ };