@webiny/api-file-manager 5.41.0-dbt.0 → 5.41.1-beta.0

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 +1 @@
1
- {"version":3,"names":["_handlerGraphql","require","_pubsub","_error","_interopRequireDefault","_contants","_apiSecurity","_date","_identity","createFilesCrud","config","storageOperations","filesPermissions","getLocaleCode","getTenantId","getIdentity","WEBINY_VERSION","onFileBeforeCreate","createTopic","onFileAfterCreate","onFileBeforeBatchCreate","onFileAfterBatchCreate","onFileBeforeUpdate","onFileAfterUpdate","onFileBeforeDelete","onFileAfterDelete","getFile","id","ensure","rwd","file","files","get","where","tenant","locale","NotFoundError","owns","createdBy","createFile","input","meta","key","split","currentDateTime","Date","currentIdentity","tags","Array","isArray","aliases","location","folderId","ROOT_FOLDER","private","createdOn","getDate","modifiedOn","savedOn","utilsGetIdentity","modifiedBy","savedBy","webinyVersion","publish","result","create","ex","NotAuthorizedError","WebinyError","message","code","data","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","map","results","createBatch","listFiles","params","limit","after","initialWhere","sort","initialSort","search","private_not","canAccessOnlyOwnRecords","identity","length","list","listTags","exports"],"sources":["files.crud.ts"],"sourcesContent":["import { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport WebinyError from \"@webiny/error\";\nimport {\n File,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilesCRUD,\n FilesListOpts\n} from \"~/types\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\nimport { ROOT_FOLDER } from \"~/contants\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getDate } from \"@webiny/api-headless-cms/utils/date\";\nimport { getIdentity as utilsGetIdentity } from \"@webiny/api-headless-cms/utils/identity\";\n\nexport const createFilesCrud = (config: FileManagerConfig): FilesCRUD => {\n const {\n storageOperations,\n filesPermissions,\n getLocaleCode,\n getTenantId,\n getIdentity,\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 await filesPermissions.ensure({ 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 await filesPermissions.ensure({ owns: file.createdBy });\n\n return file;\n },\n async createFile(input, meta) {\n await filesPermissions.ensure({ rwd: \"w\" });\n\n // Extract ID from file key\n const [id] = input.key.split(\"/\");\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\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 location: {\n folderId: input.location?.folderId ?? ROOT_FOLDER\n },\n meta: {\n private: false,\n ...(input.meta || {})\n },\n\n createdOn: getDate(input.createdOn, currentDateTime),\n modifiedOn: getDate(input.modifiedOn, null),\n savedOn: getDate(input.savedOn, currentDateTime),\n createdBy: utilsGetIdentity(input.createdBy, currentIdentity),\n modifiedBy: utilsGetIdentity(input.modifiedBy, null),\n savedBy: utilsGetIdentity(input.savedBy, currentIdentity),\n\n tenant: getTenantId(),\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 // If a `NotAuthorizedError` error was thrown, then we just want to rethrow it.\n if (ex instanceof NotAuthorizedError) {\n throw ex;\n }\n\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 await filesPermissions.ensure({ 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 await filesPermissions.ensure({ owns: original.createdBy });\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\n\n const file: File = {\n ...original,\n ...input,\n\n createdOn: getDate(input.createdOn, original.createdOn),\n modifiedOn: getDate(input.modifiedOn, currentDateTime),\n savedOn: getDate(input.savedOn, currentDateTime),\n createdBy: utilsGetIdentity(input.createdBy, original.createdBy),\n modifiedBy: utilsGetIdentity(input.modifiedBy, currentIdentity),\n savedBy: utilsGetIdentity(input.savedBy, currentIdentity),\n\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 await filesPermissions.ensure({ 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 await filesPermissions.ensure({ owns: file.createdBy });\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 filesPermissions.ensure({ rwd: \"w\" });\n\n const tenant = getTenantId();\n const locale = getLocaleCode();\n\n const currentIdentity = getIdentity();\n const currentDateTime = new Date();\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 location: {\n folderId: input.location?.folderId ?? ROOT_FOLDER\n },\n\n createdOn: getDate(currentDateTime),\n modifiedOn: null,\n savedOn: getDate(currentDateTime),\n createdBy: utilsGetIdentity(currentIdentity),\n modifiedBy: null,\n savedBy: utilsGetIdentity(currentIdentity),\n\n tenant,\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 await filesPermissions.ensure({ rwd: \"r\" });\n\n const {\n limit = 40,\n after = null,\n where: initialWhere,\n sort: initialSort,\n search\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...{ meta: { private_not: true }, ...initialWhere },\n locale: getLocaleCode(),\n tenant: getTenantId()\n };\n\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (await filesPermissions.canAccessOnlyOwnRecords()) {\n const identity = getIdentity();\n where.createdBy = identity.id;\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 search\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 filesPermissions.ensure();\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,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AASA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AAEO,MAAMQ,eAAe,GAAIC,MAAyB,IAAgB;EACrE,MAAM;IACFC,iBAAiB;IACjBC,gBAAgB;IAChBC,aAAa;IACbC,WAAW;IACXC,WAAW;IACXC;EACJ,CAAC,GAAGN,MAAM;EAEV,OAAO;IACHO,kBAAkB,EAAE,IAAAC,mBAAW,EAAC,gCAAgC,CAAC;IACjEC,iBAAiB,EAAE,IAAAD,mBAAW,EAAC,+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AAE,CAACI,IAAI,IAAI,uBAAuB,EAClC;UACI,IAAIJ,EAAE,CAACK,IAAI,IAAI,CAAC,CAAC,CAAC;UAClBY;QACJ,CACJ,CAAC;MACL;IACJ;EACJ,CAAC;AACL,CAAC;AAACa,OAAA,CAAAvF,eAAA,GAAAA,eAAA","ignoreList":[]}
1
+ {"version":3,"names":["_handlerGraphql","require","_pubsub","_error","_interopRequireDefault","_contants","_apiSecurity","_date","_identity","createFilesCrud","config","storageOperations","filesPermissions","getLocaleCode","getTenantId","getIdentity","WEBINY_VERSION","onFileBeforeCreate","createTopic","onFileAfterCreate","onFileBeforeBatchCreate","onFileAfterBatchCreate","onFileBeforeUpdate","onFileAfterUpdate","onFileBeforeDelete","onFileAfterDelete","getFile","id","ensure","rwd","file","files","get","where","tenant","locale","NotFoundError","owns","createdBy","createFile","input","meta","key","split","currentDateTime","Date","currentIdentity","tags","Array","isArray","aliases","location","folderId","ROOT_FOLDER","private","createdOn","getDate","modifiedOn","savedOn","utilsGetIdentity","modifiedBy","savedBy","webinyVersion","publish","result","create","ex","NotAuthorizedError","WebinyError","message","code","data","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","map","results","createBatch","listFiles","params","limit","after","initialWhere","sort","initialSort","search","private_not","canAccessOnlyOwnRecords","identity","length","list","listTags","exports"],"sources":["files.crud.ts"],"sourcesContent":["import { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport WebinyError from \"@webiny/error\";\nimport {\n File,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilesCRUD,\n FilesListOpts\n} from \"~/types\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\nimport { ROOT_FOLDER } from \"~/contants\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getDate } from \"@webiny/api-headless-cms/utils/date\";\nimport { getIdentity as utilsGetIdentity } from \"@webiny/api-headless-cms/utils/identity\";\nimport { CmsEntryListSort } from \"@webiny/api-headless-cms/types\";\n\nexport const createFilesCrud = (config: FileManagerConfig): FilesCRUD => {\n const {\n storageOperations,\n filesPermissions,\n getLocaleCode,\n getTenantId,\n getIdentity,\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 await filesPermissions.ensure({ 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 await filesPermissions.ensure({ owns: file.createdBy });\n\n return file;\n },\n async createFile(input, meta) {\n await filesPermissions.ensure({ rwd: \"w\" });\n\n // Extract ID from file key\n const [id] = input.key.split(\"/\");\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\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 location: {\n folderId: input.location?.folderId ?? ROOT_FOLDER\n },\n meta: {\n private: false,\n ...(input.meta || {})\n },\n\n createdOn: getDate(input.createdOn, currentDateTime),\n modifiedOn: getDate(input.modifiedOn, null),\n savedOn: getDate(input.savedOn, currentDateTime),\n createdBy: utilsGetIdentity(input.createdBy, currentIdentity),\n modifiedBy: utilsGetIdentity(input.modifiedBy, null),\n savedBy: utilsGetIdentity(input.savedBy, currentIdentity),\n\n tenant: getTenantId(),\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 // If a `NotAuthorizedError` error was thrown, then we just want to rethrow it.\n if (ex instanceof NotAuthorizedError) {\n throw ex;\n }\n\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 await filesPermissions.ensure({ 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 await filesPermissions.ensure({ owns: original.createdBy });\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\n\n const file: File = {\n ...original,\n ...input,\n\n createdOn: getDate(input.createdOn, original.createdOn),\n modifiedOn: getDate(input.modifiedOn, currentDateTime),\n savedOn: getDate(input.savedOn, currentDateTime),\n createdBy: utilsGetIdentity(input.createdBy, original.createdBy),\n modifiedBy: utilsGetIdentity(input.modifiedBy, currentIdentity),\n savedBy: utilsGetIdentity(input.savedBy, currentIdentity),\n\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 await filesPermissions.ensure({ 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 await filesPermissions.ensure({ owns: file.createdBy });\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 filesPermissions.ensure({ rwd: \"w\" });\n\n const tenant = getTenantId();\n const locale = getLocaleCode();\n\n const currentIdentity = getIdentity();\n const currentDateTime = new Date();\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 location: {\n folderId: input.location?.folderId ?? ROOT_FOLDER\n },\n\n createdOn: getDate(currentDateTime),\n modifiedOn: null,\n savedOn: getDate(currentDateTime),\n createdBy: utilsGetIdentity(currentIdentity),\n modifiedBy: null,\n savedBy: utilsGetIdentity(currentIdentity),\n\n tenant,\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 await filesPermissions.ensure({ rwd: \"r\" });\n\n const {\n limit = 40,\n after = null,\n where: initialWhere,\n sort: initialSort,\n search\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...{ meta: { private_not: true }, ...initialWhere },\n locale: getLocaleCode(),\n tenant: getTenantId()\n };\n\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (await filesPermissions.canAccessOnlyOwnRecords()) {\n const identity = getIdentity();\n where.createdBy = identity.id;\n }\n\n const sort: CmsEntryListSort =\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 search\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 filesPermissions.ensure();\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,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AASA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AAGO,MAAMQ,eAAe,GAAIC,MAAyB,IAAgB;EACrE,MAAM;IACFC,iBAAiB;IACjBC,gBAAgB;IAChBC,aAAa;IACbC,WAAW;IACXC,WAAW;IACXC;EACJ,CAAC,GAAGN,M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CAAC;MACrD,CAAC,CAAC,OAAOjB,EAAE,EAAE;QACT,MAAM,IAAIE,cAAW,CACjBF,EAAE,CAACG,OAAO,IAAI,4BAA4B,EAC1CH,EAAE,CAACI,IAAI,IAAI,uBAAuB,EAClC;UACI,IAAIJ,EAAE,CAACK,IAAI,IAAI,CAAC,CAAC,CAAC;UAClBY;QACJ,CACJ,CAAC;MACL;IACJ;EACJ,CAAC;AACL,CAAC;AAACa,OAAA,CAAAvF,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { AssetContentsReader, AssetOutputStrategy } from "..";
3
4
  type Setter<T> = (arg: T | undefined) => T;
4
5
  export interface AssetData {
@@ -15,11 +16,12 @@ export declare class Asset {
15
16
  private contentsReader;
16
17
  constructor(props: AssetData);
17
18
  clone(): Asset;
19
+ withProps(props: Partial<AssetData>): Asset;
18
20
  getId(): string;
19
21
  getTenant(): string;
20
22
  getLocale(): string;
21
23
  getKey(): string;
22
- getSize(): Promise<number>;
24
+ getSize(): number;
23
25
  getContentType(): string;
24
26
  getExtension(): string;
25
27
  getContents(): Promise<Buffer>;
@@ -9,10 +9,16 @@ class Asset {
9
9
  this.props = props;
10
10
  }
11
11
  clone() {
12
- const clonedAsset = new Asset(structuredClone(this.props));
13
- clonedAsset.outputStrategy = this.outputStrategy;
14
- clonedAsset.contentsReader = this.contentsReader;
15
- return clonedAsset;
12
+ return this.withProps(structuredClone(this.props));
13
+ }
14
+ withProps(props) {
15
+ const newAsset = new Asset({
16
+ ...this.props,
17
+ ...props
18
+ });
19
+ newAsset.contentsReader = this.contentsReader;
20
+ newAsset.outputStrategy = this.outputStrategy;
21
+ return newAsset;
16
22
  }
17
23
  getId() {
18
24
  return this.props.id;
@@ -26,9 +32,8 @@ class Asset {
26
32
  getKey() {
27
33
  return this.props.key;
28
34
  }
29
- async getSize() {
30
- const buffer = await this.getContents();
31
- return buffer.length;
35
+ getSize() {
36
+ return this.props.size;
32
37
  }
33
38
  getContentType() {
34
39
  return this.props.contentType;
@@ -1 +1 @@
1
- {"version":3,"names":["Asset","constructor","props","clone","clonedAsset","structuredClone","outputStrategy","contentsReader","getId","id","getTenant","tenant","getLocale","locale","getKey","key","getSize","buffer","getContents","length","getContentType","contentType","getExtension","split","pop","Error","read","setContentsReader","reader","output","setOutputStrategy","setter","exports"],"sources":["Asset.ts"],"sourcesContent":["import { AssetContentsReader, AssetOutputStrategy } from \"~/delivery\";\n\ntype Setter<T> = (arg: T | undefined) => T;\n\nexport interface AssetData {\n id: string;\n tenant: string;\n locale: string;\n key: string;\n size: number;\n contentType: string;\n}\n\nexport class Asset {\n protected readonly props: AssetData;\n private outputStrategy: AssetOutputStrategy | undefined;\n private contentsReader: AssetContentsReader | undefined;\n\n constructor(props: AssetData) {\n this.props = props;\n }\n\n clone() {\n const clonedAsset = new Asset(structuredClone(this.props));\n clonedAsset.outputStrategy = this.outputStrategy;\n clonedAsset.contentsReader = this.contentsReader;\n return clonedAsset;\n }\n\n getId() {\n return this.props.id;\n }\n getTenant() {\n return this.props.tenant;\n }\n getLocale() {\n return this.props.locale;\n }\n getKey() {\n return this.props.key;\n }\n async getSize() {\n const buffer = await this.getContents();\n return buffer.length;\n }\n getContentType() {\n return this.props.contentType;\n }\n getExtension() {\n return this.getKey().split(\".\").pop() ?? \"\";\n }\n\n getContents() {\n if (!this.contentsReader) {\n throw Error(`Asset contents reader was not configured!`);\n }\n return this.contentsReader.read(this);\n }\n\n setContentsReader(reader: AssetContentsReader) {\n this.contentsReader = reader;\n }\n\n output() {\n if (!this.outputStrategy) {\n throw Error(`Asset output strategy was not configured!`);\n }\n\n return this.outputStrategy.output(this);\n }\n\n setOutputStrategy(setter: Setter<AssetOutputStrategy> | AssetOutputStrategy) {\n if (typeof setter === \"function\") {\n this.outputStrategy = setter(this.outputStrategy);\n } else {\n this.outputStrategy = setter;\n }\n }\n}\n"],"mappings":";;;;;;AAaO,MAAMA,KAAK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C,MAAMA,CAAA,EAAG;IACL,IAAI,CAAC,IAAI,CAACvB,cAAc,EAAE;MACtB,MAAMmB,KAAK,CAAE,2CAA0C,CAAC;IAC5D;IAEA,OAAO,IAAI,CAACnB,cAAc,CAACuB,MAAM,CAAC,IAAI,CAAC;EAC3C;EAEAC,iBAAiBA,CAACC,MAAyD,EAAE;IACzE,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;MAC9B,IAAI,CAACzB,cAAc,GAAGyB,MAAM,CAAC,IAAI,CAACzB,cAAc,CAAC;IACrD,CAAC,MAAM;MACH,IAAI,CAACA,cAAc,GAAGyB,MAAM;IAChC;EACJ;AACJ;AAACC,OAAA,CAAAhC,KAAA,GAAAA,KAAA","ignoreList":[]}
1
+ {"version":3,"names":["Asset","constructor","props","clone","withProps","structuredClone","newAsset","contentsReader","outputStrategy","getId","id","getTenant","tenant","getLocale","locale","getKey","key","getSize","size","getContentType","contentType","getExtension","split","pop","getContents","Error","read","setContentsReader","reader","output","setOutputStrategy","setter","exports"],"sources":["Asset.ts"],"sourcesContent":["import { AssetContentsReader, AssetOutputStrategy } from \"~/delivery\";\n\ntype Setter<T> = (arg: T | undefined) => T;\n\nexport interface AssetData {\n id: string;\n tenant: string;\n locale: string;\n key: string;\n size: number;\n contentType: string;\n}\n\nexport class Asset {\n protected readonly props: AssetData;\n private outputStrategy: AssetOutputStrategy | undefined;\n private contentsReader: AssetContentsReader | undefined;\n\n constructor(props: AssetData) {\n this.props = props;\n }\n\n clone() {\n return this.withProps(structuredClone(this.props));\n }\n\n withProps(props: Partial<AssetData>) {\n const newAsset = new Asset({ ...this.props, ...props });\n newAsset.contentsReader = this.contentsReader;\n newAsset.outputStrategy = this.outputStrategy;\n return newAsset;\n }\n\n getId() {\n return this.props.id;\n }\n getTenant() {\n return this.props.tenant;\n }\n getLocale() {\n return this.props.locale;\n }\n getKey() {\n return this.props.key;\n }\n getSize() {\n return this.props.size;\n }\n getContentType() {\n return this.props.contentType;\n }\n getExtension() {\n return this.getKey().split(\".\").pop() ?? \"\";\n }\n\n getContents() {\n if (!this.contentsReader) {\n throw Error(`Asset contents reader was not configured!`);\n }\n return this.contentsReader.read(this);\n }\n\n setContentsReader(reader: AssetContentsReader) {\n this.contentsReader = reader;\n }\n\n output() {\n if (!this.outputStrategy) {\n throw Error(`Asset output strategy was not configured!`);\n }\n\n return this.outputStrategy.output(this);\n }\n\n setOutputStrategy(setter: Setter<AssetOutputStrategy> | AssetOutputStrategy) {\n if (typeof setter === \"function\") {\n this.outputStrategy = setter(this.outputStrategy);\n } else {\n this.outputStrategy = setter;\n }\n }\n}\n"],"mappings":";;;;;;AAaO,MAAMA,KAAK,CAAC;EAKfC,WAAWA,CAACC,KAAgB,EAAE;IAC1B,IAAI,CAACA,KAAK,GAAGA,KAAK;EACtB;EAEAC,KAAKA,CAAA,EAAG;IACJ,OAAO,IAAI,CAACC,SAAS,CAACC,eAAe,CAAC,IAAI,CAACH,KAAK,CAAC,CAAC;EACtD;EAEAE,SAASA,CAACF,KAAyB,EAAE;IACjC,MAAMI,QAAQ,GAAG,IAAIN,KAAK,CAAC;MAAE,GAAG,IAAI,CAACE,KAAK;MAAE,GAAGA;IAAM,CAAC,CAAC;IACvDI,QAAQ,CAACC,cAAc,GAAG,IAAI,CAACA,cAAc;IAC7CD,QAAQ,CAACE,cAAc,GAAG,IAAI,CAACA,cAAc;IAC7C,OAAOF,QAAQ;EACnB;EAEAG,KAAKA,CAAA,EAAG;IACJ,OAAO,IAAI,CAACP,KAAK,CAACQ,EAAE;EACxB;EACAC,SAASA,CAAA,EAAG;IACR,OAAO,IAAI,CAACT,KAAK,CAACU,MAAM;EAC5B;EACAC,SAASA,CAAA,EAAG;IACR,OAAO,IAAI,CAACX,KAAK,CAACY,MAAM;EAC5B;EACAC,MAAMA,CAAA,EAAG;IACL,OAAO,IAAI,CAACb,KAAK,CAACc,GAAG;EACzB;EACAC,OAAOA,CAAA,EAAG;IACN,OAAO,IAAI,CAACf,KAAK,CAACgB,IAAI;EAC1B;EACAC,cAAcA,CAAA,EAAG;IACb,OAAO,IAAI,CAACjB,KAAK,CAACkB,WAAW;EACjC;EACAC,YAAYA,CAAA,EAAG;IACX,OAAO,IAAI,CAACN,MAAM,CAAC,CAAC,CAACO,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,IAAI,EAAE;EAC/C;EAEAC,WAAWA,CAAA,EAAG;IACV,IAAI,CAAC,IAAI,CAACjB,cAAc,EAAE;MACtB,MAAMkB,KAAK,CAAE,2CAA0C,CAAC;IAC5D;IACA,OAAO,IAAI,CAAClB,cAAc,CAACmB,IAAI,CAAC,IAAI,CAAC;EACzC;EAEAC,iBAAiBA,CAACC,MAA2B,EAAE;IAC3C,IAAI,CAACrB,cAAc,GAAGqB,MAAM;EAChC;EAEAC,MAAMA,CAAA,EAAG;IACL,IAAI,CAAC,IAAI,CAACrB,cAAc,EAAE;MACtB,MAAMiB,KAAK,CAAE,2CAA0C,CAAC;IAC5D;IAEA,OAAO,IAAI,CAACjB,cAAc,CAACqB,MAAM,CAAC,IAAI,CAAC;EAC3C;EAEAC,iBAAiBA,CAACC,MAAyD,EAAE;IACzE,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;MAC9B,IAAI,CAACvB,cAAc,GAAGuB,MAAM,CAAC,IAAI,CAACvB,cAAc,CAAC;IACrD,CAAC,MAAM;MACH,IAAI,CAACA,cAAc,GAAGuB,MAAM;IAChC;EACJ;AACJ;AAACC,OAAA,CAAAhC,KAAA,GAAAA,KAAA","ignoreList":[]}
@@ -16,15 +16,19 @@ class FilesAssetRequestResolver {
16
16
 
17
17
  // Example: { '*': '/files/65722cb5c7824a0008d05963/image-48.jpg' },
18
18
  const path = params["*"];
19
+ const options = {
20
+ ...query,
21
+ original: "original" in query
22
+ };
23
+ if (query.width) {
24
+ options.width = parseInt(query.width);
25
+ }
19
26
  return new _AssetRequest.AssetRequest({
20
27
  key: decodeURI(path).replace("/files/", ""),
21
28
  context: {
22
29
  url: request.url
23
30
  },
24
- options: {
25
- ...query,
26
- width: query.width ? parseInt(query.width) : undefined
27
- }
31
+ options
28
32
  });
29
33
  }
30
34
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_AssetRequest","require","FilesAssetRequestResolver","resolve","request","url","startsWith","undefined","params","query","path","AssetRequest","key","decodeURI","replace","context","options","width","parseInt","exports"],"sources":["FilesAssetRequestResolver.ts"],"sourcesContent":["import { Request } from \"@webiny/handler/types\";\nimport { AssetRequestResolver } from \"./abstractions/AssetRequestResolver\";\nimport { AssetRequest } from \"./AssetRequest\";\n\nexport class FilesAssetRequestResolver implements AssetRequestResolver {\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n // Example: /files/65722cb5c7824a0008d05963/image-48.jpg?width=300\n if (!request.url.startsWith(\"/files/\")) {\n return undefined;\n }\n\n const params = (request.params as Record<string, any>) ?? {};\n const query = (request.query as Record<string, any>) ?? {};\n\n // Example: { '*': '/files/65722cb5c7824a0008d05963/image-48.jpg' },\n const path = params[\"*\"];\n\n return new AssetRequest({\n key: decodeURI(path).replace(\"/files/\", \"\"),\n context: {\n url: request.url\n },\n options: {\n ...query,\n width: query.width ? parseInt(query.width) : undefined\n }\n });\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAEO,MAAMC,yBAAyB,CAAiC;EACnE,MAAMC,OAAOA,CAACC,OAAgB,EAAqC;IAC/D;IACA,IAAI,CAACA,OAAO,CAACC,GAAG,CAACC,UAAU,CAAC,SAAS,CAAC,EAAE;MACpC,OAAOC,SAAS;IACpB;IAEA,MAAMC,MAAM,GAAIJ,OAAO,CAACI,MAAM,IAA4B,CAAC,CAAC;IAC5D,MAAMC,KAAK,GAAIL,OAAO,CAACK,KAAK,IAA4B,CAAC,CAAC;;IAE1D;IACA,MAAMC,IAAI,GAAGF,MAAM,CAAC,GAAG,CAAC;IAExB,OAAO,IAAIG,0BAAY,CAAC;MACpBC,GAAG,EAAEC,SAAS,CAACH,IAAI,CAAC,CAACI,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;MAC3CC,OAAO,EAAE;QACLV,GAAG,EAAED,OAAO,CAACC;MACjB,CAAC;MACDW,OAAO,EAAE;QACL,GAAGP,KAAK;QACRQ,KAAK,EAAER,KAAK,CAACQ,KAAK,GAAGC,QAAQ,CAACT,KAAK,CAACQ,KAAK,CAAC,GAAGV;MACjD;IACJ,CAAC,CAAC;EACN;AACJ;AAACY,OAAA,CAAAjB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_AssetRequest","require","FilesAssetRequestResolver","resolve","request","url","startsWith","undefined","params","query","path","options","original","width","parseInt","AssetRequest","key","decodeURI","replace","context","exports"],"sources":["FilesAssetRequestResolver.ts"],"sourcesContent":["import { Request } from \"@webiny/handler/types\";\nimport { AssetRequestResolver } from \"./abstractions/AssetRequestResolver\";\nimport { AssetRequest, AssetRequestOptions } from \"./AssetRequest\";\n\nexport class FilesAssetRequestResolver implements AssetRequestResolver {\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n // Example: /files/65722cb5c7824a0008d05963/image-48.jpg?width=300\n if (!request.url.startsWith(\"/files/\")) {\n return undefined;\n }\n\n const params = (request.params as Record<string, any>) ?? {};\n const query = (request.query as Record<string, any>) ?? {};\n\n // Example: { '*': '/files/65722cb5c7824a0008d05963/image-48.jpg' },\n const path = params[\"*\"];\n\n const options: AssetRequestOptions = {\n ...query,\n original: \"original\" in query\n };\n\n if (query.width) {\n options.width = parseInt(query.width);\n }\n\n return new AssetRequest({\n key: decodeURI(path).replace(\"/files/\", \"\"),\n context: {\n url: request.url\n },\n options\n });\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAEO,MAAMC,yBAAyB,CAAiC;EACnE,MAAMC,OAAOA,CAACC,OAAgB,EAAqC;IAC/D;IACA,IAAI,CAACA,OAAO,CAACC,GAAG,CAACC,UAAU,CAAC,SAAS,CAAC,EAAE;MACpC,OAAOC,SAAS;IACpB;IAEA,MAAMC,MAAM,GAAIJ,OAAO,CAACI,MAAM,IAA4B,CAAC,CAAC;IAC5D,MAAMC,KAAK,GAAIL,OAAO,CAACK,KAAK,IAA4B,CAAC,CAAC;;IAE1D;IACA,MAAMC,IAAI,GAAGF,MAAM,CAAC,GAAG,CAAC;IAExB,MAAMG,OAA4B,GAAG;MACjC,GAAGF,KAAK;MACRG,QAAQ,EAAE,UAAU,IAAIH;IAC5B,CAAC;IAED,IAAIA,KAAK,CAACI,KAAK,EAAE;MACbF,OAAO,CAACE,KAAK,GAAGC,QAAQ,CAACL,KAAK,CAACI,KAAK,CAAC;IACzC;IAEA,OAAO,IAAIE,0BAAY,CAAC;MACpBC,GAAG,EAAEC,SAAS,CAACP,IAAI,CAAC,CAACQ,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;MAC3CC,OAAO,EAAE;QACLd,GAAG,EAAED,OAAO,CAACC;MACjB,CAAC;MACDM;IACJ,CAAC,CAAC;EACN;AACJ;AAACS,OAAA,CAAAlB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Asset } from "../..";
3
4
  export interface AssetContentsReader {
4
5
  read(asset: Asset): Promise<Buffer>;
@@ -15,6 +15,7 @@ class TransformationAssetProcessor {
15
15
 
16
16
  // If the `original` image was requested, we skip all transformations.
17
17
  if (original) {
18
+ console.log("Skip transformations; original asset was requested.");
18
19
  return asset;
19
20
  }
20
21
  return this.strategy.transform(assetRequest, asset);
@@ -1 +1 @@
1
- {"version":3,"names":["TransformationAssetProcessor","constructor","strategy","process","assetRequest","asset","original","getOptions","transform","exports"],"sources":["TransformationAssetProcessor.ts"],"sourcesContent":["import { Asset, AssetProcessor, AssetRequest, AssetTransformationStrategy } from \"~/delivery\";\n\nexport class TransformationAssetProcessor implements AssetProcessor {\n private strategy: AssetTransformationStrategy;\n\n constructor(strategy: AssetTransformationStrategy) {\n this.strategy = strategy;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const { original } = assetRequest.getOptions();\n\n // If the `original` image was requested, we skip all transformations.\n if (original) {\n return asset;\n }\n\n return this.strategy.transform(assetRequest, asset);\n }\n}\n"],"mappings":";;;;;;AAEO,MAAMA,4BAA4B,CAA2B;EAGhEC,WAAWA,CAACC,QAAqC,EAAE;IAC/C,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,YAA0B,EAAEC,KAAY,EAAkB;IACpE,MAAM;MAAEC;IAAS,CAAC,GAAGF,YAAY,CAACG,UAAU,CAAC,CAAC;;IAE9C;IACA,IAAID,QAAQ,EAAE;MACV,OAAOD,KAAK;IAChB;IAEA,OAAO,IAAI,CAACH,QAAQ,CAACM,SAAS,CAACJ,YAAY,EAAEC,KAAK,CAAC;EACvD;AACJ;AAACI,OAAA,CAAAT,4BAAA,GAAAA,4BAAA","ignoreList":[]}
1
+ {"version":3,"names":["TransformationAssetProcessor","constructor","strategy","process","assetRequest","asset","original","getOptions","console","log","transform","exports"],"sources":["TransformationAssetProcessor.ts"],"sourcesContent":["import { Asset, AssetProcessor, AssetRequest, AssetTransformationStrategy } from \"~/delivery\";\n\nexport class TransformationAssetProcessor implements AssetProcessor {\n private strategy: AssetTransformationStrategy;\n\n constructor(strategy: AssetTransformationStrategy) {\n this.strategy = strategy;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const { original } = assetRequest.getOptions();\n\n // If the `original` image was requested, we skip all transformations.\n if (original) {\n console.log(\"Skip transformations; original asset was requested.\");\n return asset;\n }\n\n return this.strategy.transform(assetRequest, asset);\n }\n}\n"],"mappings":";;;;;;AAEO,MAAMA,4BAA4B,CAA2B;EAGhEC,WAAWA,CAACC,QAAqC,EAAE;IAC/C,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,YAA0B,EAAEC,KAAY,EAAkB;IACpE,MAAM;MAAEC;IAAS,CAAC,GAAGF,YAAY,CAACG,UAAU,CAAC,CAAC;;IAE9C;IACA,IAAID,QAAQ,EAAE;MACVE,OAAO,CAACC,GAAG,CAAC,qDAAqD,CAAC;MAClE,OAAOJ,KAAK;IAChB;IAEA,OAAO,IAAI,CAACH,QAAQ,CAACQ,SAAS,CAACN,YAAY,EAAEC,KAAK,CAAC;EACvD;AACJ;AAACM,OAAA,CAAAX,4BAAA,GAAAA,4BAAA","ignoreList":[]}
@@ -3,4 +3,4 @@ import { AssetDeliveryConfigModifierPlugin } from "./index";
3
3
  export interface AssetDeliveryParams {
4
4
  documentClient: DynamoDBDocument;
5
5
  }
6
- export declare const setupAssetDelivery: (params: AssetDeliveryParams) => (import("@webiny/handler").ModifyFastifyPlugin | AssetDeliveryConfigModifierPlugin)[];
6
+ export declare const setupAssetDelivery: (params: AssetDeliveryParams) => (AssetDeliveryConfigModifierPlugin | import("@webiny/handler").ModifyFastifyPlugin)[];
@@ -95,6 +95,7 @@ const setupAssetDelivery = params => {
95
95
  const processedAsset = await assetProcessor.process(resolvedRequest, resolvedAsset);
96
96
 
97
97
  // Get reply object (runs the output strategy under the hood).
98
+ console.log(`Output asset (size: ${processedAsset.getSize()} bytes).`);
98
99
  return outputAsset(reply, processedAsset);
99
100
  }, {
100
101
  override: true
@@ -1 +1 @@
1
- {"version":3,"names":["_handler","require","_PrivateFilesAssetProcessor","_PrivateAuthenticatedAuthorizer","_PrivateFileAssetRequestResolver","_index","noCacheHeaders","ResponseHeaders","create","assertAssetRequestWasResolved","request","undefined","Error","assertAssetWasResolved","asset","setupAssetDelivery","params","outputAsset","reply","assetReply","output","headers","getHeaders","set","code","getCode","send","getBody","createModifyFastifyPlugin","app","configBuilder","AssetDeliveryConfigBuilder","configPlugins","webiny","plugins","byType","AssetDeliveryConfigModifierPlugin","type","forEach","configPlugin","buildConfig","resolvedRequest","resolvedAsset","handlerOnRequest","createHandlerOnRequest","requestResolver","getAssetRequestResolver","resolve","error","hijack","assetResolver","getAssetResolver","assetLocale","getLocale","getTenant","deliveryRoute","createRoute","onGet","context","_","wcp","canUsePrivateFiles","decorateAssetProcessor","assetProcessor","assetAuthorizer","PrivateAuthenticatedAuthorizer","PrivateFilesAssetProcessor","outputStrategy","getAssetOutputStrategy","setOutputStrategy","getAssetProcessor","processedAsset","process","override","register","createAssetDeliveryConfig","config","decorateAssetRequestResolver","FilesAssetRequestResolver","assetRequestResolver","AliasAssetRequestResolver","documentClient","PrivateFileAssetRequestResolver","exports"],"sources":["setupAssetDelivery.ts"],"sourcesContent":["import { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport {\n createHandlerOnRequest,\n createModifyFastifyPlugin,\n createRoute,\n ResponseHeaders\n} from \"@webiny/handler\";\nimport { FileManagerContext } from \"~/types\";\nimport { PrivateFilesAssetProcessor } from \"./AssetDelivery/privateFiles/PrivateFilesAssetProcessor\";\nimport { PrivateAuthenticatedAuthorizer } from \"./AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer\";\nimport { PrivateFileAssetRequestResolver } from \"./AssetDelivery/privateFiles/PrivateFileAssetRequestResolver\";\nimport {\n Asset,\n AssetDeliveryConfigBuilder,\n AssetDeliveryConfigModifierPlugin,\n AssetRequest,\n AliasAssetRequestResolver,\n FilesAssetRequestResolver,\n createAssetDeliveryConfig\n} from \"./index\";\nimport { Reply } from \"@webiny/handler/types\";\n\nconst noCacheHeaders = ResponseHeaders.create({\n \"content-type\": \"application/json\",\n \"cache-control\": \"no-cache, no-store, must-revalidate\"\n});\n\nfunction assertAssetRequestWasResolved(request: any): asserts request is AssetRequest {\n if (request === undefined) {\n throw new Error(\"Not an AssetRequest!\");\n }\n}\n\nfunction assertAssetWasResolved(asset: Asset | undefined): asserts asset is Asset {\n if (asset === undefined) {\n throw new Error(\"Not an Asset!\");\n }\n}\n\nexport interface AssetDeliveryParams {\n documentClient: DynamoDBDocument;\n}\n\nexport const setupAssetDelivery = (params: AssetDeliveryParams) => {\n const outputAsset = async (reply: Reply, asset: Asset) => {\n const assetReply = await asset.output();\n const headers = assetReply.getHeaders();\n\n // Set default headers.\n headers.set(\"x-webiny-base64-encoded\", true);\n\n reply.code(assetReply.getCode());\n reply.headers(headers.getHeaders());\n return reply.send(await assetReply.getBody());\n };\n\n return [\n createModifyFastifyPlugin(app => {\n // Config builder allows config modification via plugins.\n const configBuilder = new AssetDeliveryConfigBuilder();\n\n // Apply config modifications.\n const configPlugins = app.webiny.plugins.byType<AssetDeliveryConfigModifierPlugin>(\n AssetDeliveryConfigModifierPlugin.type\n );\n\n configPlugins.forEach(configPlugin => configPlugin.buildConfig(configBuilder));\n\n let resolvedRequest: AssetRequest | undefined;\n let resolvedAsset: Asset | undefined;\n\n // Create a `HandlerOnRequest` plugin to resolve `tenant` and `locale`, and allow the system to bootstrap.\n const handlerOnRequest = createHandlerOnRequest(async (request, reply) => {\n const requestResolver = configBuilder.getAssetRequestResolver();\n resolvedRequest = await requestResolver.resolve(request);\n\n if (!resolvedRequest) {\n reply\n .code(404)\n .headers(noCacheHeaders.getHeaders())\n .send({ error: \"Unable to resolve the request!\" })\n .hijack();\n\n return false;\n }\n\n const assetResolver = configBuilder.getAssetResolver();\n\n resolvedAsset = await assetResolver.resolve(resolvedRequest);\n\n if (!resolvedAsset) {\n reply\n .code(404)\n .headers(noCacheHeaders.getHeaders())\n .send({ error: \"Asset not found!\" })\n .hijack();\n\n return false;\n }\n\n const assetLocale = resolvedAsset.getLocale();\n\n request.headers = {\n ...request.headers,\n \"x-tenant\": resolvedAsset.getTenant(),\n \"x-i18n-locale\": `default:${assetLocale};content:${assetLocale};`\n };\n\n return;\n });\n\n // Create the `Route` plugin, to handle all GET requests, and output the resolved asset.\n const deliveryRoute = createRoute<FileManagerContext>(({ onGet, context }) => {\n onGet(\n \"*\",\n async (_, reply) => {\n assertAssetRequestWasResolved(resolvedRequest);\n assertAssetWasResolved(resolvedAsset);\n\n if (context.wcp.canUsePrivateFiles()) {\n configBuilder.decorateAssetProcessor(({ assetProcessor, context }) => {\n // Currently, we only have one authorizer.\n const assetAuthorizer = new PrivateAuthenticatedAuthorizer(context);\n\n return new PrivateFilesAssetProcessor(\n context,\n assetAuthorizer,\n assetProcessor\n );\n });\n }\n\n const outputStrategy = configBuilder.getAssetOutputStrategy(\n context,\n resolvedRequest,\n resolvedAsset\n );\n\n resolvedAsset.setOutputStrategy(outputStrategy);\n\n const assetProcessor = configBuilder.getAssetProcessor(context);\n\n const processedAsset = await assetProcessor.process(\n resolvedRequest,\n resolvedAsset\n );\n\n // Get reply object (runs the output strategy under the hood).\n return outputAsset(reply, processedAsset);\n },\n { override: true }\n );\n });\n\n app.webiny.plugins.register(handlerOnRequest, deliveryRoute);\n }),\n // Create the default configuration\n createAssetDeliveryConfig(config => {\n config.decorateAssetRequestResolver(() => {\n // This resolver works with `/files/*` requests.\n return new FilesAssetRequestResolver();\n });\n\n config.decorateAssetRequestResolver(({ assetRequestResolver }) => {\n // This resolver tries to resolve the request using aliases.\n return new AliasAssetRequestResolver(params.documentClient, assetRequestResolver);\n });\n\n config.decorateAssetRequestResolver(({ assetRequestResolver }) => {\n // This resolver works with `/private/*` requests.\n return new PrivateFileAssetRequestResolver(assetRequestResolver);\n });\n })\n ];\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAOA,IAAAC,2BAAA,GAAAD,OAAA;AACA,IAAAE,+BAAA,GAAAF,OAAA;AACA,IAAAG,gCAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAWA,MAAMK,cAAc,GAAGC,wBAAe,CAACC,MAAM,CAAC;EAC1C,cAAc,EAAE,kBAAkB;EAClC,eAAe,EAAE;AACrB,CAAC,CAAC;AAEF,SAASC,6BAA6BA,CAACC,OAAY,EAAmC;EAClF,IAAIA,OAAO,KAAKC,SAAS,EAAE;IACvB,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;EAC3C;AACJ;AAEA,SAASC,sB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3,"names":["_handler","require","_PrivateFilesAssetProcessor","_PrivateAuthenticatedAuthorizer","_PrivateFileAssetRequestResolver","_index","noCacheHeaders","ResponseHeaders","create","assertAssetRequestWasResolved","request","undefined","Error","assertAssetWasResolved","asset","setupAssetDelivery","params","outputAsset","reply","assetReply","output","headers","getHeaders","set","code","getCode","send","getBody","createModifyFastifyPlugin","app","configBuilder","AssetDeliveryConfigBuilder","configPlugins","webiny","plugins","byType","AssetDeliveryConfigModifierPlugin","type","forEach","configPlugin","buildConfig","resolvedRequest","resolvedAsset","handlerOnRequest","createHandlerOnRequest","requestResolver","getAssetRequestResolver","resolve","error","hijack","assetResolver","getAssetResolver","assetLocale","getLocale","getTenant","deliveryRoute","createRoute","onGet","context","_","wcp","canUsePrivateFiles","decorateAssetProcessor","assetProcessor","assetAuthorizer","PrivateAuthenticatedAuthorizer","PrivateFilesAssetProcessor","outputStrategy","getAssetOutputStrategy","setOutputStrategy","getAssetProcessor","processedAsset","process","console","log","getSize","override","register","createAssetDeliveryConfig","config","decorateAssetRequestResolver","FilesAssetRequestResolver","assetRequestResolver","AliasAssetRequestResolver","documentClient","PrivateFileAssetRequestResolver","exports"],"sources":["setupAssetDelivery.ts"],"sourcesContent":["import { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport {\n createHandlerOnRequest,\n createModifyFastifyPlugin,\n createRoute,\n ResponseHeaders\n} from \"@webiny/handler\";\nimport { FileManagerContext } from \"~/types\";\nimport { PrivateFilesAssetProcessor } from \"./AssetDelivery/privateFiles/PrivateFilesAssetProcessor\";\nimport { PrivateAuthenticatedAuthorizer } from \"./AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer\";\nimport { PrivateFileAssetRequestResolver } from \"./AssetDelivery/privateFiles/PrivateFileAssetRequestResolver\";\nimport {\n Asset,\n AssetDeliveryConfigBuilder,\n AssetDeliveryConfigModifierPlugin,\n AssetRequest,\n AliasAssetRequestResolver,\n FilesAssetRequestResolver,\n createAssetDeliveryConfig\n} from \"./index\";\nimport { Reply } from \"@webiny/handler/types\";\n\nconst noCacheHeaders = ResponseHeaders.create({\n \"content-type\": \"application/json\",\n \"cache-control\": \"no-cache, no-store, must-revalidate\"\n});\n\nfunction assertAssetRequestWasResolved(request: any): asserts request is AssetRequest {\n if (request === undefined) {\n throw new Error(\"Not an AssetRequest!\");\n }\n}\n\nfunction assertAssetWasResolved(asset: Asset | undefined): asserts asset is Asset {\n if (asset === undefined) {\n throw new Error(\"Not an Asset!\");\n }\n}\n\nexport interface AssetDeliveryParams {\n documentClient: DynamoDBDocument;\n}\n\nexport const setupAssetDelivery = (params: AssetDeliveryParams) => {\n const outputAsset = async (reply: Reply, asset: Asset) => {\n const assetReply = await asset.output();\n const headers = assetReply.getHeaders();\n\n // Set default headers.\n headers.set(\"x-webiny-base64-encoded\", true);\n\n reply.code(assetReply.getCode());\n reply.headers(headers.getHeaders());\n return reply.send(await assetReply.getBody());\n };\n\n return [\n createModifyFastifyPlugin(app => {\n // Config builder allows config modification via plugins.\n const configBuilder = new AssetDeliveryConfigBuilder();\n\n // Apply config modifications.\n const configPlugins = app.webiny.plugins.byType<AssetDeliveryConfigModifierPlugin>(\n AssetDeliveryConfigModifierPlugin.type\n );\n\n configPlugins.forEach(configPlugin => configPlugin.buildConfig(configBuilder));\n\n let resolvedRequest: AssetRequest | undefined;\n let resolvedAsset: Asset | undefined;\n\n // Create a `HandlerOnRequest` plugin to resolve `tenant` and `locale`, and allow the system to bootstrap.\n const handlerOnRequest = createHandlerOnRequest(async (request, reply) => {\n const requestResolver = configBuilder.getAssetRequestResolver();\n resolvedRequest = await requestResolver.resolve(request);\n\n if (!resolvedRequest) {\n reply\n .code(404)\n .headers(noCacheHeaders.getHeaders())\n .send({ error: \"Unable to resolve the request!\" })\n .hijack();\n\n return false;\n }\n\n const assetResolver = configBuilder.getAssetResolver();\n\n resolvedAsset = await assetResolver.resolve(resolvedRequest);\n\n if (!resolvedAsset) {\n reply\n .code(404)\n .headers(noCacheHeaders.getHeaders())\n .send({ error: \"Asset not found!\" })\n .hijack();\n\n return false;\n }\n\n const assetLocale = resolvedAsset.getLocale();\n\n request.headers = {\n ...request.headers,\n \"x-tenant\": resolvedAsset.getTenant(),\n \"x-i18n-locale\": `default:${assetLocale};content:${assetLocale};`\n };\n\n return;\n });\n\n // Create the `Route` plugin, to handle all GET requests, and output the resolved asset.\n const deliveryRoute = createRoute<FileManagerContext>(({ onGet, context }) => {\n onGet(\n \"*\",\n async (_, reply) => {\n assertAssetRequestWasResolved(resolvedRequest);\n assertAssetWasResolved(resolvedAsset);\n\n if (context.wcp.canUsePrivateFiles()) {\n configBuilder.decorateAssetProcessor(({ assetProcessor, context }) => {\n // Currently, we only have one authorizer.\n const assetAuthorizer = new PrivateAuthenticatedAuthorizer(context);\n\n return new PrivateFilesAssetProcessor(\n context,\n assetAuthorizer,\n assetProcessor\n );\n });\n }\n\n const outputStrategy = configBuilder.getAssetOutputStrategy(\n context,\n resolvedRequest,\n resolvedAsset\n );\n\n resolvedAsset.setOutputStrategy(outputStrategy);\n\n const assetProcessor = configBuilder.getAssetProcessor(context);\n\n const processedAsset = await assetProcessor.process(\n resolvedRequest,\n resolvedAsset\n );\n\n // Get reply object (runs the output strategy under the hood).\n console.log(`Output asset (size: ${processedAsset.getSize()} bytes).`);\n return outputAsset(reply, processedAsset);\n },\n { override: true }\n );\n });\n\n app.webiny.plugins.register(handlerOnRequest, deliveryRoute);\n }),\n // Create the default configuration\n createAssetDeliveryConfig(config => {\n config.decorateAssetRequestResolver(() => {\n // This resolver works with `/files/*` requests.\n return new FilesAssetRequestResolver();\n });\n\n config.decorateAssetRequestResolver(({ assetRequestResolver }) => {\n // This resolver tries to resolve the request using aliases.\n return new AliasAssetRequestResolver(params.documentClient, assetRequestResolver);\n });\n\n config.decorateAssetRequestResolver(({ assetRequestResolver }) => {\n // This resolver works with `/private/*` requests.\n return new PrivateFileAssetRequestResolver(assetRequestResolver);\n });\n })\n ];\n};\n"],"mappings":";;;;;;AACA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M,IAAI;IAChCA,MAAM,CAACC,4BAA4B,CAAC,MAAM;MACtC;MACA,OAAO,IAAIC,gCAAyB,CAAC,CAAC;IAC1C,CAAC,CAAC;IAEFF,MAAM,CAACC,4BAA4B,CAAC,CAAC;MAAEE;IAAqB,CAAC,KAAK;MAC9D;MACA,OAAO,IAAIC,gCAAyB,CAACnE,MAAM,CAACoE,cAAc,EAAEF,oBAAoB,CAAC;IACrF,CAAC,CAAC;IAEFH,MAAM,CAACC,4BAA4B,CAAC,CAAC;MAAEE;IAAqB,CAAC,KAAK;MAC9D;MACA,OAAO,IAAIG,gEAA+B,CAACH,oBAAoB,CAAC;IACpE,CAAC,CAAC;EACN,CAAC,CAAC,CACL;AACL,CAAC;AAACI,OAAA,CAAAvE,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -7,5 +7,5 @@ export declare const emptyResolver: () => {};
7
7
  interface ResolveCallable {
8
8
  (): Promise<any>;
9
9
  }
10
- export declare const resolve: (fn: ResolveCallable) => Promise<ErrorResponse | Response<any>>;
10
+ export declare const resolve: (fn: ResolveCallable) => Promise<Response<any> | ErrorResponse>;
11
11
  export {};
package/index.d.ts CHANGED
@@ -7,4 +7,4 @@ export * from "./plugins";
7
7
  export * from "./delivery";
8
8
  export declare const createFileManagerContext: ({ storageOperations }: Pick<FileManagerConfig, "storageOperations">) => ContextPlugin<FileManagerContext>;
9
9
  export declare const createFileManagerGraphQL: () => (import("@webiny/handler-graphql").GraphQLSchemaPlugin<FileManagerContext> | ContextPlugin<FileManagerContext>)[];
10
- export declare const createAssetDelivery: (config: AssetDeliveryParams) => (import("@webiny/handler").ModifyFastifyPlugin | import("./delivery").AssetDeliveryConfigModifierPlugin)[];
10
+ export declare const createAssetDelivery: (config: AssetDeliveryParams) => (import("./delivery").AssetDeliveryConfigModifierPlugin | import("@webiny/handler").ModifyFastifyPlugin)[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-file-manager",
3
- "version": "5.41.0-dbt.0",
3
+ "version": "5.41.1-beta.0",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "fm:base"
@@ -20,20 +20,20 @@
20
20
  "dependencies": {
21
21
  "@babel/runtime": "7.24.1",
22
22
  "@commodo/fields": "1.1.2-beta.20",
23
- "@webiny/api": "5.41.0-dbt.0",
24
- "@webiny/api-headless-cms": "5.41.0-dbt.0",
25
- "@webiny/api-security": "5.41.0-dbt.0",
26
- "@webiny/api-tenancy": "5.41.0-dbt.0",
27
- "@webiny/aws-sdk": "5.41.0-dbt.0",
28
- "@webiny/error": "5.41.0-dbt.0",
29
- "@webiny/handler": "5.41.0-dbt.0",
30
- "@webiny/handler-aws": "5.41.0-dbt.0",
31
- "@webiny/handler-graphql": "5.41.0-dbt.0",
32
- "@webiny/plugins": "5.41.0-dbt.0",
33
- "@webiny/project-utils": "5.41.0-dbt.0",
34
- "@webiny/pubsub": "5.41.0-dbt.0",
35
- "@webiny/tasks": "5.41.0-dbt.0",
36
- "@webiny/validation": "5.41.0-dbt.0",
23
+ "@webiny/api": "5.41.1-beta.0",
24
+ "@webiny/api-headless-cms": "5.41.1-beta.0",
25
+ "@webiny/api-security": "5.41.1-beta.0",
26
+ "@webiny/api-tenancy": "5.41.1-beta.0",
27
+ "@webiny/aws-sdk": "5.41.1-beta.0",
28
+ "@webiny/error": "5.41.1-beta.0",
29
+ "@webiny/handler": "5.41.1-beta.0",
30
+ "@webiny/handler-aws": "5.41.1-beta.0",
31
+ "@webiny/handler-graphql": "5.41.1-beta.0",
32
+ "@webiny/plugins": "5.41.1-beta.0",
33
+ "@webiny/project-utils": "5.41.1-beta.0",
34
+ "@webiny/pubsub": "5.41.1-beta.0",
35
+ "@webiny/tasks": "5.41.1-beta.0",
36
+ "@webiny/validation": "5.41.1-beta.0",
37
37
  "cache-control-parser": "2.0.6",
38
38
  "lodash": "4.17.21",
39
39
  "object-hash": "3.0.0"
@@ -46,9 +46,9 @@
46
46
  "@babel/preset-env": "7.24.3",
47
47
  "@babel/preset-typescript": "7.24.1",
48
48
  "@types/sharp": "0.32.0",
49
- "@webiny/api-i18n": "5.41.0-dbt.0",
50
- "@webiny/cli": "5.41.0-dbt.0",
51
- "@webiny/utils": "5.41.0-dbt.0",
49
+ "@webiny/api-i18n": "5.41.1-beta.0",
50
+ "@webiny/cli": "5.41.1-beta.0",
51
+ "@webiny/utils": "5.41.1-beta.0",
52
52
  "jest": "29.7.0",
53
53
  "rimraf": "5.0.5",
54
54
  "ttypescript": "1.5.15",
@@ -72,5 +72,5 @@
72
72
  ]
73
73
  }
74
74
  },
75
- "gitHead": "bbaec4dd1685579548c08bbde386aee5d96b80f8"
75
+ "gitHead": "004f3d7a2022be14f14bd2f9342d009d7974ccd0"
76
76
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Plugin } from "@webiny/plugins";
3
4
  import { FileManagerSettings } from "../types";
4
5
  export interface FilePhysicalStoragePluginParams<U extends FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams> {
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { FileManagerContext } from "../types";
3
4
  import { FilePhysicalStoragePlugin } from "../plugins/FilePhysicalStoragePlugin";
4
5
  export type Result = Record<string, any>;
package/types/file.d.ts CHANGED
@@ -23,6 +23,7 @@ export interface File {
23
23
  createdBy: CreatedBy;
24
24
  modifiedBy: CreatedBy | null;
25
25
  savedBy: CreatedBy;
26
+ extensions?: Record<string, any>;
26
27
  /**
27
28
  * Added with new storage operations refactoring.
28
29
  */
package/types/file.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["file.ts"],"sourcesContent":["type PublicAccess = {\n type: \"public\";\n};\n\ntype PrivateAuthenticatedAccess = {\n type: \"private-authenticated\";\n};\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n accessControl?: PublicAccess | PrivateAuthenticatedAccess;\n location: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n\n createdOn: string;\n modifiedOn: string | null;\n savedOn: string;\n createdBy: CreatedBy;\n modifiedBy: CreatedBy | null;\n savedBy: CreatedBy;\n\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object, so we must allow it in the types.\n */\n\n [key: string]: any;\n}\n\nexport interface FileAlias {\n tenant: string;\n locale: string;\n fileId: string;\n alias: string;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["file.ts"],"sourcesContent":["type PublicAccess = {\n type: \"public\";\n};\n\ntype PrivateAuthenticatedAccess = {\n type: \"private-authenticated\";\n};\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n accessControl?: PublicAccess | PrivateAuthenticatedAccess;\n location: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n\n createdOn: string;\n modifiedOn: string | null;\n savedOn: string;\n createdBy: CreatedBy;\n modifiedBy: CreatedBy | null;\n savedBy: CreatedBy;\n extensions?: Record<string, any>;\n\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object, so we must allow it in the types.\n */\n\n [key: string]: any;\n}\n\nexport interface FileAlias {\n tenant: string;\n locale: string;\n fileId: string;\n alias: string;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n"],"mappings":"","ignoreList":[]}
package/types.d.ts CHANGED
@@ -6,7 +6,7 @@ import { Context } from "@webiny/api/types";
6
6
  import { FileLifecycleEvents } from "./types/file.lifecycle";
7
7
  import { CreatedBy, File } from "./types/file";
8
8
  import { Topic } from "@webiny/pubsub/types";
9
- import { CmsContext } from "@webiny/api-headless-cms/types";
9
+ import { CmsContext, CmsEntryListSort } from "@webiny/api-headless-cms/types";
10
10
  import { Context as TasksContext } from "@webiny/tasks/types";
11
11
  export * from "./types/file.lifecycle";
12
12
  export * from "./types/file";
@@ -52,7 +52,7 @@ export interface FilesListOpts {
52
52
  limit?: number;
53
53
  after?: string;
54
54
  where?: FileListWhereParams;
55
- sort?: string[];
55
+ sort?: CmsEntryListSort;
56
56
  }
57
57
  export interface FileListMeta {
58
58
  cursor: string | null;
@@ -286,7 +286,7 @@ export interface FileManagerFilesStorageOperationsListParamsWhere {
286
286
  */
287
287
  export interface FileManagerFilesStorageOperationsListParams {
288
288
  where: FileManagerFilesStorageOperationsListParamsWhere;
289
- sort: string[];
289
+ sort: CmsEntryListSort;
290
290
  limit: number;
291
291
  after: string | null;
292
292
  search?: string;
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_file","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_file2"],"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 { CreatedBy, File } from \"./types/file\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport { Context as TasksContext } from \"@webiny/tasks/types\";\n\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext\n extends Context,\n SecurityContext,\n TenancyContext,\n I18NContext,\n CmsContext,\n TasksContext {\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\n // In the background, we're actually mapping these to entry-level fields.\n // This is fine since we don't use revisions for files.\n createdOn?: string | Date | null;\n modifiedOn?: string | Date | null;\n savedOn?: string | Date | null;\n createdBy?: CreatedBy | null;\n modifiedBy?: CreatedBy | null;\n savedBy?: CreatedBy | null;\n\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n location?: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n extensions?: Record<string, any>;\n}\n\nexport interface FileListWhereParams {\n AND?: FileListWhereParams[];\n OR?: FileListWhereParams[];\n [key: string]: any;\n}\nexport interface FilesListOpts {\n search?: 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 interface OnSettingsBeforeUpdateTopicParams {\n input: Partial<FileManagerSettings>;\n original: FileManagerSettings;\n settings: FileManagerSettings;\n}\n\nexport interface OnSettingsAfterUpdateTopicParams {\n input: Partial<FileManagerSettings>;\n original: FileManagerSettings;\n settings: FileManagerSettings;\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 onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;\n onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;\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 [key: string]: any;\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 search?: string;\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 FileManagerAliasesStorageOperations {\n storeAliases(file: File): Promise<void>;\n deleteAliases(file: File): Promise<void>;\n}\n\nexport interface FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n aliases: FileManagerAliasesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AAWA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AACAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_file","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_file2"],"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 { CreatedBy, File } from \"./types/file\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { CmsContext, CmsEntryListSort } from \"@webiny/api-headless-cms/types\";\nimport { Context as TasksContext } from \"@webiny/tasks/types\";\n\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext\n extends Context,\n SecurityContext,\n TenancyContext,\n I18NContext,\n CmsContext,\n TasksContext {\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\n // In the background, we're actually mapping these to entry-level fields.\n // This is fine since we don't use revisions for files.\n createdOn?: string | Date | null;\n modifiedOn?: string | Date | null;\n savedOn?: string | Date | null;\n createdBy?: CreatedBy | null;\n modifiedBy?: CreatedBy | null;\n savedBy?: CreatedBy | null;\n\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n location?: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n extensions?: Record<string, any>;\n}\n\nexport interface FileListWhereParams {\n AND?: FileListWhereParams[];\n OR?: FileListWhereParams[];\n [key: string]: any;\n}\nexport interface FilesListOpts {\n search?: string;\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: CmsEntryListSort;\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 interface OnSettingsBeforeUpdateTopicParams {\n input: Partial<FileManagerSettings>;\n original: FileManagerSettings;\n settings: FileManagerSettings;\n}\n\nexport interface OnSettingsAfterUpdateTopicParams {\n input: Partial<FileManagerSettings>;\n original: FileManagerSettings;\n settings: FileManagerSettings;\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 onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;\n onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;\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 [key: string]: any;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: CmsEntryListSort;\n limit: number;\n after: string | null;\n search?: string;\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 FileManagerAliasesStorageOperations {\n storeAliases(file: File): Promise<void>;\n deleteAliases(file: File): Promise<void>;\n}\n\nexport interface FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n aliases: FileManagerAliasesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AAWA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AACAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}