@voltro/cli 0.45.0 → 0.46.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 +176 -0
- package/dist/{apiBuild-CDQBNRDx.js → apiBuild-BKdd0I1Z.js} +2 -2
- package/dist/apiBuild-P2gewrfQ.js +2 -0
- package/dist/bin.d.ts +8 -0
- package/dist/bin.js +1 -1
- package/dist/{build-yvsLG77U.js → build-co6yadYz.js} +7 -7
- package/dist/{checkCommand-Boxov8lr.js → checkCommand-B-eiW-G_.js} +3 -3
- package/dist/{checkCommand-lrzwOzV1.js → checkCommand-CXAXTjZL.js} +1 -1
- package/dist/{codegenCommand-CQOLytL-.js → codegenCommand-CB6_3sX0.js} +15 -15
- package/dist/{codemodRunner-5ZhDH3rB.js → codemodRunner-DSZjgyCL.js} +8 -0
- package/dist/{commands-CEkVoFM5.js → commands-C-hxgAGr.js} +23 -23
- package/dist/{dashboardCommand-0ahyp-zA.js → dashboardCommand-CEVO0GWF.js} +3 -3
- package/dist/{dataCommand-D4IlZcih.js → dataCommand-k0ezbQWa.js} +271 -230
- package/dist/{dbCommand-B237qI-j.js → dbCommand-BwkyNxn-.js} +110 -110
- package/dist/dbCommand-C2XK63Dd.js +2 -0
- package/dist/{dev-DAM5CnAa.js → dev-8hTEnN6s.js} +2080 -2057
- package/dist/{dev-P4HyeY9W.js → dev-DyoYst4j.js} +1 -1
- package/dist/devActivity.d.ts +8 -0
- package/dist/{doctorCommand-DW2cwAvC.js → doctorCommand-B6D7HH1-.js} +14 -14
- package/dist/doctorCommand-Btl2Jz1a.js +2 -0
- package/dist/{dormancyCommand-BqQz7lbM.js → dormancyCommand-CrPAwOgo.js} +1 -1
- package/dist/{embeddingsCommand-DJyArpU4.js → embeddingsCommand-DsSxsn_b.js} +1 -1
- package/dist/{envCommand-CviRZx1L.js → envCommand-B_NPVGUf.js} +2 -2
- package/dist/{evalCommand-6RUfPen4.js → evalCommand-Db01Kbng.js} +24 -24
- package/dist/{evolveCommand-qdlP-R9G.js → evolveCommand-DUuaCIyn.js} +2 -2
- package/dist/{frameworkTableAssembly-oMPBKqlE.js → frameworkTableAssembly-BPlPfU07.js} +82 -78
- package/dist/frameworkTableAssembly-Bob3vj9R.js +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -1
- package/dist/{infoCommand-CNWPSUcW.js → infoCommand-CuNl9cbh.js} +1 -1
- package/dist/inspectState.d.ts +8 -0
- package/dist/interruptedReplace-C1ZI84xi.js +27 -0
- package/dist/interruptedReplace-DNJ7MKph.js +2 -0
- package/dist/{migrate-DN47p2PG.js → migrate-CM1qwalu.js} +27 -27
- package/dist/{runtimeTrace-BDZSt9W_.js → runtimeTrace-BRNM06vK.js} +1 -1
- package/dist/{sdkgen-sNaD3oZB.js → sdkgen-CRCw_XcR.js} +1 -1
- package/dist/{seedRunner-IdHEprqf.js → seedRunner-Dgsiwk_e.js} +59 -59
- package/dist/serveCommand-BNHMVXyp.js +2 -0
- package/dist/serveCommand-CHOr74WM.js +1928 -0
- package/dist/serveEntry.d.ts +8 -0
- package/dist/serveEntry.js +1 -1
- package/dist/{start-Ds3xyn8R.js → start-7HcSIKEp.js} +1 -1
- package/dist/{start-BAlGcjF5.js → start-DvlYDyAr.js} +1 -1
- package/dist/startEntry.d.ts +8 -0
- package/dist/startEntry.js +1 -1
- package/dist/startup.d.ts +8 -0
- package/dist/{updateCommand-rCnhaj84.js → updateCommand-BlyXavoG.js} +1 -1
- package/dist/updateCommand-CT5AvVg7.js +2 -0
- package/dist/{webDev-101csg6Q.js → webDev-B4IEMB0n.js} +6 -6
- package/dist/webDev-B79ji8M5.js +2 -0
- package/dist/{webhooksCommand-C0iZZfaI.js → webhooksCommand-BRrG_sGf.js} +1 -1
- package/package.json +23 -17
- package/templates/AGENTS.md +1 -1
- package/templates/agent-docs/_index.md +1 -1
- package/templates/agent-docs/cli.md +138 -2
- package/templates/agent-docs/data.md +70 -4
- package/templates/agent-docs/whats-new.md +127 -54
- 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-sqlite/package.json +8 -8
- package/templates/apps/api-backend-storage/package.json +8 -8
- package/templates/apps/api-cms/package.json +10 -10
- package/templates/apps/api-collab/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-saas-starter/package.json +10 -10
- package/templates/apps/api-search/package.json +8 -8
- package/templates/apps/api-status/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 +9 -9
- package/templates/apps/frontend-auth/package.json +8 -8
- package/templates/apps/frontend-blank/package.json +7 -7
- package/templates/apps/frontend-cms/package.json +9 -9
- package/templates/apps/frontend-collab/package.json +10 -10
- 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-portal/package.json +8 -8
- package/templates/apps/frontend-saas/package.json +8 -8
- 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/templates/apps/frontend-status/package.json +8 -8
- package/templates/apps/mobile-app/package.json +4 -4
- package/dist/apiBuild-yJCqJYQ8.js +0 -2
- package/dist/dbCommand-BvQeKQOb.js +0 -2
- package/dist/doctorCommand-2K1dIzYk.js +0 -2
- package/dist/frameworkTableAssembly-DgylYh9_.js +0 -2
- package/dist/serveCommand-BBhT2U94.js +0 -1885
- package/dist/serveCommand-DY2jLy0o.js +0 -2
- package/dist/updateCommand-BH6EGuCc.js +0 -2
- package/dist/webDev-BLKBO34K.js +0 -2
|
@@ -0,0 +1,1928 @@
|
|
|
1
|
+
import { t as e } from "./nodeEnvironment-cGFAj1J8.js";
|
|
2
|
+
import { t } from "./frameworkInspectState-CX2250XB.js";
|
|
3
|
+
import { r as n, t as r } from "./appModuleLoader-C9r9mxZt.js";
|
|
4
|
+
import { t as i } from "./bootRefusal-pgvDxlrU.js";
|
|
5
|
+
import { n as a, r as o } from "./startupRunner-CEqQq7ax.js";
|
|
6
|
+
import { t as ee } from "./interruptedReplace-C1ZI84xi.js";
|
|
7
|
+
import { $ as s, $t as c, A as l, At as u, Bt as d, C as f, Cn as p, Ct as m, D as h, Dt as g, E as _, En as te, Et as v, F as ne, Ft as re, G as ie, Gt as ae, H as y, Ht as oe, I as se, It as ce, J as le, Jt as b, K as x, Kt as ue, L as S, Lt as de, M as fe, Mt as pe, N as me, Nt as he, O as ge, Ot as _e, P as ve, Pt as ye, Q as be, Qt as xe, R as C, Rt as Se, S as Ce, St as we, T as Te, Tn as Ee, Tt as w, U as De, V as Oe, W as ke, Wt as Ae, X as je, Xt as Me, Y as Ne, Yt as T, Z as Pe, Zt as Fe, _ as E, _n as Ie, _t as D, an as Le, at as Re, b as ze, bn as Be, bt as Ve, c as He, cn as Ue, ct as We, dn as Ge, dt as Ke, en as qe, et as Je, f as Ye, fn as Xe, ft as Ze, g as Qe, gt as $e, h as et, hn as tt, ht as nt, i as rt, in as it, it as at, j as ot, jt as st, k as ct, kt as lt, ln as ut, lt as dt, m as ft, mn as pt, mt, nn as ht, nt as O, o as k, on as gt, ot as A, p as j, pn as _t, pt as vt, q as yt, qt as bt, r as xt, rn as St, rt as Ct, sn as M, st as wt, t as Tt, tn as Et, tt as Dt, u as Ot, un as kt, ut as At, v as jt, vn as Mt, vt as N, w as P, wn as Nt, wt as Pt, x as Ft, xn as It, xt as Lt, y as Rt, yn as zt, yt as Bt, zt as Vt } from "./dev-8hTEnN6s.js";
|
|
8
|
+
import { n as Ht } from "./cliArgs-D4p8n7EE.js";
|
|
9
|
+
import { r as F } from "./appPort-B_HpJ_ck.js";
|
|
10
|
+
import { ht as Ut, pt as Wt } from "./webDev-B4IEMB0n.js";
|
|
11
|
+
import { r as I } from "./dialectDriver-czCHYpeH.js";
|
|
12
|
+
import { i as Gt, n as Kt } from "./connectionConfig-Bk9IC7D0.js";
|
|
13
|
+
import { c as qt, n as L, o as Jt } from "./seedRunner-Dgsiwk_e.js";
|
|
14
|
+
import { C as Yt, S as Xt, _ as Zt, d as Qt, g as $t, l as en, m as tn, r as nn, u as rn, v as an } from "./frameworkTableAssembly-BPlPfU07.js";
|
|
15
|
+
import { S as on, c as sn, n as cn, p as ln, s as un, x as dn } from "./fileConventions-Cof68_BL.js";
|
|
16
|
+
import { h as fn, o as pn } from "./inspect-B7U7Cl_Z.js";
|
|
17
|
+
import { n as mn } from "./mssqlClusterPatch-_4cE_nun.js";
|
|
18
|
+
import { i as hn, n as gn, r as _n, t as vn } from "./webhookDiscovery-CphsQe59.js";
|
|
19
|
+
import { t as yn } from "./inspectMetrics-CfdKLh6t.js";
|
|
20
|
+
import { r as bn, u as xn } from "./apiBuild-BKdd0I1Z.js";
|
|
21
|
+
import { t as Sn } from "./bootTiming-BdyP9nYw.js";
|
|
22
|
+
import { t as Cn } from "./dataProfile-Cm0YVKSy.js";
|
|
23
|
+
import wn, { basename as Tn, join as En } from "node:path";
|
|
24
|
+
import { createWriteStream as Dn, existsSync as On } from "node:fs";
|
|
25
|
+
import { pathToFileURL as kn } from "node:url";
|
|
26
|
+
import { createLogger as R } from "@voltro/logger";
|
|
27
|
+
import { AuthMiddleware as An, ConnectionInfoMiddleware as jn, actionToRpc as z, anonymousSubject as Mn, isWireReachable as Nn, mutationToRpc as Pn, queryToRpc as B, streamToRpc as Fn, wireErrorUnion as In, workflowCancelDescriptor as Ln, workflowDomainEventsQueryDescriptor as Rn, workflowEventDeliveriesQueryDescriptor as V, workflowResumeDescriptor as zn, workflowRunEventsQueryDescriptor as Bn, workflowRunQueryDescriptor as Vn, workflowRunStepsQueryDescriptor as Hn, workflowRunsQueryDescriptor as Un, workflowSignalDescriptor as Wn, workflowUpdateDescriptor as Gn } from "@voltro/protocol";
|
|
28
|
+
import { allRegisteredTables as Kn, and as H, connectionIdentity as qn, ensureTableRegistered as Jn, eq as U, or as Yn } from "@voltro/database";
|
|
29
|
+
import { Cause as Xn, Effect as W, Layer as G, ManagedRuntime as Zn } from "effect";
|
|
30
|
+
import { SqlClient as Qn } from "@effect/sql";
|
|
31
|
+
import { declaredSnapshot as $n, describeOutcome as er, pendingFileMigrationIds as tr, runPlannedMigrations as nr } from "@voltro/database/sql";
|
|
32
|
+
import { AggregateRegistry as rr, CostRegistry as ir, DORMANCY_WAKEUP_TENANT as ar, Dispatcher as or, ExpectationRegistry as sr, ExperimentRegistry as cr, apiKeyManagementRoutes as lr, attachAnalyticsMirror as ur, attachExpectations as dr, attachExperiments as fr, attachFinops as pr, awaitServerListening as mr, bindMutation as K, bindStream as hr, bindSubscription as q, buildTracingLayer as gr, cancelWakeup as _r, compileCron as vr, dataStoreApiKeyStore as yr, formatServerOnlyLeaks as br, formatUnresolvedSources as xr, frameworkApiKeyStrategy as Sr, getResourcePolicy as Cr, installPolicyGuardResolver as wr, loadResourceTuples as Tr, makeActionRunner as Er, makeAdvisoryLockCoordinator as Dr, makeApiKeyService as Or, makeApiKeyUsageBuffer as kr, makeApiKeyUsageFlusher as Ar, makeAsyncKv as jr, makeAuthMiddlewareLayers as Mr, makeCoordinatedScheduler as Nr, makeEffectStoreLayer as Pr, makeLazyWorkflowFacade as Fr, makeMutationOutputCodec as Ir, makeMutationRunner as Lr, makeOneShotQueryRunner as Rr, makeQueryDescriptorProducer as zr, makeQueryFinalizer as Br, makeQueryReauthorizer as Vr, makeQuerySubscriber as Hr, makeSchemaRegistry as Ur, makeWorkflowFacade as J, makeWorkflowFacadeWithCallerContext as Wr, makeWorkflowLayers as Gr, noopKv as Kr, onProcessShutdown as qr, recordSubscriptionDelivery as Jr, recordWorkflowRun as Yr, registerDefaultTupleSource as Xr, registerWakeup as Zr, resolveSecretsBackend as Qr, runProvidedEffect as Y, setSecretsBackend as $r, setSystemStoreHandle as ei, shutdownGraceMsFromEnv as ti, singleCoordinator as ni, startRpcServer as ri, startScheduler as ii, stripForbiddenForWire as ai, undoCaptureEnabled as oi, unresolvedSources as si, withScopedRequest as ci, workflowToRpc as li, wrapStoreWithBootCodec as ui } from "@voltro/runtime";
|
|
33
|
+
import di, { tmpdir as fi } from "node:os";
|
|
34
|
+
import { RpcGroup as pi } from "@effect/rpc";
|
|
35
|
+
import { appStorageProvider as mi, fromNodeReadable as hi, getObjectStream as gi, putObjectStream as _i, toNodeReadable as vi } from "@voltro/plugin-storage";
|
|
36
|
+
import { isEnvContract as yi } from "@voltro/env";
|
|
37
|
+
import { assertProductionSessionSecret as bi } from "@voltro/protocol/session";
|
|
38
|
+
import X from "node:fs/promises";
|
|
39
|
+
import { createHash as xi, timingSafeEqual as Si } from "node:crypto";
|
|
40
|
+
import { buildDeliverWebhookExecute as Ci, buildWebhooksService as wi, defaultIncomingPath as Ti, deliverWebhookWorkflow as Ei, makeDeferredEmitHandler as Di, mountIncomingWebhook as Oi } from "@voltro/plugin-webhooks";
|
|
41
|
+
import { getAuthSessionStrategy as ki } from "@voltro/plugin-auth";
|
|
42
|
+
import { registerEmailTemplates as Ai } from "@voltro/plugin-mail";
|
|
43
|
+
import { channelFor as ji, getBroadcastPlugin as Mi } from "@voltro/plugin-broadcast";
|
|
44
|
+
import { packBundle as Ni, runExport as Pi, runImport as Fi, storageBlobSink as Ii, storageRefsBlobSource as Li, unpackBundle as Ri, unpackBundleToDir as zi } from "@voltro/data-transfer";
|
|
45
|
+
//#region src/serveDrain.ts
|
|
46
|
+
var Bi = () => Math.max(500, Math.floor(ti() * .6)), Vi = (e) => new Promise((t) => setTimeout(t, e)), Hi = (e) => {
|
|
47
|
+
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = 0;
|
|
48
|
+
e.on("connection", (e) => {
|
|
49
|
+
t.add(e), e.once("close", () => {
|
|
50
|
+
t.delete(e), n.delete(e);
|
|
51
|
+
});
|
|
52
|
+
}), e.on("upgrade", (e, t) => {
|
|
53
|
+
n.add(t);
|
|
54
|
+
}), e.on("request", (e, t) => {
|
|
55
|
+
r += 1, t.once("close", () => {
|
|
56
|
+
--r;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
let i, a = async (t = {}) => {
|
|
60
|
+
let n = t.budgetMs ?? Bi();
|
|
61
|
+
i ??= new Promise((t) => {
|
|
62
|
+
e.close(() => {
|
|
63
|
+
t();
|
|
64
|
+
});
|
|
65
|
+
}), e.closeIdleConnections();
|
|
66
|
+
let a = Date.now() + n;
|
|
67
|
+
for (; r > 0 && Date.now() < a;) await Vi(25), e.closeIdleConnections();
|
|
68
|
+
e.closeIdleConnections();
|
|
69
|
+
}, o = async () => {
|
|
70
|
+
i ??= new Promise((t) => {
|
|
71
|
+
e.close(() => {
|
|
72
|
+
t();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
for (let e of t) if (n.has(e)) try {
|
|
76
|
+
e.write(Buffer.from([
|
|
77
|
+
136,
|
|
78
|
+
2,
|
|
79
|
+
3,
|
|
80
|
+
233
|
|
81
|
+
]));
|
|
82
|
+
} catch {}
|
|
83
|
+
else e.destroy();
|
|
84
|
+
for (let e = 0; t.size > 0 && e < 250; e += 25) await Vi(25);
|
|
85
|
+
for (let e of t) e.destroy();
|
|
86
|
+
await i;
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
activeRequests: () => r,
|
|
90
|
+
drainRequests: a,
|
|
91
|
+
finish: o,
|
|
92
|
+
drain: async (e = {}) => {
|
|
93
|
+
await a(e), await o();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, Ui = "/_voltro/admin/import", Wi = "/_voltro/admin/export", Z = (e, t) => ({
|
|
97
|
+
status: e,
|
|
98
|
+
contentType: "application/json; charset=utf-8",
|
|
99
|
+
body: JSON.stringify(t)
|
|
100
|
+
}), Gi = (e) => {
|
|
101
|
+
let t = e.authorization ?? e.Authorization, n = t ? /^Bearer\s+(.+)$/i.exec(t) : null;
|
|
102
|
+
return n ? n[1] : null;
|
|
103
|
+
}, Ki = (e, t) => Si(xi("sha256").update(e).digest(), xi("sha256").update(t).digest()), qi = (e, t) => {
|
|
104
|
+
if (e.method.toUpperCase() !== "POST") return Z(405, { error: "method not allowed" });
|
|
105
|
+
if (!t || t.length < 16) return Z(503, { error: "data transfer misconfigured (no/weak secret)" });
|
|
106
|
+
let n = Gi(e.headers);
|
|
107
|
+
return !n || !Ki(n, t) ? Z(401, { error: "unauthorized" }) : null;
|
|
108
|
+
}, Ji = /^[A-Za-z0-9_-]{8,64}$/, Yi = (e) => Ji.test(e), Xi = () => wn.join(di.tmpdir(), "voltro-import-uploads"), Zi = (e) => wn.join(Xi(), e), Qi = (e) => wn.join(Zi(e), "archive.bin"), $i = (e) => wn.join(Zi(e), "meta.json"), ea = async (e = Date.now()) => {
|
|
109
|
+
let t = 0;
|
|
110
|
+
try {
|
|
111
|
+
for (let n of await X.readdir(Xi())) {
|
|
112
|
+
let r = await X.stat(Zi(n)).catch(() => null);
|
|
113
|
+
r !== null && (e - r.mtimeMs <= 864e5 || (await X.rm(Zi(n), {
|
|
114
|
+
recursive: !0,
|
|
115
|
+
force: !0
|
|
116
|
+
}).catch(() => void 0), t++));
|
|
117
|
+
}
|
|
118
|
+
} catch {}
|
|
119
|
+
return t;
|
|
120
|
+
}, ta = async (e) => {
|
|
121
|
+
if (!Yi(e)) return {
|
|
122
|
+
bytes: 0,
|
|
123
|
+
key: null
|
|
124
|
+
};
|
|
125
|
+
let t = await X.stat(Qi(e)).catch(() => null);
|
|
126
|
+
if (t === null) return {
|
|
127
|
+
bytes: 0,
|
|
128
|
+
key: null
|
|
129
|
+
};
|
|
130
|
+
let n = await X.readFile($i(e), "utf8").then((e) => JSON.parse(e), () => ({}));
|
|
131
|
+
return {
|
|
132
|
+
bytes: t.size,
|
|
133
|
+
key: n.key ?? null
|
|
134
|
+
};
|
|
135
|
+
}, na = async (e) => {
|
|
136
|
+
if (!Yi(e.id)) return {
|
|
137
|
+
reason: "bad-id",
|
|
138
|
+
message: `upload id must match ${String(Ji)}`
|
|
139
|
+
};
|
|
140
|
+
let t = await ta(e.id);
|
|
141
|
+
return t.key !== null && t.key !== e.key ? {
|
|
142
|
+
reason: "key-mismatch",
|
|
143
|
+
message: "this upload id already holds a different bundle. Use a new upload id, or delete the partial upload."
|
|
144
|
+
} : e.offset === t.bytes ? (await X.mkdir(Zi(e.id), { recursive: !0 }), t.key === null && await X.writeFile($i(e.id), JSON.stringify({
|
|
145
|
+
key: e.key,
|
|
146
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
147
|
+
})), await new Promise((t, n) => {
|
|
148
|
+
let r = Dn(Qi(e.id), { flags: "a" });
|
|
149
|
+
r.on("error", n), r.on("finish", () => t()), r.end(Buffer.from(e.bytes));
|
|
150
|
+
}), { total: t.bytes + e.bytes.byteLength }) : {
|
|
151
|
+
reason: "offset-mismatch",
|
|
152
|
+
message: `chunk starts at ${e.offset} but the server holds ${t.bytes} byte(s)`,
|
|
153
|
+
expectedOffset: t.bytes
|
|
154
|
+
};
|
|
155
|
+
}, ra = async (e) => {
|
|
156
|
+
let t = await X.stat(Qi(e));
|
|
157
|
+
return {
|
|
158
|
+
path: Qi(e),
|
|
159
|
+
bytes: t.size
|
|
160
|
+
};
|
|
161
|
+
}, ia = async (e) => {
|
|
162
|
+
Yi(e) && await X.rm(Zi(e), {
|
|
163
|
+
recursive: !0,
|
|
164
|
+
force: !0
|
|
165
|
+
}).catch(() => void 0);
|
|
166
|
+
}, Q = R({ scope: "voltro:admin-import" }), aa = "VBUNDLE2", oa = (e) => {
|
|
167
|
+
let t = e.req.headers["x-import-rollback-key"];
|
|
168
|
+
if (e.mode !== "replace") return { options: {} };
|
|
169
|
+
if (typeof t != "string" || t.length === 0) return Q.warn("admin.import: no rollback capture — this run empties the target first, and nothing was asked to be kept. Send `x-import-rollback-key: <storage key>` (voltro data import --rollback-key <key>) to have the instance store the target's current rows before deleting them."), { options: {} };
|
|
170
|
+
if (e.deps.putArchive === void 0) return {
|
|
171
|
+
options: {},
|
|
172
|
+
refusal: Z(409, {
|
|
173
|
+
error: "rollback capture requested but this instance has no object storage configured",
|
|
174
|
+
hint: "A capture written to the pod would not survive the failure it exists for. Configure storage (the same one the storage-push export uses), or re-send without `x-import-rollback-key` to accept that a run which does not finish can leave the target emptied."
|
|
175
|
+
})
|
|
176
|
+
};
|
|
177
|
+
let n = En(fi(), `voltro-rollback-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`), r = e.deps.putArchive;
|
|
178
|
+
return {
|
|
179
|
+
key: t,
|
|
180
|
+
options: {
|
|
181
|
+
rollbackDir: n,
|
|
182
|
+
onRollbackCaptured: async () => {
|
|
183
|
+
await r(t, () => Ni({ dir: n })), Q.info("admin.import: rollback capture stored", { bundleKey: t });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}, sa = async function* (e) {
|
|
188
|
+
yield e;
|
|
189
|
+
}, ca = (e) => async (t) => {
|
|
190
|
+
let n = qi(t, e.secret);
|
|
191
|
+
if (n) return n;
|
|
192
|
+
let r = t.headers["x-import-mode"], i = t.headers["x-import-on-conflict"], a = t.headers["x-import-atomic"], o = a === "0" || a === "false" ? !1 : a === "1" || a === "true" || r === "replace", ee = t.headers["x-import-force"] === "1" || t.headers["x-import-force"] === "true", s = oa({
|
|
193
|
+
req: t,
|
|
194
|
+
mode: r,
|
|
195
|
+
deps: e
|
|
196
|
+
});
|
|
197
|
+
if (s.refusal !== void 0) return s.refusal;
|
|
198
|
+
let c = t.headers["x-import-dry-run"] === "1" || t.headers["x-import-dry-run"] === "true", l = (t.headers["x-import-tables"] ?? "").split(",").map((e) => e.trim()).filter(Boolean), u = t.headers["x-import-upload-id"], d;
|
|
199
|
+
if (u !== void 0 && u !== "") {
|
|
200
|
+
if (ea(), t.headers["x-import-probe"] === "1") return Z(200, {
|
|
201
|
+
uploadId: u,
|
|
202
|
+
bytes: (await ta(u)).bytes
|
|
203
|
+
});
|
|
204
|
+
let e = t.headers["x-import-upload-key"] ?? "", n = Number(t.headers["x-import-chunk-offset"] ?? "0");
|
|
205
|
+
if (e === "" || !Number.isFinite(n) || n < 0) return Z(400, { error: "a chunked upload needs x-import-upload-key and a numeric x-import-chunk-offset" });
|
|
206
|
+
let r = await na({
|
|
207
|
+
id: u,
|
|
208
|
+
key: e,
|
|
209
|
+
offset: n,
|
|
210
|
+
bytes: t.rawBody
|
|
211
|
+
});
|
|
212
|
+
if ("reason" in r) return Q.warn("admin.import chunk refused", {
|
|
213
|
+
uploadId: u,
|
|
214
|
+
reason: r.reason
|
|
215
|
+
}), Z(409, {
|
|
216
|
+
error: "chunk refused",
|
|
217
|
+
reason: r.reason,
|
|
218
|
+
message: r.message,
|
|
219
|
+
...r.expectedOffset === void 0 ? {} : { expectedOffset: r.expectedOffset }
|
|
220
|
+
});
|
|
221
|
+
if (t.headers["x-import-chunk-final"] !== "1") return Z(202, {
|
|
222
|
+
uploadId: u,
|
|
223
|
+
bytes: r.total
|
|
224
|
+
});
|
|
225
|
+
d = (await ra(u)).path;
|
|
226
|
+
}
|
|
227
|
+
let f = t.rawBody.byteLength >= 8 && Buffer.from(t.rawBody.subarray(0, 8)).toString("latin1") === aa, p, m;
|
|
228
|
+
if (d !== void 0) {
|
|
229
|
+
let { createReadStream: e } = await import("node:fs");
|
|
230
|
+
p = e(d), m = "chunked";
|
|
231
|
+
} else if (f) p = sa(t.rawBody), m = "upload";
|
|
232
|
+
else {
|
|
233
|
+
let n;
|
|
234
|
+
try {
|
|
235
|
+
n = JSON.parse(Buffer.from(t.rawBody).toString("utf8") || "{}");
|
|
236
|
+
} catch {
|
|
237
|
+
return Z(400, { error: "body must be a packed bundle archive or { bundleKey } JSON" });
|
|
238
|
+
}
|
|
239
|
+
if (typeof n.bundleKey != "string" || !n.bundleKey) return Z(400, { error: "body.bundleKey (string) is required for the storage transport" });
|
|
240
|
+
if (!e.openArchive) return Z(501, { error: "storage transport not configured on this instance" });
|
|
241
|
+
p = e.openArchive(n.bundleKey), m = "storage";
|
|
242
|
+
}
|
|
243
|
+
let h = await import("node:os"), g = await import("node:fs/promises"), _ = await import("node:path"), te = await g.mkdtemp(_.join(h.tmpdir(), "voltro-admin-import-"));
|
|
244
|
+
try {
|
|
245
|
+
e.assetSink ? await Ri(p, {
|
|
246
|
+
dir: te,
|
|
247
|
+
blobs: e.assetSink
|
|
248
|
+
}) : await zi(p, te);
|
|
249
|
+
let t = await W.runPromiseExit(Fi({
|
|
250
|
+
store: e.store,
|
|
251
|
+
bundleDir: te,
|
|
252
|
+
...r ? { mode: r } : {},
|
|
253
|
+
...i ? { onConflict: i } : {},
|
|
254
|
+
atomic: o,
|
|
255
|
+
...s.options,
|
|
256
|
+
recordInterruption: !0,
|
|
257
|
+
via: "api",
|
|
258
|
+
...c ? { dryRun: c } : {},
|
|
259
|
+
...l.length > 0 ? { tables: l } : {},
|
|
260
|
+
...e.snapshot ? { targetSnapshot: e.snapshot } : {},
|
|
261
|
+
force: ee,
|
|
262
|
+
onWarn: (e) => Q.warn("admin.import", { message: e }),
|
|
263
|
+
...e.assetSink ? { assetsAlreadyRestored: !0 } : {}
|
|
264
|
+
}));
|
|
265
|
+
if (t._tag === "Failure") {
|
|
266
|
+
let e = t.cause._tag === "Fail" ? t.cause.error : void 0;
|
|
267
|
+
if (e && e._tag === "SchemaDriftError") {
|
|
268
|
+
let t = e;
|
|
269
|
+
return Q.warn("admin.import refused (schema drift)", {
|
|
270
|
+
transport: m,
|
|
271
|
+
bundle: t.bundleFingerprint.slice(0, 16),
|
|
272
|
+
target: t.targetFingerprint.slice(0, 16)
|
|
273
|
+
}), Z(409, {
|
|
274
|
+
error: "schema drift",
|
|
275
|
+
bundleFingerprint: t.bundleFingerprint,
|
|
276
|
+
targetFingerprint: t.targetFingerprint,
|
|
277
|
+
diff: t.diff,
|
|
278
|
+
hint: "each line above would break the load: a table or column the bundle carries that the target cannot take, or a column the target requires that the bundle has no value for. Fix the target schema, re-export against it, or resend with x-import-force: 1 to write anyway."
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
let n = typeof e?.reason == "string" ? e.reason : void 0;
|
|
282
|
+
if (n !== void 0 && e._tag === "ImportModeError") return Q.warn("admin.import refused (mode)", {
|
|
283
|
+
transport: m,
|
|
284
|
+
mode: e.mode
|
|
285
|
+
}), Z(409, {
|
|
286
|
+
error: "import mode refused",
|
|
287
|
+
mode: e.mode,
|
|
288
|
+
message: n
|
|
289
|
+
});
|
|
290
|
+
throw Error(n ?? String(e?.message ?? e ?? "import failed"));
|
|
291
|
+
}
|
|
292
|
+
let n = t.value, a = n.manifest.tables.reduce((e, t) => e + t.rowCount, 0), u = n.rowsWritten;
|
|
293
|
+
return Q.info(c ? "admin.import (dry run — nothing written)" : "admin.import", {
|
|
294
|
+
transport: m,
|
|
295
|
+
tables: n.tablesWritten,
|
|
296
|
+
rows: u,
|
|
297
|
+
carried: a,
|
|
298
|
+
mode: r ?? "upsert",
|
|
299
|
+
atomic: o,
|
|
300
|
+
...n.tablesSkipped > 0 ? {
|
|
301
|
+
skippedTables: n.tablesSkipped,
|
|
302
|
+
skippedRows: n.rowsSkipped
|
|
303
|
+
} : {}
|
|
304
|
+
}), c || e.refreshSubscriptions?.(`data import: ${n.tablesWritten} table(s), mode ${r ?? "upsert"}`), Z(200, {
|
|
305
|
+
tables: n.tablesWritten,
|
|
306
|
+
rows: u,
|
|
307
|
+
carried: a,
|
|
308
|
+
transport: m,
|
|
309
|
+
...n.tablesSkipped > 0 ? {
|
|
310
|
+
skippedTables: n.tablesSkipped,
|
|
311
|
+
skippedRows: n.rowsSkipped,
|
|
312
|
+
fullyResumed: n.fullyResumed
|
|
313
|
+
} : {},
|
|
314
|
+
...c ? {
|
|
315
|
+
dryRun: !0,
|
|
316
|
+
wrote: !1
|
|
317
|
+
} : {}
|
|
318
|
+
});
|
|
319
|
+
} catch (e) {
|
|
320
|
+
return Q.warn("admin.import failed", {
|
|
321
|
+
transport: m,
|
|
322
|
+
error: e?.message ?? String(e)
|
|
323
|
+
}), Z(500, {
|
|
324
|
+
error: "import failed",
|
|
325
|
+
message: e?.message ?? String(e)
|
|
326
|
+
});
|
|
327
|
+
} finally {
|
|
328
|
+
await g.rm(te, {
|
|
329
|
+
recursive: !0,
|
|
330
|
+
force: !0
|
|
331
|
+
}), u !== void 0 && u !== "" && d !== void 0 && await ia(u);
|
|
332
|
+
}
|
|
333
|
+
}, la = R({ scope: "voltro:admin-export" }), ua = async (e) => {
|
|
334
|
+
let t = [];
|
|
335
|
+
for await (let n of e) t.push(Buffer.from(n));
|
|
336
|
+
return new Uint8Array(Buffer.concat(t));
|
|
337
|
+
}, da = (e) => typeof e.tenant == "string" && e.tenant ? {
|
|
338
|
+
kind: "tenant",
|
|
339
|
+
tenantId: e.tenant
|
|
340
|
+
} : Array.isArray(e.tables) && e.tables.length ? {
|
|
341
|
+
kind: "tables",
|
|
342
|
+
tables: e.tables.filter((e) => typeof e == "string")
|
|
343
|
+
} : { kind: "all" }, fa = (e) => async (t) => {
|
|
344
|
+
let n = qi(t, e.secret);
|
|
345
|
+
if (n) return n;
|
|
346
|
+
let r;
|
|
347
|
+
try {
|
|
348
|
+
r = JSON.parse(Buffer.from(t.rawBody).toString("utf8") || "{}");
|
|
349
|
+
} catch {
|
|
350
|
+
return Z(400, { error: "body must be JSON: { profile?, tenant?, tables?, consistency?, compression?, bundleKey? }" });
|
|
351
|
+
}
|
|
352
|
+
let i = {};
|
|
353
|
+
if (typeof r.profile == "string" && r.profile) {
|
|
354
|
+
if (!e.loadProfile) return Z(501, { error: "server-side profiles not configured on this instance" });
|
|
355
|
+
try {
|
|
356
|
+
i = await e.loadProfile(r.profile);
|
|
357
|
+
} catch (e) {
|
|
358
|
+
return Z(400, {
|
|
359
|
+
error: `profile '${r.profile}' could not be loaded`,
|
|
360
|
+
message: e?.message ?? String(e)
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
let a = r.consistency === "snapshot" ? "snapshot" : i.consistency ?? "live", o = (typeof r.compression == "string" ? r.compression : void 0) ?? i.compression, ee = i.scope ?? da(r), s = typeof r.bundleKey == "string" && r.bundleKey.length > 0, c = r.assets === !0 && e.assetSource ? { blobs: e.assetSource } : {}, l = await import("node:os"), u = await import("node:fs/promises"), d = await import("node:path"), f = await u.mkdtemp(d.join(l.tmpdir(), "voltro-admin-export-"));
|
|
365
|
+
try {
|
|
366
|
+
let t = await W.runPromise(Pi({
|
|
367
|
+
store: e.store,
|
|
368
|
+
snapshot: e.snapshot,
|
|
369
|
+
dialect: e.dialect,
|
|
370
|
+
outDir: f,
|
|
371
|
+
...i.subset ? { subset: i.subset } : {
|
|
372
|
+
scope: ee,
|
|
373
|
+
...e.tenantTables && e.tenantTables.length > 0 ? { tenantTables: e.tenantTables } : {}
|
|
374
|
+
},
|
|
375
|
+
consistency: a,
|
|
376
|
+
...o ? { compression: o } : {},
|
|
377
|
+
...i.masking ? { masking: i.masking } : {}
|
|
378
|
+
})), n = t.tables.reduce((e, t) => e + t.rowCount, 0), l = t.masking?.transformed.length ?? 0;
|
|
379
|
+
if (s) {
|
|
380
|
+
if (!e.putArchive) return Z(501, { error: "storage transport not configured on this instance" });
|
|
381
|
+
let i = r.bundleKey;
|
|
382
|
+
return await e.putArchive(i, () => Ni({
|
|
383
|
+
dir: f,
|
|
384
|
+
...c
|
|
385
|
+
})), la.info("admin.export", {
|
|
386
|
+
transport: "storage",
|
|
387
|
+
tables: t.tables.length,
|
|
388
|
+
rows: n,
|
|
389
|
+
masked: l,
|
|
390
|
+
bundleKey: i
|
|
391
|
+
}), Z(200, {
|
|
392
|
+
bundleKey: i,
|
|
393
|
+
tables: t.tables.length,
|
|
394
|
+
rows: n,
|
|
395
|
+
masked: l,
|
|
396
|
+
transport: "storage"
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
let u = await ua(Ni({
|
|
400
|
+
dir: f,
|
|
401
|
+
...c
|
|
402
|
+
}));
|
|
403
|
+
return la.info("admin.export", {
|
|
404
|
+
transport: "download",
|
|
405
|
+
tables: t.tables.length,
|
|
406
|
+
rows: n,
|
|
407
|
+
masked: l,
|
|
408
|
+
bytes: u.byteLength
|
|
409
|
+
}), {
|
|
410
|
+
status: 200,
|
|
411
|
+
contentType: "application/octet-stream",
|
|
412
|
+
body: u,
|
|
413
|
+
headers: {
|
|
414
|
+
"x-export-tables": String(t.tables.length),
|
|
415
|
+
"x-export-rows": String(n),
|
|
416
|
+
"x-export-masked": String(l)
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
} catch (e) {
|
|
420
|
+
return la.warn("admin.export failed", { error: e?.message ?? String(e) }), Z(500, {
|
|
421
|
+
error: "export failed",
|
|
422
|
+
message: e?.message ?? String(e)
|
|
423
|
+
});
|
|
424
|
+
} finally {
|
|
425
|
+
await u.rm(f, {
|
|
426
|
+
recursive: !0,
|
|
427
|
+
force: !0
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}, pa = (e, t, n = {}) => (async function* () {
|
|
431
|
+
let r = await W.runPromise(gi(e, t).pipe(W.timeout(n.openTimeout ?? "30 seconds"))), i = await vi(r.stream), a = n.stallMs ?? 12e4, o, ee = () => {
|
|
432
|
+
o && clearTimeout(o), o = setTimeout(() => i.destroy(/* @__PURE__ */ Error(`storage read stalled for ${a}ms reading '${t}'`)), a);
|
|
433
|
+
};
|
|
434
|
+
try {
|
|
435
|
+
ee();
|
|
436
|
+
for await (let e of i) ee(), yield e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
437
|
+
} finally {
|
|
438
|
+
o && clearTimeout(o), i.destroy();
|
|
439
|
+
}
|
|
440
|
+
})(), ma = {
|
|
441
|
+
get: async () => void 0,
|
|
442
|
+
set: async () => {},
|
|
443
|
+
setWithTags: async () => {},
|
|
444
|
+
remove: async () => !1,
|
|
445
|
+
has: async () => !1,
|
|
446
|
+
clear: async () => {},
|
|
447
|
+
invalidateTag: async () => 0,
|
|
448
|
+
wrap: async (e, t, n) => n()
|
|
449
|
+
}, ha = async (e) => {
|
|
450
|
+
d(e.appProcedures ?? e.discovered, {
|
|
451
|
+
defaultDeny: e.security?.defaultDeny ?? !0,
|
|
452
|
+
commandHint: "`voltro serve`"
|
|
453
|
+
}), ei({
|
|
454
|
+
dataStore: e.store,
|
|
455
|
+
schemaRegistry: e.schemaRegistry
|
|
456
|
+
});
|
|
457
|
+
let t = (e.discovered.budgets?.length ?? 0) > 0, n, r = new or({
|
|
458
|
+
store: e.store,
|
|
459
|
+
...e.snapshotCache ? { cache: e.snapshotCache } : {},
|
|
460
|
+
...e.reactive === void 0 ? {} : { reactive: e.reactive },
|
|
461
|
+
...t ? { recordCost: (e) => n?.record(e) } : {},
|
|
462
|
+
recordDelivery: (e) => Jr({
|
|
463
|
+
label: e.label,
|
|
464
|
+
kind: e.kind,
|
|
465
|
+
durationMs: e.durationMs,
|
|
466
|
+
rowCount: e.rowCount
|
|
467
|
+
})
|
|
468
|
+
}), i = e.cache ?? ma, a = e.kv ?? Kr, o, ee = () => void 0, c, l, u, f, p, m, h, _ = ue({
|
|
469
|
+
store: e.store,
|
|
470
|
+
warn: (e, t) => {
|
|
471
|
+
process.stderr.write(`[workflow] ${e} ${JSON.stringify(t)}\n`);
|
|
472
|
+
}
|
|
473
|
+
}), te = _.remember, ae = _.resolve, oe = bt({
|
|
474
|
+
authority: e.authority,
|
|
475
|
+
getStore: () => e.store
|
|
476
|
+
}), S = (e.discovered.workflows?.length ?? 0) > 0 ? Fr(() => o) : void 0, de = (e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.eventTriggers?.length ?? 0) > 0, he = de || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster", ge = e.tenantIsolation === "namespace", _e = (e.log ?? R({ scope: "voltro:serve" })).child("webhooks"), ve, ye, C = e.discovered.webhooks;
|
|
477
|
+
if (C && C.outgoing.length > 0 && e.workflowEngineLayer !== void 0) {
|
|
478
|
+
e.workflowEngineLayer;
|
|
479
|
+
let t = ut({
|
|
480
|
+
store: e.store,
|
|
481
|
+
schemaRegistry: e.schemaRegistry,
|
|
482
|
+
cache: i,
|
|
483
|
+
kv: a
|
|
484
|
+
}), n = C.outgoing.map((e) => e.descriptor);
|
|
485
|
+
ye = Ei.toLayer(Ci(t, { events: n })), ve = wi(t, async (e) => {
|
|
486
|
+
let t = u;
|
|
487
|
+
if (t === void 0) {
|
|
488
|
+
_e.error("webhook delivery skipped — the workflow runtime was never built. This is a framework defect, not a configuration problem: report it with your engine setting. Deliveries are NOT queued and will not be retried.", {
|
|
489
|
+
deliveryId: e.deliveryId,
|
|
490
|
+
targetId: e.targetId
|
|
491
|
+
});
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
t.runPromise(Ei.execute(e)).catch((t) => {
|
|
495
|
+
_e.error("deliverWebhook workflow crashed", {
|
|
496
|
+
deliveryId: e.deliveryId,
|
|
497
|
+
targetId: e.targetId
|
|
498
|
+
}, t);
|
|
499
|
+
});
|
|
500
|
+
}, { events: n });
|
|
501
|
+
}
|
|
502
|
+
let Se = /* @__PURE__ */ new Map();
|
|
503
|
+
if (C) for (let e of C.incoming) {
|
|
504
|
+
let t = e.descriptor.path ?? Ti(e.descriptor.id), n = `VOLTRO_WEBHOOK_SECRET_${e.descriptor.id.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`, r = Oi(e.descriptor, {
|
|
505
|
+
resolveSecret: async () => process.env[n] ?? null,
|
|
506
|
+
resolveWorkflows: () => S === void 0 ? void 0 : Wr(S, {
|
|
507
|
+
traceId: `incoming:${e.descriptor.id}`,
|
|
508
|
+
source: `incoming:${e.descriptor.id}`
|
|
509
|
+
}),
|
|
510
|
+
log: (e) => {
|
|
511
|
+
let t = {
|
|
512
|
+
webhookId: e.webhookId,
|
|
513
|
+
status: e.status,
|
|
514
|
+
signatureOk: String(e.signatureOk),
|
|
515
|
+
idempotency: e.idempotency,
|
|
516
|
+
durationMs: e.durationMs
|
|
517
|
+
};
|
|
518
|
+
e.status >= 500 ? _e.error("incoming delivery failed", t) : e.status >= 400 ? _e.warn("incoming delivery rejected", t) : _e.info("incoming delivery handled", t);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
Se.set(t, { handle: r });
|
|
522
|
+
}
|
|
523
|
+
wr(), Xr((t) => Tr(e.store, t.subjectId, t.resourceType, t.resourceId)) || R({ scope: "voltro:serve" }).info("policy guards: using the app-registered tuple source");
|
|
524
|
+
let Ce = [], Te = [...e.discovered.outboxHandlers ?? [], ...gn((C?.outgoing.length ?? 0) + (C?.incoming.length ?? 0) + (C?.providers.length ?? 0), []) ? [{
|
|
525
|
+
file: "<framework>/webhooks",
|
|
526
|
+
id: "voltro-webhook-emit",
|
|
527
|
+
definition: Di(() => ve)
|
|
528
|
+
}] : []], Ee = Te.length > 0 ? Fe({
|
|
529
|
+
handlers: Te,
|
|
530
|
+
store: e.store,
|
|
531
|
+
log: (e.log ?? R({ scope: "voltro:serve" })).child("outbox"),
|
|
532
|
+
onChange: (t) => e.store.onChange((e) => t({
|
|
533
|
+
table: e.table,
|
|
534
|
+
op: e.op
|
|
535
|
+
})),
|
|
536
|
+
onShutdown: (e) => {
|
|
537
|
+
Ce.push(e);
|
|
538
|
+
}
|
|
539
|
+
}) : void 0, w = T({
|
|
540
|
+
definitions: (e.discovered.connections ?? []).map((e) => e.definition),
|
|
541
|
+
store: e.store,
|
|
542
|
+
publicUrl: b(e.port ?? 4e3),
|
|
543
|
+
log: (e.log ?? R({ scope: "voltro:serve" })).child("connections")
|
|
544
|
+
});
|
|
545
|
+
ot({
|
|
546
|
+
events: e.discovered.events ?? [],
|
|
547
|
+
rpcTags: [
|
|
548
|
+
...e.discovered.queries.map((e) => e.descriptor.name),
|
|
549
|
+
...e.discovered.mutations.map((e) => e.descriptor.name),
|
|
550
|
+
...e.discovered.actions.map((e) => e.descriptor.name),
|
|
551
|
+
...(e.discovered.streams ?? []).map((e) => e.descriptor.name)
|
|
552
|
+
]
|
|
553
|
+
});
|
|
554
|
+
let Ae = (e.log ?? R({ scope: "voltro:serve" })).child("events"), je = e.broadcastNamespace ?? Qe(e.plugins, void 0), Me = E(e.plugins, je, Ae), Ne = e.membership?.instanceId ?? process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, Ie = e.membership ?? jt(e.plugins, {
|
|
555
|
+
instanceId: Ne,
|
|
556
|
+
namespace: je,
|
|
557
|
+
meta: { mode: "serve" },
|
|
558
|
+
logger: Ae
|
|
559
|
+
}), D = fe({
|
|
560
|
+
events: e.discovered.events ?? [],
|
|
561
|
+
origin: Ne,
|
|
562
|
+
...Me.publishRemote === void 0 ? {} : { publishRemote: Me.publishRemote }
|
|
563
|
+
}), Le = (e.discovered.events ?? []).length > 0 ? await Me.attach(D.bus) : null, Re = Ue({
|
|
564
|
+
store: e.store,
|
|
565
|
+
schemaRegistry: e.schemaRegistry,
|
|
566
|
+
cache: i,
|
|
567
|
+
kv: a,
|
|
568
|
+
...ve === void 0 ? {} : { webhooksService: ve },
|
|
569
|
+
...S === void 0 ? {} : { workflowsProxy: S },
|
|
570
|
+
eventTriggers: e.discovered.eventTriggers ?? [],
|
|
571
|
+
namespaceIsolationOn: ge,
|
|
572
|
+
...e.ensureTenantProvisioned === void 0 ? {} : { ensureTenantProvisioned: e.ensureTenantProvisioned },
|
|
573
|
+
...e.resolveResidentStore === void 0 ? {} : { resolveResidentStore: e.resolveResidentStore },
|
|
574
|
+
...Ee === void 0 ? {} : { outbox: { nudge: Ee.nudge } },
|
|
575
|
+
...w.active ? { connections: { registry: w.registry } } : {},
|
|
576
|
+
eventBus: D.bus
|
|
577
|
+
}), ze = G.succeed(rr, g), Be = G.succeed(sr, Lt), He = G.succeed(ir, Ve), Ge = G.succeed(cr, we), qe = (t, n) => {
|
|
578
|
+
let r = t.pipe(W.provide(Pr(n)));
|
|
579
|
+
return (e.baseLayer ? r.pipe(W.provide(e.baseLayer)) : r).pipe(W.provide(ze)).pipe(W.provide(Be)).pipe(W.provide(He)).pipe(W.provide(Ge));
|
|
580
|
+
}, Ye = (e, t) => {
|
|
581
|
+
let n = qe(e, t);
|
|
582
|
+
return Y(n);
|
|
583
|
+
}, Xe = yn(), et = le(e.plugins ?? [], Xe), tt = Oe({
|
|
584
|
+
plugins: e.plugins ?? [],
|
|
585
|
+
metrics: Xe,
|
|
586
|
+
log: e.log ?? R({ scope: "voltro:serve" })
|
|
587
|
+
}), nt = x(e.plugins ?? [], Xe), rt = e.security?.defaultDeny ?? !0, at = Lr({
|
|
588
|
+
store: e.store,
|
|
589
|
+
defaultDeny: rt,
|
|
590
|
+
recordMetric: (e) => {
|
|
591
|
+
Xe.record(e);
|
|
592
|
+
},
|
|
593
|
+
...et.mutation === void 0 ? {} : { interceptor: et.mutation },
|
|
594
|
+
buildContext: (e, t, n) => Re(e, t, n),
|
|
595
|
+
runEffect: Ye,
|
|
596
|
+
undoCapture: s()
|
|
597
|
+
}), ct = be();
|
|
598
|
+
{
|
|
599
|
+
let t = Je();
|
|
600
|
+
t !== void 0 && (e.log ?? R({ scope: "voltro:serve" })).info(t);
|
|
601
|
+
}
|
|
602
|
+
let lt = Pe({
|
|
603
|
+
store: e.store,
|
|
604
|
+
...e.approvals === void 0 ? {} : { defaultExpiryMs: e.approvals.defaultExpiryMs }
|
|
605
|
+
}), ft = Er({
|
|
606
|
+
defaultDeny: rt,
|
|
607
|
+
buildContext: (e) => Re(e),
|
|
608
|
+
runEffect: Ye,
|
|
609
|
+
recordMetric: (e) => {
|
|
610
|
+
Xe.record(e);
|
|
611
|
+
},
|
|
612
|
+
...et.action === void 0 ? {} : { interceptor: et.action }
|
|
613
|
+
}), pt = Br({
|
|
614
|
+
tenantScopedTables: e.tenantScopedTables,
|
|
615
|
+
softDeleteScopedTables: e.softDeleteScopedTables
|
|
616
|
+
}), mt = {
|
|
617
|
+
defaultDeny: rt,
|
|
618
|
+
buildContext: (e) => Re(e),
|
|
619
|
+
finalize: (e, t) => pt(e, t.subject),
|
|
620
|
+
provideEffect: qe,
|
|
621
|
+
...et.query === void 0 ? {} : { interceptor: et.query }
|
|
622
|
+
}, O = zr(mt), k = Rr({
|
|
623
|
+
...mt,
|
|
624
|
+
queryRows: (t, n) => e.store.query(t).then((e) => ai(t.table, e, n.subject))
|
|
625
|
+
}), gt = Hr({
|
|
626
|
+
...mt,
|
|
627
|
+
subscribeDescriptor: (e, t, n) => r.subscribe(e, t, n),
|
|
628
|
+
subscribeComputed: (e, t, n) => r.subscribeComputed(e, t, n)
|
|
629
|
+
}), A = (e) => e.filter((e) => Nn(e.descriptor)), j = {};
|
|
630
|
+
for (let t of [
|
|
631
|
+
...A(e.discovered.queries),
|
|
632
|
+
...ct.queries,
|
|
633
|
+
...lt.queries,
|
|
634
|
+
...w.queries
|
|
635
|
+
]) j[t.descriptor.name] = (e) => q(O(t, e), r, `subscription.${t.descriptor.name}`, void 0, void 0, Vr(t, e));
|
|
636
|
+
for (let t of [
|
|
637
|
+
...A(e.discovered.mutations),
|
|
638
|
+
...ct.mutations,
|
|
639
|
+
...lt.mutations,
|
|
640
|
+
...w.mutations
|
|
641
|
+
]) {
|
|
642
|
+
let n = Ir(t.descriptor.output);
|
|
643
|
+
j[t.descriptor.name] = (r) => K(async (e, n) => at(t, e, n), r, `mutation.${t.descriptor.name}`, n, e.idempotency, In(t.descriptor, "mutation"));
|
|
644
|
+
}
|
|
645
|
+
for (let t of [...A(e.discovered.actions), ...w.actions]) {
|
|
646
|
+
let n = Ir(t.descriptor.output);
|
|
647
|
+
j[t.descriptor.name] = (r) => K(async (e, n) => ft(t, e, n), r, `action.${t.descriptor.name}`, n, e.idempotency, In(t.descriptor, "action"));
|
|
648
|
+
}
|
|
649
|
+
let _t = () => `public-${Math.random().toString(36).slice(2, 10)}`, vt = [
|
|
650
|
+
...e.discovered.queries.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
651
|
+
descriptor: e.descriptor,
|
|
652
|
+
invoke: (t, n) => k(e, t, {
|
|
653
|
+
subject: n.subject,
|
|
654
|
+
traceId: _t()
|
|
655
|
+
}),
|
|
656
|
+
subscribe: (t, n, r) => gt(e, t, {
|
|
657
|
+
subject: n.subject,
|
|
658
|
+
traceId: _t()
|
|
659
|
+
}, r)
|
|
660
|
+
})),
|
|
661
|
+
...e.discovered.mutations.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
662
|
+
descriptor: e.descriptor,
|
|
663
|
+
invoke: (t, n) => at(e, t, {
|
|
664
|
+
subject: n.subject,
|
|
665
|
+
traceId: _t()
|
|
666
|
+
})
|
|
667
|
+
})),
|
|
668
|
+
...e.discovered.actions.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
669
|
+
descriptor: e.descriptor,
|
|
670
|
+
invoke: (t, n) => ft(e, t, {
|
|
671
|
+
subject: n.subject,
|
|
672
|
+
traceId: _t()
|
|
673
|
+
})
|
|
674
|
+
}))
|
|
675
|
+
], yt = {
|
|
676
|
+
candidates: ce({
|
|
677
|
+
queries: e.discovered.queries,
|
|
678
|
+
mutations: e.discovered.mutations,
|
|
679
|
+
actions: e.discovered.actions,
|
|
680
|
+
descriptorOf: (e) => e.descriptor,
|
|
681
|
+
runQuery: (e, t, n) => Promise.resolve(k(e, t, n)),
|
|
682
|
+
runMutation: (e, t, n) => Promise.resolve(at(e, t, n)),
|
|
683
|
+
runAction: (e, t, n) => Promise.resolve(ft(e, t, n))
|
|
684
|
+
}),
|
|
685
|
+
policy: e.agents?.tools ?? {},
|
|
686
|
+
mcpEnabled: e.agents?.mcp === !0,
|
|
687
|
+
resolveSubject: (t) => e.resolveSubject(t, -1).then((e) => e.subject)
|
|
688
|
+
}, xt = ht({
|
|
689
|
+
...e.restRoutes === void 0 ? {} : { restRoutes: e.restRoutes },
|
|
690
|
+
publicApiEntries: vt,
|
|
691
|
+
store: e.store,
|
|
692
|
+
resolveSubject: (t) => e.resolveSubject(t, -1).then((e) => e.subject),
|
|
693
|
+
...e.idempotency === void 0 ? {} : { idempotency: e.idempotency },
|
|
694
|
+
log: e.log ?? R({ scope: "voltro:serve" })
|
|
695
|
+
}), St = e.dataTransferSecret ?? process.env.VOLTRO_DATA_TRANSFER_SECRET, Ct = async (e, t) => {
|
|
696
|
+
let { Readable: n } = await import("node:stream"), r = mi(), i = hi("storage", () => n.from(t()));
|
|
697
|
+
await W.runPromise(_i(r, e, i, { contentType: "application/octet-stream" }));
|
|
698
|
+
}, wt = St && St.length >= 16 ? [{
|
|
699
|
+
method: "POST",
|
|
700
|
+
path: Ui,
|
|
701
|
+
handle: ca({
|
|
702
|
+
secret: St,
|
|
703
|
+
store: e.store,
|
|
704
|
+
...e.dataTransferSnapshot ? { snapshot: e.dataTransferSnapshot } : {},
|
|
705
|
+
assetSink: Ii(mi()),
|
|
706
|
+
openArchive: (e) => pa(mi(), e),
|
|
707
|
+
refreshSubscriptions: (e) => {
|
|
708
|
+
r.refreshAll(e);
|
|
709
|
+
},
|
|
710
|
+
putArchive: Ct,
|
|
711
|
+
...e.dataTransferDialect ? { dialect: e.dataTransferDialect } : {}
|
|
712
|
+
})
|
|
713
|
+
}, {
|
|
714
|
+
method: "POST",
|
|
715
|
+
path: Wi,
|
|
716
|
+
handle: fa({
|
|
717
|
+
secret: St,
|
|
718
|
+
store: e.store,
|
|
719
|
+
snapshot: e.dataTransferSnapshot ?? { tables: [] },
|
|
720
|
+
dialect: e.dataTransferDialect ?? "memory",
|
|
721
|
+
tenantTables: [...e.tenantScopedTables],
|
|
722
|
+
loadProfile: Cn,
|
|
723
|
+
assetSource: Li(mi(), e.store),
|
|
724
|
+
putArchive: Ct
|
|
725
|
+
})
|
|
726
|
+
}] : [], Tt = [
|
|
727
|
+
...e.httpRoutes ?? [],
|
|
728
|
+
...xt.httpRoutes,
|
|
729
|
+
...wt,
|
|
730
|
+
...w.httpRoutes
|
|
731
|
+
];
|
|
732
|
+
Object.assign(j, D.handlers);
|
|
733
|
+
for (let t of A(e.discovered.streams ?? [])) j[t.descriptor.name] = (n) => hr((r) => ci(r, (r) => {
|
|
734
|
+
let i = Re(r), a = t.executor(n, i);
|
|
735
|
+
if (W.isEffect(a)) {
|
|
736
|
+
let t = a.pipe(W.provide(Pr(i.store)));
|
|
737
|
+
return (e.baseLayer ? t.pipe(W.provide(e.baseLayer)) : t).pipe(W.provide(ze)).pipe(W.provide(Be)).pipe(W.provide(He)).pipe(W.provide(Ge));
|
|
738
|
+
}
|
|
739
|
+
return typeof a == "object" && a && typeof a.then == "function" ? W.promise(() => a) : a;
|
|
740
|
+
}), `stream.${t.descriptor.name}`);
|
|
741
|
+
for (let t of e.discovered.workflows ?? []) j[t.definition.name] = (e) => K(async (e, n) => {
|
|
742
|
+
let r = n;
|
|
743
|
+
return Wr(S, {
|
|
744
|
+
subject: r.subject,
|
|
745
|
+
traceId: r.traceId,
|
|
746
|
+
source: "workflow-rpc"
|
|
747
|
+
}).start(t.definition.name, e);
|
|
748
|
+
}, e, `workflow.${t.definition.name}`);
|
|
749
|
+
de && (j[Vn.name] = (e) => q(O({
|
|
750
|
+
descriptor: Vn,
|
|
751
|
+
executor: (e) => {
|
|
752
|
+
let t = e.id;
|
|
753
|
+
return {
|
|
754
|
+
table: "_voltro_workflow_runs",
|
|
755
|
+
order: [{
|
|
756
|
+
column: "startedAt",
|
|
757
|
+
direction: "desc"
|
|
758
|
+
}],
|
|
759
|
+
predicate: Yn(U("id", t), U("executionId", t)),
|
|
760
|
+
take: 1,
|
|
761
|
+
skip: void 0,
|
|
762
|
+
projection: void 0
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
}, e), r, `subscription.${Vn.name}`), j[Un.name] = (e) => q(O({
|
|
766
|
+
descriptor: Un,
|
|
767
|
+
executor: (e) => {
|
|
768
|
+
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;
|
|
769
|
+
return {
|
|
770
|
+
table: "_voltro_workflow_runs",
|
|
771
|
+
order: [{
|
|
772
|
+
column: "startedAt",
|
|
773
|
+
direction: "desc"
|
|
774
|
+
}],
|
|
775
|
+
predicate: n.length === 0 ? void 0 : n.length === 1 ? n[0] : H(...n),
|
|
776
|
+
take: r,
|
|
777
|
+
skip: void 0,
|
|
778
|
+
projection: void 0
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
}, e), r, `subscription.${Un.name}`), j[Hn.name] = (e) => q(O({
|
|
782
|
+
descriptor: Hn,
|
|
783
|
+
executor: (e) => {
|
|
784
|
+
let t = e.runId;
|
|
785
|
+
return {
|
|
786
|
+
table: "_voltro_workflow_run_steps",
|
|
787
|
+
order: [{
|
|
788
|
+
column: "startedAt",
|
|
789
|
+
direction: "asc"
|
|
790
|
+
}],
|
|
791
|
+
predicate: U("runId", t),
|
|
792
|
+
take: 1e3,
|
|
793
|
+
skip: void 0,
|
|
794
|
+
projection: void 0
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
}, e), r, `subscription.${Hn.name}`), j[Bn.name] = (e) => q(O({
|
|
798
|
+
descriptor: Bn,
|
|
799
|
+
executor: (e) => {
|
|
800
|
+
let t = e.runId;
|
|
801
|
+
return {
|
|
802
|
+
table: "_voltro_workflow_run_events",
|
|
803
|
+
order: [{
|
|
804
|
+
column: "occurredAt",
|
|
805
|
+
direction: "asc"
|
|
806
|
+
}],
|
|
807
|
+
predicate: U("runId", t),
|
|
808
|
+
take: 1e3,
|
|
809
|
+
skip: void 0,
|
|
810
|
+
projection: void 0
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
}, e), r, `subscription.${Bn.name}`), j[Rn.name] = (e) => q(O({
|
|
814
|
+
descriptor: Rn,
|
|
815
|
+
executor: (e) => {
|
|
816
|
+
let t = e;
|
|
817
|
+
return {
|
|
818
|
+
table: "_voltro_workflow_events",
|
|
819
|
+
order: [{
|
|
820
|
+
column: "occurredAt",
|
|
821
|
+
direction: "desc"
|
|
822
|
+
}],
|
|
823
|
+
predicate: t.name === void 0 ? void 0 : U("name", t.name),
|
|
824
|
+
take: Math.max(1, Math.min(500, t.limit ?? 100)),
|
|
825
|
+
skip: void 0,
|
|
826
|
+
projection: void 0
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
}, e), r, `subscription.${Rn.name}`), j[V.name] = (e) => q(O({
|
|
830
|
+
descriptor: V,
|
|
831
|
+
executor: (e) => {
|
|
832
|
+
let t = e.eventId;
|
|
833
|
+
return {
|
|
834
|
+
table: "_voltro_workflow_event_deliveries",
|
|
835
|
+
order: [{
|
|
836
|
+
column: "createdAt",
|
|
837
|
+
direction: "asc"
|
|
838
|
+
}],
|
|
839
|
+
predicate: U("eventId", t),
|
|
840
|
+
take: 500,
|
|
841
|
+
skip: void 0,
|
|
842
|
+
projection: void 0
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
}, e), r, `subscription.${V.name}`), j[Ln.name] = (t) => K(async (t, n) => {
|
|
846
|
+
let r = t;
|
|
847
|
+
return await M(e.store, n.subject, { executionId: r.executionId }), await S.cancel(r.workflowName, r.executionId), await Pt(r.workflowName, r.executionId, "workflow.cancel"), { ok: !0 };
|
|
848
|
+
}, t, `action.${Ln.name}`), j[zn.name] = (t) => K(async (t, n) => {
|
|
849
|
+
let r = t;
|
|
850
|
+
return await M(e.store, n.subject, { executionId: r.executionId }), await S.resume(r.workflowName, r.executionId), { ok: !0 };
|
|
851
|
+
}, t, `action.${zn.name}`), j[Wn.name] = (t) => K(async (t, n) => {
|
|
852
|
+
let r = t;
|
|
853
|
+
return await M(e.store, n.subject, { id: r.id }), S.signal({ id: r.id }, r.signalName, r.payload);
|
|
854
|
+
}, t, `action.${Wn.name}`), j[Gn.name] = (t) => K(async (t, n) => {
|
|
855
|
+
let r = t;
|
|
856
|
+
return await M(e.store, n.subject, { id: r.id }), S.update({ id: r.id }, r.updateName, r.payload, r.timeoutMs === void 0 ? void 0 : { timeoutMs: r.timeoutMs });
|
|
857
|
+
}, t, `action.${Gn.name}`));
|
|
858
|
+
let Et = [
|
|
859
|
+
...A(e.discovered.queries).map((e) => B(e.descriptor)),
|
|
860
|
+
...A(e.discovered.mutations).map((e) => Pn(e.descriptor)),
|
|
861
|
+
...A(e.discovered.actions).map((e) => z(e.descriptor)),
|
|
862
|
+
...ct.queries.map((e) => B(e.descriptor)),
|
|
863
|
+
...ct.mutations.map((e) => Pn(e.descriptor)),
|
|
864
|
+
...lt.queries.map((e) => B(e.descriptor)),
|
|
865
|
+
...lt.mutations.map((e) => Pn(e.descriptor)),
|
|
866
|
+
...w.queries.map((e) => B(e.descriptor)),
|
|
867
|
+
...w.mutations.map((e) => Pn(e.descriptor)),
|
|
868
|
+
...w.actions.map((e) => z(e.descriptor)),
|
|
869
|
+
...A(e.discovered.streams ?? []).map((e) => Fn(e.descriptor)),
|
|
870
|
+
...D.rpcs,
|
|
871
|
+
...(e.discovered.workflows ?? []).map((e) => li(e.definition)),
|
|
872
|
+
...de ? [
|
|
873
|
+
B(Vn),
|
|
874
|
+
B(Un),
|
|
875
|
+
B(Hn),
|
|
876
|
+
B(Bn),
|
|
877
|
+
B(Rn),
|
|
878
|
+
B(V),
|
|
879
|
+
z(Ln),
|
|
880
|
+
z(zn),
|
|
881
|
+
z(Wn),
|
|
882
|
+
z(Gn)
|
|
883
|
+
] : []
|
|
884
|
+
], Dt = pi.make(...Et).middleware(An).middleware(jn), Ot = Mr({ resolveSubject: ({ headers: t, clientId: n }) => e.resolveSubject(t, n) }), kt = e.dormancyTenantId ?? ar, Mt = e.dormancy === "sleep" ? {
|
|
885
|
+
register: (t, n, r) => Zr(e.store, {
|
|
886
|
+
tenantId: r ?? kt,
|
|
887
|
+
kind: "workflow",
|
|
888
|
+
refId: t,
|
|
889
|
+
wakeAt: n
|
|
890
|
+
}),
|
|
891
|
+
cancel: (t, n) => _r(e.store, {
|
|
892
|
+
tenantId: n ?? kt,
|
|
893
|
+
kind: "workflow",
|
|
894
|
+
refId: t
|
|
895
|
+
}).then(() => {})
|
|
896
|
+
} : void 0, N = he ? await import("@voltro/workflow") : void 0, P = N?.makeWorkflowRunRecorder({
|
|
897
|
+
store: e.store,
|
|
898
|
+
...e.workflowRecording === void 0 ? {} : { recording: e.workflowRecording },
|
|
899
|
+
...Mt === void 0 ? {} : { wakeups: Mt }
|
|
900
|
+
}), Nt = async (t, n) => {
|
|
901
|
+
await N.closeWorkflowChildrenForParent({
|
|
902
|
+
store: e.store,
|
|
903
|
+
parentExecutionId: t,
|
|
904
|
+
parentStatus: n,
|
|
905
|
+
recorder: P,
|
|
906
|
+
log: { warn: (e, t) => {
|
|
907
|
+
process.stderr.write(`[workflow] ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
908
|
+
} },
|
|
909
|
+
interruptChild: async (t, n) => {
|
|
910
|
+
let r = (e.discovered.workflows ?? []).find((e) => e.definition.name === t);
|
|
911
|
+
if (!r) throw Error(`Unknown child workflow: ${t}`);
|
|
912
|
+
if (!u) throw Error("Workflow runtime is not ready");
|
|
913
|
+
await u.runPromise(r.definition.interrupt(n));
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
}, Pt = async (t, n, r) => {
|
|
917
|
+
let i = (await e.store.query({
|
|
918
|
+
table: "_voltro_workflow_runs",
|
|
919
|
+
order: [],
|
|
920
|
+
predicate: U("executionId", n),
|
|
921
|
+
projection: void 0,
|
|
922
|
+
skip: void 0,
|
|
923
|
+
take: 1
|
|
924
|
+
}))[0];
|
|
925
|
+
if (i === void 0) return;
|
|
926
|
+
let a = await e.store.update("_voltro_workflow_runs", i.id, {
|
|
927
|
+
status: "cancelled",
|
|
928
|
+
cancelled: !0,
|
|
929
|
+
completedAt: /* @__PURE__ */ new Date()
|
|
930
|
+
}), o = i.subject?.tenantId ?? void 0;
|
|
931
|
+
a && await P.recordEvent({
|
|
932
|
+
runId: i.id,
|
|
933
|
+
eventType: "run-cancelled",
|
|
934
|
+
payload: {
|
|
935
|
+
reason: r,
|
|
936
|
+
workflowName: t,
|
|
937
|
+
executionId: n,
|
|
938
|
+
...o == null ? {} : { tenantId: o }
|
|
939
|
+
}
|
|
940
|
+
}), a && await Nt(n, "cancelled");
|
|
941
|
+
}, Ft = [
|
|
942
|
+
...Gr(e.discovered.workflows ?? [], {
|
|
943
|
+
buildContext: (t, n) => e.buildContextForWorkflow?.(t, n) ?? Re({
|
|
944
|
+
subject: t.subject,
|
|
945
|
+
traceId: t.traceId
|
|
946
|
+
}, e.store, void 0, `workflow:${n.workflowName}`, { parentExecutionId: n.executionId }),
|
|
947
|
+
resolveStartContext: ae,
|
|
948
|
+
...oe === void 0 ? {} : { resolveAuthority: oe }
|
|
949
|
+
}, (t, n, r) => {
|
|
950
|
+
let i = N.getWorkflowVersionMetadata(t.definition);
|
|
951
|
+
return N.wrapWorkflowExecuteWithRunRecording({
|
|
952
|
+
name: t.definition.name,
|
|
953
|
+
store: e.store,
|
|
954
|
+
subject: r.subject,
|
|
955
|
+
source: r.source ?? null,
|
|
956
|
+
traceId: r.traceId,
|
|
957
|
+
workflowVersion: i.version,
|
|
958
|
+
workflowCompatibleVersions: i.compatibleWith,
|
|
959
|
+
workflowPatches: i.patches,
|
|
960
|
+
parentExecutionId: r?.parentExecutionId ?? null,
|
|
961
|
+
parentClosePolicy: r?.parentClosePolicy ?? null,
|
|
962
|
+
onParentClose: ({ executionId: e, status: t }) => Nt(e, t),
|
|
963
|
+
...dt(t.definition),
|
|
964
|
+
onTerminal: async ({ executionId: e }) => {
|
|
965
|
+
await l?.gate.release(e);
|
|
966
|
+
},
|
|
967
|
+
recorder: P,
|
|
968
|
+
pluginWorkflowStepLayer: nt,
|
|
969
|
+
recordRun: Yr
|
|
970
|
+
}, n);
|
|
971
|
+
}),
|
|
972
|
+
...e.discovered.workflowWorkers ?? [],
|
|
973
|
+
...ye === void 0 ? [] : [ye]
|
|
974
|
+
], It = [...(e.discovered.workflows ?? []).map((e) => e.definition.name).filter(Boolean), ...ye === void 0 ? [] : ["voltro.deliverWebhook"]], Rt = Ft.length > 0 ? G.mergeAll(...Ft) : G.empty;
|
|
975
|
+
if (((e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster" || ye !== void 0) && e.workflowEngineLayer !== void 0) {
|
|
976
|
+
let t = Rt.pipe(G.provideMerge(e.workflowEngineLayer));
|
|
977
|
+
u = Zn.make(e.baseLayer === void 0 ? t : t.pipe(G.provideMerge(e.baseLayer))), await u.runPromise(W.void), (e.log ?? R({ scope: "voltro:serve" })).child("workflow").info(`workflow runtime ready — ${It.length} entity type(s) registered`, { entities: It });
|
|
978
|
+
let n = await import("@voltro/workflow/cluster"), r = (e) => u.runPromise(n.redriveFailedRun(e)), i = (e) => u.runPromise(n.resumeRunFromStep(e));
|
|
979
|
+
m = await zt({
|
|
980
|
+
provider: Mi(e.plugins ?? [])?.broadcast?.provider,
|
|
981
|
+
crossReplica: Mi(e.plugins ?? [])?.broadcast?.crossReplica ?? !1,
|
|
982
|
+
namespace: je,
|
|
983
|
+
replicaId: crypto.randomUUID(),
|
|
984
|
+
pollStorage: () => u.runPromise(n.pollWorkflowStorage),
|
|
985
|
+
onChange: (t) => e.store.onChange((e) => t({
|
|
986
|
+
table: e.table,
|
|
987
|
+
op: e.op,
|
|
988
|
+
...e.origin === void 0 ? {} : { origin: e.origin }
|
|
989
|
+
})),
|
|
990
|
+
log: (e.log ?? R({ scope: "voltro:serve" })).child("workflow")
|
|
991
|
+
}), f = async (t) => {
|
|
992
|
+
let n = await De({
|
|
993
|
+
store: e.store,
|
|
994
|
+
workflows: e.discovered.workflows ?? [],
|
|
995
|
+
runRedrive: r
|
|
996
|
+
}, t.runId);
|
|
997
|
+
return n.statusReset && await P.recordEvent({
|
|
998
|
+
runId: t.runId,
|
|
999
|
+
eventType: "run-redriven",
|
|
1000
|
+
payload: {
|
|
1001
|
+
reason: "inspect.redrive",
|
|
1002
|
+
activitiesReset: n.outcome.activitiesReset
|
|
1003
|
+
}
|
|
1004
|
+
}), {
|
|
1005
|
+
redriven: n.outcome.redriven,
|
|
1006
|
+
activitiesReset: n.outcome.activitiesReset,
|
|
1007
|
+
reason: n.outcome.reason
|
|
1008
|
+
};
|
|
1009
|
+
}, p = async (t) => {
|
|
1010
|
+
let n = await ke({
|
|
1011
|
+
store: e.store,
|
|
1012
|
+
workflows: e.discovered.workflows ?? [],
|
|
1013
|
+
runResume: i
|
|
1014
|
+
}, t.runId, t.step);
|
|
1015
|
+
return n.statusReset && await P.recordEvent({
|
|
1016
|
+
runId: t.runId,
|
|
1017
|
+
eventType: "run-redriven",
|
|
1018
|
+
payload: {
|
|
1019
|
+
reason: "inspect.resume-from-step",
|
|
1020
|
+
step: n.stepName,
|
|
1021
|
+
activitiesReset: n.outcome.activitiesReset
|
|
1022
|
+
}
|
|
1023
|
+
}), {
|
|
1024
|
+
redriven: n.outcome.redriven,
|
|
1025
|
+
stepName: n.stepName,
|
|
1026
|
+
activitiesReset: n.outcome.activitiesReset,
|
|
1027
|
+
reason: n.outcome.reason
|
|
1028
|
+
};
|
|
1029
|
+
};
|
|
1030
|
+
let a = (e.scheduleCoordination ?? "single") === "advisoryLock" ? Dr(e.store, e.scheduleReplicaId ?? `pid-${process.pid}`) : ni, s = Nr({
|
|
1031
|
+
coordinator: a,
|
|
1032
|
+
replicaId: e.scheduleReplicaId ?? `pid-${process.pid}`
|
|
1033
|
+
}), d = {
|
|
1034
|
+
info: (e, t) => {
|
|
1035
|
+
process.stdout.write(`[flow-control] ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
1036
|
+
},
|
|
1037
|
+
warn: (e, t) => {
|
|
1038
|
+
process.stderr.write(`[flow-control] ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
1039
|
+
},
|
|
1040
|
+
error: (e, t) => {
|
|
1041
|
+
process.stderr.write(`[flow-control] ERROR ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
1042
|
+
}
|
|
1043
|
+
}, h, g = () => {
|
|
1044
|
+
if (h !== void 0) return h;
|
|
1045
|
+
if (o !== void 0 && P !== void 0) return h = ne({
|
|
1046
|
+
store: e.store,
|
|
1047
|
+
log: L,
|
|
1048
|
+
workflows: e.discovered.workflows ?? [],
|
|
1049
|
+
workflowsProxy: o,
|
|
1050
|
+
workflowRuntime: u,
|
|
1051
|
+
workflowRunRecorder: P,
|
|
1052
|
+
closeChildrenForParent: Nt
|
|
1053
|
+
}), h;
|
|
1054
|
+
};
|
|
1055
|
+
ee = g, l = $e({
|
|
1056
|
+
store: e.store,
|
|
1057
|
+
onChange: (t) => e.store.onChange((e) => t({
|
|
1058
|
+
table: e.table,
|
|
1059
|
+
op: e.op
|
|
1060
|
+
})),
|
|
1061
|
+
...e.scheduling === void 0 ? {} : {
|
|
1062
|
+
disarmWhenIdle: e.scheduling.disarmWhenIdle,
|
|
1063
|
+
drainIntervalMs: e.scheduling.admissionDrainMs,
|
|
1064
|
+
cancelSweepIntervalMs: e.scheduling.cancelSweepMs,
|
|
1065
|
+
stalenessSweepIntervalMs: e.scheduling.stalenessSweepMs
|
|
1066
|
+
},
|
|
1067
|
+
workflows: e.discovered.workflows ?? [],
|
|
1068
|
+
facade: () => o,
|
|
1069
|
+
cancelRunWithReason: g,
|
|
1070
|
+
recordRunEvent: () => P?.recordEvent,
|
|
1071
|
+
...e.workflowStaleness === void 0 ? {} : { staleness: e.workflowStaleness },
|
|
1072
|
+
...e.workflowSuspendSignalHintMs === void 0 ? {} : { suspendSignalHintMs: e.workflowSuspendSignalHintMs },
|
|
1073
|
+
scheduleCoordinated: s,
|
|
1074
|
+
onAbandoned: async (t) => {
|
|
1075
|
+
await We({
|
|
1076
|
+
workflows: e.discovered.workflows ?? [],
|
|
1077
|
+
facade: () => o,
|
|
1078
|
+
log: d,
|
|
1079
|
+
...t
|
|
1080
|
+
});
|
|
1081
|
+
},
|
|
1082
|
+
log: d
|
|
1083
|
+
});
|
|
1084
|
+
let _ = l;
|
|
1085
|
+
_ !== void 0 && qr(() => _.stop()), c = Ze({
|
|
1086
|
+
store: e.store,
|
|
1087
|
+
onChange: (t) => e.store.onChange((e) => t({
|
|
1088
|
+
table: e.table,
|
|
1089
|
+
op: e.op
|
|
1090
|
+
})),
|
|
1091
|
+
...e.scheduling === void 0 ? {} : {
|
|
1092
|
+
disarmWhenIdle: e.scheduling.disarmWhenIdle,
|
|
1093
|
+
tickIntervalMs: e.scheduling.inferenceTickMs
|
|
1094
|
+
},
|
|
1095
|
+
enabled: (e.discovered.workflows?.length ?? 0) > 0,
|
|
1096
|
+
resumeSignal: () => u === void 0 || N === void 0 ? void 0 : async ({ executionId: t, workflowName: n, signalName: r, payload: i }) => {
|
|
1097
|
+
await u.runPromise(N.completeSuspendingSignal({
|
|
1098
|
+
store: e.store,
|
|
1099
|
+
target: Ke(t, n),
|
|
1100
|
+
signalName: r,
|
|
1101
|
+
payload: i
|
|
1102
|
+
}));
|
|
1103
|
+
},
|
|
1104
|
+
runEffect: (e) => u.runPromise(e),
|
|
1105
|
+
scheduleCoordinated: s,
|
|
1106
|
+
log: d
|
|
1107
|
+
});
|
|
1108
|
+
let v = c;
|
|
1109
|
+
v !== void 0 && qr(() => v.stop()), o = (e.discovered.workflows?.length ?? 0) > 0 ? J({
|
|
1110
|
+
workflows: e.discovered.workflows ?? [],
|
|
1111
|
+
runEffect: (e) => u.runPromise(e),
|
|
1112
|
+
onEnqueue: () => m?.publishWake(),
|
|
1113
|
+
..._ === void 0 ? {} : {
|
|
1114
|
+
admitStart: _.gate.admitStart,
|
|
1115
|
+
startPayloadSchema: _.gate.startPayloadSchema,
|
|
1116
|
+
parkDelayedStart: _.gate.parkDelayed
|
|
1117
|
+
},
|
|
1118
|
+
rememberStartContext: te,
|
|
1119
|
+
signal: async (t, n, r) => {
|
|
1120
|
+
let i = await N.sendWorkflowSignal({
|
|
1121
|
+
store: e.store,
|
|
1122
|
+
recorder: P,
|
|
1123
|
+
target: t,
|
|
1124
|
+
signalName: n,
|
|
1125
|
+
payload: r
|
|
1126
|
+
});
|
|
1127
|
+
return await u.runPromise(N.completeSuspendingSignal({
|
|
1128
|
+
store: e.store,
|
|
1129
|
+
target: t,
|
|
1130
|
+
signalName: n,
|
|
1131
|
+
payload: r
|
|
1132
|
+
})).catch(() => {}), i;
|
|
1133
|
+
},
|
|
1134
|
+
update: (t, n, r, i) => N.sendWorkflowUpdate({
|
|
1135
|
+
store: e.store,
|
|
1136
|
+
recorder: P,
|
|
1137
|
+
target: t,
|
|
1138
|
+
updateName: n,
|
|
1139
|
+
payload: r,
|
|
1140
|
+
...i === void 0 ? {} : { options: i }
|
|
1141
|
+
}),
|
|
1142
|
+
listRuns: (t) => y(e.store, t),
|
|
1143
|
+
retry: (t, n) => ie({
|
|
1144
|
+
store: e.store,
|
|
1145
|
+
workflows: e.discovered.workflows ?? [],
|
|
1146
|
+
runPromise: (e) => u.runPromise(e)
|
|
1147
|
+
}, t, n),
|
|
1148
|
+
redrive: (t) => De({
|
|
1149
|
+
store: e.store,
|
|
1150
|
+
workflows: e.discovered.workflows ?? [],
|
|
1151
|
+
runRedrive: r
|
|
1152
|
+
}, t).then((e) => e.outcome)
|
|
1153
|
+
}) : void 0;
|
|
1154
|
+
}
|
|
1155
|
+
let Bt = G.mergeAll(Dt.toLayer(j), Ot), Vt = it(j, e.discovered.queries.map((e) => e.descriptor.name), de), Ht = G.mergeAll(Dt.toLayer(Vt), Ot), F = e.observability, Ut = await gr({
|
|
1156
|
+
...e.appName === void 0 ? {} : { serviceName: e.appName },
|
|
1157
|
+
...F && F.spanProcessors.length > 0 ? { extraSpanProcessors: F.spanProcessors } : {},
|
|
1158
|
+
...F && F.metricReaders.length > 0 ? { extraMetricReaders: F.metricReaders } : {},
|
|
1159
|
+
...F && Object.keys(F.resourceAttributes).length > 0 ? { resourceAttributes: F.resourceAttributes } : {},
|
|
1160
|
+
...F && F.sampler !== void 0 ? { sampler: F.sampler } : {}
|
|
1161
|
+
}), Wt = !1, I = e.store.ping ? () => e.store.ping().then(() => !0).catch(() => !1) : void 0, { server: Gt, shutdown: Kt } = ri({
|
|
1162
|
+
group: Dt,
|
|
1163
|
+
handlersLayer: Bt,
|
|
1164
|
+
httpHandlersLayer: Ht,
|
|
1165
|
+
port: e.port ?? 4e3,
|
|
1166
|
+
...e.host === void 0 ? {} : { host: e.host },
|
|
1167
|
+
path: e.path ?? "/ws",
|
|
1168
|
+
tracerLayer: Ut.layer,
|
|
1169
|
+
security: re(e),
|
|
1170
|
+
...tt,
|
|
1171
|
+
healthCheck: {
|
|
1172
|
+
isReady: () => Wt,
|
|
1173
|
+
...I ? { ping: I } : {}
|
|
1174
|
+
},
|
|
1175
|
+
...Tt.length > 0 ? { httpRoutes: Tt } : {},
|
|
1176
|
+
...e.getStore === void 0 ? {} : { getStore: e.getStore },
|
|
1177
|
+
...Se.size > 0 ? { webhookRoutes: Se } : {},
|
|
1178
|
+
...e.inspectRoute === void 0 ? {} : { inspectRoute: e.inspectRoute }
|
|
1179
|
+
}), qt = Hi(Gt);
|
|
1180
|
+
if (await mr(Gt), (e.discovered.schedules?.length ?? 0) > 0) {
|
|
1181
|
+
let t = (e.scheduleCoordination ?? "single") === "advisoryLock" ? Dr(e.store, e.scheduleReplicaId ?? `pid-${process.pid}`) : ni;
|
|
1182
|
+
h = await ii(e.discovered.schedules ?? [], {
|
|
1183
|
+
store: e.store,
|
|
1184
|
+
coordinator: t,
|
|
1185
|
+
defaultTrigger: e.scheduleDefaultTrigger ?? "self",
|
|
1186
|
+
replicaId: e.scheduleReplicaId ?? `pid-${process.pid}`,
|
|
1187
|
+
armSelf: e.scheduleArmSelf ?? !0,
|
|
1188
|
+
dormancy: e.dormancy ?? "always-on",
|
|
1189
|
+
...e.dormancyTenantId === void 0 ? {} : { dormancyTenantId: e.dormancyTenantId },
|
|
1190
|
+
buildContext: ({ traceId: t, scheduleName: n, subject: r }) => Re({
|
|
1191
|
+
subject: r,
|
|
1192
|
+
traceId: t
|
|
1193
|
+
}, e.store, void 0, `schedule:${n}`),
|
|
1194
|
+
log: {
|
|
1195
|
+
info: (e, t) => {
|
|
1196
|
+
process.stdout.write(`[schedule] ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
1197
|
+
},
|
|
1198
|
+
warn: (e, t) => {
|
|
1199
|
+
process.stderr.write(`[schedule] ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
1200
|
+
},
|
|
1201
|
+
error: (e, t) => {
|
|
1202
|
+
process.stderr.write(`[schedule] ERROR ${e} ${t ? JSON.stringify(t) : ""}\n`);
|
|
1203
|
+
},
|
|
1204
|
+
debug: () => {}
|
|
1205
|
+
},
|
|
1206
|
+
...e.scheduleFireInterceptor === void 0 ? {} : { interceptFire: e.scheduleFireInterceptor },
|
|
1207
|
+
...e.onScheduleRunEvent === void 0 ? {} : { onRunEvent: e.onScheduleRunEvent }
|
|
1208
|
+
}), e.onSchedulerReady?.(h);
|
|
1209
|
+
}
|
|
1210
|
+
let L = e.log ?? R({ scope: "voltro:serve" }), Jt, Yt;
|
|
1211
|
+
if ((e.discovered.subscribers?.length ?? 0) > 0 && (Jt = xe(e.discovered.subscribers ?? [], e.store, L.child("subscribe"), e.schemaRegistry, D.bus)), (e.discovered.reactions?.length ?? 0) > 0) {
|
|
1212
|
+
let t = L.child("reaction"), n = async (n, r) => {
|
|
1213
|
+
if (n.kind === "workflow") {
|
|
1214
|
+
if (S === void 0) {
|
|
1215
|
+
t.warn("reaction workflow act skipped — no workflow engine in this app", { workflow: n.workflow });
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
let e = n.payload === void 0 ? r.new ?? r.old ?? {} : n.payload(r);
|
|
1219
|
+
await Wr(S, {
|
|
1220
|
+
traceId: `reaction:${n.workflow}`,
|
|
1221
|
+
source: `reaction:${n.workflow}`
|
|
1222
|
+
}).start(n.workflow, e);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
await pe(n.agent, r, {
|
|
1226
|
+
findAgentSend: (t) => e.discovered.actions.find((e) => e.descriptor.name === `${t}.send`),
|
|
1227
|
+
runAction: (e, t, n) => Promise.resolve(ft(e, t, n)),
|
|
1228
|
+
makeSubject: (e) => Mn(e),
|
|
1229
|
+
now: () => Date.now(),
|
|
1230
|
+
log: t
|
|
1231
|
+
});
|
|
1232
|
+
}, r = async (n, r) => {
|
|
1233
|
+
try {
|
|
1234
|
+
let { requireAiBudget: t } = await import("@voltro/ai");
|
|
1235
|
+
return (await W.runPromise(W.either(t(e.store, {
|
|
1236
|
+
tenantId: n,
|
|
1237
|
+
limitUsd: r
|
|
1238
|
+
}))))._tag === "Right";
|
|
1239
|
+
} catch (e) {
|
|
1240
|
+
return t.warn("reaction budget check failed — refusing the act", { tenantId: n }, e), !1;
|
|
1241
|
+
}
|
|
1242
|
+
}, i = At(e.store, { onError: (e) => t.warn("reaction: rate-slot claim failed; refusing the act", { cause: String(e) }) });
|
|
1243
|
+
Yt = st(e.discovered.reactions ?? [], e.store, {
|
|
1244
|
+
runAct: n,
|
|
1245
|
+
checkBudget: r,
|
|
1246
|
+
claimRateSlot: (e) => i.claim(e)
|
|
1247
|
+
}, t);
|
|
1248
|
+
}
|
|
1249
|
+
let Xt;
|
|
1250
|
+
(e.discovered.aggregates?.length ?? 0) > 0 && (Xt = await v({
|
|
1251
|
+
discovered: e.discovered.aggregates ?? [],
|
|
1252
|
+
store: e.store,
|
|
1253
|
+
log: L.child("aggregate"),
|
|
1254
|
+
...e.analytics === void 0 ? {} : { analytics: e.analytics },
|
|
1255
|
+
...e.aggregateStorage === void 0 ? {} : { storage: e.aggregateStorage },
|
|
1256
|
+
...e.aggregateCoordinator === void 0 ? {} : { coordinator: e.aggregateCoordinator }
|
|
1257
|
+
}), ze = G.succeed(rr, Xt.registry));
|
|
1258
|
+
let Zt;
|
|
1259
|
+
(e.discovered.expectations?.length ?? 0) > 0 && (Zt = dr({
|
|
1260
|
+
discovered: e.discovered.expectations ?? [],
|
|
1261
|
+
store: e.store,
|
|
1262
|
+
log: L.child("expectation")
|
|
1263
|
+
}), Be = G.succeed(sr, Zt.registry)), (e.discovered.budgets?.length ?? 0) > 0 && (n = pr({
|
|
1264
|
+
discovered: e.discovered.budgets ?? [],
|
|
1265
|
+
log: L.child("finops")
|
|
1266
|
+
}), He = G.succeed(ir, n.registry));
|
|
1267
|
+
let Qt;
|
|
1268
|
+
return (e.discovered.experiments?.length ?? 0) > 0 && (Qt = fr({
|
|
1269
|
+
discovered: e.discovered.experiments ?? [],
|
|
1270
|
+
store: e.store,
|
|
1271
|
+
log: L.child("experiment")
|
|
1272
|
+
}), Ge = G.succeed(cr, Qt.registry)), Wt = !0, e.bootTiming?.mark("ready"), {
|
|
1273
|
+
dispatcher: r,
|
|
1274
|
+
server: Gt,
|
|
1275
|
+
scheduler: h,
|
|
1276
|
+
eventsSnapshot: me(D.bus, D.declared),
|
|
1277
|
+
membersSnapshot: () => ({
|
|
1278
|
+
members: Ie.membership.list(),
|
|
1279
|
+
capturedAt: Date.now()
|
|
1280
|
+
}),
|
|
1281
|
+
agentTools: () => yt,
|
|
1282
|
+
rpcMetrics: () => Xe,
|
|
1283
|
+
webhooksService: () => ve,
|
|
1284
|
+
runCanceller: () => ee(),
|
|
1285
|
+
flowControlHealth: () => l?.cancelHealth(),
|
|
1286
|
+
inferenceHealth: () => c?.health(),
|
|
1287
|
+
workflowWriteActions: () => S === void 0 || P === void 0 ? void 0 : se({
|
|
1288
|
+
store: e.store,
|
|
1289
|
+
log: L,
|
|
1290
|
+
workflows: e.discovered.workflows ?? [],
|
|
1291
|
+
workflowsProxy: o,
|
|
1292
|
+
workflowRuntime: u,
|
|
1293
|
+
workflowRunRecorder: P,
|
|
1294
|
+
closeChildrenForParent: Nt
|
|
1295
|
+
}),
|
|
1296
|
+
redriveWorkflowRun: (e) => f ? f(e) : Promise.reject(/* @__PURE__ */ Error("redrive: this app registers no workflows")),
|
|
1297
|
+
resumeWorkflowRunFromStep: (e) => p ? p(e) : Promise.reject(/* @__PURE__ */ Error("resume-from-step: this app registers no workflows")),
|
|
1298
|
+
close: async () => {
|
|
1299
|
+
Wt = !1, await qt.drainRequests();
|
|
1300
|
+
for (let e of Ce) try {
|
|
1301
|
+
await e();
|
|
1302
|
+
} catch (e) {
|
|
1303
|
+
L.warn("serve: teardown step failed", {}, e);
|
|
1304
|
+
}
|
|
1305
|
+
await Le?.detach(), await Ie.detach(), Xt?.detach(), Zt?.detach(), n?.detach(), Qt?.detach(), Yt?.(), Jt?.(), await h?.shutdown(), r.close(), await m?.detach(), await u?.dispose(), await Kt(), await qt.finish();
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
}, $ = R({ scope: "voltro:serve" }), ga = (e, t, n) => (e === "production" || e === "staging") && t !== "memory" && n !== "0", _a = Ht, va = async (e) => {
|
|
1309
|
+
let t = xn(process.cwd());
|
|
1310
|
+
if (On(t)) {
|
|
1311
|
+
let n;
|
|
1312
|
+
try {
|
|
1313
|
+
let e = await import(kn(t).href);
|
|
1314
|
+
typeof e.runServe == "function" ? n = e.runServe : $.warn("serve bundle has no runServe export — using the standard serve path");
|
|
1315
|
+
} catch (e) {
|
|
1316
|
+
$.warn("serve bundle failed to load — using the standard serve path", {}, e);
|
|
1317
|
+
}
|
|
1318
|
+
if (n) return $.info("serve: booting from the precompiled serve bundle"), n(e);
|
|
1319
|
+
}
|
|
1320
|
+
return ya(e);
|
|
1321
|
+
}, ya = async (s) => {
|
|
1322
|
+
let d = Sn();
|
|
1323
|
+
e("serve");
|
|
1324
|
+
try {
|
|
1325
|
+
bi();
|
|
1326
|
+
} catch (e) {
|
|
1327
|
+
throw i(e instanceof Error ? e.message : String(e));
|
|
1328
|
+
}
|
|
1329
|
+
let g = process.cwd(), v = await He(g), ne = F({
|
|
1330
|
+
kind: "api",
|
|
1331
|
+
configPort: v?.port,
|
|
1332
|
+
env: process.env,
|
|
1333
|
+
flagPort: _a(s, "--port")
|
|
1334
|
+
});
|
|
1335
|
+
for (let e of ne.warnings) $.warn(e);
|
|
1336
|
+
let ie = ne.port;
|
|
1337
|
+
$r(Qr(v?.secrets)), await Ut({
|
|
1338
|
+
rawEnv: v?.env,
|
|
1339
|
+
appType: "api",
|
|
1340
|
+
root: g,
|
|
1341
|
+
log: $,
|
|
1342
|
+
generateTypes: !1
|
|
1343
|
+
}), d.mark("config");
|
|
1344
|
+
let y = (process.env.DB_DIALECT ?? v?.store ?? "memory").toLowerCase(), se = (y === "mariadb" || y === "postgres" || y === "mssql") && (process.env.CDC ?? "1") !== "0", ce = y === "mariadb" ? "mariadb" : y === "mssql" ? "mssql" : void 0, le = bn(g);
|
|
1345
|
+
if (!r() && On(le)) try {
|
|
1346
|
+
let e = await import(kn(le).href);
|
|
1347
|
+
if (e.modules) {
|
|
1348
|
+
let t = {};
|
|
1349
|
+
for (let [n, r] of Object.entries(e.modules)) t[En(g, n)] = r;
|
|
1350
|
+
n(t), $.info("precompiled api bundle loaded", { modules: Object.keys(t).length });
|
|
1351
|
+
}
|
|
1352
|
+
} catch (e) {
|
|
1353
|
+
$.warn("precompiled api bundle failed to load — falling back to source", {}, e);
|
|
1354
|
+
}
|
|
1355
|
+
let b = await Ye(g), x = await Ot(b, { cdc: se && ce !== void 0 }), ue = Vt(x);
|
|
1356
|
+
{
|
|
1357
|
+
let e = /* @__PURE__ */ new Set([
|
|
1358
|
+
...x.queries.filter((e) => e.descriptor.overridesPlugin === !0).map((e) => e.descriptor.name),
|
|
1359
|
+
...x.mutations.filter((e) => e.descriptor.overridesPlugin === !0).map((e) => e.descriptor.name),
|
|
1360
|
+
...x.actions.filter((e) => e.descriptor.overridesPlugin === !0).map((e) => e.descriptor.name)
|
|
1361
|
+
]);
|
|
1362
|
+
Xt(Yt(v?.plugins ?? []), [
|
|
1363
|
+
...x.queries.map((e) => e.descriptor.name),
|
|
1364
|
+
...x.mutations.map((e) => e.descriptor.name),
|
|
1365
|
+
...x.actions.map((e) => e.descriptor.name),
|
|
1366
|
+
...x.streams.map((e) => e.descriptor.name)
|
|
1367
|
+
], e);
|
|
1368
|
+
let t = ae(x.serverOnlyLeaks, Ae(process.env, "strict"), br, "`voltro serve`");
|
|
1369
|
+
if (t.action === "fail") throw i(t.message ?? "");
|
|
1370
|
+
t.action === "warn" && $.warn(t.message ?? "");
|
|
1371
|
+
}
|
|
1372
|
+
let fe = b.filter((e) => vn.test(e)), pe = fe.length > 0 ? await _n(fe, $.child("webhooks")) : {
|
|
1373
|
+
outgoing: [],
|
|
1374
|
+
incoming: [],
|
|
1375
|
+
providers: []
|
|
1376
|
+
}, me = hn(x.events), be = pe.outgoing.length + pe.incoming.length + pe.providers.length + me.length === 0 ? void 0 : {
|
|
1377
|
+
...pe,
|
|
1378
|
+
outgoing: [...pe.outgoing, ...me]
|
|
1379
|
+
}, xe = rn({
|
|
1380
|
+
nodeEnv: process.env.NODE_ENV,
|
|
1381
|
+
cdcDialect: ce,
|
|
1382
|
+
declared: v?.schema
|
|
1383
|
+
}), we = Qt({
|
|
1384
|
+
gates: xe,
|
|
1385
|
+
runtime: {
|
|
1386
|
+
traces: ve(),
|
|
1387
|
+
undo: oi()
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
if (we !== void 0) throw i(`serve: ${we}`);
|
|
1391
|
+
let De = nn({
|
|
1392
|
+
mix: x.featureMix,
|
|
1393
|
+
plugins: v?.plugins ?? [],
|
|
1394
|
+
gates: xe,
|
|
1395
|
+
...ce ? { cdcDialect: ce } : {}
|
|
1396
|
+
}), Oe = v?.analytics !== void 0 && v.analytics.kind !== "noop" && y !== "memory" ? (await I(y)).makeSqlLayer(k()) : void 0, ke = await qe({
|
|
1397
|
+
spec: v?.analytics,
|
|
1398
|
+
sqlLayer: Oe,
|
|
1399
|
+
log: $
|
|
1400
|
+
}), T = (() => {
|
|
1401
|
+
let e = new Set(x.tables.map((e) => e.tableName)), t = [...x.tables];
|
|
1402
|
+
for (let n of [...De, ...ke.tables]) e.has(n.tableName) || (e.add(n.tableName), t.push(n));
|
|
1403
|
+
return t;
|
|
1404
|
+
})();
|
|
1405
|
+
for (let e of T) Jn(e);
|
|
1406
|
+
{
|
|
1407
|
+
let e = xr(si(Be(x), It(T)));
|
|
1408
|
+
e !== void 0 && $.warn(e);
|
|
1409
|
+
}
|
|
1410
|
+
let Pe = (process.env.NODE_ENV ?? "").toLowerCase();
|
|
1411
|
+
if (ga(Pe, y, process.env.VOLTRO_AUTO_MIGRATE)) {
|
|
1412
|
+
let e = (await I(y)).makeSqlLayer(k()), t = await W.runPromise(Qn.SqlClient.pipe(W.flatMap((e) => tr(e, g)), W.provide(e), W.catchAll(() => W.succeed([]))));
|
|
1413
|
+
t.length > 0 && ($.error(`serve: refusing to boot — ${t.length} pending file-based migration(s) have never run against this database. They perform the changes a schema diff cannot infer (data moves, backfills, table splits), so the declarative fingerprint check below cannot see them and would have let this process serve un-migrated data.`, { pending: t }), $.error("Run them from your pre-deploy job — `voltro db migrate .` (schema + files) or `voltro db files .` (files alone) — or set VOLTRO_AUTO_MIGRATE=0 to bypass every boot schema check. `voltro serve` never applies them itself: a rolling deploy would start N replicas and each would try."), process.exit(1));
|
|
1414
|
+
let n = await W.runPromise(Qn.SqlClient.pipe(W.flatMap((e) => nr(e, T, {
|
|
1415
|
+
appliedBy: `serve:${Pe}`,
|
|
1416
|
+
environment: "prod",
|
|
1417
|
+
dialectId: y
|
|
1418
|
+
})), W.provide(e)));
|
|
1419
|
+
n.kind === "prod-mismatch" && ($.error(er(n, y)), $.error(en({
|
|
1420
|
+
gates: xe,
|
|
1421
|
+
nodeEnv: process.env.NODE_ENV,
|
|
1422
|
+
cdcDialect: ce,
|
|
1423
|
+
declared: v?.schema
|
|
1424
|
+
})), $.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(er(n, y));
|
|
1425
|
+
}
|
|
1426
|
+
await Jt({
|
|
1427
|
+
dialectId: y,
|
|
1428
|
+
tables: T,
|
|
1429
|
+
mode: qt(v?.reactiveTriggers),
|
|
1430
|
+
lockSchema: k().schema,
|
|
1431
|
+
makeLayer: async () => (await I(y)).makeSqlLayer(k()),
|
|
1432
|
+
log: {
|
|
1433
|
+
info: (e, t) => $.info(e, t ?? {}),
|
|
1434
|
+
warn: (e, t) => $.warn(e, t ?? {})
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
let Fe = Ur(T);
|
|
1438
|
+
d.mark("discover");
|
|
1439
|
+
let E = await rt(v, void 0);
|
|
1440
|
+
{
|
|
1441
|
+
let e = await ee(E);
|
|
1442
|
+
if (e !== void 0) throw i(`serve: ${e}`);
|
|
1443
|
+
}
|
|
1444
|
+
let Ve = ui(E, y);
|
|
1445
|
+
for (let e of tt({
|
|
1446
|
+
dialect: String(v?.store ?? process.env.DB_DIALECT ?? "postgres"),
|
|
1447
|
+
changeStrategy: (process.env.CDC ?? "1") === "0" ? "inline" : "cdc",
|
|
1448
|
+
dbUrl: process.env.DB_URL,
|
|
1449
|
+
crossReplicaBus: Mi(v?.plugins ?? [])?.broadcast.crossReplica === !0,
|
|
1450
|
+
tables: x.tables.map((e) => ({
|
|
1451
|
+
tableName: e.tableName,
|
|
1452
|
+
isReactive: e.isReactive === !0
|
|
1453
|
+
})),
|
|
1454
|
+
querySources: x.queries.flatMap((e) => {
|
|
1455
|
+
let t = e.descriptor.source;
|
|
1456
|
+
return t === void 0 ? [] : typeof t == "string" ? [t] : [...t];
|
|
1457
|
+
})
|
|
1458
|
+
})) e.level === "warn" ? $.warn(e.message) : $.info(e.message);
|
|
1459
|
+
{
|
|
1460
|
+
let e = _t({
|
|
1461
|
+
tables: Kn().map((e) => ({ tableName: e.tableName })),
|
|
1462
|
+
queries: x.queries.map((e) => ({
|
|
1463
|
+
name: e.descriptor.name,
|
|
1464
|
+
source: e.descriptor.source
|
|
1465
|
+
}))
|
|
1466
|
+
}), t = pt(e);
|
|
1467
|
+
t !== void 0 && $.warn(t);
|
|
1468
|
+
}
|
|
1469
|
+
v?.cache && !process.env.CACHE_BACKEND && (process.env.CACHE_BACKEND = v.cache), v?.cacheRedisUrl && !process.env.CACHE_REDIS_URL && (process.env.CACHE_REDIS_URL = v.cacheRedisUrl), v?.cacheRedisDriver && !process.env.CACHE_REDIS_DRIVER && (process.env.CACHE_REDIS_DRIVER = v.cacheRedisDriver), v?.cacheKeyPrefix && !process.env.CACHE_KEY_PREFIX && (process.env.CACHE_KEY_PREFIX = v.cacheKeyPrefix);
|
|
1470
|
+
let { service: Ue, invalidationBus: We, snapshotCache: Ke, cache: Je, semantic: Ze, evictSource: $e, backend: it, stats: ot, dispose: st } = await Xe({
|
|
1471
|
+
env: process.env,
|
|
1472
|
+
semantic: v?.cacheSemantic ?? !1
|
|
1473
|
+
});
|
|
1474
|
+
Ze !== void 0 && $.info("semantic cache enabled — reactive eviction on live writes"), $.info(`cache backend resolved: ${it}` + (it === "redis" ? ` (driver ${process.env.CACHE_REDIS_DRIVER ?? "resp"})` : " — in-process, not cross-instance")), E.onChange((e) => {
|
|
1475
|
+
if (W.runFork(We.publish(e.table)), $e !== void 0) {
|
|
1476
|
+
let t = (e.new ?? e.old)?.id;
|
|
1477
|
+
$e({
|
|
1478
|
+
table: e.table,
|
|
1479
|
+
op: e.op,
|
|
1480
|
+
...t === void 0 ? {} : { id: t }
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
}), v?.kv && !process.env.KV_BACKEND && (process.env.KV_BACKEND = v.kv), v?.kvRedisUrl && !process.env.KV_REDIS_URL && (process.env.KV_REDIS_URL = v.kvRedisUrl), v?.kvKeyPrefix && !process.env.KV_KEY_PREFIX && (process.env.KV_KEY_PREFIX = v.kvKeyPrefix);
|
|
1484
|
+
let { kv: ut, service: dt } = await jr({ store: E });
|
|
1485
|
+
Nt({
|
|
1486
|
+
log: $,
|
|
1487
|
+
max: Kt(),
|
|
1488
|
+
outOfPool: p(y, (process.env.CDC ?? "1") !== "0"),
|
|
1489
|
+
readPools: t.replicationSnapshot()?.replicaCount ?? 0,
|
|
1490
|
+
always: !0
|
|
1491
|
+
}), d.mark("store");
|
|
1492
|
+
let ht = ur({
|
|
1493
|
+
store: E,
|
|
1494
|
+
sink: ke.sink,
|
|
1495
|
+
log: $
|
|
1496
|
+
}), bt = Ge({
|
|
1497
|
+
store: E,
|
|
1498
|
+
dialect: y,
|
|
1499
|
+
log: { info: (e) => $.info(e) }
|
|
1500
|
+
}), M = v?.plugins ?? [], At = process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, Lt, zt;
|
|
1501
|
+
y !== "memory" && (Lt = Zn.make((await I(y)).makeSqlLayer(k())), zt = await Lt.runPromise(Qn.SqlClient));
|
|
1502
|
+
let Ht = [
|
|
1503
|
+
"postgres",
|
|
1504
|
+
"mariadb",
|
|
1505
|
+
"mysql",
|
|
1506
|
+
"mssql"
|
|
1507
|
+
].includes(y) ? Dr(E, At, $) : ni, gn = N(v?.scheduling), xn = Nr({
|
|
1508
|
+
maxIdleIntervalMs: gn.pollCeilingMs,
|
|
1509
|
+
coordinator: Ht,
|
|
1510
|
+
replicaId: At,
|
|
1511
|
+
log: $
|
|
1512
|
+
}), Cn = [], wn = process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, Dn = Mi(v?.plugins ?? [])?.broadcast?.provider, R = Qe(v?.plugins, v?.name ?? Tn(g));
|
|
1513
|
+
{
|
|
1514
|
+
let e = et(v?.plugins, v?.name ?? Tn(g));
|
|
1515
|
+
e !== void 0 && $.warn(e);
|
|
1516
|
+
}
|
|
1517
|
+
let An = jt(v?.plugins, {
|
|
1518
|
+
instanceId: wn,
|
|
1519
|
+
namespace: R,
|
|
1520
|
+
meta: { mode: "serve" },
|
|
1521
|
+
logger: $
|
|
1522
|
+
}), jn = {
|
|
1523
|
+
...zt ? { sql: zt } : {},
|
|
1524
|
+
instanceId: wn,
|
|
1525
|
+
membership: An.membership,
|
|
1526
|
+
...Dn === void 0 ? {} : { broadcast: Dn },
|
|
1527
|
+
broadcastChannels: { presence: ji(R, "presence") },
|
|
1528
|
+
scheduleCoordinated: (e, t, n) => {
|
|
1529
|
+
let r = xn(e, t, n);
|
|
1530
|
+
return Cn.push(r), r;
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
for (let e of M) e.bindDataStore?.(Ve, jn);
|
|
1534
|
+
l({
|
|
1535
|
+
store: E,
|
|
1536
|
+
...ct(),
|
|
1537
|
+
log: $
|
|
1538
|
+
});
|
|
1539
|
+
let z = M.filter((e) => typeof e.onChangeEvent == "function");
|
|
1540
|
+
if (z.length > 0) {
|
|
1541
|
+
let e = E.changeScope ?? "local";
|
|
1542
|
+
E.onChange((t) => {
|
|
1543
|
+
let n = ye(t, e);
|
|
1544
|
+
for (let e of z) W.runFork(e.onChangeEvent(n).pipe(W.catchAllCause((t) => W.sync(() => $.warn(`plugin ${e.name} onChangeEvent failed`, { error: Xn.pretty(t) })))));
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
let Mn = Ne({
|
|
1548
|
+
plugins: M,
|
|
1549
|
+
appName: v?.name ?? "voltro-api",
|
|
1550
|
+
appType: "api",
|
|
1551
|
+
voltroVersion: process.env.npm_package_version ?? "0.0.0",
|
|
1552
|
+
log: $
|
|
1553
|
+
});
|
|
1554
|
+
M.length && await Mn.activate(), d.mark("plugins");
|
|
1555
|
+
let Nn = await Mn.gatherObservability(), Pn = {
|
|
1556
|
+
info: (e, t) => process.stdout.write(`[broadcast] ${e} ${t ? JSON.stringify(t) : ""}\n`),
|
|
1557
|
+
warn: (e, t) => process.stderr.write(`[broadcast] ${e} ${t ? JSON.stringify(t) : ""}\n`),
|
|
1558
|
+
debug: () => {}
|
|
1559
|
+
}, B, Fn = await j(E, v, y, R, Pn, (e, t) => {
|
|
1560
|
+
B?.refreshAll(`broadcast gap: missed ${t} change(s) from ${e}`);
|
|
1561
|
+
}), In = v?.apiKeys, Ln = (typeof In == "object" ? In.prefix : void 0) ?? "voltro_", Rn = In ? yr(E) : void 0, V = Rn ? kr({ flush: Ar(Rn) }) : void 0;
|
|
1562
|
+
V && qr(() => V.shutdown());
|
|
1563
|
+
let zn = Rn ? Or(Rn, {
|
|
1564
|
+
prefix: Ln,
|
|
1565
|
+
...V ? { usage: V } : {}
|
|
1566
|
+
}) : void 0, Bn = zn ? [Sr(zn, { prefix: Ln })] : [], Vn = xt([...v?.auth?.strategies ?? [], ...Bn], ki(v?.plugins ?? []), v?.auth?.anonymousTenantRequired ?? !1, v?.auth, () => Ve), Hn = [...v?.restRoutes ?? [], ...zn ? lr(zn, (typeof In == "object" ? In.managementPath : void 0) ?? "/v1/api-keys") : []], Un = St(v?.idempotency, E), Wn = M.map((e) => e.services).filter((e) => e !== void 0), Gn = G.mergeAll(gt({
|
|
1567
|
+
analyticsLayer: ke.layer,
|
|
1568
|
+
cacheService: Ue,
|
|
1569
|
+
kvService: dt,
|
|
1570
|
+
...Ze === void 0 ? {} : { semanticCache: Ze },
|
|
1571
|
+
pluginServices: Wn,
|
|
1572
|
+
userLayers: v?.layers ?? []
|
|
1573
|
+
}), Le(v?.http ?? {})), H = await Re({
|
|
1574
|
+
files: b,
|
|
1575
|
+
store: E,
|
|
1576
|
+
log: $,
|
|
1577
|
+
seedPolicy: "report",
|
|
1578
|
+
seedPattern: dn,
|
|
1579
|
+
loadSeedFiles: L,
|
|
1580
|
+
startupPattern: on,
|
|
1581
|
+
loadStartupFiles: a,
|
|
1582
|
+
runStartups: o,
|
|
1583
|
+
emailPattern: A,
|
|
1584
|
+
loadEmailFiles: wt,
|
|
1585
|
+
registerEmailTemplates: Ai
|
|
1586
|
+
});
|
|
1587
|
+
(H.startupCount > 0 || H.emailCount > 0) && $.info("boot lifecycle", {
|
|
1588
|
+
startups: H.startupCount,
|
|
1589
|
+
emailTemplates: H.emailCount
|
|
1590
|
+
}), H.startups !== void 0 && qr(async () => {
|
|
1591
|
+
await H.startups.stop();
|
|
1592
|
+
}), de({
|
|
1593
|
+
demands: Se(ue),
|
|
1594
|
+
isRegistered: (e) => Cr(e) !== void 0
|
|
1595
|
+
});
|
|
1596
|
+
let U = Ct({
|
|
1597
|
+
schedules: at({
|
|
1598
|
+
schedules: x.schedules,
|
|
1599
|
+
seeds: H.seeds,
|
|
1600
|
+
store: E,
|
|
1601
|
+
log: $.child("seeds")
|
|
1602
|
+
}),
|
|
1603
|
+
workflows: x.workflows ?? [],
|
|
1604
|
+
log: $.child("workflow-schedules")
|
|
1605
|
+
}), Yn = v?.scheduling ?? {}, rr = Yn.trigger ?? "self", ir = /* @__PURE__ */ new Set([
|
|
1606
|
+
"postgres",
|
|
1607
|
+
"mysql",
|
|
1608
|
+
"mariadb",
|
|
1609
|
+
"mssql"
|
|
1610
|
+
]), ar = Yn.coordination ?? (ir.has(y) ? "advisoryLock" : "single"), or = ar === "cluster" && ir.has(y), sr = or ? "cluster" : ar === "advisoryLock" && ir.has(y) ? "advisoryLock" : "single";
|
|
1611
|
+
ar === "cluster" && !or && $.warn("scheduling.coordination=cluster needs a sql-backed store except sqlite — falling back to single"), ar === "advisoryLock" && !ir.has(y) && $.warn("scheduling.coordination=advisoryLock needs a SQL store (the claim-row gate) — falling back to single");
|
|
1612
|
+
let cr, dr = x.workflows.length > 0 || x.workflowWorkers.length > 0 || x.eventTriggers.length > 0 || (be?.outgoing.length ?? 0) > 0 || or, fr;
|
|
1613
|
+
if (dr) {
|
|
1614
|
+
if (y === "mssql") {
|
|
1615
|
+
let e = await mn(process.cwd());
|
|
1616
|
+
e && $.warn(e);
|
|
1617
|
+
}
|
|
1618
|
+
let [{ WorkflowEngine: e }, { makeClusterCronLayer: t, workflowEngineLayer: n, resolveRunnerStorage: r, resolveFailoverTuning: i }] = await Promise.all([import("@effect/workflow"), import("@voltro/workflow/cluster")]), a = or ? U.filter((e) => (e.trigger ?? rr) === "self").map((e) => t({
|
|
1619
|
+
name: e.name,
|
|
1620
|
+
cron: vr(e),
|
|
1621
|
+
execute: async () => {
|
|
1622
|
+
await cr?.fireFromCluster(e.name);
|
|
1623
|
+
}
|
|
1624
|
+
})) : [];
|
|
1625
|
+
fr = y === "memory" ? e.layerMemory : await (async () => {
|
|
1626
|
+
let e = await I(y), t = r({ sqliteFamily: e.id === "sqlite" || e.id === "turso" });
|
|
1627
|
+
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({
|
|
1628
|
+
sqlClientLayer: e.makeSqlLayer(k()),
|
|
1629
|
+
runnerStorage: t,
|
|
1630
|
+
dialectId: e.id,
|
|
1631
|
+
...process.env.VOLTRO_WORKFLOW_RUNNER_PORT ? { runnerListenPort: Number(process.env.VOLTRO_WORKFLOW_RUNNER_PORT) } : {},
|
|
1632
|
+
...i(),
|
|
1633
|
+
...a.length > 0 ? { extraShardingLayers: a } : {}
|
|
1634
|
+
});
|
|
1635
|
+
})();
|
|
1636
|
+
}
|
|
1637
|
+
let pr = yt(M, yn()), mr = b.filter((e) => /\.subscribe\.tsx?$/.test(e)), K = mr.length > 0 ? await c(mr, $) : [], hr = b.filter((e) => /\.reaction\.tsx?$/.test(e)), q = hr.length > 0 ? await he(hr, $) : [], gr = b.filter((e) => ln.test(e)), _r = gr.length > 0 ? await Me(gr, $) : [], wr = b.filter((e) => /\.aggregate\.tsx?$/.test(e)), Tr = wr.length > 0 ? await _e(wr, $) : [];
|
|
1638
|
+
{
|
|
1639
|
+
let e = xr(si(Be({ aggregates: Tr.map((e) => e.definition) }), It(T)));
|
|
1640
|
+
e !== void 0 && $.warn(e);
|
|
1641
|
+
}
|
|
1642
|
+
let Er = lt();
|
|
1643
|
+
if (Tr.length > 0 && y !== "memory") try {
|
|
1644
|
+
let e = (await I(y)).makeSqlLayer(k());
|
|
1645
|
+
Er = u(e);
|
|
1646
|
+
} catch (e) {
|
|
1647
|
+
$.warn("aggregate: SQL storage init failed — falling back to in-process", { err: String(e) });
|
|
1648
|
+
}
|
|
1649
|
+
let Mr = y === "memory" ? ni : Dr(E, `aggregate@${process.pid}`, $), Pr = b.filter((e) => un.test(e)), Fr = Pr.length > 0 ? await Pt(Pr, $) : [], Ir = b.filter((e) => cn.test(e)), Lr = Ir.length > 0 ? await m(Ir, $) : [], Rr = b.filter((e) => sn.test(e)), zr = Rr.length > 0 ? await w(Rr, $) : [], Br = [], Vr = [], Hr = b.filter((e) => tn.test(e));
|
|
1650
|
+
if (Hr.length > 0) {
|
|
1651
|
+
let e = $.child("agent"), t = b.filter((e) => $t.test(e));
|
|
1652
|
+
t.length > 0 && await an(t, e);
|
|
1653
|
+
let n = await Zt(Hr, e);
|
|
1654
|
+
for (let e of n.agents) for (let t of Dt(e)) (t.kind === "action" ? Br : Vr).push({
|
|
1655
|
+
file: t.file,
|
|
1656
|
+
descriptor: t.descriptor,
|
|
1657
|
+
executor: t.executor
|
|
1658
|
+
});
|
|
1659
|
+
n.agents.length > 0 && e.info("synthesized agent routes", { agents: n.agents.map((e) => e.descriptor.name) });
|
|
1660
|
+
}
|
|
1661
|
+
d.mark("workflow");
|
|
1662
|
+
let J = () => {
|
|
1663
|
+
let e = Y.workflowWriteActions();
|
|
1664
|
+
if (e === void 0) throw Error("workflow actions: this app registers no workflows");
|
|
1665
|
+
return e;
|
|
1666
|
+
}, Wr = qn({
|
|
1667
|
+
dialect: y,
|
|
1668
|
+
...k()
|
|
1669
|
+
}), Gr = y === "memory" ? void 0 : (await I(y)).makeSqlLayer(k()), Kr = async () => O({
|
|
1670
|
+
sqlLayer: Gr,
|
|
1671
|
+
declared: T,
|
|
1672
|
+
log: $
|
|
1673
|
+
}), Jr = {
|
|
1674
|
+
kind: "api",
|
|
1675
|
+
meta: {
|
|
1676
|
+
name: v?.name ?? "voltro-api",
|
|
1677
|
+
voltroVersion: Tt,
|
|
1678
|
+
port: ie,
|
|
1679
|
+
mode: "start",
|
|
1680
|
+
store: y,
|
|
1681
|
+
cdc: se ? "on" : "off",
|
|
1682
|
+
...Wr === void 0 ? {} : { databaseId: Wr }
|
|
1683
|
+
},
|
|
1684
|
+
rpc: Ie(x, g),
|
|
1685
|
+
workflows: Mt(x, g),
|
|
1686
|
+
migrations: Kr,
|
|
1687
|
+
events: () => Y.eventsSnapshot(),
|
|
1688
|
+
agentTools: () => Y.agentTools(),
|
|
1689
|
+
invariantChecks: () => ({
|
|
1690
|
+
mode: "serve",
|
|
1691
|
+
accessGate: ue,
|
|
1692
|
+
config: v,
|
|
1693
|
+
serverOnlyLeaks: x.serverOnlyLeaks,
|
|
1694
|
+
migrations: Kr
|
|
1695
|
+
}),
|
|
1696
|
+
members: () => Y.membersSnapshot(),
|
|
1697
|
+
inspectFireSchedule: async ({ name: e, trigger: t }) => {
|
|
1698
|
+
if (!cr) throw Error("scheduler not started — this app registers no self-triggered schedules (all schedules are trigger:'external', or there are none).");
|
|
1699
|
+
return { runId: await cr.fireNow(e, t) ?? null };
|
|
1700
|
+
},
|
|
1701
|
+
inspectBackfillSchedule: _({
|
|
1702
|
+
getHandle: () => cr,
|
|
1703
|
+
getSchedules: () => U
|
|
1704
|
+
}),
|
|
1705
|
+
...be === void 0 ? {} : { webhooks: () => ge({
|
|
1706
|
+
store: E,
|
|
1707
|
+
discoveredWebhooks: be
|
|
1708
|
+
}) },
|
|
1709
|
+
plugins: () => ({
|
|
1710
|
+
plugins: Mn.snapshot(),
|
|
1711
|
+
capturedAt: Date.now()
|
|
1712
|
+
}),
|
|
1713
|
+
env: () => Wt(v?.name ?? Tn(g), {
|
|
1714
|
+
...v?.env !== void 0 && yi(v.env) ? { contract: v.env } : {},
|
|
1715
|
+
plugins: v?.plugins ?? []
|
|
1716
|
+
}),
|
|
1717
|
+
dataCache: () => ze({
|
|
1718
|
+
stats: ot,
|
|
1719
|
+
backendKind: it
|
|
1720
|
+
}),
|
|
1721
|
+
subscriptions: () => Ft(() => B),
|
|
1722
|
+
inspectTables: () => S(x.tables),
|
|
1723
|
+
inspectRows: C({
|
|
1724
|
+
store: E,
|
|
1725
|
+
tables: x.tables,
|
|
1726
|
+
mask: !0
|
|
1727
|
+
}),
|
|
1728
|
+
metrics: (e) => Y.rpcMetrics().snapshot(e),
|
|
1729
|
+
cluster: () => Rt({
|
|
1730
|
+
store: E,
|
|
1731
|
+
dialect: y,
|
|
1732
|
+
useClusterCron: or,
|
|
1733
|
+
scheduleCoordChoice: ar
|
|
1734
|
+
}),
|
|
1735
|
+
inspectSchedules: () => Te({
|
|
1736
|
+
schedules: U,
|
|
1737
|
+
defaultTrigger: rr,
|
|
1738
|
+
coordination: sr
|
|
1739
|
+
}),
|
|
1740
|
+
inspectScheduleRuns: (e) => P(E, e),
|
|
1741
|
+
...f(E, {
|
|
1742
|
+
controls: nt(x.workflows ?? []),
|
|
1743
|
+
active: (x.workflows?.length ?? 0) > 0,
|
|
1744
|
+
cancellation: () => Y.flowControlHealth()
|
|
1745
|
+
}),
|
|
1746
|
+
webhookActions: Ce(() => Y.webhooksService()),
|
|
1747
|
+
inspectStartWorkflow: (e) => J().inspectStartWorkflow(e),
|
|
1748
|
+
inspectCancelWorkflowRun: (e) => J().inspectCancelWorkflowRun(e),
|
|
1749
|
+
inspectSuspendWorkflowRun: (e) => J().inspectSuspendWorkflowRun(e),
|
|
1750
|
+
inspectResumeWorkflowRun: (e) => J().inspectResumeWorkflowRun(e),
|
|
1751
|
+
inspectDiscardWorkflowRun: (e) => J().inspectDiscardWorkflowRun(e),
|
|
1752
|
+
inspectRetryWorkflowRun: (e) => J().inspectRetryWorkflowRun(e),
|
|
1753
|
+
inspectSignalWorkflowRun: (e) => J().inspectSignalWorkflowRun(e),
|
|
1754
|
+
inspectUpdateWorkflowRun: (e) => J().inspectUpdateWorkflowRun(e),
|
|
1755
|
+
inspectInferences: (e) => vt({
|
|
1756
|
+
store: E,
|
|
1757
|
+
active: (x.workflows?.length ?? 0) > 0,
|
|
1758
|
+
dispatcher: () => Y.inferenceHealth()
|
|
1759
|
+
}, e.limit === void 0 ? {} : { limit: e.limit }),
|
|
1760
|
+
...mt({
|
|
1761
|
+
store: E,
|
|
1762
|
+
cancelRun: async (e) => await Y.runCanceller()?.(e) ?? !1,
|
|
1763
|
+
retryRun: async (e) => J().inspectRetryWorkflowRun({ runId: e }),
|
|
1764
|
+
redriveRun: async (e) => Y.redriveWorkflowRun({ runId: e }),
|
|
1765
|
+
log: $
|
|
1766
|
+
}),
|
|
1767
|
+
inspectRedriveWorkflowRun: (e) => Y.redriveWorkflowRun(e),
|
|
1768
|
+
inspectResumeWorkflowRunFromStep: (e) => Y.resumeWorkflowRunFromStep(e)
|
|
1769
|
+
}, Yr = (process.env.VOLTRO_TENANT_ISOLATION ?? v?.tenancy?.isolation) === "namespace", Xr = Yr && y !== "memory" ? await (async () => {
|
|
1770
|
+
let e = await I(y);
|
|
1771
|
+
return kt({
|
|
1772
|
+
tables: T,
|
|
1773
|
+
sqlLayer: e.makeSqlLayer(k()),
|
|
1774
|
+
dialect: y,
|
|
1775
|
+
options: { retryFilter: e.retryFilter },
|
|
1776
|
+
log: {
|
|
1777
|
+
info: (e, t) => $.info(e, t),
|
|
1778
|
+
error: (e, t, n) => $.error(e, t ?? {}, n)
|
|
1779
|
+
}
|
|
1780
|
+
});
|
|
1781
|
+
})() : void 0, Zr = await ft({
|
|
1782
|
+
input: v?.tenancy?.residency,
|
|
1783
|
+
namespaceIsolationOn: Yr,
|
|
1784
|
+
makeStoreForUrl: (e, t) => rt(v, void 0, Gt(k(), t)),
|
|
1785
|
+
log: {
|
|
1786
|
+
info: (e, t) => $.info(e, t),
|
|
1787
|
+
warn: (e, t) => $.warn(e, t)
|
|
1788
|
+
}
|
|
1789
|
+
});
|
|
1790
|
+
Zr !== void 0 && qr(async () => {
|
|
1791
|
+
await Zr.close();
|
|
1792
|
+
});
|
|
1793
|
+
let Y = await ha({
|
|
1794
|
+
bootTiming: d,
|
|
1795
|
+
broadcastNamespace: R,
|
|
1796
|
+
scheduling: (() => {
|
|
1797
|
+
let e = gn;
|
|
1798
|
+
return {
|
|
1799
|
+
admissionDrainMs: e.admissionDrainMs,
|
|
1800
|
+
inferenceTickMs: e.inferenceTickMs,
|
|
1801
|
+
cancelSweepMs: e.cancelSweepMs,
|
|
1802
|
+
stalenessSweepMs: e.stalenessSweepMs,
|
|
1803
|
+
disarmWhenIdle: D({
|
|
1804
|
+
changeScope: E.changeScope,
|
|
1805
|
+
broadcastAttached: Fn !== void 0
|
|
1806
|
+
})
|
|
1807
|
+
};
|
|
1808
|
+
})(),
|
|
1809
|
+
...v?.workflows?.staleness === void 0 ? {} : { workflowStaleness: v.workflows.staleness },
|
|
1810
|
+
...v?.workflows?.suspendSignalHintMs === void 0 ? {} : { workflowSuspendSignalHintMs: v.workflows.suspendSignalHintMs },
|
|
1811
|
+
workflowRecording: Bt(v?.workflows?.recording),
|
|
1812
|
+
membership: {
|
|
1813
|
+
...An,
|
|
1814
|
+
instanceId: wn
|
|
1815
|
+
},
|
|
1816
|
+
security: {
|
|
1817
|
+
defaultDeny: oe(v),
|
|
1818
|
+
...re(v)
|
|
1819
|
+
},
|
|
1820
|
+
approvals: { defaultExpiryMs: je(v) },
|
|
1821
|
+
...v?.plugins === void 0 ? {} : { plugins: v.plugins },
|
|
1822
|
+
...Un ? { idempotency: Un } : {},
|
|
1823
|
+
restRoutes: Hn,
|
|
1824
|
+
appProcedures: ue,
|
|
1825
|
+
discovered: {
|
|
1826
|
+
queries: [...x.queries, ...Vr],
|
|
1827
|
+
mutations: x.mutations,
|
|
1828
|
+
actions: [...x.actions, ...Br],
|
|
1829
|
+
streams: x.streams,
|
|
1830
|
+
events: x.events,
|
|
1831
|
+
workflows: x.workflows,
|
|
1832
|
+
workflowWorkers: x.workflowWorkers,
|
|
1833
|
+
eventTriggers: x.eventTriggers,
|
|
1834
|
+
schedules: U,
|
|
1835
|
+
subscribers: K,
|
|
1836
|
+
outboxHandlers: _r,
|
|
1837
|
+
connections: x.connections,
|
|
1838
|
+
reactions: q,
|
|
1839
|
+
aggregates: Tr,
|
|
1840
|
+
expectations: Fr,
|
|
1841
|
+
budgets: Lr,
|
|
1842
|
+
experiments: zr,
|
|
1843
|
+
...be === void 0 ? {} : { webhooks: be }
|
|
1844
|
+
},
|
|
1845
|
+
log: $,
|
|
1846
|
+
analytics: ke.sink,
|
|
1847
|
+
aggregateStorage: Er,
|
|
1848
|
+
aggregateCoordinator: Mr,
|
|
1849
|
+
store: E,
|
|
1850
|
+
kv: ut,
|
|
1851
|
+
cache: Je,
|
|
1852
|
+
snapshotCache: Ke,
|
|
1853
|
+
...v?.reactive === void 0 ? {} : { reactive: v.reactive },
|
|
1854
|
+
schemaRegistry: Fe,
|
|
1855
|
+
tenantScopedTables: x.tenantScopedTables,
|
|
1856
|
+
softDeleteScopedTables: x.softDeleteScopedTables,
|
|
1857
|
+
dataTransferSnapshot: $n(T, y),
|
|
1858
|
+
dataTransferDialect: y,
|
|
1859
|
+
...Xr === void 0 ? {} : { ensureTenantProvisioned: Xr.ensure },
|
|
1860
|
+
...Zr === void 0 ? {} : { resolveResidentStore: Zr.resolveStore },
|
|
1861
|
+
tenantIsolation: (process.env.VOLTRO_TENANT_ISOLATION ?? v?.tenancy?.isolation) === "namespace" ? "namespace" : "shared-schema",
|
|
1862
|
+
resolveSubject: (e, t) => Vn({
|
|
1863
|
+
headers: e,
|
|
1864
|
+
clientId: t
|
|
1865
|
+
}),
|
|
1866
|
+
...v?.auth === void 0 ? {} : { authority: v.auth },
|
|
1867
|
+
...v?.agents === void 0 ? {} : { agents: v.agents },
|
|
1868
|
+
httpRoutes: M.flatMap((e) => e.httpRoutes ?? []),
|
|
1869
|
+
getStore: () => Ve,
|
|
1870
|
+
...Gn ? { baseLayer: Gn } : {},
|
|
1871
|
+
...fr === void 0 ? {} : { workflowEngineLayer: fr },
|
|
1872
|
+
scheduleDefaultTrigger: rr,
|
|
1873
|
+
scheduleCoordination: sr,
|
|
1874
|
+
scheduleArmSelf: !or,
|
|
1875
|
+
dormancy: process.env.VOLTRO_DORMANCY === "sleep" || process.env.VOLTRO_DORMANCY === "always-on" ? process.env.VOLTRO_DORMANCY : v?.dormancy ?? "always-on",
|
|
1876
|
+
scheduleReplicaId: process.env.HOSTNAME ?? `pid-${process.pid}`,
|
|
1877
|
+
...pr === void 0 ? {} : { scheduleFireInterceptor: pr },
|
|
1878
|
+
onSchedulerReady: (e) => {
|
|
1879
|
+
cr = e;
|
|
1880
|
+
},
|
|
1881
|
+
inspectRoute: { handle: async (e, t, n, r) => await h(e, Jr, t, {
|
|
1882
|
+
method: n,
|
|
1883
|
+
...r === void 0 ? {} : { body: r }
|
|
1884
|
+
}) || ((n === "GET" ? await pn(e, Jr, t, { method: n }) : null) ?? fn(e, Jr, t, {
|
|
1885
|
+
method: n,
|
|
1886
|
+
...r === void 0 ? {} : { body: r }
|
|
1887
|
+
}) ?? {
|
|
1888
|
+
status: 404,
|
|
1889
|
+
contentType: "application/json",
|
|
1890
|
+
body: JSON.stringify({ error: "not an inspect route" })
|
|
1891
|
+
}) },
|
|
1892
|
+
...v?.name === void 0 ? {} : { appName: v.name },
|
|
1893
|
+
observability: Nn,
|
|
1894
|
+
port: ie,
|
|
1895
|
+
...v?.transport?.wsPath ? { path: v.transport.wsPath } : {}
|
|
1896
|
+
});
|
|
1897
|
+
return B = Y.dispatcher, te(Ee([
|
|
1898
|
+
x.queries,
|
|
1899
|
+
x.mutations,
|
|
1900
|
+
x.actions,
|
|
1901
|
+
x.streams
|
|
1902
|
+
]), (e) => {
|
|
1903
|
+
$.warn(e);
|
|
1904
|
+
}), $.info(`API listening on :${ie}`, {
|
|
1905
|
+
dialect: y,
|
|
1906
|
+
queries: x.queries.length,
|
|
1907
|
+
mutations: x.mutations.length,
|
|
1908
|
+
actions: x.actions.length,
|
|
1909
|
+
streams: x.streams.length,
|
|
1910
|
+
workflows: x.workflows.length,
|
|
1911
|
+
workflowWorkers: x.workflowWorkers.length,
|
|
1912
|
+
schedules: U.length,
|
|
1913
|
+
scheduleCoordination: sr
|
|
1914
|
+
}), d.finish($), qr(async () => {
|
|
1915
|
+
for (let e of Cn) e.stop();
|
|
1916
|
+
bt.stop();
|
|
1917
|
+
try {
|
|
1918
|
+
await Y.close(), st(), Lt?.dispose(), await Mn.deactivate(), await Fn?.close(), await Et({
|
|
1919
|
+
mirror: ht,
|
|
1920
|
+
log: $
|
|
1921
|
+
}), await ke.dispose(), await E.close?.();
|
|
1922
|
+
} catch (e) {
|
|
1923
|
+
console.error("serve: shutdown step failed, exiting anyway:", e);
|
|
1924
|
+
}
|
|
1925
|
+
}), await new Promise(() => {}), 0;
|
|
1926
|
+
};
|
|
1927
|
+
//#endregion
|
|
1928
|
+
export { va as n, ga as r, ya as t };
|