speedkey 0.1.0

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.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
+ *
4
+ * This entry point re-exports:
5
+ * - Native bindings auto-generated by napi-rs (moved to ./native.js)
6
+ * - All TypeScript client-side APIs from ./src/
7
+ */
8
+ export * from "../build-ts/native";
9
+ export * from "./BaseClient.js";
10
+ export * from "./Batch.js";
11
+ export * from "./Commands.js";
12
+ export * from "./Errors.js";
13
+ export * from "./GlideClient.js";
14
+ export * from "./GlideClusterClient.js";
15
+ export * from "./Logger.js";
16
+ export * from "./OpenTelemetry.js";
17
+ export * from "./server-modules/GlideFt.js";
18
+ export * from "./server-modules/GlideFtOptions.js";
19
+ export * from "./server-modules/GlideJson.js";
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
4
+ *
5
+ * This entry point re-exports:
6
+ * - Native bindings auto-generated by napi-rs (moved to ./native.js)
7
+ * - All TypeScript client-side APIs from ./src/
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ __exportStar(require("../build-ts/native"), exports);
25
+ // Export TypeScript APIs
26
+ __exportStar(require("./BaseClient.js"), exports);
27
+ __exportStar(require("./Batch.js"), exports);
28
+ __exportStar(require("./Commands.js"), exports);
29
+ __exportStar(require("./Errors.js"), exports);
30
+ __exportStar(require("./GlideClient.js"), exports);
31
+ __exportStar(require("./GlideClusterClient.js"), exports);
32
+ __exportStar(require("./Logger.js"), exports);
33
+ __exportStar(require("./OpenTelemetry.js"), exports);
34
+ __exportStar(require("./server-modules/GlideFt.js"), exports);
35
+ __exportStar(require("./server-modules/GlideFtOptions.js"), exports);
36
+ __exportStar(require("./server-modules/GlideJson.js"), exports);
@@ -0,0 +1,286 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ /**
4
+ * This struct is used to keep track of the cursor of a cluster scan.
5
+ * We want to avoid passing the cursor between layers of the application,
6
+ * So we keep the state in the container and only pass the id of the cursor.
7
+ * The cursor is stored in the container and can be retrieved using the id.
8
+ * The cursor is removed from the container when the object is deleted (dropped).
9
+ * To create a cursor:
10
+ * ```typescript
11
+ * // For a new cursor
12
+ * let cursor = new ClusterScanCursor();
13
+ * // Using an existing id
14
+ * let cursor = new ClusterScanCursor("cursor_id");
15
+ * ```
16
+ * To get the cursor id:
17
+ * ```typescript
18
+ * let cursorId = cursor.getCursor();
19
+ * ```
20
+ * To check if the scan is finished:
21
+ * ```typescript
22
+ * let isFinished = cursor.isFinished(); // true if the scan is finished
23
+ * ```
24
+ */
25
+ export declare class ClusterScanCursor {
26
+ constructor(newCursor?: string | undefined | null)
27
+ /** Returns the cursor id. */
28
+ getCursor(): string
29
+ /** Returns true if the scan is finished. */
30
+ isFinished(): boolean
31
+ }
32
+
33
+ /**
34
+ * A handle to a Glide client that allows sending commands directly via NAPI.
35
+ * The client is pinned to a dedicated worker thread for lock-free concurrent execution.
36
+ * Commands are sent via channel to the worker thread which executes them via spawn_local.
37
+ *
38
+ * Response Buffering Architecture:
39
+ * - Responses are pushed to a shared buffer instead of calling ThreadsafeFunction per-response
40
+ * - A wake-up callback is called ONCE when the buffer transitions from empty to non-empty
41
+ * - JS drains all responses from the buffer in a single call
42
+ */
43
+ export declare class GlideClientHandle {
44
+ /**
45
+ * Sends a command to the Valkey/Redis server.
46
+ *
47
+ * This method is the core of the direct NAPI layer. It:
48
+ * 1. Checks inflight request limits synchronously
49
+ * 2. Reconstructs the command arguments from the pointer
50
+ * 3. Spawns an async task to execute the command
51
+ * 4. Calls the response callback with the result
52
+ *
53
+ * # Arguments
54
+ * * `callback_idx` - Index to identify this request in JavaScript
55
+ * * `request_type` - The type of Redis command (maps to RequestType enum)
56
+ * * `args_pointer_high` - High 32 bits of the args Vec<Bytes> pointer
57
+ * * `args_pointer_low` - Low 32 bits of the args Vec<Bytes> pointer
58
+ * * `route_bytes` - Optional routing information for cluster mode
59
+ *
60
+ * # Returns
61
+ * * `true` if the command was successfully queued
62
+ * * `false` if the inflight request limit was exceeded
63
+ */
64
+ sendCommand(callbackIdx: number, requestType: number, argsPointerHigh: number, argsPointerLow: number, routeBytes?: Uint8Array | undefined | null): boolean
65
+ /**
66
+ * Drains all pending responses from the buffer.
67
+ * This should be called from JS when the wake callback is triggered.
68
+ */
69
+ drainResponses(): Array<CommandResponse>
70
+ /**
71
+ * Closes the client connection.
72
+ * After calling this, the client handle should not be used.
73
+ * This marks the buffer as closed to prevent any further wake-up callbacks,
74
+ * which prevents use-after-free crashes during shutdown.
75
+ */
76
+ close(): void
77
+ /**
78
+ * Returns the number of available inflight request slots.
79
+ * This can be used to check if more commands can be sent.
80
+ */
81
+ availableInflightSlots(): number
82
+ /**
83
+ * Sends a batch of commands to the Valkey/Redis server.
84
+ *
85
+ * # Arguments
86
+ * * `callback_idx` - Index to identify this request in JavaScript
87
+ * * `commands` - Array of command tuples (request_type, args_pointer_high, args_pointer_low)
88
+ * * `is_atomic` - If true, execute as transaction (MULTI/EXEC); if false, as pipeline
89
+ * * `raise_on_error` - Whether to raise error on first failure
90
+ * * `timeout` - Optional timeout in milliseconds
91
+ *
92
+ * # Returns
93
+ * * `true` if the batch was successfully queued
94
+ * * `false` if the inflight request limit was exceeded
95
+ */
96
+ sendBatch(callbackIdx: number, commands: Array<BatchCommand>, isAtomic: boolean, raiseOnError: boolean, timeout?: number | undefined | null, retryServerError?: boolean | undefined | null, retryConnectionError?: boolean | undefined | null, routeBytes?: Uint8Array | undefined | null): boolean
97
+ /** Invokes a Lua script using EVALSHA with automatic LOAD fallback. */
98
+ invokeScript(callbackIdx: number, hash: string, keysPointerHigh: number, keysPointerLow: number, argsPointerHigh: number, argsPointerLow: number, routeBytes?: Uint8Array | undefined | null): boolean
99
+ /** Performs cluster-wide key scanning. */
100
+ clusterScan(callbackIdx: number, cursor: string, matchPattern?: Uint8Array | undefined | null, count?: number | undefined | null, objectType?: string | undefined | null, allowNonCoveredSlots?: boolean | undefined | null): boolean
101
+ /** Updates the connection password. */
102
+ updateConnectionPassword(callbackIdx: number, password: string | undefined | null, immediateAuth: boolean): boolean
103
+ /** Refreshes the IAM token. */
104
+ refreshIamToken(callbackIdx: number): boolean
105
+ }
106
+
107
+ /**
108
+ * A wrapper for a script object. As long as this object is alive, the script's code is saved in memory, and can be resent to the server.
109
+ *
110
+ * **IMPORTANT**: Script objects are NOT automatically garbage collected. You are responsible for calling `release()`
111
+ * on every Script object when you're done with it to prevent memory leaks. Failure to do so will result in memory leaks.
112
+ */
113
+ export declare class Script {
114
+ /** Construct with the script's code. */
115
+ constructor(code: string | Uint8Array)
116
+ /** Returns the hash of the script. */
117
+ getHash(): string
118
+ /**
119
+ * Decrements the script's reference count in the local container.
120
+ * Removes the script when the count reaches zero.
121
+ *
122
+ * You need to call this method when you're done with the Script object. Script objects are NOT
123
+ * automatically garbage collected, and failure to call release() will result in memory leaks.
124
+ */
125
+ release(): void
126
+ }
127
+
128
+ /** A single command in a batch */
129
+ export interface BatchCommand {
130
+ requestType: number
131
+ argsPointerHigh: number
132
+ argsPointerLow: number
133
+ }
134
+
135
+ /**
136
+ * Response object passed to the JavaScript callback for command results.
137
+ * This replaces the protobuf-based response used in the socket IPC layer.
138
+ */
139
+ export interface CommandResponse {
140
+ /** The callback index that identifies this request on the JS side */
141
+ callbackIdx: number
142
+ /** High 32 bits of the response value pointer (if response is a Value) */
143
+ respPointerHigh?: number
144
+ /** Low 32 bits of the response value pointer (if response is a Value) */
145
+ respPointerLow?: number
146
+ /** Constant response string (e.g., "OK" for simple responses) */
147
+ constantResponse?: string
148
+ /** Error information if the request failed */
149
+ requestError?: RequestErrorNapi
150
+ /** Closing error message if the client is closing */
151
+ closingError?: string
152
+ /** Whether this is a push message (pub/sub) */
153
+ isPush: boolean
154
+ }
155
+
156
+ /**
157
+ * Creates a new direct NAPI client connection with response buffering.
158
+ *
159
+ * This function creates a Client using the glide-core library and wraps it
160
+ * in a GlideClientHandle that can send commands directly without socket IPC.
161
+ *
162
+ * Response Buffering:
163
+ * - Responses are accumulated in a shared buffer
164
+ * - A single wake-up callback notifies JS when responses are available
165
+ * - JS then calls drainResponses() to get all pending responses at once
166
+ * - This reduces ThreadsafeFunction call overhead from N to ~1 per batch
167
+ *
168
+ * # Arguments
169
+ * * `connection_request_bytes` - Protobuf-encoded ConnectionRequest
170
+ * * `wake_callback` - JavaScript callback to wake up when responses available
171
+ *
172
+ * # Returns
173
+ * A Promise that resolves to a GlideClientHandle on success
174
+ */
175
+ export declare function CreateDirectClient(connectionRequestBytes: Uint8Array, wakeCallback: () => void): Promise<GlideClientHandle>
176
+
177
+ /** Creates an open telemetry span with the given name and returns a pointer to the span */
178
+ export declare function createLeakedOtelSpan(name: string): [number, number]
179
+
180
+ /**
181
+ * @internal @test
182
+ * This function is for tests that require a value allocated on the heap.
183
+ * Should NOT be used in production.
184
+ */
185
+ export declare function createLeakedStringVec(message: Array<Uint8Array>): [number, number]
186
+
187
+ export const DEFAULT_CONNECTION_TIMEOUT_IN_MILLISECONDS: number
188
+
189
+ export const DEFAULT_INFLIGHT_REQUESTS_LIMIT: number
190
+
191
+ export const DEFAULT_REQUEST_TIMEOUT_IN_MILLISECONDS: number
192
+
193
+ export declare function dropOtelSpan(spanPtr: bigint): void
194
+
195
+ /**
196
+ * Free a previously leaked string vec by its split pointer.
197
+ * Called from JS to reclaim memory when a leaked pointer will not be
198
+ * passed to send_command/send_batch/invoke_script (e.g., early error paths).
199
+ */
200
+ export declare function freeLeakedStringVec(highBits: number, lowBits: number): void
201
+
202
+ export declare function getStatistics(): object
203
+
204
+ export declare function InitInternalLogger(level?: Level | undefined | null, fileName?: string | undefined | null): Level
205
+
206
+ export declare function InitOpenTelemetry(openTelemetryConfig: OpenTelemetryConfig): void
207
+
208
+ export declare const enum Level {
209
+ Debug = 3,
210
+ Error = 0,
211
+ Info = 2,
212
+ Trace = 4,
213
+ Warn = 1,
214
+ Off = 5
215
+ }
216
+
217
+ export declare function log(logLevel: Level, logIdentifier: string, message: string): void
218
+
219
+ export const MAX_REQUEST_ARGS_LEN: number
220
+
221
+ /**
222
+ * Configuration for OpenTelemetry integration in the Node.js client.
223
+ *
224
+ * This struct allows you to configure how telemetry data (traces and metrics) is exported to an OpenTelemetry collector.
225
+ * - `traces`: Optional configuration for exporting trace data. If `None`, trace data will not be exported.
226
+ * - `metrics`: Optional configuration for exporting metrics data. If `None`, metrics data will not be exported.
227
+ * - `flush_interval_ms`: Optional interval in milliseconds between consecutive exports of telemetry data. If `None`, a default value will be used.
228
+ *
229
+ * At least one of traces or metrics must be provided.
230
+ */
231
+ export interface OpenTelemetryConfig {
232
+ /** Optional configuration for exporting trace data. If `None`, trace data will not be exported. */
233
+ traces?: OpenTelemetryTracesConfig
234
+ /** Optional configuration for exporting metrics data. If `None`, metrics data will not be exported. */
235
+ metrics?: OpenTelemetryMetricsConfig
236
+ /** Optional interval in milliseconds between consecutive exports of telemetry data. If `None`, the default `DEFAULT_FLUSH_SIGNAL_INTERVAL_MS` will be used. */
237
+ flushIntervalMs?: number
238
+ }
239
+
240
+ /**
241
+ * Configuration for exporting OpenTelemetry metrics.
242
+ *
243
+ * - `endpoint`: The endpoint to which metrics data will be exported. Expected format:
244
+ * - For gRPC: `grpc://host:port`
245
+ * - For HTTP: `http://host:port` or `https://host:port`
246
+ * - For file exporter: `file:///absolute/path/to/folder/file.json`
247
+ */
248
+ export interface OpenTelemetryMetricsConfig {
249
+ /** The endpoint to which metrics data will be exported. */
250
+ endpoint: string
251
+ }
252
+
253
+ /**
254
+ * Configuration for exporting OpenTelemetry traces.
255
+ *
256
+ * - `endpoint`: The endpoint to which trace data will be exported. Expected format:
257
+ * - For gRPC: `grpc://host:port`
258
+ * - For HTTP: `http://host:port` or `https://host:port`
259
+ * - For file exporter: `file:///absolute/path/to/folder/file.json`
260
+ * - `sample_percentage`: The percentage of requests to sample and create a span for, used to measure command duration. If `None`, a default value DEFAULT_TRACE_SAMPLE_PERCENTAGE will be used.
261
+ * Note: There is a tradeoff between sampling percentage and performance. Higher sampling percentages will provide more detailed telemetry data but will impact performance.
262
+ * It is recommended to keep this number low (1-5%) in production environments unless you have specific needs for higher sampling rates.
263
+ */
264
+ export interface OpenTelemetryTracesConfig {
265
+ /** The endpoint to which trace data will be exported. */
266
+ endpoint: string
267
+ /**
268
+ * The percentage of requests to sample and create a span for, used to measure command duration. If `None`, a default value DEFAULT_TRACE_SAMPLE_PERCENTAGE will be used.
269
+ * Note: There is a tradeoff between sampling percentage and performance. Higher sampling percentages will provide more detailed telemetry data but will impact performance.
270
+ * It is recommended to keep this number low (1-5%) in production environments unless you have specific needs for higher sampling rates.
271
+ */
272
+ samplePercentage?: number
273
+ }
274
+
275
+ /** Error information for failed requests. */
276
+ export interface RequestErrorNapi {
277
+ /** Human-readable error message */
278
+ message: string
279
+ /**
280
+ * Error type code (maps to RequestErrorType enum)
281
+ * 0 = Unspecified, 1 = ExecAbort, 2 = Timeout, 3 = Disconnect
282
+ */
283
+ errorType: number
284
+ }
285
+
286
+ export declare function valueFromSplitPointer(highBits: number, lowBits: number, stringDecoder: boolean): null | string | Uint8Array | number | {} | Boolean | BigInt | Set<any> | any[] | Buffer