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