@dnax/core 0.4.1 → 0.4.3
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/driver/mongo/rest.ts +2 -11
- package/lib/collection.ts +18 -1
- package/lib/schema.ts +1 -1
- package/package.json +1 -1
package/driver/mongo/rest.ts
CHANGED
|
@@ -118,7 +118,7 @@ class useRest {
|
|
|
118
118
|
output = value;
|
|
119
119
|
data = {
|
|
120
120
|
...data,
|
|
121
|
-
...output,
|
|
121
|
+
...(value || output),
|
|
122
122
|
};
|
|
123
123
|
//console.log(value);
|
|
124
124
|
}
|
|
@@ -239,10 +239,6 @@ class useRest {
|
|
|
239
239
|
|
|
240
240
|
var { valid, output, error } = this.validator(collection, data);
|
|
241
241
|
if (!valid) fn.error(error, 400);
|
|
242
|
-
data = {
|
|
243
|
-
...output,
|
|
244
|
-
...data,
|
|
245
|
-
};
|
|
246
242
|
|
|
247
243
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
248
244
|
await col.hooks.beforeOperation({
|
|
@@ -343,12 +339,7 @@ class useRest {
|
|
|
343
339
|
d = await hashPasswordAuto(d, col);
|
|
344
340
|
d = deepSetId(col, d);
|
|
345
341
|
var { valid, output, error } = this.validator(collection, d);
|
|
346
|
-
|
|
347
342
|
if (!valid) fn.error(error, 400);
|
|
348
|
-
d = {
|
|
349
|
-
...output,
|
|
350
|
-
...d,
|
|
351
|
-
};
|
|
352
343
|
}
|
|
353
344
|
|
|
354
345
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
@@ -515,7 +506,7 @@ class useRest {
|
|
|
515
506
|
|
|
516
507
|
let resultDocs = toJson(result.docs);
|
|
517
508
|
if (typeof options?.elementAt == "number") {
|
|
518
|
-
resultDocs = resultDocs[options?.elementAt]
|
|
509
|
+
resultDocs = resultDocs[options?.elementAt] ?? null;
|
|
519
510
|
}
|
|
520
511
|
return resolve(resultDocs);
|
|
521
512
|
} catch (err) {
|
package/lib/collection.ts
CHANGED
|
@@ -93,18 +93,22 @@ async function syncCollectionDatabase() {
|
|
|
93
93
|
|
|
94
94
|
var allIndexes = await t.database.db?.collection(c.slug).indexes();
|
|
95
95
|
|
|
96
|
+
// console.log('Allindex',allIndexes)
|
|
97
|
+
|
|
96
98
|
for await (let dbIndex of allIndexes || []) {
|
|
97
99
|
if (
|
|
98
100
|
dbIndex?.key?.createdAt ||
|
|
99
101
|
dbIndex?.key?.updatedAt ||
|
|
100
102
|
dbIndex?.key?._id
|
|
101
103
|
) {
|
|
102
|
-
|
|
104
|
+
continue;
|
|
103
105
|
}
|
|
104
106
|
|
|
107
|
+
// creation des indexes si n'existe in remote
|
|
105
108
|
let findexIndexKey = c.fields?.map(
|
|
106
109
|
(field) => dbIndex.key[field.name]
|
|
107
110
|
);
|
|
111
|
+
|
|
108
112
|
if (!findexIndexKey)
|
|
109
113
|
await t.database.db
|
|
110
114
|
?.collection(c?.slug)
|
|
@@ -118,6 +122,19 @@ async function syncCollectionDatabase() {
|
|
|
118
122
|
.createIndex(["createdAt", "updatedAt"])
|
|
119
123
|
.then((e) => {});
|
|
120
124
|
|
|
125
|
+
// 3- suppression des indexes
|
|
126
|
+
c.fields?.map((f) => {
|
|
127
|
+
if (!f?.unique && allIndexes?.find((e) => e?.key[f.name])) {
|
|
128
|
+
//@ts-expect-error
|
|
129
|
+
t.database.db
|
|
130
|
+
?.collection(c.slug)
|
|
131
|
+
.dropIndex({
|
|
132
|
+
[f.name]: 1,
|
|
133
|
+
})
|
|
134
|
+
.catch();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
121
138
|
// 2- Creation des indexes par champs unique/random
|
|
122
139
|
|
|
123
140
|
c.fields?.map((f) => {
|
package/lib/schema.ts
CHANGED
|
@@ -118,7 +118,7 @@ function buildSchema(col: Collection) {
|
|
|
118
118
|
if (f?.validate?.schema) {
|
|
119
119
|
propertySchema[f.name] = f.validate.schema;
|
|
120
120
|
}
|
|
121
|
-
if (f?.defaultValue) {
|
|
121
|
+
if (f?.defaultValue !== undefined && f?.defaultValue !== null) {
|
|
122
122
|
propertySchema[f.name] = propertySchema[f.name]?.default(f.defaultValue);
|
|
123
123
|
}
|
|
124
124
|
|