@strifeapp/astro 1.0.27 → 1.0.29
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 +90 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -361
- package/dist/localized-content-index.js +587 -0
- package/dist/services/ImageService.d.ts +1 -0
- package/dist/services/ImageService.d.ts.map +1 -0
- package/dist/vite-plugin-strife-store-HEEze8Mw.js +73 -0
- package/dist/vite-plugin-strife-store-entry.d.ts +6 -1
- package/dist/vite-plugin-strife-store-entry.d.ts.map +1 -0
- package/dist/vite-plugin-strife-store-entry.js +4 -0
- package/dist/vite-plugin-strife-store.d.ts +2 -1
- package/dist/vite-plugin-strife-store.d.ts.map +1 -0
- package/package.json +6 -11
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @strifeapp/astro - RECOVERED SOURCE CODE
|
|
2
|
+
|
|
3
|
+
This source code was recovered from the compiled distribution package v1.0.27.
|
|
4
|
+
|
|
5
|
+
## ⚠️ Important Notes
|
|
6
|
+
|
|
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
|
+
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
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
## Structure
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
src/
|
|
17
|
+
├── index.ts # Main Astro integration export
|
|
18
|
+
├── vite-plugin-strife-store.ts # Vite plugin for virtual module
|
|
19
|
+
├── vite-plugin-strife-store-entry.ts # Entry point for standalone plugin export
|
|
20
|
+
├── env.ts # Environment variable loader
|
|
21
|
+
├── indexMapping.js # RavenDB index mapping functions (JavaScript!)
|
|
22
|
+
└── services/
|
|
23
|
+
└── ImageService.ts # Image service (needs implementation)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Building
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install
|
|
30
|
+
npm run build
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This will compile TypeScript and generate type definitions in the `dist/` folder.
|
|
34
|
+
|
|
35
|
+
## Environment Variables
|
|
36
|
+
|
|
37
|
+
Required environment variables:
|
|
38
|
+
|
|
39
|
+
- `STRIFE_DATABASE_URLS` - Comma-separated list of RavenDB URLs
|
|
40
|
+
- `STRIFE_DATABASE` - Database name
|
|
41
|
+
- `STRIFE_CERTIFICATE` - Base64-encoded PFX certificate (optional for development)
|
|
42
|
+
- `STRIFE_CERTIFICATE_PASSWORD` - Certificate password (optional for development)
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
In your Astro project:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { defineConfig } from 'astro/config';
|
|
50
|
+
import strifeIntegration from '@strifeapp/astro';
|
|
51
|
+
|
|
52
|
+
export default defineConfig({
|
|
53
|
+
integrations: [
|
|
54
|
+
strifeIntegration({
|
|
55
|
+
// Optional: Override environment variables
|
|
56
|
+
urls: ['https://your-ravendb.com'],
|
|
57
|
+
database: 'your-database',
|
|
58
|
+
collections: [
|
|
59
|
+
{ name: 'Posts' },
|
|
60
|
+
{ name: 'Pages' },
|
|
61
|
+
],
|
|
62
|
+
}),
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## What This Integration Does
|
|
68
|
+
|
|
69
|
+
1. **Connects to RavenDB** using environment variables or provided config
|
|
70
|
+
2. **Deploys a search index** called `Content_ByUrl` for content search
|
|
71
|
+
3. **Indexes documents** from specified collections (default: Posts)
|
|
72
|
+
4. **Creates a virtual module** `strife:store` that exports the RavenDB DocumentStore
|
|
73
|
+
5. **Bulk inserts templates** into the Templates collection
|
|
74
|
+
|
|
75
|
+
## Recovery Process
|
|
76
|
+
|
|
77
|
+
The source was recovered by:
|
|
78
|
+
|
|
79
|
+
1. Analyzing the minified compiled output
|
|
80
|
+
2. Identifying variable names and function patterns
|
|
81
|
+
3. Extracting the embedded index mapping source code
|
|
82
|
+
4. Reconstructing TypeScript types from `.d.ts` files
|
|
83
|
+
5. Reverse engineering the build configuration
|
|
84
|
+
|
|
85
|
+
## Next Steps
|
|
86
|
+
|
|
87
|
+
- [ ] Implement the ImageService if needed
|
|
88
|
+
- [ ] Verify the build output matches the original
|
|
89
|
+
- [ ] Add tests
|
|
90
|
+
- [ ] Update version number if making changes
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +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;AAI5C,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,CAsCxF"}
|
package/dist/index.js
CHANGED
|
@@ -1,371 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
* Creates an indexed item that will be stored in the index.
|
|
5
|
-
* @param {string} name - Name of property to index
|
|
6
|
-
* @param {any} value - Value to index and store
|
|
7
|
-
* @returns a new object to index and store
|
|
8
|
-
*/
|
|
9
|
-
function storeAs(name, value) {
|
|
10
|
-
return {
|
|
11
|
-
$value: value,
|
|
12
|
-
$name: name,
|
|
13
|
-
$options: { storage: true },
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Create an indexed item without storing value in the index.
|
|
19
|
-
* @param {string} name - Name of the property to index
|
|
20
|
-
* @param {any} value - The value to index
|
|
21
|
-
* @returns a new object to index (no store)
|
|
22
|
-
*/
|
|
23
|
-
function indexAs(name, value) {
|
|
24
|
-
return {
|
|
25
|
-
$value: value,
|
|
26
|
-
$name: name,
|
|
27
|
-
$options: { storage: false },
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Loads the documents referenced by reference objects in the array
|
|
33
|
-
* @param {any} references - Array of document references: { id, collection }
|
|
34
|
-
* @returns The list of loaded documents.
|
|
35
|
-
*/
|
|
36
|
-
function loadRelatedDocuments(references) {
|
|
37
|
-
if (references == null) return null;
|
|
38
|
-
return references
|
|
39
|
-
.filter((item) => typeof item.id === 'string') // Ensure each ID is a string
|
|
40
|
-
.map((item) => load(item.id, 'Labels'))
|
|
41
|
-
.filter(Boolean); // Filter out any null/undefined values
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Builds an url for a document by traversing its ancestor origins
|
|
46
|
-
* @param {*} doc - The leaf document
|
|
47
|
-
* @returns The full url of the document
|
|
48
|
-
*/
|
|
49
|
-
function buildUrl(doc) {
|
|
50
|
-
const visited = {};
|
|
51
|
-
const slugs = [];
|
|
52
|
-
let c = doc;
|
|
53
|
-
|
|
54
|
-
do {
|
|
55
|
-
if (c.slug) {
|
|
56
|
-
slugs.unshift(c.slug);
|
|
57
|
-
}
|
|
58
|
-
if (!c.origin || visited[c.origin.id]) break;
|
|
59
|
-
visited[c.origin.id] = true;
|
|
60
|
-
c = load(c.origin.id, c.origin.collection);
|
|
61
|
-
} while (c);
|
|
62
|
-
|
|
63
|
-
return slugs.shift() + slugs.join('/');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Editor types that contains {collection, id} references that we want to load
|
|
68
|
-
*/
|
|
69
|
-
const RELATION_EDITORS = ['related', 'references'];
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Loads the template document of the specified document
|
|
73
|
-
* @param {any} document - The document to index
|
|
74
|
-
* @returns The document's template, loaded
|
|
75
|
-
*/
|
|
76
|
-
function loadTemplate(document) {
|
|
77
|
-
const collection = document['@metadata']['@collection'];
|
|
78
|
-
const template = load('templates/' + collection, 'templates');
|
|
79
|
-
return template;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Loads the metadata template
|
|
84
|
-
* @returns The metadata template
|
|
85
|
-
*/
|
|
86
|
-
function loadMetadataTemplate() {
|
|
87
|
-
const template = load('templates/metadata', 'templates');
|
|
88
|
-
return template;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Iterates the template's editors and copies the respective values to the
|
|
93
|
-
* result object. Properties containing references are resolved recursively.
|
|
94
|
-
* Mutually recursive with \`loadRelatedDocumentsRecurse\`.
|
|
95
|
-
* @param {*} document - The document to extract values from
|
|
96
|
-
* @param {*} template - The document's template
|
|
97
|
-
* @param {*} metadataTemplate - The metadata template
|
|
98
|
-
* @param {*} result - The populated result
|
|
99
|
-
*/
|
|
100
|
-
function populateValuesByEditor(document, template, metadataTemplate, result, loadedDocs) {
|
|
101
|
-
const aggregatedEditors = template.editors.concat(metadataTemplate.editors);
|
|
102
|
-
// Add dynamic fields and handle "related" type
|
|
103
|
-
aggregatedEditors.forEach((editor) => {
|
|
104
|
-
if (editor.editor && editor.editor.propertyName) {
|
|
105
|
-
const propertyName = editor.editor.propertyName;
|
|
106
|
-
|
|
107
|
-
if (RELATION_EDITORS.includes(editor.editor.type) && Array.isArray(document[propertyName])) {
|
|
108
|
-
// Load related documents in the array of document references
|
|
109
|
-
const relatedDocs = loadRelatedDocumentsRecurse(document[propertyName], metadataTemplate, loadedDocs);
|
|
110
|
-
result[propertyName] = relatedDocs;
|
|
111
|
-
} else if (editor.editor.type === 'content-template') {
|
|
112
|
-
const content = document[propertyName];
|
|
113
|
-
if (content) {
|
|
114
|
-
const contentTemplate = load(editor.editor.attributes.templateId, 'templates');
|
|
115
|
-
const docResult = {};
|
|
116
|
-
populateValuesByEditor(content, contentTemplate, metadataTemplate, docResult, loadedDocs);
|
|
117
|
-
result[propertyName] = docResult;
|
|
118
|
-
}
|
|
119
|
-
} else if (editor.editor.type === 'chapters') {
|
|
120
|
-
const chapters = document[propertyName];
|
|
121
|
-
if (chapters && Array.isArray(chapters)) {
|
|
122
|
-
const docResults = [];
|
|
123
|
-
chapters.forEach((chapter) => {
|
|
124
|
-
if (chapter['@strife'] && chapter['@strife'].templateId) {
|
|
125
|
-
const docResult = {};
|
|
126
|
-
const chaptersTemplate = load(chapter['@strife'].templateId, 'templates');
|
|
127
|
-
populateValuesByEditor(chapter, chaptersTemplate, metadataTemplate, docResult, loadedDocs);
|
|
128
|
-
docResults.push(docResult);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
result[propertyName] = docResults;
|
|
132
|
-
}
|
|
133
|
-
} else if (document[propertyName] !== undefined) {
|
|
134
|
-
// For other types, index the field value directly
|
|
135
|
-
result[propertyName] = document[propertyName];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
if (document['@strife']) {
|
|
140
|
-
result['@strife'] = document['@strife'];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Loads the documents referenced by the array of references. Mutually recursive
|
|
146
|
-
* with \`populateValuesByEditor\`.
|
|
147
|
-
* @param {*} references - List of references to load.
|
|
148
|
-
* @returns
|
|
149
|
-
*/
|
|
150
|
-
function loadRelatedDocumentsRecurse(references, metadataTemplate, loadedDocs) {
|
|
151
|
-
if (references == null) return null;
|
|
152
|
-
const documents = references
|
|
153
|
-
.map((id) => (typeof id === 'string' ? id : id.id))
|
|
154
|
-
.map((id) => {
|
|
155
|
-
if (loadedDocs.has(id)) return null;
|
|
156
|
-
|
|
157
|
-
const aDoc = load(id, '@all_docs');
|
|
158
|
-
|
|
159
|
-
if (aDoc) {
|
|
160
|
-
loadedDocs.add(id);
|
|
161
|
-
}
|
|
162
|
-
return aDoc;
|
|
163
|
-
})
|
|
164
|
-
.filter(Boolean); // Filter out any null/undefined values
|
|
165
|
-
|
|
166
|
-
const docResults = [];
|
|
167
|
-
documents.forEach((doc) => {
|
|
168
|
-
const template = loadTemplate(doc);
|
|
169
|
-
const docResult = {
|
|
170
|
-
id: Id(doc),
|
|
171
|
-
url: buildUrl(doc),
|
|
172
|
-
collection: doc['@metadata']['@collection'],
|
|
173
|
-
labels: loadRelatedDocuments(
|
|
174
|
-
doc.labels.map((l) => {
|
|
175
|
-
return { id: l, collection: 'Labels' };
|
|
176
|
-
}),
|
|
177
|
-
),
|
|
178
|
-
};
|
|
179
|
-
populateValuesByEditor(doc, template, metadataTemplate, docResult, loadedDocs);
|
|
180
|
-
docResults.push(docResult);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
return docResults;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Maps a document to an index entry for Strife's content index
|
|
188
|
-
* @param {any} document - The document to index
|
|
189
|
-
* @returns An object to be indexed by RavenDB
|
|
190
|
-
*/
|
|
191
|
-
function mapDocument(document) {
|
|
192
|
-
const collection = document['@metadata']['@collection'];
|
|
193
|
-
const template = load('templates/' + collection, 'templates');
|
|
194
|
-
|
|
195
|
-
if (!template || !template.editors || document.deleted || document.archived) {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const metadataTemplate = loadMetadataTemplate();
|
|
200
|
-
|
|
201
|
-
// Initialize result with static fields
|
|
202
|
-
const result = {
|
|
203
|
-
id: Id(document),
|
|
204
|
-
displayName: document.displayName,
|
|
205
|
-
url: storeAs('url', buildUrl(document)),
|
|
206
|
-
origin: document.origin,
|
|
207
|
-
collection: storeAs('collection', collection),
|
|
208
|
-
publishedDate: storeAs('publishedAt', document.publishedDate),
|
|
209
|
-
createdAt: storeAs('createdAt', document.createdAt),
|
|
210
|
-
changedAt: storeAs('changedAt', document.changedAt),
|
|
211
|
-
labels: storeAs(
|
|
212
|
-
'labels',
|
|
213
|
-
loadRelatedDocuments(
|
|
214
|
-
document.labels.map((l) => {
|
|
215
|
-
return { id: l, collection: 'Labels' };
|
|
216
|
-
}),
|
|
217
|
-
),
|
|
218
|
-
),
|
|
219
|
-
deleted: document.deleted,
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// Keep tabs of loaded documents to avoid infinite recursion
|
|
223
|
-
const loadedDocuments = new Set(result.id);
|
|
224
|
-
|
|
225
|
-
// Add dynamic fields and handle "related" type
|
|
226
|
-
template.editors.forEach((editor) => {
|
|
227
|
-
if (editor.editor && editor.editor.propertyName) {
|
|
228
|
-
const propertyName = editor.editor.propertyName;
|
|
229
|
-
|
|
230
|
-
if (RELATION_EDITORS.includes(editor.editor.type) && Array.isArray(document[propertyName])) {
|
|
231
|
-
// Load related documents in the array of document references
|
|
232
|
-
const relatedDocs = loadRelatedDocumentsRecurse(document[propertyName], metadataTemplate, loadedDocuments);
|
|
233
|
-
result[propertyName] = storeAs(propertyName, relatedDocs);
|
|
234
|
-
} else if (editor.editor.type === 'content-template') {
|
|
235
|
-
const content = document[propertyName];
|
|
236
|
-
if (content) {
|
|
237
|
-
const template = load(editor.editor.attributes.templateId, 'templates');
|
|
238
|
-
const docResult = {};
|
|
239
|
-
populateValuesByEditor(content, template, metadataTemplate, docResult, loadedDocuments);
|
|
240
|
-
result[propertyName] = storeAs(propertyName, docResult);
|
|
241
|
-
}
|
|
242
|
-
} else if (editor.editor.type === 'chapters') {
|
|
243
|
-
const chapters = document[propertyName];
|
|
244
|
-
if (chapters && Array.isArray(chapters)) {
|
|
245
|
-
const docResults = [];
|
|
246
|
-
chapters.forEach((chapter) => {
|
|
247
|
-
if (chapter['@strife'] && chapter['@strife'].templateId) {
|
|
248
|
-
const docResult = {};
|
|
249
|
-
const template = load(chapter['@strife'].templateId, 'templates');
|
|
250
|
-
populateValuesByEditor(chapter, template, metadataTemplate, docResult, loadedDocuments);
|
|
251
|
-
docResults.push(docResult);
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
result[propertyName] = storeAs(propertyName, docResults);
|
|
255
|
-
}
|
|
256
|
-
} else if (document[propertyName] !== undefined) {
|
|
257
|
-
// For other types, index the field value directly
|
|
258
|
-
result[propertyName] = indexAs(propertyName, document[propertyName]);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
return result;
|
|
264
|
-
}`, m = "strife:store", p = "\0" + m;
|
|
265
|
-
function h(e) {
|
|
266
|
-
return {
|
|
267
|
-
name: "strife:store",
|
|
268
|
-
resolveId(s) {
|
|
269
|
-
if (s === m)
|
|
270
|
-
return p;
|
|
271
|
-
},
|
|
272
|
-
load(s) {
|
|
273
|
-
var o;
|
|
274
|
-
if (s === p)
|
|
275
|
-
return `
|
|
276
|
-
import { DocumentStore, AbstractJavaScriptMultiMapIndexCreationTask } from "ravendb";
|
|
277
|
-
|
|
278
|
-
${e.certificate && e.password ? `
|
|
279
|
-
const authOptions = {
|
|
280
|
-
type: 'pfx',
|
|
281
|
-
certificate: Buffer.from(${d(e.certificate)}, 'base64'),
|
|
282
|
-
password: ${d(e.password)},
|
|
283
|
-
};
|
|
284
|
-
` : ""}
|
|
285
|
-
|
|
286
|
-
const store = new DocumentStore(
|
|
287
|
-
${d(e.urls ? e.urls : [])},
|
|
288
|
-
${d(e.database || "")}${e.certificate && e.password ? `,
|
|
289
|
-
authOptions` : ""}
|
|
290
|
-
).initialize()
|
|
291
|
-
|
|
292
|
-
class Content_ByUrl extends AbstractJavaScriptMultiMapIndexCreationTask {
|
|
293
|
-
constructor() {
|
|
294
|
-
super();
|
|
295
|
-
|
|
296
|
-
this.additionalSources = {"Helper": ${d(y)}}
|
|
297
|
-
|
|
298
|
-
${(e.collections || ["Posts"]).map((t) => `this.map("${typeof t == "string" ? t : t.name}", (doc) => { return mapDocument(doc) });`).join(`
|
|
299
|
-
`)}
|
|
300
|
-
|
|
301
|
-
this.deploymentMode = 'Rolling';
|
|
302
|
-
this.searchEngineType = 'Lucene';
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
console.log('Deploying index...');
|
|
307
|
-
|
|
308
|
-
await store.executeIndex(new Content_ByUrl());
|
|
309
|
-
|
|
310
|
-
const bulkInsert = store.bulkInsert();
|
|
311
|
-
|
|
312
|
-
${(o = e.collections) == null ? void 0 : o.map((t) => `
|
|
313
|
-
await bulkInsert.store(${JSON.stringify(t)}, 'templates/${t.name}', { '@collection': 'Templates' });
|
|
314
|
-
`).join(`
|
|
315
|
-
`)}
|
|
316
|
-
|
|
317
|
-
await bulkInsert.finish();
|
|
318
|
-
|
|
319
|
-
export { store };
|
|
320
|
-
`;
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
const T = {
|
|
1
|
+
import { v as _ } from "./vite-plugin-strife-store-HEEze8Mw.js";
|
|
2
|
+
import { loadEnv as l } from "vite";
|
|
3
|
+
const a = {
|
|
325
4
|
type: "pfx"
|
|
326
5
|
};
|
|
327
|
-
function
|
|
328
|
-
let o = process.env.STRIFE_DATABASE_URLS, t = process.env.STRIFE_DATABASE, r = process.env.STRIFE_CERTIFICATE, l = process.env.STRIFE_CERTIFICATE_PASSWORD;
|
|
329
|
-
if (!o || !t || !r || !l) {
|
|
330
|
-
const n = f(e, s ?? "", "");
|
|
331
|
-
o = o || n.STRIFE_DATABASE_URLS, t = t || n.STRIFE_DATABASE, r = r || n.STRIFE_CERTIFICATE, l = l || n.STRIFE_CERTIFICATE_PASSWORD;
|
|
332
|
-
}
|
|
333
|
-
return console.log("[strifeIntegration] Loaded environment variables:"), console.log(` STRIFE_DATABASE_URLS: ${o ? "[SET]" : "[NOT SET]"}`), console.log(` STRIFE_DATABASE: ${t || "[NOT SET]"}`), console.log(` STRIFE_CERTIFICATE: ${r ? `[SET, length=${r.length}]` : "[NOT SET]"}`), console.log(` STRIFE_CERTIFICATE_PASSWORD: ${l ? "[SET]" : "[NOT SET]"}`), {
|
|
334
|
-
urls: o ? o.split(",").map((n) => n.trim()).filter(Boolean) : void 0,
|
|
335
|
-
database: t || void 0,
|
|
336
|
-
certificate: r || void 0,
|
|
337
|
-
password: l || void 0
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
function v(e) {
|
|
6
|
+
function d(e) {
|
|
341
7
|
return {
|
|
342
8
|
name: "@strife/astro",
|
|
343
9
|
hooks: {
|
|
344
|
-
"astro:config:setup": ({
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
...
|
|
348
|
-
|
|
349
|
-
),
|
|
10
|
+
"astro:config:setup": ({ config: c, updateConfig: f }) => {
|
|
11
|
+
const E = c.vite.envDir || process.cwd(), { STRIFE_CERTIFICATE: t, STRIFE_CERTIFICATE_PASSWORD: T, STRIFE_DATABASE_URLS: r, STRIFE_DATABASE: S } = l(process.env.NODE_ENV ?? "", E, "");
|
|
12
|
+
e = {
|
|
13
|
+
...e,
|
|
14
|
+
certificate: t ?? (e == null ? void 0 : e.certificate) ?? a.certificate,
|
|
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,
|
|
350
21
|
...e ? Object.fromEntries(
|
|
351
|
-
Object.entries(e).filter(([
|
|
22
|
+
Object.entries(e).filter(([u, I]) => !!I)
|
|
352
23
|
) : {}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
);
|
|
356
|
-
if (u.length > 0)
|
|
357
|
-
throw new Error(
|
|
358
|
-
`[strifeIntegration] Missing required environment variables: ${u.join(", ")}.
|
|
359
|
-
Set them in your .env file (for local) or Vercel project settings (for deployment).
|
|
360
|
-
Current values:
|
|
361
|
-
` + c.map((a) => ` ${a}: ${JSON.stringify(n[a])}`).join(`
|
|
362
|
-
`)
|
|
363
|
-
);
|
|
364
|
-
t({
|
|
24
|
+
};
|
|
25
|
+
f({
|
|
365
26
|
vite: {
|
|
366
|
-
plugins: [
|
|
367
|
-
h(n)
|
|
368
|
-
]
|
|
27
|
+
plugins: [_(A)]
|
|
369
28
|
}
|
|
370
29
|
});
|
|
371
30
|
}
|
|
@@ -373,5 +32,5 @@ Current values:
|
|
|
373
32
|
};
|
|
374
33
|
}
|
|
375
34
|
export {
|
|
376
|
-
|
|
35
|
+
d as default
|
|
377
36
|
};
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"ImageService.d.ts","sourceRoot":"","sources":["../../src/services/ImageService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAI1C,QAAA,MAAM,OAAO,EAAE,YAGP,CAAC;AAET,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
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, "./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
|
+
};
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Entry point for importing the vite plugin directly
|
|
3
|
+
* Usage: import { vitePluginStrifeStore } from '@strifeapp/astro/vite-plugin-strife-store'
|
|
4
|
+
*/
|
|
5
|
+
export { vitePluginStrifeStore } from './vite-plugin-strife-store';
|
|
6
|
+
//# sourceMappingURL=vite-plugin-strife-store-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-strife-store-entry.d.ts","sourceRoot":"","sources":["../src/vite-plugin-strife-store-entry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { IntegrationOptions } from './index';
|
|
2
1
|
import { PluginOption } from 'vite';
|
|
2
|
+
import { IntegrationOptions } from './index';
|
|
3
3
|
export declare function vitePluginStrifeStore(config: IntegrationOptions): PluginOption;
|
|
4
|
+
//# sourceMappingURL=vite-plugin-strife-store.d.ts.map
|
|
@@ -0,0 +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,CAmE9E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strifeapp/astro",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"description": "Official Strife Astro integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro-integration",
|
|
@@ -29,24 +29,19 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"astro": "^4.0.0 || ^5.0.0",
|
|
32
|
-
"dotenv": "^
|
|
33
|
-
"ravendb": "^
|
|
32
|
+
"dotenv": "^17.2.3",
|
|
33
|
+
"ravendb": "^7.1.4",
|
|
34
34
|
"serialize-javascript": "^6.0.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/dotenv": "^8.2.0",
|
|
38
|
+
"@types/serialize-javascript": "^5.0.4",
|
|
38
39
|
"rimraf": "^6.0.1",
|
|
39
40
|
"typescript": "^5.7.3",
|
|
40
|
-
"vite": "^6.
|
|
41
|
+
"vite": "^6.4.1",
|
|
41
42
|
"vite-plugin-dts": "^4.5.3"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
|
-
"astro": "^4.0.0 || ^5.0.0"
|
|
45
|
-
"ravendb": "^5.4.3"
|
|
46
|
-
},
|
|
47
|
-
"compilerOptions": {
|
|
48
|
-
"declaration": true,
|
|
49
|
-
"emitDeclarationOnly": false,
|
|
50
|
-
"outDir": "dist"
|
|
45
|
+
"astro": "^4.0.0 || ^5.0.0"
|
|
51
46
|
}
|
|
52
47
|
}
|