@onecx/accelerator 8.0.0-rc.1 → 8.0.0-rc.10
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/README.md +12 -7
- package/dist/index.cjs +680 -0
- package/dist/index.mjs +649 -0
- package/package.json +17 -12
- package/src/index.d.ts +3 -0
- package/src/index.js +14 -14
- package/src/index.js.map +1 -1
- package/src/lib/declarations.d.ts +40 -30
- package/src/lib/declarations.js +6 -10
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/topic/message.d.ts +0 -5
- package/src/lib/topic/message.js +5 -8
- package/src/lib/topic/message.js.map +1 -1
- package/src/lib/topic/mocks/broadcast-channel.mock.js +1 -5
- package/src/lib/topic/mocks/broadcast-channel.mock.js.map +1 -1
- package/src/lib/topic/mocks/fake-topic.js +5 -9
- package/src/lib/topic/mocks/fake-topic.js.map +1 -1
- package/src/lib/topic/syncable-topic.js +2 -6
- package/src/lib/topic/syncable-topic.js.map +1 -1
- package/src/lib/topic/topic-data-message.js +2 -6
- package/src/lib/topic/topic-data-message.js.map +1 -1
- package/src/lib/topic/topic-message-type.js +0 -2
- package/src/lib/topic/topic-message.js +5 -9
- package/src/lib/topic/topic-message.js.map +1 -1
- package/src/lib/topic/topic-publisher.d.ts +3 -0
- package/src/lib/topic/topic-publisher.js +24 -17
- package/src/lib/topic/topic-publisher.js.map +1 -1
- package/src/lib/topic/topic-resolve-message.js +2 -6
- package/src/lib/topic/topic-resolve-message.js.map +1 -1
- package/src/lib/topic/topic.d.ts +4 -2
- package/src/lib/topic/topic.js +50 -43
- package/src/lib/topic/topic.js.map +1 -1
- package/src/lib/utils/create-logger.utils.d.ts +42 -0
- package/src/lib/utils/create-logger.utils.js +37 -0
- package/src/lib/utils/create-logger.utils.js.map +1 -0
- package/src/lib/utils/date.utils.js +2 -6
- package/src/lib/utils/date.utils.js.map +1 -1
- package/src/lib/utils/ensure-property.utils.d.ts +89 -0
- package/src/lib/utils/ensure-property.utils.js +17 -0
- package/src/lib/utils/ensure-property.utils.js.map +1 -0
- package/src/lib/utils/gatherer.d.ts +1 -2
- package/src/lib/utils/gatherer.js +22 -28
- package/src/lib/utils/gatherer.js.map +1 -1
- package/src/lib/utils/get-normalized-browser-locales.utils.js +6 -8
- package/src/lib/utils/get-normalized-browser-locales.utils.js.map +1 -1
- package/src/lib/utils/get-onecx-shared-recommendations.d.ts +9 -0
- package/src/lib/utils/get-onecx-shared-recommendations.js +11 -0
- package/src/lib/utils/get-onecx-shared-recommendations.js.map +1 -0
- package/src/lib/utils/is-test.utils.js +1 -4
- package/src/lib/utils/is-test.utils.js.map +1 -1
- package/src/lib/utils/logger.utils.d.ts +1 -0
- package/src/lib/utils/logger.utils.js +4 -0
- package/src/lib/utils/logger.utils.js.map +1 -0
- package/src/lib/utils/logs.utils.d.ts +0 -1
- package/src/lib/utils/logs.utils.js +11 -18
- package/src/lib/utils/logs.utils.js.map +1 -1
- package/src/lib/utils/normalize-locales.utils.js +1 -4
- package/src/lib/utils/normalize-locales.utils.js.map +1 -1
- package/src/lib/utils/path.utils.js +10 -8
- package/src/lib/utils/path.utils.js.map +1 -1
- package/src/version.d.ts +2 -0
- package/src/version.js +3 -0
- package/src/version.js.map +1 -0
- package/migrations/index.d.ts +0 -1
- package/migrations/index.js +0 -5
- package/migrations/index.js.map +0 -1
- package/migrations/v6/migrate-onecx-to-v6.d.ts +0 -2
- package/migrations/v6/migrate-onecx-to-v6.js +0 -8
- package/migrations/v6/migrate-onecx-to-v6.js.map +0 -1
- package/migrations.json +0 -34
package/src/lib/topic/topic.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Topic extends topic_publisher_1.TopicPublisher {
|
|
1
|
+
import { filter, map } from 'rxjs/operators';
|
|
2
|
+
import { BehaviorSubject, } from 'rxjs';
|
|
3
|
+
import { TopicMessage } from './topic-message';
|
|
4
|
+
import { TopicPublisher } from './topic-publisher';
|
|
5
|
+
import { increaseInstanceCount, isStatsEnabled } from '../utils/logs.utils';
|
|
6
|
+
import { createLogger } from '../utils/logger.utils';
|
|
7
|
+
import { acceleratorState } from '../declarations';
|
|
8
|
+
export class Topic extends TopicPublisher {
|
|
9
|
+
logger = createLogger(`Topic:${this.name}`);
|
|
11
10
|
isInitializedPromise;
|
|
12
|
-
data = new
|
|
11
|
+
data = new BehaviorSubject(undefined);
|
|
13
12
|
isInit = false;
|
|
14
13
|
resolveInitPromise;
|
|
15
14
|
windowEventListener = (m) => this.onWindowMessage(m);
|
|
16
15
|
readBroadcastChannel;
|
|
16
|
+
readBroadcastChannelV2;
|
|
17
17
|
constructor(name, version, sendGetMessage = true) {
|
|
18
18
|
super(name, version);
|
|
19
|
-
|
|
20
|
-
window['@onecx/accelerator'].topic ??= {};
|
|
21
|
-
window['@onecx/accelerator'].topic.initDate ??= Date.now();
|
|
22
|
-
if (window['@onecx/accelerator']?.topic?.useBroadcastChannel) {
|
|
19
|
+
if (acceleratorState['@onecx/accelerator'].topic.useBroadcastChannel) {
|
|
23
20
|
if (typeof BroadcastChannel === 'undefined') {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
window['@onecx/accelerator'].topic ??= {};
|
|
27
|
-
window['@onecx/accelerator'].topic.useBroadcastChannel = false;
|
|
21
|
+
this.logger.info('BroadcastChannel not supported. Disabling BroadcastChannel for topic');
|
|
22
|
+
acceleratorState['@onecx/accelerator'].topic.useBroadcastChannel = false;
|
|
28
23
|
}
|
|
29
24
|
else {
|
|
30
25
|
this.readBroadcastChannel = new BroadcastChannel(`Topic-${this.name}|${this.version}`);
|
|
26
|
+
this.readBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${acceleratorState['@onecx/accelerator'].topic.tabId}`);
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
|
-
if (
|
|
34
|
-
|
|
29
|
+
if (isStatsEnabled()) {
|
|
30
|
+
increaseInstanceCount(this.name);
|
|
35
31
|
}
|
|
36
32
|
this.isInitializedPromise = new Promise((resolve) => {
|
|
37
33
|
this.resolveInitPromise = resolve;
|
|
38
34
|
});
|
|
39
|
-
|
|
35
|
+
const addEventListener = globalThis.addEventListener;
|
|
36
|
+
if (typeof addEventListener === 'function') {
|
|
37
|
+
addEventListener('message', this.windowEventListener);
|
|
38
|
+
}
|
|
40
39
|
this.readBroadcastChannel?.addEventListener('message', (m) => this.onBroadcastChannelMessage(m));
|
|
40
|
+
this.readBroadcastChannelV2?.addEventListener('message', (m) => this.onBroadcastChannelMessageV2(m));
|
|
41
41
|
if (sendGetMessage) {
|
|
42
|
-
if (
|
|
43
|
-
Date.now() -
|
|
42
|
+
if (acceleratorState['@onecx/accelerator'].topic.initDate &&
|
|
43
|
+
Date.now() - acceleratorState['@onecx/accelerator'].topic.initDate < 2000) {
|
|
44
44
|
// Delay the get message a bit to give other topics time to initialize
|
|
45
45
|
setTimeout(() => {
|
|
46
46
|
if (!this.isInit) {
|
|
47
|
-
const message = new
|
|
47
|
+
const message = new TopicMessage("TopicGet" /* TopicMessageType.TopicGet */, this.name, this.version);
|
|
48
48
|
this.sendMessage(message);
|
|
49
49
|
}
|
|
50
50
|
}, 100);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
const message = new
|
|
53
|
+
const message = new TopicMessage("TopicGet" /* TopicMessageType.TopicGet */, this.name, this.version);
|
|
54
54
|
this.sendMessage(message);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -59,7 +59,7 @@ class Topic extends topic_publisher_1.TopicPublisher {
|
|
|
59
59
|
return this.isInitializedPromise;
|
|
60
60
|
}
|
|
61
61
|
asObservable() {
|
|
62
|
-
return this.data.asObservable().pipe(
|
|
62
|
+
return this.data.asObservable().pipe(filter(() => this.isInit), map((d) => d.data));
|
|
63
63
|
}
|
|
64
64
|
subscribe(observerOrNext, error, complete) {
|
|
65
65
|
return this.asObservable().subscribe(observerOrNext, error, complete);
|
|
@@ -98,13 +98,18 @@ class Topic extends topic_publisher_1.TopicPublisher {
|
|
|
98
98
|
return this.asObservable().toPromise();
|
|
99
99
|
}
|
|
100
100
|
destroy() {
|
|
101
|
-
|
|
101
|
+
const removeEventListener = globalThis.removeEventListener;
|
|
102
|
+
if (typeof removeEventListener === 'function') {
|
|
103
|
+
removeEventListener('message', this.windowEventListener, true);
|
|
104
|
+
}
|
|
102
105
|
this.readBroadcastChannel?.close();
|
|
103
106
|
this.publishBroadcastChannel?.close();
|
|
107
|
+
this.readBroadcastChannelV2?.close();
|
|
108
|
+
this.publishBroadcastChannelV2?.close();
|
|
104
109
|
}
|
|
105
110
|
onWindowMessage(m) {
|
|
106
|
-
if (
|
|
107
|
-
|
|
111
|
+
if (m.data?.name === this.name && m.data?.version === this.version) {
|
|
112
|
+
this.logger.debug('received message via window', m.data);
|
|
108
113
|
}
|
|
109
114
|
switch (m.data.type) {
|
|
110
115
|
case "TopicNext" /* TopicMessageType.TopicNext */: {
|
|
@@ -129,9 +134,11 @@ class Topic extends topic_publisher_1.TopicPublisher {
|
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
onBroadcastChannelMessage(m) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
this.disableBroadcastChannelV2();
|
|
138
|
+
this.onBroadcastChannelMessageV2(m);
|
|
139
|
+
}
|
|
140
|
+
onBroadcastChannelMessageV2(m) {
|
|
141
|
+
this.logger.debug('received message', m.data);
|
|
135
142
|
switch (m.data.type) {
|
|
136
143
|
case "TopicNext" /* TopicMessageType.TopicNext */: {
|
|
137
144
|
this.handleTopicNextMessage(m);
|
|
@@ -150,15 +157,16 @@ class Topic extends topic_publisher_1.TopicPublisher {
|
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
159
|
disableBroadcastChannel() {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (window['@onecx/accelerator'].topic.useBroadcastChannel === true) {
|
|
156
|
-
console.log('Disabling BroadcastChannel for topic');
|
|
160
|
+
if (acceleratorState['@onecx/accelerator'].topic.useBroadcastChannel === true) {
|
|
161
|
+
this.logger.info('Disabling BroadcastChannel for topic');
|
|
157
162
|
}
|
|
158
|
-
|
|
163
|
+
acceleratorState['@onecx/accelerator'].topic.useBroadcastChannel = false;
|
|
159
164
|
}
|
|
160
|
-
|
|
161
|
-
|
|
165
|
+
disableBroadcastChannelV2() {
|
|
166
|
+
if (acceleratorState['@onecx/accelerator'].topic.useBroadcastChannel === "V2") {
|
|
167
|
+
this.logger.info('Disabling BroadcastChannel V2 for topic');
|
|
168
|
+
}
|
|
169
|
+
acceleratorState['@onecx/accelerator'].topic.useBroadcastChannel = true;
|
|
162
170
|
}
|
|
163
171
|
handleTopicResolveMessage(m) {
|
|
164
172
|
const publishPromiseResolver = this.publishPromiseResolver[m.data.resolveId];
|
|
@@ -170,7 +178,7 @@ class Topic extends topic_publisher_1.TopicPublisher {
|
|
|
170
178
|
delete this.publishPromiseResolver[m.data.resolveId];
|
|
171
179
|
}
|
|
172
180
|
catch (error) {
|
|
173
|
-
|
|
181
|
+
this.logger.error('Error handling TopicResolveMessage:', error);
|
|
174
182
|
}
|
|
175
183
|
}
|
|
176
184
|
}
|
|
@@ -193,9 +201,8 @@ class Topic extends topic_publisher_1.TopicPublisher {
|
|
|
193
201
|
this.isInit &&
|
|
194
202
|
m.data.timestamp === this.data.value.timestamp &&
|
|
195
203
|
((m.data.id && !this.data.value.id) || (!m.data.id && this.data.value.id))) {
|
|
196
|
-
|
|
204
|
+
this.logger.warn('Message was dropped because of equal timestamps, because there was an old style message in the system. Please upgrade all libraries to the latest version.');
|
|
197
205
|
}
|
|
198
206
|
}
|
|
199
207
|
}
|
|
200
|
-
exports.Topic = Topic;
|
|
201
208
|
//# sourceMappingURL=topic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topic.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/topic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"topic.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/topic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EACL,eAAe,GAOhB,MAAM,MAAM,CAAA;AAEb,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,OAAO,KAAS,SAAQ,cAAiB;IAC5B,MAAM,GAAG,YAAY,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IAClD,oBAAoB,CAAe;IACnC,IAAI,GAAG,IAAI,eAAe,CAAkC,SAAS,CAAC,CAAA;IAEtE,MAAM,GAAG,KAAK,CAAA;IAChB,kBAAkB,CAA4C;IACrD,mBAAmB,GAAG,CAAC,CAA6B,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;IAC9E,oBAAoB,CAA8B;IAClD,sBAAsB,CAA8B;IAEvE,YAAY,IAAY,EAAE,OAAe,EAAE,cAAc,GAAG,IAAI;QAC9D,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEpB,IAAI,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC;YACrE,IAAI,OAAO,gBAAgB,KAAK,WAAW,EAAE,CAAC;gBAC5C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAA;gBACxF,gBAAgB,CAAC,oBAAoB,CAAC,CAA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AAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAC1E,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,4JAA4J,CAC7J,CAAA;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Debugger } from "debug";
|
|
2
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
3
|
+
/**
|
|
4
|
+
* Logger for a single component.
|
|
5
|
+
*
|
|
6
|
+
* Each property is a `debug` instance with a namespace of the form:
|
|
7
|
+
* `<libName>:<location>:<level>`
|
|
8
|
+
*/
|
|
9
|
+
export interface ComponentLogger {
|
|
10
|
+
/** Logs with namespace `<libName>:<location>:debug`. */
|
|
11
|
+
debug: Debugger;
|
|
12
|
+
/** Logs with namespace `<libName>:<location>:info`. */
|
|
13
|
+
info: Debugger;
|
|
14
|
+
/** Logs with namespace `<libName>:<location>:warn`. */
|
|
15
|
+
warn: Debugger;
|
|
16
|
+
/** Logs with namespace `<libName>:<location>:error`. */
|
|
17
|
+
error: Debugger;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Function that creates a {@link ComponentLogger} for a given component name.
|
|
21
|
+
*
|
|
22
|
+
* @param location - Where the logger is used (e.g. component, service, directive, pipe, guard).
|
|
23
|
+
* @returns A logger whose namespaces include the location.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const createLogger = createLoggerFactory("myLib");
|
|
28
|
+
* const log = createLogger("AuthPanel");
|
|
29
|
+
* log.warn("token missing");
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type CreateLogger = (location: string) => ComponentLogger;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a {@link CreateLogger} function for a given library name.
|
|
35
|
+
*
|
|
36
|
+
* Namespaces will follow the schema:
|
|
37
|
+
* `<libName>:<location>:<level>`
|
|
38
|
+
*
|
|
39
|
+
* @param libOrAppName - The library (or application) namespace prefix.
|
|
40
|
+
* @returns A function that creates component loggers.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createLoggerFactory(libOrAppName: string): CreateLogger;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
// Bind debug.log to console.log for proper output
|
|
3
|
+
debug.log = console.log.bind(console);
|
|
4
|
+
/**
|
|
5
|
+
* Creates a {@link CreateLogger} function for a given library name.
|
|
6
|
+
*
|
|
7
|
+
* Namespaces will follow the schema:
|
|
8
|
+
* `<libName>:<location>:<level>`
|
|
9
|
+
*
|
|
10
|
+
* @param libOrAppName - The library (or application) namespace prefix.
|
|
11
|
+
* @returns A function that creates component loggers.
|
|
12
|
+
*/
|
|
13
|
+
export function createLoggerFactory(libOrAppName) {
|
|
14
|
+
const prefix = libOrAppName.trim();
|
|
15
|
+
if (!prefix)
|
|
16
|
+
throw new Error("createLoggerFactory(libOrAppName): libOrAppName must be a non-empty string.");
|
|
17
|
+
/**
|
|
18
|
+
* Creates a logger for a specific location.
|
|
19
|
+
*
|
|
20
|
+
* Note: This function is produced by {@link createLoggerFactory}. Its TS-Doc is
|
|
21
|
+
* provided via the {@link CreateLogger} type so editors can show it in IntelliSense.
|
|
22
|
+
*/
|
|
23
|
+
const createLogger = (location) => {
|
|
24
|
+
const trimmedLocation = location.trim();
|
|
25
|
+
if (!trimmedLocation)
|
|
26
|
+
throw new Error("createLogger(location): location must be a non-empty string.");
|
|
27
|
+
const ns = (level) => `${prefix}:${trimmedLocation}:${level}`;
|
|
28
|
+
return {
|
|
29
|
+
debug: debug(ns("debug")),
|
|
30
|
+
info: debug(ns("info")),
|
|
31
|
+
warn: debug(ns("warn")),
|
|
32
|
+
error: debug(ns("error")),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
return createLogger;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=create-logger.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-logger.utils.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/create-logger.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAuC7C,kDAAkD;AAClD,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,YAAoB;IACtD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;IACnC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IAE5G;;;;;OAKG;IACH,MAAM,YAAY,GAAiB,CAAC,QAAgB,EAAE,EAAE;QACtD,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC,eAAe;YAAE,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;QAEtG,MAAM,EAAE,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,eAAe,IAAI,KAAK,EAAE,CAAC;QAExE,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;YACzB,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;YACvB,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;YACvB,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;SAC1B,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidDate = isValidDate;
|
|
4
|
-
exports.getUTCDateWithoutTimezoneIssues = getUTCDateWithoutTimezoneIssues;
|
|
5
|
-
function isValidDate(value) {
|
|
1
|
+
export function isValidDate(value) {
|
|
6
2
|
return value instanceof Date && !isNaN(value);
|
|
7
3
|
}
|
|
8
4
|
/**
|
|
@@ -11,7 +7,7 @@ function isValidDate(value) {
|
|
|
11
7
|
* @param date a date-time Date object
|
|
12
8
|
* @returns the date without time / timezone issues
|
|
13
9
|
*/
|
|
14
|
-
function getUTCDateWithoutTimezoneIssues(date) {
|
|
10
|
+
export function getUTCDateWithoutTimezoneIssues(date) {
|
|
15
11
|
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0));
|
|
16
12
|
}
|
|
17
13
|
//# sourceMappingURL=date.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.utils.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/date.utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date.utils.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/date.utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,KAAU;IACpC,OAAO,KAAK,YAAY,IAAI,IAAI,CAAC,KAAK,CAAC,KAAY,CAAC,CAAA;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAAC,IAAU;IACxD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACzF,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
type PathKeys<T, Depth extends number = 5> = [Depth] extends [never] ? never : T extends object ? {
|
|
2
|
+
[K in keyof T]-?: K extends string | number ? T[K] extends object | undefined ? `${K}` | `${K}.${PathKeys<NonNullable<T[K]>, Prev[Depth]>}` : `${K}` : never;
|
|
3
|
+
}[keyof T] : never;
|
|
4
|
+
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
|
5
|
+
type PathToTuple<S extends string> = S extends `${infer First}.${infer Rest}` ? [First, ...PathToTuple<Rest>] : [S];
|
|
6
|
+
type ValidPaths<T> = PathKeys<T> extends infer P ? P extends string ? PathToTuple<P> : never : never;
|
|
7
|
+
type SetPathTuple<T, Path extends ReadonlyArray<string | number>, Value> = Path extends readonly [infer Key, ...infer Rest] ? Key extends string | number ? Rest extends ReadonlyArray<string | number> ? Rest['length'] extends 0 ? T & {
|
|
8
|
+
[K in Key]: Value;
|
|
9
|
+
} : {
|
|
10
|
+
[K in keyof T | Key]-?: K extends Key ? K extends keyof T ? SetPathTuple<NonNullable<T[K]>, Rest, Value> : SetPathTuple<object, Rest, Value> : K extends keyof T ? T[K] : never;
|
|
11
|
+
} : never : never : never;
|
|
12
|
+
/**
|
|
13
|
+
* Ensures that a property exists at the specified path within an object.
|
|
14
|
+
* Creates intermediate objects as needed and sets the final property to the initial value
|
|
15
|
+
* only if the property is currently null or undefined.
|
|
16
|
+
*
|
|
17
|
+
* This function is useful for safely initializing deeply nested properties without worrying
|
|
18
|
+
* about intermediate objects being missing. It will not overwrite existing values - only
|
|
19
|
+
* null or undefined values are replaced.
|
|
20
|
+
*
|
|
21
|
+
* **Returns the typed object** - you should use the return value to access the properties
|
|
22
|
+
* with full type safety.
|
|
23
|
+
*
|
|
24
|
+
* Supports property names with special characters that can only be accessed via bracket notation.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The object type
|
|
27
|
+
* @template Path - The path as a tuple of keys
|
|
28
|
+
* @template Value - The type of the value to set
|
|
29
|
+
* @param obj - The object to modify
|
|
30
|
+
* @param path - An array representing the path to the property (e.g., ['user', 'profile', 'name'])
|
|
31
|
+
* @param initialValue - The value to set if the property is currently null or undefined
|
|
32
|
+
* @returns The same object with updated type information including the new property
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Recommended: Use the return value for full type safety
|
|
36
|
+
* const g = ensureProperty(globalThis, ['myApp', 'config', 'debug'], false);
|
|
37
|
+
* if (g.myApp.config.debug) {
|
|
38
|
+
* console.log('Debug mode enabled');
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // For regular property names (no special chars), both ways work:
|
|
43
|
+
* // 1. Using return value (recommended for consistency)
|
|
44
|
+
* let config = {};
|
|
45
|
+
* config = ensureProperty(config, ['database', 'host'], 'localhost');
|
|
46
|
+
* console.log(config.database.host); // TypeScript knows about this
|
|
47
|
+
*
|
|
48
|
+
* // 2. Without using return value (works for non-special chars)
|
|
49
|
+
* const settings = {};
|
|
50
|
+
* ensureProperty(settings, ['server', 'port'], 3000);
|
|
51
|
+
* console.log(settings.server.port); // Also works, but less type-safe
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // For globalThis with regular names, you can declare it globally:
|
|
55
|
+
* declare global {
|
|
56
|
+
* var myApp: { config: { debug: boolean } };
|
|
57
|
+
* }
|
|
58
|
+
* ensureProperty(globalThis, ['myApp', 'config', 'debug'], false);
|
|
59
|
+
* if (globalThis.myApp.config.debug) { // Works without using return value
|
|
60
|
+
* console.log('Debug enabled');
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // For special characters, MUST use return value:
|
|
65
|
+
* const g = ensureProperty(globalThis, ['@onecx/accelerator', 'version'], '1.0.0');
|
|
66
|
+
* console.log(g['@onecx/accelerator'].version); // TypeScript knows this exists
|
|
67
|
+
* // globalThis['@onecx/accelerator'].version won't work without the return value
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Won't overwrite existing values
|
|
71
|
+
* let obj = { name: 'John' };
|
|
72
|
+
* obj = ensureProperty(obj, ['name'], 'Jane');
|
|
73
|
+
* console.log(obj.name); // Still 'John'
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Replaces null values
|
|
77
|
+
* let obj = { name: null };
|
|
78
|
+
* obj = ensureProperty(obj, ['name'], 'Default');
|
|
79
|
+
* console.log(obj.name); // Now 'Default'
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* // Nested paths with special characters
|
|
83
|
+
* const g = ensureProperty(globalThis, ['@myapp/config', 'feature-flags', 'enabled'], true);
|
|
84
|
+
* console.log(g['@myapp/config']['feature-flags'].enabled);
|
|
85
|
+
*/
|
|
86
|
+
export declare function ensureProperty<const Path extends ReadonlyArray<string | number>, Value>(obj: typeof globalThis, path: Path, initialValue: Value): typeof globalThis & SetPathTuple<typeof globalThis, Path, Value>;
|
|
87
|
+
export declare function ensureProperty<T extends object, const Path extends ValidPaths<T>, Value>(obj: T, path: Path, initialValue: Value): T & SetPathTuple<T, Path, Value>;
|
|
88
|
+
export declare function ensureProperty<T extends object, const Path extends ReadonlyArray<string | number>, Value>(obj: T, path: Path, initialValue: Value): T & SetPathTuple<T, Path, Value>;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function ensureProperty(obj, path, initialValue) {
|
|
2
|
+
let current = obj;
|
|
3
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
4
|
+
const key = path[i];
|
|
5
|
+
if (current[key] == null || typeof current[key] !== 'object') {
|
|
6
|
+
current[key] = {};
|
|
7
|
+
}
|
|
8
|
+
current = current[key];
|
|
9
|
+
}
|
|
10
|
+
const lastKey = path.at(-1);
|
|
11
|
+
if (lastKey === undefined) {
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
current[lastKey] ??= initialValue;
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ensure-property.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-property.utils.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/ensure-property.utils.ts"],"names":[],"mappings":"AAmJA,MAAM,UAAU,cAAc,CAC1B,GAAM,EACN,IAAU,EACV,YAAmB;IAEnB,IAAI,OAAO,GAAQ,GAAG,CAAC;IAEvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC3D,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACtB,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,GAAuC,CAAC;IACnD,CAAC;IACD,OAAO,CAAC,OAAO,CAAC,KAAK,YAAY,CAAC;IAClC,OAAO,GAAuC,CAAC;AACnD,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import '../declarations';
|
|
2
1
|
/**
|
|
3
2
|
* Implementation of the Scatter-Gather pattern.
|
|
4
3
|
*/
|
|
5
4
|
export declare class Gatherer<Request, Response> {
|
|
5
|
+
private readonly logger;
|
|
6
6
|
private static id;
|
|
7
7
|
private readonly topic;
|
|
8
8
|
private readonly ownIds;
|
|
@@ -13,6 +13,5 @@ export declare class Gatherer<Request, Response> {
|
|
|
13
13
|
gather(request: Request): Promise<Response[]>;
|
|
14
14
|
private logReceivedIfDebug;
|
|
15
15
|
private logAnsweredIfDebug;
|
|
16
|
-
private logIfDebug;
|
|
17
16
|
private isOwnerOfRequest;
|
|
18
17
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const topic_1 = require("../topic/topic");
|
|
5
|
-
require("../declarations");
|
|
1
|
+
import { Topic } from '../topic/topic';
|
|
2
|
+
import { createLogger } from './logger.utils';
|
|
3
|
+
import { acceleratorState } from '../declarations';
|
|
6
4
|
/**
|
|
7
5
|
* Implementation of the Scatter-Gather pattern.
|
|
8
6
|
*/
|
|
9
|
-
class Gatherer {
|
|
7
|
+
export class Gatherer {
|
|
8
|
+
logger;
|
|
10
9
|
static id = 0;
|
|
11
10
|
topic;
|
|
12
11
|
ownIds = new Set();
|
|
@@ -14,18 +13,19 @@ class Gatherer {
|
|
|
14
13
|
topicName;
|
|
15
14
|
constructor(name, version, callback) {
|
|
16
15
|
this.topicName = name;
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
16
|
+
this.logger = createLogger(`Gatherer:${name}`);
|
|
17
|
+
this.logger.debug(`Gatherer ${name}: ${version} created`);
|
|
18
|
+
this.topic = new Topic(name, version, false);
|
|
19
19
|
// Perform a callback every time a request is received in the topic.
|
|
20
20
|
this.topicSub = this.topic.subscribe((m) => {
|
|
21
|
-
if (!this.isOwnerOfRequest(m) &&
|
|
21
|
+
if (!this.isOwnerOfRequest(m) && acceleratorState['@onecx/accelerator'].gatherer.promises) {
|
|
22
22
|
this.logReceivedIfDebug(name, version, m);
|
|
23
|
-
if (!
|
|
24
|
-
|
|
23
|
+
if (!acceleratorState['@onecx/accelerator'].gatherer.promises[m.id]) {
|
|
24
|
+
this.logger.warn('Expected an array of promises to gather for id ', m.id, ' but the id was not present');
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
let resolve;
|
|
28
|
-
|
|
28
|
+
acceleratorState['@onecx/accelerator'].gatherer.promises[m.id].push(new Promise((r) => {
|
|
29
29
|
resolve = r;
|
|
30
30
|
}));
|
|
31
31
|
callback(m.request).then((response) => {
|
|
@@ -36,51 +36,45 @@ class Gatherer {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
destroy() {
|
|
39
|
-
this.
|
|
39
|
+
this.logger.debug(`Gatherer ${this.topic.name}: ${this.topic.version} destroyed`);
|
|
40
40
|
this.topicSub?.unsubscribe();
|
|
41
41
|
this.topic.destroy();
|
|
42
42
|
for (const id of this.ownIds) {
|
|
43
|
-
if (
|
|
44
|
-
delete
|
|
43
|
+
if (acceleratorState['@onecx/accelerator'].gatherer.promises?.[id]) {
|
|
44
|
+
delete acceleratorState['@onecx/accelerator'].gatherer.promises[id];
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
async gather(request) {
|
|
49
|
-
if (!
|
|
49
|
+
if (!acceleratorState['@onecx/accelerator'].gatherer?.promises) {
|
|
50
50
|
throw new Error('Gatherer is not initialized');
|
|
51
51
|
}
|
|
52
52
|
const id = Gatherer.id++;
|
|
53
53
|
// Save the id to ownIds to prevent processing own requests.
|
|
54
54
|
this.ownIds.add(id);
|
|
55
|
-
|
|
55
|
+
acceleratorState['@onecx/accelerator'].gatherer.promises[id] = [];
|
|
56
56
|
// Publish the request to the topic.
|
|
57
57
|
// This will trigger the callback for all instances of gatherer.
|
|
58
58
|
// Await is crucial here to ensure that promises are created before awaiting them.
|
|
59
59
|
// See Why Awaiting the Promise Works in dev-docs/topics/scheduling.adoc.
|
|
60
60
|
const message = { id, request };
|
|
61
61
|
await this.topic.publish(message);
|
|
62
|
-
const promises =
|
|
63
|
-
delete
|
|
62
|
+
const promises = acceleratorState['@onecx/accelerator'].gatherer.promises[id];
|
|
63
|
+
delete acceleratorState['@onecx/accelerator'].gatherer.promises[id];
|
|
64
64
|
this.ownIds.delete(id);
|
|
65
65
|
return Promise.all(promises).then((v) => {
|
|
66
|
-
this.
|
|
66
|
+
this.logger.debug('Finished gathering responses', v);
|
|
67
67
|
return v;
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
logReceivedIfDebug(name, version, m) {
|
|
71
|
-
this.
|
|
71
|
+
this.logger.debug('Gatherer ' + name + ': ' + version + ' received request ' + m.request);
|
|
72
72
|
}
|
|
73
73
|
logAnsweredIfDebug(name, version, m, response) {
|
|
74
|
-
this.
|
|
75
|
-
}
|
|
76
|
-
logIfDebug(name, ...args) {
|
|
77
|
-
if (window['@onecx/accelerator']?.gatherer?.debug?.includes(name)) {
|
|
78
|
-
console.log(...args);
|
|
79
|
-
}
|
|
74
|
+
this.logger.debug('Gatherer ' + name + ': ' + version + ' answered request ' + m.request + ' with response', response);
|
|
80
75
|
}
|
|
81
76
|
isOwnerOfRequest(m) {
|
|
82
77
|
return this.ownIds.has(m.id);
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
|
-
exports.Gatherer = Gatherer;
|
|
86
80
|
//# sourceMappingURL=gatherer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gatherer.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/gatherer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gatherer.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/gatherer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD;;GAEG;AACH,MAAM,OAAO,QAAQ;IACF,MAAM,CAAiC;IAChD,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,EAAE,QAAiD;QAC1F,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,YAAY,IAAI,EAAE,CAAC,C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,CAAC,QAAQ,CAAC,EAAE,CAAwB,CAAA;QACpG,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACnE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACtB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,CAAC,CAAC,CAAA;YACpD,OAAO,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,kBAAkB,CAAC,IAAY,EAAE,OAAe,EAAE,CAAmC;QAC3F,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,oBAAoB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAA;IAC3F,CAAC;IAEO,kBAAkB,CAAC,IAAY,EAAE,OAAe,EAAE,CAAmC,EAAE,QAAkB;QAC/G,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,WAAW,GAAG,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,oBAAoB,GAAG,CAAC,CAAC,OAAO,GAAG,gBAAgB,EACzF,QAAQ,CACT,CAAA;IACH,CAAC;IAEO,gBAAgB,CAAC,CAAmC;QAC1D,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function getNormalizedBrowserLocales() {
|
|
6
|
-
if (typeof window === 'undefined' || typeof window.navigator === 'undefined') {
|
|
1
|
+
import { normalizeLocales } from './normalize-locales.utils';
|
|
2
|
+
export function getNormalizedBrowserLocales() {
|
|
3
|
+
const navigator = globalThis.navigator;
|
|
4
|
+
if (!navigator) {
|
|
7
5
|
return ['en'];
|
|
8
6
|
}
|
|
9
|
-
const langs =
|
|
10
|
-
return
|
|
7
|
+
const langs = navigator.languages || [navigator.language];
|
|
8
|
+
return normalizeLocales(langs.filter(Boolean));
|
|
11
9
|
}
|
|
12
10
|
//# sourceMappingURL=get-normalized-browser-locales.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-normalized-browser-locales.utils.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/get-normalized-browser-locales.utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-normalized-browser-locales.utils.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/get-normalized-browser-locales.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAE5D,MAAM,UAAU,2BAA2B;IACzC,MAAM,SAAS,GAAG,UAAU,CAAC,SAAkC,CAAA;IAC/D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;IACzD,OAAO,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SharedLibraryConfig {
|
|
2
|
+
singleton?: boolean;
|
|
3
|
+
strictVersion?: boolean;
|
|
4
|
+
eager?: boolean;
|
|
5
|
+
requiredVersion?: string | false;
|
|
6
|
+
version?: string;
|
|
7
|
+
includeSecondaries?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function getOneCXSharedRecommendations(libraryName: string, sharedConfig: SharedLibraryConfig): false | SharedLibraryConfig;
|