@requence/service 1.0.0-alpha.21 → 1.0.0-alpha.23
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/CHANGELOG.md +12 -0
- package/build/index.js +330 -85
- package/build/index.js.map +10 -9
- package/build/types/helpers/src/files/fileObject.d.ts +2 -2
- package/build/types/helpers/src/index.d.ts +1 -0
- package/build/types/helpers/src/index.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/mapSchema.d.ts +1 -1
- package/build/types/helpers/src/jsonschema/mapSchema.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/types.d.ts +2 -1
- package/build/types/helpers/src/jsonschema/types.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/update.d.ts +56 -0
- package/build/types/helpers/src/protocol/update.d.ts.map +1 -1
- package/build/types/helpers/src/utils/mapData.d.ts +1 -0
- package/build/types/helpers/src/utils/mapData.d.ts.map +1 -1
- package/build/types/helpers/src/utils/requenceCallback.d.ts +15 -0
- package/build/types/helpers/src/utils/requenceCallback.d.ts.map +1 -0
- package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts +7 -1
- package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts.map +1 -1
- package/build/types/service/src/createAmqpConnection.d.ts +2 -2
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -1
- package/build/types/service/src/helpers.d.ts +48 -17
- package/build/types/service/src/helpers.d.ts.map +1 -1
- package/build/types/service/src/index.d.ts +1 -0
- package/build/types/service/src/index.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/build/index.js
CHANGED
|
@@ -88,9 +88,15 @@ function mapData(data, visitors) {
|
|
|
88
88
|
if (typeof data2 === "symbol") {
|
|
89
89
|
return notUndefined(visitors.Symbol?.(data2, path), data2);
|
|
90
90
|
}
|
|
91
|
+
if (typeof data2 === "function") {
|
|
92
|
+
return notUndefined(visitors.Function?.(data2, path), data2);
|
|
93
|
+
}
|
|
91
94
|
if (isRecord(data2)) {
|
|
92
95
|
return resolve(visitors.Object?.(structuredClone(data2), path), (resolvedData) => {
|
|
93
96
|
const nextData = resolvedData ?? data2;
|
|
97
|
+
if (!isRecord(nextData)) {
|
|
98
|
+
return nextData;
|
|
99
|
+
}
|
|
94
100
|
const entries = Object.entries(nextData).map(([key, value]) => [
|
|
95
101
|
key,
|
|
96
102
|
traverseData(value, [...path, key])
|
|
@@ -119,6 +125,34 @@ mapData.abort = () => {
|
|
|
119
125
|
throw new AbortMapData;
|
|
120
126
|
};
|
|
121
127
|
|
|
128
|
+
// ../helpers/src/utils/requenceCallback.ts
|
|
129
|
+
import { z as z2 } from "zod/v4";
|
|
130
|
+
var callbackObjectSchema = z2.object({
|
|
131
|
+
sourceId: z2.string(),
|
|
132
|
+
outputName: z2.string().nullable(),
|
|
133
|
+
propertyPath: z2.array(z2.union([z2.string(), z2.int()])),
|
|
134
|
+
callbackId: z2.uuid(),
|
|
135
|
+
__REQUENCE_type: z2.literal("RequenceCallback")
|
|
136
|
+
});
|
|
137
|
+
function isCallbackObject(data) {
|
|
138
|
+
return callbackObjectSchema.safeParse(data).success;
|
|
139
|
+
}
|
|
140
|
+
function createCallback(callback) {
|
|
141
|
+
let resolvePromise;
|
|
142
|
+
const promise = new Promise((resolve2) => {
|
|
143
|
+
resolvePromise = resolve2;
|
|
144
|
+
});
|
|
145
|
+
const executor = (arg) => {
|
|
146
|
+
resolvePromise(arg);
|
|
147
|
+
callback?.(arg);
|
|
148
|
+
};
|
|
149
|
+
return Object.assign(executor, {
|
|
150
|
+
response() {
|
|
151
|
+
return promise;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
122
156
|
// ../helpers/src/files/mapOutput.ts
|
|
123
157
|
async function upload(uploadUrl, body, signal, contentType) {
|
|
124
158
|
const uploadResponse = await fetch(uploadUrl, {
|
|
@@ -346,11 +380,11 @@ class RequenceStream {
|
|
|
346
380
|
}
|
|
347
381
|
|
|
348
382
|
// ../helpers/src/files/streamObject.ts
|
|
349
|
-
import { z as
|
|
350
|
-
var streamObjectSchema =
|
|
351
|
-
mime:
|
|
352
|
-
url:
|
|
353
|
-
__REQUENCE_type:
|
|
383
|
+
import { z as z3 } from "zod/v4";
|
|
384
|
+
var streamObjectSchema = z3.object({
|
|
385
|
+
mime: z3.string(),
|
|
386
|
+
url: z3.string().url(),
|
|
387
|
+
__REQUENCE_type: z3.literal("RequenceStream")
|
|
354
388
|
});
|
|
355
389
|
function isStreamObject(data) {
|
|
356
390
|
return streamObjectSchema.safeParse(data).success;
|
|
@@ -363,12 +397,12 @@ function toStreamObject(streamInfo) {
|
|
|
363
397
|
}
|
|
364
398
|
|
|
365
399
|
// ../helpers/src/files/fileObject.ts
|
|
366
|
-
import { z as
|
|
367
|
-
var fileObjectSchema =
|
|
368
|
-
size:
|
|
369
|
-
mime:
|
|
370
|
-
url:
|
|
371
|
-
__REQUENCE_type:
|
|
400
|
+
import { z as z4 } from "zod/v4";
|
|
401
|
+
var fileObjectSchema = z4.object({
|
|
402
|
+
size: z4.int().positive(),
|
|
403
|
+
mime: z4.string(),
|
|
404
|
+
url: z4.url(),
|
|
405
|
+
__REQUENCE_type: z4.literal("RequenceFile")
|
|
372
406
|
});
|
|
373
407
|
function toFileObject(fileInfo) {
|
|
374
408
|
return {
|
|
@@ -381,7 +415,7 @@ function isFileObject(data) {
|
|
|
381
415
|
}
|
|
382
416
|
|
|
383
417
|
// ../helpers/src/utils/resolveRequenceTypes.ts
|
|
384
|
-
function resolveRequenceTypes(data) {
|
|
418
|
+
function resolveRequenceTypes(data, onCallback) {
|
|
385
419
|
return mapData(data, {
|
|
386
420
|
Object(obj) {
|
|
387
421
|
if (isFileObject(obj)) {
|
|
@@ -390,18 +424,23 @@ function resolveRequenceTypes(data) {
|
|
|
390
424
|
if (isStreamObject(obj)) {
|
|
391
425
|
return RequenceStream.fromStreamObject(obj);
|
|
392
426
|
}
|
|
427
|
+
if (isCallbackObject(obj)) {
|
|
428
|
+
return (arg) => {
|
|
429
|
+
onCallback({ ...obj, arg });
|
|
430
|
+
};
|
|
431
|
+
}
|
|
393
432
|
}
|
|
394
433
|
});
|
|
395
434
|
}
|
|
396
435
|
|
|
397
436
|
// src/index.ts
|
|
398
|
-
import { z as
|
|
437
|
+
import { z as z6 } from "zod/v4";
|
|
399
438
|
|
|
400
439
|
// src/createAmqpConnection.ts
|
|
401
440
|
import {
|
|
402
441
|
connect
|
|
403
442
|
} from "amqp-connection-manager";
|
|
404
|
-
import { z as
|
|
443
|
+
import { z as z5 } from "zod/v4";
|
|
405
444
|
|
|
406
445
|
// src/helpers.ts
|
|
407
446
|
class RetryError extends Error {
|
|
@@ -421,54 +460,131 @@ var OUTPUT_VALUE = Symbol("output_value");
|
|
|
421
460
|
function isOutputValue(value) {
|
|
422
461
|
return value !== null && typeof value === "object" && OUTPUT_VALUE in value;
|
|
423
462
|
}
|
|
424
|
-
|
|
425
|
-
|
|
463
|
+
function processData(params) {
|
|
464
|
+
return mapOutput({
|
|
465
|
+
value: mapData(params.data, {
|
|
466
|
+
Function(data, path) {
|
|
467
|
+
return {
|
|
468
|
+
...params.onCallback(data),
|
|
469
|
+
outputName: params.outputName,
|
|
470
|
+
propertyPath: path,
|
|
471
|
+
__REQUENCE_type: "RequenceCallback"
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
}),
|
|
475
|
+
options: params.options,
|
|
476
|
+
onDone: params.onDone
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
async function unwrapResult(params) {
|
|
480
|
+
if (isOutputValue(params.result)) {
|
|
426
481
|
return {
|
|
427
|
-
value: await
|
|
428
|
-
|
|
482
|
+
value: await processData({
|
|
483
|
+
outputName: params.result[OUTPUT_VALUE],
|
|
484
|
+
data: params.result.value,
|
|
485
|
+
options: params.options,
|
|
486
|
+
onDone: params.onDone,
|
|
487
|
+
onCallback: params.onCallback
|
|
488
|
+
}),
|
|
489
|
+
outputName: params.result[OUTPUT_VALUE]
|
|
429
490
|
};
|
|
430
491
|
}
|
|
431
492
|
return {
|
|
432
|
-
value: await
|
|
493
|
+
value: await processData({
|
|
494
|
+
outputName: null,
|
|
495
|
+
data: params.result,
|
|
496
|
+
options: params.options,
|
|
497
|
+
onDone: params.onDone,
|
|
498
|
+
onCallback: params.onCallback
|
|
499
|
+
}),
|
|
433
500
|
outputName: null
|
|
434
501
|
};
|
|
435
502
|
}
|
|
503
|
+
function isAsyncIterable(iterable) {
|
|
504
|
+
return typeof iterable[Symbol.asyncIterator] === "function";
|
|
505
|
+
}
|
|
436
506
|
function createContextHelper(options) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
507
|
+
const terminatePromise = createRemotePromise();
|
|
508
|
+
return [
|
|
509
|
+
{
|
|
510
|
+
taskId: options.taskId,
|
|
511
|
+
input: resolveRequenceTypes(options.input, options.onCallback),
|
|
512
|
+
configuration: resolveRequenceTypes(options.configuration, () => {
|
|
513
|
+
throw new Error("configuration may not have callbacks");
|
|
514
|
+
}),
|
|
515
|
+
toOutput(name, value) {
|
|
516
|
+
return {
|
|
517
|
+
[OUTPUT_VALUE]: name,
|
|
518
|
+
value
|
|
519
|
+
};
|
|
520
|
+
},
|
|
521
|
+
defer: options.onDefer,
|
|
522
|
+
debug: {
|
|
523
|
+
log(...data) {
|
|
524
|
+
options.onLog("log", data);
|
|
525
|
+
},
|
|
526
|
+
info(...data) {
|
|
527
|
+
options.onLog("info", data);
|
|
528
|
+
},
|
|
529
|
+
warn(...data) {
|
|
530
|
+
options.onLog("warn", data);
|
|
531
|
+
},
|
|
532
|
+
error(...data) {
|
|
533
|
+
options.onLog("error", data);
|
|
534
|
+
}
|
|
451
535
|
},
|
|
452
|
-
|
|
453
|
-
|
|
536
|
+
retry(delay) {
|
|
537
|
+
throw new RetryError(delay);
|
|
454
538
|
},
|
|
455
|
-
|
|
456
|
-
|
|
539
|
+
abort(reason) {
|
|
540
|
+
throw new AbortError(reason);
|
|
457
541
|
},
|
|
458
|
-
|
|
459
|
-
|
|
542
|
+
skip() {
|
|
543
|
+
throw new SkipError;
|
|
544
|
+
},
|
|
545
|
+
terminated: terminatePromise.promise,
|
|
546
|
+
wrapIterable: function(iterable) {
|
|
547
|
+
if (isAsyncIterable(iterable)) {
|
|
548
|
+
return {
|
|
549
|
+
[Symbol.asyncIterator]() {
|
|
550
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
551
|
+
return {
|
|
552
|
+
async next() {
|
|
553
|
+
const result = await Promise.race([
|
|
554
|
+
terminatePromise.promise,
|
|
555
|
+
iterator.next()
|
|
556
|
+
]);
|
|
557
|
+
if (typeof result === "string") {
|
|
558
|
+
return { done: true, value: undefined };
|
|
559
|
+
}
|
|
560
|
+
return result;
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
return {
|
|
567
|
+
[Symbol.iterator]() {
|
|
568
|
+
const iterator = iterable[Symbol.iterator]();
|
|
569
|
+
let terminated = false;
|
|
570
|
+
terminatePromise.then(() => {
|
|
571
|
+
terminated = true;
|
|
572
|
+
});
|
|
573
|
+
return {
|
|
574
|
+
next() {
|
|
575
|
+
if (terminated) {
|
|
576
|
+
return { done: true, value: undefined };
|
|
577
|
+
}
|
|
578
|
+
const result = iterator.next();
|
|
579
|
+
return result;
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
};
|
|
460
584
|
}
|
|
461
585
|
},
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
},
|
|
465
|
-
abort(reason) {
|
|
466
|
-
throw new AbortError(reason);
|
|
467
|
-
},
|
|
468
|
-
skip() {
|
|
469
|
-
throw new SkipError;
|
|
470
|
-
}
|
|
471
|
-
};
|
|
586
|
+
terminatePromise
|
|
587
|
+
];
|
|
472
588
|
}
|
|
473
589
|
|
|
474
590
|
// src/mapInput.ts
|
|
@@ -486,33 +602,50 @@ function mapInput(data) {
|
|
|
486
602
|
}
|
|
487
603
|
|
|
488
604
|
// src/createAmqpConnection.ts
|
|
489
|
-
var messageKeySchema =
|
|
605
|
+
var messageKeySchema = z5.string().transform((str) => deobfuscate(str)).pipe(z5.tuple([z5.uuid(), z5.uuid()]).rest(z5.string())).transform((arr) => ({
|
|
490
606
|
taskId: arr[0],
|
|
491
607
|
messageId: arr[1],
|
|
492
608
|
uploadUrl: arr[2] || undefined,
|
|
493
609
|
streamUrl: arr[3] || undefined
|
|
494
610
|
}));
|
|
495
|
-
var headerSchema =
|
|
496
|
-
properties:
|
|
497
|
-
correlationId:
|
|
498
|
-
headers:
|
|
499
|
-
|
|
500
|
-
taskId: z4.uuid()
|
|
611
|
+
var headerSchema = z5.object({
|
|
612
|
+
properties: z5.object({
|
|
613
|
+
correlationId: z5.uuid(),
|
|
614
|
+
headers: z5.object({
|
|
615
|
+
taskId: z5.uuid()
|
|
501
616
|
})
|
|
502
617
|
})
|
|
503
618
|
}).transform((msg) => ({
|
|
504
|
-
version: msg.properties.headers.version,
|
|
505
619
|
messageId: msg.properties.correlationId,
|
|
506
620
|
taskId: msg.properties.headers.taskId
|
|
507
621
|
}));
|
|
508
|
-
var payloadSchema =
|
|
509
|
-
input:
|
|
510
|
-
configuration:
|
|
511
|
-
options:
|
|
512
|
-
uploadUrl:
|
|
513
|
-
streamUrl:
|
|
622
|
+
var payloadSchema = z5.object({ content: z5.instanceof(Buffer) }).transform((msg) => JSON.parse(msg.content.toString())).pipe(z5.object({
|
|
623
|
+
input: z5.unknown(),
|
|
624
|
+
configuration: z5.unknown(),
|
|
625
|
+
options: z5.object({
|
|
626
|
+
uploadUrl: z5.url().optional(),
|
|
627
|
+
streamUrl: z5.url().optional()
|
|
514
628
|
})
|
|
515
629
|
}));
|
|
630
|
+
var backchannelMessageSchema = z5.object({
|
|
631
|
+
content: z5.instanceof(Buffer).transform((content) => JSON.parse(content.toString())).pipe(z5.discriminatedUnion("type", [
|
|
632
|
+
z5.object({
|
|
633
|
+
type: z5.literal("stop")
|
|
634
|
+
}),
|
|
635
|
+
z5.object({
|
|
636
|
+
type: z5.literal("callback"),
|
|
637
|
+
callbackId: z5.uuid(),
|
|
638
|
+
arg: z5.any()
|
|
639
|
+
})
|
|
640
|
+
])),
|
|
641
|
+
properties: z5.object({
|
|
642
|
+
correlationId: z5.string()
|
|
643
|
+
})
|
|
644
|
+
}).transform((message) => ({
|
|
645
|
+
payload: message.content,
|
|
646
|
+
messageId: message.properties.correlationId
|
|
647
|
+
}));
|
|
648
|
+
var abortSymbol = Symbol();
|
|
516
649
|
function isMessageHandlerGenerator(handler) {
|
|
517
650
|
return handler.constructor.name === "GeneratorFunction" || handler.constructor.name === "AsyncGeneratorFunction";
|
|
518
651
|
}
|
|
@@ -548,11 +681,17 @@ function createConnection({
|
|
|
548
681
|
connection.addListener("connect", handleConnect);
|
|
549
682
|
connection.addListener("connectFailed", handleConnectFailed);
|
|
550
683
|
});
|
|
684
|
+
const connectionId = crypto.randomUUID();
|
|
685
|
+
const backchannelQueue = `${queue}-backchannel-${connectionId}`;
|
|
551
686
|
const channel = connection.createChannel({
|
|
552
687
|
async setup(channel2) {
|
|
553
688
|
await channel2.checkExchange(exchange);
|
|
554
689
|
await channel2.checkExchange(`${exchange}-retry`);
|
|
555
690
|
await channel2.checkQueue(queue);
|
|
691
|
+
await channel2.assertQueue(backchannelQueue, {
|
|
692
|
+
exclusive: true
|
|
693
|
+
});
|
|
694
|
+
await channel2.bindQueue(backchannelQueue, "service", backchannelQueue);
|
|
556
695
|
await channel2.prefetch(prefetch);
|
|
557
696
|
}
|
|
558
697
|
});
|
|
@@ -570,13 +709,36 @@ function createConnection({
|
|
|
570
709
|
priority,
|
|
571
710
|
headers: {
|
|
572
711
|
outputName: outputName ?? null,
|
|
712
|
+
connectionId,
|
|
573
713
|
...headers
|
|
574
714
|
}
|
|
575
715
|
});
|
|
576
716
|
};
|
|
717
|
+
const generatorTerminators = new Map;
|
|
718
|
+
const callbacks = new Map;
|
|
719
|
+
channel.consume(backchannelQueue, async (message) => {
|
|
720
|
+
const result = backchannelMessageSchema.safeParse(message);
|
|
721
|
+
if (!result.success) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
const backchannelMessage = result.data;
|
|
725
|
+
switch (backchannelMessage.payload.type) {
|
|
726
|
+
case "stop": {
|
|
727
|
+
generatorTerminators.get(backchannelMessage.messageId)?.("task stopped");
|
|
728
|
+
break;
|
|
729
|
+
}
|
|
730
|
+
case "callback": {
|
|
731
|
+
callbacks.get(backchannelMessage.payload.callbackId)?.(backchannelMessage.payload.arg);
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}, {
|
|
736
|
+
noAck: true
|
|
737
|
+
});
|
|
577
738
|
channel.consume(queue, async (message) => {
|
|
578
739
|
let publishIndex = 0;
|
|
579
740
|
const donePromises = [];
|
|
741
|
+
const registeredCallbackIds = new Set;
|
|
580
742
|
let removeActiveMessage = () => {};
|
|
581
743
|
let acked = false;
|
|
582
744
|
const ack = () => {
|
|
@@ -585,14 +747,14 @@ function createConnection({
|
|
|
585
747
|
channel.ack(message);
|
|
586
748
|
}
|
|
587
749
|
};
|
|
750
|
+
const { messageId, taskId } = headerSchema.parse(message);
|
|
588
751
|
try {
|
|
589
752
|
let deferred = false;
|
|
590
753
|
let deferredReason = null;
|
|
591
|
-
const { messageId, taskId } = headerSchema.parse(message);
|
|
592
754
|
activeMessages.add(messageId);
|
|
593
755
|
removeActiveMessage = () => activeMessages.delete(messageId);
|
|
594
756
|
const payload = payloadSchema.parse(message);
|
|
595
|
-
const extendedContext = createContextHelper({
|
|
757
|
+
const [extendedContext, terminatePromise] = createContextHelper({
|
|
596
758
|
taskId,
|
|
597
759
|
input: mapInput(payload.input),
|
|
598
760
|
configuration: mapInput(payload.configuration),
|
|
@@ -612,12 +774,45 @@ function createConnection({
|
|
|
612
774
|
deferredReason = reason || null;
|
|
613
775
|
ack();
|
|
614
776
|
return obfuscate(taskId, messageId, payload.options.uploadUrl ?? "", payload.options.streamUrl ?? "");
|
|
777
|
+
},
|
|
778
|
+
onCallback(params) {
|
|
779
|
+
publish({
|
|
780
|
+
index: 0,
|
|
781
|
+
taskId,
|
|
782
|
+
messageId,
|
|
783
|
+
data: params.arg,
|
|
784
|
+
outputName: params.outputName,
|
|
785
|
+
connectionId: params.sourceId,
|
|
786
|
+
callbackId: params.callbackId,
|
|
787
|
+
propertyPath: params.propertyPath
|
|
788
|
+
});
|
|
615
789
|
}
|
|
616
790
|
});
|
|
791
|
+
publish({
|
|
792
|
+
index: publishIndex++,
|
|
793
|
+
messageId,
|
|
794
|
+
taskId,
|
|
795
|
+
priority: message.properties.priority,
|
|
796
|
+
begin: true
|
|
797
|
+
});
|
|
617
798
|
if (isMessageHandlerGenerator(messageHandler)) {
|
|
618
799
|
const generator = messageHandler(extendedContext);
|
|
800
|
+
const terminationPromise = createRemotePromise();
|
|
801
|
+
generatorTerminators.set(messageId, (reason) => {
|
|
802
|
+
generator.return();
|
|
803
|
+
terminationPromise.resolve(abortSymbol);
|
|
804
|
+
terminatePromise.resolve(reason);
|
|
805
|
+
ack();
|
|
806
|
+
});
|
|
619
807
|
while (true) {
|
|
620
|
-
const
|
|
808
|
+
const next = await Promise.race([
|
|
809
|
+
terminationPromise,
|
|
810
|
+
generator.next()
|
|
811
|
+
]);
|
|
812
|
+
if (next === abortSymbol) {
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
const { value: result, done } = next;
|
|
621
816
|
ack();
|
|
622
817
|
if (deferred) {
|
|
623
818
|
deferred = false;
|
|
@@ -625,7 +820,20 @@ function createConnection({
|
|
|
625
820
|
}
|
|
626
821
|
const donePromise = createRemotePromise();
|
|
627
822
|
donePromises.push(donePromise);
|
|
628
|
-
const { value, outputName } = await unwrapResult(
|
|
823
|
+
const { value, outputName } = await unwrapResult({
|
|
824
|
+
result,
|
|
825
|
+
options: payload.options,
|
|
826
|
+
onDone: donePromise.resolve,
|
|
827
|
+
onCallback: (callback) => {
|
|
828
|
+
const callbackId = crypto.randomUUID();
|
|
829
|
+
registeredCallbackIds.add(callbackId);
|
|
830
|
+
callbacks.set(callbackId, callback);
|
|
831
|
+
return {
|
|
832
|
+
sourceId: connectionId,
|
|
833
|
+
callbackId
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
});
|
|
629
837
|
if (!done || typeof value !== "undefined") {
|
|
630
838
|
publish({
|
|
631
839
|
index: publishIndex++,
|
|
@@ -645,7 +853,14 @@ function createConnection({
|
|
|
645
853
|
ack();
|
|
646
854
|
const donePromise = createRemotePromise();
|
|
647
855
|
donePromises.push(donePromise);
|
|
648
|
-
const { value, outputName } = await unwrapResult(
|
|
856
|
+
const { value, outputName } = await unwrapResult({
|
|
857
|
+
result,
|
|
858
|
+
options: payload.options,
|
|
859
|
+
onDone: donePromise.resolve,
|
|
860
|
+
onCallback: () => {
|
|
861
|
+
throw new Error("callbacks can only be used in generator functions");
|
|
862
|
+
}
|
|
863
|
+
});
|
|
649
864
|
if (deferred && value) {
|
|
650
865
|
console.warn("returning a value in a deferred message resets the deferred status");
|
|
651
866
|
deferred = false;
|
|
@@ -695,9 +910,10 @@ function createConnection({
|
|
|
695
910
|
...message.properties,
|
|
696
911
|
expiration: error.delay || 1000
|
|
697
912
|
};
|
|
698
|
-
channel.publish(`${exchange}-retry`,
|
|
913
|
+
channel.publish(`${exchange}-retry`, version, message.content, properties);
|
|
699
914
|
ack();
|
|
700
915
|
}
|
|
916
|
+
return;
|
|
701
917
|
}
|
|
702
918
|
if (error instanceof AbortError && error.message.length > 0) {
|
|
703
919
|
if (assertNack("data already send, cannot abort")) {
|
|
@@ -706,6 +922,7 @@ function createConnection({
|
|
|
706
922
|
contentType: "text/plain",
|
|
707
923
|
headers: {
|
|
708
924
|
...message.properties.headers,
|
|
925
|
+
index: publishIndex++,
|
|
709
926
|
abort: true
|
|
710
927
|
}
|
|
711
928
|
});
|
|
@@ -723,7 +940,9 @@ function createConnection({
|
|
|
723
940
|
...message.properties,
|
|
724
941
|
headers: {
|
|
725
942
|
...message.properties.headers,
|
|
943
|
+
version,
|
|
726
944
|
exception: true,
|
|
945
|
+
index: publishIndex++,
|
|
727
946
|
"error-message": error.message || "error in service handler"
|
|
728
947
|
}
|
|
729
948
|
});
|
|
@@ -735,6 +954,8 @@ function createConnection({
|
|
|
735
954
|
channel.nack(message, false, false);
|
|
736
955
|
}
|
|
737
956
|
} finally {
|
|
957
|
+
generatorTerminators.delete(messageId);
|
|
958
|
+
registeredCallbackIds.forEach((id) => callbacks.delete(id));
|
|
738
959
|
removeActiveMessage();
|
|
739
960
|
}
|
|
740
961
|
});
|
|
@@ -752,6 +973,7 @@ function createConnection({
|
|
|
752
973
|
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
753
974
|
}
|
|
754
975
|
};
|
|
976
|
+
const registeredCallbackIds = new Set;
|
|
755
977
|
const donePromises = [];
|
|
756
978
|
await actor({
|
|
757
979
|
async sendToOutput(outputName, data) {
|
|
@@ -762,10 +984,20 @@ function createConnection({
|
|
|
762
984
|
index: publishIndex++,
|
|
763
985
|
messageId,
|
|
764
986
|
taskId,
|
|
765
|
-
data: await
|
|
766
|
-
|
|
987
|
+
data: await processData({
|
|
988
|
+
outputName,
|
|
989
|
+
data,
|
|
767
990
|
options,
|
|
768
|
-
onDone: donePromise.resolve
|
|
991
|
+
onDone: donePromise.resolve,
|
|
992
|
+
onCallback: (callback) => {
|
|
993
|
+
const callbackId = crypto.randomUUID();
|
|
994
|
+
registeredCallbackIds.add(callbackId);
|
|
995
|
+
callbacks.set(callbackId, callback);
|
|
996
|
+
return {
|
|
997
|
+
sourceId: connectionId,
|
|
998
|
+
callbackId
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
769
1001
|
}),
|
|
770
1002
|
outputName
|
|
771
1003
|
});
|
|
@@ -778,10 +1010,20 @@ function createConnection({
|
|
|
778
1010
|
index: publishIndex++,
|
|
779
1011
|
messageId,
|
|
780
1012
|
taskId,
|
|
781
|
-
data: await
|
|
782
|
-
|
|
1013
|
+
data: await processData({
|
|
1014
|
+
outputName: null,
|
|
1015
|
+
data,
|
|
783
1016
|
options,
|
|
784
|
-
onDone: donePromise.resolve
|
|
1017
|
+
onDone: donePromise.resolve,
|
|
1018
|
+
onCallback: (callback) => {
|
|
1019
|
+
const callbackId = crypto.randomUUID();
|
|
1020
|
+
registeredCallbackIds.add(callbackId);
|
|
1021
|
+
callbacks.set(callbackId, callback);
|
|
1022
|
+
return {
|
|
1023
|
+
sourceId: connectionId,
|
|
1024
|
+
callbackId
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
785
1027
|
})
|
|
786
1028
|
});
|
|
787
1029
|
},
|
|
@@ -795,6 +1037,7 @@ function createConnection({
|
|
|
795
1037
|
contentType: "text/plain",
|
|
796
1038
|
headers: {
|
|
797
1039
|
taskId,
|
|
1040
|
+
index: publishIndex++,
|
|
798
1041
|
abort: true
|
|
799
1042
|
}
|
|
800
1043
|
});
|
|
@@ -802,6 +1045,7 @@ function createConnection({
|
|
|
802
1045
|
});
|
|
803
1046
|
setImmediate(async () => {
|
|
804
1047
|
await Promise.allSettled(donePromises);
|
|
1048
|
+
registeredCallbackIds.forEach((id) => callbacks.delete(id));
|
|
805
1049
|
publish({
|
|
806
1050
|
index: publishIndex++,
|
|
807
1051
|
messageId,
|
|
@@ -815,16 +1059,16 @@ function createConnection({
|
|
|
815
1059
|
}
|
|
816
1060
|
|
|
817
1061
|
// src/index.ts
|
|
818
|
-
var connectionOptionsSchema =
|
|
819
|
-
url:
|
|
820
|
-
|
|
821
|
-
|
|
1062
|
+
var connectionOptionsSchema = z6.object({
|
|
1063
|
+
url: z6.union([
|
|
1064
|
+
z6.string().regex(/^amqps?:\/\/(.+):(.+)@(.+)$/).transform((str) => new URL(str)),
|
|
1065
|
+
z6.instanceof(URL).refine((url) => url.protocol.match(/^amqps?:/), "Wrong protocol")
|
|
822
1066
|
]),
|
|
823
|
-
version:
|
|
824
|
-
silent:
|
|
825
|
-
prefetch:
|
|
826
|
-
connectionTimeout:
|
|
827
|
-
connectionOptions:
|
|
1067
|
+
version: z6.string(),
|
|
1068
|
+
silent: z6.boolean().optional(),
|
|
1069
|
+
prefetch: z6.number().int().optional(),
|
|
1070
|
+
connectionTimeout: z6.number().positive().default(3000),
|
|
1071
|
+
connectionOptions: z6.any()
|
|
828
1072
|
});
|
|
829
1073
|
function createService(optionsOrVersion, optionalMessageHandler) {
|
|
830
1074
|
let options;
|
|
@@ -858,9 +1102,10 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
858
1102
|
}
|
|
859
1103
|
export {
|
|
860
1104
|
createService,
|
|
1105
|
+
createCallback,
|
|
861
1106
|
RequenceStream,
|
|
862
1107
|
RequenceFile
|
|
863
1108
|
};
|
|
864
1109
|
|
|
865
|
-
//# debugId=
|
|
1110
|
+
//# debugId=DB60EAB4653D0F1964756E2164756E21
|
|
866
1111
|
//# sourceMappingURL=index.js.map
|