@dnax/core 0.8.10 → 0.8.12

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;
@@ -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,16 @@ 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
+
237
+
238
+
229
239
  export {
230
240
  loadAllCollections,
231
241
  getCollection,
package/lib/schema.ts CHANGED
@@ -4,6 +4,11 @@ import v, { type AnySchema } from "joi";
4
4
  function buildSchema(col: Collection) {
5
5
  let propertySchema = {} as { [key: string]: AnySchema };
6
6
 
7
+ if (col?.timestamps) {
8
+ propertySchema["createdAt"] = v.date();
9
+ propertySchema["updatedAt"] = v.date();
10
+ }
11
+
7
12
  if (col?.media) {
8
13
  propertySchema["_file"] = v.object();
9
14
  }
@@ -134,7 +139,7 @@ function buildSchema(col: Collection) {
134
139
  }
135
140
  });
136
141
 
137
- let buildSchema = v.object(propertySchema).unknown();
142
+ let buildSchema = v.object(propertySchema);
138
143
 
139
144
  return buildSchema;
140
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {