@voltro/runtime 0.85.0 → 0.87.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 +5987 -0
- package/README.md +43 -0
- package/THIRD-PARTY-NOTICES.md +864 -253
- package/dist/aggregate.js +42 -0
- package/dist/aggregateExtrema.js +80 -0
- package/dist/aggregateIvm.js +115 -0
- package/dist/analyticsMirror.js +228 -0
- package/dist/analyticsSink.js +32 -0
- package/dist/apiKeyUsage.js +33 -0
- package/dist/apiKeys.js +227 -0
- package/dist/apiKeysWiring.js +114 -0
- package/dist/apiRoleBucketSampler.js +64 -0
- package/dist/apiRoleWorkloadHistory.js +56 -0
- package/dist/apiRoleWorkloadMetrics.js +78 -0
- package/dist/apiRoleWorkloadStorage.js +95 -0
- package/dist/approvalBuiltins.js +10 -0
- package/dist/approvals.js +262 -0
- package/dist/authMiddlewareLayer.js +48 -0
- package/dist/bindEvent.js +92 -0
- package/dist/bootListener.js +143 -0
- package/dist/bootRefusal.js +7 -0
- package/dist/bootStoreCodec.js +71 -0
- package/dist/businessRules.js +67 -0
- package/dist/changeClaimsTable.js +12 -0
- package/dist/circuitBreaker.js +1 -0
- package/dist/columnOnUpdate.js +23 -0
- package/dist/composeAnalytics.js +129 -0
- package/dist/computedQuery.js +4 -0
- package/dist/computedQueryCache.js +231 -0
- package/dist/connectionBuiltins.js +81 -0
- package/dist/connectionCredentials.js +66 -0
- package/dist/connectionState.js +34 -0
- package/dist/connectionVault.js +410 -0
- package/dist/connectionsFacade.js +56 -0
- package/dist/coordinatedSchedule.js +145 -0
- package/dist/crdtHistory.js +138 -0
- package/dist/crdtMerge.js +179 -0
- package/dist/crdtVersionsTable.js +25 -0
- package/dist/credentialBound.js +12 -0
- package/dist/crud.js +72 -0
- package/dist/dataStore.js +712 -0
- package/dist/dataloader.js +61 -0
- package/dist/declaredTablesGuard.js +49 -0
- package/dist/defineExecutor.js +4 -0
- package/dist/dependencyGraph.js +32 -0
- package/dist/devices.js +228 -0
- package/dist/devicesWiring.js +168 -0
- package/dist/dialectReplicationAdapter.js +29 -0
- package/dist/dispatcher.js +522 -0
- package/dist/effectStore.js +71 -0
- package/dist/engineClients.js +24 -0
- package/dist/eventBus.js +260 -0
- package/dist/eventPublish.js +49 -0
- package/dist/events.js +193 -0
- package/dist/expectation.js +52 -0
- package/dist/expectationEvaluator.js +308 -0
- package/dist/experiment.js +96 -0
- package/dist/experimentEvaluator.js +245 -0
- package/dist/externalizedTasks.js +38 -0
- package/dist/fieldCipher.js +130 -0
- package/dist/fieldKeyRegistry.js +295 -0
- package/dist/fieldKeyRekey.js +286 -0
- package/dist/fieldKeyScan.js +136 -0
- package/dist/fieldKeyring.js +77 -0
- package/dist/fingerprint.js +21 -0
- package/dist/finops.js +42 -0
- package/dist/finopsAccountant.js +216 -0
- package/dist/handlerBody.js +8 -0
- package/dist/healthProbes.js +55 -0
- package/dist/hot.d.ts +56 -0
- package/dist/hot.js +3 -0
- package/dist/hotDataStore.js +148 -0
- package/dist/hotDataStoreSnapshot.js +98 -0
- package/dist/hotDataStoreTables.js +18 -0
- package/dist/http-range.d.ts +53 -0
- package/dist/http-range.js +52 -0
- package/dist/httpClientSsrf.js +24 -0
- package/dist/httpClientTracing.js +14 -0
- package/dist/httpCompression.js +76 -0
- package/dist/httpInputStream.js +82 -0
- package/dist/httpKeepAlive.js +12 -0
- package/dist/httpRouteMounts.js +48 -0
- package/dist/idempotencyStore.js +110 -0
- package/dist/idleDetector.js +21 -0
- package/dist/index.d.ts +1249 -517
- package/dist/index.js +155 -15292
- package/dist/insertRequiredColumns.js +19 -0
- package/dist/inspectWorkflow.js +1 -0
- package/dist/instanceMembership.js +98 -0
- package/dist/ivm.js +125 -0
- package/dist/kvDataStore.js +86 -0
- package/dist/kvFacade.js +38 -0
- package/dist/matcher.js +304 -0
- package/dist/memoryColumnDefaults.js +11 -0
- package/dist/memoryQueryJoins.js +114 -0
- package/dist/memorySetOperations.js +43 -0
- package/dist/metrics.js +175 -0
- package/dist/observability.js +123 -0
- package/dist/observedGraph.js +52 -0
- package/dist/originGuard.js +116 -0
- package/dist/outbox.js +352 -0
- package/dist/pluginRefRules.js +65 -0
- package/dist/policyGuardResolver.js +55 -0
- package/dist/preview.js +62 -0
- package/dist/projectedRows.js +12 -0
- package/dist/provenance.js +63 -0
- package/dist/rangeIndex.js +89 -0
- package/dist/rawReadScope.js +17 -0
- package/dist/reaction.js +85 -0
- package/dist/reactiveConfig.js +11 -0
- package/dist/readClassification.js +57 -0
- package/dist/readRecorder.js +67 -0
- package/dist/readScopePredicate.js +12 -0
- package/dist/rebac.js +104 -0
- package/dist/rebacInterceptor.js +81 -0
- package/dist/registry.js +29 -0
- package/dist/relevantFields.js +65 -0
- package/dist/replicaHealth.js +42 -0
- package/dist/replicaLocality.js +44 -0
- package/dist/replicaObservations.js +121 -0
- package/dist/replicaSelection.js +32 -0
- package/dist/replicatedDataStore.js +257 -0
- package/dist/requestLoader.js +7 -0
- package/dist/resumeCensus.js +28 -0
- package/dist/revalidation.js +22 -0
- package/dist/rowFilter.js +82 -0
- package/dist/rowStateBytes.js +45 -0
- package/dist/rpcBodyCap.js +63 -0
- package/dist/rpcConnections.js +83 -0
- package/dist/rpcDefectDiagnostics.js +15 -0
- package/dist/rpcServer.js +1065 -0
- package/dist/rpcWorkloadAdmission.js +50 -0
- package/dist/runAsSystem.js +23 -0
- package/dist/rywPositionStore.js +119 -0
- package/dist/schedule.js +23 -0
- package/dist/scheduleBackfillRequests.js +151 -0
- package/dist/scheduleClaimsTable.js +11 -0
- package/dist/scheduleRunsTable.js +37 -0
- package/dist/scheduler.js +840 -0
- package/dist/schemaRegistry.js +65 -0
- package/dist/secretsResolver.js +35 -0
- package/dist/securityHeaders.js +33 -0
- package/dist/servePipeline.js +374 -0
- package/dist/serverOnlyAudit.js +66 -0
- package/dist/serverTracer.js +15 -0
- package/dist/serviceCredentials.js +40 -0
- package/dist/setReadScopes.js +28 -0
- package/dist/singleNodeOrchestrator.js +91 -0
- package/dist/snapshotValueCodec.js +46 -0
- package/dist/sourceResolution.js +52 -0
- package/dist/storeMiddleware.js +882 -0
- package/dist/storeQuery.js +204 -0
- package/dist/storeRead.js +10 -0
- package/dist/subscriber.js +8 -0
- package/dist/subscriptionOutbox.js +139 -0
- package/dist/subscriptionRegistry.js +82 -0
- package/dist/subscriptionResume.js +132 -0
- package/dist/subscriptionSocketMetrics.js +65 -0
- package/dist/systemSubject.js +5 -0
- package/dist/tenantScope.js +11 -0
- package/dist/tenantSelection.js +27 -0
- package/dist/timeline.js +105 -0
- package/dist/traceContext.js +5 -0
- package/dist/traceSink.js +63 -0
- package/dist/traceSpansTable.js +29 -0
- package/dist/traceparent.js +23 -0
- package/dist/transactionSubject.js +12 -0
- package/dist/trustedProxy.js +155 -0
- package/dist/undo.js +129 -0
- package/dist/undoBuiltins.js +69 -0
- package/dist/undoCapture.js +74 -0
- package/dist/undoLogTable.js +16 -0
- package/dist/upsertBinding.js +20 -0
- package/dist/wakeOrchestrator.js +34 -0
- package/dist/wakeRegistry.js +71 -0
- package/dist/wakeRouter.js +63 -0
- package/dist/wakeSupervisor.js +62 -0
- package/dist/wakeupsTable.js +12 -0
- package/dist/webSocketGatewayRuntime.js +154 -0
- package/dist/webhookVerification.js +18 -0
- package/dist/wireColumnStrip.js +84 -0
- package/dist/workflowReadBuiltins.js +87 -0
- package/dist/workflowRuntime.js +708 -0
- package/package.json +19 -7
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//#region src/schemaRegistry.ts
|
|
2
|
+
var e = "voltro/audit", t = "voltro/softDelete", n = "voltro/expires", r = "voltro/tenant", i = "voltro/localFirst", a = (e) => {
|
|
3
|
+
let t = /* @__PURE__ */ new Map();
|
|
4
|
+
for (let n of e) {
|
|
5
|
+
let e = /* @__PURE__ */ new Set();
|
|
6
|
+
for (let t of n.appliedMixins ?? []) t.id !== void 0 && e.add(t.id);
|
|
7
|
+
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s, c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d;
|
|
8
|
+
for (let [e, t] of Object.entries(n.fields)) t.unique && r.add(e), t.type === "id" && (r.add(e), t.idScheme !== void 0 && (d = t.idScheme)), t.defaultFactory !== void 0 && i.set(e, t.defaultFactory), t.computed !== void 0 && a.set(e, t.computed), t.onUpdate !== void 0 && o.set(e, t.onUpdate), t.versionColumn === !0 && (s = e), t.generatedAs !== void 0 && c.add(e), t.crdtManaged === !0 && l.add(e), t.crdtSealed === !0 && u.add(e);
|
|
9
|
+
let f = n.appliedIndexes ?? [];
|
|
10
|
+
for (let e of f) {
|
|
11
|
+
let t = e.fields[0];
|
|
12
|
+
t !== void 0 && r.add(t);
|
|
13
|
+
}
|
|
14
|
+
let p = {
|
|
15
|
+
tableName: n.tableName,
|
|
16
|
+
mixinIds: e,
|
|
17
|
+
fields: new Set(Object.keys(n.fields)),
|
|
18
|
+
indexedFields: r,
|
|
19
|
+
compositeIndexes: f.map((e) => ({
|
|
20
|
+
name: e.name,
|
|
21
|
+
fields: [...e.fields]
|
|
22
|
+
})),
|
|
23
|
+
defaultFactories: i,
|
|
24
|
+
computedFields: a,
|
|
25
|
+
...o.size > 0 ? { onUpdateFields: o } : {},
|
|
26
|
+
...s === void 0 ? {} : { versionColumn: s },
|
|
27
|
+
generatedColumns: c,
|
|
28
|
+
crdtColumns: l,
|
|
29
|
+
sealedColumns: u,
|
|
30
|
+
...d === void 0 ? {} : { idScheme: d },
|
|
31
|
+
declaredPrimaryKey: [...n.appliedPrimaryKey ?? []],
|
|
32
|
+
...n.insertSchema === void 0 ? {} : { insertSchema: n.insertSchema },
|
|
33
|
+
...n.validatePatchSchema === void 0 ? {} : { validatePatchSchema: n.validatePatchSchema }
|
|
34
|
+
};
|
|
35
|
+
t.set(n.tableName, p);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
tables: t,
|
|
39
|
+
hasMixin: (e, n) => t.get(e)?.mixinIds.has(n) ?? !1,
|
|
40
|
+
hasAudit: (e) => t.get(e)?.mixinIds.has("voltro/audit") ?? !1,
|
|
41
|
+
hasSoftDelete: (e) => t.get(e)?.mixinIds.has("voltro/softDelete") ?? !1,
|
|
42
|
+
hasExpires: (e) => t.get(e)?.mixinIds.has("voltro/expires") ?? !1,
|
|
43
|
+
hasTenant: (e) => t.get(e)?.mixinIds.has("voltro/tenant") ?? !1,
|
|
44
|
+
hasLocalFirst: (e) => t.get(e)?.mixinIds.has("voltro/localFirst") ?? !1,
|
|
45
|
+
hasField: (e, n) => t.get(e)?.fields.has(n) ?? !1,
|
|
46
|
+
anyFieldIndexed: (e, n) => {
|
|
47
|
+
let r = t.get(e);
|
|
48
|
+
if (r === void 0) return !1;
|
|
49
|
+
for (let e of n) if (r.indexedFields.has(e)) return !0;
|
|
50
|
+
return !1;
|
|
51
|
+
},
|
|
52
|
+
idScheme: (e) => t.get(e)?.idScheme,
|
|
53
|
+
declaredPrimaryKey: (e) => t.get(e)?.declaredPrimaryKey ?? c,
|
|
54
|
+
defaultFactories: (e) => t.get(e)?.defaultFactories ?? o,
|
|
55
|
+
computedFields: (e) => t.get(e)?.computedFields ?? s,
|
|
56
|
+
versionColumn: (e) => t.get(e)?.versionColumn,
|
|
57
|
+
generatedColumns: (e) => t.get(e)?.generatedColumns ?? l,
|
|
58
|
+
crdtColumns: (e) => t.get(e)?.crdtColumns ?? u,
|
|
59
|
+
sealedColumns: (e) => t.get(e)?.sealedColumns ?? u,
|
|
60
|
+
insertSchema: (e) => t.get(e)?.insertSchema,
|
|
61
|
+
validatePatchSchema: (e) => t.get(e)?.validatePatchSchema
|
|
62
|
+
};
|
|
63
|
+
}, o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = [], l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = a([]);
|
|
64
|
+
//#endregion
|
|
65
|
+
export { e as VOLTRO_AUDIT_MIXIN_ID, n as VOLTRO_EXPIRES_MIXIN_ID, i as VOLTRO_LOCAL_FIRST_MIXIN_ID, t as VOLTRO_SOFT_DELETE_MIXIN_ID, r as VOLTRO_TENANT_MIXIN_ID, d as emptySchemaRegistry, a as makeSchemaRegistry };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/secretsResolver.ts
|
|
2
|
+
var e = { get: (e) => Promise.resolve(process.env[e]) }, t = e, n = (e) => {
|
|
3
|
+
t = e;
|
|
4
|
+
}, r = () => {
|
|
5
|
+
t = e;
|
|
6
|
+
}, i = async (e) => await t.get(e) ?? process.env[e], a = (e) => process.env[e], o = (e, t = 6e4, n = () => Date.now()) => {
|
|
7
|
+
let r = /* @__PURE__ */ new Map();
|
|
8
|
+
return { get: async (i) => {
|
|
9
|
+
let a = r.get(i);
|
|
10
|
+
if (a && n() - a.at < t) return a.value;
|
|
11
|
+
let o = await e.get(i);
|
|
12
|
+
return r.set(i, {
|
|
13
|
+
value: o,
|
|
14
|
+
at: n()
|
|
15
|
+
}), o;
|
|
16
|
+
} };
|
|
17
|
+
}, s = (e) => {
|
|
18
|
+
let t = {
|
|
19
|
+
accept: "application/json",
|
|
20
|
+
...e.headers ?? {}
|
|
21
|
+
};
|
|
22
|
+
if (e.perKey) return o({ get: async (n) => {
|
|
23
|
+
let r = await fetch(`${e.url.replace(/\/$/, "")}/${encodeURIComponent(n)}`, { headers: t });
|
|
24
|
+
if (!r.ok) return;
|
|
25
|
+
let i = await r.json();
|
|
26
|
+
return typeof i.value == "string" ? i.value : void 0;
|
|
27
|
+
} }, e.ttlMs);
|
|
28
|
+
let n, r = 0, i = e.ttlMs ?? 6e4, a = () => (n !== void 0 && Date.now() - r < i || (r = Date.now(), n = fetch(e.url, { headers: t }).then((e) => e.ok ? e.json() : {}).catch(() => ({}))), n);
|
|
29
|
+
return { get: async (e) => {
|
|
30
|
+
let t = (await a())[e];
|
|
31
|
+
return typeof t == "string" ? t : void 0;
|
|
32
|
+
} };
|
|
33
|
+
}, c = (t) => t === void 0 || t === "env" || typeof t == "object" && t.kind === "env" ? e : t.kind === "custom" ? t.backend : t.kind === "http" ? s(t) : e;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { o as cachedBackend, e as envSecretsBackend, s as httpSecretsBackend, r as resetSecretsBackend, i as resolveSecret, a as resolveSecretSync, c as resolveSecretsBackend, n as setSecretsBackend };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/securityHeaders.ts
|
|
2
|
+
var e = "default-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'", t = "frame-ancestors 'none'; base-uri 'none'; object-src 'none'", n = "max-age=15552000; includeSubDomains", r = /* @__PURE__ */ new Set(["no-referrer"]), i = (e) => {
|
|
3
|
+
if (e === !1) return !0;
|
|
4
|
+
let t = e.split(",").map((e) => e.trim().toLowerCase()).filter((e) => e !== ""), n = t[t.length - 1];
|
|
5
|
+
return n === void 0 || !r.has(n);
|
|
6
|
+
}, a = (e) => {
|
|
7
|
+
let t = e?.trim().toLowerCase();
|
|
8
|
+
return t === "off" || t === "default" || t === "strict" ? t : void 0;
|
|
9
|
+
}, o = (e) => {
|
|
10
|
+
if (e === void 0) return;
|
|
11
|
+
let t = e.trim();
|
|
12
|
+
if (t !== "") return t.toLowerCase() !== "off" && t;
|
|
13
|
+
}, s = (e, t = process.env) => {
|
|
14
|
+
let n = e?.mode ?? a(t.VOLTRO_SECURITY_HEADERS) ?? "default", r = e?.csp ?? o(t.VOLTRO_CSP) ?? "default-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'";
|
|
15
|
+
return {
|
|
16
|
+
mode: n,
|
|
17
|
+
csp: r,
|
|
18
|
+
cspHtml: e?.cspHtml ?? o(t.VOLTRO_CSP_HTML) ?? (n === "strict" ? r : "frame-ancestors 'none'; base-uri 'none'; object-src 'none'"),
|
|
19
|
+
hsts: e?.hsts ?? o(t.VOLTRO_HSTS) ?? "max-age=15552000; includeSubDomains",
|
|
20
|
+
frameOptions: e?.frameOptions ?? "DENY",
|
|
21
|
+
referrerPolicy: e?.referrerPolicy ?? "strict-origin-when-cross-origin",
|
|
22
|
+
contentTypeOptions: e?.contentTypeOptions ?? "nosniff",
|
|
23
|
+
extra: e?.extra ?? {}
|
|
24
|
+
};
|
|
25
|
+
}, c = (e, t) => {
|
|
26
|
+
if (e.mode === "off") return {};
|
|
27
|
+
let n = (t.contentType ?? "").toLowerCase().includes("text/html") ? e.cspHtml : e.csp, r = {};
|
|
28
|
+
n !== !1 && (r["content-security-policy"] = n), e.frameOptions !== !1 && (r["x-frame-options"] = e.frameOptions), e.referrerPolicy !== !1 && (r["referrer-policy"] = e.referrerPolicy), e.contentTypeOptions !== !1 && (r["x-content-type-options"] = e.contentTypeOptions), e.hsts !== !1 && t.https && (r["strict-transport-security"] = e.hsts);
|
|
29
|
+
for (let [t, n] of Object.entries(e.extra)) r[t.toLowerCase()] = n;
|
|
30
|
+
return r;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { e as API_CSP, n as DEFAULT_HSTS, t as HTML_CSP, r as ORIGIN_NULLING_REFERRER_POLICIES, i as preservesSameOriginHeader, s as resolveSecurityHeaders, c as securityHeadersFor };
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { cachedComputedCall as e, computedCacheKey as t, currentQueryDependencies as n, enterQueryDependencies as r } from "./computedQueryCache.js";
|
|
2
|
+
import { enterReadRecording as i } from "./readRecorder.js";
|
|
3
|
+
import { getRowFilter as a, makeDefaultRefilter as o, resolveRowFilterScope as s } from "./rowFilter.js";
|
|
4
|
+
import { isComputedQuery as c } from "./computedQuery.js";
|
|
5
|
+
import { TX_READ_VERSIONS_KEY as l, isTransactionReadConflict as u } from "./storeMiddleware.js";
|
|
6
|
+
import { evaluateTouchedRules as d, makeRuleCapture as f } from "./businessRules.js";
|
|
7
|
+
import { enforceApproval as p } from "./approvals.js";
|
|
8
|
+
import { observeApiRoleEffect as m } from "./apiRoleWorkloadMetrics.js";
|
|
9
|
+
import { Cause as h, Effect as g, Exit as _, Option as v } from "effect";
|
|
10
|
+
import { isTransientContention as y } from "@voltro/database";
|
|
11
|
+
import { SubjectService as b, checkGuardsEffect as x, currentSubjectAuthority as S, recheckGuardsEffect as C } from "@voltro/protocol";
|
|
12
|
+
import { createLogger as w } from "@voltro/logger";
|
|
13
|
+
//#region src/servePipeline.ts
|
|
14
|
+
var T = (e, t) => g.runPromiseExit(e, t).then((e) => {
|
|
15
|
+
if (_.isSuccess(e)) return e.value;
|
|
16
|
+
let t = h.findErrorOption(e.cause);
|
|
17
|
+
throw v.isSome(t) ? t.value : h.squash(e.cause);
|
|
18
|
+
}), E = (e) => T(e), D = (e, t) => e.pipe(g.provideService(b, t)), O = async (e, t, n, r) => {
|
|
19
|
+
let i = await g.runPromise(x(t, e.guards, n, {
|
|
20
|
+
defaultDeny: r === !0,
|
|
21
|
+
procedure: e.name
|
|
22
|
+
}));
|
|
23
|
+
if (i) throw i;
|
|
24
|
+
}, k = async (e, t, n, r) => {
|
|
25
|
+
e.requiresApproval !== void 0 && await p({
|
|
26
|
+
procedure: e.name,
|
|
27
|
+
kind: t,
|
|
28
|
+
policy: e.requiresApproval,
|
|
29
|
+
subject: n.subject,
|
|
30
|
+
input: r,
|
|
31
|
+
traceId: n.traceId
|
|
32
|
+
});
|
|
33
|
+
}, A = w({ scope: "voltro:rpc" }), j = async (e) => {
|
|
34
|
+
if (a() === void 0) return e;
|
|
35
|
+
let t = await E(s(e.subject, (e) => {
|
|
36
|
+
A.error("row filter failed to load", {}, e instanceof Error ? e : Error(String(e)));
|
|
37
|
+
}));
|
|
38
|
+
return {
|
|
39
|
+
...e,
|
|
40
|
+
rowFilter: t
|
|
41
|
+
};
|
|
42
|
+
}, M = (e) => ({
|
|
43
|
+
...e.surface === void 0 ? {} : { surface: e.surface },
|
|
44
|
+
...e.publicApi === void 0 ? {} : { publicApi: e.publicApi },
|
|
45
|
+
...e.remoteAddr === void 0 ? {} : { remoteAddr: e.remoteAddr }
|
|
46
|
+
}), N = (e) => {
|
|
47
|
+
let t = e.descriptor.target;
|
|
48
|
+
if (t == null) return [];
|
|
49
|
+
let n = Array.isArray(t) ? t : [t], r = /* @__PURE__ */ new Set();
|
|
50
|
+
for (let e of n) {
|
|
51
|
+
let t = e.table;
|
|
52
|
+
typeof t == "string" && t.length > 0 && r.add(t);
|
|
53
|
+
}
|
|
54
|
+
return [...r];
|
|
55
|
+
}, P = async (e) => {
|
|
56
|
+
let { store: t, target: n, procedure: r, input: i, output: a } = e;
|
|
57
|
+
if (n == null) return;
|
|
58
|
+
let o = Array.isArray(n) ? n : [n];
|
|
59
|
+
for (let e of o) {
|
|
60
|
+
let n = e.relations;
|
|
61
|
+
if (n !== void 0) for (let [o, s] of Object.entries(n)) {
|
|
62
|
+
let n = s.junction, c = i?.[o];
|
|
63
|
+
if (c === void 0) continue;
|
|
64
|
+
if (!Array.isArray(c)) throw Error(`${r}: declared relation '${o}' → '${n}' expects an ARRAY of target ids in input.${o}, got ${typeof c}. Omit the field to leave the links untouched; send [] to clear them.`);
|
|
65
|
+
let l = a?.id ?? i?.id;
|
|
66
|
+
if (typeof l != "string" || l.length === 0) throw Error(`${r}: declared relation '${o}' → '${n}' needs the written row's id — neither output.id nor input.id is a string. Return the row (or its id) from the executor.`);
|
|
67
|
+
let u = t.relationLinks(n, e.table, l), d = u.columns;
|
|
68
|
+
if (d.anchorColumn !== s.anchorColumn || d.targetColumn !== s.targetColumn) throw Error(`${r}: declared relation '${o}' → '${n}' names columns the junction does not have. Declared { anchorColumn: '${s.anchorColumn}', targetColumn: '${s.targetColumn}' }; '${n}' resolves to { anchorColumn: '${d.anchorColumn}', targetColumn: '${d.targetColumn}' } for anchor table '${e.table}'. The client patches the junction optimistically from THIS declaration, so a wrong pair would show links the write never made — fix the declaration to the pair named here.`);
|
|
69
|
+
await u.set(c.map((e) => String(e)));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, F = (e, t) => e === void 0 ? {} : { enqueueOutcome: async (n, r, i) => {
|
|
73
|
+
let a = e(t);
|
|
74
|
+
if (a === void 0) throw TypeError("Invocation outcome outbox is unavailable");
|
|
75
|
+
return a.enqueue(n, r, i);
|
|
76
|
+
} }, I = async (e) => {
|
|
77
|
+
let t = `${e.kind}.${e.name}`, n = Date.now(), r = "ok";
|
|
78
|
+
try {
|
|
79
|
+
if (e.interceptor) {
|
|
80
|
+
let t = g.tryPromise({
|
|
81
|
+
try: () => e.runExecutor(),
|
|
82
|
+
catch: (e) => e
|
|
83
|
+
}), n = e.interceptor(t, {
|
|
84
|
+
tag: e.name,
|
|
85
|
+
kind: e.kind,
|
|
86
|
+
input: e.input,
|
|
87
|
+
subject: e.requestContext.subject,
|
|
88
|
+
traceId: e.requestContext.traceId,
|
|
89
|
+
...e.enqueueOutcome === void 0 ? {} : { enqueueOutcome: e.enqueueOutcome },
|
|
90
|
+
...e.requestContext.spanId === void 0 ? {} : { spanId: e.requestContext.spanId },
|
|
91
|
+
...e.target !== void 0 && e.target.length > 0 ? { target: e.target } : {},
|
|
92
|
+
...M(e.requestContext)
|
|
93
|
+
}), r = await g.runPromiseExit(n, e.requestContext.signal === void 0 ? void 0 : { signal: e.requestContext.signal });
|
|
94
|
+
if (_.isSuccess(r)) return r.value;
|
|
95
|
+
throw h.squash(r.cause);
|
|
96
|
+
}
|
|
97
|
+
return await e.runExecutor();
|
|
98
|
+
} catch (e) {
|
|
99
|
+
throw r = "error", e;
|
|
100
|
+
} finally {
|
|
101
|
+
e.recordMetric?.({
|
|
102
|
+
kind: "rpc",
|
|
103
|
+
tag: t,
|
|
104
|
+
durationMs: Date.now() - n,
|
|
105
|
+
status: r
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}, L = (e) => y(e) || u(e), R = 3, z = (e) => new Promise((t) => setTimeout(t, e)), B = async (e, t) => {
|
|
109
|
+
let n = t?.delay ?? ((e) => z(e * 20 + Math.floor(Math.random() * 30))), r = t?.attempts ?? 3;
|
|
110
|
+
for (let t = 1;; t++) try {
|
|
111
|
+
return await e();
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (t >= r || !L(e)) throw u(e) ? e.conflict : e;
|
|
114
|
+
await n(t);
|
|
115
|
+
}
|
|
116
|
+
}, V = (e) => (t, n, r) => I({
|
|
117
|
+
name: t.descriptor.name,
|
|
118
|
+
kind: "mutation",
|
|
119
|
+
input: n,
|
|
120
|
+
requestContext: r,
|
|
121
|
+
...F(e.outcomeOutbox, r),
|
|
122
|
+
target: N(t),
|
|
123
|
+
...e.interceptor ? { interceptor: e.interceptor } : {},
|
|
124
|
+
...e.recordMetric ? { recordMetric: e.recordMetric } : {},
|
|
125
|
+
runExecutor: async () => {
|
|
126
|
+
let i = Date.now();
|
|
127
|
+
await q(t, "mutation", { defaultDeny: e.defaultDeny === !0 })(n, r);
|
|
128
|
+
let a = {
|
|
129
|
+
...r,
|
|
130
|
+
subject: S(r.subject)
|
|
131
|
+
};
|
|
132
|
+
await k(t.descriptor, "mutation", a, n);
|
|
133
|
+
let o = await j(a), s = e.resolveStore === void 0 ? e.store : await e.resolveStore(o), c = [], u = [], p = await B(async () => s.transactional(async (a) => {
|
|
134
|
+
c.length = 0, u.length = 0, a[Symbol.for("@voltro/runtime:tx-fold-releases")] = u, a[l] = /* @__PURE__ */ new Map();
|
|
135
|
+
let p = t.descriptor.undo?.capture === !1 ? void 0 : e.undoCapture?.(a), m = p ? p.tx : a, h = f(m), _ = e.buildContext(o, h.tx, {
|
|
136
|
+
committedStore: s,
|
|
137
|
+
afterCommit: (e) => {
|
|
138
|
+
c.push(e);
|
|
139
|
+
}
|
|
140
|
+
}), v = e.measureSync ? e.measureSync(() => t.executor(n, _)) : t.executor(n, _), y = g.isEffect(v) ? await e.runEffect(D(v, o.subject), _.store) : await v;
|
|
141
|
+
if (await P({
|
|
142
|
+
store: _.store,
|
|
143
|
+
target: t.descriptor.target,
|
|
144
|
+
procedure: t.descriptor.name,
|
|
145
|
+
input: n,
|
|
146
|
+
output: y
|
|
147
|
+
}), p && await p.persist(_.store, {
|
|
148
|
+
tag: t.descriptor.name,
|
|
149
|
+
subject: o.subject,
|
|
150
|
+
traceId: r.traceId
|
|
151
|
+
}), await d({
|
|
152
|
+
touched: h.drain(),
|
|
153
|
+
store: _.store,
|
|
154
|
+
subject: o.subject
|
|
155
|
+
}), e.beforeMutationCommit !== void 0) {
|
|
156
|
+
let r = N(t), a = e.beforeMutationCommit({
|
|
157
|
+
tag: t.descriptor.name,
|
|
158
|
+
kind: "mutation",
|
|
159
|
+
input: n,
|
|
160
|
+
output: y,
|
|
161
|
+
subject: o.subject,
|
|
162
|
+
traceId: o.traceId,
|
|
163
|
+
store: _.store,
|
|
164
|
+
..._.outbox === void 0 ? {} : { outbox: _.outbox },
|
|
165
|
+
startedAt: i,
|
|
166
|
+
durationMs: Math.max(0, Date.now() - i),
|
|
167
|
+
...o.spanId === void 0 ? {} : { spanId: o.spanId },
|
|
168
|
+
...r.length > 0 ? { target: r } : {},
|
|
169
|
+
...M(o)
|
|
170
|
+
});
|
|
171
|
+
await e.runEffect(D(a, o.subject), _.store);
|
|
172
|
+
}
|
|
173
|
+
return y;
|
|
174
|
+
}), { ...e.replayAttempts === void 0 ? {} : { attempts: e.replayAttempts } });
|
|
175
|
+
if (u.length > 0) {
|
|
176
|
+
let t = e.buildContext(o, s, {
|
|
177
|
+
committedStore: s,
|
|
178
|
+
afterCommit: () => {}
|
|
179
|
+
}).store;
|
|
180
|
+
for (let e of u.splice(0)) await t.update(e.table, e.pk, e.patch);
|
|
181
|
+
}
|
|
182
|
+
for (let e of c) await e();
|
|
183
|
+
return e.settleCacheInvalidations !== void 0 && await e.settleCacheInvalidations(), p;
|
|
184
|
+
}
|
|
185
|
+
}), H = (e) => (t, n, r, i) => I({
|
|
186
|
+
name: t.name,
|
|
187
|
+
kind: "workflow",
|
|
188
|
+
input: n,
|
|
189
|
+
requestContext: r,
|
|
190
|
+
...F(e.outcomeOutbox, r),
|
|
191
|
+
...e.interceptor ? { interceptor: e.interceptor } : {},
|
|
192
|
+
...e.recordMetric ? { recordMetric: e.recordMetric } : {},
|
|
193
|
+
runExecutor: async () => (await O(t, r.subject, n, e.defaultDeny), i())
|
|
194
|
+
}), U = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, W = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, G = (e) => {
|
|
195
|
+
let t = e.descriptor.source;
|
|
196
|
+
return t == null ? [] : typeof t == "string" ? [t] : [...t];
|
|
197
|
+
}, K = (e, t, n) => (r) => () => g.runPromise(C(r, e.descriptor.guards, t, {
|
|
198
|
+
defaultDeny: n === !0,
|
|
199
|
+
procedure: e.descriptor.name
|
|
200
|
+
})), q = (e, t, n = {}) => async (r, i) => {
|
|
201
|
+
let a = i.subject;
|
|
202
|
+
n.bindReplayAuthority?.({
|
|
203
|
+
tag: e.descriptor.name,
|
|
204
|
+
kind: t,
|
|
205
|
+
input: r,
|
|
206
|
+
subject: a,
|
|
207
|
+
traceId: i.traceId,
|
|
208
|
+
...i.surface === void 0 ? {} : { surface: i.surface },
|
|
209
|
+
...i.publicApi === void 0 ? {} : { publicApi: i.publicApi },
|
|
210
|
+
...i.remoteAddr === void 0 ? {} : { remoteAddr: i.remoteAddr }
|
|
211
|
+
});
|
|
212
|
+
let o = await K(e, r, n.defaultDeny)(a)();
|
|
213
|
+
if (o) throw o;
|
|
214
|
+
}, J = (e, t) => e.rowFilter !== void 0 || a() === void 0 ? t(e) : g.promise(() => j(e)).pipe(g.flatMap((e) => {
|
|
215
|
+
let n = t(e);
|
|
216
|
+
return g.isEffect(n) ? n : g.succeed(n);
|
|
217
|
+
})), Y = (e, t) => X(e, t, /* @__PURE__ */ new Set()), X = (o, s, l) => (u, d) => (f) => {
|
|
218
|
+
if (f.rowFilter === void 0 && a() !== void 0) return J(f, (e) => X(o, s, l)(u, d)(e));
|
|
219
|
+
let p = s ?? (f.connection?.transport === "http" ? "rpc" : "subscriptions"), h = (e) => o.workloadMetrics ? o.workloadMetrics.measureSync(p, e) : e(), _ = (e, t) => {
|
|
220
|
+
let n = o.provideEffect(e, t);
|
|
221
|
+
return o.workloadMetrics ? m(n, o.workloadMetrics, p) : n;
|
|
222
|
+
}, v = o.buildContext(f), y = K(u, d, o.defaultDeny)(f.subject), b = async () => {
|
|
223
|
+
let e = await y();
|
|
224
|
+
if (e) throw e;
|
|
225
|
+
let t = {
|
|
226
|
+
...f,
|
|
227
|
+
subject: S(f.subject)
|
|
228
|
+
}, n = o.buildContext(await j(t)), r = h(() => u.executor(d, n)), i = g.isEffect(r) ? await T(_(D(r, t.subject), n.store), f.signal === void 0 ? void 0 : { signal: f.signal }) : U(await Promise.resolve(r)), a = await y();
|
|
229
|
+
if (a) throw a;
|
|
230
|
+
return i;
|
|
231
|
+
}, C = (e, t = n()) => {
|
|
232
|
+
let r = U(e);
|
|
233
|
+
if (W(r)) {
|
|
234
|
+
let e = o.finalize(r, f), t = G(u);
|
|
235
|
+
if (t.length === 0) return e;
|
|
236
|
+
let n = e.dependentTables ?? [];
|
|
237
|
+
return {
|
|
238
|
+
...e,
|
|
239
|
+
dependentTables: [.../* @__PURE__ */ new Set([...n, ...t])]
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
__voltroComputed: !0,
|
|
244
|
+
value: r,
|
|
245
|
+
dependentTables: [.../* @__PURE__ */ new Set([...G(u), ...t])],
|
|
246
|
+
tenantId: f.subject?.tenantId ?? null,
|
|
247
|
+
recompute: b
|
|
248
|
+
};
|
|
249
|
+
}, w = (e, t) => {
|
|
250
|
+
let n = C(e, t);
|
|
251
|
+
return c(n) ? g.tryPromise({
|
|
252
|
+
try: y,
|
|
253
|
+
catch: (e) => e
|
|
254
|
+
}).pipe(g.flatMap((e) => e ? g.fail(e) : g.succeed(n))) : n;
|
|
255
|
+
}, E = (e, t) => {
|
|
256
|
+
let n = w(e, t);
|
|
257
|
+
return g.isEffect(n) ? n : g.succeed(n);
|
|
258
|
+
}, O = () => {
|
|
259
|
+
let n = o.computedCache, r = u.descriptor.cache;
|
|
260
|
+
if (n === void 0 || r === void 0 || l.has(u.descriptor.name)) return;
|
|
261
|
+
let i = n.policyFor(r);
|
|
262
|
+
if (i === void 0) return;
|
|
263
|
+
let a = f.subject, s = G(u), c = t({
|
|
264
|
+
name: u.descriptor.name,
|
|
265
|
+
codeIdentity: n.codeIdentity,
|
|
266
|
+
output: u.descriptor.output,
|
|
267
|
+
input: u.descriptor.input,
|
|
268
|
+
decodedInput: d,
|
|
269
|
+
scope: i.scope,
|
|
270
|
+
subject: a,
|
|
271
|
+
rowFilter: f.rowFilter,
|
|
272
|
+
declaredSources: s
|
|
273
|
+
});
|
|
274
|
+
if ("bypass" in c) c.bypass === "input-not-encodable" && n.notice(u.descriptor.name, c.bypass, `${u.descriptor.name}: \`cache:\` NOT applied — the input does not encode through its \`input\` schema, so it has no key.`);
|
|
275
|
+
else return e({
|
|
276
|
+
cache: n,
|
|
277
|
+
policy: i,
|
|
278
|
+
key: c.key,
|
|
279
|
+
name: u.descriptor.name,
|
|
280
|
+
sources: s,
|
|
281
|
+
output: u.descriptor.output,
|
|
282
|
+
subject: f.subject,
|
|
283
|
+
rowFilter: f.rowFilter,
|
|
284
|
+
ctx: v,
|
|
285
|
+
...f.signal === void 0 ? {} : { signal: f.signal },
|
|
286
|
+
execute: (e, t) => {
|
|
287
|
+
let n = h(() => u.executor(d, e));
|
|
288
|
+
return g.isEffect(n) ? T(_(D(n, t), v.store), f.signal === void 0 ? void 0 : { signal: f.signal }) : Promise.resolve(n);
|
|
289
|
+
},
|
|
290
|
+
onDescriptor: () => {
|
|
291
|
+
l.add(u.descriptor.name);
|
|
292
|
+
},
|
|
293
|
+
isDescriptor: (e) => W(U(e)),
|
|
294
|
+
unwrap: (e) => U(e)
|
|
295
|
+
}).pipe(g.flatMap(({ value: e, dependencies: t }) => E(e, t)));
|
|
296
|
+
}, k = () => {
|
|
297
|
+
i(u.descriptor.name, G(u)), r();
|
|
298
|
+
let e = O();
|
|
299
|
+
if (e !== void 0) return e;
|
|
300
|
+
let t = h(() => u.executor(d, v));
|
|
301
|
+
return g.isEffect(t) ? _(D(t, f.subject), v.store).pipe(g.flatMap(E)) : t instanceof Promise ? g.promise(() => t).pipe(g.flatMap(E)) : w(t);
|
|
302
|
+
}, A = () => {
|
|
303
|
+
let e = u.descriptor.guards;
|
|
304
|
+
return (!e || e.length === 0) && o.defaultDeny !== !0 && f.subject.type !== "service" ? k() : x(f.subject, e, d, {
|
|
305
|
+
defaultDeny: o.defaultDeny === !0,
|
|
306
|
+
procedure: u.descriptor.name
|
|
307
|
+
}).pipe(g.flatMap((e) => {
|
|
308
|
+
if (e) return g.fail(e);
|
|
309
|
+
let t = k();
|
|
310
|
+
return g.isEffect(t) ? t : g.succeed(t);
|
|
311
|
+
}));
|
|
312
|
+
};
|
|
313
|
+
if (!o.interceptor) return A();
|
|
314
|
+
let N = g.suspend(() => {
|
|
315
|
+
let e = A();
|
|
316
|
+
return g.isEffect(e) ? e : g.succeed(e);
|
|
317
|
+
});
|
|
318
|
+
return o.interceptor(N, {
|
|
319
|
+
tag: u.descriptor.name,
|
|
320
|
+
kind: "query",
|
|
321
|
+
input: d,
|
|
322
|
+
subject: f.subject,
|
|
323
|
+
traceId: f.traceId,
|
|
324
|
+
...f.spanId === void 0 ? {} : { spanId: f.spanId },
|
|
325
|
+
...M(f)
|
|
326
|
+
});
|
|
327
|
+
}, Z = (e) => async (t, n, r) => {
|
|
328
|
+
let i = await j(r), a = Y(e, "rpc")(t, n)(i), o = g.isEffect(a) ? await E(a) : a;
|
|
329
|
+
if (c(o)) return o.value;
|
|
330
|
+
let s = e.buildContext(i), l = await e.queryRows(o, i, s.store), u = await K(t, n, e.defaultDeny)(i.subject)();
|
|
331
|
+
if (u) throw u;
|
|
332
|
+
return l;
|
|
333
|
+
}, Q = (e) => (t, n, r, i) => {
|
|
334
|
+
let a = !1, s;
|
|
335
|
+
return (async () => {
|
|
336
|
+
try {
|
|
337
|
+
let l = await j(r), u = Y(e, "subscriptions")(t, n)(l), d = g.isEffect(u) ? await E(u) : u, f = (e) => i(e), p = c(d) ? await e.subscribeComputed(d, f, l) : await e.subscribeDescriptor(d, f, l, K(t, n, e.defaultDeny)(l.subject), o(l.subject));
|
|
338
|
+
a ? p() : s = p;
|
|
339
|
+
} catch (e) {
|
|
340
|
+
i({
|
|
341
|
+
_tag: "error",
|
|
342
|
+
error: e instanceof Error ? {
|
|
343
|
+
message: e.message,
|
|
344
|
+
..."_tag" in e ? { _tag: e._tag } : {}
|
|
345
|
+
} : e
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
})(), () => {
|
|
349
|
+
a = !0, s?.();
|
|
350
|
+
};
|
|
351
|
+
}, $ = (e) => (t, n, r) => I({
|
|
352
|
+
name: t.descriptor.name,
|
|
353
|
+
kind: "action",
|
|
354
|
+
input: n,
|
|
355
|
+
requestContext: r,
|
|
356
|
+
...F(e.outcomeOutbox, r),
|
|
357
|
+
target: N(t),
|
|
358
|
+
...e.interceptor ? { interceptor: e.interceptor } : {},
|
|
359
|
+
...e.recordMetric ? { recordMetric: e.recordMetric } : {},
|
|
360
|
+
runExecutor: async () => {
|
|
361
|
+
await q(t, "action", { defaultDeny: e.defaultDeny === !0 })(n, r);
|
|
362
|
+
let a = {
|
|
363
|
+
...r,
|
|
364
|
+
subject: S(r.subject)
|
|
365
|
+
};
|
|
366
|
+
await k(t.descriptor, "action", a, n);
|
|
367
|
+
let o = e.buildContext(await j(a));
|
|
368
|
+
i(t.descriptor.name, G(t));
|
|
369
|
+
let s = e.measureSync ? e.measureSync(() => t.executor(n, o)) : t.executor(n, o), c = g.isEffect(s) ? await e.runEffect(D(s, a.subject), o.store) : await s;
|
|
370
|
+
return e.settleCacheInvalidations !== void 0 && await e.settleCacheInvalidations(), c;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
//#endregion
|
|
374
|
+
export { R as DEFAULT_MUTATION_REPLAY_ATTEMPTS, P as applyDeclaredRelations, $ as makeActionRunner, q as makeMutationReplayAdmission, V as makeMutationRunner, Z as makeOneShotQueryRunner, Y as makeQueryDescriptorProducer, K as makeQueryReauthorizer, Q as makeQuerySubscriber, H as makeWorkflowStartRunner, E as runProvidedEffect, B as runWithDeadlockRetry, j as withRowFilter, J as withScopedRequest };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { SchemaAST as e } from "effect";
|
|
2
|
+
//#region src/serverOnlyAudit.ts
|
|
3
|
+
var t = (t) => {
|
|
4
|
+
let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = (t) => {
|
|
5
|
+
if (!r.has(t)) switch (r.add(t), t.encoding !== void 0 && i(e.toEncoded(t)), t._tag) {
|
|
6
|
+
case "Objects":
|
|
7
|
+
for (let e of t.propertySignatures) typeof e.name == "string" && n.add(e.name), i(e.type);
|
|
8
|
+
for (let e of t.indexSignatures) i(e.type);
|
|
9
|
+
break;
|
|
10
|
+
case "Arrays":
|
|
11
|
+
for (let e of t.elements) i(e);
|
|
12
|
+
for (let e of t.rest) i(e);
|
|
13
|
+
break;
|
|
14
|
+
case "Union":
|
|
15
|
+
for (let e of t.types) i(e);
|
|
16
|
+
break;
|
|
17
|
+
case "Suspend": i(t.thunk());
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return i(t.ast), n;
|
|
21
|
+
}, n = (t) => {
|
|
22
|
+
let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = (t) => {
|
|
23
|
+
if (t.encoding !== void 0) return i(e.toEncoded(t));
|
|
24
|
+
switch (t._tag) {
|
|
25
|
+
case "Null": return !0;
|
|
26
|
+
case "Literal": return t.literal === null;
|
|
27
|
+
case "Union": return t.types.length > 0 && t.types.every(i);
|
|
28
|
+
case "Suspend": return i(t.thunk());
|
|
29
|
+
default: return !1;
|
|
30
|
+
}
|
|
31
|
+
}, a = (t) => {
|
|
32
|
+
if (!r.has(t)) switch (r.add(t), t.encoding !== void 0 && a(e.toEncoded(t)), t._tag) {
|
|
33
|
+
case "Objects":
|
|
34
|
+
for (let e of t.propertySignatures) typeof e.name == "string" && i(e.type) && n.add(e.name), a(e.type);
|
|
35
|
+
break;
|
|
36
|
+
case "Arrays":
|
|
37
|
+
for (let e of t.elements) a(e);
|
|
38
|
+
for (let e of t.rest) a(e);
|
|
39
|
+
break;
|
|
40
|
+
case "Union":
|
|
41
|
+
for (let e of t.types) a(e);
|
|
42
|
+
break;
|
|
43
|
+
case "Suspend": a(t.thunk());
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return a(t.ast), n;
|
|
47
|
+
}, r = (e, r) => {
|
|
48
|
+
let i = e.source === void 0 ? [] : Array.isArray(e.source) ? e.source : [e.source];
|
|
49
|
+
if (i.length === 0) return [];
|
|
50
|
+
let a = t(e.output), o = n(e.output), s = [];
|
|
51
|
+
for (let t of i) for (let n of r.get(t) ?? []) a.has(n) && !o.has(n) && s.push({
|
|
52
|
+
query: e.name,
|
|
53
|
+
table: t,
|
|
54
|
+
column: n
|
|
55
|
+
});
|
|
56
|
+
return s;
|
|
57
|
+
}, i = (e) => {
|
|
58
|
+
if (e.length !== 0) return `A wire-reachable query exposes a server-only column:\n${e.map((e) => ` • query '${e.query}' output declares '${e.column}' — a .serverOnly() column of '${e.table}'`).join("\n")}\nThree ways out, in order of preference:\n 1. Omit the column from the query's output schema. The crud.* read helpers strip these automatically.\n 2. Keep the KEY but type it \`Schema.Null\` — for a view that must stay wire-compatible (an importer that breaks if the key vanishes) while never sending a value. The audit accepts that, because the schema then PROVES no value can flow instead of promising it. Pair it with a \`hasX\` boolean.\n 3. Drop the .serverOnly() marker, if the column may in fact reach a client.\nNote the audit reads the DECLARED shape, not what your handler emits: a field typed \`string\` that you always set to null still fails, and should — the next edit to that handler is one line away from sending it.`;
|
|
59
|
+
}, a = (e, t) => e.cache?.scope === "global" ? (e.source === void 0 ? [] : Array.isArray(e.source) ? e.source : [e.source]).filter((e) => t.has(e)).map((t) => ({
|
|
60
|
+
query: e.name,
|
|
61
|
+
table: t
|
|
62
|
+
})) : [], o = (e) => {
|
|
63
|
+
if (e.length !== 0) return `A cached query shares one entry across tenants:\n${e.map((e) => ` • query '${e.query}' caches scope:'global' while reading '${e.table}', a tenant()-scoped table`).join("\n")}\n\nscope:'global' stores ONE entry for every caller. On a tenant-scoped table the\nrows depend on who asked, so the first caller's rows are served to the next one.\n\nUse scope:'tenant' — one entry per org, none shared across orgs. Use 'subject'\nif the result also depends on WHICH person is asking, and 'global' only for data\nthat depends on neither.`;
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { a as cacheScopeLeaks, o as formatCacheScopeLeaks, i as formatServerOnlyLeaks, t as schemaPropertyNames, r as serverOnlyLeaks };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Effect as e, Layer as t } from "effect";
|
|
2
|
+
//#region src/serverTracer.ts
|
|
3
|
+
var n = Symbol.for("@voltro/runtime:serverTracer"), r = (() => {
|
|
4
|
+
let e = globalThis;
|
|
5
|
+
return e[n] ??= {};
|
|
6
|
+
})(), i = (e) => {
|
|
7
|
+
e === void 0 ? delete r.tracer : r.tracer = e;
|
|
8
|
+
}, a = () => r.tracer, o = t.effectDiscard(e.flatMap(e.tracer, (t) => e.sync(() => {
|
|
9
|
+
i(t);
|
|
10
|
+
}))), s = (t) => {
|
|
11
|
+
let n = r.tracer;
|
|
12
|
+
return n === void 0 ? t : e.withTracer(t, n);
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { o as publishServerTracerLayer, a as serverTracer, i as setServerTracer, s as withServerTracer };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createHash as e, randomBytes as t, timingSafeEqual as n } from "node:crypto";
|
|
2
|
+
import { SERVICE_NAME_PATTERN as r, serviceSubject as i } from "@voltro/protocol";
|
|
3
|
+
//#region src/serviceCredentials.ts
|
|
4
|
+
var a = "vsvc_", o = /^vsvc_[A-Za-z0-9_-]{43}$/, s = () => `${a}${t(32).toString("base64url")}`, c = (e) => o.test(e), l = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/-/g, "_").toUpperCase(), u = (e) => `VOLTRO_SERVICE_CALLER_${l(e)}_TOKEN`, d = (e) => `${u(e)}_NEXT`, f = (e) => `VOLTRO_API_${l(e)}_TOKEN`, p = (e) => `VOLTRO_API_${l(e)}_URL`, m = (e) => {
|
|
5
|
+
for (let t of Object.keys(e)) if (!r.test(t)) throw Error(`serviceCallers: ${JSON.stringify(t)} is not an app name — letters, digits and dashes, starting with a letter, at most 56 characters. It is the name the calling app binds this api under and the name its procedures list in \`service: { callers }\`.`);
|
|
6
|
+
}, h = (t) => e("sha256").update(t).digest(), g = (e, t) => n(e, h(t)), _ = (e, t) => [e[u(t)], e[d(t)]].filter((e) => typeof e == "string" && e !== ""), v = (e) => {
|
|
7
|
+
m(e.callers);
|
|
8
|
+
let t = Object.keys(e.callers), n = e.env ?? (() => process.env);
|
|
9
|
+
return {
|
|
10
|
+
id: "voltro-service",
|
|
11
|
+
claimsBearerPrefix: a,
|
|
12
|
+
verifyConfig: () => {
|
|
13
|
+
let e = n(), r = [], i = [];
|
|
14
|
+
for (let n of t) {
|
|
15
|
+
let t = _(e, n);
|
|
16
|
+
t.length === 0 && r.push(u(n));
|
|
17
|
+
for (let [e, r] of t.entries()) c(r) || i.push(e === 0 ? u(n) : d(n));
|
|
18
|
+
}
|
|
19
|
+
if (r.length > 0) throw Error(`serviceCallers: no token for ${r.join(", ")}. Every app listed in \`serviceCallers\` needs the credential it presents. \`voltro dev\` mints one per caller into both apps' \`.env.local\`; in production set the variable to the same value as the caller's \`VOLTRO_API_<NAME>_TOKEN\` (\`voltro secret generate service\` prints a fresh one).`);
|
|
20
|
+
if (i.length > 0) throw Error(`serviceCallers: ${i.join(", ")} ${i.length === 1 ? "is" : "are"} not a service token (\`${a}\` followed by 43 base64url characters). Generate one with \`voltro secret generate service\` rather than choosing a value by hand.`);
|
|
21
|
+
},
|
|
22
|
+
resolve: (e) => {
|
|
23
|
+
let r = e.headers.authorization ?? e.headers.Authorization;
|
|
24
|
+
if (r === void 0) return { kind: "skip" };
|
|
25
|
+
let a = /^Bearer\s+(\S+)$/i.exec(r)?.[1];
|
|
26
|
+
if (a === void 0 || !a.startsWith("vsvc_")) return { kind: "skip" };
|
|
27
|
+
let o = h(a), s = n(), c;
|
|
28
|
+
for (let e of t) for (let t of _(s, e)) g(o, t) && c === void 0 && (c = e);
|
|
29
|
+
return c === void 0 ? {
|
|
30
|
+
kind: "failed",
|
|
31
|
+
reason: "service credential matches no caller in `serviceCallers`"
|
|
32
|
+
} : {
|
|
33
|
+
kind: "matched",
|
|
34
|
+
subject: i(c)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { a as SERVICE_TOKEN_PREFIX, f as apiBindingTokenEnv, p as apiBindingUrlEnv, m as assertServiceCallersConfig, c as isWellFormedServiceToken, s as mintServiceToken, d as serviceCallerNextTokenEnv, v as serviceCallerStrategy, u as serviceCallerTokenEnv, l as serviceEnvSegment };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/setReadScopes.ts
|
|
2
|
+
var e = [
|
|
3
|
+
"crossTenant",
|
|
4
|
+
"includeDeleted",
|
|
5
|
+
"includeExpired"
|
|
6
|
+
], t = (t, n) => {
|
|
7
|
+
let r = (t, i) => {
|
|
8
|
+
let a = t;
|
|
9
|
+
for (let t of e) i?.[t] === !0 && a[t] !== !0 && (a = {
|
|
10
|
+
...a,
|
|
11
|
+
[t]: !0
|
|
12
|
+
});
|
|
13
|
+
let o = a.setOp;
|
|
14
|
+
if (o === void 0) return n(a);
|
|
15
|
+
if (o.queries.length < 2) throw Error("A set operation requires at least two inputs");
|
|
16
|
+
let s = o.queries.map((e) => r(e, a));
|
|
17
|
+
return s.every((e, t) => e === o.queries[t]) ? a : {
|
|
18
|
+
...a,
|
|
19
|
+
setOp: {
|
|
20
|
+
...o,
|
|
21
|
+
queries: s
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
return r(t);
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { t as mapSetReadScopes };
|