mq-bridge 0.3.9 → 0.4.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.
- package/README.md +47 -2
- package/index.d.ts +105 -0
- package/index.js +247 -0
- package/native.d.ts +79 -0
- package/native.js +57 -52
- package/package.json +11 -7
- package/plugin-packaging.mjs +46 -0
package/README.md
CHANGED
|
@@ -153,12 +153,57 @@ that ack each batch individually (NATS JetStream, AMQP, MQTT) accept any order.
|
|
|
153
153
|
> source position (Kafka `partition:offset`, NATS `stream_sequence`, AMQP delivery
|
|
154
154
|
> tag) and makes a natural primary key; source cursor fields are also available in
|
|
155
155
|
> `message.metadata` (`mqb.src.kafka_topic`/`mqb.src.kafka_offset`, `mqb.src.nats_subject`/`mqb.src.nats_stream_sequence`,
|
|
156
|
-
> `mqb.src.amqp_routing_key`/`mqb.src.amqp_delivery_tag`) when
|
|
157
|
-
> `
|
|
156
|
+
> `mqb.src.amqp_routing_key`/`mqb.src.amqp_delivery_tag`) when its Kafka, NATS, or
|
|
157
|
+
> AMQP source config sets `source_metadata: true` (off by default). Keep `batchSize × per-record cost` under
|
|
158
158
|
> the smallest broker ack deadline (JetStream `AckWait`, AMQP prefetch/timeout, MQTT
|
|
159
159
|
> inflight) or raise it in config. **Kafka has no per-message nack:** `nack` there
|
|
160
160
|
> leaves the offset unadvanced, so redelivery happens on the next run/rebalance.
|
|
161
161
|
|
|
162
|
+
## Custom endpoints and middleware
|
|
163
|
+
|
|
164
|
+
Register a JS object as an endpoint, and use its name in any route config —
|
|
165
|
+
useful when a system has a good Node SDK but no Rust one.
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
const mqb = require("mq-bridge");
|
|
169
|
+
|
|
170
|
+
mqb.registerEndpoint("pulsar", (routeName, config) => ({
|
|
171
|
+
async receiveBatch(maxMessages) {
|
|
172
|
+
// [] = nothing right now; throw mqb.EndOfStream when the source is done
|
|
173
|
+
return await pullFrom(config.url, config.topic, maxMessages);
|
|
174
|
+
},
|
|
175
|
+
async commit(dispositions) {}, // optional: one "ack"/"nack" per message
|
|
176
|
+
async close() {},
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
const route = mqb.Route.fromConfig({
|
|
180
|
+
input: { pulsar: { url: "pulsar://localhost:6650", topic: "orders" } },
|
|
181
|
+
output: { file: { path: "orders.jsonl" } },
|
|
182
|
+
}, "ingest");
|
|
183
|
+
route.start();
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Implement `sendBatch(messages)` instead of `receiveBatch` for an output. A
|
|
187
|
+
middleware works the same way via `registerMiddleware`, with `onReceive` /
|
|
188
|
+
`onSend` hooks that return one slot per input message (`null` drops it).
|
|
189
|
+
|
|
190
|
+
Because the endpoint runs in JavaScript, **keep the event loop free** while the
|
|
191
|
+
route is running — `route.join()` straight after `stop()` blocks the very
|
|
192
|
+
dispatch the endpoint needs. Yield first:
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
route.stop();
|
|
196
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
197
|
+
route.join();
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
A registered endpoint also keeps the process alive. Once the routes using it
|
|
201
|
+
have stopped, `unregisterEndpoint(name)` (or `unregisterMiddleware(name)`)
|
|
202
|
+
releases it so the process can exit on its own — unlike `process.exit()`, which
|
|
203
|
+
skips pending flushes and `close()` hooks.
|
|
204
|
+
|
|
205
|
+
**Full guide, including the Rust path:** [EXTENDING.md](../../docs/EXTENDING.md).
|
|
206
|
+
|
|
162
207
|
## Logging
|
|
163
208
|
|
|
164
209
|
By default the Rust core's internal `tracing` events go nowhere. Call
|
package/index.d.ts
CHANGED
|
@@ -151,4 +151,109 @@ export function initLogging(
|
|
|
151
151
|
level?: string | null,
|
|
152
152
|
): void;
|
|
153
153
|
|
|
154
|
+
/** Throw from {@link CustomEndpoint.receiveBatch} to end the route cleanly. */
|
|
155
|
+
export class EndOfStream extends Error {
|
|
156
|
+
constructor(message?: string);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** One message disposition reported to {@link CustomEndpoint.commit}. */
|
|
160
|
+
export type Disposition = "ack" | "nack";
|
|
161
|
+
|
|
162
|
+
/** What a {@link registerEndpoint} factory returns. */
|
|
163
|
+
export interface CustomEndpoint {
|
|
164
|
+
/**
|
|
165
|
+
* Read up to `maxMessages`. Return `null` or `[]` when nothing is available
|
|
166
|
+
* right now (the route backs off and retries; under `exit_on_empty` this is
|
|
167
|
+
* the drain signal), or throw {@link EndOfStream} when the source is done.
|
|
168
|
+
*/
|
|
169
|
+
receiveBatch?(
|
|
170
|
+
maxMessages: number,
|
|
171
|
+
):
|
|
172
|
+
| Promise<Iterable<Message | Buffer | Uint8Array | string | JsonValue> | null>
|
|
173
|
+
| Iterable<Message | Buffer | Uint8Array | string | JsonValue>
|
|
174
|
+
| null;
|
|
175
|
+
/** Called once per received batch, with one disposition per message. */
|
|
176
|
+
commit?(dispositions: Disposition[]): Promise<void> | void;
|
|
177
|
+
/** Publish a batch. Throw to fail it; set `err.retryable` to have it retried. */
|
|
178
|
+
sendBatch?(messages: Message[]): Promise<void> | void;
|
|
179
|
+
/** Called when the route releases the endpoint. */
|
|
180
|
+
close?(): Promise<void> | void;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Register a custom endpoint implemented in JavaScript under `name`, making it
|
|
185
|
+
* usable as an endpoint type in route configs — either as `{ pulsar: {...} }`
|
|
186
|
+
* or explicitly as `{ custom: { name: "pulsar", config: {...} } }`.
|
|
187
|
+
*
|
|
188
|
+
* `factory` is called once per route leg. The returned object must implement
|
|
189
|
+
* `receiveBatch` to be usable as an input and/or `sendBatch` to be usable as an
|
|
190
|
+
* output. Register before starting a route that names it; registering the same
|
|
191
|
+
* name twice throws and preserves the first factory.
|
|
192
|
+
*/
|
|
193
|
+
export function registerEndpoint(
|
|
194
|
+
name: string,
|
|
195
|
+
factory: (
|
|
196
|
+
routeName: string,
|
|
197
|
+
config: Record<string, JsonValue>,
|
|
198
|
+
) => CustomEndpoint | Promise<CustomEndpoint>,
|
|
199
|
+
): void;
|
|
200
|
+
|
|
201
|
+
/** Unregister a custom endpoint after all routes using it have stopped. */
|
|
202
|
+
export function unregisterEndpoint(name: string): boolean;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Load a native endpoint plugin and register the endpoint it provides.
|
|
206
|
+
*
|
|
207
|
+
* `path` is the compiled plugin library shipped by an endpoint package (for
|
|
208
|
+
* example `mq-bridge-pulsar`), which normally exposes its own `register()`
|
|
209
|
+
* helper that resolves the bundled file and calls this. Returns the registered
|
|
210
|
+
* endpoint name, usable as a route's endpoint type.
|
|
211
|
+
*
|
|
212
|
+
* Call once, before starting routes; loading the same file again is a no-op. A
|
|
213
|
+
* plugin is native code with the same privileges as the Node process.
|
|
214
|
+
*/
|
|
215
|
+
export function loadEndpointPlugin(path: string): string;
|
|
216
|
+
|
|
217
|
+
/** Resolves the native library in an mq-bridge plugin package directory. */
|
|
218
|
+
export function pluginLibraryPath(packageDirectory: string): string;
|
|
219
|
+
|
|
220
|
+
/** Resolves and loads the native library in an mq-bridge plugin package. */
|
|
221
|
+
export function loadPluginPackage(packageDirectory: string): string;
|
|
222
|
+
|
|
223
|
+
/** Standard exports for a thin JavaScript plugin package entry point. */
|
|
224
|
+
export function definePluginPackage(packageDirectory: string): {
|
|
225
|
+
ENDPOINT_NAME: string;
|
|
226
|
+
libraryPath(): string;
|
|
227
|
+
register(): string;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/** What a {@link registerMiddleware} factory returns. */
|
|
231
|
+
export interface CustomMiddleware {
|
|
232
|
+
/** Applies on an input endpoint, after the source produced the batch. */
|
|
233
|
+
onReceive?(messages: Message[]): Promise<(Message | null)[]> | (Message | null)[];
|
|
234
|
+
/** Applies on an output endpoint, before the sink receives the batch. */
|
|
235
|
+
onSend?(messages: Message[]): Promise<(Message | null)[]> | (Message | null)[];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Register a custom middleware implemented in JavaScript under `name`, usable in
|
|
240
|
+
* any endpoint's `middlewares` list as `{ custom: { name, config: {...} } }`.
|
|
241
|
+
*
|
|
242
|
+
* `factory` is called once per endpoint the middleware is attached to. A side
|
|
243
|
+
* the returned object does not implement passes through untouched. Both hooks
|
|
244
|
+
* must return one item per input message — a `Message` to keep it (possibly
|
|
245
|
+
* rewritten) or `null` to drop it — which is what keeps acknowledgements aligned
|
|
246
|
+
* with the source batch.
|
|
247
|
+
*/
|
|
248
|
+
export function registerMiddleware(
|
|
249
|
+
name: string,
|
|
250
|
+
factory: (
|
|
251
|
+
routeName: string,
|
|
252
|
+
config: Record<string, JsonValue>,
|
|
253
|
+
) => CustomMiddleware | Promise<CustomMiddleware>,
|
|
254
|
+
): void;
|
|
255
|
+
|
|
256
|
+
/** Unregister custom middleware after all routes using it have stopped. */
|
|
257
|
+
export function unregisterMiddleware(name: string): boolean;
|
|
258
|
+
|
|
154
259
|
export const version: string;
|
package/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
3
5
|
const native = require("./native.js");
|
|
4
6
|
|
|
5
7
|
class Message {
|
|
@@ -216,6 +218,185 @@ class Route {
|
|
|
216
218
|
}
|
|
217
219
|
}
|
|
218
220
|
|
|
221
|
+
/** Throw this from `receiveBatch` to tell the route the source is finished. */
|
|
222
|
+
class EndOfStream extends Error {
|
|
223
|
+
constructor(message = "end of stream") {
|
|
224
|
+
super(message);
|
|
225
|
+
this.name = "EndOfStream";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Register a custom endpoint implemented in JavaScript under `name`, making it
|
|
231
|
+
* usable as an endpoint type in route configs — either as `{ pulsar: {...} }`
|
|
232
|
+
* or explicitly as `{ custom: { name: "pulsar", config: {...} } }`.
|
|
233
|
+
*
|
|
234
|
+
* `factory(routeName, config)` is called once per route leg and returns an
|
|
235
|
+
* object implementing `receiveBatch(maxMessages)` to be usable as an input
|
|
236
|
+
* and/or `sendBatch(messages)` to be usable as an output, plus optional
|
|
237
|
+
* `commit(dispositions)` and `close()`. All of them may be async.
|
|
238
|
+
*
|
|
239
|
+
* `receiveBatch` returns an array of `Message`/Buffer/string values, or
|
|
240
|
+
* `null`/`[]` when nothing is available right now; throw `EndOfStream` to end
|
|
241
|
+
* the route. `commit` receives one `"ack"`/`"nack"` per message in the batch.
|
|
242
|
+
* Set `err.retryable = true` on a thrown error to have it retried.
|
|
243
|
+
*/
|
|
244
|
+
function registerEndpoint(name, factory) {
|
|
245
|
+
if (typeof factory !== "function") {
|
|
246
|
+
throw new TypeError("factory must be callable as factory(routeName, config)");
|
|
247
|
+
}
|
|
248
|
+
// The instance table lives here because JS objects cannot cross to Rust;
|
|
249
|
+
// native code refers to each instance by the id it allocated.
|
|
250
|
+
const instances = new Map();
|
|
251
|
+
|
|
252
|
+
native.registerEndpointDispatch(name, async (error, call) => {
|
|
253
|
+
if (error) {
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
return await dispatchEndpointCall(instances, factory, call);
|
|
258
|
+
} catch (err) {
|
|
259
|
+
if (err instanceof EndOfStream) {
|
|
260
|
+
return { endOfStream: true };
|
|
261
|
+
}
|
|
262
|
+
return errorReply(err);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Unregister a custom endpoint after all routes using it have stopped. */
|
|
268
|
+
function unregisterEndpoint(name) {
|
|
269
|
+
return native.unregisterEndpointDispatch(name);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Report a thrown error back to Rust. `retryable` stays `undefined` unless the
|
|
274
|
+
* host set it explicitly — collapsing it to `false` would classify every
|
|
275
|
+
* ordinary error as permanent and stop the route instead of reconnecting.
|
|
276
|
+
*/
|
|
277
|
+
function errorReply(err) {
|
|
278
|
+
return {
|
|
279
|
+
error: String((err && err.stack) || err),
|
|
280
|
+
retryable: typeof err?.retryable === "boolean" ? err.retryable : undefined,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Register a custom middleware implemented in JavaScript under `name`, usable in
|
|
286
|
+
* any endpoint's `middlewares` list as
|
|
287
|
+
* `{ custom: { name, config: {...} } }`.
|
|
288
|
+
*
|
|
289
|
+
* `factory(routeName, config)` is called once per endpoint the middleware is
|
|
290
|
+
* attached to and returns an object implementing `onReceive(messages)` (applies
|
|
291
|
+
* on an input endpoint) and/or `onSend(messages)` (applies on an output
|
|
292
|
+
* endpoint). A side the object does not implement passes through untouched.
|
|
293
|
+
*
|
|
294
|
+
* Both hooks take the batch and must return one item per input message: a
|
|
295
|
+
* `Message` (kept, possibly rewritten) or `null` to drop it. Keeping the length
|
|
296
|
+
* fixed is what lets acknowledgements stay aligned with the source batch.
|
|
297
|
+
*/
|
|
298
|
+
function registerMiddleware(name, factory) {
|
|
299
|
+
if (typeof factory !== "function") {
|
|
300
|
+
throw new TypeError("factory must be callable as factory(routeName, config)");
|
|
301
|
+
}
|
|
302
|
+
const instances = new Map();
|
|
303
|
+
|
|
304
|
+
native.registerMiddlewareDispatch(name, async (error, call) => {
|
|
305
|
+
if (error) {
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
return await dispatchEndpointCall(instances, factory, call);
|
|
310
|
+
} catch (err) {
|
|
311
|
+
return errorReply(err);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Unregister a custom middleware after all routes using it have stopped. */
|
|
317
|
+
function unregisterMiddleware(name) {
|
|
318
|
+
return native.unregisterMiddlewareDispatch(name);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function dispatchEndpointCall(instances, factory, call) {
|
|
322
|
+
if (call.op === "create") {
|
|
323
|
+
const instance = await factory(call.routeName, call.config ?? {});
|
|
324
|
+
instances.set(call.instance, instance);
|
|
325
|
+
return {
|
|
326
|
+
consumer: typeof instance?.receiveBatch === "function",
|
|
327
|
+
publisher: typeof instance?.sendBatch === "function",
|
|
328
|
+
onReceive: typeof instance?.onReceive === "function",
|
|
329
|
+
onSend: typeof instance?.onSend === "function",
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const instance = instances.get(call.instance);
|
|
334
|
+
if (!instance) {
|
|
335
|
+
// `close` is also sent when the native side drops the endpoint, which can
|
|
336
|
+
// race a close that already happened; that is not an error.
|
|
337
|
+
if (call.op === "close") {
|
|
338
|
+
return {};
|
|
339
|
+
}
|
|
340
|
+
throw new Error(`unknown endpoint instance ${call.instance}`);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
switch (call.op) {
|
|
344
|
+
case "receive": {
|
|
345
|
+
const batch = await instance.receiveBatch(call.maxMessages);
|
|
346
|
+
if (batch == null) {
|
|
347
|
+
return { messages: [] };
|
|
348
|
+
}
|
|
349
|
+
return { messages: Array.from(batch, toNativeEndpointMessage) };
|
|
350
|
+
}
|
|
351
|
+
case "commit": {
|
|
352
|
+
if (typeof instance.commit === "function") {
|
|
353
|
+
await instance.commit(call.dispositions ?? []);
|
|
354
|
+
}
|
|
355
|
+
return {};
|
|
356
|
+
}
|
|
357
|
+
case "send": {
|
|
358
|
+
const messages = (call.messages ?? []).map(Message._fromNative);
|
|
359
|
+
await instance.sendBatch(messages);
|
|
360
|
+
return {};
|
|
361
|
+
}
|
|
362
|
+
case "onReceive":
|
|
363
|
+
case "onSend": {
|
|
364
|
+
const hook = call.op === "onReceive" ? instance.onReceive : instance.onSend;
|
|
365
|
+
const messages = (call.messages ?? []).map(Message._fromNative);
|
|
366
|
+
const result = await hook.call(instance, messages);
|
|
367
|
+
return {
|
|
368
|
+
filtered: Array.from(result ?? [], (item) =>
|
|
369
|
+
item == null ? null : toNativeEndpointMessage(item),
|
|
370
|
+
),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
case "close": {
|
|
374
|
+
instances.delete(call.instance);
|
|
375
|
+
if (typeof instance.close === "function") {
|
|
376
|
+
await instance.close();
|
|
377
|
+
}
|
|
378
|
+
return {};
|
|
379
|
+
}
|
|
380
|
+
default:
|
|
381
|
+
throw new Error(`unknown endpoint op '${call.op}'`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** Accepts what an endpoint may yield: a Message, a Buffer, or a string. */
|
|
386
|
+
function toNativeEndpointMessage(item) {
|
|
387
|
+
if (item instanceof Message) {
|
|
388
|
+
return item._native;
|
|
389
|
+
}
|
|
390
|
+
if (typeof item === "string") {
|
|
391
|
+
return native.createMessage(Buffer.from(item), null, null);
|
|
392
|
+
}
|
|
393
|
+
if (Buffer.isBuffer(item) || item instanceof Uint8Array) {
|
|
394
|
+
return native.createMessage(Buffer.from(item), null, null);
|
|
395
|
+
}
|
|
396
|
+
// Anything else: treat as JSON, matching the Python binding.
|
|
397
|
+
return native.messageFromJson(item, null, null);
|
|
398
|
+
}
|
|
399
|
+
|
|
219
400
|
function configSchema() {
|
|
220
401
|
if (typeof native.configSchema !== "function") {
|
|
221
402
|
throw new Error(
|
|
@@ -229,12 +410,78 @@ function initLogging(callback, level = null) {
|
|
|
229
410
|
return native.initLogging(callback, level);
|
|
230
411
|
}
|
|
231
412
|
|
|
413
|
+
function loadEndpointPlugin(pluginPath) {
|
|
414
|
+
return native.loadEndpointPlugin(pluginPath);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function pluginPlatformTag(platform = process.platform, arch = process.arch) {
|
|
418
|
+
const normalizedArch = arch === "x86_64" ? "x64" : arch === "aarch64" ? "arm64" : arch;
|
|
419
|
+
const suffix = platform === "linux" ? "-gnu" : platform === "win32" ? "-msvc" : "";
|
|
420
|
+
return `${platform}-${normalizedArch}${suffix}`;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function readPluginManifest(packageDirectory) {
|
|
424
|
+
const root = path.resolve(packageDirectory);
|
|
425
|
+
const manifestPath = path.join(root, "mq-bridge-plugin.json");
|
|
426
|
+
if (!fs.existsSync(manifestPath)) {
|
|
427
|
+
throw new Error(`mq-bridge plugin manifest not found: ${manifestPath}`);
|
|
428
|
+
}
|
|
429
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
430
|
+
if (typeof manifest.name !== "string" || typeof manifest.library !== "string") {
|
|
431
|
+
throw new Error(`${manifestPath} must contain string fields 'name' and 'library'`);
|
|
432
|
+
}
|
|
433
|
+
return { root, manifest };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function pluginLibraryPath(packageDirectory) {
|
|
437
|
+
const { root, manifest } = readPluginManifest(packageDirectory);
|
|
438
|
+
const fileName = process.platform === "win32"
|
|
439
|
+
? `${manifest.library}.dll`
|
|
440
|
+
: process.platform === "darwin"
|
|
441
|
+
? `lib${manifest.library}.dylib`
|
|
442
|
+
: `lib${manifest.library}.so`;
|
|
443
|
+
const candidates = [
|
|
444
|
+
path.join(root, "prebuilds", pluginPlatformTag(), fileName),
|
|
445
|
+
path.join(root, fileName),
|
|
446
|
+
];
|
|
447
|
+
const library = candidates.find((candidate) => fs.existsSync(candidate));
|
|
448
|
+
if (library) {
|
|
449
|
+
return library;
|
|
450
|
+
}
|
|
451
|
+
throw new Error(
|
|
452
|
+
`no native library for ${pluginPlatformTag()} in mq-bridge plugin package ${root}; ` +
|
|
453
|
+
`looked in ${candidates.join(", ")}`,
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function loadPluginPackage(packageDirectory) {
|
|
458
|
+
return loadEndpointPlugin(pluginLibraryPath(packageDirectory));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function definePluginPackage(packageDirectory) {
|
|
462
|
+
const { manifest } = readPluginManifest(packageDirectory);
|
|
463
|
+
return {
|
|
464
|
+
ENDPOINT_NAME: manifest.name,
|
|
465
|
+
libraryPath: () => pluginLibraryPath(packageDirectory),
|
|
466
|
+
register: () => loadPluginPackage(packageDirectory),
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
232
470
|
module.exports = {
|
|
233
471
|
Message,
|
|
234
472
|
Publisher,
|
|
235
473
|
Consumer,
|
|
236
474
|
Route,
|
|
475
|
+
EndOfStream,
|
|
237
476
|
configSchema,
|
|
238
477
|
initLogging,
|
|
478
|
+
definePluginPackage,
|
|
479
|
+
loadEndpointPlugin,
|
|
480
|
+
loadPluginPackage,
|
|
481
|
+
pluginLibraryPath,
|
|
482
|
+
registerEndpoint,
|
|
483
|
+
registerMiddleware,
|
|
484
|
+
unregisterEndpoint,
|
|
485
|
+
unregisterMiddleware,
|
|
239
486
|
version: native.VERSION,
|
|
240
487
|
};
|
package/native.d.ts
CHANGED
|
@@ -171,6 +171,54 @@ export declare function configSchema(): JsonValue
|
|
|
171
171
|
|
|
172
172
|
export declare function createMessage(payload: Buffer, metadata?: Record<string, string> | undefined | null, id?: string | undefined | null): NativeMessage
|
|
173
173
|
|
|
174
|
+
/**
|
|
175
|
+
* One operation on a JS endpoint instance. A single dispatch callback per
|
|
176
|
+
* registered name carries all of them: JS objects are not `Send`, so the
|
|
177
|
+
* instance table lives on the JS side and Rust refers to instances by id.
|
|
178
|
+
*/
|
|
179
|
+
export interface EndpointCall {
|
|
180
|
+
/** `create` | `receive` | `commit` | `send` | `close`. */
|
|
181
|
+
op: string
|
|
182
|
+
/** Identifies the endpoint instance the op applies to. */
|
|
183
|
+
instance: number
|
|
184
|
+
routeName: string
|
|
185
|
+
/** The endpoint's config block. `create` only. */
|
|
186
|
+
config?: JsonValue
|
|
187
|
+
/** `receive` only. */
|
|
188
|
+
maxMessages?: number
|
|
189
|
+
/** `send` only. */
|
|
190
|
+
messages?: Array<NativeMessage>
|
|
191
|
+
/** `commit` only: one `"ack"`/`"nack"` per message in the batch. */
|
|
192
|
+
dispositions?: Array<string>
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* What the JS dispatcher reports back. Failures come back as a populated
|
|
197
|
+
* `error` rather than a rejected promise, so the retryable flag survives.
|
|
198
|
+
*/
|
|
199
|
+
export interface EndpointReply {
|
|
200
|
+
/** `receive` only. Absent or empty means "nothing right now". */
|
|
201
|
+
messages?: Array<NativeMessage>
|
|
202
|
+
/** `receive` only: the source is finished, so the route can stop. */
|
|
203
|
+
endOfStream?: boolean
|
|
204
|
+
/** `create` only: whether the instance implements `receiveBatch`. */
|
|
205
|
+
consumer?: boolean
|
|
206
|
+
/** `create` only: whether the instance implements `sendBatch`. */
|
|
207
|
+
publisher?: boolean
|
|
208
|
+
/** `create` only: whether the instance implements `onReceive`. */
|
|
209
|
+
onReceive?: boolean
|
|
210
|
+
/** `create` only: whether the instance implements `onSend`. */
|
|
211
|
+
onSend?: boolean
|
|
212
|
+
/** `onReceive`/`onSend` only: one slot per input message, `null` for dropped. */
|
|
213
|
+
filtered?: Array<NativeMessage | undefined | null>
|
|
214
|
+
error?: string
|
|
215
|
+
/**
|
|
216
|
+
* Whether `error` should be retried. When absent, consumer errors are retried
|
|
217
|
+
* as connection failures while publisher errors are non-retryable.
|
|
218
|
+
*/
|
|
219
|
+
retryable?: boolean
|
|
220
|
+
}
|
|
221
|
+
|
|
174
222
|
/**
|
|
175
223
|
* Route the library's internal `tracing` events into a JS callback so the host
|
|
176
224
|
* logger (console, pino, winston, …) owns output. Call once at startup. `level`
|
|
@@ -181,6 +229,19 @@ export declare function createMessage(payload: Buffer, metadata?: Record<string,
|
|
|
181
229
|
*/
|
|
182
230
|
export declare function initLogging(callback: (record: LogRecord) => void, level?: string | undefined | null): void
|
|
183
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Load a native endpoint plugin and register the endpoint it provides.
|
|
234
|
+
*
|
|
235
|
+
* `path` is the compiled plugin library shipped by an endpoint package (for
|
|
236
|
+
* example `mq-bridge-pulsar`); those packages expose a `register()` helper that
|
|
237
|
+
* resolves the bundled file and calls this. Returns the registered endpoint
|
|
238
|
+
* name, usable as a route's endpoint type.
|
|
239
|
+
*
|
|
240
|
+
* Call once, before starting routes. Loading the same file again is a no-op.
|
|
241
|
+
* A plugin is native code with the same privileges as the Node process.
|
|
242
|
+
*/
|
|
243
|
+
export declare function loadEndpointPlugin(path: string): string
|
|
244
|
+
|
|
184
245
|
/** One library log event, delivered to the `initLogging` callback. */
|
|
185
246
|
export interface LogRecord {
|
|
186
247
|
/** `error` / `warn` / `info` / `debug` / `trace`. */
|
|
@@ -209,4 +270,22 @@ export interface PollBatch {
|
|
|
209
270
|
token?: number
|
|
210
271
|
}
|
|
211
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Register a JS endpoint dispatcher under `name`. Called by the `registerEndpoint`
|
|
275
|
+
* wrapper in `index.js`, which owns the instance table — do not call directly.
|
|
276
|
+
*/
|
|
277
|
+
export declare function registerEndpointDispatch(name: string, dispatch: ((err: Error | null, arg: EndpointCall) => Promise<EndpointReply>)): void
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Register a JS middleware dispatcher under `name`. Called by the
|
|
281
|
+
* `registerMiddleware` wrapper in `index.js` — do not call directly.
|
|
282
|
+
*/
|
|
283
|
+
export declare function registerMiddlewareDispatch(name: string, dispatch: ((err: Error | null, arg: EndpointCall) => Promise<EndpointReply>)): void
|
|
284
|
+
|
|
285
|
+
/** Unregister a JS endpoint dispatcher after all routes using it have stopped. */
|
|
286
|
+
export declare function unregisterEndpointDispatch(name: string): boolean
|
|
287
|
+
|
|
288
|
+
/** Unregister a JS middleware dispatcher after all routes using it have stopped. */
|
|
289
|
+
export declare function unregisterMiddlewareDispatch(name: string): boolean
|
|
290
|
+
|
|
212
291
|
export const version: string
|
package/native.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('mq-bridge-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('mq-bridge-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '0.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
80
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('mq-bridge-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('mq-bridge-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '0.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
96
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('mq-bridge-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('mq-bridge-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '0.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
117
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('mq-bridge-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('mq-bridge-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '0.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
133
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('mq-bridge-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('mq-bridge-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '0.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
150
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('mq-bridge-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('mq-bridge-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '0.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
166
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('mq-bridge-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('mq-bridge-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '0.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
185
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('mq-bridge-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('mq-bridge-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '0.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
201
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('mq-bridge-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('mq-bridge-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '0.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
217
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('mq-bridge-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('mq-bridge-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '0.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
237
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('mq-bridge-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('mq-bridge-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '0.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
253
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('mq-bridge-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('mq-bridge-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '0.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
274
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('mq-bridge-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('mq-bridge-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '0.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
290
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('mq-bridge-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('mq-bridge-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '0.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
308
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('mq-bridge-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('mq-bridge-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '0.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
324
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('mq-bridge-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('mq-bridge-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '0.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
342
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('mq-bridge-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('mq-bridge-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '0.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
358
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('mq-bridge-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('mq-bridge-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '0.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
376
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('mq-bridge-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('mq-bridge-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '0.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
392
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('mq-bridge-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('mq-bridge-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '0.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
410
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('mq-bridge-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('mq-bridge-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '0.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
426
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('mq-bridge-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('mq-bridge-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '0.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
443
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('mq-bridge-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('mq-bridge-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '0.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
459
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('mq-bridge-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('mq-bridge-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '0.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
479
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('mq-bridge-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('mq-bridge-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '0.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
495
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('mq-bridge-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('mq-bridge-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '0.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
511
|
+
if (bindingPackageVersion !== '0.4.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
|
@@ -593,8 +593,13 @@ module.exports.Route = nativeBinding.Route
|
|
|
593
593
|
module.exports.configSchema = nativeBinding.configSchema
|
|
594
594
|
module.exports.createMessage = nativeBinding.createMessage
|
|
595
595
|
module.exports.initLogging = nativeBinding.initLogging
|
|
596
|
+
module.exports.loadEndpointPlugin = nativeBinding.loadEndpointPlugin
|
|
596
597
|
module.exports.messageFromJson = nativeBinding.messageFromJson
|
|
597
598
|
module.exports.messageJson = nativeBinding.messageJson
|
|
598
599
|
module.exports.messageText = nativeBinding.messageText
|
|
600
|
+
module.exports.registerEndpointDispatch = nativeBinding.registerEndpointDispatch
|
|
601
|
+
module.exports.registerMiddlewareDispatch = nativeBinding.registerMiddlewareDispatch
|
|
602
|
+
module.exports.unregisterEndpointDispatch = nativeBinding.unregisterEndpointDispatch
|
|
603
|
+
module.exports.unregisterMiddlewareDispatch = nativeBinding.unregisterMiddlewareDispatch
|
|
599
604
|
module.exports.version = nativeBinding.version
|
|
600
605
|
module.exports.VERSION = nativeBinding.VERSION
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mq-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Node.js bindings for mq-bridge",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,11 +10,15 @@
|
|
|
10
10
|
},
|
|
11
11
|
"main": "index.js",
|
|
12
12
|
"types": "index.d.ts",
|
|
13
|
+
"bin": {
|
|
14
|
+
"mq-bridge-package-plugin": "plugin-packaging.mjs"
|
|
15
|
+
},
|
|
13
16
|
"files": [
|
|
14
17
|
"index.js",
|
|
15
18
|
"index.d.ts",
|
|
16
19
|
"native.js",
|
|
17
|
-
"native.d.ts"
|
|
20
|
+
"native.d.ts",
|
|
21
|
+
"plugin-packaging.mjs"
|
|
18
22
|
],
|
|
19
23
|
"napi": {
|
|
20
24
|
"binaryName": "mq_bridge_node",
|
|
@@ -39,11 +43,11 @@
|
|
|
39
43
|
"artifacts": "napi artifacts"
|
|
40
44
|
},
|
|
41
45
|
"optionalDependencies": {
|
|
42
|
-
"mq-bridge-darwin-x64": "0.
|
|
43
|
-
"mq-bridge-darwin-arm64": "0.
|
|
44
|
-
"mq-bridge-linux-x64-gnu": "0.
|
|
45
|
-
"mq-bridge-linux-arm64-gnu": "0.
|
|
46
|
-
"mq-bridge-win32-x64-msvc": "0.
|
|
46
|
+
"mq-bridge-darwin-x64": "0.4.0",
|
|
47
|
+
"mq-bridge-darwin-arm64": "0.4.0",
|
|
48
|
+
"mq-bridge-linux-x64-gnu": "0.4.0",
|
|
49
|
+
"mq-bridge-linux-arm64-gnu": "0.4.0",
|
|
50
|
+
"mq-bridge-win32-x64-msvc": "0.4.0"
|
|
47
51
|
},
|
|
48
52
|
"devDependencies": {
|
|
49
53
|
"@napi-rs/cli": "^3.0.0"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
function option(name, fallback) {
|
|
8
|
+
const index = process.argv.indexOf(name);
|
|
9
|
+
return index === -1 ? fallback : process.argv[index + 1];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const root = path.resolve(option("--root", process.cwd()));
|
|
13
|
+
const packageDirectory = path.resolve(root, option("--package", "node"));
|
|
14
|
+
const manifestPath = path.join(packageDirectory, "mq-bridge-plugin.json");
|
|
15
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
16
|
+
if (typeof manifest.library !== "string") {
|
|
17
|
+
throw new Error(`${manifestPath} must contain a string field 'library'`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const suffix = process.platform === "linux" ? "-gnu" : process.platform === "win32" ? "-msvc" : "";
|
|
21
|
+
const target = `${process.platform}-${process.arch}${suffix}`;
|
|
22
|
+
const fileName = process.platform === "win32"
|
|
23
|
+
? `${manifest.library}.dll`
|
|
24
|
+
: process.platform === "darwin"
|
|
25
|
+
? `lib${manifest.library}.dylib`
|
|
26
|
+
: `lib${manifest.library}.so`;
|
|
27
|
+
|
|
28
|
+
execFileSync("cargo", ["build", "--release"], { cwd: root, stdio: "inherit" });
|
|
29
|
+
const library = path.join(root, "target", "release", fileName);
|
|
30
|
+
if (!fs.existsSync(library)) {
|
|
31
|
+
throw new Error(`cargo produced no plugin library at ${library}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const targetDirectory = path.join(packageDirectory, "prebuilds", target);
|
|
35
|
+
fs.mkdirSync(targetDirectory, { recursive: true });
|
|
36
|
+
fs.copyFileSync(library, path.join(targetDirectory, fileName));
|
|
37
|
+
console.log(`staged ${fileName} for ${target}`);
|
|
38
|
+
|
|
39
|
+
if (process.argv.includes("--pack")) {
|
|
40
|
+
const output = path.resolve(root, option("--out", "npm"));
|
|
41
|
+
fs.mkdirSync(output, { recursive: true });
|
|
42
|
+
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
43
|
+
execFileSync(npm, ["pack", packageDirectory, "--pack-destination", output], {
|
|
44
|
+
stdio: "inherit",
|
|
45
|
+
});
|
|
46
|
+
}
|