@dnax/core 0.14.4 → 0.14.8
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 +4 -1
- package/lib/collection.ts +16 -35
- package/package.json +1 -1
- package/types/index.ts +3 -0
package/driver/mongo/rest.ts
CHANGED
|
@@ -917,7 +917,10 @@ class useRest {
|
|
|
917
917
|
...(formatData(filter) || {}),
|
|
918
918
|
},
|
|
919
919
|
{
|
|
920
|
-
...formatData(omit(update, omitUpdate)
|
|
920
|
+
...formatData(omit(update, omitUpdate), {
|
|
921
|
+
collection: collection,
|
|
922
|
+
tenant_id: this.#tenant_id,
|
|
923
|
+
}),
|
|
921
924
|
$currentDate: {
|
|
922
925
|
updatedAt: true,
|
|
923
926
|
},
|
package/lib/collection.ts
CHANGED
|
@@ -91,6 +91,14 @@ async function syncCollectionDatabase() {
|
|
|
91
91
|
await t.database.db?.createCollection(c.slug);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
// suppression auto Removes des indexes
|
|
95
|
+
|
|
96
|
+
if (c?.autoRemoveIndexes?.length && c?.autoRemoveIndexes) {
|
|
97
|
+
for await (let index of c?.autoRemoveIndexes || []) {
|
|
98
|
+
await t.database?.db?.collection(c.slug).dropIndex(index);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
94
102
|
var allIndexes = await t.database.db
|
|
95
103
|
?.collection(c.slug)
|
|
96
104
|
.indexes()
|
|
@@ -108,19 +116,6 @@ async function syncCollectionDatabase() {
|
|
|
108
116
|
) {
|
|
109
117
|
continue;
|
|
110
118
|
}
|
|
111
|
-
|
|
112
|
-
// creation des indexes si n'existe in remote
|
|
113
|
-
let findexIndexKey = c.fields?.map(
|
|
114
|
-
(field) => dbIndex.key[field.name]
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
if (!findexIndexKey)
|
|
118
|
-
await t.database.db
|
|
119
|
-
?.collection(c?.slug)
|
|
120
|
-
.dropIndex(dbIndex?.name as string)
|
|
121
|
-
.catch((err) => {
|
|
122
|
-
console.error(err?.message);
|
|
123
|
-
});
|
|
124
119
|
}
|
|
125
120
|
|
|
126
121
|
//console.log(t.database.db);
|
|
@@ -133,25 +128,14 @@ async function syncCollectionDatabase() {
|
|
|
133
128
|
console.error(err?.message);
|
|
134
129
|
});
|
|
135
130
|
|
|
136
|
-
// 3- suppression des indexes
|
|
137
|
-
//
|
|
138
|
-
c.fields?.map((f) => {
|
|
139
|
-
if (!f?.unique && allIndexes?.find((e) => e?.key[f.name])) {
|
|
140
|
-
//@ts-expect-error
|
|
141
|
-
t.database.db
|
|
142
|
-
?.collection(c.slug)
|
|
143
|
-
.dropIndex({
|
|
144
|
-
[f.name]: 1,
|
|
145
|
-
})
|
|
146
|
-
.catch((err) => {
|
|
147
|
-
console.error(err?.message);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
131
|
// 2- Creation des indexes par champs unique/random
|
|
153
132
|
|
|
154
133
|
c.fields?.map((f) => {
|
|
134
|
+
if (f?.index) {
|
|
135
|
+
t.database.db?.collection(c.slug).createIndex({
|
|
136
|
+
[f.name]: f.index == true ? 1 : f.index,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
155
139
|
if (f?.unique || f?.random) {
|
|
156
140
|
t.database.db
|
|
157
141
|
?.collection(c.slug)
|
|
@@ -165,13 +149,12 @@ async function syncCollectionDatabase() {
|
|
|
165
149
|
}
|
|
166
150
|
)
|
|
167
151
|
.catch((err) => {
|
|
168
|
-
console.
|
|
152
|
+
console.error(err);
|
|
169
153
|
});
|
|
170
154
|
}
|
|
171
155
|
});
|
|
172
156
|
|
|
173
|
-
// 3- Creation des indexes par indexes
|
|
174
|
-
|
|
157
|
+
// 3- Creation des indexes par indexes array
|
|
175
158
|
for await (let index of c?.indexes || []) {
|
|
176
159
|
let indexHasAlready = allIndexes?.find((el) => {
|
|
177
160
|
return deepEqual(
|
|
@@ -185,7 +168,7 @@ async function syncCollectionDatabase() {
|
|
|
185
168
|
?.collection(c.slug)
|
|
186
169
|
.dropIndex(indexHasAlready?.name)
|
|
187
170
|
.catch((err) => {
|
|
188
|
-
console.
|
|
171
|
+
console.error(err?.message);
|
|
189
172
|
});
|
|
190
173
|
}
|
|
191
174
|
|
|
@@ -234,8 +217,6 @@ function getKeyFields(col: Collection) {
|
|
|
234
217
|
return keyFields;
|
|
235
218
|
}
|
|
236
219
|
|
|
237
|
-
|
|
238
|
-
|
|
239
220
|
export {
|
|
240
221
|
loadAllCollections,
|
|
241
222
|
getCollection,
|
package/package.json
CHANGED