@aom-js/transfer 0.0.3 → 0.0.5
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/dist/cjs/defines/decorators.d.ts +2 -0
- package/dist/cjs/defines/decorators.d.ts.map +1 -1
- package/dist/cjs/defines/decorators.js +30 -122
- package/dist/cjs/defines/decorators.js.map +1 -1
- package/dist/cjs/defines/index.d.ts +1 -0
- package/dist/cjs/defines/index.d.ts.map +1 -1
- package/dist/cjs/defines/index.js +1 -0
- package/dist/cjs/defines/index.js.map +1 -1
- package/dist/cjs/defines/main.d.ts +18 -3
- package/dist/cjs/defines/main.d.ts.map +1 -1
- package/dist/cjs/defines/main.js +40 -35
- package/dist/cjs/defines/main.js.map +1 -1
- package/dist/cjs/defines/registry.d.ts +11 -0
- package/dist/cjs/defines/registry.d.ts.map +1 -0
- package/dist/cjs/defines/registry.js +34 -0
- package/dist/cjs/defines/registry.js.map +1 -0
- package/dist/cjs/defines/rx-transfer.d.ts +11 -0
- package/dist/cjs/defines/rx-transfer.d.ts.map +1 -0
- package/dist/cjs/defines/rx-transfer.js +163 -0
- package/dist/cjs/defines/rx-transfer.js.map +1 -0
- package/dist/cjs/defines/types.d.ts +25 -4
- package/dist/cjs/defines/types.d.ts.map +1 -1
- package/dist/mjs/defines/decorators.js +28 -86
- package/dist/mjs/defines/decorators.js.map +1 -1
- package/dist/mjs/defines/index.js +1 -0
- package/dist/mjs/defines/index.js.map +1 -1
- package/dist/mjs/defines/main.js +40 -35
- package/dist/mjs/defines/main.js.map +1 -1
- package/dist/mjs/defines/registry.js +28 -0
- package/dist/mjs/defines/registry.js.map +1 -0
- package/dist/mjs/defines/rx-transfer.js +123 -0
- package/dist/mjs/defines/rx-transfer.js.map +1 -0
- package/dist/types/defines/decorators.d.ts +2 -0
- package/dist/types/defines/index.d.ts +1 -0
- package/dist/types/defines/main.d.ts +18 -3
- package/dist/types/defines/registry.d.ts +10 -0
- package/dist/types/defines/rx-transfer.d.ts +10 -0
- package/dist/types/defines/types.d.ts +25 -4
- package/package.json +2 -2
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.RxTransfer = void 0;
|
|
40
|
+
const rxjs = __importStar(require("rxjs"));
|
|
41
|
+
const rxjsOperators = __importStar(require("rxjs/operators"));
|
|
42
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
43
|
+
rxjs.config.onUnhandledError = (err) => console.error("rxjs unhandled error", err);
|
|
44
|
+
class RxTransfer {
|
|
45
|
+
constructor(transfer) {
|
|
46
|
+
this.transfer = transfer;
|
|
47
|
+
}
|
|
48
|
+
initReplySubscription($) {
|
|
49
|
+
const { topic, replyTopic } = $;
|
|
50
|
+
if (!$.replySubscribers[replyTopic]) {
|
|
51
|
+
this.transfer.subscriber({ topic: replyTopic, next: this.replyHandler(topic) });
|
|
52
|
+
$.replySubscribers[replyTopic] = true;
|
|
53
|
+
}
|
|
54
|
+
return $.replySubscribers[replyTopic];
|
|
55
|
+
}
|
|
56
|
+
request(value, $) {
|
|
57
|
+
const { topic, replyTopic } = $;
|
|
58
|
+
const constructor = $._.target;
|
|
59
|
+
const uniqKey = node_crypto_1.default.randomUUID();
|
|
60
|
+
const hash = node_crypto_1.default.createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
61
|
+
const topicProcessKey = `${topic}_${hash}_${$.singletone ? "singletone" : uniqKey}`;
|
|
62
|
+
const headers = {
|
|
63
|
+
replyTopic,
|
|
64
|
+
uniqKey,
|
|
65
|
+
};
|
|
66
|
+
const existsProcess = $.topicProcessMap.get(topicProcessKey);
|
|
67
|
+
if (existsProcess) {
|
|
68
|
+
return existsProcess;
|
|
69
|
+
}
|
|
70
|
+
const instanceTopic = $._.root.instanceTopic(topic);
|
|
71
|
+
const rx$ = rxjs
|
|
72
|
+
.defer(async () => this.initReplySubscription($))
|
|
73
|
+
.pipe(rxjsOperators.mergeMap(() => new rxjs.Observable((observer) => {
|
|
74
|
+
const callback = callbackObserver(observer);
|
|
75
|
+
this.transfer.callbackMap.set(uniqKey, callback);
|
|
76
|
+
this.transfer.publisher({ topic: instanceTopic, message: { headers, value } });
|
|
77
|
+
return () => {
|
|
78
|
+
this.transfer.callbackMap.delete(uniqKey);
|
|
79
|
+
};
|
|
80
|
+
})));
|
|
81
|
+
let result;
|
|
82
|
+
if ($.waitForResponse) {
|
|
83
|
+
result = rxjs
|
|
84
|
+
.firstValueFrom(rx$)
|
|
85
|
+
.then((result) => {
|
|
86
|
+
$.topicProcessMap.delete(topicProcessKey);
|
|
87
|
+
return result;
|
|
88
|
+
})
|
|
89
|
+
.catch((err) => {
|
|
90
|
+
$.topicProcessMap.delete(topicProcessKey);
|
|
91
|
+
throw err;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
result = rx$.subscribe();
|
|
96
|
+
result.add(() => {
|
|
97
|
+
$.topicProcessMap.delete(topicProcessKey);
|
|
98
|
+
Reflect.apply($.originDescriptorValue, constructor, []);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
$.topicProcessMap.set(topicProcessKey, result);
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
replyHandler(topic) {
|
|
105
|
+
return (message) => {
|
|
106
|
+
const { value, headers } = message;
|
|
107
|
+
const { uniqKey, error } = headers;
|
|
108
|
+
const callback = this.transfer.callbackMap.get(uniqKey);
|
|
109
|
+
if (callback) {
|
|
110
|
+
if (error) {
|
|
111
|
+
callback({ error: value, topic });
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
callback({ topic, value });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
execHandler(handler) {
|
|
120
|
+
return (message) => {
|
|
121
|
+
const { value, headers } = message;
|
|
122
|
+
const { replyTopic, uniqKey } = headers;
|
|
123
|
+
Promise.all([Reflect.apply(handler, undefined, value)])
|
|
124
|
+
.then(([result]) => {
|
|
125
|
+
replyTopic &&
|
|
126
|
+
this.transfer.publisher({
|
|
127
|
+
topic: replyTopic,
|
|
128
|
+
message: { value: result || {}, headers: { uniqKey } },
|
|
129
|
+
});
|
|
130
|
+
})
|
|
131
|
+
.catch((error) => {
|
|
132
|
+
console.error("caught isolator error", error, value);
|
|
133
|
+
replyTopic &&
|
|
134
|
+
this.transfer.publisher({
|
|
135
|
+
topic: replyTopic,
|
|
136
|
+
message: { value: error, headers: { uniqKey, error: true } },
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.RxTransfer = RxTransfer;
|
|
143
|
+
function callbackObserver(observer) {
|
|
144
|
+
const serializeError = (err, topic) => {
|
|
145
|
+
return err;
|
|
146
|
+
};
|
|
147
|
+
const serializeResponse = (response, topic) => {
|
|
148
|
+
return response;
|
|
149
|
+
};
|
|
150
|
+
return (result) => {
|
|
151
|
+
const { error, value, topic, isCompleted } = result;
|
|
152
|
+
if (error) {
|
|
153
|
+
return observer.error(serializeError(error, topic));
|
|
154
|
+
}
|
|
155
|
+
else if (isCompleted) {
|
|
156
|
+
observer.next(serializeResponse(value, topic));
|
|
157
|
+
return observer.complete();
|
|
158
|
+
}
|
|
159
|
+
observer.next(serializeResponse(value, topic));
|
|
160
|
+
return null;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=rx-transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rx-transfer.js","sourceRoot":"","sources":["../../../src/defines/rx-transfer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,8DAAgD;AAChD,8DAAiC;AAUjC,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,CAAC,GAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;AAE1F,MAAa,UAAU;IAGrB,YAAY,Q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AAC;YAC/C,OAAO,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -3,7 +3,7 @@ export declare interface TransferTopics {
|
|
|
3
3
|
replyTopic: string;
|
|
4
4
|
}
|
|
5
5
|
export declare interface TransferMessageHeaders {
|
|
6
|
-
uniqKey
|
|
6
|
+
uniqKey?: string;
|
|
7
7
|
replyTopic?: string;
|
|
8
8
|
error?: boolean;
|
|
9
9
|
}
|
|
@@ -19,12 +19,33 @@ export declare interface TransferMessageSchema {
|
|
|
19
19
|
value: any;
|
|
20
20
|
}
|
|
21
21
|
export declare type TransferNextFunction = (message: TransferMessageSchema) => void;
|
|
22
|
-
export declare
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
export declare interface StructureReceiveSchema {
|
|
23
|
+
instance: InstancesData;
|
|
24
|
+
value: any;
|
|
25
|
+
}
|
|
26
|
+
export declare type StructureCollectorFunction = (data: StructureReceiveSchema) => void;
|
|
27
|
+
export declare type TransferPublishHandlerArgs = {
|
|
28
|
+
topic: string;
|
|
29
|
+
message: TransferMessageSchema;
|
|
30
|
+
};
|
|
31
|
+
export declare type TransferPublishHandler = (args: TransferPublishHandlerArgs) => void;
|
|
32
|
+
export declare type TransferSubscribeHandlerArgs = {
|
|
33
|
+
topic: string;
|
|
34
|
+
next: TransferNextFunction;
|
|
35
|
+
queue?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export declare type TransferSubscribeHandler = (args: TransferSubscribeHandlerArgs) => void;
|
|
38
|
+
export declare interface InstancesData {
|
|
25
39
|
instanceName: string;
|
|
26
40
|
instanceKey: string;
|
|
41
|
+
}
|
|
42
|
+
export declare interface TransferConfig extends InstancesData {
|
|
27
43
|
publisher: TransferPublishHandler;
|
|
28
44
|
subscriber: TransferSubscribeHandler;
|
|
29
45
|
}
|
|
46
|
+
export declare interface TransferRegisty {
|
|
47
|
+
receiver: InstancesData;
|
|
48
|
+
sender: InstancesData;
|
|
49
|
+
schemas: any;
|
|
50
|
+
}
|
|
30
51
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/defines/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,cAAc;IACrC,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,MAAM,CAAC,OAAO,WAAW,sBAAsB;IAE7C,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/defines/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,cAAc;IACrC,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,MAAM,CAAC,OAAO,WAAW,sBAAsB;IAE7C,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAMD,MAAM,CAAC,OAAO,WAAW,wBAAwB;IAE/C,KAAK,EAAE,MAAM,CAAC;IAGd,KAAK,CAAC,EAAE,GAAG,CAAC;IAGZ,KAAK,CAAC,EAAE,KAAK,CAAC;IAGd,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAMD,MAAM,CAAC,OAAO,MAAM,uBAAuB,GAAG,CAAC,QAAQ,EAAE,wBAAwB,KAAK,IAAI,CAAC;AAM3F,MAAM,CAAC,OAAO,WAAW,qBAAqB;IAE5C,OAAO,EAAE,sBAAsB,CAAC;IAGhC,KAAK,EAAE,GAAG,CAAC;CACZ;AAMD,MAAM,CAAC,OAAO,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAMpF,MAAM,CAAC,OAAO,WAAW,sBAAsB;IAC7C,QAAQ,EAAE,aAAa,CAAC;IAExB,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,MAAM,CAAC,OAAO,MAAM,0BAA0B,GAAG,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;AAExF,MAAM,CAAC,OAAO,MAAM,0BAA0B,GAAG;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,qBAAqB,CAAC;CAChC,CAAC;AAMF,MAAM,CAAC,OAAO,MAAM,sBAAsB,GAAG,CAAC,IAAI,EAAE,0BAA0B,KAAK,IAAI,CAAC;AAExF,MAAM,CAAC,OAAO,MAAM,4BAA4B,GAAG;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,oBAAoB,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAKF,MAAM,CAAC,OAAO,MAAM,wBAAwB,GAAG,CAAC,IAAI,EAAE,4BAA4B,KAAK,IAAI,CAAC;AAE5F,MAAM,CAAC,OAAO,WAAW,aAAa;IAEpC,YAAY,EAAE,MAAM,CAAC;IAGrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAMD,MAAM,CAAC,OAAO,WAAW,cAAe,SAAQ,aAAa;IAE3D,SAAS,EAAE,sBAAsB,CAAC;IAGlC,UAAU,EAAE,wBAAwB,CAAC;CACtC;AAED,MAAM,CAAC,OAAO,WAAW,eAAe;IACtC,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,GAAG,CAAC;CACd"}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { DecoratorsQueueStore } from "@aom-js/core";
|
|
2
|
-
import * as rxjs from "rxjs";
|
|
3
|
-
import * as rxjsOperators from "rxjs/operators";
|
|
4
|
-
import crypto from "node:crypto";
|
|
5
2
|
import { Transfer, AomIsolator } from "./main";
|
|
3
|
+
import { RxTransfer } from "./rx-transfer";
|
|
6
4
|
export function Isolator(transfer) {
|
|
7
5
|
return AomIsolator.classDecorator(($) => {
|
|
8
6
|
$.transfer = transfer;
|
|
7
|
+
$.rx = new RxTransfer(transfer);
|
|
9
8
|
$._.apply();
|
|
10
9
|
});
|
|
11
10
|
}
|
|
11
|
+
export function IsQueue() {
|
|
12
|
+
return AomIsolator.methodDecorator(($) => {
|
|
13
|
+
$.queue = true;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function IsDistributed() {
|
|
17
|
+
return AomIsolator.classDecorator(($) => {
|
|
18
|
+
$.transfer.registryMap.set($._.target, $._.target.name);
|
|
19
|
+
}, DecoratorsQueueStore.LAST);
|
|
20
|
+
}
|
|
12
21
|
export function CustomTopic(singletone) {
|
|
13
22
|
return AutoTopic(false, singletone);
|
|
14
23
|
}
|
|
@@ -16,8 +25,8 @@ export function ResponseTopic(singletone) {
|
|
|
16
25
|
return AutoTopic(true, singletone);
|
|
17
26
|
}
|
|
18
27
|
function DefineTopics() {
|
|
19
|
-
return AomIsolator.methodDecorator(($,
|
|
20
|
-
const { topicsMap } = $._.root;
|
|
28
|
+
return AomIsolator.methodDecorator(($, _descriptor) => {
|
|
29
|
+
const { topicsMap, instancesMap } = $._.root;
|
|
21
30
|
const constructor = $._.target;
|
|
22
31
|
const propertyKey = $._.property;
|
|
23
32
|
$._.root.isolatedMethods.push($);
|
|
@@ -30,6 +39,7 @@ function DefineTopics() {
|
|
|
30
39
|
const replyTopic = `reply_${topic}_${transfer.instanceKey}_${transfer.instanceName}`;
|
|
31
40
|
topics = { topic, replyTopic };
|
|
32
41
|
topicsMap.set(constructor[propertyKey], topics);
|
|
42
|
+
instancesMap.set(constructor[propertyKey], $);
|
|
33
43
|
}
|
|
34
44
|
return topics;
|
|
35
45
|
};
|
|
@@ -43,66 +53,13 @@ function AutoTopic(waitForResponse, singletone) {
|
|
|
43
53
|
return AomIsolator.methodDecorator(($, descriptor) => {
|
|
44
54
|
const constructor = $._.target;
|
|
45
55
|
const propertyKey = $._.property;
|
|
56
|
+
$.singletone = singletone;
|
|
57
|
+
$.waitForResponse = waitForResponse;
|
|
58
|
+
$.originDescriptorValue = descriptor.value;
|
|
46
59
|
Reflect.decorate([DefineTopics()], constructor, propertyKey);
|
|
47
|
-
const { value: originValue } = descriptor;
|
|
48
|
-
const topicProcessMap = new Map();
|
|
49
|
-
const replySubscribers = {};
|
|
50
|
-
const initReplySubscription = (topics, transfer) => {
|
|
51
|
-
const { topic, replyTopic } = topics;
|
|
52
|
-
if (!replySubscribers[replyTopic]) {
|
|
53
|
-
transfer.subscriber(replyTopic, transfer.replyHandler(topic));
|
|
54
|
-
replySubscribers[replyTopic] = true;
|
|
55
|
-
}
|
|
56
|
-
return replySubscribers[replyTopic];
|
|
57
|
-
};
|
|
58
60
|
descriptor.value = async (...args) => {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const { transfer } = $._.root;
|
|
62
|
-
const uniqKey = crypto.randomUUID();
|
|
63
|
-
const hash = crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
64
|
-
const topicProcessKey = `${topic}_${hash}_${singletone ? "singletone" : uniqKey}`;
|
|
65
|
-
const headers = {
|
|
66
|
-
replyTopic,
|
|
67
|
-
uniqKey,
|
|
68
|
-
};
|
|
69
|
-
const existsProcess = topicProcessMap.get(topicProcessKey);
|
|
70
|
-
if (existsProcess) {
|
|
71
|
-
return existsProcess;
|
|
72
|
-
}
|
|
73
|
-
const instanceTopic = $._.root.instanceTopic(topic);
|
|
74
|
-
const rx$ = rxjs
|
|
75
|
-
.defer(async () => initReplySubscription({ topic, replyTopic }, transfer))
|
|
76
|
-
.pipe(rxjsOperators.mergeMap(() => new rxjs.Observable((observer) => {
|
|
77
|
-
const callback = callbackObserver(observer);
|
|
78
|
-
transfer.callbackMap.set(uniqKey, callback);
|
|
79
|
-
transfer.publisher(instanceTopic, { headers, value });
|
|
80
|
-
return () => {
|
|
81
|
-
transfer.callbackMap.delete(uniqKey);
|
|
82
|
-
};
|
|
83
|
-
})));
|
|
84
|
-
let result;
|
|
85
|
-
if (waitForResponse) {
|
|
86
|
-
result = rxjs
|
|
87
|
-
.firstValueFrom(rx$)
|
|
88
|
-
.then((result) => {
|
|
89
|
-
topicProcessMap.delete(topicProcessKey);
|
|
90
|
-
return result;
|
|
91
|
-
})
|
|
92
|
-
.catch((err) => {
|
|
93
|
-
topicProcessMap.delete(topicProcessKey);
|
|
94
|
-
throw err;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
result = rx$.subscribe();
|
|
99
|
-
result.add(() => {
|
|
100
|
-
topicProcessMap.delete(topicProcessKey);
|
|
101
|
-
Reflect.apply(originValue, constructor, []);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
topicProcessMap.set(topicProcessKey, result);
|
|
105
|
-
return result;
|
|
61
|
+
const { rx } = $._.root;
|
|
62
|
+
return rx.request(args, $);
|
|
106
63
|
};
|
|
107
64
|
}, DecoratorsQueueStore.FIRST);
|
|
108
65
|
}
|
|
@@ -125,35 +82,20 @@ export function Executor(instanceId) {
|
|
|
125
82
|
}
|
|
126
83
|
function attachIsolation(constructor, propertyKey, instanceId) {
|
|
127
84
|
const parentConstructor = Object.getPrototypeOf(constructor);
|
|
128
|
-
const parent$ = AomIsolator.instance(
|
|
85
|
+
const parent$ = AomIsolator.instance(parentConstructor);
|
|
129
86
|
const { name } = constructor;
|
|
130
|
-
const { transfer
|
|
87
|
+
const { transfer, rx, topicsMap, instancesMap } = parent$;
|
|
131
88
|
const isolatedTopics = topicsMap.get(parentConstructor[propertyKey]);
|
|
89
|
+
const parentProperty$ = instancesMap.get(parentConstructor[propertyKey]);
|
|
132
90
|
if (!isolatedTopics) {
|
|
133
91
|
throw new Error(`attached handler is not isolated topic ${name}.${String(propertyKey)}`);
|
|
134
92
|
}
|
|
135
93
|
const { topic } = isolatedTopics;
|
|
136
94
|
const instanceTopic = Transfer.instanceTopic(topic, instanceId);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
const serializeResponse = (response, topic) => {
|
|
144
|
-
return response;
|
|
145
|
-
};
|
|
146
|
-
return (result) => {
|
|
147
|
-
const { error, value, topic, isCompleted } = result;
|
|
148
|
-
if (error) {
|
|
149
|
-
return observer.error(serializeError(error, topic));
|
|
150
|
-
}
|
|
151
|
-
else if (isCompleted) {
|
|
152
|
-
observer.next(serializeResponse(value, topic));
|
|
153
|
-
return observer.complete();
|
|
154
|
-
}
|
|
155
|
-
observer.next(serializeResponse(value, topic));
|
|
156
|
-
return null;
|
|
157
|
-
};
|
|
95
|
+
transfer.subscriber({
|
|
96
|
+
topic: instanceTopic,
|
|
97
|
+
next: rx.execHandler((...args) => Reflect.apply(constructor[propertyKey], constructor, args)),
|
|
98
|
+
queue: parentProperty$.queue,
|
|
99
|
+
});
|
|
158
100
|
}
|
|
159
101
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/defines/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,oBAAoB,EAAY,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/defines/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,oBAAoB,EAAY,MAAM,cAAc,CAAC;AAG3E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAO3C,MAAM,UAAU,QAAQ,CAAC,QAAkB;IAEzC,OAAO,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE;QACtC,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACtB,CAAC,CAAC,EAAE,GAAG,IAAI,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cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/defines/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
|
package/dist/mjs/defines/main.js
CHANGED
|
@@ -2,8 +2,11 @@ import { AomCore } from "@aom-js/core";
|
|
|
2
2
|
export class AomIsolator extends AomCore {
|
|
3
3
|
constructor() {
|
|
4
4
|
super(...arguments);
|
|
5
|
+
this.replySubscribers = {};
|
|
6
|
+
this.topicProcessMap = new Map();
|
|
5
7
|
this.isolatedMethods = [];
|
|
6
8
|
this.topicsMap = new WeakMap();
|
|
9
|
+
this.instancesMap = new WeakMap();
|
|
7
10
|
}
|
|
8
11
|
instanceTopic(topic) {
|
|
9
12
|
const result = Transfer.instanceTopic(topic, this.instanceId);
|
|
@@ -13,11 +16,22 @@ export class AomIsolator extends AomCore {
|
|
|
13
16
|
}
|
|
14
17
|
export class Transfer {
|
|
15
18
|
constructor(config) {
|
|
19
|
+
this.registryRequestTopic = `!Transfer_Registry_Request!`;
|
|
20
|
+
this.registryResponseTopic = `!Transfer_Registry_Notification!`;
|
|
21
|
+
this.registryMap = new Map();
|
|
16
22
|
this.publisher = config.publisher;
|
|
17
23
|
this.subscriber = config.subscriber;
|
|
18
24
|
this.instanceKey = config.instanceKey;
|
|
19
25
|
this.instanceName = config.instanceName;
|
|
20
26
|
this.callbackMap = new Map();
|
|
27
|
+
this.subscriber({
|
|
28
|
+
topic: this.registryRequestTopic,
|
|
29
|
+
next: (message) => this.requestRegistry(message.value),
|
|
30
|
+
});
|
|
31
|
+
this.subscriber({
|
|
32
|
+
topic: this.registryResponseTopic,
|
|
33
|
+
next: (message) => this.acceptRegistry(message.value),
|
|
34
|
+
});
|
|
21
35
|
}
|
|
22
36
|
static toInstance(constructor, instanceId) {
|
|
23
37
|
AomIsolator.instance(constructor).instanceId = instanceId;
|
|
@@ -26,42 +40,33 @@ export class Transfer {
|
|
|
26
40
|
static instanceTopic(topic, instanceId) {
|
|
27
41
|
return [topic, instanceId].filter(Boolean).join("_");
|
|
28
42
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
callback({ topic, value });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
+
collectDistributions(colllectCallbackHandler) {
|
|
44
|
+
this.structureCollector = colllectCallbackHandler;
|
|
45
|
+
const { instanceName, instanceKey } = this;
|
|
46
|
+
const value = { instanceName, instanceKey };
|
|
47
|
+
this.publisher({
|
|
48
|
+
topic: this.registryRequestTopic,
|
|
49
|
+
message: { value, headers: {} },
|
|
50
|
+
});
|
|
43
51
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
};
|
|
52
|
+
requestRegistry(sender) {
|
|
53
|
+
const { instanceName, instanceKey } = this;
|
|
54
|
+
if (!(sender.instanceName === instanceName && sender.instanceKey === instanceKey)) {
|
|
55
|
+
const schemas = this.registryMap.entries();
|
|
56
|
+
const value = { receiver: sender, sender: { instanceName, instanceKey }, schemas };
|
|
57
|
+
this.publisher({ topic: this.registryResponseTopic, message: { value, headers: {} } });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
acceptRegistry(registry) {
|
|
61
|
+
const { receiver } = registry;
|
|
62
|
+
const { instanceName, instanceKey } = this;
|
|
63
|
+
if (this.structureCollector &&
|
|
64
|
+
receiver.instanceName === instanceName &&
|
|
65
|
+
receiver.instanceKey === instanceKey) {
|
|
66
|
+
const { schemas, sender } = registry;
|
|
67
|
+
const structureData = { instance: sender, value: schemas };
|
|
68
|
+
Reflect.apply(this.structureCollector, null, [structureData]);
|
|
69
|
+
}
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/defines/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/defines/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiC,MAAM,cAAc,CAAC;AAgBtE,MAAM,OAAO,WAAY,SAAQ,OAAO;IAAxC;;QAeE,qBAAgB,GAA4B,EAAE,CAAC;QAE/C,oBAAe,GAAqB,IAAI,GAAG,EAAE,CAAC;QAE9C,oBAAe,GAAkB,EAAE,CAAC;QAEpC,cAAS,GAAyC,IAAI,OAAO,EAAE,CAAC;QAEhE,iBAAY,GAAsC,IAAI,OAAO,EAAE,CAAC;IAalE,CAAC;IALC,aAAa,CAAC,KAAa;QACzB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC9D,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAMD,MAAM,OAAO,QAAQ;IA4BnB,YAAY,MAAsB;QATzB,yBAAoB,GAAG,6BAA6B,CAAC;QACrD,0BAAqB,GAAG,kCAAkC,CAAC;QAE3D,gBAAW,GAA+B,IAAI,GAAG,EAAE,CAAC;QAQ3D,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,UAA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? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { ResponseTopic } from "./decorators";
|
|
11
|
+
export class TransferRegistry {
|
|
12
|
+
static async Init(transfer) { }
|
|
13
|
+
}
|
|
14
|
+
export class TransferRegistryIsolator {
|
|
15
|
+
static Request(value) { }
|
|
16
|
+
}
|
|
17
|
+
__decorate([
|
|
18
|
+
ResponseTopic(),
|
|
19
|
+
__metadata("design:type", Function),
|
|
20
|
+
__metadata("design:paramtypes", [String]),
|
|
21
|
+
__metadata("design:returntype", void 0)
|
|
22
|
+
], TransferRegistryIsolator, "Request", null);
|
|
23
|
+
export class TransferRegistryExecutor extends TransferRegistryIsolator {
|
|
24
|
+
static Request(value) {
|
|
25
|
+
console.log("TransferRegistryExecutor.Request received", { value });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/defines/registry.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAY,aAAa,EAAE,MAAM,cAAc,CAAC;AAGvD,MAAM,OAAO,gBAAgB;IAC3B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAkB,IAAG,CAAC;CACzC;AAED,MAAM,OAAO,wBAAwB;IAE5B,AAAP,MAAM,CAAC,OAAO,CAAC,KAAa,IAAG,CAAC;CACjC;AADQ;IADN,aAAa,EAAE;;;;6CACgB;AAGlC,MAAM,OAAO,wBAAyB,SAAQ,wBAAwB;IACpE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAEtE,CAAC;CACF"}
|