@aeriajs/core 0.0.204 → 0.0.205

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.
@@ -101,14 +101,9 @@ const preloadDescription = async (originalDescription, options) => {
101
101
  Object.assign(description, merge);
102
102
  }
103
103
  if (description.properties) {
104
- const properties = [];
105
104
  for (const [propName, property] of Object.entries(description.properties)) {
106
- properties.push([
107
- propName,
108
- await recurseProperty(property, propName, description),
109
- ]);
105
+ description.properties[propName] = await recurseProperty(property, propName, description);
110
106
  }
111
- description.properties = Object.fromEntries(properties);
112
107
  }
113
108
  if (memoize) {
114
109
  preloadMemo[originalDescription.$id] = description;
@@ -77,14 +77,9 @@ export const preloadDescription = async (originalDescription, options) => {
77
77
  Object.assign(description, merge);
78
78
  }
79
79
  if (description.properties) {
80
- const properties = [];
81
80
  for (const [propName, property] of Object.entries(description.properties)) {
82
- properties.push([
83
- propName,
84
- await recurseProperty(property, propName, description)
85
- ]);
81
+ description.properties[propName] = await recurseProperty(property, propName, description);
86
82
  }
87
- description.properties = Object.fromEntries(properties);
88
83
  }
89
84
  if (memoize) {
90
85
  preloadMemo[originalDescription.$id] = description;
@@ -41,9 +41,7 @@ const getReferences = async (properties, options = {}) => {
41
41
  reference.deepReferences = deepReferences;
42
42
  }
43
43
  }
44
- const indexes = refProperty.indexes
45
- ? refProperty.indexes
46
- : description.indexes || [];
44
+ const { indexes = description.indexes || [] } = refProperty;
47
45
  reference.populate = (refProperty.populate || []).concat(indexes.filter((index) => typeof index === 'string'));
48
46
  }
49
47
  else {
@@ -199,7 +197,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
199
197
  };
200
198
  }
201
199
  if (reference.deepReferences) {
202
- const stages = [];
200
+ const stages = {};
203
201
  for (const [subRefName, subReference] of Object.entries(reference.deepReferences)) {
204
202
  let newElem;
205
203
  if (shouldUseArrayIndex) {
@@ -231,10 +229,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
231
229
  'referencedCollection' in subReference,
232
230
  ],
233
231
  ]), newElem);
234
- stages.push([
235
- subRefName,
236
- result,
237
- ]);
232
+ stages[subRefName] = result;
238
233
  }
239
234
  if (reference.referencedCollection) {
240
235
  return {
@@ -253,14 +248,14 @@ const recurseSetStage = (reference, path, parentElem, options = {
253
248
  }, path, parentElem, {
254
249
  noCond: true,
255
250
  }),
256
- Object.fromEntries(stages),
251
+ stages,
257
252
  ],
258
253
  },
259
254
  null,
260
255
  ],
261
256
  };
262
257
  }
263
- return Object.fromEntries(stages);
258
+ return stages;
264
259
  }
265
260
  const arrayElemAt = {
266
261
  $arrayElemAt: [
@@ -296,7 +291,7 @@ const buildLookupPipeline = (refMap, options = {}) => {
296
291
  }
297
292
  }
298
293
  const pipeline = [];
299
- const setProperties = [];
294
+ const setProperties = {};
300
295
  for (const [refName, reference] of Object.entries(refMap)) {
301
296
  if (project) {
302
297
  if (!project.includes(refName)) {
@@ -316,10 +311,7 @@ const buildLookupPipeline = (refMap, options = {}) => {
316
311
  path: newPath,
317
312
  });
318
313
  const result = (0, exports.recurseSetStage)(reference, newPath, `$${refName}`);
319
- setProperties.push([
320
- refName,
321
- result,
322
- ]);
314
+ setProperties[refName] = result;
323
315
  }
324
316
  if (reference.referencedCollection) {
325
317
  const tempName = getTempName(newPath);
@@ -354,17 +346,14 @@ const buildLookupPipeline = (refMap, options = {}) => {
354
346
  });
355
347
  if (!reference.deepReferences) {
356
348
  const result = (0, exports.recurseSetStage)(reference, newPath, `$${refName}`);
357
- setProperties.push([
358
- refName,
359
- result,
360
- ]);
349
+ setProperties[refName] = result;
361
350
  }
362
351
  }
363
352
  }
364
353
  if (path.length === 0) {
365
- if (setProperties.length > 0) {
354
+ if (Object.keys(setProperties).length > 0) {
366
355
  pipeline.push({
367
- $set: Object.fromEntries(setProperties),
356
+ $set: setProperties,
368
357
  });
369
358
  }
370
359
  if (tempNames.length > 0) {
@@ -43,7 +43,7 @@ export const getReferences = async (properties, options = {}) => {
43
43
  reference.deepReferences = deepReferences;
44
44
  }
45
45
  }
46
- const indexes = refProperty.indexes ? refProperty.indexes : description.indexes || [];
46
+ const { indexes = description.indexes || [] } = refProperty;
47
47
  reference.populate = (refProperty.populate || []).concat(indexes.filter((index) => typeof index === "string"));
48
48
  } else {
49
49
  const entrypoint = "items" in property ? property.items : property;
@@ -186,7 +186,7 @@ export const recurseSetStage = (reference, path, parentElem, options = {
186
186
  };
187
187
  }
188
188
  if (reference.deepReferences) {
189
- const stages = [];
189
+ const stages = {};
190
190
  for (const [subRefName, subReference] of Object.entries(reference.deepReferences)) {
191
191
  let newElem;
192
192
  if (shouldUseArrayIndex) {
@@ -214,10 +214,7 @@ export const recurseSetStage = (reference, path, parentElem, options = {
214
214
  "referencedCollection" in subReference
215
215
  ]
216
216
  ]), newElem);
217
- stages.push([
218
- subRefName,
219
- result
220
- ]);
217
+ stages[subRefName] = result;
221
218
  }
222
219
  if (reference.referencedCollection) {
223
220
  return {
@@ -236,14 +233,14 @@ export const recurseSetStage = (reference, path, parentElem, options = {
236
233
  }, path, parentElem, {
237
234
  noCond: true
238
235
  }),
239
- Object.fromEntries(stages)
236
+ stages
240
237
  ]
241
238
  },
242
239
  null
243
240
  ]
244
241
  };
245
242
  }
246
- return Object.fromEntries(stages);
243
+ return stages;
247
244
  }
248
245
  const arrayElemAt = {
249
246
  $arrayElemAt: [
@@ -282,7 +279,7 @@ export const buildLookupPipeline = (refMap, options = {}) => {
282
279
  }
283
280
  }
284
281
  const pipeline = [];
285
- const setProperties = [];
282
+ const setProperties = {};
286
283
  for (const [refName, reference] of Object.entries(refMap)) {
287
284
  if (project) {
288
285
  if (!project.includes(refName)) {
@@ -302,10 +299,7 @@ export const buildLookupPipeline = (refMap, options = {}) => {
302
299
  path: newPath
303
300
  });
304
301
  const result = recurseSetStage(reference, newPath, `$${refName}`);
305
- setProperties.push([
306
- refName,
307
- result
308
- ]);
302
+ setProperties[refName] = result;
309
303
  }
310
304
  if (reference.referencedCollection) {
311
305
  const tempName = getTempName(newPath);
@@ -337,17 +331,14 @@ export const buildLookupPipeline = (refMap, options = {}) => {
337
331
  });
338
332
  if (!reference.deepReferences) {
339
333
  const result = recurseSetStage(reference, newPath, `$${refName}`);
340
- setProperties.push([
341
- refName,
342
- result
343
- ]);
334
+ setProperties[refName] = result;
344
335
  }
345
336
  }
346
337
  }
347
338
  if (path.length === 0) {
348
- if (setProperties.length > 0) {
339
+ if (Object.keys(setProperties).length > 0) {
349
340
  pipeline.push({
350
- $set: Object.fromEntries(setProperties)
341
+ $set: setProperties
351
342
  });
352
343
  }
353
344
  if (tempNames.length > 0) {
@@ -139,7 +139,7 @@ const autoCast = (value, ctx) => {
139
139
  return value.map((v) => autoCast(v, ctx));
140
140
  }
141
141
  if (Object.keys(value).length > 0) {
142
- const entries = [];
142
+ const entries = {};
143
143
  for (const [k, v] of Object.entries(value)) {
144
144
  const subProperty = !k.startsWith('$')
145
145
  ? getProperty(k, ctx.property)
@@ -147,15 +147,12 @@ const autoCast = (value, ctx) => {
147
147
  if (!subProperty) {
148
148
  continue;
149
149
  }
150
- entries.push([
151
- k,
152
- autoCast(v, {
153
- ...ctx,
154
- property: subProperty,
155
- }),
156
- ]);
150
+ entries[k] = autoCast(v, {
151
+ ...ctx,
152
+ property: subProperty,
153
+ });
157
154
  }
158
- return Object.fromEntries(entries);
155
+ return entries;
159
156
  }
160
157
  }
161
158
  }
@@ -266,7 +263,7 @@ const recurseDeep = async (value, ctx) => {
266
263
  return value;
267
264
  };
268
265
  const recurse = async (target, ctx) => {
269
- const entries = [];
266
+ const entries = {};
270
267
  const entrypoint = ctx.options.fromProperties && 'properties' in ctx.property
271
268
  ? {
272
269
  _id: null,
@@ -279,33 +276,24 @@ const recurse = async (target, ctx) => {
279
276
  if (propName === '_id') {
280
277
  if (value) {
281
278
  if (ctx.options.autoCast) {
282
- entries.push([
279
+ entries[propName] = autoCast(value, {
280
+ ...ctx,
281
+ target,
283
282
  propName,
284
- autoCast(value, {
285
- ...ctx,
286
- target,
287
- propName,
288
- property: {
289
- $ref: '',
290
- },
291
- }),
292
- ]);
283
+ property: {
284
+ $ref: '',
285
+ },
286
+ });
293
287
  }
294
288
  else {
295
- entries.push([
296
- propName,
297
- value,
298
- ]);
289
+ entries[propName] = value;
299
290
  }
300
291
  }
301
292
  continue;
302
293
  }
303
294
  if (ctx.options.undefinedToNull) {
304
295
  if (value === undefined) {
305
- entries.push([
306
- propName,
307
- null,
308
- ]);
296
+ entries[propName] = null;
309
297
  continue;
310
298
  }
311
299
  }
@@ -317,13 +305,10 @@ const recurse = async (target, ctx) => {
317
305
  }
318
306
  if (key === '$regex' && typeof value[key] === 'string') {
319
307
  if (!ctx.options.noRegExpEscaping) {
320
- entries.push([
321
- propName,
322
- {
323
- ...value,
324
- $regex: escapeRegExp(value[key]),
325
- },
326
- ]);
308
+ entries[propName] = {
309
+ ...value,
310
+ $regex: escapeRegExp(value[key]),
311
+ };
327
312
  continue entrypoint;
328
313
  }
329
314
  }
@@ -341,26 +326,17 @@ const recurse = async (target, ctx) => {
341
326
  }
342
327
  operations.push(result);
343
328
  }
344
- entries.push([
345
- propName,
346
- operations,
347
- ]);
329
+ entries[propName] = operations;
348
330
  continue;
349
331
  }
350
332
  const { error, result: operator } = await recurse(value, ctx);
351
333
  if (error) {
352
334
  return types_1.Result.error(error);
353
335
  }
354
- entries.push([
355
- propName,
356
- operator,
357
- ]);
336
+ entries[propName] = operator;
358
337
  continue;
359
338
  }
360
- entries.push([
361
- propName,
362
- value,
363
- ]);
339
+ entries[propName] = value;
364
340
  }
365
341
  else {
366
342
  if (!ctx.options.preserveHidden && property.hidden) {
@@ -397,38 +373,29 @@ const recurse = async (target, ctx) => {
397
373
  }
398
374
  documents.push(result);
399
375
  }
400
- entries.push([
401
- propName,
402
- documents,
403
- ]);
376
+ entries[propName] = documents;
404
377
  continue;
405
378
  }
406
- const { error, result: document } = await (0, exports.traverseDocument)(value, targetDescription, ctx.options);
379
+ const { error, result: doc } = await (0, exports.traverseDocument)(value, targetDescription, ctx.options);
407
380
  if (error) {
408
381
  return types_1.Result.error(error);
409
382
  }
410
- entries.push([
411
- propName,
412
- document,
413
- ]);
383
+ entries[propName] = doc;
414
384
  continue;
415
385
  }
416
386
  }
417
- entries.push([
387
+ entries[propName] = await ctx.options.pipe(value, {
388
+ ...ctx,
389
+ target,
418
390
  propName,
419
- await ctx.options.pipe(value, {
420
- ...ctx,
421
- target,
422
- propName,
423
- propPath: ctx.propPath
424
- ? `${ctx.propPath}.${propName}`
425
- : propName,
426
- property,
427
- }),
428
- ]);
391
+ propPath: ctx.propPath
392
+ ? `${ctx.propPath}.${propName}`
393
+ : propName,
394
+ property,
395
+ });
429
396
  }
430
397
  }
431
- return types_1.Result.result(Object.fromEntries(entries));
398
+ return types_1.Result.result(entries);
432
399
  };
433
400
  const traverseDocument = async (what, description, _options) => {
434
401
  if (!what) {
@@ -109,21 +109,18 @@ const autoCast = (value, ctx) => {
109
109
  return value.map((v) => autoCast(v, ctx));
110
110
  }
111
111
  if (Object.keys(value).length > 0) {
112
- const entries = [];
112
+ const entries = {};
113
113
  for (const [k, v] of Object.entries(value)) {
114
114
  const subProperty = !k.startsWith("$") ? getProperty(k, ctx.property) : ctx.property;
115
115
  if (!subProperty) {
116
116
  continue;
117
117
  }
118
- entries.push([
119
- k,
120
- autoCast(v, {
121
- ...ctx,
122
- property: subProperty
123
- })
124
- ]);
118
+ entries[k] = autoCast(v, {
119
+ ...ctx,
120
+ property: subProperty
121
+ });
125
122
  }
126
- return Object.fromEntries(entries);
123
+ return entries;
127
124
  }
128
125
  }
129
126
  }
@@ -233,7 +230,7 @@ const recurseDeep = async (value, ctx) => {
233
230
  return value;
234
231
  };
235
232
  const recurse = async (target, ctx) => {
236
- const entries = [];
233
+ const entries = {};
237
234
  const entrypoint = ctx.options.fromProperties && "properties" in ctx.property ? {
238
235
  _id: null,
239
236
  ...ctx.property.properties
@@ -244,32 +241,23 @@ const recurse = async (target, ctx) => {
244
241
  if (propName === "_id") {
245
242
  if (value) {
246
243
  if (ctx.options.autoCast) {
247
- entries.push([
244
+ entries[propName] = autoCast(value, {
245
+ ...ctx,
246
+ target,
248
247
  propName,
249
- autoCast(value, {
250
- ...ctx,
251
- target,
252
- propName,
253
- property: {
254
- $ref: ""
255
- }
256
- })
257
- ]);
248
+ property: {
249
+ $ref: ""
250
+ }
251
+ });
258
252
  } else {
259
- entries.push([
260
- propName,
261
- value
262
- ]);
253
+ entries[propName] = value;
263
254
  }
264
255
  }
265
256
  continue;
266
257
  }
267
258
  if (ctx.options.undefinedToNull) {
268
259
  if (value === void 0) {
269
- entries.push([
270
- propName,
271
- null
272
- ]);
260
+ entries[propName] = null;
273
261
  continue;
274
262
  }
275
263
  }
@@ -281,13 +269,10 @@ const recurse = async (target, ctx) => {
281
269
  }
282
270
  if (key === "$regex" && typeof value[key] === "string") {
283
271
  if (!ctx.options.noRegExpEscaping) {
284
- entries.push([
285
- propName,
286
- {
287
- ...value,
288
- $regex: escapeRegExp(value[key])
289
- }
290
- ]);
272
+ entries[propName] = {
273
+ ...value,
274
+ $regex: escapeRegExp(value[key])
275
+ };
291
276
  continue entrypoint;
292
277
  }
293
278
  }
@@ -305,26 +290,17 @@ const recurse = async (target, ctx) => {
305
290
  }
306
291
  operations.push(result);
307
292
  }
308
- entries.push([
309
- propName,
310
- operations
311
- ]);
293
+ entries[propName] = operations;
312
294
  continue;
313
295
  }
314
296
  const { error, result: operator } = await recurse(value, ctx);
315
297
  if (error) {
316
298
  return Result.error(error);
317
299
  }
318
- entries.push([
319
- propName,
320
- operator
321
- ]);
300
+ entries[propName] = operator;
322
301
  continue;
323
302
  }
324
- entries.push([
325
- propName,
326
- value
327
- ]);
303
+ entries[propName] = value;
328
304
  } else {
329
305
  if (!ctx.options.preserveHidden && property.hidden) {
330
306
  continue;
@@ -358,36 +334,27 @@ const recurse = async (target, ctx) => {
358
334
  }
359
335
  documents.push(result);
360
336
  }
361
- entries.push([
362
- propName,
363
- documents
364
- ]);
337
+ entries[propName] = documents;
365
338
  continue;
366
339
  }
367
- const { error, result: document } = await traverseDocument(value, targetDescription, ctx.options);
340
+ const { error, result: doc } = await traverseDocument(value, targetDescription, ctx.options);
368
341
  if (error) {
369
342
  return Result.error(error);
370
343
  }
371
- entries.push([
372
- propName,
373
- document
374
- ]);
344
+ entries[propName] = doc;
375
345
  continue;
376
346
  }
377
347
  }
378
- entries.push([
348
+ entries[propName] = await ctx.options.pipe(value, {
349
+ ...ctx,
350
+ target,
379
351
  propName,
380
- await ctx.options.pipe(value, {
381
- ...ctx,
382
- target,
383
- propName,
384
- propPath: ctx.propPath ? `${ctx.propPath}.${propName}` : propName,
385
- property
386
- })
387
- ]);
352
+ propPath: ctx.propPath ? `${ctx.propPath}.${propName}` : propName,
353
+ property
354
+ });
388
355
  }
389
356
  }
390
- return Result.result(Object.fromEntries(entries));
357
+ return Result.result(entries);
391
358
  };
392
359
  export const traverseDocument = async (what, description, _options) => {
393
360
  if (!what) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
3
- import { ACError, HTTPStatus, Result } from "@aeriajs/types";
3
+ import { Result, HTTPStatus, ACError } from "@aeriajs/types";
4
4
  import { throwIfError } from "@aeriajs/common";
5
5
  import {
6
6
  traverseDocument,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.204",
3
+ "version": "0.0.205",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "aeriaMain": "tests/fixtures/aeriaMain.js",
@@ -42,13 +42,13 @@
42
42
  "mongodb-memory-server": "^9.2.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@aeriajs/builtins": "^0.0.204",
45
+ "@aeriajs/builtins": "^0.0.205",
46
46
  "@aeriajs/common": "^0.0.125",
47
47
  "@aeriajs/entrypoint": "^0.0.128",
48
- "@aeriajs/http": "^0.0.144",
49
- "@aeriajs/security": "^0.0.204",
48
+ "@aeriajs/http": "^0.0.145",
49
+ "@aeriajs/security": "^0.0.205",
50
50
  "@aeriajs/types": "^0.0.107",
51
- "@aeriajs/validation": "^0.0.133"
51
+ "@aeriajs/validation": "^0.0.134"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",