@voltro/runtime 0.85.0 → 0.86.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 +666 -0
- package/THIRD-PARTY-NOTICES.md +5 -33
- 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 +38 -0
- package/dist/apiKeyUsage.js +33 -0
- package/dist/apiKeys.js +223 -0
- package/dist/apiKeysWiring.js +114 -0
- package/dist/approvalBuiltins.js +10 -0
- package/dist/approvals.js +269 -0
- package/dist/authMiddlewareLayer.js +47 -0
- package/dist/bindEvent.js +72 -0
- package/dist/bootListener.js +76 -0
- package/dist/bootRefusal.js +7 -0
- package/dist/bootStoreCodec.js +70 -0
- package/dist/businessRules.js +67 -0
- package/dist/changeClaimsTable.js +12 -0
- package/dist/circuitBreaker.js +72 -0
- package/dist/columnOnUpdate.js +23 -0
- package/dist/composeAnalytics.js +108 -0
- package/dist/computedQuery.js +4 -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 +54 -0
- package/dist/coordinatedSchedule.js +139 -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 +679 -0
- package/dist/dataloader.js +61 -0
- package/dist/declaredTablesGuard.js +48 -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 +447 -0
- package/dist/effectStore.js +71 -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 +25 -0
- package/dist/fieldCipher.js +61 -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/httpClientSsrf.js +49 -0
- package/dist/httpClientTracing.js +11 -0
- package/dist/httpCompression.js +76 -0
- package/dist/httpKeepAlive.js +12 -0
- package/dist/httpRouteMounts.js +47 -0
- package/dist/idempotencyStore.js +70 -0
- package/dist/idleDetector.js +21 -0
- package/dist/index.d.ts +88 -69
- package/dist/index.js +144 -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 +32 -0
- package/dist/matcher.js +304 -0
- package/dist/memoryColumnDefaults.js +11 -0
- package/dist/memoryQueryJoins.js +114 -0
- package/dist/metrics.js +161 -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 +66 -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 +239 -0
- package/dist/requestLoader.js +7 -0
- package/dist/resumeCensus.js +28 -0
- package/dist/revalidation.js +22 -0
- package/dist/rowFilter.js +65 -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 +992 -0
- package/dist/runAsSystem.js +23 -0
- package/dist/rywPositionStore.js +84 -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 +835 -0
- package/dist/schemaRegistry.js +65 -0
- package/dist/secretsResolver.js +35 -0
- package/dist/securityHeaders.js +33 -0
- package/dist/servePipeline.js +305 -0
- package/dist/serverOnlyAudit.js +66 -0
- package/dist/serverTracer.js +15 -0
- package/dist/serviceCredentials.js +40 -0
- package/dist/singleNodeOrchestrator.js +91 -0
- package/dist/sourceResolution.js +42 -0
- package/dist/storeMiddleware.js +880 -0
- package/dist/storeQuery.js +204 -0
- package/dist/storeRead.js +10 -0
- package/dist/subscriber.js +7 -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 +23 -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 +34 -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 +114 -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 +7 -7
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { crdtCompactMaxBytes as e, crdtMaxDocumentBytes as t, crdtMaxUpdateBytes as n, crdtMigrationsFor as r, crdtRebaseMaxBytes as i, describeCrdtState as a } from "./crdtMerge.js";
|
|
2
|
+
import { CRDT_VERSIONS_TABLE as o } from "./crdtVersionsTable.js";
|
|
3
|
+
import { and as s, eq as c } from "@voltro/database";
|
|
4
|
+
import { ValidationError as l } from "@voltro/protocol";
|
|
5
|
+
import { crdtSchemaVersionOf as u, decodeSealedLog as d, defaultCrdtBackend as f, emptyCrdtState as p, latestCrdtSchemaVersion as m, sealedLogEpoch as h } from "@voltro/local-first";
|
|
6
|
+
//#region src/crdtHistory.ts
|
|
7
|
+
var g = (e, t, n, r) => e.query({
|
|
8
|
+
table: t,
|
|
9
|
+
predicate: n,
|
|
10
|
+
order: [{
|
|
11
|
+
column: "createdAt",
|
|
12
|
+
direction: "desc"
|
|
13
|
+
}],
|
|
14
|
+
take: r,
|
|
15
|
+
skip: void 0,
|
|
16
|
+
projection: void 0
|
|
17
|
+
}), _ = async (e, t) => {
|
|
18
|
+
let n = (await e.query({
|
|
19
|
+
table: t.table,
|
|
20
|
+
predicate: {
|
|
21
|
+
column: "id",
|
|
22
|
+
op: "eq",
|
|
23
|
+
value: t.id
|
|
24
|
+
},
|
|
25
|
+
order: [],
|
|
26
|
+
take: 1,
|
|
27
|
+
skip: void 0,
|
|
28
|
+
projection: void 0
|
|
29
|
+
}))[0];
|
|
30
|
+
if (n === void 0) return;
|
|
31
|
+
let r = n[t.column];
|
|
32
|
+
return { state: r instanceof Uint8Array ? r : void 0 };
|
|
33
|
+
}, v = (e) => ({
|
|
34
|
+
id: String(e.id),
|
|
35
|
+
reason: e.reason,
|
|
36
|
+
label: e.label ?? null,
|
|
37
|
+
epoch: e.epoch ?? null,
|
|
38
|
+
createdBy: e.createdBy ?? null,
|
|
39
|
+
createdAt: e.createdAt instanceof Date ? e.createdAt : new Date(String(e.createdAt))
|
|
40
|
+
}), y = (e) => {
|
|
41
|
+
let t = a(e);
|
|
42
|
+
return t === void 0 ? d(e) === void 0 ? null : h(e) || null : t.epoch;
|
|
43
|
+
}, b = async (e, t, n, r, i, a) => v(await e.insert(o, {
|
|
44
|
+
tableName: t.table,
|
|
45
|
+
rowId: t.id,
|
|
46
|
+
columnName: t.column,
|
|
47
|
+
state: n,
|
|
48
|
+
reason: r,
|
|
49
|
+
label: i ?? null,
|
|
50
|
+
epoch: y(n),
|
|
51
|
+
createdBy: a ?? null
|
|
52
|
+
})), x = async (e, t) => {
|
|
53
|
+
let n = await _(e, t);
|
|
54
|
+
if (n !== void 0) return b(e, t, n.state ?? p(), "snapshot", t.label, t.createdBy);
|
|
55
|
+
}, S = async (e, t) => await _(e, t) === void 0 ? [] : (await g(e, o, s(c("tableName", t.table), c("rowId", t.id), c("columnName", t.column)))).map(v), C = async (e, t) => {
|
|
56
|
+
let n = (await g(e, o, c("id", t.versionId), 1))[0];
|
|
57
|
+
if (n === void 0) return;
|
|
58
|
+
let r = {
|
|
59
|
+
table: String(n.tableName),
|
|
60
|
+
id: String(n.rowId),
|
|
61
|
+
column: String(n.columnName)
|
|
62
|
+
}, i = await _(e, r);
|
|
63
|
+
if (i === void 0) return;
|
|
64
|
+
let s = n.state;
|
|
65
|
+
if (!(s instanceof Uint8Array)) return;
|
|
66
|
+
let u = i.state ?? p();
|
|
67
|
+
if (a(u) === void 0 || a(s) === void 0) throw new l({
|
|
68
|
+
field: r.column,
|
|
69
|
+
message: "crdt.sealedRestoreIsClientSide",
|
|
70
|
+
params: { table: r.table }
|
|
71
|
+
});
|
|
72
|
+
let d = await b(e, r, u, "restore", `before restoring ${t.versionId}`, t.createdBy);
|
|
73
|
+
return await e.update(r.table, r.id, { [r.column]: f.restoreTo(u, s) }), d;
|
|
74
|
+
}, w = async (e, t) => {
|
|
75
|
+
let n = (await g(e, o, c("id", t.versionId), 1))[0];
|
|
76
|
+
if (n === void 0) return;
|
|
77
|
+
let r = {
|
|
78
|
+
table: String(n.tableName),
|
|
79
|
+
id: String(n.rowId),
|
|
80
|
+
column: String(n.columnName)
|
|
81
|
+
}, i = await _(e, r);
|
|
82
|
+
if (i === void 0) return;
|
|
83
|
+
let s = n.state;
|
|
84
|
+
if (s instanceof Uint8Array) {
|
|
85
|
+
if (a(s) !== void 0) throw new l({
|
|
86
|
+
field: r.column,
|
|
87
|
+
message: "crdt.openRestoreIsServerSide",
|
|
88
|
+
params: { table: r.table }
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
undoPoint: await b(e, r, i.state ?? p(), "restore", `before restoring ${t.versionId}`, t.createdBy),
|
|
92
|
+
versionLog: s
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}, T = async (r, l) => {
|
|
96
|
+
let u = await _(r, l);
|
|
97
|
+
if (u === void 0) return;
|
|
98
|
+
let d = u.state, f = await g(r, o, s(c("tableName", l.table), c("rowId", l.id), c("columnName", l.column)));
|
|
99
|
+
return {
|
|
100
|
+
bytes: d?.length ?? 0,
|
|
101
|
+
epoch: d === void 0 ? null : y(d),
|
|
102
|
+
authors: d === void 0 ? 0 : a(d)?.authors ?? 0,
|
|
103
|
+
versions: f.length,
|
|
104
|
+
limits: {
|
|
105
|
+
compactMaxBytes: e(),
|
|
106
|
+
rebaseMaxBytes: i(),
|
|
107
|
+
maxDocumentBytes: t(),
|
|
108
|
+
maxUpdateBytes: n()
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}, E = async (e, t) => {
|
|
112
|
+
let n = m(r(t.table, t.column)), i = t.batchSize ?? 200, a = 0, o = 0;
|
|
113
|
+
for (let r = 0;; r += i) {
|
|
114
|
+
let s = await e.query({
|
|
115
|
+
table: t.table,
|
|
116
|
+
predicate: void 0,
|
|
117
|
+
order: [{
|
|
118
|
+
column: "id",
|
|
119
|
+
direction: "asc"
|
|
120
|
+
}],
|
|
121
|
+
take: i,
|
|
122
|
+
skip: r,
|
|
123
|
+
projection: void 0
|
|
124
|
+
});
|
|
125
|
+
for (let r of s) {
|
|
126
|
+
a += 1;
|
|
127
|
+
let i = r[t.column];
|
|
128
|
+
i instanceof Uint8Array && i.length !== 0 && (u(i) >= n || (await e.update(t.table, r.id, { [t.column]: p() }), o += 1));
|
|
129
|
+
}
|
|
130
|
+
if (s.length < i) break;
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
scanned: a,
|
|
134
|
+
migrated: o
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
export { T as crdtCellStats, S as listCrdtVersions, E as migrateCrdtColumn, w as prepareSealedCrdtRestore, C as restoreCrdtVersion, x as snapshotCrdt };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { ValidationError as e } from "@voltro/protocol";
|
|
2
|
+
import { applyCrdtMigrations as t, applySealedFrame as n, defaultCrdtBackend as r, emptyCrdtState as i, mergeCrdtStates as a, setDefaultCrdtBackend as o } from "@voltro/local-first";
|
|
3
|
+
//#region src/crdtMerge.ts
|
|
4
|
+
var s = 524288, c = Symbol.for("@voltro/runtime:crdt-compact-max-bytes"), l = (e) => {
|
|
5
|
+
let t = globalThis;
|
|
6
|
+
t[c] = e;
|
|
7
|
+
}, u = () => {
|
|
8
|
+
let e = globalThis[c];
|
|
9
|
+
if (e != null) return e;
|
|
10
|
+
let t = process.env.VOLTRO_CRDT_COMPACT_MAX_BYTES;
|
|
11
|
+
if (t !== void 0 && t !== "") {
|
|
12
|
+
let e = Number(t);
|
|
13
|
+
if (Number.isFinite(e) && e >= 0) return e;
|
|
14
|
+
}
|
|
15
|
+
return s;
|
|
16
|
+
}, d = (e, t, n) => {
|
|
17
|
+
if (n instanceof Uint8Array && t instanceof Uint8Array) try {
|
|
18
|
+
let e = r.createDoc(t), i = r.createDoc(n);
|
|
19
|
+
return e.epoch() === i.epoch() ? i.encodeUpdateSince(e.stateVector()) : void 0;
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}, f = (e, t, n) => {
|
|
24
|
+
if (!(n instanceof Uint8Array) || !(t instanceof Uint8Array)) return n;
|
|
25
|
+
try {
|
|
26
|
+
return a(t, n);
|
|
27
|
+
} catch {
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
}, p = 1048576, m = 16777216, h = 4194304, g = Symbol.for("@voltro/runtime:crdt-admission"), _ = (e) => {
|
|
31
|
+
globalThis[g] = e;
|
|
32
|
+
}, v = () => globalThis[g] ?? {}, y = (e, t, n) => {
|
|
33
|
+
if (e != null) return e;
|
|
34
|
+
let r = process.env[t];
|
|
35
|
+
if (r !== void 0 && r !== "") {
|
|
36
|
+
let e = Number(r);
|
|
37
|
+
if (Number.isFinite(e) && e >= 0) return e;
|
|
38
|
+
}
|
|
39
|
+
return n;
|
|
40
|
+
}, b = () => y(v().maxUpdateBytes, "VOLTRO_CRDT_MAX_UPDATE_BYTES", p), x = () => y(v().maxDocumentBytes, "VOLTRO_CRDT_MAX_DOCUMENT_BYTES", m), S = () => y(v().rebaseMaxBytes, "VOLTRO_CRDT_REBASE_MAX_BYTES", h), C = (t, n, o) => {
|
|
41
|
+
if (!(o instanceof Uint8Array)) return;
|
|
42
|
+
let s = b();
|
|
43
|
+
if (s > 0 && o.length > s) throw new e({
|
|
44
|
+
field: n,
|
|
45
|
+
message: "crdt.updateTooLarge",
|
|
46
|
+
params: {
|
|
47
|
+
table: t,
|
|
48
|
+
bytes: o.length,
|
|
49
|
+
maxBytes: s
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
a(i(), o);
|
|
54
|
+
} catch {
|
|
55
|
+
try {
|
|
56
|
+
r.authorsOf(o);
|
|
57
|
+
} catch {
|
|
58
|
+
throw new e({
|
|
59
|
+
field: n,
|
|
60
|
+
message: "crdt.updateNotDecodable",
|
|
61
|
+
params: { table: t }
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}, w = (e) => {
|
|
66
|
+
let t = u();
|
|
67
|
+
if (t === 0 || e.length <= t) return e;
|
|
68
|
+
let n = r.compact(e);
|
|
69
|
+
return n.length < e.length ? n : e;
|
|
70
|
+
}, T = (n, o, s, c = "", l) => {
|
|
71
|
+
if (n.size === 0) return s;
|
|
72
|
+
let u;
|
|
73
|
+
for (let d of n) {
|
|
74
|
+
if (!(d in s)) continue;
|
|
75
|
+
let n = s[d];
|
|
76
|
+
if (!(n instanceof Uint8Array)) continue;
|
|
77
|
+
let f = o?.[d], p = f instanceof Uint8Array ? f : void 0;
|
|
78
|
+
C(c, d, n);
|
|
79
|
+
let m;
|
|
80
|
+
try {
|
|
81
|
+
m = w(a(p ?? i(), n));
|
|
82
|
+
} catch {
|
|
83
|
+
throw new e({
|
|
84
|
+
field: d,
|
|
85
|
+
message: "crdt.updateNotDecodable",
|
|
86
|
+
params: { table: c }
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (p !== void 0 && r.missingDependencies?.(m) === !0 && r.missingDependencies(p) !== !0) throw new e({
|
|
90
|
+
field: d,
|
|
91
|
+
message: "crdt.updateNotDecodable",
|
|
92
|
+
params: { table: c }
|
|
93
|
+
});
|
|
94
|
+
let h = v().migrations?.[c]?.[d];
|
|
95
|
+
if (h !== void 0) {
|
|
96
|
+
let e = r.carryReplaced?.(m, n);
|
|
97
|
+
e !== void 0 && (m = a(m, e)), m = t(m, h) ?? m;
|
|
98
|
+
}
|
|
99
|
+
let g = S();
|
|
100
|
+
l !== void 0 && g > 0 && m.length > g && (l(d, m), m = r.rebase(m, crypto.randomUUID()));
|
|
101
|
+
let _ = x();
|
|
102
|
+
if (_ > 0 && m.length > _) throw new e({
|
|
103
|
+
field: d,
|
|
104
|
+
message: "crdt.documentTooLarge",
|
|
105
|
+
params: {
|
|
106
|
+
table: c,
|
|
107
|
+
bytes: m.length,
|
|
108
|
+
maxBytes: _
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
let y = v().validate?.({
|
|
112
|
+
table: c,
|
|
113
|
+
column: d,
|
|
114
|
+
state: m,
|
|
115
|
+
previous: p,
|
|
116
|
+
update: n
|
|
117
|
+
});
|
|
118
|
+
if (y !== void 0) throw new e({
|
|
119
|
+
field: d,
|
|
120
|
+
message: y,
|
|
121
|
+
params: { table: c }
|
|
122
|
+
});
|
|
123
|
+
u === void 0 && (u = { ...s }), u[d] = m;
|
|
124
|
+
}
|
|
125
|
+
return u ?? s;
|
|
126
|
+
}, E = (e, t) => {
|
|
127
|
+
if (e.size === 0) return !1;
|
|
128
|
+
for (let n of e) if (n in t) return !0;
|
|
129
|
+
return !1;
|
|
130
|
+
}, D = (e) => {
|
|
131
|
+
try {
|
|
132
|
+
return {
|
|
133
|
+
epoch: r.epochOf(e) ?? null,
|
|
134
|
+
authors: r.authorsOf(e).size
|
|
135
|
+
};
|
|
136
|
+
} catch {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}, O = (t, r, i, a) => {
|
|
140
|
+
if (!(a instanceof Uint8Array)) throw new e({
|
|
141
|
+
field: r,
|
|
142
|
+
message: "crdt.sealedFrameInvalid",
|
|
143
|
+
params: { table: t }
|
|
144
|
+
});
|
|
145
|
+
let o = b();
|
|
146
|
+
if (o > 0 && a.length > o) throw new e({
|
|
147
|
+
field: r,
|
|
148
|
+
message: "crdt.updateTooLarge",
|
|
149
|
+
params: {
|
|
150
|
+
table: t,
|
|
151
|
+
bytes: a.length,
|
|
152
|
+
maxBytes: o
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
let s = n(i instanceof Uint8Array ? i : void 0, a);
|
|
156
|
+
if ("refused" in s) {
|
|
157
|
+
let n = s.refused === "stale-lineage" ? "crdt.staleLineage" : s.refused === "snapshot-stale" ? "crdt.sealedSnapshotStale" : "crdt.sealedFrameInvalid";
|
|
158
|
+
throw new e({
|
|
159
|
+
field: r,
|
|
160
|
+
message: n,
|
|
161
|
+
params: { table: t }
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
let c = x();
|
|
165
|
+
if (c > 0 && s.log.length > c) throw new e({
|
|
166
|
+
field: r,
|
|
167
|
+
message: "crdt.documentTooLarge",
|
|
168
|
+
params: {
|
|
169
|
+
table: t,
|
|
170
|
+
bytes: s.log.length,
|
|
171
|
+
maxBytes: c
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return s;
|
|
175
|
+
}, k = (e) => {
|
|
176
|
+
o(e);
|
|
177
|
+
}, A = (e, t) => v().migrations?.[e]?.[t] ?? [];
|
|
178
|
+
//#endregion
|
|
179
|
+
export { s as DEFAULT_CRDT_COMPACT_MAX_BYTES, m as DEFAULT_CRDT_MAX_DOCUMENT_BYTES, p as DEFAULT_CRDT_MAX_UPDATE_BYTES, h as DEFAULT_CRDT_REBASE_MAX_BYTES, O as applySealedWrite, C as assertCrdtUpdateAdmissible, u as crdtCompactMaxBytes, f as crdtFoldCell, d as crdtIncrementalCell, x as crdtMaxDocumentBytes, b as crdtMaxUpdateBytes, A as crdtMigrationsFor, S as crdtRebaseMaxBytes, D as describeCrdtState, T as mergeCrdtColumnsIntoPatch, E as patchTouchesCrdt, _ as setCrdtAdmission, k as setCrdtBackend, l as setCrdtCompactMaxBytes };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { bytes as e, id as t, table as n, text as r, timestamp as i } from "@voltro/database";
|
|
2
|
+
//#region src/crdtVersionsTable.ts
|
|
3
|
+
var a = "_voltro_crdt_versions", o = n(a, {
|
|
4
|
+
id: t({ prefix: "crdtv" }),
|
|
5
|
+
tableName: r(),
|
|
6
|
+
rowId: r(),
|
|
7
|
+
columnName: r(),
|
|
8
|
+
state: e().serverOnly(),
|
|
9
|
+
reason: r().oneOf([
|
|
10
|
+
"snapshot",
|
|
11
|
+
"restore",
|
|
12
|
+
"rebase"
|
|
13
|
+
]),
|
|
14
|
+
label: r().nullable(),
|
|
15
|
+
epoch: r().nullable(),
|
|
16
|
+
createdBy: r().nullable(),
|
|
17
|
+
createdAt: i().default("now")
|
|
18
|
+
}).index("_voltro_crdt_versions_cell_created_idx", [
|
|
19
|
+
"tableName",
|
|
20
|
+
"rowId",
|
|
21
|
+
"columnName",
|
|
22
|
+
"createdAt"
|
|
23
|
+
]);
|
|
24
|
+
//#endregion
|
|
25
|
+
export { a as CRDT_VERSIONS_TABLE, o as _voltroCrdtVersionsTable };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Duration as e, Effect as t, Ref as n, Stream as r } from "effect";
|
|
2
|
+
//#region src/credentialBound.ts
|
|
3
|
+
var i = (i, a, o, s) => {
|
|
4
|
+
if (a === void 0) return i;
|
|
5
|
+
let c = a * 1e3 - Date.now();
|
|
6
|
+
return c <= 0 ? o : s === void 0 ? r.interruptWhen(i, t.sleep(e.millis(c))) : r.unwrap(t.gen(function* () {
|
|
7
|
+
let a = yield* n.make(!1), o = t.sleep(e.millis(c)).pipe(t.andThen(n.set(a, !0)));
|
|
8
|
+
return r.concat(r.interruptWhen(i, o), r.unwrap(n.get(a).pipe(t.map((e) => e ? s : r.empty))));
|
|
9
|
+
}));
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { i as boundByCredential };
|
package/dist/crud.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getTable as e, serverOnlyColumns as t } from "@voltro/database";
|
|
2
|
+
import { ServerOnlyColumnWrite as n } from "@voltro/protocol";
|
|
3
|
+
//#region src/crud.ts
|
|
4
|
+
var r = (e, t) => {
|
|
5
|
+
if (t === void 0 || t.length === 0) return e;
|
|
6
|
+
let n = { ...e };
|
|
7
|
+
for (let e of t) delete n[e];
|
|
8
|
+
return n;
|
|
9
|
+
}, i = (n, r) => {
|
|
10
|
+
let i = e(n), a = i === void 0 ? [] : t(i);
|
|
11
|
+
return a.length === 0 ? r ?? [] : r === void 0 ? a : [...r, ...a];
|
|
12
|
+
}, a = (r, i) => {
|
|
13
|
+
let a = e(r);
|
|
14
|
+
if (a === void 0) return;
|
|
15
|
+
let o = t(a).filter((e) => i[e] !== void 0);
|
|
16
|
+
if (o.length !== 0) throw new n({
|
|
17
|
+
table: r,
|
|
18
|
+
columns: o
|
|
19
|
+
});
|
|
20
|
+
}, o = (e, t) => t.length === 0 ? e : e.map((e) => r(e, t)), s = (e, t, n, r, i) => {
|
|
21
|
+
let a = {
|
|
22
|
+
...t?.(r) ?? {},
|
|
23
|
+
...n?.(i) ?? {}
|
|
24
|
+
}, o = e;
|
|
25
|
+
for (let [e, t] of Object.entries(a)) t !== void 0 && (o = o.where(e, t));
|
|
26
|
+
return o;
|
|
27
|
+
}, c = 1e3, l = (e, t = c) => {
|
|
28
|
+
let n = (e) => typeof e == "number" && Number.isFinite(e) ? e : void 0, r = (e) => Math.max(1, Math.min(Math.floor(e), t)), i = n(e.page);
|
|
29
|
+
if (i !== void 0) {
|
|
30
|
+
let t = r(n(e.pageSize) ?? 100);
|
|
31
|
+
return {
|
|
32
|
+
limit: t,
|
|
33
|
+
offset: Math.max(0, Math.floor(i) - 1) * t
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
limit: r(n(e.limit) ?? 100),
|
|
38
|
+
offset: Math.max(0, Math.floor(n(e.offset) ?? 0))
|
|
39
|
+
};
|
|
40
|
+
}, u = {
|
|
41
|
+
list: (e, t = {}) => async (n, r) => {
|
|
42
|
+
let a = n ?? {}, c = r.store.select(e);
|
|
43
|
+
if (t.columns !== void 0 && t.columns.length > 0) {
|
|
44
|
+
let n = new Set(i(e, void 0)), r = t.columns.filter((e) => !n.has(e));
|
|
45
|
+
r.length > 0 && (c = c.select(...r));
|
|
46
|
+
}
|
|
47
|
+
t.include !== void 0 && (c = c.with(t.include)), c = s(c, t.filter, t.scope, a, r);
|
|
48
|
+
for (let e of t.sort ?? []) c = c.orderBy(e.column, e.direction ?? "asc");
|
|
49
|
+
if (t.paginate === !0) {
|
|
50
|
+
let { limit: e, offset: n } = l(a, t.maxPageSize);
|
|
51
|
+
c = c.limit(e).offset(n);
|
|
52
|
+
}
|
|
53
|
+
return o(await c.all(), i(e, t.redact));
|
|
54
|
+
},
|
|
55
|
+
getById: (e, t = {}) => async (n, a) => {
|
|
56
|
+
let o = a.store.select(e).where("id", n.id);
|
|
57
|
+
t.include !== void 0 && (o = o.with(t.include));
|
|
58
|
+
let s = await o.first();
|
|
59
|
+
return s === null ? null : r(s, i(e, t.redact));
|
|
60
|
+
},
|
|
61
|
+
create: (e, t = {}) => async (n, o) => (a(e, n), r(await o.store.insert(e, n), i(e, t.redact))),
|
|
62
|
+
update: (e, t = {}) => async (n, o) => {
|
|
63
|
+
let { id: s, ...c } = n;
|
|
64
|
+
a(e, c);
|
|
65
|
+
let l = await o.store.update(e, s, c);
|
|
66
|
+
return l === null ? null : r(l, i(e, t.redact));
|
|
67
|
+
},
|
|
68
|
+
count: (e, t = {}) => async (n, r) => s(r.store.select(e), t.filter, t.scope, n ?? {}, r).count(),
|
|
69
|
+
remove: (e) => async (t, n) => ({ deleted: await n.store.delete(e, t.id) })
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { u as crud, o as redactColumns };
|