@rivetkit/rivetkit-native 0.0.0-pr.4658.756b818 → 0.0.0-pr.4663.046f5f1
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 +114 -61
- package/package.json +9 -9
- package/wrapper.d.ts +17 -4
- package/wrapper.js +0 -44
package/index.d.ts
CHANGED
|
@@ -4,54 +4,54 @@
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
6
|
export interface JsBindParam {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
kind: string;
|
|
8
|
+
intValue?: number;
|
|
9
|
+
floatValue?: number;
|
|
10
|
+
textValue?: string;
|
|
11
|
+
blobValue?: Buffer;
|
|
12
12
|
}
|
|
13
13
|
export interface ExecuteResult {
|
|
14
|
-
|
|
14
|
+
changes: number;
|
|
15
15
|
}
|
|
16
16
|
export interface QueryResult {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
columns: Array<string>;
|
|
18
|
+
rows: Array<Array<any>>;
|
|
19
19
|
}
|
|
20
20
|
/** Open a native SQLite database backed by the envoy's KV channel. */
|
|
21
|
-
export declare function openDatabaseFromEnvoy(
|
|
21
|
+
export declare function openDatabaseFromEnvoy(
|
|
22
|
+
jsHandle: JsEnvoyHandle,
|
|
23
|
+
actorId: string,
|
|
24
|
+
preloadedEntries?: Array<JsKvEntry> | undefined | null,
|
|
25
|
+
): Promise<JsNativeDatabase>;
|
|
22
26
|
/** Configuration for starting the native envoy client. */
|
|
23
27
|
export interface JsEnvoyConfig {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
endpoint: string;
|
|
29
|
+
token: string;
|
|
30
|
+
namespace: string;
|
|
31
|
+
poolName: string;
|
|
32
|
+
version: number;
|
|
33
|
+
metadata?: any;
|
|
34
|
+
notGlobal: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Log level for the Rust tracing subscriber (e.g. "trace", "debug", "info", "warn", "error").
|
|
37
|
+
* Falls back to RIVET_LOG_LEVEL, then LOG_LEVEL, then RUST_LOG env vars. Defaults to "warn".
|
|
38
|
+
*/
|
|
39
|
+
logLevel?: string;
|
|
36
40
|
}
|
|
37
41
|
/** Options for KV list operations. */
|
|
38
42
|
export interface JsKvListOptions {
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
reverse?: boolean;
|
|
44
|
+
limit?: number;
|
|
41
45
|
}
|
|
42
46
|
/** A key-value entry returned from KV list operations. */
|
|
43
47
|
export interface JsKvEntry {
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
key: Buffer;
|
|
49
|
+
value: Buffer;
|
|
46
50
|
}
|
|
47
51
|
/** A single hibernating request entry. */
|
|
48
52
|
export interface HibernatingRequestEntry {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
envoyMessageIndex: number
|
|
52
|
-
rivetMessageIndex: number
|
|
53
|
-
path: string
|
|
54
|
-
headers?: Record<string, string>
|
|
53
|
+
gatewayId: Buffer;
|
|
54
|
+
requestId: Buffer;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Start the native envoy client synchronously.
|
|
@@ -59,40 +59,93 @@ export interface HibernatingRequestEntry {
|
|
|
59
59
|
* Returns a handle immediately. The caller must call `await handle.started()`
|
|
60
60
|
* to wait for the connection to be ready.
|
|
61
61
|
*/
|
|
62
|
-
export declare function startEnvoySyncJs(
|
|
62
|
+
export declare function startEnvoySyncJs(
|
|
63
|
+
config: JsEnvoyConfig,
|
|
64
|
+
eventCallback: (event: any) => void,
|
|
65
|
+
): JsEnvoyHandle;
|
|
63
66
|
/** Start the native envoy client asynchronously. */
|
|
64
|
-
export declare function startEnvoyJs(
|
|
67
|
+
export declare function startEnvoyJs(
|
|
68
|
+
config: JsEnvoyConfig,
|
|
69
|
+
eventCallback: (event: any) => void,
|
|
70
|
+
): JsEnvoyHandle;
|
|
65
71
|
/** Native SQLite database handle exposed to JavaScript. */
|
|
66
72
|
export declare class JsNativeDatabase {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
takeLastKvError(): string | null;
|
|
74
|
+
run(
|
|
75
|
+
sql: string,
|
|
76
|
+
params?: Array<JsBindParam> | undefined | null,
|
|
77
|
+
): Promise<ExecuteResult>;
|
|
78
|
+
query(
|
|
79
|
+
sql: string,
|
|
80
|
+
params?: Array<JsBindParam> | undefined | null,
|
|
81
|
+
): Promise<QueryResult>;
|
|
82
|
+
exec(sql: string): Promise<QueryResult>;
|
|
83
|
+
close(): Promise<void>;
|
|
72
84
|
}
|
|
73
85
|
/** Native envoy handle exposed to JavaScript via N-API. */
|
|
74
86
|
export declare class JsEnvoyHandle {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
started(): Promise<void>;
|
|
88
|
+
shutdown(immediate: boolean): void;
|
|
89
|
+
get envoyKey(): string;
|
|
90
|
+
sleepActor(actorId: string, generation?: number | undefined | null): void;
|
|
91
|
+
stopActor(
|
|
92
|
+
actorId: string,
|
|
93
|
+
generation?: number | undefined | null,
|
|
94
|
+
error?: string | undefined | null,
|
|
95
|
+
): void;
|
|
96
|
+
destroyActor(actorId: string, generation?: number | undefined | null): void;
|
|
97
|
+
setAlarm(
|
|
98
|
+
actorId: string,
|
|
99
|
+
alarmTs?: number | undefined | null,
|
|
100
|
+
generation?: number | undefined | null,
|
|
101
|
+
): void;
|
|
102
|
+
kvGet(
|
|
103
|
+
actorId: string,
|
|
104
|
+
keys: Array<Buffer>,
|
|
105
|
+
): Promise<Array<Buffer | undefined | null>>;
|
|
106
|
+
kvPut(actorId: string, entries: Array<JsKvEntry>): Promise<void>;
|
|
107
|
+
kvDelete(actorId: string, keys: Array<Buffer>): Promise<void>;
|
|
108
|
+
kvDeleteRange(actorId: string, start: Buffer, end: Buffer): Promise<void>;
|
|
109
|
+
kvListAll(
|
|
110
|
+
actorId: string,
|
|
111
|
+
options?: JsKvListOptions | undefined | null,
|
|
112
|
+
): Promise<Array<JsKvEntry>>;
|
|
113
|
+
kvListRange(
|
|
114
|
+
actorId: string,
|
|
115
|
+
start: Buffer,
|
|
116
|
+
end: Buffer,
|
|
117
|
+
exclusive?: boolean | undefined | null,
|
|
118
|
+
options?: JsKvListOptions | undefined | null,
|
|
119
|
+
): Promise<Array<JsKvEntry>>;
|
|
120
|
+
kvListPrefix(
|
|
121
|
+
actorId: string,
|
|
122
|
+
prefix: Buffer,
|
|
123
|
+
options?: JsKvListOptions | undefined | null,
|
|
124
|
+
): Promise<Array<JsKvEntry>>;
|
|
125
|
+
kvDrop(actorId: string): Promise<void>;
|
|
126
|
+
restoreHibernatingRequests(
|
|
127
|
+
actorId: string,
|
|
128
|
+
requests: Array<HibernatingRequestEntry>,
|
|
129
|
+
): void;
|
|
130
|
+
sendHibernatableWebSocketMessageAck(
|
|
131
|
+
gatewayId: Buffer,
|
|
132
|
+
requestId: Buffer,
|
|
133
|
+
clientMessageIndex: number,
|
|
134
|
+
): void;
|
|
135
|
+
/** Send a message on an open WebSocket connection identified by messageIdHex. */
|
|
136
|
+
sendWsMessage(
|
|
137
|
+
gatewayId: Buffer,
|
|
138
|
+
requestId: Buffer,
|
|
139
|
+
data: Buffer,
|
|
140
|
+
binary: boolean,
|
|
141
|
+
): Promise<void>;
|
|
142
|
+
/** Close an open WebSocket connection. */
|
|
143
|
+
closeWebsocket(
|
|
144
|
+
gatewayId: Buffer,
|
|
145
|
+
requestId: Buffer,
|
|
146
|
+
code?: number | undefined | null,
|
|
147
|
+
reason?: string | undefined | null,
|
|
148
|
+
): Promise<void>;
|
|
149
|
+
startServerless(payload: Buffer): Promise<void>;
|
|
150
|
+
respondCallback(responseId: string, data: any): Promise<void>;
|
|
98
151
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivetkit/rivetkit-native",
|
|
3
|
-
"version": "0.0.0-pr.
|
|
3
|
+
"version": "0.0.0-pr.4663.046f5f1",
|
|
4
4
|
"description": "Native N-API addon for RivetKit providing envoy client and SQLite access",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "index.js",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@napi-rs/cli": "^2.18.4",
|
|
52
|
-
"@rivetkit/engine-envoy-protocol": "0.0.0-pr.
|
|
52
|
+
"@rivetkit/engine-envoy-protocol": "0.0.0-pr.4663.046f5f1"
|
|
53
53
|
},
|
|
54
54
|
"optionalDependencies": {
|
|
55
|
-
"@rivetkit/rivetkit-native-darwin-arm64": "0.0.0-pr.
|
|
56
|
-
"@rivetkit/rivetkit-native-darwin-x64": "0.0.0-pr.
|
|
57
|
-
"@rivetkit/rivetkit-native-linux-arm64-gnu": "0.0.0-pr.
|
|
58
|
-
"@rivetkit/rivetkit-native-linux-arm64-musl": "0.0.0-pr.
|
|
59
|
-
"@rivetkit/rivetkit-native-linux-x64-gnu": "0.0.0-pr.
|
|
60
|
-
"@rivetkit/rivetkit-native-linux-x64-musl": "0.0.0-pr.
|
|
61
|
-
"@rivetkit/rivetkit-native-win32-x64-msvc": "0.0.0-pr.
|
|
55
|
+
"@rivetkit/rivetkit-native-darwin-arm64": "0.0.0-pr.4663.046f5f1",
|
|
56
|
+
"@rivetkit/rivetkit-native-darwin-x64": "0.0.0-pr.4663.046f5f1",
|
|
57
|
+
"@rivetkit/rivetkit-native-linux-arm64-gnu": "0.0.0-pr.4663.046f5f1",
|
|
58
|
+
"@rivetkit/rivetkit-native-linux-arm64-musl": "0.0.0-pr.4663.046f5f1",
|
|
59
|
+
"@rivetkit/rivetkit-native-linux-x64-gnu": "0.0.0-pr.4663.046f5f1",
|
|
60
|
+
"@rivetkit/rivetkit-native-linux-x64-musl": "0.0.0-pr.4663.046f5f1",
|
|
61
|
+
"@rivetkit/rivetkit-native-win32-x64-msvc": "0.0.0-pr.4663.046f5f1"
|
|
62
62
|
}
|
|
63
63
|
}
|
package/wrapper.d.ts
CHANGED
|
@@ -29,9 +29,16 @@ export interface EnvoyHandle {
|
|
|
29
29
|
sleepActor(actorId: string, generation?: number): void;
|
|
30
30
|
stopActor(actorId: string, generation?: number, error?: string): void;
|
|
31
31
|
destroyActor(actorId: string, generation?: number): void;
|
|
32
|
-
setAlarm(
|
|
32
|
+
setAlarm(
|
|
33
|
+
actorId: string,
|
|
34
|
+
alarmTs: number | null,
|
|
35
|
+
generation?: number,
|
|
36
|
+
): void;
|
|
33
37
|
kvGet(actorId: string, keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
|
|
34
|
-
kvListAll(
|
|
38
|
+
kvListAll(
|
|
39
|
+
actorId: string,
|
|
40
|
+
options?: KvListOptions,
|
|
41
|
+
): Promise<[Uint8Array, Uint8Array][]>;
|
|
35
42
|
kvListRange(
|
|
36
43
|
actorId: string,
|
|
37
44
|
start: Uint8Array,
|
|
@@ -46,7 +53,11 @@ export interface EnvoyHandle {
|
|
|
46
53
|
): Promise<[Uint8Array, Uint8Array][]>;
|
|
47
54
|
kvPut(actorId: string, entries: [Uint8Array, Uint8Array][]): Promise<void>;
|
|
48
55
|
kvDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
|
|
49
|
-
kvDeleteRange(
|
|
56
|
+
kvDeleteRange(
|
|
57
|
+
actorId: string,
|
|
58
|
+
start: Uint8Array,
|
|
59
|
+
end: Uint8Array,
|
|
60
|
+
): Promise<void>;
|
|
50
61
|
kvDrop(actorId: string): Promise<void>;
|
|
51
62
|
restoreHibernatingRequests(
|
|
52
63
|
actorId: string,
|
|
@@ -105,7 +116,9 @@ export interface EnvoyConfig {
|
|
|
105
116
|
actorId: string,
|
|
106
117
|
generation: number,
|
|
107
118
|
config: import("@rivetkit/engine-envoy-protocol").ActorConfig,
|
|
108
|
-
preloadedKv:
|
|
119
|
+
preloadedKv:
|
|
120
|
+
| import("@rivetkit/engine-envoy-protocol").PreloadedKv
|
|
121
|
+
| null,
|
|
109
122
|
) => Promise<void>;
|
|
110
123
|
onActorStop: (
|
|
111
124
|
envoyHandle: EnvoyHandle,
|
package/wrapper.js
CHANGED
|
@@ -98,10 +98,6 @@ function wrapHandle(jsHandle) {
|
|
|
98
98
|
const requests = (metaEntries || []).map((e) => ({
|
|
99
99
|
gatewayId: Buffer.from(e.gatewayId),
|
|
100
100
|
requestId: Buffer.from(e.requestId),
|
|
101
|
-
envoyMessageIndex: e.envoyMessageIndex ?? 0,
|
|
102
|
-
rivetMessageIndex: e.rivetMessageIndex ?? 0,
|
|
103
|
-
path: e.path ?? "",
|
|
104
|
-
headers: e.headers ?? {},
|
|
105
101
|
}));
|
|
106
102
|
jsHandle.restoreHibernatingRequests(actorId, requests);
|
|
107
103
|
},
|
|
@@ -312,46 +308,6 @@ function handleEvent(event, config, wrappedHandle) {
|
|
|
312
308
|
);
|
|
313
309
|
break;
|
|
314
310
|
}
|
|
315
|
-
case "websocket_can_hibernate": {
|
|
316
|
-
const gatewayId = Buffer.from(event.gatewayId);
|
|
317
|
-
const requestId = Buffer.from(event.requestId);
|
|
318
|
-
const headers = new Headers(event.headers || {});
|
|
319
|
-
headers.set("Upgrade", "websocket");
|
|
320
|
-
headers.set("Connection", "Upgrade");
|
|
321
|
-
const request = new Request(`http://actor${event.path}`, {
|
|
322
|
-
method: event.method,
|
|
323
|
-
headers,
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
Promise.resolve(
|
|
327
|
-
config.hibernatableWebSocket
|
|
328
|
-
? config.hibernatableWebSocket.canHibernate(
|
|
329
|
-
event.actorId,
|
|
330
|
-
gatewayId,
|
|
331
|
-
requestId,
|
|
332
|
-
request,
|
|
333
|
-
)
|
|
334
|
-
: false,
|
|
335
|
-
).then(
|
|
336
|
-
async (canHibernate) => {
|
|
337
|
-
if (handle._raw) {
|
|
338
|
-
await handle._raw.respondCallback(event.responseId, {
|
|
339
|
-
canHibernate: Boolean(canHibernate),
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
async (err) => {
|
|
344
|
-
console.error("canHibernate error:", err);
|
|
345
|
-
if (handle._raw) {
|
|
346
|
-
await handle._raw.respondCallback(event.responseId, {
|
|
347
|
-
canHibernate: false,
|
|
348
|
-
error: String(err),
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
);
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
311
|
case "websocket_open": {
|
|
356
312
|
if (config.websocket) {
|
|
357
313
|
const messageId = Buffer.from(event.messageId);
|