@isardsat/editorial-server 6.5.1 → 6.6.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/dist/lib/storage.d.ts +5 -1
- package/dist/lib/storage.js +21 -4
- package/package.json +3 -3
package/dist/lib/storage.d.ts
CHANGED
|
@@ -19,15 +19,19 @@ export declare function createStorage(dataDirectory: string): {
|
|
|
19
19
|
saveLocalisationMessages: (messages: any) => Promise<boolean>;
|
|
20
20
|
createItem: (item: EditorialDataObjectWithType) => Promise<import("zod").objectOutputType<{
|
|
21
21
|
id: import("zod").ZodString;
|
|
22
|
-
|
|
22
|
+
isDraft: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
23
|
+
createdAt: import("zod").ZodDefault<import("zod").ZodString>;
|
|
24
|
+
updatedAt: import("zod").ZodDefault<import("zod").ZodString>;
|
|
23
25
|
}, import("zod").ZodTypeAny, "passthrough">>;
|
|
24
26
|
updateItem: (item: EditorialDataObjectWithType) => Promise<import("zod").objectOutputType<{
|
|
25
27
|
id: import("zod").ZodString;
|
|
28
|
+
isDraft: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
26
29
|
createdAt: import("zod").ZodDefault<import("zod").ZodString>;
|
|
27
30
|
updatedAt: import("zod").ZodDefault<import("zod").ZodString>;
|
|
28
31
|
}, import("zod").ZodTypeAny, "passthrough">>;
|
|
29
32
|
deleteItem: (item: EditorialDataObjectWithType) => Promise<Record<string, Record<string, import("zod").objectOutputType<{
|
|
30
33
|
id: import("zod").ZodString;
|
|
34
|
+
isDraft: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
31
35
|
createdAt: import("zod").ZodDefault<import("zod").ZodString>;
|
|
32
36
|
updatedAt: import("zod").ZodDefault<import("zod").ZodString>;
|
|
33
37
|
}, import("zod").ZodTypeAny, "passthrough">>>>;
|
package/dist/lib/storage.js
CHANGED
|
@@ -17,14 +17,30 @@ export function createStorage(dataDirectory) {
|
|
|
17
17
|
* TODO: This should ideally cache the result of reading the file until an update occurs.
|
|
18
18
|
*/
|
|
19
19
|
async function getContent({ production, }) {
|
|
20
|
-
|
|
20
|
+
const content = await readFile(production ? dataProdPath : dataPath, "utf-8").then((value) => EditorialDataSchema.parse(JSON.parse(value)));
|
|
21
|
+
return content;
|
|
21
22
|
}
|
|
22
23
|
async function getLocalisationMessages(langCode) {
|
|
23
24
|
return await readFile(join(dataDirectory, "locales", "messages", `${langCode}.json`), "utf-8").then((value) => JSON.parse(value));
|
|
24
25
|
}
|
|
25
26
|
async function saveContent({ production }) {
|
|
26
27
|
const content = await getContent({ production: false });
|
|
27
|
-
|
|
28
|
+
/** Do not save any items that have `isDraft` */
|
|
29
|
+
if (production) {
|
|
30
|
+
const filteredContent = {};
|
|
31
|
+
for (const [itemType, items] of Object.entries(content)) {
|
|
32
|
+
filteredContent[itemType] = {};
|
|
33
|
+
const typedItems = items;
|
|
34
|
+
for (const [itemId, item] of Object.entries(typedItems)) {
|
|
35
|
+
if (!item.isDraft) {
|
|
36
|
+
filteredContent[itemType][itemId] = item;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
await writeFileSafe(dataProdPath, JSON.stringify(EditorialDataSchema.parse(filteredContent), null, 2));
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
await writeFileSafe(dataPath, JSON.stringify(EditorialDataSchema.parse(content), null, 2));
|
|
28
44
|
return true;
|
|
29
45
|
}
|
|
30
46
|
async function saveLocalisationMessages(messages) {
|
|
@@ -34,10 +50,11 @@ export function createStorage(dataDirectory) {
|
|
|
34
50
|
async function createItem(item) {
|
|
35
51
|
const content = await getContent({ production: false });
|
|
36
52
|
content[item.type] = content[item.type] ?? {};
|
|
37
|
-
|
|
53
|
+
const parsedItem = EditorialDataItemSchema.parse(item);
|
|
54
|
+
content[item.type][item.id] = parsedItem;
|
|
38
55
|
// TODO: Use superjson to safely encode different types.
|
|
39
56
|
await writeFileSafe(dataPath, JSON.stringify(content, null, 2));
|
|
40
|
-
return
|
|
57
|
+
return parsedItem;
|
|
41
58
|
}
|
|
42
59
|
async function updateItem(item) {
|
|
43
60
|
const content = await getContent({ production: false });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isardsat/editorial-server",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"hono": "^4.6.20",
|
|
15
15
|
"yaml": "^2.7.0",
|
|
16
16
|
"zod": "^3.24.1",
|
|
17
|
-
"@isardsat/editorial-admin": "^6.
|
|
18
|
-
"@isardsat/editorial-common": "^6.
|
|
17
|
+
"@isardsat/editorial-admin": "^6.6.1",
|
|
18
|
+
"@isardsat/editorial-common": "^6.6.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@tsconfig/node22": "^22.0.0",
|