@onecx/accelerator 5.52.10 → 5.53.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onecx/accelerator",
3
- "version": "5.52.10",
3
+ "version": "5.53.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,7 +8,8 @@
8
8
  },
9
9
  "peerDependencies": {
10
10
  "tslib": "^2.6.3",
11
- "rxjs": "^7.8.1"
11
+ "rxjs": "^7.8.1",
12
+ "@nx/module-federation": "20.4.0"
12
13
  },
13
14
  "type": "commonjs",
14
15
  "main": "./src/index.js",
package/src/index.d.ts CHANGED
@@ -7,3 +7,5 @@ export * from './lib/utils/date.utils';
7
7
  export * from './lib/utils/is-test.utils';
8
8
  export * from './lib/utils/normalize-locales.utils';
9
9
  export * from './lib/utils/get-normalized-browser-locales.utils';
10
+ export * from './lib/utils/ensure-property.utils';
11
+ export * from './lib/utils/get-onecx-shared-recommendations';
package/src/index.js CHANGED
@@ -10,4 +10,6 @@ tslib_1.__exportStar(require("./lib/utils/date.utils"), exports);
10
10
  tslib_1.__exportStar(require("./lib/utils/is-test.utils"), exports);
11
11
  tslib_1.__exportStar(require("./lib/utils/normalize-locales.utils"), exports);
12
12
  tslib_1.__exportStar(require("./lib/utils/get-normalized-browser-locales.utils"), exports);
13
+ tslib_1.__exportStar(require("./lib/utils/ensure-property.utils"), exports);
14
+ tslib_1.__exportStar(require("./lib/utils/get-onecx-shared-recommendations"), exports);
13
15
  //# 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,mFAAwD;AACxD,qEAA0C;AAC1C,sEAA2C;AAC3C,iEAAsC;AACtC,iEAAsC;AACtC,oEAAyC;AACzC,8EAAmD;AACnD,2FAAgE"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/accelerator/src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAiC;AACjC,mFAAwD;AACxD,qEAA0C;AAC1C,sEAA2C;AAC3C,iEAAsC;AACtC,iEAAsC;AACtC,oEAAyC;AACzC,8EAAmD;AACnD,2FAAgE;AAChE,4EAAiD;AACjD,uFAA4D"}
@@ -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,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureProperty = ensureProperty;
4
+ function ensureProperty(obj, path, initialValue) {
5
+ let current = obj;
6
+ for (let i = 0; i < path.length - 1; i++) {
7
+ const key = path[i];
8
+ if (current[key] == null || typeof current[key] !== 'object') {
9
+ current[key] = {};
10
+ }
11
+ current = current[key];
12
+ }
13
+ const lastKey = path.at(-1);
14
+ if (lastKey === undefined) {
15
+ return obj;
16
+ }
17
+ current[lastKey] ??= initialValue;
18
+ return obj;
19
+ }
20
+ //# 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,wCAqBC;AArBD,SAAgB,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"}
@@ -0,0 +1,2 @@
1
+ import { SharedLibraryConfig } from '@nx/module-federation';
2
+ export declare function getOneCXSharedRecommendations(libraryName: string, sharedConfig: SharedLibraryConfig): false | SharedLibraryConfig;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOneCXSharedRecommendations = getOneCXSharedRecommendations;
4
+ const sharedLibraryPatterns = [/^@angular.*$/, /^@onecx.*$/, /^rxjs.*$/, /^primeng.*$/, /^@ngx-translate.*$/];
5
+ function getOneCXSharedRecommendations(libraryName, sharedConfig) {
6
+ if (!sharedLibraryPatterns.some((pattern) => pattern.test(libraryName))) {
7
+ return false;
8
+ }
9
+ sharedConfig.singleton = false;
10
+ sharedConfig.strictVersion = false;
11
+ sharedConfig.eager = false;
12
+ return sharedConfig;
13
+ }
14
+ //# sourceMappingURL=get-onecx-shared-recommendations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-onecx-shared-recommendations.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/utils/get-onecx-shared-recommendations.ts"],"names":[],"mappings":";;AAIA,sEAWC;AAbD,MAAM,qBAAqB,GAAa,CAAC,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,oBAAoB,CAAC,CAAA;AAEvH,SAAgB,6BAA6B,CAC3C,WAAmB,EACnB,YAAiC;IAEjC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;QACxE,OAAO,KAAK,CAAA;IACd,CAAC;IACD,YAAY,CAAC,SAAS,GAAG,KAAK,CAAA;IAC9B,YAAY,CAAC,aAAa,GAAG,KAAK,CAAA;IAClC,YAAY,CAAC,KAAK,GAAG,KAAK,CAAA;IAC1B,OAAO,YAAY,CAAA;AACrB,CAAC"}