@strifeapp/astro 1.0.7 → 1.0.9

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { loadEnv as f } from "vite";
2
- import r from "serialize-javascript";
2
+ import a from "serialize-javascript";
3
3
  const y = `/**
4
4
  * Creates an indexed item that will be stored in the index.
5
5
  * @param {string} name - Name of property to index
@@ -7,240 +7,293 @@ const y = `/**
7
7
  * @returns a new object to index and store
8
8
  */
9
9
  function storeAs(name, value) {
10
- return {
10
+ return {
11
11
  $value: value,
12
12
  $name: name,
13
- $options: { storage: true }
14
- };
15
- }
13
+ $options: { storage: true },
14
+ };
15
+ }
16
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 {
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
25
  $value: value,
26
26
  $name: name,
27
- $options: { storage: false }
28
- };
29
- }
27
+ $options: { storage: false },
28
+ };
29
+ }
30
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'))
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
41
  .filter(Boolean); // Filter out any null/undefined values
42
- }
43
-
42
+ }
44
43
 
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;
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;
54
53
 
55
- do {
54
+ do {
56
55
  if (c.slug) {
57
- slugs.unshift(c.slug);
56
+ slugs.unshift(c.slug);
58
57
  }
59
58
  if (!c.origin || visited[c.origin.id]) break;
60
59
  visited[c.origin.id] = true;
61
60
  c = load(c.origin.id, c.origin.collection);
62
- } while (c);
61
+ } while (c);
63
62
 
64
- return slugs.shift() + slugs.join('/');
65
- }
63
+ return slugs.shift() + slugs.join('/');
64
+ }
66
65
 
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
- }
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
+ }
82
90
 
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 => {
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) => {
94
104
  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];
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;
104
132
  }
133
+ } else if (document[propertyName] !== undefined) {
134
+ // For other types, index the field value directly
135
+ result[propertyName] = document[propertyName];
136
+ }
105
137
  }
106
- });
107
- if (document['@strife']) {
138
+ });
139
+ if (document['@strife']) {
108
140
  result['@strife'] = document['@strife'];
141
+ }
109
142
  }
110
- }
111
143
 
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')))
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
+ })
124
164
  .filter(Boolean); // Filter out any null/undefined values
125
165
 
126
- const docResults = [];
127
- documents.forEach(doc => {
166
+ const docResults = [];
167
+ documents.forEach((doc) => {
128
168
  const template = loadTemplate(doc);
129
169
  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" } })),
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
+ ),
135
178
  };
136
- populateValuesByEditor(doc, template, docResult);
137
- docResults.push(docResult)
138
- });
179
+ populateValuesByEditor(doc, template, metadataTemplate, docResult, loadedDocs);
180
+ docResults.push(docResult);
181
+ });
139
182
 
140
- return docResults;
141
- }
183
+ return docResults;
184
+ }
142
185
 
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');
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');
151
194
 
152
- if (!template || !template.editors || document.deleted || document.archived) {
195
+ if (!template || !template.editors || document.deleted || document.archived) {
153
196
  return null;
154
- }
197
+ }
198
+
199
+ const metadataTemplate = loadMetadataTemplate();
155
200
 
156
- // Initialize result with static fields
157
- const result = {
201
+ // Initialize result with static fields
202
+ const result = {
158
203
  id: Id(document),
159
204
  displayName: document.displayName,
160
205
  url: storeAs('url', buildUrl(document)),
161
206
  origin: document.origin,
162
207
  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" } }))),
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
+ ),
167
219
  deleted: document.deleted,
168
- };
220
+ };
221
+
222
+ // Keep tabs of loaded documents to avoid infinite recursion
223
+ const loadedDocuments = new Set(result.id);
169
224
 
170
- // Add dynamic fields and handle "related" type
171
- template.editors.forEach(editor => {
225
+ // Add dynamic fields and handle "related" type
226
+ template.editors.forEach((editor) => {
172
227
  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
- }
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);
201
241
  }
202
- else if (document[propertyName] !== undefined) {
203
- // For other types, index the field value directly
204
- result[propertyName] = indexAs(propertyName, document[propertyName]);
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);
205
255
  }
256
+ } else if (document[propertyName] !== undefined) {
257
+ // For other types, index the field value directly
258
+ result[propertyName] = indexAs(propertyName, document[propertyName]);
259
+ }
206
260
  }
207
- });
261
+ });
208
262
 
209
- return result;
210
- }
211
- `, d = "strife:store", i = "\0" + d;
263
+ return result;
264
+ }`, l = "strife:store", d = "\0" + l;
212
265
  function h(e) {
213
266
  return {
214
267
  name: "strife:store",
215
268
  resolveId(o) {
216
- if (o === d)
217
- return i;
269
+ if (o === l)
270
+ return d;
218
271
  },
219
272
  load(o) {
220
273
  var t;
221
- if (o === i)
274
+ if (o === d)
222
275
  return `
223
276
  import { DocumentStore, AbstractJavaScriptMultiMapIndexCreationTask, IndexCreation } from "ravendb";
224
277
 
225
278
  const authOptions = {
226
279
  type: 'pfx',
227
- certificate: Buffer.from(${r(e.certificate)}, 'base64'),
228
- password: ${r(e.password)},
280
+ certificate: Buffer.from(${a(e.certificate)}, 'base64'),
281
+ password: ${a(e.password)},
229
282
  };
230
283
 
231
284
  const store = new DocumentStore(
232
- ${r(e.urls ? e.urls : [])},
233
- ${r(e.database || "")},
285
+ ${a(e.urls ? e.urls : [])},
286
+ ${a(e.database || "")},
234
287
  authOptions
235
288
  ).initialize()
236
289
 
237
- class Content_ByUrlzz extends AbstractJavaScriptMultiMapIndexCreationTask {
290
+ class Content_ByUrl extends AbstractJavaScriptMultiMapIndexCreationTask {
238
291
  constructor() {
239
292
  super();
240
293
 
241
- this.additionalSources = {"Helper": ${r(y)}}
294
+ this.additionalSources = {"Helper": ${a(y)}}
242
295
 
243
- ${(e.collections || ["Posts"]).map((n) => `this.map("${typeof n == "string" ? n : n.name}", (doc) => mapDocument(doc));`).join(`
296
+ ${(e.collections || ["Posts"]).map((n) => `this.map("${typeof n == "string" ? n : n.name}", (doc) => { return });`).join(`
244
297
  `)}
245
298
 
246
299
  this.deploymentMode = 'Rolling';
@@ -249,12 +302,13 @@ function h(e) {
249
302
  }
250
303
 
251
304
  console.log('Deploying index...');
252
- await IndexCreation.createIndexes([new Content_ByUrlzz()], store);
305
+
306
+ await IndexCreation.createIndexes([new Content_ByUrl()], store);
253
307
 
254
308
  const bulkInsert = store.bulkInsert();
255
309
 
256
310
  ${(t = e.collections) == null ? void 0 : t.map((n) => `
257
- bulkInsert.store(${JSON.stringify(n)}, 'templates/${n.name}', { '@collection': 'Templates' });
311
+ await bulkInsert.store(${JSON.stringify(n)}, 'templates/${n.name}', { '@collection': 'Templates' });
258
312
  `).join(`
259
313
  `)}
260
314
 
@@ -265,33 +319,33 @@ function h(e) {
265
319
  }
266
320
  };
267
321
  }
268
- const v = {
322
+ const T = {
269
323
  type: "pfx"
270
324
  };
271
- function N(e) {
325
+ function b(e) {
272
326
  let o, t;
273
327
  return {
274
328
  name: "@strife/astro",
275
329
  hooks: {
276
- "astro:config:setup": ({ command: n, config: a, updateConfig: l }) => {
330
+ "astro:config:setup": ({ command: n, config: r, updateConfig: c }) => {
277
331
  var s;
278
- o = n, t = f(o, a.vite.envDir ?? "", "");
279
- const c = {
332
+ o = n, t = f(o, r.vite.envDir ?? "", "");
333
+ const i = {
280
334
  urls: (s = t.STRIFE_DATABASE_URLS) == null ? void 0 : s.split(","),
281
335
  database: t.STRIFE_DATABASE,
282
336
  certificate: t.STRIFE_CERTIFICATE,
283
337
  password: t.STRIFE_CERTIFICATE_PASSWORD
284
338
  }, u = Object.fromEntries(
285
- Object.entries(c).filter(([R, m]) => m !== void 0)
339
+ Object.entries(i).filter(([R, m]) => m !== void 0)
286
340
  ), p = {
287
- ...v,
341
+ ...T,
288
342
  // Base defaults
289
343
  ...u,
290
344
  // Environment variables override defaults
291
345
  ...e
292
346
  // Explicit options override everything
293
347
  };
294
- l({
348
+ c({
295
349
  vite: {
296
350
  plugins: [
297
351
  h(p)
@@ -303,5 +357,5 @@ function N(e) {
303
357
  };
304
358
  }
305
359
  export {
306
- N as default
360
+ b as default
307
361
  };
@@ -0,0 +1,3 @@
1
+ import { ImageService } from 'astro';
2
+ declare const service: ImageService;
3
+ export default service;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strifeapp/astro",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Official Strife Astro integration",
5
5
  "keywords": [
6
6
  "astro-integration",