@contentstorage/core 0.3.33 → 0.3.35
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.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AppConfig, ContentStructure, GetImageReturn, GetTextReturn, GetVariationReturn } from '../types.js';
|
|
2
2
|
export declare let activeContent: object | null;
|
|
3
|
-
export declare let appConfig: AppConfig | null;
|
|
3
|
+
export declare let appConfig: Pick<AppConfig, 'contentKey' | 'languageCodes'> | null;
|
|
4
4
|
/**
|
|
5
5
|
* Loads and sets the content for a specific language.
|
|
6
6
|
* It will internally ensure the application configuration (for contentDir) is loaded.
|
|
7
7
|
* @param contentJson
|
|
8
8
|
*/
|
|
9
9
|
export declare function setContentLanguage(contentJson: object): void;
|
|
10
|
-
export declare function initContentStorage(config: AppConfig): void;
|
|
10
|
+
export declare function initContentStorage(config: Pick<AppConfig, 'contentKey' | 'languageCodes'>): void;
|
|
11
11
|
/**
|
|
12
12
|
* Retrieves the text string from the loaded JSON content for the given path.
|
|
13
13
|
* Autocompletion for pathString is enabled via module augmentation of CustomContentStructure.
|
|
@@ -20,7 +20,7 @@ export declare function initContentStorage(config: AppConfig): void;
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function getText<Path extends keyof ContentStructure>(contentKey: Path, variables?: ContentStructure[Path] extends {
|
|
22
22
|
variables: infer Vars;
|
|
23
|
-
} ? keyof Vars : Record<string, any>): GetTextReturn
|
|
23
|
+
} ? keyof Vars : Record<string, any>): GetTextReturn;
|
|
24
24
|
export declare function getImage(contentKey: keyof ContentStructure): GetImageReturn | undefined;
|
|
25
25
|
export declare function getVariation<Path extends keyof ContentStructure>(contentKey: Path, variationKey?: ContentStructure[Path] extends {
|
|
26
26
|
data: infer D;
|
|
@@ -45,10 +45,14 @@ export function initContentStorage(config) {
|
|
|
45
45
|
* @returns The text string from the JSON, or the fallbackValue, or undefined.
|
|
46
46
|
*/
|
|
47
47
|
export function getText(contentKey, variables) {
|
|
48
|
+
const defaultVal = {
|
|
49
|
+
contentKey,
|
|
50
|
+
text: '',
|
|
51
|
+
};
|
|
48
52
|
if (!activeContent) {
|
|
49
53
|
const msg = `[Contentstorage] getText: Content not loaded (Key: "${String(contentKey)}"). Ensure setContentLanguage() was called and completed successfully.`;
|
|
50
54
|
console.warn(msg);
|
|
51
|
-
return
|
|
55
|
+
return defaultVal;
|
|
52
56
|
}
|
|
53
57
|
const keys = contentKey.split('.');
|
|
54
58
|
let current = activeContent;
|
|
@@ -59,7 +63,7 @@ export function getText(contentKey, variables) {
|
|
|
59
63
|
else {
|
|
60
64
|
const msg = `[Contentstorage] getText: Path "${String(contentKey)}" not found in loaded content.`;
|
|
61
65
|
console.warn(msg);
|
|
62
|
-
return
|
|
66
|
+
return defaultVal;
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
if (typeof current === 'string') {
|
|
@@ -77,7 +81,7 @@ export function getText(contentKey, variables) {
|
|
|
77
81
|
else {
|
|
78
82
|
const msg = `[Contentstorage] getText: Value at path "${String(contentKey)}" is not a string (actual type: ${typeof current}).`;
|
|
79
83
|
console.warn(msg);
|
|
80
|
-
return
|
|
84
|
+
return defaultVal;
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
export function getImage(contentKey) {
|
|
@@ -15,7 +15,6 @@ export async function fetchContent(language) {
|
|
|
15
15
|
// Fetch data for the current language
|
|
16
16
|
const response = await axios.get(fileUrl);
|
|
17
17
|
const jsonData = response.data;
|
|
18
|
-
// Basic check for data existence, although axios usually throws for non-2xx responses
|
|
19
18
|
if (jsonData === undefined || jsonData === null) {
|
|
20
19
|
throw new Error(`No data received from ${fileUrl} for language ${languageToFetch}.`);
|
|
21
20
|
}
|
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.35",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"description": "Fetch content from contentstorage and generate TypeScript types",
|
|
8
8
|
"module": "dist/index.js",
|