@voltro/cli 0.51.0 → 0.53.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 +356 -0
- package/THIRD-PARTY-NOTICES.md +8311 -3318
- package/dist/{agentsMd-D6yD7IQv.js → agentsMd-0l980yhL.js} +4 -1
- package/dist/agentsMd-SDDSkyl4.js +2 -0
- package/dist/{apiBuild-CPDHXF72.js → apiBuild-CaPfoWku.js} +11 -5
- package/dist/apiBuild-DHtLXYx9.js +2 -0
- package/dist/bin.js +1 -1
- package/dist/build-D-OnvNMf.js +843 -0
- package/dist/{checkCommand-DNuPiWMc.js → checkCommand-C5elt0tW.js} +92 -46
- package/dist/checkCommand-D2ZduVlh.js +2 -0
- package/dist/{cloudCmd-F4YJeqM3.js → cloudCmd-QUXh-b5w.js} +1 -1
- package/dist/codegen-BWpt3VgF.js +2 -0
- package/dist/{codegen-CrMXs4hb.js → codegen-FEk8AZHb.js} +2 -2
- package/dist/{codegenCommand-BNBHcNNj.js → codegenCommand-BOiWQ5hz.js} +12 -12
- package/dist/{codemodRunner-BDVixlSw.js → codemodRunner-BjtB2lq6.js} +691 -545
- package/dist/{commands-B1OiS9bX.js → commands-DyxAmhP0.js} +36 -36
- package/dist/{dashboardCommand-C-vvPY1B.js → dashboardCommand-BdKTyT13.js} +3 -3
- package/dist/{dataCommand-C1GxXW5q.js → dataCommand-Bab9X7s8.js} +27 -27
- package/dist/{dbCommand-If4Y1xQ-.js → dbCommand-06O2finM.js} +277 -236
- package/dist/dbCommand-B1EXBC6f.js +2 -0
- package/dist/{dev-kdAg9Q7l.js → dev-C6LGF4iY.js} +2998 -2379
- package/dist/dev-GjJWAYo2.js +3 -0
- package/dist/doctorCommand-B0hX0tdz.js +2 -0
- package/dist/{doctorCommand-nKmeW78u.js → doctorCommand-etMkflRc.js} +332 -220
- package/dist/{dormancyCommand-CY3wa_SW.js → dormancyCommand-UwZ1AZzB.js} +1 -1
- package/dist/{embeddingsCommand-BDLIgje_.js → embeddingsCommand-C70zWHwo.js} +1 -1
- package/dist/{envCommand-C6V_xVlT.js → envCommand-dSyKvRkM.js} +15 -15
- package/dist/{evolveCommand-D3c4DSfN.js → evolveCommand-CG0_ebO5.js} +2 -2
- package/dist/fileConventions-DASGEmj-.js +35 -0
- package/dist/{fileTaxonomy-CJfgOllU.js → fileTaxonomy-B7uxipWS.js} +55 -55
- package/dist/fontPipeline-LxIHa1vo.js +2 -0
- package/dist/fontPipeline-Tsh8kZfA.js +152 -0
- package/dist/frameworkTableAssembly-C_7Z-rMs.js +2 -0
- package/dist/{frameworkTableAssembly-BwJVEKLr.js → frameworkTableAssembly-DKx3ba3S.js} +5 -5
- package/dist/imagePipeline-B_GVJgm6.js +2 -0
- package/dist/imagePipeline-CBZmjT4i.js +127 -0
- package/dist/index.js +1 -1
- package/dist/{infoCommand-BnRFEF1o.js → infoCommand-_53iOc_j.js} +1 -1
- package/dist/{inspect-CtL_xTbu.js → inspect-Bd8-9wsi.js} +1 -1
- package/dist/inspect-CuoDInfZ.js +2 -0
- package/dist/{inspectGateHint-BjnFubmH.js → inspectGateHint-4LxkNtrz.js} +1 -1
- package/dist/inspectMetrics-CGF94puw.js +143 -0
- package/dist/manifestBuild-C4-J1-m_.js +2 -0
- package/dist/{manifestBuild-CuU1VrSm.js → manifestBuild-Cqgsx2bM.js} +1 -1
- package/dist/{metaCommands-CfRLra0s.js → metaCommands-Cn2oboG4.js} +9 -3
- package/dist/{migrate-DehuBakM.js → migrate-Cko9rswM.js} +2 -2
- package/dist/{pageConvention-cEiRxdab.js → pageConvention-C938S8oC.js} +1 -1
- package/dist/{privacyCommand-XejDMvmu.js → privacyCommand-DWTQMC6R.js} +2 -2
- package/dist/{probeCommand-C9gazU0H.js → probeCommand-DkGGLknv.js} +83 -24
- package/dist/{projectScaffold-mIX_DpSe.js → projectScaffold-B4dmTlwT.js} +1 -1
- package/dist/{projectScaffold-BIl97_E6.js → projectScaffold-EzlErR4E.js} +1 -1
- package/dist/{renderModeScan-D7J1B7Kw.js → renderModeScan-CUbOeOAg.js} +28 -11
- package/dist/{renderProfile-1OWWAAtx.js → renderProfile-CskIgAfn.js} +2 -2
- package/dist/{runtimeTrace-ZsBU7Tkx.js → runtimeTrace-c0APJz7E.js} +1 -1
- package/dist/{sdkgen-O4XqWOjM.js → sdkgen-BiQCgIEr.js} +1 -1
- package/dist/serveCommand-CueKQgzl.js +2443 -0
- package/dist/serveCommand-DsnrVN3U.js +2 -0
- package/dist/serveEntry.js +1 -1
- package/dist/start-BJzZLbt8.js +3 -0
- package/dist/start-ekPan8BT.js +1510 -0
- package/dist/startEntry.js +1 -1
- package/dist/{staticCommand-Dr2M6tpU.js → staticCommand-xlSL-IWk.js} +1 -1
- package/dist/{test-rXFq4S76.js → test-BWPQcRoB.js} +1 -1
- package/dist/updateCommand-Bqql_rsQ.js +2 -0
- package/dist/{updateCommand-Bs322Q78.js → updateCommand-C_8I8Rzo.js} +139 -115
- package/dist/webDev-C7jWJ5dX.js +2 -0
- package/dist/{webDev-B-ubQEMX.js → webDev-oczpugbx.js} +1767 -913
- package/dist/{webhooksCommand-FLYY9IXh.js → webhooksCommand-4SVPDjKg.js} +1 -1
- package/package.json +72 -18
- package/templates/AGENTS.core.md +11 -0
- package/templates/AGENTS.md +19 -6
- package/templates/agent-docs/_index.md +8 -6
- package/templates/agent-docs/_manifest.json +31 -15
- package/templates/agent-docs/ai.md +2 -2
- package/templates/agent-docs/authentication.md +1 -1
- package/templates/agent-docs/cli.md +97 -15
- package/templates/agent-docs/configuration.md +17 -0
- package/templates/agent-docs/data.md +680 -33
- package/templates/agent-docs/database/advancedqueries.md +7 -7
- package/templates/agent-docs/database/columntypes.md +2 -2
- package/templates/agent-docs/database/querying.md +1 -1
- package/templates/agent-docs/database/schema.md +2 -2
- package/templates/agent-docs/database/seedsdialects.md +2 -2
- package/templates/agent-docs/database/transactions.md +3 -3
- package/templates/agent-docs/deployment.md +30 -3
- package/templates/agent-docs/internationalization.md +2 -2
- package/templates/agent-docs/introduction.md +52 -0
- package/templates/agent-docs/local-first-mobile.md +132 -7
- package/templates/agent-docs/observability.md +2 -0
- package/templates/agent-docs/plugins/ai-flows.md +1 -1
- package/templates/agent-docs/plugins/audit.md +5 -5
- package/templates/agent-docs/plugins/auth.md +1 -1
- package/templates/agent-docs/plugins/cdc-out.md +2 -2
- package/templates/agent-docs/plugins/comments.md +142 -0
- package/templates/agent-docs/plugins/notifications.md +47 -4
- package/templates/agent-docs/plugins/presence.md +16 -3
- package/templates/agent-docs/plugins/prometheus.md +1 -1
- package/templates/agent-docs/plugins/queue.md +129 -0
- package/templates/agent-docs/plugins/{versioning.md → row-history.md} +22 -22
- package/templates/agent-docs/plugins/storage.md +2 -2
- package/templates/agent-docs/plugins.md +38 -12
- package/templates/agent-docs/reference.md +54 -5
- package/templates/agent-docs/routing.md +868 -50
- package/templates/agent-docs/schema-driven-ui.md +292 -5
- package/templates/agent-docs/security.md +125 -8
- package/templates/agent-docs/templates/apibackends.md +14 -14
- package/templates/agent-docs/templates/overview.md +1 -1
- package/templates/agent-docs/whats-new.md +171 -54
- package/templates/apps/api-ai/package.json +6 -7
- package/templates/apps/api-ai/tests/summarize.test.ts +1 -1
- 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 +9 -10
- package/templates/apps/api-collab/package.json +8 -8
- package/templates/apps/api-data-advanced/package.json +8 -8
- package/templates/apps/api-durable/package.json +8 -8
- package/templates/apps/api-feature-flags/package.json +9 -9
- package/templates/apps/api-governance/package.json +8 -8
- package/templates/apps/api-kv/package.json +8 -8
- package/templates/apps/api-moderation/package.json +8 -8
- package/templates/apps/api-observability/package.json +8 -8
- package/templates/apps/api-ratelimit/package.json +8 -8
- package/templates/apps/api-rbac/package.json +8 -8
- package/templates/apps/api-rest/package.json +7 -7
- package/templates/apps/{api-versioning → api-row-history}/README.md +3 -3
- package/templates/apps/{api-versioning → api-row-history}/actions/documents.asOf.action.server.ts +1 -1
- package/templates/apps/{api-versioning → api-row-history}/actions/documents.history.action.server.ts +1 -1
- package/templates/apps/{api-versioning → api-row-history}/app.config.ts +3 -3
- package/templates/apps/{api-versioning → api-row-history}/database/schema.ts +1 -1
- package/templates/apps/{api-versioning → api-row-history}/mutations/documents.create.mutation.server.ts +1 -1
- package/templates/apps/{api-versioning → api-row-history}/mutations/documents.create.mutation.ts +1 -1
- package/templates/apps/{api-versioning → api-row-history}/mutations/documents.update.mutation.ts +1 -1
- package/templates/apps/{api-versioning → api-row-history}/package.json +8 -8
- package/templates/apps/api-row-history/template.json +6 -0
- package/templates/apps/{api-versioning → api-row-history}/tests/documents.create.test.ts +1 -1
- package/templates/apps/api-saas/app.config.ts +1 -0
- package/templates/apps/api-saas/package.json +10 -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-webhooks/package.json +9 -9
- package/templates/apps/changelog/app.config.ts +26 -2
- package/templates/apps/changelog/content/releases/{0.1.0.mdx → v0-1-0.mdx} +0 -1
- package/templates/apps/changelog/content/releases/{0.2.0.mdx → v0-2-0.mdx} +0 -1
- package/templates/apps/changelog/package.json +8 -8
- package/templates/apps/changelog/src/collections/releases.collection.ts +48 -0
- package/templates/apps/changelog/src/globals.d.ts +1 -1
- package/templates/apps/changelog/src/locales/de.ts +1 -1
- package/templates/apps/changelog/src/locales/en.ts +1 -1
- package/templates/apps/changelog/src/pages/[locale]/[slug]/page.tsx +7 -4
- package/templates/apps/changelog/src/pages/[locale]/mirrors.test.tsx +13 -41
- package/templates/apps/changelog/src/pages/[slug]/page.test.tsx +26 -51
- package/templates/apps/changelog/src/pages/[slug]/page.tsx +21 -19
- package/templates/apps/changelog/src/pages/page.test.tsx +14 -37
- package/templates/apps/changelog/src/pages/page.tsx +18 -12
- 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-collab/src/pages/page.test.tsx +10 -9
- package/templates/apps/frontend-collab/src/pages/page.tsx +42 -65
- package/templates/apps/frontend-contact/package.json +7 -7
- package/templates/apps/frontend-dashboard/package.json +7 -7
- package/templates/apps/frontend-docs/content/docs/de/guides/first-page.md +4 -0
- package/templates/apps/frontend-docs/content/docs/de/intro/getting-started.md +4 -0
- package/templates/apps/frontend-docs/content/docs/en/guides/first-page.md +4 -0
- package/templates/apps/frontend-docs/content/docs/en/intro/getting-started.md +4 -0
- package/templates/apps/frontend-docs/package.json +8 -7
- package/templates/apps/frontend-docs/src/collections/docs.collection.ts +21 -0
- package/templates/apps/frontend-docs/src/locales/de.ts +0 -5
- package/templates/apps/frontend-docs/src/locales/en.ts +0 -5
- package/templates/apps/frontend-docs/src/pages/[locale]/docs/[...slug]/page.tsx +17 -9
- package/templates/apps/frontend-docs/src/pages/[locale]/mirrors.test.tsx +10 -5
- package/templates/apps/frontend-docs/src/pages/[locale]/page.tsx +8 -0
- package/templates/apps/frontend-docs/src/pages/docs/[...slug]/page.test.tsx +53 -15
- package/templates/apps/frontend-docs/src/pages/docs/[...slug]/page.tsx +27 -33
- package/templates/apps/frontend-docs/src/pages/page.test.tsx +17 -3
- package/templates/apps/frontend-docs/src/pages/page.tsx +16 -12
- package/templates/apps/frontend-i18n/package.json +6 -6
- package/templates/apps/frontend-landing/package.json +6 -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/content/posts/cms-to-ssg.md +12 -0
- package/templates/apps/frontend-static-blog/content/posts/hello-static.md +12 -0
- package/templates/apps/frontend-static-blog/content/posts/islands-not-hydration.md +14 -0
- package/templates/apps/frontend-static-blog/package.json +8 -6
- package/templates/apps/frontend-static-blog/src/collections/posts.collection.ts +27 -0
- package/templates/apps/frontend-static-blog/src/pages/[locale]/blog/[slug]/page.tsx +7 -4
- package/templates/apps/frontend-static-blog/src/pages/[locale]/mirrors.test.tsx +7 -1
- package/templates/apps/frontend-static-blog/src/pages/blog/[slug]/page.test.tsx +19 -9
- package/templates/apps/frontend-static-blog/src/pages/blog/[slug]/page.tsx +19 -21
- package/templates/apps/frontend-static-blog/src/pages/page.test.tsx +18 -5
- package/templates/apps/frontend-static-blog/src/pages/page.tsx +21 -14
- package/templates/apps/frontend-status/package.json +8 -8
- package/templates/apps/mobile-app/package.json +4 -4
- package/dist/agentsMd-Bu_XQgVf.js +0 -2
- package/dist/apiBuild-GDKuGOMV.js +0 -2
- package/dist/build-DETLZAFt.js +0 -752
- package/dist/checkCommand-CWcnDArJ.js +0 -2
- package/dist/codegen-DiMn2KkZ.js +0 -2
- package/dist/dbCommand-C27HIsGE.js +0 -2
- package/dist/dev-CK522MV5.js +0 -3
- package/dist/doctorCommand-BK4l18eG.js +0 -2
- package/dist/fileConventions-Cof68_BL.js +0 -33
- package/dist/frameworkTableAssembly-CVDB2hCq.js +0 -2
- package/dist/inspect-CuGDYES0.js +0 -2
- package/dist/inspectMetrics-CfdKLh6t.js +0 -72
- package/dist/manifestBuild-CPjhvM62.js +0 -2
- package/dist/serveCommand-BRnPCxVd.js +0 -2
- package/dist/serveCommand-DdiYNBBu.js +0 -2362
- package/dist/start-BLNmWkLa.js +0 -1154
- package/dist/start-Dzicuyw8.js +0 -3
- package/dist/updateCommand-eXB35SEv.js +0 -2
- package/dist/webDev-DposiF3j.js +0 -2
- package/templates/apps/api-versioning/template.json +0 -6
- package/templates/apps/changelog/scripts/generate-rss.mjs +0 -38
- package/templates/apps/changelog/src/lib/releases.ts +0 -21
- package/templates/apps/frontend-static-blog/src/content/posts.ts +0 -64
- /package/templates/apps/{api-versioning → api-row-history}/actions/documents.asOf.action.ts +0 -0
- /package/templates/apps/{api-versioning → api-row-history}/actions/documents.history.action.ts +0 -0
- /package/templates/apps/{api-versioning → api-row-history}/mutations/documents.update.mutation.server.ts +0 -0
- /package/templates/apps/{api-versioning → api-row-history}/tsconfig.json +0 -0
|
@@ -0,0 +1,2443 @@
|
|
|
1
|
+
import { t as e } from "./nodeEnvironment-cGFAj1J8.js";
|
|
2
|
+
import { t } from "./frameworkInspectState-CX2250XB.js";
|
|
3
|
+
import { r as n, t as r } from "./appModuleLoader-C9r9mxZt.js";
|
|
4
|
+
import { t as i } from "./bootRefusal-pgvDxlrU.js";
|
|
5
|
+
import { n as a, r as o } from "./startupRunner-CEqQq7ax.js";
|
|
6
|
+
import { t as s } from "./interruptedReplace-C3O3M1MM.js";
|
|
7
|
+
import { $ as c, $t as l, A as u, An as d, At as f, Bt as ee, C as te, Cn as p, Ct as m, D as ne, Dn as h, Dt as re, E as g, Et as ie, F as ae, Ft as oe, G as se, Gt as ce, H as _, I as le, It as ue, J as de, Jt as fe, K as pe, Kt as v, L as y, Lt as b, M as me, Mt as he, N as ge, Nt as _e, O as ve, On as ye, Ot as be, P as xe, Pt as Se, Q as Ce, Qt as we, R as Te, Rt as Ee, S as x, Sn as De, St as Oe, T as ke, Tn as Ae, Tt as je, U as Me, Ut as S, Vt as Ne, W as C, X as Pe, Xt as Fe, Y as Ie, Yt as w, Z as Le, Zt as Re, _ as ze, _n as Be, _t as Ve, an as He, at as T, b as Ue, bn as We, bt as Ge, c as Ke, cn as qe, ct as Je, d as Ye, dn as Xe, dt as Ze, en as Qe, et as $e, fn as et, ft as tt, g as nt, gn as rt, gt as it, h as at, hn as ot, ht as st, i as ct, in as lt, it as ut, j as dt, jt as ft, k as pt, kn as mt, kt as ht, ln as gt, lt as _t, m as vt, mn as yt, mt as E, nn as D, nt as bt, o as O, on as xt, ot as St, p as Ct, pn as k, pt as wt, q as Tt, qt as Et, r as Dt, rn as Ot, rt as kt, sn as At, st as jt, t as Mt, tn as Nt, tt as A, u as Pt, un as Ft, ut as It, v as Lt, vn as j, vt as M, w as Rt, wn as zt, wt as Bt, x as Vt, xn as Ht, xt as Ut, y as Wt, yt as Gt, z as Kt, zt as qt } from "./dev-C6LGF4iY.js";
|
|
8
|
+
import { n as N } from "./cliArgs-D4p8n7EE.js";
|
|
9
|
+
import { r as Jt } from "./appPort-B_HpJ_ck.js";
|
|
10
|
+
import { Ht as Yt, Wt as Xt } from "./webDev-oczpugbx.js";
|
|
11
|
+
import { r as P } from "./dialectDriver-czCHYpeH.js";
|
|
12
|
+
import { i as Zt, n as Qt } from "./connectionConfig-Bk9IC7D0.js";
|
|
13
|
+
import { c as F, n as $t, o as en } from "./seedRunner-Dgsiwk_e.js";
|
|
14
|
+
import { d as tn, h as nn, m as rn, p as an, r as on } from "./frameworkTableAssembly-DKx3ba3S.js";
|
|
15
|
+
import { n as sn, r as cn, t as ln } from "./declaredSchemaGates-BlcwObhb.js";
|
|
16
|
+
import { C as un, S as dn, a as fn, c as pn, l as mn, m as hn, n as gn } from "./fileConventions-DASGEmj-.js";
|
|
17
|
+
import { h as _n, o as vn } from "./inspect-Bd8-9wsi.js";
|
|
18
|
+
import { i as yn, n as bn, t as xn } from "./inspectMetrics-CGF94puw.js";
|
|
19
|
+
import { n as Sn } from "./mssqlClusterPatch-_4cE_nun.js";
|
|
20
|
+
import { i as Cn, n as wn, r as Tn, t as En } from "./webhookDiscovery-CphsQe59.js";
|
|
21
|
+
import { r as Dn, u as On } from "./apiBuild-CaPfoWku.js";
|
|
22
|
+
import { t as kn } from "./bootTiming-BdyP9nYw.js";
|
|
23
|
+
import { a as An, o as jn, t as Mn } from "./dataProfile-Du3ztYxv.js";
|
|
24
|
+
import I, { basename as Nn, join as Pn } from "node:path";
|
|
25
|
+
import { createWriteStream as Fn, existsSync as In } from "node:fs";
|
|
26
|
+
import { pathToFileURL as Ln } from "node:url";
|
|
27
|
+
import { LoggerLayer as Rn, createLogger as L } from "@voltro/logger";
|
|
28
|
+
import { AuthMiddleware as zn, ConnectionInfoMiddleware as Bn, actionToRpc as R, anonymousSubject as Vn, isWireReachable as Hn, mutationToRpc as Un, queryToRpc as z, streamToRpc as Wn, wireErrorUnion as Gn, workflowCancelDescriptor as Kn, workflowDomainEventsQueryDescriptor as B, workflowEventDeliveriesQueryDescriptor as V, workflowResumeDescriptor as qn, workflowRunEventsQueryDescriptor as Jn, workflowRunQueryDescriptor as Yn, workflowRunStepsQueryDescriptor as Xn, workflowRunsQueryDescriptor as Zn, workflowSignalDescriptor as Qn, workflowUpdateDescriptor as $n } from "@voltro/protocol";
|
|
29
|
+
import { DATA_TRANSFERS_TABLE as H, _voltroDataTransfersTable as er, allRegisteredTables as tr, and as nr, connectionIdentity as rr, derivedRowId as ir, describeTransferRun as ar, ensureTableRegistered as or, eq as U, or as sr } from "@voltro/database";
|
|
30
|
+
import { Cause as cr, Effect as W, Layer as G, ManagedRuntime as lr } from "effect";
|
|
31
|
+
import { SqlClient as ur } from "@effect/sql";
|
|
32
|
+
import { declaredSnapshot as dr, describeOutcome as fr, pendingFileMigrationIds as pr, runPlannedMigrations as mr } from "@voltro/database/sql";
|
|
33
|
+
import { AggregateRegistry as hr, CostRegistry as gr, DORMANCY_WAKEUP_TENANT as _r, Dispatcher as vr, ExpectationRegistry as yr, ExperimentRegistry as br, apiKeyManagementRoutes as xr, attachAnalyticsMirror as Sr, attachExpectations as Cr, attachExperiments as wr, attachFinops as Tr, awaitServerListening as Er, bindMutation as Dr, bindStream as Or, bindSubscription as K, buildTracingLayer as kr, cancelWakeup as Ar, compileCron as jr, dataStoreApiKeyStore as Mr, formatServerOnlyLeaks as Nr, formatUnresolvedSources as Pr, frameworkApiKeyStrategy as Fr, getResourcePolicy as Ir, installPolicyGuardResolver as Lr, loadResourceTuples as Rr, makeActionRunner as zr, makeAdvisoryLockCoordinator as Br, makeApiKeyService as Vr, makeApiKeyUsageBuffer as Hr, makeApiKeyUsageFlusher as Ur, makeAsyncKv as Wr, makeAuthMiddlewareLayers as Gr, makeCoordinatedScheduler as Kr, makeEffectStoreLayer as qr, makeLazyWorkflowFacade as Jr, makeMutationOutputCodec as Yr, makeMutationRunner as Xr, makeOneShotQueryRunner as Zr, makeQueryDescriptorProducer as q, makeQueryFinalizer as Qr, makeQueryReauthorizer as $r, makeQuerySubscriber as ei, makeSchemaRegistry as ti, makeWorkflowFacade as ni, makeWorkflowFacadeWithCallerContext as ri, makeWorkflowLayers as ii, noopKv as ai, onProcessShutdown as J, recordSubscriptionDelivery as Y, recordWorkflowRun as oi, registerDefaultTupleSource as si, registerWakeup as ci, resolveSecretsBackend as li, runProvidedEffect as ui, setSecretsBackend as di, setSystemStoreHandle as fi, shutdownGraceMsFromEnv as pi, singleCoordinator as mi, startRpcServer as hi, startScheduler as gi, stripForbiddenForWire as _i, undoCaptureEnabled as vi, unresolvedSources as yi, withScopedRequest as bi, workflowToRpc as xi, wrapStoreWithBootCodec as Si } from "@voltro/runtime";
|
|
34
|
+
import Ci, { tmpdir as wi } from "node:os";
|
|
35
|
+
import { RpcGroup as Ti } from "@effect/rpc";
|
|
36
|
+
import { appStorageProvider as Ei, durabilityNotice as Di, fromNodeReadable as Oi, getObjectStream as ki, putObjectStream as Ai, toNodeReadable as ji } from "@voltro/plugin-storage";
|
|
37
|
+
import { isEnvContract as Mi } from "@voltro/env";
|
|
38
|
+
import { assertProductionSessionSecret as Ni } from "@voltro/protocol/session";
|
|
39
|
+
import X from "node:fs/promises";
|
|
40
|
+
import { createHash as Pi, timingSafeEqual as Fi } from "node:crypto";
|
|
41
|
+
import { channelFor as Ii, getBroadcastPlugin as Li } from "@voltro/plugin-broadcast";
|
|
42
|
+
import { buildDeliverWebhookExecute as Ri, buildWebhooksService as zi, defaultIncomingPath as Bi, deliverWebhookWorkflow as Vi, makeDeferredEmitHandler as Hi, mountIncomingWebhook as Ui } from "@voltro/plugin-webhooks";
|
|
43
|
+
import { getAuthSessionStrategy as Wi } from "@voltro/plugin-auth";
|
|
44
|
+
import { registerEmailTemplates as Gi } from "@voltro/plugin-mail";
|
|
45
|
+
import { checkSchemaDrift as Ki, decideStaging as qi, isEnvironmentLocal as Ji, packBundle as Yi, peekBundle as Xi, runExport as Zi, runImport as Qi, storageBlobSink as $i, storageRefsBlobSource as ea, unpackBundle as ta, unpackBundleToDir as na } from "@voltro/data-transfer";
|
|
46
|
+
//#region \0rolldown/runtime.js
|
|
47
|
+
var ra = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
|
|
48
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
49
|
+
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
50
|
+
}), ia = () => Math.max(500, Math.floor(pi() * .6)), aa = (e) => new Promise((t) => setTimeout(t, e)), oa = (e) => {
|
|
51
|
+
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = 0;
|
|
52
|
+
e.on("connection", (e) => {
|
|
53
|
+
t.add(e), e.once("close", () => {
|
|
54
|
+
t.delete(e), n.delete(e);
|
|
55
|
+
});
|
|
56
|
+
}), e.on("upgrade", (e, t) => {
|
|
57
|
+
n.add(t);
|
|
58
|
+
}), e.on("request", (e, t) => {
|
|
59
|
+
r += 1, t.once("close", () => {
|
|
60
|
+
--r;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
let i, a = async (t = {}) => {
|
|
64
|
+
let n = t.budgetMs ?? ia();
|
|
65
|
+
i ??= new Promise((t) => {
|
|
66
|
+
e.close(() => {
|
|
67
|
+
t();
|
|
68
|
+
});
|
|
69
|
+
}), e.closeIdleConnections();
|
|
70
|
+
let a = Date.now() + n;
|
|
71
|
+
for (; r > 0 && Date.now() < a;) await aa(25), e.closeIdleConnections();
|
|
72
|
+
e.closeIdleConnections();
|
|
73
|
+
}, o = async () => {
|
|
74
|
+
i ??= new Promise((t) => {
|
|
75
|
+
e.close(() => {
|
|
76
|
+
t();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
for (let e of t) if (n.has(e)) try {
|
|
80
|
+
e.write(Buffer.from([
|
|
81
|
+
136,
|
|
82
|
+
2,
|
|
83
|
+
3,
|
|
84
|
+
233
|
|
85
|
+
]));
|
|
86
|
+
} catch {}
|
|
87
|
+
else e.destroy();
|
|
88
|
+
for (let e = 0; t.size > 0 && e < 250; e += 25) await aa(25);
|
|
89
|
+
for (let e of t) e.destroy();
|
|
90
|
+
await i;
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
activeRequests: () => r,
|
|
94
|
+
drainRequests: a,
|
|
95
|
+
finish: o,
|
|
96
|
+
drain: async (e = {}) => {
|
|
97
|
+
await a(e), await o();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}, sa = "/_voltro/admin/import", ca = "/_voltro/admin/import/start", la = "/_voltro/admin/export", ua = "/_voltro/admin/export/download", da = "/_voltro/admin/transfers", Z = (e, t) => ({
|
|
101
|
+
status: e,
|
|
102
|
+
contentType: "application/json; charset=utf-8",
|
|
103
|
+
body: JSON.stringify(t)
|
|
104
|
+
}), fa = (e) => {
|
|
105
|
+
let t = e.authorization ?? e.Authorization, n = t ? /^Bearer\s+(.+)$/i.exec(t) : null;
|
|
106
|
+
return n ? n[1] : null;
|
|
107
|
+
}, pa = (e, t) => Fi(Pi("sha256").update(e).digest(), Pi("sha256").update(t).digest()), ma = (e, t, n = "POST") => {
|
|
108
|
+
if (e.method.toUpperCase() !== n) return Z(405, { error: "method not allowed" });
|
|
109
|
+
if (!t || t.length < 16) return Z(503, { error: "data transfer misconfigured (no/weak secret)" });
|
|
110
|
+
let r = fa(e.headers);
|
|
111
|
+
return !r || !pa(r, t) ? Z(401, { error: "unauthorized" }) : null;
|
|
112
|
+
}, ha = /^[A-Za-z0-9_-]{8,64}$/, ga = (e) => ha.test(e), _a = () => process.env.VOLTRO_IMPORT_UPLOAD_DIR ?? I.join(Ci.tmpdir(), "voltro-import-uploads"), va = (e) => I.join(_a(), e), ya = (e) => I.join(va(e), "archive.bin"), ba = (e) => I.join(va(e), "meta.json"), xa = async (e = Date.now()) => {
|
|
113
|
+
let t = 0;
|
|
114
|
+
try {
|
|
115
|
+
for (let n of await X.readdir(_a())) {
|
|
116
|
+
if (n === ".runs") continue;
|
|
117
|
+
let r = await X.stat(va(n)).catch(() => null);
|
|
118
|
+
r !== null && (e - r.mtimeMs <= 864e5 || (await X.rm(va(n), {
|
|
119
|
+
recursive: !0,
|
|
120
|
+
force: !0
|
|
121
|
+
}).catch(() => void 0), t++));
|
|
122
|
+
}
|
|
123
|
+
} catch {}
|
|
124
|
+
return t;
|
|
125
|
+
}, Sa = async (e) => {
|
|
126
|
+
if (!ga(e)) return {
|
|
127
|
+
bytes: 0,
|
|
128
|
+
key: null,
|
|
129
|
+
runId: null
|
|
130
|
+
};
|
|
131
|
+
let t = await X.stat(ya(e)).catch(() => null);
|
|
132
|
+
if (t === null) return {
|
|
133
|
+
bytes: 0,
|
|
134
|
+
key: null,
|
|
135
|
+
runId: null
|
|
136
|
+
};
|
|
137
|
+
let n = await Ca(e);
|
|
138
|
+
return {
|
|
139
|
+
bytes: t.size,
|
|
140
|
+
key: n.key ?? null,
|
|
141
|
+
runId: n.runId ?? null
|
|
142
|
+
};
|
|
143
|
+
}, Ca = async (e) => {
|
|
144
|
+
try {
|
|
145
|
+
let t = await X.readFile(ba(e), "utf8");
|
|
146
|
+
return JSON.parse(t);
|
|
147
|
+
} catch {
|
|
148
|
+
return {};
|
|
149
|
+
}
|
|
150
|
+
}, wa = async (e, t) => {
|
|
151
|
+
let n = ba(e), r = `${n}.${process.pid}.${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
152
|
+
await X.writeFile(r, JSON.stringify(t)), await X.rename(r, n);
|
|
153
|
+
}, Ta = async (e, t, n) => {
|
|
154
|
+
if (!ga(e)) return t;
|
|
155
|
+
await X.mkdir(va(e), { recursive: !0 });
|
|
156
|
+
let r = await Ca(e), i = typeof r.runId == "string" && r.runId.length > 0 ? r.runId : null;
|
|
157
|
+
return i !== null && n?.takeOver !== !0 ? i : (await wa(e, {
|
|
158
|
+
...r,
|
|
159
|
+
runId: t
|
|
160
|
+
}), t);
|
|
161
|
+
}, Ea = async (e) => {
|
|
162
|
+
if (!ga(e)) return;
|
|
163
|
+
let t = await Ca(e);
|
|
164
|
+
if (t.runId === void 0) return;
|
|
165
|
+
let { runId: n, ...r } = t;
|
|
166
|
+
await wa(e, r).catch(() => void 0);
|
|
167
|
+
}, Da = async (e, t, n) => (await X.mkdir(va(e), { recursive: !0 }), await X.writeFile(ya(e), Buffer.from(t)), await wa(e, {
|
|
168
|
+
...await Ca(e),
|
|
169
|
+
key: n,
|
|
170
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
171
|
+
}), t.byteLength), Oa = (e) => `up-${Pi("sha256").update(e).digest("hex").slice(0, 32)}`, ka = async (e) => {
|
|
172
|
+
if (!ga(e.id)) return {
|
|
173
|
+
reason: "bad-id",
|
|
174
|
+
message: `upload id must match ${String(ha)}`
|
|
175
|
+
};
|
|
176
|
+
let t = await Sa(e.id);
|
|
177
|
+
if (t.key !== null && t.key !== e.key) return {
|
|
178
|
+
reason: "key-mismatch",
|
|
179
|
+
message: "this upload id already holds a different bundle. Use a new upload id, or delete the partial upload."
|
|
180
|
+
};
|
|
181
|
+
if (e.offset !== t.bytes) return {
|
|
182
|
+
reason: "offset-mismatch",
|
|
183
|
+
message: `chunk starts at ${e.offset} but the server holds ${t.bytes} byte(s)`,
|
|
184
|
+
expectedOffset: t.bytes
|
|
185
|
+
};
|
|
186
|
+
if (await X.mkdir(va(e.id), { recursive: !0 }), t.key === null) {
|
|
187
|
+
let t = await Ca(e.id);
|
|
188
|
+
await wa(e.id, {
|
|
189
|
+
...t,
|
|
190
|
+
key: e.key,
|
|
191
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return await new Promise((t, n) => {
|
|
195
|
+
let r = Fn(ya(e.id), { flags: "a" });
|
|
196
|
+
r.on("error", n), r.on("finish", () => t()), r.end(Buffer.from(e.bytes));
|
|
197
|
+
}), { total: t.bytes + e.bytes.byteLength };
|
|
198
|
+
}, Aa = async (e) => {
|
|
199
|
+
let t = await X.stat(ya(e));
|
|
200
|
+
return {
|
|
201
|
+
path: ya(e),
|
|
202
|
+
bytes: t.size
|
|
203
|
+
};
|
|
204
|
+
}, ja = () => I.join(_a(), ".runs"), Ma = (e) => I.join(ja(), `${e}.bin`), Na = async (e, t) => {
|
|
205
|
+
if (!ga(e)) return null;
|
|
206
|
+
let n = ya(e), r = await X.stat(n).catch(() => null);
|
|
207
|
+
if (r === null || r.size === 0) return null;
|
|
208
|
+
await X.mkdir(ja(), { recursive: !0 });
|
|
209
|
+
let i = Ma(t);
|
|
210
|
+
return await X.rename(n, i), i;
|
|
211
|
+
}, Pa = async (e) => {
|
|
212
|
+
await X.rm(Ma(e), { force: !0 }).catch(() => void 0);
|
|
213
|
+
}, Q = L({ scope: "voltro:admin-import" }), Fa = "VBUNDLE2", Ia = (e) => {
|
|
214
|
+
let t = e.req.headers["x-import-rollback-key"];
|
|
215
|
+
if (e.mode !== "replace") return { options: {} };
|
|
216
|
+
if (typeof t != "string" || t.length === 0) return Q.warn("admin.import: no rollback capture — this run empties the target first, and nothing was asked to be kept. Send `x-import-rollback-key: <storage key>` (voltro data import --rollback-key <key>) to have the instance store the target's current rows before deleting them."), { options: {} };
|
|
217
|
+
if (e.deps.putArchive === void 0) return {
|
|
218
|
+
options: {},
|
|
219
|
+
refusal: Z(409, {
|
|
220
|
+
error: "rollback capture requested but this instance has no object storage configured",
|
|
221
|
+
hint: "A capture written to the pod would not survive the failure it exists for. Configure storage (the same one the storage-push export uses), or re-send without `x-import-rollback-key` to accept that a run which does not finish can leave the target emptied. Note that CONFIGURED is not the same question as SURVIVES: a `filesystem` provider pointed at a container directory with no volume behind it passes this check and dies with the pod. The run says so when it can observe it — the capture path being on the same filesystem as `/`."
|
|
222
|
+
})
|
|
223
|
+
};
|
|
224
|
+
let n = Pn(wi(), `voltro-rollback-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`), r = e.deps.putArchive;
|
|
225
|
+
return {
|
|
226
|
+
key: t,
|
|
227
|
+
options: {
|
|
228
|
+
rollbackDir: n,
|
|
229
|
+
onRollbackCaptured: async () => {
|
|
230
|
+
let e = Di(n);
|
|
231
|
+
e !== void 0 && Q.warn(`admin.import: ${e}`), await r(t, () => Yi({ dir: n })), Q.info("admin.import: rollback capture stored", { bundleKey: t });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}, La = (e) => {
|
|
236
|
+
let t = e["x-import-mode"], n = e["x-import-atomic"];
|
|
237
|
+
return {
|
|
238
|
+
mode: t,
|
|
239
|
+
onConflict: e["x-import-on-conflict"],
|
|
240
|
+
atomic: n === "0" || n === "false" ? !1 : n === "1" || n === "true" || t === "replace",
|
|
241
|
+
force: e["x-import-force"] === "1" || e["x-import-force"] === "true",
|
|
242
|
+
dryRun: e["x-import-dry-run"] === "1" || e["x-import-dry-run"] === "true",
|
|
243
|
+
tables: (e["x-import-tables"] ?? "").split(",").map((e) => e.trim()).filter(Boolean)
|
|
244
|
+
};
|
|
245
|
+
}, Ra = async (e, t) => {
|
|
246
|
+
if (typeof t.bundleKey == "string" && t.bundleKey !== "") {
|
|
247
|
+
if (!e.openArchive) return { refusal: Z(501, { error: "storage transport not configured on this instance" }) };
|
|
248
|
+
let n = e.openArchive, r = t.bundleKey;
|
|
249
|
+
return {
|
|
250
|
+
source: () => n(r),
|
|
251
|
+
transport: "storage",
|
|
252
|
+
uploadId: Oa(r)
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
let n = t.uploadId;
|
|
256
|
+
if (typeof n != "string" || !ga(n)) return { refusal: Z(400, { error: "start needs { uploadId } from an upload, or { bundleKey } for the storage transport" }) };
|
|
257
|
+
let r = await Aa(n).catch(() => null);
|
|
258
|
+
return r === null || r.bytes === 0 ? { refusal: Z(409, {
|
|
259
|
+
error: "no such upload",
|
|
260
|
+
message: `this instance holds no bytes for upload '${n}'. Upload the bundle first, or re-upload if it has expired.`
|
|
261
|
+
}) } : {
|
|
262
|
+
source: () => za(r.path),
|
|
263
|
+
transport: "upload",
|
|
264
|
+
uploadId: n
|
|
265
|
+
};
|
|
266
|
+
}, za = (e) => {
|
|
267
|
+
let { createReadStream: t } = ra("node:fs");
|
|
268
|
+
return t(e);
|
|
269
|
+
}, Ba = (e) => async (t) => {
|
|
270
|
+
let n = ma(t, e.secret);
|
|
271
|
+
if (n) return n;
|
|
272
|
+
let r = La(t.headers), i = Ia({
|
|
273
|
+
req: t,
|
|
274
|
+
mode: r.mode,
|
|
275
|
+
deps: e
|
|
276
|
+
});
|
|
277
|
+
if (i.refusal !== void 0) return i.refusal;
|
|
278
|
+
if (t.headers["x-import-preflight"] === "1" || t.headers["x-import-preflight"] === "true") {
|
|
279
|
+
let n;
|
|
280
|
+
try {
|
|
281
|
+
n = JSON.parse(Buffer.from(t.rawBody).toString("utf8") || "{}");
|
|
282
|
+
} catch {
|
|
283
|
+
return Z(400, { error: "a preflight body must be JSON: { tables: string[] } or { bundleKey: string }" });
|
|
284
|
+
}
|
|
285
|
+
let a = Array.isArray(n.tables) ? n.tables.filter((e) => typeof e == "string") : [];
|
|
286
|
+
if (a.length === 0 && typeof n.bundleKey == "string" && n.bundleKey !== "" && e.openArchive && (a = [...await Va(e.openArchive(n.bundleKey))]), a.length === 0) return Z(400, {
|
|
287
|
+
error: "a preflight needs { tables: string[] } — the bundle's table names, so the staging decision can be made against them",
|
|
288
|
+
hint: "or { bundleKey } on an instance with storage configured, where this endpoint reads the table list out of the archive itself"
|
|
289
|
+
});
|
|
290
|
+
let o = qi({
|
|
291
|
+
mode: r.mode ?? "upsert",
|
|
292
|
+
...e.dialect === void 0 ? {} : { targetDialect: e.dialect },
|
|
293
|
+
...e.snapshot === void 0 ? {} : { targetSnapshot: e.snapshot },
|
|
294
|
+
bundleTables: a,
|
|
295
|
+
isSkipped: Ji,
|
|
296
|
+
canRunSql: !0
|
|
297
|
+
});
|
|
298
|
+
return Z(200, {
|
|
299
|
+
preflight: !0,
|
|
300
|
+
mode: r.mode ?? "upsert",
|
|
301
|
+
atomic: r.atomic,
|
|
302
|
+
staged: o.active,
|
|
303
|
+
...o.blocker === void 0 ? {} : { reason: o.blocker },
|
|
304
|
+
stagedTables: o.tables.length,
|
|
305
|
+
rollback: i.key === void 0 ? { taken: !1 } : {
|
|
306
|
+
taken: !0,
|
|
307
|
+
key: i.key
|
|
308
|
+
},
|
|
309
|
+
dialect: e.dialect ?? null
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
let a = t.headers["x-import-upload-id"];
|
|
313
|
+
if (a !== void 0 && a !== "") {
|
|
314
|
+
if (xa(), t.headers["x-import-probe"] === "1") {
|
|
315
|
+
let e = await Sa(a);
|
|
316
|
+
return Z(200, {
|
|
317
|
+
uploadId: a,
|
|
318
|
+
bytes: e.bytes,
|
|
319
|
+
...e.runId === null ? {} : { runId: e.runId }
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
let e = t.headers["x-import-upload-key"] ?? "", n = Number(t.headers["x-import-chunk-offset"] ?? "0");
|
|
323
|
+
if (e === "" || !Number.isFinite(n) || n < 0) return Z(400, { error: "a chunked upload needs x-import-upload-key and a numeric x-import-chunk-offset" });
|
|
324
|
+
let r = await ka({
|
|
325
|
+
id: a,
|
|
326
|
+
key: e,
|
|
327
|
+
offset: n,
|
|
328
|
+
bytes: t.rawBody
|
|
329
|
+
});
|
|
330
|
+
if ("reason" in r) return Q.warn("admin.import chunk refused", {
|
|
331
|
+
uploadId: a,
|
|
332
|
+
reason: r.reason
|
|
333
|
+
}), Z(409, {
|
|
334
|
+
error: "chunk refused",
|
|
335
|
+
reason: r.reason,
|
|
336
|
+
message: r.message,
|
|
337
|
+
...r.expectedOffset === void 0 ? {} : { expectedOffset: r.expectedOffset }
|
|
338
|
+
});
|
|
339
|
+
let i = t.headers["x-import-chunk-final"] === "1";
|
|
340
|
+
return Z(202, {
|
|
341
|
+
uploadId: a,
|
|
342
|
+
bytes: r.total,
|
|
343
|
+
complete: i
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (t.rawBody.byteLength >= 8 && Buffer.from(t.rawBody.subarray(0, 8)).toString("latin1") === Fa) {
|
|
347
|
+
xa();
|
|
348
|
+
let e = Pi("sha256").update(Buffer.from(t.rawBody)).digest("hex"), n = Oa(e);
|
|
349
|
+
return Z(202, {
|
|
350
|
+
uploadId: n,
|
|
351
|
+
bytes: await Da(n, t.rawBody, e),
|
|
352
|
+
complete: !0
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
let o;
|
|
356
|
+
try {
|
|
357
|
+
o = JSON.parse(Buffer.from(t.rawBody).toString("utf8") || "{}");
|
|
358
|
+
} catch {
|
|
359
|
+
return Z(400, { error: "body must be a packed bundle archive or { bundleKey } JSON" });
|
|
360
|
+
}
|
|
361
|
+
return typeof o.bundleKey != "string" || !o.bundleKey ? Z(400, { error: "body.bundleKey (string) is required for the storage transport" }) : e.openArchive ? Z(202, {
|
|
362
|
+
uploadId: Oa(o.bundleKey),
|
|
363
|
+
bundleKey: o.bundleKey,
|
|
364
|
+
complete: !0
|
|
365
|
+
}) : Z(501, { error: "storage transport not configured on this instance" });
|
|
366
|
+
}, Va = async (e) => {
|
|
367
|
+
let t = await Xi(e, ["manifest.json"]).then((e) => e.get("manifest.json"), () => void 0);
|
|
368
|
+
if (t === void 0) return [];
|
|
369
|
+
try {
|
|
370
|
+
return (JSON.parse(Buffer.from(t).toString("utf8")).tables ?? []).map((e) => e.name).filter((e) => typeof e == "string");
|
|
371
|
+
} catch {
|
|
372
|
+
return [];
|
|
373
|
+
}
|
|
374
|
+
}, Ha = (e) => async (t) => {
|
|
375
|
+
let n = ma(t, e.secret);
|
|
376
|
+
if (n) return n;
|
|
377
|
+
let r = La(t.headers), i = Ia({
|
|
378
|
+
req: t,
|
|
379
|
+
mode: r.mode,
|
|
380
|
+
deps: e
|
|
381
|
+
});
|
|
382
|
+
if (i.refusal !== void 0) return i.refusal;
|
|
383
|
+
let a;
|
|
384
|
+
try {
|
|
385
|
+
a = JSON.parse(Buffer.from(t.rawBody).toString("utf8") || "{}");
|
|
386
|
+
} catch {
|
|
387
|
+
return Z(400, { error: "body must be JSON: { uploadId } or { bundleKey }" });
|
|
388
|
+
}
|
|
389
|
+
let o = typeof a.bundleKey == "string" && a.bundleKey !== "" ? Oa(a.bundleKey) : typeof a.uploadId == "string" ? a.uploadId : "";
|
|
390
|
+
if (!ga(o)) return Z(400, { error: "start needs { uploadId } from an upload, or { bundleKey } for the storage transport" });
|
|
391
|
+
let s = ir("dimp", `${o}-${Date.now()}-${Math.random()}`), c = await Ta(o, s);
|
|
392
|
+
if (c !== s) {
|
|
393
|
+
let t = await An(e.store, c);
|
|
394
|
+
if (jn(t) === void 0 && t !== null) return Q.info("admin.import start: already running", {
|
|
395
|
+
uploadId: o,
|
|
396
|
+
runId: c
|
|
397
|
+
}), Z(202, {
|
|
398
|
+
runId: c,
|
|
399
|
+
uploadId: o,
|
|
400
|
+
alreadyStarted: !0
|
|
401
|
+
});
|
|
402
|
+
Q.info("admin.import start: taking over a claim whose run is not running", {
|
|
403
|
+
uploadId: o,
|
|
404
|
+
staleRunId: c,
|
|
405
|
+
outcome: jn(t) ?? "no record"
|
|
406
|
+
}), c = await Ta(o, s, { takeOver: !0 });
|
|
407
|
+
}
|
|
408
|
+
let l = async (e) => (await Ea(o).catch(() => void 0), e), u = await Ra(e, {
|
|
409
|
+
...typeof a.uploadId == "string" ? { uploadId: a.uploadId } : {},
|
|
410
|
+
...typeof a.bundleKey == "string" ? { bundleKey: a.bundleKey } : {}
|
|
411
|
+
});
|
|
412
|
+
if ("refusal" in u) return l(u.refusal);
|
|
413
|
+
if (e.snapshot !== void 0 && !r.force) {
|
|
414
|
+
let t = await Ua(u.source());
|
|
415
|
+
if (t !== null) {
|
|
416
|
+
let n = Ki(t.source?.schemaFingerprint ?? "", e.snapshot, Wa(t));
|
|
417
|
+
if (n.drifted) return Q.warn("admin.import refused (schema drift)", {
|
|
418
|
+
transport: u.transport,
|
|
419
|
+
bundle: n.bundleFingerprint.slice(0, 16),
|
|
420
|
+
target: n.targetFingerprint.slice(0, 16)
|
|
421
|
+
}), l(Z(409, {
|
|
422
|
+
error: "schema drift",
|
|
423
|
+
bundleFingerprint: n.bundleFingerprint,
|
|
424
|
+
targetFingerprint: n.targetFingerprint,
|
|
425
|
+
diff: n.diff,
|
|
426
|
+
hint: "each line above would break the load: a table or column the bundle carries that the target cannot take, or a column the target requires that the bundle has no value for. Fix the target schema, re-export against it, or resend with x-import-force: 1 to write anyway."
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
let d = null;
|
|
431
|
+
if (u.transport === "upload" && (d = await Na(u.uploadId, c), d === null)) return l(Z(409, {
|
|
432
|
+
error: "no such upload",
|
|
433
|
+
message: `the bytes for upload '${u.uploadId}' are gone. Re-upload the bundle.`
|
|
434
|
+
}));
|
|
435
|
+
let f = await Ga(e.store, {
|
|
436
|
+
runId: c,
|
|
437
|
+
mode: r.mode ?? "upsert",
|
|
438
|
+
via: "api",
|
|
439
|
+
bundle: u.transport === "storage" ? String(a.bundleKey) : u.uploadId
|
|
440
|
+
});
|
|
441
|
+
return Ka({
|
|
442
|
+
deps: e,
|
|
443
|
+
opts: r,
|
|
444
|
+
rollback: i,
|
|
445
|
+
runId: c,
|
|
446
|
+
traced: f,
|
|
447
|
+
resolved: d === null ? u : {
|
|
448
|
+
...u,
|
|
449
|
+
source: () => za(d)
|
|
450
|
+
}
|
|
451
|
+
}), Q.info("admin.import started", {
|
|
452
|
+
runId: c,
|
|
453
|
+
uploadId: u.uploadId,
|
|
454
|
+
transport: u.transport,
|
|
455
|
+
mode: r.mode ?? "upsert",
|
|
456
|
+
atomic: r.atomic,
|
|
457
|
+
dryRun: r.dryRun
|
|
458
|
+
}), Z(202, {
|
|
459
|
+
runId: c,
|
|
460
|
+
uploadId: u.uploadId,
|
|
461
|
+
transport: u.transport,
|
|
462
|
+
mode: r.mode ?? "upsert",
|
|
463
|
+
atomic: r.atomic,
|
|
464
|
+
...r.dryRun ? { dryRun: !0 } : {},
|
|
465
|
+
recorded: f,
|
|
466
|
+
outcome: "poll /_voltro/admin/transfers for this runId — a 202 means started, not finished"
|
|
467
|
+
});
|
|
468
|
+
}, Ua = async (e) => {
|
|
469
|
+
let t = await Xi(e, ["manifest.json"]).then((e) => e.get("manifest.json"), () => null);
|
|
470
|
+
if (t == null) return null;
|
|
471
|
+
try {
|
|
472
|
+
return JSON.parse(Buffer.from(t).toString("utf8"));
|
|
473
|
+
} catch {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
}, Wa = (e) => ({ tables: (e.tables ?? []).map((e) => ({
|
|
477
|
+
name: e.name,
|
|
478
|
+
indexes: [],
|
|
479
|
+
columns: Object.entries(e.columnTypes ?? {}).map(([e, t]) => ({
|
|
480
|
+
name: e,
|
|
481
|
+
type: t,
|
|
482
|
+
nullable: !0,
|
|
483
|
+
unique: !1,
|
|
484
|
+
hasDefault: !1
|
|
485
|
+
}))
|
|
486
|
+
})) }), Ga = async (e, t) => {
|
|
487
|
+
try {
|
|
488
|
+
return or(er), await e.insert(H, {
|
|
489
|
+
id: t.runId,
|
|
490
|
+
direction: "import",
|
|
491
|
+
startedAt: /* @__PURE__ */ new Date(),
|
|
492
|
+
finishedAt: null,
|
|
493
|
+
failure: null,
|
|
494
|
+
mode: t.mode,
|
|
495
|
+
via: t.via,
|
|
496
|
+
bundle: t.bundle,
|
|
497
|
+
sourceFingerprint: null,
|
|
498
|
+
tablesWritten: 0,
|
|
499
|
+
rowsWritten: 0,
|
|
500
|
+
staged: null
|
|
501
|
+
}), !0;
|
|
502
|
+
} catch (e) {
|
|
503
|
+
return Q.warn("admin.import: the run could not be recorded", {
|
|
504
|
+
runId: t.runId,
|
|
505
|
+
error: e?.message ?? String(e)
|
|
506
|
+
}), !1;
|
|
507
|
+
}
|
|
508
|
+
}, Ka = async (e) => {
|
|
509
|
+
let { deps: t, opts: n, rollback: r, resolved: i, runId: a } = e, o = await import("node:os"), s = await import("node:fs/promises"), c = await import("node:path"), l = await s.mkdtemp(c.join(o.tmpdir(), "voltro-admin-import-")), u = async (n) => {
|
|
510
|
+
Q.warn("admin.import failed", {
|
|
511
|
+
runId: a,
|
|
512
|
+
transport: i.transport,
|
|
513
|
+
error: n
|
|
514
|
+
}), e.traced && await t.store.update(H, a, {
|
|
515
|
+
failure: n,
|
|
516
|
+
finishedAt: null
|
|
517
|
+
}).then(() => void 0, () => void 0);
|
|
518
|
+
};
|
|
519
|
+
try {
|
|
520
|
+
t.assetSink ? await ta(i.source(), {
|
|
521
|
+
dir: l,
|
|
522
|
+
blobs: t.assetSink
|
|
523
|
+
}) : await na(i.source(), l);
|
|
524
|
+
let o = await W.runPromiseExit(Qi({
|
|
525
|
+
store: t.store,
|
|
526
|
+
bundleDir: l,
|
|
527
|
+
...n.mode ? { mode: n.mode } : {},
|
|
528
|
+
...n.onConflict ? { onConflict: n.onConflict } : {},
|
|
529
|
+
atomic: n.atomic,
|
|
530
|
+
...r.options,
|
|
531
|
+
recordInterruption: !0,
|
|
532
|
+
via: "api",
|
|
533
|
+
...e.traced ? { traceId: a } : {},
|
|
534
|
+
...n.dryRun ? { dryRun: n.dryRun } : {},
|
|
535
|
+
...n.tables.length > 0 ? { tables: [...n.tables] } : {},
|
|
536
|
+
...t.snapshot ? { targetSnapshot: t.snapshot } : {},
|
|
537
|
+
...t.dialect ? { targetDialect: t.dialect } : {},
|
|
538
|
+
force: n.force,
|
|
539
|
+
onWarn: (e) => Q.warn("admin.import", {
|
|
540
|
+
runId: a,
|
|
541
|
+
message: e
|
|
542
|
+
}),
|
|
543
|
+
...t.assetSink ? { assetsAlreadyRestored: !0 } : {}
|
|
544
|
+
}));
|
|
545
|
+
if (o._tag === "Failure") {
|
|
546
|
+
let e = o.cause._tag === "Fail" ? o.cause.error : void 0, t = typeof e?.reason == "string" ? e.reason : void 0, n = e?.diff;
|
|
547
|
+
await u(t ?? (Array.isArray(n) ? `schema drift: ${n.join("; ")}` : void 0) ?? String(e?.message ?? e ?? "import failed"));
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
let s = o.value;
|
|
551
|
+
Q.info(n.dryRun ? "admin.import (dry run — nothing written)" : "admin.import complete", {
|
|
552
|
+
runId: a,
|
|
553
|
+
transport: i.transport,
|
|
554
|
+
tables: s.tablesWritten,
|
|
555
|
+
rows: s.rowsWritten,
|
|
556
|
+
mode: n.mode ?? "upsert",
|
|
557
|
+
atomic: n.atomic,
|
|
558
|
+
...s.tablesSkipped > 0 ? {
|
|
559
|
+
skippedTables: s.tablesSkipped,
|
|
560
|
+
skippedRows: s.rowsSkipped
|
|
561
|
+
} : {}
|
|
562
|
+
}), n.dryRun || t.refreshSubscriptions?.(`data import: ${s.tablesWritten} table(s), mode ${n.mode ?? "upsert"}`);
|
|
563
|
+
} catch (e) {
|
|
564
|
+
await u(e?.message ?? String(e));
|
|
565
|
+
} finally {
|
|
566
|
+
await s.rm(l, {
|
|
567
|
+
recursive: !0,
|
|
568
|
+
force: !0
|
|
569
|
+
}).catch(() => void 0), await Pa(a).catch(() => void 0), await Ea(i.uploadId).catch(() => void 0);
|
|
570
|
+
}
|
|
571
|
+
}, qa = /^[A-Za-z0-9_-]{8,64}$/, Ja = (e) => qa.test(e), Ya = () => process.env.VOLTRO_EXPORT_ARTIFACT_DIR ?? I.join(Ci.tmpdir(), "voltro-export-artifacts"), Xa = (e) => I.join(Ya(), e), Za = (e) => I.join(Xa(e), "archive.bin"), Qa = async (e = Date.now()) => {
|
|
572
|
+
let t = 0;
|
|
573
|
+
try {
|
|
574
|
+
for (let n of await X.readdir(Ya())) {
|
|
575
|
+
let r = await X.stat(Xa(n)).catch(() => null);
|
|
576
|
+
r !== null && (e - r.mtimeMs <= 864e5 || (await X.rm(Xa(n), {
|
|
577
|
+
recursive: !0,
|
|
578
|
+
force: !0
|
|
579
|
+
}).catch(() => void 0), t++));
|
|
580
|
+
}
|
|
581
|
+
} catch {}
|
|
582
|
+
return t;
|
|
583
|
+
}, $a = async (e, t) => {
|
|
584
|
+
if (!Ja(e)) throw Error(`invalid run id: ${e}`);
|
|
585
|
+
await X.mkdir(Xa(e), { recursive: !0 });
|
|
586
|
+
let { createWriteStream: n } = await import("node:fs"), r = n(Za(e)), i = 0;
|
|
587
|
+
try {
|
|
588
|
+
for await (let e of t) i += e.byteLength, r.write(Buffer.from(e)) || await new Promise((e, t) => {
|
|
589
|
+
r.once("drain", e), r.once("error", t);
|
|
590
|
+
});
|
|
591
|
+
} finally {
|
|
592
|
+
await new Promise((e, t) => {
|
|
593
|
+
r.end(() => e()), r.once("error", t);
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
return i;
|
|
597
|
+
}, eo = async (e) => {
|
|
598
|
+
if (!Ja(e)) return null;
|
|
599
|
+
let t = await X.stat(Za(e)).catch(() => null);
|
|
600
|
+
return t === null ? null : t.size;
|
|
601
|
+
}, to = async (e, t, n) => {
|
|
602
|
+
let r = await eo(e);
|
|
603
|
+
if (r === null) return null;
|
|
604
|
+
if (t >= r) return {
|
|
605
|
+
bytes: Buffer.alloc(0),
|
|
606
|
+
total: r
|
|
607
|
+
};
|
|
608
|
+
let i = await X.open(Za(e), "r");
|
|
609
|
+
try {
|
|
610
|
+
let e = Math.max(0, Math.min(n, r - t)), a = Buffer.alloc(e);
|
|
611
|
+
return await i.read(a, 0, e, t), {
|
|
612
|
+
bytes: a,
|
|
613
|
+
total: r
|
|
614
|
+
};
|
|
615
|
+
} finally {
|
|
616
|
+
await i.close();
|
|
617
|
+
}
|
|
618
|
+
}, no = async (e) => {
|
|
619
|
+
Ja(e) && await X.rm(Xa(e), {
|
|
620
|
+
recursive: !0,
|
|
621
|
+
force: !0
|
|
622
|
+
}).catch(() => void 0);
|
|
623
|
+
}, ro = L({ scope: "voltro:admin-export" }), io = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "string") : [], ao = (e) => {
|
|
624
|
+
if (typeof e.tenant == "string" && e.tenant) return {
|
|
625
|
+
kind: "tenant",
|
|
626
|
+
tenantId: e.tenant
|
|
627
|
+
};
|
|
628
|
+
if (Array.isArray(e.tables) && e.tables.length) return {
|
|
629
|
+
kind: "tables",
|
|
630
|
+
tables: io(e.tables)
|
|
631
|
+
};
|
|
632
|
+
let t = io(e.exclude);
|
|
633
|
+
return t.length > 0 ? {
|
|
634
|
+
kind: "all",
|
|
635
|
+
exclude: t
|
|
636
|
+
} : { kind: "all" };
|
|
637
|
+
}, oo = (e) => async (t) => {
|
|
638
|
+
let n = ma(t, e.secret);
|
|
639
|
+
if (n) return n;
|
|
640
|
+
let r;
|
|
641
|
+
try {
|
|
642
|
+
r = JSON.parse(Buffer.from(t.rawBody).toString("utf8") || "{}");
|
|
643
|
+
} catch {
|
|
644
|
+
return Z(400, { error: "body must be JSON: { profile?, tenant?, tables?, consistency?, compression?, bundleKey? }" });
|
|
645
|
+
}
|
|
646
|
+
let i = {};
|
|
647
|
+
if (typeof r.profile == "string" && r.profile) {
|
|
648
|
+
if (!e.loadProfile) return Z(501, { error: "server-side profiles not configured on this instance" });
|
|
649
|
+
try {
|
|
650
|
+
i = await e.loadProfile(r.profile);
|
|
651
|
+
} catch (e) {
|
|
652
|
+
return Z(400, {
|
|
653
|
+
error: `profile '${r.profile}' could not be loaded`,
|
|
654
|
+
message: e?.message ?? String(e)
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
let a = r.consistency === "snapshot" ? "snapshot" : i.consistency ?? "live", o = (typeof r.compression == "string" ? r.compression : void 0) ?? i.compression, s = i.scope ?? ao(r), c = typeof r.bundleKey == "string" && r.bundleKey.length > 0, l = r.assets === !0 && e.assetSource ? { blobs: e.assetSource } : {}, u = ir("dexp", `${Date.now()}-${Math.random()}`), d = await so(e.store, {
|
|
659
|
+
runId: u,
|
|
660
|
+
mode: i.subset ? "subset" : s.kind,
|
|
661
|
+
bundle: c ? String(r.bundleKey) : null
|
|
662
|
+
});
|
|
663
|
+
return co({
|
|
664
|
+
deps: e,
|
|
665
|
+
runId: u,
|
|
666
|
+
recorded: d,
|
|
667
|
+
profile: i,
|
|
668
|
+
scope: s,
|
|
669
|
+
consistency: a,
|
|
670
|
+
blobs: l,
|
|
671
|
+
...o ? { compression: o } : {},
|
|
672
|
+
...c ? { bundleKey: String(r.bundleKey) } : {}
|
|
673
|
+
}), Qa(), ro.info("admin.export started", {
|
|
674
|
+
runId: u,
|
|
675
|
+
scope: s.kind,
|
|
676
|
+
storage: c
|
|
677
|
+
}), Z(202, {
|
|
678
|
+
runId: u,
|
|
679
|
+
transport: c ? "storage" : "download",
|
|
680
|
+
...c ? { bundleKey: r.bundleKey } : {},
|
|
681
|
+
recorded: d,
|
|
682
|
+
outcome: "poll /_voltro/admin/transfers for this runId; fetch the bytes from /_voltro/admin/export/download"
|
|
683
|
+
});
|
|
684
|
+
}, so = async (e, t) => {
|
|
685
|
+
try {
|
|
686
|
+
return or(er), await e.insert(H, {
|
|
687
|
+
id: t.runId,
|
|
688
|
+
direction: "export",
|
|
689
|
+
startedAt: /* @__PURE__ */ new Date(),
|
|
690
|
+
finishedAt: null,
|
|
691
|
+
failure: null,
|
|
692
|
+
mode: t.mode,
|
|
693
|
+
via: "api",
|
|
694
|
+
bundle: t.bundle,
|
|
695
|
+
sourceFingerprint: null,
|
|
696
|
+
tablesWritten: 0,
|
|
697
|
+
rowsWritten: 0,
|
|
698
|
+
staged: null
|
|
699
|
+
}), !0;
|
|
700
|
+
} catch (e) {
|
|
701
|
+
return ro.warn("admin.export: the run could not be recorded", {
|
|
702
|
+
runId: t.runId,
|
|
703
|
+
error: e?.message ?? String(e)
|
|
704
|
+
}), !1;
|
|
705
|
+
}
|
|
706
|
+
}, co = async (e) => {
|
|
707
|
+
let { deps: t, runId: n } = e, r = await import("node:os"), i = await import("node:fs/promises"), a = await import("node:path"), o = await i.mkdtemp(a.join(r.tmpdir(), "voltro-admin-export-")), s = async (r) => {
|
|
708
|
+
e.recorded && await t.store.update(H, n, r).then(() => void 0, () => void 0);
|
|
709
|
+
};
|
|
710
|
+
try {
|
|
711
|
+
let r = await W.runPromise(Zi({
|
|
712
|
+
store: t.store,
|
|
713
|
+
snapshot: t.snapshot,
|
|
714
|
+
dialect: t.dialect,
|
|
715
|
+
outDir: o,
|
|
716
|
+
...e.profile.subset ? { subset: e.profile.subset } : {
|
|
717
|
+
scope: e.scope,
|
|
718
|
+
...t.tenantTables && t.tenantTables.length > 0 ? { tenantTables: t.tenantTables } : {}
|
|
719
|
+
},
|
|
720
|
+
consistency: e.consistency,
|
|
721
|
+
...e.compression ? { compression: e.compression } : {},
|
|
722
|
+
...e.profile.masking ? { masking: e.profile.masking } : {}
|
|
723
|
+
})), i = r.tables.reduce((e, t) => e + t.rowCount, 0), a = r.masking?.transformed.length ?? 0;
|
|
724
|
+
if (e.bundleKey !== void 0) {
|
|
725
|
+
if (!t.putArchive) throw Error("storage transport not configured on this instance");
|
|
726
|
+
await t.putArchive(e.bundleKey, () => Yi({
|
|
727
|
+
dir: o,
|
|
728
|
+
...e.blobs
|
|
729
|
+
}));
|
|
730
|
+
}
|
|
731
|
+
let c = await $a(n, Yi({
|
|
732
|
+
dir: o,
|
|
733
|
+
...e.blobs
|
|
734
|
+
}));
|
|
735
|
+
ro.info("admin.export complete", {
|
|
736
|
+
runId: n,
|
|
737
|
+
tables: r.tables.length,
|
|
738
|
+
rows: i,
|
|
739
|
+
masked: a,
|
|
740
|
+
bytes: c,
|
|
741
|
+
...e.bundleKey === void 0 ? {} : { bundleKey: e.bundleKey }
|
|
742
|
+
}), await s({
|
|
743
|
+
finishedAt: /* @__PURE__ */ new Date(),
|
|
744
|
+
failure: null,
|
|
745
|
+
tablesWritten: r.tables.length,
|
|
746
|
+
rowsWritten: i,
|
|
747
|
+
sourceFingerprint: r.source?.schemaFingerprint ?? null
|
|
748
|
+
});
|
|
749
|
+
} catch (e) {
|
|
750
|
+
let t = e?.message ?? String(e);
|
|
751
|
+
ro.warn("admin.export failed", {
|
|
752
|
+
runId: n,
|
|
753
|
+
error: t
|
|
754
|
+
}), await s({
|
|
755
|
+
failure: t,
|
|
756
|
+
finishedAt: null
|
|
757
|
+
}), await no(n);
|
|
758
|
+
} finally {
|
|
759
|
+
await i.rm(o, {
|
|
760
|
+
recursive: !0,
|
|
761
|
+
force: !0
|
|
762
|
+
}).catch(() => void 0);
|
|
763
|
+
}
|
|
764
|
+
}, lo = (e) => async (t) => {
|
|
765
|
+
let n = ma(t, e.secret, "GET");
|
|
766
|
+
if (n) return n;
|
|
767
|
+
let r = new URLSearchParams(t.query ?? ""), i = r.get("runId") ?? "";
|
|
768
|
+
if (!Ja(i)) return Z(400, { error: "download needs ?runId=<id> from the 202 the export answered with" });
|
|
769
|
+
let a = Math.max(0, Number(r.get("offset") ?? "0") || 0), o = Number(r.get("length") ?? "8388608"), s = await to(i, a, Number.isFinite(o) && o > 0 ? Math.min(o, fo) : uo);
|
|
770
|
+
return s === null ? Z(404, {
|
|
771
|
+
error: "no artefact",
|
|
772
|
+
message: `this instance holds no produced bundle for run '${i}'. It may have expired, or the export may still be running — poll the run first.`
|
|
773
|
+
}) : {
|
|
774
|
+
status: 200,
|
|
775
|
+
contentType: "application/octet-stream",
|
|
776
|
+
body: new Uint8Array(s.bytes),
|
|
777
|
+
headers: {
|
|
778
|
+
"x-export-total-bytes": String(s.total),
|
|
779
|
+
"x-export-offset": String(a),
|
|
780
|
+
"x-export-length": String(s.bytes.byteLength)
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
}, uo = 8388608, fo = 33554432, po = async (e, t) => await e.query({
|
|
784
|
+
table: H,
|
|
785
|
+
order: [{
|
|
786
|
+
column: "startedAt",
|
|
787
|
+
direction: "desc"
|
|
788
|
+
}],
|
|
789
|
+
predicate: void 0,
|
|
790
|
+
projection: void 0,
|
|
791
|
+
skip: 0,
|
|
792
|
+
take: t
|
|
793
|
+
}), mo = (e) => {
|
|
794
|
+
let t = new Date(e);
|
|
795
|
+
return Number.isFinite(t.getTime()) ? t : /* @__PURE__ */ new Date(0);
|
|
796
|
+
}, ho = (e) => ({
|
|
797
|
+
...e,
|
|
798
|
+
startedAt: mo(e.startedAt),
|
|
799
|
+
finishedAt: e.finishedAt === null || e.finishedAt === void 0 ? null : mo(e.finishedAt)
|
|
800
|
+
}), go = (e) => async (t) => {
|
|
801
|
+
let n = ma(t, e.secret, "GET");
|
|
802
|
+
if (n) return n;
|
|
803
|
+
let r = Number(new URLSearchParams(t.query ?? "").get("limit") ?? "20"), i = Number.isFinite(r) ? Math.max(1, Math.min(200, Math.trunc(r))) : 20, a;
|
|
804
|
+
try {
|
|
805
|
+
a = (await po(e.store, i)).map(ho);
|
|
806
|
+
} catch (e) {
|
|
807
|
+
return Z(409, {
|
|
808
|
+
error: "no import history",
|
|
809
|
+
message: `this instance has no \`${H}\` table, so no import has been recorded. Run \`voltro db apply\` against it; imports themselves are unaffected.`,
|
|
810
|
+
detail: e?.message ?? String(e)
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
return Z(200, {
|
|
814
|
+
running: a.filter((e) => e.finishedAt === null && e.failure === null).length,
|
|
815
|
+
runs: a.map((e) => ({
|
|
816
|
+
id: e.id,
|
|
817
|
+
startedAt: e.startedAt.toISOString(),
|
|
818
|
+
finishedAt: e.finishedAt === null ? null : e.finishedAt.toISOString(),
|
|
819
|
+
mode: e.mode,
|
|
820
|
+
via: e.via,
|
|
821
|
+
bundle: e.bundle,
|
|
822
|
+
sourceFingerprint: e.sourceFingerprint,
|
|
823
|
+
tablesWritten: e.tablesWritten,
|
|
824
|
+
rowsWritten: e.rowsWritten,
|
|
825
|
+
direction: e.direction,
|
|
826
|
+
failure: e.failure,
|
|
827
|
+
staged: e.staged,
|
|
828
|
+
line: ar(e)
|
|
829
|
+
}))
|
|
830
|
+
});
|
|
831
|
+
}, _o = (e, t, n = {}) => (async function* () {
|
|
832
|
+
let r = await W.runPromise(ki(e, t).pipe(W.timeout(n.openTimeout ?? "30 seconds"))), i = await ji(r.stream), a = n.stallMs ?? 12e4, o, s = () => {
|
|
833
|
+
o && clearTimeout(o), o = setTimeout(() => i.destroy(/* @__PURE__ */ Error(`storage read stalled for ${a}ms reading '${t}'`)), a);
|
|
834
|
+
};
|
|
835
|
+
try {
|
|
836
|
+
s();
|
|
837
|
+
for await (let e of i) s(), yield e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
838
|
+
} finally {
|
|
839
|
+
o && clearTimeout(o), i.destroy();
|
|
840
|
+
}
|
|
841
|
+
})(), vo = {
|
|
842
|
+
get: async () => void 0,
|
|
843
|
+
set: async () => {},
|
|
844
|
+
setWithTags: async () => {},
|
|
845
|
+
remove: async () => !1,
|
|
846
|
+
has: async () => !1,
|
|
847
|
+
clear: async () => {},
|
|
848
|
+
invalidateTag: async () => 0,
|
|
849
|
+
wrap: async (e, t, n) => n()
|
|
850
|
+
}, yo = async (e) => {
|
|
851
|
+
Ne(e.appProcedures ?? e.discovered, {
|
|
852
|
+
defaultDeny: e.security?.defaultDeny ?? !0,
|
|
853
|
+
commandHint: "`voltro serve`"
|
|
854
|
+
}), fi({
|
|
855
|
+
dataStore: e.store,
|
|
856
|
+
schemaRegistry: e.schemaRegistry
|
|
857
|
+
});
|
|
858
|
+
let t = (e.discovered.budgets?.length ?? 0) > 0, n, r = new vr({
|
|
859
|
+
crdtColumnsOf: (t) => e.schemaRegistry.crdtColumns(t),
|
|
860
|
+
store: e.store,
|
|
861
|
+
...e.snapshotCache ? { cache: e.snapshotCache } : {},
|
|
862
|
+
...e.reactive === void 0 ? {} : { reactive: e.reactive },
|
|
863
|
+
...t ? { recordCost: (e) => n?.record(e) } : {},
|
|
864
|
+
recordDelivery: (e) => Y({
|
|
865
|
+
label: e.label,
|
|
866
|
+
kind: e.kind,
|
|
867
|
+
durationMs: e.durationMs,
|
|
868
|
+
rowCount: e.rowCount
|
|
869
|
+
})
|
|
870
|
+
}), i = e.cache ?? vo, a = e.kv ?? ai, o, s = () => void 0, u, d, f, ee, te, ne, h, g = L({ scope: "voltro:workflow" }), ie = L({ scope: "voltro:schedule" }), ae = Et({
|
|
871
|
+
store: e.store,
|
|
872
|
+
warn: (e, t) => g.warn(e, t)
|
|
873
|
+
}), oe = ae.remember, ce = ae.resolve, de = fe({
|
|
874
|
+
authority: e.authority,
|
|
875
|
+
getStore: () => e.store
|
|
876
|
+
}), v = (e.discovered.workflows?.length ?? 0) > 0 ? Jr(() => o) : void 0, ve = (e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.eventTriggers?.length ?? 0) > 0, ye = ve || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster", Se = e.tenantIsolation === "namespace", we = (e.log ?? L({ scope: "voltro:serve" })).child("webhooks"), Te, Ee, x = e.discovered.webhooks;
|
|
877
|
+
if (x && x.outgoing.length > 0 && e.workflowEngineLayer !== void 0) {
|
|
878
|
+
e.workflowEngineLayer;
|
|
879
|
+
let t = Xe({
|
|
880
|
+
store: e.store,
|
|
881
|
+
schemaRegistry: e.schemaRegistry,
|
|
882
|
+
cache: i,
|
|
883
|
+
kv: a
|
|
884
|
+
}), n = x.outgoing.map((e) => e.descriptor);
|
|
885
|
+
Ee = Vi.toLayer(Ri(t, { events: n })), Te = zi(t, async (e) => {
|
|
886
|
+
let t = f;
|
|
887
|
+
if (t === void 0) {
|
|
888
|
+
we.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.", {
|
|
889
|
+
deliveryId: e.deliveryId,
|
|
890
|
+
targetId: e.targetId
|
|
891
|
+
});
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
t.runPromise(Vi.execute(e)).catch((t) => {
|
|
895
|
+
we.error("deliverWebhook workflow crashed", {
|
|
896
|
+
deliveryId: e.deliveryId,
|
|
897
|
+
targetId: e.targetId
|
|
898
|
+
}, t);
|
|
899
|
+
});
|
|
900
|
+
}, { events: n });
|
|
901
|
+
}
|
|
902
|
+
let De = /* @__PURE__ */ new Map();
|
|
903
|
+
if (x) for (let e of x.incoming) {
|
|
904
|
+
let t = e.descriptor.path ?? Bi(e.descriptor.id), n = `VOLTRO_WEBHOOK_SECRET_${e.descriptor.id.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`, r = Ui(e.descriptor, {
|
|
905
|
+
resolveSecret: async () => process.env[n] ?? null,
|
|
906
|
+
resolveWorkflows: () => v === void 0 ? void 0 : ri(v, {
|
|
907
|
+
traceId: `incoming:${e.descriptor.id}`,
|
|
908
|
+
source: `incoming:${e.descriptor.id}`
|
|
909
|
+
}),
|
|
910
|
+
log: (e) => {
|
|
911
|
+
let t = {
|
|
912
|
+
webhookId: e.webhookId,
|
|
913
|
+
status: e.status,
|
|
914
|
+
signatureOk: String(e.signatureOk),
|
|
915
|
+
idempotency: e.idempotency,
|
|
916
|
+
durationMs: e.durationMs
|
|
917
|
+
};
|
|
918
|
+
e.status >= 500 ? we.error("incoming delivery failed", t) : e.status >= 400 ? we.warn("incoming delivery rejected", t) : we.info("incoming delivery handled", t);
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
De.set(t, { handle: r });
|
|
922
|
+
}
|
|
923
|
+
Lr(), si((t) => Rr(e.store, t.subjectId, t.resourceType, t.resourceId)) || L({ scope: "voltro:serve" }).info("policy guards: using the app-registered tuple source");
|
|
924
|
+
let ke = [], Ae = [...e.discovered.outboxHandlers ?? [], ...wn((x?.outgoing.length ?? 0) + (x?.incoming.length ?? 0) + (x?.providers.length ?? 0), []) ? [{
|
|
925
|
+
file: "<framework>/webhooks",
|
|
926
|
+
id: "voltro-webhook-emit",
|
|
927
|
+
definition: Hi(() => Te)
|
|
928
|
+
}] : []], je = Ae.length > 0 ? l({
|
|
929
|
+
handlers: Ae,
|
|
930
|
+
store: e.store,
|
|
931
|
+
log: (e.log ?? L({ scope: "voltro:serve" })).child("outbox"),
|
|
932
|
+
onChange: (t) => e.store.onChange((e) => t({
|
|
933
|
+
table: e.table,
|
|
934
|
+
op: e.op
|
|
935
|
+
})),
|
|
936
|
+
onShutdown: (e) => {
|
|
937
|
+
ke.push(e);
|
|
938
|
+
}
|
|
939
|
+
}) : void 0, S = Fe({
|
|
940
|
+
definitions: (e.discovered.connections ?? []).map((e) => e.definition),
|
|
941
|
+
store: e.store,
|
|
942
|
+
publicUrl: w(e.port ?? 4e3),
|
|
943
|
+
log: (e.log ?? L({ scope: "voltro:serve" })).child("connections")
|
|
944
|
+
});
|
|
945
|
+
me({
|
|
946
|
+
events: e.discovered.events ?? [],
|
|
947
|
+
rpcTags: [
|
|
948
|
+
...e.discovered.queries.map((e) => e.descriptor.name),
|
|
949
|
+
...e.discovered.mutations.map((e) => e.descriptor.name),
|
|
950
|
+
...e.discovered.actions.map((e) => e.descriptor.name),
|
|
951
|
+
...(e.discovered.streams ?? []).map((e) => e.descriptor.name)
|
|
952
|
+
]
|
|
953
|
+
});
|
|
954
|
+
let Pe = (e.log ?? L({ scope: "voltro:serve" })).child("events"), Le = e.broadcastNamespace ?? ze(e.plugins, void 0), Re = Lt(e.plugins, Le, Pe), Be = e.membership?.instanceId ?? process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, He = e.membership ?? Wt(e.plugins, {
|
|
955
|
+
instanceId: Be,
|
|
956
|
+
namespace: Le,
|
|
957
|
+
meta: { mode: "serve" },
|
|
958
|
+
logger: Pe
|
|
959
|
+
}), T = ge({
|
|
960
|
+
events: e.discovered.events ?? [],
|
|
961
|
+
origin: Be,
|
|
962
|
+
...Re.publishRemote === void 0 ? {} : { publishRemote: Re.publishRemote }
|
|
963
|
+
}), Ue = (e.discovered.events ?? []).length > 0 ? await Re.attach(T.bus) : null, Ge = Ft({
|
|
964
|
+
store: e.store,
|
|
965
|
+
schemaRegistry: e.schemaRegistry,
|
|
966
|
+
cache: i,
|
|
967
|
+
kv: a,
|
|
968
|
+
...Te === void 0 ? {} : { webhooksService: Te },
|
|
969
|
+
...v === void 0 ? {} : { workflowsProxy: v },
|
|
970
|
+
eventTriggers: e.discovered.eventTriggers ?? [],
|
|
971
|
+
namespaceIsolationOn: Se,
|
|
972
|
+
...e.ensureTenantProvisioned === void 0 ? {} : { ensureTenantProvisioned: e.ensureTenantProvisioned },
|
|
973
|
+
...e.resolveResidentStore === void 0 ? {} : { resolveResidentStore: e.resolveResidentStore },
|
|
974
|
+
...je === void 0 ? {} : { outbox: { nudge: je.nudge } },
|
|
975
|
+
...S.active ? { connections: { registry: S.registry } } : {},
|
|
976
|
+
eventBus: T.bus
|
|
977
|
+
}), Ke = G.succeed(hr, be), qe = G.succeed(yr, Oe), Je = G.succeed(gr, Ut), Ye = G.succeed(br, m), et = (t, n) => {
|
|
978
|
+
let r = t.pipe(W.provide(qr(n)));
|
|
979
|
+
return (e.baseLayer ? r.pipe(W.provide(e.baseLayer)) : r).pipe(W.provide(Ke)).pipe(W.provide(qe)).pipe(W.provide(Je)).pipe(W.provide(Ye));
|
|
980
|
+
}, nt = (e, t) => {
|
|
981
|
+
let n = et(e, t);
|
|
982
|
+
return ui(n);
|
|
983
|
+
}, rt = xn(), it = Ie(e.plugins ?? [], rt), at = _({
|
|
984
|
+
plugins: e.plugins ?? [],
|
|
985
|
+
metrics: rt,
|
|
986
|
+
log: e.log ?? L({ scope: "voltro:serve" })
|
|
987
|
+
}), ot = Tt(e.plugins ?? [], rt), st = e.security?.defaultDeny ?? !0, ct = Xr({
|
|
988
|
+
store: e.store,
|
|
989
|
+
defaultDeny: st,
|
|
990
|
+
recordMetric: (e) => {
|
|
991
|
+
rt.record(e);
|
|
992
|
+
},
|
|
993
|
+
...it.mutation === void 0 ? {} : { interceptor: it.mutation },
|
|
994
|
+
buildContext: (e, t, n) => Ge(e, t, n),
|
|
995
|
+
runEffect: nt,
|
|
996
|
+
undoCapture: $e((t) => e.schemaRegistry.crdtColumns(t))
|
|
997
|
+
}), ut = c();
|
|
998
|
+
{
|
|
999
|
+
let t = A();
|
|
1000
|
+
t !== void 0 && (e.log ?? L({ scope: "voltro:serve" })).info(t);
|
|
1001
|
+
}
|
|
1002
|
+
let dt = Ce({
|
|
1003
|
+
store: e.store,
|
|
1004
|
+
...e.approvals === void 0 ? {} : { defaultExpiryMs: e.approvals.defaultExpiryMs }
|
|
1005
|
+
}), ft = zr({
|
|
1006
|
+
defaultDeny: st,
|
|
1007
|
+
buildContext: (e) => Ge(e),
|
|
1008
|
+
runEffect: nt,
|
|
1009
|
+
recordMetric: (e) => {
|
|
1010
|
+
rt.record(e);
|
|
1011
|
+
},
|
|
1012
|
+
...it.action === void 0 ? {} : { interceptor: it.action }
|
|
1013
|
+
}), pt = Qr({
|
|
1014
|
+
tenantScopedTables: e.tenantScopedTables,
|
|
1015
|
+
softDeleteScopedTables: e.softDeleteScopedTables
|
|
1016
|
+
}), mt = {
|
|
1017
|
+
defaultDeny: st,
|
|
1018
|
+
buildContext: (e) => Ge(e),
|
|
1019
|
+
finalize: (e, t) => pt(e, t.subject),
|
|
1020
|
+
provideEffect: et,
|
|
1021
|
+
...it.query === void 0 ? {} : { interceptor: it.query }
|
|
1022
|
+
}, ht = q(mt), vt = Zr({
|
|
1023
|
+
...mt,
|
|
1024
|
+
queryRows: (t, n) => e.store.query(t).then((e) => _i(t.table, e, n.subject))
|
|
1025
|
+
}), yt = ei({
|
|
1026
|
+
...mt,
|
|
1027
|
+
subscribeDescriptor: (e, t, n) => r.subscribe(e, t, n),
|
|
1028
|
+
subscribeComputed: (e, t, n) => r.subscribeComputed(e, t, n)
|
|
1029
|
+
}), E = (e) => e.filter((e) => Hn(e.descriptor)), D = {};
|
|
1030
|
+
for (let t of [
|
|
1031
|
+
...E(e.discovered.queries),
|
|
1032
|
+
...ut.queries,
|
|
1033
|
+
...dt.queries,
|
|
1034
|
+
...S.queries
|
|
1035
|
+
]) D[t.descriptor.name] = (e) => K(ht(t, e), r, `subscription.${t.descriptor.name}`, void 0, void 0, $r(t, e));
|
|
1036
|
+
for (let t of [
|
|
1037
|
+
...E(e.discovered.mutations),
|
|
1038
|
+
...ut.mutations,
|
|
1039
|
+
...dt.mutations,
|
|
1040
|
+
...S.mutations
|
|
1041
|
+
]) {
|
|
1042
|
+
let n = Yr(t.descriptor.output);
|
|
1043
|
+
D[t.descriptor.name] = (r) => Dr(async (e, n) => ct(t, e, n), r, `mutation.${t.descriptor.name}`, n, e.idempotency, Gn(t.descriptor, "mutation"));
|
|
1044
|
+
}
|
|
1045
|
+
for (let t of [...E(e.discovered.actions), ...S.actions]) {
|
|
1046
|
+
let n = Yr(t.descriptor.output);
|
|
1047
|
+
D[t.descriptor.name] = (r) => Dr(async (e, n) => ft(t, e, n), r, `action.${t.descriptor.name}`, n, e.idempotency, Gn(t.descriptor, "action"));
|
|
1048
|
+
}
|
|
1049
|
+
let bt = () => `public-${Math.random().toString(36).slice(2, 10)}`, O = [
|
|
1050
|
+
...e.discovered.queries.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
1051
|
+
descriptor: e.descriptor,
|
|
1052
|
+
invoke: (t, n) => vt(e, t, {
|
|
1053
|
+
subject: n.subject,
|
|
1054
|
+
traceId: bt()
|
|
1055
|
+
}),
|
|
1056
|
+
subscribe: (t, n, r) => yt(e, t, {
|
|
1057
|
+
subject: n.subject,
|
|
1058
|
+
traceId: bt()
|
|
1059
|
+
}, r)
|
|
1060
|
+
})),
|
|
1061
|
+
...e.discovered.mutations.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
1062
|
+
descriptor: e.descriptor,
|
|
1063
|
+
invoke: (t, n) => ct(e, t, {
|
|
1064
|
+
subject: n.subject,
|
|
1065
|
+
traceId: bt()
|
|
1066
|
+
})
|
|
1067
|
+
})),
|
|
1068
|
+
...e.discovered.actions.filter((e) => e.descriptor.publicApi !== void 0).map((e) => ({
|
|
1069
|
+
descriptor: e.descriptor,
|
|
1070
|
+
invoke: (t, n) => ft(e, t, {
|
|
1071
|
+
subject: n.subject,
|
|
1072
|
+
traceId: bt()
|
|
1073
|
+
})
|
|
1074
|
+
}))
|
|
1075
|
+
], St = {
|
|
1076
|
+
candidates: b({
|
|
1077
|
+
queries: e.discovered.queries,
|
|
1078
|
+
mutations: e.discovered.mutations,
|
|
1079
|
+
actions: e.discovered.actions,
|
|
1080
|
+
descriptorOf: (e) => e.descriptor,
|
|
1081
|
+
runQuery: (e, t, n) => Promise.resolve(vt(e, t, n)),
|
|
1082
|
+
runMutation: (e, t, n) => Promise.resolve(ct(e, t, n)),
|
|
1083
|
+
runAction: (e, t, n) => Promise.resolve(ft(e, t, n))
|
|
1084
|
+
}),
|
|
1085
|
+
policy: e.agents?.tools ?? {},
|
|
1086
|
+
mcpEnabled: e.agents?.mcp === !0,
|
|
1087
|
+
resolveSubject: (t) => e.resolveSubject(t, -1).then((e) => e.subject)
|
|
1088
|
+
};
|
|
1089
|
+
if (e.grpc !== void 0) {
|
|
1090
|
+
let t = () => `grpc-${Math.random().toString(36).slice(2, 10)}`, n = [
|
|
1091
|
+
...e.discovered.queries.map((e) => ({
|
|
1092
|
+
tag: e.descriptor.name,
|
|
1093
|
+
kind: "query",
|
|
1094
|
+
input: e.descriptor.input,
|
|
1095
|
+
output: e.descriptor.output,
|
|
1096
|
+
invoke: (n, r, i) => vt(e, n, {
|
|
1097
|
+
subject: r.subject,
|
|
1098
|
+
traceId: t(),
|
|
1099
|
+
signal: i
|
|
1100
|
+
}),
|
|
1101
|
+
subscribe: (n, r, i) => yt(e, n, {
|
|
1102
|
+
subject: r.subject,
|
|
1103
|
+
traceId: t()
|
|
1104
|
+
}, i)
|
|
1105
|
+
})),
|
|
1106
|
+
...e.discovered.mutations.map((e) => ({
|
|
1107
|
+
tag: e.descriptor.name,
|
|
1108
|
+
kind: "mutation",
|
|
1109
|
+
input: e.descriptor.input,
|
|
1110
|
+
output: e.descriptor.output,
|
|
1111
|
+
invoke: (n, r, i) => ct(e, n, {
|
|
1112
|
+
subject: r.subject,
|
|
1113
|
+
traceId: t(),
|
|
1114
|
+
signal: i
|
|
1115
|
+
})
|
|
1116
|
+
})),
|
|
1117
|
+
...e.discovered.actions.map((e) => ({
|
|
1118
|
+
tag: e.descriptor.name,
|
|
1119
|
+
kind: "action",
|
|
1120
|
+
input: e.descriptor.input,
|
|
1121
|
+
output: e.descriptor.output,
|
|
1122
|
+
invoke: async (n, r, i) => ft(e, n, {
|
|
1123
|
+
subject: r.subject,
|
|
1124
|
+
traceId: t(),
|
|
1125
|
+
signal: i
|
|
1126
|
+
})
|
|
1127
|
+
}))
|
|
1128
|
+
];
|
|
1129
|
+
await We({
|
|
1130
|
+
config: e.grpc.config,
|
|
1131
|
+
candidates: n,
|
|
1132
|
+
resolveSubject: async (t) => {
|
|
1133
|
+
let { subject: n } = await e.resolveSubject(t, -1), r = n;
|
|
1134
|
+
return r.type === "anonymous" && r.credentialRejected !== void 0 ? null : {
|
|
1135
|
+
subject: n,
|
|
1136
|
+
anonymous: r.type === "anonymous"
|
|
1137
|
+
};
|
|
1138
|
+
},
|
|
1139
|
+
store: e.store,
|
|
1140
|
+
root: e.grpc.root,
|
|
1141
|
+
log: e.log ?? L({ scope: "voltro:serve" }),
|
|
1142
|
+
onShutdown: (e) => J(e)
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
let Ct = lt({
|
|
1146
|
+
...e.restRoutes === void 0 ? {} : { restRoutes: e.restRoutes },
|
|
1147
|
+
publicApiEntries: O,
|
|
1148
|
+
store: e.store,
|
|
1149
|
+
resolveSubject: (t) => e.resolveSubject(t, -1).then((e) => e.subject),
|
|
1150
|
+
...e.idempotency === void 0 ? {} : { idempotency: e.idempotency },
|
|
1151
|
+
log: e.log ?? L({ scope: "voltro:serve" })
|
|
1152
|
+
}), k = e.dataTransferSecret ?? process.env.VOLTRO_DATA_TRANSFER_SECRET, Dt = async (e, t) => {
|
|
1153
|
+
let { Readable: n } = await import("node:stream"), r = Ei(), i = Oi("storage", () => n.from(t()));
|
|
1154
|
+
await W.runPromise(Ai(r, e, i, { contentType: "application/octet-stream" }));
|
|
1155
|
+
}, Ot = k && k.length >= 16 ? [
|
|
1156
|
+
{
|
|
1157
|
+
method: "POST",
|
|
1158
|
+
path: sa,
|
|
1159
|
+
handle: Ba({
|
|
1160
|
+
secret: k,
|
|
1161
|
+
store: e.store,
|
|
1162
|
+
...e.dataTransferSnapshot ? { snapshot: e.dataTransferSnapshot } : {},
|
|
1163
|
+
...e.dataTransferDialect ? { dialect: e.dataTransferDialect } : {},
|
|
1164
|
+
assetSink: $i(Ei()),
|
|
1165
|
+
openArchive: (e) => _o(Ei(), e),
|
|
1166
|
+
refreshSubscriptions: (e) => {
|
|
1167
|
+
r.refreshAll(e);
|
|
1168
|
+
},
|
|
1169
|
+
putArchive: Dt,
|
|
1170
|
+
...e.dataTransferDialect ? { dialect: e.dataTransferDialect } : {}
|
|
1171
|
+
})
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
method: "POST",
|
|
1175
|
+
path: ca,
|
|
1176
|
+
handle: Ha({
|
|
1177
|
+
secret: k,
|
|
1178
|
+
store: e.store,
|
|
1179
|
+
...e.dataTransferSnapshot ? { snapshot: e.dataTransferSnapshot } : {},
|
|
1180
|
+
...e.dataTransferDialect ? { dialect: e.dataTransferDialect } : {},
|
|
1181
|
+
assetSink: $i(Ei()),
|
|
1182
|
+
openArchive: (e) => _o(Ei(), e),
|
|
1183
|
+
refreshSubscriptions: (e) => {
|
|
1184
|
+
r.refreshAll(e);
|
|
1185
|
+
},
|
|
1186
|
+
putArchive: Dt
|
|
1187
|
+
})
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
method: "GET",
|
|
1191
|
+
path: da,
|
|
1192
|
+
handle: go({
|
|
1193
|
+
secret: k,
|
|
1194
|
+
store: e.store
|
|
1195
|
+
})
|
|
1196
|
+
},
|
|
1197
|
+
{
|
|
1198
|
+
method: "GET",
|
|
1199
|
+
path: ua,
|
|
1200
|
+
handle: lo({ secret: k })
|
|
1201
|
+
},
|
|
1202
|
+
{
|
|
1203
|
+
method: "POST",
|
|
1204
|
+
path: la,
|
|
1205
|
+
handle: oo({
|
|
1206
|
+
secret: k,
|
|
1207
|
+
store: e.store,
|
|
1208
|
+
snapshot: e.dataTransferSnapshot ?? { tables: [] },
|
|
1209
|
+
dialect: e.dataTransferDialect ?? "memory",
|
|
1210
|
+
tenantTables: [...e.tenantScopedTables],
|
|
1211
|
+
loadProfile: Mn,
|
|
1212
|
+
assetSource: ea(Ei(), e.store),
|
|
1213
|
+
putArchive: Dt
|
|
1214
|
+
})
|
|
1215
|
+
}
|
|
1216
|
+
] : [], kt = [
|
|
1217
|
+
...e.httpRoutes ?? [],
|
|
1218
|
+
...Ct.httpRoutes,
|
|
1219
|
+
...Ot,
|
|
1220
|
+
...S.httpRoutes
|
|
1221
|
+
];
|
|
1222
|
+
Object.assign(D, T.handlers);
|
|
1223
|
+
for (let t of E(e.discovered.streams ?? [])) D[t.descriptor.name] = (n) => Or((r) => bi(r, (r) => {
|
|
1224
|
+
let i = Ge(r), a = t.executor(n, i);
|
|
1225
|
+
if (W.isEffect(a)) {
|
|
1226
|
+
let t = a.pipe(W.provide(qr(i.store)));
|
|
1227
|
+
return (e.baseLayer ? t.pipe(W.provide(e.baseLayer)) : t).pipe(W.provide(Ke)).pipe(W.provide(qe)).pipe(W.provide(Je)).pipe(W.provide(Ye));
|
|
1228
|
+
}
|
|
1229
|
+
return typeof a == "object" && a && typeof a.then == "function" ? W.promise(() => a) : a;
|
|
1230
|
+
}), `stream.${t.descriptor.name}`);
|
|
1231
|
+
for (let t of e.discovered.workflows ?? []) D[t.definition.name] = (e) => Dr(async (e, n) => {
|
|
1232
|
+
let r = n;
|
|
1233
|
+
return ri(v, {
|
|
1234
|
+
subject: r.subject,
|
|
1235
|
+
traceId: r.traceId,
|
|
1236
|
+
source: "workflow-rpc"
|
|
1237
|
+
}).start(t.definition.name, e);
|
|
1238
|
+
}, e, `workflow.${t.definition.name}`);
|
|
1239
|
+
ve && (D[Yn.name] = (e) => K(ht({
|
|
1240
|
+
descriptor: Yn,
|
|
1241
|
+
executor: (e) => {
|
|
1242
|
+
let t = e.id;
|
|
1243
|
+
return {
|
|
1244
|
+
table: "_voltro_workflow_runs",
|
|
1245
|
+
order: [{
|
|
1246
|
+
column: "startedAt",
|
|
1247
|
+
direction: "desc"
|
|
1248
|
+
}],
|
|
1249
|
+
predicate: sr(U("id", t), U("executionId", t)),
|
|
1250
|
+
take: 1,
|
|
1251
|
+
skip: void 0,
|
|
1252
|
+
projection: void 0
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
}, e), r, `subscription.${Yn.name}`), D[Zn.name] = (e) => K(ht({
|
|
1256
|
+
descriptor: Zn,
|
|
1257
|
+
executor: (e) => {
|
|
1258
|
+
let t = e, n = [...t.tag === void 0 ? [] : [U("tag", t.tag)], ...t.status === void 0 ? [] : [U("status", t.status)]], r = Number.isFinite(t.limit) && t.limit !== void 0 ? Math.min(Math.max(Math.floor(t.limit), 1), 500) : 100;
|
|
1259
|
+
return {
|
|
1260
|
+
table: "_voltro_workflow_runs",
|
|
1261
|
+
order: [{
|
|
1262
|
+
column: "startedAt",
|
|
1263
|
+
direction: "desc"
|
|
1264
|
+
}],
|
|
1265
|
+
predicate: n.length === 0 ? void 0 : n.length === 1 ? n[0] : nr(...n),
|
|
1266
|
+
take: r,
|
|
1267
|
+
skip: void 0,
|
|
1268
|
+
projection: void 0
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
}, e), r, `subscription.${Zn.name}`), D[Xn.name] = (e) => K(ht({
|
|
1272
|
+
descriptor: Xn,
|
|
1273
|
+
executor: (e) => {
|
|
1274
|
+
let t = e.runId;
|
|
1275
|
+
return {
|
|
1276
|
+
table: "_voltro_workflow_run_steps",
|
|
1277
|
+
order: [{
|
|
1278
|
+
column: "startedAt",
|
|
1279
|
+
direction: "asc"
|
|
1280
|
+
}],
|
|
1281
|
+
predicate: U("runId", t),
|
|
1282
|
+
take: 1e3,
|
|
1283
|
+
skip: void 0,
|
|
1284
|
+
projection: void 0
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
}, e), r, `subscription.${Xn.name}`), D[Jn.name] = (e) => K(ht({
|
|
1288
|
+
descriptor: Jn,
|
|
1289
|
+
executor: (e) => {
|
|
1290
|
+
let t = e.runId;
|
|
1291
|
+
return {
|
|
1292
|
+
table: "_voltro_workflow_run_events",
|
|
1293
|
+
order: [{
|
|
1294
|
+
column: "occurredAt",
|
|
1295
|
+
direction: "asc"
|
|
1296
|
+
}],
|
|
1297
|
+
predicate: U("runId", t),
|
|
1298
|
+
take: 1e3,
|
|
1299
|
+
skip: void 0,
|
|
1300
|
+
projection: void 0
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
}, e), r, `subscription.${Jn.name}`), D[B.name] = (e) => K(ht({
|
|
1304
|
+
descriptor: B,
|
|
1305
|
+
executor: (e) => {
|
|
1306
|
+
let t = e;
|
|
1307
|
+
return {
|
|
1308
|
+
table: "_voltro_workflow_events",
|
|
1309
|
+
order: [{
|
|
1310
|
+
column: "occurredAt",
|
|
1311
|
+
direction: "desc"
|
|
1312
|
+
}],
|
|
1313
|
+
predicate: t.name === void 0 ? void 0 : U("name", t.name),
|
|
1314
|
+
take: Math.max(1, Math.min(500, t.limit ?? 100)),
|
|
1315
|
+
skip: void 0,
|
|
1316
|
+
projection: void 0
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
}, e), r, `subscription.${B.name}`), D[V.name] = (e) => K(ht({
|
|
1320
|
+
descriptor: V,
|
|
1321
|
+
executor: (e) => {
|
|
1322
|
+
let t = e.eventId;
|
|
1323
|
+
return {
|
|
1324
|
+
table: "_voltro_workflow_event_deliveries",
|
|
1325
|
+
order: [{
|
|
1326
|
+
column: "createdAt",
|
|
1327
|
+
direction: "asc"
|
|
1328
|
+
}],
|
|
1329
|
+
predicate: U("eventId", t),
|
|
1330
|
+
take: 500,
|
|
1331
|
+
skip: void 0,
|
|
1332
|
+
projection: void 0
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
}, e), r, `subscription.${V.name}`), D[Kn.name] = (t) => Dr(async (t, n) => {
|
|
1336
|
+
let r = t;
|
|
1337
|
+
return await gt(e.store, n.subject, { executionId: r.executionId }), await v.cancel(r.workflowName, r.executionId), await zt(r.workflowName, r.executionId, "workflow.cancel"), { ok: !0 };
|
|
1338
|
+
}, t, `action.${Kn.name}`), D[qn.name] = (t) => Dr(async (t, n) => {
|
|
1339
|
+
let r = t;
|
|
1340
|
+
return await gt(e.store, n.subject, { executionId: r.executionId }), await v.resume(r.workflowName, r.executionId), { ok: !0 };
|
|
1341
|
+
}, t, `action.${qn.name}`), D[Qn.name] = (t) => Dr(async (t, n) => {
|
|
1342
|
+
let r = t;
|
|
1343
|
+
return await gt(e.store, n.subject, { id: r.id }), v.signal({ id: r.id }, r.signalName, r.payload);
|
|
1344
|
+
}, t, `action.${Qn.name}`), D[$n.name] = (t) => Dr(async (t, n) => {
|
|
1345
|
+
let r = t;
|
|
1346
|
+
return await gt(e.store, n.subject, { id: r.id }), v.update({ id: r.id }, r.updateName, r.payload, r.timeoutMs === void 0 ? void 0 : { timeoutMs: r.timeoutMs });
|
|
1347
|
+
}, t, `action.${$n.name}`));
|
|
1348
|
+
let At = [
|
|
1349
|
+
...E(e.discovered.queries).map((e) => z(e.descriptor)),
|
|
1350
|
+
...E(e.discovered.mutations).map((e) => Un(e.descriptor)),
|
|
1351
|
+
...E(e.discovered.actions).map((e) => R(e.descriptor)),
|
|
1352
|
+
...ut.queries.map((e) => z(e.descriptor)),
|
|
1353
|
+
...ut.mutations.map((e) => Un(e.descriptor)),
|
|
1354
|
+
...dt.queries.map((e) => z(e.descriptor)),
|
|
1355
|
+
...dt.mutations.map((e) => Un(e.descriptor)),
|
|
1356
|
+
...S.queries.map((e) => z(e.descriptor)),
|
|
1357
|
+
...S.mutations.map((e) => Un(e.descriptor)),
|
|
1358
|
+
...S.actions.map((e) => R(e.descriptor)),
|
|
1359
|
+
...E(e.discovered.streams ?? []).map((e) => Wn(e.descriptor)),
|
|
1360
|
+
...T.rpcs,
|
|
1361
|
+
...(e.discovered.workflows ?? []).map((e) => xi(e.definition)),
|
|
1362
|
+
...ve ? [
|
|
1363
|
+
z(Yn),
|
|
1364
|
+
z(Zn),
|
|
1365
|
+
z(Xn),
|
|
1366
|
+
z(Jn),
|
|
1367
|
+
z(B),
|
|
1368
|
+
z(V),
|
|
1369
|
+
R(Kn),
|
|
1370
|
+
R(qn),
|
|
1371
|
+
R(Qn),
|
|
1372
|
+
R($n)
|
|
1373
|
+
] : []
|
|
1374
|
+
], jt = Ti.make(...At).middleware(zn).middleware(Bn), Mt = Gr({ resolveSubject: ({ headers: t, clientId: n }) => e.resolveSubject(t, n) }), Nt = e.dormancyTenantId ?? _r, Pt = e.dormancy === "sleep" ? {
|
|
1375
|
+
register: (t, n, r) => ci(e.store, {
|
|
1376
|
+
tenantId: r ?? Nt,
|
|
1377
|
+
kind: "workflow",
|
|
1378
|
+
refId: t,
|
|
1379
|
+
wakeAt: n
|
|
1380
|
+
}),
|
|
1381
|
+
cancel: (t, n) => Ar(e.store, {
|
|
1382
|
+
tenantId: n ?? Nt,
|
|
1383
|
+
kind: "workflow",
|
|
1384
|
+
refId: t
|
|
1385
|
+
}).then(() => {})
|
|
1386
|
+
} : void 0, j = ye ? await import("@voltro/workflow") : void 0, M = j?.makeWorkflowRunRecorder({
|
|
1387
|
+
store: e.store,
|
|
1388
|
+
...e.workflowRecording === void 0 ? {} : { recording: e.workflowRecording },
|
|
1389
|
+
...Pt === void 0 ? {} : { wakeups: Pt }
|
|
1390
|
+
}), Rt = async (t, n) => {
|
|
1391
|
+
await j.closeWorkflowChildrenForParent({
|
|
1392
|
+
store: e.store,
|
|
1393
|
+
parentExecutionId: t,
|
|
1394
|
+
parentStatus: n,
|
|
1395
|
+
recorder: M,
|
|
1396
|
+
log: { warn: (e, t) => g.warn(e, t ?? {}) },
|
|
1397
|
+
interruptChild: async (t, n) => {
|
|
1398
|
+
let r = (e.discovered.workflows ?? []).find((e) => e.definition.name === t);
|
|
1399
|
+
if (!r) throw Error(`Unknown child workflow: ${t}`);
|
|
1400
|
+
if (!f) throw Error("Workflow runtime is not ready");
|
|
1401
|
+
await f.runPromise(r.definition.interrupt(n));
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
}, zt = async (t, n, r) => {
|
|
1405
|
+
let i = (await e.store.query({
|
|
1406
|
+
table: "_voltro_workflow_runs",
|
|
1407
|
+
order: [],
|
|
1408
|
+
predicate: U("executionId", n),
|
|
1409
|
+
projection: void 0,
|
|
1410
|
+
skip: void 0,
|
|
1411
|
+
take: 1
|
|
1412
|
+
}))[0];
|
|
1413
|
+
if (i === void 0) return;
|
|
1414
|
+
let a = await e.store.update("_voltro_workflow_runs", i.id, {
|
|
1415
|
+
status: "cancelled",
|
|
1416
|
+
cancelled: !0,
|
|
1417
|
+
completedAt: /* @__PURE__ */ new Date()
|
|
1418
|
+
}), o = i.subject?.tenantId ?? void 0;
|
|
1419
|
+
a && await M.recordEvent({
|
|
1420
|
+
runId: i.id,
|
|
1421
|
+
eventType: "run-cancelled",
|
|
1422
|
+
payload: {
|
|
1423
|
+
reason: r,
|
|
1424
|
+
workflowName: t,
|
|
1425
|
+
executionId: n,
|
|
1426
|
+
...o == null ? {} : { tenantId: o }
|
|
1427
|
+
}
|
|
1428
|
+
}), a && await Rt(n, "cancelled");
|
|
1429
|
+
}, Bt = [
|
|
1430
|
+
...ii(e.discovered.workflows ?? [], {
|
|
1431
|
+
buildContext: (t, n) => e.buildContextForWorkflow?.(t, n) ?? Ge({
|
|
1432
|
+
subject: t.subject,
|
|
1433
|
+
traceId: t.traceId
|
|
1434
|
+
}, e.store, void 0, `workflow:${n.workflowName}`, { parentExecutionId: n.executionId }),
|
|
1435
|
+
resolveStartContext: ce,
|
|
1436
|
+
...de === void 0 ? {} : { resolveAuthority: de }
|
|
1437
|
+
}, (t, n, r) => {
|
|
1438
|
+
let i = j.getWorkflowVersionMetadata(t.definition);
|
|
1439
|
+
return j.wrapWorkflowExecuteWithRunRecording({
|
|
1440
|
+
name: t.definition.name,
|
|
1441
|
+
store: e.store,
|
|
1442
|
+
subject: r.subject,
|
|
1443
|
+
source: r.source ?? null,
|
|
1444
|
+
traceId: r.traceId,
|
|
1445
|
+
workflowVersion: i.version,
|
|
1446
|
+
workflowCompatibleVersions: i.compatibleWith,
|
|
1447
|
+
workflowPatches: i.patches,
|
|
1448
|
+
parentExecutionId: r?.parentExecutionId ?? null,
|
|
1449
|
+
parentClosePolicy: r?.parentClosePolicy ?? null,
|
|
1450
|
+
onParentClose: ({ executionId: e, status: t }) => Rt(e, t),
|
|
1451
|
+
...It(t.definition),
|
|
1452
|
+
onTerminal: async ({ executionId: e }) => {
|
|
1453
|
+
await d?.gate.release(e);
|
|
1454
|
+
},
|
|
1455
|
+
recorder: M,
|
|
1456
|
+
pluginWorkflowStepLayer: ot,
|
|
1457
|
+
recordRun: oi
|
|
1458
|
+
}, n);
|
|
1459
|
+
}),
|
|
1460
|
+
...e.discovered.workflowWorkers ?? [],
|
|
1461
|
+
...Ee === void 0 ? [] : [Ee]
|
|
1462
|
+
], Vt = [...(e.discovered.workflows ?? []).map((e) => e.definition.name).filter(Boolean), ...Ee === void 0 ? [] : ["voltro.deliverWebhook"]], Ht = Bt.length > 0 ? G.mergeAll(...Bt) : G.empty;
|
|
1463
|
+
if (((e.discovered.workflows?.length ?? 0) > 0 || (e.discovered.workflowWorkers?.length ?? 0) > 0 || e.scheduleCoordination === "cluster" || Ee !== void 0) && e.workflowEngineLayer !== void 0) {
|
|
1464
|
+
let t = Ht.pipe(G.provideMerge(e.workflowEngineLayer));
|
|
1465
|
+
f = lr.make((e.baseLayer === void 0 ? t : t.pipe(G.provideMerge(e.baseLayer))).pipe(G.provideMerge(Rn({})))), await f.runPromise(W.void), (e.log ?? L({ scope: "voltro:serve" })).child("workflow").info(`workflow runtime ready — ${Vt.length} entity type(s) registered`, { entities: Vt });
|
|
1466
|
+
let n = await import("@voltro/workflow/cluster"), r = (e) => f.runPromise(n.redriveFailedRun(e)), i = (e) => f.runPromise(n.resumeRunFromStep(e));
|
|
1467
|
+
ne = await p({
|
|
1468
|
+
provider: Li(e.plugins ?? [])?.broadcast?.provider,
|
|
1469
|
+
crossReplica: Li(e.plugins ?? [])?.broadcast?.crossReplica ?? !1,
|
|
1470
|
+
namespace: Le,
|
|
1471
|
+
replicaId: crypto.randomUUID(),
|
|
1472
|
+
pollStorage: () => f.runPromise(n.pollWorkflowStorage),
|
|
1473
|
+
onChange: (t) => e.store.onChange((e) => t({
|
|
1474
|
+
table: e.table,
|
|
1475
|
+
op: e.op,
|
|
1476
|
+
...e.origin === void 0 ? {} : { origin: e.origin }
|
|
1477
|
+
})),
|
|
1478
|
+
log: (e.log ?? L({ scope: "voltro:serve" })).child("workflow")
|
|
1479
|
+
}), ee = async (t) => {
|
|
1480
|
+
let n = await C({
|
|
1481
|
+
store: e.store,
|
|
1482
|
+
workflows: e.discovered.workflows ?? [],
|
|
1483
|
+
runRedrive: r
|
|
1484
|
+
}, t.runId);
|
|
1485
|
+
return n.statusReset && await M.recordEvent({
|
|
1486
|
+
runId: t.runId,
|
|
1487
|
+
eventType: "run-redriven",
|
|
1488
|
+
payload: {
|
|
1489
|
+
reason: "inspect.redrive",
|
|
1490
|
+
activitiesReset: n.outcome.activitiesReset
|
|
1491
|
+
}
|
|
1492
|
+
}), {
|
|
1493
|
+
redriven: n.outcome.redriven,
|
|
1494
|
+
activitiesReset: n.outcome.activitiesReset,
|
|
1495
|
+
reason: n.outcome.reason
|
|
1496
|
+
};
|
|
1497
|
+
}, te = async (t) => {
|
|
1498
|
+
let n = await se({
|
|
1499
|
+
store: e.store,
|
|
1500
|
+
workflows: e.discovered.workflows ?? [],
|
|
1501
|
+
runResume: i
|
|
1502
|
+
}, t.runId, t.step);
|
|
1503
|
+
return n.statusReset && await M.recordEvent({
|
|
1504
|
+
runId: t.runId,
|
|
1505
|
+
eventType: "run-redriven",
|
|
1506
|
+
payload: {
|
|
1507
|
+
reason: "inspect.resume-from-step",
|
|
1508
|
+
step: n.stepName,
|
|
1509
|
+
activitiesReset: n.outcome.activitiesReset
|
|
1510
|
+
}
|
|
1511
|
+
}), {
|
|
1512
|
+
redriven: n.outcome.redriven,
|
|
1513
|
+
stepName: n.stepName,
|
|
1514
|
+
activitiesReset: n.outcome.activitiesReset,
|
|
1515
|
+
reason: n.outcome.reason
|
|
1516
|
+
};
|
|
1517
|
+
};
|
|
1518
|
+
let a = (e.scheduleCoordination ?? "single") === "advisoryLock" ? Br(e.store, e.scheduleReplicaId ?? `pid-${process.pid}`) : mi, c = Kr({
|
|
1519
|
+
coordinator: a,
|
|
1520
|
+
replicaId: e.scheduleReplicaId ?? `pid-${process.pid}`
|
|
1521
|
+
}), l = L({ scope: "voltro:flow-control" }), m = {
|
|
1522
|
+
info: (e, t) => {
|
|
1523
|
+
l.info(e, t);
|
|
1524
|
+
},
|
|
1525
|
+
warn: (e, t) => {
|
|
1526
|
+
l.warn(e, t);
|
|
1527
|
+
},
|
|
1528
|
+
error: (e, t) => {
|
|
1529
|
+
l.error(e, t ?? {});
|
|
1530
|
+
}
|
|
1531
|
+
}, h, re = () => {
|
|
1532
|
+
if (h !== void 0) return h;
|
|
1533
|
+
if (o !== void 0 && M !== void 0) return h = le({
|
|
1534
|
+
store: e.store,
|
|
1535
|
+
log: F,
|
|
1536
|
+
workflows: e.discovered.workflows ?? [],
|
|
1537
|
+
workflowsProxy: o,
|
|
1538
|
+
workflowRuntime: f,
|
|
1539
|
+
workflowRunRecorder: M,
|
|
1540
|
+
closeChildrenForParent: Rt
|
|
1541
|
+
}), h;
|
|
1542
|
+
};
|
|
1543
|
+
s = re, d = Ve({
|
|
1544
|
+
store: e.store,
|
|
1545
|
+
onChange: (t) => e.store.onChange((e) => t({
|
|
1546
|
+
table: e.table,
|
|
1547
|
+
op: e.op
|
|
1548
|
+
})),
|
|
1549
|
+
...e.scheduling === void 0 ? {} : {
|
|
1550
|
+
disarmWhenIdle: e.scheduling.disarmWhenIdle,
|
|
1551
|
+
drainIntervalMs: e.scheduling.admissionDrainMs,
|
|
1552
|
+
cancelSweepIntervalMs: e.scheduling.cancelSweepMs,
|
|
1553
|
+
stalenessSweepIntervalMs: e.scheduling.stalenessSweepMs
|
|
1554
|
+
},
|
|
1555
|
+
workflows: e.discovered.workflows ?? [],
|
|
1556
|
+
facade: () => o,
|
|
1557
|
+
cancelRunWithReason: re,
|
|
1558
|
+
recordRunEvent: () => M?.recordEvent,
|
|
1559
|
+
...e.workflowStaleness === void 0 ? {} : { staleness: e.workflowStaleness },
|
|
1560
|
+
...e.workflowSuspendSignalHintMs === void 0 ? {} : { suspendSignalHintMs: e.workflowSuspendSignalHintMs },
|
|
1561
|
+
scheduleCoordinated: c,
|
|
1562
|
+
onAbandoned: async (t) => {
|
|
1563
|
+
await _t({
|
|
1564
|
+
workflows: e.discovered.workflows ?? [],
|
|
1565
|
+
facade: () => o,
|
|
1566
|
+
log: m,
|
|
1567
|
+
...t
|
|
1568
|
+
});
|
|
1569
|
+
},
|
|
1570
|
+
log: m
|
|
1571
|
+
});
|
|
1572
|
+
let g = d;
|
|
1573
|
+
g !== void 0 && J(() => g.stop()), u = wt({
|
|
1574
|
+
store: e.store,
|
|
1575
|
+
onChange: (t) => e.store.onChange((e) => t({
|
|
1576
|
+
table: e.table,
|
|
1577
|
+
op: e.op
|
|
1578
|
+
})),
|
|
1579
|
+
...e.scheduling === void 0 ? {} : {
|
|
1580
|
+
disarmWhenIdle: e.scheduling.disarmWhenIdle,
|
|
1581
|
+
tickIntervalMs: e.scheduling.inferenceTickMs
|
|
1582
|
+
},
|
|
1583
|
+
enabled: (e.discovered.workflows?.length ?? 0) > 0,
|
|
1584
|
+
resumeSignal: () => f === void 0 || j === void 0 ? void 0 : async ({ executionId: t, workflowName: n, signalName: r, payload: i }) => {
|
|
1585
|
+
await f.runPromise(j.completeSuspendingSignal({
|
|
1586
|
+
store: e.store,
|
|
1587
|
+
target: tt(t, n),
|
|
1588
|
+
signalName: r,
|
|
1589
|
+
payload: i
|
|
1590
|
+
}));
|
|
1591
|
+
},
|
|
1592
|
+
runEffect: (e) => f.runPromise(e),
|
|
1593
|
+
scheduleCoordinated: c,
|
|
1594
|
+
log: m
|
|
1595
|
+
});
|
|
1596
|
+
let ie = u;
|
|
1597
|
+
ie !== void 0 && J(() => ie.stop()), o = (e.discovered.workflows?.length ?? 0) > 0 ? ni({
|
|
1598
|
+
workflows: e.discovered.workflows ?? [],
|
|
1599
|
+
runEffect: (e) => f.runPromise(e),
|
|
1600
|
+
onEnqueue: () => ne?.publishWake(),
|
|
1601
|
+
...g === void 0 ? {} : {
|
|
1602
|
+
admitStart: g.gate.admitStart,
|
|
1603
|
+
startPayloadSchema: g.gate.startPayloadSchema,
|
|
1604
|
+
parkDelayedStart: g.gate.parkDelayed
|
|
1605
|
+
},
|
|
1606
|
+
rememberStartContext: oe,
|
|
1607
|
+
signal: async (t, n, r) => {
|
|
1608
|
+
let i = await j.sendWorkflowSignal({
|
|
1609
|
+
store: e.store,
|
|
1610
|
+
recorder: M,
|
|
1611
|
+
target: t,
|
|
1612
|
+
signalName: n,
|
|
1613
|
+
payload: r
|
|
1614
|
+
});
|
|
1615
|
+
return await f.runPromise(j.completeSuspendingSignal({
|
|
1616
|
+
store: e.store,
|
|
1617
|
+
target: t,
|
|
1618
|
+
signalName: n,
|
|
1619
|
+
payload: r
|
|
1620
|
+
})).catch(() => {}), i;
|
|
1621
|
+
},
|
|
1622
|
+
update: (t, n, r, i) => j.sendWorkflowUpdate({
|
|
1623
|
+
store: e.store,
|
|
1624
|
+
recorder: M,
|
|
1625
|
+
target: t,
|
|
1626
|
+
updateName: n,
|
|
1627
|
+
payload: r,
|
|
1628
|
+
...i === void 0 ? {} : { options: i }
|
|
1629
|
+
}),
|
|
1630
|
+
listRuns: (t) => Me(e.store, t),
|
|
1631
|
+
retry: (t, n) => pe({
|
|
1632
|
+
store: e.store,
|
|
1633
|
+
workflows: e.discovered.workflows ?? [],
|
|
1634
|
+
runPromise: (e) => f.runPromise(e)
|
|
1635
|
+
}, t, n),
|
|
1636
|
+
redrive: (t) => C({
|
|
1637
|
+
store: e.store,
|
|
1638
|
+
workflows: e.discovered.workflows ?? [],
|
|
1639
|
+
runRedrive: r
|
|
1640
|
+
}, t).then((e) => e.outcome)
|
|
1641
|
+
}) : void 0;
|
|
1642
|
+
}
|
|
1643
|
+
let Gt = G.mergeAll(jt.toLayer(D), Mt), Kt = xt(D, e.discovered.queries.map((e) => e.descriptor.name), ve), qt = G.mergeAll(jt.toLayer(Kt), Mt), N = e.observability, Jt = await kr({
|
|
1644
|
+
...e.appName === void 0 ? {} : { serviceName: e.appName },
|
|
1645
|
+
...N && N.spanProcessors.length > 0 ? { extraSpanProcessors: N.spanProcessors } : {},
|
|
1646
|
+
...N && N.metricReaders.length > 0 ? { extraMetricReaders: N.metricReaders } : {},
|
|
1647
|
+
...N && Object.keys(N.resourceAttributes).length > 0 ? { resourceAttributes: N.resourceAttributes } : {},
|
|
1648
|
+
...N && N.sampler !== void 0 ? { sampler: N.sampler } : {}
|
|
1649
|
+
}), Yt = !1, Xt = e.store.ping ? () => e.store.ping().then(() => !0).catch(() => !1) : void 0, { server: P, shutdown: Zt } = hi({
|
|
1650
|
+
group: jt,
|
|
1651
|
+
handlersLayer: Gt,
|
|
1652
|
+
httpHandlersLayer: qt,
|
|
1653
|
+
port: e.port ?? 4e3,
|
|
1654
|
+
...e.host === void 0 ? {} : { host: e.host },
|
|
1655
|
+
path: e.path ?? "/ws",
|
|
1656
|
+
tracerLayer: Jt.layer,
|
|
1657
|
+
security: ue(e),
|
|
1658
|
+
...bn(e),
|
|
1659
|
+
...e.discovered.wsGateways !== void 0 && e.discovered.wsGateways.length > 0 ? { webSocketGateways: e.discovered.wsGateways } : {},
|
|
1660
|
+
resolveGatewaySubject: async (t) => {
|
|
1661
|
+
let n = await e.resolveSubject(t, -1);
|
|
1662
|
+
return n.subject.type === "anonymous" ? null : {
|
|
1663
|
+
subject: n.subject,
|
|
1664
|
+
...n.credentialExpiresAt === void 0 ? {} : { credentialExpiresAt: n.credentialExpiresAt * 1e3 }
|
|
1665
|
+
};
|
|
1666
|
+
},
|
|
1667
|
+
...at,
|
|
1668
|
+
healthCheck: {
|
|
1669
|
+
isReady: () => Yt,
|
|
1670
|
+
...Xt ? { ping: Xt } : {}
|
|
1671
|
+
},
|
|
1672
|
+
...kt.length > 0 ? { httpRoutes: kt } : {},
|
|
1673
|
+
...e.getStore === void 0 ? {} : { getStore: e.getStore },
|
|
1674
|
+
...De.size > 0 ? { webhookRoutes: De } : {},
|
|
1675
|
+
...e.inspectRoute === void 0 ? {} : { inspectRoute: e.inspectRoute }
|
|
1676
|
+
}), Qt = oa(P);
|
|
1677
|
+
if (await Er(P), (e.discovered.schedules?.length ?? 0) > 0) {
|
|
1678
|
+
let t = (e.scheduleCoordination ?? "single") === "advisoryLock" ? Br(e.store, e.scheduleReplicaId ?? `pid-${process.pid}`) : mi;
|
|
1679
|
+
h = await gi(e.discovered.schedules ?? [], {
|
|
1680
|
+
store: e.store,
|
|
1681
|
+
coordinator: t,
|
|
1682
|
+
defaultTrigger: e.scheduleDefaultTrigger ?? "self",
|
|
1683
|
+
replicaId: e.scheduleReplicaId ?? `pid-${process.pid}`,
|
|
1684
|
+
armSelf: e.scheduleArmSelf ?? !0,
|
|
1685
|
+
dormancy: e.dormancy ?? "always-on",
|
|
1686
|
+
...e.dormancyTenantId === void 0 ? {} : { dormancyTenantId: e.dormancyTenantId },
|
|
1687
|
+
buildContext: ({ traceId: t, scheduleName: n, subject: r }) => Ge({
|
|
1688
|
+
subject: r,
|
|
1689
|
+
traceId: t
|
|
1690
|
+
}, e.store, void 0, `schedule:${n}`),
|
|
1691
|
+
log: {
|
|
1692
|
+
info: (e, t) => {
|
|
1693
|
+
ie.info(e, t);
|
|
1694
|
+
},
|
|
1695
|
+
warn: (e, t) => {
|
|
1696
|
+
ie.warn(e, t);
|
|
1697
|
+
},
|
|
1698
|
+
error: (e, t) => {
|
|
1699
|
+
ie.error(e, t ?? {});
|
|
1700
|
+
},
|
|
1701
|
+
debug: () => {}
|
|
1702
|
+
},
|
|
1703
|
+
...e.scheduleFireInterceptor === void 0 ? {} : { interceptFire: e.scheduleFireInterceptor },
|
|
1704
|
+
...e.onScheduleRunEvent === void 0 ? {} : { onRunEvent: e.onScheduleRunEvent }
|
|
1705
|
+
}), e.onSchedulerReady?.(h);
|
|
1706
|
+
}
|
|
1707
|
+
let F = e.log ?? L({ scope: "voltro:serve" }), $t, en;
|
|
1708
|
+
if ((e.discovered.subscribers?.length ?? 0) > 0 && ($t = Qe(e.discovered.subscribers ?? [], e.store, F.child("subscribe"), e.schemaRegistry, T.bus)), (e.discovered.reactions?.length ?? 0) > 0) {
|
|
1709
|
+
let t = F.child("reaction"), n = async (n, r) => {
|
|
1710
|
+
if (n.kind === "workflow") {
|
|
1711
|
+
if (v === void 0) {
|
|
1712
|
+
t.warn("reaction workflow act skipped — no workflow engine in this app", { workflow: n.workflow });
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
let e = n.payload === void 0 ? r.new ?? r.old ?? {} : n.payload(r);
|
|
1716
|
+
await ri(v, {
|
|
1717
|
+
traceId: `reaction:${n.workflow}`,
|
|
1718
|
+
source: `reaction:${n.workflow}`
|
|
1719
|
+
}).start(n.workflow, e);
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
await _e(n.agent, r, {
|
|
1723
|
+
findAgentSend: (t) => e.discovered.actions.find((e) => e.descriptor.name === `${t}.send`),
|
|
1724
|
+
runAction: (e, t, n) => Promise.resolve(ft(e, t, n)),
|
|
1725
|
+
makeSubject: (e) => Vn(e),
|
|
1726
|
+
now: () => Date.now(),
|
|
1727
|
+
log: t
|
|
1728
|
+
});
|
|
1729
|
+
}, r = async (n, r) => {
|
|
1730
|
+
try {
|
|
1731
|
+
let { requireAiBudget: t } = await import("@voltro/ai");
|
|
1732
|
+
return (await W.runPromise(W.either(t(e.store, {
|
|
1733
|
+
tenantId: n,
|
|
1734
|
+
limitUsd: r
|
|
1735
|
+
}))))._tag === "Right";
|
|
1736
|
+
} catch (e) {
|
|
1737
|
+
return t.warn("reaction budget check failed — refusing the act", { tenantId: n }, e), !1;
|
|
1738
|
+
}
|
|
1739
|
+
}, i = Ze(e.store, { onError: (e) => t.warn("reaction: rate-slot claim failed; refusing the act", { cause: String(e) }) });
|
|
1740
|
+
en = he(e.discovered.reactions ?? [], e.store, {
|
|
1741
|
+
runAct: n,
|
|
1742
|
+
checkBudget: r,
|
|
1743
|
+
claimRateSlot: (e) => i.claim(e)
|
|
1744
|
+
}, t);
|
|
1745
|
+
}
|
|
1746
|
+
let tn;
|
|
1747
|
+
(e.discovered.aggregates?.length ?? 0) > 0 && (tn = await re({
|
|
1748
|
+
discovered: e.discovered.aggregates ?? [],
|
|
1749
|
+
store: e.store,
|
|
1750
|
+
log: F.child("aggregate"),
|
|
1751
|
+
...e.analytics === void 0 ? {} : { analytics: e.analytics },
|
|
1752
|
+
...e.aggregateStorage === void 0 ? {} : { storage: e.aggregateStorage },
|
|
1753
|
+
...e.aggregateCoordinator === void 0 ? {} : { coordinator: e.aggregateCoordinator }
|
|
1754
|
+
}), Ke = G.succeed(hr, tn.registry));
|
|
1755
|
+
let nn;
|
|
1756
|
+
(e.discovered.expectations?.length ?? 0) > 0 && (nn = Cr({
|
|
1757
|
+
discovered: e.discovered.expectations ?? [],
|
|
1758
|
+
store: e.store,
|
|
1759
|
+
log: F.child("expectation")
|
|
1760
|
+
}), qe = G.succeed(yr, nn.registry)), (e.discovered.budgets?.length ?? 0) > 0 && (n = Tr({
|
|
1761
|
+
discovered: e.discovered.budgets ?? [],
|
|
1762
|
+
log: F.child("finops")
|
|
1763
|
+
}), Je = G.succeed(gr, n.registry));
|
|
1764
|
+
let rn;
|
|
1765
|
+
return (e.discovered.experiments?.length ?? 0) > 0 && (rn = wr({
|
|
1766
|
+
discovered: e.discovered.experiments ?? [],
|
|
1767
|
+
store: e.store,
|
|
1768
|
+
log: F.child("experiment")
|
|
1769
|
+
}), Ye = G.succeed(br, rn.registry)), Yt = !0, e.bootTiming?.mark("ready"), {
|
|
1770
|
+
dispatcher: r,
|
|
1771
|
+
server: P,
|
|
1772
|
+
scheduler: h,
|
|
1773
|
+
eventsSnapshot: xe(T.bus, T.declared),
|
|
1774
|
+
membersSnapshot: () => ({
|
|
1775
|
+
members: He.membership.list(),
|
|
1776
|
+
capturedAt: Date.now()
|
|
1777
|
+
}),
|
|
1778
|
+
agentTools: () => St,
|
|
1779
|
+
rpcMetrics: () => rt,
|
|
1780
|
+
webhooksService: () => Te,
|
|
1781
|
+
runCanceller: () => s(),
|
|
1782
|
+
flowControlHealth: () => d?.cancelHealth(),
|
|
1783
|
+
inferenceHealth: () => u?.health(),
|
|
1784
|
+
workflowWriteActions: () => v === void 0 || M === void 0 ? void 0 : y({
|
|
1785
|
+
store: e.store,
|
|
1786
|
+
log: F,
|
|
1787
|
+
workflows: e.discovered.workflows ?? [],
|
|
1788
|
+
workflowsProxy: o,
|
|
1789
|
+
workflowRuntime: f,
|
|
1790
|
+
workflowRunRecorder: M,
|
|
1791
|
+
closeChildrenForParent: Rt
|
|
1792
|
+
}),
|
|
1793
|
+
redriveWorkflowRun: (e) => ee ? ee(e) : Promise.reject(/* @__PURE__ */ Error("redrive: this app registers no workflows")),
|
|
1794
|
+
resumeWorkflowRunFromStep: (e) => te ? te(e) : Promise.reject(/* @__PURE__ */ Error("resume-from-step: this app registers no workflows")),
|
|
1795
|
+
close: async () => {
|
|
1796
|
+
Yt = !1, await Qt.drainRequests();
|
|
1797
|
+
for (let e of ke) try {
|
|
1798
|
+
await e();
|
|
1799
|
+
} catch (e) {
|
|
1800
|
+
F.warn("serve: teardown step failed", {}, e);
|
|
1801
|
+
}
|
|
1802
|
+
await Ue?.detach(), await He.detach(), tn?.detach(), nn?.detach(), n?.detach(), rn?.detach(), en?.(), $t?.(), await h?.shutdown(), r.close(), await ne?.detach(), await f?.dispose(), await Zt(), await Qt.finish();
|
|
1803
|
+
}
|
|
1804
|
+
};
|
|
1805
|
+
}, $ = L({ scope: "voltro:serve" }), bo = (e, t, n) => (e === "production" || e === "staging") && t !== "memory" && n !== "0", xo = N, So = async (e) => {
|
|
1806
|
+
let t = On(process.cwd());
|
|
1807
|
+
if (In(t)) {
|
|
1808
|
+
let n;
|
|
1809
|
+
try {
|
|
1810
|
+
let e = await import(Ln(t).href);
|
|
1811
|
+
typeof e.runServe == "function" ? n = e.runServe : $.warn("serve bundle has no runServe export — using the standard serve path");
|
|
1812
|
+
} catch (e) {
|
|
1813
|
+
$.warn("serve bundle failed to load — using the standard serve path", {}, e);
|
|
1814
|
+
}
|
|
1815
|
+
if (n) return $.info("serve: booting from the precompiled serve bundle"), n(e);
|
|
1816
|
+
}
|
|
1817
|
+
return Co(e);
|
|
1818
|
+
}, Co = async (c) => {
|
|
1819
|
+
let l = kn();
|
|
1820
|
+
e("serve");
|
|
1821
|
+
try {
|
|
1822
|
+
Ni();
|
|
1823
|
+
} catch (e) {
|
|
1824
|
+
throw i(e instanceof Error ? e.message : String(e));
|
|
1825
|
+
}
|
|
1826
|
+
let p = process.cwd(), m = await Ke(p), re = Jt({
|
|
1827
|
+
kind: "api",
|
|
1828
|
+
configPort: m?.port,
|
|
1829
|
+
env: process.env,
|
|
1830
|
+
flagPort: xo(c, "--port")
|
|
1831
|
+
});
|
|
1832
|
+
for (let e of re.warnings) $.warn(e);
|
|
1833
|
+
let se = re.port;
|
|
1834
|
+
di(li(m?.secrets)), await Xt({
|
|
1835
|
+
rawEnv: m?.env,
|
|
1836
|
+
appType: "api",
|
|
1837
|
+
root: p,
|
|
1838
|
+
log: $,
|
|
1839
|
+
generateTypes: !1
|
|
1840
|
+
}), l.mark("config");
|
|
1841
|
+
let _ = (process.env.DB_DIALECT ?? m?.store ?? "memory").toLowerCase(), le = (_ === "mariadb" || _ === "postgres" || _ === "mssql") && (process.env.CDC ?? "1") !== "0", fe = _ === "mariadb" ? "mariadb" : _ === "mssql" ? "mssql" : void 0, pe = Dn(p);
|
|
1842
|
+
if (!r() && In(pe)) try {
|
|
1843
|
+
let e = await import(Ln(pe).href);
|
|
1844
|
+
if (e.modules) {
|
|
1845
|
+
let t = {};
|
|
1846
|
+
for (let [n, r] of Object.entries(e.modules)) t[Pn(p, n)] = r;
|
|
1847
|
+
n(t), $.info("precompiled api bundle loaded", { modules: Object.keys(t).length });
|
|
1848
|
+
}
|
|
1849
|
+
} catch (e) {
|
|
1850
|
+
$.warn("precompiled api bundle failed to load — falling back to source", {}, e);
|
|
1851
|
+
}
|
|
1852
|
+
let y = await Ct(p), b = await Pt(y, { cdc: le && fe !== void 0 }), me = ee(b);
|
|
1853
|
+
{
|
|
1854
|
+
Ye({
|
|
1855
|
+
plugins: m?.plugins ?? [],
|
|
1856
|
+
queries: b.queries,
|
|
1857
|
+
mutations: b.mutations,
|
|
1858
|
+
actions: b.actions,
|
|
1859
|
+
streams: b.streams,
|
|
1860
|
+
log: $
|
|
1861
|
+
});
|
|
1862
|
+
let e = v(b.serverOnlyLeaks, ce(process.env, "strict"), Nr, "`voltro serve`");
|
|
1863
|
+
if (e.action === "fail") throw i(e.message ?? "");
|
|
1864
|
+
e.action === "warn" && $.warn(e.message ?? "");
|
|
1865
|
+
}
|
|
1866
|
+
let he = y.filter((e) => En.test(e)), ge = he.length > 0 ? await Tn(he, $.child("webhooks")) : {
|
|
1867
|
+
outgoing: [],
|
|
1868
|
+
incoming: [],
|
|
1869
|
+
providers: []
|
|
1870
|
+
}, _e = Cn(b.events), be = ge.outgoing.length + ge.incoming.length + ge.providers.length + _e.length === 0 ? void 0 : {
|
|
1871
|
+
...ge,
|
|
1872
|
+
outgoing: [...ge.outgoing, ..._e]
|
|
1873
|
+
}, xe = sn({
|
|
1874
|
+
nodeEnv: process.env.NODE_ENV,
|
|
1875
|
+
cdcDialect: fe,
|
|
1876
|
+
declared: m?.schema
|
|
1877
|
+
}), Ce = cn({
|
|
1878
|
+
gates: xe,
|
|
1879
|
+
runtime: {
|
|
1880
|
+
traces: ae(),
|
|
1881
|
+
undo: vi()
|
|
1882
|
+
}
|
|
1883
|
+
});
|
|
1884
|
+
if (Ce !== void 0) throw i(`serve: ${Ce}`);
|
|
1885
|
+
let Oe = on({
|
|
1886
|
+
mix: b.featureMix,
|
|
1887
|
+
plugins: m?.plugins ?? [],
|
|
1888
|
+
gates: xe,
|
|
1889
|
+
...fe ? { cdcDialect: fe } : {}
|
|
1890
|
+
}), Me = m?.analytics !== void 0 && m.analytics.kind !== "noop" && _ !== "memory" ? (await P(_)).makeSqlLayer(O()) : void 0, Ne = await D({
|
|
1891
|
+
spec: m?.analytics,
|
|
1892
|
+
sqlLayer: Me,
|
|
1893
|
+
log: $
|
|
1894
|
+
}), C = (() => {
|
|
1895
|
+
let e = new Set(b.tables.map((e) => e.tableName)), t = [...b.tables];
|
|
1896
|
+
for (let n of [...Oe, ...Ne.tables]) e.has(n.tableName) || (e.add(n.tableName), t.push(n));
|
|
1897
|
+
return t;
|
|
1898
|
+
})();
|
|
1899
|
+
for (let e of C) or(e);
|
|
1900
|
+
{
|
|
1901
|
+
let e = Pr(yi(zt(b), Ae(C)));
|
|
1902
|
+
e !== void 0 && $.warn(e);
|
|
1903
|
+
}
|
|
1904
|
+
let Fe = (process.env.NODE_ENV ?? "").toLowerCase();
|
|
1905
|
+
if (bo(Fe, _, process.env.VOLTRO_AUTO_MIGRATE)) {
|
|
1906
|
+
let e = (await P(_)).makeSqlLayer(O()), t = await W.runPromise(ur.SqlClient.pipe(W.flatMap((e) => pr(e, p)), W.provide(e), W.catchAll(() => W.succeed([]))));
|
|
1907
|
+
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));
|
|
1908
|
+
let n = await W.runPromise(ur.SqlClient.pipe(W.flatMap((e) => mr(e, C, {
|
|
1909
|
+
appliedBy: `serve:${Fe}`,
|
|
1910
|
+
environment: "prod",
|
|
1911
|
+
dialectId: _
|
|
1912
|
+
})), W.provide(e)));
|
|
1913
|
+
n.kind === "prod-mismatch" && ($.error(fr(n, _)), $.error(ln({
|
|
1914
|
+
gates: xe,
|
|
1915
|
+
nodeEnv: process.env.NODE_ENV,
|
|
1916
|
+
cdcDialect: fe,
|
|
1917
|
+
declared: m?.schema
|
|
1918
|
+
})), $.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(fr(n, _));
|
|
1919
|
+
}
|
|
1920
|
+
await en({
|
|
1921
|
+
dialectId: _,
|
|
1922
|
+
tables: C,
|
|
1923
|
+
mode: F(m?.reactiveTriggers),
|
|
1924
|
+
lockSchema: O().schema,
|
|
1925
|
+
makeLayer: async () => (await P(_)).makeSqlLayer(O()),
|
|
1926
|
+
log: {
|
|
1927
|
+
info: (e, t) => $.info(e, t ?? {}),
|
|
1928
|
+
warn: (e, t) => $.warn(e, t ?? {})
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
let Ie = ti(C);
|
|
1932
|
+
l.mark("discover");
|
|
1933
|
+
let w = await ct(m, void 0);
|
|
1934
|
+
{
|
|
1935
|
+
let e = await s(w);
|
|
1936
|
+
if (e !== void 0) throw i(`serve: ${e}`);
|
|
1937
|
+
}
|
|
1938
|
+
let Ve = Si(w, _);
|
|
1939
|
+
for (let e of j({
|
|
1940
|
+
dialect: String(m?.store ?? process.env.DB_DIALECT ?? "postgres"),
|
|
1941
|
+
changeStrategy: (process.env.CDC ?? "1") === "0" ? "inline" : "cdc",
|
|
1942
|
+
dbUrl: process.env.DB_URL,
|
|
1943
|
+
crossReplicaBus: Li(m?.plugins ?? [])?.broadcast.crossReplica === !0,
|
|
1944
|
+
tables: b.tables.map((e) => ({
|
|
1945
|
+
tableName: e.tableName,
|
|
1946
|
+
isReactive: e.isReactive === !0
|
|
1947
|
+
})),
|
|
1948
|
+
querySources: b.queries.flatMap((e) => {
|
|
1949
|
+
let t = e.descriptor.source;
|
|
1950
|
+
return t === void 0 ? [] : typeof t == "string" ? [t] : [...t];
|
|
1951
|
+
})
|
|
1952
|
+
})) e.level === "warn" ? $.warn(e.message) : $.info(e.message);
|
|
1953
|
+
{
|
|
1954
|
+
let e = rt({
|
|
1955
|
+
tables: tr().map((e) => ({ tableName: e.tableName })),
|
|
1956
|
+
queries: b.queries.map((e) => ({
|
|
1957
|
+
name: e.descriptor.name,
|
|
1958
|
+
source: e.descriptor.source
|
|
1959
|
+
}))
|
|
1960
|
+
}), t = Be(e);
|
|
1961
|
+
t !== void 0 && $.warn(t);
|
|
1962
|
+
}
|
|
1963
|
+
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);
|
|
1964
|
+
let { service: We, invalidationBus: Xe, snapshotCache: Ze, cache: Qe, semantic: $e, evictSource: tt, backend: lt, stats: gt, dispose: _t } = await ot({
|
|
1965
|
+
env: process.env,
|
|
1966
|
+
semantic: m?.cacheSemantic ?? !1
|
|
1967
|
+
});
|
|
1968
|
+
$e !== void 0 && $.info("semantic cache enabled — reactive eviction on live writes"), $.info(`cache backend resolved: ${lt}` + (lt === "redis" ? ` (driver ${process.env.CACHE_REDIS_DRIVER ?? "resp"})` : " — in-process, not cross-instance")), w.onChange((e) => {
|
|
1969
|
+
if (W.runFork(Xe.publish(e.table)), tt !== void 0) {
|
|
1970
|
+
let t = (e.new ?? e.old)?.id;
|
|
1971
|
+
tt({
|
|
1972
|
+
table: e.table,
|
|
1973
|
+
op: e.op,
|
|
1974
|
+
...t === void 0 ? {} : { id: t }
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
}), 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);
|
|
1978
|
+
let { kv: xt, service: wt } = await Wr({ store: w });
|
|
1979
|
+
ye({
|
|
1980
|
+
log: $,
|
|
1981
|
+
max: Qt(),
|
|
1982
|
+
outOfPool: h(_, (process.env.CDC ?? "1") !== "0"),
|
|
1983
|
+
readPools: t.replicationSnapshot()?.replicaCount ?? 0,
|
|
1984
|
+
always: !0
|
|
1985
|
+
}), l.mark("store");
|
|
1986
|
+
let Tt = Sr({
|
|
1987
|
+
store: w,
|
|
1988
|
+
sink: Ne.sink,
|
|
1989
|
+
log: $
|
|
1990
|
+
}), Et = yt({
|
|
1991
|
+
store: w,
|
|
1992
|
+
dialect: _,
|
|
1993
|
+
log: { info: (e) => $.info(e) }
|
|
1994
|
+
}), A = m?.plugins ?? [], Ft = process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, It, Lt;
|
|
1995
|
+
_ !== "memory" && (It = lr.make((await P(_)).makeSqlLayer(O()).pipe(G.provideMerge(Rn({})))), Lt = await It.runPromise(ur.SqlClient));
|
|
1996
|
+
let Ut = [
|
|
1997
|
+
"postgres",
|
|
1998
|
+
"mariadb",
|
|
1999
|
+
"mysql",
|
|
2000
|
+
"mssql"
|
|
2001
|
+
].includes(_) ? Br(w, Ft, $) : mi, N = Gt(m?.scheduling), bn = Kr({
|
|
2002
|
+
maxIdleIntervalMs: N.pollCeilingMs,
|
|
2003
|
+
coordinator: Ut,
|
|
2004
|
+
replicaId: Ft,
|
|
2005
|
+
log: $
|
|
2006
|
+
}), wn = [], On = process.env.POD_NAME ?? process.env.HOSTNAME ?? `serve-${process.pid}`, An = Li(m?.plugins ?? [])?.broadcast?.provider, jn = ze(m?.plugins, m?.name ?? Nn(p));
|
|
2007
|
+
{
|
|
2008
|
+
let e = nt(m?.plugins, m?.name ?? Nn(p));
|
|
2009
|
+
e !== void 0 && $.warn(e);
|
|
2010
|
+
}
|
|
2011
|
+
let Mn = Wt(m?.plugins, {
|
|
2012
|
+
instanceId: On,
|
|
2013
|
+
namespace: jn,
|
|
2014
|
+
meta: { mode: "serve" },
|
|
2015
|
+
logger: $
|
|
2016
|
+
}), I = yn({
|
|
2017
|
+
mode: "serve",
|
|
2018
|
+
dialect: _,
|
|
2019
|
+
...An === void 0 ? {} : { provider: An },
|
|
2020
|
+
logger: $
|
|
2021
|
+
});
|
|
2022
|
+
J(async () => {
|
|
2023
|
+
await I.stop();
|
|
2024
|
+
}), k(m?.reactive);
|
|
2025
|
+
let Fn = {
|
|
2026
|
+
...Lt ? { sql: Lt } : {},
|
|
2027
|
+
instanceId: On,
|
|
2028
|
+
membership: Mn.membership,
|
|
2029
|
+
...An === void 0 ? {} : { broadcast: An },
|
|
2030
|
+
broadcastChannels: { presence: Ii(jn, "presence") },
|
|
2031
|
+
scheduleCoordinated: (e, t, n) => {
|
|
2032
|
+
let r = bn(e, t, n);
|
|
2033
|
+
return wn.push(r), r;
|
|
2034
|
+
}
|
|
2035
|
+
};
|
|
2036
|
+
for (let e of A) e.bindDataStore?.(Ve, Fn);
|
|
2037
|
+
dt({
|
|
2038
|
+
store: w,
|
|
2039
|
+
...u(),
|
|
2040
|
+
log: $
|
|
2041
|
+
});
|
|
2042
|
+
let zn = A.filter((e) => typeof e.onChangeEvent == "function");
|
|
2043
|
+
if (zn.length > 0) {
|
|
2044
|
+
let e = w.changeScope ?? "local";
|
|
2045
|
+
w.onChange((t) => {
|
|
2046
|
+
let n = oe(t, e);
|
|
2047
|
+
for (let e of zn) W.runFork(e.onChangeEvent(n).pipe(W.catchAllCause((t) => W.sync(() => $.warn(`plugin ${e.name} onChangeEvent failed`, { error: cr.pretty(t) })))));
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
let Bn = y.filter((e) => fn.test(e));
|
|
2051
|
+
Bn.length > 0 && (await Re(Bn, $), $.info(`queue: ${Bn.length} consumer file(s) loaded`));
|
|
2052
|
+
let R = Pe({
|
|
2053
|
+
plugins: A,
|
|
2054
|
+
appName: m?.name ?? "voltro-api",
|
|
2055
|
+
appType: "api",
|
|
2056
|
+
voltroVersion: process.env.npm_package_version ?? "0.0.0",
|
|
2057
|
+
log: $
|
|
2058
|
+
});
|
|
2059
|
+
A.length && await R.activate(), l.mark("plugins");
|
|
2060
|
+
let Vn = await R.gatherObservability(), Hn = L({ scope: "voltro:broadcast" }), Un = {
|
|
2061
|
+
info: (e, t) => {
|
|
2062
|
+
Hn.info(e, t);
|
|
2063
|
+
},
|
|
2064
|
+
warn: (e, t) => {
|
|
2065
|
+
Hn.warn(e, t);
|
|
2066
|
+
},
|
|
2067
|
+
debug: () => {}
|
|
2068
|
+
}, z, Wn = await vt(w, m, _, jn, Un, (e, t) => {
|
|
2069
|
+
z?.refreshAll(`broadcast gap: missed ${t} change(s) from ${e}`);
|
|
2070
|
+
}), Gn = m?.apiKeys, Kn = (typeof Gn == "object" ? Gn.prefix : void 0) ?? "voltro_", B = Gn ? Mr(w) : void 0, V = B ? Hr({ flush: Ur(B) }) : void 0;
|
|
2071
|
+
V && J(() => V.shutdown());
|
|
2072
|
+
let qn = B ? Vr(B, {
|
|
2073
|
+
prefix: Kn,
|
|
2074
|
+
...V ? { usage: V } : {}
|
|
2075
|
+
}) : void 0, Jn = qn ? [Fr(qn, { prefix: Kn })] : [], Yn = Dt([...m?.auth?.strategies ?? [], ...Jn], Wi(m?.plugins ?? []), m?.auth?.anonymousTenantRequired ?? !1, m?.auth, () => Ve), Xn = [...m?.restRoutes ?? [], ...qn ? xr(qn, (typeof Gn == "object" ? Gn.managementPath : void 0) ?? "/v1/api-keys") : []], Zn = He(m?.idempotency, w), Qn = A.map((e) => e.services).filter((e) => e !== void 0), $n = G.mergeAll(qe({
|
|
2076
|
+
analyticsLayer: Ne.layer,
|
|
2077
|
+
cacheService: We,
|
|
2078
|
+
kvService: wt,
|
|
2079
|
+
...$e === void 0 ? {} : { semanticCache: $e },
|
|
2080
|
+
pluginServices: Qn,
|
|
2081
|
+
userLayers: m?.layers ?? []
|
|
2082
|
+
}), At(m?.http ?? {})), H = await St({
|
|
2083
|
+
files: y,
|
|
2084
|
+
store: w,
|
|
2085
|
+
log: $,
|
|
2086
|
+
seedPolicy: "report",
|
|
2087
|
+
seedPattern: dn,
|
|
2088
|
+
loadSeedFiles: $t,
|
|
2089
|
+
startupPattern: un,
|
|
2090
|
+
loadStartupFiles: a,
|
|
2091
|
+
runStartups: o,
|
|
2092
|
+
emailPattern: jt,
|
|
2093
|
+
loadEmailFiles: Je,
|
|
2094
|
+
registerEmailTemplates: Gi
|
|
2095
|
+
});
|
|
2096
|
+
(H.startupCount > 0 || H.emailCount > 0) && $.info("boot lifecycle", {
|
|
2097
|
+
startups: H.startupCount,
|
|
2098
|
+
emailTemplates: H.emailCount
|
|
2099
|
+
}), H.startups !== void 0 && J(async () => {
|
|
2100
|
+
await H.startups.stop();
|
|
2101
|
+
}), Ee({
|
|
2102
|
+
demands: qt(me),
|
|
2103
|
+
isRegistered: (e) => Ir(e) !== void 0
|
|
2104
|
+
});
|
|
2105
|
+
let er = ut({
|
|
2106
|
+
schedules: T({
|
|
2107
|
+
schedules: b.schedules,
|
|
2108
|
+
seeds: H.seeds,
|
|
2109
|
+
store: w,
|
|
2110
|
+
log: $.child("seeds")
|
|
2111
|
+
}),
|
|
2112
|
+
workflows: b.workflows ?? [],
|
|
2113
|
+
log: $.child("workflow-schedules")
|
|
2114
|
+
}), nr = m?.scheduling ?? {}, ir = nr.trigger ?? "self", ar = /* @__PURE__ */ new Set([
|
|
2115
|
+
"postgres",
|
|
2116
|
+
"mysql",
|
|
2117
|
+
"mariadb",
|
|
2118
|
+
"mssql"
|
|
2119
|
+
]), U = nr.coordination ?? (ar.has(_) ? "advisoryLock" : "single"), sr = U === "cluster" && ar.has(_), hr = sr ? "cluster" : U === "advisoryLock" && ar.has(_) ? "advisoryLock" : "single";
|
|
2120
|
+
U === "cluster" && !sr && $.warn("scheduling.coordination=cluster needs a sql-backed store except sqlite — falling back to single"), U === "advisoryLock" && !ar.has(_) && $.warn("scheduling.coordination=advisoryLock needs a SQL store (the claim-row gate) — falling back to single");
|
|
2121
|
+
let gr, _r = b.workflows.length > 0 || b.workflowWorkers.length > 0 || b.eventTriggers.length > 0 || (be?.outgoing.length ?? 0) > 0 || sr, vr;
|
|
2122
|
+
if (_r) {
|
|
2123
|
+
if (_ === "mssql") {
|
|
2124
|
+
let e = await Sn(process.cwd());
|
|
2125
|
+
e && $.warn(e);
|
|
2126
|
+
}
|
|
2127
|
+
let [{ WorkflowEngine: e }, { makeClusterCronLayer: t, workflowEngineLayer: n, resolveRunnerStorage: r, resolveFailoverTuning: i }] = await Promise.all([import("@effect/workflow"), import("@voltro/workflow/cluster")]), a = sr ? er.filter((e) => (e.trigger ?? ir) === "self").map((e) => t({
|
|
2128
|
+
name: e.name,
|
|
2129
|
+
cron: jr(e),
|
|
2130
|
+
execute: async () => {
|
|
2131
|
+
await gr?.fireFromCluster(e.name);
|
|
2132
|
+
}
|
|
2133
|
+
})) : [];
|
|
2134
|
+
vr = _ === "memory" ? e.layerMemory : await (async () => {
|
|
2135
|
+
let e = await P(_), t = r({ sqliteFamily: e.id === "sqlite" || e.id === "turso" });
|
|
2136
|
+
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({
|
|
2137
|
+
sqlClientLayer: e.makeSqlLayer(O()),
|
|
2138
|
+
runnerStorage: t,
|
|
2139
|
+
dialectId: e.id,
|
|
2140
|
+
...process.env.VOLTRO_WORKFLOW_RUNNER_PORT ? { runnerListenPort: Number(process.env.VOLTRO_WORKFLOW_RUNNER_PORT) } : {},
|
|
2141
|
+
...i(),
|
|
2142
|
+
...a.length > 0 ? { extraShardingLayers: a } : {}
|
|
2143
|
+
});
|
|
2144
|
+
})();
|
|
2145
|
+
}
|
|
2146
|
+
let yr = de(A, xn()), br = y.filter((e) => /\.subscribe\.tsx?$/.test(e)), Cr = br.length > 0 ? await Nt(br, $) : [], wr = y.filter((e) => /\.reaction\.tsx?$/.test(e)), Tr = wr.length > 0 ? await Se(wr, $) : [], Er = y.filter((e) => hn.test(e)), Dr = Er.length > 0 ? await we(Er, $) : [], Or = y.filter((e) => /\.aggregate\.tsx?$/.test(e)), K = Or.length > 0 ? await ht(Or, $) : [];
|
|
2147
|
+
{
|
|
2148
|
+
let e = Pr(yi(zt({ aggregates: K.map((e) => e.definition) }), Ae(C)));
|
|
2149
|
+
e !== void 0 && $.warn(e);
|
|
2150
|
+
}
|
|
2151
|
+
let kr = f();
|
|
2152
|
+
if (K.length > 0 && _ !== "memory") try {
|
|
2153
|
+
let e = (await P(_)).makeSqlLayer(O());
|
|
2154
|
+
kr = ft(e);
|
|
2155
|
+
} catch (e) {
|
|
2156
|
+
$.warn("aggregate: SQL storage init failed — falling back to in-process", { err: String(e) });
|
|
2157
|
+
}
|
|
2158
|
+
let Ar = _ === "memory" ? mi : Br(w, `aggregate@${process.pid}`, $), Lr = y.filter((e) => pn.test(e)), Rr = Lr.length > 0 ? await je(Lr, $) : [], zr = y.filter((e) => gn.test(e)), Gr = zr.length > 0 ? await Bt(zr, $) : [], qr = y.filter((e) => mn.test(e)), Jr = qr.length > 0 ? await ie(qr, $) : [], Yr = [], Xr = [], Zr = y.filter((e) => tn.test(e));
|
|
2159
|
+
if (Zr.length > 0) {
|
|
2160
|
+
let e = $.child("agent"), t = y.filter((e) => an.test(e));
|
|
2161
|
+
t.length > 0 && await nn(t, e);
|
|
2162
|
+
let n = await rn(Zr, e);
|
|
2163
|
+
for (let e of n.agents) for (let t of bt(e)) (t.kind === "action" ? Yr : Xr).push({
|
|
2164
|
+
file: t.file,
|
|
2165
|
+
descriptor: t.descriptor,
|
|
2166
|
+
executor: t.executor
|
|
2167
|
+
});
|
|
2168
|
+
n.agents.length > 0 && e.info("synthesized agent routes", { agents: n.agents.map((e) => e.descriptor.name) });
|
|
2169
|
+
}
|
|
2170
|
+
l.mark("workflow");
|
|
2171
|
+
let q = () => {
|
|
2172
|
+
let e = Y.workflowWriteActions();
|
|
2173
|
+
if (e === void 0) throw Error("workflow actions: this app registers no workflows");
|
|
2174
|
+
return e;
|
|
2175
|
+
}, Qr = rr({
|
|
2176
|
+
dialect: _,
|
|
2177
|
+
...O()
|
|
2178
|
+
}), $r = _ === "memory" ? void 0 : (await P(_)).makeSqlLayer(O()), ei = async () => kt({
|
|
2179
|
+
sqlLayer: $r,
|
|
2180
|
+
declared: C,
|
|
2181
|
+
log: $
|
|
2182
|
+
}), ni = {
|
|
2183
|
+
kind: "api",
|
|
2184
|
+
meta: {
|
|
2185
|
+
name: m?.name ?? "voltro-api",
|
|
2186
|
+
voltroVersion: Mt,
|
|
2187
|
+
port: se,
|
|
2188
|
+
mode: "start",
|
|
2189
|
+
store: _,
|
|
2190
|
+
cdc: le ? "on" : "off",
|
|
2191
|
+
...Qr === void 0 ? {} : { databaseId: Qr }
|
|
2192
|
+
},
|
|
2193
|
+
rpc: Ht(b, p),
|
|
2194
|
+
workflows: De(b, p),
|
|
2195
|
+
migrations: ei,
|
|
2196
|
+
events: () => Y.eventsSnapshot(),
|
|
2197
|
+
agentTools: () => Y.agentTools(),
|
|
2198
|
+
invariantChecks: () => ({
|
|
2199
|
+
mode: "serve",
|
|
2200
|
+
accessGate: me,
|
|
2201
|
+
config: m,
|
|
2202
|
+
serverOnlyLeaks: b.serverOnlyLeaks,
|
|
2203
|
+
migrations: ei
|
|
2204
|
+
}),
|
|
2205
|
+
members: () => Y.membersSnapshot(),
|
|
2206
|
+
inspectFireSchedule: async ({ name: e, trigger: t }) => {
|
|
2207
|
+
if (!gr) throw Error("scheduler not started — this app registers no self-triggered schedules (all schedules are trigger:'external', or there are none).");
|
|
2208
|
+
return { runId: await gr.fireNow(e, t) ?? null };
|
|
2209
|
+
},
|
|
2210
|
+
inspectBackfillSchedule: ne({
|
|
2211
|
+
getHandle: () => gr,
|
|
2212
|
+
getSchedules: () => er
|
|
2213
|
+
}),
|
|
2214
|
+
...be === void 0 ? {} : { webhooks: () => pt({
|
|
2215
|
+
store: w,
|
|
2216
|
+
discoveredWebhooks: be
|
|
2217
|
+
}) },
|
|
2218
|
+
plugins: () => ({
|
|
2219
|
+
plugins: R.snapshot(),
|
|
2220
|
+
capturedAt: Date.now()
|
|
2221
|
+
}),
|
|
2222
|
+
env: () => Yt(m?.name ?? Nn(p), {
|
|
2223
|
+
...m?.env !== void 0 && Mi(m.env) ? { contract: m.env } : {},
|
|
2224
|
+
plugins: m?.plugins ?? []
|
|
2225
|
+
}),
|
|
2226
|
+
dataCache: () => Vt({
|
|
2227
|
+
stats: gt,
|
|
2228
|
+
backendKind: lt
|
|
2229
|
+
}),
|
|
2230
|
+
subscriptions: () => x(() => z),
|
|
2231
|
+
inspectTables: () => Te(C),
|
|
2232
|
+
inspectRows: Kt({
|
|
2233
|
+
store: w,
|
|
2234
|
+
tables: C,
|
|
2235
|
+
mask: !0
|
|
2236
|
+
}),
|
|
2237
|
+
metrics: (e) => Y.rpcMetrics().snapshot(e),
|
|
2238
|
+
cluster: () => Ue({
|
|
2239
|
+
store: w,
|
|
2240
|
+
dialect: _,
|
|
2241
|
+
useClusterCron: sr,
|
|
2242
|
+
scheduleCoordChoice: U
|
|
2243
|
+
}),
|
|
2244
|
+
inspectSchedules: () => g({
|
|
2245
|
+
schedules: er,
|
|
2246
|
+
defaultTrigger: ir,
|
|
2247
|
+
coordination: hr
|
|
2248
|
+
}),
|
|
2249
|
+
inspectScheduleRuns: (e) => ke(w, e),
|
|
2250
|
+
...Rt(w, {
|
|
2251
|
+
controls: it(b.workflows ?? []),
|
|
2252
|
+
active: (b.workflows?.length ?? 0) > 0,
|
|
2253
|
+
cancellation: () => Y.flowControlHealth()
|
|
2254
|
+
}),
|
|
2255
|
+
webhookActions: te(() => Y.webhooksService()),
|
|
2256
|
+
inspectStartWorkflow: (e) => q().inspectStartWorkflow(e),
|
|
2257
|
+
inspectCancelWorkflowRun: (e) => q().inspectCancelWorkflowRun(e),
|
|
2258
|
+
inspectSuspendWorkflowRun: (e) => q().inspectSuspendWorkflowRun(e),
|
|
2259
|
+
inspectResumeWorkflowRun: (e) => q().inspectResumeWorkflowRun(e),
|
|
2260
|
+
inspectDiscardWorkflowRun: (e) => q().inspectDiscardWorkflowRun(e),
|
|
2261
|
+
inspectRetryWorkflowRun: (e) => q().inspectRetryWorkflowRun(e),
|
|
2262
|
+
inspectSignalWorkflowRun: (e) => q().inspectSignalWorkflowRun(e),
|
|
2263
|
+
inspectUpdateWorkflowRun: (e) => q().inspectUpdateWorkflowRun(e),
|
|
2264
|
+
inspectInferences: (e) => E({
|
|
2265
|
+
store: w,
|
|
2266
|
+
active: (b.workflows?.length ?? 0) > 0,
|
|
2267
|
+
dispatcher: () => Y.inferenceHealth()
|
|
2268
|
+
}, e.limit === void 0 ? {} : { limit: e.limit }),
|
|
2269
|
+
...st({
|
|
2270
|
+
store: w,
|
|
2271
|
+
cancelRun: async (e) => await Y.runCanceller()?.(e) ?? !1,
|
|
2272
|
+
retryRun: async (e) => q().inspectRetryWorkflowRun({ runId: e }),
|
|
2273
|
+
redriveRun: async (e) => Y.redriveWorkflowRun({ runId: e }),
|
|
2274
|
+
log: $
|
|
2275
|
+
}),
|
|
2276
|
+
inspectRedriveWorkflowRun: (e) => Y.redriveWorkflowRun(e),
|
|
2277
|
+
inspectResumeWorkflowRunFromStep: (e) => Y.resumeWorkflowRunFromStep(e)
|
|
2278
|
+
}, ri = (process.env.VOLTRO_TENANT_ISOLATION ?? m?.tenancy?.isolation) === "namespace", ii = ri && _ !== "memory" ? await (async () => {
|
|
2279
|
+
let e = await P(_);
|
|
2280
|
+
return et({
|
|
2281
|
+
tables: C,
|
|
2282
|
+
sqlLayer: e.makeSqlLayer(O()),
|
|
2283
|
+
dialect: _,
|
|
2284
|
+
options: { retryFilter: e.retryFilter },
|
|
2285
|
+
log: {
|
|
2286
|
+
info: (e, t) => $.info(e, t),
|
|
2287
|
+
error: (e, t, n) => $.error(e, t ?? {}, n)
|
|
2288
|
+
}
|
|
2289
|
+
});
|
|
2290
|
+
})() : void 0, ai = await at({
|
|
2291
|
+
input: m?.tenancy?.residency,
|
|
2292
|
+
namespaceIsolationOn: ri,
|
|
2293
|
+
makeStoreForUrl: (e, t) => ct(m, void 0, Zt(O(), t)),
|
|
2294
|
+
log: {
|
|
2295
|
+
info: (e, t) => $.info(e, t),
|
|
2296
|
+
warn: (e, t) => $.warn(e, t)
|
|
2297
|
+
}
|
|
2298
|
+
});
|
|
2299
|
+
ai !== void 0 && J(async () => {
|
|
2300
|
+
await ai.close();
|
|
2301
|
+
});
|
|
2302
|
+
let Y = await yo({
|
|
2303
|
+
bootTiming: l,
|
|
2304
|
+
broadcastNamespace: jn,
|
|
2305
|
+
scheduling: (() => {
|
|
2306
|
+
let e = N;
|
|
2307
|
+
return {
|
|
2308
|
+
admissionDrainMs: e.admissionDrainMs,
|
|
2309
|
+
inferenceTickMs: e.inferenceTickMs,
|
|
2310
|
+
cancelSweepMs: e.cancelSweepMs,
|
|
2311
|
+
stalenessSweepMs: e.stalenessSweepMs,
|
|
2312
|
+
disarmWhenIdle: M({
|
|
2313
|
+
changeScope: w.changeScope,
|
|
2314
|
+
broadcastAttached: Wn !== void 0
|
|
2315
|
+
})
|
|
2316
|
+
};
|
|
2317
|
+
})(),
|
|
2318
|
+
...m?.workflows?.staleness === void 0 ? {} : { workflowStaleness: m.workflows.staleness },
|
|
2319
|
+
...m?.workflows?.suspendSignalHintMs === void 0 ? {} : { workflowSuspendSignalHintMs: m.workflows.suspendSignalHintMs },
|
|
2320
|
+
workflowRecording: Ge(m?.workflows?.recording),
|
|
2321
|
+
membership: {
|
|
2322
|
+
...Mn,
|
|
2323
|
+
instanceId: On
|
|
2324
|
+
},
|
|
2325
|
+
security: {
|
|
2326
|
+
defaultDeny: S(m),
|
|
2327
|
+
...ue(m)
|
|
2328
|
+
},
|
|
2329
|
+
approvals: { defaultExpiryMs: Le(m) },
|
|
2330
|
+
...m?.plugins === void 0 ? {} : { plugins: m.plugins },
|
|
2331
|
+
...Zn ? { idempotency: Zn } : {},
|
|
2332
|
+
restRoutes: Xn,
|
|
2333
|
+
...m?.grpc === void 0 ? {} : { grpc: {
|
|
2334
|
+
config: m.grpc,
|
|
2335
|
+
root: p
|
|
2336
|
+
} },
|
|
2337
|
+
appProcedures: me,
|
|
2338
|
+
discovered: {
|
|
2339
|
+
wsGateways: b.wsGateways,
|
|
2340
|
+
queries: [...b.queries, ...Xr],
|
|
2341
|
+
mutations: b.mutations,
|
|
2342
|
+
actions: [...b.actions, ...Yr],
|
|
2343
|
+
streams: b.streams,
|
|
2344
|
+
events: b.events,
|
|
2345
|
+
workflows: b.workflows,
|
|
2346
|
+
workflowWorkers: b.workflowWorkers,
|
|
2347
|
+
eventTriggers: b.eventTriggers,
|
|
2348
|
+
schedules: er,
|
|
2349
|
+
subscribers: Cr,
|
|
2350
|
+
outboxHandlers: Dr,
|
|
2351
|
+
connections: b.connections,
|
|
2352
|
+
reactions: Tr,
|
|
2353
|
+
aggregates: K,
|
|
2354
|
+
expectations: Rr,
|
|
2355
|
+
budgets: Gr,
|
|
2356
|
+
experiments: Jr,
|
|
2357
|
+
...be === void 0 ? {} : { webhooks: be }
|
|
2358
|
+
},
|
|
2359
|
+
log: $,
|
|
2360
|
+
analytics: Ne.sink,
|
|
2361
|
+
aggregateStorage: kr,
|
|
2362
|
+
aggregateCoordinator: Ar,
|
|
2363
|
+
store: w,
|
|
2364
|
+
kv: xt,
|
|
2365
|
+
cache: Qe,
|
|
2366
|
+
snapshotCache: Ze,
|
|
2367
|
+
...m?.reactive === void 0 ? {} : { reactive: m.reactive },
|
|
2368
|
+
schemaRegistry: Ie,
|
|
2369
|
+
tenantScopedTables: b.tenantScopedTables,
|
|
2370
|
+
softDeleteScopedTables: b.softDeleteScopedTables,
|
|
2371
|
+
dataTransferSnapshot: dr(C, _),
|
|
2372
|
+
dataTransferDialect: _,
|
|
2373
|
+
...ii === void 0 ? {} : { ensureTenantProvisioned: ii.ensure },
|
|
2374
|
+
...ai === void 0 ? {} : { resolveResidentStore: ai.resolveStore },
|
|
2375
|
+
tenantIsolation: (process.env.VOLTRO_TENANT_ISOLATION ?? m?.tenancy?.isolation) === "namespace" ? "namespace" : "shared-schema",
|
|
2376
|
+
resolveSubject: (e, t) => Yn({
|
|
2377
|
+
headers: e,
|
|
2378
|
+
clientId: t
|
|
2379
|
+
}),
|
|
2380
|
+
...m?.auth === void 0 ? {} : { authority: m.auth },
|
|
2381
|
+
...m?.agents === void 0 ? {} : { agents: m.agents },
|
|
2382
|
+
httpRoutes: A.flatMap((e) => e.httpRoutes ?? []),
|
|
2383
|
+
getStore: () => Ve,
|
|
2384
|
+
...$n ? { baseLayer: $n } : {},
|
|
2385
|
+
...vr === void 0 ? {} : { workflowEngineLayer: vr },
|
|
2386
|
+
scheduleDefaultTrigger: ir,
|
|
2387
|
+
scheduleCoordination: hr,
|
|
2388
|
+
scheduleArmSelf: !sr,
|
|
2389
|
+
dormancy: process.env.VOLTRO_DORMANCY === "sleep" || process.env.VOLTRO_DORMANCY === "always-on" ? process.env.VOLTRO_DORMANCY : m?.dormancy ?? "always-on",
|
|
2390
|
+
scheduleReplicaId: process.env.HOSTNAME ?? `pid-${process.pid}`,
|
|
2391
|
+
...yr === void 0 ? {} : { scheduleFireInterceptor: yr },
|
|
2392
|
+
onSchedulerReady: (e) => {
|
|
2393
|
+
gr = e;
|
|
2394
|
+
},
|
|
2395
|
+
inspectRoute: { handle: async (e, t, n, r) => await ve(e, ni, t, {
|
|
2396
|
+
method: n,
|
|
2397
|
+
...r === void 0 ? {} : { body: r }
|
|
2398
|
+
}) || ((n === "GET" ? await vn(e, ni, t, { method: n }) : null) ?? _n(e, ni, t, {
|
|
2399
|
+
method: n,
|
|
2400
|
+
...r === void 0 ? {} : { body: r }
|
|
2401
|
+
}) ?? {
|
|
2402
|
+
status: 404,
|
|
2403
|
+
contentType: "application/json",
|
|
2404
|
+
body: JSON.stringify({ error: "not an inspect route" })
|
|
2405
|
+
}) },
|
|
2406
|
+
...m?.name === void 0 ? {} : { appName: m.name },
|
|
2407
|
+
observability: Vn,
|
|
2408
|
+
port: se,
|
|
2409
|
+
...m?.transport?.wsPath ? { path: m.transport.wsPath } : {},
|
|
2410
|
+
...m?.http === void 0 ? {} : { http: m.http }
|
|
2411
|
+
});
|
|
2412
|
+
return z = Y.dispatcher, d(mt([
|
|
2413
|
+
b.queries,
|
|
2414
|
+
b.mutations,
|
|
2415
|
+
b.actions,
|
|
2416
|
+
b.streams
|
|
2417
|
+
]), (e) => {
|
|
2418
|
+
$.warn(e);
|
|
2419
|
+
}), $.info(`API listening on :${se}`, {
|
|
2420
|
+
dialect: _,
|
|
2421
|
+
queries: b.queries.length,
|
|
2422
|
+
mutations: b.mutations.length,
|
|
2423
|
+
actions: b.actions.length,
|
|
2424
|
+
streams: b.streams.length,
|
|
2425
|
+
workflows: b.workflows.length,
|
|
2426
|
+
workflowWorkers: b.workflowWorkers.length,
|
|
2427
|
+
schedules: er.length,
|
|
2428
|
+
scheduleCoordination: hr
|
|
2429
|
+
}), l.finish($), J(async () => {
|
|
2430
|
+
for (let e of wn) e.stop();
|
|
2431
|
+
Et.stop();
|
|
2432
|
+
try {
|
|
2433
|
+
await Y.close(), _t(), It?.dispose(), await R.deactivate(), await Wn?.close(), await Ot({
|
|
2434
|
+
mirror: Tt,
|
|
2435
|
+
log: $
|
|
2436
|
+
}), await Ne.dispose(), await w.close?.();
|
|
2437
|
+
} catch (e) {
|
|
2438
|
+
console.error("serve: shutdown step failed, exiting anyway:", e);
|
|
2439
|
+
}
|
|
2440
|
+
}), await new Promise(() => {}), 0;
|
|
2441
|
+
};
|
|
2442
|
+
//#endregion
|
|
2443
|
+
export { So as n, bo as r, Co as t };
|