@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.
- package/definitions/entry.js +7 -9
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +7 -9
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +7 -9
- package/definitions/model.js.map +1 -1
- package/definitions/table.js +6 -7
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +11 -5
- package/definitions/types.js +0 -3
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +6 -3
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.js +16 -29
- package/dynamoDb/path/locationFolderId.js.map +1 -1
- package/dynamoDb/path/plainObject.js +11 -21
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/transformValue/datetime.js +21 -32
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +1 -2
- package/index.js +74 -79
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +22 -29
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +2 -1
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -26
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +32 -38
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +32 -38
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.js +34 -44
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.js +8 -9
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +1 -0
- package/operations/entry/dataLoader/types.js +0 -3
- package/operations/entry/dataLoaders.js +81 -97
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +6 -5
- package/operations/entry/filtering/createExpressions.js +110 -161
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.js +83 -96
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.js +50 -74
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +5 -4
- package/operations/entry/filtering/filter.js +73 -138
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +2 -2
- package/operations/entry/filtering/fullTextSearch.js +21 -38
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +31 -53
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.js +0 -2
- package/operations/entry/filtering/mapPlugins.js +15 -22
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +29 -33
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.js +7 -3
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +60 -76
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +55 -66
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +43 -51
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.js +34 -60
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.js +144 -111
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.js +4 -8
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +2 -2
- package/operations/entry/filtering/types.js +0 -3
- package/operations/entry/filtering/values.js +11 -12
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +17 -23
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +2 -0
- package/operations/entry/index.js +896 -1149
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +6 -0
- package/operations/entry/keys.js +57 -77
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +2 -3
- package/operations/group/index.js +115 -139
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +100 -122
- package/operations/model/index.js.map +1 -1
- package/package.json +27 -19
- package/plugins/CmsEntryFieldFilterPathPlugin.js +23 -33
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +3 -3
- package/plugins/CmsEntryFieldFilterPlugin.js +16 -17
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.js +16 -15
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.js +15 -12
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.js +0 -2
- package/types.d.ts +5 -3
- package/types.js +6 -5
- package/types.js.map +1 -1
- package/definitions/types.js.map +0 -1
- package/dynamoDb/storage/longText.d.ts +0 -10
- package/dynamoDb/storage/longText.js +0 -86
- package/dynamoDb/storage/longText.js.map +0 -1
- package/dynamoDb/storage/richText.d.ts +0 -2
- package/dynamoDb/storage/richText.js +0 -52
- package/dynamoDb/storage/richText.js.map +0 -1
- package/operations/entry/dataLoader/types.js.map +0 -1
- package/operations/entry/filtering/index.js.map +0 -1
- package/operations/entry/filtering/types.js.map +0 -1
- package/plugins/index.js.map +0 -1
|
@@ -1,145 +1,121 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tenant
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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,"
|
|
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,UAAU,OAAO,CAACE;IAErC,MAAMC,SAAS,OAAOX;QAClB,MAA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AM,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
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { convertException } from "@webiny/utils";
|
|
3
|
-
const createPartitionKey = params
|
|
4
|
-
|
|
5
|
-
tenant
|
|
6
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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,"
|
|
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,GAAG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