@unchainedshop/core-files 2.0.0-beta7 → 2.0.0-beta8
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.
|
@@ -28,7 +28,7 @@ export const configureFilesModule = async ({ db, options: filesOptions = {}, })
|
|
|
28
28
|
const finalURL = new URL(transformedURLString, process.env.ROOT_URL);
|
|
29
29
|
return finalURL.href;
|
|
30
30
|
}
|
|
31
|
-
catch (
|
|
31
|
+
catch (e2) {
|
|
32
32
|
// else return the transformed string because it's not an URL
|
|
33
33
|
return transformedURLString;
|
|
34
34
|
}
|
|
@@ -37,38 +37,26 @@ export const configureFilesModule = async ({ db, options: filesOptions = {}, })
|
|
|
37
37
|
findFile: async ({ fileId }, options) => {
|
|
38
38
|
return Files.findOne(generateDbFilterById(fileId), options);
|
|
39
39
|
},
|
|
40
|
-
findFiles: async (selector) => {
|
|
41
|
-
return Files.find(selector).toArray();
|
|
40
|
+
findFiles: async (selector, options) => {
|
|
41
|
+
return Files.find(selector, options).toArray();
|
|
42
42
|
},
|
|
43
43
|
deleteMany: async (fileIds) => {
|
|
44
|
-
await Files.deleteMany({ _id: { $in: fileIds } });
|
|
45
|
-
|
|
46
|
-
findFilesByMetaData: async ({ meta }, options) => {
|
|
47
|
-
const metaKeys = Object.keys(meta);
|
|
48
|
-
if (metaKeys.length === 0)
|
|
49
|
-
return [];
|
|
50
|
-
const selector = metaKeys.reduce((currentSelector, key) => meta[key] !== undefined
|
|
51
|
-
? {
|
|
52
|
-
...currentSelector,
|
|
53
|
-
[`meta.${key}`]: meta[key],
|
|
54
|
-
}
|
|
55
|
-
: currentSelector, {});
|
|
56
|
-
const files = Files.find(selector, options);
|
|
57
|
-
return files.toArray();
|
|
44
|
+
const deletionResult = await Files.deleteMany({ _id: { $in: fileIds } });
|
|
45
|
+
return deletionResult.deletedCount;
|
|
58
46
|
},
|
|
59
47
|
create: async (doc, userId) => {
|
|
60
48
|
const fileId = await mutations.create(doc, userId);
|
|
61
|
-
emit('FILE_CREATE', { fileId });
|
|
49
|
+
await emit('FILE_CREATE', { fileId });
|
|
62
50
|
return fileId;
|
|
63
51
|
},
|
|
64
52
|
update: async (_id, doc, userId) => {
|
|
65
53
|
const fileId = await mutations.update(_id, { $set: doc }, userId);
|
|
66
|
-
emit('FILE_UPDATE', { fileId });
|
|
54
|
+
await emit('FILE_UPDATE', { fileId });
|
|
67
55
|
return fileId;
|
|
68
56
|
},
|
|
69
57
|
delete: async (fileId, userId) => {
|
|
70
58
|
const deletedCount = await mutations.delete(fileId, userId);
|
|
71
|
-
emit('FILE_REMOVE', { fileId });
|
|
59
|
+
await emit('FILE_REMOVE', { fileId });
|
|
72
60
|
return deletedCount;
|
|
73
61
|
},
|
|
74
62
|
deletePermanently: mutations.deletePermanently,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureFilesModule.js","sourceRoot":"","sources":["../../src/module/configureFilesModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configureFilesModule.js","sourceRoot":"","sources":["../../src/module/configureFilesModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,WAAW,GAAa,CAAC,aAAa,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;AAE5E,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,EACzC,EAAE,EACF,OAAO,EAAE,YAAY,GAAG,EAAE,GACQ,EAAwB,EAAE;IAC5D,cAAc,CAAC,WAAW,CAAC,CAAC;IAE5B,WAAW;IACX,MAAM,aAA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{
|
|
6
6
|
".": "./lib/files-index.js",
|
|
@@ -30,20 +30,20 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unchainedshop/events": "^2.0.0-
|
|
34
|
-
"@unchainedshop/file-upload": "^2.0.0-
|
|
35
|
-
"@unchainedshop/logger": "^2.0.0-
|
|
36
|
-
"@unchainedshop/utils": "^2.0.0-
|
|
33
|
+
"@unchainedshop/events": "^2.0.0-beta8",
|
|
34
|
+
"@unchainedshop/file-upload": "^2.0.0-beta8",
|
|
35
|
+
"@unchainedshop/logger": "^2.0.0-beta8",
|
|
36
|
+
"@unchainedshop/utils": "^2.0.0-beta8",
|
|
37
37
|
"mime-types": "^2.1.35",
|
|
38
38
|
"minio": "^7.0.32",
|
|
39
39
|
"simpl-schema": "^3.0.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/minio": "^7.0.
|
|
42
|
+
"@types/minio": "^7.0.15",
|
|
43
43
|
"@types/node": "^18.11.9",
|
|
44
|
-
"@unchainedshop/types": "^2.0.0-
|
|
44
|
+
"@unchainedshop/types": "^2.0.0-beta8",
|
|
45
45
|
"jest": "^29.3.1",
|
|
46
46
|
"ts-jest": "^29.0.3",
|
|
47
|
-
"typescript": "^4.
|
|
47
|
+
"typescript": "^4.9.3"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Query } from '@unchainedshop/types/common';
|
|
2
1
|
import { ModuleInput, ModuleMutations } from '@unchainedshop/types/core';
|
|
3
2
|
import { File, FilesModule, FilesSettingsOptions } from '@unchainedshop/types/files';
|
|
4
3
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
@@ -37,7 +36,7 @@ export const configureFilesModule = async ({
|
|
|
37
36
|
// else try to fix by using ROOT_URL env
|
|
38
37
|
const finalURL = new URL(transformedURLString, process.env.ROOT_URL);
|
|
39
38
|
return finalURL.href;
|
|
40
|
-
} catch (
|
|
39
|
+
} catch (e2) {
|
|
41
40
|
// else return the transformed string because it's not an URL
|
|
42
41
|
return transformedURLString;
|
|
43
42
|
}
|
|
@@ -48,48 +47,28 @@ export const configureFilesModule = async ({
|
|
|
48
47
|
return Files.findOne(generateDbFilterById(fileId), options);
|
|
49
48
|
},
|
|
50
49
|
|
|
51
|
-
findFiles: async (selector) => {
|
|
52
|
-
return Files.find(selector).toArray();
|
|
50
|
+
findFiles: async (selector, options) => {
|
|
51
|
+
return Files.find(selector, options).toArray();
|
|
53
52
|
},
|
|
54
53
|
|
|
55
54
|
deleteMany: async (fileIds) => {
|
|
56
|
-
await Files.deleteMany({ _id: { $in: fileIds } });
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
findFilesByMetaData: async ({ meta }, options) => {
|
|
60
|
-
const metaKeys = Object.keys(meta);
|
|
61
|
-
|
|
62
|
-
if (metaKeys.length === 0) return [];
|
|
63
|
-
|
|
64
|
-
const selector: Query = metaKeys.reduce(
|
|
65
|
-
(currentSelector, key) =>
|
|
66
|
-
meta[key] !== undefined
|
|
67
|
-
? {
|
|
68
|
-
...currentSelector,
|
|
69
|
-
[`meta.${key}`]: meta[key],
|
|
70
|
-
}
|
|
71
|
-
: currentSelector,
|
|
72
|
-
{},
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const files = Files.find(selector, options);
|
|
76
|
-
|
|
77
|
-
return files.toArray();
|
|
55
|
+
const deletionResult = await Files.deleteMany({ _id: { $in: fileIds } });
|
|
56
|
+
return deletionResult.deletedCount;
|
|
78
57
|
},
|
|
79
58
|
|
|
80
59
|
create: async (doc: File, userId: string) => {
|
|
81
60
|
const fileId = await mutations.create(doc, userId);
|
|
82
|
-
emit('FILE_CREATE', { fileId });
|
|
61
|
+
await emit('FILE_CREATE', { fileId });
|
|
83
62
|
return fileId;
|
|
84
63
|
},
|
|
85
64
|
update: async (_id: string, doc: File, userId: string) => {
|
|
86
65
|
const fileId = await mutations.update(_id, { $set: doc }, userId);
|
|
87
|
-
emit('FILE_UPDATE', { fileId });
|
|
66
|
+
await emit('FILE_UPDATE', { fileId });
|
|
88
67
|
return fileId;
|
|
89
68
|
},
|
|
90
69
|
delete: async (fileId: string, userId: string) => {
|
|
91
70
|
const deletedCount = await mutations.delete(fileId, userId);
|
|
92
|
-
emit('FILE_REMOVE', { fileId });
|
|
71
|
+
await emit('FILE_REMOVE', { fileId });
|
|
93
72
|
return deletedCount;
|
|
94
73
|
},
|
|
95
74
|
deletePermanently: mutations.deletePermanently,
|