@webiny/api-headless-cms-ddb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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 (172) hide show
  1. package/README.md +6 -20
  2. package/definitions/entry.d.ts +4 -5
  3. package/definitions/entry.js +9 -94
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.d.ts +4 -5
  6. package/definitions/group.js +9 -68
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.d.ts +4 -5
  9. package/definitions/model.js +9 -90
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/table.d.ts +4 -6
  12. package/definitions/table.js +8 -30
  13. package/definitions/table.js.map +1 -1
  14. package/definitions/types.d.ts +65 -0
  15. package/definitions/types.js +0 -0
  16. package/dynamoDb/index.d.ts +1 -1
  17. package/dynamoDb/index.js +11 -20
  18. package/dynamoDb/index.js.map +1 -1
  19. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  20. package/dynamoDb/path/locationFolderId.js +21 -0
  21. package/dynamoDb/path/locationFolderId.js.map +1 -0
  22. package/dynamoDb/path/plainObject.d.ts +1 -1
  23. package/dynamoDb/path/plainObject.js +13 -37
  24. package/dynamoDb/path/plainObject.js.map +1 -1
  25. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  26. package/dynamoDb/transformValue/datetime.js +27 -50
  27. package/dynamoDb/transformValue/datetime.js.map +1 -1
  28. package/index.d.ts +2 -3
  29. package/index.js +83 -139
  30. package/index.js.map +1 -1
  31. package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
  32. package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
  33. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  34. package/operations/entry/dataLoader/constants.d.ts +1 -0
  35. package/operations/entry/dataLoader/constants.js +5 -0
  36. package/operations/entry/dataLoader/constants.js.map +1 -0
  37. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  38. package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
  39. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  40. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  41. package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
  42. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  43. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  44. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
  45. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  46. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  47. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
  48. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  49. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  50. package/operations/entry/dataLoader/getRevisionById.js +42 -0
  51. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  52. package/operations/entry/dataLoader/index.d.ts +8 -0
  53. package/operations/entry/dataLoader/index.js +18 -0
  54. package/operations/entry/dataLoader/index.js.map +1 -0
  55. package/operations/entry/dataLoader/types.d.ts +6 -0
  56. package/operations/entry/dataLoader/types.js +0 -0
  57. package/operations/entry/dataLoaders.d.ts +14 -30
  58. package/operations/entry/dataLoaders.js +83 -314
  59. package/operations/entry/dataLoaders.js.map +1 -1
  60. package/operations/entry/filtering/createExpressions.d.ts +27 -0
  61. package/operations/entry/filtering/createExpressions.js +124 -0
  62. package/operations/entry/filtering/createExpressions.js.map +1 -0
  63. package/operations/entry/filtering/createFields.d.ts +16 -0
  64. package/operations/entry/filtering/createFields.js +93 -0
  65. package/operations/entry/filtering/createFields.js.map +1 -0
  66. package/operations/entry/filtering/extractSort.d.ts +17 -0
  67. package/operations/entry/filtering/extractSort.js +60 -0
  68. package/operations/entry/filtering/extractSort.js.map +1 -0
  69. package/operations/entry/filtering/filter.d.ts +16 -0
  70. package/operations/entry/filtering/filter.js +85 -0
  71. package/operations/entry/filtering/filter.js.map +1 -0
  72. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  73. package/operations/entry/filtering/fullTextSearch.js +25 -0
  74. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  75. package/operations/entry/filtering/getValue.d.ts +5 -0
  76. package/operations/entry/filtering/getValue.js +37 -0
  77. package/operations/entry/filtering/getValue.js.map +1 -0
  78. package/operations/entry/filtering/index.d.ts +2 -0
  79. package/operations/entry/filtering/index.js +2 -0
  80. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  81. package/operations/entry/filtering/mapPlugins.js +18 -0
  82. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  83. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  84. package/operations/entry/filtering/plugins/defaultFilterCreate.js +33 -0
  85. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  86. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  87. package/operations/entry/filtering/plugins/index.js +13 -0
  88. package/operations/entry/filtering/plugins/index.js.map +1 -0
  89. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  90. package/operations/entry/filtering/plugins/objectFilterCreate.js +68 -0
  91. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  92. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -0
  93. package/operations/entry/filtering/plugins/refFilterCreate.js +63 -0
  94. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  95. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  96. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +49 -0
  97. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  98. package/operations/entry/filtering/sort.d.ts +12 -0
  99. package/operations/entry/filtering/sort.js +41 -0
  100. package/operations/entry/filtering/sort.js.map +1 -0
  101. package/operations/entry/filtering/systemFields.d.ts +2 -0
  102. package/operations/entry/filtering/systemFields.js +149 -0
  103. package/operations/entry/filtering/systemFields.js.map +1 -0
  104. package/operations/entry/filtering/transform.d.ts +6 -0
  105. package/operations/entry/filtering/transform.js +7 -0
  106. package/operations/entry/filtering/transform.js.map +1 -0
  107. package/operations/entry/filtering/types.d.ts +40 -0
  108. package/operations/entry/filtering/types.js +0 -0
  109. package/operations/entry/filtering/values.d.ts +2 -0
  110. package/operations/entry/filtering/values.js +15 -0
  111. package/operations/entry/filtering/values.js.map +1 -0
  112. package/operations/entry/filtering/where.d.ts +5 -0
  113. package/operations/entry/filtering/where.js +22 -0
  114. package/operations/entry/filtering/where.js.map +1 -0
  115. package/operations/entry/index.d.ts +5 -4
  116. package/operations/entry/index.js +931 -845
  117. package/operations/entry/index.js.map +1 -1
  118. package/operations/entry/keys.d.ts +46 -2
  119. package/operations/entry/keys.js +53 -66
  120. package/operations/entry/keys.js.map +1 -1
  121. package/operations/group/index.d.ts +4 -5
  122. package/operations/group/index.js +116 -187
  123. package/operations/group/index.js.map +1 -1
  124. package/operations/model/index.d.ts +3 -3
  125. package/operations/model/index.js +102 -158
  126. package/operations/model/index.js.map +1 -1
  127. package/package.json +34 -33
  128. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +5 -4
  129. package/plugins/CmsEntryFieldFilterPathPlugin.js +25 -50
  130. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  131. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  132. package/plugins/CmsEntryFieldFilterPlugin.js +20 -0
  133. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  134. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  135. package/plugins/CmsEntryFieldSortingPlugin.js +20 -0
  136. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  137. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  138. package/plugins/CmsFieldFilterValueTransformPlugin.js +19 -0
  139. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  140. package/plugins/index.d.ts +4 -1
  141. package/plugins/index.js +4 -18
  142. package/types.d.ts +28 -21
  143. package/types.js +8 -15
  144. package/types.js.map +1 -1
  145. package/definitions/settings.d.ts +0 -9
  146. package/definitions/settings.js +0 -58
  147. package/definitions/settings.js.map +0 -1
  148. package/definitions/system.d.ts +0 -9
  149. package/definitions/system.js +0 -46
  150. package/definitions/system.js.map +0 -1
  151. package/dynamoDb/storage/date.d.ts +0 -2
  152. package/dynamoDb/storage/date.js +0 -99
  153. package/dynamoDb/storage/date.js.map +0 -1
  154. package/dynamoDb/storage/longText.d.ts +0 -10
  155. package/dynamoDb/storage/longText.js +0 -101
  156. package/dynamoDb/storage/longText.js.map +0 -1
  157. package/dynamoDb/storage/richText.d.ts +0 -2
  158. package/dynamoDb/storage/richText.js +0 -113
  159. package/dynamoDb/storage/richText.js.map +0 -1
  160. package/operations/entry/systemFields.d.ts +0 -2
  161. package/operations/entry/systemFields.js +0 -74
  162. package/operations/entry/systemFields.js.map +0 -1
  163. package/operations/entry/utils.d.ts +0 -36
  164. package/operations/entry/utils.js +0 -680
  165. package/operations/entry/utils.js.map +0 -1
  166. package/operations/settings/index.d.ts +0 -7
  167. package/operations/settings/index.js +0 -135
  168. package/operations/settings/index.js.map +0 -1
  169. package/operations/system/index.d.ts +0 -7
  170. package/operations/system/index.js +0 -99
  171. package/operations/system/index.js.map +0 -1
  172. package/plugins/index.js.map +0 -1
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import type { CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
3
+ import type { IDataLoaderParams } from "./types.js";
4
+ export declare const createGetPublishedRevisionByEntryId: (params: IDataLoaderParams) => DataLoader<string, CmsStorageEntry<import("@webiny/api-headless-cms/types/types.js").CmsEntryValues>[], string>;
@@ -0,0 +1,40 @@
1
+ import dataloader from "dataloader";
2
+ import { cleanupItems } from "@webiny/db-dynamodb/utils/cleanup.js";
3
+ import { createPartitionKey, createPublishedSortKey } from "../keys.js";
4
+ import { parseIdentifier } from "@webiny/utils";
5
+ import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
6
+ const createGetPublishedRevisionByEntryId = (params)=>{
7
+ const { entity, tenant, modelId } = params;
8
+ const publishedKey = createPublishedSortKey();
9
+ return new dataloader(async (ids)=>{
10
+ const reader = entity.createEntityReader();
11
+ const keys = new Set();
12
+ for (const id of ids){
13
+ const partitionKey = createPartitionKey({
14
+ tenant,
15
+ id
16
+ });
17
+ if (!keys.has(partitionKey)) {
18
+ keys.add(partitionKey);
19
+ reader.get({
20
+ PK: partitionKey,
21
+ SK: publishedKey
22
+ });
23
+ }
24
+ }
25
+ const records = await reader.execute();
26
+ const items = cleanupItems(entity.entity, records).map((item)=>item.data);
27
+ return ids.map((id)=>{
28
+ const { id: entryId } = parseIdentifier(id);
29
+ return items.filter((item)=>{
30
+ if (item.modelId !== modelId) return false;
31
+ return entryId === item.entryId;
32
+ });
33
+ });
34
+ }, {
35
+ batchScheduleFn: createBatchScheduleFn()
36
+ });
37
+ };
38
+ export { createGetPublishedRevisionByEntryId };
39
+
40
+ //# sourceMappingURL=getPublishedRevisionByEntryId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/dataLoader/getPublishedRevisionByEntryId.js","sources":["../../../../src/operations/entry/dataLoader/getPublishedRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup.js\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createPartitionKey, createPublishedSortKey } from \"~/operations/entry/keys.js\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn.js\";\n\nexport const createGetPublishedRevisionByEntryId = (params: IDataLoaderParams) => {\n const { entity, tenant, modelId } = params;\n\n const publishedKey = createPublishedSortKey();\n return new DataLoader<string, CmsStorageEntry[]>(\n async ids => {\n const reader = entity.createEntityReader();\n\n const keys = new Set<string>();\n\n for (const id of ids) {\n const partitionKey = createPartitionKey({\n tenant,\n id\n });\n if (keys.has(partitionKey)) {\n continue;\n }\n keys.add(partitionKey);\n reader.get({\n PK: partitionKey,\n SK: publishedKey\n });\n }\n\n const records = await reader.execute();\n const items = cleanupItems(entity.entity, records).map(item => {\n return item.data;\n });\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n if (item.modelId !== modelId) {\n return false;\n }\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"names":["createGetPublishedRevisionByEntryId","params","entity","tenant","modelId","publishedKey","createPublishedSortKey","DataLoader","ids","reader","keys","Set","id","partitionKey","createPartitionKey","records","items","cleanupItems","item","entryId","parseIdentifier","createBatchScheduleFn"],"mappings":";;;;;AAQO,MAAMA,sCAAsC,CAACC;IAChD,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAEpC,MAAMI,eAAeC;IACrB,OAAO,IAAIC,WACP,OAAMC;QACF,MAAMC,SAASP,OAAO,kBAAkB;QAExC,MAAMQ,OAAO,IAAIC;QAEjB,KAAK,MAAMC,MAAMJ,IAAK;YAClB,MAAMK,eAAeC,mBAAmB;gBACpCX;gBACAS;YACJ;YACA,KAAIF,KAAK,GAAG,CAACG;gBAGbH,KAAK,GAAG,CAACG;gBACTJ,OAAO,GAAG,CAAC;oBACP,IAAII;oBACJ,IAAIR;gBACR;;QACJ;QAEA,MAAMU,UAAU,MAAMN,OAAO,OAAO;QACpC,MAAMO,QAAQC,aAAaf,OAAO,MAAM,EAAEa,SAAS,GAAG,CAACG,CAAAA,OAC5CA,KAAK,IAAI;QAGpB,OAAOV,IAAI,GAAG,CAACI,CAAAA;YACX,MAAM,EAAE,IAAIO,OAAO,EAAE,GAAGC,gBAAgBR;YACxC,OAAOI,MAAM,MAAM,CAACE,CAAAA;gBAChB,IAAIA,KAAK,OAAO,KAAKd,SACjB,OAAO;gBAEX,OAAOe,YAAYD,KAAK,OAAO;YACnC;QACJ;IACJ,GACA;QACI,iBAAiBG;IACrB;AAER"}
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import type { CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
3
+ import type { IDataLoaderParams } from "./types.js";
4
+ export declare const createGetRevisionById: (params: IDataLoaderParams) => DataLoader<string, CmsStorageEntry<import("@webiny/api-headless-cms/types/types.js").CmsEntryValues>[], string>;
@@ -0,0 +1,42 @@
1
+ import dataloader from "dataloader";
2
+ import { cleanupItems } from "@webiny/db-dynamodb/utils/cleanup.js";
3
+ import { createPartitionKey, createRevisionSortKey } from "../keys.js";
4
+ import { parseIdentifier } from "@webiny/utils";
5
+ import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
6
+ const createGetRevisionById = (params)=>{
7
+ const { entity, tenant, modelId } = params;
8
+ return new dataloader(async (ids)=>{
9
+ const reader = entity.createEntityReader();
10
+ const keys = new Set();
11
+ for (const id of ids){
12
+ const partitionKey = createPartitionKey({
13
+ tenant,
14
+ id
15
+ });
16
+ const { version } = parseIdentifier(id);
17
+ if (null === version) continue;
18
+ const sortKey = createRevisionSortKey({
19
+ version
20
+ });
21
+ const key = `${partitionKey}__${sortKey}`;
22
+ if (!keys.has(key)) {
23
+ keys.add(key);
24
+ reader.get({
25
+ PK: partitionKey,
26
+ SK: sortKey
27
+ });
28
+ }
29
+ }
30
+ const records = await reader.execute();
31
+ const items = cleanupItems(entity.entity, records).map((item)=>item.data);
32
+ return ids.map((id)=>items.filter((item)=>{
33
+ if (item.modelId !== modelId) return false;
34
+ return id === item.id;
35
+ }));
36
+ }, {
37
+ batchScheduleFn: createBatchScheduleFn()
38
+ });
39
+ };
40
+ export { createGetRevisionById };
41
+
42
+ //# sourceMappingURL=getRevisionById.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/dataLoader/getRevisionById.js","sources":["../../../../src/operations/entry/dataLoader/getRevisionById.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup.js\";\nimport { createPartitionKey, createRevisionSortKey } from \"~/operations/entry/keys.js\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn.js\";\n\nexport const createGetRevisionById = (params: IDataLoaderParams) => {\n const { entity, tenant, modelId } = params;\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async ids => {\n const reader = entity.createEntityReader();\n\n const keys = new Set<string>();\n\n for (const id of ids) {\n const partitionKey = createPartitionKey({\n tenant,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n continue;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const key = `${partitionKey}__${sortKey}`;\n if (keys.has(key)) {\n continue;\n }\n keys.add(key);\n\n reader.get({\n PK: partitionKey,\n SK: sortKey\n });\n }\n\n const records = await reader.execute();\n const items = cleanupItems(entity.entity, records).map(item => {\n return item.data;\n });\n\n return ids.map(id => {\n return items.filter(item => {\n if (item.modelId !== modelId) {\n return false;\n }\n return id === item.id;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"names":["createGetRevisionById","params","entity","tenant","modelId","DataLoader","ids","reader","keys","Set","id","partitionKey","createPartitionKey","version","parseIdentifier","sortKey","createRevisionSortKey","key","records","items","cleanupItems","item","createBatchScheduleFn"],"mappings":";;;;;AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAEpC,OAAO,IAAII,WACP,OAAMC;QACF,MAAMC,SAASL,OAAO,kBAAkB;QAExC,MAAMM,OAAO,IAAIC;QAEjB,KAAK,MAAMC,MAAMJ,IAAK;YAClB,MAAMK,eAAeC,mBAAmB;gBACpCT;gBACAO;YACJ;YACA,MAAM,EAAEG,OAAO,EAAE,GAAGC,gBAAgBJ;YACpC,IAAIG,AAAY,SAAZA,SACA;YAEJ,MAAME,UAAUC,sBAAsB;gBAClCH;YACJ;YACA,MAAMI,MAAM,GAAGN,aAAa,EAAE,EAAEI,SAAS;YACzC,KAAIP,KAAK,GAAG,CAACS;gBAGbT,KAAK,GAAG,CAACS;gBAETV,OAAO,GAAG,CAAC;oBACP,IAAII;oBACJ,IAAII;gBACR;;QACJ;QAEA,MAAMG,UAAU,MAAMX,OAAO,OAAO;QACpC,MAAMY,QAAQC,aAAalB,OAAO,MAAM,EAAEgB,SAAS,GAAG,CAACG,CAAAA,OAC5CA,KAAK,IAAI;QAGpB,OAAOf,IAAI,GAAG,CAACI,CAAAA,KACJS,MAAM,MAAM,CAACE,CAAAA;gBAChB,IAAIA,KAAK,OAAO,KAAKjB,SACjB,OAAO;gBAEX,OAAOM,OAAOW,KAAK,EAAE;YACzB;IAER,GACA;QACI,iBAAiBC;IACrB;AAER"}
@@ -0,0 +1,8 @@
1
+ import type DataLoader from "dataloader";
2
+ import type { IDataLoaderParams } from "./types.js";
3
+ export * from "./DataLoaderCache.js";
4
+ interface Callable {
5
+ (params: IDataLoaderParams): DataLoader<any, any>;
6
+ }
7
+ export type DataLoaders = "getAllEntryRevisions" | "getRevisionById" | "getPublishedRevisionByEntryId" | "getLatestRevisionByEntryId";
8
+ export declare const getDataLoaderFactory: (name: string) => Callable;
@@ -0,0 +1,18 @@
1
+ import { createGetAllEntryRevisions } from "./getAllEntryRevisions.js";
2
+ import { createGetLatestRevisionByEntryId } from "./getLatestRevisionByEntryId.js";
3
+ import { createGetPublishedRevisionByEntryId } from "./getPublishedRevisionByEntryId.js";
4
+ import { createGetRevisionById } from "./getRevisionById.js";
5
+ export * from "./DataLoaderCache.js";
6
+ const dataLoaders = {
7
+ getAllEntryRevisions: createGetAllEntryRevisions,
8
+ getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,
9
+ getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,
10
+ getRevisionById: createGetRevisionById
11
+ };
12
+ const getDataLoaderFactory = (name)=>{
13
+ if (!dataLoaders[name]) throw new Error(`Missing data loader "${name}".`);
14
+ return dataLoaders[name];
15
+ };
16
+ export { getDataLoaderFactory };
17
+
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/dataLoader/index.js","sources":["../../../../src/operations/entry/dataLoader/index.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { createGetAllEntryRevisions } from \"./getAllEntryRevisions.js\";\nimport { createGetLatestRevisionByEntryId } from \"./getLatestRevisionByEntryId.js\";\nimport { createGetPublishedRevisionByEntryId } from \"./getPublishedRevisionByEntryId.js\";\nimport { createGetRevisionById } from \"./getRevisionById.js\";\n\nexport * from \"./DataLoaderCache.js\";\n\ninterface Callable {\n (params: IDataLoaderParams): DataLoader<any, any>;\n}\n\nconst dataLoaders: Record<string, Callable> = {\n getAllEntryRevisions: createGetAllEntryRevisions,\n getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,\n getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,\n getRevisionById: createGetRevisionById\n};\n\nexport type DataLoaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nexport const getDataLoaderFactory = (name: string) => {\n if (!dataLoaders[name]) {\n throw new Error(`Missing data loader \"${name}\".`);\n }\n return dataLoaders[name];\n};\n"],"names":["dataLoaders","createGetAllEntryRevisions","createGetLatestRevisionByEntryId","createGetPublishedRevisionByEntryId","createGetRevisionById","getDataLoaderFactory","name","Error"],"mappings":";;;;;AAaA,MAAMA,cAAwC;IAC1C,sBAAsBC;IACtB,4BAA4BC;IAC5B,+BAA+BC;IAC/B,iBAAiBC;AACrB;AAQO,MAAMC,uBAAuB,CAACC;IACjC,IAAI,CAACN,WAAW,CAACM,KAAK,EAClB,MAAM,IAAIC,MAAM,CAAC,qBAAqB,EAAED,KAAK,EAAE,CAAC;IAEpD,OAAON,WAAW,CAACM,KAAK;AAC5B"}
@@ -0,0 +1,6 @@
1
+ import type { IEntryEntity } from "../../../definitions/types.js";
2
+ export interface IDataLoaderParams {
3
+ entity: IEntryEntity;
4
+ tenant: string;
5
+ modelId: string;
6
+ }
File without changes
@@ -1,42 +1,26 @@
1
- import { CmsStorageEntry, CmsModel } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
3
- export interface GetAllEntryRevisionsParams {
1
+ import type { CmsEntryValues, CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { DataLoadersHandlerInterfaceClearAllParams, IDataLoadersHandler, IEntryEntity } from "../../types.js";
3
+ interface DataLoaderParams {
4
+ model: Pick<CmsModel, "tenant" | "modelId">;
4
5
  ids: readonly string[];
5
- model: CmsModel;
6
6
  }
7
- export interface GetRevisionByIdParams {
8
- ids: readonly string[];
9
- model: CmsModel;
10
- }
11
- export interface GetPublishedRevisionByEntryIdParams {
12
- ids: readonly string[];
13
- model: CmsModel;
14
- }
15
- export interface GetLatestRevisionByEntryIdParams {
16
- ids: readonly string[];
17
- model: CmsModel;
18
- }
19
- interface ClearLoaderParams {
20
- model: CmsModel;
21
- entry?: CmsStorageEntry;
22
- }
23
- interface DataLoadersHandlerParams {
24
- entity: Entity<any>;
7
+ interface IDataLoadersHandlerParams {
8
+ entity: IEntryEntity;
25
9
  }
26
- export declare class DataLoadersHandler {
27
- private readonly loaders;
10
+ export declare class DataLoadersHandler implements IDataLoadersHandler {
28
11
  private readonly entity;
29
- constructor(params: DataLoadersHandlerParams);
30
- getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsStorageEntry[]>;
31
- getRevisionById(params: GetRevisionByIdParams): Promise<CmsStorageEntry[]>;
32
- getPublishedRevisionByEntryId(params: GetPublishedRevisionByEntryIdParams): Promise<CmsStorageEntry[]>;
33
- getLatestRevisionByEntryId(params: GetLatestRevisionByEntryIdParams): Promise<CmsStorageEntry[]>;
12
+ private readonly cache;
13
+ constructor(params: IDataLoadersHandlerParams);
14
+ getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
15
+ getRevisionById<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
16
+ getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
17
+ getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
34
18
  /**
35
19
  * TODO @ts-refactor
36
20
  * Maybe pass on the generics to DataLoader definition?
37
21
  */
38
22
  private getLoader;
39
23
  private loadMany;
40
- clearAll(params: Omit<ClearLoaderParams, "entry">): void;
24
+ clearAll(params?: DataLoadersHandlerInterfaceClearAllParams): void;
41
25
  }
42
26
  export {};
@@ -1,321 +1,90 @@
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.DataLoadersHandler = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- var _dataloader = _interopRequireDefault(require("dataloader"));
15
-
16
- var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
- var _query = require("@webiny/db-dynamodb/utils/query");
19
-
20
- var _keys = require("./keys");
21
-
22
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
23
-
24
- var _utils = require("@webiny/utils");
25
-
26
- var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
27
-
28
- const getAllEntryRevisions = params => {
29
- const {
30
- entity,
31
- model
32
- } = params;
33
- const {
34
- tenant,
35
- locale
36
- } = model;
37
- return new _dataloader.default(async ids => {
38
- const results = {};
39
-
40
- for (const id of ids) {
41
- const queryAllParams = {
42
- entity,
43
- partitionKey: (0, _keys.createPartitionKey)({
44
- tenant,
45
- locale,
46
- id
47
- }),
48
- options: {
49
- beginsWith: "REV#"
50
- }
51
- };
52
- const items = await (0, _query.queryAll)(queryAllParams);
53
- results[id] = (0, _cleanup.cleanupItems)(entity, items);
54
- }
55
-
56
- return ids.map(id => {
57
- return results[id] || [];
58
- });
59
- });
60
- };
61
-
62
- const getRevisionById = params => {
63
- const {
64
- entity,
65
- model
66
- } = params;
67
- const {
68
- locale,
69
- tenant
70
- } = model;
71
- return new _dataloader.default(async ids => {
72
- const queries = ids.reduce((collection, id) => {
73
- const partitionKey = (0, _keys.createPartitionKey)({
74
- tenant,
75
- locale,
76
- id
77
- });
78
- const {
79
- version
80
- } = (0, _utils.parseIdentifier)(id);
81
-
82
- if (version === null) {
83
- return collection;
84
- }
85
-
86
- const sortKey = (0, _keys.createRevisionSortKey)({
87
- version
88
- });
89
- const keys = `${partitionKey}__${sortKey}`;
90
-
91
- if (collection[keys]) {
92
- return collection;
93
- }
94
-
95
- collection[keys] = entity.getBatch({
96
- PK: partitionKey,
97
- SK: sortKey
98
- });
99
- return collection;
100
- /**
101
- * We cast as any because there is no return type defined.
102
- */
103
- }, {});
104
- const records = await (0, _batchRead.batchReadAll)({
105
- table: entity.table,
106
- items: Object.values(queries)
107
- });
108
- const items = (0, _cleanup.cleanupItems)(entity, records);
109
- return ids.map(id => {
110
- return items.filter(item => {
111
- return id === item.id;
112
- });
113
- });
114
- });
115
- };
116
-
117
- const getPublishedRevisionByEntryId = params => {
118
- const {
119
- entity,
120
- model
121
- } = params;
122
- const {
123
- locale,
124
- tenant
125
- } = model;
126
- const publishedKey = (0, _keys.createPublishedSortKey)();
127
- return new _dataloader.default(async ids => {
128
- const queries = ids.reduce((collection, id) => {
129
- const partitionKey = (0, _keys.createPartitionKey)({
130
- tenant,
131
- locale,
132
- id
133
- });
134
-
135
- if (collection[partitionKey]) {
136
- return collection;
137
- }
138
-
139
- collection[partitionKey] = entity.getBatch({
140
- PK: partitionKey,
141
- SK: publishedKey
142
- });
143
- return collection;
144
- /**
145
- * We cast as any because there is no return type defined.
146
- */
147
- }, {});
148
- const records = await (0, _batchRead.batchReadAll)({
149
- table: entity.table,
150
- items: Object.values(queries)
151
- });
152
- const items = (0, _cleanup.cleanupItems)(entity, records);
153
- return ids.map(id => {
154
- const {
155
- id: entryId
156
- } = (0, _utils.parseIdentifier)(id);
157
- return items.filter(item => {
158
- return entryId === item.entryId;
159
- });
160
- });
161
- });
162
- };
163
-
164
- const getLatestRevisionByEntryId = params => {
165
- const {
166
- entity,
167
- model
168
- } = params;
169
- const {
170
- locale,
171
- tenant
172
- } = model;
173
- const latestKey = (0, _keys.createLatestSortKey)();
174
- return new _dataloader.default(async ids => {
175
- const queries = ids.reduce((collection, id) => {
176
- const partitionKey = (0, _keys.createPartitionKey)({
177
- tenant,
178
- locale,
179
- id
180
- });
181
-
182
- if (collection[partitionKey]) {
183
- return collection;
184
- }
185
-
186
- collection[partitionKey] = entity.getBatch({
187
- PK: partitionKey,
188
- SK: latestKey
189
- });
190
- return collection;
191
- /**
192
- * We cast as any because there is no return type defined.
193
- */
194
- }, {});
195
- const records = await (0, _batchRead.batchReadAll)({
196
- table: entity.table,
197
- items: Object.values(queries)
198
- });
199
- const items = (0, _cleanup.cleanupItems)(entity, records);
200
- return ids.map(id => {
201
- const {
202
- id: entryId
203
- } = (0, _utils.parseIdentifier)(id);
204
- return items.filter(item => {
205
- return entryId === item.entryId;
206
- });
207
- });
208
- });
209
- };
210
-
211
- const dataLoaders = {
212
- getAllEntryRevisions,
213
- getRevisionById,
214
- getPublishedRevisionByEntryId,
215
- getLatestRevisionByEntryId
216
- };
217
- const loaderNames = Object.keys(dataLoaders);
218
-
1
+ import error from "@webiny/error";
2
+ import { DataLoaderCache } from "./dataLoader/DataLoaderCache.js";
3
+ import { getDataLoaderFactory } from "./dataLoader/index.js";
4
+ import { parseIdentifier } from "@webiny/utils";
219
5
  class DataLoadersHandler {
220
- constructor(params) {
221
- (0, _defineProperty2.default)(this, "loaders", new Map());
222
- (0, _defineProperty2.default)(this, "entity", void 0);
223
- this.entity = params.entity;
224
- }
225
-
226
- async getAllEntryRevisions(params) {
227
- return await this.loadMany("getAllEntryRevisions", params, params.ids);
228
- }
229
-
230
- async getRevisionById(params) {
231
- return await this.loadMany("getRevisionById", params, params.ids);
232
- }
233
-
234
- async getPublishedRevisionByEntryId(params) {
235
- return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
236
- }
237
-
238
- async getLatestRevisionByEntryId(params) {
239
- return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
240
- }
241
- /**
242
- * TODO @ts-refactor
243
- * Maybe pass on the generics to DataLoader definition?
244
- */
245
-
246
-
247
- getLoader(name, params) {
248
- if (!dataLoaders[name]) {
249
- throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
250
- name
251
- });
6
+ constructor(params){
7
+ this.cache = new DataLoaderCache();
8
+ this.entity = params.entity;
252
9
  }
253
-
254
- const {
255
- model
256
- } = params;
257
- const {
258
- tenant,
259
- locale
260
- } = model;
261
- const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
262
-
263
- if (!this.loaders.has(loaderKey)) {
264
- this.loaders.set(loaderKey, dataLoaders[name]((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
265
- entity: this.entity
266
- })));
10
+ async getAllEntryRevisions(params) {
11
+ const ids = params.ids.map((id)=>{
12
+ const { id: entryId } = parseIdentifier(id);
13
+ return entryId;
14
+ });
15
+ return await this.loadMany("getAllEntryRevisions", params, ids);
267
16
  }
268
-
269
- return this.loaders.get(loaderKey);
270
- }
271
-
272
- async loadMany(loader, params, ids) {
273
- let results;
274
-
275
- try {
276
- results = await this.getLoader(loader, params).loadMany(ids);
277
-
278
- if (Array.isArray(results) === true) {
279
- return results.reduce((acc, res) => {
280
- if (Array.isArray(res) === false) {
281
- if (res && res.message) {
282
- throw new _error.default(res.message, res.code, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, res), {}, {
283
- data: JSON.stringify(res.data || {})
284
- }));
285
- }
286
-
287
- throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
288
- loader
289
- }));
290
- }
291
-
292
- acc.push(...res);
293
- return acc;
294
- }, []);
295
- }
296
- } catch (ex) {
297
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
298
- error: ex
299
- }, params), {}, {
300
- loader,
301
- ids
302
- }));
17
+ async getRevisionById(params) {
18
+ return await this.loadMany("getRevisionById", params, params.ids);
303
19
  }
304
-
305
- throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
306
- loader,
307
- ids,
308
- results
309
- });
310
- }
311
-
312
- clearAll(params) {
313
- for (const name of loaderNames) {
314
- const loader = this.getLoader(name, params);
315
- loader.clearAll();
20
+ async getPublishedRevisionByEntryId(params) {
21
+ const ids = params.ids.map((id)=>{
22
+ const { id: entryId } = parseIdentifier(id);
23
+ return entryId;
24
+ });
25
+ return await this.loadMany("getPublishedRevisionByEntryId", params, ids);
26
+ }
27
+ async getLatestRevisionByEntryId(params) {
28
+ const ids = params.ids.map((id)=>{
29
+ const { id: entryId } = parseIdentifier(id);
30
+ return entryId;
31
+ });
32
+ return await this.loadMany("getLatestRevisionByEntryId", params, ids);
33
+ }
34
+ getLoader(name, params) {
35
+ const { model } = params;
36
+ const cacheParams = {
37
+ tenant: model.tenant,
38
+ modelId: model.modelId,
39
+ name
40
+ };
41
+ let loader = this.cache.getDataLoader(cacheParams);
42
+ if (loader) return loader;
43
+ const factory = getDataLoaderFactory(name);
44
+ loader = factory({
45
+ entity: this.entity,
46
+ tenant: model.tenant,
47
+ modelId: model.modelId
48
+ });
49
+ this.cache.setDataLoader(cacheParams, loader);
50
+ return loader;
51
+ }
52
+ async loadMany(loader, params, ids) {
53
+ let results = [];
54
+ try {
55
+ results = await this.getLoader(loader, params).loadMany(ids);
56
+ if (true === Array.isArray(results)) return results.reduce((acc, res)=>{
57
+ if (false === Array.isArray(res)) {
58
+ if (res && res.message) throw new error(res.message, res.code, {
59
+ ...res,
60
+ data: JSON.stringify(res.data || {})
61
+ });
62
+ throw new error("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
63
+ ...params,
64
+ loader
65
+ });
66
+ }
67
+ acc.push(...res);
68
+ return acc;
69
+ }, []);
70
+ } catch (ex) {
71
+ throw new error(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
72
+ error: ex,
73
+ ...params,
74
+ loader,
75
+ ids
76
+ });
77
+ }
78
+ throw new error("Data loader did not return array of items or empty array.", "INVALID_DATA_LOADER_RESULT", {
79
+ loader,
80
+ ids,
81
+ results
82
+ });
83
+ }
84
+ clearAll(params) {
85
+ this.cache.clearAll(params?.model);
316
86
  }
317
- }
318
-
319
87
  }
88
+ export { DataLoadersHandler };
320
89
 
321
- exports.DataLoadersHandler = DataLoadersHandler;
90
+ //# sourceMappingURL=dataLoaders.js.map