@dnax/core 0.14.6 → 0.14.9
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/lib/collection.ts +19 -35
- package/package.json +1 -1
- package/types/index.ts +3 -0
package/lib/collection.ts
CHANGED
|
@@ -91,6 +91,17 @@ 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
|
|
99
|
+
?.collection(c.slug)
|
|
100
|
+
.dropIndex(index)
|
|
101
|
+
.catch((err) => {});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
94
105
|
var allIndexes = await t.database.db
|
|
95
106
|
?.collection(c.slug)
|
|
96
107
|
.indexes()
|
|
@@ -108,19 +119,6 @@ async function syncCollectionDatabase() {
|
|
|
108
119
|
) {
|
|
109
120
|
continue;
|
|
110
121
|
}
|
|
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
122
|
}
|
|
125
123
|
|
|
126
124
|
//console.log(t.database.db);
|
|
@@ -133,25 +131,14 @@ async function syncCollectionDatabase() {
|
|
|
133
131
|
console.error(err?.message);
|
|
134
132
|
});
|
|
135
133
|
|
|
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
134
|
// 2- Creation des indexes par champs unique/random
|
|
153
135
|
|
|
154
136
|
c.fields?.map((f) => {
|
|
137
|
+
if (f?.index) {
|
|
138
|
+
t.database.db?.collection(c.slug).createIndex({
|
|
139
|
+
[f.name]: f.index == true ? 1 : f.index,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
155
142
|
if (f?.unique || f?.random) {
|
|
156
143
|
t.database.db
|
|
157
144
|
?.collection(c.slug)
|
|
@@ -165,13 +152,12 @@ async function syncCollectionDatabase() {
|
|
|
165
152
|
}
|
|
166
153
|
)
|
|
167
154
|
.catch((err) => {
|
|
168
|
-
console.
|
|
155
|
+
console.error(err);
|
|
169
156
|
});
|
|
170
157
|
}
|
|
171
158
|
});
|
|
172
159
|
|
|
173
|
-
// 3- Creation des indexes par indexes
|
|
174
|
-
|
|
160
|
+
// 3- Creation des indexes par indexes array
|
|
175
161
|
for await (let index of c?.indexes || []) {
|
|
176
162
|
let indexHasAlready = allIndexes?.find((el) => {
|
|
177
163
|
return deepEqual(
|
|
@@ -185,7 +171,7 @@ async function syncCollectionDatabase() {
|
|
|
185
171
|
?.collection(c.slug)
|
|
186
172
|
.dropIndex(indexHasAlready?.name)
|
|
187
173
|
.catch((err) => {
|
|
188
|
-
console.
|
|
174
|
+
console.error(err?.message);
|
|
189
175
|
});
|
|
190
176
|
}
|
|
191
177
|
|
|
@@ -234,8 +220,6 @@ function getKeyFields(col: Collection) {
|
|
|
234
220
|
return keyFields;
|
|
235
221
|
}
|
|
236
222
|
|
|
237
|
-
|
|
238
|
-
|
|
239
223
|
export {
|
|
240
224
|
loadAllCollections,
|
|
241
225
|
getCollection,
|
package/package.json
CHANGED