@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acodeninja/persist",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "A JSON based data modelling and persistence module with alternate storage mechanisms.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/Persist.js CHANGED
@@ -1,4 +1,4 @@
1
- import Type from '../src/type/index.js';
1
+ import Type from './type/index.js';
2
2
  import enableTransactions from './Transactions.js';
3
3
 
4
4
  /**
@@ -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(async subModel => {
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 await this.get(subModelClass, subModel.id);
293
+ return this.get(subModelClass, subModel.id);
292
294
  }));
293
295
 
294
- return await Promise.all(newModelList.map(async subModel => {
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 await hydrateModel(await this.get(model.constructor, model.id));
317
+ return hydrateModel(await this.get(model.constructor, model.id));
316
318
  }
317
319
 
318
320
  /**
@@ -126,7 +126,7 @@ class HTTPEngine extends Engine {
126
126
  *
127
127
  * @throws {HTTPRequestFailedError} Thrown if the fetch request fails.
128
128
  */
129
- static async getById(id) {
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 await this._processFetch(url, this._getReadOptions());
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 await this._processFetch(url, {
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 async getIndex(model) {
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 await this._processFetch(url, this._getReadOptions(), {});
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 async getSearchIndexCompiled(model) {
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 await this._processFetch(url, this._getReadOptions());
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 async getSearchIndexRaw(model) {
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 await this._processFetch(url, this._getReadOptions()).catch(() => ({}));
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 async putSearchIndexCompiled(model, compiledIndex) {
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 async putSearchIndexRaw(model, rawIndex) {
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 await this._processFetch(url, {
287
+ return this._processFetch(url, {
288
288
  ...this._getWriteOptions(),
289
289
  body: JSON.stringify(rawIndex),
290
290
  });
@@ -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 async getSearchIndexCompiled(model) {
157
- return await this.configuration.client.send(new GetObjectCommand({
158
- Key: [this.configuration.prefix, model.name, '_search_index.json'].join('/'),
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 async getSearchIndexRaw(model) {
171
- return await this.configuration.client.send(new GetObjectCommand({
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
@@ -40,7 +40,7 @@ class Model {
40
40
  }
41
41
  if (value?._resolved) {
42
42
  Object.defineProperty(this, key, {
43
- get: function () {
43
+ get() {
44
44
  return value.resolve(this);
45
45
  },
46
46
  });
@@ -53,6 +53,8 @@ class SlugType extends ResolvedType {
53
53
 
54
54
  return slugify(model?.[property], {
55
55
  lower: true,
56
+ strict: true,
57
+ trim: true,
56
58
  });
57
59
  }
58
60
  }