rivetkit 0.0.0-sqlite-sync-3-0-1-release.95f6e2d → 0.0.0-sqlite-query-metrics-v3.1dff84f
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 +58 -48
- package/dist/browser/client.js +67 -7
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +4 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/{chunk-UHMB5FFB.cjs → chunk-22S5RCCJ.cjs} +3 -3
- package/dist/tsup/{chunk-UHMB5FFB.cjs.map → chunk-22S5RCCJ.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZMVYZ7ZI.js → chunk-2CTZU7GL.js} +2 -2
- package/dist/tsup/{chunk-VKXEBB3Z.cjs → chunk-CWN7N5AF.cjs} +7 -7
- package/dist/tsup/{chunk-VKXEBB3Z.cjs.map → chunk-CWN7N5AF.cjs.map} +1 -1
- package/dist/tsup/{chunk-2HWY7FZU.js → chunk-D7DWNYEO.js} +2 -2
- package/dist/tsup/{chunk-OWZ76NSH.js → chunk-F5PWAGS7.js} +2 -2
- package/dist/tsup/{chunk-QIIIRYN7.js → chunk-FT6VRK4C.js} +2 -2
- package/dist/tsup/{chunk-MYWNJP55.cjs → chunk-HFGXV2CC.cjs} +10 -10
- package/dist/tsup/{chunk-MYWNJP55.cjs.map → chunk-HFGXV2CC.cjs.map} +1 -1
- package/dist/tsup/{chunk-QFZY2CK3.js → chunk-HRKFVQPS.js} +4 -4
- package/dist/tsup/{chunk-E6HKVCPA.cjs → chunk-HXJ5U2ZI.cjs} +3 -3
- package/dist/tsup/{chunk-E6HKVCPA.cjs.map → chunk-HXJ5U2ZI.cjs.map} +1 -1
- package/dist/tsup/{chunk-E4KDQJCR.cjs → chunk-JJUSO7GJ.cjs} +3 -3
- package/dist/tsup/{chunk-E4KDQJCR.cjs.map → chunk-JJUSO7GJ.cjs.map} +1 -1
- package/dist/tsup/{chunk-EQBUH25O.cjs → chunk-NG5CUXMM.cjs} +203 -146
- package/dist/tsup/chunk-NG5CUXMM.cjs.map +1 -0
- package/dist/tsup/{chunk-HQHTTJW5.js → chunk-NNCL4IBC.js} +9 -3
- package/dist/tsup/chunk-NNCL4IBC.js.map +1 -0
- package/dist/tsup/{chunk-62WFU3BQ.js → chunk-QQIFRR3B.js} +69 -12
- package/dist/tsup/chunk-QQIFRR3B.js.map +1 -0
- package/dist/tsup/{chunk-HDVZ6YZG.cjs → chunk-SSF2XC33.cjs} +1 -1
- package/dist/tsup/chunk-SSF2XC33.cjs.map +1 -0
- package/dist/tsup/{chunk-QE5MTZHB.js → chunk-SW33HMM5.js} +3 -3
- package/dist/tsup/{chunk-6FEYCVZC.js → chunk-UXDASKP6.js} +1 -1
- package/dist/tsup/chunk-UXDASKP6.js.map +1 -0
- package/dist/tsup/{chunk-AQWZWR2P.cjs → chunk-Y4QLVCCS.cjs} +9 -3
- package/dist/tsup/chunk-Y4QLVCCS.cjs.map +1 -0
- package/dist/tsup/{chunk-M5SQGPRJ.cjs → chunk-Y5CFDGPA.cjs} +4 -4
- package/dist/tsup/{chunk-M5SQGPRJ.cjs.map → chunk-Y5CFDGPA.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +5 -5
- package/dist/tsup/client/mod.d.cts +3 -3
- package/dist/tsup/client/mod.d.ts +3 -3
- package/dist/tsup/client/mod.js +4 -4
- 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-B4erdavw.d.ts → config-BiiS5T5M.d.ts} +3 -16
- package/dist/tsup/{config-DK144OAw.d.cts → config-BnMhcPHl.d.cts} +3 -16
- package/dist/tsup/{config-BfG1qpYz.d.cts → config-CBTr4IhE.d.cts} +50 -34
- package/dist/tsup/{config-BfG1qpYz.d.ts → config-CBTr4IhE.d.ts} +50 -34
- package/dist/tsup/{context-Cvnf3BRe.d.cts → context-DVE8XMm1.d.cts} +2 -2
- package/dist/tsup/{context-Oxi6YWcG.d.ts → context-iMxXq_Lt.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.cjs +2 -2
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/dynamic/mod.js +1 -1
- 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.cjs +2 -2
- package/dist/tsup/inspector-tab/mod.d.cts +3 -3
- package/dist/tsup/inspector-tab/mod.d.ts +3 -3
- package/dist/tsup/inspector-tab/mod.js +1 -1
- package/dist/tsup/mod.cjs +166 -417
- 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 +67 -318
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +6 -6
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +4 -4
- 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 +10 -10
- 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 +12 -9
- package/src/actor/config.ts +2 -0
- package/src/client/actor-handle.ts +43 -7
- package/src/client/raw-utils.ts +17 -3
- package/src/client/utils.ts +4 -0
- package/src/common/database/config.ts +50 -46
- package/src/common/database/native-database.ts +21 -230
- package/src/db/mod.ts +1 -0
- package/src/registry/config/index.ts +7 -5
- package/src/registry/napi-runtime.ts +0 -78
- package/src/registry/native.ts +41 -74
- package/src/registry/runtime.ts +1 -53
- package/src/registry/wasm-runtime.ts +0 -88
- package/src/utils/env-vars.ts +4 -2
- package/dist/tsup/chunk-62WFU3BQ.js.map +0 -1
- package/dist/tsup/chunk-6FEYCVZC.js.map +0 -1
- package/dist/tsup/chunk-AQWZWR2P.cjs.map +0 -1
- package/dist/tsup/chunk-EQBUH25O.cjs.map +0 -1
- package/dist/tsup/chunk-HDVZ6YZG.cjs.map +0 -1
- package/dist/tsup/chunk-HQHTTJW5.js.map +0 -1
- /package/dist/tsup/{chunk-ZMVYZ7ZI.js.map → chunk-2CTZU7GL.js.map} +0 -0
- /package/dist/tsup/{chunk-2HWY7FZU.js.map → chunk-D7DWNYEO.js.map} +0 -0
- /package/dist/tsup/{chunk-OWZ76NSH.js.map → chunk-F5PWAGS7.js.map} +0 -0
- /package/dist/tsup/{chunk-QIIIRYN7.js.map → chunk-FT6VRK4C.js.map} +0 -0
- /package/dist/tsup/{chunk-QFZY2CK3.js.map → chunk-HRKFVQPS.js.map} +0 -0
- /package/dist/tsup/{chunk-QE5MTZHB.js.map → chunk-SW33HMM5.js.map} +0 -0
|
@@ -200,8 +200,16 @@ export class ActorHandleRaw {
|
|
|
200
200
|
},
|
|
201
201
|
}).send(name, body, options as any);
|
|
202
202
|
} catch (err) {
|
|
203
|
-
const {
|
|
204
|
-
|
|
203
|
+
const {
|
|
204
|
+
group,
|
|
205
|
+
code,
|
|
206
|
+
message,
|
|
207
|
+
metadata,
|
|
208
|
+
rayId,
|
|
209
|
+
actor,
|
|
210
|
+
public: isPublic,
|
|
211
|
+
statusCode,
|
|
212
|
+
} = deconstructError(err, true);
|
|
205
213
|
|
|
206
214
|
if (
|
|
207
215
|
this.#shouldRetryQueueDispatchOverload(
|
|
@@ -272,6 +280,8 @@ export class ActorHandleRaw {
|
|
|
272
280
|
}
|
|
273
281
|
|
|
274
282
|
throw new ActorError(group, code, message, {
|
|
283
|
+
public: isPublic,
|
|
284
|
+
statusCode,
|
|
275
285
|
metadata,
|
|
276
286
|
rayId,
|
|
277
287
|
actor,
|
|
@@ -434,8 +444,16 @@ export class ActorHandleRaw {
|
|
|
434
444
|
}
|
|
435
445
|
return output;
|
|
436
446
|
} catch (err) {
|
|
437
|
-
const {
|
|
438
|
-
|
|
447
|
+
const {
|
|
448
|
+
group,
|
|
449
|
+
code,
|
|
450
|
+
message,
|
|
451
|
+
metadata,
|
|
452
|
+
rayId,
|
|
453
|
+
actor,
|
|
454
|
+
public: isPublic,
|
|
455
|
+
statusCode,
|
|
456
|
+
} = deconstructError(err, true);
|
|
439
457
|
|
|
440
458
|
if (
|
|
441
459
|
await this.#shouldRetrySchedulingError(
|
|
@@ -476,7 +494,13 @@ export class ActorHandleRaw {
|
|
|
476
494
|
"actor",
|
|
477
495
|
"not_found",
|
|
478
496
|
"The actor does not exist or was destroyed.",
|
|
479
|
-
{
|
|
497
|
+
{
|
|
498
|
+
public: true,
|
|
499
|
+
statusCode: 404,
|
|
500
|
+
metadata,
|
|
501
|
+
rayId,
|
|
502
|
+
actor,
|
|
503
|
+
},
|
|
480
504
|
);
|
|
481
505
|
}
|
|
482
506
|
|
|
@@ -498,6 +522,8 @@ export class ActorHandleRaw {
|
|
|
498
522
|
}
|
|
499
523
|
|
|
500
524
|
throw new ActorError(group, code, message, {
|
|
525
|
+
public: isPublic,
|
|
526
|
+
statusCode,
|
|
501
527
|
metadata,
|
|
502
528
|
rayId,
|
|
503
529
|
actor,
|
|
@@ -779,8 +805,16 @@ export class ActorHandleRaw {
|
|
|
779
805
|
}
|
|
780
806
|
return response;
|
|
781
807
|
} catch (err) {
|
|
782
|
-
const {
|
|
783
|
-
|
|
808
|
+
const {
|
|
809
|
+
group,
|
|
810
|
+
code,
|
|
811
|
+
message,
|
|
812
|
+
metadata,
|
|
813
|
+
rayId,
|
|
814
|
+
actor,
|
|
815
|
+
public: isPublic,
|
|
816
|
+
statusCode,
|
|
817
|
+
} = deconstructError(err, true);
|
|
784
818
|
|
|
785
819
|
if (
|
|
786
820
|
await this.#shouldRetrySchedulingError(
|
|
@@ -828,6 +862,8 @@ export class ActorHandleRaw {
|
|
|
828
862
|
}
|
|
829
863
|
|
|
830
864
|
throw new ActorError(group, code, message, {
|
|
865
|
+
public: isPublic,
|
|
866
|
+
statusCode,
|
|
831
867
|
metadata,
|
|
832
868
|
rayId,
|
|
833
869
|
actor,
|
package/src/client/raw-utils.ts
CHANGED
|
@@ -129,9 +129,23 @@ export async function rawHttpFetch(
|
|
|
129
129
|
return driver.sendRequest(target, proxyRequest, options);
|
|
130
130
|
} catch (err) {
|
|
131
131
|
// Standardize to ClientActorError instead of the native backend error
|
|
132
|
-
const {
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
const {
|
|
133
|
+
group,
|
|
134
|
+
code,
|
|
135
|
+
message,
|
|
136
|
+
metadata,
|
|
137
|
+
rayId,
|
|
138
|
+
actor,
|
|
139
|
+
public: isPublic,
|
|
140
|
+
statusCode,
|
|
141
|
+
} = deconstructError(err, true);
|
|
142
|
+
throw new ActorError(group, code, message, {
|
|
143
|
+
public: isPublic,
|
|
144
|
+
statusCode,
|
|
145
|
+
metadata,
|
|
146
|
+
rayId,
|
|
147
|
+
actor,
|
|
148
|
+
});
|
|
135
149
|
}
|
|
136
150
|
}
|
|
137
151
|
|
package/src/client/utils.ts
CHANGED
|
@@ -169,6 +169,10 @@ export async function sendHttpRequest<
|
|
|
169
169
|
}),
|
|
170
170
|
);
|
|
171
171
|
} catch (error) {
|
|
172
|
+
// Credential providers and custom transports can already supply a structured error.
|
|
173
|
+
if (ActorError.isRivetError(error)) {
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
172
176
|
throw new HttpRequestError(`Request failed: ${error}`, {
|
|
173
177
|
cause: error,
|
|
174
178
|
});
|
|
@@ -52,13 +52,16 @@ export interface SqliteTransactionOptions {
|
|
|
52
52
|
* to change without notice.
|
|
53
53
|
*/
|
|
54
54
|
export interface SqliteProfilingOptions {
|
|
55
|
-
/** Exact SQL
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
/** Exact SQL filter. Union with filterQueryFingerprints; both empty means all queries. */
|
|
56
|
+
filterQueries?: string[];
|
|
57
|
+
/** Fingerprint filter, including transaction fingerprints. Filters metrics, not diagnostic logs. */
|
|
58
|
+
filterQueryFingerprints?: string[];
|
|
59
|
+
/** Metric defaults apply even when omitted. Disabled metrics allocate no series. */
|
|
60
|
+
metrics?: SqliteProfilingMetricsOptions;
|
|
61
|
+
/** Duration buckets in seconds. Default [0.01, 0.1, 1]. Positive, finite, strictly increasing.
|
|
62
|
+
* All actors in a process enabling the duration histogram must use identical buckets. */
|
|
63
|
+
durationHistogramBucketsSeconds?: number[];
|
|
64
|
+
/** Maximum distinct statement fingerprints per process. Default: 512. */
|
|
62
65
|
maxTrackedStatementFingerprints?: number;
|
|
63
66
|
maxTrackedTransactionFingerprints?: number;
|
|
64
67
|
maxPrometheusSeries?: number;
|
|
@@ -71,6 +74,46 @@ export interface SqliteProfilingOptions {
|
|
|
71
74
|
diagnosticEventQueueCapacity?: number;
|
|
72
75
|
}
|
|
73
76
|
|
|
77
|
+
/** SQLite profiling metrics. Physical-request metrics and gauges have no query labels. */
|
|
78
|
+
export interface SqliteProfilingMetricsOptions {
|
|
79
|
+
/** Execution count and cumulative seconds. Uses histogram count/sum when enabled, otherwise counters. Default: true. */
|
|
80
|
+
duration?: boolean;
|
|
81
|
+
/** Execution duration histogram. Only applies when duration is enabled. Default: true. */
|
|
82
|
+
durationHistogram?: boolean;
|
|
83
|
+
/** Outcome counters, including success and errors. Default: true. */
|
|
84
|
+
outcomes?: boolean;
|
|
85
|
+
/** Per-query timing phase histograms. Default: false. */
|
|
86
|
+
phaseDurationHistogram?: boolean;
|
|
87
|
+
/** Storage round trips per operation histogram. Default: false. */
|
|
88
|
+
getPagesRoundTripsHistogram?: boolean;
|
|
89
|
+
/** Statements per transaction histogram. Default: false. */
|
|
90
|
+
transactionStatementCountHistogram?: boolean;
|
|
91
|
+
/** Per-query pages returned from storage, including returned prefetch pages. Default: true. */
|
|
92
|
+
pagesFetched?: boolean;
|
|
93
|
+
/** Actor-level page counters by page kind (no query labels). Default: false. */
|
|
94
|
+
localPages?: boolean;
|
|
95
|
+
/** Actor-level byte counters by byte kind (no query labels). Default: false. */
|
|
96
|
+
localBytes?: boolean;
|
|
97
|
+
/** Actor-level physical storage request duration histogram. Default: false. */
|
|
98
|
+
getPagesDurationHistogram?: boolean;
|
|
99
|
+
/** Actor-level pages per storage request histograms, by page kind. Default: false. */
|
|
100
|
+
getPagesPagesHistogram?: boolean;
|
|
101
|
+
/** Actor-level storage response byte histogram. Default: false. */
|
|
102
|
+
getPagesResponseBytesHistogram?: boolean;
|
|
103
|
+
/** Actor-level missing response page counter. Default: false. */
|
|
104
|
+
getPagesMissingPages?: boolean;
|
|
105
|
+
/** Queued SQLite work, aggregated by actor name. Default: true. */
|
|
106
|
+
workerQueueDepth?: boolean;
|
|
107
|
+
/** Executing SQLite work, aggregated by actor name. Default: true. */
|
|
108
|
+
workerInflight?: boolean;
|
|
109
|
+
/** Transaction waiters, aggregated by actor name. Default: true. */
|
|
110
|
+
coordinatorQueueDepth?: boolean;
|
|
111
|
+
/** Counts observations exceeding fingerprint or series limits. Default: true. */
|
|
112
|
+
fingerprintOverflow?: boolean;
|
|
113
|
+
/** Counts diagnostic events dropped by rate limits or backpressure. Default: true. */
|
|
114
|
+
eventDropped?: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
74
117
|
export interface SqliteNativeMetrics {
|
|
75
118
|
requestBuildNs: number;
|
|
76
119
|
serializeNs: number;
|
|
@@ -90,12 +133,7 @@ export interface SqliteDatabase {
|
|
|
90
133
|
sql: string,
|
|
91
134
|
callback?: (row: unknown[], columns: string[]) => void,
|
|
92
135
|
): Promise<void>;
|
|
93
|
-
execSync?(
|
|
94
|
-
sql: string,
|
|
95
|
-
callback?: (row: unknown[], columns: string[]) => void,
|
|
96
|
-
): void;
|
|
97
136
|
execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
|
|
98
|
-
executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
|
|
99
137
|
executeBatch(
|
|
100
138
|
statements: SqliteBatchStatement[],
|
|
101
139
|
): Promise<SqliteExecuteResult[]>;
|
|
@@ -103,31 +141,12 @@ export interface SqliteDatabase {
|
|
|
103
141
|
timeoutMs?: number,
|
|
104
142
|
name?: string,
|
|
105
143
|
): Promise<SqliteTransactionDatabase>;
|
|
106
|
-
beginTransactionSync?(
|
|
107
|
-
timeoutMs?: number,
|
|
108
|
-
name?: string,
|
|
109
|
-
): SynchronousSqliteTransactionDatabase;
|
|
110
144
|
run(sql: string, params?: SqliteBindings): Promise<void>;
|
|
111
145
|
query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
|
|
112
146
|
nativeMetrics?():
|
|
113
147
|
| SqliteNativeMetrics
|
|
114
148
|
| Promise<SqliteNativeMetrics | null>
|
|
115
149
|
| 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;
|
|
131
150
|
close(): Promise<void>;
|
|
132
151
|
}
|
|
133
152
|
|
|
@@ -136,26 +155,11 @@ export interface SqliteTransactionDatabase {
|
|
|
136
155
|
sql: string,
|
|
137
156
|
callback?: (row: unknown[], columns: string[]) => void,
|
|
138
157
|
): Promise<void>;
|
|
139
|
-
execSync?(
|
|
140
|
-
sql: string,
|
|
141
|
-
callback?: (row: unknown[], columns: string[]) => void,
|
|
142
|
-
): void;
|
|
143
158
|
execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
|
|
144
|
-
executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
|
|
145
159
|
commit(): Promise<void>;
|
|
146
160
|
rollback(): Promise<void>;
|
|
147
161
|
}
|
|
148
162
|
|
|
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
|
-
|
|
159
163
|
/**
|
|
160
164
|
* Provider for opening native databases from the active runtime.
|
|
161
165
|
*/
|
|
@@ -6,7 +6,6 @@ import type {
|
|
|
6
6
|
SqliteExecuteResult,
|
|
7
7
|
SqliteNativeMetrics,
|
|
8
8
|
SqliteTransactionDatabase,
|
|
9
|
-
SynchronousSqliteTransactionDatabase,
|
|
10
9
|
} from "./config";
|
|
11
10
|
|
|
12
11
|
type NativeBindNoValues = {
|
|
@@ -75,15 +74,10 @@ interface NativeBatchStatement {
|
|
|
75
74
|
|
|
76
75
|
export interface JsNativeDatabaseLike {
|
|
77
76
|
exec(sql: string): Promise<NativeExecResult>;
|
|
78
|
-
execSync(sql: string): NativeExecResult;
|
|
79
77
|
execute(
|
|
80
78
|
sql: string,
|
|
81
79
|
params?: NativeBindParam[] | null,
|
|
82
80
|
): Promise<NativeExecuteResult>;
|
|
83
|
-
executeSync(
|
|
84
|
-
sql: string,
|
|
85
|
-
params?: NativeBindParam[] | null,
|
|
86
|
-
): NativeExecuteResult;
|
|
87
81
|
executeBatch?(
|
|
88
82
|
statements: NativeBatchStatement[],
|
|
89
83
|
): Promise<NativeExecuteResult[]>;
|
|
@@ -95,10 +89,6 @@ export interface JsNativeDatabaseLike {
|
|
|
95
89
|
timeoutMs?: number,
|
|
96
90
|
name?: string,
|
|
97
91
|
): Promise<JsNativeTransactionLike>;
|
|
98
|
-
beginTransactionSync(
|
|
99
|
-
timeoutMs?: number,
|
|
100
|
-
name?: string,
|
|
101
|
-
): JsNativeSynchronousTransactionLike;
|
|
102
92
|
query(
|
|
103
93
|
sql: string,
|
|
104
94
|
params?: NativeBindParam[] | null,
|
|
@@ -109,16 +99,9 @@ export interface JsNativeDatabaseLike {
|
|
|
109
99
|
): Promise<NativeRunResult>;
|
|
110
100
|
metrics?(): SqliteNativeMetrics | null;
|
|
111
101
|
takeLastKvError?(): string | null;
|
|
112
|
-
open(): Promise<void>;
|
|
113
|
-
commitTicket(): number;
|
|
114
|
-
whenDurable(ticket: number): Promise<void>;
|
|
115
|
-
abortGeneration(reason: string): void;
|
|
116
102
|
close(): Promise<void>;
|
|
117
103
|
}
|
|
118
104
|
export type StateAwareSqliteDatabase = SqliteDatabase & {
|
|
119
|
-
open(): Promise<void>;
|
|
120
|
-
commitTicket(): number;
|
|
121
|
-
whenDurable(ticket: number): Promise<void>;
|
|
122
105
|
beginStateTransaction(
|
|
123
106
|
timeoutMs?: number,
|
|
124
107
|
context?: unknown,
|
|
@@ -140,28 +123,6 @@ export interface JsNativeTransactionLike {
|
|
|
140
123
|
rollback(): Promise<void>;
|
|
141
124
|
}
|
|
142
125
|
|
|
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
|
-
|
|
165
126
|
function shouldAttachNativeKvError(message: string): boolean {
|
|
166
127
|
return /i\/o error|unable to open database file/i.test(message);
|
|
167
128
|
}
|
|
@@ -200,19 +161,13 @@ function toNativeBinding(arg: unknown): NativeBindParam {
|
|
|
200
161
|
if (arg === null || arg === undefined) {
|
|
201
162
|
return { kind: "null" };
|
|
202
163
|
}
|
|
203
|
-
if (
|
|
204
|
-
|
|
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 };
|
|
164
|
+
if (typeof arg === "bigint") {
|
|
165
|
+
return { kind: "int", intValue: Number(arg) };
|
|
214
166
|
}
|
|
215
167
|
if (typeof arg === "number") {
|
|
168
|
+
if (Number.isInteger(arg)) {
|
|
169
|
+
return { kind: "int", intValue: arg };
|
|
170
|
+
}
|
|
216
171
|
return { kind: "float", floatValue: arg };
|
|
217
172
|
}
|
|
218
173
|
if (typeof arg === "string") {
|
|
@@ -230,13 +185,9 @@ function toNativeBinding(arg: unknown): NativeBindParam {
|
|
|
230
185
|
function extractNamedSqliteParameters(sql: string): string[] {
|
|
231
186
|
const orderedNames: string[] = [];
|
|
232
187
|
const seen = new Set<string>();
|
|
233
|
-
|
|
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;
|
|
188
|
+
const pattern = /([:@$][A-Za-z_][A-Za-z0-9_]*)/g;
|
|
237
189
|
for (const match of sql.matchAll(pattern)) {
|
|
238
190
|
const name = match[1];
|
|
239
|
-
if (!name) continue;
|
|
240
191
|
if (seen.has(name)) {
|
|
241
192
|
continue;
|
|
242
193
|
}
|
|
@@ -390,49 +341,21 @@ export function wrapJsNativeDatabase(
|
|
|
390
341
|
sql: string,
|
|
391
342
|
params?: SqliteBindings,
|
|
392
343
|
): Promise<SqliteExecuteResult> => {
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
lastInsertRowId,
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
const nativeParams = toNativeBindings(sql, params);
|
|
406
|
-
const result = await database.execute(sql, nativeParams);
|
|
407
|
-
if (result.lastInsertRowId != null) {
|
|
408
|
-
lastInsertRowId = result.lastInsertRowId;
|
|
409
|
-
}
|
|
410
|
-
return result;
|
|
411
|
-
} catch (error) {
|
|
412
|
-
enrichNativeDatabaseError(database, error);
|
|
413
|
-
} finally {
|
|
414
|
-
release();
|
|
344
|
+
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
345
|
+
if (lastInsertRowIdColumn) {
|
|
346
|
+
return {
|
|
347
|
+
columns: [lastInsertRowIdColumn],
|
|
348
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
349
|
+
changes: 0,
|
|
350
|
+
lastInsertRowId,
|
|
351
|
+
};
|
|
415
352
|
}
|
|
416
|
-
|
|
417
|
-
const executeNativeSync = (
|
|
418
|
-
sql: string,
|
|
419
|
-
params?: SqliteBindings,
|
|
420
|
-
): SqliteExecuteResult => {
|
|
353
|
+
|
|
421
354
|
const release = gate.enter();
|
|
422
355
|
try {
|
|
423
356
|
const nativeParams = toNativeBindings(sql, params);
|
|
424
|
-
const result = database.
|
|
425
|
-
|
|
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) {
|
|
357
|
+
const result = await database.execute(sql, nativeParams);
|
|
358
|
+
if (result.lastInsertRowId !== undefined) {
|
|
436
359
|
lastInsertRowId = result.lastInsertRowId;
|
|
437
360
|
}
|
|
438
361
|
return result;
|
|
@@ -464,34 +387,12 @@ export function wrapJsNativeDatabase(
|
|
|
464
387
|
callback(row, result.columns);
|
|
465
388
|
}
|
|
466
389
|
},
|
|
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
|
-
},
|
|
486
390
|
async execute(
|
|
487
391
|
sql: string,
|
|
488
392
|
params?: SqliteBindings,
|
|
489
393
|
): Promise<SqliteExecuteResult> {
|
|
490
394
|
return await executeNative(sql, params);
|
|
491
395
|
},
|
|
492
|
-
executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult {
|
|
493
|
-
return executeNativeSync(sql, params);
|
|
494
|
-
},
|
|
495
396
|
async executeBatch(
|
|
496
397
|
statements: SqliteBatchStatement[],
|
|
497
398
|
): Promise<SqliteExecuteResult[]> {
|
|
@@ -518,7 +419,7 @@ export function wrapJsNativeDatabase(
|
|
|
518
419
|
return transactionResults;
|
|
519
420
|
})();
|
|
520
421
|
for (const result of results) {
|
|
521
|
-
if (result.lastInsertRowId
|
|
422
|
+
if (result.lastInsertRowId !== undefined) {
|
|
522
423
|
lastInsertRowId = result.lastInsertRowId;
|
|
523
424
|
}
|
|
524
425
|
}
|
|
@@ -550,26 +451,7 @@ export function wrapJsNativeDatabase(
|
|
|
550
451
|
release();
|
|
551
452
|
}
|
|
552
453
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
553
|
-
if (result.lastInsertRowId
|
|
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) {
|
|
454
|
+
if (result.lastInsertRowId !== undefined) {
|
|
573
455
|
lastInsertRowId = result.lastInsertRowId;
|
|
574
456
|
}
|
|
575
457
|
});
|
|
@@ -594,7 +476,7 @@ export function wrapJsNativeDatabase(
|
|
|
594
476
|
release();
|
|
595
477
|
}
|
|
596
478
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
597
|
-
if (result.lastInsertRowId
|
|
479
|
+
if (result.lastInsertRowId !== undefined) {
|
|
598
480
|
lastInsertRowId = result.lastInsertRowId;
|
|
599
481
|
}
|
|
600
482
|
});
|
|
@@ -609,25 +491,6 @@ export function wrapJsNativeDatabase(
|
|
|
609
491
|
nativeMetrics(): SqliteNativeMetrics | null {
|
|
610
492
|
return normalizeNativeMetrics(database.metrics?.());
|
|
611
493
|
},
|
|
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
|
-
},
|
|
631
494
|
async close(): Promise<void> {
|
|
632
495
|
terminalPromise ??= gate.close(() => database.close());
|
|
633
496
|
await terminalPromise;
|
|
@@ -639,25 +502,13 @@ export function wrapJsNativeDatabase(
|
|
|
639
502
|
};
|
|
640
503
|
}
|
|
641
504
|
|
|
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;
|
|
654
505
|
function wrapTransaction(
|
|
655
506
|
database: JsNativeDatabaseLike,
|
|
656
507
|
transaction: JsNativeTransactionLike,
|
|
657
508
|
gate: NativeCloseGate,
|
|
658
509
|
onExecute: (result: NativeExecuteResult) => void,
|
|
659
510
|
): SqliteTransactionDatabase {
|
|
660
|
-
|
|
511
|
+
return {
|
|
661
512
|
async exec(sql, callback) {
|
|
662
513
|
const release = gate.enter();
|
|
663
514
|
let result: NativeExecResult;
|
|
@@ -708,66 +559,6 @@ function wrapTransaction(
|
|
|
708
559
|
}
|
|
709
560
|
},
|
|
710
561
|
};
|
|
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;
|
|
771
562
|
}
|
|
772
563
|
|
|
773
564
|
function lastInsertRowIdColumnName(sql: string): string | undefined {
|