@acodeninja/persist 2.3.1 → 2.3.2
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/package.json +1 -1
- package/src/Persist.js +1 -1
- package/src/engine/Engine.js +6 -4
- package/src/engine/HTTPEngine.js +12 -12
- package/src/engine/S3Engine.js +5 -5
- package/src/type/Model.js +1 -1
- package/src/type/resolved/SlugType.js +2 -0
package/package.json
CHANGED
package/src/Persist.js
CHANGED
package/src/engine/Engine.js
CHANGED
@@ -258,8 +258,10 @@ class Engine {
|
|
258
258
|
|
259
259
|
for (const [name, property] of Object.entries(modelToProcess)) {
|
260
260
|
if (Type.Model.isDryModel(property)) {
|
261
|
+
// skipcq: JS-0129
|
261
262
|
modelToProcess[name] = await hydrateSubModel(property, modelToProcess, name);
|
262
263
|
} else if (Array.isArray(property) && Type.Model.isDryModel(property[0])) {
|
264
|
+
// skipcq: JS-0129
|
263
265
|
modelToProcess[name] = await hydrateModelList(property, modelToProcess, name);
|
264
266
|
}
|
265
267
|
}
|
@@ -283,15 +285,15 @@ class Engine {
|
|
283
285
|
const hydrateModelList = async (property, modelToProcess, name) => {
|
284
286
|
const subModelClass = getSubModelClass(modelToProcess, name, true);
|
285
287
|
|
286
|
-
const newModelList = await Promise.all(property.map(
|
288
|
+
const newModelList = await Promise.all(property.map(subModel => {
|
287
289
|
if (hydratedModels[subModel.id]) {
|
288
290
|
return hydratedModels[subModel.id];
|
289
291
|
}
|
290
292
|
|
291
|
-
return
|
293
|
+
return this.get(subModelClass, subModel.id);
|
292
294
|
}));
|
293
295
|
|
294
|
-
return
|
296
|
+
return Promise.all(newModelList.map(async subModel => {
|
295
297
|
if (hydratedModels[subModel.id]) {
|
296
298
|
return hydratedModels[subModel.id];
|
297
299
|
}
|
@@ -312,7 +314,7 @@ class Engine {
|
|
312
314
|
return isArray ? constructorField._items : constructorField;
|
313
315
|
}
|
314
316
|
|
315
|
-
return
|
317
|
+
return hydrateModel(await this.get(model.constructor, model.id));
|
316
318
|
}
|
317
319
|
|
318
320
|
/**
|
package/src/engine/HTTPEngine.js
CHANGED
@@ -126,7 +126,7 @@ class HTTPEngine extends Engine {
|
|
126
126
|
*
|
127
127
|
* @throws {HTTPRequestFailedError} Thrown if the fetch request fails.
|
128
128
|
*/
|
129
|
-
static
|
129
|
+
static getById(id) {
|
130
130
|
this.checkConfiguration();
|
131
131
|
|
132
132
|
const url = new URL([
|
@@ -135,7 +135,7 @@ class HTTPEngine extends Engine {
|
|
135
135
|
`${id}.json`,
|
136
136
|
].filter(e => Boolean(e)).join('/'));
|
137
137
|
|
138
|
-
return
|
138
|
+
return this._processFetch(url, this._getReadOptions());
|
139
139
|
}
|
140
140
|
|
141
141
|
/**
|
@@ -177,7 +177,7 @@ class HTTPEngine extends Engine {
|
|
177
177
|
'_index.json',
|
178
178
|
].filter(e => Boolean(e)).join('/'));
|
179
179
|
|
180
|
-
return
|
180
|
+
return this._processFetch(url, {
|
181
181
|
...this._getWriteOptions(),
|
182
182
|
body: JSON.stringify({
|
183
183
|
...await this.getIndex(location),
|
@@ -199,7 +199,7 @@ class HTTPEngine extends Engine {
|
|
199
199
|
* @param {Model.constructor?} model - The model in the host where the index is stored.
|
200
200
|
* @returns {Promise<Object>} The index data in JSON format.
|
201
201
|
*/
|
202
|
-
static
|
202
|
+
static getIndex(model) {
|
203
203
|
const url = new URL([
|
204
204
|
this.configuration.host,
|
205
205
|
this.configuration.prefix,
|
@@ -207,7 +207,7 @@ class HTTPEngine extends Engine {
|
|
207
207
|
'_index.json',
|
208
208
|
].filter(e => Boolean(e)).join('/'));
|
209
209
|
|
210
|
-
return
|
210
|
+
return this._processFetch(url, this._getReadOptions(), {});
|
211
211
|
}
|
212
212
|
|
213
213
|
/**
|
@@ -216,7 +216,7 @@ class HTTPEngine extends Engine {
|
|
216
216
|
* @param {Model.constructor} model - The model whose compiled search index to retrieve.
|
217
217
|
* @returns {Promise<Object>} The compiled search index in JSON format.
|
218
218
|
*/
|
219
|
-
static
|
219
|
+
static getSearchIndexCompiled(model) {
|
220
220
|
const url = new URL([
|
221
221
|
this.configuration.host,
|
222
222
|
this.configuration.prefix,
|
@@ -224,7 +224,7 @@ class HTTPEngine extends Engine {
|
|
224
224
|
'_search_index.json',
|
225
225
|
].join('/'));
|
226
226
|
|
227
|
-
return
|
227
|
+
return this._processFetch(url, this._getReadOptions());
|
228
228
|
}
|
229
229
|
|
230
230
|
/**
|
@@ -233,7 +233,7 @@ class HTTPEngine extends Engine {
|
|
233
233
|
* @param {Model.constructor} model - The model whose raw search index to retrieve.
|
234
234
|
* @returns {Promise<Object>} The raw search index in JSON format, or an empty object if not found.
|
235
235
|
*/
|
236
|
-
static
|
236
|
+
static getSearchIndexRaw(model) {
|
237
237
|
const url = new URL([
|
238
238
|
this.configuration.host,
|
239
239
|
this.configuration.prefix,
|
@@ -241,7 +241,7 @@ class HTTPEngine extends Engine {
|
|
241
241
|
'_search_index_raw.json',
|
242
242
|
].join('/'));
|
243
243
|
|
244
|
-
return
|
244
|
+
return this._processFetch(url, this._getReadOptions()).catch(() => ({}));
|
245
245
|
}
|
246
246
|
|
247
247
|
/**
|
@@ -253,7 +253,7 @@ class HTTPEngine extends Engine {
|
|
253
253
|
*
|
254
254
|
* @throws {HTTPRequestFailedError} Thrown if the PUT request fails.
|
255
255
|
*/
|
256
|
-
static
|
256
|
+
static putSearchIndexCompiled(model, compiledIndex) {
|
257
257
|
const url = new URL([
|
258
258
|
this.configuration.host,
|
259
259
|
this.configuration.prefix,
|
@@ -276,7 +276,7 @@ class HTTPEngine extends Engine {
|
|
276
276
|
*
|
277
277
|
* @throws {HTTPRequestFailedError} Thrown if the PUT request fails.
|
278
278
|
*/
|
279
|
-
static
|
279
|
+
static putSearchIndexRaw(model, rawIndex) {
|
280
280
|
const url = new URL([
|
281
281
|
this.configuration.host,
|
282
282
|
this.configuration.prefix,
|
@@ -284,7 +284,7 @@ class HTTPEngine extends Engine {
|
|
284
284
|
'_search_index_raw.json',
|
285
285
|
].filter(e => Boolean(e)).join('/'));
|
286
286
|
|
287
|
-
return
|
287
|
+
return this._processFetch(url, {
|
288
288
|
...this._getWriteOptions(),
|
289
289
|
body: JSON.stringify(rawIndex),
|
290
290
|
});
|
package/src/engine/S3Engine.js
CHANGED
@@ -153,9 +153,9 @@ class S3Engine extends Engine {
|
|
153
153
|
* @param {Model.constructor} model - The model whose search index to retrieve.
|
154
154
|
* @returns {Promise<Object>} The compiled search index.
|
155
155
|
*/
|
156
|
-
static
|
157
|
-
return
|
158
|
-
Key: [this.configuration.prefix, model.
|
156
|
+
static getSearchIndexCompiled(model) {
|
157
|
+
return this.configuration.client.send(new GetObjectCommand({
|
158
|
+
Key: [this.configuration.prefix, model.toString(), '_search_index.json'].join('/'),
|
159
159
|
Bucket: this.configuration.bucket,
|
160
160
|
})).then(data => data.Body.transformToString())
|
161
161
|
.then(JSON.parse);
|
@@ -167,8 +167,8 @@ class S3Engine extends Engine {
|
|
167
167
|
* @param {Model.constructor} model - The model whose raw search index to retrieve.
|
168
168
|
* @returns {Promise<Object>} The raw search index, or an empty object if not found.
|
169
169
|
*/
|
170
|
-
static
|
171
|
-
return
|
170
|
+
static getSearchIndexRaw(model) {
|
171
|
+
return this.configuration.client.send(new GetObjectCommand({
|
172
172
|
Key: [this.configuration.prefix, model.toString(), '_search_index_raw.json'].join('/'),
|
173
173
|
Bucket: this.configuration.bucket,
|
174
174
|
})).then(data => data.Body.transformToString())
|
package/src/type/Model.js
CHANGED