@webiny/api-headless-cms-ddb 0.0.0-unstable.6f45466a1d → 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 (119) 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 +11 -5
  10. package/definitions/types.js +0 -3
  11. package/dynamoDb/index.d.ts +1 -1
  12. package/dynamoDb/index.js +6 -3
  13. package/dynamoDb/index.js.map +1 -1
  14. package/dynamoDb/path/locationFolderId.js +16 -29
  15. package/dynamoDb/path/locationFolderId.js.map +1 -1
  16. package/dynamoDb/path/plainObject.js +11 -21
  17. package/dynamoDb/path/plainObject.js.map +1 -1
  18. package/dynamoDb/transformValue/datetime.js +21 -32
  19. package/dynamoDb/transformValue/datetime.js.map +1 -1
  20. package/index.d.ts +1 -2
  21. package/index.js +74 -79
  22. package/index.js.map +1 -1
  23. package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -0
  24. package/operations/entry/dataLoader/DataLoaderCache.js +22 -29
  25. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  26. package/operations/entry/dataLoader/constants.js +2 -1
  27. package/operations/entry/dataLoader/constants.js.map +1 -1
  28. package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
  29. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  30. package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -26
  31. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  32. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +32 -38
  33. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  34. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +32 -38
  35. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  36. package/operations/entry/dataLoader/getRevisionById.js +34 -44
  37. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  38. package/operations/entry/dataLoader/index.js +8 -9
  39. package/operations/entry/dataLoader/index.js.map +1 -1
  40. package/operations/entry/dataLoader/types.d.ts +1 -0
  41. package/operations/entry/dataLoader/types.js +0 -3
  42. package/operations/entry/dataLoaders.js +81 -97
  43. package/operations/entry/dataLoaders.js.map +1 -1
  44. package/operations/entry/filtering/createExpressions.d.ts +6 -5
  45. package/operations/entry/filtering/createExpressions.js +110 -161
  46. package/operations/entry/filtering/createExpressions.js.map +1 -1
  47. package/operations/entry/filtering/createFields.js +83 -96
  48. package/operations/entry/filtering/createFields.js.map +1 -1
  49. package/operations/entry/filtering/extractSort.js +50 -74
  50. package/operations/entry/filtering/extractSort.js.map +1 -1
  51. package/operations/entry/filtering/filter.d.ts +5 -4
  52. package/operations/entry/filtering/filter.js +73 -138
  53. package/operations/entry/filtering/filter.js.map +1 -1
  54. package/operations/entry/filtering/fullTextSearch.d.ts +2 -2
  55. package/operations/entry/filtering/fullTextSearch.js +21 -38
  56. package/operations/entry/filtering/fullTextSearch.js.map +1 -1
  57. package/operations/entry/filtering/getValue.js +31 -53
  58. package/operations/entry/filtering/getValue.js.map +1 -1
  59. package/operations/entry/filtering/index.js +0 -2
  60. package/operations/entry/filtering/mapPlugins.js +15 -22
  61. package/operations/entry/filtering/mapPlugins.js.map +1 -1
  62. package/operations/entry/filtering/plugins/defaultFilterCreate.js +29 -33
  63. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
  64. package/operations/entry/filtering/plugins/index.js +7 -3
  65. package/operations/entry/filtering/plugins/index.js.map +1 -1
  66. package/operations/entry/filtering/plugins/objectFilterCreate.js +60 -76
  67. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
  68. package/operations/entry/filtering/plugins/refFilterCreate.js +55 -66
  69. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
  70. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +43 -51
  71. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
  72. package/operations/entry/filtering/sort.js +34 -60
  73. package/operations/entry/filtering/sort.js.map +1 -1
  74. package/operations/entry/filtering/systemFields.js +144 -111
  75. package/operations/entry/filtering/systemFields.js.map +1 -1
  76. package/operations/entry/filtering/transform.js +4 -8
  77. package/operations/entry/filtering/transform.js.map +1 -1
  78. package/operations/entry/filtering/types.d.ts +2 -2
  79. package/operations/entry/filtering/types.js +0 -3
  80. package/operations/entry/filtering/values.js +11 -12
  81. package/operations/entry/filtering/values.js.map +1 -1
  82. package/operations/entry/filtering/where.js +17 -23
  83. package/operations/entry/filtering/where.js.map +1 -1
  84. package/operations/entry/index.d.ts +2 -0
  85. package/operations/entry/index.js +896 -1149
  86. package/operations/entry/index.js.map +1 -1
  87. package/operations/entry/keys.d.ts +6 -0
  88. package/operations/entry/keys.js +57 -77
  89. package/operations/entry/keys.js.map +1 -1
  90. package/operations/group/index.d.ts +2 -3
  91. package/operations/group/index.js +115 -139
  92. package/operations/group/index.js.map +1 -1
  93. package/operations/model/index.js +100 -122
  94. package/operations/model/index.js.map +1 -1
  95. package/package.json +27 -19
  96. package/plugins/CmsEntryFieldFilterPathPlugin.js +23 -33
  97. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  98. package/plugins/CmsEntryFieldFilterPlugin.d.ts +3 -3
  99. package/plugins/CmsEntryFieldFilterPlugin.js +16 -17
  100. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
  101. package/plugins/CmsEntryFieldSortingPlugin.js +16 -15
  102. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
  103. package/plugins/CmsFieldFilterValueTransformPlugin.js +15 -12
  104. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
  105. package/plugins/index.js +0 -2
  106. package/types.d.ts +5 -3
  107. package/types.js +6 -5
  108. package/types.js.map +1 -1
  109. package/definitions/types.js.map +0 -1
  110. package/dynamoDb/storage/longText.d.ts +0 -10
  111. package/dynamoDb/storage/longText.js +0 -86
  112. package/dynamoDb/storage/longText.js.map +0 -1
  113. package/dynamoDb/storage/richText.d.ts +0 -2
  114. package/dynamoDb/storage/richText.js +0 -52
  115. package/dynamoDb/storage/richText.js.map +0 -1
  116. package/operations/entry/dataLoader/types.js.map +0 -1
  117. package/operations/entry/filtering/index.js.map +0 -1
  118. package/operations/entry/filtering/types.js.map +0 -1
  119. package/plugins/index.js.map +0 -1
@@ -1,145 +1,121 @@
1
- import WebinyError from "@webiny/error";
2
- import { filterItems, sortItems, ValueFilterPlugin } from "@webiny/db-dynamodb";
3
- const createPartitionKey = params => {
4
- const {
5
- tenant
6
- } = params;
7
- return `T#${tenant}#CMS#CMG`;
1
+ import error from "@webiny/error";
2
+ import { sortItems } from "@webiny/db-dynamodb";
3
+ import { FilterUtil } from "@webiny/db-dynamodb/feature/FilterUtil/index.js";
4
+ const createPartitionKey = (params)=>{
5
+ const { tenant } = params;
6
+ return `T#${tenant}#CMS#CMG`;
8
7
  };
9
- const createSortKeys = params => {
10
- const {
11
- id
12
- } = params;
13
- return id;
8
+ const createSortKeys = (params)=>{
9
+ const { id } = params;
10
+ return id;
14
11
  };
15
- const createKeys = params => {
16
- return {
17
- PK: createPartitionKey(params),
18
- SK: createSortKeys(params),
19
- GSI_TENANT: params.tenant
20
- };
21
- };
22
- const createType = () => {
23
- return "cms.group";
24
- };
25
- export const createGroupsStorageOperations = params => {
26
- const {
27
- entity,
28
- plugins
29
- } = params;
30
- const filteringPlugins = plugins.byType(ValueFilterPlugin.type);
31
- if (filteringPlugins.length === 0) {
32
- throw new WebinyError("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
33
- }
34
- const create = async params => {
35
- const {
36
- group
37
- } = params;
38
- const keys = createKeys(group);
39
- try {
40
- await entity.put({
41
- data: group,
42
- TYPE: createType(),
43
- ...keys
44
- });
45
- } catch (ex) {
46
- throw new WebinyError(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
47
- error: ex,
48
- group,
49
- keys
50
- });
51
- }
52
- };
53
- const update = async params => {
54
- const {
55
- group
56
- } = params;
57
- const keys = createKeys(group);
58
- try {
59
- await entity.put({
60
- data: group,
61
- TYPE: createType(),
62
- ...keys
63
- });
64
- } catch (ex) {
65
- throw new WebinyError(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
66
- error: ex,
67
- group,
68
- keys
69
- });
70
- }
71
- };
72
- const deleteGroup = async params => {
73
- const {
74
- group
75
- } = params;
76
- const keys = createKeys(group);
77
- try {
78
- await entity.delete(keys);
79
- } catch (ex) {
80
- throw new WebinyError(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
81
- error: ex,
82
- group,
83
- keys
84
- });
85
- }
86
- };
87
- const get = async params => {
88
- const keys = createKeys(params);
89
- try {
90
- const result = await entity.get(keys);
91
- return result?.data || null;
92
- } catch (ex) {
93
- throw new WebinyError(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", {
94
- error: ex,
95
- ...params,
96
- keys
97
- });
98
- }
99
- };
100
- const list = async params => {
101
- const {
102
- sort,
103
- where
104
- } = params;
105
- let records = [];
106
- try {
107
- const ddbRecords = await entity.queryAll({
108
- partitionKey: createPartitionKey(where),
109
- options: {
110
- gte: " "
111
- }
112
- });
113
- records = ddbRecords.map(item => item.data);
114
- } catch (ex) {
115
- throw new WebinyError(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", {
116
- error: ex,
117
- ...params,
118
- sort,
119
- where
120
- });
121
- }
122
- const filteredItems = filterItems({
123
- items: records,
124
- where,
125
- fields: [],
126
- plugins
12
+ const createKeys = (params)=>({
13
+ PK: createPartitionKey(params),
14
+ SK: createSortKeys(params),
15
+ GSI_TENANT: params.tenant
127
16
  });
128
- if (!sort || sort.length === 0) {
129
- return filteredItems;
130
- }
131
- return sortItems({
132
- items: filteredItems,
133
- sort
134
- });
135
- };
136
- return {
137
- create,
138
- update,
139
- delete: deleteGroup,
140
- get,
141
- list
142
- };
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
+ };
143
118
  };
119
+ export { createGroupsStorageOperations };
144
120
 
145
121
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","filterItems","sortItems","ValueFilterPlugin","createPartitionKey","params","tenant","createSortKeys","id","createKeys","PK","SK","GSI_TENANT","createType","createGroupsStorageOperations","entity","plugins","filteringPlugins","byType","type","length","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","items","fields"],"sources":["index.ts"],"sourcesContent":["import type {\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 { filterItems, sortItems, ValueFilterPlugin } from \"@webiny/db-dynamodb\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { IGroupEntity } from \"~/definitions/types.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 plugins: PluginsContainer;\n}\nexport const createGroupsStorageOperations = (\n params: CreateGroupsStorageOperationsParams\n): CmsGroupStorageOperations => {\n const { entity, plugins } = params;\n\n const filteringPlugins = plugins.byType<ValueFilterPlugin>(ValueFilterPlugin.type);\n if (filteringPlugins.length === 0) {\n throw new WebinyError(\n \"DynamoDB filtering plugins not loaded.\",\n \"MISSING_DYNAMODB_FILTERING_PLUGINS\"\n );\n }\n\n const create = async (params: CmsGroupStorageOperationsCreateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n 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 = filterItems({\n items: records,\n where,\n fields: [],\n plugins\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":"AASA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,WAAW,EAAEC,SAAS,EAAEC,iBAAiB,QAAQ,qBAAqB;AAO/E,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,EAAE;AACb,CAAC;AAOD,MAAMC,UAAU,GAAIJ,MAA0C,IAAW;EACrE,OAAO;IACHK,EAAE,EAAEN,kBAAkB,CAACC,MAAM,CAAC;IAC9BM,EAAE,EAAEJ,cAAc,CAACF,MAAM,CAAC;IAC1BO,UAAU,EAAEP,MAAM,CAACC;EACvB,CAAC;AACL,CAAC;AAED,MAAMO,UAAU,GAAGA,CAAA,KAAc;EAC7B,OAAO,WAAW;AACtB,CAAC;AAMD,OAAO,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C,kBAAkB,CAACkC,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,IAAI3B,WAAW,CACjB2B,EAAE,CAACC,OAAO,IAAI,wBAAwB,EACtCD,EAAE,CAACE,IAAI,IAAI,kBAAkB,EAC7B;QACIC,KAAK,EAAEH,EAAE;QACT,GAAGtB,MAAM;QACTgC,IAAI;QACJC;MACJ,CACJ,CAAC;IACL;IAEA,MAAMS,aAAa,GAAG9C,WAAW,CAAC;MAC9B+C,KAAK,EAAET,OAAO;MACdD,KAAK;MACLW,MAAM,EAAE,EAAE;MACVjC;IACJ,CAAC,CAAC;IACF,IAAI,CAACqB,IAAI,IAAIA,IAAI,CAACjB,MAAM,KAAK,CAAC,EAAE;MAC5B,OAAO2B,aAAa;IACxB;IAEA,OAAO7C,SAAS,CAAC;MACb8C,KAAK,EAAED,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,YAAYA,OAAO,MAAM;IAC7B;AAGJ,MAAMK,aAAa,IACR;AAOJ,MAAMC,gCAAgC,CACzCN;IAEA,MAAM,EAAEO,MAAM,EAAEC,SAAS,EAAE,GAAGR;IAC9B,MAAMS,aAAaD,UAA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ACJ;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,128 +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
- return model;
77
- } catch (ex) {
78
- throw new WebinyError(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
79
- error: ex,
80
- model,
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 model.", ex.code || "MODEL_GET_ERROR", {
92
- error: ex,
93
- keys
94
- });
95
- }
96
- };
97
- const list = async params => {
98
- const {
99
- where
100
- } = params;
101
- const partitionKey = createPartitionKey(where);
102
- try {
103
- const result = await entity.queryAll({
104
- partitionKey,
105
- options: {
106
- 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
+ });
107
94
  }
108
- });
109
- return result.map(item => {
110
- return item.data;
111
- });
112
- } catch (ex) {
113
- throw new WebinyError(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
114
- error: ex,
115
- partitionKey
116
- });
117
- }
118
- };
119
- return {
120
- create,
121
- update,
122
- delete: deleteModel,
123
- get,
124
- list
125
- };
95
+ };
96
+ return {
97
+ create,
98
+ update,
99
+ delete: deleteModel,
100
+ get,
101
+ list
102
+ };
126
103
  };
104
+ export { createModelsStorageOperations };
127
105
 
128
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 return model;\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,M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,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,CAAC;gBACb,MAAME;gBACN,GAAGC,IAAI;gBACP,MAAML;YACV;YACA,OAAOI;QACX,EAAE,OAAOE,IAAI;YACT,MAAM,IAAIT,MAAY,uCAAuC,s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