@unchainedshop/utils 1.2.42 → 1.2.43
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.
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
2
2
|
const buildIndexes = (collection, indexes) => Promise.all(indexes.map(async ({ index, options }) => {
|
|
3
|
-
|
|
3
|
+
try {
|
|
4
|
+
await collection.createIndex(index, options);
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
return e;
|
|
9
|
+
}
|
|
4
10
|
}));
|
|
5
11
|
export const buildDbIndexes = async (collection, indexes) => {
|
|
6
12
|
let success = true;
|
|
@@ -10,7 +16,7 @@ export const buildDbIndexes = async (collection, indexes) => {
|
|
|
10
16
|
if (!dropError) {
|
|
11
17
|
const rebuildErrors = (await buildIndexes(collection, indexes)).filter(Boolean);
|
|
12
18
|
if (rebuildErrors.length) {
|
|
13
|
-
log(
|
|
19
|
+
log(`Error building some indexes for ${collection.collectionName}`, {
|
|
14
20
|
level: LogLevel.Error,
|
|
15
21
|
...rebuildErrors,
|
|
16
22
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-db-indexes.js","sourceRoot":"","sources":["../../src/db/build-db-indexes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"build-db-indexes.js","sourceRoot":"","sources":["../../src/db/build-db-indexes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,YAAY,GAAG,CACnB,UAAyB,EACzB,OAAmB,EACY,EAAE,CACjC,OAAO,CAAC,GAAG,CACT,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;IACvC,IAAI;QACF,MAAM,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC7C,OAAO,KAAK,CAAC;KACd;IAAC,OAAO,CAAM,EAAE;QACf,OAAO,CAAU,CAAC;KACnB;AACH,CAAC,CAAC,CACH,CAAC;AAEJ,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,UAAyB,EACzB,OAAmB,EACnB,EAAE;IACF,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,MAAM,WAAW,GAAG,CAAC,MAAM,YAAY,CAAI,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEjF,IAAI,WAAW,CAAC,MAAM,EAAE;QACtB,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAEjE,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,aAAa,GAAG,CAAC,MAAM,YAAY,CAAI,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAEnF,IAAI,aAAa,CAAC,MAAM,EAAE;gBACxB,GAAG,CAAC,mCAAmC,UAAU,CAAC,cAAc,EAAE,EAAE;oBAClE,KAAK,EAAE,QAAQ,CAAC,KAAK;oBACrB,GAAG,aAAa;iBACjB,CAAC,CAAC;gBACH,OAAO,GAAG,KAAK,CAAC;aACjB;SACF;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.43",
|
|
4
4
|
"main": "lib/utils-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/utils-index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@unchainedshop/logger": "^1.2.
|
|
32
|
+
"@unchainedshop/logger": "^1.2.43",
|
|
33
33
|
"abort-controller": "3.0.0",
|
|
34
34
|
"bson": "^4.7.0",
|
|
35
35
|
"hashids": "^2.2.10",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"simpl-schema": "^3.0.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^16.18.
|
|
43
|
-
"@unchainedshop/types": "^1.2.
|
|
42
|
+
"@types/node": "^16.18.3",
|
|
43
|
+
"@unchainedshop/types": "^1.2.43",
|
|
44
44
|
"typescript": "^4.8.4"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { Collection, Indexes, Document } from '@unchainedshop/types/common';
|
|
2
2
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
3
3
|
|
|
4
|
-
const buildIndexes = <T>(
|
|
4
|
+
const buildIndexes = <T>(
|
|
5
|
+
collection: Collection<T>,
|
|
6
|
+
indexes: Indexes<T>,
|
|
7
|
+
): Promise<Array<false | Error>> =>
|
|
5
8
|
Promise.all(
|
|
6
9
|
indexes.map(async ({ index, options }) => {
|
|
7
|
-
|
|
10
|
+
try {
|
|
11
|
+
await collection.createIndex(index, options);
|
|
12
|
+
return false;
|
|
13
|
+
} catch (e: any) {
|
|
14
|
+
return e as Error;
|
|
15
|
+
}
|
|
8
16
|
}),
|
|
9
17
|
);
|
|
10
18
|
|
|
@@ -22,7 +30,7 @@ export const buildDbIndexes = async <T extends Document>(
|
|
|
22
30
|
const rebuildErrors = (await buildIndexes<T>(collection, indexes)).filter(Boolean);
|
|
23
31
|
|
|
24
32
|
if (rebuildErrors.length) {
|
|
25
|
-
log(
|
|
33
|
+
log(`Error building some indexes for ${collection.collectionName}`, {
|
|
26
34
|
level: LogLevel.Error,
|
|
27
35
|
...rebuildErrors,
|
|
28
36
|
});
|