@onecx/accelerator 6.26.0 → 6.27.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onecx/accelerator",
3
- "version": "6.26.0",
3
+ "version": "6.27.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,7 +10,7 @@
10
10
  "tslib": "^2.6.3",
11
11
  "rxjs": "^7.8.1",
12
12
  "@nx/devkit": "^20.3.0",
13
- "@onecx/nx-migration-utils": "^6.26.0"
13
+ "@onecx/nx-migration-utils": "^6.27.0"
14
14
  },
15
15
  "peerDependenciesMeta": {
16
16
  "@nx/devkit": {
package/src/index.d.ts CHANGED
@@ -8,5 +8,6 @@ export * from './lib/utils/date.utils';
8
8
  export * from './lib/utils/is-test.utils';
9
9
  export * from './lib/utils/normalize-locales.utils';
10
10
  export * from './lib/utils/get-normalized-browser-locales.utils';
11
+ export * from './lib/utils/gatherer';
11
12
  export * from './lib/utils/ensure-property.utils';
12
13
  export * from './lib/utils/get-onecx-shared-recommendations';
package/src/index.js CHANGED
@@ -11,6 +11,7 @@ tslib_1.__exportStar(require("./lib/utils/date.utils"), exports);
11
11
  tslib_1.__exportStar(require("./lib/utils/is-test.utils"), exports);
12
12
  tslib_1.__exportStar(require("./lib/utils/normalize-locales.utils"), exports);
13
13
  tslib_1.__exportStar(require("./lib/utils/get-normalized-browser-locales.utils"), exports);
14
+ tslib_1.__exportStar(require("./lib/utils/gatherer"), exports);
14
15
  tslib_1.__exportStar(require("./lib/utils/ensure-property.utils"), exports);
15
16
  tslib_1.__exportStar(require("./lib/utils/get-onecx-shared-recommendations"), exports);
16
17
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/accelerator/src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAiC;AACjC,uEAA4C;AAC5C,mFAAwD;AACxD,qEAA0C;AAC1C,sEAA2C;AAC3C,iEAAsC;AACtC,iEAAsC;AACtC,oEAAyC;AACzC,8EAAmD;AACnD,2FAAgE;AAChE,4EAAiD;AACjD,uFAA4D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/accelerator/src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAiC;AACjC,uEAA4C;AAC5C,mFAAwD;AACxD,qEAA0C;AAC1C,sEAA2C;AAC3C,iEAAsC;AACtC,iEAAsC;AACtC,oEAAyC;AACzC,8EAAmD;AACnD,2FAAgE;AAChE,+DAAoC;AACpC,4EAAiD;AACjD,uFAA4D"}
@@ -1,11 +1,35 @@
1
1
  declare const topicTabId: object & {
2
2
  "@onecx/accelerator": {
3
+ gatherer: object & {
4
+ promises: Record<number, Promise<any>[]>;
5
+ };
6
+ };
7
+ } & {
8
+ "@onecx/accelerator": {
9
+ gatherer: object & {
10
+ promises: Record<number, Promise<any>[]>;
11
+ } & {
12
+ debug: string[];
13
+ };
14
+ };
15
+ } & {
16
+ "@onecx/accelerator": {
17
+ gatherer: object & {
18
+ promises: Record<number, Promise<any>[]>;
19
+ } & {
20
+ debug: string[];
21
+ };
3
22
  topic: object & {
4
23
  useBroadcastChannel: boolean | "V2";
5
24
  };
6
25
  };
7
26
  } & {
8
27
  "@onecx/accelerator": {
28
+ gatherer: object & {
29
+ promises: Record<number, Promise<any>[]>;
30
+ } & {
31
+ debug: string[];
32
+ };
9
33
  topic: object & {
10
34
  useBroadcastChannel: boolean | "V2";
11
35
  } & {
@@ -14,6 +38,11 @@ declare const topicTabId: object & {
14
38
  };
15
39
  } & {
16
40
  "@onecx/accelerator": {
41
+ gatherer: object & {
42
+ promises: Record<number, Promise<any>[]>;
43
+ } & {
44
+ debug: string[];
45
+ };
17
46
  topic: object & {
18
47
  useBroadcastChannel: boolean | "V2";
19
48
  } & {
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.acceleratorState = void 0;
4
4
  const ensure_property_utils_1 = require("./utils/ensure-property.utils");
5
- const topicUseBroadcastChannel = (0, ensure_property_utils_1.ensureProperty)(globalThis, ['@onecx/accelerator', 'topic', 'useBroadcastChannel'], 'V2');
5
+ const gatherPromises = (0, ensure_property_utils_1.ensureProperty)(globalThis, ['@onecx/accelerator', 'gatherer', 'promises'], {});
6
+ const gatherDebug = (0, ensure_property_utils_1.ensureProperty)(gatherPromises, ['@onecx/accelerator', 'gatherer', 'debug'], []);
7
+ const topicUseBroadcastChannel = (0, ensure_property_utils_1.ensureProperty)(gatherDebug, ['@onecx/accelerator', 'topic', 'useBroadcastChannel'], 'V2');
6
8
  const topicInitDate = (0, ensure_property_utils_1.ensureProperty)(topicUseBroadcastChannel, ['@onecx/accelerator', 'topic', 'initDate'], Date.now());
7
9
  const topicTabId = (0, ensure_property_utils_1.ensureProperty)(topicInitDate, ['@onecx/accelerator', 'topic', 'tabId'], Math.ceil(globalThis.performance?.now?.() ?? 0));
8
10
  exports.acceleratorState = topicTabId;
@@ -1 +1 @@
1
- {"version":3,"file":"declarations.js","sourceRoot":"","sources":["../../../../../libs/accelerator/src/lib/declarations.ts"],"names":[],"mappings":";;;AAAA,yEAA8D;AAE9D,MAAM,wBAAwB,GAAG,IAAA,sCAAc,EAAC,UAAoB,EAAE,CAAC,oBAAoB,EAAE,OAAO,EAAE,qBAAqB,CAAC,EAAE,IAAsB,CAAC,CAAA;AACrJ,MAAM,aAAa,GAAG,IAAA,sCAAc,EAAC,wBAAwB,EAAE,CAAC,oBAAoB,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;AACvH,MAAM,UAAU,GAAG,IAAA,sCAAc,EAAC,aAAa,EAAE,CAAC,oBAAoB,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;AAEpH,sCAAgB"}
1
+ {"version":3,"file":"declarations.js","sourceRoot":"","sources":["../../../../../libs/accelerator/src/lib/declarations.ts"],"names":[],"mappings":";;;AAAA,yEAA8D;AAE9D,MAAM,cAAc,GAAG,IAAA,sCAAc,EAAC,UAAoB,EAAE,CAAC,oBAAoB,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,EAAyC,CAAC,CAAA;AACtJ,MAAM,WAAW,GAAG,IAAA,sCAAc,EAAC,cAAc,EAAE,CAAC,oBAAoB,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,EAAc,CAAC,CAAA;AAC/G,MAAM,wBAAwB,GAAG,IAAA,sCAAc,EAAC,WAAW,EAAE,CAAC,oBAAoB,EAAE,OAAO,EAAE,qBAAqB,CAAC,EAAE,IAAsB,CAAC,CAAA;AAC5I,MAAM,aAAa,GAAG,IAAA,sCAAc,EAAC,wBAAwB,EAAE,CAAC,oBAAoB,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;AACvH,MAAM,UAAU,GAAG,IAAA,sCAAc,EAAC,aAAa,EAAE,CAAC,oBAAoB,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;AAEpH,sCAAgB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Implementation of the Scatter-Gather pattern.
3
+ */
4
+ export declare class Gatherer<Request, Response> {
5
+ private static id;
6
+ private readonly topic;
7
+ private readonly ownIds;
8
+ private readonly topicSub;
9
+ private readonly topicName;
10
+ constructor(name: string, version: number, callback: (request: Request) => Promise<Response>);
11
+ destroy(): void;
12
+ gather(request: Request): Promise<Response[]>;
13
+ private logReceivedIfDebug;
14
+ private logAnsweredIfDebug;
15
+ private logIfDebug;
16
+ private isOwnerOfRequest;
17
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Gatherer = void 0;
4
+ const topic_1 = require("../topic/topic");
5
+ const declarations_1 = require("../declarations");
6
+ /**
7
+ * Implementation of the Scatter-Gather pattern.
8
+ */
9
+ class Gatherer {
10
+ static id = 0;
11
+ topic;
12
+ ownIds = new Set();
13
+ topicSub = null;
14
+ topicName;
15
+ constructor(name, version, callback) {
16
+ this.topicName = name;
17
+ this.logIfDebug(name, `Gatherer ${name}: ${version} created`);
18
+ this.topic = new topic_1.Topic(name, version, false);
19
+ // Perform a callback every time a request is received in the topic.
20
+ this.topicSub = this.topic.subscribe((m) => {
21
+ if (!this.isOwnerOfRequest(m) && declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises) {
22
+ this.logReceivedIfDebug(name, version, m);
23
+ if (!declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises[m.id]) {
24
+ console.warn('Expected an array of promises to gather for id ', m.id, ' but the id was not present');
25
+ return;
26
+ }
27
+ let resolve;
28
+ declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises[m.id].push(new Promise((r) => {
29
+ resolve = r;
30
+ }));
31
+ callback(m.request).then((response) => {
32
+ resolve(response);
33
+ this.logAnsweredIfDebug(name, version, m, response);
34
+ });
35
+ }
36
+ });
37
+ }
38
+ destroy() {
39
+ this.logIfDebug(this.topic.name, `Gatherer ${this.topic.name}: ${this.topic.version} destroyed`);
40
+ this.topicSub?.unsubscribe();
41
+ this.topic.destroy();
42
+ for (const id of this.ownIds) {
43
+ if (declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises?.[id]) {
44
+ delete declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises[id];
45
+ }
46
+ }
47
+ }
48
+ async gather(request) {
49
+ if (!declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises) {
50
+ throw new Error('Gatherer is not initialized');
51
+ }
52
+ const id = Gatherer.id++;
53
+ // Save the id to ownIds to prevent processing own requests.
54
+ this.ownIds.add(id);
55
+ declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises[id] = [];
56
+ // Publish the request to the topic.
57
+ // This will trigger the callback for all instances of gatherer.
58
+ // Await is crucial here to ensure that promises are created before awaiting them.
59
+ // See Why Awaiting the Promise Works in dev-docs/topics/scheduling.adoc.
60
+ const message = { id, request };
61
+ await this.topic.publish(message);
62
+ const promises = declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises[id];
63
+ delete declarations_1.acceleratorState['@onecx/accelerator'].gatherer.promises[id];
64
+ this.ownIds.delete(id);
65
+ return Promise.all(promises).then((v) => {
66
+ this.logIfDebug(this.topicName, 'Finished gathering responses', v);
67
+ return v;
68
+ });
69
+ }
70
+ logReceivedIfDebug(name, version, m) {
71
+ this.logIfDebug(name, 'Gatherer ' + name + ': ' + version + ' received request ' + m.request);
72
+ }
73
+ logAnsweredIfDebug(name, version, m, response) {
74
+ this.logIfDebug(name, 'Gatherer ' + name + ': ' + version + ' answered request ' + m.request + ' with response', response);
75
+ }
76
+ logIfDebug(name, ...args) {
77
+ if (declarations_1.acceleratorState['@onecx/accelerator'].gatherer.debug.includes(name)) {
78
+ console.log(...args);
79
+ }
80
+ }
81
+ isOwnerOfRequest(m) {
82
+ return this.ownIds.has(m.id);
83
+ }
84
+ }
85
+ exports.Gatherer = Gatherer;
86
+ //# sourceMappingURL=gatherer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gatherer.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/gatherer.ts"],"names":[],"mappings":";;;AACA,0CAAsC;AAEtC,kDAAkD;AAElD;;GAEG;AACH,MAAa,QAAQ;IACX,MAAM,CAAC,EAAE,GAAG,CAAC,CAAA;IACJ,KAAK,CAAyC;IAC9C,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAC1B,QAAQ,GAAwB,IAAI,CAAA;IACpC,SAAS,CAAQ;IAElC,YAAY,IAAY,EAAE,OAAe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