@voltro/cli 0.26.0 → 0.27.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.
- package/CHANGELOG.md +297 -0
- package/dist/apiBuild-BrjrVJJh.js +2 -0
- package/dist/{apiBuild-BtrTyKnF.js → apiBuild-D22_EpoR.js} +1 -1
- package/dist/bin.js +1 -1
- package/dist/{commands-D-9iYF2D.js → commands-jBX8no1I.js} +23 -23
- package/dist/{dev-BnWq4jeA.js → dev-DNkso403.js} +1 -1
- package/dist/{dev-Dbm6SWtn.js → dev-DcbIJrWg.js} +1777 -1718
- package/dist/index.js +1 -1
- package/dist/serveCommand-DfkisVWP.js +1310 -0
- package/dist/serveEntry.js +1 -1
- package/package.json +17 -17
- package/templates/AGENTS.md +1 -1
- package/templates/agent-docs/_index.md +1 -1
- package/templates/agent-docs/data.md +219 -0
- package/templates/agent-docs/plugins.md +28 -0
- package/templates/agent-docs/whats-new.md +128 -310
- package/templates/apps/api-ai/package.json +7 -7
- package/templates/apps/api-auth/package.json +8 -8
- package/templates/apps/api-backend/package.json +7 -7
- package/templates/apps/api-backend-deactivation/package.json +7 -7
- package/templates/apps/api-backend-mail/package.json +8 -8
- package/templates/apps/api-backend-mariadb/package.json +9 -9
- package/templates/apps/api-backend-storage/package.json +8 -8
- package/templates/apps/api-data-advanced/package.json +8 -8
- package/templates/apps/api-durable/package.json +8 -8
- package/templates/apps/api-feature-flags/package.json +9 -9
- package/templates/apps/api-governance/package.json +8 -8
- package/templates/apps/api-kv/package.json +8 -8
- package/templates/apps/api-moderation/package.json +8 -8
- package/templates/apps/api-observability/package.json +8 -8
- package/templates/apps/api-ratelimit/package.json +8 -8
- package/templates/apps/api-rbac/package.json +8 -8
- package/templates/apps/api-rest/package.json +7 -7
- package/templates/apps/api-saas/package.json +11 -11
- package/templates/apps/api-search/package.json +8 -8
- package/templates/apps/api-versioning/package.json +8 -8
- package/templates/apps/api-webhooks/package.json +9 -9
- package/templates/apps/changelog/package.json +6 -6
- package/templates/apps/edge-functions/package.json +2 -2
- package/templates/apps/frontend-admin/package.json +8 -8
- package/templates/apps/frontend-app/package.json +8 -8
- package/templates/apps/frontend-blank/package.json +7 -7
- package/templates/apps/frontend-contact/package.json +7 -7
- package/templates/apps/frontend-dashboard/package.json +7 -7
- package/templates/apps/frontend-docs/package.json +7 -7
- package/templates/apps/frontend-i18n/package.json +6 -6
- package/templates/apps/frontend-landing/package.json +7 -7
- package/templates/apps/frontend-spa/package.json +7 -7
- package/templates/apps/frontend-ssr/package.json +7 -7
- package/templates/apps/frontend-ssr-api/package.json +8 -8
- package/templates/apps/frontend-static-blog/package.json +6 -6
- package/dist/apiBuild-DDJ0It4j.js +0 -2
- package/dist/serveCommand-XBXuwJty.js +0 -1294
|
@@ -1,1294 +0,0 @@
|
|
|
1
|
-
import { ot as e, t } from "./inspectMetrics-BU90mvJN.js";
|
|
2
|
-
import { s as n } from "./seedRunner-D6eu-u5U.js";
|
|
3
|
-
import { r, t as i } from "./appModuleLoader-C9r9mxZt.js";
|
|
4
|
-
import { $ as a, A as o, B as s, D as c, E as l, F as u, G as d, H as f, I as p, J as ee, K as m, L as te, M as ne, N as re, O as h, P as ie, R as ae, S as oe, St as se, T as ce, U as le, V as g, W as ue, X as _, Y as de, Z as fe, _ as pe, _t as v, b as y, bt as me, c as he, ct as ge, dt as b, et as x, ft as _e, g as ve, gt as ye, h as be, ht as xe, i as Se, j as S, k as Ce, lt as we, mt as C, nt as Te, o as w, pt as T, q as Ee, r as De, t as Oe, tt as ke, u as Ae, ut as je, v as Me, vt as E, w as Ne, x as D, xt as Pe, y as Fe, z as Ie } from "./dev-Dbm6SWtn.js";
|
|
5
|
-
import { _ as O, f as k, m as Le, n as Re, p as ze, u as Be, v as Ve } from "./frameworkTableAssembly-BwHU9Euq.js";
|
|
6
|
-
import { u as He } from "./fileConventions-3bffWssN.js";
|
|
7
|
-
import { p as Ue } from "./inspect-CUCCzw2I.js";
|
|
8
|
-
import { r as We, u as Ge } from "./apiBuild-BtrTyKnF.js";
|
|
9
|
-
import { t as Ke } from "./bootTiming-BdyP9nYw.js";
|
|
10
|
-
import { n as qe } from "./cliArgs-qdZSElM3.js";
|
|
11
|
-
import { basename as Je, join as A } from "node:path";
|
|
12
|
-
import { pathToFileURL as j } from "node:url";
|
|
13
|
-
import { Cause as Ye, Effect as M, Layer as N, ManagedRuntime as Xe } from "effect";
|
|
14
|
-
import { createLogger as P } from "@voltro/logger";
|
|
15
|
-
import { existsSync as Ze } from "node:fs";
|
|
16
|
-
import { AggregateRegistry as Qe, Dispatcher as $e, apiKeyManagementRoutes as et, applySoftDeleteScope as tt, applyTenantScope as nt, attachAnalyticsMirror as rt, awaitServerListening as it, bindMutation as F, bindStream as at, bindSubscription as I, buildTracingLayer as L, cancelWakeup as ot, compileCron as st, dataStoreApiKeyStore as ct, dataStoreIdempotencyStore as lt, formatServerOnlyLeaks as R, formatUnresolvedSources as ut, frameworkApiKeyStrategy as dt, installPolicyGuardResolver as ft, loadResourceTuples as pt, makeActionRunner as mt, makeAdvisoryLockCoordinator as ht, makeApiKeyService as gt, makeApiKeyUsageBuffer as _t, makeApiKeyUsageFlusher as vt, makeAsyncKv as yt, makeCoordinatedScheduler as bt, makeEffectStoreLayer as xt, makeLazyWorkflowFacade as St, makeMutationOutputCodec as Ct, makeMutationRunner as wt, makeOneShotQueryRunner as Tt, makeQueryDescriptorProducer as Et, makeQueryReauthorizer as Dt, makeQuerySubscriber as Ot, makeSchemaRegistry as kt, makeWorkflowFacade as At, makeWorkflowFacadeWithCallerContext as jt, makeWorkflowLayers as Mt, noopKv as Nt, onProcessShutdown as Pt, recordSubscriptionDelivery as z, recordWorkflowRun as Ft, registerWakeup as It, resolveSecretsBackend as Lt, runProvidedEffect as Rt, setSecretsBackend as zt, setSystemStoreHandle as Bt, setTupleSource as Vt, singleCoordinator as Ht, startRpcServer as Ut, startScheduler as Wt, workflowToRpc as B, wrapStoreWithBootCodec as Gt } from "@voltro/runtime";
|
|
17
|
-
import { RpcGroup as V } from "@effect/rpc";
|
|
18
|
-
import { SqlClient as Kt } from "@effect/sql";
|
|
19
|
-
import { and as qt, ensureTableRegistered as Jt, eq as H, or as Yt } from "@voltro/database";
|
|
20
|
-
import { appStorageProvider as U, fromNodeReadable as Xt, getObjectStream as Zt, putObjectStream as Qt, toNodeReadable as W } from "@voltro/plugin-storage";
|
|
21
|
-
import { AuthMiddleware as $t, ConnectionInfoMiddleware as G, actionToRpc as K, anonymousSubject as en, isWireReachable as tn, mutationToRpc as nn, queryToRpc as q, streamToRpc as rn, workflowCancelDescriptor as an, workflowDomainEventsQueryDescriptor as J, workflowEventDeliveriesQueryDescriptor as on, workflowResumeDescriptor as sn, workflowRunEventsQueryDescriptor as Y, workflowRunQueryDescriptor as X, workflowRunStepsQueryDescriptor as cn, workflowRunsQueryDescriptor as Z, workflowSignalDescriptor as ln, workflowUpdateDescriptor as un } from "@voltro/protocol";
|
|
22
|
-
import { assertProductionSessionSecret as dn, sessionExpiryFromHeaders as fn } from "@voltro/protocol/session";
|
|
23
|
-
import { createHash as pn, timingSafeEqual as mn } from "node:crypto";
|
|
24
|
-
import { declaredSnapshot as hn, describeOutcome as gn, runPlannedMigrations as _n } from "@voltro/database/sql";
|
|
25
|
-
import { getAuthSessionStrategy as vn } from "@voltro/plugin-auth";
|
|
26
|
-
import { collectPublicApiRoutes as yn, restRoutesToHttpRoutes as bn } from "@voltro/protocol/rest";
|
|
27
|
-
import { buildDeliverWebhookExecute as xn, buildWebhooksService as Sn, defaultIncomingPath as Cn, deliverWebhookWorkflow as wn, mountIncomingWebhook as Tn } from "@voltro/plugin-webhooks";
|
|
28
|
-
import { channelFor as En, getBroadcastPlugin as Dn } from "@voltro/plugin-broadcast";
|
|
29
|
-
import { packBundle as On, runExport as kn, runImport as An, storageBlobSink as jn, storageRefsBlobSource as Mn, unpackBundle as Nn, unpackBundleToDir as Pn } from "@voltro/data-transfer";
|
|
30
|
-
//#region src/bootRefusal.ts
|
|
31
|
-
var Fn = "VoltroBootRefusal", In = (e) => {
|
|
32
|
-
let t = Error(e);
|
|
33
|
-
return t.name = Fn, t;
|
|
34
|
-
}, Ln = "/_voltro/admin/import", Rn = "/_voltro/admin/export", Q = (e, t) => ({
|
|
35
|
-
status: e,
|
|
36
|
-
contentType: "application/json; charset=utf-8",
|
|
37
|
-
body: JSON.stringify(t)
|
|
38
|
-
}), zn = (e) => {
|
|
39
|
-
let t = e.authorization ?? e.Authorization, n = t ? /^Bearer\s+(.+)$/i.exec(t) : null;
|
|
40
|
-
return n ? n[1] : null;
|
|
41
|
-
}, Bn = (e, t) => mn(pn("sha256").update(e).digest(), pn("sha256").update(t).digest()), Vn = (e, t) => {
|
|
42
|
-
if (e.method.toUpperCase() !== "POST") return Q(405, { error: "method not allowed" });
|
|
43
|
-
if (!t || t.length < 16) return Q(503, { error: "data transfer misconfigured (no/weak secret)" });
|
|
44
|
-
let n = zn(e.headers);
|
|
45
|
-
return !n || !Bn(n, t) ? Q(401, { error: "unauthorized" }) : null;
|
|
46
|
-
}, Hn = P({ scope: "voltro:admin-import" }), Un = "VBUNDLE2", Wn = async function* (e) {
|
|
47
|
-
yield e;
|
|
48
|
-
}, Gn = (e) => async (t) => {
|
|
49
|
-
let n = Vn(t, e.secret);
|
|
50
|
-
if (n) return n;
|
|
51
|
-
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") === Un, c, l;
|
|
52
|
-
if (s) c = Wn(t.rawBody), l = "upload";
|
|
53
|
-
else {
|
|
54
|
-
let n;
|
|
55
|
-
try {
|
|
56
|
-
n = JSON.parse(Buffer.from(t.rawBody).toString("utf8") || "{}");
|
|
57
|
-
} catch {
|
|
58
|
-
return Q(400, { error: "body must be a packed bundle archive or { bundleKey } JSON" });
|
|
59
|
-
}
|
|
60
|
-
if (typeof n.bundleKey != "string" || !n.bundleKey) return Q(400, { error: "body.bundleKey (string) is required for the storage transport" });
|
|
61
|
-
if (!e.openArchive) return Q(501, { error: "storage transport not configured on this instance" });
|
|
62
|
-
c = e.openArchive(n.bundleKey), l = "storage";
|
|
63
|
-
}
|
|
64
|
-
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-"));
|
|
65
|
-
try {
|
|
66
|
-
e.assetSink ? await Nn(c, {
|
|
67
|
-
dir: p,
|
|
68
|
-
blobs: e.assetSink
|
|
69
|
-
}) : await Pn(c, p);
|
|
70
|
-
let t = await M.runPromiseExit(An({
|
|
71
|
-
store: e.store,
|
|
72
|
-
bundleDir: p,
|
|
73
|
-
...r ? { mode: r } : {},
|
|
74
|
-
...i ? { onConflict: i } : {},
|
|
75
|
-
...a ? { atomic: a } : {},
|
|
76
|
-
...e.snapshot ? { targetSnapshot: e.snapshot } : {},
|
|
77
|
-
force: o,
|
|
78
|
-
onWarn: (e) => Hn.warn("admin.import", { message: e }),
|
|
79
|
-
...e.assetSink ? { assetsAlreadyRestored: !0 } : {}
|
|
80
|
-
}));
|
|
81
|
-
if (t._tag === "Failure") {
|
|
82
|
-
let e = t.cause._tag === "Fail" ? t.cause.error : void 0;
|
|
83
|
-
if (e && e._tag === "SchemaDriftError") {
|
|
84
|
-
let t = e;
|
|
85
|
-
return Hn.warn("admin.import refused (schema drift)", {
|
|
86
|
-
transport: l,
|
|
87
|
-
bundle: t.bundleFingerprint.slice(0, 16),
|
|
88
|
-
target: t.targetFingerprint.slice(0, 16)
|
|
89
|
-
}), Q(409, {
|
|
90
|
-
error: "schema drift",
|
|
91
|
-
bundleFingerprint: t.bundleFingerprint,
|
|
92
|
-
targetFingerprint: t.targetFingerprint,
|
|
93
|
-
diff: t.diff,
|
|
94
|
-
hint: "re-export against the current schema, or resend with x-import-force: 1"
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
throw Error(String(e?.message ?? e ?? "import failed"));
|
|
98
|
-
}
|
|
99
|
-
let n = t.value, s = n.tables.reduce((e, t) => e + t.rowCount, 0);
|
|
100
|
-
return Hn.info("admin.import", {
|
|
101
|
-
transport: l,
|
|
102
|
-
tables: n.tables.length,
|
|
103
|
-
rows: s,
|
|
104
|
-
mode: r ?? "upsert",
|
|
105
|
-
atomic: a
|
|
106
|
-
}), Q(200, {
|
|
107
|
-
tables: n.tables.length,
|
|
108
|
-
rows: s,
|
|
109
|
-
transport: l
|
|
110
|
-
});
|
|
111
|
-
} catch (e) {
|
|
112
|
-
return Hn.warn("admin.import failed", {
|
|
113
|
-
transport: l,
|
|
114
|
-
error: e?.message ?? String(e)
|
|
115
|
-
}), Q(500, {
|
|
116
|
-
error: "import failed",
|
|
117
|
-
message: e?.message ?? String(e)
|
|
118
|
-
});
|
|
119
|
-
} finally {
|
|
120
|
-
await d.rm(p, {
|
|
121
|
-
recursive: !0,
|
|
122
|
-
force: !0
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}, Kn = P({ scope: "voltro:admin-export" }), qn = async (e) => {
|
|
126
|
-
let t = [];
|
|
127
|
-
for await (let n of e) t.push(Buffer.from(n));
|
|
128
|
-
return new Uint8Array(Buffer.concat(t));
|
|
129
|
-
}, Jn = (e) => typeof e.tenant == "string" && e.tenant ? {
|
|
130
|
-
kind: "tenant",
|
|
131
|
-
tenantId: e.tenant
|
|
132
|
-
} : Array.isArray(e.tables) && e.tables.length ? {
|
|
133
|
-
kind: "tables",
|
|
134
|
-
tables: e.tables.filter((e) => typeof e == "string")
|
|
135
|
-
} : { kind: "all" }, Yn = (e) => async (t) => {
|
|
136
|
-
let n = Vn(t, e.secret);
|
|
137
|
-
if (n) return n;
|
|
138
|
-
let r;
|
|
139
|
-
try {
|
|
140
|
-
r = JSON.parse(Buffer.from(t.rawBody).toString("utf8") || "{}");
|
|
141
|
-
} catch {
|
|
142
|
-
return Q(400, { error: "body must be JSON: { profile?, tenant?, tables?, consistency?, compression?, bundleKey? }" });
|
|
143
|
-
}
|
|
144
|
-
let i = {};
|
|
145
|
-
if (typeof r.profile == "string" && r.profile) {
|
|
146
|
-
if (!e.loadProfile) return Q(501, { error: "server-side profiles not configured on this instance" });
|
|
147
|
-
try {
|
|
148
|
-
i = await e.loadProfile(r.profile);
|
|
149
|
-
} catch (e) {
|
|
150
|
-
return Q(400, {
|
|
151
|
-
error: `profile '${r.profile}' could not be loaded`,
|
|
152
|
-
message: e?.message ?? String(e)
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
let a = r.consistency === "snapshot" ? "snapshot" : i.consistency ?? "live", o = (typeof r.compression == "string" ? r.compression : void 0) ?? i.compression, s = i.scope ?? Jn(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-"));
|
|
157
|
-
try {
|
|
158
|
-
let t = await M.runPromise(kn({
|
|
159
|
-
store: e.store,
|
|
160
|
-
snapshot: e.snapshot,
|
|
161
|
-
dialect: e.dialect,
|
|
162
|
-
outDir: p,
|
|
163
|
-
...i.subset ? { subset: i.subset } : {
|
|
164
|
-
scope: s,
|
|
165
|
-
...e.tenantTables && e.tenantTables.length > 0 ? { tenantTables: e.tenantTables } : {}
|
|
166
|
-
},
|
|
167
|
-
consistency: a,
|
|
168
|
-
...o ? { compression: o } : {},
|
|
169
|
-
...i.masking ? { masking: i.masking } : {}
|
|
170
|
-
})), n = t.tables.reduce((e, t) => e + t.rowCount, 0), u = t.masking?.transformed.length ?? 0;
|
|
171
|
-
if (c) {
|
|
172
|
-
if (!e.putArchive) return Q(501, { error: "storage transport not configured on this instance" });
|
|
173
|
-
let i = r.bundleKey;
|
|
174
|
-
return await e.putArchive(i, () => On({
|
|
175
|
-
dir: p,
|
|
176
|
-
...l
|
|
177
|
-
})), Kn.info("admin.export", {
|
|
178
|
-
transport: "storage",
|
|
179
|
-
tables: t.tables.length,
|
|
180
|
-
rows: n,
|
|
181
|
-
masked: u,
|
|
182
|
-
bundleKey: i
|
|
183
|
-
}), Q(200, {
|
|
184
|
-
bundleKey: i,
|
|
185
|
-
tables: t.tables.length,
|
|
186
|
-
rows: n,
|
|
187
|
-
masked: u,
|
|
188
|
-
transport: "storage"
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
let d = await qn(On({
|
|
192
|
-
dir: p,
|
|
193
|
-
...l
|
|
194
|
-
}));
|
|
195
|
-
return Kn.info("admin.export", {
|
|
196
|
-
transport: "download",
|
|
197
|
-
tables: t.tables.length,
|
|
198
|
-
rows: n,
|
|
199
|
-
masked: u,
|
|
200
|
-
bytes: d.byteLength
|
|
201
|
-
}), {
|
|
202
|
-
status: 200,
|
|
203
|
-
contentType: "application/octet-stream",
|
|
204
|
-
body: d,
|
|
205
|
-
headers: {
|
|
206
|
-
"x-export-tables": String(t.tables.length),
|
|
207
|
-
"x-export-rows": String(n),
|
|
208
|
-
"x-export-masked": String(u)
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
} catch (e) {
|
|
212
|
-
return Kn.warn("admin.export failed", { error: e?.message ?? String(e) }), Q(500, {
|
|
213
|
-
error: "export failed",
|
|
214
|
-
message: e?.message ?? String(e)
|
|
215
|
-
});
|
|
216
|
-
} finally {
|
|
217
|
-
await d.rm(p, {
|
|
218
|
-
recursive: !0,
|
|
219
|
-
force: !0
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}, Xn = async (e) => {
|
|
223
|
-
let { resolve: t } = await import("node:path"), { existsSync: n } = await import("node:fs"), r = [
|
|
224
|
-
e,
|
|
225
|
-
`${e}.profile.ts`,
|
|
226
|
-
`data-profiles/${e}.ts`,
|
|
227
|
-
`data-profiles/${e}.profile.ts`
|
|
228
|
-
].map((e) => t(process.cwd(), e)), i = r.find((e) => n(e));
|
|
229
|
-
if (!i) throw Error(`data profile '${e}' not found (looked for: ${r.join(", ")})`);
|
|
230
|
-
let a = await import(i), o = a.default ?? a.profile;
|
|
231
|
-
if (!o) throw Error(`data profile '${i}' has no default export`);
|
|
232
|
-
return o;
|
|
233
|
-
}, Zn = (e, t, n = {}) => (async function* () {
|
|
234
|
-
let r = await W((await M.runPromise(Zt(e, t).pipe(M.timeout(n.openTimeout ?? "30 seconds")))).stream), i = n.stallMs ?? 12e4, a, o = () => {
|
|
235
|
-
a && clearTimeout(a), a = setTimeout(() => r.destroy(/* @__PURE__ */ Error(`storage read stalled for ${i}ms reading '${t}'`)), i);
|
|
236
|
-
};
|
|
237
|
-
try {
|
|
238
|
-
o();
|
|
239
|
-
for await (let e of r) o(), yield e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
240
|
-
} finally {
|
|
241
|
-
a && clearTimeout(a), r.destroy();
|
|
242
|
-
}
|
|
243
|
-
})(), Qn = {
|
|
244
|
-
get: async () => void 0,
|
|
245
|
-
set: async () => {},
|
|
246
|
-
setWithTags: async () => {},
|
|
247
|
-
remove: async () => !1,
|
|
248
|
-
has: async () => !1,
|
|
249
|
-
clear: async () => {},
|
|
250
|
-
invalidateTag: async () => 0,
|
|
251
|
-
wrap: async (e, t, n) => n()
|
|
252
|
-
}, $n = async (e) => {
|
|
253
|
-
Bt({
|
|
254
|
-
dataStore: e.store,
|
|
255
|
-
schemaRegistry: e.schemaRegistry
|
|
256
|
-
});
|
|
257
|
-
let t = new $e({
|
|
258
|
-
store: e.store,
|
|
259
|
-
...e.snapshotCache ? { cache: e.snapshotCache } : {},
|
|
260
|
-
recordDelivery: (e) => z({
|
|
261
|
-
label: e.label,
|
|
262
|
-
kind: e.kind,
|
|
263
|
-
durationMs: e.durationMs,
|
|
264
|
-
rowCount: e.rowCount
|
|
265
|
-
})
|
|
266
|
-
}), n = e.cache ?? Qn, r = e.kv ?? Nt, i, a, c, d, f, ee = /* @__PURE__ */ new Map(), te = () => `wfctx_${globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`}`, ne = async (t, n, r) => {
|
|
267
|
-
let i = {
|
|
268
|
-
...r,
|
|
269
|
-
source: r.source ?? `workflow:${t}`
|
|
270
|
-
};
|
|
271
|
-
ee.set(n, i);
|
|
272
|
-
try {
|
|
273
|
-
let r = await e.store.query({
|
|
274
|
-
table: "_voltro_workflow_start_contexts",
|
|
275
|
-
order: [],
|
|
276
|
-
predicate: H("executionId", n),
|
|
277
|
-
projection: ["id"],
|
|
278
|
-
skip: void 0,
|
|
279
|
-
take: 1
|
|
280
|
-
}), a = {
|
|
281
|
-
workflowName: t,
|
|
282
|
-
executionId: n,
|
|
283
|
-
subject: i.subject ?? null,
|
|
284
|
-
traceId: i.traceId ?? null,
|
|
285
|
-
source: i.source ?? null,
|
|
286
|
-
parentExecutionId: i.parentExecutionId ?? null,
|
|
287
|
-
parentClosePolicy: i.parentClosePolicy ?? null,
|
|
288
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
289
|
-
};
|
|
290
|
-
r[0] === void 0 ? await e.store.insert("_voltro_workflow_start_contexts", {
|
|
291
|
-
id: te(),
|
|
292
|
-
...a
|
|
293
|
-
}) : await e.store.update("_voltro_workflow_start_contexts", r[0].id, a);
|
|
294
|
-
} catch (e) {
|
|
295
|
-
process.stderr.write(`[workflow] failed to persist start context for ${t}/${n}: ${e?.message ?? String(e)}\n`);
|
|
296
|
-
}
|
|
297
|
-
}, re = async (t, n) => {
|
|
298
|
-
let r = ee.get(n);
|
|
299
|
-
if (r !== void 0) return r;
|
|
300
|
-
try {
|
|
301
|
-
let t = (await e.store.query({
|
|
302
|
-
table: "_voltro_workflow_start_contexts",
|
|
303
|
-
order: [],
|
|
304
|
-
predicate: H("executionId", n),
|
|
305
|
-
projection: void 0,
|
|
306
|
-
skip: void 0,
|
|
307
|
-
take: 1
|
|
308
|
-
}))[0];
|
|
309
|
-
if (t === void 0) return;
|
|
310
|
-
let r = {
|
|
311
|
-
...t.subject === null ? {} : { subject: t.subject },
|
|
312
|
-
...t.traceId === null ? {} : { traceId: t.traceId },
|
|
313
|
-
...t.source === null ? {} : { source: t.source },
|
|
314
|
-
...t.parentExecutionId === null ? {} : { parentExecutionId: t.parentExecutionId },
|
|
315
|
-
...t.parentClosePolicy === null ? {} : { parentClosePolicy: t.parentClosePolicy }
|
|
316
|
-
};
|
|
317
|
-
return ee.set(n, r), r;
|
|
318
|
-
} catch (e) {
|
|
319
|
-
process.stderr.write(`[workflow] failed to load start context for ${n}: ${e?.message ?? String(e)}\n`);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
}, h = (e.discovered.workflows?.length ?? 0) > 0 ? St(() => i) : void 0, ie = (e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.eventTriggers?.length ?? 0) > 0, ae = ie || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster", le = e.tenantIsolation === "namespace", ue = (e.log ?? P({ scope: "voltro:serve" })).child("webhooks"), fe, v = e.discovered.webhooks;
|
|
323
|
-
if (v && v.outgoing.length > 0 && e.workflowEngineLayer !== void 0) {
|
|
324
|
-
let t = e.workflowEngineLayer, i = T({
|
|
325
|
-
store: e.store,
|
|
326
|
-
schemaRegistry: e.schemaRegistry,
|
|
327
|
-
cache: n,
|
|
328
|
-
kv: r
|
|
329
|
-
}), a = v.outgoing.map((e) => e.descriptor);
|
|
330
|
-
fe = Sn(i, async (e) => {
|
|
331
|
-
let n = wn.execute(e).pipe(M.provide(wn.toLayer(xn(i, { events: a })).pipe(N.provideMerge(t))));
|
|
332
|
-
M.runPromise(n).catch((t) => {
|
|
333
|
-
ue.error("deliverWebhook workflow crashed", {
|
|
334
|
-
deliveryId: e.deliveryId,
|
|
335
|
-
targetId: e.targetId
|
|
336
|
-
}, t);
|
|
337
|
-
});
|
|
338
|
-
}, { events: a });
|
|
339
|
-
}
|
|
340
|
-
let me = /* @__PURE__ */ new Map();
|
|
341
|
-
if (v) for (let e of v.incoming) {
|
|
342
|
-
let t = e.descriptor.path ?? Cn(e.descriptor.id), n = `VOLTRO_WEBHOOK_SECRET_${e.descriptor.id.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`, r = Tn(e.descriptor, {
|
|
343
|
-
resolveSecret: async () => process.env[n] ?? null,
|
|
344
|
-
resolveWorkflows: () => h === void 0 ? void 0 : jt(h, {
|
|
345
|
-
traceId: `incoming:${e.descriptor.id}`,
|
|
346
|
-
source: `incoming:${e.descriptor.id}`
|
|
347
|
-
}),
|
|
348
|
-
log: (e) => {
|
|
349
|
-
let t = {
|
|
350
|
-
webhookId: e.webhookId,
|
|
351
|
-
status: e.status,
|
|
352
|
-
signatureOk: String(e.signatureOk),
|
|
353
|
-
idempotency: e.idempotency,
|
|
354
|
-
durationMs: e.durationMs
|
|
355
|
-
};
|
|
356
|
-
e.status >= 500 ? ue.error("incoming delivery failed", t) : e.status >= 400 ? ue.warn("incoming delivery rejected", t) : ue.info("incoming delivery handled", t);
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
me.set(t, { handle: r });
|
|
360
|
-
}
|
|
361
|
-
ft(), Vt((t) => pt(e.store, t.subjectId, t.resourceType, t.resourceId));
|
|
362
|
-
let he = (e.discovered.outboxHandlers?.length ?? 0) > 0 ? de({
|
|
363
|
-
handlers: e.discovered.outboxHandlers ?? [],
|
|
364
|
-
store: e.store,
|
|
365
|
-
log: (e.log ?? P({ scope: "voltro:serve" })).child("outbox")
|
|
366
|
-
}) : void 0, x = Ee({
|
|
367
|
-
definitions: (e.discovered.connections ?? []).map((e) => e.definition),
|
|
368
|
-
store: e.store,
|
|
369
|
-
publicUrl: m(e.port ?? 4e3),
|
|
370
|
-
log: (e.log ?? P({ scope: "voltro:serve" })).child("connections")
|
|
371
|
-
});
|
|
372
|
-
y({
|
|
373
|
-
events: e.discovered.events ?? [],
|
|
374
|
-
rpcTags: [
|
|
375
|
-
...e.discovered.queries.map((e) => e.descriptor.name),
|
|
376
|
-
...e.discovered.mutations.map((e) => e.descriptor.name),
|
|
377
|
-
...e.discovered.actions.map((e) => e.descriptor.name),
|
|
378
|
-
...(e.discovered.streams ?? []).map((e) => e.descriptor.name)
|
|
379
|
-
]
|
|
380
|
-
});
|
|
381
|
-
let ve = (e.log ?? P({ scope: "voltro:serve" })).child("events"), ye = e.broadcastNamespace ?? pe(e.plugins, void 0), be = Me(e.plugins, ye, ve), xe = e.membership?.instanceId ?? process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, Se = e.membership ?? Fe(e.plugins, {
|
|
382
|
-
instanceId: xe,
|
|
383
|
-
namespace: ye,
|
|
384
|
-
meta: { mode: "serve" },
|
|
385
|
-
logger: ve
|
|
386
|
-
}), S = D({
|
|
387
|
-
events: e.discovered.events ?? [],
|
|
388
|
-
origin: xe,
|
|
389
|
-
...be.publishRemote === void 0 ? {} : { publishRemote: be.publishRemote }
|
|
390
|
-
}), we = (e.discovered.events ?? []).length > 0 ? await be.attach(S.bus) : null, C = _e({
|
|
391
|
-
store: e.store,
|
|
392
|
-
schemaRegistry: e.schemaRegistry,
|
|
393
|
-
cache: n,
|
|
394
|
-
kv: r,
|
|
395
|
-
...fe === void 0 ? {} : { webhooksService: fe },
|
|
396
|
-
...h === void 0 ? {} : { workflowsProxy: h },
|
|
397
|
-
eventTriggers: e.discovered.eventTriggers ?? [],
|
|
398
|
-
namespaceIsolationOn: le,
|
|
399
|
-
...he === void 0 ? {} : { outbox: { nudge: he.nudge } },
|
|
400
|
-
...x.active ? { connections: { registry: x.registry } } : {},
|
|
401
|
-
eventBus: S.bus
|
|
402
|
-
}), Te = N.succeed(Qe, p), w = (t, n) => {
|
|
403
|
-
let r = t.pipe(M.provide(xt(n)));
|
|
404
|
-
return (e.baseLayer ? r.pipe(M.provide(e.baseLayer)) : r).pipe(M.provide(Te));
|
|
405
|
-
}, De = (e, t) => Rt(w(e, t)), Oe = wt({
|
|
406
|
-
store: e.store,
|
|
407
|
-
buildContext: (e, t, n) => C(e, t, n),
|
|
408
|
-
runEffect: De,
|
|
409
|
-
undoCapture: o()
|
|
410
|
-
}), ke = Ce(), Ae = mt({
|
|
411
|
-
buildContext: (e) => C(e),
|
|
412
|
-
runEffect: De
|
|
413
|
-
}), je = {
|
|
414
|
-
buildContext: (e) => C(e),
|
|
415
|
-
finalize: (t, n) => tt(nt(t, e.tenantScopedTables, n.subject.tenantId), e.softDeleteScopedTables),
|
|
416
|
-
provideEffect: w
|
|
417
|
-
}, E = Et(je), Pe = Tt({
|
|
418
|
-
...je,
|
|
419
|
-
queryRows: (t) => e.store.query(t)
|
|
420
|
-
}), Ie = Ot({
|
|
421
|
-
...je,
|
|
422
|
-
subscribeDescriptor: (e, n, r) => t.subscribe(e, n, r),
|
|
423
|
-
subscribeComputed: (e, n, r) => t.subscribeComputed(e, n, r)
|
|
424
|
-
}), O = (e) => e.filter((e) => tn(e.descriptor)), k = {};
|
|
425
|
-
for (let n of [
|
|
426
|
-
...O(e.discovered.queries),
|
|
427
|
-
...ke.queries,
|
|
428
|
-
...x.queries
|
|
429
|
-
]) k[n.descriptor.name] = (e) => I(E(n, e), t, `subscription.${n.descriptor.name}`, void 0, void 0, Dt(n, e));
|
|
430
|
-
for (let t of [
|
|
431
|
-
...O(e.discovered.mutations),
|
|
432
|
-
...ke.mutations,
|
|
433
|
-
...x.mutations
|
|
434
|
-
]) {
|
|
435
|
-
let n = Ct(t.descriptor.output);
|
|
436
|
-
k[t.descriptor.name] = (r) => F(async (e, n) => Oe(t, e, n), r, `mutation.${t.descriptor.name}`, n, e.idempotency);
|
|
437
|
-
}
|
|
438
|
-
for (let t of [...O(e.discovered.actions), ...x.actions]) {
|
|
439
|
-
let n = Ct(t.descriptor.output);
|
|
440
|
-
k[t.descriptor.name] = (r) => F(async (e, n) => Ae(t, e, n), r, `action.${t.descriptor.name}`, n, e.idempotency);
|
|
441
|
-
}
|
|
442
|
-
let Le = () => `public-${Math.random().toString(36).slice(2, 10)}`, Re = [
|
|
443
|
-
...e.discovered.queries.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
444
|
-
descriptor: e.descriptor,
|
|
445
|
-
invoke: (t, n) => Pe(e, t, {
|
|
446
|
-
subject: n.subject,
|
|
447
|
-
traceId: Le()
|
|
448
|
-
}),
|
|
449
|
-
subscribe: (t, n, r) => Ie(e, t, {
|
|
450
|
-
subject: n.subject,
|
|
451
|
-
traceId: Le()
|
|
452
|
-
}, r)
|
|
453
|
-
})),
|
|
454
|
-
...e.discovered.mutations.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
455
|
-
descriptor: e.descriptor,
|
|
456
|
-
invoke: (t, n) => Oe(e, t, {
|
|
457
|
-
subject: n.subject,
|
|
458
|
-
traceId: Le()
|
|
459
|
-
})
|
|
460
|
-
})),
|
|
461
|
-
...e.discovered.actions.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
462
|
-
descriptor: e.descriptor,
|
|
463
|
-
invoke: (t, n) => Ae(e, t, {
|
|
464
|
-
subject: n.subject,
|
|
465
|
-
traceId: Le()
|
|
466
|
-
})
|
|
467
|
-
}))
|
|
468
|
-
], ze = Re.length > 0 ? bn(yn(Re), {
|
|
469
|
-
store: e.store,
|
|
470
|
-
resolveSubject: (t) => e.resolveSubject(t, -1)
|
|
471
|
-
}) : [], Be = e.dataTransferSecret ?? process.env.VOLTRO_DATA_TRANSFER_SECRET, Ve = Be && Be.length >= 16 ? [{
|
|
472
|
-
method: "POST",
|
|
473
|
-
path: Ln,
|
|
474
|
-
handle: Gn({
|
|
475
|
-
secret: Be,
|
|
476
|
-
store: e.store,
|
|
477
|
-
...e.dataTransferSnapshot ? { snapshot: e.dataTransferSnapshot } : {},
|
|
478
|
-
assetSink: jn(U()),
|
|
479
|
-
openArchive: (e) => Zn(U(), e)
|
|
480
|
-
})
|
|
481
|
-
}, {
|
|
482
|
-
method: "POST",
|
|
483
|
-
path: Rn,
|
|
484
|
-
handle: Yn({
|
|
485
|
-
secret: Be,
|
|
486
|
-
store: e.store,
|
|
487
|
-
snapshot: e.dataTransferSnapshot ?? { tables: [] },
|
|
488
|
-
dialect: e.dataTransferDialect ?? "memory",
|
|
489
|
-
tenantTables: [...e.tenantScopedTables],
|
|
490
|
-
loadProfile: Xn,
|
|
491
|
-
assetSource: Mn(U(), e.store),
|
|
492
|
-
putArchive: async (e, t) => {
|
|
493
|
-
let { Readable: n } = await import("node:stream"), r = U(), i = Xt("storage", () => n.from(t()));
|
|
494
|
-
await M.runPromise(Qt(r, e, i, { contentType: "application/octet-stream" }));
|
|
495
|
-
}
|
|
496
|
-
})
|
|
497
|
-
}] : [], He = [
|
|
498
|
-
...e.httpRoutes ?? [],
|
|
499
|
-
...ze,
|
|
500
|
-
...Ve,
|
|
501
|
-
...x.httpRoutes
|
|
502
|
-
];
|
|
503
|
-
Object.assign(k, S.handlers);
|
|
504
|
-
for (let t of O(e.discovered.streams ?? [])) k[t.descriptor.name] = (n) => at((r) => {
|
|
505
|
-
let i = C(r), a = t.executor(n, i);
|
|
506
|
-
if (M.isEffect(a)) {
|
|
507
|
-
let t = a.pipe(M.provide(xt(i.store)));
|
|
508
|
-
return (e.baseLayer ? t.pipe(M.provide(e.baseLayer)) : t).pipe(M.provide(Te));
|
|
509
|
-
}
|
|
510
|
-
return typeof a == "object" && a && typeof a.then == "function" ? M.promise(() => a) : a;
|
|
511
|
-
}, `stream.${t.descriptor.name}`);
|
|
512
|
-
for (let t of e.discovered.workflows ?? []) k[t.definition.name] = (e) => F(async (e, n) => {
|
|
513
|
-
let r = n;
|
|
514
|
-
return jt(h, {
|
|
515
|
-
subject: r.subject,
|
|
516
|
-
traceId: r.traceId,
|
|
517
|
-
source: "workflow-rpc"
|
|
518
|
-
}).start(t.definition.name, e);
|
|
519
|
-
}, e, `workflow.${t.definition.name}`);
|
|
520
|
-
ie && (k[X.name] = (e) => I(E({
|
|
521
|
-
descriptor: X,
|
|
522
|
-
executor: (e) => {
|
|
523
|
-
let t = e.id;
|
|
524
|
-
return {
|
|
525
|
-
table: "_voltro_workflow_runs",
|
|
526
|
-
order: [{
|
|
527
|
-
column: "startedAt",
|
|
528
|
-
direction: "desc"
|
|
529
|
-
}],
|
|
530
|
-
predicate: Yt(H("id", t), H("executionId", t)),
|
|
531
|
-
take: 1,
|
|
532
|
-
skip: void 0,
|
|
533
|
-
projection: void 0
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
}, e), t, `subscription.${X.name}`), k[Z.name] = (e) => I(E({
|
|
537
|
-
descriptor: Z,
|
|
538
|
-
executor: (e) => {
|
|
539
|
-
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;
|
|
540
|
-
return {
|
|
541
|
-
table: "_voltro_workflow_runs",
|
|
542
|
-
order: [{
|
|
543
|
-
column: "startedAt",
|
|
544
|
-
direction: "desc"
|
|
545
|
-
}],
|
|
546
|
-
predicate: n.length === 0 ? void 0 : n.length === 1 ? n[0] : qt(...n),
|
|
547
|
-
take: r,
|
|
548
|
-
skip: void 0,
|
|
549
|
-
projection: void 0
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
}, e), t, `subscription.${Z.name}`), k[cn.name] = (e) => I(E({
|
|
553
|
-
descriptor: cn,
|
|
554
|
-
executor: (e) => {
|
|
555
|
-
let t = e.runId;
|
|
556
|
-
return {
|
|
557
|
-
table: "_voltro_workflow_run_steps",
|
|
558
|
-
order: [{
|
|
559
|
-
column: "startedAt",
|
|
560
|
-
direction: "asc"
|
|
561
|
-
}],
|
|
562
|
-
predicate: H("runId", t),
|
|
563
|
-
take: 1e3,
|
|
564
|
-
skip: void 0,
|
|
565
|
-
projection: void 0
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
}, e), t, `subscription.${cn.name}`), k[Y.name] = (e) => I(E({
|
|
569
|
-
descriptor: Y,
|
|
570
|
-
executor: (e) => {
|
|
571
|
-
let t = e.runId;
|
|
572
|
-
return {
|
|
573
|
-
table: "_voltro_workflow_run_events",
|
|
574
|
-
order: [{
|
|
575
|
-
column: "occurredAt",
|
|
576
|
-
direction: "asc"
|
|
577
|
-
}],
|
|
578
|
-
predicate: H("runId", t),
|
|
579
|
-
take: 1e3,
|
|
580
|
-
skip: void 0,
|
|
581
|
-
projection: void 0
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
}, e), t, `subscription.${Y.name}`), k[J.name] = (e) => I(E({
|
|
585
|
-
descriptor: J,
|
|
586
|
-
executor: (e) => {
|
|
587
|
-
let t = e;
|
|
588
|
-
return {
|
|
589
|
-
table: "_voltro_workflow_events",
|
|
590
|
-
order: [{
|
|
591
|
-
column: "occurredAt",
|
|
592
|
-
direction: "desc"
|
|
593
|
-
}],
|
|
594
|
-
predicate: t.name === void 0 ? void 0 : H("name", t.name),
|
|
595
|
-
take: Math.max(1, Math.min(500, t.limit ?? 100)),
|
|
596
|
-
skip: void 0,
|
|
597
|
-
projection: void 0
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
}, e), t, `subscription.${J.name}`), k[on.name] = (e) => I(E({
|
|
601
|
-
descriptor: on,
|
|
602
|
-
executor: (e) => {
|
|
603
|
-
let t = e.eventId;
|
|
604
|
-
return {
|
|
605
|
-
table: "_voltro_workflow_event_deliveries",
|
|
606
|
-
order: [{
|
|
607
|
-
column: "createdAt",
|
|
608
|
-
direction: "asc"
|
|
609
|
-
}],
|
|
610
|
-
predicate: H("eventId", t),
|
|
611
|
-
take: 500,
|
|
612
|
-
skip: void 0,
|
|
613
|
-
projection: void 0
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
}, e), t, `subscription.${on.name}`), k[an.name] = (t) => F(async (t, n) => {
|
|
617
|
-
let r = t;
|
|
618
|
-
return await b(e.store, n.subject, { executionId: r.executionId }), await h.cancel(r.workflowName, r.executionId), await Ze(r.workflowName, r.executionId, "workflow.cancel"), { ok: !0 };
|
|
619
|
-
}, t, `action.${an.name}`), k[sn.name] = (t) => F(async (t, n) => {
|
|
620
|
-
let r = t;
|
|
621
|
-
return await b(e.store, n.subject, { executionId: r.executionId }), await h.resume(r.workflowName, r.executionId), { ok: !0 };
|
|
622
|
-
}, t, `action.${sn.name}`), k[ln.name] = (t) => F(async (t, n) => {
|
|
623
|
-
let r = t;
|
|
624
|
-
return await b(e.store, n.subject, { id: r.id }), h.signal({ id: r.id }, r.signalName, r.payload);
|
|
625
|
-
}, t, `action.${ln.name}`), k[un.name] = (t) => F(async (t, n) => {
|
|
626
|
-
let r = t;
|
|
627
|
-
return await b(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 });
|
|
628
|
-
}, t, `action.${un.name}`));
|
|
629
|
-
let Ue = [
|
|
630
|
-
...O(e.discovered.queries).map((e) => q(e.descriptor)),
|
|
631
|
-
...O(e.discovered.mutations).map((e) => nn(e.descriptor)),
|
|
632
|
-
...O(e.discovered.actions).map((e) => K(e.descriptor)),
|
|
633
|
-
...ke.queries.map((e) => q(e.descriptor)),
|
|
634
|
-
...ke.mutations.map((e) => nn(e.descriptor)),
|
|
635
|
-
...x.queries.map((e) => q(e.descriptor)),
|
|
636
|
-
...x.mutations.map((e) => nn(e.descriptor)),
|
|
637
|
-
...x.actions.map((e) => K(e.descriptor)),
|
|
638
|
-
...O(e.discovered.streams ?? []).map((e) => rn(e.descriptor)),
|
|
639
|
-
...S.rpcs,
|
|
640
|
-
...(e.discovered.workflows ?? []).map((e) => B(e.definition)),
|
|
641
|
-
...ie ? [
|
|
642
|
-
q(X),
|
|
643
|
-
q(Z),
|
|
644
|
-
q(cn),
|
|
645
|
-
q(Y),
|
|
646
|
-
q(J),
|
|
647
|
-
q(on),
|
|
648
|
-
K(an),
|
|
649
|
-
K(sn),
|
|
650
|
-
K(ln),
|
|
651
|
-
K(un)
|
|
652
|
-
] : []
|
|
653
|
-
], We = V.make(...Ue).middleware($t).middleware(G), Ge = N.succeed($t, $t.of(({ headers: t, clientId: n }) => M.promise(() => e.resolveSubject(t, n)))), Ke = N.succeed(G, G.of(({ headers: e, clientId: t }) => M.sync(() => {
|
|
654
|
-
let n = fn(e);
|
|
655
|
-
return {
|
|
656
|
-
clientId: t,
|
|
657
|
-
...e["idempotency-key"] ? { idempotencyKey: e["idempotency-key"] } : {},
|
|
658
|
-
...n === void 0 ? {} : { credentialExpiresAt: n }
|
|
659
|
-
};
|
|
660
|
-
}))), qe = e.dormancyTenantId ?? "default", Je = e.dormancy === "sleep" ? {
|
|
661
|
-
register: (t, n, r) => It(e.store, {
|
|
662
|
-
tenantId: r ?? qe,
|
|
663
|
-
kind: "workflow",
|
|
664
|
-
refId: t,
|
|
665
|
-
wakeAt: n
|
|
666
|
-
}),
|
|
667
|
-
cancel: (t, n) => ot(e.store, {
|
|
668
|
-
tenantId: n ?? qe,
|
|
669
|
-
kind: "workflow",
|
|
670
|
-
refId: t
|
|
671
|
-
}).then(() => {})
|
|
672
|
-
} : void 0, A = ae ? await import("@voltro/workflow") : void 0, j = A?.makeWorkflowRunRecorder({
|
|
673
|
-
store: e.store,
|
|
674
|
-
...Je === void 0 ? {} : { wakeups: Je }
|
|
675
|
-
}), Ye = async (t, n) => {
|
|
676
|
-
await A.closeWorkflowChildrenForParent({
|
|
677
|
-
store: e.store,
|
|
678
|
-
parentExecutionId: t,
|
|
679
|
-
parentStatus: n,
|
|
680
|
-
recorder: j,
|
|
681
|
-
log: { warn: (e, t) => {
|
|
682
|
-
process.stderr.write(`[workflow] ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
683
|
-
} },
|
|
684
|
-
interruptChild: async (t, n) => {
|
|
685
|
-
let r = (e.discovered.workflows ?? []).find((e) => e.definition.name === t);
|
|
686
|
-
if (!r) throw Error(`Unknown child workflow: ${t}`);
|
|
687
|
-
if (!a) throw Error("Workflow runtime is not ready");
|
|
688
|
-
await a.runPromise(r.definition.interrupt(n));
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
}, Ze = async (t, n, r) => {
|
|
692
|
-
let i = (await e.store.query({
|
|
693
|
-
table: "_voltro_workflow_runs",
|
|
694
|
-
order: [],
|
|
695
|
-
predicate: H("executionId", n),
|
|
696
|
-
projection: void 0,
|
|
697
|
-
skip: void 0,
|
|
698
|
-
take: 1
|
|
699
|
-
}))[0];
|
|
700
|
-
if (i === void 0) return;
|
|
701
|
-
let a = await e.store.update("_voltro_workflow_runs", i.id, {
|
|
702
|
-
status: "cancelled",
|
|
703
|
-
cancelled: !0,
|
|
704
|
-
completedAt: /* @__PURE__ */ new Date()
|
|
705
|
-
}), o = i.subject?.tenantId ?? void 0;
|
|
706
|
-
a && await j.recordEvent({
|
|
707
|
-
runId: i.id,
|
|
708
|
-
eventType: "run-cancelled",
|
|
709
|
-
payload: {
|
|
710
|
-
reason: r,
|
|
711
|
-
workflowName: t,
|
|
712
|
-
executionId: n,
|
|
713
|
-
...o == null ? {} : { tenantId: o }
|
|
714
|
-
}
|
|
715
|
-
}), a && await Ye(n, "cancelled");
|
|
716
|
-
}, et = [...Mt(e.discovered.workflows ?? [], {
|
|
717
|
-
buildContext: (t, n) => e.buildContextForWorkflow?.(t, n) ?? C({
|
|
718
|
-
subject: t.subject,
|
|
719
|
-
traceId: t.traceId
|
|
720
|
-
}, e.store, void 0, `workflow:${n.workflowName}`, { parentExecutionId: n.executionId }),
|
|
721
|
-
resolveStartContext: re
|
|
722
|
-
}, (t, n, r) => {
|
|
723
|
-
let i = A.getWorkflowVersionMetadata(t.definition);
|
|
724
|
-
return A.wrapWorkflowExecuteWithRunRecording({
|
|
725
|
-
name: t.definition.name,
|
|
726
|
-
store: e.store,
|
|
727
|
-
subject: r.subject,
|
|
728
|
-
source: r.source ?? null,
|
|
729
|
-
traceId: r.traceId,
|
|
730
|
-
workflowVersion: i.version,
|
|
731
|
-
workflowCompatibleVersions: i.compatibleWith,
|
|
732
|
-
workflowPatches: i.patches,
|
|
733
|
-
parentExecutionId: r?.parentExecutionId ?? null,
|
|
734
|
-
parentClosePolicy: r?.parentClosePolicy ?? null,
|
|
735
|
-
onParentClose: ({ executionId: e, status: t }) => Ye(e, t),
|
|
736
|
-
recorder: j,
|
|
737
|
-
recordRun: Ft
|
|
738
|
-
}, n);
|
|
739
|
-
}), ...e.discovered.workflowWorkers ?? []], rt = et.length > 0 ? N.mergeAll(...et) : N.empty;
|
|
740
|
-
if (((e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster") && e.workflowEngineLayer !== void 0) {
|
|
741
|
-
let t = rt.pipe(N.provideMerge(e.workflowEngineLayer));
|
|
742
|
-
a = Xe.make(e.baseLayer === void 0 ? t : t.pipe(N.provideMerge(e.baseLayer))), await a.runPromise(M.void);
|
|
743
|
-
let n = await import("@voltro/workflow/cluster"), r = (e) => a.runPromise(n.redriveFailedRun(e));
|
|
744
|
-
d = await se({
|
|
745
|
-
provider: Dn(e.plugins ?? [])?.broadcast?.provider,
|
|
746
|
-
crossReplica: Dn(e.plugins ?? [])?.broadcast?.crossReplica ?? !1,
|
|
747
|
-
namespace: ye,
|
|
748
|
-
replicaId: crypto.randomUUID(),
|
|
749
|
-
pollStorage: () => a.runPromise(n.pollWorkflowStorage),
|
|
750
|
-
log: (e.log ?? P({ scope: "voltro:serve" })).child("workflow")
|
|
751
|
-
}), c = async (t) => {
|
|
752
|
-
let n = await ce({
|
|
753
|
-
store: e.store,
|
|
754
|
-
workflows: e.discovered.workflows ?? [],
|
|
755
|
-
runRedrive: r
|
|
756
|
-
}, t.runId);
|
|
757
|
-
return n.statusReset && await j.recordEvent({
|
|
758
|
-
runId: t.runId,
|
|
759
|
-
eventType: "run-redriven",
|
|
760
|
-
payload: {
|
|
761
|
-
reason: "inspect.redrive",
|
|
762
|
-
activitiesReset: n.outcome.activitiesReset
|
|
763
|
-
}
|
|
764
|
-
}), {
|
|
765
|
-
redriven: n.outcome.redriven,
|
|
766
|
-
activitiesReset: n.outcome.activitiesReset,
|
|
767
|
-
reason: n.outcome.reason
|
|
768
|
-
};
|
|
769
|
-
}, i = (e.discovered.workflows?.length ?? 0) > 0 ? At({
|
|
770
|
-
workflows: e.discovered.workflows ?? [],
|
|
771
|
-
runEffect: (e) => a.runPromise(e),
|
|
772
|
-
onEnqueue: () => d?.publishWake(),
|
|
773
|
-
rememberStartContext: ne,
|
|
774
|
-
signal: async (t, n, r) => {
|
|
775
|
-
let i = await A.sendWorkflowSignal({
|
|
776
|
-
store: e.store,
|
|
777
|
-
recorder: j,
|
|
778
|
-
target: t,
|
|
779
|
-
signalName: n,
|
|
780
|
-
payload: r
|
|
781
|
-
});
|
|
782
|
-
return await a.runPromise(A.completeSuspendingSignal({
|
|
783
|
-
store: e.store,
|
|
784
|
-
target: t,
|
|
785
|
-
signalName: n,
|
|
786
|
-
payload: r
|
|
787
|
-
})).catch(() => {}), i;
|
|
788
|
-
},
|
|
789
|
-
update: (t, n, r, i) => A.sendWorkflowUpdate({
|
|
790
|
-
store: e.store,
|
|
791
|
-
recorder: j,
|
|
792
|
-
target: t,
|
|
793
|
-
updateName: n,
|
|
794
|
-
payload: r,
|
|
795
|
-
...i === void 0 ? {} : { options: i }
|
|
796
|
-
}),
|
|
797
|
-
listRuns: (t) => Ne(e.store, t),
|
|
798
|
-
retry: (t, n) => l({
|
|
799
|
-
store: e.store,
|
|
800
|
-
workflows: e.discovered.workflows ?? [],
|
|
801
|
-
runPromise: (e) => a.runPromise(e)
|
|
802
|
-
}, t, n),
|
|
803
|
-
redrive: (t) => ce({
|
|
804
|
-
store: e.store,
|
|
805
|
-
workflows: e.discovered.workflows ?? [],
|
|
806
|
-
runRedrive: r
|
|
807
|
-
}, t).then((e) => e.outcome)
|
|
808
|
-
}) : void 0;
|
|
809
|
-
}
|
|
810
|
-
let st = N.mergeAll(We.toLayer(k), Ge, Ke), ct = ge(k, e.discovered.queries.map((e) => e.descriptor.name), ie), lt = N.mergeAll(We.toLayer(ct), Ge, Ke), R = e.observability, ut = await L({
|
|
811
|
-
...R && R.spanProcessors.length > 0 ? { extraSpanProcessors: R.spanProcessors } : {},
|
|
812
|
-
...R && R.metricReaders.length > 0 ? { extraMetricReaders: R.metricReaders } : {},
|
|
813
|
-
...R && Object.keys(R.resourceAttributes).length > 0 ? { resourceAttributes: R.resourceAttributes } : {},
|
|
814
|
-
...R && R.sampler !== void 0 ? { sampler: R.sampler } : {}
|
|
815
|
-
}), dt = !1, gt = e.store.ping ? () => e.store.ping().then(() => !0).catch(() => !1) : void 0, { server: _t, shutdown: vt } = Ut({
|
|
816
|
-
group: We,
|
|
817
|
-
handlersLayer: st,
|
|
818
|
-
httpHandlersLayer: lt,
|
|
819
|
-
port: e.port ?? 4e3,
|
|
820
|
-
...e.host === void 0 ? {} : { host: e.host },
|
|
821
|
-
path: e.path ?? "/ws",
|
|
822
|
-
tracerLayer: ut.layer,
|
|
823
|
-
healthCheck: {
|
|
824
|
-
isReady: () => dt,
|
|
825
|
-
...gt ? { ping: gt } : {}
|
|
826
|
-
},
|
|
827
|
-
...He.length > 0 ? { httpRoutes: He } : {},
|
|
828
|
-
...e.getStore === void 0 ? {} : { getStore: e.getStore },
|
|
829
|
-
...me.size > 0 ? { webhookRoutes: me } : {},
|
|
830
|
-
...e.inspectRoute === void 0 ? {} : { inspectRoute: e.inspectRoute }
|
|
831
|
-
});
|
|
832
|
-
if (await it(_t), (e.discovered.schedules?.length ?? 0) > 0) {
|
|
833
|
-
let t = (e.scheduleCoordination ?? "single") === "advisoryLock" ? ht(e.store, e.scheduleReplicaId ?? `pid-${process.pid}`) : Ht;
|
|
834
|
-
f = await Wt(e.discovered.schedules ?? [], {
|
|
835
|
-
store: e.store,
|
|
836
|
-
coordinator: t,
|
|
837
|
-
defaultTrigger: e.scheduleDefaultTrigger ?? "self",
|
|
838
|
-
replicaId: e.scheduleReplicaId ?? `pid-${process.pid}`,
|
|
839
|
-
armSelf: e.scheduleArmSelf ?? !0,
|
|
840
|
-
dormancy: e.dormancy ?? "always-on",
|
|
841
|
-
...e.dormancyTenantId === void 0 ? {} : { dormancyTenantId: e.dormancyTenantId },
|
|
842
|
-
buildContext: ({ traceId: t, scheduleName: n, subject: r }) => C({
|
|
843
|
-
subject: r,
|
|
844
|
-
traceId: t
|
|
845
|
-
}, e.store, void 0, `schedule:${n}`),
|
|
846
|
-
log: {
|
|
847
|
-
info: (e, t) => {
|
|
848
|
-
process.stdout.write(`[schedule] ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
849
|
-
},
|
|
850
|
-
warn: (e, t) => {
|
|
851
|
-
process.stderr.write(`[schedule] ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
852
|
-
},
|
|
853
|
-
error: (e, t) => {
|
|
854
|
-
process.stderr.write(`[schedule] ERROR ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
855
|
-
},
|
|
856
|
-
debug: () => {}
|
|
857
|
-
},
|
|
858
|
-
...e.scheduleFireInterceptor === void 0 ? {} : { interceptFire: e.scheduleFireInterceptor },
|
|
859
|
-
...e.onScheduleRunEvent === void 0 ? {} : { onRunEvent: e.onScheduleRunEvent }
|
|
860
|
-
}), e.onSchedulerReady?.(f);
|
|
861
|
-
}
|
|
862
|
-
let yt = e.log ?? P({ scope: "voltro:serve" }), bt, kt;
|
|
863
|
-
if ((e.discovered.subscribers?.length ?? 0) > 0 && (bt = _(e.discovered.subscribers ?? [], e.store, yt.child("subscribe"), e.schemaRegistry, S.bus)), (e.discovered.reactions?.length ?? 0) > 0) {
|
|
864
|
-
let t = yt.child("reaction");
|
|
865
|
-
kt = s(e.discovered.reactions ?? [], e.store, {
|
|
866
|
-
runAct: async (n, r) => {
|
|
867
|
-
if (n.kind === "workflow") {
|
|
868
|
-
if (h === void 0) {
|
|
869
|
-
t.warn("reaction workflow act skipped — no workflow engine in this app", { workflow: n.workflow });
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
let e = r.new ?? r.old ?? {};
|
|
873
|
-
await jt(h, {
|
|
874
|
-
traceId: `reaction:${n.workflow}`,
|
|
875
|
-
source: `reaction:${n.workflow}`
|
|
876
|
-
}).start(n.workflow, e);
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
879
|
-
await g(n.agent, r, {
|
|
880
|
-
findAgentSend: (t) => e.discovered.actions.find((e) => e.descriptor.name === `${t}.send`),
|
|
881
|
-
runAction: (e, t, n) => Promise.resolve(Ae(e, t, n)),
|
|
882
|
-
makeSubject: (e) => en(e),
|
|
883
|
-
now: () => Date.now(),
|
|
884
|
-
log: t
|
|
885
|
-
});
|
|
886
|
-
},
|
|
887
|
-
checkBudget: async (n, r) => {
|
|
888
|
-
try {
|
|
889
|
-
let { requireAiBudget: t } = await import("@voltro/ai");
|
|
890
|
-
return (await M.runPromise(M.either(t(e.store, {
|
|
891
|
-
tenantId: n,
|
|
892
|
-
limitUsd: r
|
|
893
|
-
}))))._tag === "Right";
|
|
894
|
-
} catch (e) {
|
|
895
|
-
return t.warn("reaction budget check failed — refusing the act", { tenantId: n }, e), !1;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
}, t);
|
|
899
|
-
}
|
|
900
|
-
let Pt;
|
|
901
|
-
return (e.discovered.aggregates?.length ?? 0) > 0 && (Pt = await u({
|
|
902
|
-
discovered: e.discovered.aggregates ?? [],
|
|
903
|
-
store: e.store,
|
|
904
|
-
log: yt.child("aggregate"),
|
|
905
|
-
...e.analytics === void 0 ? {} : { analytics: e.analytics },
|
|
906
|
-
...e.aggregateStorage === void 0 ? {} : { storage: e.aggregateStorage },
|
|
907
|
-
...e.aggregateCoordinator === void 0 ? {} : { coordinator: e.aggregateCoordinator }
|
|
908
|
-
}), Te = N.succeed(Qe, Pt.registry)), dt = !0, e.bootTiming?.mark("ready"), {
|
|
909
|
-
dispatcher: t,
|
|
910
|
-
server: _t,
|
|
911
|
-
scheduler: f,
|
|
912
|
-
eventsSnapshot: oe(S.bus, S.declared),
|
|
913
|
-
membersSnapshot: () => ({
|
|
914
|
-
members: Se.membership.list(),
|
|
915
|
-
capturedAt: Date.now()
|
|
916
|
-
}),
|
|
917
|
-
redriveWorkflowRun: (e) => c ? c(e) : Promise.reject(/* @__PURE__ */ Error("redrive: this app registers no workflows")),
|
|
918
|
-
close: async () => {
|
|
919
|
-
dt = !1, await we?.detach(), await Se.detach(), Pt?.detach(), kt?.(), bt?.(), await f?.shutdown(), t.close(), await d?.detach(), await a?.dispose(), await new Promise((e) => _t.close(() => e())), await vt();
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
}, $ = P({ scope: "voltro:serve" }), er = (e, t, n) => (e === "production" || e === "staging") && t !== "memory" && n !== "0", tr = qe, nr = async (e) => {
|
|
923
|
-
let t = Ge(process.cwd());
|
|
924
|
-
if (Ze(t)) {
|
|
925
|
-
let n;
|
|
926
|
-
try {
|
|
927
|
-
let e = await import(j(t).href);
|
|
928
|
-
typeof e.runServe == "function" ? n = e.runServe : $.warn("serve bundle has no runServe export — using the standard serve path");
|
|
929
|
-
} catch (e) {
|
|
930
|
-
$.warn("serve bundle failed to load — using the standard serve path", {}, e);
|
|
931
|
-
}
|
|
932
|
-
if (n) return $.info("serve: booting from the precompiled serve bundle"), n(e);
|
|
933
|
-
}
|
|
934
|
-
return rr(e);
|
|
935
|
-
}, rr = async (o) => {
|
|
936
|
-
let s = Ke();
|
|
937
|
-
process.env.NODE_ENV || (process.env.NODE_ENV = "production");
|
|
938
|
-
try {
|
|
939
|
-
dn();
|
|
940
|
-
} catch (e) {
|
|
941
|
-
throw In(e instanceof Error ? e.message : String(e));
|
|
942
|
-
}
|
|
943
|
-
let l = process.cwd(), u = Number(process.env.PORT ?? tr(o, "--port") ?? 4e3), p = await he(l);
|
|
944
|
-
zt(Lt(p?.secrets)), await e({
|
|
945
|
-
rawEnv: p?.env,
|
|
946
|
-
appType: "api",
|
|
947
|
-
root: l,
|
|
948
|
-
log: $,
|
|
949
|
-
generateTypes: !1
|
|
950
|
-
}), s.mark("config");
|
|
951
|
-
let m = (process.env.DB_DIALECT ?? p?.store ?? "memory").toLowerCase(), oe = (m === "mariadb" || m === "postgres" || m === "mssql") && (process.env.CDC ?? "1") !== "0", se = m === "mariadb" ? "mariadb" : m === "mssql" ? "mssql" : void 0, ce = We(l);
|
|
952
|
-
if (!i() && Ze(ce)) try {
|
|
953
|
-
let e = await import(j(ce).href);
|
|
954
|
-
if (e.modules) {
|
|
955
|
-
let t = {};
|
|
956
|
-
for (let [n, r] of Object.entries(e.modules)) t[A(l, n)] = r;
|
|
957
|
-
r(t), $.info("precompiled api bundle loaded", { modules: Object.keys(t).length });
|
|
958
|
-
}
|
|
959
|
-
} catch (e) {
|
|
960
|
-
$.warn("precompiled api bundle failed to load — falling back to source", {}, e);
|
|
961
|
-
}
|
|
962
|
-
let g = await be(l), _ = await Ae(g, { cdc: oe && se !== void 0 });
|
|
963
|
-
{
|
|
964
|
-
let e = /* @__PURE__ */ new Set([
|
|
965
|
-
..._.queries.filter((e) => e.descriptor.overridesPlugin === !0).map((e) => e.descriptor.name),
|
|
966
|
-
..._.mutations.filter((e) => e.descriptor.overridesPlugin === !0).map((e) => e.descriptor.name),
|
|
967
|
-
..._.actions.filter((e) => e.descriptor.overridesPlugin === !0).map((e) => e.descriptor.name)
|
|
968
|
-
]);
|
|
969
|
-
O(Ve(p?.plugins ?? []), [
|
|
970
|
-
..._.queries.map((e) => e.descriptor.name),
|
|
971
|
-
..._.mutations.map((e) => e.descriptor.name),
|
|
972
|
-
..._.actions.map((e) => e.descriptor.name),
|
|
973
|
-
..._.streams.map((e) => e.descriptor.name)
|
|
974
|
-
], e);
|
|
975
|
-
let t = ut(_.unresolvedSources);
|
|
976
|
-
t !== void 0 && $.warn(t);
|
|
977
|
-
let n = d(_.serverOnlyLeaks, ue(process.env, "strict"), R, "`voltro serve`");
|
|
978
|
-
if (n.action === "fail") throw In(n.message ?? "");
|
|
979
|
-
n.action === "warn" && $.warn(n.message ?? "");
|
|
980
|
-
}
|
|
981
|
-
let de = g.filter((e) => ne.test(e)), y = de.length > 0 ? await re(de, $.child("webhooks")) : {
|
|
982
|
-
outgoing: [],
|
|
983
|
-
incoming: [],
|
|
984
|
-
providers: []
|
|
985
|
-
}, ge = ie(_.events), b = y.outgoing.length + y.incoming.length + y.providers.length + ge.length === 0 ? void 0 : {
|
|
986
|
-
...y,
|
|
987
|
-
outgoing: [...y.outgoing, ...ge]
|
|
988
|
-
}, _e = Re({
|
|
989
|
-
mix: _.featureMix,
|
|
990
|
-
plugins: p?.plugins ?? [],
|
|
991
|
-
cdc: oe && se !== void 0,
|
|
992
|
-
...se ? { cdcDialect: se } : {}
|
|
993
|
-
}), Ce = p?.analytics !== void 0 && p.analytics.kind !== "noop" && m !== "memory" ? (await n(m)).makeSqlLayer(w()) : void 0, T = await x({
|
|
994
|
-
spec: p?.analytics,
|
|
995
|
-
sqlLayer: Ce,
|
|
996
|
-
log: $
|
|
997
|
-
}), Ee = (() => {
|
|
998
|
-
let e = new Set(_.tables.map((e) => e.tableName)), t = [..._.tables];
|
|
999
|
-
for (let n of [..._e, ...T.tables]) e.has(n.tableName) || (e.add(n.tableName), t.push(n));
|
|
1000
|
-
return t;
|
|
1001
|
-
})();
|
|
1002
|
-
for (let e of Ee) Jt(e);
|
|
1003
|
-
let Me = (process.env.NODE_ENV ?? "").toLowerCase();
|
|
1004
|
-
if (er(Me, m, process.env.VOLTRO_AUTO_MIGRATE)) {
|
|
1005
|
-
let e = (await n(m)).makeSqlLayer(w()), t = await M.runPromise(Kt.SqlClient.pipe(M.flatMap((e) => _n(e, Ee, {
|
|
1006
|
-
appliedBy: `serve:${Me}`,
|
|
1007
|
-
environment: "prod",
|
|
1008
|
-
dialectId: m
|
|
1009
|
-
})), M.provide(e)));
|
|
1010
|
-
t.kind === "prod-mismatch" && ($.error(gn(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(gn(t, m));
|
|
1011
|
-
}
|
|
1012
|
-
let Ne = kt(Ee);
|
|
1013
|
-
s.mark("discover");
|
|
1014
|
-
let D = await Se(p, void 0), Ge = Gt(D, m);
|
|
1015
|
-
for (let e of E({
|
|
1016
|
-
dialect: String(p?.store ?? process.env.DB_DIALECT ?? "postgres"),
|
|
1017
|
-
changeStrategy: (process.env.CDC ?? "1") === "0" ? "inline" : "cdc",
|
|
1018
|
-
dbUrl: process.env.DB_URL,
|
|
1019
|
-
tables: _.tables.map((e) => ({
|
|
1020
|
-
tableName: e.tableName,
|
|
1021
|
-
isReactive: e.isReactive === !0
|
|
1022
|
-
})),
|
|
1023
|
-
querySources: _.queries.flatMap((e) => {
|
|
1024
|
-
let t = e.descriptor.source;
|
|
1025
|
-
return t === void 0 ? [] : typeof t == "string" ? [t] : [...t];
|
|
1026
|
-
})
|
|
1027
|
-
})) e.level === "warn" ? $.warn(e.message) : $.info(e.message);
|
|
1028
|
-
{
|
|
1029
|
-
let e = v(ye({
|
|
1030
|
-
tables: _.tables.map((e) => ({ tableName: e.tableName })),
|
|
1031
|
-
queries: _.queries.map((e) => ({
|
|
1032
|
-
name: e.descriptor.name,
|
|
1033
|
-
source: e.descriptor.source
|
|
1034
|
-
}))
|
|
1035
|
-
}));
|
|
1036
|
-
e !== void 0 && $.warn(e);
|
|
1037
|
-
}
|
|
1038
|
-
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);
|
|
1039
|
-
let { service: qe, invalidationBus: P, snapshotCache: Qe, cache: $e, backend: tt, dispose: nt } = await xe({ env: process.env });
|
|
1040
|
-
$.info(`cache backend resolved: ${tt}` + (tt === "redis" ? ` (driver ${process.env.CACHE_REDIS_DRIVER ?? "resp"})` : " — in-process, not cross-instance")), D.onChange((e) => {
|
|
1041
|
-
M.runFork(P.publish(e.table));
|
|
1042
|
-
}), 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);
|
|
1043
|
-
let { kv: it, service: F } = await yt({ store: D });
|
|
1044
|
-
s.mark("store");
|
|
1045
|
-
let at = rt({
|
|
1046
|
-
store: D,
|
|
1047
|
-
sink: T.sink,
|
|
1048
|
-
log: $
|
|
1049
|
-
}), I = C({
|
|
1050
|
-
store: D,
|
|
1051
|
-
dialect: m
|
|
1052
|
-
}), L = p?.plugins ?? [], ot = process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, ft, pt;
|
|
1053
|
-
m !== "memory" && (ft = Xe.make((await n(m)).makeSqlLayer(w())), pt = await ft.runPromise(Kt.SqlClient));
|
|
1054
|
-
let mt = bt({
|
|
1055
|
-
coordinator: [
|
|
1056
|
-
"postgres",
|
|
1057
|
-
"mariadb",
|
|
1058
|
-
"mysql",
|
|
1059
|
-
"mssql"
|
|
1060
|
-
].includes(m) ? ht(D, ot, $) : Ht,
|
|
1061
|
-
replicaId: ot,
|
|
1062
|
-
log: $
|
|
1063
|
-
}), xt = [], St = process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, Ct = Dn(p?.plugins ?? [])?.broadcast?.provider, wt = pe(p?.plugins, p?.name ?? Je(l)), Tt = Fe(p?.plugins, {
|
|
1064
|
-
instanceId: St,
|
|
1065
|
-
namespace: wt,
|
|
1066
|
-
meta: { mode: "serve" },
|
|
1067
|
-
logger: $
|
|
1068
|
-
}), Et = {
|
|
1069
|
-
...pt ? { sql: pt } : {},
|
|
1070
|
-
instanceId: St,
|
|
1071
|
-
membership: Tt.membership,
|
|
1072
|
-
...Ct === void 0 ? {} : { broadcast: Ct },
|
|
1073
|
-
broadcastChannels: { presence: En(wt, "presence") },
|
|
1074
|
-
scheduleCoordinated: (e, t, n) => {
|
|
1075
|
-
let r = mt(e, t, n);
|
|
1076
|
-
return xt.push(r), r;
|
|
1077
|
-
}
|
|
1078
|
-
};
|
|
1079
|
-
for (let e of L) e.bindDataStore?.(D, Et);
|
|
1080
|
-
let Dt = L.filter((e) => typeof e.onChangeEvent == "function");
|
|
1081
|
-
if (Dt.length > 0) {
|
|
1082
|
-
let e = D.changeScope ?? "local";
|
|
1083
|
-
D.onChange((t) => {
|
|
1084
|
-
let n = le(t, e);
|
|
1085
|
-
for (let e of Dt) M.runFork(e.onChangeEvent(n).pipe(M.catchAllCause((t) => M.sync(() => $.warn(`plugin ${e.name} onChangeEvent failed`, { error: Ye.pretty(t) })))));
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
let Ot = h({
|
|
1089
|
-
plugins: L,
|
|
1090
|
-
appName: p?.name ?? "voltro-api",
|
|
1091
|
-
appType: "api",
|
|
1092
|
-
voltroVersion: process.env.npm_package_version ?? "0.0.0",
|
|
1093
|
-
log: $
|
|
1094
|
-
});
|
|
1095
|
-
L.length && await Ot.activate(), s.mark("plugins");
|
|
1096
|
-
let At = await Ot.gatherObservability(), jt = {
|
|
1097
|
-
info: (e, t) => process.stdout.write(`[broadcast] ${e} ${t ? JSON.stringify(t) : ""}\n`),
|
|
1098
|
-
warn: (e, t) => process.stderr.write(`[broadcast] ${e} ${t ? JSON.stringify(t) : ""}\n`),
|
|
1099
|
-
debug: () => {}
|
|
1100
|
-
}, Mt, Nt = await ve(D, p, m, wt, jt, (e, t) => {
|
|
1101
|
-
Mt?.refreshAll(`broadcast gap: missed ${t} change(s) from ${e}`);
|
|
1102
|
-
}), z = p?.apiKeys, Ft = (typeof z == "object" ? z.prefix : void 0) ?? "voltro_", It = z ? ct(D) : void 0, Rt = It ? _t({ flush: vt(It) }) : void 0;
|
|
1103
|
-
Rt && Pt(() => Rt.shutdown());
|
|
1104
|
-
let Bt = It ? gt(It, {
|
|
1105
|
-
prefix: Ft,
|
|
1106
|
-
...Rt ? { usage: Rt } : {}
|
|
1107
|
-
}) : void 0, Vt = Bt ? [dt(Bt, { prefix: Ft })] : [], Ut = De([...p?.auth?.strategies ?? [], ...Vt], vn(p?.plugins ?? []), p?.auth?.anonymousTenantRequired ?? !1, p?.auth?.resolveScopes, () => Ge), Wt = [...p?.restRoutes ?? [], ...Bt ? et(Bt, (typeof z == "object" ? z.managementPath : void 0) ?? "/v1/api-keys") : []], B = p?.idempotency, V = B ? {
|
|
1108
|
-
store: lt(D),
|
|
1109
|
-
header: (typeof B == "object" ? B.header : void 0) ?? "Idempotency-Key",
|
|
1110
|
-
ttlMs: (typeof B == "object" ? B.ttlMs : void 0) ?? 864e5
|
|
1111
|
-
} : void 0, qt = Wt.length > 0 ? bn(Wt, {
|
|
1112
|
-
store: D,
|
|
1113
|
-
resolveSubject: (e) => Ut({
|
|
1114
|
-
headers: e,
|
|
1115
|
-
clientId: -1
|
|
1116
|
-
}),
|
|
1117
|
-
...V ? { idempotency: V } : {}
|
|
1118
|
-
}) : [], H = L.map((e) => e.services).filter((e) => e !== void 0), Yt = N.mergeAll(je({
|
|
1119
|
-
analyticsLayer: T.layer,
|
|
1120
|
-
cacheService: qe,
|
|
1121
|
-
kvService: F,
|
|
1122
|
-
pluginServices: H,
|
|
1123
|
-
userLayers: p?.layers ?? []
|
|
1124
|
-
}), we(p?.http ?? {})), U = p?.scheduling ?? {}, Xt = U.trigger ?? "self", Zt = /* @__PURE__ */ new Set([
|
|
1125
|
-
"postgres",
|
|
1126
|
-
"mysql",
|
|
1127
|
-
"mariadb",
|
|
1128
|
-
"mssql"
|
|
1129
|
-
]), Qt = U.coordination ?? (Zt.has(m) ? "advisoryLock" : "single"), W = Qt === "cluster" && Zt.has(m), $t = W ? "cluster" : Qt === "advisoryLock" && Zt.has(m) ? "advisoryLock" : "single";
|
|
1130
|
-
Qt === "cluster" && !W && $.warn("scheduling.coordination=cluster needs a sql-backed store except sqlite — falling back to single"), Qt === "advisoryLock" && !Zt.has(m) && $.warn("scheduling.coordination=advisoryLock needs a SQL store (the claim-row gate) — falling back to single");
|
|
1131
|
-
let G, K = _.workflows.length > 0 || _.workflowWorkers.length > 0 || _.eventTriggers.length > 0 || (b?.outgoing.length ?? 0) > 0 || W, en;
|
|
1132
|
-
if (K) {
|
|
1133
|
-
if (m === "mssql") {
|
|
1134
|
-
let e = await a(process.cwd());
|
|
1135
|
-
e && $.warn(e);
|
|
1136
|
-
}
|
|
1137
|
-
let [{ WorkflowEngine: e }, { makeClusterCronLayer: t, workflowEngineLayer: r, resolveRunnerStorage: i, resolveFailoverTuning: o }] = await Promise.all([import("@effect/workflow"), import("@voltro/workflow/cluster")]), s = W ? _.schedules.filter((e) => (e.trigger ?? Xt) === "self").map((e) => t({
|
|
1138
|
-
name: e.name,
|
|
1139
|
-
cron: st(e),
|
|
1140
|
-
execute: async () => {
|
|
1141
|
-
await G?.fireFromCluster(e.name);
|
|
1142
|
-
}
|
|
1143
|
-
})) : [];
|
|
1144
|
-
en = m === "memory" ? e.layerMemory : await (async () => {
|
|
1145
|
-
let e = await n(m), t = i({ sqliteFamily: e.id === "sqlite" || e.id === "turso" });
|
|
1146
|
-
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)" : "") : "")), r({
|
|
1147
|
-
sqlClientLayer: e.makeSqlLayer(w()),
|
|
1148
|
-
runnerStorage: t,
|
|
1149
|
-
dialectId: e.id,
|
|
1150
|
-
...process.env.VOLTRO_WORKFLOW_RUNNER_PORT ? { runnerListenPort: Number(process.env.VOLTRO_WORKFLOW_RUNNER_PORT) } : {},
|
|
1151
|
-
...o(),
|
|
1152
|
-
...s.length > 0 ? { extraShardingLayers: s } : {}
|
|
1153
|
-
});
|
|
1154
|
-
})();
|
|
1155
|
-
}
|
|
1156
|
-
let tn = c(L, t()), nn = g.filter((e) => /\.subscribe\.tsx?$/.test(e)), q = nn.length > 0 ? await fe(nn, $) : [], rn = g.filter((e) => /\.reaction\.tsx?$/.test(e)), an = rn.length > 0 ? await f(rn, $) : [], J = g.filter((e) => He.test(e)), on = J.length > 0 ? await ee(J, $) : [], sn = g.filter((e) => /\.aggregate\.tsx?$/.test(e)), Y = sn.length > 0 ? await te(sn, $) : [], X = ae();
|
|
1157
|
-
if (Y.length > 0 && m !== "memory") try {
|
|
1158
|
-
X = Ie((await n(m)).makeSqlLayer(w()));
|
|
1159
|
-
} catch (e) {
|
|
1160
|
-
$.warn("aggregate: SQL storage init failed — falling back to in-process", { err: String(e) });
|
|
1161
|
-
}
|
|
1162
|
-
let cn = m === "memory" ? Ht : ht(D, `aggregate@${process.pid}`, $), Z = [], ln = [], un = g.filter((e) => Be.test(e));
|
|
1163
|
-
if (un.length > 0) {
|
|
1164
|
-
let e = $.child("agent"), t = g.filter((e) => k.test(e));
|
|
1165
|
-
t.length > 0 && await Le(t, e);
|
|
1166
|
-
let n = await ze(un, e);
|
|
1167
|
-
for (let e of n.agents) for (let t of S(e)) (t.kind === "action" ? Z : ln).push({
|
|
1168
|
-
file: t.file,
|
|
1169
|
-
descriptor: t.descriptor,
|
|
1170
|
-
executor: t.executor
|
|
1171
|
-
});
|
|
1172
|
-
n.agents.length > 0 && e.info("synthesized agent routes", { agents: n.agents.map((e) => e.descriptor.name) });
|
|
1173
|
-
}
|
|
1174
|
-
s.mark("workflow");
|
|
1175
|
-
let fn = await $n({
|
|
1176
|
-
bootTiming: s,
|
|
1177
|
-
broadcastNamespace: wt,
|
|
1178
|
-
membership: {
|
|
1179
|
-
...Tt,
|
|
1180
|
-
instanceId: St
|
|
1181
|
-
},
|
|
1182
|
-
...p?.plugins === void 0 ? {} : { plugins: p.plugins },
|
|
1183
|
-
...V ? { idempotency: {
|
|
1184
|
-
store: V.store,
|
|
1185
|
-
ttlMs: V.ttlMs
|
|
1186
|
-
} } : {},
|
|
1187
|
-
discovered: {
|
|
1188
|
-
queries: [..._.queries, ...ln],
|
|
1189
|
-
mutations: _.mutations,
|
|
1190
|
-
actions: [..._.actions, ...Z],
|
|
1191
|
-
streams: _.streams,
|
|
1192
|
-
events: _.events,
|
|
1193
|
-
workflows: _.workflows,
|
|
1194
|
-
workflowWorkers: _.workflowWorkers,
|
|
1195
|
-
eventTriggers: _.eventTriggers,
|
|
1196
|
-
schedules: _.schedules,
|
|
1197
|
-
subscribers: q,
|
|
1198
|
-
outboxHandlers: on,
|
|
1199
|
-
connections: _.connections,
|
|
1200
|
-
reactions: an,
|
|
1201
|
-
aggregates: Y,
|
|
1202
|
-
...b === void 0 ? {} : { webhooks: b }
|
|
1203
|
-
},
|
|
1204
|
-
log: $,
|
|
1205
|
-
analytics: T.sink,
|
|
1206
|
-
aggregateStorage: X,
|
|
1207
|
-
aggregateCoordinator: cn,
|
|
1208
|
-
store: D,
|
|
1209
|
-
kv: it,
|
|
1210
|
-
cache: $e,
|
|
1211
|
-
snapshotCache: Qe,
|
|
1212
|
-
schemaRegistry: Ne,
|
|
1213
|
-
tenantScopedTables: _.tenantScopedTables,
|
|
1214
|
-
softDeleteScopedTables: _.softDeleteScopedTables,
|
|
1215
|
-
dataTransferSnapshot: hn(Ee),
|
|
1216
|
-
dataTransferDialect: m,
|
|
1217
|
-
tenantIsolation: (process.env.VOLTRO_TENANT_ISOLATION ?? p?.tenancy?.isolation) === "namespace" ? "namespace" : "shared-schema",
|
|
1218
|
-
resolveSubject: (e, t) => Ut({
|
|
1219
|
-
headers: e,
|
|
1220
|
-
clientId: t
|
|
1221
|
-
}),
|
|
1222
|
-
httpRoutes: [...L.flatMap((e) => e.httpRoutes ?? []), ...qt],
|
|
1223
|
-
getStore: () => Ge,
|
|
1224
|
-
...Yt ? { baseLayer: Yt } : {},
|
|
1225
|
-
...en === void 0 ? {} : { workflowEngineLayer: en },
|
|
1226
|
-
scheduleDefaultTrigger: Xt,
|
|
1227
|
-
scheduleCoordination: $t,
|
|
1228
|
-
scheduleArmSelf: !W,
|
|
1229
|
-
dormancy: process.env.VOLTRO_DORMANCY === "sleep" || process.env.VOLTRO_DORMANCY === "always-on" ? process.env.VOLTRO_DORMANCY : p?.dormancy ?? "always-on",
|
|
1230
|
-
scheduleReplicaId: process.env.HOSTNAME ?? `pid-${process.pid}`,
|
|
1231
|
-
...tn === void 0 ? {} : { scheduleFireInterceptor: tn },
|
|
1232
|
-
onSchedulerReady: (e) => {
|
|
1233
|
-
G = e;
|
|
1234
|
-
},
|
|
1235
|
-
inspectRoute: { handle: (e, t, n, r) => Ue(e, {
|
|
1236
|
-
kind: "api",
|
|
1237
|
-
meta: {
|
|
1238
|
-
name: p?.name ?? "voltro-api",
|
|
1239
|
-
voltroVersion: Oe,
|
|
1240
|
-
port: u,
|
|
1241
|
-
mode: "start",
|
|
1242
|
-
store: m,
|
|
1243
|
-
cdc: oe ? "on" : "off"
|
|
1244
|
-
},
|
|
1245
|
-
rpc: me(_, l),
|
|
1246
|
-
workflows: Pe(_, l),
|
|
1247
|
-
events: () => fn.eventsSnapshot(),
|
|
1248
|
-
members: () => fn.membersSnapshot(),
|
|
1249
|
-
inspectFireSchedule: async ({ name: e, trigger: t }) => {
|
|
1250
|
-
if (!G) throw Error("scheduler not started — this app registers no self-triggered schedules (all schedules are trigger:'external', or there are none).");
|
|
1251
|
-
return { runId: await G.fireNow(e, t) ?? null };
|
|
1252
|
-
},
|
|
1253
|
-
inspectRedriveWorkflowRun: (e) => fn.redriveWorkflowRun(e)
|
|
1254
|
-
}, t, {
|
|
1255
|
-
method: n,
|
|
1256
|
-
...r === void 0 ? {} : { body: r }
|
|
1257
|
-
}) ?? {
|
|
1258
|
-
status: 404,
|
|
1259
|
-
contentType: "application/json",
|
|
1260
|
-
body: JSON.stringify({ error: "not an inspect route" })
|
|
1261
|
-
} },
|
|
1262
|
-
observability: At,
|
|
1263
|
-
port: u,
|
|
1264
|
-
...p?.transport?.wsPath ? { path: p.transport.wsPath } : {}
|
|
1265
|
-
});
|
|
1266
|
-
return Mt = fn.dispatcher, Te(ke([
|
|
1267
|
-
_.queries,
|
|
1268
|
-
_.mutations,
|
|
1269
|
-
_.actions,
|
|
1270
|
-
_.streams
|
|
1271
|
-
]), (e) => {
|
|
1272
|
-
$.warn(e);
|
|
1273
|
-
}), $.info(`API listening on :${u}`, {
|
|
1274
|
-
dialect: m,
|
|
1275
|
-
queries: _.queries.length,
|
|
1276
|
-
mutations: _.mutations.length,
|
|
1277
|
-
actions: _.actions.length,
|
|
1278
|
-
streams: _.streams.length,
|
|
1279
|
-
workflows: _.workflows.length,
|
|
1280
|
-
workflowWorkers: _.workflowWorkers.length,
|
|
1281
|
-
schedules: _.schedules.length,
|
|
1282
|
-
scheduleCoordination: $t
|
|
1283
|
-
}), s.finish($), Pt(async () => {
|
|
1284
|
-
for (let e of xt) e.stop();
|
|
1285
|
-
at.detach(), I.stop(), nt(), ft?.dispose();
|
|
1286
|
-
try {
|
|
1287
|
-
await Ot.deactivate(), await Nt?.close(), await T.dispose(), await fn.close(), await D.close?.();
|
|
1288
|
-
} catch (e) {
|
|
1289
|
-
console.error("serve: shutdown step failed, exiting anyway:", e);
|
|
1290
|
-
}
|
|
1291
|
-
}), await new Promise(() => {}), 0;
|
|
1292
|
-
};
|
|
1293
|
-
//#endregion
|
|
1294
|
-
export { nr as n, Xn as r, rr as t };
|