@webiny/api-file-manager-ddb 5.24.0 → 5.25.0-beta.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["filesEntity.ts"],"names":["params","context","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","TYPE","type","id","key","size","meta","tags","createdOn","createdBy","tenant","locale","webinyVersion"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;;;;;eAMgBA,MAAD,IAA4C;AACvD,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAqBF,MAA3B;AACA,QAAMG,UAAU,GAAG,OAAnB;AACA,QAAMC,UAAU,GAAG,oCAAmBH,OAAnB,EAA4BE,UAA5B,CAAnB;AACA,SAAO,IAAIE,uBAAJ,CAAW;AACdC,IAAAA,IAAI,EAAEH,UADQ;AAEdD,IAAAA,KAFc;AAGdE,IAAAA,UAAU;AACNG,MAAAA,EAAE,EAAE;AACAC,QAAAA,YAAY,EAAE;AADd,OADE;AAINC,MAAAA,EAAE,EAAE;AACAC,QAAAA,OAAO,EAAE;AADT,OAJE;AAONC,MAAAA,IAAI,EAAE;AACFC,QAAAA,IAAI,EAAE;AADJ,OAPA;AAUNC,MAAAA,EAAE,EAAE;AACAD,QAAAA,IAAI,EAAE;AADN,OAVE;AAaNE,MAAAA,GAAG,EAAE;AACDF,QAAAA,IAAI,EAAE;AADL,OAbC;AAgBNG,MAAAA,IAAI,EAAE;AACFH,QAAAA,IAAI,EAAE;AADJ,OAhBA;AAmBNA,MAAAA,IAAI,EAAE;AACFA,QAAAA,IAAI,EAAE;AADJ,OAnBA;AAsBNN,MAAAA,IAAI,EAAE;AACFM,QAAAA,IAAI,EAAE;AADJ,OAtBA;AAyBNI,MAAAA,IAAI,EAAE;AACFJ,QAAAA,IAAI,EAAE;AADJ,OAzBA;AA4BNK,MAAAA,IAAI,EAAE;AACFL,QAAAA,IAAI,EAAE;AADJ,OA5BA;AA+BNM,MAAAA,SAAS,EAAE;AACPN,QAAAA,IAAI,EAAE;AADC,OA/BL;AAkCNO,MAAAA,SAAS,EAAE;AACPP,QAAAA,IAAI,EAAE;AADC,OAlCL;AAqCNQ,MAAAA,MAAM,EAAE;AACJR,QAAAA,IAAI,EAAE;AADF,OArCF;AAwCNS,MAAAA,MAAM,EAAE;AACJT,QAAAA,IAAI,EAAE;AADF,OAxCF;AA2CNU,MAAAA,aAAa,EAAE;AACXV,QAAAA,IAAI,EAAE;AADK;AA3CT,OA8CHR,UA9CG;AAHI,GAAX,CAAP;AAoDH,C","sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { getExtraAttributes } from \"@webiny/db-dynamodb/utils/attributes\";\n\nexport interface FilesEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: FilesEntityParams): Entity<any> => {\n const { context, table } = params;\n const entityName = \"Files\";\n const attributes = getExtraAttributes(context, entityName);\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n key: {\n type: \"string\"\n },\n size: {\n type: \"number\"\n },\n type: {\n type: \"string\"\n },\n name: {\n type: \"string\"\n },\n meta: {\n type: \"map\"\n },\n tags: {\n type: \"list\"\n },\n createdOn: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n ...attributes\n }\n });\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["settingsEntity.ts"],"names":["params","context","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","TYPE","type","key","uploadMinFileSize","uploadMaxFileSize","srcPrefix"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;;;;;eAMgBA,MAAD,IAA+C;AAC1D,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAqBF,MAA3B;AACA,QAAMG,UAAU,GAAG,UAAnB;AACA,QAAMC,UAAU,GAAG,oCAAmBH,OAAnB,EAA4BE,UAA5B,CAAnB;AACA,SAAO,IAAIE,uBAAJ,CAAW;AACdC,IAAAA,IAAI,EAAEH,UADQ;AAEdD,IAAAA,KAFc;AAGdE,IAAAA,UAAU;AACNG,MAAAA,EAAE,EAAE;AACAC,QAAAA,YAAY,EAAE;AADd,OADE;AAINC,MAAAA,EAAE,EAAE;AACAC,QAAAA,OAAO,EAAE;AADT,OAJE;AAONC,MAAAA,IAAI,EAAE;AACFC,QAAAA,IAAI,EAAE;AADJ,OAPA;AAUNC,MAAAA,GAAG,EAAE;AACDD,QAAAA,IAAI,EAAE;AADL,OAVC;AAaNE,MAAAA,iBAAiB,EAAE;AACfF,QAAAA,IAAI,EAAE;AADS,OAbb;AAgBNG,MAAAA,iBAAiB,EAAE;AACfH,QAAAA,IAAI,EAAE;AADS,OAhBb;AAmBNI,MAAAA,SAAS,EAAE;AACPJ,QAAAA,IAAI,EAAE;AADC;AAnBL,OAsBHR,UAtBG;AAHI,GAAX,CAAP;AA4BH,C","sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { getExtraAttributes } from \"@webiny/db-dynamodb/utils/attributes\";\n\nexport interface SettingsEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: SettingsEntityParams): Entity<any> => {\n const { context, table } = params;\n const entityName = \"Settings\";\n const attributes = getExtraAttributes(context, entityName);\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n key: {\n type: \"string\"\n },\n uploadMinFileSize: {\n type: \"number\"\n },\n uploadMaxFileSize: {\n type: \"number\"\n },\n srcPrefix: {\n type: \"string\"\n },\n ...attributes\n }\n });\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["systemEntity.ts"],"names":["params","context","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","version","type","tenant"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;;;;;eAMgBA,MAAD,IAA6C;AACxD,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAqBF,MAA3B;AACA,QAAMG,UAAU,GAAG,QAAnB;AACA,QAAMC,UAAU,GAAG,oCAAmBH,OAAnB,EAA4BE,UAA5B,CAAnB;AACA,SAAO,IAAIE,uBAAJ,CAAW;AACdC,IAAAA,IAAI,EAAEH,UADQ;AAEdD,IAAAA,KAFc;AAGdE,IAAAA,UAAU;AACNG,MAAAA,EAAE,EAAE;AACAC,QAAAA,YAAY,EAAE;AADd,OADE;AAINC,MAAAA,EAAE,EAAE;AACAC,QAAAA,OAAO,EAAE;AADT,OAJE;AAONC,MAAAA,OAAO,EAAE;AACLC,QAAAA,IAAI,EAAE;AADD,OAPH;AAUNC,MAAAA,MAAM,EAAE;AACJD,QAAAA,IAAI,EAAE;AADF;AAVF,OAaHR,UAbG;AAHI,GAAX,CAAP;AAmBH,C","sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { getExtraAttributes } from \"@webiny/db-dynamodb/utils/attributes\";\n\nexport interface SystemEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: SystemEntityParams): Entity<any> => {\n const { context, table } = params;\n const entityName = \"System\";\n const attributes = getExtraAttributes(context, entityName);\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n version: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n ...attributes\n }\n });\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["table.ts"],"names":["params","context","Table","name","configurations","db","table","partitionKey","sortKey","DocumentClient"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;eAMgBA,MAAD,IAAgC;AAC3C,QAAM;AAAEC,IAAAA;AAAF,MAAcD,MAApB;AACA,SAAO,IAAIE,sBAAJ,CAAU;AACbC,IAAAA,IAAI,EAAEC,wBAAeC,EAAf,GAAoBC,KAApB,IAA6B,qBAASL,OAAT,CADtB;AAEbM,IAAAA,YAAY,EAAE,IAFD;AAGbC,IAAAA,OAAO,EAAE,IAHI;AAIbC,IAAAA,cAAc,EAAE,8BAAkBR,OAAlB;AAJH,GAAV,CAAP;AAMH,C","sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport configurations from \"~/operations/configurations\";\nimport { getDocumentClient, getTable } from \"~/operations/utils\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\n\nexport interface TableParams {\n context: FileManagerContext;\n}\nexport default (params: TableParams): Table => {\n const { context } = params;\n return new Table({\n name: configurations.db().table || getTable(context),\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: getDocumentClient(context)\n });\n};\n"]}
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":["FilesStorageOperationsProviderDdb","SettingsStorageOperationsProviderDdbPlugin","SystemStorageOperationsProviderDdbPlugin"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;eAEe,MAAM,CACjB,IAAIA,wCAAJ,EADiB,EAEjB,IAAIC,oDAAJ,EAFiB,EAGjB,IAAIC,gDAAJ,EAHiB,C","sourcesContent":["import { FilesStorageOperationsProviderDdb } from \"./operations/files\";\nimport { SettingsStorageOperationsProviderDdbPlugin } from \"./operations/settings\";\nimport { SystemStorageOperationsProviderDdbPlugin } from \"./operations/system\";\n\nexport default () => [\n new FilesStorageOperationsProviderDdb(),\n new SettingsStorageOperationsProviderDdbPlugin(),\n new SystemStorageOperationsProviderDdbPlugin()\n];\n"]}
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  db: () => {
3
- table: string;
3
+ table: string | undefined;
4
4
  keys: {
5
5
  primary: boolean;
6
6
  unique: boolean;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["configurations.ts"],"names":["db","table","process","env","DB_TABLE_FILE_MANGER","DB_TABLE","keys","primary","unique","name","fields"],"mappings":";;;;;;eAAe;AACXA,EAAAA,EAAE,EAAE,OAAO;AACPC,IAAAA,KAAK,EAAEC,OAAO,CAACC,GAAR,CAAYC,oBAAZ,IAAoCF,OAAO,CAACC,GAAR,CAAYE,QADhD;AAEPC,IAAAA,IAAI,EAAE,CACF;AACIC,MAAAA,OAAO,EAAE,IADb;AAEIC,MAAAA,MAAM,EAAE,IAFZ;AAGIC,MAAAA,IAAI,EAAE,SAHV;AAIIC,MAAAA,MAAM,EAAE,CAAC;AAAED,QAAAA,IAAI,EAAE;AAAR,OAAD,EAAiB;AAAEA,QAAAA,IAAI,EAAE;AAAR,OAAjB;AAJZ,KADE;AAFC,GAAP;AADO,C","sourcesContent":["export default {\n db: () => ({\n table: process.env.DB_TABLE_FILE_MANGER || process.env.DB_TABLE,\n keys: [\n {\n primary: true,\n unique: true,\n name: \"primary\",\n fields: [{ name: \"PK\" }, { name: \"SK\" }]\n }\n ]\n })\n};\n"]}
@@ -246,7 +246,7 @@ class FilesStorageOperations {
246
246
  sort,
247
247
  fields
248
248
  });
249
- const start = parseInt((0, _cursor.decodeCursor)(after)) || 0;
249
+ const start = parseInt((0, _cursor.decodeCursor)(after) || "0") || 0;
250
250
  const hasMoreItems = totalCount > start + limit;
251
251
  const end = limit > totalCount + start + limit ? undefined : start + limit;
252
252
  const files = sortedFiles.slice(start, end);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["FilesStorageOperations.ts"],"names":["FilesStorageOperations","context","_context","constructor","table","entity","get","params","where","keys","PK","createPartitionKey","SK","createSortKey","file","ex","WebinyError","message","code","error","create","item","TYPE","put","update","delete","createBatch","files","items","map","putBatch","list","initialWhere","limit","after","sort","options","createQueryAllOptions","queryAllParams","partitionKey","queryParams","name","search","contains","fields","value","plugins","byType","FileDynamoDbFieldPlugin","type","filteredFiles","totalCount","length","sortedFiles","start","parseInt","hasMoreItems","end","undefined","slice","cursor","meta","tags","gte","reverse","results","query","tagsObject","reduce","collection","Array","isArray","tag","push","id","Object","eq","tenant","locale"],"mappings":";;;;;;;;;;;AAiBA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAyBO,MAAMA,sBAAN,CAA0E;AAK1D,MAAPC,OAAO,GAAuB;AACtC,WAAO,KAAKC,QAAZ;AACH;;AAEMC,EAAAA,WAAW,CAAC;AAAEF,IAAAA;AAAF,GAAD,EAAiC;AAAA;AAAA;AAAA;AAC/C,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKG,KAAL,GAAa,oBAAY;AACrBH,MAAAA;AADqB,KAAZ,CAAb;AAIA,SAAKI,MAAL,GAAc,0BAAkB;AAC5BJ,MAAAA,OAD4B;AAE5BG,MAAAA,KAAK,EAAE,KAAKA;AAFgB,KAAlB,CAAd;AAIH;;AAEe,QAAHE,GAAG,CAACC,MAAD,EAA2E;AACvF,UAAM;AAAEC,MAAAA;AAAF,QAAYD,MAAlB;AACA,UAAME,IAAI,GAAG;AACTC,MAAAA,EAAE,EAAE,KAAKC,kBAAL,CAAwBH,KAAxB,CADK;AAETI,MAAAA,EAAE,EAAE,KAAKC,aAAL,CAAmBL,KAAnB;AAFK,KAAb;;AAIA,QAAI;AACA,YAAMM,IAAI,GAAG,MAAM,cAAoB;AACnCT,QAAAA,MAAM,EAAE,KAAKA,MADsB;AAEnCI,QAAAA;AAFmC,OAApB,CAAnB;AAIA,aAAO,0BAAkB,KAAKJ,MAAvB,EAA+BS,IAA/B,CAAP;AACH,KAND,CAME,OAAOC,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,iCADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,gBAFT,EAGF;AACIC,QAAAA,KAAK,EAAEJ,EADX;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AAAA,UAAU,CAACG,GAAD,CAAV,GAAkB,EAAlB;AACH;;AACDH,QAAAA,UAAU,CAACG,GAAD,CAAV,CAAgBC,IAAhB,CAAqBpD,IAAI,CAACqD,EAA1B;AACH;;AACD,aAAOL,UAAP;AACH,KATkB,EAShB,EATgB,CAAnB;AAWA,UAAMP,IAAc,GAAGa,MAAM,CAAClE,IAAP,CAAY0D,UAAZ,CAAvB;AAEA,UAAMX,YAAY,GAAG,KAArB;AACA,UAAML,UAAU,GAAGW,IAAI,CAACV,MAAxB;AAEA,UAAMS,IAAuD,GAAG;AAC5DL,MAAAA,YAD4D;AAE5DL,MAAAA,UAF4D;AAG5DS,MAAAA,MAAM,EAAE;AAHoD,KAAhE;AAMA,WAAO,CAACE,IAAD,EAAOD,IAAP,CAAP;AACH;;AAEOxB,EAAAA,qBAAqB,CAAC;AAAE7B,IAAAA;AAAF,GAAD,EAAgE;AACzF,UAAM4B,OAAoC,GAAG,EAA7C;;AACA,QAAI5B,KAAK,CAACkE,EAAV,EAAc;AACVtC,MAAAA,OAAO,CAACwC,EAAR,GAAapE,KAAK,CAACkE,EAAnB;AACH;;AACD,WAAOtC,OAAP;AACH;;AAEOzB,EAAAA,kBAAkB,CAACJ,MAAD,EAA2C;AACjE,UAAM;AAAEsE,MAAAA,MAAF;AAAUC,MAAAA;AAAV,QAAqBvE,MAA3B;AACA,WAAQ,KAAIsE,MAAO,MAAKC,MAAO,OAA/B;AACH;;AAEOjE,EAAAA,aAAa,CAACN,MAAD,EAA8B;AAC/C,UAAM;AAAEmE,MAAAA;AAAF,QAASnE,MAAf;AAEA,WAAOmE,EAAP;AACH;;AA/T4E","sourcesContent":["import {\n File,\n FileManagerContext,\n FileManagerFilesStorageOperations,\n FileManagerFilesStorageOperationsCreateBatchParams,\n FileManagerFilesStorageOperationsCreateParams,\n FileManagerFilesStorageOperationsDeleteParams,\n FileManagerFilesStorageOperationsGetParams,\n FileManagerFilesStorageOperationsListParams,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsListResponse,\n FileManagerFilesStorageOperationsListResponseMeta,\n FileManagerFilesStorageOperationsTagsParams,\n FileManagerFilesStorageOperationsTagsResponse,\n FileManagerFilesStorageOperationsUpdateParams\n} from \"@webiny/api-file-manager/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport defineTable from \"~/definitions/table\";\nimport defineFilesEntity from \"~/definitions/filesEntity\";\nimport { queryOptions as DynamoDBToolboxQueryOptions } from \"dynamodb-toolbox/dist/classes/Table\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { decodeCursor, encodeCursor } from \"@webiny/db-dynamodb/utils/cursor\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { FileDynamoDbFieldPlugin } from \"~/plugins/FileDynamoDbFieldPlugin\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport { get as getEntityItem } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface FileItem extends File {\n PK: string;\n SK: string;\n TYPE: string;\n}\n\ninterface ConstructorParams {\n context: FileManagerContext;\n}\n\ninterface QueryAllOptionsParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n}\n\ninterface CreatePartitionKeyParams {\n locale: string;\n tenant: string;\n}\n\ninterface CreateSortKeyParams {\n id: string;\n}\n\nexport class FilesStorageOperations implements FileManagerFilesStorageOperations {\n private readonly _context: FileManagerContext;\n private readonly table: Table;\n private readonly entity: Entity<any>;\n\n private get context(): FileManagerContext {\n return this._context;\n }\n\n public constructor({ context }: ConstructorParams) {\n this._context = context;\n this.table = defineTable({\n context\n });\n\n this.entity = defineFilesEntity({\n context,\n table: this.table\n });\n }\n\n public async get(params: FileManagerFilesStorageOperationsGetParams): Promise<File | null> {\n const { where } = params;\n const keys = {\n PK: this.createPartitionKey(where),\n SK: this.createSortKey(where)\n };\n try {\n const file = await getEntityItem<File>({\n entity: this.entity,\n keys\n });\n return cleanupItem<File>(this.entity, file);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not fetch requested file.\",\n ex.code || \"GET_FILE_ERROR\",\n {\n error: ex,\n where\n }\n );\n }\n }\n\n public async create(params: FileManagerFilesStorageOperationsCreateParams): Promise<File> {\n const { file } = params;\n\n const keys = {\n PK: this.createPartitionKey(file),\n SK: this.createSortKey(file)\n };\n const item: FileItem = {\n ...file,\n ...keys,\n TYPE: \"fm.file\"\n };\n try {\n await this.entity.put(item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a new file in the DynamoDB.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n error: ex,\n item\n }\n );\n }\n\n return file;\n }\n\n public async update(params: FileManagerFilesStorageOperationsUpdateParams): Promise<File> {\n const { file } = params;\n const keys = {\n PK: this.createPartitionKey(file),\n SK: this.createSortKey(file)\n };\n\n const item: FileItem = {\n ...file,\n ...keys,\n TYPE: \"fm.file\"\n };\n try {\n await this.entity.put(item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file in the DynamoDB.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n error: ex,\n item\n }\n );\n }\n return file;\n }\n\n public async delete(params: FileManagerFilesStorageOperationsDeleteParams): Promise<void> {\n const { file } = params;\n const keys = {\n PK: this.createPartitionKey(file),\n SK: this.createSortKey(file)\n };\n\n try {\n await this.entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete file from the DynamoDB.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n error: ex,\n file,\n keys\n }\n );\n }\n }\n\n public async createBatch(\n params: FileManagerFilesStorageOperationsCreateBatchParams\n ): Promise<File[]> {\n const { files } = params;\n\n const items = files.map(file => {\n return this.entity.putBatch({\n ...file,\n PK: this.createPartitionKey(file),\n SK: this.createSortKey(file),\n TYPE: \"fm.file\"\n });\n });\n\n try {\n await batchWriteAll({\n table: this.entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch insert a list of files.\",\n ex.code || \"BATCH_CREATE_FILES_ERROR\",\n {\n error: ex,\n files\n }\n );\n }\n return files;\n }\n\n public async list(\n params: FileManagerFilesStorageOperationsListParams\n ): Promise<FileManagerFilesStorageOperationsListResponse> {\n const { where: initialWhere, limit, after, sort } = params;\n\n const options = this.createQueryAllOptions({\n where: initialWhere\n });\n const queryAllParams = {\n entity: this.entity,\n partitionKey: this.createPartitionKey(initialWhere),\n options\n };\n let items = [];\n try {\n items = await queryAll<File>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query for the files.\",\n ex.code || \"FILE_LIST_ERROR\",\n {\n error: ex,\n where: initialWhere,\n limit,\n after,\n sort,\n queryParams: {\n options,\n partitionKey: queryAllParams.partitionKey,\n entity: queryAllParams.entity.name,\n table: queryAllParams.entity.table.name\n }\n }\n );\n }\n\n const where: Partial<FileManagerFilesStorageOperationsListParamsWhere> & {\n contains?: { fields: string[]; value: string };\n } = {\n ...initialWhere\n };\n if (where.search) {\n where.contains = {\n fields: [\"name\", \"tags\"],\n value: where.search\n };\n }\n delete where[\"tenant\"];\n delete where[\"locale\"];\n delete where[\"search\"];\n\n const fields = this.context.plugins.byType<FileDynamoDbFieldPlugin>(\n FileDynamoDbFieldPlugin.type\n );\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredFiles = filterItems({\n plugins: this.context.plugins,\n items,\n where,\n fields\n });\n\n const totalCount = filteredFiles.length;\n /**\n * Sorting is also done via the code.\n * It takes the sort input and sorts by it via the lodash sortBy method.\n */\n const sortedFiles = sortItems({\n items: filteredFiles,\n sort,\n fields\n });\n\n const start = parseInt(decodeCursor(after) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const files = sortedFiles.slice(start, end);\n /**\n * Although we do not need a cursor here, we will use it as such to keep it standardized.\n * Number is simply encoded.\n */\n const cursor = files.length > 0 ? encodeCursor(start + limit) : null;\n\n const meta = {\n hasMoreItems,\n totalCount: totalCount,\n cursor\n };\n\n return [files, meta];\n }\n public async tags(\n params: FileManagerFilesStorageOperationsTagsParams\n ): Promise<FileManagerFilesStorageOperationsTagsResponse> {\n const { where } = params;\n\n const queryAllParams = {\n entity: this.entity,\n partitionKey: this.createPartitionKey(where),\n options: {\n gte: \" \",\n reverse: false\n }\n };\n let results = [];\n try {\n results = await queryAll<File>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Error in the DynamoDB query.\",\n ex.code || \"DYNAMODB_ERROR\",\n {\n error: ex,\n query: queryAllParams\n }\n );\n }\n /**\n * Aggregate all the tags from all the items in the database.\n */\n const tagsObject = results.reduce((collection, item) => {\n const tags = Array.isArray(item.tags) ? item.tags : [];\n for (const tag of tags) {\n if (!collection[tag]) {\n collection[tag] = [];\n }\n collection[tag].push(item.id);\n }\n return collection;\n }, {} as Record<string, string[]>);\n\n const tags: string[] = Object.keys(tagsObject);\n\n const hasMoreItems = false;\n const totalCount = tags.length;\n\n const meta: FileManagerFilesStorageOperationsListResponseMeta = {\n hasMoreItems,\n totalCount,\n cursor: null\n };\n\n return [tags, meta];\n }\n\n private createQueryAllOptions({ where }: QueryAllOptionsParams): DynamoDBToolboxQueryOptions {\n const options: DynamoDBToolboxQueryOptions = {};\n if (where.id) {\n options.eq = where.id;\n }\n return options;\n }\n\n private createPartitionKey(params: CreatePartitionKeyParams): string {\n const { tenant, locale } = params;\n return `T#${tenant}#L#${locale}#FM#F`;\n }\n\n private createSortKey(params: CreateSortKeyParams) {\n const { id } = params;\n\n return id;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["fields.ts"],"names":["FileDynamoDbFieldPlugin","field","path","type"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,gDAAJ,CAA4B;AACxBC,EAAAA,KAAK,EAAE;AADiB,CAA5B,CADiB;AAIjB;AACJ;AACA;AACI,IAAID,gDAAJ,CAA4B;AACxBC,EAAAA,KAAK,EAAE,WADiB;AAExBC,EAAAA,IAAI,EAAE;AAFkB,CAA5B,CAPiB;AAWjB;AACJ;AACA;AACI,IAAIF,gDAAJ,CAA4B;AACxBC,EAAAA,KAAK,EAAE,SADiB;AAExBC,EAAAA,IAAI,EAAE;AAFkB,CAA5B,CAdiB;AAkBjB;AACJ;AACA;AACI,IAAIF,gDAAJ,CAA4B;AACxBC,EAAAA,KAAK,EAAE,KADiB;AAExBC,EAAAA,IAAI,EAAE;AAFkB,CAA5B,CArBiB;AAyBjB;AACJ;AACA;AACI,IAAIF,gDAAJ,CAA4B;AACxBC,EAAAA,KAAK,EAAE,WADiB;AAExBE,EAAAA,IAAI,EAAE;AAFkB,CAA5B,CA5BiB,C","sourcesContent":["import { FileDynamoDbFieldPlugin } from \"~/plugins/FileDynamoDbFieldPlugin\";\n\nexport default () => [\n new FileDynamoDbFieldPlugin({\n field: \"id\"\n }),\n /**\n * Path plugin for the field that are ddb map type and the value filtered by is the id property in the object.\n */\n new FileDynamoDbFieldPlugin({\n field: \"createdBy\",\n path: \"createdBy.id\"\n }),\n /**\n * Path plugin for meta field properties.\n */\n new FileDynamoDbFieldPlugin({\n field: \"private\",\n path: \"meta.private\"\n }),\n /**\n * Path plugin for tag field.\n */\n new FileDynamoDbFieldPlugin({\n field: \"tag\",\n path: \"tags\"\n }),\n /**\n * Value transformation for the dateTime field.\n */\n new FileDynamoDbFieldPlugin({\n field: \"createdOn\",\n type: \"date\"\n })\n];\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":["FilesStorageOperationsProviderDdb","FilesStorageOperationsProviderPlugin","provide","context","plugins","register","FilesStorageOperations"],"mappings":";;;;;;;;;;;AAAA;;AAIA;;AACA;;AAEO,MAAMA,iCAAN,SAAgDC,0EAAhD,CAAqF;AAAA;AAAA;AAAA,gDACjE,wCADiE;AAAA;;AAE3E,QAAPC,OAAO,CAAC;AAAEC,IAAAA;AAAF,GAAD,EAA0D;AACnEA,IAAAA,OAAO,CAACC,OAAR,CAAgBC,QAAhB,CAAyB,sBAAzB;AACA,WAAO,IAAIC,8CAAJ,CAA2B;AAC9BH,MAAAA;AAD8B,KAA3B,CAAP;AAGH;;AAPuF","sourcesContent":["import {\n FilesStorageOperationsProviderPlugin,\n FilesStorageOperationsProviderPluginParams\n} from \"@webiny/api-file-manager/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport { FilesStorageOperations } from \"./FilesStorageOperations\";\nimport fields from \"./fields\";\n\nexport class FilesStorageOperationsProviderDdb extends FilesStorageOperationsProviderPlugin {\n public override name = \"fm.storageOperationsProvider.files.ddb\";\n async provide({ context }: FilesStorageOperationsProviderPluginParams) {\n context.plugins.register(fields());\n return new FilesStorageOperations({\n context\n });\n }\n}\n"]}
@@ -7,7 +7,7 @@ export declare class SettingsStorageOperations implements FileManagerSettingsSto
7
7
  private readonly _entity;
8
8
  private get partitionKey();
9
9
  constructor({ context }: SettingsStorageOperationsConstructorParams);
10
- get(): Promise<FileManagerSettings>;
10
+ get(): Promise<FileManagerSettings | null>;
11
11
  create({ data }: FileManagerSettingsStorageOperationsCreateParams): Promise<FileManagerSettings>;
12
12
  update({ data }: FileManagerSettingsStorageOperationsUpdateParams): Promise<FileManagerSettings>;
13
13
  delete(): Promise<void>;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["SettingsStorageOperations.ts"],"names":["SORT_KEY","SettingsStorageOperations","partitionKey","tenant","_context","tenancy","getCurrentTenant","WebinyError","id","constructor","context","table","_entity","get","settings","PK","SK","Item","ex","message","code","create","data","original","update","put","delete"],"mappings":";;;;;;;;;;;AAQA;;AACA;;AACA;;;;;;AAMA,MAAMA,QAAQ,GAAG,SAAjB;;AAEO,MAAMC,yBAAN,CAAgF;AAI3D,MAAZC,YAAY,GAAW;AAC/B,UAAMC,MAAM,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CAAaa,GAAb;AACFV,QAAAA,EAAE,EAAE,KAAKb,YADP;AAEFc,QAAAA,EAAE,EAAEhB;AAFF,SAGCsB,IAHD,EAAN;AAKA,aAAOA,IAAP;AACH,KAPD,CAOE,OAAOJ,EAAP,EAAW;AACT,YAAM,IAAIX,cAAJ,CACFW,EAAE,CAACC,OAAH,IAAc,qCADZ,EAEFD,EAAE,CAACE,IAAH,IAAW,0BAFT,EAGF;AACIE,QAAAA;AADJ,OAHE,CAAN;AAOH;AACJ;;AAEkB,QAANE,MAAM,CAAC;AAChBF,IAAAA;AADgB,GAAD,EAEgE;AAC/E,QAAI;AACA,YAAM,KAAKV,OAAL,CAAaY,MAAb;AACFT,QAAAA,EAAE,EAAE,KAAKb,YADP;AAEFc,QAAAA,EAAE,EAAEhB;AAFF,SAGCsB,IAHD,EAAN;AAKA,aAAOA,IAAP;AACH,KAPD,CAOE,OAAOJ,EAAP,EAAW;AACT,YAAM,IAAIX,cAAJ,CACFW,EAAE,CAACC,OAAH,IAAc,qCADZ,EAEFD,EAAE,CAACE,IAAH,IAAW,0BAFT,EAGF;AACIE,QAAAA;AADJ,OAHE,CAAN;AAOH;AACJ;;AAEkB,QAANI,MAAM,GAAkB;AACjC,WAAO,KAAKd,OAAL,CAAac,MAAb,CAAoB;AACvBX,MAAAA,EAAE,EAAE,KAAKb,YADc;AAEvBc,MAAAA,EAAE,EAAEhB;AAFmB,KAApB,CAAP;AAIH;;AAjGkF","sourcesContent":["import {\n FileManagerContext,\n FileManagerSettings,\n FileManagerSettingsStorageOperations,\n FileManagerSettingsStorageOperationsCreateParams,\n FileManagerSettingsStorageOperationsUpdateParams\n} from \"@webiny/api-file-manager/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport defineTable from \"~/definitions/table\";\nimport defineSettingsEntity from \"~/definitions/settingsEntity\";\n\ninterface SettingsStorageOperationsConstructorParams {\n context: FileManagerContext;\n}\n\nconst SORT_KEY = \"default\";\n\nexport class SettingsStorageOperations implements FileManagerSettingsStorageOperations {\n private readonly _context: FileManagerContext;\n private readonly _entity: Entity<any>;\n\n private get partitionKey(): string {\n const tenant = this._context.tenancy.getCurrentTenant();\n if (!tenant) {\n throw new WebinyError(\"Tenant missing.\", \"TENANT_NOT_FOUND\");\n }\n return `T#${tenant.id}#FM#SETTINGS`;\n }\n\n public constructor({ context }: SettingsStorageOperationsConstructorParams) {\n this._context = context;\n const table = defineTable({\n context\n });\n\n this._entity = defineSettingsEntity({\n context,\n table\n });\n }\n\n public async get(): Promise<FileManagerSettings | null> {\n try {\n const settings = await this._entity.get({\n PK: this.partitionKey,\n SK: SORT_KEY\n });\n if (!settings || !settings.Item) {\n return null;\n }\n return settings.Item;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not fetch the FileManager settings.\",\n ex.code || \"GET_SETTINGS_ERROR\"\n );\n }\n }\n\n public async create({\n data\n }: FileManagerSettingsStorageOperationsCreateParams): Promise<FileManagerSettings> {\n const original = await this.get();\n /**\n * TODO: check if need to throw an error on existing settings\n */\n if (original) {\n return await this.update({ original, data });\n }\n\n try {\n await this._entity.put({\n PK: this.partitionKey,\n SK: SORT_KEY,\n ...data\n });\n return data;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Cannot create FileManager settings.\",\n ex.code || \"CREATE_FM_SETTINGS_ERROR\",\n {\n data\n }\n );\n }\n }\n\n public async update({\n data\n }: FileManagerSettingsStorageOperationsUpdateParams): Promise<FileManagerSettings> {\n try {\n await this._entity.update({\n PK: this.partitionKey,\n SK: SORT_KEY,\n ...data\n });\n return data;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Cannot update FileManager settings.\",\n ex.code || \"UPDATE_FM_SETTINGS_ERROR\",\n {\n data\n }\n );\n }\n }\n\n public async delete(): Promise<void> {\n return this._entity.delete({\n PK: this.partitionKey,\n SK: SORT_KEY\n });\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":["SettingsStorageOperationsProviderDdbPlugin","SettingsStorageOperationsProviderPlugin","provide","context","SettingsStorageOperations"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAKO,MAAMA,0CAAN,SAAyDC,gFAAzD,CAAiG;AAAA;AAAA;AAAA,gDAC7E,2CAD6E;AAAA;;AAGhF,QAAPC,OAAO,CAAC;AAAEC,IAAAA;AAAF,GAAD,EAA6D;AAC7E,WAAO,IAAIC,oDAAJ,CAA8B;AACjCD,MAAAA;AADiC,KAA9B,CAAP;AAGH;;AAPmG","sourcesContent":["import { SettingsStorageOperations } from \"./SettingsStorageOperations\";\nimport {\n SettingsStorageOperationsProviderPlugin,\n SettingsStorageOperationsProviderPluginParams\n} from \"@webiny/api-file-manager/plugins/definitions/SettingsStorageOperationsProviderPlugin\";\n\nexport class SettingsStorageOperationsProviderDdbPlugin extends SettingsStorageOperationsProviderPlugin {\n public override name = \"fm.storageOperationsProvider.settings.ddb\";\n\n public async provide({ context }: SettingsStorageOperationsProviderPluginParams) {\n return new SettingsStorageOperations({\n context\n });\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["SystemStorageOperations.ts"],"names":["SORT_KEY","SystemStorageOperations","partitionKey","tenant","_context","tenancy","getCurrentTenant","WebinyError","id","constructor","context","table","_entity","get","system","PK","SK","Item","ex","message","code","create","params","data","put","update","original"],"mappings":";;;;;;;;;;;AAQA;;AACA;;AACA;;;;;;AAMA,MAAMA,QAAQ,GAAG,IAAjB;;AAEO,MAAMC,uBAAN,CAA4E;AAIvD,MAAZC,YAAY,GAAW;AAC/B,UAAMC,MAAM,GAAG,KAAKC,QAAL,CAAcC,OAAd,CAAsBC,gBAAtB,EAAf;;AACA,QAAI,CAACH,MAAL,EAAa;AACT,YAAM,IAAII,cAAJ,CAAgB,iBAAhB,EAAmC,kBAAnC,CAAN;AACH;;AACD,WAAQ,KAAIJ,MAAM,CAACK,EAAG,SAAtB;AACH;;AAEMC,EAAAA,WAAW,CAAC;AAAEC,IAAAA;AA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FV,QAAAA,EAAE,EAAE,KAAKb,YADP;AAEFc,QAAAA,EAAE,EAAEhB;AAFF,SAGCuB,IAHD,EAAN;AAKH,KAND,CAME,OAAOL,EAAP,EAAW;AACT,YAAM,IAAIX,cAAJ,CACF,+CADE,EAEF,qBAFE,EAGF;AACIgB,QAAAA;AADJ,OAHE,CAAN;AAOH;;AACD,2CACOG,QADP,GAEOH,IAFP;AAIH;;AAxF8E","sourcesContent":["import {\n FileManagerContext,\n FileManagerSystem,\n FileManagerSystemStorageOperations,\n FileManagerSystemStorageOperationsCreateParams,\n FileManagerSystemStorageOperationsUpdateParams\n} from \"@webiny/api-file-manager/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport defineSystemEntity from \"~/definitions/systemEntity\";\nimport defineTable from \"~/definitions/table\";\n\ninterface SystemStorageOperationsConstructorParams {\n context: FileManagerContext;\n}\n\nconst SORT_KEY = \"FM\";\n\nexport class SystemStorageOperations implements FileManagerSystemStorageOperations {\n private readonly _context: FileManagerContext;\n private readonly _entity: Entity<any>;\n\n private get partitionKey(): string {\n const tenant = this._context.tenancy.getCurrentTenant();\n if (!tenant) {\n throw new WebinyError(\"Tenant missing.\", \"TENANT_NOT_FOUND\");\n }\n return `T#${tenant.id}#SYSTEM`;\n }\n\n public constructor({ context }: SystemStorageOperationsConstructorParams) {\n this._context = context;\n const table = defineTable({\n context\n });\n\n this._entity = defineSystemEntity({\n context,\n table\n });\n }\n\n public async get(): Promise<FileManagerSystem | null> {\n try {\n const system = await this._entity.get({\n PK: this.partitionKey,\n SK: SORT_KEY\n });\n if (!system || !system.Item) {\n return null;\n }\n return system.Item;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not fetch the FileManager system.\",\n ex.code || \"GET_SYSTEM_ERROR\"\n );\n }\n }\n\n public async create(\n params: FileManagerSystemStorageOperationsCreateParams\n ): Promise<FileManagerSystem> {\n const { data } = params;\n try {\n await this._entity.put({\n PK: this.partitionKey,\n SK: SORT_KEY,\n ...data\n });\n } catch (ex) {\n throw new WebinyError(\n \"Could not insert new system data into DynamoDB\",\n \"CREATE_SYSTEM_ERROR\",\n {\n data\n }\n );\n }\n return data;\n }\n\n public async update(\n params: FileManagerSystemStorageOperationsUpdateParams\n ): Promise<FileManagerSystem> {\n const { original, data } = params;\n\n try {\n await this._entity.update({\n PK: this.partitionKey,\n SK: SORT_KEY,\n ...data\n });\n } catch (ex) {\n throw new WebinyError(\n \"Could not update system data in the DynamoDB.\",\n \"UPDATE_SYSTEM_ERROR\",\n {\n data\n }\n );\n }\n return {\n ...original,\n ...data\n };\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":["SystemStorageOperationsProviderDdbPlugin","SystemStorageOperationsProviderPlugin","provide","context","SystemStorageOperations"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAKO,MAAMA,wCAAN,SAAuDC,4EAAvD,CAA6F;AAAA;AAAA;AAAA,gDACzE,yCADyE;AAAA;;AAE5E,QAAPC,OAAO,CAAC;AAAEC,IAAAA;AAAF,GAAD,EAA2D;AAC3E,WAAO,IAAIC,gDAAJ,CAA4B;AAC/BD,MAAAA;AAD+B,KAA5B,CAAP;AAGH;;AAN+F","sourcesContent":["import { SystemStorageOperations } from \"./SystemStorageOperations\";\nimport {\n SystemStorageOperationsProviderPlugin,\n SystemStorageOperationsProviderPluginParams\n} from \"@webiny/api-file-manager/plugins/definitions/SystemStorageOperationsProviderPlugin\";\n\nexport class SystemStorageOperationsProviderDdbPlugin extends SystemStorageOperationsProviderPlugin {\n public override name = \"fm.storageOperationsProvider.system.ddb\";\n public async provide({ context }: SystemStorageOperationsProviderPluginParams) {\n return new SystemStorageOperations({\n context\n });\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils.ts"],"names":["getDocumentClient","context","driver","db","documentClient","WebinyError","getTable","table"],"mappings":";;;;;;;;;AAAA;;AAIO,MAAMA,iBAAiB,GAAIC,OAAD,IAAiD;AAC9E,QAAMC,MAAM,GAAGD,OAAO,CAACE,EAAR,CAAWD,MAA1B;;AACA,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACE,cAAvB,EAAuC;AACnC,UAAM,IAAIC,cAAJ,CACD,2DADC,EAEF,uBAFE,CAAN;AAIH;;AACD,SAAOH,MAAM,CAACE,cAAd;AACH,CATM;;;;AAWA,MAAME,QAAQ,GAAIL,OAAD,IAAyC;AAC7D,QAAME,EAAE,GAAGF,OAAO,CAACE,EAAnB;;AACA,MAAI,CAACA,EAAL,EAAS;AACL,UAAM,IAAIE,cAAJ,CAAgB,wBAAhB,EAA0C,UAA1C,CAAN;AACH,GAFD,MAEO,IAAI,CAACF,EAAE,CAACI,KAAR,EAAe;AAClB,UAAM,IAAIF,cAAJ,CAAgB,8BAAhB,EAAgD,aAAhD,CAAN;AACH;;AACD,SAAOF,EAAE,CAACI,KAAV;AACH,CARM","sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\n\nexport const getDocumentClient = (context: FileManagerContext): DocumentClient => {\n const driver = context.db.driver as any;\n if (!driver || !driver.documentClient) {\n throw new WebinyError(\n `Missing documentDriver on the context db.driver property.`,\n \"DOCUMENT_CLIENT_ERROR\"\n );\n }\n return driver.documentClient;\n};\n\nexport const getTable = (context: FileManagerContext): string => {\n const db = context.db as any;\n if (!db) {\n throw new WebinyError(\"Missing db on context.\", \"DB_ERROR\");\n } else if (!db.table) {\n throw new WebinyError(\"Missing table on context.db.\", \"TABLE_ERROR\");\n }\n return db.table;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-file-manager-ddb",
3
- "version": "5.24.0",
3
+ "version": "5.25.0-beta.2",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "@webiny/api-file-manager",
@@ -21,12 +21,12 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@babel/runtime": "7.16.7",
25
- "@webiny/api-file-manager": "5.24.0",
26
- "@webiny/db-dynamodb": "5.24.0",
27
- "@webiny/error": "5.24.0",
28
- "@webiny/project-utils": "5.24.0",
29
- "aws-sdk": "2.1066.0",
24
+ "@babel/runtime": "7.17.7",
25
+ "@webiny/api-file-manager": "5.25.0-beta.2",
26
+ "@webiny/db-dynamodb": "5.25.0-beta.2",
27
+ "@webiny/error": "5.25.0-beta.2",
28
+ "@webiny/project-utils": "5.25.0-beta.2",
29
+ "aws-sdk": "2.1095.0",
30
30
  "dynamodb-toolbox": "0.3.5"
31
31
  },
32
32
  "devDependencies": {
@@ -36,13 +36,13 @@
36
36
  "@babel/plugin-transform-runtime": "^7.16.4",
37
37
  "@babel/preset-env": "^7.16.4",
38
38
  "@babel/preset-typescript": "^7.16.0",
39
- "@webiny/cli": "^5.24.0",
39
+ "@webiny/cli": "^5.25.0-beta.2",
40
40
  "jest": "^26.6.3",
41
41
  "jest-dynalite": "^3.2.0",
42
42
  "jsonpack": "^1.1.5",
43
43
  "rimraf": "^3.0.2",
44
44
  "ttypescript": "^1.5.12",
45
- "typescript": "^4.1.3"
45
+ "typescript": "4.5.5"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public",
@@ -63,5 +63,5 @@
63
63
  ]
64
64
  }
65
65
  },
66
- "gitHead": "be0cbfcaa9247c658c44179af7943cc5d6d71bc7"
66
+ "gitHead": "ed2f22976af47aea0b6b5d638f8afdc39951b014"
67
67
  }
@@ -1,4 +1,4 @@
1
- import { AttributePlugin, Params } from "@webiny/db-dynamodb/plugins/definitions/AttributePlugin";
1
+ import { AttributePlugin, AttributePluginParams } from "@webiny/db-dynamodb/plugins/definitions/AttributePlugin";
2
2
  export declare class FileAttributePlugin extends AttributePlugin {
3
- constructor(params: Omit<Params, "entity">);
3
+ constructor(params: Omit<AttributePluginParams, "entity">);
4
4
  }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["FileAttributePlugin.ts"],"names":["FileAttributePlugin","AttributePlugin","constructor","params","entity"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAKO,MAAMA,mBAAN,SAAkCC,gCAAlC,CAAkD;AAC9CC,EAAAA,WAAW,CAACC,MAAD,EAAgD;AAC9D,0CACOA,MADP;AAEIC,MAAAA,MAAM,EAAE;AAFZ;AAIH;;AANoD","sourcesContent":["import {\n AttributePlugin,\n AttributePluginParams\n} from \"@webiny/db-dynamodb/plugins/definitions/AttributePlugin\";\n\nexport class FileAttributePlugin extends AttributePlugin {\n public constructor(params: Omit<AttributePluginParams, \"entity\">) {\n super({\n ...params,\n entity: \"Files\"\n });\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["FileDynamoDbFieldPlugin.ts"],"names":["FileDynamoDbFieldPlugin","FieldPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,uBAAN,SAAsCC,wBAAtC,CAAkD;;;8BAA5CD,uB,UACsC,iC","sourcesContent":["import { FieldPlugin } from \"@webiny/db-dynamodb/plugins/definitions/FieldPlugin\";\n\nexport class FileDynamoDbFieldPlugin extends FieldPlugin {\n public static override readonly type: string = \"fileManager.dynamodb.field.file\";\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { AttributePlugin, Params } from "@webiny/db-dynamodb/plugins/definitions/AttributePlugin";
1
+ import { AttributePlugin, AttributePluginParams } from "@webiny/db-dynamodb/plugins/definitions/AttributePlugin";
2
2
  export declare class SettingsAttributePlugin extends AttributePlugin {
3
- constructor(params: Omit<Params, "entity">);
3
+ constructor(params: Omit<AttributePluginParams, "entity">);
4
4
  }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["SettingsAttributePlugin.ts"],"names":["SettingsAttributePlugin","AttributePlugin","constructor","params","entity"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAKO,MAAMA,uBAAN,SAAsCC,gCAAtC,CAAsD;AAClDC,EAAAA,WAAW,CAACC,MAAD,EAAgD;AAC9D,0CACOA,MADP;AAEIC,MAAAA,MAAM,EAAE;AAFZ;AAIH;;AANwD","sourcesContent":["import {\n AttributePlugin,\n AttributePluginParams\n} from \"@webiny/db-dynamodb/plugins/definitions/AttributePlugin\";\n\nexport class SettingsAttributePlugin extends AttributePlugin {\n public constructor(params: Omit<AttributePluginParams, \"entity\">) {\n super({\n ...params,\n entity: \"Settings\"\n });\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { AttributePlugin, Params } from "@webiny/db-dynamodb/plugins/definitions/AttributePlugin";
1
+ import { AttributePlugin, AttributePluginParams } from "@webiny/db-dynamodb/plugins/definitions/AttributePlugin";
2
2
  export declare class SystemAttributePlugin extends AttributePlugin {
3
- constructor(params: Omit<Params, "entity">);
3
+ constructor(params: Omit<AttributePluginParams, "entity">);
4
4
  }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["SystemAttributePlugin.ts"],"names":["SystemAttributePlugin","AttributePlugin","constructor","params","entity"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAKO,MAAMA,qBAAN,SAAoCC,gCAApC,CAAoD;AAChDC,EAAAA,WAAW,CAACC,MAAD,EAAgD;AAC9D,0CACOA,MADP;AAEIC,MAAAA,MAAM,EAAE;AAFZ;AAIH;;AANsD","sourcesContent":["import {\n AttributePlugin,\n AttributePluginParams\n} from \"@webiny/db-dynamodb/plugins/definitions/AttributePlugin\";\n\nexport class SystemAttributePlugin extends AttributePlugin {\n public constructor(params: Omit<AttributePluginParams, \"entity\">) {\n super({\n ...params,\n entity: \"System\"\n });\n }\n}\n"]}
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}