@dnax/core 0.8.9 → 0.8.11

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.
@@ -108,6 +108,7 @@ class useRest {
108
108
 
109
109
  if (col?.schema) {
110
110
  let schema = col.schema as Schema;
111
+ schema = schema;
111
112
 
112
113
  if (options.partial) {
113
114
  let partialSchema = schema.fork(
@@ -116,9 +117,13 @@ class useRest {
116
117
  return sc.optional();
117
118
  }
118
119
  );
119
- control = partialSchema.validate(data) as any;
120
+ control = partialSchema.validate(data, {
121
+ allowUnknown: false,
122
+ }) as any;
120
123
  } else {
121
- control = schema.validate(data) as any;
124
+ control = schema.validate(data, {
125
+ allowUnknown: false,
126
+ }) as any;
122
127
  }
123
128
 
124
129
  const { error, value } = control;
@@ -441,19 +446,22 @@ class useRest {
441
446
  let result = {} as any;
442
447
  for await (let query of queries) {
443
448
  let resultName = query.as || query.collection;
444
- if (query.action == "findOne") {
449
+ if (
450
+ query.action == "findOne" &&
451
+ (query?.filter?.id || query?.filter?._id)
452
+ ) {
445
453
  result[resultName] = await this.findOne(
446
454
  query.collection,
447
- query.filter.id,
448
- query.filter.params,
455
+ query?.filter?.id || query?.filter?._id,
456
+ query?.filter?.params || {},
449
457
  query.options
450
458
  );
451
459
  }
452
460
  if (query.action == "find") {
453
461
  result[resultName] = await this.find(
454
462
  query.collection,
455
- query.filter.params,
456
- query.options
463
+ query?.filter?.params || {},
464
+ query?.options || {}
457
465
  );
458
466
  }
459
467
  }
@@ -375,7 +375,24 @@ function formatData(
375
375
  return data;
376
376
  }
377
377
 
378
+ function removeKeysAtFirstLevel(data: any, keysToRemove: string[]) {
379
+ if (Array.isArray(data)) {
380
+ return data.map((item) => removeKeys(item, keysToRemove));
381
+ } else {
382
+ return removeKeys(data, keysToRemove);
383
+ }
384
+ }
385
+
386
+ function removeKeys(obj: object, keysToRemove: string[]) {
387
+ const newObj = { ...obj };
388
+ keysToRemove.forEach((key) => {
389
+ delete newObj[key];
390
+ });
391
+ return newObj;
392
+ }
393
+
378
394
  export {
395
+ removeKeysAtFirstLevel,
379
396
  buildPipeline,
380
397
  deepSetId,
381
398
  toBson,
package/lib/collection.ts CHANGED
@@ -226,6 +226,14 @@ async function syncCollectionDatabase() {
226
226
  }
227
227
  }
228
228
 
229
+ function getKeyFields(col: Collection) {
230
+ let keyFields: string[] = [];
231
+ col?.fields?.map((f) => {
232
+ keyFields.push(f.name);
233
+ });
234
+ return keyFields;
235
+ }
236
+
229
237
  export {
230
238
  loadAllCollections,
231
239
  getCollection,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.8.9",
3
+ "version": "0.8.11",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {