@aom-js/transfer 0.0.1

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.
Files changed (37) hide show
  1. package/dist/cjs/defines/decorators.d.ts +6 -0
  2. package/dist/cjs/defines/decorators.d.ts.map +1 -0
  3. package/dist/cjs/defines/decorators.js +204 -0
  4. package/dist/cjs/defines/decorators.js.map +1 -0
  5. package/dist/cjs/defines/index.d.ts +4 -0
  6. package/dist/cjs/defines/index.d.ts.map +1 -0
  7. package/dist/cjs/defines/index.js +20 -0
  8. package/dist/cjs/defines/index.js.map +1 -0
  9. package/dist/cjs/defines/main.d.ts +26 -0
  10. package/dist/cjs/defines/main.d.ts.map +1 -0
  11. package/dist/cjs/defines/main.js +76 -0
  12. package/dist/cjs/defines/main.js.map +1 -0
  13. package/dist/cjs/defines/types.d.ts +30 -0
  14. package/dist/cjs/defines/types.d.ts.map +1 -0
  15. package/dist/cjs/defines/types.js +3 -0
  16. package/dist/cjs/defines/types.js.map +1 -0
  17. package/dist/cjs/index.d.ts +3 -0
  18. package/dist/cjs/index.d.ts.map +1 -0
  19. package/dist/cjs/index.js +19 -0
  20. package/dist/cjs/index.js.map +1 -0
  21. package/dist/mjs/defines/decorators.js +162 -0
  22. package/dist/mjs/defines/decorators.js.map +1 -0
  23. package/dist/mjs/defines/index.js +4 -0
  24. package/dist/mjs/defines/index.js.map +1 -0
  25. package/dist/mjs/defines/main.js +71 -0
  26. package/dist/mjs/defines/main.js.map +1 -0
  27. package/dist/mjs/defines/types.js +2 -0
  28. package/dist/mjs/defines/types.js.map +1 -0
  29. package/dist/mjs/index.js +3 -0
  30. package/dist/mjs/index.js.map +1 -0
  31. package/dist/types/defines/decorators.d.ts +5 -0
  32. package/dist/types/defines/index.d.ts +3 -0
  33. package/dist/types/defines/main.d.ts +25 -0
  34. package/dist/types/defines/types.d.ts +29 -0
  35. package/dist/types/index.d.ts +2 -0
  36. package/package.json +52 -0
  37. package/readme.md +3 -0
@@ -0,0 +1,6 @@
1
+ import { Transfer } from "./main";
2
+ export declare function Isolator(transfer?: Transfer): ClassDecorator;
3
+ export declare function CustomTopic(singletone?: boolean): MethodDecorator;
4
+ export declare function ResponseTopic(singletone?: boolean): MethodDecorator;
5
+ export declare function Executor(instanceId?: string): ClassDecorator;
6
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/defines/decorators.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAe,MAAM,QAAQ,CAAC;AAQ/C,wBAAgB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,cAAc,CAU5D;AAOD,wBAAgB,WAAW,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,eAAe,CAEjE;AAOD,wBAAgB,aAAa,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,eAAe,CAEnE;AAoKD,wBAAgB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAkB5D"}
@@ -0,0 +1,204 @@
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.Isolator = Isolator;
40
+ exports.CustomTopic = CustomTopic;
41
+ exports.ResponseTopic = ResponseTopic;
42
+ exports.Executor = Executor;
43
+ const core_1 = require("@aom-js/core");
44
+ const rxjs = __importStar(require("rxjs"));
45
+ const rxjsOperators = __importStar(require("rxjs/operators"));
46
+ const node_crypto_1 = __importDefault(require("node:crypto"));
47
+ const main_1 = require("./main");
48
+ function Isolator(transfer) {
49
+ if (!transfer) {
50
+ transfer = main_1.Transfer.default;
51
+ }
52
+ return main_1.AomIsolator.classDecorator(($) => {
53
+ $.transfer = transfer;
54
+ $._.apply();
55
+ });
56
+ }
57
+ function CustomTopic(singletone) {
58
+ return AutoTopic(false, singletone);
59
+ }
60
+ function ResponseTopic(singletone) {
61
+ return AutoTopic(true, singletone);
62
+ }
63
+ function DefineTopics() {
64
+ return main_1.AomIsolator.methodDecorator(($, descriptor) => {
65
+ const { topicsMap } = $._.root;
66
+ const constructor = $._.target;
67
+ const propertyKey = $._.property;
68
+ $._.root.isolatedMethods.push($);
69
+ const handler = constructor[propertyKey];
70
+ const defineTopics = (transfer) => {
71
+ let topics = topicsMap.get(handler);
72
+ if (!topics) {
73
+ const { name } = $._.target;
74
+ const topic = `${name}.${String($._.property)}`;
75
+ const replyTopic = `reply_${topic}_${transfer.instanceKey}_${transfer.instanceName}`;
76
+ topics = { topic, replyTopic };
77
+ topicsMap.set(constructor[propertyKey], topics);
78
+ }
79
+ return topics;
80
+ };
81
+ const { transfer } = $._.root;
82
+ const { topic, replyTopic } = defineTopics(transfer);
83
+ $.topic = topic;
84
+ $.replyTopic = replyTopic;
85
+ }, core_1.DecoratorsQueueStore.LAST);
86
+ }
87
+ function AutoTopic(waitForResponse, singletone) {
88
+ return main_1.AomIsolator.methodDecorator(($, descriptor) => {
89
+ const constructor = $._.target;
90
+ const propertyKey = $._.property;
91
+ Reflect.decorate([DefineTopics()], constructor, propertyKey);
92
+ const { value: originValue } = descriptor;
93
+ const topicProcessMap = new Map();
94
+ const replySubscribers = {};
95
+ const initReplySubscription = (topics, transfer) => {
96
+ const { topic, replyTopic } = topics;
97
+ if (!replySubscribers[replyTopic]) {
98
+ transfer.subscriber(replyTopic, transfer.replyHandler(topic));
99
+ replySubscribers[replyTopic] = true;
100
+ }
101
+ return replySubscribers[replyTopic];
102
+ };
103
+ descriptor.value = async (...args) => {
104
+ const value = args;
105
+ const { topic, replyTopic } = $;
106
+ const { transfer } = $._.root;
107
+ const uniqKey = node_crypto_1.default.randomUUID();
108
+ const hash = node_crypto_1.default.createHash("sha256").update(JSON.stringify(value)).digest("hex");
109
+ const topicProcessKey = `${topic}_${hash}_${singletone ? "singletone" : uniqKey}`;
110
+ const headers = {
111
+ replyTopic,
112
+ uniqKey,
113
+ };
114
+ const existsProcess = topicProcessMap.get(topicProcessKey);
115
+ if (existsProcess) {
116
+ return existsProcess;
117
+ }
118
+ const instanceTopic = $._.root.instanceTopic(topic);
119
+ const rx$ = rxjs
120
+ .defer(async () => initReplySubscription({ topic, replyTopic }, transfer))
121
+ .pipe(rxjsOperators.mergeMap(() => new rxjs.Observable((observer) => {
122
+ const callback = callbackObserver(observer);
123
+ transfer.callbackMap.set(uniqKey, callback);
124
+ transfer.publisher(instanceTopic, { headers, value });
125
+ return () => {
126
+ transfer.callbackMap.delete(uniqKey);
127
+ };
128
+ })));
129
+ let result;
130
+ if (waitForResponse) {
131
+ result = rxjs
132
+ .firstValueFrom(rx$)
133
+ .then((result) => {
134
+ topicProcessMap.delete(topicProcessKey);
135
+ return result;
136
+ })
137
+ .catch((err) => {
138
+ topicProcessMap.delete(topicProcessKey);
139
+ throw err;
140
+ });
141
+ }
142
+ else {
143
+ result = rx$.subscribe();
144
+ result.add(() => {
145
+ topicProcessMap.delete(topicProcessKey);
146
+ Reflect.apply(originValue, constructor, []);
147
+ });
148
+ }
149
+ topicProcessMap.set(topicProcessKey, result);
150
+ return result;
151
+ };
152
+ }, core_1.DecoratorsQueueStore.FIRST);
153
+ }
154
+ function Executor(instanceId) {
155
+ return main_1.AomIsolator.classDecorator(($) => {
156
+ const constructor = $._.target;
157
+ const parent$ = main_1.AomIsolator.instance(Object.getPrototypeOf(constructor));
158
+ parent$.isolatedMethods.forEach((_$) => {
159
+ const { property } = _$._;
160
+ if (property) {
161
+ if (Reflect.getOwnPropertyDescriptor(constructor, property)) {
162
+ attachIsolation(constructor, property, instanceId);
163
+ }
164
+ else {
165
+ console.warn("isolated property `", property, "` has no executor");
166
+ }
167
+ }
168
+ });
169
+ });
170
+ }
171
+ function attachIsolation(constructor, propertyKey, instanceId) {
172
+ const parentConstructor = Object.getPrototypeOf(constructor);
173
+ const parent$ = main_1.AomIsolator.instance(Object.getPrototypeOf(constructor));
174
+ const { name } = constructor;
175
+ const { transfer: isolator, topicsMap } = parent$;
176
+ const isolatedTopics = topicsMap.get(parentConstructor[propertyKey]);
177
+ if (!isolatedTopics) {
178
+ throw new Error(`attached handler is not isolated topic ${name}.${String(propertyKey)}`);
179
+ }
180
+ const { topic } = isolatedTopics;
181
+ const instanceTopic = main_1.Transfer.instanceTopic(topic, instanceId);
182
+ isolator.subscriber(instanceTopic, isolator.execHandler(constructor, propertyKey));
183
+ }
184
+ function callbackObserver(observer) {
185
+ const serializeError = (err, topic) => {
186
+ return err;
187
+ };
188
+ const serializeResponse = (response, topic) => {
189
+ return response;
190
+ };
191
+ return (result) => {
192
+ const { error, value, topic, isCompleted } = result;
193
+ if (error) {
194
+ return observer.error(serializeError(error, topic));
195
+ }
196
+ else if (isCompleted) {
197
+ observer.next(serializeResponse(value, topic));
198
+ return observer.complete();
199
+ }
200
+ observer.next(serializeResponse(value, topic));
201
+ return null;
202
+ };
203
+ }
204
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/defines/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,4BAUC;AAOD,kCAEC;AAOD,sCAEC;AAoKD,4BAkBC;AAhOD,uCAA2E;AAC3E,2CAA6B;AAC7B,8DAAgD;AAChD,8DAAiC;AAGjC,iCAA+C;AAQ/C,SAAgB,QAAQ,CAAC,QAAmB;IAE1C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,eAAQ,CAAC,OAAO,CAAC;IAC9B,CAAC;IACD,OAAO,kBAAW,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE;QACtC,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACtB,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IAEd,CAAC,CAAC,CAAC;AACL,CAAC;AAOD,SAAgB,WAAW,CAAC,UAAoB;IAC9C,OAAO,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AACtC,CAAC;AAOD,SAAgB,aAAa,CAAC,UAAoB;IAChD,OAAO,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACrC,CAAC;AAGD,SAAS,YAAY;IACnB,OAAO,kBAAW,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE;QACnD,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/B,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC/B,MAAM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AAgC,EAAE,EAAE;QAE1C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;QAGpD,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QACtD,CAAC;aAAM,IAAI,WAAW,EAAE,CAAC;YACvB,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;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"}
@@ -0,0 +1,4 @@
1
+ export * from "./decorators";
2
+ export * from "./types";
3
+ export * from "./main";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/defines/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,20 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./decorators"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./main"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/defines/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,0CAAwB;AACxB,yCAAuB"}
@@ -0,0 +1,26 @@
1
+ import { AomCore, Constructor, ClassConstructor } from "@aom-js/core";
2
+ import { TransferConfig, TransferPublishHandler, TransferSubscribeHandler, TransferCallbackHandler, TransferNextFunction, TransferTopics } from "./types";
3
+ export declare class AomIsolator extends AomCore {
4
+ transfer: Transfer;
5
+ isolatedMethods: AomIsolator[];
6
+ topicsMap: WeakMap<Constructor, TransferTopics>;
7
+ instanceId?: string;
8
+ topic: string;
9
+ replyTopic: string;
10
+ instanceTopic(topic: string): string;
11
+ }
12
+ export declare class Transfer implements TransferConfig {
13
+ instanceName: string;
14
+ instanceKey: string;
15
+ publisher: TransferPublishHandler;
16
+ subscriber: TransferSubscribeHandler;
17
+ callbackMap: Map<string, TransferCallbackHandler>;
18
+ constructor(config: TransferConfig);
19
+ static default: Transfer;
20
+ static config(config: TransferConfig): Transfer;
21
+ static toInstance<T extends ClassConstructor<any>>(constructor: T, instanceId: string): T;
22
+ static instanceTopic(topic: string, instanceId?: string): string;
23
+ replyHandler(topic: string): TransferNextFunction;
24
+ execHandler(constructor: Constructor, propertyKey: string): TransferNextFunction;
25
+ }
26
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/defines/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EAEvB,oBAAoB,EACpB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,qBAAa,WAAY,SAAQ,OAAO;IACtC,QAAQ,EAAE,QAAQ,CAAC;IAEnB,eAAe,EAAE,WAAW,EAAE,CAAM;IAEpC,SAAS,EAAE,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAiB;IAEhE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,EAAE,MAAM,CAAC;IAEnB,aAAa,CAAC,KAAK,EAAE,MAAM;CAK5B;AAMD,qBAAa,QAAS,YAAW,cAAc;IAE7C,YAAY,EAAE,MAAM,CAAC;IAGrB,WAAW,EAAE,MAAM,CAAC;IAGpB,SAAS,EAAE,sBAAsB,CAAC;IAGlC,UAAU,EAAE,wBAAwB,CAAC;IAGrC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;gBAMtC,MAAM,EAAE,cAAc;IAYlC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC;IAMzB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ;IAW/C,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,gBAAgB,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;IAWzF,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;IAShE,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB;IA2BjD,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,GAAG,oBAAoB;CA4BjF"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Transfer = exports.AomIsolator = void 0;
4
+ const core_1 = require("@aom-js/core");
5
+ class AomIsolator extends core_1.AomCore {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.isolatedMethods = [];
9
+ this.topicsMap = new WeakMap();
10
+ }
11
+ instanceTopic(topic) {
12
+ const result = Transfer.instanceTopic(topic, this.instanceId);
13
+ this.instanceId = undefined;
14
+ return result;
15
+ }
16
+ }
17
+ exports.AomIsolator = AomIsolator;
18
+ class Transfer {
19
+ constructor(config) {
20
+ this.publisher = config.publisher;
21
+ this.subscriber = config.subscriber;
22
+ this.instanceKey = config.instanceKey;
23
+ this.instanceName = config.instanceName;
24
+ this.callbackMap = new Map();
25
+ }
26
+ static config(config) {
27
+ this.default = new this(config);
28
+ return this.default;
29
+ }
30
+ static toInstance(constructor, instanceId) {
31
+ AomIsolator.instance(constructor).instanceId = instanceId;
32
+ return constructor;
33
+ }
34
+ static instanceTopic(topic, instanceId) {
35
+ return [topic, instanceId].filter(Boolean).join("_");
36
+ }
37
+ replyHandler(topic) {
38
+ return (message) => {
39
+ const { value, headers } = message;
40
+ const { uniqKey, error } = headers;
41
+ const callback = this.callbackMap.get(uniqKey);
42
+ if (callback) {
43
+ if (error) {
44
+ callback({ error: value, topic });
45
+ }
46
+ else {
47
+ callback({ topic, value });
48
+ }
49
+ }
50
+ };
51
+ }
52
+ execHandler(constructor, propertyKey) {
53
+ return (message) => {
54
+ const { value, headers } = message;
55
+ const { replyTopic, uniqKey } = headers;
56
+ Promise.all([Reflect.apply(constructor[propertyKey], constructor, value)])
57
+ .then(([result]) => {
58
+ replyTopic &&
59
+ this.publisher(replyTopic, {
60
+ value: result || {},
61
+ headers: { uniqKey },
62
+ });
63
+ })
64
+ .catch((error) => {
65
+ console.error("caught isolator error", error, value);
66
+ replyTopic &&
67
+ this.publisher(replyTopic, {
68
+ value: error,
69
+ headers: { uniqKey, error: true },
70
+ });
71
+ });
72
+ };
73
+ }
74
+ }
75
+ exports.Transfer = Transfer;
76
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","source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AC,UAAU,EAAE;wBACzB,KAAK,EAAE,KAAK;wBACZ,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE;qBAClC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;IACJ,CAAC;CACF;AA5HD,4BA4HC"}
@@ -0,0 +1,30 @@
1
+ export declare interface TransferTopics {
2
+ topic: string;
3
+ replyTopic: string;
4
+ }
5
+ export declare interface TransferMessageHeaders {
6
+ uniqKey: string;
7
+ replyTopic?: string;
8
+ error?: boolean;
9
+ }
10
+ export declare interface TransferCallbackResponse {
11
+ topic: string;
12
+ value?: any;
13
+ error?: Error;
14
+ isCompleted?: boolean;
15
+ }
16
+ export declare type TransferCallbackHandler = (response: TransferCallbackResponse) => void;
17
+ export declare interface TransferMessageSchema {
18
+ headers: TransferMessageHeaders;
19
+ value: any;
20
+ }
21
+ export declare type TransferNextFunction = (message: TransferMessageSchema) => void;
22
+ export declare type TransferPublishHandler = (topic: string, message: TransferMessageSchema) => void;
23
+ export declare type TransferSubscribeHandler = (topic: string, next: TransferNextFunction) => void;
24
+ export declare interface TransferConfig {
25
+ instanceName: string;
26
+ instanceKey: string;
27
+ publisher: TransferPublishHandler;
28
+ subscriber: TransferSubscribeHandler;
29
+ }
30
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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;IAGhB,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,MAAM,sBAAsB,GAAG,CAC3C,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,qBAAqB,KAC3B,IAAI,CAAC;AAMV,MAAM,CAAC,OAAO,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAMnG,MAAM,CAAC,OAAO,WAAW,cAAc;IAErC,YAAY,EAAE,MAAM,CAAC;IAGrB,WAAW,EAAE,MAAM,CAAC;IAGpB,SAAS,EAAE,sBAAsB,CAAC;IAGlC,UAAU,EAAE,wBAAwB,CAAC;CACtC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/defines/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import "reflect-metadata";
2
+ export * from "./defines";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("reflect-metadata");
18
+ __exportStar(require("./defines"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4BAA0B;AAE1B,4CAA0B"}
@@ -0,0 +1,162 @@
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
+ import { Transfer, AomIsolator } from "./main";
6
+ export function Isolator(transfer) {
7
+ if (!transfer) {
8
+ transfer = Transfer.default;
9
+ }
10
+ return AomIsolator.classDecorator(($) => {
11
+ $.transfer = transfer;
12
+ $._.apply();
13
+ });
14
+ }
15
+ export function CustomTopic(singletone) {
16
+ return AutoTopic(false, singletone);
17
+ }
18
+ export function ResponseTopic(singletone) {
19
+ return AutoTopic(true, singletone);
20
+ }
21
+ function DefineTopics() {
22
+ return AomIsolator.methodDecorator(($, descriptor) => {
23
+ const { topicsMap } = $._.root;
24
+ const constructor = $._.target;
25
+ const propertyKey = $._.property;
26
+ $._.root.isolatedMethods.push($);
27
+ const handler = constructor[propertyKey];
28
+ const defineTopics = (transfer) => {
29
+ let topics = topicsMap.get(handler);
30
+ if (!topics) {
31
+ const { name } = $._.target;
32
+ const topic = `${name}.${String($._.property)}`;
33
+ const replyTopic = `reply_${topic}_${transfer.instanceKey}_${transfer.instanceName}`;
34
+ topics = { topic, replyTopic };
35
+ topicsMap.set(constructor[propertyKey], topics);
36
+ }
37
+ return topics;
38
+ };
39
+ const { transfer } = $._.root;
40
+ const { topic, replyTopic } = defineTopics(transfer);
41
+ $.topic = topic;
42
+ $.replyTopic = replyTopic;
43
+ }, DecoratorsQueueStore.LAST);
44
+ }
45
+ function AutoTopic(waitForResponse, singletone) {
46
+ return AomIsolator.methodDecorator(($, descriptor) => {
47
+ const constructor = $._.target;
48
+ const propertyKey = $._.property;
49
+ Reflect.decorate([DefineTopics()], constructor, propertyKey);
50
+ const { value: originValue } = descriptor;
51
+ const topicProcessMap = new Map();
52
+ const replySubscribers = {};
53
+ const initReplySubscription = (topics, transfer) => {
54
+ const { topic, replyTopic } = topics;
55
+ if (!replySubscribers[replyTopic]) {
56
+ transfer.subscriber(replyTopic, transfer.replyHandler(topic));
57
+ replySubscribers[replyTopic] = true;
58
+ }
59
+ return replySubscribers[replyTopic];
60
+ };
61
+ descriptor.value = async (...args) => {
62
+ const value = args;
63
+ const { topic, replyTopic } = $;
64
+ const { transfer } = $._.root;
65
+ const uniqKey = crypto.randomUUID();
66
+ const hash = crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex");
67
+ const topicProcessKey = `${topic}_${hash}_${singletone ? "singletone" : uniqKey}`;
68
+ const headers = {
69
+ replyTopic,
70
+ uniqKey,
71
+ };
72
+ const existsProcess = topicProcessMap.get(topicProcessKey);
73
+ if (existsProcess) {
74
+ return existsProcess;
75
+ }
76
+ const instanceTopic = $._.root.instanceTopic(topic);
77
+ const rx$ = rxjs
78
+ .defer(async () => initReplySubscription({ topic, replyTopic }, transfer))
79
+ .pipe(rxjsOperators.mergeMap(() => new rxjs.Observable((observer) => {
80
+ const callback = callbackObserver(observer);
81
+ transfer.callbackMap.set(uniqKey, callback);
82
+ transfer.publisher(instanceTopic, { headers, value });
83
+ return () => {
84
+ transfer.callbackMap.delete(uniqKey);
85
+ };
86
+ })));
87
+ let result;
88
+ if (waitForResponse) {
89
+ result = rxjs
90
+ .firstValueFrom(rx$)
91
+ .then((result) => {
92
+ topicProcessMap.delete(topicProcessKey);
93
+ return result;
94
+ })
95
+ .catch((err) => {
96
+ topicProcessMap.delete(topicProcessKey);
97
+ throw err;
98
+ });
99
+ }
100
+ else {
101
+ result = rx$.subscribe();
102
+ result.add(() => {
103
+ topicProcessMap.delete(topicProcessKey);
104
+ Reflect.apply(originValue, constructor, []);
105
+ });
106
+ }
107
+ topicProcessMap.set(topicProcessKey, result);
108
+ return result;
109
+ };
110
+ }, DecoratorsQueueStore.FIRST);
111
+ }
112
+ export function Executor(instanceId) {
113
+ return AomIsolator.classDecorator(($) => {
114
+ const constructor = $._.target;
115
+ const parent$ = AomIsolator.instance(Object.getPrototypeOf(constructor));
116
+ parent$.isolatedMethods.forEach((_$) => {
117
+ const { property } = _$._;
118
+ if (property) {
119
+ if (Reflect.getOwnPropertyDescriptor(constructor, property)) {
120
+ attachIsolation(constructor, property, instanceId);
121
+ }
122
+ else {
123
+ console.warn("isolated property `", property, "` has no executor");
124
+ }
125
+ }
126
+ });
127
+ });
128
+ }
129
+ function attachIsolation(constructor, propertyKey, instanceId) {
130
+ const parentConstructor = Object.getPrototypeOf(constructor);
131
+ const parent$ = AomIsolator.instance(Object.getPrototypeOf(constructor));
132
+ const { name } = constructor;
133
+ const { transfer: isolator, topicsMap } = parent$;
134
+ const isolatedTopics = topicsMap.get(parentConstructor[propertyKey]);
135
+ if (!isolatedTopics) {
136
+ throw new Error(`attached handler is not isolated topic ${name}.${String(propertyKey)}`);
137
+ }
138
+ const { topic } = isolatedTopics;
139
+ const instanceTopic = Transfer.instanceTopic(topic, instanceId);
140
+ isolator.subscriber(instanceTopic, isolator.execHandler(constructor, propertyKey));
141
+ }
142
+ function callbackObserver(observer) {
143
+ const serializeError = (err, topic) => {
144
+ return err;
145
+ };
146
+ const serializeResponse = (response, topic) => {
147
+ return response;
148
+ };
149
+ return (result) => {
150
+ const { error, value, topic, isCompleted } = result;
151
+ if (error) {
152
+ return observer.error(serializeError(error, topic));
153
+ }
154
+ else if (isCompleted) {
155
+ observer.next(serializeResponse(value, topic));
156
+ return observer.complete();
157
+ }
158
+ observer.next(serializeResponse(value, topic));
159
+ return null;
160
+ };
161
+ }
162
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/defines/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,oBAAoB,EAAY,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAChD,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAQ/C,MAAM,UAAU,QAAQ,CAAC,QAAmB;IAE1C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC;IAC9B,CAAC;IACD,OAAO,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE;QACtC,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACtB,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IAEd,CAAC,CAAC,CAAC;AACL,CAAC;AAOD,MAAM,UAAU,WAAW,CAAC,UAAoB;IAC9C,OAAO,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AACtC,CAAC;AAOD,MAAM,UAAU,aAAa,CAAC,UAAoB;IAChD,OAAO,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACrC,CAAC;AAGD,SAAS,YAAY;IACnB,OAAO,WAAW,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AAU,EAAE,KAAa,EAAE,EAAE;QAEnD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;IAQF,MAAM,iBAAiB,GAAG,CAAC,QAAa,EAAE,KAAa,EAAE,EAAE;QAEzD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAGF,OAAO,CAAC,MAAgC,EAAE,EAAE;QAE1C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;QAGpD,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QACtD,CAAC;aAAM,IAAI,WAAW,EAAE,CAAC;YACvB,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;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"}
@@ -0,0 +1,4 @@
1
+ export * from "./decorators";
2
+ export * from "./types";
3
+ export * from "./main";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,71 @@
1
+ import { AomCore } from "@aom-js/core";
2
+ export class AomIsolator extends AomCore {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.isolatedMethods = [];
6
+ this.topicsMap = new WeakMap();
7
+ }
8
+ instanceTopic(topic) {
9
+ const result = Transfer.instanceTopic(topic, this.instanceId);
10
+ this.instanceId = undefined;
11
+ return result;
12
+ }
13
+ }
14
+ export class Transfer {
15
+ constructor(config) {
16
+ this.publisher = config.publisher;
17
+ this.subscriber = config.subscriber;
18
+ this.instanceKey = config.instanceKey;
19
+ this.instanceName = config.instanceName;
20
+ this.callbackMap = new Map();
21
+ }
22
+ static config(config) {
23
+ this.default = new this(config);
24
+ return this.default;
25
+ }
26
+ static toInstance(constructor, instanceId) {
27
+ AomIsolator.instance(constructor).instanceId = instanceId;
28
+ return constructor;
29
+ }
30
+ static instanceTopic(topic, instanceId) {
31
+ return [topic, instanceId].filter(Boolean).join("_");
32
+ }
33
+ replyHandler(topic) {
34
+ return (message) => {
35
+ const { value, headers } = message;
36
+ const { uniqKey, error } = headers;
37
+ const callback = this.callbackMap.get(uniqKey);
38
+ if (callback) {
39
+ if (error) {
40
+ callback({ error: value, topic });
41
+ }
42
+ else {
43
+ callback({ topic, value });
44
+ }
45
+ }
46
+ };
47
+ }
48
+ execHandler(constructor, propertyKey) {
49
+ return (message) => {
50
+ const { value, headers } = message;
51
+ const { replyTopic, uniqKey } = headers;
52
+ Promise.all([Reflect.apply(constructor[propertyKey], constructor, value)])
53
+ .then(([result]) => {
54
+ replyTopic &&
55
+ this.publisher(replyTopic, {
56
+ value: result || {},
57
+ headers: { uniqKey },
58
+ });
59
+ })
60
+ .catch((error) => {
61
+ console.error("caught isolator error", error, value);
62
+ replyTopic &&
63
+ this.publisher(replyTopic, {
64
+ value: error,
65
+ headers: { uniqKey, error: true },
66
+ });
67
+ });
68
+ };
69
+ }
70
+ }
71
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/defines/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiC,MAAM,cAAc,CAAC;AAYtE,MAAM,OAAO,WAAY,SAAQ,OAAO;IAAxC;;QAGE,oBAAe,GAAkB,EAAE,CAAC;QAEpC,cAAS,GAAyC,IAAI,OAAO,EAAE,CAAC;IAalE,CAAC;IALC,aAAa,C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
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/defines/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import "reflect-metadata";
2
+ export * from "./defines";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Transfer } from "./main";
2
+ export declare function Isolator(transfer?: Transfer): ClassDecorator;
3
+ export declare function CustomTopic(singletone?: boolean): MethodDecorator;
4
+ export declare function ResponseTopic(singletone?: boolean): MethodDecorator;
5
+ export declare function Executor(instanceId?: string): ClassDecorator;
@@ -0,0 +1,3 @@
1
+ export * from "./decorators";
2
+ export * from "./types";
3
+ export * from "./main";
@@ -0,0 +1,25 @@
1
+ import { AomCore, Constructor, ClassConstructor } from "@aom-js/core";
2
+ import { TransferConfig, TransferPublishHandler, TransferSubscribeHandler, TransferCallbackHandler, TransferNextFunction, TransferTopics } from "./types";
3
+ export declare class AomIsolator extends AomCore {
4
+ transfer: Transfer;
5
+ isolatedMethods: AomIsolator[];
6
+ topicsMap: WeakMap<Constructor, TransferTopics>;
7
+ instanceId?: string;
8
+ topic: string;
9
+ replyTopic: string;
10
+ instanceTopic(topic: string): string;
11
+ }
12
+ export declare class Transfer implements TransferConfig {
13
+ instanceName: string;
14
+ instanceKey: string;
15
+ publisher: TransferPublishHandler;
16
+ subscriber: TransferSubscribeHandler;
17
+ callbackMap: Map<string, TransferCallbackHandler>;
18
+ constructor(config: TransferConfig);
19
+ static default: Transfer;
20
+ static config(config: TransferConfig): Transfer;
21
+ static toInstance<T extends ClassConstructor<any>>(constructor: T, instanceId: string): T;
22
+ static instanceTopic(topic: string, instanceId?: string): string;
23
+ replyHandler(topic: string): TransferNextFunction;
24
+ execHandler(constructor: Constructor, propertyKey: string): TransferNextFunction;
25
+ }
@@ -0,0 +1,29 @@
1
+ export declare interface TransferTopics {
2
+ topic: string;
3
+ replyTopic: string;
4
+ }
5
+ export declare interface TransferMessageHeaders {
6
+ uniqKey: string;
7
+ replyTopic?: string;
8
+ error?: boolean;
9
+ }
10
+ export declare interface TransferCallbackResponse {
11
+ topic: string;
12
+ value?: any;
13
+ error?: Error;
14
+ isCompleted?: boolean;
15
+ }
16
+ export declare type TransferCallbackHandler = (response: TransferCallbackResponse) => void;
17
+ export declare interface TransferMessageSchema {
18
+ headers: TransferMessageHeaders;
19
+ value: any;
20
+ }
21
+ export declare type TransferNextFunction = (message: TransferMessageSchema) => void;
22
+ export declare type TransferPublishHandler = (topic: string, message: TransferMessageSchema) => void;
23
+ export declare type TransferSubscribeHandler = (topic: string, next: TransferNextFunction) => void;
24
+ export declare interface TransferConfig {
25
+ instanceName: string;
26
+ instanceKey: string;
27
+ publisher: TransferPublishHandler;
28
+ subscriber: TransferSubscribeHandler;
29
+ }
@@ -0,0 +1,2 @@
1
+ import "reflect-metadata";
2
+ export * from "./defines";
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "version": "0.0.1",
3
+ "name": "@aom-js/transfer",
4
+ "description": "`@aom` meta-framework transfer code",
5
+ "homepage": "https://github.com/aom-js/main#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/aom-js/main/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/aom-js/main.git",
12
+ "directory": "packages/transfer"
13
+ },
14
+ "license": "ISC",
15
+ "author": "Grigory B. Kholstinnikov (scarych)",
16
+ "dependencies": {
17
+ "@aom-js/core": "*",
18
+ "reflect-metadata": "^0.2.2",
19
+ "rxjs": "^7.8.2"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^22.14.0",
23
+ "tslib": "^2.8.1",
24
+ "typescript": "^5.8.3"
25
+ },
26
+ "main": "./dist/cjs/index.js",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "type": "module",
31
+ "module": "./dist/mjs/index.js",
32
+ "types": "./dist/types/index.d.ts",
33
+ "files": [
34
+ "./dist/cjs",
35
+ "./dist/mjs",
36
+ "./dist/types"
37
+ ],
38
+ "exports": {
39
+ ".": {
40
+ "import": "./dist/mjs/index.js",
41
+ "require": "./dist/cjs/index.js",
42
+ "types": "./dist/types/index.d.ts"
43
+ }
44
+ },
45
+ "scripts": {
46
+ "test": "echo \"Error: no test specified\" && exit 1",
47
+ "clean": "rm -rf dist/",
48
+ "prebuild": "rm -rf dist/",
49
+ "build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.mjs.json && tsc --project tsconfig.build.types.json ",
50
+ "prepare": "npm run build"
51
+ }
52
+ }
package/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@aom-js/transfer`
2
+
3
+ Abstract data transfer module.