@rivetkit/rivetkit-napi 0.0.0-pr.4701.a818b77
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 +266 -0
- package/index.js +329 -0
- package/package.json +57 -0
- package/scripts/build.mjs +66 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
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 JsRequestSaveOpts {
|
|
27
|
+
immediate?: boolean
|
|
28
|
+
maxWaitMs?: number
|
|
29
|
+
}
|
|
30
|
+
export interface JsInspectorSnapshot {
|
|
31
|
+
stateRevision: number
|
|
32
|
+
connectionsRevision: number
|
|
33
|
+
queueRevision: number
|
|
34
|
+
activeConnections: number
|
|
35
|
+
queueSize: number
|
|
36
|
+
connectedClients: number
|
|
37
|
+
}
|
|
38
|
+
export interface JsHttpResponse {
|
|
39
|
+
status?: number
|
|
40
|
+
headers?: Record<string, string>
|
|
41
|
+
body?: Buffer
|
|
42
|
+
}
|
|
43
|
+
export interface JsQueueSendResult {
|
|
44
|
+
status: string
|
|
45
|
+
response?: Buffer
|
|
46
|
+
}
|
|
47
|
+
export interface JsActorConfig {
|
|
48
|
+
name?: string
|
|
49
|
+
icon?: string
|
|
50
|
+
canHibernateWebsocket?: boolean
|
|
51
|
+
stateSaveIntervalMs?: number
|
|
52
|
+
createStateTimeoutMs?: number
|
|
53
|
+
onCreateTimeoutMs?: number
|
|
54
|
+
createVarsTimeoutMs?: number
|
|
55
|
+
createConnStateTimeoutMs?: number
|
|
56
|
+
onBeforeConnectTimeoutMs?: number
|
|
57
|
+
onConnectTimeoutMs?: number
|
|
58
|
+
onMigrateTimeoutMs?: number
|
|
59
|
+
onWakeTimeoutMs?: number
|
|
60
|
+
onBeforeActorStartTimeoutMs?: number
|
|
61
|
+
onDestroyTimeoutMs?: number
|
|
62
|
+
actionTimeoutMs?: number
|
|
63
|
+
onRequestTimeoutMs?: number
|
|
64
|
+
sleepTimeoutMs?: number
|
|
65
|
+
noSleep?: boolean
|
|
66
|
+
sleepGracePeriodMs?: number
|
|
67
|
+
connectionLivenessTimeoutMs?: number
|
|
68
|
+
connectionLivenessIntervalMs?: number
|
|
69
|
+
maxQueueSize?: number
|
|
70
|
+
maxQueueMessageSize?: number
|
|
71
|
+
maxIncomingMessageSize?: number
|
|
72
|
+
maxOutgoingMessageSize?: number
|
|
73
|
+
preloadMaxWorkflowBytes?: number
|
|
74
|
+
preloadMaxConnectionsBytes?: number
|
|
75
|
+
}
|
|
76
|
+
export declare function pollCancelToken(id: bigint): boolean
|
|
77
|
+
export declare function registerNativeCancelToken(): bigint
|
|
78
|
+
export declare function cancelNativeCancelToken(id: bigint): void
|
|
79
|
+
export declare function dropNativeCancelToken(id: bigint): void
|
|
80
|
+
export interface JsBindParam {
|
|
81
|
+
kind: string
|
|
82
|
+
intValue?: number
|
|
83
|
+
floatValue?: number
|
|
84
|
+
textValue?: string
|
|
85
|
+
blobValue?: Buffer
|
|
86
|
+
}
|
|
87
|
+
export interface ExecuteResult {
|
|
88
|
+
changes: number
|
|
89
|
+
}
|
|
90
|
+
export interface QueryResult {
|
|
91
|
+
columns: Array<string>
|
|
92
|
+
rows: Array<Array<any>>
|
|
93
|
+
}
|
|
94
|
+
export interface JsSqliteVfsMetrics {
|
|
95
|
+
requestBuildNs: number
|
|
96
|
+
serializeNs: number
|
|
97
|
+
transportNs: number
|
|
98
|
+
stateUpdateNs: number
|
|
99
|
+
totalNs: number
|
|
100
|
+
commitCount: number
|
|
101
|
+
}
|
|
102
|
+
export interface JsQueueNextOptions {
|
|
103
|
+
names?: Array<string>
|
|
104
|
+
timeoutMs?: number
|
|
105
|
+
completable?: boolean
|
|
106
|
+
}
|
|
107
|
+
export interface JsQueueNextBatchOptions {
|
|
108
|
+
names?: Array<string>
|
|
109
|
+
count?: number
|
|
110
|
+
timeoutMs?: number
|
|
111
|
+
completable?: boolean
|
|
112
|
+
}
|
|
113
|
+
export interface JsQueueWaitOptions {
|
|
114
|
+
timeoutMs?: number
|
|
115
|
+
completable?: boolean
|
|
116
|
+
}
|
|
117
|
+
export interface JsQueueEnqueueAndWaitOptions {
|
|
118
|
+
timeoutMs?: number
|
|
119
|
+
}
|
|
120
|
+
export interface JsQueueTryNextOptions {
|
|
121
|
+
names?: Array<string>
|
|
122
|
+
completable?: boolean
|
|
123
|
+
}
|
|
124
|
+
export interface JsQueueTryNextBatchOptions {
|
|
125
|
+
names?: Array<string>
|
|
126
|
+
count?: number
|
|
127
|
+
completable?: boolean
|
|
128
|
+
}
|
|
129
|
+
export interface JsServeConfig {
|
|
130
|
+
version: number
|
|
131
|
+
endpoint: string
|
|
132
|
+
token?: string
|
|
133
|
+
namespace: string
|
|
134
|
+
poolName: string
|
|
135
|
+
engineBinaryPath?: string
|
|
136
|
+
handleInspectorHttpInRuntime?: boolean
|
|
137
|
+
}
|
|
138
|
+
/** Options for KV list operations. */
|
|
139
|
+
export interface JsKvListOptions {
|
|
140
|
+
reverse?: boolean
|
|
141
|
+
limit?: number
|
|
142
|
+
}
|
|
143
|
+
/** A key-value entry returned from KV list operations. */
|
|
144
|
+
export interface JsKvEntry {
|
|
145
|
+
key: Buffer
|
|
146
|
+
value: Buffer
|
|
147
|
+
}
|
|
148
|
+
/** N-API wrapper around `rivetkit-core::ActorContext`. */
|
|
149
|
+
export declare class ActorContext {
|
|
150
|
+
constructor(actorId: string, name: string, region: string)
|
|
151
|
+
state(): Buffer
|
|
152
|
+
beginOnStateChange(): void
|
|
153
|
+
endOnStateChange(): void
|
|
154
|
+
kv(): Kv
|
|
155
|
+
sql(): JsNativeDatabase
|
|
156
|
+
schedule(): Schedule
|
|
157
|
+
queue(): Queue
|
|
158
|
+
setAlarm(timestampMs?: number | undefined | null): void
|
|
159
|
+
requestSave(opts?: JsRequestSaveOpts | undefined | null): void
|
|
160
|
+
requestSaveAndWait(opts?: JsRequestSaveOpts | undefined | null): Promise<void>
|
|
161
|
+
decodeInspectorRequest(bytes: Buffer, advertisedVersion: number): Buffer
|
|
162
|
+
encodeInspectorResponse(bytes: Buffer, targetVersion: number): Buffer
|
|
163
|
+
inspectorSnapshot(): JsInspectorSnapshot
|
|
164
|
+
verifyInspectorAuth(bearerToken?: string | undefined | null): Promise<void>
|
|
165
|
+
queueHibernationRemoval(connId: string): void
|
|
166
|
+
hasPendingHibernationChanges(): boolean
|
|
167
|
+
takePendingHibernationChanges(): Array<string>
|
|
168
|
+
dirtyHibernatableConns(): Array<ConnHandle>
|
|
169
|
+
saveState(payload: StateDeltaPayload): Promise<void>
|
|
170
|
+
actorId(): string
|
|
171
|
+
name(): string
|
|
172
|
+
key(): Array<JsActorKeySegment>
|
|
173
|
+
region(): string
|
|
174
|
+
sleep(): void
|
|
175
|
+
destroy(): void
|
|
176
|
+
destroyRequested(): boolean
|
|
177
|
+
waitForDestroyCompletion(): Promise<void>
|
|
178
|
+
setPreventSleep(preventSleep: boolean): void
|
|
179
|
+
preventSleep(): boolean
|
|
180
|
+
aborted(): boolean
|
|
181
|
+
runHandlerActive(): boolean
|
|
182
|
+
restartRunHandler(): void
|
|
183
|
+
markReady(): void
|
|
184
|
+
markStarted(): void
|
|
185
|
+
isReady(): boolean
|
|
186
|
+
isStarted(): boolean
|
|
187
|
+
beginWebsocketCallback(): number
|
|
188
|
+
endWebsocketCallback(regionId: number): void
|
|
189
|
+
abortSignal(): AbortSignal
|
|
190
|
+
conns(): Array<ConnHandle>
|
|
191
|
+
connectConn(params: Buffer, request?: JsHttpRequest | undefined | null): Promise<ConnHandle>
|
|
192
|
+
disconnectConn(id: string): Promise<void>
|
|
193
|
+
disconnectConns(predicate: (...args: any[]) => any): Promise<void>
|
|
194
|
+
broadcast(name: string, args: Buffer): void
|
|
195
|
+
waitUntil(promise: Promise<any>): Promise<void>
|
|
196
|
+
registerTask(promise: Promise<any>): void
|
|
197
|
+
}
|
|
198
|
+
export declare class NapiActorFactory {
|
|
199
|
+
constructor(callbacks: object, config?: JsActorConfig | undefined | null)
|
|
200
|
+
}
|
|
201
|
+
export declare class CancellationToken {
|
|
202
|
+
constructor()
|
|
203
|
+
aborted(): boolean
|
|
204
|
+
cancel(): void
|
|
205
|
+
onCancelled(callback: (...args: any[]) => any): void
|
|
206
|
+
}
|
|
207
|
+
export declare class ConnHandle {
|
|
208
|
+
id(): string
|
|
209
|
+
params(): Buffer
|
|
210
|
+
state(): Buffer
|
|
211
|
+
setState(state: Buffer): void
|
|
212
|
+
isHibernatable(): boolean
|
|
213
|
+
send(name: string, args: Buffer): void
|
|
214
|
+
disconnect(reason?: string | undefined | null): Promise<void>
|
|
215
|
+
}
|
|
216
|
+
export declare class JsNativeDatabase {
|
|
217
|
+
takeLastKvError(): string | null
|
|
218
|
+
getSqliteVfsMetrics(): JsSqliteVfsMetrics | null
|
|
219
|
+
run(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<ExecuteResult>
|
|
220
|
+
query(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<QueryResult>
|
|
221
|
+
exec(sql: string): Promise<QueryResult>
|
|
222
|
+
close(): Promise<void>
|
|
223
|
+
}
|
|
224
|
+
export declare class Kv {
|
|
225
|
+
get(key: Buffer): Promise<Buffer | null>
|
|
226
|
+
put(key: Buffer, value: Buffer): Promise<void>
|
|
227
|
+
delete(key: Buffer): Promise<void>
|
|
228
|
+
deleteRange(start: Buffer, end: Buffer): Promise<void>
|
|
229
|
+
listPrefix(prefix: Buffer, options?: JsKvListOptions | undefined | null): Promise<Array<JsKvEntry>>
|
|
230
|
+
listRange(start: Buffer, end: Buffer, options?: JsKvListOptions | undefined | null): Promise<Array<JsKvEntry>>
|
|
231
|
+
batchGet(keys: Array<Buffer>): Promise<Array<Buffer | undefined | null>>
|
|
232
|
+
batchPut(entries: Array<JsKvEntry>): Promise<void>
|
|
233
|
+
batchDelete(keys: Array<Buffer>): Promise<void>
|
|
234
|
+
}
|
|
235
|
+
export declare class Queue {
|
|
236
|
+
send(name: string, body: Buffer): Promise<QueueMessage>
|
|
237
|
+
next(options?: JsQueueNextOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage | null>
|
|
238
|
+
nextBatch(options?: JsQueueNextBatchOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Array<QueueMessage>>
|
|
239
|
+
waitForNames(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, cancelTokenId?: bigint | undefined | null): Promise<QueueMessage>
|
|
240
|
+
waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null): Promise<void>
|
|
241
|
+
enqueueAndWait(name: string, body: Buffer, options?: JsQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Buffer | null>
|
|
242
|
+
tryNext(options?: JsQueueTryNextOptions | undefined | null): QueueMessage | null
|
|
243
|
+
tryNextBatch(options?: JsQueueTryNextBatchOptions | undefined | null): Array<QueueMessage>
|
|
244
|
+
}
|
|
245
|
+
export declare class QueueMessage {
|
|
246
|
+
id(): bigint
|
|
247
|
+
name(): string
|
|
248
|
+
body(): Buffer
|
|
249
|
+
createdAt(): number
|
|
250
|
+
isCompletable(): boolean
|
|
251
|
+
complete(response?: Buffer | undefined | null): Promise<void>
|
|
252
|
+
}
|
|
253
|
+
export declare class CoreRegistry {
|
|
254
|
+
constructor()
|
|
255
|
+
register(name: string, factory: NapiActorFactory): void
|
|
256
|
+
serve(config: JsServeConfig): Promise<void>
|
|
257
|
+
}
|
|
258
|
+
export declare class Schedule {
|
|
259
|
+
after(durationMs: number, actionName: string, args: Buffer): void
|
|
260
|
+
at(timestampMs: number, actionName: string, args: Buffer): void
|
|
261
|
+
}
|
|
262
|
+
export declare class WebSocket {
|
|
263
|
+
send(data: Buffer, binary: boolean): void
|
|
264
|
+
close(code?: number | undefined | null, reason?: string | undefined | null): Promise<void>
|
|
265
|
+
setEventCallback(callback: (...args: any[]) => any): void
|
|
266
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
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, NapiActorFactory, pollCancelToken, registerNativeCancelToken, cancelNativeCancelToken, dropNativeCancelToken, CancellationToken, ConnHandle, JsNativeDatabase, Kv, Queue, QueueMessage, CoreRegistry, Schedule, WebSocket } = nativeBinding
|
|
314
|
+
|
|
315
|
+
module.exports.ActorContext = ActorContext
|
|
316
|
+
module.exports.NapiActorFactory = NapiActorFactory
|
|
317
|
+
module.exports.pollCancelToken = pollCancelToken
|
|
318
|
+
module.exports.registerNativeCancelToken = registerNativeCancelToken
|
|
319
|
+
module.exports.cancelNativeCancelToken = cancelNativeCancelToken
|
|
320
|
+
module.exports.dropNativeCancelToken = dropNativeCancelToken
|
|
321
|
+
module.exports.CancellationToken = CancellationToken
|
|
322
|
+
module.exports.ConnHandle = ConnHandle
|
|
323
|
+
module.exports.JsNativeDatabase = JsNativeDatabase
|
|
324
|
+
module.exports.Kv = Kv
|
|
325
|
+
module.exports.Queue = Queue
|
|
326
|
+
module.exports.QueueMessage = QueueMessage
|
|
327
|
+
module.exports.CoreRegistry = CoreRegistry
|
|
328
|
+
module.exports.Schedule = Schedule
|
|
329
|
+
module.exports.WebSocket = WebSocket
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rivetkit/rivetkit-napi",
|
|
3
|
+
"version": "0.0.0-pr.4701.a818b77",
|
|
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
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@napi-rs/cli": "^2.18.4",
|
|
46
|
+
"@rivetkit/engine-envoy-protocol": "0.0.0-pr.4701.a818b77"
|
|
47
|
+
},
|
|
48
|
+
"optionalDependencies": {
|
|
49
|
+
"@rivetkit/rivetkit-napi-darwin-arm64": "0.0.0-pr.4701.a818b77",
|
|
50
|
+
"@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-pr.4701.a818b77",
|
|
51
|
+
"@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-pr.4701.a818b77",
|
|
52
|
+
"@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-pr.4701.a818b77",
|
|
53
|
+
"@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-pr.4701.a818b77",
|
|
54
|
+
"@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-pr.4701.a818b77",
|
|
55
|
+
"@rivetkit/rivetkit-napi-win32-x64-msvc": "0.0.0-pr.4701.a818b77"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Smart build wrapper for rivetkit-napi.
|
|
4
|
+
*
|
|
5
|
+
* Skips the napi build if a prebuilt .node file already exists next to
|
|
6
|
+
* this package (either a root-level `rivetkit-napi.*.node` or one inside
|
|
7
|
+
* a `npm/<platform>/` directory). This lets CI skip a redundant napi build
|
|
8
|
+
* when the cross-compiled artifacts have already been downloaded from the
|
|
9
|
+
* platform build jobs.
|
|
10
|
+
*
|
|
11
|
+
* Pass `--force` to always run the napi build.
|
|
12
|
+
*/
|
|
13
|
+
import { execSync } from "node:child_process";
|
|
14
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
15
|
+
import { dirname, join } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
|
|
18
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const packageDir = join(__dirname, "..");
|
|
20
|
+
|
|
21
|
+
const args = process.argv.slice(2);
|
|
22
|
+
const force = args.includes("--force");
|
|
23
|
+
const releaseArg = args.find((a) => a === "--release");
|
|
24
|
+
const extraFlags = releaseArg ? ["--release"] : [];
|
|
25
|
+
|
|
26
|
+
// Explicit skip for environments that don't need the native binary (e.g.
|
|
27
|
+
// Docker engine-frontend build which only consumes TypeScript types).
|
|
28
|
+
if (!force && process.env.SKIP_NAPI_BUILD === "1") {
|
|
29
|
+
console.log(
|
|
30
|
+
"[rivetkit-napi/build] SKIP_NAPI_BUILD=1 — skipping napi build",
|
|
31
|
+
);
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function hasPrebuiltArtifact() {
|
|
36
|
+
// Check for root-level .node files.
|
|
37
|
+
const rootFiles = readdirSync(packageDir);
|
|
38
|
+
if (rootFiles.some((f) => f.endsWith(".node"))) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
// Check for any npm/<platform>/*.node files.
|
|
42
|
+
const npmDir = join(packageDir, "npm");
|
|
43
|
+
if (existsSync(npmDir) && statSync(npmDir).isDirectory()) {
|
|
44
|
+
for (const entry of readdirSync(npmDir)) {
|
|
45
|
+
const platDir = join(npmDir, entry);
|
|
46
|
+
if (!statSync(platDir).isDirectory()) continue;
|
|
47
|
+
const files = readdirSync(platDir);
|
|
48
|
+
if (files.some((f) => f.endsWith(".node"))) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!force && hasPrebuiltArtifact()) {
|
|
57
|
+
console.log(
|
|
58
|
+
"[rivetkit-napi/build] prebuilt .node artifact found — skipping napi build",
|
|
59
|
+
);
|
|
60
|
+
console.log("[rivetkit-napi/build] use --force to rebuild from source");
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const cmd = ["napi", "build", "--platform", ...extraFlags].join(" ");
|
|
65
|
+
console.log(`[rivetkit-napi/build] running: ${cmd}`);
|
|
66
|
+
execSync(cmd, { stdio: "inherit", cwd: packageDir });
|