geonix 1.23.6 → 1.30.2
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/LICENSE.md +1 -1
- package/README.md +348 -4
- package/exports.js +0 -2
- package/index.d.ts +292 -237
- package/package.json +11 -8
- package/src/Codec.js +20 -7
- package/src/Connection.js +94 -40
- package/src/Crypto.js +103 -0
- package/src/Gateway.js +155 -70
- package/src/Logger.js +90 -9
- package/src/Registry.js +133 -15
- package/src/Remote.js +15 -6
- package/src/Request.js +117 -80
- package/src/RequestOptions.js +11 -8
- package/src/Service.js +133 -91
- package/src/Stream.js +69 -15
- package/src/Util.js +196 -158
- package/src/WebServer.js +18 -10
- package/test/context.js +0 -35
- package/test/delayedStart.js +0 -24
- package/test/gateway.js +0 -34
- package/test/middleware.js +0 -24
- package/test/package.json +0 -16
- package/test/pubsub.js +0 -29
- package/test/simple.js +0 -29
- package/test/static/index.html +0 -1
- package/test/stream.js +0 -43
- package/test/upload.js +0 -34
- package/test/ws_auth.js +0 -21
package/index.d.ts
CHANGED
|
@@ -1,266 +1,321 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Readable } from "stream";
|
|
3
|
+
import type { IncomingMessage } from "http";
|
|
4
|
+
import type { EventEmitter } from "events";
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Service
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
export interface ServiceOptions {
|
|
11
|
+
/** Override the class name used to identify the service on the bus. */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** Override the service version. Falls back to GX_VERSION env var, then a dev default. */
|
|
14
|
+
version?: string;
|
|
15
|
+
/** Optional static ID for targeting a specific instance via Remote("#<id>"). */
|
|
16
|
+
id?: string;
|
|
17
|
+
/** Toggle built-in Express body parsers. All default to true. */
|
|
18
|
+
middleware?: {
|
|
19
|
+
json?: boolean;
|
|
20
|
+
raw?: boolean;
|
|
21
|
+
cookies?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* When false, only the instance ID is sent in beacon messages (saves bandwidth).
|
|
25
|
+
* Default: true.
|
|
26
|
+
*/
|
|
27
|
+
fullBeacon?: boolean;
|
|
28
|
+
/** Express route handlers injected before / after each service endpoint handler. */
|
|
29
|
+
handlers?: {
|
|
30
|
+
before?: ((...args: any[]) => any)[];
|
|
31
|
+
after?: ((...args: any[]) => any)[];
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
6
35
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
36
|
+
* Base class for all Geonix services. Extend this and call `Service.start()` to register on
|
|
37
|
+
* the NATS bus, expose HTTP endpoints, and begin sending presence beacons.
|
|
9
38
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
39
|
+
* @example
|
|
40
|
+
* class GreetingService extends Service {
|
|
41
|
+
* async greet(name: string) {
|
|
42
|
+
* return `Hello, ${name}!`;
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* GreetingService.start();
|
|
12
46
|
*/
|
|
13
|
-
declare class
|
|
47
|
+
export declare class Service {
|
|
14
48
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
49
|
+
* Override to hard-code the service version. Ignored when GX_VERSION / VERSION env vars
|
|
50
|
+
* are set, or when `options.version` is passed to `start()`.
|
|
17
51
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
52
|
+
version?: string;
|
|
53
|
+
/** Called once after the service has connected and registered on the bus. */
|
|
54
|
+
onStart?(): void | Promise<void>;
|
|
55
|
+
/** Creates an instance of the subclass and starts it on the NATS bus. */
|
|
56
|
+
static start(options?: ServiceOptions): void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// Remote
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Creates a proxy that forwards property-access calls to a named remote service.
|
|
65
|
+
* Without a type parameter the proxy is fully dynamic (`any`). Pass a service
|
|
66
|
+
* interface as the type parameter for IDE autocompletion and type checking.
|
|
67
|
+
*
|
|
68
|
+
* @param service - Service name, optionally with version (`@^1.2`) or static ID (`#<id>`).
|
|
69
|
+
* @param context - Optional context values forwarded to every remote method call.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Fully dynamic — no types required, `as` casts work freely
|
|
73
|
+
* const svc = Remote("GreetingService");
|
|
74
|
+
* const result = await svc.greet("Alice");
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Typed — opt-in
|
|
78
|
+
* interface GreetingService { greet(name: string): Promise<string> }
|
|
79
|
+
* const svc = Remote<GreetingService>("GreetingService");
|
|
80
|
+
*/
|
|
81
|
+
export declare function Remote<T = any>(
|
|
82
|
+
service: string,
|
|
83
|
+
...context: any[]
|
|
84
|
+
): T;
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Stream
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
/** A Geonix stream descriptor — the wire representation of a streaming value. */
|
|
91
|
+
export interface StreamDescriptor {
|
|
92
|
+
$: "stream";
|
|
93
|
+
id: string;
|
|
94
|
+
/** HTTP addresses (host:port) where the stream can be fetched. */
|
|
95
|
+
a?: string[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Map of in-process stream IDs to their active Readable instances. */
|
|
99
|
+
export declare const activeStreams: Record<string, Readable>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Wraps data in a Geonix stream descriptor for transport over NATS or HTTP.
|
|
103
|
+
* Buffers, strings, and Readables are accepted. Already-wrapped descriptors
|
|
104
|
+
* are returned unchanged.
|
|
105
|
+
*/
|
|
106
|
+
export declare function Stream(data: Buffer | string | Readable | object): StreamDescriptor;
|
|
107
|
+
|
|
108
|
+
/** Returns `true` if `object` is a Geonix stream descriptor. */
|
|
109
|
+
export declare function isStream(object: unknown): object is StreamDescriptor;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Resolves a stream descriptor to a Node.js Readable.
|
|
113
|
+
* Prefers HTTP; falls back to NATS. Non-descriptor values are returned as-is.
|
|
114
|
+
*/
|
|
115
|
+
export declare function getReadable(object: StreamDescriptor | any): Promise<Readable>;
|
|
116
|
+
|
|
117
|
+
/** Reads a stream or descriptor fully into memory and returns a Buffer. */
|
|
118
|
+
export declare function streamToBuffer(object: Readable | StreamDescriptor): Promise<Buffer>;
|
|
119
|
+
|
|
120
|
+
/** Reads a stream or descriptor fully into memory and returns a string. */
|
|
121
|
+
export declare function streamToString(object: Readable | StreamDescriptor, encoding?: BufferEncoding): Promise<string>;
|
|
122
|
+
|
|
123
|
+
/** Reads a stream or descriptor fully into memory and parses the result as JSON. */
|
|
124
|
+
export declare function streamToJSON(object: Readable | StreamDescriptor): Promise<any>;
|
|
125
|
+
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// Gateway
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
export interface GatewayOptions {
|
|
24
131
|
/**
|
|
25
|
-
*
|
|
132
|
+
* CORS mode:
|
|
133
|
+
* - omitted / `false` — no CORS headers set
|
|
134
|
+
* - `"*"` — wildcard, all origins, no credentials
|
|
135
|
+
* - `true` — reflect any origin with credentials
|
|
136
|
+
* - `string[]` — allow-list; credentials only for listed origins
|
|
26
137
|
*/
|
|
138
|
+
cors?: boolean | "*" | string[];
|
|
139
|
+
beforeRequest?: (req: any, res: any) => void;
|
|
140
|
+
afterRequest?: (req: any, res: any) => void;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* HTTP / WebSocket gateway that auto-discovers services via the registry and reverse-proxies
|
|
145
|
+
* incoming requests to the appropriate instance.
|
|
146
|
+
*/
|
|
147
|
+
export declare class Gateway {
|
|
148
|
+
static start(opts?: GatewayOptions): Gateway;
|
|
149
|
+
stop(): void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// Connection
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
interface Connection {
|
|
157
|
+
start(transport?: string): Promise<void>;
|
|
158
|
+
monitorStatus(): void;
|
|
27
159
|
waitUntilReady(): Promise<void>;
|
|
28
|
-
|
|
29
|
-
* Publish JSON
|
|
30
|
-
*
|
|
31
|
-
* @param {string} subject
|
|
32
|
-
* @param {object} json
|
|
33
|
-
* @returns void
|
|
34
|
-
*/
|
|
160
|
+
waitUntilClosed(): Promise<void>;
|
|
35
161
|
publish(subject: string, json: object): Promise<void>;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* @param {string | Buffer} data
|
|
41
|
-
* @returns void
|
|
42
|
-
*/
|
|
43
|
-
publishRaw(subject: string, data: string | Buffer): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Request/Reply pattern on top of pub/sub
|
|
46
|
-
*
|
|
47
|
-
* @param {string} subject
|
|
48
|
-
* @param {object} json
|
|
49
|
-
* @param {object} options
|
|
50
|
-
* @returns any
|
|
51
|
-
*/
|
|
52
|
-
request(subject: string, json: object, opts?: {}): Promise<unknown>;
|
|
53
|
-
subscribe(subject: any, options: any): Promise<any>;
|
|
54
|
-
unsubscribe(subscription: any): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* @returns {number}
|
|
58
|
-
*/
|
|
162
|
+
publishRaw(subject: string, data?: string | Buffer): Promise<void>;
|
|
163
|
+
subscribe(subject: string, options?: object): Promise<AsyncIterable<any>>;
|
|
164
|
+
unsubscribe(subscription: AsyncIterable<any>): void;
|
|
165
|
+
request(subject: string, json: object, opts?: object): Promise<any>;
|
|
59
166
|
getMaxPayloadSize(): number;
|
|
60
167
|
isClosed(): boolean;
|
|
61
168
|
drain(): Promise<void>;
|
|
62
|
-
#private;
|
|
63
169
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
170
|
+
|
|
171
|
+
/** Singleton NATS connection pool shared across the process. */
|
|
172
|
+
export declare const connection: Connection;
|
|
173
|
+
|
|
174
|
+
/** Initiates a graceful shutdown by draining all NATS connections. */
|
|
175
|
+
export declare function stopConnection(): void;
|
|
176
|
+
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
// Registry
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
/** A live service entry as seen by the local registry. */
|
|
182
|
+
export interface RegistryEntry {
|
|
183
|
+
/** Unique instance ID (re-generated on each start) */
|
|
184
|
+
i: string;
|
|
185
|
+
/** Service name */
|
|
186
|
+
n: string;
|
|
187
|
+
/** Service version */
|
|
188
|
+
v: string;
|
|
189
|
+
/** Exposed method names */
|
|
190
|
+
m: string[];
|
|
191
|
+
/** Network addresses in `host:port` form */
|
|
192
|
+
a: string[];
|
|
193
|
+
/** Geonix version the service is running */
|
|
194
|
+
gx: string;
|
|
195
|
+
/** Optional static service ID */
|
|
196
|
+
id?: string;
|
|
69
197
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Registry maintains a local list of available services and their versions.
|
|
81
|
-
*/
|
|
82
|
-
declare class Registry {
|
|
83
|
-
getEntries(): {};
|
|
84
|
-
getIdentifier(service: any, version: any, id: any): any;
|
|
85
|
-
#private;
|
|
198
|
+
|
|
199
|
+
interface Registry extends EventEmitter {
|
|
200
|
+
stop(): void;
|
|
201
|
+
getEntries(): Record<string, RegistryEntry>;
|
|
202
|
+
getEntriesForIdentifier(identifier: string): RegistryEntry[];
|
|
203
|
+
getIdentifier(service: string, version?: string, id?: string): string | undefined;
|
|
204
|
+
on(event: "added" | "removed", listener: (entry: RegistryEntry) => void): this;
|
|
205
|
+
once(event: "added" | "removed", listener: (entry: RegistryEntry) => void): this;
|
|
206
|
+
off(event: "added" | "removed", listener: (entry: RegistryEntry) => void): this;
|
|
86
207
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* @param {any[]} context
|
|
96
|
-
* @param {object} options
|
|
97
|
-
* @returns
|
|
98
|
-
*/
|
|
99
|
-
export function Request(service: string, method: string, args: any[], context: any[], options: object): Promise<any>;
|
|
100
|
-
/**
|
|
101
|
-
* Send a request to a service
|
|
102
|
-
*
|
|
103
|
-
* @param {string} identifier
|
|
104
|
-
* @param {string} method
|
|
105
|
-
* @param {any[]} args
|
|
106
|
-
* @param {any[]} context
|
|
107
|
-
* @param {object} options
|
|
108
|
-
* @returns
|
|
109
|
-
*/
|
|
110
|
-
export function directRequest(identifier: string, method: string, args: any[], context: any[], options: object, service: any): Promise<any>;
|
|
208
|
+
|
|
209
|
+
/** Singleton Registry instance — local view of all live services on the bus. */
|
|
210
|
+
export declare const registry: Registry;
|
|
211
|
+
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
// Request / Subscribe / Publish
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
|
|
111
216
|
/**
|
|
112
|
-
*
|
|
217
|
+
* Sends a request to a named service, waiting in the registry if the service is not yet up.
|
|
113
218
|
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
219
|
+
* @param service - Service name, optionally with version (`@^1.2`) or instance ID (`#<id>`).
|
|
220
|
+
* @param method - Method name to invoke on the remote service.
|
|
221
|
+
* @param args - Arguments. The first element may be a `RequestOptions` sentinel.
|
|
222
|
+
* @param context - Optional context forwarded to the remote method.
|
|
116
223
|
*/
|
|
117
|
-
export function
|
|
224
|
+
export declare function Request(
|
|
225
|
+
service: string,
|
|
226
|
+
method: string,
|
|
227
|
+
args: any[],
|
|
228
|
+
context?: any[]
|
|
229
|
+
): Promise<any>;
|
|
230
|
+
|
|
231
|
+
/** Subscribes to a NATS subject and calls `callback` with raw message data for each message. */
|
|
232
|
+
export declare function Subscribe(subject: string, callback: (data: Buffer) => void): Promise<void>;
|
|
233
|
+
|
|
234
|
+
/** Publishes a raw payload to a NATS subject. Fire-and-forget. */
|
|
235
|
+
export declare function Publish(subject: string, payload: string | Buffer): Promise<void>;
|
|
236
|
+
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
// RequestOptions
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
export interface RequestOptionsInput {
|
|
242
|
+
/** Max time in ms to wait for the service to appear in the registry. Default: 300 000. */
|
|
243
|
+
timeout?: number;
|
|
244
|
+
/** Max time in ms to wait for the HTTP RPC response. Default: 5 000. */
|
|
245
|
+
httpTimeout?: number;
|
|
246
|
+
}
|
|
247
|
+
|
|
118
248
|
/**
|
|
119
|
-
*
|
|
249
|
+
* Wraps per-call options in a sentinel that `Request` (and `Remote`) detects and extracts
|
|
250
|
+
* when passed as the first argument of a service method call.
|
|
120
251
|
*
|
|
121
|
-
* @
|
|
122
|
-
*
|
|
123
|
-
* @returns
|
|
252
|
+
* @example
|
|
253
|
+
* const result = await myService.compute(RequestOptions({ timeout: 60_000 }), payload);
|
|
124
254
|
*/
|
|
125
|
-
export function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
255
|
+
export declare function RequestOptions(options: RequestOptionsInput): object;
|
|
256
|
+
|
|
257
|
+
// ---------------------------------------------------------------------------
|
|
258
|
+
// Utilities
|
|
259
|
+
// ---------------------------------------------------------------------------
|
|
260
|
+
|
|
261
|
+
/** The installed Geonix package version string. Equals `"N/A"` if metadata is unavailable. */
|
|
262
|
+
export declare const GeonixVersion: string;
|
|
263
|
+
|
|
264
|
+
/** Generates a cryptographically random Base62-encoded ID string. */
|
|
265
|
+
export declare function randomID(size?: number): string;
|
|
266
|
+
|
|
267
|
+
// ---------------------------------------------------------------------------
|
|
268
|
+
// parseMultipart
|
|
269
|
+
// ---------------------------------------------------------------------------
|
|
270
|
+
|
|
271
|
+
export interface ParseMultipartOptions {
|
|
272
|
+
/** Buffer parts in memory instead of writing to temp files. Default: false. */
|
|
273
|
+
useMemory?: boolean;
|
|
274
|
+
/** Maximum allowed size in bytes for a single part. */
|
|
275
|
+
maxFileSize?: number;
|
|
276
|
+
/** Maximum number of parts allowed. */
|
|
277
|
+
maxFiles?: number;
|
|
129
278
|
}
|
|
130
|
-
|
|
131
|
-
export
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
node: {
|
|
143
|
-
version: any;
|
|
144
|
-
platform: any;
|
|
145
|
-
arch: any;
|
|
146
|
-
};
|
|
147
|
-
env: any;
|
|
148
|
-
mem: any;
|
|
149
|
-
rss: any;
|
|
150
|
-
cpu: any;
|
|
151
|
-
};
|
|
152
|
-
$getServiceInfo(): {};
|
|
153
|
-
#private;
|
|
279
|
+
|
|
280
|
+
export interface MultipartPart {
|
|
281
|
+
/** Field name from Content-Disposition, or `null` if absent. */
|
|
282
|
+
name: string | null;
|
|
283
|
+
/** Filename from Content-Disposition, or `null` if absent. */
|
|
284
|
+
filename: string | null;
|
|
285
|
+
/** Parsed part headers (lowercase keys). */
|
|
286
|
+
headers: Record<string, string>;
|
|
287
|
+
/** Readable stream of the part body. */
|
|
288
|
+
body: Readable;
|
|
289
|
+
/** Part body size in bytes. */
|
|
290
|
+
size: number;
|
|
154
291
|
}
|
|
292
|
+
|
|
155
293
|
/**
|
|
156
|
-
*
|
|
294
|
+
* Parses a `multipart/form-data` request body into an array of part objects.
|
|
157
295
|
*
|
|
158
|
-
* @
|
|
159
|
-
* @param {*} automated
|
|
160
|
-
* @returns
|
|
296
|
+
* @throws If the content-type is not `multipart/form-data` or a size/count limit is exceeded.
|
|
161
297
|
*/
|
|
162
|
-
export function
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
"name-": string;
|
|
180
|
-
/**
|
|
181
|
-
* - Filename of the part (extracted from Content-Disposition)
|
|
182
|
-
*/
|
|
183
|
-
filename: string;
|
|
184
|
-
/**
|
|
185
|
-
* - Headers of the part
|
|
186
|
-
*/
|
|
187
|
-
headers: Object;
|
|
188
|
-
/**
|
|
189
|
-
* - Path to the file when useMemory is false
|
|
190
|
-
*/
|
|
191
|
-
bodyFile: string;
|
|
192
|
-
/**
|
|
193
|
-
* - Readable stream of the part
|
|
194
|
-
*/
|
|
195
|
-
body: Readable;
|
|
196
|
-
};
|
|
197
|
-
type ServiceOptions = {
|
|
198
|
-
middleware?: {
|
|
199
|
-
/**
|
|
200
|
-
* Enable JSON middleware
|
|
201
|
-
*/
|
|
202
|
-
json?: boolean | undefined;
|
|
203
|
-
/**
|
|
204
|
-
* Enable RAW middleware
|
|
205
|
-
*/
|
|
206
|
-
raw?: boolean | undefined;
|
|
207
|
-
/**
|
|
208
|
-
* Enable cookies middleware
|
|
209
|
-
*/
|
|
210
|
-
cookies?: boolean | undefined;
|
|
211
|
-
} | undefined;
|
|
212
|
-
/**
|
|
213
|
-
* Enable full beacon
|
|
214
|
-
*/
|
|
215
|
-
fullBeacon?: boolean | undefined;
|
|
216
|
-
};
|
|
217
|
-
/**
|
|
218
|
-
* Parse nats:// URL
|
|
219
|
-
* @param {string} url
|
|
220
|
-
* @returns
|
|
221
|
-
*/
|
|
222
|
-
export function parseURL(url: string): any;
|
|
223
|
-
export function getFirstItemFromAsyncIterable(asyncIterable: any): Promise<any>;
|
|
224
|
-
export function getNetworkAddresses(): any[];
|
|
225
|
-
export function isIterable(obj: any): any;
|
|
298
|
+
export declare function parseMultipart(
|
|
299
|
+
req: IncomingMessage,
|
|
300
|
+
options?: ParseMultipartOptions
|
|
301
|
+
): Promise<MultipartPart[]>;
|
|
302
|
+
|
|
303
|
+
// ---------------------------------------------------------------------------
|
|
304
|
+
// ServeStatic
|
|
305
|
+
// ---------------------------------------------------------------------------
|
|
306
|
+
|
|
307
|
+
export interface ServeStaticOptions {
|
|
308
|
+
/** URL prefix to strip before resolving the file path. */
|
|
309
|
+
root?: string;
|
|
310
|
+
/** If `true`, respond with `index.html` for all 404s — useful for SPAs. */
|
|
311
|
+
indexOn404?: boolean;
|
|
312
|
+
[key: string]: any;
|
|
313
|
+
}
|
|
314
|
+
|
|
226
315
|
/**
|
|
316
|
+
* Creates an Express router that serves static files from `root`.
|
|
227
317
|
*
|
|
228
|
-
*
|
|
229
|
-
* @param
|
|
230
|
-
* @param {parseMultipartOptions} options
|
|
231
|
-
* @returns ParsedMultiPart[]
|
|
318
|
+
* @param root - Filesystem path to the directory containing static assets.
|
|
319
|
+
* @param options - Options forwarded to `express.static`, plus `root` prefix strip and `indexOn404`.
|
|
232
320
|
*/
|
|
233
|
-
export function
|
|
234
|
-
headers: {};
|
|
235
|
-
bodyFile: any;
|
|
236
|
-
body: any;
|
|
237
|
-
}[]>;
|
|
238
|
-
export function tempFilename(): any;
|
|
239
|
-
export function randomSafeId(size?: number): string;
|
|
240
|
-
export function deepMerge(target: any, ...source: any[]): any;
|
|
241
|
-
export function sleep(delay: number): Promise<any>;
|
|
242
|
-
export function nextTick(): Promise<any>;
|
|
243
|
-
export function picoid(size?: number): any;
|
|
244
|
-
export function hash(data: string | Buffer): any;
|
|
245
|
-
export function createServerAtPort(port: number, pkg: Object, handler: Function): Promise<any>;
|
|
246
|
-
export function createServerAtFreePort(pkg: Object, handler: Function, start?: number, poolSize?: number): Promise<any>;
|
|
247
|
-
export function createTCPServer(handler: Function, start?: number, poolSize?: number): Promise<any>;
|
|
248
|
-
export function createHTTPServer(handler: Function, start?: number, poolSize?: number): Promise<any>;
|
|
249
|
-
export function getSecondsSinceMidnight(): number;
|
|
250
|
-
export function getFunctionParams(fn: any): any;
|
|
251
|
-
export function proxyHttp(target: any, req: any, res: any): Promise<any>;
|
|
252
|
-
export function OverlayObject(object: any, overlay: any): any;
|
|
253
|
-
export const GeonixVersion: string;
|
|
254
|
-
export function StreamChunker(chunkSize?: number): any;
|
|
255
|
-
export const HEALTH_CHECK_ENDPOINT: "/pA4vY7fT9oG5aI8cA4yV3qW5fP9qR1vI";
|
|
256
|
-
export function ServeStatic(root: any, options?: {}): any;
|
|
257
|
-
export const webserver: WebServer;
|
|
258
|
-
declare class WebServer {
|
|
259
|
-
start(): Promise<void>;
|
|
260
|
-
getPort(): any;
|
|
261
|
-
router(): any;
|
|
262
|
-
waitUntilReady(): Promise<void>;
|
|
263
|
-
stop(): void;
|
|
264
|
-
#private;
|
|
265
|
-
}
|
|
266
|
-
export {};
|
|
321
|
+
export declare function ServeStatic(root: string, options?: ServeStaticOptions): any;
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geonix",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gateway": "./.bin/gateway.js"
|
|
8
8
|
},
|
|
9
9
|
"main": "exports.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"test": "
|
|
12
|
-
"
|
|
12
|
+
"test": "npm run test:unit && npm run test:integration",
|
|
13
|
+
"test:unit": "GX_LOG_LEVEL=none node --test --test-reporter=spec tests/unit/*.test.js",
|
|
14
|
+
"test:integration": "GX_LOG_LEVEL=none node --test --test-concurrency=1 --test-reporter=spec tests/integration/*.test.js",
|
|
13
15
|
"lint": "npx eslint src",
|
|
14
16
|
"deploy": "npm run build && npm publish"
|
|
15
17
|
},
|
|
@@ -17,18 +19,19 @@
|
|
|
17
19
|
"license": "MIT",
|
|
18
20
|
"dependencies": {
|
|
19
21
|
"cookie-parser": "1.4.7",
|
|
20
|
-
"express": "^4.
|
|
22
|
+
"express": "^4.22.1",
|
|
21
23
|
"express-async-errors": "3.1.1",
|
|
22
24
|
"express-ws": "5.0.2",
|
|
23
|
-
"nats": "2.
|
|
24
|
-
"semver": "7.
|
|
25
|
+
"nats": "^2.29.3",
|
|
26
|
+
"semver": "^7.7.4",
|
|
25
27
|
"ws": "8.18.0"
|
|
26
28
|
},
|
|
27
29
|
"publishConfig": {
|
|
28
30
|
"registry": "https://registry.npmjs.org/"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"eslint": "^
|
|
32
|
-
"
|
|
33
|
+
"@eslint/js": "^10.0.1",
|
|
34
|
+
"eslint": "^10.1.0",
|
|
35
|
+
"globals": "^17.4.0"
|
|
33
36
|
}
|
|
34
37
|
}
|
package/src/Codec.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { JSONCodec } from "nats";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Shared NATS JSON codec instance used to serialise and deserialise message payloads.
|
|
5
|
+
*
|
|
6
|
+
* @type {import('nats').Codec<any>}
|
|
7
|
+
*/
|
|
3
8
|
export const codec = JSONCodec();
|
|
4
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Serialises `data` to a NATS-compatible `Uint8Array` using the JSON codec.
|
|
12
|
+
*
|
|
13
|
+
* @param {any} data - Value to encode.
|
|
14
|
+
* @returns {Uint8Array}
|
|
15
|
+
*/
|
|
5
16
|
export function encode(data) {
|
|
6
17
|
return codec.encode(data);
|
|
7
18
|
}
|
|
8
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Deserialises a `Uint8Array` NATS payload back to a JavaScript value using the JSON codec.
|
|
22
|
+
*
|
|
23
|
+
* @param {Uint8Array|Buffer} data - Raw bytes to decode.
|
|
24
|
+
* @returns {any}
|
|
25
|
+
* @throws {Error} If the bytes cannot be decoded as JSON.
|
|
26
|
+
*/
|
|
9
27
|
export function decode(data) {
|
|
10
|
-
// check if data is json
|
|
11
|
-
if (Buffer.isBuffer(data) && data.readUInt8(0) === "{".charCodeAt(0)) {
|
|
12
|
-
return codec.decode(data);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
28
|
try {
|
|
16
29
|
return codec.decode(data);
|
|
17
|
-
} catch {
|
|
18
|
-
throw new Error(
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw new Error(`Codec.decode: ${e.message}`, { cause: e });
|
|
19
32
|
}
|
|
20
33
|
}
|