@contentstorage/core 0.3.14 → 0.3.15
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.
|
@@ -4,7 +4,7 @@ import { ContentStructure, DotNotationPaths } from '../types.js';
|
|
|
4
4
|
* It will internally ensure the application configuration (for contentDir) is loaded.
|
|
5
5
|
* @param languageCode The language code (e.g., 'EN', 'FR') for the JSON file to load.
|
|
6
6
|
*/
|
|
7
|
-
export declare function setContentLanguage(contentJson: ContentStructure | null):
|
|
7
|
+
export declare function setContentLanguage(contentJson: ContentStructure | null): void;
|
|
8
8
|
/**
|
|
9
9
|
* Retrieves the text string from the loaded JSON content for the given path.
|
|
10
10
|
* Autocompletion for pathString is enabled via module augmentation of CustomContentStructure.
|
|
@@ -4,7 +4,7 @@ let activeContent = null;
|
|
|
4
4
|
* It will internally ensure the application configuration (for contentDir) is loaded.
|
|
5
5
|
* @param languageCode The language code (e.g., 'EN', 'FR') for the JSON file to load.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export function setContentLanguage(contentJson) {
|
|
8
8
|
if (!contentJson || typeof contentJson !== 'object') {
|
|
9
9
|
throw new Error('[Contentstorage] Invalid contentUrl provided to setContentLanguage.');
|
|
10
10
|
}
|
|
@@ -27,9 +27,7 @@ export async function setContentLanguage(contentJson) {
|
|
|
27
27
|
* If not provided, and path is not found/value not string, undefined is returned.
|
|
28
28
|
* @returns The text string from the JSON, or the fallbackValue, or undefined.
|
|
29
29
|
*/
|
|
30
|
-
export function getText(
|
|
31
|
-
// @ts-expect-error Is fine
|
|
32
|
-
pathString, fallbackValue) {
|
|
30
|
+
export function getText(pathString, fallbackValue) {
|
|
33
31
|
if (!activeContent) {
|
|
34
32
|
const msg = `[Contentstorage] getText: Content not loaded (Path: "${String(pathString)}"). Ensure setContentLanguage() was called and completed successfully.`;
|
|
35
33
|
console.warn(msg);
|
package/dist/types.d.ts
CHANGED
|
@@ -23,13 +23,17 @@ export type LanguageCode = 'SQ' | 'BE' | 'BS' | 'BG' | 'HR' | 'CS' | 'DA' | 'NL'
|
|
|
23
23
|
export interface ContentStructure {
|
|
24
24
|
[key: string]: any;
|
|
25
25
|
}
|
|
26
|
+
type MaxPathDepth = [any, any, any, any, any, any];
|
|
26
27
|
/**
|
|
27
|
-
* Generates a union of all possible dot-notation path strings for a given object type `T
|
|
28
|
-
*
|
|
28
|
+
* Generates a union of all possible dot-notation path strings for a given object type `T`,
|
|
29
|
+
* with a limit on recursion depth to prevent TypeScript errors.
|
|
30
|
+
* Defaults to using the `CustomContentStructure` interface, which consumers augment.
|
|
29
31
|
*
|
|
30
|
-
* @template T The object type to generate paths from.
|
|
31
|
-
* @template Prefix Internal accumulator for the current path prefix
|
|
32
|
+
* @template T The object type to generate paths from.
|
|
33
|
+
* @template Prefix Internal accumulator for the current path prefix.
|
|
34
|
+
* @template CurrentDepth Internal tuple to track recursion depth.
|
|
32
35
|
*/
|
|
33
|
-
export type DotNotationPaths<T = ContentStructure, Prefix extends string = ''> = T extends object ? {
|
|
34
|
-
[K in keyof T
|
|
35
|
-
}[keyof T] :
|
|
36
|
+
export type DotNotationPaths<T = ContentStructure, Prefix extends string = '', CurrentDepth extends any[] = []> = T extends object ? {
|
|
37
|
+
[K in keyof T & (string | number)]-?: CurrentDepth['length'] extends MaxPathDepth['length'] ? `${Prefix}${K}` : T[K] extends object ? `${Prefix}${K}` | DotNotationPaths<T[K], `${Prefix}${K}.`, [...CurrentDepth, any]> : `${Prefix}${K}`;
|
|
38
|
+
}[keyof T & (string | number)] : never;
|
|
39
|
+
export {};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@contentstorage/core",
|
|
3
3
|
"author": "Kaido Hussar <kaidohus@gmail.com>",
|
|
4
4
|
"homepage": "https://contentstorage.app",
|
|
5
|
-
"version": "0.3.
|
|
5
|
+
"version": "0.3.15",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"description": "Fetch content from contentstorage and generate TypeScript types",
|
|
8
8
|
"module": "dist/index.js",
|