@webiny/api-file-manager 0.0.0-unstable.496cf268ac → 0.0.0-unstable.606fc9c866
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/createFileManager/files.crud.js +12 -15
- package/createFileManager/files.crud.js.map +1 -1
- package/graphql/index.js +17 -6
- package/graphql/index.js.map +1 -1
- package/package.json +17 -17
- package/types/file.lifecycle.d.ts +4 -0
- package/types/file.lifecycle.js.map +1 -1
- package/types.d.ts +12 -8
- package/types.js.map +1 -1
- package/plugins/crud/files/validation.d.ts +0 -3
- package/plugins/crud/files/validation.js +0 -41
- package/plugins/crud/files/validation.js.map +0 -1
- package/plugins/crud/files.crud.d.ts +0 -4
- package/plugins/crud/files.crud.js +0 -431
- package/plugins/crud/files.crud.js.map +0 -1
- package/plugins/crud/settings.crud.d.ts +0 -5
- package/plugins/crud/settings.crud.js +0 -116
- package/plugins/crud/settings.crud.js.map +0 -1
- package/plugins/crud/system.crud.d.ts +0 -4
- package/plugins/crud/system.crud.js +0 -153
- package/plugins/crud/system.crud.js.map +0 -1
- package/plugins/crud/utils/checkBasePermissions.d.ts +0 -5
- package/plugins/crud/utils/checkBasePermissions.js +0 -33
- package/plugins/crud/utils/checkBasePermissions.js.map +0 -1
- package/plugins/crud/utils/createFileModel.d.ts +0 -5
- package/plugins/crud/utils/createFileModel.js +0 -77
- package/plugins/crud/utils/createFileModel.js.map +0 -1
- package/plugins/crud/utils/lifecycleEvents.d.ts +0 -6
- package/plugins/crud/utils/lifecycleEvents.js +0 -38
- package/plugins/crud/utils/lifecycleEvents.js.map +0 -1
- package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +0 -21
- package/plugins/definitions/FilePhysicalStoragePlugin.js +0 -42
- package/plugins/definitions/FilePhysicalStoragePlugin.js.map +0 -1
- package/plugins/definitions/FilePlugin.d.ts +0 -136
- package/plugins/definitions/FilePlugin.js +0 -70
- package/plugins/definitions/FilePlugin.js.map +0 -1
- package/plugins/definitions/FileStorageTransformPlugin.d.ts +0 -34
- package/plugins/definitions/FileStorageTransformPlugin.js +0 -51
- package/plugins/definitions/FileStorageTransformPlugin.js.map +0 -1
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +0 -9
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +0 -17
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +0 -1
- package/plugins/definitions/InstallationPlugin.d.ts +0 -19
- package/plugins/definitions/InstallationPlugin.js +0 -42
- package/plugins/definitions/InstallationPlugin.js.map +0 -1
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +0 -9
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +0 -17
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +0 -1
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +0 -9
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +0 -17
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +0 -1
- package/plugins/graphql.d.ts +0 -4
- package/plugins/graphql.js +0 -290
- package/plugins/graphql.js.map +0 -1
- package/plugins/storage/FileStorage.d.ts +0 -30
- package/plugins/storage/FileStorage.js +0 -103
- package/plugins/storage/FileStorage.js.map +0 -1
- package/plugins/storage/index.d.ts +0 -4
- package/plugins/storage/index.js +0 -26
- package/plugins/storage/index.js.map +0 -1
- package/utils.d.ts +0 -4
- package/utils.js +0 -16
- package/utils.js.map +0 -1
|
@@ -56,7 +56,7 @@ const createFilesCrud = config => {
|
|
|
56
56
|
checkOwnership(file, permission, getIdentity());
|
|
57
57
|
return file;
|
|
58
58
|
},
|
|
59
|
-
async createFile(input) {
|
|
59
|
+
async createFile(input, meta) {
|
|
60
60
|
await (0, _checkBasePermissions.checkBasePermissions)(getPermission, {
|
|
61
61
|
rwd: "w"
|
|
62
62
|
});
|
|
@@ -83,13 +83,15 @@ const createFilesCrud = config => {
|
|
|
83
83
|
});
|
|
84
84
|
try {
|
|
85
85
|
await this.onFileBeforeCreate.publish({
|
|
86
|
-
file
|
|
86
|
+
file,
|
|
87
|
+
meta
|
|
87
88
|
});
|
|
88
89
|
const result = await storageOperations.files.create({
|
|
89
90
|
file
|
|
90
91
|
});
|
|
91
92
|
await this.onFileAfterCreate.publish({
|
|
92
|
-
file
|
|
93
|
+
file,
|
|
94
|
+
meta
|
|
93
95
|
});
|
|
94
96
|
return result;
|
|
95
97
|
} catch (ex) {
|
|
@@ -175,7 +177,7 @@ const createFilesCrud = config => {
|
|
|
175
177
|
}
|
|
176
178
|
return true;
|
|
177
179
|
},
|
|
178
|
-
async createFilesInBatch(inputs) {
|
|
180
|
+
async createFilesInBatch(inputs, meta) {
|
|
179
181
|
await (0, _checkBasePermissions.checkBasePermissions)(getPermission, {
|
|
180
182
|
rwd: "w"
|
|
181
183
|
});
|
|
@@ -203,13 +205,15 @@ const createFilesCrud = config => {
|
|
|
203
205
|
});
|
|
204
206
|
try {
|
|
205
207
|
await this.onFileBeforeBatchCreate.publish({
|
|
206
|
-
files
|
|
208
|
+
files,
|
|
209
|
+
meta
|
|
207
210
|
});
|
|
208
211
|
const results = await storageOperations.files.createBatch({
|
|
209
212
|
files
|
|
210
213
|
});
|
|
211
214
|
await this.onFileAfterBatchCreate.publish({
|
|
212
|
-
files
|
|
215
|
+
files,
|
|
216
|
+
meta
|
|
213
217
|
});
|
|
214
218
|
return results;
|
|
215
219
|
} catch (ex) {
|
|
@@ -302,18 +306,11 @@ const createFilesCrud = config => {
|
|
|
302
306
|
});
|
|
303
307
|
const params = {
|
|
304
308
|
where,
|
|
305
|
-
limit: limit ||
|
|
309
|
+
limit: limit || 1000000,
|
|
306
310
|
after
|
|
307
311
|
};
|
|
308
312
|
try {
|
|
309
|
-
|
|
310
|
-
if (Array.isArray(tags) === false) {
|
|
311
|
-
return [];
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* just to keep it standardized, sort by the tag ASC
|
|
315
|
-
*/
|
|
316
|
-
return tags.sort();
|
|
313
|
+
return await storageOperations.files.tags(params);
|
|
317
314
|
} catch (ex) {
|
|
318
315
|
throw new _error.default(ex.message || "Could not search for tags.", ex.code || "FILE_TAG_SEARCH_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
319
316
|
params
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["checkOwnership","file","permission","identity","own","createdBy","id","NotAuthorizedError","createFilesCrud","config","storageOperations","getLocaleCode","getTenantId","getIdentity","getPermission","WEBINY_VERSION","onFileBeforeCreate","createTopic","onFileAfterCreate","onFileBeforeBatchCreate","onFileAfterBatchCreate","onFileBeforeUpdate","onFileAfterUpdate","onFileBeforeDelete","onFileAfterDelete","getFile","checkBasePermissions","rwd","files","get","where","tenant","locale","NotFoundError","createFile","input","key","split","tags","Array","isArray","aliases","meta","private","createdOn","Date","toISOString","displayName","type","webinyVersion","publish","result","create","ex","WebinyError","message","code","data","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","length","type_in","tag_in","tag","toLowerCase","id_in","list","listTags"],"sources":["files.crud.ts"],"sourcesContent":["import { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport WebinyError from \"@webiny/error\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n CreatedBy,\n File,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesCRUD,\n FilesListOpts\n} from \"~/types\";\nimport { checkBasePermissions } from \"./checkBasePermissions\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, identity: SecurityIdentity) => {\n if (permission?.own === true) {\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nexport const createFilesCrud = (config: FileManagerConfig): FilesCRUD => {\n const {\n storageOperations,\n getLocaleCode,\n getTenantId,\n getIdentity,\n getPermission,\n WEBINY_VERSION\n } = config;\n\n return {\n onFileBeforeCreate: createTopic(\"fileManager.onFileBeforeCreate\"),\n onFileAfterCreate: createTopic(\"fileManager.onFileAfterCreate\"),\n onFileBeforeBatchCreate: createTopic(\"fileManager.onFileBeforeBatchCreate\"),\n onFileAfterBatchCreate: createTopic(\"fileManager.onFileAfterBatchCreate\"),\n onFileBeforeUpdate: createTopic(\"fileManager.onFileBeforeUpdate\"),\n onFileAfterUpdate: createTopic(\"fileManager.onFileAfterUpdate\"),\n onFileBeforeDelete: createTopic(\"fileManager.onFileBeforeDelete\"),\n onFileAfterDelete: createTopic(\"fileManager.onFileAfterDelete\"),\n async getFile(id: string) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"r\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, getIdentity());\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(getPermission, { rwd: \"w\" });\n const identity = getIdentity();\n\n // Extract ID from file key\n const [id] = input.key.split(\"/\");\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n id: input.id || id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: getTenantId(),\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(),\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeCreate.publish({ file });\n\n const result = await storageOperations.files.create({ file });\n\n await this.onFileAfterCreate.publish({ file });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"w\" });\n\n const original = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, getIdentity());\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n aliases: Array.isArray(input.aliases)\n ? input.aliases\n : Array.isArray(original.aliases)\n ? original.aliases\n : [],\n id: original.id,\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeUpdate.publish({\n original,\n file,\n input\n });\n\n const result = await storageOperations.files.update({\n original,\n file\n });\n\n await this.onFileAfterUpdate.publish({\n original,\n file,\n input\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"d\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, getIdentity());\n\n try {\n await this.onFileBeforeDelete.publish({ file });\n\n await storageOperations.files.delete({\n file\n });\n\n await this.onFileAfterDelete.publish({ file });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n await checkBasePermissions(getPermission, { rwd: \"w\" });\n\n const identity = getIdentity();\n const tenant = getTenantId();\n const locale = getLocaleCode();\n\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant,\n createdOn: new Date().toISOString(),\n createdBy,\n locale,\n webinyVersion: WEBINY_VERSION\n };\n });\n\n try {\n await this.onFileBeforeBatchCreate.publish({ files });\n const results = await storageOperations.files.createBatch({\n files\n });\n await this.onFileAfterBatchCreate.publish({ files });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(),\n tenant: getTenantId()\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.files.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(getPermission);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: getTenantId(),\n locale: getLocaleCode()\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.files.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAWA;AAGA;AACA;AACA;AACA,MAAMA,cAAc,GAAG,CAACC,IAAU,EAAEC,UAA0B,EAAEC,QAA0B,KAAK;EAC3F,IAAI,CAAAD,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEE,GAAG,MAAK,IAAI,EAAE;IAC1B,IAAIH,IAAI,CAACI,SAAS,CAACC,EAAE,KAAKH,QAAQ,CAACG,EAAE,EAAE;MACnC,MAAM,IAAIC,+BAAkB,EAAE;IAClC;EACJ;AACJ,CAAC;AAEM,MAAMC,eAAe,GAAIC,MAAyB,IAAgB;EACrE,MAAM;IACFC,iBAAiB;IACjBC,aAAa;IACbC,WAAW;IACXC,WAAW;IACXC,aAAa;IACbC;EACJ,CAAC,GAAGN,MAAM;EAEV,OAAO;IACHO,kBAAkB,EAAE,IAAAC,mBAAW,EAAC,gCAAgC,CAAC;IACjEC,iBAAi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Z,aAAa,CAAC;MAEzC,MAAMgB,KAAuD,+DACtD6C,YAAY;QACf5C,MAAM,EAAEnB,WAAW,EAAE;QACrBoB,MAAM,EAAErB,aAAa;MAAE,EAC1B;MAED,MAAM0D,MAAM,GAAG;QACXvC,KAAK;QACLwC,KAAK,EAAEA,KAAK,IAAI,MAAM;QACtBI;MACJ,CAAC;MAED,IAAI;QACA,MAAM,CAACpC,IAAI,CAAC,GAAG,MAAM5B,iBAAiB,CAACkB,KAAK,CAACU,IAAI,CAAC+B,MAAM,CAAC;QACzD,IAAI9B,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,KAAK,KAAK,EAAE;UAC/B,OAAO,EAAE;QACb;QACA;AAChB;AACA;QACgB,OAAOA,IAAI,CAACsC,IAAI,EAAE;MACtB,CAAC,CAAC,OAAOvB,EAAE,EAAE;QACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,4BAA4B,EAC1CF,EAAE,CAACG,IAAI,IAAI,uBAAuB,8DAE1BH,EAAE,CAACI,IAAI,IAAI,CAAC,CAAC;UACjBY;QAAM,GAEb;MACL;IACJ;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["checkOwnership","file","permission","identity","own","createdBy","id","NotAuthorizedError","createFilesCrud","config","storageOperations","getLocaleCode","getTenantId","getIdentity","getPermission","WEBINY_VERSION","onFileBeforeCreate","createTopic","onFileAfterCreate","onFileBeforeBatchCreate","onFileAfterBatchCreate","onFileBeforeUpdate","onFileAfterUpdate","onFileBeforeDelete","onFileAfterDelete","getFile","checkBasePermissions","rwd","files","get","where","tenant","locale","NotFoundError","createFile","input","meta","key","split","tags","Array","isArray","aliases","private","createdOn","Date","toISOString","displayName","type","webinyVersion","publish","result","create","ex","WebinyError","message","code","data","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","length","type_in","tag_in","tag","toLowerCase","id_in","list","listTags"],"sources":["files.crud.ts"],"sourcesContent":["import { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport WebinyError from \"@webiny/error\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n CreatedBy,\n File,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesCRUD,\n FilesListOpts\n} from \"~/types\";\nimport { checkBasePermissions } from \"./checkBasePermissions\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, identity: SecurityIdentity) => {\n if (permission?.own === true) {\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nexport const createFilesCrud = (config: FileManagerConfig): FilesCRUD => {\n const {\n storageOperations,\n getLocaleCode,\n getTenantId,\n getIdentity,\n getPermission,\n WEBINY_VERSION\n } = config;\n\n return {\n onFileBeforeCreate: createTopic(\"fileManager.onFileBeforeCreate\"),\n onFileAfterCreate: createTopic(\"fileManager.onFileAfterCreate\"),\n onFileBeforeBatchCreate: createTopic(\"fileManager.onFileBeforeBatchCreate\"),\n onFileAfterBatchCreate: createTopic(\"fileManager.onFileAfterBatchCreate\"),\n onFileBeforeUpdate: createTopic(\"fileManager.onFileBeforeUpdate\"),\n onFileAfterUpdate: createTopic(\"fileManager.onFileAfterUpdate\"),\n onFileBeforeDelete: createTopic(\"fileManager.onFileBeforeDelete\"),\n onFileAfterDelete: createTopic(\"fileManager.onFileAfterDelete\"),\n async getFile(id: string) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"r\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, getIdentity());\n\n return file;\n },\n async createFile(input, meta) {\n await checkBasePermissions(getPermission, { rwd: \"w\" });\n const identity = getIdentity();\n\n // Extract ID from file key\n const [id] = input.key.split(\"/\");\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n id: input.id || id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: getTenantId(),\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(),\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeCreate.publish({ file, meta });\n\n const result = await storageOperations.files.create({ file });\n\n await this.onFileAfterCreate.publish({ file, meta });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"w\" });\n\n const original = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, getIdentity());\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n aliases: Array.isArray(input.aliases)\n ? input.aliases\n : Array.isArray(original.aliases)\n ? original.aliases\n : [],\n id: original.id,\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeUpdate.publish({\n original,\n file,\n input\n });\n\n const result = await storageOperations.files.update({\n original,\n file\n });\n\n await this.onFileAfterUpdate.publish({\n original,\n file,\n input\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"d\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, getIdentity());\n\n try {\n await this.onFileBeforeDelete.publish({ file });\n\n await storageOperations.files.delete({\n file\n });\n\n await this.onFileAfterDelete.publish({ file });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs, meta) {\n await checkBasePermissions(getPermission, { rwd: \"w\" });\n\n const identity = getIdentity();\n const tenant = getTenantId();\n const locale = getLocaleCode();\n\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant,\n createdOn: new Date().toISOString(),\n createdBy,\n locale,\n webinyVersion: WEBINY_VERSION\n };\n });\n\n try {\n await this.onFileBeforeBatchCreate.publish({ files, meta });\n const results = await storageOperations.files.createBatch({\n files\n });\n await this.onFileAfterBatchCreate.publish({ files, meta });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(),\n tenant: getTenantId()\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.files.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(getPermission);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: getTenantId(),\n locale: getLocaleCode()\n };\n\n const params = {\n where,\n limit: limit || 1000000,\n after\n };\n\n try {\n return await storageOperations.files.tags(params);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAWA;AAGA;AACA;AACA;AACA,MAAMA,cAAc,GAAG,CAACC,IAAU,EAAEC,UAA0B,EAAEC,QA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AG,CAAC,SAAS,CAAC;MACpF,IAAI;QACA,OAAO,MAAMnE,iBAAiB,CAACkB,KAAK,CAACwD,IAAI,CAAC;UACtCtD,KAAK;UACL4C,KAAK;UACLJ,KAAK;UACLM;QACJ,CAAC,CAAC;MACN,CAAC,CAAC,OAAOvB,EAAE,EAAE;QACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,2CAA2C,EACzDF,EAAE,CAACG,IAAI,IAAI,uBAAuB,8DAE1BH,EAAE,CAACI,IAAI,IAAI,CAAC,CAAC;UACjB3B,KAAK;UACL4C,KAAK;UACLJ,KAAK;UACLM;QAAI,GAEX;MACL;IACJ,CAAC;IACD,MAAMS,QAAQ,CAAC;MAAEvD,KAAK,EAAE6C,YAAY;MAAED,KAAK;MAAEJ;IAAM,CAAC,EAAE;MAClD,MAAM,IAAA5C,0CAAoB,EAACZ,aAAa,CAAC;MAEzC,MAAMgB,KAAuD,+DACtD6C,YAAY;QACf5C,MAAM,EAAEnB,WAAW,EAAE;QACrBoB,MAAM,EAAErB,aAAa;MAAE,EAC1B;MAED,MAAM0D,MAAM,GAAG;QACXvC,KAAK;QACLwC,KAAK,EAAEA,KAAK,IAAI,OAAO;QACvBI;MACJ,CAAC;MAED,IAAI;QACA,OAAO,MAAMhE,iBAAiB,CAACkB,KAAK,CAACW,IAAI,CAAC8B,MAAM,CAAC;MACrD,CAAC,CAAC,OAAOhB,EAAE,EAAE;QACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,4BAA4B,EAC1CF,EAAE,CAACG,IAAI,IAAI,uBAAuB,8DAE1BH,EAAE,CAACI,IAAI,IAAI,CAAC,CAAC;UACjBY;QAAM,GAEb;MACL;IACJ;EACJ,CAAC;AACL,CAAC;AAAC"}
|
package/graphql/index.js
CHANGED
|
@@ -146,6 +146,16 @@ const createGraphQLSchemaPlugin = () => {
|
|
|
146
146
|
tag_not_startsWith: String
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
type ListTagResponseItem {
|
|
150
|
+
tag: String!
|
|
151
|
+
count: Number!
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type ListTagsResponse {
|
|
155
|
+
data: [ListTagResponseItem!]
|
|
156
|
+
error: FileError
|
|
157
|
+
}
|
|
158
|
+
|
|
149
159
|
type FmQuery {
|
|
150
160
|
getFile(id: ID, where: JSON, sort: String): FileResponse
|
|
151
161
|
|
|
@@ -159,7 +169,7 @@ const createGraphQLSchemaPlugin = () => {
|
|
|
159
169
|
where: FileWhereInput
|
|
160
170
|
): FileListResponse
|
|
161
171
|
|
|
162
|
-
listTags(where: TagWhereInput):
|
|
172
|
+
listTags(where: TagWhereInput): ListTagsResponse!
|
|
163
173
|
|
|
164
174
|
# Get installed version
|
|
165
175
|
version: String
|
|
@@ -173,8 +183,8 @@ const createGraphQLSchemaPlugin = () => {
|
|
|
173
183
|
}
|
|
174
184
|
|
|
175
185
|
type FmMutation {
|
|
176
|
-
createFile(data: CreateFileInput
|
|
177
|
-
createFiles(data: [CreateFileInput]
|
|
186
|
+
createFile(data: CreateFileInput!, meta: JSON): FileResponse
|
|
187
|
+
createFiles(data: [CreateFileInput]!, meta: JSON): CreateFilesResponse
|
|
178
188
|
updateFile(id: ID!, data: UpdateFileInput!): FileResponse
|
|
179
189
|
deleteFile(id: ID!): FilesDeleteResponse
|
|
180
190
|
install(srcPrefix: String): FileManagerBooleanResponse
|
|
@@ -220,7 +230,8 @@ const createGraphQLSchemaPlugin = () => {
|
|
|
220
230
|
},
|
|
221
231
|
async listTags(_, args, context) {
|
|
222
232
|
try {
|
|
223
|
-
|
|
233
|
+
const tags = await context.fileManager.listTags(args || {});
|
|
234
|
+
return new _handlerGraphql.Response(tags);
|
|
224
235
|
} catch (error) {
|
|
225
236
|
return new _handlerGraphql.ErrorResponse(error);
|
|
226
237
|
}
|
|
@@ -242,13 +253,13 @@ const createGraphQLSchemaPlugin = () => {
|
|
|
242
253
|
},
|
|
243
254
|
FmMutation: {
|
|
244
255
|
async createFile(_, args, context) {
|
|
245
|
-
return resolve(() => context.fileManager.createFile(args.data));
|
|
256
|
+
return resolve(() => context.fileManager.createFile(args.data, args.meta));
|
|
246
257
|
},
|
|
247
258
|
async updateFile(_, args, context) {
|
|
248
259
|
return resolve(() => context.fileManager.updateFile(args.id, args.data));
|
|
249
260
|
},
|
|
250
261
|
async createFiles(_, args, context) {
|
|
251
|
-
return resolve(() => context.fileManager.createFilesInBatch(args.data));
|
|
262
|
+
return resolve(() => context.fileManager.createFilesInBatch(args.data, args.meta));
|
|
252
263
|
},
|
|
253
264
|
async deleteFile(_, args, context) {
|
|
254
265
|
return resolve(async () => {
|
package/graphql/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["emptyResolver","resolve","fn","Response","e","ErrorResponse","createGraphQLSchemaPlugin","fileManagerGraphQL","GraphQLSchemaPlugin","typeDefs","resolvers","File","src","file","_","context","settings","fileManager","getSettings","srcPrefix","key","Query","Mutation","FmQuery","getFile","args","id","listFiles","data","meta","ListResponse","listTags","error","version","__","i18n","tenancy","getCurrentTenant","getContentLocale","getVersion","FmMutation","createFile","updateFile","createFiles","createFilesInBatch","deleteFile","storage","delete","install","updateSettings","name"],"sources":["index.ts"],"sourcesContent":["import {\n Response,\n ErrorResponse,\n ListResponse,\n GraphQLSchemaPlugin\n} from \"@webiny/handler-graphql\";\nimport { FileManagerContext, FilesListOpts } from \"~/types\";\n\nconst emptyResolver = () => ({});\n\n/**\n * Use any because it really can be any.\n * TODO @ts-refactor maybe use generics at some point?\n */\ninterface ResolveCallable {\n (): Promise<any>;\n}\n\nconst resolve = async (fn: ResolveCallable) => {\n try {\n return new Response(await fn());\n } catch (e) {\n return new ErrorResponse(e);\n }\n};\n\nexport const createGraphQLSchemaPlugin = () => {\n const fileManagerGraphQL = new GraphQLSchemaPlugin<FileManagerContext>({\n typeDefs: /* GraphQL */ `\n type FmCreatedBy {\n id: ID\n displayName: String\n }\n\n input CreateFileInput {\n id: ID!\n key: String!\n name: String!\n size: Long!\n type: String!\n tags: [String!]\n aliases: [String!]\n meta: JSON\n }\n\n input UpdateFileInput {\n key: String\n name: String\n size: Long\n type: String\n tags: [String!]\n aliases: [String!]\n meta: JSON\n }\n\n type UploadFileResponseDataFile {\n id: ID!\n name: String!\n type: String!\n size: Long!\n key: String!\n }\n\n type UploadFileResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type FileListMeta {\n cursor: String\n totalCount: Int\n hasMoreItems: Boolean\n }\n\n type FileError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type FileListResponse {\n data: [File]\n meta: FileListMeta\n error: FileError\n }\n\n type FileResponse {\n data: File\n error: FileError\n }\n\n type CreateFilesResponse {\n data: [File!]\n error: FileError\n }\n\n type File {\n id: ID!\n key: String!\n name: String!\n size: Long!\n type: String!\n src: String!\n tags: [String!]\n aliases: [String!]\n meta: JSON\n createdOn: DateTime\n createdBy: FmCreatedBy\n }\n\n type FileManagerBooleanResponse {\n data: Boolean\n error: FileError\n }\n\n type FileManagerSettings {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n input FileManagerSettingsInput {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n type FileManagerSettingsResponse {\n data: FileManagerSettings\n error: FileError\n }\n\n input FileWhereInput {\n search: String\n type: String\n type_in: [String!]\n tag: String\n tag_in: [String!]\n tag_and_in: [String!]\n tag_startsWith: String\n tag_not_startsWith: String\n id_in: [ID!]\n id: ID\n createdBy: ID\n }\n\n input TagWhereInput {\n tag_startsWith: String\n tag_not_startsWith: String\n }\n\n type FmQuery {\n getFile(id: ID, where: JSON, sort: String): FileResponse\n\n listFiles(\n limit: Int\n after: String\n types: [String]\n tags: [String]\n ids: [ID]\n search: String\n where: FileWhereInput\n ): FileListResponse\n\n listTags(where: TagWhereInput): [String]\n\n # Get installed version\n version: String\n\n getSettings: FileManagerSettingsResponse\n }\n\n type FilesDeleteResponse {\n data: Boolean\n error: FileError\n }\n\n type FmMutation {\n createFile(data: CreateFileInput!): FileResponse\n createFiles(data: [CreateFileInput]!): CreateFilesResponse\n updateFile(id: ID!, data: UpdateFileInput!): FileResponse\n deleteFile(id: ID!): FilesDeleteResponse\n install(srcPrefix: String): FileManagerBooleanResponse\n updateSettings(data: FileManagerSettingsInput): FileManagerSettingsResponse\n }\n\n input FilesInstallInput {\n srcPrefix: String!\n }\n\n extend type Query {\n fileManager: FmQuery\n }\n\n extend type Mutation {\n fileManager: FmMutation\n }\n `,\n resolvers: {\n File: {\n async src(file, _, context: FileManagerContext) {\n const settings = await context.fileManager.getSettings();\n return (settings?.srcPrefix || \"\") + file.key;\n }\n },\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmQuery: {\n getFile(_, args: any, context) {\n return resolve(() => context.fileManager.getFile(args.id));\n },\n async listFiles(_, args: FilesListOpts, context) {\n try {\n const [data, meta] = await context.fileManager.listFiles(args);\n return new ListResponse(data, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n async listTags(_, args: any, context) {\n try {\n return await context.fileManager.listTags(args || {});\n } catch (error) {\n return new ErrorResponse(error);\n }\n },\n async version(_, __, context) {\n const { i18n, tenancy, fileManager } = context;\n if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {\n return null;\n }\n\n return await fileManager.getVersion();\n },\n async getSettings(_, __, context) {\n return resolve(() => context.fileManager.getSettings());\n }\n },\n FmMutation: {\n async createFile(_, args: any, context) {\n return resolve(() => context.fileManager.createFile(args.data));\n },\n async updateFile(_, args: any, context) {\n return resolve(() => context.fileManager.updateFile(args.id, args.data));\n },\n async createFiles(_, args: any, context) {\n return resolve(() => context.fileManager.createFilesInBatch(args.data));\n },\n async deleteFile(_, args: any, context) {\n return resolve(async () => {\n // TODO: Ideally, this should work via a lifecycle hook; first we delete a record from DB, then from cloud storage.\n const file = await context.fileManager.getFile(args.id);\n return await context.fileManager.storage.delete({\n id: file.id,\n key: file.key\n });\n });\n },\n async install(_, args: any, context) {\n return resolve(() =>\n context.fileManager.install({ srcPrefix: args.srcPrefix })\n );\n },\n async updateSettings(_, args: any, context) {\n return resolve(() => context.fileManager.updateSettings(args.data));\n }\n }\n }\n });\n fileManagerGraphQL.name = \"fm.graphql.schema\";\n\n return fileManagerGraphQL;\n};\n"],"mappings":";;;;;;AAAA;AAQA,MAAMA,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;;AAKA,MAAMC,OAAO,GAAG,MAAOC,EAAmB,IAAK;EAC3C,IAAI;IACA,OAAO,IAAIC,wBAAQ,CAAC,MAAMD,EAAE,EAAE,CAAC;EACnC,CAAC,CAAC,OAAOE,CAAC,EAAE;IACR,OAAO,IAAIC,6BAAa,CAACD,CAAC,CAAC;EAC/B;AACJ,CAAC;AAEM,MAAME,yBAAyB,GAAG,MAAM;EAC3C,MAAMC,kBAAkB,GAAG,IAAIC,mCAAmB,CAAqB;IACnEC,QAAQ,EAAE,aAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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ACE,WAAW,CAAC2B,kBAAkB,CAACnB,IAAI,CAACG,IAAI,CAAC,CAAC;QAC3E,CAAC;QACD,MAAMiB,UAAU,CAAC/B,CAAC,EAAEW,IAAS,EAAEV,OAAO,EAAE;UACpC,OAAOd,OAAO,CAAC,YAAY;YACvB;YACA,MAAMY,IAAI,GAAG,MAAME,OAAO,CAACE,WAAW,CAACO,OAAO,CAACC,IAAI,CAACC,EAAE,CAAC;YACvD,OAAO,MAAMX,OAAO,CAACE,WAAW,CAAC6B,OAAO,CAACC,MAAM,CAAC;cAC5CrB,EAAE,EAAEb,IAAI,CAACa,EAAE;cACXN,GAAG,EAAEP,IAAI,CAACO;YACd,CAAC,CAAC;UACN,CAAC,CAAC;QACN,CAAC;QACD,MAAM4B,OAAO,CAAClC,CAAC,EAAEW,IAAS,EAAEV,OAAO,EAAE;UACjC,OAAOd,OAAO,CAAC,MACXc,OAAO,CAACE,WAAW,CAAC+B,OAAO,CAAC;YAAE7B,SAAS,EAAEM,IAAI,CAACN;UAAU,CAAC,CAAC,CAC7D;QACL,CAAC;QACD,MAAM8B,cAAc,CAACnC,CAAC,EAAEW,IAAS,EAAEV,OAAO,EAAE;UACxC,OAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAW,CAACgC,cAAc,CAACxB,IAAI,CAACG,IAAI,CAAC,CAAC;QACvE;MACJ;IACJ;EACJ,CAAC,CAAC;EACFrB,kBAAkB,CAAC2C,IAAI,GAAG,mBAAmB;EAE7C,OAAO3C,kBAAkB;AAC7B,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["emptyResolver","resolve","fn","Response","e","ErrorResponse","createGraphQLSchemaPlugin","fileManagerGraphQL","GraphQLSchemaPlugin","typeDefs","resolvers","File","src","file","_","context","settings","fileManager","getSettings","srcPrefix","key","Query","Mutation","FmQuery","getFile","args","id","listFiles","data","meta","ListResponse","listTags","tags","error","version","__","i18n","tenancy","getCurrentTenant","getContentLocale","getVersion","FmMutation","createFile","updateFile","createFiles","createFilesInBatch","deleteFile","storage","delete","install","updateSettings","name"],"sources":["index.ts"],"sourcesContent":["import {\n Response,\n ErrorResponse,\n ListResponse,\n GraphQLSchemaPlugin\n} from \"@webiny/handler-graphql\";\nimport { FileManagerContext, FilesListOpts } from \"~/types\";\n\nconst emptyResolver = () => ({});\n\n/**\n * Use any because it really can be any.\n * TODO @ts-refactor maybe use generics at some point?\n */\ninterface ResolveCallable {\n (): Promise<any>;\n}\n\nconst resolve = async (fn: ResolveCallable) => {\n try {\n return new Response(await fn());\n } catch (e) {\n return new ErrorResponse(e);\n }\n};\n\nexport const createGraphQLSchemaPlugin = () => {\n const fileManagerGraphQL = new GraphQLSchemaPlugin<FileManagerContext>({\n typeDefs: /* GraphQL */ `\n type FmCreatedBy {\n id: ID\n displayName: String\n }\n\n input CreateFileInput {\n id: ID!\n key: String!\n name: String!\n size: Long!\n type: String!\n tags: [String!]\n aliases: [String!]\n meta: JSON\n }\n\n input UpdateFileInput {\n key: String\n name: String\n size: Long\n type: String\n tags: [String!]\n aliases: [String!]\n meta: JSON\n }\n\n type UploadFileResponseDataFile {\n id: ID!\n name: String!\n type: String!\n size: Long!\n key: String!\n }\n\n type UploadFileResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type FileListMeta {\n cursor: String\n totalCount: Int\n hasMoreItems: Boolean\n }\n\n type FileError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type FileListResponse {\n data: [File]\n meta: FileListMeta\n error: FileError\n }\n\n type FileResponse {\n data: File\n error: FileError\n }\n\n type CreateFilesResponse {\n data: [File!]\n error: FileError\n }\n\n type File {\n id: ID!\n key: String!\n name: String!\n size: Long!\n type: String!\n src: String!\n tags: [String!]\n aliases: [String!]\n meta: JSON\n createdOn: DateTime\n createdBy: FmCreatedBy\n }\n\n type FileManagerBooleanResponse {\n data: Boolean\n error: FileError\n }\n\n type FileManagerSettings {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n input FileManagerSettingsInput {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n type FileManagerSettingsResponse {\n data: FileManagerSettings\n error: FileError\n }\n\n input FileWhereInput {\n search: String\n type: String\n type_in: [String!]\n tag: String\n tag_in: [String!]\n tag_and_in: [String!]\n tag_startsWith: String\n tag_not_startsWith: String\n id_in: [ID!]\n id: ID\n createdBy: ID\n }\n\n input TagWhereInput {\n tag_startsWith: String\n tag_not_startsWith: String\n }\n\n type ListTagResponseItem {\n tag: String!\n count: Number!\n }\n\n type ListTagsResponse {\n data: [ListTagResponseItem!]\n error: FileError\n }\n\n type FmQuery {\n getFile(id: ID, where: JSON, sort: String): FileResponse\n\n listFiles(\n limit: Int\n after: String\n types: [String]\n tags: [String]\n ids: [ID]\n search: String\n where: FileWhereInput\n ): FileListResponse\n\n listTags(where: TagWhereInput): ListTagsResponse!\n\n # Get installed version\n version: String\n\n getSettings: FileManagerSettingsResponse\n }\n\n type FilesDeleteResponse {\n data: Boolean\n error: FileError\n }\n\n type FmMutation {\n createFile(data: CreateFileInput!, meta: JSON): FileResponse\n createFiles(data: [CreateFileInput]!, meta: JSON): CreateFilesResponse\n updateFile(id: ID!, data: UpdateFileInput!): FileResponse\n deleteFile(id: ID!): FilesDeleteResponse\n install(srcPrefix: String): FileManagerBooleanResponse\n updateSettings(data: FileManagerSettingsInput): FileManagerSettingsResponse\n }\n\n input FilesInstallInput {\n srcPrefix: String!\n }\n\n extend type Query {\n fileManager: FmQuery\n }\n\n extend type Mutation {\n fileManager: FmMutation\n }\n `,\n resolvers: {\n File: {\n async src(file, _, context: FileManagerContext) {\n const settings = await context.fileManager.getSettings();\n return (settings?.srcPrefix || \"\") + file.key;\n }\n },\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmQuery: {\n getFile(_, args: any, context) {\n return resolve(() => context.fileManager.getFile(args.id));\n },\n async listFiles(_, args: FilesListOpts, context) {\n try {\n const [data, meta] = await context.fileManager.listFiles(args);\n return new ListResponse(data, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n async listTags(_, args: any, context) {\n try {\n const tags = await context.fileManager.listTags(args || {});\n\n return new Response(tags);\n } catch (error) {\n return new ErrorResponse(error);\n }\n },\n async version(_, __, context) {\n const { i18n, tenancy, fileManager } = context;\n if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {\n return null;\n }\n\n return await fileManager.getVersion();\n },\n async getSettings(_, __, context) {\n return resolve(() => context.fileManager.getSettings());\n }\n },\n FmMutation: {\n async createFile(_, args: any, context) {\n return resolve(() => context.fileManager.createFile(args.data, args.meta));\n },\n async updateFile(_, args: any, context) {\n return resolve(() => context.fileManager.updateFile(args.id, args.data));\n },\n async createFiles(_, args: any, context) {\n return resolve(() =>\n context.fileManager.createFilesInBatch(args.data, args.meta)\n );\n },\n async deleteFile(_, args: any, context) {\n return resolve(async () => {\n // TODO: Ideally, this should work via a lifecycle hook; first we delete a record from DB, then from cloud storage.\n const file = await context.fileManager.getFile(args.id);\n return await context.fileManager.storage.delete({\n id: file.id,\n key: file.key\n });\n });\n },\n async install(_, args: any, context) {\n return resolve(() =>\n context.fileManager.install({ srcPrefix: args.srcPrefix })\n );\n },\n async updateSettings(_, args: any, context) {\n return resolve(() => context.fileManager.updateSettings(args.data));\n }\n }\n }\n });\n fileManagerGraphQL.name = \"fm.graphql.schema\";\n\n return fileManagerGraphQL;\n};\n"],"mappings":";;;;;;AAAA;AAQA,MAAMA,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;;AAKA,MAAMC,OAAO,GAAG,MAAOC,EAAmB,IAAK;EAC3C,IAAI;IACA,OAAO,IAAIC,wBAAQ,CAAC,MAAMD,EAAE,EAAE,CAAC;EACnC,CAAC,CAAC,OAAOE,CAAC,EAAE;IACR,OAAO,IAAIC,6BAAa,CAACD,CAAC,CAAC;EAC/B;AACJ,CAAC;AAEM,MAAME,yBAAyB,GAAG,MAAM;EAC3C,MAAMC,kBAAkB,GAAG,IAAIC,mCAAmB,CAAqB;IACnEC,QAAQ,EAAE,aAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;IACDC,SAAS,EAAE;MACPC,IAAI,EAAE;QACF,MAAMC,GAAG,CAACC,IAAI,EAAEC,CAAC,EAAEC,OAA2B,EAAE;UAC5C,MAAMC,QAAQ,GAAG,MAAMD,OAAO,CAACE,WAAW,CAACC,WAAW,EAAE;UACxD,OAAO,CAAC,CAAAF,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEG,SAAS,KAAI,EAA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AAC,CAAC;UACN,CAAC,CAAC;QACN,CAAC;QACD,MAAM6B,OAAO,CAACnC,CAAC,EAAEW,IAAS,EAAEV,OAAO,EAAE;UACjC,OAAOd,OAAO,CAAC,MACXc,OAAO,CAACE,WAAW,CAACgC,OAAO,CAAC;YAAE9B,SAAS,EAAEM,IAAI,CAACN;UAAU,CAAC,CAAC,CAC7D;QACL,CAAC;QACD,MAAM+B,cAAc,CAACpC,CAAC,EAAEW,IAAS,EAAEV,OAAO,EAAE;UACxC,OAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAW,CAACiC,cAAc,CAACzB,IAAI,CAACG,IAAI,CAAC,CAAC;QACvE;MACJ;IACJ;EACJ,CAAC,CAAC;EACFrB,kBAAkB,CAAC4C,IAAI,GAAG,mBAAmB;EAE7C,OAAO5C,kBAAkB;AAC7B,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.606fc9c866",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fm:base"
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/runtime": "7.20.13",
|
|
22
22
|
"@commodo/fields": "1.1.2-beta.20",
|
|
23
|
-
"@webiny/api": "0.0.0-unstable.
|
|
24
|
-
"@webiny/api-security": "0.0.0-unstable.
|
|
25
|
-
"@webiny/api-tenancy": "0.0.0-unstable.
|
|
26
|
-
"@webiny/error": "0.0.0-unstable.
|
|
27
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
28
|
-
"@webiny/handler-aws": "0.0.0-unstable.
|
|
29
|
-
"@webiny/handler-client": "0.0.0-unstable.
|
|
30
|
-
"@webiny/handler-graphql": "0.0.0-unstable.
|
|
31
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
32
|
-
"@webiny/project-utils": "0.0.0-unstable.
|
|
33
|
-
"@webiny/pubsub": "0.0.0-unstable.
|
|
34
|
-
"@webiny/validation": "0.0.0-unstable.
|
|
23
|
+
"@webiny/api": "0.0.0-unstable.606fc9c866",
|
|
24
|
+
"@webiny/api-security": "0.0.0-unstable.606fc9c866",
|
|
25
|
+
"@webiny/api-tenancy": "0.0.0-unstable.606fc9c866",
|
|
26
|
+
"@webiny/error": "0.0.0-unstable.606fc9c866",
|
|
27
|
+
"@webiny/handler": "0.0.0-unstable.606fc9c866",
|
|
28
|
+
"@webiny/handler-aws": "0.0.0-unstable.606fc9c866",
|
|
29
|
+
"@webiny/handler-client": "0.0.0-unstable.606fc9c866",
|
|
30
|
+
"@webiny/handler-graphql": "0.0.0-unstable.606fc9c866",
|
|
31
|
+
"@webiny/plugins": "0.0.0-unstable.606fc9c866",
|
|
32
|
+
"@webiny/project-utils": "0.0.0-unstable.606fc9c866",
|
|
33
|
+
"@webiny/pubsub": "0.0.0-unstable.606fc9c866",
|
|
34
|
+
"@webiny/validation": "0.0.0-unstable.606fc9c866",
|
|
35
35
|
"aws-sdk": "2.1310.0",
|
|
36
36
|
"object-hash": "2.2.0"
|
|
37
37
|
},
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
43
43
|
"@babel/preset-env": "^7.19.4",
|
|
44
44
|
"@babel/preset-typescript": "^7.18.6",
|
|
45
|
-
"@webiny/api-i18n": "^0.0.0-unstable.
|
|
46
|
-
"@webiny/api-i18n-ddb": "^0.0.0-unstable.
|
|
47
|
-
"@webiny/cli": "^0.0.0-unstable.
|
|
45
|
+
"@webiny/api-i18n": "^0.0.0-unstable.606fc9c866",
|
|
46
|
+
"@webiny/api-i18n-ddb": "^0.0.0-unstable.606fc9c866",
|
|
47
|
+
"@webiny/cli": "^0.0.0-unstable.606fc9c866",
|
|
48
48
|
"jest": "^28.1.0",
|
|
49
49
|
"mdbid": "^1.0.0",
|
|
50
50
|
"rimraf": "^3.0.2",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
]
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "606fc9c866aec436f24983abc9bdaf02af2b8746"
|
|
74
74
|
}
|
|
@@ -2,15 +2,19 @@ import { Topic } from "@webiny/pubsub/types";
|
|
|
2
2
|
import { File } from "./file";
|
|
3
3
|
export interface OnFileBeforeCreateTopicParams<TFile extends File = File> {
|
|
4
4
|
file: TFile;
|
|
5
|
+
meta?: Record<string, any>;
|
|
5
6
|
}
|
|
6
7
|
export interface OnFileAfterCreateTopicParams<TFile extends File = File> {
|
|
7
8
|
file: TFile;
|
|
9
|
+
meta?: Record<string, any>;
|
|
8
10
|
}
|
|
9
11
|
export interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {
|
|
10
12
|
files: TFile[];
|
|
13
|
+
meta?: Record<string, any>;
|
|
11
14
|
}
|
|
12
15
|
export interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {
|
|
13
16
|
files: TFile[];
|
|
17
|
+
meta?: Record<string, any>;
|
|
14
18
|
}
|
|
15
19
|
export interface OnFileBeforeUpdateTopicParams<TFile extends File = File> {
|
|
16
20
|
original: TFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["file.lifecycle.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { File } from \"./file\";\n\nexport interface OnFileBeforeCreateTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileAfterCreateTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n}\n\nexport interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n}\n\nexport interface OnFileBeforeUpdateTopicParams<TFile extends File = File> {\n original: TFile;\n file: TFile;\n input: Record<string, any>;\n}\n\nexport interface OnFileAfterUpdateTopicParams<TFile extends File = File> {\n original: TFile;\n file: TFile;\n input: Record<string, any>;\n}\n\nexport interface OnFileBeforeDeleteTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileAfterDeleteTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface FileLifecycleEvents {\n onFileBeforeCreate: Topic<OnFileBeforeCreateTopicParams>;\n onFileAfterCreate: Topic<OnFileAfterCreateTopicParams>;\n onFileBeforeBatchCreate: Topic<OnFileBeforeBatchCreateTopicParams>;\n onFileAfterBatchCreate: Topic<OnFileAfterBatchCreateTopicParams>;\n onFileBeforeUpdate: Topic<OnFileBeforeUpdateTopicParams>;\n onFileAfterUpdate: Topic<OnFileAfterUpdateTopicParams>;\n onFileBeforeDelete: Topic<OnFileBeforeDeleteTopicParams>;\n onFileAfterDelete: Topic<OnFileAfterDeleteTopicParams>;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["file.lifecycle.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { File } from \"./file\";\n\nexport interface OnFileBeforeCreateTopicParams<TFile extends File = File> {\n file: TFile;\n meta?: Record<string, any>;\n}\n\nexport interface OnFileAfterCreateTopicParams<TFile extends File = File> {\n file: TFile;\n meta?: Record<string, any>;\n}\n\nexport interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n meta?: Record<string, any>;\n}\n\nexport interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n meta?: Record<string, any>;\n}\n\nexport interface OnFileBeforeUpdateTopicParams<TFile extends File = File> {\n original: TFile;\n file: TFile;\n input: Record<string, any>;\n}\n\nexport interface OnFileAfterUpdateTopicParams<TFile extends File = File> {\n original: TFile;\n file: TFile;\n input: Record<string, any>;\n}\n\nexport interface OnFileBeforeDeleteTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileAfterDeleteTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface FileLifecycleEvents {\n onFileBeforeCreate: Topic<OnFileBeforeCreateTopicParams>;\n onFileAfterCreate: Topic<OnFileAfterCreateTopicParams>;\n onFileBeforeBatchCreate: Topic<OnFileBeforeBatchCreateTopicParams>;\n onFileAfterBatchCreate: Topic<OnFileAfterBatchCreateTopicParams>;\n onFileBeforeUpdate: Topic<OnFileBeforeUpdateTopicParams>;\n onFileAfterUpdate: Topic<OnFileAfterUpdateTopicParams>;\n onFileBeforeDelete: Topic<OnFileBeforeDeleteTopicParams>;\n onFileAfterDelete: Topic<OnFileAfterDeleteTopicParams>;\n}\n"],"mappings":""}
|
package/types.d.ts
CHANGED
|
@@ -66,14 +66,18 @@ interface FilesCrudListTagsParams {
|
|
|
66
66
|
limit?: number;
|
|
67
67
|
after?: string;
|
|
68
68
|
}
|
|
69
|
+
export interface ListTagsResponse {
|
|
70
|
+
tag: string;
|
|
71
|
+
count: number;
|
|
72
|
+
}
|
|
69
73
|
export interface FilesCRUD extends FileLifecycleEvents {
|
|
70
74
|
getFile(id: string): Promise<File>;
|
|
71
75
|
listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;
|
|
72
|
-
listTags(params: FilesCrudListTagsParams): Promise<
|
|
73
|
-
createFile(data: FileInput): Promise<File>;
|
|
76
|
+
listTags(params: FilesCrudListTagsParams): Promise<ListTagsResponse[]>;
|
|
77
|
+
createFile(data: FileInput, meta?: Record<string, any>): Promise<File>;
|
|
74
78
|
updateFile(id: string, data: Partial<FileInput>): Promise<File>;
|
|
75
79
|
deleteFile(id: string): Promise<boolean>;
|
|
76
|
-
createFilesInBatch(data: FileInput[]): Promise<File[]>;
|
|
80
|
+
createFilesInBatch(data: FileInput[], meta?: Record<string, any>): Promise<File[]>;
|
|
77
81
|
}
|
|
78
82
|
export interface SystemCRUD {
|
|
79
83
|
onSystemBeforeInstall: Topic;
|
|
@@ -296,10 +300,10 @@ export declare type FileManagerFilesStorageOperationsListResponse = [
|
|
|
296
300
|
File[],
|
|
297
301
|
FileManagerFilesStorageOperationsListResponseMeta
|
|
298
302
|
];
|
|
299
|
-
export
|
|
300
|
-
string
|
|
301
|
-
|
|
302
|
-
|
|
303
|
+
export interface FileManagerFilesStorageOperationsTagsResponse {
|
|
304
|
+
tag: string;
|
|
305
|
+
count: number;
|
|
306
|
+
}
|
|
303
307
|
export interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {
|
|
304
308
|
locale: string;
|
|
305
309
|
tenant: string;
|
|
@@ -346,7 +350,7 @@ export interface FileManagerFilesStorageOperations {
|
|
|
346
350
|
/**
|
|
347
351
|
* Get a list of all file tags filtered by given parameters.
|
|
348
352
|
*/
|
|
349
|
-
tags: (params: FileManagerFilesStorageOperationsTagsParams) => Promise<FileManagerFilesStorageOperationsTagsResponse>;
|
|
353
|
+
tags: (params: FileManagerFilesStorageOperationsTagsParams) => Promise<FileManagerFilesStorageOperationsTagsResponse[]>;
|
|
350
354
|
}
|
|
351
355
|
export interface FileManagerStorageOperations<TContext = FileManagerContext> {
|
|
352
356
|
beforeInit?: (context: TContext) => Promise<void>;
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { FileLifecycleEvents } from \"./types/file.lifecycle\";\nimport { File } from \"./types/file\";\nimport { Topic } from \"@webiny/pubsub/types\";\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: FileManagerContextObject;\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface FileInput {\n id: string;\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n aliases: string[];\n}\n\nexport interface FileListWhereParams {\n search?: string;\n type?: string;\n type_in?: string[];\n tag?: string;\n tag_in?: string[];\n tag_and_in?: string[];\n id_in?: string[];\n id?: string;\n}\nexport interface FilesListOpts {\n search?: string;\n types?: string[];\n tags?: string[];\n ids?: string[];\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface FilesCRUD extends FileLifecycleEvents {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<string[]>;\n createFile(data: FileInput): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[]): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n onSystemBeforeInstall: Topic;\n onSystemAfterInstall: Topic;\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n tenant: string;\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\nexport interface FileManagerSystemStorageOperationsGetParams {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\nexport interface FileManagerStorageOperationsGetSettingsParams {\n tenant: string;\n}\n\nexport interface FileManagerStorageOperationsDeleteSettings {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (\n params: FileManagerStorageOperationsGetSettingsParams\n ) => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n id?: string;\n id_in?: string[];\n name?: string;\n name_contains?: string;\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n createdBy?: string;\n locale: string;\n tenant: string;\n private?: boolean;\n type?: string;\n type_in?: string[];\n search?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport type FileManagerFilesStorageOperationsTagsResponse = [\n string[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse>;\n}\n\nexport interface FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AAQA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { FileLifecycleEvents } from \"./types/file.lifecycle\";\nimport { File } from \"./types/file\";\nimport { Topic } from \"@webiny/pubsub/types\";\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: FileManagerContextObject;\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface FileInput {\n id: string;\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n aliases: string[];\n}\n\nexport interface FileListWhereParams {\n search?: string;\n type?: string;\n type_in?: string[];\n tag?: string;\n tag_in?: string[];\n tag_and_in?: string[];\n id_in?: string[];\n id?: string;\n}\nexport interface FilesListOpts {\n search?: string;\n types?: string[];\n tags?: string[];\n ids?: string[];\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface ListTagsResponse {\n tag: string;\n count: number;\n}\nexport interface FilesCRUD extends FileLifecycleEvents {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<ListTagsResponse[]>;\n createFile(data: FileInput, meta?: Record<string, any>): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[], meta?: Record<string, any>): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n onSystemBeforeInstall: Topic;\n onSystemAfterInstall: Topic;\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n tenant: string;\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\nexport interface FileManagerSystemStorageOperationsGetParams {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\nexport interface FileManagerStorageOperationsGetSettingsParams {\n tenant: string;\n}\n\nexport interface FileManagerStorageOperationsDeleteSettings {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (\n params: FileManagerStorageOperationsGetSettingsParams\n ) => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n id?: string;\n id_in?: string[];\n name?: string;\n name_contains?: string;\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n createdBy?: string;\n locale: string;\n tenant: string;\n private?: boolean;\n type?: string;\n type_in?: string[];\n search?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsResponse {\n tag: string;\n count: number;\n}\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse[]>;\n}\n\nexport interface FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AAQA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _FilePlugin = require("../../definitions/FilePlugin");
|
|
11
|
-
|
|
12
|
-
var _createFileModel = _interopRequireDefault(require("../utils/createFileModel"));
|
|
13
|
-
|
|
14
|
-
var _default = () => [new _FilePlugin.FilePlugin({
|
|
15
|
-
beforeCreate: async ({
|
|
16
|
-
data
|
|
17
|
-
}) => {
|
|
18
|
-
const FileModel = (0, _createFileModel.default)();
|
|
19
|
-
const fileData = new FileModel().populate(data);
|
|
20
|
-
await fileData.validate();
|
|
21
|
-
},
|
|
22
|
-
beforeUpdate: async ({
|
|
23
|
-
data
|
|
24
|
-
}) => {
|
|
25
|
-
const FileModel = (0, _createFileModel.default)(false);
|
|
26
|
-
const updatedFileData = new FileModel().populate(data);
|
|
27
|
-
await updatedFileData.validate();
|
|
28
|
-
},
|
|
29
|
-
beforeBatchCreate: async ({
|
|
30
|
-
data
|
|
31
|
-
}) => {
|
|
32
|
-
const FileModel = (0, _createFileModel.default)();
|
|
33
|
-
|
|
34
|
-
for (const input of data) {
|
|
35
|
-
const fileInstance = new FileModel().populate(input);
|
|
36
|
-
await fileInstance.validate();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
})];
|
|
40
|
-
|
|
41
|
-
exports.default = _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["FilePlugin","beforeCreate","data","FileModel","createFileModel","fileData","populate","validate","beforeUpdate","updatedFileData","beforeBatchCreate","input","fileInstance"],"sources":["validation.ts"],"sourcesContent":["import { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport createFileModel from \"~/plugins/crud/utils/createFileModel\";\n\nexport default (): FilePlugin[] => [\n new FilePlugin({\n beforeCreate: async ({ data }) => {\n const FileModel = createFileModel();\n const fileData = new FileModel().populate(data);\n await fileData.validate();\n },\n beforeUpdate: async ({ data }) => {\n const FileModel = createFileModel(false);\n const updatedFileData = new FileModel().populate(data);\n await updatedFileData.validate();\n },\n beforeBatchCreate: async ({ data }) => {\n const FileModel = createFileModel();\n for (const input of data) {\n const fileInstance = new FileModel().populate(input);\n await fileInstance.validate();\n }\n }\n })\n];\n"],"mappings":";;;;;;;;;AAAA;;AACA;;eAEe,MAAoB,CAC/B,IAAIA,sBAAJ,CAAe;EACXC,YAAY,EAAE,OAAO;IAAEC;EAAF,CAAP,KAAoB;IAC9B,MAAMC,SAAS,GAAG,IAAAC,wBAAA,GAAlB;IACA,MAAMC,QAAQ,GAAG,IAAIF,SAAJ,GAAgBG,QAAhB,CAAyBJ,IAAzB,CAAjB;IACA,MAAMG,QAAQ,CAACE,QAAT,EAAN;EACH,CALU;EAMXC,YAAY,EAAE,OAAO;IAAEN;EAAF,CAAP,KAAoB;IAC9B,MAAMC,SAAS,GAAG,IAAAC,wBAAA,EAAgB,KAAhB,CAAlB;IACA,MAAMK,eAAe,GAAG,IAAIN,SAAJ,GAAgBG,QAAhB,CAAyBJ,IAAzB,CAAxB;IACA,MAAMO,eAAe,CAACF,QAAhB,EAAN;EACH,CAVU;EAWXG,iBAAiB,EAAE,OAAO;IAAER;EAAF,CAAP,KAAoB;IACnC,MAAMC,SAAS,GAAG,IAAAC,wBAAA,GAAlB;;IACA,KAAK,MAAMO,KAAX,IAAoBT,IAApB,EAA0B;MACtB,MAAMU,YAAY,GAAG,IAAIT,SAAJ,GAAgBG,QAAhB,CAAyBK,KAAzB,CAArB;MACA,MAAMC,YAAY,CAACL,QAAb,EAAN;IACH;EACJ;AAjBU,CAAf,CAD+B,C"}
|