@webiny/api-headless-cms-ddb 0.0.0-ee-vpcs.549378cf03

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.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/definitions/entry.d.ts +9 -0
  4. package/definitions/entry.js +96 -0
  5. package/definitions/entry.js.map +1 -0
  6. package/definitions/group.d.ts +9 -0
  7. package/definitions/group.js +70 -0
  8. package/definitions/group.js.map +1 -0
  9. package/definitions/model.d.ts +9 -0
  10. package/definitions/model.js +97 -0
  11. package/definitions/model.js.map +1 -0
  12. package/definitions/settings.d.ts +9 -0
  13. package/definitions/settings.js +58 -0
  14. package/definitions/settings.js.map +1 -0
  15. package/definitions/system.d.ts +9 -0
  16. package/definitions/system.js +46 -0
  17. package/definitions/system.js.map +1 -0
  18. package/definitions/table.d.ts +9 -0
  19. package/definitions/table.js +30 -0
  20. package/definitions/table.js.map +1 -0
  21. package/dynamoDb/index.d.ts +2 -0
  22. package/dynamoDb/index.js +20 -0
  23. package/dynamoDb/index.js.map +1 -0
  24. package/dynamoDb/path/plainObject.d.ts +2 -0
  25. package/dynamoDb/path/plainObject.js +40 -0
  26. package/dynamoDb/path/plainObject.js.map +1 -0
  27. package/dynamoDb/storage/date.d.ts +3 -0
  28. package/dynamoDb/storage/date.js +109 -0
  29. package/dynamoDb/storage/date.js.map +1 -0
  30. package/dynamoDb/storage/longText.d.ts +10 -0
  31. package/dynamoDb/storage/longText.js +108 -0
  32. package/dynamoDb/storage/longText.js.map +1 -0
  33. package/dynamoDb/storage/richText.d.ts +2 -0
  34. package/dynamoDb/storage/richText.js +113 -0
  35. package/dynamoDb/storage/richText.js.map +1 -0
  36. package/dynamoDb/transformValue/datetime.d.ts +5 -0
  37. package/dynamoDb/transformValue/datetime.js +52 -0
  38. package/dynamoDb/transformValue/datetime.js.map +1 -0
  39. package/index.d.ts +3 -0
  40. package/index.js +150 -0
  41. package/index.js.map +1 -0
  42. package/operations/entry/dataLoaders.d.ts +42 -0
  43. package/operations/entry/dataLoaders.js +321 -0
  44. package/operations/entry/dataLoaders.js.map +1 -0
  45. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  46. package/operations/entry/filtering/createExpressions.js +217 -0
  47. package/operations/entry/filtering/createExpressions.js.map +1 -0
  48. package/operations/entry/filtering/createFields.d.ts +14 -0
  49. package/operations/entry/filtering/createFields.js +123 -0
  50. package/operations/entry/filtering/createFields.js.map +1 -0
  51. package/operations/entry/filtering/extractSort.d.ts +13 -0
  52. package/operations/entry/filtering/extractSort.js +55 -0
  53. package/operations/entry/filtering/extractSort.js.map +1 -0
  54. package/operations/entry/filtering/filter.d.ts +15 -0
  55. package/operations/entry/filtering/filter.js +178 -0
  56. package/operations/entry/filtering/filter.js.map +1 -0
  57. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  58. package/operations/entry/filtering/fullTextSearch.js +60 -0
  59. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  60. package/operations/entry/filtering/getValue.d.ts +5 -0
  61. package/operations/entry/filtering/getValue.js +81 -0
  62. package/operations/entry/filtering/getValue.js.map +1 -0
  63. package/operations/entry/filtering/index.d.ts +2 -0
  64. package/operations/entry/filtering/index.js +21 -0
  65. package/operations/entry/filtering/index.js.map +1 -0
  66. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  67. package/operations/entry/filtering/mapPlugins.js +39 -0
  68. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  69. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  70. package/operations/entry/filtering/plugins/defaultFilterCreate.js +48 -0
  71. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  72. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  73. package/operations/entry/filtering/plugins/index.js +18 -0
  74. package/operations/entry/filtering/plugins/index.js.map +1 -0
  75. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  76. package/operations/entry/filtering/plugins/objectFilterCreate.js +107 -0
  77. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  78. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
  79. package/operations/entry/filtering/plugins/refFilterCreate.js +89 -0
  80. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  81. package/operations/entry/filtering/sort.d.ts +9 -0
  82. package/operations/entry/filtering/sort.js +80 -0
  83. package/operations/entry/filtering/sort.js.map +1 -0
  84. package/operations/entry/filtering/systemFields.d.ts +4 -0
  85. package/operations/entry/filtering/systemFields.js +72 -0
  86. package/operations/entry/filtering/systemFields.js.map +1 -0
  87. package/operations/entry/filtering/transform.d.ts +6 -0
  88. package/operations/entry/filtering/transform.js +19 -0
  89. package/operations/entry/filtering/transform.js.map +1 -0
  90. package/operations/entry/filtering/types.d.ts +40 -0
  91. package/operations/entry/filtering/types.js +5 -0
  92. package/operations/entry/filtering/types.js.map +1 -0
  93. package/operations/entry/filtering/values.d.ts +2 -0
  94. package/operations/entry/filtering/values.js +28 -0
  95. package/operations/entry/filtering/values.js.map +1 -0
  96. package/operations/entry/filtering/where.d.ts +5 -0
  97. package/operations/entry/filtering/where.js +38 -0
  98. package/operations/entry/filtering/where.js.map +1 -0
  99. package/operations/entry/index.d.ts +8 -0
  100. package/operations/entry/index.js +872 -0
  101. package/operations/entry/index.js.map +1 -0
  102. package/operations/entry/keys.d.ts +25 -0
  103. package/operations/entry/keys.js +73 -0
  104. package/operations/entry/keys.js.map +1 -0
  105. package/operations/entry/systemFields.d.ts +2 -0
  106. package/operations/entry/systemFields.js +74 -0
  107. package/operations/entry/systemFields.js.map +1 -0
  108. package/operations/group/index.d.ts +9 -0
  109. package/operations/group/index.js +192 -0
  110. package/operations/group/index.js.map +1 -0
  111. package/operations/model/index.d.ts +7 -0
  112. package/operations/model/index.js +162 -0
  113. package/operations/model/index.js.map +1 -0
  114. package/operations/settings/index.d.ts +7 -0
  115. package/operations/settings/index.js +135 -0
  116. package/operations/settings/index.js.map +1 -0
  117. package/operations/system/index.d.ts +7 -0
  118. package/operations/system/index.js +99 -0
  119. package/operations/system/index.js.map +1 -0
  120. package/package.json +60 -0
  121. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +22 -0
  122. package/plugins/CmsEntryFieldFilterPathPlugin.js +55 -0
  123. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
  124. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  125. package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
  126. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  127. package/plugins/index.d.ts +1 -0
  128. package/plugins/index.js +18 -0
  129. package/plugins/index.js.map +1 -0
  130. package/types.d.ts +53 -0
  131. package/types.js +16 -0
  132. package/types.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createType","createLatestType","createPublishedType","convertToStorageEntry","params","model","storageEntry","values","convertValueKeyToStorage","fields","convertFromStorageEntry","convertValueKeyFromStorage","createEntriesStorageOperations","entity","plugins","dataLoaders","DataLoadersHandler","storageTransformPlugins","byType","StorageTransformPlugin","type","reduce","collection","plugin","fieldType","createStorageTransformCallable","field","value","fromStorage","getStoragePlugin","create","entry","initialStorageEntry","partitionKey","createPartitionKey","id","locale","tenant","isPublished","status","locked","items","putBatch","PK","SK","createRevisionSortKey","TYPE","GSI1_PK","createGSIPartitionKey","GSI1_SK","createGSISortKey","createLatestSortKey","push","createPublishedSortKey","batchWriteAll","table","clearAll","ex","WebinyError","message","code","error","createRevisionFrom","update","latestStorageEntry","getLatestRevisionByEntryId","deleteEntry","queryAllParams","options","gte","records","queryAll","map","item","deleteBatch","deleteRevision","latestEntry","initialLatestStorageEntry","publishedStorageEntry","getPublishedRevisionByEntryId","ids","shift","getRevisionById","getRevisions","getAllEntryRevisions","getByIds","getLatestByIds","getPublishedByIds","getPreviousRevision","entryId","version","queryParams","lt","zeroPad","filters","attr","eq","reverse","result","queryOne","cleanupItem","list","limit","initialLimit","where","initialWhere","after","sort","sortBy","search","published","index","storageEntries","length","hasMoreItems","totalCount","cursor","modelFields","createFields","Promise","all","fieldId","filteredItems","filter","fullTextSearch","term","sortedItems","start","parseInt","decodeCursor","end","undefined","slicedItems","slice","encodeCursor","cleanupItems","get","publish","initialPublishedStorageEntry","CONTENT_ENTRY_STATUS","UNPUBLISHED","unpublish","delete"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { DataLoadersHandler } from \"./dataLoaders\";\nimport {\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryStorageOperations,\n CmsEntryStorageOperationsCreateParams,\n CmsEntryStorageOperationsCreateRevisionFromParams,\n CmsEntryStorageOperationsDeleteParams,\n CmsEntryStorageOperationsDeleteRevisionParams,\n CmsEntryStorageOperationsGetByIdsParams,\n CmsEntryStorageOperationsGetLatestByIdsParams,\n CmsEntryStorageOperationsGetLatestRevisionParams,\n CmsEntryStorageOperationsGetParams,\n CmsEntryStorageOperationsGetPreviousRevisionParams,\n CmsEntryStorageOperationsGetPublishedByIdsParams,\n CmsEntryStorageOperationsGetRevisionParams,\n CmsEntryStorageOperationsGetRevisionsParams,\n CmsEntryStorageOperationsListParams,\n CmsEntryStorageOperationsPublishParams,\n CmsEntryStorageOperationsUnpublishParams,\n CmsEntryStorageOperationsUpdateParams,\n StorageOperationsCmsModel,\n CONTENT_ENTRY_STATUS,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport {\n createGSIPartitionKey,\n createGSISortKey,\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"~/operations/entry/keys\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport {\n queryAll,\n QueryAllParams,\n queryOne,\n QueryOneParams\n} from \"@webiny/db-dynamodb/utils/query\";\nimport { cleanupItem, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { decodeCursor, encodeCursor } from \"@webiny/utils/cursor\";\nimport { zeroPad } from \"@webiny/utils/zeroPad\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\nimport { FilterItemFromStorage } from \"./filtering/types\";\nimport { createFields } from \"~/operations/entry/filtering/createFields\";\nimport { filter, sort } from \"~/operations/entry/filtering\";\n\nconst createType = (): string => {\n return \"cms.entry\";\n};\nconst createLatestType = (): string => {\n return `${createType()}.l`;\n};\nconst createPublishedType = (): string => {\n return `${createType()}.p`;\n};\n\ninterface ConvertStorageEntryParams {\n storageEntry: CmsStorageEntry;\n model: StorageOperationsCmsModel;\n}\nconst convertToStorageEntry = (params: ConvertStorageEntryParams): CmsStorageEntry => {\n const { model, storageEntry } = params;\n\n const values = model.convertValueKeyToStorage({\n fields: model.fields,\n values: storageEntry.values\n });\n return {\n ...storageEntry,\n values\n };\n};\n\nconst convertFromStorageEntry = (params: ConvertStorageEntryParams): CmsStorageEntry => {\n const { model, storageEntry } = params;\n\n const values = model.convertValueKeyFromStorage({\n fields: model.fields,\n values: storageEntry.values\n });\n return {\n ...storageEntry,\n values\n };\n};\n\nexport interface CreateEntriesStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createEntriesStorageOperations = (\n params: CreateEntriesStorageOperationsParams\n): CmsEntryStorageOperations => {\n const { entity, plugins } = params;\n\n const dataLoaders = new DataLoadersHandler({\n entity\n });\n\n const storageTransformPlugins = plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n .reduce((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n const createStorageTransformCallable = (\n model: StorageOperationsCmsModel\n ): FilterItemFromStorage => {\n return (field, value) => {\n const plugin: StorageTransformPlugin = storageTransformPlugins[field.type];\n if (!plugin) {\n return value;\n }\n return plugin.fromStorage({\n model,\n field,\n value,\n getStoragePlugin(fieldType: string): StorageTransformPlugin {\n return storageTransformPlugins[fieldType] || storageTransformPlugins[\"*\"];\n },\n plugins\n });\n };\n };\n\n const create = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsCreateParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const isPublished = entry.status === \"published\";\n\n const locked = isPublished ? true : entry.locked;\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to:\n * - create new main entry item\n * - create new or update latest entry item\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n\n /**\n * We need to create published entry if\n */\n if (isPublished) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert data into the DynamoDB.\",\n ex.code || \"CREATE_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n\n return initialStorageEntry;\n };\n\n const createRevisionFrom = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsCreateRevisionFromParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const storageEntry = convertToStorageEntry({\n storageEntry: initialStorageEntry,\n model\n });\n /**\n * We need to:\n * - create the main entry item\n * - update the last entry item to a current one\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create revision from given entry.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n /**\n * There are no modifications on the entry created so just return the data.\n */\n return initialStorageEntry;\n };\n\n const update = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsUpdateParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const items = [];\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to:\n * - update the current entry\n * - update the latest entry if the current entry is the latest one\n */\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n\n if (isPublished) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n }\n\n /**\n * We need the latest entry to update it as well if neccessary.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry.\",\n ex.code || \"UPDATE_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry\n }\n );\n }\n };\n\n const deleteEntry = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsDeleteParams\n ) => {\n const { entry } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n }),\n options: {\n gte: \" \"\n }\n };\n\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load all records.\",\n ex.code || \"LOAD_ALL_RECORDS_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n const items = records.map(item => {\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete the entry.\",\n ex.code || \"DELETE_ENTRY_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n entry\n }\n );\n }\n };\n\n const deleteRevision = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsDeleteRevisionParams\n ) => {\n const { entry, latestEntry, latestStorageEntry: initialLatestStorageEntry } = params;\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createRevisionSortKey(entry)\n })\n ];\n\n const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n\n /**\n * If revision we are deleting is the published one as well, we need to delete those records as well.\n */\n if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {\n items.push(\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n if (initialLatestStorageEntry) {\n const latestStorageEntry = convertToStorageEntry({\n storageEntry: initialLatestStorageEntry,\n model\n });\n items.push(\n entity.putBatch({\n ...latestStorageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(latestStorageEntry)\n })\n );\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, {\n error: ex,\n entry,\n latestEntry\n });\n }\n };\n\n const getLatestRevisionByEntryId = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const items = await dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n const getPublishedRevisionByEntryId = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const items = await dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n\n const getRevisionById = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetRevisionParams\n ) => {\n const items = await dataLoaders.getRevisionById({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n\n const getRevisions = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetRevisionsParams\n ) => {\n const items = await dataLoaders.getAllEntryRevisions({\n model,\n ids: [params.id]\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetByIdsParams\n ) => {\n const items = await dataLoaders.getRevisionById({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getLatestByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestByIdsParams\n ) => {\n const items = await dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getPublishedByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetPublishedByIdsParams\n ) => {\n const items = await dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getPreviousRevision = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ) => {\n const { entryId, version } = params;\n const queryParams: QueryOneParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant: model.tenant,\n locale: model.locale,\n id: entryId\n }),\n options: {\n lt: `REV#${zeroPad(version)}`,\n /**\n * We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.\n */\n filters: [\n {\n attr: \"TYPE\",\n eq: createType()\n },\n {\n attr: \"version\",\n lt: version\n }\n ],\n reverse: true\n }\n };\n\n try {\n const result = await queryOne<CmsEntry>(queryParams);\n\n const storageEntry = cleanupItem(entity, result);\n if (!storageEntry) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry,\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get previous version of given entry.\",\n ex.code || \"GET_PREVIOUS_VERSION_ERROR\",\n {\n ...params,\n error: ex,\n partitionKey: queryParams.partitionKey,\n options: queryParams.options,\n model\n }\n );\n }\n };\n\n const list = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsListParams\n ) => {\n const {\n limit: initialLimit = 10,\n where: initialWhere,\n after,\n sort: sortBy,\n fields,\n search\n } = params;\n const limit = initialLimit <= 0 || initialLimit >= 10000 ? 10000 : initialLimit;\n\n const type = initialWhere.published ? \"P\" : \"L\";\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createGSIPartitionKey(model, type),\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n };\n let storageEntries: CmsStorageEntry[] = [];\n try {\n storageEntries = await queryAll<CmsStorageEntry>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(ex.message, \"QUERY_ENTRIES_ERROR\", {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n });\n }\n if (storageEntries.length === 0) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n delete where[\"published\"];\n delete where[\"latest\"];\n /**\n * We need an object containing field, transformers and paths.\n * Just build it here and pass on into other methods that require it to avoid mapping multiple times.\n */\n const modelFields = createFields({\n plugins,\n fields: model.fields\n });\n\n const fromStorage = createStorageTransformCallable(model);\n /**\n * Let's transform records from storage ones to regular ones, so we do not need to do it later.\n *\n * This is always being done, but at least its in parallel.\n */\n const records = await Promise.all(\n storageEntries.map(async storageEntry => {\n const entry = convertFromStorageEntry({\n storageEntry,\n model\n });\n\n for (const field of model.fields) {\n entry.values[field.fieldId] = await fromStorage(\n field,\n entry.values[field.fieldId]\n );\n }\n\n return entry as CmsEntry;\n })\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 filteredItems = filter({\n items: records,\n where,\n plugins,\n fields: modelFields,\n fullTextSearch: {\n term: search,\n fields: fields || []\n }\n });\n\n const totalCount = filteredItems.length;\n\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 sortedItems = sort({\n items: filteredItems,\n sort: sortBy,\n fields: modelFields\n });\n\n const start = parseInt((decodeCursor(after) as string) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const slicedItems = sortedItems.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 = totalCount > start + limit ? encodeCursor(`${start + limit}`) : null;\n return {\n hasMoreItems,\n totalCount,\n cursor,\n items: cleanupItems(entity, slicedItems)\n };\n };\n\n const get = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetParams\n ) => {\n const { items } = await list(model, {\n ...params,\n limit: 1\n });\n return items.shift() || null;\n };\n\n const publish = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsPublishParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n /**\n * We need the latest and published entries to see if something needs to be updated along side the publishing one.\n */\n const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to update:\n * - current entry revision sort key\n * - published sort key\n * - latest sort key - if entry updated is actually latest\n * - previous published entry to unpublished status - if any previously published entry\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {\n const publishedStorageEntry = convertToStorageEntry({\n storageEntry: initialPublishedStorageEntry,\n model\n });\n items.push(\n entity.putBatch({\n ...publishedStorageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(publishedStorageEntry),\n TYPE: createType(),\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED,\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(publishedStorageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute the publishing batch.\",\n ex.code || \"PUBLISH_ERROR\",\n {\n entry,\n latestStorageEntry: initialLatestStorageEntry,\n publishedStorageEntry: initialPublishedStorageEntry\n }\n );\n }\n };\n\n const unpublish = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsUnpublishParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const storageEntry = convertToStorageEntry({\n storageEntry: initialStorageEntry,\n model\n });\n /**\n * We need to:\n * - delete currently published entry\n * - update current entry revision with new data\n * - update latest entry status - if entry being unpublished is latest\n */\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the unpublishing one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && entry.id === latestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute unpublish batch.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n };\n\n return {\n create,\n createRevisionFrom,\n update,\n delete: deleteEntry,\n deleteRevision,\n getPreviousRevision,\n getPublishedByIds,\n getLatestByIds,\n getByIds,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId,\n get,\n getRevisions,\n publish,\n list,\n unpublish\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAyBA;;AAQA;;AACA;;AAMA;;AAEA;;AACA;;AACA;;AAEA;;AACA;;AAEA,MAAMA,UAAU,GAAG,MAAc;EAC7B,OAAO,WAAP;AACH,CAFD;;AAGA,MAAMC,gBAAgB,GAAG,MAAc;EACnC,OAAQ,GAAED,UAAU,EAAG,IAAvB;AACH,CAFD;;AAGA,MAAME,mBAAmB,GAAG,MAAc;EACtC,OAAQ,GAAEF,UAAU,EAAG,IAAvB;AACH,CAFD;;AAQA,MAAMG,qBAAqB,GAAIC,MAAD,IAAwD;EAClF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gBHpC,IAhBG;IAiBHwC;EAjBG,CAAP;AAmBH,CA14BM"}
@@ -0,0 +1,25 @@
1
+ interface BasePartitionKeyParams {
2
+ tenant: string;
3
+ locale: string;
4
+ }
5
+ export interface PartitionKeyParams extends BasePartitionKeyParams {
6
+ id: string;
7
+ }
8
+ export declare const createPartitionKey: (params: PartitionKeyParams) => string;
9
+ export interface SortKeyParams {
10
+ version: number;
11
+ }
12
+ export declare const createRevisionSortKey: (params: SortKeyParams) => string;
13
+ export declare const createLatestSortKey: () => string;
14
+ export declare const createPublishedSortKey: () => string;
15
+ export interface GSIPartitionKeyParams {
16
+ tenant: string;
17
+ locale: string;
18
+ modelId: string;
19
+ }
20
+ export declare const createGSIPartitionKey: (params: GSIPartitionKeyParams, type: "A" | "L" | "P") => string;
21
+ export interface GSISortKeyParams {
22
+ id: string;
23
+ }
24
+ export declare const createGSISortKey: (params: GSISortKeyParams) => string;
25
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createRevisionSortKey = exports.createPublishedSortKey = exports.createPartitionKey = exports.createLatestSortKey = exports.createGSISortKey = exports.createGSIPartitionKey = void 0;
9
+
10
+ var _utils = require("@webiny/utils");
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ const createBasePartitionKey = params => {
15
+ const {
16
+ tenant,
17
+ locale
18
+ } = params;
19
+
20
+ if (!tenant) {
21
+ throw new _error.default(`Missing tenant variable when creating entry basePartitionKey`);
22
+ } else if (!locale) {
23
+ throw new _error.default(`Missing tenant variable when creating entry basePartitionKey`);
24
+ }
25
+
26
+ return `T#${tenant}#L#${locale}#CMS#CME`;
27
+ };
28
+
29
+ const createPartitionKey = params => {
30
+ const {
31
+ id: initialId
32
+ } = params;
33
+ const {
34
+ id
35
+ } = (0, _utils.parseIdentifier)(initialId);
36
+ return `${createBasePartitionKey(params)}#CME#${id}`;
37
+ };
38
+
39
+ exports.createPartitionKey = createPartitionKey;
40
+
41
+ const createRevisionSortKey = params => {
42
+ return `REV#${(0, _utils.zeroPad)(params.version)}`;
43
+ };
44
+
45
+ exports.createRevisionSortKey = createRevisionSortKey;
46
+
47
+ const createLatestSortKey = () => {
48
+ return "L";
49
+ };
50
+
51
+ exports.createLatestSortKey = createLatestSortKey;
52
+
53
+ const createPublishedSortKey = () => {
54
+ return "P";
55
+ };
56
+
57
+ exports.createPublishedSortKey = createPublishedSortKey;
58
+
59
+ const createGSIPartitionKey = (params, type) => {
60
+ const {
61
+ modelId
62
+ } = params;
63
+ const partitionKey = createBasePartitionKey(params);
64
+ return `${partitionKey}#M#${modelId}#${type}`;
65
+ };
66
+
67
+ exports.createGSIPartitionKey = createGSIPartitionKey;
68
+
69
+ const createGSISortKey = params => {
70
+ return params.id;
71
+ };
72
+
73
+ exports.createGSISortKey = createGSISortKey;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createBasePartitionKey","params","tenant","locale","WebinyError","createPartitionKey","id","initialId","parseIdentifier","createRevisionSortKey","zeroPad","version","createLatestSortKey","createPublishedSortKey","createGSIPartitionKey","type","modelId","partitionKey","createGSISortKey"],"sources":["keys.ts"],"sourcesContent":["import { parseIdentifier, zeroPad } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\n\ninterface BasePartitionKeyParams {\n tenant: string;\n locale: string;\n}\nconst createBasePartitionKey = (params: BasePartitionKeyParams): string => {\n const { tenant, locale } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating entry basePartitionKey`);\n } else if (!locale) {\n throw new WebinyError(`Missing tenant variable when creating entry basePartitionKey`);\n }\n return `T#${tenant}#L#${locale}#CMS#CME`;\n};\n\nexport interface PartitionKeyParams extends BasePartitionKeyParams {\n id: string;\n}\nexport const createPartitionKey = (params: PartitionKeyParams): string => {\n const { id: initialId } = params;\n const { id } = parseIdentifier(initialId);\n return `${createBasePartitionKey(params)}#CME#${id}`;\n};\n\nexport interface SortKeyParams {\n version: number;\n}\nexport const createRevisionSortKey = (params: SortKeyParams): string => {\n return `REV#${zeroPad(params.version)}`;\n};\n\nexport const createLatestSortKey = (): string => {\n return \"L\";\n};\n\nexport const createPublishedSortKey = (): string => {\n return \"P\";\n};\n\nexport interface GSIPartitionKeyParams {\n tenant: string;\n locale: string;\n modelId: string;\n}\nexport const createGSIPartitionKey = (params: GSIPartitionKeyParams, type: \"A\" | \"L\" | \"P\") => {\n const { modelId } = params;\n const partitionKey = createBasePartitionKey(params);\n return `${partitionKey}#M#${modelId}#${type}`;\n};\n\nexport interface GSISortKeyParams {\n id: string;\n}\nexport const createGSISortKey = (params: GSISortKeyParams): string => {\n return params.id;\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAMA,MAAMA,sBAAsB,GAAIC,MAAD,IAA4C;EACvE,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;;EACA,IAAI,CAACC,MAAL,EAAa;IACT,MAAM,IAAIE,cAAJ,CAAiB,8DAAjB,CAAN;EACH,CAFD,MAEO,IAAI,CAACD,MAAL,EAAa;IAChB,MAAM,IAAIC,cAAJ,CAAiB,8DAAjB,CAAN;EACH;;EACD,OAAQ,KAAIF,MAAO,MAAKC,MAAO,UAA/B;AACH,CARD;;AAaO,MAAME,kBAAkB,GAAIJ,MAAD,IAAwC;EACtE,MAAM;IAAEK,EAAE,EAAEC;EAAN,IAAoBN,MAA1B;EACA,MAAM;IAAEK;EAAF,IAAS,IAAAE,sBAAA,EAAgBD,SAAhB,CAAf;EACA,OAAQ,GAAEP,sBAAsB,CAACC,MAAD,CAAS,QAAOK,EAAG,EAAnD;AACH,CAJM;;;;AASA,MAAMG,qBAAqB,GAAIR,MAAD,IAAmC;EACpE,OAAQ,OAAM,IAAAS,cAAA,EAAQT,MAAM,CAACU,OAAf,CAAwB,EAAtC;AACH,CAFM;;;;AAIA,MAAMC,mBAAmB,GAAG,MAAc;EAC7C,OAAO,GAAP;AACH,CAFM;;;;AAIA,MAAMC,sBAAsB,GAAG,MAAc;EAChD,OAAO,GAAP;AACH,CAFM;;;;AASA,MAAMC,qBAAqB,GAAG,CAACb,MAAD,EAAgCc,IAAhC,KAA0D;EAC3F,MAAM;IAAEC;EAAF,IAAcf,MAApB;EACA,MAAMgB,YAAY,GAAGjB,sBAAsB,CAACC,MAAD,CAA3C;EACA,OAAQ,GAAEgB,YAAa,MAAKD,OAAQ,IAAGD,IAAK,EAA5C;AACH,CAJM;;;;AASA,MAAMG,gBAAgB,GAAIjB,MAAD,IAAsC;EAClE,OAAOA,MAAM,CAACK,EAAd;AACH,CAFM"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "@webiny/api-headless-cms/types";
2
+ export declare const systemFields: Record<string, CmsModelField>;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.systemFields = void 0;
7
+
8
+ const createSystemField = field => {
9
+ return field;
10
+ };
11
+
12
+ const systemFields = {
13
+ id: createSystemField({
14
+ id: "id",
15
+ type: "text",
16
+ storageId: "id",
17
+ fieldId: "id"
18
+ }),
19
+ entryId: createSystemField({
20
+ id: "entryId",
21
+ type: "text",
22
+ storageId: "entryId",
23
+ fieldId: "entryId"
24
+ }),
25
+ createdOn: createSystemField({
26
+ id: "createdOn",
27
+ type: "datetime",
28
+ storageId: "createdOn",
29
+ fieldId: "createdOn"
30
+ }),
31
+ savedOn: createSystemField({
32
+ id: "savedOn",
33
+ type: "datetime",
34
+ storageId: "savedOn",
35
+ fieldId: "savedOn"
36
+ }),
37
+ createdBy: createSystemField({
38
+ id: "createdBy",
39
+ type: "plainObject",
40
+ storageId: "createdBy",
41
+ fieldId: "createdBy",
42
+ settings: {
43
+ path: "createdBy.id"
44
+ }
45
+ }),
46
+ meta: createSystemField({
47
+ id: "meta",
48
+ type: "plainObject",
49
+ storageId: "meta",
50
+ fieldId: "meta"
51
+ }),
52
+ ownedBy: createSystemField({
53
+ id: "ownedBy",
54
+ type: "plainObject",
55
+ storageId: "ownedBy",
56
+ fieldId: "ownedBy",
57
+ settings: {
58
+ path: "ownedBy.id"
59
+ }
60
+ }),
61
+ version: createSystemField({
62
+ id: "version",
63
+ type: "number",
64
+ storageId: "version",
65
+ fieldId: "version"
66
+ }),
67
+ status: createSystemField({
68
+ id: "status",
69
+ type: "string",
70
+ storageId: "status",
71
+ fieldId: "status"
72
+ })
73
+ };
74
+ exports.systemFields = systemFields;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSystemField","field","systemFields","id","type","storageId","fieldId","entryId","createdOn","savedOn","createdBy","settings","path","meta","ownedBy","version","status"],"sources":["systemFields.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\ntype CmsModelFieldInput = Partial<CmsModelField> &\n Pick<CmsModelField, \"id\" | \"type\" | \"storageId\" | \"fieldId\">;\nconst createSystemField = (field: CmsModelFieldInput): CmsModelField => {\n return field as CmsModelField;\n};\n\nexport const systemFields: Record<string, CmsModelField> = {\n id: createSystemField({\n id: \"id\",\n type: \"text\",\n storageId: \"id\",\n fieldId: \"id\"\n }),\n entryId: createSystemField({\n id: \"entryId\",\n type: \"text\",\n storageId: \"entryId\",\n fieldId: \"entryId\"\n }),\n createdOn: createSystemField({\n id: \"createdOn\",\n type: \"datetime\",\n storageId: \"createdOn\",\n fieldId: \"createdOn\"\n }),\n savedOn: createSystemField({\n id: \"savedOn\",\n type: \"datetime\",\n storageId: \"savedOn\",\n fieldId: \"savedOn\"\n }),\n createdBy: createSystemField({\n id: \"createdBy\",\n type: \"plainObject\",\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n settings: {\n path: \"createdBy.id\"\n }\n }),\n meta: createSystemField({\n id: \"meta\",\n type: \"plainObject\",\n storageId: \"meta\",\n fieldId: \"meta\"\n }),\n ownedBy: createSystemField({\n id: \"ownedBy\",\n type: \"plainObject\",\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n settings: {\n path: \"ownedBy.id\"\n }\n }),\n version: createSystemField({\n id: \"version\",\n type: \"number\",\n storageId: \"version\",\n fieldId: \"version\"\n }),\n status: createSystemField({\n id: \"status\",\n type: \"string\",\n storageId: \"status\",\n fieldId: \"status\"\n })\n};\n"],"mappings":";;;;;;;AAIA,MAAMA,iBAAiB,GAAIC,KAAD,IAA8C;EACpE,OAAOA,KAAP;AACH,CAFD;;AAIO,MAAMC,YAA2C,GAAG;EACvDC,EAAE,EAAEH,iBAAiB,CAAC;IAClBG,EAAE,EAAE,IADc;IAElBC,IAAI,EAAE,MAFY;IAGlBC,SAAS,EAAE,IAHO;IAIlBC,OAAO,EAAE;EAJS,CAAD,CADkC;EAOvDC,OAAO,EAAEP,iBAAiB,CAAC;IACvBG,EAAE,EAAE,SADmB;IAEvBC,IAAI,EAAE,MAFiB;IAGvBC,SAAS,EAAE,SAHY;IAIvBC,OAAO,EAAE;EAJc,CAAD,CAP6B;EAavDE,SAAS,EAAER,iBAAiB,CAAC;IACzBG,EAAE,EAAE,WADqB;IAEzBC,IAAI,EAAE,UAFmB;IAGzBC,SAAS,EAAE,WAHc;IAIzBC,OAAO,EAAE;EAJgB,CAAD,CAb2B;EAmBvDG,OAAO,EAAET,iBAAiB,CAAC;IACvBG,EAAE,EAAE,SADmB;IAEvBC,IAAI,EAAE,UAFiB;IAGvBC,SAAS,EAAE,SAHY;IAIvBC,OAAO,EAAE;EAJc,CAAD,CAnB6B;EAyBvDI,SAAS,EAAEV,iBAAiB,CAAC;IACzBG,EAAE,EAAE,WADqB;IAEzBC,IAAI,EAAE,aAFmB;IAGzBC,SAAS,EAAE,WAHc;IAIzBC,OAAO,EAAE,WAJgB;IAKzBK,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA;EALe,CAAD,CAzB2B;EAkCvDC,IAAI,EAAEb,iBAAiB,CAAC;IACpBG,EAAE,EAAE,MADgB;IAEpBC,IAAI,EAAE,aAFc;IAGpBC,SAAS,EAAE,MAHS;IAIpBC,OAAO,EAAE;EAJW,CAAD,CAlCgC;EAwCvDQ,OAAO,EAAEd,iBAAiB,CAAC;IACvBG,EAAE,EAAE,SADmB;IAEvBC,IAAI,EAAE,aAFiB;IAGvBC,SAAS,EAAE,SAHY;IAIvBC,OAAO,EAAE,SAJc;IAKvBK,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA;EALa,CAAD,CAxC6B;EAiDvDG,OAAO,EAAEf,iBAAiB,CAAC;IACvBG,EAAE,EAAE,SADmB;IAEvBC,IAAI,EAAE,QAFiB;IAGvBC,SAAS,EAAE,SAHY;IAIvBC,OAAO,EAAE;EAJc,CAAD,CAjD6B;EAuDvDU,MAAM,EAAEhB,iBAAiB,CAAC;IACtBG,EAAE,EAAE,QADkB;IAEtBC,IAAI,EAAE,QAFgB;IAGtBC,SAAS,EAAE,QAHW;IAItBC,OAAO,EAAE;EAJa,CAAD;AAvD8B,CAApD"}
@@ -0,0 +1,9 @@
1
+ import { CmsGroupStorageOperations } from "@webiny/api-headless-cms/types";
2
+ import { Entity } from "dynamodb-toolbox";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ interface CreateGroupsStorageOperationsParams {
5
+ entity: Entity<any>;
6
+ plugins: PluginsContainer;
7
+ }
8
+ export declare const createGroupsStorageOperations: (params: CreateGroupsStorageOperationsParams) => CmsGroupStorageOperations;
9
+ export {};
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createGroupsStorageOperations = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _get = require("@webiny/db-dynamodb/utils/get");
15
+
16
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
+
18
+ var _query = require("@webiny/db-dynamodb/utils/query");
19
+
20
+ var _filter = require("@webiny/db-dynamodb/utils/filter");
21
+
22
+ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
23
+
24
+ var _sort = require("@webiny/db-dynamodb/utils/sort");
25
+
26
+ const createPartitionKey = params => {
27
+ const {
28
+ tenant,
29
+ locale
30
+ } = params;
31
+ return `T#${tenant}#L#${locale}#CMS#CMG`;
32
+ };
33
+
34
+ const createSortKeys = params => {
35
+ const {
36
+ id
37
+ } = params;
38
+ return id;
39
+ };
40
+
41
+ const createKeys = params => {
42
+ return {
43
+ PK: createPartitionKey(params),
44
+ SK: createSortKeys(params)
45
+ };
46
+ };
47
+
48
+ const createType = () => {
49
+ return "cms.group";
50
+ };
51
+
52
+ const createGroupsStorageOperations = params => {
53
+ const {
54
+ entity,
55
+ plugins
56
+ } = params;
57
+ const filteringPlugins = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type);
58
+
59
+ if (filteringPlugins.length === 0) {
60
+ throw new _error.default("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
61
+ }
62
+
63
+ const create = async params => {
64
+ const {
65
+ group
66
+ } = params;
67
+ const keys = createKeys(group);
68
+
69
+ try {
70
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
71
+ TYPE: createType()
72
+ }, keys));
73
+ return group;
74
+ } catch (ex) {
75
+ throw new _error.default(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
76
+ error: ex,
77
+ group,
78
+ keys
79
+ });
80
+ }
81
+ };
82
+
83
+ const update = async params => {
84
+ const {
85
+ group
86
+ } = params;
87
+ const keys = createKeys(group);
88
+
89
+ try {
90
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
91
+ TYPE: createType()
92
+ }, keys));
93
+ return group;
94
+ } catch (ex) {
95
+ throw new _error.default(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
96
+ error: ex,
97
+ group,
98
+ keys
99
+ });
100
+ }
101
+ };
102
+
103
+ const deleteGroup = async params => {
104
+ const {
105
+ group
106
+ } = params; // TODO make sure that group has locale and tenant on it - add it in the crud just in case
107
+
108
+ const keys = createKeys(group);
109
+
110
+ try {
111
+ await entity.delete(keys);
112
+ return group;
113
+ } catch (ex) {
114
+ throw new _error.default(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
115
+ error: ex,
116
+ group,
117
+ keys
118
+ });
119
+ }
120
+ };
121
+
122
+ const get = async params => {
123
+ const keys = createKeys(params);
124
+
125
+ try {
126
+ const group = await (0, _get.get)({
127
+ entity,
128
+ keys
129
+ });
130
+ return (0, _cleanup.cleanupItem)(entity, group);
131
+ } catch (ex) {
132
+ throw new _error.default(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
133
+ error: ex
134
+ }, params), {}, {
135
+ keys
136
+ }));
137
+ }
138
+ };
139
+
140
+ const list = async params => {
141
+ const {
142
+ sort,
143
+ where
144
+ } = params;
145
+ const queryAllParams = {
146
+ entity,
147
+ partitionKey: createPartitionKey(where),
148
+ options: {
149
+ gte: " "
150
+ }
151
+ };
152
+ let records = [];
153
+
154
+ try {
155
+ records = await (0, _query.queryAll)(queryAllParams);
156
+ } catch (ex) {
157
+ throw new _error.default(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
158
+ error: ex
159
+ }, params), {}, {
160
+ sort,
161
+ where
162
+ }));
163
+ }
164
+
165
+ const filteredItems = (0, _filter.filterItems)({
166
+ items: records,
167
+ where,
168
+ fields: [],
169
+ plugins
170
+ });
171
+
172
+ if (!sort || sort.length === 0) {
173
+ return filteredItems;
174
+ }
175
+
176
+ return (0, _sort.sortItems)({
177
+ items: filteredItems,
178
+ sort,
179
+ fields: []
180
+ });
181
+ };
182
+
183
+ return {
184
+ create,
185
+ update,
186
+ delete: deleteGroup,
187
+ get,
188
+ list
189
+ };
190
+ };
191
+
192
+ exports.createGroupsStorageOperations = createGroupsStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createPartitionKey","params","tenant","locale","createSortKeys","id","createKeys","PK","SK","createType","createGroupsStorageOperations","entity","plugins","filteringPlugins","byType","ValueFilterPlugin","type","length","WebinyError","create","group","keys","put","TYPE","ex","message","code","error","update","deleteGroup","delete","get","getRecord","cleanupItem","list","sort","where","queryAllParams","partitionKey","options","gte","records","queryAll","filteredItems","filterItems","items","fields","sortItems"],"sources":["index.ts"],"sourcesContent":["import {\n CmsGroup,\n CmsGroupStorageOperations,\n CmsGroupStorageOperationsCreateParams,\n CmsGroupStorageOperationsDeleteParams,\n CmsGroupStorageOperationsGetParams,\n CmsGroupStorageOperationsListParams,\n CmsGroupStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\n\ninterface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant, locale } = params;\n return `T#${tenant}#L#${locale}#CMS#CMG`;\n};\n\ninterface SortKeyParams {\n id: string;\n}\nconst createSortKeys = (params: SortKeyParams): string => {\n const { id } = params;\n return id;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKeys(params)\n };\n};\n\nconst createType = (): string => {\n return \"cms.group\";\n};\n\ninterface CreateGroupsStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createGroupsStorageOperations = (\n params: CreateGroupsStorageOperationsParams\n): CmsGroupStorageOperations => {\n const { entity, plugins } = params;\n\n const filteringPlugins = plugins.byType<ValueFilterPlugin>(ValueFilterPlugin.type);\n if (filteringPlugins.length === 0) {\n throw new WebinyError(\n \"DynamoDB filtering plugins not loaded.\",\n \"MISSING_DYNAMODB_FILTERING_PLUGINS\"\n );\n }\n\n const create = async (params: CmsGroupStorageOperationsCreateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n ...group,\n TYPE: createType(),\n ...keys\n });\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create group.\",\n ex.code || \"CREATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const update = async (params: CmsGroupStorageOperationsUpdateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n ...group,\n TYPE: createType(),\n ...keys\n });\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update group.\",\n ex.code || \"UPDATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const deleteGroup = async (params: CmsGroupStorageOperationsDeleteParams) => {\n const { group } = params;\n // TODO make sure that group has locale and tenant on it - add it in the crud just in case\n const keys = createKeys(group);\n\n try {\n await entity.delete(keys);\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete group.\",\n ex.code || \"DELETE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const get = async (params: CmsGroupStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const group = await getRecord<CmsGroup>({\n entity,\n keys\n });\n\n return cleanupItem(entity, group);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get group.\",\n ex.code || \"GET_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n keys\n }\n );\n }\n };\n const list = async (params: CmsGroupStorageOperationsListParams) => {\n const { sort, where } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n };\n\n let records: CmsGroup[] = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list groups.\",\n ex.code || \"LIST_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n sort,\n where\n }\n );\n }\n\n const filteredItems = filterItems({\n items: records,\n where,\n fields: [],\n plugins\n });\n if (!sort || sort.length === 0) {\n return filteredItems;\n }\n return sortItems({\n items: filteredItems,\n sort,\n fields: []\n });\n };\n\n return {\n create,\n update,\n delete: deleteGroup,\n get,\n list\n };\n};\n"],"mappings":";;;;;;;;;;;AAUA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAMA,MAAMA,kBAAkB,GAAIC,MAAD,IAAwC;EAC/D,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,OAAQ,KAAIC,MAAO,MAAKC,MAAO,UAA/B;AACH,CAHD;;AAQA,MAAMC,cAAc,GAAIH,MAAD,IAAmC;EACtD,MAAM;IAAEI;EAAF,IAASJ,MAAf;EACA,OAAOI,EAAP;AACH,CAHD;;AASA,MAAMC,UAAU,GAAIL,MAAD,IAAsD;EACrE,OAAO;IACHM,EAAE,EAAEP,kBAAkB,CAACC,MAAD,CADnB;IAEHO,EAAE,EAAEJ,cAAc,CAACH,MAAD;EAFf,CAAP;AAIH,CALD;;AAOA,MAAMQ,UAAU,GAAG,MAAc;EAC7B,OAAO,WAAP;AACH,CAFD;;AAQO,MAAMC,6BAA6B,GACtCT,MADyC,IAEb;EAC5B,MAAM;IAAEU,MAAF;IAAUC;EAAV,IAAsBX,MAA5B;EAEA,MAAMY,gBAAgB,GAAGD,OAA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,CAAhB;IACH,CAFD,CAEE,OAAOb,EAAP,EAAW;MACT,MAAM,IAAIN,cAAJ,CACFM,EAAE,CAACC,OAAH,IAAc,wBADZ,EAEFD,EAAE,CAACE,IAAH,IAAW,kBAFT;QAIEC,KAAK,EAAEH;MAJT,GAKKvB,MALL;QAMEkC,IANF;QAOEC;MAPF,GAAN;IAUH;;IAED,MAAMO,aAAa,GAAG,IAAAC,mBAAA,EAAY;MAC9BC,KAAK,EAAEJ,OADuB;MAE9BL,KAF8B;MAG9BU,MAAM,EAAE,EAHsB;MAI9BlC;IAJ8B,CAAZ,CAAtB;;IAMA,IAAI,CAACuB,IAAD,IAASA,IAAI,CAAClB,MAAL,KAAgB,CAA7B,EAAgC;MAC5B,OAAO0B,aAAP;IACH;;IACD,OAAO,IAAAI,eAAA,EAAU;MACbF,KAAK,EAAEF,aADM;MAEbR,IAFa;MAGbW,MAAM,EAAE;IAHK,CAAV,CAAP;EAKH,CAzCD;;EA2CA,OAAO;IACH3B,MADG;IAEHS,MAFG;IAGHE,MAAM,EAAED,WAHL;IAIHE,GAJG;IAKHG;EALG,CAAP;AAOH,CArJM"}
@@ -0,0 +1,7 @@
1
+ import { CmsModelStorageOperations } from "@webiny/api-headless-cms/types";
2
+ import { Entity } from "dynamodb-toolbox";
3
+ interface CreateModelsStorageOperationsParams {
4
+ entity: Entity<any>;
5
+ }
6
+ export declare const createModelsStorageOperations: (params: CreateModelsStorageOperationsParams) => CmsModelStorageOperations;
7
+ export {};