@yysng/astro-boilerplate 1.1.10 → 1.1.11
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 +1 -1
- package/src/content-system/updater.js +10 -33
package/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { CONTENT_REGISTRY } from "./registry.js";
|
|
4
|
-
import { schemas } from "./schemas.js";
|
|
5
|
-
import { getContentRoot } from "./config.js";
|
|
1
|
+
// src/content-system/updater.js
|
|
6
2
|
|
|
3
|
+
import { schemas } from "./schemas.js";
|
|
4
|
+
import { loadContent } from "./loader.js";
|
|
7
5
|
|
|
8
6
|
function logAuditEvent({ section, incoming, merged }) {
|
|
9
7
|
const timestamp = new Date().toISOString();
|
|
@@ -11,26 +9,18 @@ function logAuditEvent({ section, incoming, merged }) {
|
|
|
11
9
|
console.log("[AI-EDIT]", {
|
|
12
10
|
section,
|
|
13
11
|
timestamp,
|
|
14
|
-
incoming,
|
|
15
|
-
result: merged
|
|
12
|
+
incoming,
|
|
13
|
+
result: merged
|
|
16
14
|
});
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
/**
|
|
20
|
-
* Merge only defined values from `incoming` into `existing`.
|
|
21
|
-
* - Undefined fields do NOT overwrite existing values
|
|
22
|
-
* - Nested objects (e.g. CTA) are merged recursively
|
|
23
|
-
*/
|
|
24
17
|
function mergeDefined(existing, incoming) {
|
|
25
18
|
const result = { ...existing };
|
|
26
19
|
|
|
27
20
|
for (const key of Object.keys(incoming)) {
|
|
28
21
|
const value = incoming[key];
|
|
29
|
-
|
|
30
|
-
// Skip undefined (true partial update behavior)
|
|
31
22
|
if (value === undefined) continue;
|
|
32
23
|
|
|
33
|
-
// Recursively merge objects (but not arrays)
|
|
34
24
|
if (
|
|
35
25
|
typeof value === "object" &&
|
|
36
26
|
value !== null &&
|
|
@@ -50,23 +40,13 @@ export async function updateContent(key, incoming) {
|
|
|
50
40
|
throw new Error("Incoming content must be an object");
|
|
51
41
|
}
|
|
52
42
|
|
|
53
|
-
const entry = CONTENT_REGISTRY[key];
|
|
54
|
-
if (!entry) {
|
|
55
|
-
throw new Error(`Unknown content key: ${key}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
43
|
const schema = schemas[key];
|
|
59
44
|
if (!schema) {
|
|
60
45
|
throw new Error(`No schema defined for content key: ${key}`);
|
|
61
46
|
}
|
|
62
47
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
let existing = {};
|
|
66
|
-
try {
|
|
67
|
-
const raw = await fs.readFile(filePath, "utf-8");
|
|
68
|
-
existing = JSON.parse(raw);
|
|
69
|
-
} catch {}
|
|
48
|
+
// Load existing content (edge-safe)
|
|
49
|
+
const existing = loadContent(key);
|
|
70
50
|
|
|
71
51
|
const merged = mergeDefined(existing, incoming);
|
|
72
52
|
|
|
@@ -78,9 +58,6 @@ export async function updateContent(key, incoming) {
|
|
|
78
58
|
merged
|
|
79
59
|
});
|
|
80
60
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"utf-8"
|
|
85
|
-
);
|
|
86
|
-
}
|
|
61
|
+
// EDGE MODE: return merged result only
|
|
62
|
+
return merged;
|
|
63
|
+
}
|