rivetkit 0.0.0-sqlite-query-metrics-v2.f5d3605 → 0.0.0-sqlite-sync-3-0-1-release.95f6e2d
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 +99 -59
- package/dist/browser/client.js +228 -34
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -2
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/{chunk-3URZ4UV5.js → chunk-2HWY7FZU.js} +2 -2
- package/dist/tsup/{chunk-PJ5EXY6F.js → chunk-62WFU3BQ.js} +223 -42
- package/dist/tsup/chunk-62WFU3BQ.js.map +1 -0
- package/dist/tsup/{chunk-JI6GZ2C2.js → chunk-A2CF6PFH.js} +18 -1
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-KDT56V3Y.cjs → chunk-AQWZWR2P.cjs} +10 -11
- package/dist/tsup/chunk-AQWZWR2P.cjs.map +1 -0
- package/dist/tsup/{chunk-L3Z3W44Q.cjs → chunk-E4KDQJCR.cjs} +3 -3
- package/dist/tsup/{chunk-L3Z3W44Q.cjs.map → chunk-E4KDQJCR.cjs.map} +1 -1
- package/dist/tsup/{chunk-DHL2M2E2.cjs → chunk-E6HKVCPA.cjs} +3 -3
- package/dist/tsup/{chunk-DHL2M2E2.cjs.map → chunk-E6HKVCPA.cjs.map} +1 -1
- package/dist/tsup/{chunk-DDS7OOVF.cjs → chunk-EQBUH25O.cjs} +362 -181
- package/dist/tsup/chunk-EQBUH25O.cjs.map +1 -0
- package/dist/tsup/{chunk-USKGKQZM.js → chunk-HQHTTJW5.js} +10 -11
- package/dist/tsup/chunk-HQHTTJW5.js.map +1 -0
- package/dist/tsup/{chunk-JW2WPE6Z.cjs → chunk-M5SQGPRJ.cjs} +4 -4
- package/dist/tsup/{chunk-JW2WPE6Z.cjs.map → chunk-M5SQGPRJ.cjs.map} +1 -1
- package/dist/tsup/{chunk-FYDB45YU.cjs → chunk-MYWNJP55.cjs} +10 -10
- package/dist/tsup/{chunk-FYDB45YU.cjs.map → chunk-MYWNJP55.cjs.map} +1 -1
- package/dist/tsup/{chunk-F7IGTKGM.js → chunk-OWZ76NSH.js} +2 -2
- package/dist/tsup/{chunk-KSP3NXGY.js → chunk-QE5MTZHB.js} +3 -3
- package/dist/tsup/{chunk-D4G35VTO.js → chunk-QFZY2CK3.js} +4 -4
- package/dist/tsup/{chunk-E2CUROR3.js → chunk-QIIIRYN7.js} +2 -2
- package/dist/tsup/{chunk-MYWZCDML.cjs → chunk-RTWH3AX3.cjs} +19 -2
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-HO76AEDH.cjs → chunk-UHMB5FFB.cjs} +3 -3
- package/dist/tsup/{chunk-HO76AEDH.cjs.map → chunk-UHMB5FFB.cjs.map} +1 -1
- package/dist/tsup/{chunk-QR6EAWEC.cjs → chunk-VKXEBB3Z.cjs} +7 -7
- package/dist/tsup/{chunk-QR6EAWEC.cjs.map → chunk-VKXEBB3Z.cjs.map} +1 -1
- package/dist/tsup/{chunk-EPRA2TCT.js → chunk-ZMVYZ7ZI.js} +2 -2
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +15 -3
- package/dist/tsup/client/mod.d.ts +15 -3
- 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-Cw_BwH_G.d.ts → config-B4erdavw.d.ts} +58 -12
- package/dist/tsup/{config-D4clT6mq.d.ts → config-BfG1qpYz.d.cts} +34 -52
- package/dist/tsup/{config-D4clT6mq.d.cts → config-BfG1qpYz.d.ts} +34 -52
- package/dist/tsup/{config-CkmVg2fG.d.cts → config-DK144OAw.d.cts} +58 -12
- package/dist/tsup/{context-_xIcgBnE.d.cts → context-Cvnf3BRe.d.cts} +2 -2
- package/dist/tsup/{context-BYOKTQJi.d.ts → context-Oxi6YWcG.d.ts} +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 +553 -202
- 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 +467 -116
- 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 +22 -19
- 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 +10 -7
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +9 -10
- package/src/actor/keys.ts +86 -0
- package/src/client/actor-conn.ts +136 -24
- package/src/client/actor-handle.ts +21 -3
- package/src/client/client.ts +6 -0
- package/src/client/config.ts +12 -1
- package/src/client/lifecycle-errors.ts +35 -2
- package/src/client/retry-budget.ts +78 -0
- package/src/client/utils.ts +13 -2
- package/src/common/database/config.ts +46 -52
- package/src/common/database/native-database.ts +247 -27
- package/src/common/router.ts +1 -1
- package/src/db/mod.ts +0 -1
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +4 -2
- package/src/engine-client/api-endpoints.ts +44 -14
- package/src/engine-client/mod.ts +2 -2
- package/src/registry/config/envoy.ts +1 -1
- package/src/registry/config/index.ts +29 -31
- package/src/registry/index.ts +66 -21
- package/src/registry/napi-runtime.ts +82 -3
- package/src/registry/native.ts +184 -52
- package/src/registry/runtime.ts +79 -10
- package/src/registry/wasm-runtime.ts +94 -3
- package/src/utils/env-vars.ts +15 -10
- package/src/workflow/driver.ts +5 -3
- package/dist/tsup/chunk-DDS7OOVF.cjs.map +0 -1
- package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
- package/dist/tsup/chunk-KDT56V3Y.cjs.map +0 -1
- package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
- package/dist/tsup/chunk-PJ5EXY6F.js.map +0 -1
- package/dist/tsup/chunk-USKGKQZM.js.map +0 -1
- package/src/actor/config.test.ts +0 -78
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/client/test.ts +0 -44
- package/src/client/token-provider.test.ts +0 -86
- package/src/common/database/mod.test.ts +0 -364
- package/src/common/database/native-database.test.ts +0 -220
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/db/drizzle.test.ts +0 -164
- package/src/registry/config/index.test.ts +0 -25
- package/src/registry/run-handler-coordinator.test.ts +0 -252
- package/src/registry/runtime.test.ts +0 -124
- package/src/unstable/migrations.test.ts +0 -170
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- package/src/workflow/driver.test.ts +0 -62
- /package/dist/tsup/{chunk-3URZ4UV5.js.map → chunk-2HWY7FZU.js.map} +0 -0
- /package/dist/tsup/{chunk-F7IGTKGM.js.map → chunk-OWZ76NSH.js.map} +0 -0
- /package/dist/tsup/{chunk-KSP3NXGY.js.map → chunk-QE5MTZHB.js.map} +0 -0
- /package/dist/tsup/{chunk-D4G35VTO.js.map → chunk-QFZY2CK3.js.map} +0 -0
- /package/dist/tsup/{chunk-E2CUROR3.js.map → chunk-QIIIRYN7.js.map} +0 -0
- /package/dist/tsup/{chunk-EPRA2TCT.js.map → chunk-ZMVYZ7ZI.js.map} +0 -0
|
@@ -52,18 +52,13 @@ export interface SqliteTransactionOptions {
|
|
|
52
52
|
* to change without notice.
|
|
53
53
|
*/
|
|
54
54
|
export interface SqliteProfilingOptions {
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
metrics?: SqliteProfilingMetricsOptions;
|
|
63
|
-
/** Duration buckets in seconds. Default [0.01, 0.1, 1]. Positive, finite, strictly increasing.
|
|
64
|
-
* All actors in a process enabling the duration histogram must use identical buckets. */
|
|
65
|
-
durationHistogramBucketsSeconds?: number[];
|
|
66
|
-
/** Maximum distinct statement fingerprints per process. Default: 512. */
|
|
55
|
+
/** Exact SQL statements to give fingerprint labels. Profiling defaults to actor
|
|
56
|
+
* aggregates without fingerprint labels. Profile logs remain enabled.
|
|
57
|
+
* RIVETKIT_SQLITE_PROFILING overrides selection with a JSON object containing
|
|
58
|
+
* queries and/or fingerprints arrays. An empty object clears fingerprint selection. */
|
|
59
|
+
queries?: string[];
|
|
60
|
+
/** Exact query fingerprints to label separately, as reported in profile logs. */
|
|
61
|
+
fingerprints?: string[];
|
|
67
62
|
maxTrackedStatementFingerprints?: number;
|
|
68
63
|
maxTrackedTransactionFingerprints?: number;
|
|
69
64
|
maxPrometheusSeries?: number;
|
|
@@ -76,46 +71,6 @@ export interface SqliteProfilingOptions {
|
|
|
76
71
|
diagnosticEventQueueCapacity?: number;
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
/** SQLite profiling metrics. Physical-request metrics and gauges have no query labels. */
|
|
80
|
-
export interface SqliteProfilingMetricsOptions {
|
|
81
|
-
/** Execution count and cumulative seconds. Uses histogram count/sum when enabled, otherwise counters. Default: true. */
|
|
82
|
-
duration?: boolean;
|
|
83
|
-
/** Execution duration histogram. Only applies when duration is enabled. Default: true. */
|
|
84
|
-
durationHistogram?: boolean;
|
|
85
|
-
/** Outcome counters, including success and errors. Default: true. */
|
|
86
|
-
outcomes?: boolean;
|
|
87
|
-
/** Per-query timing phase histograms. Default: false. */
|
|
88
|
-
phaseDurationHistogram?: boolean;
|
|
89
|
-
/** Storage round trips per operation histogram. Default: false. */
|
|
90
|
-
getPagesRoundTripsHistogram?: boolean;
|
|
91
|
-
/** Statements per transaction histogram. Default: false. */
|
|
92
|
-
transactionStatementCountHistogram?: boolean;
|
|
93
|
-
/** Per-query pages returned from storage, including returned prefetch pages. Default: true. */
|
|
94
|
-
pagesFetched?: boolean;
|
|
95
|
-
/** Actor-level page counters by page kind (no query labels). Default: false. */
|
|
96
|
-
localPages?: boolean;
|
|
97
|
-
/** Actor-level byte counters by byte kind (no query labels). Default: false. */
|
|
98
|
-
localBytes?: boolean;
|
|
99
|
-
/** Actor-level physical storage request duration histogram. Default: false. */
|
|
100
|
-
getPagesDurationHistogram?: boolean;
|
|
101
|
-
/** Actor-level pages per storage request histograms, by page kind. Default: false. */
|
|
102
|
-
getPagesPagesHistogram?: boolean;
|
|
103
|
-
/** Actor-level storage response byte histogram. Default: false. */
|
|
104
|
-
getPagesResponseBytesHistogram?: boolean;
|
|
105
|
-
/** Actor-level missing response page counter. Default: false. */
|
|
106
|
-
getPagesMissingPages?: boolean;
|
|
107
|
-
/** Queued SQLite work, aggregated by actor name. Default: true. */
|
|
108
|
-
workerQueueDepth?: boolean;
|
|
109
|
-
/** Executing SQLite work, aggregated by actor name. Default: true. */
|
|
110
|
-
workerInflight?: boolean;
|
|
111
|
-
/** Transaction waiters, aggregated by actor name. Default: true. */
|
|
112
|
-
coordinatorQueueDepth?: boolean;
|
|
113
|
-
/** Counts observations exceeding fingerprint or series limits. Default: true. */
|
|
114
|
-
fingerprintOverflow?: boolean;
|
|
115
|
-
/** Counts diagnostic events dropped by rate limits or backpressure. Default: true. */
|
|
116
|
-
eventDropped?: boolean;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
74
|
export interface SqliteNativeMetrics {
|
|
120
75
|
requestBuildNs: number;
|
|
121
76
|
serializeNs: number;
|
|
@@ -135,7 +90,12 @@ export interface SqliteDatabase {
|
|
|
135
90
|
sql: string,
|
|
136
91
|
callback?: (row: unknown[], columns: string[]) => void,
|
|
137
92
|
): Promise<void>;
|
|
93
|
+
execSync?(
|
|
94
|
+
sql: string,
|
|
95
|
+
callback?: (row: unknown[], columns: string[]) => void,
|
|
96
|
+
): void;
|
|
138
97
|
execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
|
|
98
|
+
executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
|
|
139
99
|
executeBatch(
|
|
140
100
|
statements: SqliteBatchStatement[],
|
|
141
101
|
): Promise<SqliteExecuteResult[]>;
|
|
@@ -143,12 +103,31 @@ export interface SqliteDatabase {
|
|
|
143
103
|
timeoutMs?: number,
|
|
144
104
|
name?: string,
|
|
145
105
|
): Promise<SqliteTransactionDatabase>;
|
|
106
|
+
beginTransactionSync?(
|
|
107
|
+
timeoutMs?: number,
|
|
108
|
+
name?: string,
|
|
109
|
+
): SynchronousSqliteTransactionDatabase;
|
|
146
110
|
run(sql: string, params?: SqliteBindings): Promise<void>;
|
|
147
111
|
query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
|
|
148
112
|
nativeMetrics?():
|
|
149
113
|
| SqliteNativeMetrics
|
|
150
114
|
| Promise<SqliteNativeMetrics | null>
|
|
151
115
|
| null;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the ticket of the latest local commit. Synchronous writes return before they are
|
|
118
|
+
* durable; pass the ticket to `whenDurable` before releasing output that depends on them.
|
|
119
|
+
*/
|
|
120
|
+
commitTicket?(): number;
|
|
121
|
+
/**
|
|
122
|
+
* Resolves once the commit `ticket` names and every earlier commit are durable. Rejects with
|
|
123
|
+
* `sqlite.durability_failed` once the database broke and the actor is restarting.
|
|
124
|
+
*/
|
|
125
|
+
whenDurable?(ticket: number): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Restarts the owning actor from durable state. Every later write fails, including the final
|
|
128
|
+
* state save. For native database providers whose in-memory state can no longer be trusted.
|
|
129
|
+
*/
|
|
130
|
+
abortGeneration?(reason: string): void;
|
|
152
131
|
close(): Promise<void>;
|
|
153
132
|
}
|
|
154
133
|
|
|
@@ -157,11 +136,26 @@ export interface SqliteTransactionDatabase {
|
|
|
157
136
|
sql: string,
|
|
158
137
|
callback?: (row: unknown[], columns: string[]) => void,
|
|
159
138
|
): Promise<void>;
|
|
139
|
+
execSync?(
|
|
140
|
+
sql: string,
|
|
141
|
+
callback?: (row: unknown[], columns: string[]) => void,
|
|
142
|
+
): void;
|
|
160
143
|
execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
|
|
144
|
+
executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
|
|
161
145
|
commit(): Promise<void>;
|
|
162
146
|
rollback(): Promise<void>;
|
|
163
147
|
}
|
|
164
148
|
|
|
149
|
+
export type SynchronousSqliteTransactionDatabase = SqliteTransactionDatabase & {
|
|
150
|
+
execSync(
|
|
151
|
+
sql: string,
|
|
152
|
+
callback?: (row: unknown[], columns: string[]) => void,
|
|
153
|
+
): void;
|
|
154
|
+
executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult;
|
|
155
|
+
commitSync(): void;
|
|
156
|
+
rollbackSync(): void;
|
|
157
|
+
};
|
|
158
|
+
|
|
165
159
|
/**
|
|
166
160
|
* Provider for opening native databases from the active runtime.
|
|
167
161
|
*/
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
SqliteExecuteResult,
|
|
7
7
|
SqliteNativeMetrics,
|
|
8
8
|
SqliteTransactionDatabase,
|
|
9
|
+
SynchronousSqliteTransactionDatabase,
|
|
9
10
|
} from "./config";
|
|
10
11
|
|
|
11
12
|
type NativeBindNoValues = {
|
|
@@ -74,10 +75,15 @@ interface NativeBatchStatement {
|
|
|
74
75
|
|
|
75
76
|
export interface JsNativeDatabaseLike {
|
|
76
77
|
exec(sql: string): Promise<NativeExecResult>;
|
|
78
|
+
execSync(sql: string): NativeExecResult;
|
|
77
79
|
execute(
|
|
78
80
|
sql: string,
|
|
79
81
|
params?: NativeBindParam[] | null,
|
|
80
82
|
): Promise<NativeExecuteResult>;
|
|
83
|
+
executeSync(
|
|
84
|
+
sql: string,
|
|
85
|
+
params?: NativeBindParam[] | null,
|
|
86
|
+
): NativeExecuteResult;
|
|
81
87
|
executeBatch?(
|
|
82
88
|
statements: NativeBatchStatement[],
|
|
83
89
|
): Promise<NativeExecuteResult[]>;
|
|
@@ -89,6 +95,10 @@ export interface JsNativeDatabaseLike {
|
|
|
89
95
|
timeoutMs?: number,
|
|
90
96
|
name?: string,
|
|
91
97
|
): Promise<JsNativeTransactionLike>;
|
|
98
|
+
beginTransactionSync(
|
|
99
|
+
timeoutMs?: number,
|
|
100
|
+
name?: string,
|
|
101
|
+
): JsNativeSynchronousTransactionLike;
|
|
92
102
|
query(
|
|
93
103
|
sql: string,
|
|
94
104
|
params?: NativeBindParam[] | null,
|
|
@@ -99,15 +109,27 @@ export interface JsNativeDatabaseLike {
|
|
|
99
109
|
): Promise<NativeRunResult>;
|
|
100
110
|
metrics?(): SqliteNativeMetrics | null;
|
|
101
111
|
takeLastKvError?(): string | null;
|
|
112
|
+
open(): Promise<void>;
|
|
113
|
+
commitTicket(): number;
|
|
114
|
+
whenDurable(ticket: number): Promise<void>;
|
|
115
|
+
abortGeneration(reason: string): void;
|
|
102
116
|
close(): Promise<void>;
|
|
103
117
|
}
|
|
104
118
|
export type StateAwareSqliteDatabase = SqliteDatabase & {
|
|
119
|
+
open(): Promise<void>;
|
|
120
|
+
commitTicket(): number;
|
|
121
|
+
whenDurable(ticket: number): Promise<void>;
|
|
105
122
|
beginStateTransaction(
|
|
106
123
|
timeoutMs?: number,
|
|
107
124
|
context?: unknown,
|
|
108
125
|
): Promise<SqliteTransactionDatabase>;
|
|
109
126
|
};
|
|
110
127
|
|
|
128
|
+
type NativeSqliteDatabase = StateAwareSqliteDatabase & {
|
|
129
|
+
/** Stop JS calls while leaving the runtime-owned backend open. */
|
|
130
|
+
detachForShutdown(): Promise<void>;
|
|
131
|
+
};
|
|
132
|
+
|
|
111
133
|
export interface JsNativeTransactionLike {
|
|
112
134
|
exec(sql: string): Promise<NativeExecResult>;
|
|
113
135
|
execute(
|
|
@@ -118,6 +140,28 @@ export interface JsNativeTransactionLike {
|
|
|
118
140
|
rollback(): Promise<void>;
|
|
119
141
|
}
|
|
120
142
|
|
|
143
|
+
export interface JsNativeSynchronousTransactionLike
|
|
144
|
+
extends JsNativeTransactionLike {
|
|
145
|
+
execSync(sql: string): NativeExecResult;
|
|
146
|
+
executeSync(
|
|
147
|
+
sql: string,
|
|
148
|
+
params?: NativeBindParam[] | null,
|
|
149
|
+
): NativeExecuteResult;
|
|
150
|
+
commitSync(): void;
|
|
151
|
+
rollbackSync(): void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function isSynchronousTransaction(
|
|
155
|
+
transaction: JsNativeTransactionLike,
|
|
156
|
+
): transaction is JsNativeSynchronousTransactionLike {
|
|
157
|
+
const candidate =
|
|
158
|
+
transaction as Partial<JsNativeSynchronousTransactionLike>;
|
|
159
|
+
return (
|
|
160
|
+
typeof candidate.commitSync === "function" &&
|
|
161
|
+
typeof candidate.rollbackSync === "function"
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
121
165
|
function shouldAttachNativeKvError(message: string): boolean {
|
|
122
166
|
return /i\/o error|unable to open database file/i.test(message);
|
|
123
167
|
}
|
|
@@ -156,13 +200,19 @@ function toNativeBinding(arg: unknown): NativeBindParam {
|
|
|
156
200
|
if (arg === null || arg === undefined) {
|
|
157
201
|
return { kind: "null" };
|
|
158
202
|
}
|
|
159
|
-
if (
|
|
160
|
-
|
|
203
|
+
if (
|
|
204
|
+
typeof arg === "bigint" ||
|
|
205
|
+
(typeof arg === "number" && Number.isInteger(arg))
|
|
206
|
+
) {
|
|
207
|
+
const value = Number(arg);
|
|
208
|
+
if (!Number.isSafeInteger(value)) {
|
|
209
|
+
throw new RangeError(
|
|
210
|
+
"SQLite integer bindings must be within the JavaScript safe integer range.",
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return { kind: "int", intValue: value };
|
|
161
214
|
}
|
|
162
215
|
if (typeof arg === "number") {
|
|
163
|
-
if (Number.isInteger(arg)) {
|
|
164
|
-
return { kind: "int", intValue: arg };
|
|
165
|
-
}
|
|
166
216
|
return { kind: "float", floatValue: arg };
|
|
167
217
|
}
|
|
168
218
|
if (typeof arg === "string") {
|
|
@@ -180,9 +230,13 @@ function toNativeBinding(arg: unknown): NativeBindParam {
|
|
|
180
230
|
function extractNamedSqliteParameters(sql: string): string[] {
|
|
181
231
|
const orderedNames: string[] = [];
|
|
182
232
|
const seen = new Set<string>();
|
|
183
|
-
|
|
233
|
+
// SQLite identifiers may contain "$" and any non-ASCII character. Consume
|
|
234
|
+
// whole identifiers so their suffixes cannot be mistaken for parameters.
|
|
235
|
+
const pattern =
|
|
236
|
+
/'(?:''|[^'])*'|"(?:""|[^"])*"|`(?:``|[^`])*`|\[[^\]]*\]|--[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|([:@$][\w$\u0080-\u{10FFFF}]+(?:::[\w$\u0080-\u{10FFFF}]+)*(?:\([^)]*\))?)|[A-Za-z_\u0080-\u{10FFFF}][\w$\u0080-\u{10FFFF}]*/gu;
|
|
184
237
|
for (const match of sql.matchAll(pattern)) {
|
|
185
238
|
const name = match[1];
|
|
239
|
+
if (!name) continue;
|
|
186
240
|
if (seen.has(name)) {
|
|
187
241
|
continue;
|
|
188
242
|
}
|
|
@@ -311,7 +365,7 @@ class NativeCloseGate {
|
|
|
311
365
|
};
|
|
312
366
|
}
|
|
313
367
|
|
|
314
|
-
async close(callback
|
|
368
|
+
async close(callback?: () => Promise<void>): Promise<void> {
|
|
315
369
|
if (this.#closed) {
|
|
316
370
|
return;
|
|
317
371
|
}
|
|
@@ -319,36 +373,66 @@ class NativeCloseGate {
|
|
|
319
373
|
if (this.#active > 0) {
|
|
320
374
|
await new Promise<void>((resolve) => this.#waiters.push(resolve));
|
|
321
375
|
}
|
|
322
|
-
await callback();
|
|
376
|
+
await callback?.();
|
|
323
377
|
}
|
|
324
378
|
}
|
|
325
379
|
|
|
326
380
|
export function wrapJsNativeDatabase(
|
|
327
381
|
database: JsNativeDatabaseLike,
|
|
328
|
-
):
|
|
382
|
+
): NativeSqliteDatabase {
|
|
329
383
|
const gate = new NativeCloseGate();
|
|
330
|
-
|
|
384
|
+
// Detach and explicit close are mutually exclusive terminal operations.
|
|
385
|
+
// Whichever starts first defines whether the backend is physically closed.
|
|
386
|
+
let terminalPromise: Promise<void> | undefined;
|
|
331
387
|
let lastInsertRowId: number | null = null;
|
|
332
388
|
|
|
333
389
|
const executeNative = async (
|
|
334
390
|
sql: string,
|
|
335
391
|
params?: SqliteBindings,
|
|
336
392
|
): Promise<SqliteExecuteResult> => {
|
|
337
|
-
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
338
|
-
if (lastInsertRowIdColumn) {
|
|
339
|
-
return {
|
|
340
|
-
columns: [lastInsertRowIdColumn],
|
|
341
|
-
rows: [[lastInsertRowId ?? 0]],
|
|
342
|
-
changes: 0,
|
|
343
|
-
lastInsertRowId,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
|
|
347
393
|
const release = gate.enter();
|
|
348
394
|
try {
|
|
395
|
+
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
396
|
+
if (lastInsertRowIdColumn) {
|
|
397
|
+
return {
|
|
398
|
+
columns: [lastInsertRowIdColumn],
|
|
399
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
400
|
+
changes: 0,
|
|
401
|
+
lastInsertRowId,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
349
405
|
const nativeParams = toNativeBindings(sql, params);
|
|
350
406
|
const result = await database.execute(sql, nativeParams);
|
|
351
|
-
if (result.lastInsertRowId
|
|
407
|
+
if (result.lastInsertRowId != null) {
|
|
408
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
409
|
+
}
|
|
410
|
+
return result;
|
|
411
|
+
} catch (error) {
|
|
412
|
+
enrichNativeDatabaseError(database, error);
|
|
413
|
+
} finally {
|
|
414
|
+
release();
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
const executeNativeSync = (
|
|
418
|
+
sql: string,
|
|
419
|
+
params?: SqliteBindings,
|
|
420
|
+
): SqliteExecuteResult => {
|
|
421
|
+
const release = gate.enter();
|
|
422
|
+
try {
|
|
423
|
+
const nativeParams = toNativeBindings(sql, params);
|
|
424
|
+
const result = database.executeSync(sql, nativeParams);
|
|
425
|
+
// Execute first so runtime availability and transaction admission are enforced.
|
|
426
|
+
const rowIdColumn = lastInsertRowIdColumnName(sql);
|
|
427
|
+
if (rowIdColumn) {
|
|
428
|
+
return {
|
|
429
|
+
columns: [rowIdColumn],
|
|
430
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
431
|
+
changes: 0,
|
|
432
|
+
lastInsertRowId,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
if (result.lastInsertRowId != null) {
|
|
352
436
|
lastInsertRowId = result.lastInsertRowId;
|
|
353
437
|
}
|
|
354
438
|
return result;
|
|
@@ -380,12 +464,34 @@ export function wrapJsNativeDatabase(
|
|
|
380
464
|
callback(row, result.columns);
|
|
381
465
|
}
|
|
382
466
|
},
|
|
467
|
+
execSync(
|
|
468
|
+
sql: string,
|
|
469
|
+
callback?: (row: unknown[], columns: string[]) => void,
|
|
470
|
+
): void {
|
|
471
|
+
const release = gate.enter();
|
|
472
|
+
let result: NativeExecResult;
|
|
473
|
+
try {
|
|
474
|
+
result = database.execSync(sql);
|
|
475
|
+
} catch (error) {
|
|
476
|
+
enrichNativeDatabaseError(database, error);
|
|
477
|
+
} finally {
|
|
478
|
+
release();
|
|
479
|
+
}
|
|
480
|
+
if (callback) {
|
|
481
|
+
for (const row of result.rows) {
|
|
482
|
+
callback(row, result.columns);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
},
|
|
383
486
|
async execute(
|
|
384
487
|
sql: string,
|
|
385
488
|
params?: SqliteBindings,
|
|
386
489
|
): Promise<SqliteExecuteResult> {
|
|
387
490
|
return await executeNative(sql, params);
|
|
388
491
|
},
|
|
492
|
+
executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult {
|
|
493
|
+
return executeNativeSync(sql, params);
|
|
494
|
+
},
|
|
389
495
|
async executeBatch(
|
|
390
496
|
statements: SqliteBatchStatement[],
|
|
391
497
|
): Promise<SqliteExecuteResult[]> {
|
|
@@ -412,7 +518,7 @@ export function wrapJsNativeDatabase(
|
|
|
412
518
|
return transactionResults;
|
|
413
519
|
})();
|
|
414
520
|
for (const result of results) {
|
|
415
|
-
if (result.lastInsertRowId
|
|
521
|
+
if (result.lastInsertRowId != null) {
|
|
416
522
|
lastInsertRowId = result.lastInsertRowId;
|
|
417
523
|
}
|
|
418
524
|
}
|
|
@@ -444,7 +550,26 @@ export function wrapJsNativeDatabase(
|
|
|
444
550
|
release();
|
|
445
551
|
}
|
|
446
552
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
447
|
-
if (result.lastInsertRowId
|
|
553
|
+
if (result.lastInsertRowId != null) {
|
|
554
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
},
|
|
558
|
+
beginTransactionSync(
|
|
559
|
+
timeoutMs?: number,
|
|
560
|
+
name?: string,
|
|
561
|
+
): SynchronousSqliteTransactionDatabase {
|
|
562
|
+
const release = gate.enter();
|
|
563
|
+
let transaction: JsNativeSynchronousTransactionLike;
|
|
564
|
+
try {
|
|
565
|
+
transaction = database.beginTransactionSync(timeoutMs, name);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
enrichNativeDatabaseError(database, error);
|
|
568
|
+
} finally {
|
|
569
|
+
release();
|
|
570
|
+
}
|
|
571
|
+
return wrapTransaction(database, transaction, gate, (result) => {
|
|
572
|
+
if (result.lastInsertRowId != null) {
|
|
448
573
|
lastInsertRowId = result.lastInsertRowId;
|
|
449
574
|
}
|
|
450
575
|
});
|
|
@@ -469,7 +594,7 @@ export function wrapJsNativeDatabase(
|
|
|
469
594
|
release();
|
|
470
595
|
}
|
|
471
596
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
472
|
-
if (result.lastInsertRowId
|
|
597
|
+
if (result.lastInsertRowId != null) {
|
|
473
598
|
lastInsertRowId = result.lastInsertRowId;
|
|
474
599
|
}
|
|
475
600
|
});
|
|
@@ -484,20 +609,55 @@ export function wrapJsNativeDatabase(
|
|
|
484
609
|
nativeMetrics(): SqliteNativeMetrics | null {
|
|
485
610
|
return normalizeNativeMetrics(database.metrics?.());
|
|
486
611
|
},
|
|
612
|
+
async open(): Promise<void> {
|
|
613
|
+
const release = gate.enter();
|
|
614
|
+
try {
|
|
615
|
+
await database.open();
|
|
616
|
+
} catch (error) {
|
|
617
|
+
enrichNativeDatabaseError(database, error);
|
|
618
|
+
} finally {
|
|
619
|
+
release();
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
commitTicket(): number {
|
|
623
|
+
return database.commitTicket();
|
|
624
|
+
},
|
|
625
|
+
async whenDurable(ticket: number): Promise<void> {
|
|
626
|
+
await database.whenDurable(ticket);
|
|
627
|
+
},
|
|
628
|
+
abortGeneration(reason: string): void {
|
|
629
|
+
database.abortGeneration(reason);
|
|
630
|
+
},
|
|
487
631
|
async close(): Promise<void> {
|
|
488
|
-
|
|
489
|
-
await
|
|
632
|
+
terminalPromise ??= gate.close(() => database.close());
|
|
633
|
+
await terminalPromise;
|
|
634
|
+
},
|
|
635
|
+
async detachForShutdown(): Promise<void> {
|
|
636
|
+
terminalPromise ??= gate.close();
|
|
637
|
+
await terminalPromise;
|
|
490
638
|
},
|
|
491
639
|
};
|
|
492
640
|
}
|
|
493
641
|
|
|
642
|
+
function wrapTransaction(
|
|
643
|
+
database: JsNativeDatabaseLike,
|
|
644
|
+
transaction: JsNativeSynchronousTransactionLike,
|
|
645
|
+
gate: NativeCloseGate,
|
|
646
|
+
onExecute: (result: NativeExecuteResult) => void,
|
|
647
|
+
): SynchronousSqliteTransactionDatabase;
|
|
648
|
+
function wrapTransaction(
|
|
649
|
+
database: JsNativeDatabaseLike,
|
|
650
|
+
transaction: JsNativeTransactionLike,
|
|
651
|
+
gate: NativeCloseGate,
|
|
652
|
+
onExecute: (result: NativeExecuteResult) => void,
|
|
653
|
+
): SqliteTransactionDatabase;
|
|
494
654
|
function wrapTransaction(
|
|
495
655
|
database: JsNativeDatabaseLike,
|
|
496
656
|
transaction: JsNativeTransactionLike,
|
|
497
657
|
gate: NativeCloseGate,
|
|
498
658
|
onExecute: (result: NativeExecuteResult) => void,
|
|
499
659
|
): SqliteTransactionDatabase {
|
|
500
|
-
|
|
660
|
+
const wrapped: SqliteTransactionDatabase = {
|
|
501
661
|
async exec(sql, callback) {
|
|
502
662
|
const release = gate.enter();
|
|
503
663
|
let result: NativeExecResult;
|
|
@@ -548,6 +708,66 @@ function wrapTransaction(
|
|
|
548
708
|
}
|
|
549
709
|
},
|
|
550
710
|
};
|
|
711
|
+
|
|
712
|
+
if (isSynchronousTransaction(transaction)) {
|
|
713
|
+
return Object.assign(wrapped, {
|
|
714
|
+
execSync(
|
|
715
|
+
sql: string,
|
|
716
|
+
callback?: (row: unknown[], columns: string[]) => void,
|
|
717
|
+
) {
|
|
718
|
+
const release = gate.enter();
|
|
719
|
+
let result: NativeExecResult;
|
|
720
|
+
try {
|
|
721
|
+
result = transaction.execSync(sql);
|
|
722
|
+
} catch (error) {
|
|
723
|
+
enrichNativeDatabaseError(database, error);
|
|
724
|
+
} finally {
|
|
725
|
+
release();
|
|
726
|
+
}
|
|
727
|
+
if (callback) {
|
|
728
|
+
for (const row of result.rows)
|
|
729
|
+
callback(row, result.columns);
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
executeSync(sql: string, params?: SqliteBindings) {
|
|
733
|
+
const release = gate.enter();
|
|
734
|
+
try {
|
|
735
|
+
const result = transaction.executeSync(
|
|
736
|
+
sql,
|
|
737
|
+
toNativeBindings(sql, params),
|
|
738
|
+
);
|
|
739
|
+
onExecute(result);
|
|
740
|
+
return result;
|
|
741
|
+
} catch (error) {
|
|
742
|
+
enrichNativeDatabaseError(database, error);
|
|
743
|
+
} finally {
|
|
744
|
+
release();
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
commitSync() {
|
|
748
|
+
const release = gate.enter();
|
|
749
|
+
try {
|
|
750
|
+
transaction.commitSync();
|
|
751
|
+
} catch (error) {
|
|
752
|
+
enrichNativeDatabaseError(database, error);
|
|
753
|
+
} finally {
|
|
754
|
+
release();
|
|
755
|
+
}
|
|
756
|
+
},
|
|
757
|
+
rollbackSync() {
|
|
758
|
+
const release = gate.enter();
|
|
759
|
+
try {
|
|
760
|
+
transaction.rollbackSync();
|
|
761
|
+
} catch (error) {
|
|
762
|
+
enrichNativeDatabaseError(database, error);
|
|
763
|
+
} finally {
|
|
764
|
+
release();
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
}) as SynchronousSqliteTransactionDatabase;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return wrapped;
|
|
551
771
|
}
|
|
552
772
|
|
|
553
773
|
function lastInsertRowIdColumnName(sql: string): string | undefined {
|
package/src/common/router.ts
CHANGED
|
@@ -182,7 +182,7 @@ export function handleMetadataRequest(
|
|
|
182
182
|
version: VERSION,
|
|
183
183
|
envoy: {
|
|
184
184
|
kind: envoyKind,
|
|
185
|
-
version: config.
|
|
185
|
+
version: config.node.version,
|
|
186
186
|
},
|
|
187
187
|
envoyProtocolVersion: envoyProtocol.VERSION,
|
|
188
188
|
actorNames: buildActorNames(config),
|
package/src/db/mod.ts
CHANGED
package/src/engine-api/actors.ts
CHANGED
|
@@ -6,7 +6,7 @@ export const ActorSchema = z.object({
|
|
|
6
6
|
name: z.string(),
|
|
7
7
|
key: z.string(),
|
|
8
8
|
namespace_id: RivetIdSchema,
|
|
9
|
-
|
|
9
|
+
pool: z.string(),
|
|
10
10
|
create_ts: z.number(),
|
|
11
11
|
connectable_ts: z.number().nullable().optional(),
|
|
12
12
|
destroy_ts: z.number().nullable().optional(),
|
|
@@ -31,7 +31,7 @@ export type ActorsListResponse = z.infer<typeof ActorsListResponseSchema>;
|
|
|
31
31
|
export const ActorsCreateRequestSchema = z.object({
|
|
32
32
|
datacenter: z.string().optional(),
|
|
33
33
|
name: z.string(),
|
|
34
|
-
|
|
34
|
+
pool: z.string(),
|
|
35
35
|
crash_policy: z.string(),
|
|
36
36
|
key: z.string().nullable().optional(),
|
|
37
37
|
input: z.string().nullable().optional(),
|
|
@@ -48,7 +48,7 @@ export const ActorsGetOrCreateRequestSchema = z.object({
|
|
|
48
48
|
datacenter: z.string().optional(),
|
|
49
49
|
name: z.string(),
|
|
50
50
|
key: z.string(),
|
|
51
|
-
|
|
51
|
+
pool: z.string(),
|
|
52
52
|
crash_policy: z.string(),
|
|
53
53
|
input: z.string().nullable().optional(),
|
|
54
54
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { actorKeyToGatewayQuery } from "@/actor/keys";
|
|
1
2
|
import {
|
|
2
3
|
type ClientConfig,
|
|
3
4
|
DEFAULT_MAX_QUERY_INPUT_SIZE,
|
|
@@ -289,8 +290,9 @@ export function buildActorQueryGatewayUrl(
|
|
|
289
290
|
}
|
|
290
291
|
|
|
291
292
|
function pushKeyQueryParams(params: URLSearchParams, key: string[]): void {
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
const rvtKey = actorKeyToGatewayQuery(key);
|
|
294
|
+
if (rvtKey !== undefined) {
|
|
295
|
+
params.append("rvt-key", rvtKey);
|
|
294
296
|
}
|
|
295
297
|
}
|
|
296
298
|
|