@webiny/api-headless-cms-ddb 6.3.0 → 6.4.0-beta.1
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 +1 -0
- package/definitions/types.js +0 -3
- package/dynamoDb/index.js +6 -1
- 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.js +67 -77
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.js +22 -26
- 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 -29
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +31 -41
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +31 -41
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.js +33 -47
- 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.js +0 -3
- package/operations/entry/dataLoaders.js +81 -99
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.js +109 -157
- 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.js +72 -140
- package/operations/entry/filtering/filter.js.map +1 -1
- 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 -56
- 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 -126
- 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.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.js +894 -1148
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +54 -77
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.js +113 -134
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +100 -121
- package/operations/model/index.js.map +1 -1
- package/package.json +16 -16
- package/plugins/CmsEntryFieldFilterPathPlugin.js +23 -33
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- 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.js +6 -5
- package/types.js.map +1 -1
- package/definitions/types.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,142 +1,121 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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,"
|
|
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":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/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
|
-
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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,"
|
|
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,sBAAsB;gBAC/E,OAAOU,iBAAiBD;gBACxBF;gBACAC;YACJ;QACJ;IACJ;IAEA,MAAMG,SAAS,OAAOb;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,MACNS,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPF;gBACAC;YACJ;QAER;IACJ;IAEA,MAAMI,cAAc,OAAOd;QACvB,MAAM,EAAES,KAAK,EAAE,GAAGT;QAClB,MAAMU,OAAON,WAAWK;QAExB,IAAI;YACA,MAAMF,OAAO,MAAM,CAACG;QACxB,EAAE,OAAOC,IAAI;YACT,MAAM,IAAIT,MACNS,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPF;gBACAC;YACJ;QAER;IACJ;IAEA,MAAMK,MAAM,OAAOf;QACf,MAAMU,OAAON,WAAWJ;QAExB,IAAI;YACA,MAAMgB,SAAS,MAAMT,OAAO,GAAG,CAACG;YAChC,OAAOM,QAAQ,QAAQ;QAC3B,EAAE,OAAOL,IAAI;YACT,MAAM,IAAIT,MACNS,GAAG,OAAO,IAAI,wBACdA,GAAG,IAAI,IAAI,mBACX;gBACI,OAAOA;gBACPD;YACJ;QAER;IACJ;IAEA,MAAMO,OAAO,OAAOjB;QAChB,MAAM,EAAEkB,KAAK,EAAE,GAAGlB;QAElB,MAAMmB,eAAepB,mBAAmBmB;QAExC,IAAI;YACA,MAAMF,SAAS,MAAMT,OAAO,QAAQ,CAAC;gBACjCY;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
|
+
"version": "6.4.0-beta.1",
|
|
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.
|
|
30
|
-
"@webiny/api-headless-cms": "6.
|
|
31
|
-
"@webiny/aws-sdk": "6.
|
|
32
|
-
"@webiny/db-dynamodb": "6.
|
|
33
|
-
"@webiny/error": "6.
|
|
34
|
-
"@webiny/feature": "6.
|
|
35
|
-
"@webiny/handler": "6.
|
|
36
|
-
"@webiny/handler-db": "6.
|
|
37
|
-
"@webiny/utils": "6.
|
|
29
|
+
"@webiny/api": "6.4.0-beta.1",
|
|
30
|
+
"@webiny/api-headless-cms": "6.4.0-beta.1",
|
|
31
|
+
"@webiny/aws-sdk": "6.4.0-beta.1",
|
|
32
|
+
"@webiny/db-dynamodb": "6.4.0-beta.1",
|
|
33
|
+
"@webiny/error": "6.4.0-beta.1",
|
|
34
|
+
"@webiny/feature": "6.4.0-beta.1",
|
|
35
|
+
"@webiny/handler": "6.4.0-beta.1",
|
|
36
|
+
"@webiny/handler-db": "6.4.0-beta.1",
|
|
37
|
+
"@webiny/utils": "6.4.0-beta.1",
|
|
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.
|
|
47
|
-
"@webiny/di": "0.
|
|
48
|
-
"@webiny/plugins": "6.
|
|
49
|
-
"@webiny/project-utils": "6.
|
|
46
|
+
"@webiny/build-tools": "6.4.0-beta.1",
|
|
47
|
+
"@webiny/di": "1.0.0",
|
|
48
|
+
"@webiny/plugins": "6.4.0-beta.1",
|
|
49
|
+
"@webiny/project-utils": "6.4.0-beta.1",
|
|
50
50
|
"jest-dynalite": "3.6.1",
|
|
51
51
|
"typescript": "6.0.3",
|
|
52
|
-
"vitest": "4.1.
|
|
52
|
+
"vitest": "4.1.6"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public",
|
|
56
56
|
"directory": "dist"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "73237b8243693038c072bae1c0b783387448cbbe"
|
|
59
59
|
}
|