@voltro/cli 0.9.0 → 0.11.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 (59) hide show
  1. package/CHANGELOG.md +394 -7
  2. package/dist/apiBuild-BCv3bekE.js +2 -0
  3. package/dist/{apiBuild-eInHm_bJ.js → apiBuild-BUbgGz73.js} +8 -8
  4. package/dist/bin.js +2 -2
  5. package/dist/{commands-Cxs97AFp.js → commands-C1qBfIBI.js} +1977 -1599
  6. package/dist/dev-DKASElZP.js +2 -0
  7. package/dist/{dev-63Ehpw2p.js → dev-ITlO-epO.js} +1600 -1512
  8. package/dist/index.js +1 -1
  9. package/dist/{inspectMetrics-DVCKKSPk.js → inspectMetrics-BeMjgt8x.js} +1018 -827
  10. package/dist/inspectState.d.ts +6 -2
  11. package/dist/{serveCommand-Cq7BhtpB.js → serveCommand-mpsE3vLY.js} +407 -420
  12. package/dist/serveEntry.js +3 -3
  13. package/dist/{start-CYe-7ueh.js → start-C_M4fGS2.js} +331 -309
  14. package/dist/startEntry.js +2 -2
  15. package/package.json +17 -17
  16. package/templates/agent-docs/cli.md +45 -17
  17. package/templates/agent-docs/data.md +145 -1
  18. package/templates/agent-docs/database/seedsdialects.md +40 -4
  19. package/templates/agent-docs/routing.md +52 -13
  20. package/templates/agent-docs/scheduling.md +32 -0
  21. package/templates/apps/api-ai/package.json +7 -7
  22. package/templates/apps/api-auth/package.json +8 -8
  23. package/templates/apps/api-backend/package.json +7 -7
  24. package/templates/apps/api-backend-deactivation/package.json +7 -7
  25. package/templates/apps/api-backend-mail/package.json +8 -8
  26. package/templates/apps/api-backend-mariadb/package.json +9 -9
  27. package/templates/apps/api-backend-storage/package.json +8 -8
  28. package/templates/apps/api-data-advanced/package.json +8 -8
  29. package/templates/apps/api-durable/package.json +8 -8
  30. package/templates/apps/api-durable/schedules/nightlyReport.cron.tsx +5 -0
  31. package/templates/apps/api-durable/subscribers/orderChanges.subscribe.ts +8 -2
  32. package/templates/apps/api-feature-flags/package.json +9 -9
  33. package/templates/apps/api-governance/package.json +8 -8
  34. package/templates/apps/api-kv/package.json +8 -8
  35. package/templates/apps/api-moderation/package.json +8 -8
  36. package/templates/apps/api-observability/package.json +8 -8
  37. package/templates/apps/api-ratelimit/package.json +8 -8
  38. package/templates/apps/api-rbac/package.json +8 -8
  39. package/templates/apps/api-rest/package.json +7 -7
  40. package/templates/apps/api-saas/package.json +11 -11
  41. package/templates/apps/api-search/package.json +8 -8
  42. package/templates/apps/api-versioning/package.json +8 -8
  43. package/templates/apps/api-webhooks/package.json +8 -8
  44. package/templates/apps/changelog/package.json +6 -6
  45. package/templates/apps/edge-functions/package.json +2 -2
  46. package/templates/apps/frontend-admin/package.json +8 -8
  47. package/templates/apps/frontend-app/package.json +8 -8
  48. package/templates/apps/frontend-blank/package.json +7 -7
  49. package/templates/apps/frontend-contact/package.json +7 -7
  50. package/templates/apps/frontend-dashboard/package.json +7 -7
  51. package/templates/apps/frontend-docs/package.json +7 -7
  52. package/templates/apps/frontend-i18n/package.json +6 -6
  53. package/templates/apps/frontend-landing/package.json +7 -7
  54. package/templates/apps/frontend-spa/package.json +7 -7
  55. package/templates/apps/frontend-ssr/package.json +7 -7
  56. package/templates/apps/frontend-ssr-api/package.json +8 -8
  57. package/templates/apps/frontend-static-blog/package.json +6 -6
  58. package/dist/apiBuild-Ba4njm9m.js +0 -2
  59. package/dist/dev-CXsR8Zgo.js +0 -2
@@ -1,30 +1,30 @@
1
- import { St as e, t } from "./inspectMetrics-DVCKKSPk.js";
2
- import { A as n, C as r, D as i, E as a, F as o, G as s, H as c, I as l, J as u, K as d, M as ee, N as f, O as p, P as m, Q as te, S as h, T as g, U as ne, W as re, X as ie, Y as _, Z as ae, _ as oe, at as v, b as se, ct as y, d as b, et as x, f as ce, g as le, h as ue, i as S, it as de, j as C, k as w, m as fe, n as pe, nt as T, o as E, q as me, rt as he, s as ge, t as D, v as _e, w as ve, x as ye, y as be } from "./dev-63Ehpw2p.js";
3
- import { a as xe, r as Se } from "./startupRunner-DhlX9nqd.js";
4
- import { a as O, t as Ce } from "./apiBuild-eInHm_bJ.js";
5
- import { join as we } from "node:path";
6
- import { pathToFileURL as Te } from "node:url";
7
- import { Cause as Ee, Effect as k, Layer as A, ManagedRuntime as De } from "effect";
1
+ import { t as e, yt as t } from "./inspectMetrics-BeMjgt8x.js";
2
+ import { $ as n, A as r, C as i, D as a, E as o, F as s, G as c, H as l, I as u, J as d, K as f, M as p, N as ee, O as m, P as h, Q as g, S as te, T as ne, U as re, W as ie, X as ae, Y as _, Z as oe, _ as se, at as v, b as ce, d as le, f as y, g as b, h as x, i as S, it as ue, j as C, k as de, lt as w, m as fe, n as pe, o as me, ot as T, q as E, rt as he, s as ge, t as _e, tt as ve, v as ye, w as be, x as xe, y as D } from "./dev-ITlO-epO.js";
3
+ import { a as Se, r as Ce } from "./startupRunner-DhlX9nqd.js";
4
+ import { a as O, t as we } from "./apiBuild-BUbgGz73.js";
5
+ import { join as Te } from "node:path";
6
+ import { pathToFileURL as Ee } from "node:url";
7
+ import { Cause as De, Effect as k, Layer as A, ManagedRuntime as Oe } from "effect";
8
8
  import { createLogger as j } from "@voltro/logger";
9
9
  import { existsSync as M } from "node:fs";
10
- import { AggregateRegistry as Oe, Dispatcher as ke, apiKeyManagementRoutes as N, applySoftDeleteScope as P, applyTenantScope as Ae, attachAnalyticsMirror as je, awaitServerListening as Me, bindMutation as F, bindStream as Ne, bindSubscription as I, buildTracingLayer as Pe, cancelWakeup as Fe, compileCron as Ie, dataStoreApiKeyStore as Le, dataStoreIdempotencyStore as Re, frameworkApiKeyStrategy as ze, installPolicyGuardResolver as Be, loadResourceTuples as Ve, makeActionRunner as He, makeAdvisoryLockCoordinator as Ue, makeApiKeyService as We, makeAsyncKv as Ge, makeCoordinatedScheduler as L, makeEffectStoreLayer as R, makeLazyWorkflowFacade as Ke, makeMutationRunner as qe, makeQueryDescriptorProducer as Je, makeQueryReauthorizer as Ye, makeSchemaRegistry as Xe, makeWorkflowFacade as Ze, makeWorkflowFacadeWithCallerContext as Qe, makeWorkflowLayers as $e, noopKv as et, recordSubscriptionDelivery as tt, registerWakeup as nt, resolveSecretsBackend as rt, runProvidedEffect as z, setSecretsBackend as it, setTupleSource as at, singleCoordinator as ot, startRpcServer as B, startScheduler as st, workflowToRpc as ct, wrapStoreWithMixinBehaviour as lt } from "@voltro/runtime";
11
- import { createHash as V, timingSafeEqual as H } from "node:crypto";
12
- import { assertProductionSessionSecret as ut } from "@voltro/protocol/session";
13
- import { RpcGroup as dt } from "@effect/rpc";
14
- import { SqlClient as ft } from "@effect/sql";
15
- import { and as pt, ensureTableRegistered as mt, eq as U, or as ht } from "@voltro/database";
16
- import { fromNodeReadable as gt, getObjectStream as _t, putObjectStream as vt, resolveStorageProvider as W, toNodeReadable as yt } from "@voltro/plugin-storage";
17
- import { AuthMiddleware as bt, ConnectionInfoMiddleware as xt, actionToRpc as G, anonymousSubject as St, mutationToRpc as Ct, queryToRpc as K, streamToRpc as wt, workflowCancelDescriptor as Tt, workflowDomainEventsQueryDescriptor as q, workflowEventDeliveriesQueryDescriptor as Et, workflowResumeDescriptor as Dt, workflowRunEventsQueryDescriptor as J, workflowRunQueryDescriptor as Y, workflowRunStepsQueryDescriptor as Ot, workflowRunsQueryDescriptor as X, workflowSignalDescriptor as Z, workflowUpdateDescriptor as kt } from "@voltro/protocol";
18
- import { declaredSnapshot as At, describeOutcome as jt, runPlannedMigrations as Mt } from "@voltro/database/sql";
19
- import { getAuthSessionStrategy as Nt } from "@voltro/plugin-auth";
20
- import { collectPublicApiRoutes as Pt, restRoutesToHttpRoutes as Ft } from "@voltro/protocol/rest";
21
- import { buildDeliverWebhookExecute as It, buildWebhooksService as Lt, defaultIncomingPath as Rt, deliverWebhookWorkflow as zt, mountIncomingWebhook as Bt } from "@voltro/plugin-webhooks";
22
- import { packBundle as Vt, runExport as Ht, runImport as Ut, storageBlobSink as Wt, storageRefsBlobSource as Gt, unpackBundle as Kt, unpackBundleToDir as qt } from "@voltro/data-transfer";
10
+ import { AggregateRegistry as ke, Dispatcher as N, apiKeyManagementRoutes as P, applySoftDeleteScope as Ae, applyTenantScope as je, attachAnalyticsMirror as Me, awaitServerListening as Ne, bindMutation as F, bindStream as Pe, bindSubscription as I, buildTracingLayer as Fe, cancelWakeup as Ie, compileCron as Le, dataStoreApiKeyStore as Re, dataStoreIdempotencyStore as ze, frameworkApiKeyStrategy as Be, installPolicyGuardResolver as Ve, loadResourceTuples as He, makeActionRunner as L, makeAdvisoryLockCoordinator as Ue, makeApiKeyService as We, makeAsyncKv as Ge, makeCoordinatedScheduler as R, makeEffectStoreLayer as Ke, makeLazyWorkflowFacade as qe, makeMutationRunner as Je, makeQueryDescriptorProducer as Ye, makeQueryReauthorizer as Xe, makeSchemaRegistry as Ze, makeWorkflowFacade as Qe, makeWorkflowFacadeWithCallerContext as $e, makeWorkflowLayers as et, noopKv as tt, recordSubscriptionDelivery as nt, registerWakeup as z, resolveSecretsBackend as rt, runProvidedEffect as it, setSecretsBackend as at, setSystemStoreHandle as ot, setTupleSource as st, singleCoordinator as ct, startRpcServer as lt, startScheduler as ut, workflowToRpc as B } from "@voltro/runtime";
11
+ import { createHash as V, timingSafeEqual as dt } from "node:crypto";
12
+ import { assertProductionSessionSecret as ft } from "@voltro/protocol/session";
13
+ import { RpcGroup as pt } from "@effect/rpc";
14
+ import { SqlClient as mt } from "@effect/sql";
15
+ import { and as ht, ensureTableRegistered as gt, eq as H, or as _t } from "@voltro/database";
16
+ import { fromNodeReadable as vt, getObjectStream as yt, putObjectStream as U, resolveStorageProvider as W, toNodeReadable as bt } from "@voltro/plugin-storage";
17
+ import { AuthMiddleware as xt, ConnectionInfoMiddleware as G, actionToRpc as K, anonymousSubject as St, mutationToRpc as Ct, queryToRpc as q, streamToRpc as wt, workflowCancelDescriptor as Tt, workflowDomainEventsQueryDescriptor as Et, workflowEventDeliveriesQueryDescriptor as J, workflowResumeDescriptor as Dt, workflowRunEventsQueryDescriptor as Y, workflowRunQueryDescriptor as Ot, workflowRunStepsQueryDescriptor as X, workflowRunsQueryDescriptor as Z, workflowSignalDescriptor as kt, workflowUpdateDescriptor as At } from "@voltro/protocol";
18
+ import { declaredSnapshot as jt, describeOutcome as Mt, runPlannedMigrations as Nt } from "@voltro/database/sql";
19
+ import { getAuthSessionStrategy as Pt } from "@voltro/plugin-auth";
20
+ import { collectPublicApiRoutes as Ft, restRoutesToHttpRoutes as It } from "@voltro/protocol/rest";
21
+ import { buildDeliverWebhookExecute as Lt, buildWebhooksService as Rt, defaultIncomingPath as zt, deliverWebhookWorkflow as Bt, mountIncomingWebhook as Vt } from "@voltro/plugin-webhooks";
22
+ import { packBundle as Ht, runExport as Ut, runImport as Wt, storageBlobSink as Gt, storageRefsBlobSource as Kt, unpackBundle as qt, unpackBundleToDir as Jt } from "@voltro/data-transfer";
23
23
  //#region src/bootTiming.ts
24
- var Jt = () => {
24
+ var Yt = () => {
25
25
  let e = process.env.VOLTRO_BOOT_TIMING;
26
26
  return e === "1" || e === "true";
27
- }, Yt = () => {
27
+ }, Xt = () => {
28
28
  let e = [{
29
29
  name: "modules",
30
30
  at: performance.now()
@@ -38,7 +38,7 @@ var Jt = () => {
38
38
  },
39
39
  finish: (t) => {
40
40
  let n = Math.round(e[e.length - 1].at);
41
- if (!Jt()) {
41
+ if (!Yt()) {
42
42
  t.info(`serve: ready in ${n}ms`);
43
43
  return;
44
44
  }
@@ -50,25 +50,25 @@ var Jt = () => {
50
50
  });
51
51
  }
52
52
  };
53
- }, Xt = "/_voltro/admin/import", Zt = "/_voltro/admin/export", Q = (e, t) => ({
53
+ }, Zt = "/_voltro/admin/import", Qt = "/_voltro/admin/export", Q = (e, t) => ({
54
54
  status: e,
55
55
  contentType: "application/json; charset=utf-8",
56
56
  body: JSON.stringify(t)
57
- }), Qt = (e) => {
57
+ }), $t = (e) => {
58
58
  let t = e.authorization ?? e.Authorization, n = t ? /^Bearer\s+(.+)$/i.exec(t) : null;
59
59
  return n ? n[1] : null;
60
- }, $t = (e, t) => H(V("sha256").update(e).digest(), V("sha256").update(t).digest()), en = (e, t) => {
60
+ }, en = (e, t) => dt(V("sha256").update(e).digest(), V("sha256").update(t).digest()), tn = (e, t) => {
61
61
  if (e.method.toUpperCase() !== "POST") return Q(405, { error: "method not allowed" });
62
62
  if (!t || t.length < 16) return Q(503, { error: "data transfer misconfigured (no/weak secret)" });
63
- let n = Qt(e.headers);
64
- return !n || !$t(n, t) ? Q(401, { error: "unauthorized" }) : null;
65
- }, tn = j({ scope: "voltro:admin-import" }), nn = "VBUNDLE2", rn = async function* (e) {
63
+ let n = $t(e.headers);
64
+ return !n || !en(n, t) ? Q(401, { error: "unauthorized" }) : null;
65
+ }, nn = j({ scope: "voltro:admin-import" }), rn = "VBUNDLE2", an = async function* (e) {
66
66
  yield e;
67
- }, an = (e) => async (t) => {
68
- let n = en(t, e.secret);
67
+ }, on = (e) => async (t) => {
68
+ let n = tn(t, e.secret);
69
69
  if (n) return n;
70
- let r = t.headers["x-import-mode"], i = t.headers["x-import-on-conflict"], a = t.headers["x-import-atomic"] === "1" || t.headers["x-import-atomic"] === "true", o = t.headers["x-import-force"] === "1" || t.headers["x-import-force"] === "true", s = t.rawBody.byteLength >= 8 && Buffer.from(t.rawBody.subarray(0, 8)).toString("latin1") === nn, c, l;
71
- if (s) c = rn(t.rawBody), l = "upload";
70
+ let r = t.headers["x-import-mode"], i = t.headers["x-import-on-conflict"], a = t.headers["x-import-atomic"] === "1" || t.headers["x-import-atomic"] === "true", o = t.headers["x-import-force"] === "1" || t.headers["x-import-force"] === "true", s = t.rawBody.byteLength >= 8 && Buffer.from(t.rawBody.subarray(0, 8)).toString("latin1") === rn, c, l;
71
+ if (s) c = an(t.rawBody), l = "upload";
72
72
  else {
73
73
  let n;
74
74
  try {
@@ -80,28 +80,28 @@ var Jt = () => {
80
80
  if (!e.openArchive) return Q(501, { error: "storage transport not configured on this instance" });
81
81
  c = e.openArchive(n.bundleKey), l = "storage";
82
82
  }
83
- let u = await import("node:os"), d = await import("node:fs/promises"), ee = await import("node:path"), f = await d.mkdtemp(ee.join(u.tmpdir(), "voltro-admin-import-"));
83
+ let u = await import("node:os"), d = await import("node:fs/promises"), f = await import("node:path"), p = await d.mkdtemp(f.join(u.tmpdir(), "voltro-admin-import-"));
84
84
  try {
85
- e.assetSink ? await Kt(c, {
86
- dir: f,
85
+ e.assetSink ? await qt(c, {
86
+ dir: p,
87
87
  blobs: e.assetSink
88
- }) : await qt(c, f);
89
- let t = await k.runPromiseExit(Ut({
88
+ }) : await Jt(c, p);
89
+ let t = await k.runPromiseExit(Wt({
90
90
  store: e.store,
91
- bundleDir: f,
91
+ bundleDir: p,
92
92
  ...r ? { mode: r } : {},
93
93
  ...i ? { onConflict: i } : {},
94
94
  ...a ? { atomic: a } : {},
95
95
  ...e.snapshot ? { targetSnapshot: e.snapshot } : {},
96
96
  force: o,
97
- onWarn: (e) => tn.warn("admin.import", { message: e }),
97
+ onWarn: (e) => nn.warn("admin.import", { message: e }),
98
98
  ...e.assetSink ? { assetsAlreadyRestored: !0 } : {}
99
99
  }));
100
100
  if (t._tag === "Failure") {
101
101
  let e = t.cause._tag === "Fail" ? t.cause.error : void 0;
102
102
  if (e && e._tag === "SchemaDriftError") {
103
103
  let t = e;
104
- return tn.warn("admin.import refused (schema drift)", {
104
+ return nn.warn("admin.import refused (schema drift)", {
105
105
  transport: l,
106
106
  bundle: t.bundleFingerprint.slice(0, 16),
107
107
  target: t.targetFingerprint.slice(0, 16)
@@ -116,7 +116,7 @@ var Jt = () => {
116
116
  throw Error(String(e?.message ?? e ?? "import failed"));
117
117
  }
118
118
  let n = t.value, s = n.tables.reduce((e, t) => e + t.rowCount, 0);
119
- return tn.info("admin.import", {
119
+ return nn.info("admin.import", {
120
120
  transport: l,
121
121
  tables: n.tables.length,
122
122
  rows: s,
@@ -128,7 +128,7 @@ var Jt = () => {
128
128
  transport: l
129
129
  });
130
130
  } catch (e) {
131
- return tn.warn("admin.import failed", {
131
+ return nn.warn("admin.import failed", {
132
132
  transport: l,
133
133
  error: e?.message ?? String(e)
134
134
  }), Q(500, {
@@ -136,23 +136,23 @@ var Jt = () => {
136
136
  message: e?.message ?? String(e)
137
137
  });
138
138
  } finally {
139
- await d.rm(f, {
139
+ await d.rm(p, {
140
140
  recursive: !0,
141
141
  force: !0
142
142
  });
143
143
  }
144
- }, on = j({ scope: "voltro:admin-export" }), sn = async (e) => {
144
+ }, sn = j({ scope: "voltro:admin-export" }), cn = async (e) => {
145
145
  let t = [];
146
146
  for await (let n of e) t.push(Buffer.from(n));
147
147
  return new Uint8Array(Buffer.concat(t));
148
- }, cn = (e) => typeof e.tenant == "string" && e.tenant ? {
148
+ }, ln = (e) => typeof e.tenant == "string" && e.tenant ? {
149
149
  kind: "tenant",
150
150
  tenantId: e.tenant
151
151
  } : Array.isArray(e.tables) && e.tables.length ? {
152
152
  kind: "tables",
153
153
  tables: e.tables.filter((e) => typeof e == "string")
154
- } : { kind: "all" }, ln = (e) => async (t) => {
155
- let n = en(t, e.secret);
154
+ } : { kind: "all" }, un = (e) => async (t) => {
155
+ let n = tn(t, e.secret);
156
156
  if (n) return n;
157
157
  let r;
158
158
  try {
@@ -172,13 +172,13 @@ var Jt = () => {
172
172
  });
173
173
  }
174
174
  }
175
- let a = r.consistency === "snapshot" ? "snapshot" : i.consistency ?? "live", o = (typeof r.compression == "string" ? r.compression : void 0) ?? i.compression, s = i.scope ?? cn(r), c = typeof r.bundleKey == "string" && r.bundleKey.length > 0, l = r.assets === !0 && e.assetSource ? { blobs: e.assetSource } : {}, u = await import("node:os"), d = await import("node:fs/promises"), ee = await import("node:path"), f = await d.mkdtemp(ee.join(u.tmpdir(), "voltro-admin-export-"));
175
+ let a = r.consistency === "snapshot" ? "snapshot" : i.consistency ?? "live", o = (typeof r.compression == "string" ? r.compression : void 0) ?? i.compression, s = i.scope ?? ln(r), c = typeof r.bundleKey == "string" && r.bundleKey.length > 0, l = r.assets === !0 && e.assetSource ? { blobs: e.assetSource } : {}, u = await import("node:os"), d = await import("node:fs/promises"), f = await import("node:path"), p = await d.mkdtemp(f.join(u.tmpdir(), "voltro-admin-export-"));
176
176
  try {
177
- let t = await k.runPromise(Ht({
177
+ let t = await k.runPromise(Ut({
178
178
  store: e.store,
179
179
  snapshot: e.snapshot,
180
180
  dialect: e.dialect,
181
- outDir: f,
181
+ outDir: p,
182
182
  ...i.subset ? { subset: i.subset } : {
183
183
  scope: s,
184
184
  ...e.tenantTables && e.tenantTables.length > 0 ? { tenantTables: e.tenantTables } : {}
@@ -190,10 +190,10 @@ var Jt = () => {
190
190
  if (c) {
191
191
  if (!e.putArchive) return Q(501, { error: "storage transport not configured on this instance" });
192
192
  let i = r.bundleKey;
193
- return await e.putArchive(i, () => Vt({
194
- dir: f,
193
+ return await e.putArchive(i, () => Ht({
194
+ dir: p,
195
195
  ...l
196
- })), on.info("admin.export", {
196
+ })), sn.info("admin.export", {
197
197
  transport: "storage",
198
198
  tables: t.tables.length,
199
199
  rows: n,
@@ -207,11 +207,11 @@ var Jt = () => {
207
207
  transport: "storage"
208
208
  });
209
209
  }
210
- let d = await sn(Vt({
211
- dir: f,
210
+ let d = await cn(Ht({
211
+ dir: p,
212
212
  ...l
213
213
  }));
214
- return on.info("admin.export", {
214
+ return sn.info("admin.export", {
215
215
  transport: "download",
216
216
  tables: t.tables.length,
217
217
  rows: n,
@@ -228,17 +228,17 @@ var Jt = () => {
228
228
  }
229
229
  };
230
230
  } catch (e) {
231
- return on.warn("admin.export failed", { error: e?.message ?? String(e) }), Q(500, {
231
+ return sn.warn("admin.export failed", { error: e?.message ?? String(e) }), Q(500, {
232
232
  error: "export failed",
233
233
  message: e?.message ?? String(e)
234
234
  });
235
235
  } finally {
236
- await d.rm(f, {
236
+ await d.rm(p, {
237
237
  recursive: !0,
238
238
  force: !0
239
239
  });
240
240
  }
241
- }, un = async (e) => {
241
+ }, dn = async (e) => {
242
242
  let { resolve: t } = await import("node:path"), { existsSync: n } = await import("node:fs"), r = [
243
243
  e,
244
244
  `${e}.profile.ts`,
@@ -249,7 +249,7 @@ var Jt = () => {
249
249
  let a = await import(i), o = a.default ?? a.profile;
250
250
  if (!o) throw Error(`data profile '${i}' has no default export`);
251
251
  return o;
252
- }, dn = {
252
+ }, fn = {
253
253
  get: async () => void 0,
254
254
  set: async () => {},
255
255
  setWithTags: async () => {},
@@ -258,17 +258,21 @@ var Jt = () => {
258
258
  clear: async () => {},
259
259
  invalidateTag: async () => 0,
260
260
  wrap: async (e, t, n) => n()
261
- }, fn = async (e) => {
262
- let t = new ke({
261
+ }, pn = async (e) => {
262
+ ot({
263
+ dataStore: e.store,
264
+ schemaRegistry: e.schemaRegistry
265
+ });
266
+ let t = new N({
263
267
  store: e.store,
264
268
  ...e.snapshotCache ? { cache: e.snapshotCache } : {},
265
- recordDelivery: (e) => tt({
269
+ recordDelivery: (e) => nt({
266
270
  label: e.label,
267
271
  kind: e.kind,
268
272
  durationMs: e.durationMs,
269
273
  rowCount: e.rowCount
270
274
  })
271
- }), n = e.cache ?? dn, i = e.kv ?? et, a, s, c, l = /* @__PURE__ */ new Map(), u = () => `wfctx_${globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`}`, f = async (t, n, r) => {
275
+ }), n = e.cache ?? fn, r = e.kv ?? tt, a, o, c, l = /* @__PURE__ */ new Map(), u = () => `wfctx_${globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`}`, d = async (t, n, r) => {
272
276
  let i = {
273
277
  ...r,
274
278
  source: r.source ?? `workflow:${t}`
@@ -278,7 +282,7 @@ var Jt = () => {
278
282
  let r = await e.store.query({
279
283
  table: "_voltro_workflow_start_contexts",
280
284
  order: [],
281
- predicate: U("executionId", n),
285
+ predicate: H("executionId", n),
282
286
  projection: ["id"],
283
287
  skip: void 0,
284
288
  take: 1
@@ -299,14 +303,14 @@ var Jt = () => {
299
303
  } catch (e) {
300
304
  process.stderr.write(`[workflow] failed to persist start context for ${t}/${n}: ${e?.message ?? String(e)}\n`);
301
305
  }
302
- }, te = async (t, n) => {
306
+ }, ee = async (t, n) => {
303
307
  let r = l.get(n);
304
308
  if (r !== void 0) return r;
305
309
  try {
306
310
  let t = (await e.store.query({
307
311
  table: "_voltro_workflow_start_contexts",
308
312
  order: [],
309
- predicate: U("executionId", n),
313
+ predicate: H("executionId", n),
310
314
  projection: void 0,
311
315
  skip: void 0,
312
316
  take: 1
@@ -324,35 +328,29 @@ var Jt = () => {
324
328
  process.stderr.write(`[workflow] failed to load start context for ${n}: ${e?.message ?? String(e)}\n`);
325
329
  return;
326
330
  }
327
- }, h = (e.discovered.workflows?.length ?? 0) > 0 ? Ke(() => a) : void 0, g = (e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.eventTriggers?.length ?? 0) > 0, ne = g || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster", re = e.tenantIsolation === "namespace", ae = (e.log ?? j({ scope: "voltro:serve" })).child("webhooks"), oe, v = e.discovered.webhooks;
331
+ }, g = (e.discovered.workflows?.length ?? 0) > 0 ? qe(() => a) : void 0, te = (e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.eventTriggers?.length ?? 0) > 0, ne = te || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster", re = e.tenantIsolation === "namespace", ie = (e.log ?? j({ scope: "voltro:serve" })).child("webhooks"), se, v = e.discovered.webhooks;
328
332
  if (v && v.outgoing.length > 0 && e.workflowEngineLayer !== void 0) {
329
- let t = e.workflowEngineLayer, r = {
330
- store: lt(e.store, {
331
- subject: St(null),
332
- schemaRegistry: e.schemaRegistry
333
- }),
334
- request: {
335
- subject: St(null),
336
- traceId: "webhooks:trigger"
337
- },
333
+ let t = e.workflowEngineLayer, i = oe({
334
+ store: e.store,
335
+ schemaRegistry: e.schemaRegistry,
338
336
  cache: n,
339
- kv: i
340
- }, a = v.outgoing.map((e) => e.descriptor);
341
- oe = Lt(r, async (e) => {
342
- let n = zt.execute(e).pipe(k.provide(zt.toLayer(It(r, { events: a })).pipe(A.provideMerge(t))));
337
+ kv: r
338
+ }), a = v.outgoing.map((e) => e.descriptor);
339
+ se = Rt(i, async (e) => {
340
+ let n = Bt.execute(e).pipe(k.provide(Bt.toLayer(Lt(i, { events: a })).pipe(A.provideMerge(t))));
343
341
  k.runPromise(n).catch((t) => {
344
- ae.error("deliverWebhook workflow crashed", {
342
+ ie.error("deliverWebhook workflow crashed", {
345
343
  deliveryId: e.deliveryId,
346
344
  targetId: e.targetId
347
345
  }, t);
348
346
  });
349
347
  }, { events: a });
350
348
  }
351
- let se = /* @__PURE__ */ new Map();
349
+ let ce = /* @__PURE__ */ new Map();
352
350
  if (v) for (let e of v.incoming) {
353
- let t = e.descriptor.path ?? Rt(e.descriptor.id), n = `VOLTRO_WEBHOOK_SECRET_${e.descriptor.id.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`, r = Bt(e.descriptor, {
351
+ let t = e.descriptor.path ?? zt(e.descriptor.id), n = `VOLTRO_WEBHOOK_SECRET_${e.descriptor.id.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`, r = Vt(e.descriptor, {
354
352
  resolveSecret: async () => process.env[n] ?? null,
355
- resolveWorkflows: () => h === void 0 ? void 0 : Qe(h, {
353
+ resolveWorkflows: () => g === void 0 ? void 0 : $e(g, {
356
354
  traceId: `incoming:${e.descriptor.id}`,
357
355
  source: `incoming:${e.descriptor.id}`
358
356
  }),
@@ -364,127 +362,127 @@ var Jt = () => {
364
362
  idempotency: e.idempotency,
365
363
  durationMs: e.durationMs
366
364
  };
367
- e.status >= 500 ? ae.error("incoming delivery failed", t) : e.status >= 400 ? ae.warn("incoming delivery rejected", t) : ae.info("incoming delivery handled", t);
365
+ e.status >= 500 ? ie.error("incoming delivery failed", t) : e.status >= 400 ? ie.warn("incoming delivery rejected", t) : ie.info("incoming delivery handled", t);
368
366
  }
369
367
  });
370
- se.set(t, { handle: r });
368
+ ce.set(t, { handle: r });
371
369
  }
372
- Be(), at((t) => Ve(e.store, t.subjectId, t.resourceType, t.resourceId));
373
- let y = (e.discovered.outboxHandlers?.length ?? 0) > 0 ? m({
370
+ Ve(), st((t) => He(e.store, t.subjectId, t.resourceType, t.resourceId));
371
+ let le = (e.discovered.outboxHandlers?.length ?? 0) > 0 ? h({
374
372
  handlers: e.discovered.outboxHandlers ?? [],
375
373
  store: e.store,
376
374
  log: (e.log ?? j({ scope: "voltro:serve" })).child("outbox")
377
- }) : void 0, b = ee({
375
+ }) : void 0, y = p({
378
376
  definitions: (e.discovered.connections ?? []).map((e) => e.definition),
379
377
  store: e.store,
380
378
  publicUrl: C(e.port ?? 4e3),
381
379
  log: (e.log ?? j({ scope: "voltro:serve" })).child("connections")
382
- }), x = ie({
380
+ }), b = ae({
383
381
  store: e.store,
384
382
  schemaRegistry: e.schemaRegistry,
385
383
  cache: n,
386
- kv: i,
387
- ...oe === void 0 ? {} : { webhooksService: oe },
388
- ...h === void 0 ? {} : { workflowsProxy: h },
384
+ kv: r,
385
+ ...se === void 0 ? {} : { webhooksService: se },
386
+ ...g === void 0 ? {} : { workflowsProxy: g },
389
387
  eventTriggers: e.discovered.eventTriggers ?? [],
390
388
  namespaceIsolationOn: re,
391
- ...y === void 0 ? {} : { outbox: { nudge: y.nudge } },
392
- ...b.active ? { connections: { registry: b.registry } } : {}
393
- }), ce = A.succeed(Oe, ve), le = (t, n) => {
394
- let r = t.pipe(k.provide(R(n)));
395
- return z((e.baseLayer ? r.pipe(k.provide(e.baseLayer)) : r).pipe(k.provide(ce)));
396
- }, S = qe({
389
+ ...le === void 0 ? {} : { outbox: { nudge: le.nudge } },
390
+ ...y.active ? { connections: { registry: y.registry } } : {}
391
+ }), S = A.succeed(ke, be), ue = (t, n) => {
392
+ let r = t.pipe(k.provide(Ke(n)));
393
+ return it((e.baseLayer ? r.pipe(k.provide(e.baseLayer)) : r).pipe(k.provide(S)));
394
+ }, w = Je({
397
395
  store: e.store,
398
- buildContext: (e, t, n) => x(e, t, n),
399
- runEffect: le,
400
- undoCapture: be()
401
- }), de = _e(), pe = He({
402
- buildContext: (e) => x(e),
403
- runEffect: le
404
- }), T = Je({
405
- buildContext: (e) => x(e),
406
- finalize: (t, n) => P(Ae(t, e.tenantScopedTables, n.subject.tenantId), e.softDeleteScopedTables),
407
- provideEffect: (e, t) => e.pipe(k.provide(R(t)))
396
+ buildContext: (e, t, n) => b(e, t, n),
397
+ runEffect: ue,
398
+ undoCapture: D()
399
+ }), pe = ye(), me = L({
400
+ buildContext: (e) => b(e),
401
+ runEffect: ue
402
+ }), T = Ye({
403
+ buildContext: (e) => b(e),
404
+ finalize: (t, n) => Ae(je(t, e.tenantScopedTables, n.subject.tenantId), e.softDeleteScopedTables),
405
+ provideEffect: (e, t) => e.pipe(k.provide(Ke(t)))
408
406
  }), E = {};
409
407
  for (let n of [
410
408
  ...e.discovered.queries,
411
- ...de.queries,
412
- ...b.queries
413
- ]) E[n.descriptor.name] = (e) => I(T(n, e), t, `subscription.${n.descriptor.name}`, void 0, void 0, Ye(n, e));
409
+ ...pe.queries,
410
+ ...y.queries
411
+ ]) E[n.descriptor.name] = (e) => I(T(n, e), t, `subscription.${n.descriptor.name}`, void 0, void 0, Xe(n, e));
414
412
  for (let t of [
415
413
  ...e.discovered.mutations,
416
- ...de.mutations,
417
- ...b.mutations
418
- ]) E[t.descriptor.name] = (e) => F(async (e, n) => S(t, e, n), e, `mutation.${t.descriptor.name}`);
419
- for (let t of [...e.discovered.actions, ...b.actions]) E[t.descriptor.name] = (e) => F(async (e, n) => pe(t, e, n), e, `action.${t.descriptor.name}`);
420
- let me = () => `public-${Math.random().toString(36).slice(2, 10)}`, he = [...e.discovered.mutations.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
414
+ ...pe.mutations,
415
+ ...y.mutations
416
+ ]) E[t.descriptor.name] = (e) => F(async (e, n) => w(t, e, n), e, `mutation.${t.descriptor.name}`);
417
+ for (let t of [...e.discovered.actions, ...y.actions]) E[t.descriptor.name] = (e) => F(async (e, n) => me(t, e, n), e, `action.${t.descriptor.name}`);
418
+ let he = () => `public-${Math.random().toString(36).slice(2, 10)}`, ge = [...e.discovered.mutations.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
421
419
  descriptor: e.descriptor,
422
- invoke: (t, n) => S(e, t, {
420
+ invoke: (t, n) => w(e, t, {
423
421
  subject: n.subject,
424
- traceId: me()
422
+ traceId: he()
425
423
  })
426
424
  })), ...e.discovered.actions.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
427
425
  descriptor: e.descriptor,
428
- invoke: (t, n) => pe(e, t, {
426
+ invoke: (t, n) => me(e, t, {
429
427
  subject: n.subject,
430
- traceId: me()
428
+ traceId: he()
431
429
  })
432
- }))], ge = he.length > 0 ? Ft(Pt(he), {
430
+ }))], _e = ge.length > 0 ? It(Ft(ge), {
433
431
  store: e.store,
434
432
  resolveSubject: (t) => e.resolveSubject(t, -1)
435
- }) : [], D = e.dataTransferSecret ?? process.env.VOLTRO_DATA_TRANSFER_SECRET, ye = D && D.length >= 16 ? [{
433
+ }) : [], ve = e.dataTransferSecret ?? process.env.VOLTRO_DATA_TRANSFER_SECRET, xe = ve && ve.length >= 16 ? [{
436
434
  method: "POST",
437
- path: Xt,
438
- handle: an({
439
- secret: D,
435
+ path: Zt,
436
+ handle: on({
437
+ secret: ve,
440
438
  store: e.store,
441
439
  ...e.dataTransferSnapshot ? { snapshot: e.dataTransferSnapshot } : {},
442
- assetSink: Wt(W({})),
440
+ assetSink: Gt(W({})),
443
441
  openArchive: (e) => (async function* () {
444
- let t = W({}), n = await yt((await k.runPromise(_t(t, e))).stream);
442
+ let t = W({}), n = await bt((await k.runPromise(yt(t, e))).stream);
445
443
  for await (let e of n) yield e instanceof Uint8Array ? e : new Uint8Array(e);
446
444
  })()
447
445
  })
448
446
  }, {
449
447
  method: "POST",
450
- path: Zt,
451
- handle: ln({
452
- secret: D,
448
+ path: Qt,
449
+ handle: un({
450
+ secret: ve,
453
451
  store: e.store,
454
452
  snapshot: e.dataTransferSnapshot ?? { tables: [] },
455
453
  dialect: e.dataTransferDialect ?? "memory",
456
454
  tenantTables: [...e.tenantScopedTables],
457
- loadProfile: un,
458
- assetSource: Gt(W({}), e.store),
455
+ loadProfile: dn,
456
+ assetSource: Kt(W({}), e.store),
459
457
  putArchive: async (e, t) => {
460
- let { Readable: n } = await import("node:stream"), r = W({}), i = gt("storage", () => n.from(t()));
461
- await k.runPromise(vt(r, e, i, { contentType: "application/octet-stream" }));
458
+ let { Readable: n } = await import("node:stream"), r = W({}), i = vt("storage", () => n.from(t()));
459
+ await k.runPromise(U(r, e, i, { contentType: "application/octet-stream" }));
462
460
  }
463
461
  })
464
- }] : [], xe = [
462
+ }] : [], Se = [
465
463
  ...e.httpRoutes ?? [],
466
- ...ge,
467
- ...ye,
468
- ...b.httpRoutes
464
+ ..._e,
465
+ ...xe,
466
+ ...y.httpRoutes
469
467
  ];
470
- for (let t of e.discovered.streams ?? []) E[t.descriptor.name] = (n) => Ne((r) => {
471
- let i = x(r), a = t.executor(n, i);
468
+ for (let t of e.discovered.streams ?? []) E[t.descriptor.name] = (n) => Pe((r) => {
469
+ let i = b(r), a = t.executor(n, i);
472
470
  if (k.isEffect(a)) {
473
- let t = a.pipe(k.provide(R(i.store)));
474
- return (e.baseLayer ? t.pipe(k.provide(e.baseLayer)) : t).pipe(k.provide(ce));
471
+ let t = a.pipe(k.provide(Ke(i.store)));
472
+ return (e.baseLayer ? t.pipe(k.provide(e.baseLayer)) : t).pipe(k.provide(S));
475
473
  }
476
474
  return typeof a == "object" && a && typeof a.then == "function" ? k.promise(() => a) : a;
477
475
  }, `stream.${t.descriptor.name}`);
478
476
  for (let t of e.discovered.workflows ?? []) E[t.definition.name] = (e) => F(async (e, n) => {
479
477
  let r = n;
480
- return Qe(h, {
478
+ return $e(g, {
481
479
  subject: r.subject,
482
480
  traceId: r.traceId,
483
481
  source: "workflow-rpc"
484
482
  }).start(t.definition.name, e);
485
483
  }, e, `workflow.${t.definition.name}`);
486
- g && (E[Y.name] = (e) => I(T({
487
- descriptor: Y,
484
+ te && (E[Ot.name] = (e) => I(T({
485
+ descriptor: Ot,
488
486
  executor: (e) => {
489
487
  let t = e.id;
490
488
  return {
@@ -493,30 +491,30 @@ var Jt = () => {
493
491
  column: "startedAt",
494
492
  direction: "desc"
495
493
  }],
496
- predicate: ht(U("id", t), U("executionId", t)),
494
+ predicate: _t(H("id", t), H("executionId", t)),
497
495
  take: 1,
498
496
  skip: void 0,
499
497
  projection: void 0
500
498
  };
501
499
  }
502
- }, e), t, `subscription.${Y.name}`), E[X.name] = (e) => I(T({
503
- descriptor: X,
500
+ }, e), t, `subscription.${Ot.name}`), E[Z.name] = (e) => I(T({
501
+ descriptor: Z,
504
502
  executor: (e) => {
505
- let t = e, n = [...t.tag === void 0 ? [] : [U("tag", t.tag)], ...t.status === void 0 ? [] : [U("status", t.status)]], r = Number.isFinite(t.limit) && t.limit !== void 0 ? Math.min(Math.max(Math.floor(t.limit), 1), 500) : 100;
503
+ let t = e, n = [...t.tag === void 0 ? [] : [H("tag", t.tag)], ...t.status === void 0 ? [] : [H("status", t.status)]], r = Number.isFinite(t.limit) && t.limit !== void 0 ? Math.min(Math.max(Math.floor(t.limit), 1), 500) : 100;
506
504
  return {
507
505
  table: "_voltro_workflow_runs",
508
506
  order: [{
509
507
  column: "startedAt",
510
508
  direction: "desc"
511
509
  }],
512
- predicate: n.length === 0 ? void 0 : n.length === 1 ? n[0] : pt(...n),
510
+ predicate: n.length === 0 ? void 0 : n.length === 1 ? n[0] : ht(...n),
513
511
  take: r,
514
512
  skip: void 0,
515
513
  projection: void 0
516
514
  };
517
515
  }
518
- }, e), t, `subscription.${X.name}`), E[Ot.name] = (e) => I(T({
519
- descriptor: Ot,
516
+ }, e), t, `subscription.${Z.name}`), E[X.name] = (e) => I(T({
517
+ descriptor: X,
520
518
  executor: (e) => {
521
519
  let t = e.runId;
522
520
  return {
@@ -525,14 +523,14 @@ var Jt = () => {
525
523
  column: "startedAt",
526
524
  direction: "asc"
527
525
  }],
528
- predicate: U("runId", t),
526
+ predicate: H("runId", t),
529
527
  take: 1e3,
530
528
  skip: void 0,
531
529
  projection: void 0
532
530
  };
533
531
  }
534
- }, e), t, `subscription.${Ot.name}`), E[J.name] = (e) => I(T({
535
- descriptor: J,
532
+ }, e), t, `subscription.${X.name}`), E[Y.name] = (e) => I(T({
533
+ descriptor: Y,
536
534
  executor: (e) => {
537
535
  let t = e.runId;
538
536
  return {
@@ -541,14 +539,14 @@ var Jt = () => {
541
539
  column: "occurredAt",
542
540
  direction: "asc"
543
541
  }],
544
- predicate: U("runId", t),
542
+ predicate: H("runId", t),
545
543
  take: 1e3,
546
544
  skip: void 0,
547
545
  projection: void 0
548
546
  };
549
547
  }
550
- }, e), t, `subscription.${J.name}`), E[q.name] = (e) => I(T({
551
- descriptor: q,
548
+ }, e), t, `subscription.${Y.name}`), E[Et.name] = (e) => I(T({
549
+ descriptor: Et,
552
550
  executor: (e) => {
553
551
  let t = e;
554
552
  return {
@@ -557,14 +555,14 @@ var Jt = () => {
557
555
  column: "occurredAt",
558
556
  direction: "desc"
559
557
  }],
560
- predicate: t.name === void 0 ? void 0 : U("name", t.name),
558
+ predicate: t.name === void 0 ? void 0 : H("name", t.name),
561
559
  take: Math.max(1, Math.min(500, t.limit ?? 100)),
562
560
  skip: void 0,
563
561
  projection: void 0
564
562
  };
565
563
  }
566
- }, e), t, `subscription.${q.name}`), E[Et.name] = (e) => I(T({
567
- descriptor: Et,
564
+ }, e), t, `subscription.${Et.name}`), E[J.name] = (e) => I(T({
565
+ descriptor: J,
568
566
  executor: (e) => {
569
567
  let t = e.eventId;
570
568
  return {
@@ -573,84 +571,84 @@ var Jt = () => {
573
571
  column: "createdAt",
574
572
  direction: "asc"
575
573
  }],
576
- predicate: U("eventId", t),
574
+ predicate: H("eventId", t),
577
575
  take: 500,
578
576
  skip: void 0,
579
577
  projection: void 0
580
578
  };
581
579
  }
582
- }, e), t, `subscription.${Et.name}`), E[Tt.name] = (t) => F(async (t, n) => {
580
+ }, e), t, `subscription.${J.name}`), E[Tt.name] = (t) => F(async (t, n) => {
583
581
  let r = t;
584
- return await _(e.store, n.subject, { executionId: r.executionId }), await h.cancel(r.workflowName, r.executionId), await Ie(r.workflowName, r.executionId, "workflow.cancel"), { ok: !0 };
582
+ return await _(e.store, n.subject, { executionId: r.executionId }), await g.cancel(r.workflowName, r.executionId), await Le(r.workflowName, r.executionId, "workflow.cancel"), { ok: !0 };
585
583
  }, t, `action.${Tt.name}`), E[Dt.name] = (t) => F(async (t, n) => {
586
584
  let r = t;
587
- return await _(e.store, n.subject, { executionId: r.executionId }), await h.resume(r.workflowName, r.executionId), { ok: !0 };
588
- }, t, `action.${Dt.name}`), E[Z.name] = (t) => F(async (t, n) => {
585
+ return await _(e.store, n.subject, { executionId: r.executionId }), await g.resume(r.workflowName, r.executionId), { ok: !0 };
586
+ }, t, `action.${Dt.name}`), E[kt.name] = (t) => F(async (t, n) => {
589
587
  let r = t;
590
- return await _(e.store, n.subject, { id: r.id }), h.signal({ id: r.id }, r.signalName, r.payload);
591
- }, t, `action.${Z.name}`), E[kt.name] = (t) => F(async (t, n) => {
588
+ return await _(e.store, n.subject, { id: r.id }), g.signal({ id: r.id }, r.signalName, r.payload);
589
+ }, t, `action.${kt.name}`), E[At.name] = (t) => F(async (t, n) => {
592
590
  let r = t;
593
- return await _(e.store, n.subject, { id: r.id }), h.update({ id: r.id }, r.updateName, r.payload, r.timeoutMs === void 0 ? void 0 : { timeoutMs: r.timeoutMs });
594
- }, t, `action.${kt.name}`));
595
- let Se = [
596
- ...e.discovered.queries.map((e) => K(e.descriptor)),
591
+ return await _(e.store, n.subject, { id: r.id }), g.update({ id: r.id }, r.updateName, r.payload, r.timeoutMs === void 0 ? void 0 : { timeoutMs: r.timeoutMs });
592
+ }, t, `action.${At.name}`));
593
+ let Ce = [
594
+ ...e.discovered.queries.map((e) => q(e.descriptor)),
597
595
  ...e.discovered.mutations.map((e) => Ct(e.descriptor)),
598
- ...e.discovered.actions.map((e) => G(e.descriptor)),
599
- ...de.queries.map((e) => K(e.descriptor)),
600
- ...de.mutations.map((e) => Ct(e.descriptor)),
601
- ...b.queries.map((e) => K(e.descriptor)),
602
- ...b.mutations.map((e) => Ct(e.descriptor)),
603
- ...b.actions.map((e) => G(e.descriptor)),
596
+ ...e.discovered.actions.map((e) => K(e.descriptor)),
597
+ ...pe.queries.map((e) => q(e.descriptor)),
598
+ ...pe.mutations.map((e) => Ct(e.descriptor)),
599
+ ...y.queries.map((e) => q(e.descriptor)),
600
+ ...y.mutations.map((e) => Ct(e.descriptor)),
601
+ ...y.actions.map((e) => K(e.descriptor)),
604
602
  ...(e.discovered.streams ?? []).map((e) => wt(e.descriptor)),
605
- ...(e.discovered.workflows ?? []).map((e) => ct(e.definition)),
606
- ...g ? [
607
- K(Y),
608
- K(X),
609
- K(Ot),
610
- K(J),
611
- K(q),
612
- K(Et),
613
- G(Tt),
614
- G(Dt),
615
- G(Z),
616
- G(kt)
603
+ ...(e.discovered.workflows ?? []).map((e) => B(e.definition)),
604
+ ...te ? [
605
+ q(Ot),
606
+ q(Z),
607
+ q(X),
608
+ q(Y),
609
+ q(Et),
610
+ q(J),
611
+ K(Tt),
612
+ K(Dt),
613
+ K(kt),
614
+ K(At)
617
615
  ] : []
618
- ], O = dt.make(...Se).middleware(bt).middleware(xt), Ce = A.succeed(bt, bt.of(({ headers: t, clientId: n }) => k.promise(() => e.resolveSubject(t, n)))), we = A.succeed(xt, xt.of(({ clientId: e }) => k.succeed({ clientId: e }))), Te = e.dormancyTenantId ?? "default", Ee = e.dormancy === "sleep" ? {
619
- register: (t, n, r) => nt(e.store, {
620
- tenantId: r ?? Te,
616
+ ], O = pt.make(...Ce).middleware(xt).middleware(G), we = A.succeed(xt, xt.of(({ headers: t, clientId: n }) => k.promise(() => e.resolveSubject(t, n)))), Te = A.succeed(G, G.of(({ clientId: e }) => k.succeed({ clientId: e }))), Ee = e.dormancyTenantId ?? "default", De = e.dormancy === "sleep" ? {
617
+ register: (t, n, r) => z(e.store, {
618
+ tenantId: r ?? Ee,
621
619
  kind: "workflow",
622
620
  refId: t,
623
621
  wakeAt: n
624
622
  }),
625
- cancel: (t, n) => Fe(e.store, {
626
- tenantId: n ?? Te,
623
+ cancel: (t, n) => Ie(e.store, {
624
+ tenantId: n ?? Ee,
627
625
  kind: "workflow",
628
626
  refId: t
629
627
  }).then(() => {})
630
- } : void 0, M = ne ? await import("@voltro/workflow") : void 0, N = M?.makeWorkflowRunRecorder({
628
+ } : void 0, M = ne ? await import("@voltro/workflow") : void 0, P = M?.makeWorkflowRunRecorder({
631
629
  store: e.store,
632
- ...Ee === void 0 ? {} : { wakeups: Ee }
633
- }), je = async (t, n) => {
630
+ ...De === void 0 ? {} : { wakeups: De }
631
+ }), Me = async (t, n) => {
634
632
  await M.closeWorkflowChildrenForParent({
635
633
  store: e.store,
636
634
  parentExecutionId: t,
637
635
  parentStatus: n,
638
- recorder: N,
636
+ recorder: P,
639
637
  log: { warn: (e, t) => {
640
638
  process.stderr.write(`[workflow] ${e} ${t ? JSON.stringify(t) : ""}\n`);
641
639
  } },
642
640
  interruptChild: async (t, n) => {
643
641
  let r = (e.discovered.workflows ?? []).find((e) => e.definition.name === t);
644
642
  if (!r) throw Error(`Unknown child workflow: ${t}`);
645
- if (!s) throw Error("Workflow runtime is not ready");
646
- await s.runPromise(r.definition.interrupt(n));
643
+ if (!o) throw Error("Workflow runtime is not ready");
644
+ await o.runPromise(r.definition.interrupt(n));
647
645
  }
648
646
  });
649
- }, Ie = async (t, n, r) => {
647
+ }, Le = async (t, n, r) => {
650
648
  let i = (await e.store.query({
651
649
  table: "_voltro_workflow_runs",
652
650
  order: [],
653
- predicate: U("executionId", n),
651
+ predicate: H("executionId", n),
654
652
  projection: void 0,
655
653
  skip: void 0,
656
654
  take: 1
@@ -661,7 +659,7 @@ var Jt = () => {
661
659
  cancelled: !0,
662
660
  completedAt: /* @__PURE__ */ new Date()
663
661
  }), o = i.subject?.tenantId ?? void 0;
664
- a && await N.recordEvent({
662
+ a && await P.recordEvent({
665
663
  runId: i.id,
666
664
  eventType: "run-cancelled",
667
665
  payload: {
@@ -670,50 +668,43 @@ var Jt = () => {
670
668
  executionId: n,
671
669
  ...o == null ? {} : { tenantId: o }
672
670
  }
673
- }), a && await je(n, "cancelled");
674
- }, Le = [...$e(e.discovered.workflows ?? [], {
675
- buildContext: (t, n) => {
676
- let r = t?.subject ?? {
677
- type: "anonymous",
678
- id: null,
679
- tenantId: null
680
- };
681
- return e.buildContextForWorkflow?.(t, n) ?? x({
682
- subject: r,
683
- traceId: t?.traceId ?? "workflow-bootstrap"
684
- }, e.store, void 0, `workflow:${n.workflowName}`, { parentExecutionId: n.executionId });
685
- },
686
- resolveStartContext: te
671
+ }), a && await Me(n, "cancelled");
672
+ }, Re = [...et(e.discovered.workflows ?? [], {
673
+ buildContext: (t, n) => e.buildContextForWorkflow?.(t, n) ?? b({
674
+ subject: t.subject,
675
+ traceId: t.traceId
676
+ }, e.store, void 0, `workflow:${n.workflowName}`, { parentExecutionId: n.executionId }),
677
+ resolveStartContext: ee
687
678
  }, (t, n, r) => {
688
679
  let i = M.getWorkflowVersionMetadata(t.definition);
689
680
  return M.wrapWorkflowExecuteWithRunRecording({
690
681
  name: t.definition.name,
691
682
  store: e.store,
692
- subject: r?.subject ?? null,
693
- source: r?.source ?? null,
694
- traceId: r?.traceId ?? null,
683
+ subject: r.subject,
684
+ source: r.source ?? null,
685
+ traceId: r.traceId,
695
686
  workflowVersion: i.version,
696
687
  workflowCompatibleVersions: i.compatibleWith,
697
688
  workflowPatches: i.patches,
698
689
  parentExecutionId: r?.parentExecutionId ?? null,
699
690
  parentClosePolicy: r?.parentClosePolicy ?? null,
700
- onParentClose: ({ executionId: e, status: t }) => je(e, t),
701
- recorder: N
691
+ onParentClose: ({ executionId: e, status: t }) => Me(e, t),
692
+ recorder: P
702
693
  }, n);
703
- }), ...e.discovered.workflowWorkers ?? []], Re = Le.length > 0 ? A.mergeAll(...Le) : A.empty;
704
- ((e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster") && e.workflowEngineLayer !== void 0 && (s = De.make(Re.pipe(A.provideMerge(e.workflowEngineLayer))), await s.runPromise(k.void), a = (e.discovered.workflows?.length ?? 0) > 0 ? Ze({
694
+ }), ...e.discovered.workflowWorkers ?? []], ze = Re.length > 0 ? A.mergeAll(...Re) : A.empty;
695
+ ((e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster") && e.workflowEngineLayer !== void 0 && (o = Oe.make(ze.pipe(A.provideMerge(e.workflowEngineLayer))), await o.runPromise(k.void), a = (e.discovered.workflows?.length ?? 0) > 0 ? Qe({
705
696
  workflows: e.discovered.workflows ?? [],
706
- runEffect: (e) => s.runPromise(e),
707
- rememberStartContext: f,
697
+ runEffect: (e) => o.runPromise(e),
698
+ rememberStartContext: d,
708
699
  signal: async (t, n, r) => {
709
700
  let i = await M.sendWorkflowSignal({
710
701
  store: e.store,
711
- recorder: N,
702
+ recorder: P,
712
703
  target: t,
713
704
  signalName: n,
714
705
  payload: r
715
706
  });
716
- return await s.runPromise(M.completeSuspendingSignal({
707
+ return await o.runPromise(M.completeSuspendingSignal({
717
708
  store: e.store,
718
709
  target: t,
719
710
  signalName: n,
@@ -722,54 +713,50 @@ var Jt = () => {
722
713
  },
723
714
  update: (t, n, r, i) => M.sendWorkflowUpdate({
724
715
  store: e.store,
725
- recorder: N,
716
+ recorder: P,
726
717
  target: t,
727
718
  updateName: n,
728
719
  payload: r,
729
720
  ...i === void 0 ? {} : { options: i }
730
721
  }),
731
722
  listRuns: (t) => fe(e.store, t),
732
- retry: (t, n) => ue({
723
+ retry: (t, n) => x({
733
724
  store: e.store,
734
725
  workflows: e.discovered.workflows ?? [],
735
- runPromise: (e) => s.runPromise(e)
726
+ runPromise: (e) => o.runPromise(e)
736
727
  }, t, n)
737
728
  }) : void 0);
738
- let ze = A.mergeAll(O.toLayer(E), Ce, we), We = d(E, e.discovered.queries.map((e) => e.descriptor.name), g), Ge = A.mergeAll(O.toLayer(We), Ce, we), L = e.observability, Xe = await Pe({
739
- ...L && L.spanProcessors.length > 0 ? { extraSpanProcessors: L.spanProcessors } : {},
740
- ...L && L.metricReaders.length > 0 ? { extraMetricReaders: L.metricReaders } : {},
741
- ...L && Object.keys(L.resourceAttributes).length > 0 ? { resourceAttributes: L.resourceAttributes } : {},
742
- ...L && L.sampler !== void 0 ? { sampler: L.sampler } : {}
743
- }), rt = !1, it = e.store.ping ? () => e.store.ping().then(() => !0).catch(() => !1) : void 0, V = B({
729
+ let Be = A.mergeAll(O.toLayer(E), we, Te), We = f(E, e.discovered.queries.map((e) => e.descriptor.name), te), Ge = A.mergeAll(O.toLayer(We), we, Te), R = e.observability, Ze = await Fe({
730
+ ...R && R.spanProcessors.length > 0 ? { extraSpanProcessors: R.spanProcessors } : {},
731
+ ...R && R.metricReaders.length > 0 ? { extraMetricReaders: R.metricReaders } : {},
732
+ ...R && Object.keys(R.resourceAttributes).length > 0 ? { resourceAttributes: R.resourceAttributes } : {},
733
+ ...R && R.sampler !== void 0 ? { sampler: R.sampler } : {}
734
+ }), rt = !1, at = e.store.ping ? () => e.store.ping().then(() => !0).catch(() => !1) : void 0, V = lt({
744
735
  group: O,
745
- handlersLayer: ze,
736
+ handlersLayer: Be,
746
737
  httpHandlersLayer: Ge,
747
738
  port: e.port ?? 4e3,
748
739
  path: e.path ?? "/ws",
749
- tracerLayer: Xe.layer,
740
+ tracerLayer: Ze.layer,
750
741
  healthCheck: {
751
742
  isReady: () => rt,
752
- ...it ? { ping: it } : {}
743
+ ...at ? { ping: at } : {}
753
744
  },
754
- ...xe.length > 0 ? { httpRoutes: xe } : {},
755
- ...se.size > 0 ? { webhookRoutes: se } : {}
745
+ ...Se.length > 0 ? { httpRoutes: Se } : {},
746
+ ...ce.size > 0 ? { webhookRoutes: ce } : {}
756
747
  });
757
- if (await Me(V), (e.discovered.schedules?.length ?? 0) > 0) {
758
- let t = (e.scheduleCoordination ?? "single") === "advisoryLock" ? Ue(e.store, e.scheduleReplicaId ?? `pid-${process.pid}`) : ot;
759
- c = await st(e.discovered.schedules ?? [], {
748
+ if (await Ne(V), (e.discovered.schedules?.length ?? 0) > 0) {
749
+ let t = (e.scheduleCoordination ?? "single") === "advisoryLock" ? Ue(e.store, e.scheduleReplicaId ?? `pid-${process.pid}`) : ct;
750
+ c = await ut(e.discovered.schedules ?? [], {
760
751
  store: e.store,
761
752
  coordinator: t,
762
753
  defaultTrigger: e.scheduleDefaultTrigger ?? "self",
763
754
  replicaId: e.scheduleReplicaId ?? `pid-${process.pid}`,
764
755
  armSelf: e.scheduleArmSelf ?? !0,
765
756
  dormancy: e.dormancy ?? "always-on",
766
- dormancyTenantId: e.dormancyTenantId ?? "default",
767
- buildContext: ({ traceId: t, scheduleName: n }) => x({
768
- subject: {
769
- type: "anonymous",
770
- id: null,
771
- tenantId: null
772
- },
757
+ ...e.dormancyTenantId === void 0 ? {} : { dormancyTenantId: e.dormancyTenantId },
758
+ buildContext: ({ traceId: t, scheduleName: n, subject: r }) => b({
759
+ subject: r,
773
760
  traceId: t
774
761
  }, e.store, void 0, `schedule:${n}`),
775
762
  log: {
@@ -785,26 +772,26 @@ var Jt = () => {
785
772
  ...e.onScheduleRunEvent === void 0 ? {} : { onRunEvent: e.onScheduleRunEvent }
786
773
  }), e.onSchedulerReady?.(c);
787
774
  }
788
- let H = e.log ?? j({ scope: "voltro:serve" }), ut, ft;
789
- if ((e.discovered.subscribers?.length ?? 0) > 0 && (ut = o(e.discovered.subscribers ?? [], e.store, H.child("subscribe"))), (e.discovered.reactions?.length ?? 0) > 0) {
790
- let t = H.child("reaction");
791
- ft = p(e.discovered.reactions ?? [], e.store, {
775
+ let dt = e.log ?? j({ scope: "voltro:serve" }), ft, mt;
776
+ if ((e.discovered.subscribers?.length ?? 0) > 0 && (ft = s(e.discovered.subscribers ?? [], e.store, dt.child("subscribe"), e.schemaRegistry)), (e.discovered.reactions?.length ?? 0) > 0) {
777
+ let t = dt.child("reaction");
778
+ mt = m(e.discovered.reactions ?? [], e.store, {
792
779
  runAct: async (n, r) => {
793
780
  if (n.kind === "workflow") {
794
- if (h === void 0) {
781
+ if (g === void 0) {
795
782
  t.warn("reaction workflow act skipped — no workflow engine in this app", { workflow: n.workflow });
796
783
  return;
797
784
  }
798
785
  let e = r.new ?? r.old ?? {};
799
- await Qe(h, {
786
+ await $e(g, {
800
787
  traceId: `reaction:${n.workflow}`,
801
788
  source: `reaction:${n.workflow}`
802
789
  }).start(n.workflow, e);
803
790
  return;
804
791
  }
805
- await w(n.agent, r, {
792
+ await de(n.agent, r, {
806
793
  findAgentSend: (t) => e.discovered.actions.find((e) => e.descriptor.name === `${t}.send`),
807
- runAction: (e, t, n) => Promise.resolve(pe(e, t, n)),
794
+ runAction: (e, t, n) => Promise.resolve(me(e, t, n)),
808
795
  makeSubject: (e) => St(e),
809
796
  now: () => Date.now(),
810
797
  log: t
@@ -823,124 +810,124 @@ var Jt = () => {
823
810
  }
824
811
  }, t);
825
812
  }
826
- let mt;
827
- return (e.discovered.aggregates?.length ?? 0) > 0 && (mt = await r({
813
+ let gt;
814
+ return (e.discovered.aggregates?.length ?? 0) > 0 && (gt = await i({
828
815
  discovered: e.discovered.aggregates ?? [],
829
816
  store: e.store,
830
- log: H.child("aggregate"),
817
+ log: dt.child("aggregate"),
831
818
  ...e.analytics === void 0 ? {} : { analytics: e.analytics },
832
819
  ...e.aggregateStorage === void 0 ? {} : { storage: e.aggregateStorage },
833
820
  ...e.aggregateCoordinator === void 0 ? {} : { coordinator: e.aggregateCoordinator }
834
- }), ce = A.succeed(Oe, mt.registry)), rt = !0, e.bootTiming?.mark("ready"), {
821
+ }), S = A.succeed(ke, gt.registry)), rt = !0, e.bootTiming?.mark("ready"), {
835
822
  dispatcher: t,
836
823
  server: V,
837
824
  scheduler: c,
838
825
  close: async () => {
839
- rt = !1, mt?.detach(), ft?.(), ut?.(), await c?.shutdown(), t.close(), await s?.dispose(), await new Promise((e) => V.close(() => e()));
826
+ rt = !1, gt?.detach(), mt?.(), ft?.(), await c?.shutdown(), t.close(), await o?.dispose(), await new Promise((e) => V.close(() => e()));
840
827
  }
841
828
  };
842
- }, $ = j({ scope: "voltro:serve" }), pn = (e, t, n) => (e === "production" || e === "staging") && t !== "memory" && n !== "0", mn = (e, t) => {
829
+ }, $ = j({ scope: "voltro:serve" }), mn = (e, t, n) => (e === "production" || e === "staging") && t !== "memory" && n !== "0", hn = (e, t) => {
843
830
  let n = e.indexOf(t);
844
831
  return n >= 0 ? e[n + 1] : void 0;
845
- }, hn = async (e) => {
832
+ }, gn = async (e) => {
846
833
  let t = O(process.cwd());
847
834
  if (M(t)) {
848
835
  let n;
849
836
  try {
850
- let e = await import(Te(t).href);
837
+ let e = await import(Ee(t).href);
851
838
  typeof e.runServe == "function" ? n = e.runServe : $.warn("serve bundle has no runServe export — using the standard serve path");
852
839
  } catch (e) {
853
840
  $.warn("serve bundle failed to load — using the standard serve path", {}, e);
854
841
  }
855
842
  if (n) return $.info("serve: booting from the precompiled serve bundle"), n(e);
856
843
  }
857
- return gn(e);
858
- }, gn = async (r) => {
859
- let o = Yt();
860
- process.env.NODE_ENV || (process.env.NODE_ENV = "production"), ut();
861
- let d = process.cwd(), ee = Number(process.env.PORT ?? mn(r, "--port") ?? 4e3), p = await E(d);
862
- it(rt(p?.secrets)), await e({
863
- rawEnv: p?.env,
844
+ return _n(e);
845
+ }, _n = async (i) => {
846
+ let s = Xt();
847
+ process.env.NODE_ENV || (process.env.NODE_ENV = "production"), ft();
848
+ let f = process.cwd(), p = Number(process.env.PORT ?? hn(i, "--port") ?? 4e3), m = await me(f);
849
+ at(rt(m?.secrets)), await t({
850
+ rawEnv: m?.env,
864
851
  appType: "api",
865
- root: d,
852
+ root: f,
866
853
  log: $,
867
854
  generateTypes: !1
868
- }), o.mark("config");
869
- let m = (process.env.DB_DIALECT ?? p?.store ?? "memory").toLowerCase(), ie = (m === "mariadb" || m === "postgres" || m === "mssql") && (process.env.CDC ?? "1") !== "0", _ = m === "mariadb" ? "mariadb" : m === "mssql" ? "mssql" : void 0, ue = Ce(d);
870
- if (!Se() && M(ue)) try {
871
- let e = await import(Te(ue).href);
855
+ }), s.mark("config");
856
+ let h = (process.env.DB_DIALECT ?? m?.store ?? "memory").toLowerCase(), ae = (h === "mariadb" || h === "postgres" || h === "mssql") && (process.env.CDC ?? "1") !== "0", _ = h === "mariadb" ? "mariadb" : h === "mssql" ? "mssql" : void 0, oe = we(f);
857
+ if (!Ce() && M(oe)) try {
858
+ let e = await import(Ee(oe).href);
872
859
  if (e.modules) {
873
860
  let t = {};
874
- for (let [n, r] of Object.entries(e.modules)) t[we(d, n)] = r;
875
- xe(t), $.info("precompiled api bundle loaded", { modules: Object.keys(t).length });
861
+ for (let [n, r] of Object.entries(e.modules)) t[Te(f, n)] = r;
862
+ Se(t), $.info("precompiled api bundle loaded", { modules: Object.keys(t).length });
876
863
  }
877
864
  } catch (e) {
878
865
  $.warn("precompiled api bundle failed to load — falling back to source", {}, e);
879
866
  }
880
- let C = await b(d), w = await ge(C, { cdc: ie && _ !== void 0 }), fe = C.filter((e) => ye.test(e)), _e = fe.length > 0 ? await h(fe, $.child("webhooks")) : void 0, ve = x({
881
- mix: w.featureMix,
882
- plugins: p?.plugins ?? [],
883
- cdc: ie && _ !== void 0,
867
+ let x = await le(f), C = await ge(x, { cdc: ae && _ !== void 0 }), de = x.filter((e) => xe.test(e)), fe = de.length > 0 ? await te(de, $.child("webhooks")) : void 0, ye = ve({
868
+ mix: C.featureMix,
869
+ plugins: m?.plugins ?? [],
870
+ cdc: ae && _ !== void 0,
884
871
  ..._ ? { cdcDialect: _ } : {}
885
- }), be = p?.analytics !== void 0 && p.analytics.kind !== "noop" && m !== "memory" ? (await y(m)).makeSqlLayer(S()) : void 0, O = await ne({
886
- spec: p?.analytics,
872
+ }), be = m?.analytics !== void 0 && m.analytics.kind !== "noop" && h !== "memory" ? (await w(h)).makeSqlLayer(S()) : void 0, D = await re({
873
+ spec: m?.analytics,
887
874
  sqlLayer: be,
888
875
  log: $
889
- }), j = (() => {
890
- let e = new Set(w.tables.map((e) => e.tableName)), t = [...w.tables];
891
- for (let n of [...ve, ...O.tables]) e.has(n.tableName) || (e.add(n.tableName), t.push(n));
876
+ }), O = (() => {
877
+ let e = new Set(C.tables.map((e) => e.tableName)), t = [...C.tables];
878
+ for (let n of [...ye, ...D.tables]) e.has(n.tableName) || (e.add(n.tableName), t.push(n));
892
879
  return t;
893
880
  })();
894
- for (let e of j) mt(e);
895
- let Oe = (process.env.NODE_ENV ?? "").toLowerCase();
896
- if (pn(Oe, m, process.env.VOLTRO_AUTO_MIGRATE)) {
897
- let e = (await y(m)).makeSqlLayer(S()), t = await k.runPromise(ft.SqlClient.pipe(k.flatMap((e) => Mt(e, j, {
898
- appliedBy: `serve:${Oe}`,
881
+ for (let e of O) gt(e);
882
+ let j = (process.env.NODE_ENV ?? "").toLowerCase();
883
+ if (mn(j, h, process.env.VOLTRO_AUTO_MIGRATE)) {
884
+ let e = (await w(h)).makeSqlLayer(S()), t = await k.runPromise(mt.SqlClient.pipe(k.flatMap((e) => Nt(e, O, {
885
+ appliedBy: `serve:${j}`,
899
886
  environment: "prod",
900
- dialectId: m
887
+ dialectId: h
901
888
  })), k.provide(e)));
902
- t.kind === "prod-mismatch" && ($.error(jt(t, m)), $.error("serve: refusing to boot — apply the schema first (voltro db apply in a pre-deploy step), or set VOLTRO_AUTO_MIGRATE=0 to bypass this check."), process.exit(1)), $.info(jt(t, m));
889
+ t.kind === "prod-mismatch" && ($.error(Mt(t, h)), $.error("serve: refusing to boot — apply the schema first (voltro db apply in a pre-deploy step), or set VOLTRO_AUTO_MIGRATE=0 to bypass this check."), process.exit(1)), $.info(Mt(t, h));
903
890
  }
904
- let ke = Xe(j);
905
- o.mark("discover");
906
- let P = await pe(p, void 0);
907
- p?.cache && !process.env.CACHE_BACKEND && (process.env.CACHE_BACKEND = p.cache), p?.cacheRedisUrl && !process.env.CACHE_REDIS_URL && (process.env.CACHE_REDIS_URL = p.cacheRedisUrl), p?.cacheRedisDriver && !process.env.CACHE_REDIS_DRIVER && (process.env.CACHE_REDIS_DRIVER = p.cacheRedisDriver), p?.cacheKeyPrefix && !process.env.CACHE_KEY_PREFIX && (process.env.CACHE_KEY_PREFIX = p.cacheKeyPrefix);
908
- let { service: Ae, invalidationBus: Me, snapshotCache: F, cache: Ne, backend: I, dispose: Pe } = await te({ env: process.env });
909
- $.info(`cache backend resolved: ${I}` + (I === "redis" ? ` (driver ${process.env.CACHE_REDIS_DRIVER ?? "resp"})` : " — in-process, not cross-instance")), P.onChange((e) => {
910
- k.runFork(Me.publish(e.table));
911
- }), p?.kv && !process.env.KV_BACKEND && (process.env.KV_BACKEND = p.kv), p?.kvRedisUrl && !process.env.KV_REDIS_URL && (process.env.KV_REDIS_URL = p.kvRedisUrl), p?.kvKeyPrefix && !process.env.KV_KEY_PREFIX && (process.env.KV_KEY_PREFIX = p.kvKeyPrefix);
912
- let { kv: Fe, service: Be } = await Ge({ store: P });
913
- o.mark("store");
914
- let Ve = je({
915
- store: P,
916
- sink: O.sink,
891
+ let ke = Ze(O);
892
+ s.mark("discover");
893
+ let N = await pe(m, void 0);
894
+ m?.cache && !process.env.CACHE_BACKEND && (process.env.CACHE_BACKEND = m.cache), m?.cacheRedisUrl && !process.env.CACHE_REDIS_URL && (process.env.CACHE_REDIS_URL = m.cacheRedisUrl), m?.cacheRedisDriver && !process.env.CACHE_REDIS_DRIVER && (process.env.CACHE_REDIS_DRIVER = m.cacheRedisDriver), m?.cacheKeyPrefix && !process.env.CACHE_KEY_PREFIX && (process.env.CACHE_KEY_PREFIX = m.cacheKeyPrefix);
895
+ let { service: Ae, invalidationBus: je, snapshotCache: Ne, cache: F, backend: Pe, dispose: I } = await n({ env: process.env });
896
+ $.info(`cache backend resolved: ${Pe}` + (Pe === "redis" ? ` (driver ${process.env.CACHE_REDIS_DRIVER ?? "resp"})` : " — in-process, not cross-instance")), N.onChange((e) => {
897
+ k.runFork(je.publish(e.table));
898
+ }), m?.kv && !process.env.KV_BACKEND && (process.env.KV_BACKEND = m.kv), m?.kvRedisUrl && !process.env.KV_REDIS_URL && (process.env.KV_REDIS_URL = m.kvRedisUrl), m?.kvKeyPrefix && !process.env.KV_KEY_PREFIX && (process.env.KV_KEY_PREFIX = m.kvKeyPrefix);
899
+ let { kv: Fe, service: Ie } = await Ge({ store: N });
900
+ s.mark("store");
901
+ let Ve = Me({
902
+ store: N,
903
+ sink: D.sink,
917
904
  log: $
918
- }), He = ae({
919
- store: P,
920
- dialect: m
921
- }), R = p?.plugins ?? [], Ke = process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, qe, Je;
922
- m !== "memory" && (qe = De.make((await y(m)).makeSqlLayer(S())), Je = await qe.runPromise(ft.SqlClient));
923
- let Ye = L({
905
+ }), He = g({
906
+ store: N,
907
+ dialect: h
908
+ }), L = m?.plugins ?? [], Ke = process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, qe, Je;
909
+ h !== "memory" && (qe = Oe.make((await w(h)).makeSqlLayer(S())), Je = await qe.runPromise(mt.SqlClient));
910
+ let Ye = R({
924
911
  coordinator: [
925
912
  "postgres",
926
913
  "mariadb",
927
914
  "mysql",
928
915
  "mssql"
929
- ].includes(m) ? Ue(P, Ke, $) : ot,
916
+ ].includes(h) ? Ue(N, Ke, $) : ct,
930
917
  replicaId: Ke,
931
918
  log: $
932
- }), Ze = [], Qe = {
919
+ }), Xe = [], Qe = {
933
920
  ...Je ? { sql: Je } : {},
934
921
  scheduleCoordinated: (e, t, n) => {
935
922
  let r = Ye(e, t, n);
936
- return Ze.push(r), r;
923
+ return Xe.push(r), r;
937
924
  }
938
925
  };
939
- for (let e of R) e.bindDataStore?.(P, Qe);
940
- let $e = R.filter((e) => typeof e.onChangeEvent == "function");
926
+ for (let e of L) e.bindDataStore?.(N, Qe);
927
+ let $e = L.filter((e) => typeof e.onChangeEvent == "function");
941
928
  if ($e.length > 0) {
942
- let e = P.changeScope ?? "local";
943
- P.onChange((t) => {
929
+ let e = N.changeScope ?? "local";
930
+ N.onChange((t) => {
944
931
  let n = {
945
932
  table: t.table,
946
933
  op: t.op,
@@ -949,60 +936,60 @@ var Jt = () => {
949
936
  ...t.origin === void 0 ? {} : { origin: t.origin },
950
937
  changeScope: e
951
938
  };
952
- for (let e of $e) k.runFork(e.onChangeEvent(n).pipe(k.catchAllCause((t) => k.sync(() => $.warn(`plugin ${e.name} onChangeEvent failed`, { error: Ee.pretty(t) })))));
939
+ for (let e of $e) k.runFork(e.onChangeEvent(n).pipe(k.catchAllCause((t) => k.sync(() => $.warn(`plugin ${e.name} onChangeEvent failed`, { error: De.pretty(t) })))));
953
940
  });
954
941
  }
955
- let et = oe({
956
- plugins: R,
957
- appName: p?.name ?? "voltro-api",
942
+ let et = se({
943
+ plugins: L,
944
+ appName: m?.name ?? "voltro-api",
958
945
  appType: "api",
959
946
  voltroVersion: process.env.npm_package_version ?? "0.0.0",
960
947
  log: $
961
948
  });
962
- R.length && await et.activate(), o.mark("plugins");
963
- let tt = await et.gatherObservability(), nt = await ce(P, p, m, {
949
+ L.length && await et.activate(), s.mark("plugins");
950
+ let tt = await et.gatherObservability(), nt = await y(N, m, h, {
964
951
  info: (e, t) => process.stdout.write(`[broadcast] ${e} ${t ? JSON.stringify(t) : ""}\n`),
965
952
  warn: (e, t) => process.stderr.write(`[broadcast] ${e} ${t ? JSON.stringify(t) : ""}\n`),
966
953
  debug: () => {}
967
- }), z = p?.apiKeys, at = (typeof z == "object" ? z.prefix : void 0) ?? "voltro_", B = z ? We(Le(P), { prefix: at }) : void 0, st = B ? [ze(B, { prefix: at })] : [], ct = D([...p?.auth?.strategies ?? [], ...st], Nt(p?.plugins ?? []), p?.auth?.anonymousTenantRequired ?? !1), lt = [...p?.restRoutes ?? [], ...B ? N(B, (typeof z == "object" ? z.managementPath : void 0) ?? "/v1/api-keys") : []], V = p?.idempotency, H = V ? {
968
- store: Re(P),
969
- header: (typeof V == "object" ? V.header : void 0) ?? "Idempotency-Key",
970
- ttlMs: (typeof V == "object" ? V.ttlMs : void 0) ?? 864e5
971
- } : void 0, dt = lt.length > 0 ? Ft(lt, {
972
- store: P,
973
- resolveSubject: (e) => ct({
954
+ }), z = m?.apiKeys, it = (typeof z == "object" ? z.prefix : void 0) ?? "voltro_", ot = z ? We(Re(N), { prefix: it }) : void 0, st = ot ? [Be(ot, { prefix: it })] : [], lt = _e([...m?.auth?.strategies ?? [], ...st], Pt(m?.plugins ?? []), m?.auth?.anonymousTenantRequired ?? !1), ut = [...m?.restRoutes ?? [], ...ot ? P(ot, (typeof z == "object" ? z.managementPath : void 0) ?? "/v1/api-keys") : []], B = m?.idempotency, V = B ? {
955
+ store: ze(N),
956
+ header: (typeof B == "object" ? B.header : void 0) ?? "Idempotency-Key",
957
+ ttlMs: (typeof B == "object" ? B.ttlMs : void 0) ?? 864e5
958
+ } : void 0, dt = ut.length > 0 ? It(ut, {
959
+ store: N,
960
+ resolveSubject: (e) => lt({
974
961
  headers: e,
975
962
  clientId: -1
976
963
  }),
977
- ...H ? { idempotency: H } : {}
978
- }) : [], pt = R.map((e) => e.services).filter((e) => e !== void 0), U = A.mergeAll(u({
979
- analyticsLayer: O.layer,
964
+ ...V ? { idempotency: V } : {}
965
+ }) : [], pt = L.map((e) => e.services).filter((e) => e !== void 0), ht = A.mergeAll(d({
966
+ analyticsLayer: D.layer,
980
967
  cacheService: Ae,
981
- kvService: Be,
968
+ kvService: Ie,
982
969
  pluginServices: pt,
983
- userLayers: p?.layers ?? []
984
- }), me), ht = p?.scheduling ?? {}, gt = ht.trigger ?? "self", _t = /* @__PURE__ */ new Set([
970
+ userLayers: m?.layers ?? []
971
+ }), E), H = m?.scheduling ?? {}, _t = H.trigger ?? "self", vt = /* @__PURE__ */ new Set([
985
972
  "postgres",
986
973
  "mysql",
987
974
  "mariadb",
988
975
  "mssql"
989
- ]), vt = ht.coordination ?? (_t.has(m) ? "advisoryLock" : "single"), W = vt === "cluster" && _t.has(m), yt = W ? "cluster" : vt === "advisoryLock" && _t.has(m) ? "advisoryLock" : "single";
990
- vt === "cluster" && !W && $.warn("scheduling.coordination=cluster needs a sql-backed store except sqlite — falling back to single"), vt === "advisoryLock" && !_t.has(m) && $.warn("scheduling.coordination=advisoryLock needs a SQL store (the claim-row gate) — falling back to single");
991
- let bt, xt = w.workflows.length > 0 || w.workflowWorkers.length > 0 || w.eventTriggers.length > 0 || (_e?.outgoing.length ?? 0) > 0 || W, G;
976
+ ]), yt = H.coordination ?? (vt.has(h) ? "advisoryLock" : "single"), U = yt === "cluster" && vt.has(h), W = U ? "cluster" : yt === "advisoryLock" && vt.has(h) ? "advisoryLock" : "single";
977
+ yt === "cluster" && !U && $.warn("scheduling.coordination=cluster needs a sql-backed store except sqlite — falling back to single"), yt === "advisoryLock" && !vt.has(h) && $.warn("scheduling.coordination=advisoryLock needs a SQL store (the claim-row gate) — falling back to single");
978
+ let bt, xt = C.workflows.length > 0 || C.workflowWorkers.length > 0 || C.eventTriggers.length > 0 || (fe?.outgoing.length ?? 0) > 0 || U, G;
992
979
  if (xt) {
993
- if (m === "mssql") {
994
- let e = await c(process.cwd());
980
+ if (h === "mssql") {
981
+ let e = await l(process.cwd());
995
982
  e && $.warn(e);
996
983
  }
997
- let [{ WorkflowEngine: e }, { makeClusterCronLayer: t, workflowEngineLayer: n, resolveRunnerStorage: r }] = await Promise.all([import("@effect/workflow"), import("@voltro/workflow/cluster")]), i = W ? w.schedules.filter((e) => (e.trigger ?? gt) === "self").map((e) => t({
984
+ let [{ WorkflowEngine: e }, { makeClusterCronLayer: t, workflowEngineLayer: n, resolveRunnerStorage: r }] = await Promise.all([import("@effect/workflow"), import("@voltro/workflow/cluster")]), i = U ? C.schedules.filter((e) => (e.trigger ?? _t) === "self").map((e) => t({
998
985
  name: e.name,
999
- cron: Ie(e),
986
+ cron: Le(e),
1000
987
  execute: async () => {
1001
988
  await bt?.fireFromCluster(e.name);
1002
989
  }
1003
990
  })) : [];
1004
- G = m === "memory" ? e.layerMemory : await (async () => {
1005
- let e = await y(m), t = r({ sqliteFamily: e.id === "sqlite" || e.id === "turso" });
991
+ G = h === "memory" ? e.layerMemory : await (async () => {
992
+ let e = await w(h), t = r({ sqliteFamily: e.id === "sqlite" || e.id === "turso" });
1006
993
  return $.info(`workflow engine: cluster-${t}, dialect=${e.id}` + (t === "memory" ? " — single-process durable replay, no cross-pod shard handoff" + (e.id !== "sqlite" && e.id !== "turso" ? " (VOLTRO_WORKFLOW_RUNNER_STORAGE=memory: SqlRunnerStorage/cluster_runners + GET_LOCK skipped)" : "") : "")), n({
1007
994
  sqlClientLayer: e.makeSqlLayer(S()),
1008
995
  runnerStorage: t,
@@ -1012,100 +999,100 @@ var Jt = () => {
1012
999
  });
1013
1000
  })();
1014
1001
  }
1015
- let St = le(R, t()), Ct = C.filter((e) => /\.subscribe\.tsx?$/.test(e)), K = Ct.length > 0 ? await l(Ct, $) : [], wt = C.filter((e) => /\.reaction\.tsx?$/.test(e)), Tt = wt.length > 0 ? await n(wt, $) : [], q = C.filter((e) => /\.outbox\.tsx?$/.test(e)), Et = q.length > 0 ? await f(q, $) : [], Dt = C.filter((e) => /\.aggregate\.tsx?$/.test(e)), J = Dt.length > 0 ? await g(Dt, $) : [], Y = a();
1016
- if (J.length > 0 && m !== "memory") try {
1017
- Y = i((await y(m)).makeSqlLayer(S()));
1002
+ let K = b(L, e()), St = x.filter((e) => /\.subscribe\.tsx?$/.test(e)), Ct = St.length > 0 ? await u(St, $) : [], q = x.filter((e) => /\.reaction\.tsx?$/.test(e)), wt = q.length > 0 ? await r(q, $) : [], Tt = x.filter((e) => /\.outbox\.tsx?$/.test(e)), Et = Tt.length > 0 ? await ee(Tt, $) : [], J = x.filter((e) => /\.aggregate\.tsx?$/.test(e)), Dt = J.length > 0 ? await ne(J, $) : [], Y = o();
1003
+ if (Dt.length > 0 && h !== "memory") try {
1004
+ Y = a((await w(h)).makeSqlLayer(S()));
1018
1005
  } catch (e) {
1019
1006
  $.warn("aggregate: SQL storage init failed — falling back to in-process", { err: String(e) });
1020
1007
  }
1021
- let Ot = m === "memory" ? ot : Ue(P, `aggregate@${process.pid}`, $), X = [], Z = [], kt = C.filter((e) => T.test(e));
1008
+ let Ot = h === "memory" ? ct : Ue(N, `aggregate@${process.pid}`, $), X = [], Z = [], kt = x.filter((e) => he.test(e));
1022
1009
  if (kt.length > 0) {
1023
- let e = $.child("agent"), t = C.filter((e) => he.test(e));
1024
- t.length > 0 && await v(t, e);
1025
- let n = await de(kt, e);
1026
- for (let e of n.agents) for (let t of se(e)) (t.kind === "action" ? X : Z).push({
1010
+ let e = $.child("agent"), t = x.filter((e) => ue.test(e));
1011
+ t.length > 0 && await T(t, e);
1012
+ let n = await v(kt, e);
1013
+ for (let e of n.agents) for (let t of ce(e)) (t.kind === "action" ? X : Z).push({
1027
1014
  file: t.file,
1028
1015
  descriptor: t.descriptor,
1029
1016
  executor: t.executor
1030
1017
  });
1031
1018
  n.agents.length > 0 && e.info("synthesized agent routes", { agents: n.agents.map((e) => e.descriptor.name) });
1032
1019
  }
1033
- o.mark("workflow");
1034
- let Pt = await fn({
1035
- bootTiming: o,
1020
+ s.mark("workflow");
1021
+ let At = await pn({
1022
+ bootTiming: s,
1036
1023
  discovered: {
1037
- queries: [...w.queries, ...Z],
1038
- mutations: w.mutations,
1039
- actions: [...w.actions, ...X],
1040
- streams: w.streams,
1041
- workflows: w.workflows,
1042
- workflowWorkers: w.workflowWorkers,
1043
- eventTriggers: w.eventTriggers,
1044
- schedules: w.schedules,
1045
- subscribers: K,
1024
+ queries: [...C.queries, ...Z],
1025
+ mutations: C.mutations,
1026
+ actions: [...C.actions, ...X],
1027
+ streams: C.streams,
1028
+ workflows: C.workflows,
1029
+ workflowWorkers: C.workflowWorkers,
1030
+ eventTriggers: C.eventTriggers,
1031
+ schedules: C.schedules,
1032
+ subscribers: Ct,
1046
1033
  outboxHandlers: Et,
1047
- connections: w.connections,
1048
- reactions: Tt,
1049
- aggregates: J,
1050
- ..._e === void 0 ? {} : { webhooks: _e }
1034
+ connections: C.connections,
1035
+ reactions: wt,
1036
+ aggregates: Dt,
1037
+ ...fe === void 0 ? {} : { webhooks: fe }
1051
1038
  },
1052
1039
  log: $,
1053
- analytics: O.sink,
1040
+ analytics: D.sink,
1054
1041
  aggregateStorage: Y,
1055
1042
  aggregateCoordinator: Ot,
1056
- store: P,
1043
+ store: N,
1057
1044
  kv: Fe,
1058
- cache: Ne,
1059
- snapshotCache: F,
1045
+ cache: F,
1046
+ snapshotCache: Ne,
1060
1047
  schemaRegistry: ke,
1061
- tenantScopedTables: w.tenantScopedTables,
1062
- softDeleteScopedTables: w.softDeleteScopedTables,
1063
- dataTransferSnapshot: At(j),
1064
- dataTransferDialect: m,
1065
- tenantIsolation: (process.env.VOLTRO_TENANT_ISOLATION ?? p?.tenancy?.isolation) === "namespace" ? "namespace" : "shared-schema",
1066
- resolveSubject: (e, t) => ct({
1048
+ tenantScopedTables: C.tenantScopedTables,
1049
+ softDeleteScopedTables: C.softDeleteScopedTables,
1050
+ dataTransferSnapshot: jt(O),
1051
+ dataTransferDialect: h,
1052
+ tenantIsolation: (process.env.VOLTRO_TENANT_ISOLATION ?? m?.tenancy?.isolation) === "namespace" ? "namespace" : "shared-schema",
1053
+ resolveSubject: (e, t) => lt({
1067
1054
  headers: e,
1068
1055
  clientId: t
1069
1056
  }),
1070
- httpRoutes: [...R.flatMap((e) => e.httpRoutes ?? []), ...dt],
1071
- ...U ? { baseLayer: U } : {},
1057
+ httpRoutes: [...L.flatMap((e) => e.httpRoutes ?? []), ...dt],
1058
+ ...ht ? { baseLayer: ht } : {},
1072
1059
  ...G === void 0 ? {} : { workflowEngineLayer: G },
1073
- scheduleDefaultTrigger: gt,
1074
- scheduleCoordination: yt,
1075
- scheduleArmSelf: !W,
1076
- dormancy: process.env.VOLTRO_DORMANCY === "sleep" || process.env.VOLTRO_DORMANCY === "always-on" ? process.env.VOLTRO_DORMANCY : p?.dormancy ?? "always-on",
1060
+ scheduleDefaultTrigger: _t,
1061
+ scheduleCoordination: W,
1062
+ scheduleArmSelf: !U,
1063
+ dormancy: process.env.VOLTRO_DORMANCY === "sleep" || process.env.VOLTRO_DORMANCY === "always-on" ? process.env.VOLTRO_DORMANCY : m?.dormancy ?? "always-on",
1077
1064
  scheduleReplicaId: process.env.HOSTNAME ?? `pid-${process.pid}`,
1078
- ...St === void 0 ? {} : { scheduleFireInterceptor: St },
1065
+ ...K === void 0 ? {} : { scheduleFireInterceptor: K },
1079
1066
  onSchedulerReady: (e) => {
1080
1067
  bt = e;
1081
1068
  },
1082
1069
  observability: tt,
1083
- port: ee,
1084
- ...p?.transport?.wsPath ? { path: p.transport.wsPath } : {}
1070
+ port: p,
1071
+ ...m?.transport?.wsPath ? { path: m.transport.wsPath } : {}
1085
1072
  });
1086
- s(re([
1087
- w.queries,
1088
- w.mutations,
1089
- w.actions,
1090
- w.streams
1073
+ c(ie([
1074
+ C.queries,
1075
+ C.mutations,
1076
+ C.actions,
1077
+ C.streams
1091
1078
  ]), (e) => {
1092
1079
  $.warn(e);
1093
- }), $.info(`API listening on :${ee}`, {
1094
- dialect: m,
1095
- queries: w.queries.length,
1096
- mutations: w.mutations.length,
1097
- actions: w.actions.length,
1098
- streams: w.streams.length,
1099
- workflows: w.workflows.length,
1100
- workflowWorkers: w.workflowWorkers.length,
1101
- schedules: w.schedules.length,
1102
- scheduleCoordination: yt
1103
- }), o.finish($);
1104
- let It = () => {
1105
- for (let e of Ze) e.stop();
1106
- Ve.detach(), He.stop(), Pe(), qe?.dispose(), Promise.resolve(et.deactivate()).then(() => nt?.close()).then(() => O.dispose()).then(() => Pt.close()).then(() => P.close?.()).then(() => process.exit(0));
1080
+ }), $.info(`API listening on :${p}`, {
1081
+ dialect: h,
1082
+ queries: C.queries.length,
1083
+ mutations: C.mutations.length,
1084
+ actions: C.actions.length,
1085
+ streams: C.streams.length,
1086
+ workflows: C.workflows.length,
1087
+ workflowWorkers: C.workflowWorkers.length,
1088
+ schedules: C.schedules.length,
1089
+ scheduleCoordination: W
1090
+ }), s.finish($);
1091
+ let Ft = () => {
1092
+ for (let e of Xe) e.stop();
1093
+ Ve.detach(), He.stop(), I(), qe?.dispose(), Promise.resolve(et.deactivate()).then(() => nt?.close()).then(() => D.dispose()).then(() => At.close()).then(() => N.close?.()).then(() => process.exit(0));
1107
1094
  };
1108
- return process.on("SIGINT", It), process.on("SIGTERM", It), await new Promise(() => {}), 0;
1095
+ return process.on("SIGINT", Ft), process.on("SIGTERM", Ft), await new Promise(() => {}), 0;
1109
1096
  };
1110
1097
  //#endregion
1111
- export { hn as n, un as r, gn as t };
1098
+ export { gn as n, dn as r, _n as t };