@rivetkit/rivetkit-napi 0.0.0-0-0-0-preview-guard-stops.9d82529

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/index.d.ts ADDED
@@ -0,0 +1,487 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export interface JsActorKeySegment {
7
+ kind: string
8
+ stringValue?: string
9
+ numberValue?: number
10
+ }
11
+ export interface JsHttpRequest {
12
+ method: string
13
+ uri: string
14
+ headers?: Record<string, string>
15
+ body?: Buffer
16
+ }
17
+ export interface StateDeltaConnHibernationEntry {
18
+ connId: string
19
+ bytes: Buffer
20
+ }
21
+ export interface StateDeltaPayload {
22
+ state?: Buffer
23
+ connHibernation: Array<StateDeltaConnHibernationEntry>
24
+ connHibernationRemoved: Array<string>
25
+ }
26
+ export interface WorkflowKvWritePayload {
27
+ key: Buffer
28
+ value: Buffer
29
+ }
30
+ export interface JsRequestSaveOpts {
31
+ immediate?: boolean
32
+ maxWaitMs?: number
33
+ }
34
+ export declare function decodeInspectorRequest(bytes: Buffer, advertisedVersion: number): Buffer
35
+ export declare function encodeInspectorResponse(bytes: Buffer, targetVersion: number): Buffer
36
+ export interface JsInspectorSnapshot {
37
+ stateRevision: number
38
+ connectionsRevision: number
39
+ queueRevision: number
40
+ activeConnections: number
41
+ queueSize: number
42
+ connectedClients: number
43
+ }
44
+ export interface JsActorRuntimeSocketEndpointInfo {
45
+ path: string
46
+ }
47
+ export interface JsQueueSendResult {
48
+ status: string
49
+ response?: Buffer
50
+ }
51
+ export interface JsActionDefinition {
52
+ name: string
53
+ }
54
+ /**
55
+ * One entry in the actor's `inspector.tabs[]` declaration. Either a
56
+ * custom-tab descriptor (id + label + source dir) or a built-in modifier
57
+ * (id + hidden=true). Validation already happened on the TS side; the
58
+ * runtime just splits the discriminator.
59
+ */
60
+ export interface JsInspectorTabEntry {
61
+ id: string
62
+ /** Required for custom entries; omitted for HideBuiltin. */
63
+ label?: string
64
+ /** Required for custom entries — absolute path to the source directory. */
65
+ source?: string
66
+ /**
67
+ * Optional icon id for custom entries. Dashboard maps strings to
68
+ * glyphs; unknown ids fall back to a generic icon.
69
+ */
70
+ icon?: string
71
+ /** Set to true for HideBuiltin entries. */
72
+ hidden?: boolean
73
+ }
74
+ /**
75
+ * Experimental SQLite profiling configuration. This entire configuration
76
+ * surface is subject to change without notice.
77
+ */
78
+ export interface JsSqliteProfilingConfig {
79
+ enabled?: boolean
80
+ maxTrackedStatementFingerprints?: number
81
+ maxTrackedTransactionFingerprints?: number
82
+ maxPrometheusSeries?: number
83
+ maxStatementsPerTransactionTrace?: number
84
+ maxGetPagesRequestsPerTrace?: number
85
+ maxTransactionNameBytes?: number
86
+ slowOperationThresholdMs?: number
87
+ baselineSampleRate?: number
88
+ maxDiagnosticEventsPerMinute?: number
89
+ diagnosticEventQueueCapacity?: number
90
+ }
91
+ export interface JsActorConfig {
92
+ name?: string
93
+ icon?: string
94
+ hasDatabase?: boolean
95
+ remoteSqlite?: boolean
96
+ sqliteProfiling?: JsSqliteProfilingConfig
97
+ enableActorRuntimeSocket?: boolean
98
+ hasState?: boolean
99
+ canHibernateWebsocket?: boolean
100
+ stateSaveIntervalMs?: number
101
+ createStateTimeoutMs?: number
102
+ onCreateTimeoutMs?: number
103
+ createVarsTimeoutMs?: number
104
+ createConnStateTimeoutMs?: number
105
+ onBeforeConnectTimeoutMs?: number
106
+ onConnectTimeoutMs?: number
107
+ onMigrateTimeoutMs?: number
108
+ onWakeTimeoutMs?: number
109
+ onBeforeActorStartTimeoutMs?: number
110
+ actionTimeoutMs?: number
111
+ onRequestTimeoutMs?: number
112
+ sleepTimeoutMs?: number
113
+ noSleep?: boolean
114
+ sleepGracePeriodMs?: number
115
+ connectionLivenessTimeoutMs?: number
116
+ connectionLivenessIntervalMs?: number
117
+ maxQueueSize?: number
118
+ maxSchedules?: number
119
+ maxQueueMessageSize?: number
120
+ maxIncomingMessageSize?: number
121
+ maxOutgoingMessageSize?: number
122
+ actions?: Array<JsActionDefinition>
123
+ inspectorTabs?: Array<JsInspectorTabEntry>
124
+ }
125
+ export interface JsBindParam {
126
+ kind: string
127
+ intValue?: number
128
+ floatValue?: number
129
+ textValue?: string
130
+ blobValue?: Buffer
131
+ }
132
+ export interface ExecuteResult {
133
+ changes: number
134
+ }
135
+ export interface QueryResult {
136
+ columns: Array<string>
137
+ rows: Array<Array<any>>
138
+ }
139
+ export interface NativeExecuteResult {
140
+ columns: Array<string>
141
+ rows: Array<Array<any>>
142
+ changes: number
143
+ lastInsertRowId?: number
144
+ }
145
+ export interface JsSqliteBatchStatement {
146
+ sql: string
147
+ params?: Array<JsBindParam>
148
+ }
149
+ export interface JsSqliteVfsMetrics {
150
+ requestBuildNs: number
151
+ serializeNs: number
152
+ transportNs: number
153
+ stateUpdateNs: number
154
+ totalNs: number
155
+ commitCount: number
156
+ pageCacheEntries: number
157
+ pageCacheWeightedSize: number
158
+ pageCacheCapacityPages: number
159
+ writeBufferDirtyPages: number
160
+ dbSizePages: number
161
+ }
162
+ export interface JsHttpResponse {
163
+ status?: number
164
+ headers?: Record<string, string>
165
+ body?: Buffer
166
+ stream?: boolean
167
+ }
168
+ export interface JsQueueNextOptions {
169
+ names?: Array<string>
170
+ timeoutMs?: number
171
+ completable?: boolean
172
+ }
173
+ export interface JsQueueNextBatchOptions {
174
+ names?: Array<string>
175
+ count?: number
176
+ timeoutMs?: number
177
+ completable?: boolean
178
+ }
179
+ export interface JsQueueWaitOptions {
180
+ timeoutMs?: number
181
+ completable?: boolean
182
+ }
183
+ export interface JsQueueEnqueueAndWaitOptions {
184
+ timeoutMs?: number
185
+ }
186
+ export interface JsQueueTryNextOptions {
187
+ names?: Array<string>
188
+ completable?: boolean
189
+ }
190
+ export interface JsQueueTryNextBatchOptions {
191
+ names?: Array<string>
192
+ count?: number
193
+ completable?: boolean
194
+ }
195
+ export interface JsQueueInspectMessage {
196
+ /**
197
+ * Queue message id. Stored as the raw u64 reinterpreted as i64 so JS
198
+ * sees a plain number; ids are monotonic and fit comfortably in i64.
199
+ */
200
+ id: number
201
+ name: string
202
+ createdAtMs: number
203
+ }
204
+ export interface JsServeConfig {
205
+ version: number
206
+ endpoint: string
207
+ token?: string
208
+ namespace: string
209
+ poolName: string
210
+ engineBinaryPath?: string
211
+ startServices?: boolean
212
+ servicesBinaryPath?: string
213
+ engineHost?: string
214
+ enginePort?: number
215
+ handleInspectorHttpInRuntime?: boolean
216
+ serverlessBasePath?: string
217
+ serverlessPackageVersion: string
218
+ serverlessClientEndpoint?: string
219
+ serverlessClientNamespace?: string
220
+ serverlessClientToken?: string
221
+ serverlessValidateEndpoint: boolean
222
+ serverlessMaxStartPayloadBytes: number
223
+ }
224
+ export interface JsListenerConfig {
225
+ /** Host to bind. Defaults to `0.0.0.0` when not provided. */
226
+ host?: string
227
+ port: number
228
+ /**
229
+ * Optional static file root mounted as a fallback below the framework
230
+ * routes.
231
+ */
232
+ publicDir?: string
233
+ }
234
+ export interface JsServerlessRequest {
235
+ method: string
236
+ url: string
237
+ headers: Record<string, string>
238
+ body: Buffer
239
+ }
240
+ export interface JsServerlessResponseHead {
241
+ status: number
242
+ headers: Record<string, string>
243
+ }
244
+ export interface JsApplicationResponse {
245
+ status: number
246
+ headers: Record<string, string>
247
+ body?: Buffer
248
+ stream?: boolean
249
+ }
250
+ export interface JsRegistryRouteResponse {
251
+ status: number
252
+ headers: Record<string, string>
253
+ body: Buffer
254
+ }
255
+ export interface JsServerlessStreamError {
256
+ group: string
257
+ code: string
258
+ message: string
259
+ }
260
+ export interface JsScheduledEventInfo {
261
+ id: string
262
+ action: string
263
+ args: Buffer
264
+ runAt: number
265
+ }
266
+ export interface JsCronJobInfo {
267
+ name: string
268
+ kind: string
269
+ action: string
270
+ args: Buffer
271
+ nextRunAt: number
272
+ lastRunAt?: number
273
+ expression?: string
274
+ timezone?: string
275
+ intervalMs?: number
276
+ maxHistory: number
277
+ }
278
+ export interface JsScheduleErrorInfo {
279
+ group: string
280
+ code: string
281
+ message: string
282
+ metadata?: any
283
+ }
284
+ export interface JsCronFire {
285
+ action: string
286
+ scheduledAt: number
287
+ firedAt: number
288
+ finishedAt?: number
289
+ result: string
290
+ error?: JsScheduleErrorInfo
291
+ }
292
+ /** Options for KV list operations. */
293
+ export interface JsKvListOptions {
294
+ reverse?: boolean
295
+ limit?: number
296
+ }
297
+ /** A key-value entry returned from KV list operations. */
298
+ export interface JsKvEntry {
299
+ key: Buffer
300
+ value: Buffer
301
+ }
302
+ /** N-API wrapper around `rivetkit-core::ActorContext`. */
303
+ export declare class ActorContext {
304
+ state(): Buffer
305
+ beginOnStateChange(): void
306
+ endOnStateChange(): void
307
+ kv(): Kv
308
+ sql(): JsNativeDatabase
309
+ provisionActorRuntimeSocket(): Promise<JsActorRuntimeSocketEndpointInfo>
310
+ schedule(): Schedule
311
+ queue(): Queue
312
+ setAlarm(timestampMs?: number | undefined | null): void
313
+ requestSave(opts?: JsRequestSaveOpts | undefined | null): void
314
+ requestSaveAndWait(opts?: JsRequestSaveOpts | undefined | null): Promise<void>
315
+ decodeInspectorRequest(bytes: Buffer, advertisedVersion: number): Buffer
316
+ encodeInspectorResponse(bytes: Buffer, targetVersion: number): Buffer
317
+ inspectorSnapshot(): JsInspectorSnapshot
318
+ verifyInspectorAuth(bearerToken?: string | undefined | null): Promise<void>
319
+ queueHibernationRemoval(connId: string): void
320
+ hasPendingHibernationChanges(): boolean
321
+ takePendingHibernationChanges(): Array<string>
322
+ dirtyHibernatableConns(): Array<ConnHandle>
323
+ saveState(payload: StateDeltaPayload): Promise<void>
324
+ beginStateTransaction(timeoutMs?: number | undefined | null): Promise<JsActorStateTransaction>
325
+ saveStateAndWorkflowBatch(writes: Array<WorkflowKvWritePayload>): Promise<void>
326
+ actorId(): string
327
+ name(): string
328
+ key(): Array<JsActorKeySegment>
329
+ region(): string
330
+ sleep(): void
331
+ destroy(): void
332
+ destroyRequested(): boolean
333
+ waitForDestroyCompletion(): Promise<void>
334
+ setPreventSleep(preventSleep: boolean): void
335
+ preventSleep(): boolean
336
+ aborted(): boolean
337
+ runHandlerActive(): boolean
338
+ restartRunHandler(): void
339
+ setRunWakeAt(timestampMs?: number | undefined | null): Promise<void>
340
+ beginKeepAwake(): number
341
+ endKeepAwake(regionId: number): void
342
+ keepAwake(promise: Promise<any>): void
343
+ beginWebsocketCallback(): number
344
+ endWebsocketCallback(regionId: number): void
345
+ abortSignal(): AbortSignal
346
+ conns(): Array<ConnHandle>
347
+ connectConn(params: Buffer, request?: JsHttpRequest | undefined | null): Promise<ConnHandle>
348
+ disconnectConn(id: string): Promise<void>
349
+ disconnectConns(predicate: (...args: any[]) => any): Promise<void>
350
+ broadcast(name: string, args: Buffer): void
351
+ waitUntil(promise: Promise<any>): void
352
+ waitForTrackedShutdownWork(): Promise<boolean>
353
+ waitForTrackedShutdownWorkUnbounded(): Promise<void>
354
+ registerTask(promise: Promise<any>): void
355
+ runtimeState(): object
356
+ clearRuntimeState(): void
357
+ }
358
+ export declare class NapiActorFactory {
359
+ constructor(callbacks: object, config?: JsActorConfig | undefined | null)
360
+ }
361
+ export declare class CancellationToken {
362
+ constructor()
363
+ aborted(): boolean
364
+ cancel(): void
365
+ onCancelled(callback: (...args: any[]) => any): void
366
+ }
367
+ export declare class ConnHandle {
368
+ id(): string
369
+ params(): Buffer
370
+ state(): Buffer
371
+ setState(state: Buffer): void
372
+ isHibernatable(): boolean
373
+ send(name: string, args: Buffer): void
374
+ disconnect(reason?: string | undefined | null): Promise<void>
375
+ }
376
+ export declare class JsNativeDatabase {
377
+ takeLastKvError(): string | null
378
+ metrics(): JsSqliteVfsMetrics | null
379
+ run(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<ExecuteResult>
380
+ query(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<QueryResult>
381
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
382
+ executeBatch(statements: Array<JsSqliteBatchStatement>): Promise<Array<NativeExecuteResult>>
383
+ exec(sql: string): Promise<QueryResult>
384
+ close(): Promise<void>
385
+ beginTransaction(timeoutMs?: number | undefined | null, name?: string | undefined | null): Promise<JsSqliteTransaction>
386
+ }
387
+ export declare class JsSqliteTransaction {
388
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
389
+ exec(sql: string): Promise<QueryResult>
390
+ commit(): Promise<void>
391
+ rollback(): Promise<void>
392
+ }
393
+ export declare class JsActorStateTransaction {
394
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
395
+ commit(payload: StateDeltaPayload): Promise<void>
396
+ rollback(): Promise<void>
397
+ }
398
+ /** JavaScript-facing writer for a streaming actor HTTP response. */
399
+ export declare class HttpResponseBodyStream {
400
+ cancelled(): Promise<void>
401
+ write(chunk: Buffer): Promise<void>
402
+ end(): Promise<void>
403
+ error(message: string): Promise<void>
404
+ }
405
+ /** JavaScript-facing reader for a streaming actor HTTP request. */
406
+ export declare class HttpRequestBodyStream {
407
+ read(): Promise<Buffer | null>
408
+ cancel(): Promise<void>
409
+ }
410
+ export declare class Kv {
411
+ get(key: Buffer): Promise<Buffer | null>
412
+ put(key: Buffer, value: Buffer): Promise<void>
413
+ delete(key: Buffer): Promise<void>
414
+ deleteRange(start: Buffer, end: Buffer): Promise<void>
415
+ listPrefix(prefix: Buffer, options?: JsKvListOptions | undefined | null): Promise<Array<JsKvEntry>>
416
+ listRange(start: Buffer, end: Buffer, options?: JsKvListOptions | undefined | null): Promise<Array<JsKvEntry>>
417
+ batchGet(keys: Array<Buffer>): Promise<Array<Buffer | undefined | null>>
418
+ batchPut(entries: Array<JsKvEntry>): Promise<void>
419
+ batchDelete(keys: Array<Buffer>): Promise<void>
420
+ }
421
+ export declare class Queue {
422
+ send(name: string, body: Buffer): Promise<QueueMessage>
423
+ next(options?: JsQueueNextOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage | null>
424
+ nextBatch(options?: JsQueueNextBatchOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Array<QueueMessage>>
425
+ waitForNames(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage>
426
+ waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<void>
427
+ completePersisted(messageId: bigint, expectedName: string, response?: Buffer | undefined | null): Promise<boolean>
428
+ enqueueAndWait(name: string, body: Buffer, options?: JsQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Buffer | null>
429
+ tryNext(options?: JsQueueTryNextOptions | undefined | null): QueueMessage | null
430
+ tryNextBatch(options?: JsQueueTryNextBatchOptions | undefined | null): Array<QueueMessage>
431
+ maxSize(): number
432
+ reset(): Promise<void>
433
+ inspectMessages(): Promise<Array<JsQueueInspectMessage>>
434
+ }
435
+ export declare class QueueMessage {
436
+ id(): bigint
437
+ name(): string
438
+ body(): Buffer
439
+ createdAt(): number
440
+ isCompletable(): boolean
441
+ complete(response?: Buffer | undefined | null): Promise<void>
442
+ }
443
+ export declare class CoreRegistry {
444
+ constructor()
445
+ register(name: string, factory: NapiActorFactory): void
446
+ serve(config: JsServeConfig): Promise<void>
447
+ /**
448
+ * Wait until the serverful envoy has completed its Engine registration.
449
+ *
450
+ * Readiness is the envoy client's `ToEnvoyInit` signal, not HTTP health or
451
+ * merely constructing the envoy handle.
452
+ */
453
+ waitReady(): Promise<void>
454
+ /**
455
+ * Trip the shutdown token and tear down any live serverless runtime.
456
+ *
457
+ * Idempotent. Safe to call when neither mode has been activated.
458
+ * Does not block on the `serve()` future; TS awaits that promise
459
+ * separately to avoid re-entrancy.
460
+ */
461
+ shutdown(): Promise<void>
462
+ actorStopThresholdMs(): Promise<number | null>
463
+ health(): Promise<JsRegistryRouteResponse>
464
+ metadata(): JsRegistryRouteResponse
465
+ metrics(): JsRegistryRouteResponse
466
+ serveApplicationListener(listener: JsListenerConfig, application: (...args: any[]) => any, config: JsServeConfig): Promise<void>
467
+ serveListener(listener: JsListenerConfig, config: JsServeConfig, application?: (...args: any[]) => any | undefined | null): Promise<void>
468
+ handleServerlessRequest(req: JsServerlessRequest, onStreamEvent: (...args: any[]) => any, cancelToken: CancellationToken, config: JsServeConfig): Promise<JsServerlessResponseHead>
469
+ }
470
+ export declare class Schedule {
471
+ after(durationMs: number, actionName: string, args: Buffer): Promise<string>
472
+ at(timestampMs: number, actionName: string, args: Buffer): Promise<string>
473
+ cancel(id: string): Promise<boolean>
474
+ get(id: string): Promise<JsScheduledEventInfo | null>
475
+ list(): Promise<Array<JsScheduledEventInfo>>
476
+ cronSet(name: string, expression: string, timezone: string | undefined | null, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
477
+ cronEvery(name: string, intervalMs: number, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
478
+ cronGet(name: string): Promise<JsCronJobInfo | null>
479
+ cronList(): Promise<Array<JsCronJobInfo>>
480
+ cronDelete(name: string): Promise<boolean>
481
+ cronHistory(name: string, limit?: number | undefined | null): Promise<Array<JsCronFire>>
482
+ }
483
+ export declare class WebSocket {
484
+ send(data: Buffer, binary: boolean): void
485
+ close(code?: number | undefined | null, reason?: string | undefined | null): Promise<void>
486
+ setEventCallback(callback: (...args: any[]) => any): void
487
+ }
package/index.js ADDED
@@ -0,0 +1,331 @@
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, 'rivetkit-napi.android-arm64.node'))
36
+ try {
37
+ if (localFileExisted) {
38
+ nativeBinding = require('./rivetkit-napi.android-arm64.node')
39
+ } else {
40
+ nativeBinding = require('@rivetkit/rivetkit-napi-android-arm64')
41
+ }
42
+ } catch (e) {
43
+ loadError = e
44
+ }
45
+ break
46
+ case 'arm':
47
+ localFileExisted = existsSync(join(__dirname, 'rivetkit-napi.android-arm-eabi.node'))
48
+ try {
49
+ if (localFileExisted) {
50
+ nativeBinding = require('./rivetkit-napi.android-arm-eabi.node')
51
+ } else {
52
+ nativeBinding = require('@rivetkit/rivetkit-napi-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, 'rivetkit-napi.win32-x64-msvc.node')
67
+ )
68
+ try {
69
+ if (localFileExisted) {
70
+ nativeBinding = require('./rivetkit-napi.win32-x64-msvc.node')
71
+ } else {
72
+ nativeBinding = require('@rivetkit/rivetkit-napi-win32-x64-msvc')
73
+ }
74
+ } catch (e) {
75
+ loadError = e
76
+ }
77
+ break
78
+ case 'ia32':
79
+ localFileExisted = existsSync(
80
+ join(__dirname, 'rivetkit-napi.win32-ia32-msvc.node')
81
+ )
82
+ try {
83
+ if (localFileExisted) {
84
+ nativeBinding = require('./rivetkit-napi.win32-ia32-msvc.node')
85
+ } else {
86
+ nativeBinding = require('@rivetkit/rivetkit-napi-win32-ia32-msvc')
87
+ }
88
+ } catch (e) {
89
+ loadError = e
90
+ }
91
+ break
92
+ case 'arm64':
93
+ localFileExisted = existsSync(
94
+ join(__dirname, 'rivetkit-napi.win32-arm64-msvc.node')
95
+ )
96
+ try {
97
+ if (localFileExisted) {
98
+ nativeBinding = require('./rivetkit-napi.win32-arm64-msvc.node')
99
+ } else {
100
+ nativeBinding = require('@rivetkit/rivetkit-napi-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, 'rivetkit-napi.darwin-universal.node'))
112
+ try {
113
+ if (localFileExisted) {
114
+ nativeBinding = require('./rivetkit-napi.darwin-universal.node')
115
+ } else {
116
+ nativeBinding = require('@rivetkit/rivetkit-napi-darwin-universal')
117
+ }
118
+ break
119
+ } catch {}
120
+ switch (arch) {
121
+ case 'x64':
122
+ localFileExisted = existsSync(join(__dirname, 'rivetkit-napi.darwin-x64.node'))
123
+ try {
124
+ if (localFileExisted) {
125
+ nativeBinding = require('./rivetkit-napi.darwin-x64.node')
126
+ } else {
127
+ nativeBinding = require('@rivetkit/rivetkit-napi-darwin-x64')
128
+ }
129
+ } catch (e) {
130
+ loadError = e
131
+ }
132
+ break
133
+ case 'arm64':
134
+ localFileExisted = existsSync(
135
+ join(__dirname, 'rivetkit-napi.darwin-arm64.node')
136
+ )
137
+ try {
138
+ if (localFileExisted) {
139
+ nativeBinding = require('./rivetkit-napi.darwin-arm64.node')
140
+ } else {
141
+ nativeBinding = require('@rivetkit/rivetkit-napi-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, 'rivetkit-napi.freebsd-x64.node'))
156
+ try {
157
+ if (localFileExisted) {
158
+ nativeBinding = require('./rivetkit-napi.freebsd-x64.node')
159
+ } else {
160
+ nativeBinding = require('@rivetkit/rivetkit-napi-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, 'rivetkit-napi.linux-x64-musl.node')
172
+ )
173
+ try {
174
+ if (localFileExisted) {
175
+ nativeBinding = require('./rivetkit-napi.linux-x64-musl.node')
176
+ } else {
177
+ nativeBinding = require('@rivetkit/rivetkit-napi-linux-x64-musl')
178
+ }
179
+ } catch (e) {
180
+ loadError = e
181
+ }
182
+ } else {
183
+ localFileExisted = existsSync(
184
+ join(__dirname, 'rivetkit-napi.linux-x64-gnu.node')
185
+ )
186
+ try {
187
+ if (localFileExisted) {
188
+ nativeBinding = require('./rivetkit-napi.linux-x64-gnu.node')
189
+ } else {
190
+ nativeBinding = require('@rivetkit/rivetkit-napi-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, 'rivetkit-napi.linux-arm64-musl.node')
201
+ )
202
+ try {
203
+ if (localFileExisted) {
204
+ nativeBinding = require('./rivetkit-napi.linux-arm64-musl.node')
205
+ } else {
206
+ nativeBinding = require('@rivetkit/rivetkit-napi-linux-arm64-musl')
207
+ }
208
+ } catch (e) {
209
+ loadError = e
210
+ }
211
+ } else {
212
+ localFileExisted = existsSync(
213
+ join(__dirname, 'rivetkit-napi.linux-arm64-gnu.node')
214
+ )
215
+ try {
216
+ if (localFileExisted) {
217
+ nativeBinding = require('./rivetkit-napi.linux-arm64-gnu.node')
218
+ } else {
219
+ nativeBinding = require('@rivetkit/rivetkit-napi-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, 'rivetkit-napi.linux-arm-musleabihf.node')
230
+ )
231
+ try {
232
+ if (localFileExisted) {
233
+ nativeBinding = require('./rivetkit-napi.linux-arm-musleabihf.node')
234
+ } else {
235
+ nativeBinding = require('@rivetkit/rivetkit-napi-linux-arm-musleabihf')
236
+ }
237
+ } catch (e) {
238
+ loadError = e
239
+ }
240
+ } else {
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'rivetkit-napi.linux-arm-gnueabihf.node')
243
+ )
244
+ try {
245
+ if (localFileExisted) {
246
+ nativeBinding = require('./rivetkit-napi.linux-arm-gnueabihf.node')
247
+ } else {
248
+ nativeBinding = require('@rivetkit/rivetkit-napi-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, 'rivetkit-napi.linux-riscv64-musl.node')
259
+ )
260
+ try {
261
+ if (localFileExisted) {
262
+ nativeBinding = require('./rivetkit-napi.linux-riscv64-musl.node')
263
+ } else {
264
+ nativeBinding = require('@rivetkit/rivetkit-napi-linux-riscv64-musl')
265
+ }
266
+ } catch (e) {
267
+ loadError = e
268
+ }
269
+ } else {
270
+ localFileExisted = existsSync(
271
+ join(__dirname, 'rivetkit-napi.linux-riscv64-gnu.node')
272
+ )
273
+ try {
274
+ if (localFileExisted) {
275
+ nativeBinding = require('./rivetkit-napi.linux-riscv64-gnu.node')
276
+ } else {
277
+ nativeBinding = require('@rivetkit/rivetkit-napi-linux-riscv64-gnu')
278
+ }
279
+ } catch (e) {
280
+ loadError = e
281
+ }
282
+ }
283
+ break
284
+ case 's390x':
285
+ localFileExisted = existsSync(
286
+ join(__dirname, 'rivetkit-napi.linux-s390x-gnu.node')
287
+ )
288
+ try {
289
+ if (localFileExisted) {
290
+ nativeBinding = require('./rivetkit-napi.linux-s390x-gnu.node')
291
+ } else {
292
+ nativeBinding = require('@rivetkit/rivetkit-napi-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 { ActorContext, decodeInspectorRequest, encodeInspectorResponse, NapiActorFactory, CancellationToken, ConnHandle, JsNativeDatabase, JsSqliteTransaction, JsActorStateTransaction, HttpResponseBodyStream, HttpRequestBodyStream, Kv, Queue, QueueMessage, CoreRegistry, Schedule, WebSocket } = nativeBinding
314
+
315
+ module.exports.ActorContext = ActorContext
316
+ module.exports.decodeInspectorRequest = decodeInspectorRequest
317
+ module.exports.encodeInspectorResponse = encodeInspectorResponse
318
+ module.exports.NapiActorFactory = NapiActorFactory
319
+ module.exports.CancellationToken = CancellationToken
320
+ module.exports.ConnHandle = ConnHandle
321
+ module.exports.JsNativeDatabase = JsNativeDatabase
322
+ module.exports.JsSqliteTransaction = JsSqliteTransaction
323
+ module.exports.JsActorStateTransaction = JsActorStateTransaction
324
+ module.exports.HttpResponseBodyStream = HttpResponseBodyStream
325
+ module.exports.HttpRequestBodyStream = HttpRequestBodyStream
326
+ module.exports.Kv = Kv
327
+ module.exports.Queue = Queue
328
+ module.exports.QueueMessage = QueueMessage
329
+ module.exports.CoreRegistry = CoreRegistry
330
+ module.exports.Schedule = Schedule
331
+ module.exports.WebSocket = WebSocket
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@rivetkit/rivetkit-napi",
3
+ "version": "0.0.0-0-0-0-preview-guard-stops.9d82529",
4
+ "description": "Native N-API addon for RivetKit providing envoy client and SQLite access",
5
+ "license": "Apache-2.0",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "default": "./index.js"
12
+ }
13
+ },
14
+ "engines": {
15
+ "node": ">= 20.0.0"
16
+ },
17
+ "napi": {
18
+ "name": "rivetkit-napi",
19
+ "triples": {
20
+ "defaults": false,
21
+ "additional": [
22
+ "x86_64-unknown-linux-gnu",
23
+ "aarch64-unknown-linux-gnu",
24
+ "x86_64-unknown-linux-musl",
25
+ "aarch64-unknown-linux-musl",
26
+ "x86_64-apple-darwin",
27
+ "aarch64-apple-darwin",
28
+ "x86_64-pc-windows-msvc"
29
+ ]
30
+ }
31
+ },
32
+ "files": [
33
+ "index.js",
34
+ "index.d.ts",
35
+ "package.json",
36
+ "scripts/build.mjs"
37
+ ],
38
+ "scripts": {
39
+ "build": "node scripts/build.mjs",
40
+ "build:release": "node scripts/build.mjs --release",
41
+ "build:force": "node scripts/build.mjs --force",
42
+ "build:force:release": "node scripts/build.mjs --force --release",
43
+ "build:embed": "node scripts/build.mjs"
44
+ },
45
+ "dependencies": {
46
+ "@napi-rs/cli": "^2.18.4",
47
+ "@rivetkit/engine-envoy-protocol": "0.0.0-0-0-0-preview-guard-stops.9d82529"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/rivet-dev/actors.git",
52
+ "directory": "rivetkit-typescript/packages/rivetkit-napi"
53
+ },
54
+ "optionalDependencies": {
55
+ "@rivetkit/rivetkit-napi-darwin-arm64": "0.0.0-0-0-0-preview-guard-stops.9d82529",
56
+ "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-0-0-0-preview-guard-stops.9d82529",
57
+ "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-0-0-0-preview-guard-stops.9d82529",
58
+ "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-0-0-0-preview-guard-stops.9d82529",
59
+ "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-0-0-0-preview-guard-stops.9d82529",
60
+ "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-0-0-0-preview-guard-stops.9d82529"
61
+ }
62
+ }
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Build wrapper for rivetkit-napi.
4
+ */
5
+ import { execFileSync } from "node:child_process";
6
+
7
+ const args = process.argv.slice(2);
8
+ const extraFlags = args.includes("--release") ? ["--release"] : [];
9
+
10
+ // Explicit skip for environments that don't need the native binary (e.g.
11
+ // Docker engine-frontend build which only consumes TypeScript types).
12
+ if (process.env.SKIP_NAPI_BUILD === "1") {
13
+ console.log(
14
+ "[rivetkit-napi/build] SKIP_NAPI_BUILD=1 — skipping napi build",
15
+ );
16
+ process.exit(0);
17
+ }
18
+
19
+ // The per-actor inspector UI (frontend/dist/inspector-ui, embedded into
20
+ // rivetkit-core by its build.rs) must be built before this napi build runs.
21
+ // It is NOT built here: rivetkit-core's embed needs rivetkit/inspector-tab,
22
+ // which is downstream of this package in the build graph, so building it from
23
+ // the napi build would invert the dependency order. CI builds it via
24
+ // `turbo build:inspector-ui` in docker/build/*.Dockerfile before `napi build`;
25
+ // for local builds run `pnpm -F @rivetkit/engine-frontend build:inspector-ui`
26
+ // (or `turbo build:inspector-ui`) first.
27
+ const cmd = ["build", "--platform", ...extraFlags];
28
+ console.log(`[rivetkit-napi/build] running: napi ${cmd.join(" ")}`);
29
+ execFileSync("napi", cmd, { stdio: "inherit" });