@strifeapp/astro 1.0.28 → 1.0.30-beta.0
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/README.md +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -20
- package/dist/localized-content-index.js +587 -0
- package/dist/vite-plugin-strife-store-DkxIFvv2.js +89 -0
- package/dist/vite-plugin-strife-store-entry.js +1 -1
- package/dist/vite-plugin-strife-store.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/vite-plugin-strife-store-B4EtLcP6.js +0 -73
package/README.md
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
# @strifeapp/astro
|
|
2
|
-
|
|
3
|
-
This source code was recovered from the compiled distribution package v1.0.27.
|
|
1
|
+
# @strifeapp/astro
|
|
4
2
|
|
|
5
3
|
## ⚠️ Important Notes
|
|
6
4
|
|
|
7
|
-
1. **ImageService**: The `src/services/ImageService.ts` file only had type definitions in the compiled version. The actual implementation needs to be filled in based on your requirements.
|
|
8
|
-
|
|
9
5
|
2. **indexMapping.js**: This file should NOT be converted to TypeScript as it runs inside RavenDB's JavaScript indexing engine. Keep it as plain JavaScript.
|
|
10
6
|
|
|
11
7
|
3. **Module References**: The vite plugin reads `indexMapping.js` at build time using `readFileSync`, so make sure the path resolution in `vite-plugin-strife-store.ts` is correct for your build setup.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAMD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,gBAAgB,CAwBxF"}
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
import { v as
|
|
2
|
-
|
|
3
|
-
const a = {
|
|
1
|
+
import { v as n } from "./vite-plugin-strife-store-DkxIFvv2.js";
|
|
2
|
+
const o = {
|
|
4
3
|
type: "pfx"
|
|
5
4
|
};
|
|
6
|
-
function
|
|
5
|
+
function s(t) {
|
|
7
6
|
return {
|
|
8
7
|
name: "@strife/astro",
|
|
9
8
|
hooks: {
|
|
10
|
-
"astro:config:setup": ({
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
...
|
|
14
|
-
|
|
15
|
-
password: T ?? (e == null ? void 0 : e.password),
|
|
16
|
-
urls: r ? r.split(",") : (e == null ? void 0 : e.urls) ?? [],
|
|
17
|
-
database: S ?? (e == null ? void 0 : e.database)
|
|
18
|
-
};
|
|
19
|
-
const A = {
|
|
20
|
-
...a,
|
|
21
|
-
...e ? Object.fromEntries(
|
|
22
|
-
Object.entries(e).filter(([u, I]) => !!I)
|
|
9
|
+
"astro:config:setup": ({ updateConfig: i }) => {
|
|
10
|
+
const r = {
|
|
11
|
+
...o,
|
|
12
|
+
...t ? Object.fromEntries(
|
|
13
|
+
Object.entries(t).filter(([, e]) => e != null)
|
|
23
14
|
) : {}
|
|
24
15
|
};
|
|
25
|
-
|
|
16
|
+
i({
|
|
26
17
|
vite: {
|
|
27
|
-
plugins: [
|
|
18
|
+
plugins: [n(r)]
|
|
28
19
|
}
|
|
29
20
|
});
|
|
30
21
|
}
|
|
@@ -32,5 +23,5 @@ function d(e) {
|
|
|
32
23
|
};
|
|
33
24
|
}
|
|
34
25
|
export {
|
|
35
|
-
|
|
26
|
+
s as default
|
|
36
27
|
};
|
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* -----------------------------------------------------------------------------
|
|
3
|
+
* STRIFE CONTENT INDEX — L10N + StrifeUri + Template-Aware Relations
|
|
4
|
+
* -----------------------------------------------------------------------------
|
|
5
|
+
* What this does
|
|
6
|
+
* Projects Strife CMS documents into a query‑friendly, localized, relation‑expanded
|
|
7
|
+
* shape with one entry per locale. It keeps a deterministic output and a
|
|
8
|
+
* centralized storage policy (Corax‑safe).
|
|
9
|
+
* Cycle safety and performance caching.
|
|
10
|
+
*
|
|
11
|
+
* Canonical root fields (unchanged semantics)
|
|
12
|
+
* - id, locale, displayName, url, origin, collection
|
|
13
|
+
* - publishedAt, createdAt, changedAt, dependencies, labels, deleted
|
|
14
|
+
*
|
|
15
|
+
* Root template (whitelist + localizable)
|
|
16
|
+
* - Root fields are populated from the document's template. Scalars marked
|
|
17
|
+
* localizable are translated using the current entry's locale and stored.
|
|
18
|
+
* - Non‑localizable scalars are index‑only at root.
|
|
19
|
+
* - Arrays/objects (relations, chapters, content objects) are stored.
|
|
20
|
+
* - Reserved root names can never be redefined by editors.
|
|
21
|
+
*
|
|
22
|
+
* Relations (template‑driven for referenced docs)
|
|
23
|
+
* - Relations are detected by value shape (array of GUIDs or { id: GUID }).
|
|
24
|
+
* - For each referenced GUID, the target document is loaded and projected with
|
|
25
|
+
* its template (resolved by collection), using the ROOT entry's locale for
|
|
26
|
+
* any localizable scalars.
|
|
27
|
+
* - Order is preserved. Only GUIDs are followed. Cycles are prevented via a
|
|
28
|
+
* visit cache.
|
|
29
|
+
*
|
|
30
|
+
* Nested content by shape (no template loads)
|
|
31
|
+
* - Chapters: arrays of small objects; expanded recursively by shape.
|
|
32
|
+
* - Content‑template (object): expanded recursively by shape.
|
|
33
|
+
* - While expanding by shape, if a field is a relation array by shape, those
|
|
34
|
+
* relations are projected via templates (same as above). Otherwise, values
|
|
35
|
+
* are copied through. No per‑field localization occurs in shape expansion.
|
|
36
|
+
*
|
|
37
|
+
* StrifeUri
|
|
38
|
+
* - Form: strife://<docId>.<collection>.<db>/<path>
|
|
39
|
+
* - Resolution: loads the target doc and walks the path; the first path
|
|
40
|
+
* segment is localized with the ROOT entry's locale. The resolved value can be:
|
|
41
|
+
* • a scalar → copied as is
|
|
42
|
+
* • an object/array → expanded by shape
|
|
43
|
+
* • a relation array → projected via templates
|
|
44
|
+
*
|
|
45
|
+
* Storage policy (centralized at root copy step)
|
|
46
|
+
* - Arrays/objects → storeAs
|
|
47
|
+
* - Scalars localizable at root → storeAs (so projections return translated strings)
|
|
48
|
+
* - Scalars not localizable → indexAs (leaner index)
|
|
49
|
+
* - Root url is always stored
|
|
50
|
+
* - Keep per‑field storage/analyzer consistent across documents (Corax‑safe)
|
|
51
|
+
*
|
|
52
|
+
* Caching & cycle safety
|
|
53
|
+
* - docCache: documents, tplCache: templates, labelCache: labels
|
|
54
|
+
* - visit cache prevents cycles and provides memoization per entry
|
|
55
|
+
* - URL builder protects against origin cycles via a local visited set
|
|
56
|
+
*
|
|
57
|
+
* Localization model
|
|
58
|
+
* - Emits one entry per configured locale.
|
|
59
|
+
* - Root scalars marked localizable are translated and stored.
|
|
60
|
+
* - Referenced docs projected via templates also translate localizable scalars
|
|
61
|
+
* using the ROOT locale. displayName is treated as non‑localized.
|
|
62
|
+
* - Shape expansion itself does not localize values, except StrifeUri's first
|
|
63
|
+
* path segment at dereference time.
|
|
64
|
+
*
|
|
65
|
+
* Determinism & engine constraints
|
|
66
|
+
* - ES5‑only (no for..of, no arrow functions).
|
|
67
|
+
* - Deterministic shapes under the same inputs.
|
|
68
|
+
* - No performance guards (depth/breadth are unbounded); cycles are still safe.
|
|
69
|
+
* -----------------------------------------------------------------------------
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
var RESERVED_ROOT_FIELDS = {
|
|
74
|
+
url: true,
|
|
75
|
+
collection: true,
|
|
76
|
+
publishedAt: true,
|
|
77
|
+
createdAt: true,
|
|
78
|
+
changedAt: true,
|
|
79
|
+
labels: true,
|
|
80
|
+
locale: true,
|
|
81
|
+
origin: true,
|
|
82
|
+
id: true,
|
|
83
|
+
displayName: true,
|
|
84
|
+
dependencies: true
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
function storeAs(name, value) {
|
|
88
|
+
return { $value: value, $name: name, $options: { storage: true } };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function indexAs(name, value) {
|
|
92
|
+
return { $value: value, $name: name, $options: { storage: false } };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function loadDocCached(id, collection, docCache) {
|
|
96
|
+
if (!id) return null;
|
|
97
|
+
var key = collection + '::' + id;
|
|
98
|
+
if (docCache.has(key)) return docCache.get(key);
|
|
99
|
+
var d = load(id, collection);
|
|
100
|
+
if (d) docCache.set(key, d);
|
|
101
|
+
return d;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function loadTemplateByCollectionCached(collection, tplCache) {
|
|
105
|
+
if (!collection) return null;
|
|
106
|
+
var key = 'templates/' + collection;
|
|
107
|
+
if (tplCache.has(key)) return tplCache.get(key);
|
|
108
|
+
var t = load(key, 'templates');
|
|
109
|
+
if (t) tplCache.set(key, t);
|
|
110
|
+
return t;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function loadTemplateByIdCached(templateId, tplCache) {
|
|
114
|
+
if (!templateId) return null;
|
|
115
|
+
var key = templateId;
|
|
116
|
+
if (tplCache.has(key)) return tplCache.get(key);
|
|
117
|
+
var t = load(templateId, 'templates');
|
|
118
|
+
if (t) tplCache.set(key, t);
|
|
119
|
+
return t;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function loadLocalizationSettings() {
|
|
123
|
+
return load('configurations/localization', 'configurations');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function loadLabelCached(id, labelCache) {
|
|
127
|
+
if (!id) return null;
|
|
128
|
+
if (labelCache.has(id)) return labelCache.get(id);
|
|
129
|
+
var d = load(id, 'Labels');
|
|
130
|
+
if (d) labelCache.set(id, d);
|
|
131
|
+
return d;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function buildUrlCached(doc, docCache) {
|
|
135
|
+
var visited = {};
|
|
136
|
+
var slugs = [];
|
|
137
|
+
var c = doc;
|
|
138
|
+
do {
|
|
139
|
+
if (c.slug) slugs.unshift(c.slug);
|
|
140
|
+
if (!c.origin || visited[c.origin.id]) break;
|
|
141
|
+
visited[c.origin.id] = true;
|
|
142
|
+
c = loadDocCached(c.origin.id, c.origin.collection, docCache);
|
|
143
|
+
} while (c);
|
|
144
|
+
|
|
145
|
+
return slugs.shift() + slugs.join('/');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function getTranslator(locale, defaultLocale, fallbackToPrimary) {
|
|
149
|
+
return function (obj) {
|
|
150
|
+
if (!obj) return null;
|
|
151
|
+
if (typeof obj === 'object' && obj.hasOwnProperty) {
|
|
152
|
+
if (obj.hasOwnProperty(locale)) return obj[locale];
|
|
153
|
+
// if (fallbackToPrimary && locale && locale.length > 2) {
|
|
154
|
+
// var base = locale.slice(0, 2);
|
|
155
|
+
// if (obj.hasOwnProperty(base)) return obj[base];
|
|
156
|
+
// }
|
|
157
|
+
//return obj[defaultLocale];
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isGuid(s) {
|
|
164
|
+
return typeof s === 'string' &&
|
|
165
|
+
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(s);
|
|
166
|
+
}
|
|
167
|
+
function isRefLike(x) {
|
|
168
|
+
// GUID string id, or object with GUID `id`
|
|
169
|
+
if (typeof x === 'string') return isGuid(x);
|
|
170
|
+
if (!x || typeof x !== 'object') return false;
|
|
171
|
+
return typeof x.id === 'string' && isGuid(x.id) && Object.keys(x).length <= 2;
|
|
172
|
+
}
|
|
173
|
+
function isRelationArray(v) {
|
|
174
|
+
if (!v || !Array.isArray(v)) return false;
|
|
175
|
+
if (v.length === 0) return false; // empty arrays are ambiguous
|
|
176
|
+
for (var i = 0; i < v.length; i++) {
|
|
177
|
+
if (!isRefLike(v[i])) return false;
|
|
178
|
+
}
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
var strifeUriPattern = /^strife:\/\/(?<id>[-\w_]*)\.(?<coll>[\w_-]*)\.(?<db>[\w_-]*)(?<path>[-\w_./]*)?$/;
|
|
183
|
+
function isStrifeUri(value) {
|
|
184
|
+
var match = strifeUriPattern.exec(value || '');
|
|
185
|
+
if (!match) return null;
|
|
186
|
+
try {
|
|
187
|
+
var path = match.groups.path || '';
|
|
188
|
+
var segs = path.length > 1 ? path.slice(1).split('/') : [];
|
|
189
|
+
return {
|
|
190
|
+
original: value,
|
|
191
|
+
db: match.groups.db,
|
|
192
|
+
collection: match.groups.coll,
|
|
193
|
+
docId: match.groups.id, // may be non-GUID by design for StrifeUri
|
|
194
|
+
segments: segs
|
|
195
|
+
};
|
|
196
|
+
} catch (e) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function tryGetReferencedValue(strifeUri, populationContext, docCache) {
|
|
202
|
+
var document = loadDocCached(strifeUri.docId, '@all_docs', docCache);
|
|
203
|
+
if (!document) return null;
|
|
204
|
+
|
|
205
|
+
var val = document;
|
|
206
|
+
if (strifeUri.segments.length > 0) {
|
|
207
|
+
// first segment may be localized
|
|
208
|
+
var first = strifeUri.segments[0];
|
|
209
|
+
val = populationContext.translate(val[first]);
|
|
210
|
+
for (var i = 1; i < strifeUri.segments.length; i++) {
|
|
211
|
+
if (val == null) break;
|
|
212
|
+
var segment = strifeUri.segments[i];
|
|
213
|
+
val = val[segment];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return val;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function resolveStrifeUriIfAny(value, populationContext, docCache) {
|
|
220
|
+
var maybeUri = isStrifeUri(value);
|
|
221
|
+
return maybeUri ? tryGetReferencedValue(maybeUri, populationContext, docCache) : value;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function loadRelatedLabels(labelIdsArray, labelCache) {
|
|
225
|
+
if (!labelIdsArray || !labelIdsArray.length) return null;
|
|
226
|
+
var out = [];
|
|
227
|
+
for (var i = 0; i < labelIdsArray.length; i++) {
|
|
228
|
+
var lid = labelIdsArray[i];
|
|
229
|
+
var d = loadLabelCached(lid, labelCache);
|
|
230
|
+
if (d) out.push(d);
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function getVisitEntry(visit, id) {
|
|
236
|
+
var e = visit.get(id);
|
|
237
|
+
if (!e) { e = { state: 'done', node: null }; visit.set(id, e); }
|
|
238
|
+
return e;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function isVisiting(visit, id) {
|
|
242
|
+
var e = visit.get(id);
|
|
243
|
+
return e ? e.state === 'visiting' : false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function markVisiting(visit, id) {
|
|
247
|
+
var e = getVisitEntry(visit, id);
|
|
248
|
+
e.state = 'visiting';
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function markDone(visit, id) {
|
|
252
|
+
var e = getVisitEntry(visit, id);
|
|
253
|
+
e.state = 'done';
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function getCachedNode(visit, id) {
|
|
257
|
+
var e = visit.get(id);
|
|
258
|
+
return e && e.node ? e.node : null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function setCachedNode(visit, id, node) {
|
|
262
|
+
var e = getVisitEntry(visit, id);
|
|
263
|
+
e.node = node;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function isContentTemplateNode(v) {
|
|
267
|
+
return v && typeof v === 'object' && !Array.isArray(v) &&
|
|
268
|
+
v['@strife'] && v['@strife'].template;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function isChaptersArray(v) {
|
|
272
|
+
if (!v || !Array.isArray(v)) return false;
|
|
273
|
+
if (v.length === 0) return false;
|
|
274
|
+
for (var i = 0; i < v.length; i++) {
|
|
275
|
+
var it = v[i];
|
|
276
|
+
if (!it || !it['@strife'] || !it['@strife'].template) return false;
|
|
277
|
+
}
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function populateByShape(document, out, populationContext, visit,
|
|
282
|
+
docCache, tplCache, labelCache) {
|
|
283
|
+
if (!document || typeof document !== 'object') return;
|
|
284
|
+
|
|
285
|
+
for (var prop in document) {
|
|
286
|
+
if (!document || !document.hasOwnProperty || !document.hasOwnProperty(prop)) continue;
|
|
287
|
+
|
|
288
|
+
// Keep metadata decorations as-is
|
|
289
|
+
if (prop.charAt(0) === '@') { out[prop] = document[prop]; continue; }
|
|
290
|
+
|
|
291
|
+
var val = document[prop];
|
|
292
|
+
// StrifeUri resolution
|
|
293
|
+
val = resolveStrifeUriIfAny(val, populationContext, docCache);
|
|
294
|
+
|
|
295
|
+
// Chapters
|
|
296
|
+
if (isChaptersArray(val)) {
|
|
297
|
+
var arr = [];
|
|
298
|
+
for (var ci = 0; ci < val.length; ci++) {
|
|
299
|
+
var chapter = val[ci];
|
|
300
|
+
if (chapter && chapter['@strife'] && chapter['@strife'].template) {
|
|
301
|
+
var child = {};
|
|
302
|
+
populateByShape(chapter, child, populationContext, visit,
|
|
303
|
+
docCache, tplCache, labelCache);
|
|
304
|
+
arr.push(child);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
out[prop] = arr;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Content-template node
|
|
312
|
+
if (isContentTemplateNode(val)) {
|
|
313
|
+
var nested = {};
|
|
314
|
+
populateByShape(val, nested, populationContext, visit,
|
|
315
|
+
docCache, tplCache, labelCache);
|
|
316
|
+
out[prop] = nested;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Relations (GUID-strict)
|
|
321
|
+
if (isRelationArray(val)) {
|
|
322
|
+
var related = projectRelationsIfAny(val, populationContext, visit, docCache, tplCache, labelCache);
|
|
323
|
+
if (related) { out[prop] = related; continue; }
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Default: copy-through (no localization inside nested)
|
|
327
|
+
out[prop] = val;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (document['@strife'] && !out['@strife']) out['@strife'] = document['@strife'];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function projectRelationsIfAny(value, populationContext, visit, docCache, tplCache, labelCache) {
|
|
334
|
+
if (!isRelationArray(value)) return null;
|
|
335
|
+
var refs = [];
|
|
336
|
+
for (var i = 0; i < value.length; i++) {
|
|
337
|
+
var v = value[i];
|
|
338
|
+
var idStr = (typeof v === 'string') ? v : (v && v.id);
|
|
339
|
+
if (isGuid(idStr)) refs.push(idStr);
|
|
340
|
+
}
|
|
341
|
+
return loadRelatedDocumentsRecurse(refs, populationContext, visit, docCache, tplCache, labelCache);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function populateValuesByEditor(document, template, result, populationContext, visit,
|
|
345
|
+
docCache, tplCache, labelCache, isRootLevel) {
|
|
346
|
+
if (!template || !template.editors) return;
|
|
347
|
+
var tEditors = template.editors || [];
|
|
348
|
+
var i, editor;
|
|
349
|
+
|
|
350
|
+
function processEditor(editor, isRoot) {
|
|
351
|
+
if (!editor || !editor.editor || !editor.editor.propertyName) return;
|
|
352
|
+
|
|
353
|
+
var propertyName = editor.editor.propertyName;
|
|
354
|
+
|
|
355
|
+
// Never let editors redefine reserved fields (consistent everywhere)
|
|
356
|
+
if (RESERVED_ROOT_FIELDS[propertyName]) return;
|
|
357
|
+
|
|
358
|
+
// Read value with optional localization
|
|
359
|
+
var rawVal = document[propertyName];
|
|
360
|
+
var docValue = (editor.localizable) ? populationContext.translate(rawVal) : rawVal;
|
|
361
|
+
|
|
362
|
+
// StrifeUri resolution
|
|
363
|
+
docValue = resolveStrifeUriIfAny(docValue, populationContext, docCache);
|
|
364
|
+
|
|
365
|
+
// Relations (GUID-strict) — detect by value shape
|
|
366
|
+
var relatedDocs = projectRelationsIfAny(docValue, populationContext, visit, docCache, tplCache, labelCache);
|
|
367
|
+
if (relatedDocs) { result[propertyName] = relatedDocs; return; }
|
|
368
|
+
|
|
369
|
+
// Chapters (nested without template loads)
|
|
370
|
+
if (editor.editor.type === 'chapters') {
|
|
371
|
+
if (docValue == null) { // missing translation
|
|
372
|
+
result[propertyName] = null; // keep null instead of dropping field
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (!Array.isArray(docValue)) return;
|
|
376
|
+
var docResults = [];
|
|
377
|
+
for (var ci = 0; ci < docValue.length; ci++) {
|
|
378
|
+
var chapter = docValue[ci];
|
|
379
|
+
if (chapter && chapter['@strife'] && chapter['@strife'].template) {
|
|
380
|
+
var child = {};
|
|
381
|
+
populateByShape(chapter, child, populationContext, visit,
|
|
382
|
+
docCache, tplCache, labelCache);
|
|
383
|
+
docResults.push(child);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
result[propertyName] = docResults;
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Content-template (nested without template loads)
|
|
391
|
+
if (editor.editor.type === 'content-template') {
|
|
392
|
+
if (docValue == null) { // missing translation
|
|
393
|
+
result[propertyName] = null;
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (docValue && typeof docValue === 'object') {
|
|
397
|
+
var nested = {};
|
|
398
|
+
populateByShape(docValue, nested, populationContext, visit,
|
|
399
|
+
docCache, tplCache, labelCache);
|
|
400
|
+
result[propertyName] = nested;
|
|
401
|
+
}
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Other fields: plain values (localized at root when editor.localizable)
|
|
406
|
+
if (docValue !== undefined) {
|
|
407
|
+
result[propertyName] = docValue;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
for (i = 0; i < tEditors.length; i++) {
|
|
412
|
+
processEditor(tEditors[i], isRootLevel);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (document['@strife']) result['@strife'] = document['@strife'];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function projectDocumentWithTemplate(doc, populationContext, visit,
|
|
419
|
+
docCache, tplCache, labelCache) {
|
|
420
|
+
var collection = doc && doc['@metadata'] ? doc['@metadata']['@collection'] : null;
|
|
421
|
+
var tpl = loadTemplateByCollectionCached(collection, tplCache);
|
|
422
|
+
var labelsArr = Array.isArray(doc.labels) ? doc.labels : null;
|
|
423
|
+
|
|
424
|
+
var result = {
|
|
425
|
+
id: Id(doc),
|
|
426
|
+
url: buildUrlCached(doc, docCache),
|
|
427
|
+
collection: collection,
|
|
428
|
+
displayName: doc.displayName,
|
|
429
|
+
slug: doc.slug,
|
|
430
|
+
publishedDate: doc.publishedDate,
|
|
431
|
+
labels: loadRelatedLabels(labelsArr, labelCache)
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// Fill fields per template (use root locale via populationContext.translate)
|
|
435
|
+
if (tpl && tpl.editors) {
|
|
436
|
+
populateValuesByEditor(doc, tpl, result, populationContext, visit,
|
|
437
|
+
docCache, tplCache, labelCache, false);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return result;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function loadRelatedDocumentsRecurse(refGuids, populationContext, visit,
|
|
444
|
+
docCache, tplCache, labelCache) {
|
|
445
|
+
if (!refGuids) return null;
|
|
446
|
+
|
|
447
|
+
var results = [];
|
|
448
|
+
for (var i = 0; i < refGuids.length; i++) {
|
|
449
|
+
var id = refGuids[i];
|
|
450
|
+
if (!isGuid(id)) continue;
|
|
451
|
+
|
|
452
|
+
if (isVisiting(visit, id)) continue;
|
|
453
|
+
|
|
454
|
+
var cached = getCachedNode(visit, id);
|
|
455
|
+
if (cached) { results.push(cached); continue; }
|
|
456
|
+
|
|
457
|
+
markVisiting(visit, id);
|
|
458
|
+
var doc = loadDocCached(id, '@all_docs', docCache);
|
|
459
|
+
|
|
460
|
+
if (doc) {
|
|
461
|
+
var projected = projectDocumentWithTemplate(doc, populationContext, visit,
|
|
462
|
+
docCache, tplCache, labelCache);
|
|
463
|
+
setCachedNode(visit, id, projected);
|
|
464
|
+
results.push(projected);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
markDone(visit, id);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return results;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function mapDocument(document) {
|
|
474
|
+
var collection = document['@metadata']['@collection'];
|
|
475
|
+
var template = load('templates/' + collection, 'templates');
|
|
476
|
+
if (!template || !template.editors || document.deleted || document.archived) return null;
|
|
477
|
+
|
|
478
|
+
var l10n = loadLocalizationSettings();
|
|
479
|
+
var locales = (l10n && Array.isArray(l10n.locales)) ? l10n.locales : [l10n && l10n.defaultLocale ? l10n.defaultLocale : 'en'];
|
|
480
|
+
|
|
481
|
+
// Shared per-document caches (shared across locales)
|
|
482
|
+
var _docCache = new Map();
|
|
483
|
+
var _tplCache = new Map();
|
|
484
|
+
var _labelCache = new Map();
|
|
485
|
+
|
|
486
|
+
var entries = [];
|
|
487
|
+
|
|
488
|
+
// Precompute root labels (loaded in helper)
|
|
489
|
+
var rootLabelIds = Array.isArray(document.labels) ? document.labels : null;
|
|
490
|
+
|
|
491
|
+
// Precompute dependencies (ES5)
|
|
492
|
+
var depsArr = [];
|
|
493
|
+
if (document.dependencies && Array.isArray(document.dependencies)) {
|
|
494
|
+
for (var di = 0; di < document.dependencies.length; di++) {
|
|
495
|
+
var dep = document.dependencies[di];
|
|
496
|
+
if (dep && typeof dep.id === 'string') depsArr.push(dep.id);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Build a set of localizable root scalar fields from the template
|
|
501
|
+
var localizableRoot = {};
|
|
502
|
+
if (template && template.editors) {
|
|
503
|
+
for (var li0 = 0; li0 < template.editors.length; li0++) {
|
|
504
|
+
var ed0 = template.editors[li0];
|
|
505
|
+
if (!ed0 || !ed0.editor || !ed0.editor.propertyName) continue;
|
|
506
|
+
var t0 = ed0.editor.type;
|
|
507
|
+
if (t0 !== 'related' && t0 !== 'references' && t0 !== 'content-template' && t0 !== 'chapters') {
|
|
508
|
+
if (ed0.localizable === true) localizableRoot[ed0.editor.propertyName] = true;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
for (var li = 0; li < locales.length; li++) {
|
|
514
|
+
|
|
515
|
+
var currentLocale = locales[li];
|
|
516
|
+
if (document.locales && Array.isArray(document.locales)) {
|
|
517
|
+
var found = false;
|
|
518
|
+
for (var k = 0; k < document.locales.length; k++) {
|
|
519
|
+
if (document.locales[k] === currentLocale) { found = true; break; }
|
|
520
|
+
}
|
|
521
|
+
if (!found) continue;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
var translate = getTranslator(currentLocale, l10n.defaultLocale, l10n.fallbackToPrimary);
|
|
525
|
+
|
|
526
|
+
// Root result (stored fields)
|
|
527
|
+
var result = {
|
|
528
|
+
id: Id(document),
|
|
529
|
+
locale: storeAs('locale', currentLocale),
|
|
530
|
+
displayName: document.displayName,
|
|
531
|
+
url: template.disableURL ? null : storeAs('url', buildUrlCached(document, _docCache)),
|
|
532
|
+
origin: storeAs('origin', document.origin ? document.origin.id : null ),
|
|
533
|
+
collection: storeAs('collection', collection),
|
|
534
|
+
publishedDate: storeAs('publishedAt', document.publishedDate),
|
|
535
|
+
createdAt: storeAs('createdAt', document.createdAt),
|
|
536
|
+
changedAt: storeAs('changedAt', document.changedAt),
|
|
537
|
+
dependencies: storeAs('dependencies', depsArr),
|
|
538
|
+
//labels: storeAs('labels', loadRelatedLabels(rootLabelIds, _labelCache)),
|
|
539
|
+
labels: storeAs('labels', loadRelatedLabels(rootLabelIds, _labelCache).map(label => label.name)),
|
|
540
|
+
deleted: document.deleted
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
// Visit cache per-locale (keeps shapes deterministic per entry)
|
|
544
|
+
var visit = new Map();
|
|
545
|
+
|
|
546
|
+
// Build dynamic fields into a temp container using ROOT TEMPLATE (respect localizable)
|
|
547
|
+
var rootContainer = {};
|
|
548
|
+
populateValuesByEditor(document, template, rootContainer, { translate: translate },
|
|
549
|
+
visit, _docCache, _tplCache, _labelCache, true);
|
|
550
|
+
|
|
551
|
+
// Copy fields from temp container into result
|
|
552
|
+
// - arrays/objects -> storeAs
|
|
553
|
+
// - scalars -> storeAs if localizable, else indexAs
|
|
554
|
+
var keys = [];
|
|
555
|
+
for (var key in rootContainer) {
|
|
556
|
+
if (rootContainer && rootContainer.hasOwnProperty && rootContainer.hasOwnProperty(key)) {
|
|
557
|
+
keys.push(key);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
for (var ei = 0; ei < keys.length; ei++) {
|
|
562
|
+
var prop = keys[ei];
|
|
563
|
+
|
|
564
|
+
// never redefine canonical root fields
|
|
565
|
+
if (RESERVED_ROOT_FIELDS[prop]) continue;
|
|
566
|
+
|
|
567
|
+
var val = rootContainer[prop];
|
|
568
|
+
var isArray = Array.isArray(val);
|
|
569
|
+
var isProjectedArray = isArray && (val.length === 0 || typeof val[0] === 'object');
|
|
570
|
+
var isProjectedObject = !isArray && typeof val === 'object';
|
|
571
|
+
|
|
572
|
+
if (isProjectedArray || isProjectedObject) {
|
|
573
|
+
result[prop] = storeAs(prop, val);
|
|
574
|
+
} else {
|
|
575
|
+
if (localizableRoot[prop] === true) {
|
|
576
|
+
result[prop] = storeAs(prop, val); // translated scalar → store so projections return translated value
|
|
577
|
+
} else {
|
|
578
|
+
result[prop] = indexAs(prop, val); // non-localizable scalar → index-only
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
entries.push(result);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return entries;
|
|
587
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { readFileSync as a } from "fs";
|
|
2
|
+
import { dirname as l, resolve as f } from "path";
|
|
3
|
+
import { fileURLToPath as u } from "url";
|
|
4
|
+
import t from "serialize-javascript";
|
|
5
|
+
const n = "strife:store", o = "\0" + n;
|
|
6
|
+
function g(i) {
|
|
7
|
+
const s = u(import.meta.url), c = l(s), r = a(
|
|
8
|
+
f(c, "./localized-content-index.js"),
|
|
9
|
+
"utf-8"
|
|
10
|
+
);
|
|
11
|
+
return {
|
|
12
|
+
name: "strife:store",
|
|
13
|
+
resolveId(e) {
|
|
14
|
+
if (e === n)
|
|
15
|
+
return o;
|
|
16
|
+
},
|
|
17
|
+
load(e) {
|
|
18
|
+
if (e === o)
|
|
19
|
+
return `
|
|
20
|
+
import { DocumentStore, AbstractJavaScriptMultiMapIndexCreationTask } from "ravendb";
|
|
21
|
+
|
|
22
|
+
const indexMappingSource = ${t(r)};
|
|
23
|
+
const defaultConfig = ${t(i)};
|
|
24
|
+
|
|
25
|
+
const urls = process.env.STRIFE_DATABASE_URLS
|
|
26
|
+
? process.env.STRIFE_DATABASE_URLS.split(',')
|
|
27
|
+
: (defaultConfig.urls || []);
|
|
28
|
+
|
|
29
|
+
const database = process.env.STRIFE_DATABASE || defaultConfig.database || '';
|
|
30
|
+
|
|
31
|
+
const certificate = process.env.STRIFE_CERTIFICATE || defaultConfig.certificate;
|
|
32
|
+
const password = process.env.STRIFE_CERTIFICATE_PASSWORD || defaultConfig.password;
|
|
33
|
+
|
|
34
|
+
const hasAuth = certificate && password;
|
|
35
|
+
|
|
36
|
+
const authOptions = hasAuth ? {
|
|
37
|
+
type: defaultConfig.type || 'pfx',
|
|
38
|
+
certificate: Buffer.from(certificate, 'base64'),
|
|
39
|
+
password,
|
|
40
|
+
} : null;
|
|
41
|
+
|
|
42
|
+
const store = new DocumentStore(
|
|
43
|
+
urls,
|
|
44
|
+
database,
|
|
45
|
+
authOptions || undefined,
|
|
46
|
+
).initialize();
|
|
47
|
+
|
|
48
|
+
class Content_ByUrl extends AbstractJavaScriptMultiMapIndexCreationTask {
|
|
49
|
+
constructor() {
|
|
50
|
+
super();
|
|
51
|
+
|
|
52
|
+
this.additionalSources = {"Helper": indexMappingSource};
|
|
53
|
+
|
|
54
|
+
const collections = (defaultConfig.collections && defaultConfig.collections.length)
|
|
55
|
+
? defaultConfig.collections
|
|
56
|
+
: ['Posts'];
|
|
57
|
+
|
|
58
|
+
for (const collection of collections) {
|
|
59
|
+
const name = typeof collection === 'string' ? collection : collection.name;
|
|
60
|
+
this.map(name, function (doc) { return mapDocument(doc); });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.deploymentMode = 'Rolling';
|
|
64
|
+
this.searchEngineType = 'Lucene';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log('Deploying index...');
|
|
69
|
+
|
|
70
|
+
await store.executeIndex(new Content_ByUrl());
|
|
71
|
+
|
|
72
|
+
const bulkInsert = store.bulkInsert();
|
|
73
|
+
|
|
74
|
+
if (defaultConfig.collections && defaultConfig.collections.length) {
|
|
75
|
+
for (const collection of defaultConfig.collections) {
|
|
76
|
+
await bulkInsert.store(collection, 'templates/' + collection.name, { '@collection': 'Templates' });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
await bulkInsert.finish();
|
|
81
|
+
|
|
82
|
+
export { store };
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
g as v
|
|
89
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-strife-store.d.ts","sourceRoot":"","sources":["../src/vite-plugin-strife-store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAKlD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"vite-plugin-strife-store.d.ts","sourceRoot":"","sources":["../src/vite-plugin-strife-store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAKlD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAsF9E"}
|
package/package.json
CHANGED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { readFileSync as c } from "fs";
|
|
2
|
-
import { dirname as m, resolve as u } from "path";
|
|
3
|
-
import { fileURLToPath as d } from "url";
|
|
4
|
-
import r from "serialize-javascript";
|
|
5
|
-
const n = "strife:store", o = "\0" + n;
|
|
6
|
-
function S(e) {
|
|
7
|
-
const i = d(import.meta.url), p = m(i), l = c(
|
|
8
|
-
u(p, "../../../../../../../data/ravendb/localized-content-index.js"),
|
|
9
|
-
"utf-8"
|
|
10
|
-
);
|
|
11
|
-
return {
|
|
12
|
-
name: "strife:store",
|
|
13
|
-
resolveId(s) {
|
|
14
|
-
if (s === n)
|
|
15
|
-
return o;
|
|
16
|
-
},
|
|
17
|
-
load(s) {
|
|
18
|
-
var a;
|
|
19
|
-
if (s === o)
|
|
20
|
-
return `
|
|
21
|
-
import { DocumentStore, AbstractJavaScriptMultiMapIndexCreationTask } from "ravendb";
|
|
22
|
-
|
|
23
|
-
${e.certificate && e.password ? `
|
|
24
|
-
const authOptions = {
|
|
25
|
-
type: 'pfx',
|
|
26
|
-
certificate: Buffer.from(${r(e.certificate)}, 'base64'),
|
|
27
|
-
password: ${r(e.password)},
|
|
28
|
-
};
|
|
29
|
-
` : ""}
|
|
30
|
-
|
|
31
|
-
const store = new DocumentStore(
|
|
32
|
-
${r(e.urls ? e.urls : [])},
|
|
33
|
-
${r(e.database || "")}${e.certificate && e.password ? `,
|
|
34
|
-
authOptions` : ""}
|
|
35
|
-
).initialize()
|
|
36
|
-
|
|
37
|
-
class Content_ByUrl extends AbstractJavaScriptMultiMapIndexCreationTask {
|
|
38
|
-
constructor() {
|
|
39
|
-
super();
|
|
40
|
-
|
|
41
|
-
this.additionalSources = {"Helper": ${r(l)}}
|
|
42
|
-
|
|
43
|
-
${(e.collections || ["Posts"]).map(
|
|
44
|
-
(t) => `this.map("${typeof t == "string" ? t : t.name}", (doc) => { return mapDocument(doc) });`
|
|
45
|
-
).join(`
|
|
46
|
-
`)}
|
|
47
|
-
|
|
48
|
-
this.deploymentMode = 'Rolling';
|
|
49
|
-
this.searchEngineType = 'Lucene';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
console.log('Deploying index...');
|
|
54
|
-
|
|
55
|
-
await store.executeIndex(new Content_ByUrl());
|
|
56
|
-
|
|
57
|
-
const bulkInsert = store.bulkInsert();
|
|
58
|
-
|
|
59
|
-
${(a = e.collections) == null ? void 0 : a.map((t) => `
|
|
60
|
-
await bulkInsert.store(${JSON.stringify(t)}, 'templates/${t.name}', { '@collection': 'Templates' });
|
|
61
|
-
`).join(`
|
|
62
|
-
`)}
|
|
63
|
-
|
|
64
|
-
await bulkInsert.finish();
|
|
65
|
-
|
|
66
|
-
export { store };
|
|
67
|
-
`;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export {
|
|
72
|
-
S as v
|
|
73
|
-
};
|