@webiny/api-headless-cms-ddb 6.3.0 → 6.4.0-beta.0

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 (100) hide show
  1. package/definitions/entry.js +7 -9
  2. package/definitions/entry.js.map +1 -1
  3. package/definitions/group.js +7 -9
  4. package/definitions/group.js.map +1 -1
  5. package/definitions/model.js +7 -9
  6. package/definitions/model.js.map +1 -1
  7. package/definitions/table.js +6 -7
  8. package/definitions/table.js.map +1 -1
  9. package/definitions/types.d.ts +1 -0
  10. package/definitions/types.js +0 -3
  11. package/dynamoDb/index.js +6 -1
  12. package/dynamoDb/index.js.map +1 -1
  13. package/dynamoDb/path/locationFolderId.js +16 -29
  14. package/dynamoDb/path/locationFolderId.js.map +1 -1
  15. package/dynamoDb/path/plainObject.js +11 -21
  16. package/dynamoDb/path/plainObject.js.map +1 -1
  17. package/dynamoDb/transformValue/datetime.js +21 -32
  18. package/dynamoDb/transformValue/datetime.js.map +1 -1
  19. package/index.js +67 -77
  20. package/index.js.map +1 -1
  21. package/operations/entry/dataLoader/DataLoaderCache.js +22 -26
  22. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  23. package/operations/entry/dataLoader/constants.js +2 -1
  24. package/operations/entry/dataLoader/constants.js.map +1 -1
  25. package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
  26. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  27. package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -29
  28. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  29. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +31 -41
  30. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  31. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +31 -41
  32. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  33. package/operations/entry/dataLoader/getRevisionById.js +33 -47
  34. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  35. package/operations/entry/dataLoader/index.js +8 -9
  36. package/operations/entry/dataLoader/index.js.map +1 -1
  37. package/operations/entry/dataLoader/types.js +0 -3
  38. package/operations/entry/dataLoaders.js +81 -99
  39. package/operations/entry/dataLoaders.js.map +1 -1
  40. package/operations/entry/filtering/createExpressions.js +109 -157
  41. package/operations/entry/filtering/createExpressions.js.map +1 -1
  42. package/operations/entry/filtering/createFields.js +83 -96
  43. package/operations/entry/filtering/createFields.js.map +1 -1
  44. package/operations/entry/filtering/extractSort.js +50 -74
  45. package/operations/entry/filtering/extractSort.js.map +1 -1
  46. package/operations/entry/filtering/filter.js +72 -140
  47. package/operations/entry/filtering/filter.js.map +1 -1
  48. package/operations/entry/filtering/fullTextSearch.js +21 -38
  49. package/operations/entry/filtering/fullTextSearch.js.map +1 -1
  50. package/operations/entry/filtering/getValue.js +31 -53
  51. package/operations/entry/filtering/getValue.js.map +1 -1
  52. package/operations/entry/filtering/index.js +0 -2
  53. package/operations/entry/filtering/mapPlugins.js +15 -22
  54. package/operations/entry/filtering/mapPlugins.js.map +1 -1
  55. package/operations/entry/filtering/plugins/defaultFilterCreate.js +29 -33
  56. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
  57. package/operations/entry/filtering/plugins/index.js +7 -3
  58. package/operations/entry/filtering/plugins/index.js.map +1 -1
  59. package/operations/entry/filtering/plugins/objectFilterCreate.js +60 -76
  60. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
  61. package/operations/entry/filtering/plugins/refFilterCreate.js +55 -66
  62. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
  63. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +43 -56
  64. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
  65. package/operations/entry/filtering/sort.js +34 -60
  66. package/operations/entry/filtering/sort.js.map +1 -1
  67. package/operations/entry/filtering/systemFields.js +144 -126
  68. package/operations/entry/filtering/systemFields.js.map +1 -1
  69. package/operations/entry/filtering/transform.js +4 -8
  70. package/operations/entry/filtering/transform.js.map +1 -1
  71. package/operations/entry/filtering/types.js +0 -3
  72. package/operations/entry/filtering/values.js +11 -12
  73. package/operations/entry/filtering/values.js.map +1 -1
  74. package/operations/entry/filtering/where.js +17 -23
  75. package/operations/entry/filtering/where.js.map +1 -1
  76. package/operations/entry/index.js +894 -1148
  77. package/operations/entry/index.js.map +1 -1
  78. package/operations/entry/keys.js +54 -77
  79. package/operations/entry/keys.js.map +1 -1
  80. package/operations/group/index.js +113 -134
  81. package/operations/group/index.js.map +1 -1
  82. package/operations/model/index.js +100 -121
  83. package/operations/model/index.js.map +1 -1
  84. package/package.json +15 -15
  85. package/plugins/CmsEntryFieldFilterPathPlugin.js +23 -33
  86. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  87. package/plugins/CmsEntryFieldFilterPlugin.js +16 -17
  88. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
  89. package/plugins/CmsEntryFieldSortingPlugin.js +16 -15
  90. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
  91. package/plugins/CmsFieldFilterValueTransformPlugin.js +15 -12
  92. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
  93. package/plugins/index.js +0 -2
  94. package/types.js +6 -5
  95. package/types.js.map +1 -1
  96. package/definitions/types.js.map +0 -1
  97. package/operations/entry/dataLoader/types.js.map +0 -1
  98. package/operations/entry/filtering/index.js.map +0 -1
  99. package/operations/entry/filtering/types.js.map +0 -1
  100. package/plugins/index.js.map +0 -1
@@ -1,142 +1,121 @@
1
- import WebinyError from "@webiny/error";
1
+ import error from "@webiny/error";
2
2
  import { sortItems } from "@webiny/db-dynamodb";
3
3
  import { FilterUtil } from "@webiny/db-dynamodb/feature/FilterUtil/index.js";
4
- const createPartitionKey = params => {
5
- const {
6
- tenant
7
- } = params;
8
- return `T#${tenant}#CMS#CMG`;
4
+ const createPartitionKey = (params)=>{
5
+ const { tenant } = params;
6
+ return `T#${tenant}#CMS#CMG`;
9
7
  };
10
- const createSortKeys = params => {
11
- const {
12
- id
13
- } = params;
14
- return id;
8
+ const createSortKeys = (params)=>{
9
+ const { id } = params;
10
+ return id;
15
11
  };
16
- const createKeys = params => {
17
- return {
18
- PK: createPartitionKey(params),
19
- SK: createSortKeys(params),
20
- GSI_TENANT: params.tenant
21
- };
22
- };
23
- const createType = () => {
24
- return "cms.group";
25
- };
26
- export const createGroupsStorageOperations = params => {
27
- const {
28
- entity,
29
- container
30
- } = params;
31
- const filterUtil = container.resolve(FilterUtil);
32
- const create = async params => {
33
- const {
34
- group
35
- } = params;
36
- const keys = createKeys(group);
37
- try {
38
- await entity.put({
39
- data: group,
40
- TYPE: createType(),
41
- ...keys
42
- });
43
- } catch (ex) {
44
- throw new WebinyError(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
45
- error: ex,
46
- group,
47
- keys
48
- });
49
- }
50
- };
51
- const update = async params => {
52
- const {
53
- group
54
- } = params;
55
- const keys = createKeys(group);
56
- try {
57
- await entity.put({
58
- data: group,
59
- TYPE: createType(),
60
- ...keys
61
- });
62
- } catch (ex) {
63
- throw new WebinyError(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
64
- error: ex,
65
- group,
66
- keys
67
- });
68
- }
69
- };
70
- const deleteGroup = async params => {
71
- const {
72
- group
73
- } = params;
74
- const keys = createKeys(group);
75
- try {
76
- await entity.delete(keys);
77
- } catch (ex) {
78
- throw new WebinyError(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
79
- error: ex,
80
- group,
81
- keys
82
- });
83
- }
84
- };
85
- const get = async params => {
86
- const keys = createKeys(params);
87
- try {
88
- const result = await entity.get(keys);
89
- return result?.data || null;
90
- } catch (ex) {
91
- throw new WebinyError(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", {
92
- error: ex,
93
- ...params,
94
- keys
95
- });
96
- }
97
- };
98
- const list = async params => {
99
- const {
100
- sort,
101
- where
102
- } = params;
103
- let records = [];
104
- try {
105
- const ddbRecords = await entity.queryAll({
106
- partitionKey: createPartitionKey(where),
107
- options: {
108
- gte: " "
109
- }
110
- });
111
- records = ddbRecords.map(item => item.data);
112
- } catch (ex) {
113
- throw new WebinyError(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", {
114
- error: ex,
115
- ...params,
116
- sort,
117
- where
118
- });
119
- }
120
- const filteredItems = filterUtil.filter({
121
- items: records,
122
- where,
123
- fields: []
12
+ const createKeys = (params)=>({
13
+ PK: createPartitionKey(params),
14
+ SK: createSortKeys(params),
15
+ GSI_TENANT: params.tenant
124
16
  });
125
- if (!sort || sort.length === 0) {
126
- return filteredItems;
127
- }
128
- return sortItems({
129
- items: filteredItems,
130
- sort
131
- });
132
- };
133
- return {
134
- create,
135
- update,
136
- delete: deleteGroup,
137
- get,
138
- list
139
- };
17
+ const createType = ()=>"cms.group";
18
+ const createGroupsStorageOperations = (params)=>{
19
+ const { entity, container } = params;
20
+ const filterUtil = container.resolve(FilterUtil);
21
+ const create = async (params)=>{
22
+ const { group } = params;
23
+ const keys = createKeys(group);
24
+ try {
25
+ await entity.put({
26
+ data: group,
27
+ TYPE: createType(),
28
+ ...keys
29
+ });
30
+ } catch (ex) {
31
+ throw new error(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
32
+ error: ex,
33
+ group,
34
+ keys
35
+ });
36
+ }
37
+ };
38
+ const update = async (params)=>{
39
+ const { group } = params;
40
+ const keys = createKeys(group);
41
+ try {
42
+ await entity.put({
43
+ data: group,
44
+ TYPE: createType(),
45
+ ...keys
46
+ });
47
+ } catch (ex) {
48
+ throw new error(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
49
+ error: ex,
50
+ group,
51
+ keys
52
+ });
53
+ }
54
+ };
55
+ const deleteGroup = async (params)=>{
56
+ const { group } = params;
57
+ const keys = createKeys(group);
58
+ try {
59
+ await entity.delete(keys);
60
+ } catch (ex) {
61
+ throw new error(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
62
+ error: ex,
63
+ group,
64
+ keys
65
+ });
66
+ }
67
+ };
68
+ const get = async (params)=>{
69
+ const keys = createKeys(params);
70
+ try {
71
+ const result = await entity.get(keys);
72
+ return result?.data || null;
73
+ } catch (ex) {
74
+ throw new error(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", {
75
+ error: ex,
76
+ ...params,
77
+ keys
78
+ });
79
+ }
80
+ };
81
+ const list = async (params)=>{
82
+ const { sort, where } = params;
83
+ let records = [];
84
+ try {
85
+ const ddbRecords = await entity.queryAll({
86
+ partitionKey: createPartitionKey(where),
87
+ options: {
88
+ gte: " "
89
+ }
90
+ });
91
+ records = ddbRecords.map((item)=>item.data);
92
+ } catch (ex) {
93
+ throw new error(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", {
94
+ error: ex,
95
+ ...params,
96
+ sort,
97
+ where
98
+ });
99
+ }
100
+ const filteredItems = filterUtil.filter({
101
+ items: records,
102
+ where,
103
+ fields: []
104
+ });
105
+ if (!sort || 0 === sort.length) return filteredItems;
106
+ return sortItems({
107
+ items: filteredItems,
108
+ sort
109
+ });
110
+ };
111
+ return {
112
+ create,
113
+ update,
114
+ delete: deleteGroup,
115
+ get,
116
+ list
117
+ };
140
118
  };
119
+ export { createGroupsStorageOperations };
141
120
 
142
121
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","sortItems","FilterUtil","createPartitionKey","params","tenant","createSortKeys","id","createKeys","PK","SK","GSI_TENANT","createType","createGroupsStorageOperations","entity","container","filterUtil","resolve","create","group","keys","put","data","TYPE","ex","message","code","error","update","deleteGroup","delete","get","result","list","sort","where","records","ddbRecords","queryAll","partitionKey","options","gte","map","item","filteredItems","filter","items","fields","length"],"sources":["index.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsGroup,\n CmsGroupStorageOperations,\n CmsGroupStorageOperationsCreateParams,\n CmsGroupStorageOperationsDeleteParams,\n CmsGroupStorageOperationsGetParams,\n CmsGroupStorageOperationsListParams,\n CmsGroupStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { sortItems } from \"@webiny/db-dynamodb\";\nimport type { IGroupEntity } from \"~/definitions/types.js\";\nimport { FilterUtil } from \"@webiny/db-dynamodb/feature/FilterUtil/index.js\";\n\ninterface PartitionKeyParams {\n tenant: string;\n}\nconst createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant } = params;\n return `T#${tenant}#CMS#CMG`;\n};\n\ninterface SortKeyParams {\n id: string;\n}\nconst createSortKeys = (params: SortKeyParams): string => {\n const { id } = params;\n return id;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n}\nconst createKeys = (params: PartitionKeyParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKeys(params),\n GSI_TENANT: params.tenant\n };\n};\n\nconst createType = (): string => {\n return \"cms.group\";\n};\n\ninterface CreateGroupsStorageOperationsParams {\n entity: IGroupEntity;\n container: CmsContext[\"container\"];\n}\nexport const createGroupsStorageOperations = (\n params: CreateGroupsStorageOperationsParams\n): CmsGroupStorageOperations => {\n const { entity, container } = params;\n const filterUtil = container.resolve(FilterUtil);\n\n const create = async (params: CmsGroupStorageOperationsCreateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n data: group,\n TYPE: createType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create group.\",\n ex.code || \"CREATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const update = async (params: CmsGroupStorageOperationsUpdateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n data: group,\n TYPE: createType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update group.\",\n ex.code || \"UPDATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const deleteGroup = async (params: CmsGroupStorageOperationsDeleteParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete group.\",\n ex.code || \"DELETE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const get = async (params: CmsGroupStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const result = await entity.get(keys);\n\n return result?.data || null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get group.\",\n ex.code || \"GET_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n keys\n }\n );\n }\n };\n const list = async (params: CmsGroupStorageOperationsListParams) => {\n const { sort, where } = params;\n\n let records: CmsGroup[] = [];\n try {\n const ddbRecords = await entity.queryAll({\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n });\n records = ddbRecords.map(item => item.data);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list groups.\",\n ex.code || \"LIST_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n sort,\n where\n }\n );\n }\n\n const filteredItems = filterUtil.filter({\n items: records,\n where,\n fields: []\n });\n if (!sort || sort.length === 0) {\n return filteredItems;\n }\n\n return sortItems({\n items: filteredItems,\n sort\n });\n };\n\n return {\n create,\n update,\n delete: deleteGroup,\n get,\n list\n };\n};\n"],"mappings":"AAUA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,SAAS,QAAQ,qBAAqB;AAE/C,SAASC,UAAU,QAAQ,iDAAiD;AAK5E,MAAMC,kBAAkB,GAAIC,MAA0B,IAAa;EAC/D,MAAM;IAAEC;EAAO,CAAC,GAAGD,MAAM;EACzB,OAAO,KAAKC,MAAM,UAAU;AAChC,CAAC;AAKD,MAAMC,cAAc,GAAIF,MAAqB,IAAa;EACtD,MAAM;IAAEG;EAAG,CAAC,GAAGH,MAAM;EACrB,OAAOG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EC;IAAM,CAAC,GAAG/B,MAAM;IAE9B,IAAIgC,OAAmB,GAAG,EAAE;IAC5B,IAAI;MACA,MAAMC,UAAU,GAAG,MAAMvB,MAAM,CAACwB,QAAQ,CAAC;QACrCC,YAAY,EAAEpC,kBAAkB,CAACgC,KAAK,CAAC;QACvCK,OAAO,EAAE;UACLC,GAAG,EAAE;QACT;MACJ,CAAC,CAAC;MACFL,OAAO,GAAGC,UAAU,CAACK,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACrB,IAAI,CAAC;IAC/C,CAAC,CAAC,OAAOE,EAAE,EAAE;MACT,MAAM,IAAIxB,WAAW,CACjBwB,EAAE,CAACC,OAAO,IAAI,wBAAwB,EACtCD,EAAE,CAACE,IAAI,IAAI,kBAAkB,EAC7B;QACIC,KAAK,EAAEH,EAAE;QACT,GAAGpB,MAAM;QACT8B,IAAI;QACJC;MACJ,CACJ,CAAC;IACL;IAEA,MAAMS,aAAa,GAAG5B,UAAU,CAAC6B,MAAM,CAAC;MACpCC,KAAK,EAAEV,OAAO;MACdD,KAAK;MACLY,MAAM,EAAE;IACZ,CAAC,CAAC;IACF,IAAI,CAACb,IAAI,IAAIA,IAAI,CAACc,MAAM,KAAK,CAAC,EAAE;MAC5B,OAAOJ,aAAa;IACxB;IAEA,OAAO3C,SAAS,CAAC;MACb6C,KAAK,EAAEF,aAAa;MACpBV;IACJ,CAAC,CAAC;EACN,CAAC;EAED,OAAO;IACHhB,MAAM;IACNU,MAAM;IACNE,MAAM,EAAED,WAAW;IACnBE,GAAG;IACHE;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"operations/group/index.js","sources":["../../../src/operations/group/index.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsGroup,\n CmsGroupStorageOperations,\n CmsGroupStorageOperationsCreateParams,\n CmsGroupStorageOperationsDeleteParams,\n CmsGroupStorageOperationsGetParams,\n CmsGroupStorageOperationsListParams,\n CmsGroupStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { sortItems } from \"@webiny/db-dynamodb\";\nimport type { IGroupEntity } from \"~/definitions/types.js\";\nimport { FilterUtil } from \"@webiny/db-dynamodb/feature/FilterUtil/index.js\";\n\ninterface PartitionKeyParams {\n tenant: string;\n}\nconst createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant } = params;\n return `T#${tenant}#CMS#CMG`;\n};\n\ninterface SortKeyParams {\n id: string;\n}\nconst createSortKeys = (params: SortKeyParams): string => {\n const { id } = params;\n return id;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n}\nconst createKeys = (params: PartitionKeyParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKeys(params),\n GSI_TENANT: params.tenant\n };\n};\n\nconst createType = (): string => {\n return \"cms.group\";\n};\n\ninterface CreateGroupsStorageOperationsParams {\n entity: IGroupEntity;\n container: CmsContext[\"container\"];\n}\nexport const createGroupsStorageOperations = (\n params: CreateGroupsStorageOperationsParams\n): CmsGroupStorageOperations => {\n const { entity, container } = params;\n const filterUtil = container.resolve(FilterUtil);\n\n const create = async (params: CmsGroupStorageOperationsCreateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n data: group,\n TYPE: createType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create group.\",\n ex.code || \"CREATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const update = async (params: CmsGroupStorageOperationsUpdateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n data: group,\n TYPE: createType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update group.\",\n ex.code || \"UPDATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const deleteGroup = async (params: CmsGroupStorageOperationsDeleteParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete group.\",\n ex.code || \"DELETE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const get = async (params: CmsGroupStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const result = await entity.get(keys);\n\n return result?.data || null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get group.\",\n ex.code || \"GET_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n keys\n }\n );\n }\n };\n const list = async (params: CmsGroupStorageOperationsListParams) => {\n const { sort, where } = params;\n\n let records: CmsGroup[] = [];\n try {\n const ddbRecords = await entity.queryAll({\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n });\n records = ddbRecords.map(item => item.data);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list groups.\",\n ex.code || \"LIST_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n sort,\n where\n }\n );\n }\n\n const filteredItems = filterUtil.filter({\n items: records,\n where,\n fields: []\n });\n if (!sort || sort.length === 0) {\n return filteredItems;\n }\n\n return sortItems({\n items: filteredItems,\n sort\n });\n };\n\n return {\n create,\n update,\n delete: deleteGroup,\n get,\n list\n };\n};\n"],"names":["createPartitionKey","params","tenant","createSortKeys","id","createKeys","createType","createGroupsStorageOperations","entity","container","filterUtil","FilterUtil","create","group","keys","ex","WebinyError","update","deleteGroup","get","result","list","sort","where","records","ddbRecords","item","filteredItems","sortItems"],"mappings":";;;AAkBA,MAAMA,qBAAqB,CAACC;IACxB,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,OAAO,CAAC,EAAE,EAAEC,OAAO,QAAQ,CAAC;AAChC;AAKA,MAAMC,iBAAiB,CAACF;IACpB,MAAM,EAAEG,EAAE,EAAE,GAAGH;IACf,OAAOG;AACX;AAOA,MAAMC,aAAa,CAACJ,SACT;QACH,IAAID,mBAAmBC;QACvB,IAAIE,eAAeF;QACnB,YAA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,QAAQ,QAAQ;QAC3B,EAAE,OAAOL,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wBACdA,GAAG,IAAI,IAAI,mBACX;gBACI,OAAOA;gBACP,GAAGd,MAAM;gBACTa;YACJ;QAER;IACJ;IACA,MAAMO,OAAO,OAAOpB;QAChB,MAAM,EAAEqB,IAAI,EAAEC,KAAK,EAAE,GAAGtB;QAExB,IAAIuB,UAAsB,EAAE;QAC5B,IAAI;YACA,MAAMC,aAAa,MAAMjB,OAAO,QAAQ,CAAC;gBACrC,cAAcR,mBAAmBuB;gBACjC,SAAS;oBACL,KAAK;gBACT;YACJ;YACAC,UAAUC,WAAW,GAAG,CAACC,CAAAA,OAAQA,KAAK,IAAI;QAC9C,EAAE,OAAOX,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,0BACdA,GAAG,IAAI,IAAI,oBACX;gBACI,OAAOA;gBACP,GAAGd,MAAM;gBACTqB;gBACAC;YACJ;QAER;QAEA,MAAMI,gBAAgBjB,WAAW,MAAM,CAAC;YACpC,OAAOc;YACPD;YACA,QAAQ,EAAE;QACd;QACA,IAAI,CAACD,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,EACpB,OAAOK;QAGX,OAAOC,UAAU;YACb,OAAOD;YACPL;QACJ;IACJ;IAEA,OAAO;QACHV;QACAK;QACA,QAAQC;QACRC;QACAE;IACJ;AACJ"}
@@ -1,127 +1,106 @@
1
- import WebinyError from "@webiny/error";
1
+ import error from "@webiny/error";
2
2
  import { convertException } from "@webiny/utils";
3
- const createPartitionKey = params => {
4
- const {
5
- tenant
6
- } = params;
7
- if (!tenant) {
8
- throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);
9
- }
10
- return `T#${tenant}#CMS#CM`;
3
+ const createPartitionKey = (params)=>{
4
+ const { tenant } = params;
5
+ if (!tenant) throw new error("Missing tenant variable when creating model partitionKey.");
6
+ return `T#${tenant}#CMS#CM`;
11
7
  };
12
- const createSortKey = params => {
13
- return params.modelId;
14
- };
15
- const createKeys = params => {
16
- return {
17
- PK: createPartitionKey(params),
18
- SK: createSortKey(params),
19
- GSI_TENANT: params.tenant
20
- };
21
- };
22
- const createType = () => {
23
- return "cms.model";
24
- };
25
- export const createModelsStorageOperations = params => {
26
- const {
27
- entity
28
- } = params;
29
- const create = async params => {
30
- const {
31
- model
32
- } = params;
33
- const keys = createKeys(model);
34
- try {
35
- await entity.put({
36
- data: model,
37
- ...keys,
38
- TYPE: createType()
39
- });
40
- return model;
41
- } catch (ex) {
42
- throw new WebinyError(`Could not create CMS Content Model.`, "CREATE_MODEL_ERROR", {
43
- error: convertException(ex),
44
- model,
45
- keys
46
- });
47
- }
48
- };
49
- const update = async params => {
50
- const {
51
- model
52
- } = params;
53
- const keys = createKeys(model);
54
- try {
55
- await entity.put({
56
- data: model,
57
- ...keys,
58
- TYPE: createType()
59
- });
60
- return model;
61
- } catch (ex) {
62
- throw new WebinyError(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
63
- error: ex,
64
- model,
65
- keys
66
- });
67
- }
68
- };
69
- const deleteModel = async params => {
70
- const {
71
- model
72
- } = params;
73
- const keys = createKeys(model);
74
- try {
75
- await entity.delete(keys);
76
- } catch (ex) {
77
- throw new WebinyError(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
78
- error: ex,
79
- model,
80
- keys
81
- });
82
- }
83
- };
84
- const get = async params => {
85
- const keys = createKeys(params);
86
- try {
87
- const result = await entity.get(keys);
88
- return result?.data || null;
89
- } catch (ex) {
90
- throw new WebinyError(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
91
- error: ex,
92
- keys
93
- });
94
- }
95
- };
96
- const list = async params => {
97
- const {
98
- where
99
- } = params;
100
- const partitionKey = createPartitionKey(where);
101
- try {
102
- const result = await entity.queryAll({
103
- partitionKey,
104
- options: {
105
- gte: " "
8
+ const createSortKey = (params)=>params.modelId;
9
+ const createKeys = (params)=>({
10
+ PK: createPartitionKey(params),
11
+ SK: createSortKey(params),
12
+ GSI_TENANT: params.tenant
13
+ });
14
+ const createType = ()=>"cms.model";
15
+ const createModelsStorageOperations = (params)=>{
16
+ const { entity } = params;
17
+ const create = async (params)=>{
18
+ const { model } = params;
19
+ const keys = createKeys(model);
20
+ try {
21
+ await entity.put({
22
+ data: model,
23
+ ...keys,
24
+ TYPE: createType()
25
+ });
26
+ return model;
27
+ } catch (ex) {
28
+ throw new error("Could not create CMS Content Model.", "CREATE_MODEL_ERROR", {
29
+ error: convertException(ex),
30
+ model,
31
+ keys
32
+ });
33
+ }
34
+ };
35
+ const update = async (params)=>{
36
+ const { model } = params;
37
+ const keys = createKeys(model);
38
+ try {
39
+ await entity.put({
40
+ data: model,
41
+ ...keys,
42
+ TYPE: createType()
43
+ });
44
+ return model;
45
+ } catch (ex) {
46
+ throw new error(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
47
+ error: ex,
48
+ model,
49
+ keys
50
+ });
51
+ }
52
+ };
53
+ const deleteModel = async (params)=>{
54
+ const { model } = params;
55
+ const keys = createKeys(model);
56
+ try {
57
+ await entity.delete(keys);
58
+ } catch (ex) {
59
+ throw new error(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
60
+ error: ex,
61
+ model,
62
+ keys
63
+ });
64
+ }
65
+ };
66
+ const get = async (params)=>{
67
+ const keys = createKeys(params);
68
+ try {
69
+ const result = await entity.get(keys);
70
+ return result?.data || null;
71
+ } catch (ex) {
72
+ throw new error(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
73
+ error: ex,
74
+ keys
75
+ });
76
+ }
77
+ };
78
+ const list = async (params)=>{
79
+ const { where } = params;
80
+ const partitionKey = createPartitionKey(where);
81
+ try {
82
+ const result = await entity.queryAll({
83
+ partitionKey,
84
+ options: {
85
+ gte: " "
86
+ }
87
+ });
88
+ return result.map((item)=>item.data);
89
+ } catch (ex) {
90
+ throw new error(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
91
+ error: ex,
92
+ partitionKey
93
+ });
106
94
  }
107
- });
108
- return result.map(item => {
109
- return item.data;
110
- });
111
- } catch (ex) {
112
- throw new WebinyError(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
113
- error: ex,
114
- partitionKey
115
- });
116
- }
117
- };
118
- return {
119
- create,
120
- update,
121
- delete: deleteModel,
122
- get,
123
- list
124
- };
95
+ };
96
+ return {
97
+ create,
98
+ update,
99
+ delete: deleteModel,
100
+ get,
101
+ list
102
+ };
125
103
  };
104
+ export { createModelsStorageOperations };
126
105
 
127
106
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","convertException","createPartitionKey","params","tenant","createSortKey","modelId","createKeys","PK","SK","GSI_TENANT","createType","createModelsStorageOperations","entity","create","model","keys","put","data","TYPE","ex","error","update","message","code","deleteModel","delete","get","result","list","where","partitionKey","queryAll","options","gte","map","item"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModelStorageOperations,\n CmsModelStorageOperationsCreateParams,\n CmsModelStorageOperationsDeleteParams,\n CmsModelStorageOperationsGetParams,\n CmsModelStorageOperationsListParams,\n CmsModelStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { IModelEntity } from \"~/definitions/types.js\";\n\ninterface PartitionKeysParams {\n tenant: string;\n}\nconst createPartitionKey = (params: PartitionKeysParams): string => {\n const { tenant } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);\n }\n return `T#${tenant}#CMS#CM`;\n};\n\ninterface SortKeyParams {\n modelId: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n return params.modelId;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n}\nconst createKeys = (params: PartitionKeysParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey(params),\n GSI_TENANT: params.tenant\n };\n};\n\nconst createType = (): string => {\n return \"cms.model\";\n};\n\ninterface CreateModelsStorageOperationsParams {\n entity: IModelEntity;\n}\nexport const createModelsStorageOperations = (\n params: CreateModelsStorageOperationsParams\n): CmsModelStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsModelStorageOperationsCreateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n data: model,\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(`Could not create CMS Content Model.`, \"CREATE_MODEL_ERROR\", {\n error: convertException(ex),\n model,\n keys\n });\n }\n };\n\n const update = async (params: CmsModelStorageOperationsUpdateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n data: model,\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update model.\",\n ex.code || \"MODEL_UPDATE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const deleteModel = async (params: CmsModelStorageOperationsDeleteParams) => {\n const { model } = params;\n const keys = createKeys(model);\n\n try {\n await entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsModelStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const result = await entity.get(keys);\n return result?.data || null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get model.\",\n ex.code || \"MODEL_GET_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n const list = async (params: CmsModelStorageOperationsListParams) => {\n const { where } = params;\n\n const partitionKey = createPartitionKey(where);\n\n try {\n const result = await entity.queryAll({\n partitionKey,\n options: {\n gte: \" \"\n }\n });\n return result.map(item => {\n return item.data;\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list models.\",\n ex.code || \"MODEL_LIST_ERROR\",\n {\n error: ex,\n partitionKey\n }\n );\n }\n };\n\n return {\n create,\n update,\n delete: deleteModel,\n get,\n list\n };\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AASvC,SAASC,gBAAgB,QAAQ,eAAe;AAMhD,MAAMC,kBAAkB,GAAIC,MAA2B,IAAa;EAChE,MAAM;IAAEC;EAAO,CAAC,GAAGD,MAAM;EACzB,IAAI,CAACC,MAAM,EAAE;IACT,MAAM,IAAIJ,WAAW,CAAC,2DAA2D,CAAC;EACtF;EACA,OAAO,KAAKI,MAAM,SAAS;AAC/B,CAAC;AAKD,MAAMC,aAAa,GAAIF,MAAqB,IAAa;EACrD,OAAOA,MAAM,CAACG,OAAO;AACzB,CAAC;AAOD,MAAMC,UAAU,GAAIJ,MAA2C,IAAW;EACtE,OAAO;IACHK,EAAE,EAAEN,kBAAkB,CAACC,MAAM,CAAC;IAC9BM,EAAE,EAAEJ,aAAa,CAACF,MAAM,CAAC;IACzBO,UAAU,EAAEP,MAAM,CAACC;EACvB,CAAC;AACL,CAAC;AAED,MAAMO,UAAU,GAAGA,CAAA,KAAc;EAC7B,OAAO,WAAW;AACtB,CAAC;AAKD,OAAO,MAAMC,6BAA6B,GACtCT,MAA2C,IACf;EAC5B,MAAM;IAAEU;EAAO,CAAC,GAAGV,MAAM;EAEzB,MAAMW,MAAM,GAAG,MAAOX,MAA6C,IAAK;IACpE,MAAM;MAAEY;IAAM,CAAC,GAAGZ,MAAM;IAExB,MAAMa,IAAI,GAAGT,UAAU,CAACQ,KAAK,CAAC;IAE9B,IAAI;MACA,MAAMF,MAAM,CAACI,GAAG,CAAC;QACbC,IAAI,EAAEH,KAAK;QACX,GAAGC,IAAI;QACPG,IAAI,EAAER,UAAU,CAAC;MACrB,CAAC,CAAC;MACF,OAAOI,KAAK;IAChB,CAAC,CAAC,OAAOK,EAAE,EAAE;MACT,MAAM,IAAIpB,WAAW,CAAC,qCAAqC,EAAE,oB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CAACc,GAAG,CAACX,IAAI,CAAC;MACrC,OAAOY,MAAM,EAAEV,IAAI,IAAI,IAAI;IAC/B,CAAC,CAAC,OAAOE,EAAE,EAAE;MACT,MAAM,IAAIpB,WAAW,CACjBoB,EAAE,CAACG,OAAO,IAAI,sBAAsB,EACpCH,EAAE,CAACI,IAAI,IAAI,iBAAiB,EAC5B;QACIH,KAAK,EAAED,EAAE;QACTJ;MACJ,CACJ,CAAC;IACL;EACJ,CAAC;EAED,MAAMa,IAAI,GAAG,MAAO1B,MAA2C,IAAK;IAChE,MAAM;MAAE2B;IAAM,CAAC,GAAG3B,MAAM;IAExB,MAAM4B,YAAY,GAAG7B,kBAAkB,CAAC4B,KAAK,CAAC;IAE9C,IAAI;MACA,MAAMF,MAAM,GAAG,MAAMf,MAAM,CAACmB,QAAQ,CAAC;QACjCD,YAAY;QACZE,OAAO,EAAE;UACLC,GAAG,EAAE;QACT;MACJ,CAAC,CAAC;MACF,OAAON,MAAM,CAACO,GAAG,CAACC,IAAI,IAAI;QACtB,OAAOA,IAAI,CAAClB,IAAI;MACpB,CAAC,CAAC;IACN,CAAC,CAAC,OAAOE,EAAE,EAAE;MACT,MAAM,IAAIpB,WAAW,CACjBoB,EAAE,CAACG,OAAO,IAAI,wBAAwB,EACtCH,EAAE,CAACI,IAAI,IAAI,kBAAkB,EAC7B;QACIH,KAAK,EAAED,EAAE;QACTW;MACJ,CACJ,CAAC;IACL;EACJ,CAAC;EAED,OAAO;IACHjB,MAAM;IACNQ,MAAM;IACNI,MAAM,EAAED,WAAW;IACnBE,GAAG;IACHE;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"operations/model/index.js","sources":["../../../src/operations/model/index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModelStorageOperations,\n CmsModelStorageOperationsCreateParams,\n CmsModelStorageOperationsDeleteParams,\n CmsModelStorageOperationsGetParams,\n CmsModelStorageOperationsListParams,\n CmsModelStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { IModelEntity } from \"~/definitions/types.js\";\n\ninterface PartitionKeysParams {\n tenant: string;\n}\nconst createPartitionKey = (params: PartitionKeysParams): string => {\n const { tenant } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);\n }\n return `T#${tenant}#CMS#CM`;\n};\n\ninterface SortKeyParams {\n modelId: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n return params.modelId;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n}\nconst createKeys = (params: PartitionKeysParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey(params),\n GSI_TENANT: params.tenant\n };\n};\n\nconst createType = (): string => {\n return \"cms.model\";\n};\n\ninterface CreateModelsStorageOperationsParams {\n entity: IModelEntity;\n}\nexport const createModelsStorageOperations = (\n params: CreateModelsStorageOperationsParams\n): CmsModelStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsModelStorageOperationsCreateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n data: model,\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(`Could not create CMS Content Model.`, \"CREATE_MODEL_ERROR\", {\n error: convertException(ex),\n model,\n keys\n });\n }\n };\n\n const update = async (params: CmsModelStorageOperationsUpdateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n data: model,\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update model.\",\n ex.code || \"MODEL_UPDATE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const deleteModel = async (params: CmsModelStorageOperationsDeleteParams) => {\n const { model } = params;\n const keys = createKeys(model);\n\n try {\n await entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsModelStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const result = await entity.get(keys);\n return result?.data || null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get model.\",\n ex.code || \"MODEL_GET_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n const list = async (params: CmsModelStorageOperationsListParams) => {\n const { where } = params;\n\n const partitionKey = createPartitionKey(where);\n\n try {\n const result = await entity.queryAll({\n partitionKey,\n options: {\n gte: \" \"\n }\n });\n return result.map(item => {\n return item.data;\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list models.\",\n ex.code || \"MODEL_LIST_ERROR\",\n {\n error: ex,\n partitionKey\n }\n );\n }\n };\n\n return {\n create,\n update,\n delete: deleteModel,\n get,\n list\n };\n};\n"],"names":["createPartitionKey","params","tenant","WebinyError","createSortKey","createKeys","createType","createModelsStorageOperations","entity","create","model","keys","ex","convertException","update","deleteModel","get","result","list","where","partitionKey","item"],"mappings":";;AAeA,MAAMA,qBAAqB,CAACC;IACxB,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,IAAI,CAACC,QACD,MAAM,IAAIC,MAAY;IAE1B,OAAO,CAAC,EAAE,EAAED,OAAO,OAAO,CAAC;AAC/B;AAKA,MAAME,gBAAgB,CAACH,SACZA,OAAO,OAAO;AAQzB,MAAMI,aAAa,CAACJ,SACT;QACH,IAAID,mBAAmBC;QACvB,IAAIG,cAAcH;QAClB,YAAYA,OAAO,MAAM;IAC7B;AAGJ,MAAMK,aAAa,IACR;AAMJ,MAAMC,gCAAgC,CACzCN;IAEA,MAAM,EAAEO,MAAM,EAAE,GAAGP;IAEnB,MAAMQ,SAAS,OAAOR;QAClB,MAAM,EAAES,KAAK,EAAE,GAAGT;QAElB,MAAMU,OAAON,WAAWK;QAExB,IAAI;YACA,MAAMF,OAAO,GAAG,C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BACjCY;gBACA,SAAS;oBACL,KAAK;gBACT;YACJ;YACA,OAAOH,OAAO,GAAG,CAACI,CAAAA,OACPA,KAAK,IAAI;QAExB,EAAE,OAAOT,IAAI;YACT,MAAM,IAAIT,MACNS,GAAG,OAAO,IAAI,0BACdA,GAAG,IAAI,IAAI,oBACX;gBACI,OAAOA;gBACPQ;YACJ;QAER;IACJ;IAEA,OAAO;QACHX;QACAK;QACA,QAAQC;QACRC;QACAE;IACJ;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-ddb",
3
- "version": "6.3.0",
3
+ "version": "6.4.0-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -26,15 +26,15 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@webiny/api": "6.3.0",
30
- "@webiny/api-headless-cms": "6.3.0",
31
- "@webiny/aws-sdk": "6.3.0",
32
- "@webiny/db-dynamodb": "6.3.0",
33
- "@webiny/error": "6.3.0",
34
- "@webiny/feature": "6.3.0",
35
- "@webiny/handler": "6.3.0",
36
- "@webiny/handler-db": "6.3.0",
37
- "@webiny/utils": "6.3.0",
29
+ "@webiny/api": "6.4.0-beta.0",
30
+ "@webiny/api-headless-cms": "6.4.0-beta.0",
31
+ "@webiny/aws-sdk": "6.4.0-beta.0",
32
+ "@webiny/db-dynamodb": "6.4.0-beta.0",
33
+ "@webiny/error": "6.4.0-beta.0",
34
+ "@webiny/feature": "6.4.0-beta.0",
35
+ "@webiny/handler": "6.4.0-beta.0",
36
+ "@webiny/handler-db": "6.4.0-beta.0",
37
+ "@webiny/utils": "6.4.0-beta.0",
38
38
  "dataloader": "2.2.3",
39
39
  "dot-object": "2.1.5",
40
40
  "dot-prop": "10.1.0",
@@ -43,17 +43,17 @@
43
43
  "devDependencies": {
44
44
  "@types/dot-object": "2.1.6",
45
45
  "@types/jsonpack": "1.1.6",
46
- "@webiny/build-tools": "6.3.0",
46
+ "@webiny/build-tools": "6.4.0-beta.0",
47
47
  "@webiny/di": "0.2.3",
48
- "@webiny/plugins": "6.3.0",
49
- "@webiny/project-utils": "6.3.0",
48
+ "@webiny/plugins": "6.4.0-beta.0",
49
+ "@webiny/project-utils": "6.4.0-beta.0",
50
50
  "jest-dynalite": "3.6.1",
51
51
  "typescript": "6.0.3",
52
- "vitest": "4.1.5"
52
+ "vitest": "4.1.6"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public",
56
56
  "directory": "dist"
57
57
  },
58
- "gitHead": "7cefe15431dbd65504e1f58147dc9e55bcbfa693"
58
+ "gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
59
59
  }