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