@webiny/api-headless-cms-ddb 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d

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 (170) hide show
  1. package/definitions/entry.d.ts +4 -3
  2. package/definitions/entry.js +108 -16
  3. package/definitions/entry.js.map +1 -1
  4. package/definitions/group.d.ts +4 -3
  5. package/definitions/group.js +8 -12
  6. package/definitions/group.js.map +1 -1
  7. package/definitions/model.d.ts +4 -3
  8. package/definitions/model.js +30 -12
  9. package/definitions/model.js.map +1 -1
  10. package/definitions/system.d.ts +4 -3
  11. package/definitions/system.js +8 -12
  12. package/definitions/system.js.map +1 -1
  13. package/definitions/table.d.ts +5 -5
  14. package/definitions/table.js +7 -6
  15. package/definitions/table.js.map +1 -1
  16. package/dynamoDb/index.d.ts +1 -1
  17. package/dynamoDb/index.js +4 -9
  18. package/dynamoDb/index.js.map +1 -1
  19. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  20. package/dynamoDb/path/locationFolderId.js +43 -0
  21. package/dynamoDb/path/locationFolderId.js.map +1 -0
  22. package/dynamoDb/path/plainObject.js +3 -8
  23. package/dynamoDb/path/plainObject.js.map +1 -1
  24. package/dynamoDb/storage/longText.d.ts +1 -1
  25. package/dynamoDb/storage/longText.js +10 -17
  26. package/dynamoDb/storage/longText.js.map +1 -1
  27. package/dynamoDb/storage/richText.d.ts +1 -1
  28. package/dynamoDb/storage/richText.js +23 -75
  29. package/dynamoDb/storage/richText.js.map +1 -1
  30. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  31. package/dynamoDb/transformValue/datetime.js +3 -8
  32. package/dynamoDb/transformValue/datetime.js.map +1 -1
  33. package/index.d.ts +1 -1
  34. package/index.js +25 -41
  35. package/index.js.map +1 -1
  36. package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
  37. package/operations/entry/dataLoader/DataLoaderCache.js +41 -0
  38. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  39. package/operations/entry/dataLoader/constants.d.ts +1 -0
  40. package/operations/entry/dataLoader/constants.js +10 -0
  41. package/operations/entry/dataLoader/constants.js.map +1 -0
  42. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  43. package/operations/entry/dataLoader/createBatchScheduleFn.js +25 -0
  44. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  45. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  46. package/operations/entry/dataLoader/getAllEntryRevisions.js +45 -0
  47. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  48. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  49. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +56 -0
  50. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  51. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  52. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +56 -0
  53. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  54. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  55. package/operations/entry/dataLoader/getRevisionById.js +62 -0
  56. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  57. package/operations/entry/dataLoader/index.d.ts +8 -0
  58. package/operations/entry/dataLoader/index.js +40 -0
  59. package/operations/entry/dataLoader/index.js.map +1 -0
  60. package/operations/entry/dataLoader/types.d.ts +6 -0
  61. package/operations/entry/dataLoader/types.js +7 -0
  62. package/operations/entry/dataLoader/types.js.map +1 -0
  63. package/operations/entry/dataLoaders.d.ts +12 -27
  64. package/operations/entry/dataLoaders.js +55 -260
  65. package/operations/entry/dataLoaders.js.map +1 -1
  66. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  67. package/operations/entry/filtering/createExpressions.js +178 -0
  68. package/operations/entry/filtering/createExpressions.js.map +1 -0
  69. package/operations/entry/filtering/createFields.d.ts +16 -0
  70. package/operations/entry/filtering/createFields.js +108 -0
  71. package/operations/entry/filtering/createFields.js.map +1 -0
  72. package/operations/entry/filtering/extractSort.d.ts +17 -0
  73. package/operations/entry/filtering/extractSort.js +69 -0
  74. package/operations/entry/filtering/extractSort.js.map +1 -0
  75. package/operations/entry/filtering/filter.d.ts +15 -0
  76. package/operations/entry/filtering/filter.js +158 -0
  77. package/operations/entry/filtering/filter.js.map +1 -0
  78. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  79. package/operations/entry/filtering/fullTextSearch.js +50 -0
  80. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  81. package/operations/entry/filtering/getValue.d.ts +5 -0
  82. package/operations/entry/filtering/getValue.js +66 -0
  83. package/operations/entry/filtering/getValue.js.map +1 -0
  84. package/operations/entry/filtering/index.d.ts +2 -0
  85. package/operations/entry/filtering/index.js +21 -0
  86. package/operations/entry/filtering/index.js.map +1 -0
  87. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  88. package/operations/entry/filtering/mapPlugins.js +33 -0
  89. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  90. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  91. package/operations/entry/filtering/plugins/defaultFilterCreate.js +45 -0
  92. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  93. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  94. package/operations/entry/filtering/plugins/index.js +16 -0
  95. package/operations/entry/filtering/plugins/index.js.map +1 -0
  96. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  97. package/operations/entry/filtering/plugins/objectFilterCreate.js +90 -0
  98. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  99. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -0
  100. package/operations/entry/filtering/plugins/refFilterCreate.js +80 -0
  101. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  102. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  103. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +65 -0
  104. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  105. package/operations/entry/filtering/sort.d.ts +12 -0
  106. package/operations/entry/filtering/sort.js +71 -0
  107. package/operations/entry/filtering/sort.js.map +1 -0
  108. package/operations/entry/filtering/systemFields.d.ts +4 -0
  109. package/operations/entry/filtering/systemFields.js +90 -0
  110. package/operations/entry/filtering/systemFields.js.map +1 -0
  111. package/operations/entry/filtering/transform.d.ts +6 -0
  112. package/operations/entry/filtering/transform.js +18 -0
  113. package/operations/entry/filtering/transform.js.map +1 -0
  114. package/operations/entry/filtering/types.d.ts +40 -0
  115. package/operations/entry/filtering/types.js +7 -0
  116. package/operations/entry/filtering/types.js.map +1 -0
  117. package/operations/entry/filtering/values.d.ts +2 -0
  118. package/operations/entry/filtering/values.js +24 -0
  119. package/operations/entry/filtering/values.js.map +1 -0
  120. package/operations/entry/filtering/where.d.ts +5 -0
  121. package/operations/entry/filtering/where.js +35 -0
  122. package/operations/entry/filtering/where.js.map +1 -0
  123. package/operations/entry/index.d.ts +3 -3
  124. package/operations/entry/index.js +733 -284
  125. package/operations/entry/index.js.map +1 -1
  126. package/operations/entry/keys.js +2 -18
  127. package/operations/entry/keys.js.map +1 -1
  128. package/operations/group/index.d.ts +3 -3
  129. package/operations/group/index.js +33 -51
  130. package/operations/group/index.js.map +1 -1
  131. package/operations/model/index.d.ts +2 -2
  132. package/operations/model/index.js +25 -37
  133. package/operations/model/index.js.map +1 -1
  134. package/operations/system/index.d.ts +2 -2
  135. package/operations/system/index.js +18 -23
  136. package/operations/system/index.js.map +1 -1
  137. package/package.json +21 -26
  138. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
  139. package/plugins/CmsEntryFieldFilterPathPlugin.js +11 -18
  140. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  141. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  142. package/plugins/CmsEntryFieldFilterPlugin.js +27 -0
  143. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  144. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  145. package/plugins/CmsEntryFieldSortingPlugin.js +27 -0
  146. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  147. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  148. package/plugins/CmsFieldFilterValueTransformPlugin.js +23 -0
  149. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  150. package/plugins/index.d.ts +3 -0
  151. package/plugins/index.js +36 -3
  152. package/plugins/index.js.map +1 -1
  153. package/types.d.ts +21 -14
  154. package/types.js +5 -6
  155. package/types.js.map +1 -1
  156. package/definitions/settings.d.ts +0 -9
  157. package/definitions/settings.js +0 -58
  158. package/definitions/settings.js.map +0 -1
  159. package/dynamoDb/storage/date.d.ts +0 -2
  160. package/dynamoDb/storage/date.js +0 -99
  161. package/dynamoDb/storage/date.js.map +0 -1
  162. package/operations/entry/systemFields.d.ts +0 -2
  163. package/operations/entry/systemFields.js +0 -74
  164. package/operations/entry/systemFields.js.map +0 -1
  165. package/operations/entry/utils.d.ts +0 -36
  166. package/operations/entry/utils.js +0 -680
  167. package/operations/entry/utils.js.map +0 -1
  168. package/operations/settings/index.d.ts +0 -7
  169. package/operations/settings/index.js +0 -135
  170. package/operations/settings/index.js.map +0 -1
package/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -9,51 +8,35 @@ var _exportNames = {
9
8
  createStorageOperations: true
10
9
  };
11
10
  exports.createStorageOperations = void 0;
12
-
13
11
  var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
14
-
15
12
  var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
16
-
17
13
  var _types = require("./types");
18
-
19
14
  var _table = require("./definitions/table");
20
-
21
- var _settings = require("./definitions/settings");
22
-
23
15
  var _system = require("./definitions/system");
24
-
25
16
  var _group = require("./definitions/group");
26
-
27
17
  var _model = require("./definitions/model");
28
-
29
18
  var _entry = require("./definitions/entry");
30
-
31
19
  var _plugins = require("@webiny/plugins");
32
-
33
20
  var _system2 = require("./operations/system");
34
-
35
- var _settings2 = require("./operations/settings");
36
-
37
21
  var _group2 = require("./operations/group");
38
-
39
22
  var _model2 = require("./operations/model");
40
-
41
23
  var _entry2 = require("./operations/entry");
42
-
43
- var _plugins2 = require("./plugins");
44
-
45
- Object.keys(_plugins2).forEach(function (key) {
24
+ var _plugins2 = require("./operations/entry/filtering/plugins");
25
+ var _plugins3 = require("./plugins");
26
+ Object.keys(_plugins3).forEach(function (key) {
46
27
  if (key === "default" || key === "__esModule") return;
47
28
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
48
- if (key in exports && exports[key] === _plugins2[key]) return;
29
+ if (key in exports && exports[key] === _plugins3[key]) return;
49
30
  Object.defineProperty(exports, key, {
50
31
  enumerable: true,
51
32
  get: function () {
52
- return _plugins2[key];
33
+ return _plugins3[key];
53
34
  }
54
35
  });
55
36
  });
56
-
37
+ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
38
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
39
+ var _api = require("@webiny/api");
57
40
  const createStorageOperations = params => {
58
41
  const {
59
42
  attributes,
@@ -66,11 +49,6 @@ const createStorageOperations = params => {
66
49
  documentClient
67
50
  });
68
51
  const entities = {
69
- settings: (0, _settings.createSettingsEntity)({
70
- entityName: _types.ENTITIES.SETTINGS,
71
- table: tableInstance,
72
- attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
73
- }),
74
52
  system: (0, _system.createSystemEntity)({
75
53
  entityName: _types.ENTITIES.SYSTEM,
76
54
  table: tableInstance,
@@ -101,31 +79,39 @@ const createStorageOperations = params => {
101
79
  * Field plugins for DynamoDB.
102
80
  */
103
81
  (0, _dynamoDb.default)(),
82
+ /**
83
+ * Filter create plugins.
84
+ */
85
+ (0, _plugins2.createFilterCreatePlugins)(),
104
86
  /**
105
87
  * User defined custom plugins.
106
88
  */
107
89
  ...(userPlugins || [])]);
90
+ const entries = (0, _entry2.createEntriesStorageOperations)({
91
+ entity: entities.entries,
92
+ plugins
93
+ });
108
94
  return {
95
+ name: "dynamodb",
109
96
  beforeInit: async context => {
97
+ const types = ["cms-model-field-to-graphql", _plugins3.CmsEntryFieldFilterPathPlugin.type, _plugins3.CmsFieldFilterValueTransformPlugin.type, _plugins3.CmsEntryFieldFilterPlugin.type, _plugins3.CmsEntryFieldSortingPlugin.type, _ValueFilterPlugin.ValueFilterPlugin.type, _apiHeadlessCms.StorageOperationsCmsModelPlugin.type, _apiHeadlessCms.StorageTransformPlugin.type, _api.CompressorPlugin.type];
110
98
  /**
111
99
  * Collect all required plugins from parent context.
112
100
  */
113
- const fieldPlugins = context.plugins.byType("cms-model-field-to-graphql");
114
- plugins.register(fieldPlugins);
101
+ for (const type of types) {
102
+ plugins.mergeByType(context.plugins, type);
103
+ }
115
104
  /**
116
105
  * Pass the plugins to the parent context.
117
106
  */
118
-
119
107
  context.plugins.register([(0, _dynamoDb.default)()]);
108
+ entries.dataLoaders.clearAll();
120
109
  },
121
110
  getEntities: () => entities,
122
111
  getTable: () => tableInstance,
123
112
  system: (0, _system2.createSystemStorageOperations)({
124
113
  entity: entities.system
125
114
  }),
126
- settings: (0, _settings2.createSettingsStorageOperations)({
127
- entity: entities.settings
128
- }),
129
115
  groups: (0, _group2.createGroupsStorageOperations)({
130
116
  entity: entities.groups,
131
117
  plugins
@@ -133,11 +119,9 @@ const createStorageOperations = params => {
133
119
  models: (0, _model2.createModelsStorageOperations)({
134
120
  entity: entities.models
135
121
  }),
136
- entries: (0, _entry2.createEntriesStorageOperations)({
137
- entity: entities.entries,
138
- plugins
139
- })
122
+ entries
140
123
  };
141
124
  };
125
+ exports.createStorageOperations = createStorageOperations;
142
126
 
143
- exports.createStorageOperations = createStorageOperations;
127
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createStorageOperations","params","attributes","table","documentClient","plugins","userPlugins","tableInstance","createTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","beforeInit","context","fieldPlugins","byType","register","getEntities","getTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createSystemStorageOperations } from \"~/operations/system\";\nimport { createSettingsStorageOperations } from \"~/operations/settings\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport { createModelsStorageOperations } from \"~/operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const { attributes, table, documentClient, plugins: userPlugins } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * User defined custom plugins.\n */\n ...(userPlugins || [])\n ]);\n\n return {\n beforeInit: async context => {\n /**\n * Collect all required plugins from parent context.\n */\n const fieldPlugins = context.plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n plugins.register(fieldPlugins);\n\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n plugins\n })\n };\n};\n"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEO,MAAMA,uBAAiD,GAAGC,MAAM,IAA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jC,CAAlB;EArBI,CAAjB;EA4BA,MAAMrB,OAAO,GAAG,IAAIsB,yBAAJ,CAAqB;EACjC;AACR;AACA;EACQ,IAAAC,gBAAA,GAJiC;EAKjC;AACR;AACA;EACQ,IAAAC,iBAAA,GARiC;EASjC;AACR;AACA;EACQ,IAAIvB,WAAW,IAAI,EAAnB,CAZiC,CAArB,CAAhB;EAeA,OAAO;IACHwB,UAAU,EAAE,MAAMC,OAAN,IAAiB;MACzB;AACZ;AACA;MACY,MAAMC,YAAY,GAAGD,OAAO,CAAC1B,OAAR,CAAgB4B,MAAhB,CACjB,4BADiB,CAArB;MAGA5B,OAAO,CAAC6B,QAAR,CAAiBF,YAAjB;MAEA;AACZ;AACA;;MACYD,OAAO,CAAC1B,OAAR,CAAgB6B,QAAhB,CAAyB,CAAC,IAAAL,iBAAA,GAAD,CAAzB;IACH,CAdE;IAeHM,WAAW,EAAE,MAAM1B,QAfhB;IAgBH2B,QAAQ,EAAE,MAAM7B,aAhBb;IAiBHQ,MAAM,EAAE,IAAAsB,sCAAA,EAA8B;MAClCC,MAAM,EAAE7B,QAAQ,CAACM;IADiB,CAA9B,CAjBL;IAoBHL,QAAQ,EAAE,IAAA6B,0CAAA,EAAgC;MACtCD,MAAM,EAAE7B,QAAQ,CAACC;IADqB,CAAhC,CApBP;IAuBHQ,MAAM,EAAE,IAAAsB,qCAAA,EAA8B;MAClCF,MAAM,EAAE7B,QAAQ,CAACS,MADiB;MAElCb;IAFkC,CAA9B,CAvBL;IA2BHgB,MAAM,EAAE,IAAAoB,qCAAA,EAA8B;MAClCH,MAAM,EAAE7B,QAAQ,CAACY;IADiB,CAA9B,CA3BL;IA8BHG,OAAO,EAAE,IAAAkB,sCAAA,EAA+B;MACpCJ,MAAM,EAAE7B,QAAQ,CAACe,OADmB;MAEpCnB;IAFoC,CAA/B;EA9BN,CAAP;AAmCH,CAtFM"}
1
+ {"version":3,"names":["_filters","_interopRequireDefault","require","_dynamoDb","_types","_table","_system","_group","_model","_entry","_plugins","_system2","_group2","_model2","_entry2","_plugins2","_plugins3","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_ValueFilterPlugin","_apiHeadlessCms","_api","createStorageOperations","params","attributes","table","documentClient","plugins","userPlugins","tableInstance","createTable","entities","system","createSystemEntity","entityName","ENTITIES","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","createFilterCreatePlugins","createEntriesStorageOperations","entity","name","beforeInit","context","types","CmsEntryFieldFilterPathPlugin","type","CmsFieldFilterValueTransformPlugin","CmsEntryFieldFilterPlugin","CmsEntryFieldSortingPlugin","ValueFilterPlugin","StorageOperationsCmsModelPlugin","StorageTransformPlugin","CompressorPlugin","mergeByType","register","dataLoaders","clearAll","getEntities","getTable","createSystemStorageOperations","createGroupsStorageOperations","createModelsStorageOperations"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport type { StorageOperationsFactory } from \"~/types\";\nimport { ENTITIES } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createSystemStorageOperations } from \"~/operations/system\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport { createModelsStorageOperations } from \"~/operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\n\nimport { createFilterCreatePlugins } from \"~/operations/entry/filtering/plugins\";\nimport {\n CmsEntryFieldFilterPathPlugin,\n CmsEntryFieldFilterPlugin,\n CmsEntryFieldSortingPlugin,\n CmsFieldFilterValueTransformPlugin\n} from \"~/plugins\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { StorageOperationsCmsModelPlugin, StorageTransformPlugin } from \"@webiny/api-headless-cms\";\nimport { CompressorPlugin } from \"@webiny/api\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const { attributes, table, documentClient, plugins: userPlugins } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n\n const entities = {\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Filter create plugins.\n */\n createFilterCreatePlugins(),\n /**\n * User defined custom plugins.\n */\n ...(userPlugins || [])\n ]);\n\n const entries = createEntriesStorageOperations({\n entity: entities.entries,\n plugins\n });\n\n return {\n name: \"dynamodb\",\n beforeInit: async context => {\n const types: string[] = [\n \"cms-model-field-to-graphql\",\n CmsEntryFieldFilterPathPlugin.type,\n CmsFieldFilterValueTransformPlugin.type,\n CmsEntryFieldFilterPlugin.type,\n CmsEntryFieldSortingPlugin.type,\n ValueFilterPlugin.type,\n StorageOperationsCmsModelPlugin.type,\n StorageTransformPlugin.type,\n CompressorPlugin.type\n ];\n /**\n * Collect all required plugins from parent context.\n */\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n\n entries.dataLoaders.clearAll();\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models\n }),\n entries\n };\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AACA,IAAAS,QAAA,GAAAT,OAAA;AACA,IAAAU,OAAA,GAAAV,OAAA;AACA,IAAAW,OAAA,GAAAX,OAAA;AACA,IAAAY,OAAA,GAAAZ,OAAA;AAEA,IAAAa,SAAA,GAAAb,OAAA;AACA,IAAAc,SAAA,GAAAd,OAAA;AAUAe,MAAA,CAAAC,IAAA,CAAAF,SAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,SAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,SAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAJA,IAAAS,kBAAA,GAAA3B,OAAA;AACA,IAAA4B,eAAA,GAAA5B,OAAA;A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Fa,MAAM,EAAE,IAAAiC,qCAA6B,EAAC;MAClCtB,MAAM,EAAEpB,QAAQ,CAACS;IACrB,CAAC,CAAC;IACFG;EACJ,CAAC;AACL,CAAC;AAAC5B,OAAA,CAAAO,uBAAA,GAAAA,uBAAA","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ import type DataLoader from "dataloader";
2
+ export interface CacheKeyParams {
3
+ name: string;
4
+ tenant: string;
5
+ locale: string;
6
+ }
7
+ export interface ClearAllParams {
8
+ tenant: string;
9
+ locale: string;
10
+ }
11
+ export declare class DataLoaderCache {
12
+ private readonly cache;
13
+ getDataLoader<I = any, R = any>(params: CacheKeyParams): DataLoader<I, R> | null;
14
+ setDataLoader(params: CacheKeyParams, dataLoader: DataLoader<any, any>): void;
15
+ clearAll(params?: ClearAllParams): void;
16
+ private createKey;
17
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DataLoaderCache = void 0;
7
+ class DataLoaderCache {
8
+ cache = {};
9
+ getDataLoader(params) {
10
+ const key = this.createKey(params);
11
+ return this.cache[key] || null;
12
+ }
13
+ setDataLoader(params, dataLoader) {
14
+ const key = this.createKey(params);
15
+ this.cache[key] = dataLoader;
16
+ }
17
+ clearAll(params) {
18
+ if (!params) {
19
+ for (const current in this.cache) {
20
+ this.cache[current].clearAll();
21
+ }
22
+ return;
23
+ }
24
+ const key = this.createKey({
25
+ ...params,
26
+ name: ""
27
+ });
28
+ for (const current in this.cache) {
29
+ if (current.startsWith(key) === false) {
30
+ continue;
31
+ }
32
+ this.cache[current].clearAll();
33
+ }
34
+ }
35
+ createKey(params) {
36
+ return `${params.tenant}_${params.locale}_${params.name}`;
37
+ }
38
+ }
39
+ exports.DataLoaderCache = DataLoaderCache;
40
+
41
+ //# sourceMappingURL=DataLoaderCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DataLoaderCache","cache","getDataLoader","params","key","createKey","setDataLoader","dataLoader","clearAll","current","name","startsWith","tenant","locale","exports"],"sources":["DataLoaderCache.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\n\nexport interface CacheKeyParams {\n name: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ClearAllParams {\n tenant: string;\n locale: string;\n}\n\nexport class DataLoaderCache {\n private readonly cache: Record<string, DataLoader<any, any>> = {};\n\n public getDataLoader<I = any, R = any>(params: CacheKeyParams): DataLoader<I, R> | null {\n const key = this.createKey(params);\n\n return this.cache[key] || null;\n }\n\n public setDataLoader(params: CacheKeyParams, dataLoader: DataLoader<any, any>): void {\n const key = this.createKey(params);\n this.cache[key] = dataLoader;\n }\n\n public clearAll(params?: ClearAllParams): void {\n if (!params) {\n for (const current in this.cache) {\n this.cache[current].clearAll();\n }\n return;\n }\n const key = this.createKey({\n ...params,\n name: \"\"\n });\n for (const current in this.cache) {\n if (current.startsWith(key) === false) {\n continue;\n }\n this.cache[current].clearAll();\n }\n }\n\n private createKey(params: CacheKeyParams): string {\n return `${params.tenant}_${params.locale}_${params.name}`;\n }\n}\n"],"mappings":";;;;;;AAaO,MAAMA,eAAe,CAAC;EACRC,KAAK,GAAyC,CAAC,CAAC;EAE1DC,aAAaA,CAAmBC,MAAsB,EAA2B;IACpF,MAAMC,GAAG,GAAG,IAAI,CAACC,SAAS,CAACF,MAAM,CAAC;IAElC,OAAO,IAAI,CAACF,KAAK,CAACG,GAAG,CAAC,IAAI,IAAI;EAClC;EAEOE,aAAaA,CAACH,MAAsB,EAAEI,UAAgC,EAAQ;IACjF,MAAMH,GAAG,GAAG,IAAI,CAACC,SAAS,CAACF,MAAM,CAAC;IAClC,IAAI,CAACF,KAAK,CAACG,GAAG,CAAC,GAAGG,UAAU;EAChC;EAEOC,QAAQA,CAACL,MAAuB,EAAQ;IAC3C,IAAI,CAACA,MAAM,EAAE;MACT,KAAK,MAAMM,OAAO,IAAI,IAAI,CAACR,KAAK,EAAE;QAC9B,IAAI,CAACA,KAAK,CAACQ,OAAO,CAAC,CAACD,QAAQ,CAAC,CAAC;MAClC;MACA;IACJ;IACA,MAAMJ,GAAG,GAAG,IAAI,CAACC,SAAS,CAAC;MACvB,GAAGF,MAAM;MACTO,IAAI,EAAE;IACV,CAAC,CAAC;IACF,KAAK,MAAMD,OAAO,IAAI,IAAI,CAACR,KAAK,EAAE;MAC9B,IAAIQ,OAAO,CAACE,UAAU,CAACP,GAAG,CAAC,KAAK,KAAK,EAAE;QACnC;MACJ;MACA,IAAI,CAACH,KAAK,CAACQ,OAAO,CAAC,CAACD,QAAQ,CAAC,CAAC;IAClC;EACJ;EAEQH,SAASA,CAACF,MAAsB,EAAU;IAC9C,OAAO,GAAGA,MAAM,CAACS,MAAM,IAAIT,MAAM,CAACU,MAAM,IAAIV,MAAM,CAACO,IAAI,EAAE;EAC7D;AACJ;AAACI,OAAA,CAAAd,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const CMS_ENTRY_BATCH_SCHEDULE_WAIT: number;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CMS_ENTRY_BATCH_SCHEDULE_WAIT = void 0;
7
+ const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || "0");
8
+ const CMS_ENTRY_BATCH_SCHEDULE_WAIT = exports.CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;
9
+
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["batchScheduleWaitEnv","Number","process","env","WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT","CMS_ENTRY_BATCH_SCHEDULE_WAIT","exports","isNaN"],"sources":["constants.ts"],"sourcesContent":["const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || \"0\");\nexport const CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;\n"],"mappings":";;;;;;AAAA,MAAMA,oBAAoB,GAAGC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,wCAAwC,IAAI,GAAG,CAAC;AACzF,MAAMC,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAGE,KAAK,CAACP,oBAAoB,CAAC,GAAG,CAAC,GAAGA,oBAAoB","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.
3
+ * Intended to be used internally or for a specific user case.
4
+ * Not to be documented and exposed to publish as it can slow the data loading a lot.
5
+ *
6
+ * https://github.com/graphql/dataloader#batch-scheduling
7
+ */
8
+ export declare const createBatchScheduleFn: () => ((callback: () => void) => void) | undefined;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createBatchScheduleFn = void 0;
7
+ var _constants = require("./constants");
8
+ /**
9
+ * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.
10
+ * Intended to be used internally or for a specific user case.
11
+ * Not to be documented and exposed to publish as it can slow the data loading a lot.
12
+ *
13
+ * https://github.com/graphql/dataloader#batch-scheduling
14
+ */
15
+ const createBatchScheduleFn = () => {
16
+ if (_constants.CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {
17
+ return undefined;
18
+ }
19
+ return callback => {
20
+ setTimeout(callback, _constants.CMS_ENTRY_BATCH_SCHEDULE_WAIT);
21
+ };
22
+ };
23
+ exports.createBatchScheduleFn = createBatchScheduleFn;
24
+
25
+ //# sourceMappingURL=createBatchScheduleFn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_constants","require","createBatchScheduleFn","CMS_ENTRY_BATCH_SCHEDULE_WAIT","undefined","callback","setTimeout","exports"],"sources":["createBatchScheduleFn.ts"],"sourcesContent":["import { CMS_ENTRY_BATCH_SCHEDULE_WAIT } from \"./constants\";\n\n/**\n * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.\n * Intended to be used internally or for a specific user case.\n * Not to be documented and exposed to publish as it can slow the data loading a lot.\n *\n * https://github.com/graphql/dataloader#batch-scheduling\n */\nexport const createBatchScheduleFn = () => {\n if (CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {\n return undefined;\n }\n return (callback: () => void) => {\n setTimeout(callback, CMS_ENTRY_BATCH_SCHEDULE_WAIT);\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,IAAIC,wCAA6B,IAAI,CAAC,EAAE;IACpC,OAAOC,SAAS;EACpB;EACA,OAAQC,QAAoB,IAAK;IAC7BC,UAAU,CAACD,QAAQ,EAAEF,wCAA6B,CAAC;EACvD,CAAC;AACL,CAAC;AAACI,OAAA,CAAAL,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import type { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
+ import type { DataLoaderParams } from "./types";
4
+ export declare const createGetAllEntryRevisions: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createGetAllEntryRevisions = void 0;
8
+ var _dataloader = _interopRequireDefault(require("dataloader"));
9
+ var _query = require("@webiny/db-dynamodb/utils/query");
10
+ var _keys = require("../keys");
11
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
12
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
13
+ const createGetAllEntryRevisions = params => {
14
+ const {
15
+ entity,
16
+ locale,
17
+ tenant
18
+ } = params;
19
+ return new _dataloader.default(async ids => {
20
+ const results = {};
21
+ for (const id of ids) {
22
+ const queryAllParams = {
23
+ entity,
24
+ partitionKey: (0, _keys.createPartitionKey)({
25
+ tenant,
26
+ locale,
27
+ id
28
+ }),
29
+ options: {
30
+ beginsWith: "REV#"
31
+ }
32
+ };
33
+ const items = await (0, _query.queryAll)(queryAllParams);
34
+ results[id] = (0, _cleanup.cleanupItems)(entity, items);
35
+ }
36
+ return ids.map(id => {
37
+ return results[id] || [];
38
+ });
39
+ }, {
40
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
41
+ });
42
+ };
43
+ exports.createGetAllEntryRevisions = createGetAllEntryRevisions;
44
+
45
+ //# sourceMappingURL=getAllEntryRevisions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_dataloader","_interopRequireDefault","require","_query","_keys","_cleanup","_createBatchScheduleFn","createGetAllEntryRevisions","params","entity","locale","tenant","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getAllEntryRevisions.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport type { QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { createPartitionKey } from \"~/operations/entry/keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport type { DataLoaderParams } from \"./types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetAllEntryRevisions = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const results: Record<string, CmsStorageEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsStorageEntry>(queryAllParams);\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,sBAAA,GAAAJ,OAAA;AAEO,MAAMK,0BAA0B,GAAIC,MAAwB,IAAK;EACpE,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EACzC,OAAO,IAAII,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAA0C,GAAG,CAAC,CAAC;IACrD,KAAK,MAAMC,EAAE,IAAIF,GAAG,EAAE;MAClB,MAAMG,cAA8B,GAAG;QACnCP,MAAM;QACNQ,YAAY,EAAE,IAAAC,wBAAkB,EAAC;UAC7BP,MAAM;UACND,MAAM;UACNK;QACJ,CAAC,CAAC;QACFI,OAAO,EAAE;UACLC,UAAU,EAAE;QAChB;MACJ,CAAC;MACD,MAAMC,KAAK,GAAG,MAAM,IAAAC,eAAQ,EAAkBN,cAAc,CAAC;MAC7DF,OAAO,CAACC,EAAE,CAAC,GAAG,IAAAQ,qBAAY,EAACd,MAAM,EAAEY,KAAK,CAAC;IAC7C;IAEA,OAAOR,GAAG,CAACW,GAAG,CAACT,EAAE,IAAI;MACjB,OAAOD,OAAO,CAACC,EAAE,CAAC,IAAI,EAAE;IAC5B,CAAC,CAAC;EACN,CAAC,EACD;IACIU,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAApB,0BAAA,GAAAA,0BAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import type { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
+ import type { DataLoaderParams } from "./types";
4
+ export declare const createGetLatestRevisionByEntryId: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createGetLatestRevisionByEntryId = void 0;
8
+ var _dataloader = _interopRequireDefault(require("dataloader"));
9
+ var _dbDynamodb = require("@webiny/db-dynamodb");
10
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
12
+ var _keys = require("../keys");
13
+ var _utils = require("@webiny/utils");
14
+ const createGetLatestRevisionByEntryId = params => {
15
+ const {
16
+ entity,
17
+ locale,
18
+ tenant
19
+ } = params;
20
+ const latestKey = (0, _keys.createLatestSortKey)();
21
+ return new _dataloader.default(async ids => {
22
+ const queries = ids.reduce((collection, id) => {
23
+ const partitionKey = (0, _keys.createPartitionKey)({
24
+ tenant,
25
+ locale,
26
+ id
27
+ });
28
+ if (collection[partitionKey]) {
29
+ return collection;
30
+ }
31
+ collection[partitionKey] = entity.getBatch({
32
+ PK: partitionKey,
33
+ SK: latestKey
34
+ });
35
+ return collection;
36
+ }, {});
37
+ const records = await (0, _dbDynamodb.batchReadAll)({
38
+ table: entity.table,
39
+ items: Object.values(queries)
40
+ });
41
+ const items = (0, _cleanup.cleanupItems)(entity, records);
42
+ return ids.map(id => {
43
+ const {
44
+ id: entryId
45
+ } = (0, _utils.parseIdentifier)(id);
46
+ return items.filter(item => {
47
+ return entryId === item.entryId;
48
+ });
49
+ });
50
+ }, {
51
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
52
+ });
53
+ };
54
+ exports.createGetLatestRevisionByEntryId = createGetLatestRevisionByEntryId;
55
+
56
+ //# sourceMappingURL=getLatestRevisionByEntryId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_dataloader","_interopRequireDefault","require","_dbDynamodb","_cleanup","_createBatchScheduleFn","_keys","_utils","createGetLatestRevisionByEntryId","params","entity","locale","tenant","latestKey","createLatestSortKey","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","entryId","parseIdentifier","filter","item","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getLatestRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\nimport { createLatestSortKey, createPartitionKey } from \"~/operations/entry/keys\";\nimport type { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\nexport const createGetLatestRevisionByEntryId = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce<Record<string, any>>((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n }, {});\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GA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,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOH,OAAO,KAAKG,IAAI,CAACH,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACII,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAhC,gCAAA,GAAAA,gCAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import type { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
+ import type { DataLoaderParams } from "./types";
4
+ export declare const createGetPublishedRevisionByEntryId: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createGetPublishedRevisionByEntryId = void 0;
8
+ var _dataloader = _interopRequireDefault(require("dataloader"));
9
+ var _dbDynamodb = require("@webiny/db-dynamodb");
10
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
+ var _keys = require("../keys");
12
+ var _utils = require("@webiny/utils");
13
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
14
+ const createGetPublishedRevisionByEntryId = params => {
15
+ const {
16
+ entity,
17
+ locale,
18
+ tenant
19
+ } = params;
20
+ const publishedKey = (0, _keys.createPublishedSortKey)();
21
+ return new _dataloader.default(async ids => {
22
+ const queries = ids.reduce((collection, id) => {
23
+ const partitionKey = (0, _keys.createPartitionKey)({
24
+ tenant,
25
+ locale,
26
+ id
27
+ });
28
+ if (collection[partitionKey]) {
29
+ return collection;
30
+ }
31
+ collection[partitionKey] = entity.getBatch({
32
+ PK: partitionKey,
33
+ SK: publishedKey
34
+ });
35
+ return collection;
36
+ }, {});
37
+ const records = await (0, _dbDynamodb.batchReadAll)({
38
+ table: entity.table,
39
+ items: Object.values(queries)
40
+ });
41
+ const items = (0, _cleanup.cleanupItems)(entity, records);
42
+ return ids.map(id => {
43
+ const {
44
+ id: entryId
45
+ } = (0, _utils.parseIdentifier)(id);
46
+ return items.filter(item => {
47
+ return entryId === item.entryId;
48
+ });
49
+ });
50
+ }, {
51
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
52
+ });
53
+ };
54
+ exports.createGetPublishedRevisionByEntryId = createGetPublishedRevisionByEntryId;
55
+
56
+ //# sourceMappingURL=getPublishedRevisionByEntryId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_dataloader","_interopRequireDefault","require","_dbDynamodb","_cleanup","_keys","_utils","_createBatchScheduleFn","createGetPublishedRevisionByEntryId","params","entity","locale","tenant","publishedKey","createPublishedSortKey","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","entryId","parseIdentifier","filter","item","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getPublishedRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createPartitionKey, createPublishedSortKey } from \"~/operations/entry/keys\";\nimport type { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetPublishedRevisionByEntryId = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n const publishedKey = createPublishedSortKey();\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce<Record<string, ReturnType<typeof entity.getBatch>>>(\n (collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n },\n {}\n );\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,KAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,sBAAA,GAAAL,OAAA;AAEO,MAAMM,mCAAmC,GAAIC,MAAwB,IAAK;EAC7E,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,MAAMI,YAAY,GAAG,IAAAC,4BAAsB,EAAC,CAAC;EAC7C,OAAO,IAAIC,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CACtB,CAACC,UAAU,EAAEC,EAAE,KAAK;MAChB,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCV,MAAM;QACND,MAAM;QACNS;MACJ,CAAC,CAAC;MACF,IAAID,UAAU,CAACE,YAAY,CAAC,EAAE;QAC1B,OAAOF,UAAU;MACrB;MACAA,UAAU,CAACE,YAAY,CAAC,GAAGX,MAAM,CAACa,QAAQ,CAAC;QACvCC,EAAE,EAAEH,YAAY;QAChBI,EAAE,EAAEZ;MACR,CAAC,CAAC;MACF,OAAOM,UAAU;IACrB,CAAC,EACD,CAAC,CACL,CAAC;IAED,MAAMO,OAAO,GAAG,MAAM,IAAAC,wBAAY,EAAkB;MAChDC,KAAK,EAAElB,MAAM,CAACkB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACd,OAAO;IAChC,CAAC,CAAC;IACF,MAAMY,KAAK,GAAG,IAAAG,qBAAY,EAACtB,MAAM,EAAEgB,OAAO,CAAC;IAE3C,OAAOV,GAAG,CAACiB,GAAG,CAACb,EAAE,IAAI;MACjB,MAAM;QAAEA,EAAE,EAAEc;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACf,EAAE,CAAC;MAC3C,OAAOS,KAAK,CAACO,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOH,OAAO,KAAKG,IAAI,CAACH,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACII,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAhC,mCAAA,GAAAA,mCAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import type { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
+ import type { DataLoaderParams } from "./types";
4
+ export declare const createGetRevisionById: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createGetRevisionById = void 0;
8
+ var _dataloader = _interopRequireDefault(require("dataloader"));
9
+ var _dbDynamodb = require("@webiny/db-dynamodb");
10
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
+ var _keys = require("../keys");
12
+ var _utils = require("@webiny/utils");
13
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
14
+ const createGetRevisionById = params => {
15
+ const {
16
+ entity,
17
+ locale,
18
+ tenant
19
+ } = params;
20
+ return new _dataloader.default(async ids => {
21
+ const queries = ids.reduce((collection, id) => {
22
+ const partitionKey = (0, _keys.createPartitionKey)({
23
+ tenant,
24
+ locale,
25
+ id
26
+ });
27
+ const {
28
+ version
29
+ } = (0, _utils.parseIdentifier)(id);
30
+ if (version === null) {
31
+ return collection;
32
+ }
33
+ const sortKey = (0, _keys.createRevisionSortKey)({
34
+ version
35
+ });
36
+ const keys = `${partitionKey}__${sortKey}`;
37
+ if (collection[keys]) {
38
+ return collection;
39
+ }
40
+ collection[keys] = entity.getBatch({
41
+ PK: partitionKey,
42
+ SK: sortKey
43
+ });
44
+ return collection;
45
+ }, {});
46
+ const records = await (0, _dbDynamodb.batchReadAll)({
47
+ table: entity.table,
48
+ items: Object.values(queries)
49
+ });
50
+ const items = (0, _cleanup.cleanupItems)(entity, records);
51
+ return ids.map(id => {
52
+ return items.filter(item => {
53
+ return id === item.id;
54
+ });
55
+ });
56
+ }, {
57
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
58
+ });
59
+ };
60
+ exports.createGetRevisionById = createGetRevisionById;
61
+
62
+ //# sourceMappingURL=getRevisionById.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_dataloader","_interopRequireDefault","require","_dbDynamodb","_cleanup","_keys","_utils","_createBatchScheduleFn","createGetRevisionById","params","entity","locale","tenant","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","filter","item","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getRevisionById.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { createPartitionKey, createRevisionSortKey } from \"~/operations/entry/keys\";\nimport type { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetRevisionById = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce<Record<string, ReturnType<typeof entity.getBatch>>>(\n (collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n },\n {}\n );\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,sBAAA,GAAAL,OAAA;AAEO,MAAMM,qBAAqB,GAAIC,MAAwB,IAAK;EAC/D,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,OAAO,IAAII,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CACtB,CAACC,UAAU,EAAEC,EAAE,KAAK;MAChB,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCR,MAAM;QACND,MAAM;QACNO;MACJ,CAAC,CAAC;MACF,MAAM;QAAEG;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACJ,EAAE,CAAC;MACvC,IAAIG,OAAO,KAAK,IAAI,EAAE;QAClB,OAAOJ,UAAU;MACrB;MACA,MAAMM,OAAO,GAAG,IAAAC,2BAAqB,EAAC;QAClCH;MACJ,CAAC,CAAC;MACF,MAAMI,IAAI,GAAG,GAAGN,YAAY,KAAKI,OAAO,EAAE;MAC1C,IAAIN,UAAU,CAACQ,IAAI,CAAC,EAAE;QAClB,OAAOR,UAAU;MACrB;MAEAA,UAAU,CAACQ,IAAI,CAAC,GAAGf,MAAM,CAACgB,QAAQ,CAAC;QAC/BC,EAAE,EAAER,YAAY;QAChBS,EAAE,EAAEL;MACR,CAAC,CAAC;MAEF,OAAON,UAAU;IACrB,CAAC,EACD,CAAC,CACL,CAAC;IAED,MAAMY,OAAO,GAAG,MAAM,IAAAC,wBAAY,EAAkB;MAChDC,KAAK,EAAErB,MAAM,CAACqB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACnB,OAAO;IAChC,CAAC,CAAC;IACF,MAAMiB,KAAK,GAAG,IAAAG,qBAAY,EAACzB,MAAM,EAAEmB,OAAO,CAAC;IAE3C,OAAOf,GAAG,CAACsB,GAAG,CAAClB,EAAE,IAAI;MACjB,OAAOc,KAAK,CAACK,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOpB,EAAE,KAAKoB,IAAI,CAACpB,EAAE;MACzB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIqB,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAjC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import type DataLoader from "dataloader";
2
+ import type { DataLoaderParams } from "./types";
3
+ export * from "./DataLoaderCache";
4
+ interface Callable {
5
+ (params: DataLoaderParams): DataLoader<any, any>;
6
+ }
7
+ export type DataLoaders = "getAllEntryRevisions" | "getRevisionById" | "getPublishedRevisionByEntryId" | "getLatestRevisionByEntryId";
8
+ export declare const getDataLoaderFactory: (name: string) => Callable;