@webiny/api-headless-cms-ddb 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c27f4d8a31

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 (169) hide show
  1. package/README.md +6 -20
  2. package/definitions/entry.d.ts +4 -5
  3. package/definitions/entry.js +6 -89
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.d.ts +4 -5
  6. package/definitions/group.js +6 -63
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.d.ts +4 -5
  9. package/definitions/model.js +6 -90
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/table.d.ts +4 -6
  12. package/definitions/table.js +7 -28
  13. package/definitions/table.js.map +1 -1
  14. package/definitions/types.d.ts +60 -0
  15. package/definitions/types.js +3 -0
  16. package/definitions/types.js.map +1 -0
  17. package/dynamoDb/index.d.ts +1 -1
  18. package/dynamoDb/index.js +8 -20
  19. package/dynamoDb/index.js.map +1 -1
  20. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  21. package/dynamoDb/path/locationFolderId.js +34 -0
  22. package/dynamoDb/path/locationFolderId.js.map +1 -0
  23. package/dynamoDb/path/plainObject.d.ts +1 -1
  24. package/dynamoDb/path/plainObject.js +6 -20
  25. package/dynamoDb/path/plainObject.js.map +1 -1
  26. package/dynamoDb/storage/longText.js +13 -35
  27. package/dynamoDb/storage/longText.js.map +1 -1
  28. package/dynamoDb/storage/richText.js +27 -88
  29. package/dynamoDb/storage/richText.js.map +1 -1
  30. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  31. package/dynamoDb/transformValue/datetime.js +7 -19
  32. package/dynamoDb/transformValue/datetime.js.map +1 -1
  33. package/index.d.ts +2 -2
  34. package/index.js +47 -111
  35. package/index.js.map +1 -1
  36. package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
  37. package/operations/entry/dataLoader/DataLoaderCache.js +31 -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 +4 -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 +19 -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 +35 -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 +50 -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 +50 -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 +56 -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 +19 -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 +3 -0
  62. package/operations/entry/dataLoader/types.js.map +1 -0
  63. package/operations/entry/dataLoaders.d.ts +14 -30
  64. package/operations/entry/dataLoaders.js +58 -271
  65. package/operations/entry/dataLoaders.js.map +1 -1
  66. package/operations/entry/filtering/createExpressions.d.ts +5 -5
  67. package/operations/entry/filtering/createExpressions.js +30 -68
  68. package/operations/entry/filtering/createExpressions.js.map +1 -1
  69. package/operations/entry/filtering/createFields.d.ts +6 -4
  70. package/operations/entry/filtering/createFields.js +86 -103
  71. package/operations/entry/filtering/createFields.js.map +1 -1
  72. package/operations/entry/filtering/extractSort.d.ts +6 -6
  73. package/operations/entry/filtering/extractSort.js +39 -32
  74. package/operations/entry/filtering/extractSort.js.map +1 -1
  75. package/operations/entry/filtering/filter.d.ts +6 -6
  76. package/operations/entry/filtering/filter.js +36 -64
  77. package/operations/entry/filtering/filter.js.map +1 -1
  78. package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
  79. package/operations/entry/filtering/fullTextSearch.js +6 -24
  80. package/operations/entry/filtering/fullTextSearch.js.map +1 -1
  81. package/operations/entry/filtering/getValue.js +5 -27
  82. package/operations/entry/filtering/getValue.js.map +1 -1
  83. package/operations/entry/filtering/index.d.ts +2 -2
  84. package/operations/entry/filtering/index.js +3 -20
  85. package/operations/entry/filtering/index.js.map +1 -1
  86. package/operations/entry/filtering/mapPlugins.d.ts +2 -2
  87. package/operations/entry/filtering/mapPlugins.js +4 -18
  88. package/operations/entry/filtering/mapPlugins.js.map +1 -1
  89. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -2
  90. package/operations/entry/filtering/plugins/defaultFilterCreate.js +9 -20
  91. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
  92. package/operations/entry/filtering/plugins/index.d.ts +1 -1
  93. package/operations/entry/filtering/plugins/index.js +7 -16
  94. package/operations/entry/filtering/plugins/index.js.map +1 -1
  95. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -2
  96. package/operations/entry/filtering/plugins/objectFilterCreate.js +16 -39
  97. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
  98. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -2
  99. package/operations/entry/filtering/plugins/refFilterCreate.js +21 -36
  100. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
  101. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  102. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +57 -0
  103. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  104. package/operations/entry/filtering/sort.d.ts +6 -6
  105. package/operations/entry/filtering/sort.js +17 -34
  106. package/operations/entry/filtering/sort.js.map +1 -1
  107. package/operations/entry/filtering/systemFields.d.ts +2 -4
  108. package/operations/entry/filtering/systemFields.js +102 -43
  109. package/operations/entry/filtering/systemFields.js.map +1 -1
  110. package/operations/entry/filtering/transform.d.ts +1 -1
  111. package/operations/entry/filtering/transform.js +2 -10
  112. package/operations/entry/filtering/transform.js.map +1 -1
  113. package/operations/entry/filtering/types.d.ts +3 -3
  114. package/operations/entry/filtering/types.js +2 -4
  115. package/operations/entry/filtering/types.js.map +1 -1
  116. package/operations/entry/filtering/values.d.ts +1 -1
  117. package/operations/entry/filtering/values.js +5 -17
  118. package/operations/entry/filtering/values.js.map +1 -1
  119. package/operations/entry/filtering/where.js +5 -15
  120. package/operations/entry/filtering/where.js.map +1 -1
  121. package/operations/entry/index.d.ts +3 -4
  122. package/operations/entry/index.js +732 -410
  123. package/operations/entry/index.js.map +1 -1
  124. package/operations/entry/keys.d.ts +40 -2
  125. package/operations/entry/keys.js +54 -47
  126. package/operations/entry/keys.js.map +1 -1
  127. package/operations/group/index.d.ts +4 -4
  128. package/operations/group/index.js +44 -91
  129. package/operations/group/index.js.map +1 -1
  130. package/operations/model/index.d.ts +3 -3
  131. package/operations/model/index.js +36 -70
  132. package/operations/model/index.js.map +1 -1
  133. package/package.json +22 -29
  134. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
  135. package/plugins/CmsEntryFieldFilterPathPlugin.js +14 -29
  136. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  137. package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
  138. package/plugins/CmsEntryFieldFilterPlugin.js +9 -19
  139. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
  140. package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
  141. package/plugins/CmsEntryFieldSortingPlugin.js +5 -24
  142. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
  143. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  144. package/plugins/CmsFieldFilterValueTransformPlugin.js +16 -0
  145. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  146. package/plugins/index.d.ts +4 -3
  147. package/plugins/index.js +5 -43
  148. package/plugins/index.js.map +1 -1
  149. package/types.d.ts +24 -19
  150. package/types.js +5 -13
  151. package/types.js.map +1 -1
  152. package/definitions/settings.d.ts +0 -9
  153. package/definitions/settings.js +0 -58
  154. package/definitions/settings.js.map +0 -1
  155. package/definitions/system.d.ts +0 -9
  156. package/definitions/system.js +0 -46
  157. package/definitions/system.js.map +0 -1
  158. package/dynamoDb/storage/date.d.ts +0 -3
  159. package/dynamoDb/storage/date.js +0 -109
  160. package/dynamoDb/storage/date.js.map +0 -1
  161. package/operations/entry/systemFields.d.ts +0 -2
  162. package/operations/entry/systemFields.js +0 -74
  163. package/operations/entry/systemFields.js.map +0 -1
  164. package/operations/settings/index.d.ts +0 -7
  165. package/operations/settings/index.js +0 -135
  166. package/operations/settings/index.js.map +0 -1
  167. package/operations/system/index.d.ts +0 -7
  168. package/operations/system/index.js +0 -99
  169. package/operations/system/index.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"names":["createSystemEntity","params","entityName","attributes","table","Entity","name","PK","partitionKey","SK","sortKey","version","type","locale","tenant","readAPIKey"],"sources":["system.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSystemEntity = (params: Params): Entity<any> => {\n const { entityName, attributes, table } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n version: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n readAPIKey: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,kBAAkB,GAAIC,MAAD,IAAiC;EAC/D,MAAM;IAAEC,UAAF;IAAcC,UAAd;IAA0BC;EAA1B,IAAoCH,MAA1C;EACA,OAAO,IAAII,uBAAJ,CAAW;IACdC,IAAI,EAAEJ,UADQ;IAEdE,KAFc;IAGdD,UAAU;MACNI,EAAE,EAAE;QACAC,YAAY,EAAE;MADd,CADE;MAINC,EAAE,EAAE;QACAC,OAAO,EAAE;MADT,CAJE;MAONC,OAAO,EAAE;QACLC,IAAI,EAAE;MADD,CAPH;MAUNC,MAAM,EAAE;QACJD,IAAI,EAAE;MADF,CAVF;MAaNE,MAAM,EAAE;QACJF,IAAI,EAAE;MADF,CAbF;MAgBNG,UAAU,EAAE;QACRH,IAAI,EAAE;MADE;IAhBN,GAmBFT,UAAU,IAAI,EAnBZ;EAHI,CAAX,CAAP;AAyBH,CA3BM"}
@@ -1,3 +0,0 @@
1
- import { StorageTransformPlugin } from "@webiny/api-headless-cms";
2
- import { CmsModelField } from "@webiny/api-headless-cms/types";
3
- export declare const createDateStorageTransformPlugin: () => StorageTransformPlugin<any, any, CmsModelField>;
@@ -1,109 +0,0 @@
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.createDateStorageTransformPlugin = void 0;
9
-
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- var _apiHeadlessCms = require("@webiny/api-headless-cms");
13
-
14
- /**
15
- * File is @internal
16
- */
17
- const excludeTypes = ["time", "dateTimeWithTimezone"];
18
-
19
- const convertFromStorage = (field, value) => {
20
- try {
21
- if (field.multipleValues) {
22
- const result = [];
23
-
24
- for (const v of value) {
25
- if (!v) {
26
- continue;
27
- }
28
-
29
- try {
30
- result.push(new Date(v));
31
- } catch {}
32
- }
33
-
34
- return result;
35
- }
36
-
37
- return new Date(value);
38
- } catch {
39
- console.log(`Could not transform from storage for field type`);
40
- return value;
41
- }
42
- };
43
-
44
- const convertValueToStorage = (field, value) => {
45
- if (value.toISOString) {
46
- return value.toISOString();
47
- } else if (typeof value === "string") {
48
- return value;
49
- }
50
-
51
- throw new _error.default("Error converting value to a storage type.", "TO_STORAGE_ERROR", {
52
- value: value,
53
- fieldId: field.fieldId,
54
- storageId: field.storageId
55
- });
56
- };
57
-
58
- const createDateStorageTransformPlugin = () => {
59
- return new _apiHeadlessCms.StorageTransformPlugin({
60
- fieldType: "datetime",
61
- fromStorage: async ({
62
- value,
63
- field
64
- }) => {
65
- const {
66
- type
67
- } = field.settings || {};
68
-
69
- if (!value || !type || excludeTypes.includes(type)) {
70
- return value;
71
- }
72
-
73
- return convertFromStorage(field, value);
74
- },
75
- toStorage: async ({
76
- value,
77
- field
78
- }) => {
79
- const {
80
- type
81
- } = field.settings || {};
82
-
83
- if (!value || !type || excludeTypes.includes(type)) {
84
- return value;
85
- }
86
-
87
- if (field.multipleValues) {
88
- const multipleValues = value;
89
- return (multipleValues || []).filter(v => !!v).map(v => {
90
- return convertValueToStorage(field, v);
91
- });
92
- }
93
-
94
- if (value.toISOString) {
95
- return value.toISOString();
96
- } else if (typeof value === "string") {
97
- return value;
98
- }
99
-
100
- throw new _error.default("Error converting value to a storage type.", "TO_STORAGE_ERROR", {
101
- value,
102
- fieldId: field.fieldId,
103
- storageId: field.storageId
104
- });
105
- }
106
- });
107
- };
108
-
109
- exports.createDateStorageTransformPlugin = createDateStorageTransformPlugin;
@@ -1 +0,0 @@
1
- {"version":3,"names":["excludeTypes","convertFromStorage","field","value","multipleValues","result","v","push","Date","console","log","convertValueToStorage","toISOString","WebinyError","fieldId","storageId","createDateStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","type","settings","includes","toStorage","filter","map"],"sources":["date.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\nconst excludeTypes = [\"time\", \"dateTimeWithTimezone\"];\n\nconst convertFromStorage = (\n field: Pick<CmsModelField, \"multipleValues\">,\n value: string | string[]\n) => {\n try {\n if (field.multipleValues) {\n const result: Date[] = [];\n for (const v of value) {\n if (!v) {\n continue;\n }\n try {\n result.push(new Date(v));\n } catch {}\n }\n return result;\n }\n return new Date(value as string);\n } catch {\n console.log(`Could not transform from storage for field type`);\n return value;\n }\n};\n\nconst convertValueToStorage = (field: CmsModelField, value: any): any => {\n if ((value as any).toISOString) {\n return (value as Date).toISOString();\n } else if (typeof value === \"string\") {\n return value as string;\n }\n throw new WebinyError(\"Error converting value to a storage type.\", \"TO_STORAGE_ERROR\", {\n value: value,\n fieldId: field.fieldId,\n storageId: field.storageId\n });\n};\n\nexport const createDateStorageTransformPlugin = () => {\n return new StorageTransformPlugin({\n fieldType: \"datetime\",\n fromStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\n }\n return convertFromStorage(field, value);\n },\n toStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\n }\n if (field.multipleValues) {\n const multipleValues = value as (string | Date | null | undefined)[];\n return (multipleValues || [])\n .filter(v => !!v)\n .map(v => {\n return convertValueToStorage(field, v);\n });\n }\n if ((value as any).toISOString) {\n return (value as Date).toISOString();\n } else if (typeof value === \"string\") {\n return value as string;\n }\n throw new WebinyError(\"Error converting value to a storage type.\", \"TO_STORAGE_ERROR\", {\n value,\n fieldId: field.fieldId,\n storageId: field.storageId\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAKA,MAAMA,YAAY,GAAG,CAAC,MAAD,EAAS,sBAAT,CAArB;;AAEA,MAAMC,kBAAkB,GAAG,CACvB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,EAAoD;QAChD,OAAOjB,KAAP;MACH;;MACD,OAAOF,kBAAkB,CAACC,KAAD,EAAQC,KAAR,CAAzB;IACH,CAR6B;IAS9BoB,SAAS,EAAE,OAAO;MAAEpB,KAAF;MAASD;IAAT,CAAP,KAA4B;MACnC,MAAM;QAAEkB;MAAF,IAAWlB,KAAK,CAACmB,QAAN,IAAkB,EAAnC;;MACA,IAAI,CAAClB,KAAD,IAAU,CAACiB,IAAX,IAAmBpB,YAAY,CAACsB,QAAb,CAAsBF,IAAtB,CAAvB,EAAoD;QAChD,OAAOjB,KAAP;MACH;;MACD,IAAID,KAAK,CAACE,cAAV,EAA0B;QACtB,MAAMA,cAAc,GAAGD,KAAvB;QACA,OAAO,CAACC,cAAc,IAAI,EAAnB,EACFoB,MADE,CACKlB,CAAC,IAAI,CAAC,CAACA,CADZ,EAEFmB,GAFE,CAEEnB,CAAC,IAAI;UACN,OAAOK,qBAAqB,CAACT,KAAD,EAAQI,CAAR,CAA5B;QACH,CAJE,CAAP;MAKH;;MACD,IAAKH,KAAD,CAAeS,WAAnB,EAAgC;QAC5B,OAAQT,KAAD,CAAgBS,WAAhB,EAAP;MACH,CAFD,MAEO,IAAI,OAAOT,KAAP,KAAiB,QAArB,EAA+B;QAClC,OAAOA,KAAP;MACH;;MACD,MAAM,IAAIU,cAAJ,CAAgB,2CAAhB,EAA6D,kBAA7D,EAAiF;QACnFV,KADmF;QAEnFW,OAAO,EAAEZ,KAAK,CAACY,OAFoE;QAGnFC,SAAS,EAAEb,KAAK,CAACa;MAHkE,CAAjF,CAAN;IAKH;EAhC6B,CAA3B,CAAP;AAkCH,CAnCM"}
@@ -1,2 +0,0 @@
1
- import { CmsModelField } from "@webiny/api-headless-cms/types";
2
- export declare const systemFields: Record<string, CmsModelField>;
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.systemFields = void 0;
7
-
8
- const createSystemField = field => {
9
- return field;
10
- };
11
-
12
- const systemFields = {
13
- id: createSystemField({
14
- id: "id",
15
- type: "text",
16
- storageId: "id",
17
- fieldId: "id"
18
- }),
19
- entryId: createSystemField({
20
- id: "entryId",
21
- type: "text",
22
- storageId: "entryId",
23
- fieldId: "entryId"
24
- }),
25
- createdOn: createSystemField({
26
- id: "createdOn",
27
- type: "datetime",
28
- storageId: "createdOn",
29
- fieldId: "createdOn"
30
- }),
31
- savedOn: createSystemField({
32
- id: "savedOn",
33
- type: "datetime",
34
- storageId: "savedOn",
35
- fieldId: "savedOn"
36
- }),
37
- createdBy: createSystemField({
38
- id: "createdBy",
39
- type: "plainObject",
40
- storageId: "createdBy",
41
- fieldId: "createdBy",
42
- settings: {
43
- path: "createdBy.id"
44
- }
45
- }),
46
- meta: createSystemField({
47
- id: "meta",
48
- type: "plainObject",
49
- storageId: "meta",
50
- fieldId: "meta"
51
- }),
52
- ownedBy: createSystemField({
53
- id: "ownedBy",
54
- type: "plainObject",
55
- storageId: "ownedBy",
56
- fieldId: "ownedBy",
57
- settings: {
58
- path: "ownedBy.id"
59
- }
60
- }),
61
- version: createSystemField({
62
- id: "version",
63
- type: "number",
64
- storageId: "version",
65
- fieldId: "version"
66
- }),
67
- status: createSystemField({
68
- id: "status",
69
- type: "string",
70
- storageId: "status",
71
- fieldId: "status"
72
- })
73
- };
74
- exports.systemFields = systemFields;
@@ -1 +0,0 @@
1
- {"version":3,"names":["createSystemField","field","systemFields","id","type","storageId","fieldId","entryId","createdOn","savedOn","createdBy","settings","path","meta","ownedBy","version","status"],"sources":["systemFields.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\ntype CmsModelFieldInput = Partial<CmsModelField> &\n Pick<CmsModelField, \"id\" | \"type\" | \"storageId\" | \"fieldId\">;\nconst createSystemField = (field: CmsModelFieldInput): CmsModelField => {\n return field as CmsModelField;\n};\n\nexport const systemFields: Record<string, CmsModelField> = {\n id: createSystemField({\n id: \"id\",\n type: \"text\",\n storageId: \"id\",\n fieldId: \"id\"\n }),\n entryId: createSystemField({\n id: \"entryId\",\n type: \"text\",\n storageId: \"entryId\",\n fieldId: \"entryId\"\n }),\n createdOn: createSystemField({\n id: \"createdOn\",\n type: \"datetime\",\n storageId: \"createdOn\",\n fieldId: \"createdOn\"\n }),\n savedOn: createSystemField({\n id: \"savedOn\",\n type: \"datetime\",\n storageId: \"savedOn\",\n fieldId: \"savedOn\"\n }),\n createdBy: createSystemField({\n id: \"createdBy\",\n type: \"plainObject\",\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n settings: {\n path: \"createdBy.id\"\n }\n }),\n meta: createSystemField({\n id: \"meta\",\n type: \"plainObject\",\n storageId: \"meta\",\n fieldId: \"meta\"\n }),\n ownedBy: createSystemField({\n id: \"ownedBy\",\n type: \"plainObject\",\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n settings: {\n path: \"ownedBy.id\"\n }\n }),\n version: createSystemField({\n id: \"version\",\n type: \"number\",\n storageId: \"version\",\n fieldId: \"version\"\n }),\n status: createSystemField({\n id: \"status\",\n type: \"string\",\n storageId: \"status\",\n fieldId: \"status\"\n })\n};\n"],"mappings":";;;;;;;AAIA,MAAMA,iBAAiB,GAAIC,KAAD,IAA8C;EACpE,OAAOA,KAAP;AACH,CAFD;;AAIO,MAAMC,YAA2C,GAAG;EACvDC,EAAE,EAAEH,iBAAiB,CAAC;IAClBG,EAAE,EAAE,IADc;IAElBC,IAAI,EAAE,MAFY;IAGlBC,SAAS,EAAE,IAHO;IAIlBC,OAAO,EAAE;EAJS,CAAD,CADkC;EAOvDC,OAAO,EAAEP,iBAAiB,CAAC;IACvBG,EAAE,EAAE,SADmB;IAEvBC,IAAI,EAAE,MAFiB;IAGvBC,SAAS,EAAE,SAHY;IAIvBC,OAAO,EAAE;EAJc,CAAD,CAP6B;EAavDE,SAAS,EAAER,iBAAiB,CAAC;IACzBG,EAAE,EAAE,WADqB;IAEzBC,IAAI,EAAE,UAFmB;IAGzBC,SAAS,EAAE,WAHc;IAIzBC,OAAO,EAAE;EAJgB,CAAD,CAb2B;EAmBvDG,OAAO,EAAET,iBAAiB,CAAC;IACvBG,EAAE,EAAE,SADmB;IAEvBC,IAAI,EAAE,UAFiB;IAGvBC,SAAS,EAAE,SAHY;IAIvBC,OAAO,EAAE;EAJc,CAAD,CAnB6B;EAyBvDI,SAAS,EAAEV,iBAAiB,CAAC;IACzBG,EAAE,EAAE,WADqB;IAEzBC,IAAI,EAAE,aAFmB;IAGzBC,SAAS,EAAE,WAHc;IAIzBC,OAAO,EAAE,WAJgB;IAKzBK,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA;EALe,CAAD,CAzB2B;EAkCvDC,IAAI,EAAEb,iBAAiB,CAAC;IACpBG,EAAE,EAAE,MADgB;IAEpBC,IAAI,EAAE,aAFc;IAGpBC,SAAS,EAAE,MAHS;IAIpBC,OAAO,EAAE;EAJW,CAAD,CAlCgC;EAwCvDQ,OAAO,EAAEd,iBAAiB,CAAC;IACvBG,EAAE,EAAE,SADmB;IAEvBC,IAAI,EAAE,aAFiB;IAGvBC,SAAS,EAAE,SAHY;IAIvBC,OAAO,EAAE,SAJc;IAKvBK,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA;EALa,CAAD,CAxC6B;EAiDvDG,OAAO,EAAEf,iBAAiB,CAAC;IACvBG,EAAE,EAAE,SADmB;IAEvBC,IAAI,EAAE,QAFiB;IAGvBC,SAAS,EAAE,SAHY;IAIvBC,OAAO,EAAE;EAJc,CAAD,CAjD6B;EAuDvDU,MAAM,EAAEhB,iBAAiB,CAAC;IACtBG,EAAE,EAAE,QADkB;IAEtBC,IAAI,EAAE,QAFgB;IAGtBC,SAAS,EAAE,QAHW;IAItBC,OAAO,EAAE;EAJa,CAAD;AAvD8B,CAApD"}
@@ -1,7 +0,0 @@
1
- import { CmsSettingsStorageOperations } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
3
- interface CreateSettingsStorageOperationsParams {
4
- entity: Entity<any>;
5
- }
6
- export declare const createSettingsStorageOperations: (params: CreateSettingsStorageOperationsParams) => CmsSettingsStorageOperations;
7
- export {};
@@ -1,135 +0,0 @@
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.createSettingsStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _get = require("@webiny/db-dynamodb/utils/get");
13
-
14
- var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
- const convertToDbData = settings => {
19
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
20
- contentModelLastChange: settings.contentModelLastChange.toISOString()
21
- });
22
- };
23
-
24
- const convertFromDbData = settings => {
25
- if (!settings) {
26
- return null;
27
- }
28
-
29
- let contentModelLastChange;
30
-
31
- try {
32
- contentModelLastChange = new Date(settings.contentModelLastChange);
33
- } catch {
34
- contentModelLastChange = new Date();
35
- }
36
-
37
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
38
- contentModelLastChange
39
- });
40
- };
41
-
42
- const createPartitionKey = ({
43
- tenant,
44
- locale
45
- }) => {
46
- return `T#${tenant}#L#${locale}#CMS#SETTINGS`;
47
- };
48
-
49
- const createSortKey = () => {
50
- return "settings";
51
- };
52
-
53
- const createKeys = params => {
54
- return {
55
- PK: createPartitionKey(params),
56
- SK: createSortKey()
57
- };
58
- };
59
-
60
- const createSettingsStorageOperations = params => {
61
- const {
62
- entity
63
- } = params;
64
-
65
- const create = async params => {
66
- const {
67
- settings
68
- } = params;
69
- const keys = createKeys(settings);
70
- const dbSettings = convertToDbData(settings);
71
-
72
- try {
73
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, dbSettings), keys));
74
- return settings;
75
- } catch (ex) {
76
- throw new _error.default(ex.message || "Could not create settings.", ex.code || "CREATE_SETTINGS_ERROR", {
77
- error: ex,
78
- settings,
79
- dbSettings,
80
- keys
81
- });
82
- }
83
- };
84
-
85
- const update = async params => {
86
- const {
87
- settings
88
- } = params;
89
- const keys = createKeys(settings);
90
- const dbSettings = convertToDbData(settings);
91
-
92
- try {
93
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, dbSettings), keys));
94
- return settings;
95
- } catch (ex) {
96
- throw new _error.default(ex.message || "Could not update settings.", ex.code || "UPDATE_SETTINGS_ERROR", {
97
- error: ex,
98
- settings,
99
- dbSettings,
100
- keys
101
- });
102
- }
103
- };
104
-
105
- const get = async params => {
106
- const keys = createKeys(params);
107
-
108
- try {
109
- const record = await (0, _get.get)({
110
- entity,
111
- keys
112
- });
113
-
114
- if (!record) {
115
- return null;
116
- }
117
-
118
- const settings = (0, _cleanup.cleanupItem)(entity, record);
119
- return convertFromDbData(settings);
120
- } catch (ex) {
121
- throw new _error.default(ex.message || "Could not get settings.", ex.code || "GET_SETTINGS_ERROR", {
122
- error: ex,
123
- keys
124
- });
125
- }
126
- };
127
-
128
- return {
129
- create,
130
- get,
131
- update
132
- };
133
- };
134
-
135
- exports.createSettingsStorageOperations = createSettingsStorageOperations;
@@ -1 +0,0 @@
1
- {"version":3,"names":["convertToDbData","settings","contentModelLastChange","toISOString","convertFromDbData","Date","createPartitionKey","tenant","locale","createSortKey","createKeys","params","PK","SK","createSettingsStorageOperations","entity","create","keys","dbSettings","put","ex","WebinyError","message","code","error","update","get","record","getRecord","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n CmsSettings,\n CmsSettingsStorageOperations,\n CmsSettingsStorageOperationsCreateParams,\n CmsSettingsStorageOperationsGetParams,\n CmsSettingsStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface CmsSettingsDb extends Omit<CmsSettings, \"contentModelLastChange\"> {\n contentModelLastChange: string;\n}\n\nconst convertToDbData = (settings: CmsSettings): CmsSettingsDb => {\n return {\n ...settings,\n contentModelLastChange: settings.contentModelLastChange.toISOString()\n };\n};\n\nconst convertFromDbData = (settings?: CmsSettingsDb): CmsSettings | null => {\n if (!settings) {\n return null;\n }\n let contentModelLastChange;\n try {\n contentModelLastChange = new Date(settings.contentModelLastChange);\n } catch {\n contentModelLastChange = new Date();\n }\n return {\n ...settings,\n contentModelLastChange\n };\n};\n\ninterface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\n\nconst createPartitionKey = ({ tenant, locale }: PartitionKeyParams): string => {\n return `T#${tenant}#L#${locale}#CMS#SETTINGS`;\n};\n\nconst createSortKey = (): string => {\n return \"settings\";\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey()\n };\n};\n\ninterface CreateSettingsStorageOperationsParams {\n entity: Entity<any>;\n}\n\nexport const createSettingsStorageOperations = (\n params: CreateSettingsStorageOperationsParams\n): CmsSettingsStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsSettingsStorageOperationsCreateParams) => {\n const { settings } = params;\n const keys = createKeys(settings);\n\n const dbSettings: CmsSettingsDb = convertToDbData(settings);\n\n try {\n await entity.put({\n ...dbSettings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create settings.\",\n ex.code || \"CREATE_SETTINGS_ERROR\",\n {\n error: ex,\n settings,\n dbSettings,\n keys\n }\n );\n }\n };\n\n const update = async (params: CmsSettingsStorageOperationsUpdateParams) => {\n const { settings } = params;\n\n const keys = createKeys(settings);\n\n const dbSettings: CmsSettingsDb = convertToDbData(settings);\n\n try {\n await entity.put({\n ...dbSettings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update settings.\",\n ex.code || \"UPDATE_SETTINGS_ERROR\",\n {\n error: ex,\n settings,\n dbSettings,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsSettingsStorageOperationsGetParams) => {\n const keys = createKeys(params);\n try {\n const record = await getRecord<CmsSettingsDb>({\n entity,\n keys\n });\n if (!record) {\n return null;\n }\n const settings = cleanupItem(entity, record) as CmsSettingsDb;\n return convertFromDbData(settings);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get settings.\",\n ex.code || \"GET_SETTINGS_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n return {\n create,\n get,\n update\n };\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AACA;;AACA;;AAMA,MAAMA,eAAe,GAAIC,QAAD,IAA0C;EAC9D,mEACOA,QADP;IAEIC,sBAAsB,EAAED,QAAQ,CAACC,sBAAT,CAAgCC,WAAhC;EAF5B;AAIH,CALD;;AAOA,MAAMC,iBAAiB,GAAIH,QAAD,IAAkD;EACxE,IAAI,CAACA,QAAL,EAAe;IACX,OAAO,IAAP;EACH;;EACD,IAAIC,sBAAJ;;EACA,IAAI;IACAA,sBAAsB,GAAG,IAAIG,IAAJ,CAASJ,QAAQ,CAACC,sBAAlB,CAAzB;EACH,CAFD,CAEE,MAAM;IACJA,sBAAsB,GAAG,IAAIG,IAAJ,EAAzB;EACH;;EACD,mEACOJ,QADP;IAEIC;EAFJ;AAIH,CAdD;;AAqBA,MAAMI,kBAAkB,GAAG,CAAC;EAAEC,MAAF;EAAUC;AAAV,CAAD,KAAoD;EAC3E,OAAQ,KAAID,MAAO,MAAKC,MAAO,eAA/B;AACH,CAFD;;AAIA,MAAMC,aAAa,GAAG,MAAc;EAChC,OAAO,UAAP;AACH,CAFD;;AAQA,MAAMC,UAAU,GAAIC,MAAD,IAAsC;EACrD,OAAO;IACHC,EAAE,EAAEN,kBAAkB,CAACK,MAAD,CADnB;IAEHE,EAAE,EA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,MAAMM,IAAI,GAAGP,UAAU,CAACC,MAAD,CAAvB;;IACA,IAAI;MACA,MAAMgB,MAAM,GAAG,MAAM,IAAAC,QAAA,EAAyB;QAC1Cb,MAD0C;QAE1CE;MAF0C,CAAzB,CAArB;;MAIA,IAAI,CAACU,MAAL,EAAa;QACT,OAAO,IAAP;MACH;;MACD,MAAM1B,QAAQ,GAAG,IAAA4B,oBAAA,EAAYd,MAAZ,EAAoBY,MAApB,CAAjB;MACA,OAAOvB,iBAAiB,CAACH,QAAD,CAAxB;IACH,CAVD,CAUE,OAAOmB,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,yBADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,oBAFT,EAGF;QACIC,KAAK,EAAEJ,EADX;QAEIH;MAFJ,CAHE,CAAN;IAQH;EACJ,CAtBD;;EAwBA,OAAO;IACHD,MADG;IAEHU,GAFG;IAGHD;EAHG,CAAP;AAKH,CAvFM"}
@@ -1,7 +0,0 @@
1
- import { CmsSystemStorageOperations } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
3
- interface CreateSystemStorageOperationsParams {
4
- entity: Entity<any>;
5
- }
6
- export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => CmsSystemStorageOperations;
7
- export {};
@@ -1,99 +0,0 @@
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.createSystemStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- var _get = require("@webiny/db-dynamodb/utils/get");
15
-
16
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
- const createPartitionKey = ({
19
- tenant
20
- }) => {
21
- return `T#${tenant.toLowerCase()}#SYSTEM`;
22
- };
23
-
24
- const createSortKey = () => {
25
- return "CMS";
26
- };
27
-
28
- const createKeys = params => {
29
- return {
30
- PK: createPartitionKey(params),
31
- SK: createSortKey()
32
- };
33
- };
34
-
35
- const createSystemStorageOperations = params => {
36
- const {
37
- entity
38
- } = params;
39
-
40
- const create = async ({
41
- system
42
- }) => {
43
- const keys = createKeys(system);
44
-
45
- try {
46
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
47
- return system;
48
- } catch (ex) {
49
- throw new _error.default(ex.message || "Could not create system.", ex.code || "CREATE_SYSTEM_ERROR", {
50
- error: ex,
51
- system,
52
- keys
53
- });
54
- }
55
- };
56
-
57
- const update = async params => {
58
- const {
59
- system
60
- } = params;
61
- const keys = createKeys(system);
62
-
63
- try {
64
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
65
- return system;
66
- } catch (ex) {
67
- throw new _error.default(ex.message || "Could not update system.", ex.code || "UPDATE_SYSTEM_ERROR", {
68
- error: ex,
69
- system,
70
- keys
71
- });
72
- }
73
- };
74
-
75
- const get = async params => {
76
- const keys = createKeys(params);
77
-
78
- try {
79
- const system = await (0, _get.get)({
80
- entity,
81
- keys
82
- });
83
- return (0, _cleanup.cleanupItem)(entity, system);
84
- } catch (ex) {
85
- throw new _error.default(ex.message || "Could not get system.", ex.code || "GET_SYSTEM_ERROR", {
86
- error: ex,
87
- keys
88
- });
89
- }
90
- };
91
-
92
- return {
93
- create,
94
- update,
95
- get
96
- };
97
- };
98
-
99
- exports.createSystemStorageOperations = createSystemStorageOperations;
@@ -1 +0,0 @@
1
- {"version":3,"names":["createPartitionKey","tenant","toLowerCase","createSortKey","createKeys","params","PK","SK","createSystemStorageOperations","entity","create","system","keys","put","ex","WebinyError","message","code","error","update","get","getRecord","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n CmsSystem,\n CmsSystemStorageOperations,\n CmsSystemStorageOperationsCreateParams,\n CmsSystemStorageOperationsGetParams,\n CmsSystemStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n}\n\ninterface PartitionKeyParams {\n tenant: string;\n}\nconst createPartitionKey = ({ tenant }: PartitionKeyParams): string => {\n return `T#${tenant.toLowerCase()}#SYSTEM`;\n};\nconst createSortKey = (): string => {\n return \"CMS\";\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey()\n };\n};\n\nexport const createSystemStorageOperations = (\n params: CreateSystemStorageOperationsParams\n): CmsSystemStorageOperations => {\n const { entity } = params;\n\n const create = async ({ system }: CmsSystemStorageOperationsCreateParams) => {\n const keys = createKeys(system);\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create system.\",\n ex.code || \"CREATE_SYSTEM_ERROR\",\n {\n error: ex,\n system,\n keys\n }\n );\n }\n };\n\n const update = async (params: CmsSystemStorageOperationsUpdateParams) => {\n const { system } = params;\n\n const keys = createKeys(system);\n\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update system.\",\n ex.code || \"UPDATE_SYSTEM_ERROR\",\n {\n error: ex,\n system,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsSystemStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const system = await getRecord<CmsSystem>({\n entity,\n keys\n });\n return cleanupItem(entity, system);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get system.\",\n ex.code || \"GET_SYSTEM_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };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