@aeriajs/core 0.0.192 → 0.0.193

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.
@@ -238,156 +238,155 @@ const recurse = async (target, ctx) => {
238
238
  _id: null,
239
239
  ...ctx.property.properties
240
240
  } : target;
241
- entrypoint:
242
- for (const propName in entrypoint) {
243
- const value = target[propName];
244
- const property = getProperty(propName, ctx.property);
245
- if (propName === "_id") {
246
- if (value) {
247
- if (ctx.options.autoCast) {
248
- entries.push([
241
+ entrypoint: for (const propName in entrypoint) {
242
+ const value = target[propName];
243
+ const property = getProperty(propName, ctx.property);
244
+ if (propName === "_id") {
245
+ if (value) {
246
+ if (ctx.options.autoCast) {
247
+ entries.push([
248
+ propName,
249
+ autoCast(value, {
250
+ ...ctx,
251
+ target,
249
252
  propName,
250
- autoCast(value, {
251
- ...ctx,
252
- target,
253
+ property: {
254
+ $ref: ""
255
+ }
256
+ })
257
+ ]);
258
+ } else {
259
+ entries.push([
260
+ propName,
261
+ value
262
+ ]);
263
+ }
264
+ }
265
+ continue;
266
+ }
267
+ if (ctx.options.undefinedToNull) {
268
+ if (value === void 0) {
269
+ entries.push([
270
+ propName,
271
+ null
272
+ ]);
273
+ continue;
274
+ }
275
+ }
276
+ if (value && typeof value === "object") {
277
+ for (const key in value) {
278
+ if (key.startsWith("$")) {
279
+ if (!ctx.options.allowOperators) {
280
+ return Result.error(ACError.InsecureOperator);
281
+ }
282
+ if (key === "$regex" && typeof value[key] === "string") {
283
+ if (!ctx.options.noRegExpEscaping) {
284
+ entries.push([
253
285
  propName,
254
- property: {
255
- $ref: ""
286
+ {
287
+ ...value,
288
+ $regex: escapeRegExp(value[key])
256
289
  }
257
- })
258
- ]);
259
- } else {
260
- entries.push([
261
- propName,
262
- value
263
- ]);
290
+ ]);
291
+ continue entrypoint;
292
+ }
264
293
  }
265
294
  }
266
- continue;
267
295
  }
268
- if (ctx.options.undefinedToNull) {
269
- if (value === void 0) {
296
+ }
297
+ if (!property) {
298
+ if (value && (value.constructor === Object || value.constructor === Array)) {
299
+ if (Array.isArray(value)) {
300
+ const operations = [];
301
+ for (const operation of value) {
302
+ const { error: error2, result } = await recurse(operation, ctx);
303
+ if (error2) {
304
+ return Result.error(error2);
305
+ }
306
+ operations.push(result);
307
+ }
270
308
  entries.push([
271
309
  propName,
272
- null
310
+ operations
273
311
  ]);
274
312
  continue;
275
313
  }
314
+ const { error, result: operator } = await recurse(value, ctx);
315
+ if (error) {
316
+ return Result.error(error);
317
+ }
318
+ entries.push([
319
+ propName,
320
+ operator
321
+ ]);
322
+ continue;
276
323
  }
277
- if (value && typeof value === "object") {
278
- for (const key in value) {
279
- if (key.startsWith("$")) {
280
- if (!ctx.options.allowOperators) {
281
- return Result.error(ACError.InsecureOperator);
282
- }
283
- if (key === "$regex" && typeof value[key] === "string") {
284
- if (!ctx.options.noRegExpEscaping) {
285
- entries.push([
286
- propName,
287
- {
288
- ...value,
289
- $regex: escapeRegExp(value[key])
290
- }
291
- ]);
292
- continue entrypoint;
293
- }
294
- }
324
+ entries.push([
325
+ propName,
326
+ value
327
+ ]);
328
+ } else {
329
+ if (!ctx.options.preserveHidden && property.hidden) {
330
+ continue;
331
+ }
332
+ if ("getters" in ctx.options && ctx.options.getters && "getter" in property) {
333
+ if (property.requires) {
334
+ const missing = property.requires.some((requiredPropName) => !(requiredPropName in target));
335
+ if (missing) {
336
+ continue;
295
337
  }
296
338
  }
297
339
  }
298
- if (!property) {
299
- if (value && (value.constructor === Object || value.constructor === Array)) {
340
+ if (ctx.options.recurseReferences) {
341
+ const propCast = "items" in property ? property.items : property;
342
+ if ("$ref" in propCast && value && !(value instanceof ObjectId)) {
343
+ const targetDescription = await preloadDescription(throwIfError(await getCollectionAsset(propCast.$ref, "description")));
300
344
  if (Array.isArray(value)) {
301
- const operations = [];
302
- for (const operation of value) {
303
- const { error: error2, result } = await recurse(operation, ctx);
345
+ const documents = [];
346
+ for (const elem of value) {
347
+ if (elem instanceof ObjectId) {
348
+ documents.push(elem);
349
+ continue;
350
+ }
351
+ if (typeof elem === "string") {
352
+ documents.push(new ObjectId(elem));
353
+ continue;
354
+ }
355
+ const { error: error2, result } = await traverseDocument(elem, targetDescription, ctx.options);
304
356
  if (error2) {
305
357
  return Result.error(error2);
306
358
  }
307
- operations.push(result);
359
+ documents.push(result);
308
360
  }
309
361
  entries.push([
310
362
  propName,
311
- operations
363
+ documents
312
364
  ]);
313
365
  continue;
314
366
  }
315
- const { error, result: operator } = await recurse(value, ctx);
367
+ const { error, result: document } = await traverseDocument(value, targetDescription, ctx.options);
316
368
  if (error) {
317
369
  return Result.error(error);
318
370
  }
319
371
  entries.push([
320
372
  propName,
321
- operator
373
+ document
322
374
  ]);
323
375
  continue;
324
376
  }
325
- entries.push([
326
- propName,
327
- value
328
- ]);
329
- } else {
330
- if (!ctx.options.preserveHidden && property.hidden) {
331
- continue;
332
- }
333
- if ("getters" in ctx.options && ctx.options.getters && "getter" in property) {
334
- if (property.requires) {
335
- const missing = property.requires.some((requiredPropName) => !(requiredPropName in target));
336
- if (missing) {
337
- continue;
338
- }
339
- }
340
- }
341
- if (ctx.options.recurseReferences) {
342
- const propCast = "items" in property ? property.items : property;
343
- if ("$ref" in propCast && value && !(value instanceof ObjectId)) {
344
- const targetDescription = await preloadDescription(throwIfError(await getCollectionAsset(propCast.$ref, "description")));
345
- if (Array.isArray(value)) {
346
- const documents = [];
347
- for (const elem of value) {
348
- if (elem instanceof ObjectId) {
349
- documents.push(elem);
350
- continue;
351
- }
352
- if (typeof elem === "string") {
353
- documents.push(new ObjectId(elem));
354
- continue;
355
- }
356
- const { error: error2, result } = await traverseDocument(elem, targetDescription, ctx.options);
357
- if (error2) {
358
- return Result.error(error2);
359
- }
360
- documents.push(result);
361
- }
362
- entries.push([
363
- propName,
364
- documents
365
- ]);
366
- continue;
367
- }
368
- const { error, result: document } = await traverseDocument(value, targetDescription, ctx.options);
369
- if (error) {
370
- return Result.error(error);
371
- }
372
- entries.push([
373
- propName,
374
- document
375
- ]);
376
- continue;
377
- }
378
- }
379
- entries.push([
380
- propName,
381
- await ctx.options.pipe(value, {
382
- ...ctx,
383
- target,
384
- propName,
385
- propPath: ctx.propPath ? `${ctx.propPath}.${propName}` : propName,
386
- property
387
- })
388
- ]);
389
377
  }
378
+ entries.push([
379
+ 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
+ ]);
390
388
  }
389
+ }
391
390
  return Result.result(Object.fromEntries(entries));
392
391
  };
393
392
  export const traverseDocument = async (what, description, _options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.192",
3
+ "version": "0.0.193",
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.192",
46
- "@aeriajs/common": "^0.0.118",
47
- "@aeriajs/entrypoint": "^0.0.121",
48
- "@aeriajs/http": "^0.0.132",
49
- "@aeriajs/security": "^0.0.192",
50
- "@aeriajs/types": "^0.0.101",
51
- "@aeriajs/validation": "^0.0.121"
45
+ "@aeriajs/builtins": "^0.0.193",
46
+ "@aeriajs/common": "^0.0.119",
47
+ "@aeriajs/entrypoint": "^0.0.122",
48
+ "@aeriajs/http": "^0.0.133",
49
+ "@aeriajs/security": "^0.0.193",
50
+ "@aeriajs/types": "^0.0.102",
51
+ "@aeriajs/validation": "^0.0.122"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",