@dnax/core 0.4.2 → 0.4.4
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 +11 -1
- package/lib/collection.ts +18 -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,6 +239,12 @@ 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
|
+
...data,
|
|
244
|
+
...(output || {}),
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
//console.log(data);
|
|
242
248
|
|
|
243
249
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
244
250
|
await col.hooks.beforeOperation({
|
|
@@ -340,6 +346,10 @@ class useRest {
|
|
|
340
346
|
d = deepSetId(col, d);
|
|
341
347
|
var { valid, output, error } = this.validator(collection, d);
|
|
342
348
|
if (!valid) fn.error(error, 400);
|
|
349
|
+
d = {
|
|
350
|
+
...d,
|
|
351
|
+
...(output || {}),
|
|
352
|
+
};
|
|
343
353
|
}
|
|
344
354
|
|
|
345
355
|
if (col?.hooks?.beforeOperation && useHook) {
|
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) => {
|