@rivetkit/sqlite-native 2.2.1-pr.4600.b74ff3b

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.
Files changed (4) hide show
  1. package/LICENSE +203 -0
  2. package/index.d.ts +180 -0
  3. package/index.js +324 -0
  4. package/package.json +43 -0
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2023 Rivet Gaming, Inc.
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
package/index.d.ts ADDED
@@ -0,0 +1,180 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ /**
7
+ * Typed bind parameter passed from JavaScript.
8
+ *
9
+ * Replaces `Vec<JsonValue>` for statement parameters, avoiding 20x
10
+ * serialization overhead for blob data. Instead of JSON arrays of numbers,
11
+ * blobs are passed as `Buffer` (a single memcpy from JS heap to Rust).
12
+ *
13
+ * See docs-internal/engine/NATIVE_SQLITE_REVIEW_FIXES.md M7.
14
+ */
15
+ export interface BindParam {
16
+ /** One of: "null", "int", "float", "text", "blob" */
17
+ kind: string
18
+ intValue?: number
19
+ floatValue?: number
20
+ textValue?: string
21
+ blobValue?: Buffer
22
+ }
23
+ /** Configuration for connecting to the KV channel endpoint. */
24
+ export interface ConnectConfig {
25
+ url: string
26
+ token?: string
27
+ namespace: string
28
+ }
29
+ /** Result of an execute() call. */
30
+ export interface ExecuteResult {
31
+ changes: number
32
+ }
33
+ /** Result of a query() call. */
34
+ export interface QueryResult {
35
+ columns: Array<string>
36
+ rows: Array<Array<JsonValue>>
37
+ }
38
+ /**
39
+ * Open the shared KV channel WebSocket connection.
40
+ *
41
+ * In production, token is the engine's admin_token (RIVET__AUTH__ADMIN_TOKEN).
42
+ * In local dev, token is config.token (RIVET_TOKEN), optional in dev mode.
43
+ */
44
+ export declare function connect(config: ConnectConfig): KvChannel
45
+ /**
46
+ * Open a database for an actor. Sends ActorOpenRequest optimistically.
47
+ *
48
+ * VFS registration and sqlite3_open_v2 run inside `spawn_blocking` because
49
+ * they trigger synchronous VFS callbacks that call `Handle::block_on()` for
50
+ * KV I/O. This is safe from a blocking thread but would deadlock or freeze
51
+ * the Node.js main thread if called via `rt.block_on()`.
52
+ */
53
+ export declare function openDatabase(channel: KvChannel, actorId: string): Promise<NativeDatabase>
54
+ /**
55
+ * Execute a statement (INSERT, UPDATE, DELETE, CREATE, etc.).
56
+ *
57
+ * SQLite operations run on tokio's blocking thread pool via `spawn_blocking`.
58
+ * VFS callbacks call `Handle::block_on()` from blocking threads (not tokio
59
+ * worker threads), which is safe. The Node.js main thread is never blocked.
60
+ *
61
+ * Three threading approaches were considered:
62
+ *
63
+ * 1. **spawn_blocking** (chosen): napi `async fn` dispatches to tokio's
64
+ * blocking thread pool (default cap 512). Simplest, idiomatic, tokio
65
+ * manages the pool. Minor downside: thread may change between queries
66
+ * (slightly worse cache locality).
67
+ *
68
+ * 2. **Dedicated thread per actor**: One `std::thread` per actor, receives
69
+ * SQL via mpsc, sends results via oneshot. Best cache locality, but
70
+ * requires manual lifecycle management and one idle thread per open actor.
71
+ *
72
+ * 3. **Channel + block-in-place**: Sync napi function, VFS callbacks send
73
+ * requests via `std::sync::mpsc` and block on `recv()`. Does NOT solve
74
+ * the core problem because the Node.js main thread is still blocked.
75
+ *
76
+ * See docs-internal/engine/NATIVE_SQLITE_REVIEW_FINDINGS.md Finding 1.
77
+ */
78
+ export declare function execute(db: NativeDatabase, sql: string, params?: Array<BindParam> | undefined | null): Promise<ExecuteResult>
79
+ /**
80
+ * Run a query (SELECT, PRAGMA, etc.).
81
+ *
82
+ * See `execute` for threading model documentation.
83
+ */
84
+ export declare function query(db: NativeDatabase, sql: string, params?: Array<BindParam> | undefined | null): Promise<QueryResult>
85
+ /**
86
+ * Execute multi-statement SQL without parameters.
87
+ * Uses sqlite3_prepare_v2 in a loop with tail pointer tracking to handle
88
+ * multiple statements (e.g., migrations). Returns columns and rows from
89
+ * the last statement that produced results.
90
+ *
91
+ * See `execute` for threading model documentation.
92
+ */
93
+ export declare function exec(db: NativeDatabase, sql: string): Promise<QueryResult>
94
+ /**
95
+ * Close the database connection and release the actor lock.
96
+ * Sends ActorCloseRequest to the server.
97
+ *
98
+ * Locks the db mutex and takes the Option, so concurrent/subsequent
99
+ * execute/query/exec operations see None and return "database is closed".
100
+ */
101
+ export declare function closeDatabase(db: NativeDatabase): Promise<void>
102
+ /** Close the KV channel WebSocket connection. */
103
+ export declare function disconnect(channel: KvChannel): Promise<void>
104
+ /** Per-operation metrics snapshot. */
105
+ export interface OpMetricsSnapshot {
106
+ count: number
107
+ totalDurationUs: number
108
+ minDurationUs: number
109
+ maxDurationUs: number
110
+ avgDurationUs: number
111
+ }
112
+ /** All KV channel metrics (Layer 1). */
113
+ export interface KvChannelMetricsSnapshot {
114
+ get: OpMetricsSnapshot
115
+ put: OpMetricsSnapshot
116
+ delete: OpMetricsSnapshot
117
+ deleteRange: OpMetricsSnapshot
118
+ actorOpen: OpMetricsSnapshot
119
+ actorClose: OpMetricsSnapshot
120
+ keysTotal: number
121
+ requestsTotal: number
122
+ batchAtomicCommits: number
123
+ batchAtomicPages: number
124
+ }
125
+ /** SQL execution metrics (Layer 0). */
126
+ export interface SqlMetricsSnapshot {
127
+ execute: OpMetricsSnapshot
128
+ query: OpMetricsSnapshot
129
+ exec: OpMetricsSnapshot
130
+ spawnBlockingWait: OpMetricsSnapshot
131
+ sqliteStep: OpMetricsSnapshot
132
+ stmtCache: OpMetricsSnapshot
133
+ resultSerialize: OpMetricsSnapshot
134
+ }
135
+ /** VFS callback metrics. */
136
+ export interface VfsMetricsSnapshot {
137
+ xreadCount: number
138
+ xreadUs: number
139
+ xwriteCount: number
140
+ xwriteUs: number
141
+ xwriteBufferedCount: number
142
+ xsyncCount: number
143
+ xsyncUs: number
144
+ commitAtomicCount: number
145
+ commitAtomicUs: number
146
+ commitAtomicPages: number
147
+ }
148
+ /** All metrics across all layers. */
149
+ export interface AllMetricsSnapshot {
150
+ kvChannel: KvChannelMetricsSnapshot
151
+ sql: SqlMetricsSnapshot
152
+ vfs: VfsMetricsSnapshot
153
+ }
154
+ /** Get a snapshot of all metrics across all layers. */
155
+ export declare function getMetrics(channel: KvChannel): AllMetricsSnapshot
156
+ export type JsKvChannel = KvChannel
157
+ /**
158
+ * A shared WebSocket connection to the KV channel server.
159
+ * One per process, shared across all actors.
160
+ *
161
+ * The tokio runtime is owned here so it is dropped when the channel is dropped,
162
+ * ensuring clean process exit after disconnect. The runtime MUST NOT be dropped
163
+ * before all actors have closed their databases.
164
+ */
165
+ export declare class KvChannel { }
166
+ export type JsNativeDatabase = NativeDatabase
167
+ /**
168
+ * An open SQLite database backed by KV storage via the channel.
169
+ *
170
+ * The `db` field is wrapped in `Arc<Mutex<Option<...>>>` so that
171
+ * `close_database` can atomically take the handle while concurrent
172
+ * `execute`/`query`/`exec` closures hold an Arc clone. Any operation
173
+ * that finds `None` returns a "database is closed" error. This prevents
174
+ * use-after-free if `close_database` runs between pointer extraction
175
+ * and `spawn_blocking` task execution.
176
+ *
177
+ * Field order matters for drop safety: `stmt_cache` is declared before `db`
178
+ * so cached statements are finalized before the database connection is closed.
179
+ */
180
+ export declare class NativeDatabase { }
package/index.js ADDED
@@ -0,0 +1,324 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /* prettier-ignore */
4
+
5
+ /* auto-generated by NAPI-RS */
6
+
7
+ const { existsSync, readFileSync } = require('fs')
8
+ const { join } = require('path')
9
+
10
+ const { platform, arch } = process
11
+
12
+ let nativeBinding = null
13
+ let localFileExisted = false
14
+ let loadError = null
15
+
16
+ function isMusl() {
17
+ // For Node 10
18
+ if (!process.report || typeof process.report.getReport !== 'function') {
19
+ try {
20
+ const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
+ return readFileSync(lddPath, 'utf8').includes('musl')
22
+ } catch (e) {
23
+ return true
24
+ }
25
+ } else {
26
+ const { glibcVersionRuntime } = process.report.getReport().header
27
+ return !glibcVersionRuntime
28
+ }
29
+ }
30
+
31
+ switch (platform) {
32
+ case 'android':
33
+ switch (arch) {
34
+ case 'arm64':
35
+ localFileExisted = existsSync(join(__dirname, 'sqlite-native.android-arm64.node'))
36
+ try {
37
+ if (localFileExisted) {
38
+ nativeBinding = require('./sqlite-native.android-arm64.node')
39
+ } else {
40
+ nativeBinding = require('@rivetkit/sqlite-native-android-arm64')
41
+ }
42
+ } catch (e) {
43
+ loadError = e
44
+ }
45
+ break
46
+ case 'arm':
47
+ localFileExisted = existsSync(join(__dirname, 'sqlite-native.android-arm-eabi.node'))
48
+ try {
49
+ if (localFileExisted) {
50
+ nativeBinding = require('./sqlite-native.android-arm-eabi.node')
51
+ } else {
52
+ nativeBinding = require('@rivetkit/sqlite-native-android-arm-eabi')
53
+ }
54
+ } catch (e) {
55
+ loadError = e
56
+ }
57
+ break
58
+ default:
59
+ throw new Error(`Unsupported architecture on Android ${arch}`)
60
+ }
61
+ break
62
+ case 'win32':
63
+ switch (arch) {
64
+ case 'x64':
65
+ localFileExisted = existsSync(
66
+ join(__dirname, 'sqlite-native.win32-x64-msvc.node')
67
+ )
68
+ try {
69
+ if (localFileExisted) {
70
+ nativeBinding = require('./sqlite-native.win32-x64-msvc.node')
71
+ } else {
72
+ nativeBinding = require('@rivetkit/sqlite-native-win32-x64-msvc')
73
+ }
74
+ } catch (e) {
75
+ loadError = e
76
+ }
77
+ break
78
+ case 'ia32':
79
+ localFileExisted = existsSync(
80
+ join(__dirname, 'sqlite-native.win32-ia32-msvc.node')
81
+ )
82
+ try {
83
+ if (localFileExisted) {
84
+ nativeBinding = require('./sqlite-native.win32-ia32-msvc.node')
85
+ } else {
86
+ nativeBinding = require('@rivetkit/sqlite-native-win32-ia32-msvc')
87
+ }
88
+ } catch (e) {
89
+ loadError = e
90
+ }
91
+ break
92
+ case 'arm64':
93
+ localFileExisted = existsSync(
94
+ join(__dirname, 'sqlite-native.win32-arm64-msvc.node')
95
+ )
96
+ try {
97
+ if (localFileExisted) {
98
+ nativeBinding = require('./sqlite-native.win32-arm64-msvc.node')
99
+ } else {
100
+ nativeBinding = require('@rivetkit/sqlite-native-win32-arm64-msvc')
101
+ }
102
+ } catch (e) {
103
+ loadError = e
104
+ }
105
+ break
106
+ default:
107
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
108
+ }
109
+ break
110
+ case 'darwin':
111
+ localFileExisted = existsSync(join(__dirname, 'sqlite-native.darwin-universal.node'))
112
+ try {
113
+ if (localFileExisted) {
114
+ nativeBinding = require('./sqlite-native.darwin-universal.node')
115
+ } else {
116
+ nativeBinding = require('@rivetkit/sqlite-native-darwin-universal')
117
+ }
118
+ break
119
+ } catch {}
120
+ switch (arch) {
121
+ case 'x64':
122
+ localFileExisted = existsSync(join(__dirname, 'sqlite-native.darwin-x64.node'))
123
+ try {
124
+ if (localFileExisted) {
125
+ nativeBinding = require('./sqlite-native.darwin-x64.node')
126
+ } else {
127
+ nativeBinding = require('@rivetkit/sqlite-native-darwin-x64')
128
+ }
129
+ } catch (e) {
130
+ loadError = e
131
+ }
132
+ break
133
+ case 'arm64':
134
+ localFileExisted = existsSync(
135
+ join(__dirname, 'sqlite-native.darwin-arm64.node')
136
+ )
137
+ try {
138
+ if (localFileExisted) {
139
+ nativeBinding = require('./sqlite-native.darwin-arm64.node')
140
+ } else {
141
+ nativeBinding = require('@rivetkit/sqlite-native-darwin-arm64')
142
+ }
143
+ } catch (e) {
144
+ loadError = e
145
+ }
146
+ break
147
+ default:
148
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
149
+ }
150
+ break
151
+ case 'freebsd':
152
+ if (arch !== 'x64') {
153
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
154
+ }
155
+ localFileExisted = existsSync(join(__dirname, 'sqlite-native.freebsd-x64.node'))
156
+ try {
157
+ if (localFileExisted) {
158
+ nativeBinding = require('./sqlite-native.freebsd-x64.node')
159
+ } else {
160
+ nativeBinding = require('@rivetkit/sqlite-native-freebsd-x64')
161
+ }
162
+ } catch (e) {
163
+ loadError = e
164
+ }
165
+ break
166
+ case 'linux':
167
+ switch (arch) {
168
+ case 'x64':
169
+ if (isMusl()) {
170
+ localFileExisted = existsSync(
171
+ join(__dirname, 'sqlite-native.linux-x64-musl.node')
172
+ )
173
+ try {
174
+ if (localFileExisted) {
175
+ nativeBinding = require('./sqlite-native.linux-x64-musl.node')
176
+ } else {
177
+ nativeBinding = require('@rivetkit/sqlite-native-linux-x64-musl')
178
+ }
179
+ } catch (e) {
180
+ loadError = e
181
+ }
182
+ } else {
183
+ localFileExisted = existsSync(
184
+ join(__dirname, 'sqlite-native.linux-x64-gnu.node')
185
+ )
186
+ try {
187
+ if (localFileExisted) {
188
+ nativeBinding = require('./sqlite-native.linux-x64-gnu.node')
189
+ } else {
190
+ nativeBinding = require('@rivetkit/sqlite-native-linux-x64-gnu')
191
+ }
192
+ } catch (e) {
193
+ loadError = e
194
+ }
195
+ }
196
+ break
197
+ case 'arm64':
198
+ if (isMusl()) {
199
+ localFileExisted = existsSync(
200
+ join(__dirname, 'sqlite-native.linux-arm64-musl.node')
201
+ )
202
+ try {
203
+ if (localFileExisted) {
204
+ nativeBinding = require('./sqlite-native.linux-arm64-musl.node')
205
+ } else {
206
+ nativeBinding = require('@rivetkit/sqlite-native-linux-arm64-musl')
207
+ }
208
+ } catch (e) {
209
+ loadError = e
210
+ }
211
+ } else {
212
+ localFileExisted = existsSync(
213
+ join(__dirname, 'sqlite-native.linux-arm64-gnu.node')
214
+ )
215
+ try {
216
+ if (localFileExisted) {
217
+ nativeBinding = require('./sqlite-native.linux-arm64-gnu.node')
218
+ } else {
219
+ nativeBinding = require('@rivetkit/sqlite-native-linux-arm64-gnu')
220
+ }
221
+ } catch (e) {
222
+ loadError = e
223
+ }
224
+ }
225
+ break
226
+ case 'arm':
227
+ if (isMusl()) {
228
+ localFileExisted = existsSync(
229
+ join(__dirname, 'sqlite-native.linux-arm-musleabihf.node')
230
+ )
231
+ try {
232
+ if (localFileExisted) {
233
+ nativeBinding = require('./sqlite-native.linux-arm-musleabihf.node')
234
+ } else {
235
+ nativeBinding = require('@rivetkit/sqlite-native-linux-arm-musleabihf')
236
+ }
237
+ } catch (e) {
238
+ loadError = e
239
+ }
240
+ } else {
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'sqlite-native.linux-arm-gnueabihf.node')
243
+ )
244
+ try {
245
+ if (localFileExisted) {
246
+ nativeBinding = require('./sqlite-native.linux-arm-gnueabihf.node')
247
+ } else {
248
+ nativeBinding = require('@rivetkit/sqlite-native-linux-arm-gnueabihf')
249
+ }
250
+ } catch (e) {
251
+ loadError = e
252
+ }
253
+ }
254
+ break
255
+ case 'riscv64':
256
+ if (isMusl()) {
257
+ localFileExisted = existsSync(
258
+ join(__dirname, 'sqlite-native.linux-riscv64-musl.node')
259
+ )
260
+ try {
261
+ if (localFileExisted) {
262
+ nativeBinding = require('./sqlite-native.linux-riscv64-musl.node')
263
+ } else {
264
+ nativeBinding = require('@rivetkit/sqlite-native-linux-riscv64-musl')
265
+ }
266
+ } catch (e) {
267
+ loadError = e
268
+ }
269
+ } else {
270
+ localFileExisted = existsSync(
271
+ join(__dirname, 'sqlite-native.linux-riscv64-gnu.node')
272
+ )
273
+ try {
274
+ if (localFileExisted) {
275
+ nativeBinding = require('./sqlite-native.linux-riscv64-gnu.node')
276
+ } else {
277
+ nativeBinding = require('@rivetkit/sqlite-native-linux-riscv64-gnu')
278
+ }
279
+ } catch (e) {
280
+ loadError = e
281
+ }
282
+ }
283
+ break
284
+ case 's390x':
285
+ localFileExisted = existsSync(
286
+ join(__dirname, 'sqlite-native.linux-s390x-gnu.node')
287
+ )
288
+ try {
289
+ if (localFileExisted) {
290
+ nativeBinding = require('./sqlite-native.linux-s390x-gnu.node')
291
+ } else {
292
+ nativeBinding = require('@rivetkit/sqlite-native-linux-s390x-gnu')
293
+ }
294
+ } catch (e) {
295
+ loadError = e
296
+ }
297
+ break
298
+ default:
299
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
300
+ }
301
+ break
302
+ default:
303
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
304
+ }
305
+
306
+ if (!nativeBinding) {
307
+ if (loadError) {
308
+ throw loadError
309
+ }
310
+ throw new Error(`Failed to load native binding`)
311
+ }
312
+
313
+ const { KvChannel, NativeDatabase, connect, openDatabase, execute, query, exec, closeDatabase, disconnect, getMetrics } = nativeBinding
314
+
315
+ module.exports.KvChannel = KvChannel
316
+ module.exports.NativeDatabase = NativeDatabase
317
+ module.exports.connect = connect
318
+ module.exports.openDatabase = openDatabase
319
+ module.exports.execute = execute
320
+ module.exports.query = query
321
+ module.exports.exec = exec
322
+ module.exports.closeDatabase = closeDatabase
323
+ module.exports.disconnect = disconnect
324
+ module.exports.getMetrics = getMetrics
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@rivetkit/sqlite-native",
3
+ "version": "2.2.1-pr.4600.b74ff3b",
4
+ "description": "DEPRECATED: Use @rivetkit/rivetkit-native instead. Native SQLite addon for RivetKit backed by KV channel protocol",
5
+ "deprecated": "Use @rivetkit/rivetkit-native which provides both native SQLite and envoy client through a unified N-API addon.",
6
+ "license": "Apache-2.0",
7
+ "main": "index.js",
8
+ "types": "index.d.ts",
9
+ "engines": {
10
+ "node": ">= 20.0.0"
11
+ },
12
+ "napi": {
13
+ "name": "sqlite-native",
14
+ "triples": {
15
+ "defaults": false,
16
+ "additional": [
17
+ "x86_64-unknown-linux-gnu",
18
+ "aarch64-unknown-linux-gnu",
19
+ "x86_64-apple-darwin",
20
+ "aarch64-apple-darwin",
21
+ "x86_64-pc-windows-msvc"
22
+ ]
23
+ }
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "index.d.ts",
28
+ "package.json"
29
+ ],
30
+ "devDependencies": {
31
+ "@napi-rs/cli": "^2.18.0"
32
+ },
33
+ "optionalDependencies": {
34
+ "@rivetkit/sqlite-native-linux-x64-gnu": "2.2.1-pr.4600.b74ff3b",
35
+ "@rivetkit/sqlite-native-linux-arm64-gnu": "2.2.1-pr.4600.b74ff3b",
36
+ "@rivetkit/sqlite-native-darwin-x64": "2.2.1-pr.4600.b74ff3b",
37
+ "@rivetkit/sqlite-native-darwin-arm64": "2.2.1-pr.4600.b74ff3b",
38
+ "@rivetkit/sqlite-native-win32-x64-msvc": "2.2.1-pr.4600.b74ff3b"
39
+ },
40
+ "scripts": {
41
+ "build": "napi build --platform --release"
42
+ }
43
+ }