@strifeapp/astro 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export
|
|
1
|
+
import { AstroIntegration } from 'astro';
|
|
2
|
+
import { IAuthOptions } from 'ravendb';
|
|
3
|
+
export interface IntegrationOptions extends IAuthOptions {
|
|
4
4
|
certificate?: string;
|
|
5
5
|
password?: string;
|
|
6
6
|
urls?: string[];
|
|
7
7
|
database?: string;
|
|
8
|
-
collections?:
|
|
9
|
-
}
|
|
8
|
+
collections?: Collection[];
|
|
9
|
+
}
|
|
10
|
+
export interface Collection {
|
|
11
|
+
name: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
10
14
|
export default function strifeIntegration(options?: IntegrationOptions): AstroIntegration;
|
package/dist/index.js
CHANGED
|
@@ -1,39 +1,307 @@
|
|
|
1
|
-
import { loadEnv } from "vite";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { loadEnv as f } from "vite";
|
|
2
|
+
import r from "serialize-javascript";
|
|
3
|
+
const y = `/**
|
|
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
|
+
/**
|
|
46
|
+
* Builds an url for a document by traversing its ancestor origins
|
|
47
|
+
* @param {*} doc - The leaf document
|
|
48
|
+
* @returns The full url of the document
|
|
49
|
+
*/
|
|
50
|
+
function buildUrl(doc) {
|
|
51
|
+
const visited = {};
|
|
52
|
+
const slugs = [];
|
|
53
|
+
let c = doc;
|
|
54
|
+
|
|
55
|
+
do {
|
|
56
|
+
if (c.slug) {
|
|
57
|
+
slugs.unshift(c.slug);
|
|
58
|
+
}
|
|
59
|
+
if (!c.origin || visited[c.origin.id]) break;
|
|
60
|
+
visited[c.origin.id] = true;
|
|
61
|
+
c = load(c.origin.id, c.origin.collection);
|
|
62
|
+
} while (c);
|
|
63
|
+
|
|
64
|
+
return slugs.shift() + slugs.join('/');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Editor types that contains {collection, id} references that we want to load
|
|
69
|
+
*/
|
|
70
|
+
const RELATION_EDITORS = ["related", "references"];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Loads the template document of the specified document
|
|
74
|
+
* @param {any} document - The document to index
|
|
75
|
+
* @returns The document's template, loaded
|
|
76
|
+
*/
|
|
77
|
+
function loadTemplate(document) {
|
|
78
|
+
const collection = document['@metadata']['@collection'];
|
|
79
|
+
const template = load('templates/' + collection, 'templates');
|
|
80
|
+
return template;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Iterates the template's editors and copies the respective values to the
|
|
85
|
+
* result object. Properties containing references are resolved recursively.
|
|
86
|
+
* Mutually recursive with \`loadRelatedDocumentsRecurse\`.
|
|
87
|
+
* @param {*} document - The document to extract values from
|
|
88
|
+
* @param {*} template - The document's template
|
|
89
|
+
* @param {*} result - The populated result
|
|
90
|
+
*/
|
|
91
|
+
function populateValuesByEditor(document, template, result) {
|
|
92
|
+
// Add dynamic fields and handle "related" type
|
|
93
|
+
template.editors.forEach(editor => {
|
|
94
|
+
if (editor.editor && editor.editor.propertyName) {
|
|
95
|
+
const propertyName = editor.editor.propertyName;
|
|
96
|
+
|
|
97
|
+
if (RELATION_EDITORS.includes(editor.editor.type) && Array.isArray(document[propertyName])) {
|
|
98
|
+
// Load related documents in the array of document references
|
|
99
|
+
const relatedDocs = loadRelatedDocumentsRecurse(document[propertyName])
|
|
100
|
+
result[propertyName] = relatedDocs;
|
|
101
|
+
} else if (document[propertyName] !== undefined) {
|
|
102
|
+
// For other types, index the field value directly
|
|
103
|
+
result[propertyName] = document[propertyName];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
if (document['@strife']) {
|
|
108
|
+
result['@strife'] = document['@strife'];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Loads the documents referenced by the array of references. Mutually recursive
|
|
114
|
+
* with \`populateValuesByEditor\`.
|
|
115
|
+
* @param {*} references - List of references to load.
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
function loadRelatedDocumentsRecurse(references) {
|
|
119
|
+
if (references == null) return null;
|
|
120
|
+
const documents = references
|
|
121
|
+
//.filter(id => typeof id === "string" || (typeof id === "object" && id.id)) // Ensure each ID is a string or object with an id
|
|
122
|
+
.map(id => (typeof id === "string" ? id : id.id))
|
|
123
|
+
.map(id => (load(id, 'Contacts') || load(id, 'Articles') || load(id, 'ContentTexts') || load(id, 'Notices') || load(id, 'EducationPages')))
|
|
124
|
+
.filter(Boolean); // Filter out any null/undefined values
|
|
125
|
+
|
|
126
|
+
const docResults = [];
|
|
127
|
+
documents.forEach(doc => {
|
|
128
|
+
const template = loadTemplate(doc);
|
|
129
|
+
const docResult = {
|
|
130
|
+
id: Id(doc),
|
|
131
|
+
url: buildUrl(doc),
|
|
132
|
+
collection: doc['@metadata']['@collection'],
|
|
133
|
+
labels: loadRelatedDocuments(
|
|
134
|
+
doc.labels.map(l => { return { id: l, collection: "Labels" } })),
|
|
135
|
+
};
|
|
136
|
+
populateValuesByEditor(doc, template, docResult);
|
|
137
|
+
docResults.push(docResult)
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return docResults;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Maps a document to an index entry for Strife's content index
|
|
145
|
+
* @param {any} document - The document to index
|
|
146
|
+
* @returns An object to be indexed by RavenDB
|
|
147
|
+
*/
|
|
148
|
+
function mapDocument(document) {
|
|
149
|
+
const collection = document['@metadata']['@collection'];
|
|
150
|
+
const template = load('templates/' + collection, 'templates');
|
|
151
|
+
|
|
152
|
+
if (!template || !template.editors || document.deleted || document.archived) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Initialize result with static fields
|
|
157
|
+
const result = {
|
|
158
|
+
id: Id(document),
|
|
159
|
+
displayName: document.displayName,
|
|
160
|
+
url: storeAs('url', buildUrl(document)),
|
|
161
|
+
origin: document.origin,
|
|
162
|
+
collection: storeAs('collection', collection),
|
|
163
|
+
publishedDate: document.publishedDate,
|
|
164
|
+
createdAt: document.createdAt,
|
|
165
|
+
labels: storeAs('labels', loadRelatedDocuments(
|
|
166
|
+
document.labels.map(l => { return { id: l, collection: "Labels" } }))),
|
|
167
|
+
deleted: document.deleted,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// Add dynamic fields and handle "related" type
|
|
171
|
+
template.editors.forEach(editor => {
|
|
172
|
+
if (editor.editor && editor.editor.propertyName) {
|
|
173
|
+
const propertyName = editor.editor.propertyName;
|
|
174
|
+
|
|
175
|
+
if (RELATION_EDITORS.includes(editor.editor.type) && Array.isArray(document[propertyName])) {
|
|
176
|
+
// Load related documents in the array of document references
|
|
177
|
+
const relatedDocs = loadRelatedDocumentsRecurse(document[propertyName]);
|
|
178
|
+
result[propertyName] = storeAs(propertyName, relatedDocs);
|
|
179
|
+
} else if (editor.editor.type === 'content-template') {
|
|
180
|
+
const content = document[propertyName];
|
|
181
|
+
if (content) {
|
|
182
|
+
const template = load(editor.editor.attributes.templateId, 'templates');
|
|
183
|
+
const docResult = {};
|
|
184
|
+
populateValuesByEditor(content, template, docResult);
|
|
185
|
+
result[propertyName] = storeAs(propertyName, docResult);
|
|
186
|
+
}
|
|
187
|
+
} else if (editor.editor.type === 'chapters') {
|
|
188
|
+
const chapters = document[propertyName];
|
|
189
|
+
if (chapters && Array.isArray(chapters)) {
|
|
190
|
+
const docResults = [];
|
|
191
|
+
chapters.forEach(chapter => {
|
|
192
|
+
if (chapter['@strife'] && chapter['@strife'].templateId) {
|
|
193
|
+
const docResult = {};
|
|
194
|
+
const template = load(chapter['@strife'].templateId, 'templates');
|
|
195
|
+
populateValuesByEditor(chapter, template, docResult);
|
|
196
|
+
docResults.push(docResult);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
result[propertyName] = storeAs(propertyName, docResults);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if (document[propertyName] !== undefined) {
|
|
203
|
+
// For other types, index the field value directly
|
|
204
|
+
result[propertyName] = indexAs(propertyName, document[propertyName]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
`, d = "strife:store", i = "\0" + d;
|
|
212
|
+
function h(e) {
|
|
213
|
+
return {
|
|
214
|
+
name: "strife:store",
|
|
215
|
+
resolveId(o) {
|
|
216
|
+
if (o === d)
|
|
217
|
+
return i;
|
|
218
|
+
},
|
|
219
|
+
load(o) {
|
|
220
|
+
var t;
|
|
221
|
+
if (o === i)
|
|
222
|
+
return `
|
|
223
|
+
import { DocumentStore, AbstractJavaScriptMultiMapIndexCreationTask, IndexCreation } from "ravendb";
|
|
224
|
+
|
|
225
|
+
const authOptions = {
|
|
226
|
+
type: 'pfx',
|
|
227
|
+
certificate: Buffer.from(${r(e.certificate)}, 'base64'),
|
|
228
|
+
password: ${r(e.password)},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const store = new DocumentStore(
|
|
232
|
+
${r(e.urls ? e.urls : [])},
|
|
233
|
+
${r(e.database || "")},
|
|
234
|
+
authOptions
|
|
235
|
+
).initialize()
|
|
236
|
+
|
|
237
|
+
class Content_ByUrlzz extends AbstractJavaScriptMultiMapIndexCreationTask {
|
|
238
|
+
constructor() {
|
|
239
|
+
super();
|
|
240
|
+
|
|
241
|
+
this.additionalSources = {"Helper": ${r(y)}}
|
|
242
|
+
|
|
243
|
+
${(e.collections || ["Posts"]).map((n) => `this.map("${typeof n == "string" ? n : n.name}", (doc) => mapDocument(doc));`).join(`
|
|
244
|
+
`)}
|
|
245
|
+
|
|
246
|
+
this.deploymentMode = 'Rolling';
|
|
247
|
+
this.searchEngineType = 'Lucene';
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
console.log('Deploying index...');
|
|
252
|
+
await IndexCreation.createIndexes([new Content_ByUrlzz()], store);
|
|
253
|
+
|
|
254
|
+
const bulkInsert = store.bulkInsert();
|
|
255
|
+
|
|
256
|
+
${(t = e.collections) == null ? void 0 : t.map((n) => `
|
|
257
|
+
bulkInsert.store(${JSON.stringify(n)}, 'templates/${n.name}', { '@collection': 'Templates' });
|
|
258
|
+
`).join(`
|
|
259
|
+
`)}
|
|
260
|
+
|
|
261
|
+
await bulkInsert.finish();
|
|
262
|
+
|
|
263
|
+
export { store };
|
|
264
|
+
`;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const v = {
|
|
269
|
+
type: "pfx"
|
|
6
270
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
271
|
+
function N(e) {
|
|
272
|
+
let o, t;
|
|
273
|
+
return {
|
|
274
|
+
name: "@strife/astro",
|
|
275
|
+
hooks: {
|
|
276
|
+
"astro:config:setup": ({ command: n, config: a, updateConfig: l }) => {
|
|
277
|
+
var s;
|
|
278
|
+
o = n, t = f(o, a.vite.envDir ?? "", "");
|
|
279
|
+
const c = {
|
|
280
|
+
urls: (s = t.STRIFE_DATABASE_URLS) == null ? void 0 : s.split(","),
|
|
281
|
+
database: t.STRIFE_DATABASE,
|
|
282
|
+
certificate: t.STRIFE_CERTIFICATE,
|
|
283
|
+
password: t.STRIFE_CERTIFICATE_PASSWORD
|
|
284
|
+
}, u = Object.fromEntries(
|
|
285
|
+
Object.entries(c).filter(([R, m]) => m !== void 0)
|
|
286
|
+
), p = {
|
|
287
|
+
...v,
|
|
288
|
+
// Base defaults
|
|
289
|
+
...u,
|
|
290
|
+
// Environment variables override defaults
|
|
291
|
+
...e
|
|
292
|
+
// Explicit options override everything
|
|
293
|
+
};
|
|
294
|
+
l({
|
|
295
|
+
vite: {
|
|
296
|
+
plugins: [
|
|
297
|
+
h(p)
|
|
298
|
+
]
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
39
304
|
}
|
|
305
|
+
export {
|
|
306
|
+
N as default
|
|
307
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { IntegrationOptions } from './index';
|
|
2
|
+
import { PluginOption } from 'vite';
|
|
3
3
|
export declare function vitePluginStrifeStore(config: IntegrationOptions): PluginOption;
|
package/package.json
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strifeapp/astro",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Official Strife Astro integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro-integration",
|
|
7
7
|
"withastro",
|
|
8
8
|
"strife"
|
|
9
9
|
],
|
|
10
|
-
"main": "dist/index.js",
|
|
11
|
-
"
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
12
13
|
"type": "module",
|
|
13
14
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
+
"clean": "rm -rf dist",
|
|
16
|
+
"build": "npm run clean && vite build",
|
|
15
17
|
"prepublishOnly": "npm run build"
|
|
16
18
|
},
|
|
17
19
|
"exports": {
|
|
18
|
-
".":
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
},
|
|
19
24
|
"./vite-plugin-strife-store": "./dist/vite-plugin-strife-store-entry.js",
|
|
20
25
|
"./module": "./module.d.ts"
|
|
21
26
|
},
|
|
@@ -30,6 +35,7 @@
|
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
32
37
|
"@types/dotenv": "^8.2.0",
|
|
38
|
+
"rimraf": "^6.0.1",
|
|
33
39
|
"typescript": "^5.7.3",
|
|
34
40
|
"vite": "^6.2.1",
|
|
35
41
|
"vite-plugin-dts": "^4.5.3"
|
|
@@ -37,5 +43,10 @@
|
|
|
37
43
|
"peerDependencies": {
|
|
38
44
|
"astro": "^4.0.0 || ^5.0.0",
|
|
39
45
|
"ravendb": "^6.0.0"
|
|
46
|
+
},
|
|
47
|
+
"compilerOptions": {
|
|
48
|
+
"declaration": true,
|
|
49
|
+
"emitDeclarationOnly": false,
|
|
50
|
+
"outDir": "dist"
|
|
40
51
|
}
|
|
41
52
|
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import serialize from 'serialize-javascript';
|
|
2
|
-
import contentIndex from './contentIndex.js?raw';
|
|
3
|
-
const virtualModuleId = 'strife:store';
|
|
4
|
-
const resolvedVirtualModuleId = '\0' + virtualModuleId;
|
|
5
|
-
export function vitePluginStrifeStore(config) {
|
|
6
|
-
return {
|
|
7
|
-
name: 'strife:store',
|
|
8
|
-
resolveId(id) {
|
|
9
|
-
if (id === virtualModuleId) {
|
|
10
|
-
return resolvedVirtualModuleId;
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
load(id) {
|
|
14
|
-
if (id === resolvedVirtualModuleId) {
|
|
15
|
-
return `
|
|
16
|
-
import { DocumentStore, AbstractJavaScriptMultiMapIndexCreationTask, IndexCreation } from "ravendb";
|
|
17
|
-
|
|
18
|
-
const authOptions = {
|
|
19
|
-
type: 'pfx',
|
|
20
|
-
certificate: Buffer.from(${serialize(config.certificate)}, 'base64'),
|
|
21
|
-
password: ${serialize(config.password)},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const store = new DocumentStore(
|
|
25
|
-
${serialize(config.urls ? config.urls : [])},
|
|
26
|
-
${serialize(config.database || '')},
|
|
27
|
-
authOptions
|
|
28
|
-
).initialize()
|
|
29
|
-
|
|
30
|
-
class Content_ByUrlzz extends AbstractJavaScriptMultiMapIndexCreationTask {
|
|
31
|
-
constructor() {
|
|
32
|
-
super();
|
|
33
|
-
|
|
34
|
-
this.additionalSources = {"Helper": ${serialize(contentIndex)}}
|
|
35
|
-
|
|
36
|
-
${(config.collections || ['Posts']).map(collection => `this.map("${collection.name}", (doc) => mapDocument(doc));`).join('\n')}
|
|
37
|
-
|
|
38
|
-
this.deploymentMode = 'Rolling';
|
|
39
|
-
this.searchEngineType = 'Lucene';
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
console.log('Deploying index...');
|
|
44
|
-
await IndexCreation.createIndexes([new Content_ByUrlzz()], store);
|
|
45
|
-
|
|
46
|
-
const bulkInsert = store.bulkInsert();
|
|
47
|
-
|
|
48
|
-
${config.collections?.map(collection => `
|
|
49
|
-
bulkInsert.store(${serialize(collection)}, 'templates/${collection.name}', { '@collection': 'Templates' });
|
|
50
|
-
`).join('\n')}
|
|
51
|
-
|
|
52
|
-
await bulkInsert.finish();
|
|
53
|
-
|
|
54
|
-
export { store };
|
|
55
|
-
`;
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|