rivetkit 0.0.0-sqlite-sync-3x-release.a00b07f → 0.0.0-sqlite-query-metrics-v2.f5d3605
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/dist/browser/client.d.ts +59 -99
- package/dist/browser/client.js +20 -193
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +2 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/{chunk-D5WUPE47.js → chunk-3URZ4UV5.js} +2 -2
- package/dist/tsup/{chunk-TSQTI6H6.js → chunk-D4G35VTO.js} +4 -4
- package/dist/tsup/{chunk-OTVJYZ2L.cjs → chunk-DDS7OOVF.cjs} +166 -326
- package/dist/tsup/chunk-DDS7OOVF.cjs.map +1 -0
- package/dist/tsup/{chunk-6KXVLIXL.cjs → chunk-DHL2M2E2.cjs} +3 -3
- package/dist/tsup/{chunk-6KXVLIXL.cjs.map → chunk-DHL2M2E2.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZYK4B5WV.js → chunk-E2CUROR3.js} +2 -2
- package/dist/tsup/{chunk-JUWMP5O3.js → chunk-EPRA2TCT.js} +2 -2
- package/dist/tsup/{chunk-3DONDAMG.js → chunk-F7IGTKGM.js} +2 -2
- package/dist/tsup/{chunk-BTSDFFDC.cjs → chunk-FYDB45YU.cjs} +10 -10
- package/dist/tsup/{chunk-BTSDFFDC.cjs.map → chunk-FYDB45YU.cjs.map} +1 -1
- package/dist/tsup/{chunk-73RNTXHB.cjs → chunk-HO76AEDH.cjs} +3 -3
- package/dist/tsup/{chunk-73RNTXHB.cjs.map → chunk-HO76AEDH.cjs.map} +1 -1
- package/dist/tsup/{chunk-A2CF6PFH.js → chunk-JI6GZ2C2.js} +1 -18
- package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
- package/dist/tsup/{chunk-Z7E2G3JZ.cjs → chunk-JW2WPE6Z.cjs} +4 -4
- package/dist/tsup/{chunk-Z7E2G3JZ.cjs.map → chunk-JW2WPE6Z.cjs.map} +1 -1
- package/dist/tsup/{chunk-2MOLY6AM.cjs → chunk-KDT56V3Y.cjs} +11 -10
- package/dist/tsup/chunk-KDT56V3Y.cjs.map +1 -0
- package/dist/tsup/{chunk-DJUBJQEQ.js → chunk-KSP3NXGY.js} +3 -3
- package/dist/tsup/{chunk-JUHXV3HF.cjs → chunk-L3Z3W44Q.cjs} +3 -3
- package/dist/tsup/{chunk-JUHXV3HF.cjs.map → chunk-L3Z3W44Q.cjs.map} +1 -1
- package/dist/tsup/{chunk-RTWH3AX3.cjs → chunk-MYWZCDML.cjs} +2 -19
- package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
- package/dist/tsup/{chunk-TRUHDXOU.js → chunk-PJ5EXY6F.js} +25 -185
- package/dist/tsup/chunk-PJ5EXY6F.js.map +1 -0
- package/dist/tsup/{chunk-TM76Z7XT.cjs → chunk-QR6EAWEC.cjs} +7 -7
- package/dist/tsup/{chunk-TM76Z7XT.cjs.map → chunk-QR6EAWEC.cjs.map} +1 -1
- package/dist/tsup/{chunk-BRH4PQS5.js → chunk-USKGKQZM.js} +11 -10
- package/dist/tsup/chunk-USKGKQZM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +3 -15
- package/dist/tsup/client/mod.d.ts +3 -15
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-DK144OAw.d.cts → config-CkmVg2fG.d.cts} +12 -58
- package/dist/tsup/{config-B4erdavw.d.ts → config-Cw_BwH_G.d.ts} +12 -58
- package/dist/tsup/{config-BfG1qpYz.d.cts → config-D4clT6mq.d.cts} +52 -34
- package/dist/tsup/{config-BfG1qpYz.d.ts → config-D4clT6mq.d.ts} +52 -34
- package/dist/tsup/{context-Oxi6YWcG.d.ts → context-BYOKTQJi.d.ts} +2 -2
- package/dist/tsup/{context-Cvnf3BRe.d.cts → context-_xIcgBnE.d.cts} +2 -2
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +3 -3
- package/dist/tsup/inspector-tab/mod.d.ts +3 -3
- package/dist/tsup/mod.cjs +201 -548
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +116 -463
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/unstable/migrations.d.cts +1 -1
- package/dist/tsup/unstable/migrations.d.ts +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +17 -17
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +5 -5
- package/package.json +10 -9
- package/src/actor/config.test.ts +78 -0
- package/src/actor/keys.test.ts +275 -0
- package/src/actor/keys.ts +0 -86
- package/src/actor/utils.test.ts +48 -0
- package/src/client/actor-conn.ts +6 -92
- package/src/client/actor-handle.ts +3 -21
- package/src/client/client.ts +0 -6
- package/src/client/config.ts +1 -12
- package/src/client/lifecycle-errors.ts +1 -16
- package/src/client/test.ts +44 -0
- package/src/client/token-provider.test.ts +86 -0
- package/src/client/utils.ts +2 -13
- package/src/common/database/config.ts +52 -46
- package/src/common/database/mod.test.ts +364 -0
- package/src/common/database/native-database.test.ts +220 -0
- package/src/common/database/native-database.ts +27 -247
- package/src/common/inline-websocket-adapter.test.ts +51 -0
- package/src/common/router.ts +1 -1
- package/src/db/drizzle.test.ts +164 -0
- package/src/db/mod.ts +1 -0
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +2 -4
- package/src/engine-client/api-endpoints.ts +14 -44
- package/src/engine-client/mod.ts +2 -2
- package/src/registry/config/envoy.ts +1 -1
- package/src/registry/config/index.test.ts +25 -0
- package/src/registry/config/index.ts +31 -28
- package/src/registry/index.ts +19 -51
- package/src/registry/napi-runtime.ts +2 -81
- package/src/registry/native.ts +51 -183
- package/src/registry/run-handler-coordinator.test.ts +252 -0
- package/src/registry/runtime.test.ts +124 -0
- package/src/registry/runtime.ts +10 -79
- package/src/registry/wasm-runtime.ts +3 -94
- package/src/unstable/migrations.test.ts +170 -0
- package/src/utils/endpoint-parser.test.ts +206 -0
- package/src/utils/env-vars.ts +10 -15
- package/src/utils.test.ts +34 -0
- package/src/workflow/driver.test.ts +62 -0
- package/dist/tsup/chunk-2MOLY6AM.cjs.map +0 -1
- package/dist/tsup/chunk-A2CF6PFH.js.map +0 -1
- package/dist/tsup/chunk-BRH4PQS5.js.map +0 -1
- package/dist/tsup/chunk-OTVJYZ2L.cjs.map +0 -1
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +0 -1
- package/dist/tsup/chunk-TRUHDXOU.js.map +0 -1
- package/src/client/retry-budget.ts +0 -78
- /package/dist/tsup/{chunk-D5WUPE47.js.map → chunk-3URZ4UV5.js.map} +0 -0
- /package/dist/tsup/{chunk-TSQTI6H6.js.map → chunk-D4G35VTO.js.map} +0 -0
- /package/dist/tsup/{chunk-ZYK4B5WV.js.map → chunk-E2CUROR3.js.map} +0 -0
- /package/dist/tsup/{chunk-JUWMP5O3.js.map → chunk-EPRA2TCT.js.map} +0 -0
- /package/dist/tsup/{chunk-3DONDAMG.js.map → chunk-F7IGTKGM.js.map} +0 -0
- /package/dist/tsup/{chunk-DJUBJQEQ.js.map → chunk-KSP3NXGY.js.map} +0 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
|
+
import { defineRunHandler, type RunControl } from "@/actor/config";
|
|
3
|
+
import { RunHandlerCoordinator } from "./run-handler-coordinator";
|
|
4
|
+
|
|
5
|
+
class Deferred<T = void> {
|
|
6
|
+
readonly promise: Promise<T>;
|
|
7
|
+
resolve!: (value: T | PromiseLike<T>) => void;
|
|
8
|
+
reject!: (reason?: unknown) => void;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
this.promise = new Promise<T>((resolve, reject) => {
|
|
12
|
+
this.resolve = resolve;
|
|
13
|
+
this.reject = reject;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function createCoordinator() {
|
|
19
|
+
let control: RunControl | undefined;
|
|
20
|
+
const dispose = vi.fn();
|
|
21
|
+
const createInspector = vi.fn((context: { control: RunControl }) => {
|
|
22
|
+
control = context.control;
|
|
23
|
+
return {
|
|
24
|
+
inspector: {
|
|
25
|
+
workflow: {
|
|
26
|
+
getHistory: () => null,
|
|
27
|
+
getState: async () => null,
|
|
28
|
+
onHistoryUpdated: () => () => {},
|
|
29
|
+
replayFromStep: async () => null,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
dispose,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const run = defineRunHandler(async () => {}, {
|
|
36
|
+
inspectorKind: "workflow",
|
|
37
|
+
createInspector,
|
|
38
|
+
});
|
|
39
|
+
const coordinator = new RunHandlerCoordinator(run);
|
|
40
|
+
const restart = vi.fn();
|
|
41
|
+
const inspector = coordinator.getInspector("actor-1", restart);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
control: control as unknown as RunControl,
|
|
45
|
+
coordinator,
|
|
46
|
+
createInspector,
|
|
47
|
+
dispose,
|
|
48
|
+
inspector,
|
|
49
|
+
restart,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("RunHandlerCoordinator", () => {
|
|
54
|
+
test("fails explicitly when a JavaScript factory omits required workflow controls", async () => {
|
|
55
|
+
const coordinator = new RunHandlerCoordinator(
|
|
56
|
+
defineRunHandler(async () => {}, {
|
|
57
|
+
inspectorKind: "workflow",
|
|
58
|
+
createInspector: (() => ({
|
|
59
|
+
inspector: { workflow: { getHistory: () => null } },
|
|
60
|
+
})) as never,
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
await expect(
|
|
65
|
+
coordinator.run(
|
|
66
|
+
"actor-1",
|
|
67
|
+
() => {},
|
|
68
|
+
async () => {},
|
|
69
|
+
),
|
|
70
|
+
).rejects.toThrow(
|
|
71
|
+
"createInspector returned an invalid workflow adapter for actor actor-1",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("initializes and disposes Inspector state even when it is never queried", async () => {
|
|
76
|
+
const dispose = vi.fn();
|
|
77
|
+
const createInspector = vi.fn(() => ({
|
|
78
|
+
inspector: {
|
|
79
|
+
workflow: {
|
|
80
|
+
getHistory: () => null,
|
|
81
|
+
getState: async () => null,
|
|
82
|
+
onHistoryUpdated: () => () => {},
|
|
83
|
+
replayFromStep: async () => null,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
dispose,
|
|
87
|
+
}));
|
|
88
|
+
const coordinator = new RunHandlerCoordinator(
|
|
89
|
+
defineRunHandler(async () => {}, {
|
|
90
|
+
inspectorKind: "workflow",
|
|
91
|
+
createInspector,
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
await coordinator.run(
|
|
96
|
+
"actor-1",
|
|
97
|
+
() => {},
|
|
98
|
+
async () => {},
|
|
99
|
+
);
|
|
100
|
+
expect(createInspector).toHaveBeenCalledOnce();
|
|
101
|
+
coordinator.destroy("actor-1");
|
|
102
|
+
expect(dispose).toHaveBeenCalledOnce();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("creates one inspector per live actor and disposes it exactly once", () => {
|
|
106
|
+
const subject = createCoordinator();
|
|
107
|
+
expect(
|
|
108
|
+
subject.coordinator.getInspector("actor-1", subject.restart),
|
|
109
|
+
).toBe(subject.inspector);
|
|
110
|
+
expect(subject.createInspector).toHaveBeenCalledOnce();
|
|
111
|
+
|
|
112
|
+
subject.coordinator.destroy("actor-1");
|
|
113
|
+
subject.coordinator.destroy("actor-1");
|
|
114
|
+
expect(subject.dispose).toHaveBeenCalledOnce();
|
|
115
|
+
|
|
116
|
+
const recreated = subject.coordinator.getInspector(
|
|
117
|
+
"actor-1",
|
|
118
|
+
subject.restart,
|
|
119
|
+
);
|
|
120
|
+
expect(recreated).not.toBe(subject.inspector);
|
|
121
|
+
expect(subject.createInspector).toHaveBeenCalledTimes(2);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("rejects replay while a run is active", async () => {
|
|
125
|
+
const subject = createCoordinator();
|
|
126
|
+
const active = new Deferred();
|
|
127
|
+
const started = new Deferred();
|
|
128
|
+
const running = subject.coordinator.run(
|
|
129
|
+
"actor-1",
|
|
130
|
+
subject.restart,
|
|
131
|
+
async () => {
|
|
132
|
+
started.resolve();
|
|
133
|
+
await active.promise;
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
await started.promise;
|
|
137
|
+
|
|
138
|
+
await expect(
|
|
139
|
+
subject.control.run.withInactive(
|
|
140
|
+
{ restartOnSuccess: true },
|
|
141
|
+
async () => {},
|
|
142
|
+
),
|
|
143
|
+
).rejects.toMatchObject({
|
|
144
|
+
group: "actor",
|
|
145
|
+
code: "run_handler_unavailable",
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
active.resolve();
|
|
149
|
+
await running;
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("uses a start queued during replay as the single restart", async () => {
|
|
153
|
+
const subject = createCoordinator();
|
|
154
|
+
const replay = new Deferred();
|
|
155
|
+
const replayStarted = new Deferred();
|
|
156
|
+
const events: string[] = [];
|
|
157
|
+
subject.restart.mockImplementation(() => {
|
|
158
|
+
events.push("restart");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const exclusive = subject.control.run.withInactive(
|
|
162
|
+
{ restartOnSuccess: true },
|
|
163
|
+
async () => {
|
|
164
|
+
events.push("replay");
|
|
165
|
+
replayStarted.resolve();
|
|
166
|
+
await replay.promise;
|
|
167
|
+
},
|
|
168
|
+
);
|
|
169
|
+
await replayStarted.promise;
|
|
170
|
+
|
|
171
|
+
const queued = subject.coordinator.run(
|
|
172
|
+
"actor-1",
|
|
173
|
+
subject.restart,
|
|
174
|
+
async () => {
|
|
175
|
+
events.push("run");
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
await Promise.resolve();
|
|
179
|
+
expect(events).toEqual(["replay"]);
|
|
180
|
+
|
|
181
|
+
replay.resolve();
|
|
182
|
+
await exclusive;
|
|
183
|
+
await queued;
|
|
184
|
+
expect(events).toEqual(["replay", "run"]);
|
|
185
|
+
expect(subject.restart).not.toHaveBeenCalled();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("drops starts queued behind a failed replay and leaves the run inactive", async () => {
|
|
189
|
+
const subject = createCoordinator();
|
|
190
|
+
const replay = new Deferred();
|
|
191
|
+
const replayStarted = new Deferred();
|
|
192
|
+
const run = vi.fn();
|
|
193
|
+
const expected = new Error("rewrite failed");
|
|
194
|
+
|
|
195
|
+
const exclusive = subject.control.run.withInactive(
|
|
196
|
+
{ restartOnSuccess: true },
|
|
197
|
+
async () => {
|
|
198
|
+
replayStarted.resolve();
|
|
199
|
+
await replay.promise;
|
|
200
|
+
throw expected;
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
await replayStarted.promise;
|
|
204
|
+
const queued = subject.coordinator.run("actor-1", subject.restart, run);
|
|
205
|
+
|
|
206
|
+
replay.resolve();
|
|
207
|
+
await expect(exclusive).rejects.toBe(expected);
|
|
208
|
+
await expect(queued).resolves.toBe("suppressed");
|
|
209
|
+
expect(run).not.toHaveBeenCalled();
|
|
210
|
+
expect(subject.restart).not.toHaveBeenCalled();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("restores a durable wake suppressed by a failed replay", async () => {
|
|
214
|
+
const subject = createCoordinator();
|
|
215
|
+
const replay = new Deferred();
|
|
216
|
+
const replayStarted = new Deferred();
|
|
217
|
+
const run = vi.fn();
|
|
218
|
+
|
|
219
|
+
const exclusive = subject.control.run.withInactive({}, async () => {
|
|
220
|
+
replayStarted.resolve();
|
|
221
|
+
await replay.promise;
|
|
222
|
+
throw new Error("rewrite failed");
|
|
223
|
+
});
|
|
224
|
+
await replayStarted.promise;
|
|
225
|
+
const queued = subject.coordinator.run("actor-1", subject.restart, run);
|
|
226
|
+
|
|
227
|
+
replay.resolve();
|
|
228
|
+
await expect(exclusive).rejects.toThrow("rewrite failed");
|
|
229
|
+
await expect(queued).resolves.toBe("suppressed");
|
|
230
|
+
expect(run).not.toHaveBeenCalled();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("allows only one concurrent replay and closes old controls on destroy", async () => {
|
|
234
|
+
const subject = createCoordinator();
|
|
235
|
+
const replay = new Deferred();
|
|
236
|
+
const first = subject.control.run.withInactive({}, async () => {
|
|
237
|
+
await replay.promise;
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
await expect(
|
|
241
|
+
subject.control.run.withInactive({}, async () => {}),
|
|
242
|
+
).rejects.toMatchObject({ code: "run_handler_unavailable" });
|
|
243
|
+
subject.coordinator.destroy("actor-1");
|
|
244
|
+
replay.resolve();
|
|
245
|
+
await expect(first).rejects.toMatchObject({
|
|
246
|
+
code: "run_handler_unavailable",
|
|
247
|
+
});
|
|
248
|
+
await expect(
|
|
249
|
+
subject.control.run.withInactive({}, async () => {}),
|
|
250
|
+
).rejects.toMatchObject({ code: "run_handler_unavailable" });
|
|
251
|
+
});
|
|
252
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import type { RegistryConfig } from "./config";
|
|
3
|
+
import { loadAutoRuntime, type RuntimeLoaders } from "./native";
|
|
4
|
+
import {
|
|
5
|
+
type CoreRuntime,
|
|
6
|
+
normalizeRuntimeSqlExecuteResult,
|
|
7
|
+
type RuntimeSqlBindParam,
|
|
8
|
+
type RuntimeSqlBindParams,
|
|
9
|
+
} from "./runtime";
|
|
10
|
+
|
|
11
|
+
describe("runtime SQL boundary", () => {
|
|
12
|
+
test("accepts exact bind param variants", () => {
|
|
13
|
+
const blob = new Uint8Array([1, 2, 3]);
|
|
14
|
+
const params = [
|
|
15
|
+
{ kind: "null" },
|
|
16
|
+
{ kind: "int", intValue: 1 },
|
|
17
|
+
{ kind: "float", floatValue: 1.5 },
|
|
18
|
+
{ kind: "text", textValue: "text" },
|
|
19
|
+
{ kind: "blob", blobValue: blob },
|
|
20
|
+
] satisfies RuntimeSqlBindParams;
|
|
21
|
+
|
|
22
|
+
expect(params).toEqual([
|
|
23
|
+
{ kind: "null" },
|
|
24
|
+
{ kind: "int", intValue: 1 },
|
|
25
|
+
{ kind: "float", floatValue: 1.5 },
|
|
26
|
+
{ kind: "text", textValue: "text" },
|
|
27
|
+
{ kind: "blob", blobValue: blob },
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("rejects bind params with mismatched value fields at typecheck time", () => {
|
|
32
|
+
const invalidIntParamCandidate = {
|
|
33
|
+
kind: "int",
|
|
34
|
+
intValue: 1,
|
|
35
|
+
textValue: "extra",
|
|
36
|
+
} as const;
|
|
37
|
+
// @ts-expect-error Runtime SQL int params must only carry intValue.
|
|
38
|
+
const invalidIntParam: RuntimeSqlBindParam = invalidIntParamCandidate;
|
|
39
|
+
|
|
40
|
+
expect(invalidIntParam.kind).toBe("int");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("normalizes execute result metadata", () => {
|
|
44
|
+
const base = {
|
|
45
|
+
columns: ["value"],
|
|
46
|
+
rows: [[1]],
|
|
47
|
+
changes: 1,
|
|
48
|
+
lastInsertRowId: null,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
expect(normalizeRuntimeSqlExecuteResult(base)).toEqual(base);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("loadAutoRuntime failure reporting", () => {
|
|
56
|
+
const wasmRuntime = { kind: "wasm" } as unknown as CoreRuntime;
|
|
57
|
+
const nativeRuntime = { kind: "napi" } as unknown as CoreRuntime;
|
|
58
|
+
const config = {} as RegistryConfig;
|
|
59
|
+
|
|
60
|
+
function loaders(overrides: Partial<RuntimeLoaders>): RuntimeLoaders {
|
|
61
|
+
return {
|
|
62
|
+
detectHost: () => "node-like",
|
|
63
|
+
loadNative: async () => ({ runtime: nativeRuntime }) as never,
|
|
64
|
+
loadWasm: async () => ({ runtime: wasmRuntime }) as never,
|
|
65
|
+
...overrides,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
test("prefers native when it loads", async () => {
|
|
70
|
+
const runtime = await loadAutoRuntime(config, loaders({}));
|
|
71
|
+
expect(runtime).toBe(nativeRuntime);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("falls back to wasm when native fails", async () => {
|
|
75
|
+
const runtime = await loadAutoRuntime(
|
|
76
|
+
config,
|
|
77
|
+
loaders({
|
|
78
|
+
loadNative: async () => {
|
|
79
|
+
throw new Error("missing platform binding");
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
expect(runtime).toBe(wasmRuntime);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("reports the native cause when both runtimes fail", async () => {
|
|
87
|
+
// The native failure is the actionable one. Before this was reported,
|
|
88
|
+
// a skipped platform binding surfaced only as the wasm loader's
|
|
89
|
+
// unrelated `file://` fetch error.
|
|
90
|
+
const promise = loadAutoRuntime(
|
|
91
|
+
config,
|
|
92
|
+
loaders({
|
|
93
|
+
loadNative: async () => {
|
|
94
|
+
throw new Error(
|
|
95
|
+
"Cannot find module '@rivetkit/rivetkit-napi-linux-x64-musl'",
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
loadWasm: async () => {
|
|
99
|
+
throw new Error("fetch failed");
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
await expect(promise).rejects.toThrow(/rivetkit-napi-linux-x64-musl/);
|
|
104
|
+
await expect(promise).rejects.toThrow(/fetch failed/);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("uses wasm directly on an edge-like host without touching native", async () => {
|
|
108
|
+
let nativeCalls = 0;
|
|
109
|
+
const runtime = await loadAutoRuntime(
|
|
110
|
+
config,
|
|
111
|
+
loaders({
|
|
112
|
+
detectHost: () => "edge-like",
|
|
113
|
+
loadNative: async () => {
|
|
114
|
+
nativeCalls += 1;
|
|
115
|
+
throw new Error(
|
|
116
|
+
"native must not be attempted on edge hosts",
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
expect(runtime).toBe(wasmRuntime);
|
|
122
|
+
expect(nativeCalls).toBe(0);
|
|
123
|
+
});
|
|
124
|
+
});
|
package/src/registry/runtime.ts
CHANGED
|
@@ -284,15 +284,10 @@ export interface RuntimeSqlRunResult {
|
|
|
284
284
|
|
|
285
285
|
export interface RuntimeSqlDatabase {
|
|
286
286
|
exec(sql: string): Promise<RuntimeSqlExecResult>;
|
|
287
|
-
execSync(sql: string): RuntimeSqlExecResult;
|
|
288
287
|
execute(
|
|
289
288
|
sql: string,
|
|
290
289
|
params?: RuntimeSqlBindParams,
|
|
291
290
|
): Promise<RuntimeSqlExecuteResult>;
|
|
292
|
-
executeSync(
|
|
293
|
-
sql: string,
|
|
294
|
-
params?: RuntimeSqlBindParams,
|
|
295
|
-
): RuntimeSqlExecuteResult;
|
|
296
291
|
executeBatch(
|
|
297
292
|
statements: RuntimeSqlBatchStatement[],
|
|
298
293
|
): Promise<RuntimeSqlExecuteResult[]>;
|
|
@@ -308,33 +303,19 @@ export interface RuntimeSqlDatabase {
|
|
|
308
303
|
timeoutMs?: number,
|
|
309
304
|
name?: string,
|
|
310
305
|
): Promise<RuntimeSqlTransactionDatabase>;
|
|
311
|
-
beginTransactionSync(
|
|
312
|
-
timeoutMs?: number,
|
|
313
|
-
name?: string,
|
|
314
|
-
): RuntimeSqlTransactionDatabase;
|
|
315
306
|
metrics?(): SqliteNativeMetrics | null;
|
|
316
307
|
takeLastKvError?(): string | null;
|
|
317
|
-
open(): Promise<void>;
|
|
318
|
-
commitTicket(): number;
|
|
319
|
-
whenDurable(ticket: number): Promise<void>;
|
|
320
308
|
close(): Promise<void>;
|
|
321
309
|
}
|
|
322
310
|
|
|
323
311
|
export interface RuntimeSqlTransactionDatabase {
|
|
324
312
|
exec(sql: string): Promise<RuntimeSqlExecResult>;
|
|
325
|
-
execSync(sql: string): RuntimeSqlExecResult;
|
|
326
313
|
execute(
|
|
327
314
|
sql: string,
|
|
328
315
|
params?: RuntimeSqlBindParams,
|
|
329
316
|
): Promise<RuntimeSqlExecuteResult>;
|
|
330
|
-
executeSync(
|
|
331
|
-
sql: string,
|
|
332
|
-
params?: RuntimeSqlBindParams,
|
|
333
|
-
): RuntimeSqlExecuteResult;
|
|
334
317
|
commit(): Promise<void>;
|
|
335
|
-
commitSync(): void;
|
|
336
318
|
rollback(): Promise<void>;
|
|
337
|
-
rollbackSync(): void;
|
|
338
319
|
}
|
|
339
320
|
|
|
340
321
|
/** Sample rates for the traces an actor starts, in the shape core takes. */
|
|
@@ -349,7 +330,6 @@ export interface RuntimeActorConfig {
|
|
|
349
330
|
icon?: string;
|
|
350
331
|
hasDatabase?: boolean;
|
|
351
332
|
remoteSqlite?: boolean;
|
|
352
|
-
sqliteDeferredCommits?: boolean;
|
|
353
333
|
sqliteProfiling?: SqliteProfilingOptions;
|
|
354
334
|
tracing?: RuntimeActorTracingConfig;
|
|
355
335
|
enableActorRuntimeSocket?: boolean;
|
|
@@ -407,8 +387,6 @@ export interface RuntimeServeConfig {
|
|
|
407
387
|
engineBinaryPath?: string;
|
|
408
388
|
startServices?: boolean;
|
|
409
389
|
servicesBinaryPath?: string;
|
|
410
|
-
/** Whether config resolution selected a managed local development engine. */
|
|
411
|
-
engineSpawn?: boolean;
|
|
412
390
|
engineHost?: string;
|
|
413
391
|
enginePort?: number;
|
|
414
392
|
handleInspectorHttpInRuntime?: boolean;
|
|
@@ -554,15 +532,10 @@ export interface CoreRuntime {
|
|
|
554
532
|
createCancellationToken(): CancellationTokenHandle;
|
|
555
533
|
cancellationTokenAborted(token: CancellationTokenHandle): boolean;
|
|
556
534
|
cancelCancellationToken(token: CancellationTokenHandle): void;
|
|
557
|
-
/**
|
|
558
|
-
* Calls `callback` once when `token` is cancelled. Returns a release
|
|
559
|
-
* function that drops the registration without calling `callback`; call it
|
|
560
|
-
* once cancellation no longer matters so the native listener is freed.
|
|
561
|
-
*/
|
|
562
535
|
onCancellationTokenCancelled(
|
|
563
536
|
token: CancellationTokenHandle,
|
|
564
537
|
callback: (...args: unknown[]) => unknown,
|
|
565
|
-
):
|
|
538
|
+
): void;
|
|
566
539
|
|
|
567
540
|
actorState(ctx: ActorContextHandle): RuntimeBytes;
|
|
568
541
|
actorBeginOnStateChange(ctx: ActorContextHandle): void;
|
|
@@ -716,20 +689,11 @@ export interface CoreRuntime {
|
|
|
716
689
|
ctx: ActorContextHandle,
|
|
717
690
|
sql: string,
|
|
718
691
|
): Promise<RuntimeSqlExecResult>;
|
|
719
|
-
actorSqlExecSync(
|
|
720
|
-
ctx: ActorContextHandle,
|
|
721
|
-
sql: string,
|
|
722
|
-
): RuntimeSqlExecResult;
|
|
723
692
|
actorSqlExecute(
|
|
724
693
|
ctx: ActorContextHandle,
|
|
725
694
|
sql: string,
|
|
726
695
|
params?: RuntimeSqlBindParams,
|
|
727
696
|
): Promise<RuntimeSqlExecuteResult>;
|
|
728
|
-
actorSqlExecuteSync(
|
|
729
|
-
ctx: ActorContextHandle,
|
|
730
|
-
sql: string,
|
|
731
|
-
params?: RuntimeSqlBindParams,
|
|
732
|
-
): RuntimeSqlExecuteResult;
|
|
733
697
|
actorSqlExecuteBatch(
|
|
734
698
|
ctx: ActorContextHandle,
|
|
735
699
|
statements: RuntimeSqlBatchStatement[],
|
|
@@ -739,37 +703,21 @@ export interface CoreRuntime {
|
|
|
739
703
|
timeoutMs?: number,
|
|
740
704
|
name?: string,
|
|
741
705
|
): Promise<SqliteTransactionHandle>;
|
|
742
|
-
actorSqlBeginTransactionSync(
|
|
743
|
-
ctx: ActorContextHandle,
|
|
744
|
-
timeoutMs?: number,
|
|
745
|
-
name?: string,
|
|
746
|
-
): SqliteTransactionHandle;
|
|
747
706
|
actorSqlTransactionExec(
|
|
748
707
|
transaction: SqliteTransactionHandle,
|
|
749
708
|
sql: string,
|
|
750
709
|
): Promise<RuntimeSqlExecResult>;
|
|
751
|
-
actorSqlTransactionExecSync(
|
|
752
|
-
transaction: SqliteTransactionHandle,
|
|
753
|
-
sql: string,
|
|
754
|
-
): RuntimeSqlExecResult;
|
|
755
710
|
actorSqlTransactionExecute(
|
|
756
711
|
transaction: SqliteTransactionHandle,
|
|
757
712
|
sql: string,
|
|
758
713
|
params?: RuntimeSqlBindParams,
|
|
759
714
|
): Promise<RuntimeSqlExecuteResult>;
|
|
760
|
-
actorSqlTransactionExecuteSync(
|
|
761
|
-
transaction: SqliteTransactionHandle,
|
|
762
|
-
sql: string,
|
|
763
|
-
params?: RuntimeSqlBindParams,
|
|
764
|
-
): RuntimeSqlExecuteResult;
|
|
765
715
|
actorSqlTransactionCommit(
|
|
766
716
|
transaction: SqliteTransactionHandle,
|
|
767
717
|
): Promise<void>;
|
|
768
|
-
actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void;
|
|
769
718
|
actorSqlTransactionRollback(
|
|
770
719
|
transaction: SqliteTransactionHandle,
|
|
771
720
|
): Promise<void>;
|
|
772
|
-
actorSqlTransactionRollbackSync(transaction: SqliteTransactionHandle): void;
|
|
773
721
|
actorBeginStateTransaction(
|
|
774
722
|
ctx: ActorContextHandle,
|
|
775
723
|
timeoutMs?: number,
|
|
@@ -798,13 +746,6 @@ export interface CoreRuntime {
|
|
|
798
746
|
): Promise<RuntimeSqlRunResult>;
|
|
799
747
|
actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
|
|
800
748
|
actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
|
|
801
|
-
/** Opens the actor database so later synchronous calls never fetch its first pages. */
|
|
802
|
-
actorSqlOpen(ctx: ActorContextHandle): Promise<void>;
|
|
803
|
-
/** Returns the ticket of the latest local commit. */
|
|
804
|
-
actorSqlCommitTicket(ctx: ActorContextHandle): number;
|
|
805
|
-
/** Resolves once the commit `ticket` names and every earlier commit are durable. */
|
|
806
|
-
actorSqlWhenDurable(ctx: ActorContextHandle, ticket: number): Promise<void>;
|
|
807
|
-
actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void;
|
|
808
749
|
actorSqlClose(ctx: ActorContextHandle): Promise<void>;
|
|
809
750
|
actorRuntimeSocketProvision(
|
|
810
751
|
ctx: ActorContextHandle,
|
|
@@ -935,13 +876,6 @@ export interface RuntimeBundle {
|
|
|
935
876
|
runtime: CoreRuntime;
|
|
936
877
|
}
|
|
937
878
|
|
|
938
|
-
export function servicesBinaryUnavailable(cause: unknown): Error {
|
|
939
|
-
return new Error(
|
|
940
|
-
"services.binary_unavailable: Install @rivet-dev/services yourself to run local Services, or set RIVET_SERVICES_BINARY to its executable path.",
|
|
941
|
-
{ cause },
|
|
942
|
-
);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
879
|
export async function buildServeConfig(
|
|
946
880
|
config: RegistryConfig,
|
|
947
881
|
loadEnginePath: () => Promise<string>,
|
|
@@ -953,12 +887,11 @@ export async function buildServeConfig(
|
|
|
953
887
|
}
|
|
954
888
|
|
|
955
889
|
const serveConfig: RuntimeServeConfig = {
|
|
956
|
-
version: config.
|
|
890
|
+
version: config.envoy.version,
|
|
957
891
|
endpoint: config.endpoint,
|
|
958
|
-
engineSpawn: config.engineSpawn,
|
|
959
892
|
token: config.token,
|
|
960
893
|
namespace: config.namespace,
|
|
961
|
-
poolName: config.
|
|
894
|
+
poolName: config.envoy.poolName,
|
|
962
895
|
startServices: config.startServices,
|
|
963
896
|
handleInspectorHttpInRuntime: true,
|
|
964
897
|
serverlessBasePath: config.serverless.basePath,
|
|
@@ -988,15 +921,13 @@ export async function buildServeConfig(
|
|
|
988
921
|
});
|
|
989
922
|
}
|
|
990
923
|
if (config.startServices) {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
throw servicesBinaryUnavailable(error);
|
|
999
|
-
}
|
|
924
|
+
try {
|
|
925
|
+
serveConfig.servicesBinaryPath = await loadServicesPath();
|
|
926
|
+
} catch (error) {
|
|
927
|
+
logger().warn({
|
|
928
|
+
msg: "could not resolve the Services binary; a local Engine will fail with services.binary_unavailable — set RIVET_RUN_SERVICES=0 to disable Services or RIVET_SERVICES_BINARY to a local rivet-services binary",
|
|
929
|
+
error: stringifyError(error),
|
|
930
|
+
});
|
|
1000
931
|
}
|
|
1001
932
|
}
|
|
1002
933
|
serveConfig.engineHost = config.engineHost;
|