@onecx/accelerator 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # accelerator
2
+
3
+ This library contains all framework independent accelerators.
4
+
5
+ ## Building
6
+
7
+ Run `nx build accelerator` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test accelerator` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@onecx/accelerator",
3
+ "version": "3.2.1",
4
+ "peerDependencies": {
5
+ "tslib": "^2.3.0",
6
+ "rxjs": "7.8.1"
7
+ },
8
+ "type": "commonjs",
9
+ "main": "./src/index.js",
10
+ "typings": "./src/index.d.ts",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ }
14
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/topic/topic';
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/topic/topic"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/accelerator/src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAiC"}
@@ -0,0 +1,5 @@
1
+ export declare class Message {
2
+ type: string;
3
+ timestamp: number;
4
+ constructor(type: string);
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Message = void 0;
4
+ class Message {
5
+ type;
6
+ timestamp;
7
+ constructor(type) {
8
+ this.type = type;
9
+ this.timestamp = window.performance.now();
10
+ }
11
+ }
12
+ exports.Message = Message;
13
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/message.ts"],"names":[],"mappings":";;;AAAA,MAAa,OAAO;IAGC;IAFnB,SAAS,CAAQ;IAEjB,YAAmB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAC7B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,CAAA;IAC3C,CAAC;CACF;AAND,0BAMC"}
@@ -0,0 +1,6 @@
1
+ import { TopicMessage } from './topic-message';
2
+ import { TopicMessageType } from './topic-message-type';
3
+ export declare class TopicDataMessage<T> extends TopicMessage {
4
+ data: T;
5
+ constructor(type: TopicMessageType, name: string, version: number, data: T);
6
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TopicDataMessage = void 0;
4
+ const topic_message_1 = require("./topic-message");
5
+ class TopicDataMessage extends topic_message_1.TopicMessage {
6
+ data;
7
+ constructor(type, name, version, data) {
8
+ super(type, name, version);
9
+ this.data = data;
10
+ }
11
+ }
12
+ exports.TopicDataMessage = TopicDataMessage;
13
+ //# sourceMappingURL=topic-data-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic-data-message.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/topic-data-message.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAG9C,MAAa,gBAAoB,SAAQ,4BAAY;IACuB;IAA1E,YAAY,IAAsB,EAAE,IAAY,EAAE,OAAe,EAAS,IAAO;QAC/E,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QAD8C,SAAI,GAAJ,IAAI,CAAG;IAEjF,CAAC;CACF;AAJD,4CAIC"}
@@ -0,0 +1,4 @@
1
+ export declare const enum TopicMessageType {
2
+ TopicNext = "TopicNext",
3
+ TopicGet = "TopicGet"
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=topic-message-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic-message-type.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/topic-message-type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { Message } from "./message";
2
+ import { TopicMessageType } from "./topic-message-type";
3
+ export declare class TopicMessage extends Message {
4
+ name: string;
5
+ version: number;
6
+ constructor(type: TopicMessageType, name: string, version: number);
7
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TopicMessage = void 0;
4
+ const message_1 = require("./message");
5
+ class TopicMessage extends message_1.Message {
6
+ name;
7
+ version;
8
+ constructor(type, name, version) {
9
+ super(type);
10
+ this.name = name;
11
+ this.version = version;
12
+ }
13
+ }
14
+ exports.TopicMessage = TopicMessage;
15
+ //# sourceMappingURL=topic-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic-message.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/topic-message.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AAGpC,MAAa,YAAa,SAAQ,iBAAO;IAG5B;IACA;IAHT,YACE,IAAsB,EACf,IAAY,EACZ,OAAe;QAEtB,KAAK,CAAC,IAAI,CAAC,CAAC;QAHL,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;IAGxB,CAAC;CACF;AARH,oCAQG"}
@@ -0,0 +1,35 @@
1
+ import { Observable, Observer, OperatorFunction, Subscribable, Subscription, UnaryFunction } from 'rxjs';
2
+ export declare class Topic<T> implements Subscribable<T> {
3
+ private name;
4
+ private version;
5
+ isInitialized: Promise<void>;
6
+ private data;
7
+ private isInit;
8
+ private resolveInitPromise;
9
+ private eventListener;
10
+ constructor(name: string, version: number);
11
+ asObservable(): Observable<T>;
12
+ subscribe(observerOrNext?: Partial<Observer<T>> | ((value: T) => void), error?: (error: any) => void, complete?: () => void): Subscription;
13
+ /**
14
+ * This function does not offer read after write consistency!
15
+ * This means you cannot call it directly after publish, because the new value will not be there yet!
16
+ * This function will return undefined unti the isInitialized promise is resolved.
17
+ * @returns the current value of the topic in a synchronous way
18
+ */
19
+ getValue(): T | undefined;
20
+ pipe(): Observable<T>;
21
+ pipe<A>(op1: UnaryFunction<Observable<T>, A>): A;
22
+ pipe<A, B>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>): B;
23
+ pipe<A, B, C>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>): C;
24
+ pipe<A, B, C, D>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>): D;
25
+ pipe<A, B, C, D, E>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>): E;
26
+ pipe<A, B, C, D, E, F>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>): F;
27
+ pipe<A, B, C, D, E, F, G>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>): G;
28
+ pipe<A, B, C, D, E, F, G, H>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>): H;
29
+ pipe<A, B, C, D, E, F, G, H, I>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>): I;
30
+ pipe<A, B, C, D, E, F, G, H, I>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>, ...operations: OperatorFunction<any, any>[]): Observable<unknown>;
31
+ pipe<A, B, C, D, E, F, G, H, I>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>, ...operations: UnaryFunction<any, any>[]): unknown;
32
+ publish(value: T): void;
33
+ destroy(): void;
34
+ private onMessage;
35
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Topic = void 0;
4
+ const operators_1 = require("rxjs/operators");
5
+ const rxjs_1 = require("rxjs");
6
+ const topic_data_message_1 = require("./topic-data-message");
7
+ const topic_message_1 = require("./topic-message");
8
+ class Topic {
9
+ name;
10
+ version;
11
+ isInitialized;
12
+ data = new rxjs_1.BehaviorSubject(undefined);
13
+ isInit = false;
14
+ resolveInitPromise;
15
+ eventListener = (m) => this.onMessage(m);
16
+ constructor(name, version) {
17
+ this.name = name;
18
+ this.version = version;
19
+ this.isInitialized = new Promise((resolve) => {
20
+ this.resolveInitPromise = resolve;
21
+ });
22
+ window.addEventListener('message', this.eventListener);
23
+ const message = new topic_message_1.TopicMessage("TopicGet" /* TopicMessageType.TopicGet */, this.name, this.version);
24
+ window.postMessage(message, '*');
25
+ }
26
+ asObservable() {
27
+ return this.data.asObservable().pipe((0, operators_1.filter)(() => this.isInit), (0, operators_1.map)((d) => d.data));
28
+ }
29
+ subscribe(observerOrNext, error, complete) {
30
+ return this.asObservable().subscribe(observerOrNext, error, complete);
31
+ }
32
+ /**
33
+ * This function does not offer read after write consistency!
34
+ * This means you cannot call it directly after publish, because the new value will not be there yet!
35
+ * This function will return undefined unti the isInitialized promise is resolved.
36
+ * @returns the current value of the topic in a synchronous way
37
+ */
38
+ getValue() {
39
+ return this.isInit ? this.data.value.data : undefined;
40
+ }
41
+ pipe(...operations) {
42
+ return this.asObservable().pipe(...operations);
43
+ }
44
+ publish(value) {
45
+ const message = new topic_data_message_1.TopicDataMessage("TopicNext" /* TopicMessageType.TopicNext */, this.name, this.version, value);
46
+ window.postMessage(message, '*');
47
+ }
48
+ destroy() {
49
+ window.removeEventListener('message', this.eventListener, true);
50
+ }
51
+ onMessage(m) {
52
+ switch (m.data.type) {
53
+ case "TopicNext" /* TopicMessageType.TopicNext */:
54
+ if (m.data.name === this.name &&
55
+ m.data.version === this.version &&
56
+ (!this.data.value || (this.isInit && m.data.timestamp > this.data.value.timestamp))) {
57
+ this.isInit = true;
58
+ this.data.next(m.data);
59
+ this.resolveInitPromise();
60
+ }
61
+ break;
62
+ case "TopicGet" /* TopicMessageType.TopicGet */:
63
+ if (m.data.name === this.name && m.data.version === this.version && this.isInit && this.data.value) {
64
+ window.postMessage(this.data.value, '*');
65
+ m.stopImmediatePropagation();
66
+ m.stopPropagation();
67
+ }
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ exports.Topic = Topic;
73
+ //# sourceMappingURL=topic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/topic.ts"],"names":[],"mappings":";;;AAAA,8CAA4C;AAC5C,+BAAyH;AACzH,6DAAuD;AACvD,mDAA8C;AAG9C,MAAa,KAAK;IAQI;IAAsB;IAPnC,aAAa,CAAe;IAC3B,IAAI,GAAG,IAAI,sBAAe,CAAkC,SAAS,CAAC,CAAA;IAEtE,MAAM,GAAG,KAAK,CAAA;I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