@tideworthy/tidysites 0.1.17 → 0.1.18
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/lib/folder.mjs +12 -1
- package/package.json +1 -1
package/lib/folder.mjs
CHANGED
|
@@ -145,9 +145,20 @@ export function pushDocument(local, snapshot, { keys, removeKeys = [], settings
|
|
|
145
145
|
// so the names the snapshot had and the file no longer has go as null.
|
|
146
146
|
const data = { ...e.data };
|
|
147
147
|
if (was?.data) for (const k of Object.keys(was.data)) if (!(k in data) && !emptyValue(was.data[k])) data[k] = null;
|
|
148
|
-
|
|
148
|
+
// A new entry's seed key is its slug, so "$ref:<slug>" from another file resolves to it once it is created.
|
|
149
|
+
(content[collection] ??= []).push({ id: e.id || slug, slug, status: e.status, data });
|
|
149
150
|
if (was?.updated_at) expect[key] = was.updated_at;
|
|
150
151
|
}
|
|
152
|
+
// "$ref:<slug>" (or "$ref:<collection>/<slug>") to an entry the folder already knows the website's id for becomes that id; a reference to an entry created by this same push stays for the website to resolve.
|
|
153
|
+
const ids = new Map();
|
|
154
|
+
for (const [k, e] of Object.entries(local)) if (e?.id) { const [, slug] = splitKey(k); ids.set(slug, e.id); ids.set(k, e.id); }
|
|
155
|
+
const resolveRefs = (v) => {
|
|
156
|
+
if (typeof v === 'string' && v.startsWith('$ref:')) { const target = v.slice(5).trim(); const id = ids.get(target) ?? ids.get(target.split('/').pop()); return id ?? `$ref:${target.split('/').pop()}`; }
|
|
157
|
+
if (Array.isArray(v)) return v.map(resolveRefs);
|
|
158
|
+
if (v && typeof v === 'object') return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolveRefs(x)]));
|
|
159
|
+
return v;
|
|
160
|
+
};
|
|
161
|
+
for (const entries of Object.values(content)) for (const e of entries) e.data = resolveRefs(e.data);
|
|
151
162
|
const remove = {};
|
|
152
163
|
for (const key of removeKeys) {
|
|
153
164
|
const [collection, slug] = splitKey(key);
|
package/package.json
CHANGED