@webiny/api-headless-cms-ddb 0.0.0-unstable.aa00eecd97 → 0.0.0-unstable.ac6ebf63c6
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/README.md +6 -20
- package/definitions/entry.d.ts +4 -5
- package/definitions/entry.js +7 -88
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -5
- package/definitions/group.js +7 -59
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -5
- package/definitions/model.js +7 -103
- package/definitions/model.js.map +1 -1
- package/definitions/table.d.ts +4 -6
- package/definitions/table.js +8 -26
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +59 -0
- package/definitions/types.js +3 -0
- package/definitions/types.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +7 -12
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +2 -0
- package/dynamoDb/path/locationFolderId.js +34 -0
- package/dynamoDb/path/locationFolderId.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +7 -14
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/longText.js +13 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +28 -71
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +7 -12
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +40 -82
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -3
- package/operations/entry/dataLoader/DataLoaderCache.js +8 -17
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +3 -8
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -10
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
- package/operations/entry/dataLoader/getAllEntryRevisions.js +13 -24
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +24 -35
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +24 -35
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
- package/operations/entry/dataLoader/getRevisionById.js +26 -37
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.d.ts +5 -5
- package/operations/entry/dataLoader/index.js +12 -31
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +3 -4
- package/operations/entry/dataLoader/types.js +2 -4
- package/operations/entry/dataLoader/types.js.map +1 -1
- package/operations/entry/dataLoaders.d.ts +11 -12
- package/operations/entry/dataLoaders.js +25 -34
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +5 -5
- package/operations/entry/filtering/createExpressions.js +29 -30
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +6 -4
- package/operations/entry/filtering/createFields.js +87 -86
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +6 -6
- package/operations/entry/filtering/extractSort.js +40 -23
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +6 -6
- package/operations/entry/filtering/filter.js +36 -29
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
- package/operations/entry/filtering/fullTextSearch.js +8 -14
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +6 -10
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.d.ts +2 -2
- package/operations/entry/filtering/index.js +3 -18
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.d.ts +2 -2
- package/operations/entry/filtering/mapPlugins.js +5 -11
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +10 -14
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/filtering/plugins/index.js +8 -12
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/objectFilterCreate.js +17 -19
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -2
- package/operations/entry/filtering/plugins/refFilterCreate.js +22 -19
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +57 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +6 -6
- package/operations/entry/filtering/sort.js +18 -20
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -4
- package/operations/entry/filtering/systemFields.js +88 -42
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.d.ts +1 -1
- package/operations/entry/filtering/transform.js +3 -8
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +3 -3
- package/operations/entry/filtering/types.js +2 -4
- package/operations/entry/filtering/types.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +1 -1
- package/operations/entry/filtering/values.js +6 -12
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +6 -10
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +3 -4
- package/operations/entry/index.js +635 -339
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +40 -2
- package/operations/entry/keys.js +55 -30
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +4 -4
- package/operations/group/index.js +44 -61
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +37 -46
- package/operations/model/index.js.map +1 -1
- package/package.json +21 -28
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
- package/plugins/CmsEntryFieldFilterPathPlugin.js +15 -16
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
- package/plugins/CmsEntryFieldFilterPlugin.js +11 -14
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldSortingPlugin.js +6 -15
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +2 -2
- package/plugins/CmsFieldFilterValueTransformPlugin.js +5 -13
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +4 -4
- package/plugins/index.js +5 -48
- package/plugins/index.js.map +1 -1
- package/types.d.ts +18 -22
- package/types.js +5 -12
- package/types.js.map +1 -1
- package/definitions/settings.d.ts +0 -9
- package/definitions/settings.js +0 -53
- package/definitions/settings.js.map +0 -1
- package/definitions/system.d.ts +0 -9
- package/definitions/system.js +0 -41
- package/definitions/system.js.map +0 -1
- package/dynamoDb/storage/date.d.ts +0 -3
- package/dynamoDb/storage/date.js +0 -91
- package/dynamoDb/storage/date.js.map +0 -1
- package/operations/entry/systemFields.d.ts +0 -2
- package/operations/entry/systemFields.js +0 -72
- package/operations/entry/systemFields.js.map +0 -1
- package/operations/settings/index.d.ts +0 -7
- package/operations/settings/index.js +0 -111
- package/operations/settings/index.js.map +0 -1
- package/operations/system/index.d.ts +0 -7
- package/operations/system/index.js +0 -82
- package/operations/system/index.js.map +0 -1
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createGroupsStorageOperations = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
11
|
-
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
12
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
13
|
-
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
14
|
-
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
15
|
-
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { filterItems, sortItems, ValueFilterPlugin } from "@webiny/db-dynamodb";
|
|
16
3
|
const createPartitionKey = params => {
|
|
17
4
|
const {
|
|
18
|
-
tenant
|
|
19
|
-
locale
|
|
5
|
+
tenant
|
|
20
6
|
} = params;
|
|
21
|
-
return `T#${tenant}#
|
|
7
|
+
return `T#${tenant}#CMS#CMG`;
|
|
22
8
|
};
|
|
23
9
|
const createSortKeys = params => {
|
|
24
10
|
const {
|
|
@@ -29,20 +15,21 @@ const createSortKeys = params => {
|
|
|
29
15
|
const createKeys = params => {
|
|
30
16
|
return {
|
|
31
17
|
PK: createPartitionKey(params),
|
|
32
|
-
SK: createSortKeys(params)
|
|
18
|
+
SK: createSortKeys(params),
|
|
19
|
+
GSI_TENANT: params.tenant
|
|
33
20
|
};
|
|
34
21
|
};
|
|
35
22
|
const createType = () => {
|
|
36
23
|
return "cms.group";
|
|
37
24
|
};
|
|
38
|
-
const createGroupsStorageOperations = params => {
|
|
25
|
+
export const createGroupsStorageOperations = params => {
|
|
39
26
|
const {
|
|
40
27
|
entity,
|
|
41
28
|
plugins
|
|
42
29
|
} = params;
|
|
43
|
-
const filteringPlugins = plugins.byType(
|
|
30
|
+
const filteringPlugins = plugins.byType(ValueFilterPlugin.type);
|
|
44
31
|
if (filteringPlugins.length === 0) {
|
|
45
|
-
throw new
|
|
32
|
+
throw new WebinyError("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
|
|
46
33
|
}
|
|
47
34
|
const create = async params => {
|
|
48
35
|
const {
|
|
@@ -50,12 +37,13 @@ const createGroupsStorageOperations = params => {
|
|
|
50
37
|
} = params;
|
|
51
38
|
const keys = createKeys(group);
|
|
52
39
|
try {
|
|
53
|
-
await entity.put(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
await entity.put({
|
|
41
|
+
data: group,
|
|
42
|
+
TYPE: createType(),
|
|
43
|
+
...keys
|
|
44
|
+
});
|
|
57
45
|
} catch (ex) {
|
|
58
|
-
throw new
|
|
46
|
+
throw new WebinyError(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
|
|
59
47
|
error: ex,
|
|
60
48
|
group,
|
|
61
49
|
keys
|
|
@@ -68,12 +56,13 @@ const createGroupsStorageOperations = params => {
|
|
|
68
56
|
} = params;
|
|
69
57
|
const keys = createKeys(group);
|
|
70
58
|
try {
|
|
71
|
-
await entity.put(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
await entity.put({
|
|
60
|
+
data: group,
|
|
61
|
+
TYPE: createType(),
|
|
62
|
+
...keys
|
|
63
|
+
});
|
|
75
64
|
} catch (ex) {
|
|
76
|
-
throw new
|
|
65
|
+
throw new WebinyError(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
|
|
77
66
|
error: ex,
|
|
78
67
|
group,
|
|
79
68
|
keys
|
|
@@ -84,13 +73,11 @@ const createGroupsStorageOperations = params => {
|
|
|
84
73
|
const {
|
|
85
74
|
group
|
|
86
75
|
} = params;
|
|
87
|
-
// TODO make sure that group has locale and tenant on it - add it in the crud just in case
|
|
88
76
|
const keys = createKeys(group);
|
|
89
77
|
try {
|
|
90
78
|
await entity.delete(keys);
|
|
91
|
-
return group;
|
|
92
79
|
} catch (ex) {
|
|
93
|
-
throw new
|
|
80
|
+
throw new WebinyError(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
|
|
94
81
|
error: ex,
|
|
95
82
|
group,
|
|
96
83
|
keys
|
|
@@ -100,17 +87,14 @@ const createGroupsStorageOperations = params => {
|
|
|
100
87
|
const get = async params => {
|
|
101
88
|
const keys = createKeys(params);
|
|
102
89
|
try {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
keys
|
|
106
|
-
});
|
|
107
|
-
return (0, _cleanup.cleanupItem)(entity, group);
|
|
90
|
+
const result = await entity.get(keys);
|
|
91
|
+
return result?.data || null;
|
|
108
92
|
} catch (ex) {
|
|
109
|
-
throw new
|
|
110
|
-
error: ex
|
|
111
|
-
|
|
93
|
+
throw new WebinyError(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", {
|
|
94
|
+
error: ex,
|
|
95
|
+
...params,
|
|
112
96
|
keys
|
|
113
|
-
})
|
|
97
|
+
});
|
|
114
98
|
}
|
|
115
99
|
};
|
|
116
100
|
const list = async params => {
|
|
@@ -118,25 +102,24 @@ const createGroupsStorageOperations = params => {
|
|
|
118
102
|
sort,
|
|
119
103
|
where
|
|
120
104
|
} = params;
|
|
121
|
-
const queryAllParams = {
|
|
122
|
-
entity,
|
|
123
|
-
partitionKey: createPartitionKey(where),
|
|
124
|
-
options: {
|
|
125
|
-
gte: " "
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
105
|
let records = [];
|
|
129
106
|
try {
|
|
130
|
-
|
|
107
|
+
const ddbRecords = await entity.queryAll({
|
|
108
|
+
partitionKey: createPartitionKey(where),
|
|
109
|
+
options: {
|
|
110
|
+
gte: " "
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
records = ddbRecords.map(item => item.data);
|
|
131
114
|
} catch (ex) {
|
|
132
|
-
throw new
|
|
133
|
-
error: ex
|
|
134
|
-
|
|
115
|
+
throw new WebinyError(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", {
|
|
116
|
+
error: ex,
|
|
117
|
+
...params,
|
|
135
118
|
sort,
|
|
136
119
|
where
|
|
137
|
-
})
|
|
120
|
+
});
|
|
138
121
|
}
|
|
139
|
-
const filteredItems =
|
|
122
|
+
const filteredItems = filterItems({
|
|
140
123
|
items: records,
|
|
141
124
|
where,
|
|
142
125
|
fields: [],
|
|
@@ -145,10 +128,9 @@ const createGroupsStorageOperations = params => {
|
|
|
145
128
|
if (!sort || sort.length === 0) {
|
|
146
129
|
return filteredItems;
|
|
147
130
|
}
|
|
148
|
-
return
|
|
131
|
+
return sortItems({
|
|
149
132
|
items: filteredItems,
|
|
150
|
-
sort
|
|
151
|
-
fields: []
|
|
133
|
+
sort
|
|
152
134
|
});
|
|
153
135
|
};
|
|
154
136
|
return {
|
|
@@ -159,4 +141,5 @@ const createGroupsStorageOperations = params => {
|
|
|
159
141
|
list
|
|
160
142
|
};
|
|
161
143
|
};
|
|
162
|
-
|
|
144
|
+
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createPartitionKey","params","tenant","
|
|
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,MAAMC,6BAA6B,GACtCT,MAA2C,IACf;EAC5B,MAAM;IAAEU,MAAM;IAAEC;EAAQ,CAAC,GAAGX,MAAM;EAElC,MAAMY,gBAAgB,GAAGD,OAAO,CAACE,MAAM,CAAoBf,iBAAiB,CAACgB,IAAI,CAAC;EAClF,IAAIF,gBAAgB,CAACG,MAAM,KAAK,CAAC,EAAE;IAC/B,MAAM,IAAIpB,WAAW,CACjB,wCAAwC,EACxC,oCACJ,CAAC;EACL;EAEA,MAAMqB,MAAM,GAAG,MAAOhB,MAA6C,IAAK;IACpE,MAAM;MAAEiB;IAAM,CAAC,GAAGjB,MAAM;IACxB,MAAMkB,IAAI,GAAGd,UAAU,CAACa,KAAK,CAAC;IAC9B,IAAI;MACA,M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AK,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,7 +1,7 @@
|
|
|
1
|
-
import { CmsModelStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import {
|
|
1
|
+
import type { CmsModelStorageOperations } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { IModelEntity } from "../../definitions/types.js";
|
|
3
3
|
interface CreateModelsStorageOperationsParams {
|
|
4
|
-
entity:
|
|
4
|
+
entity: IModelEntity;
|
|
5
5
|
}
|
|
6
6
|
export declare const createModelsStorageOperations: (params: CreateModelsStorageOperationsParams) => CmsModelStorageOperations;
|
|
7
7
|
export {};
|
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createModelsStorageOperations = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
11
|
-
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
12
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { convertException } from "@webiny/utils";
|
|
13
3
|
const createPartitionKey = params => {
|
|
14
4
|
const {
|
|
15
|
-
tenant
|
|
16
|
-
locale
|
|
5
|
+
tenant
|
|
17
6
|
} = params;
|
|
18
7
|
if (!tenant) {
|
|
19
|
-
throw new
|
|
20
|
-
} else if (!locale) {
|
|
21
|
-
throw new _error.default(`Missing locale variable when creating model partitionKey.`);
|
|
8
|
+
throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);
|
|
22
9
|
}
|
|
23
|
-
return `T#${tenant}#
|
|
10
|
+
return `T#${tenant}#CMS#CM`;
|
|
24
11
|
};
|
|
25
12
|
const createSortKey = params => {
|
|
26
13
|
return params.modelId;
|
|
@@ -28,13 +15,14 @@ const createSortKey = params => {
|
|
|
28
15
|
const createKeys = params => {
|
|
29
16
|
return {
|
|
30
17
|
PK: createPartitionKey(params),
|
|
31
|
-
SK: createSortKey(params)
|
|
18
|
+
SK: createSortKey(params),
|
|
19
|
+
GSI_TENANT: params.tenant
|
|
32
20
|
};
|
|
33
21
|
};
|
|
34
22
|
const createType = () => {
|
|
35
23
|
return "cms.model";
|
|
36
24
|
};
|
|
37
|
-
const createModelsStorageOperations = params => {
|
|
25
|
+
export const createModelsStorageOperations = params => {
|
|
38
26
|
const {
|
|
39
27
|
entity
|
|
40
28
|
} = params;
|
|
@@ -44,13 +32,15 @@ const createModelsStorageOperations = params => {
|
|
|
44
32
|
} = params;
|
|
45
33
|
const keys = createKeys(model);
|
|
46
34
|
try {
|
|
47
|
-
await entity.put(
|
|
35
|
+
await entity.put({
|
|
36
|
+
data: model,
|
|
37
|
+
...keys,
|
|
48
38
|
TYPE: createType()
|
|
49
|
-
})
|
|
39
|
+
});
|
|
50
40
|
return model;
|
|
51
41
|
} catch (ex) {
|
|
52
|
-
throw new
|
|
53
|
-
error: ex,
|
|
42
|
+
throw new WebinyError(`Could not create CMS Content Model.`, "CREATE_MODEL_ERROR", {
|
|
43
|
+
error: convertException(ex),
|
|
54
44
|
model,
|
|
55
45
|
keys
|
|
56
46
|
});
|
|
@@ -62,12 +52,14 @@ const createModelsStorageOperations = params => {
|
|
|
62
52
|
} = params;
|
|
63
53
|
const keys = createKeys(model);
|
|
64
54
|
try {
|
|
65
|
-
await entity.put(
|
|
55
|
+
await entity.put({
|
|
56
|
+
data: model,
|
|
57
|
+
...keys,
|
|
66
58
|
TYPE: createType()
|
|
67
|
-
})
|
|
59
|
+
});
|
|
68
60
|
return model;
|
|
69
61
|
} catch (ex) {
|
|
70
|
-
throw new
|
|
62
|
+
throw new WebinyError(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
|
|
71
63
|
error: ex,
|
|
72
64
|
model,
|
|
73
65
|
keys
|
|
@@ -83,7 +75,7 @@ const createModelsStorageOperations = params => {
|
|
|
83
75
|
await entity.delete(keys);
|
|
84
76
|
return model;
|
|
85
77
|
} catch (ex) {
|
|
86
|
-
throw new
|
|
78
|
+
throw new WebinyError(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
|
|
87
79
|
error: ex,
|
|
88
80
|
model,
|
|
89
81
|
keys
|
|
@@ -93,13 +85,10 @@ const createModelsStorageOperations = params => {
|
|
|
93
85
|
const get = async params => {
|
|
94
86
|
const keys = createKeys(params);
|
|
95
87
|
try {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
keys
|
|
99
|
-
});
|
|
100
|
-
return (0, _cleanup.cleanupItem)(entity, item);
|
|
88
|
+
const result = await entity.get(keys);
|
|
89
|
+
return result?.data || null;
|
|
101
90
|
} catch (ex) {
|
|
102
|
-
throw new
|
|
91
|
+
throw new WebinyError(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
|
|
103
92
|
error: ex,
|
|
104
93
|
keys
|
|
105
94
|
});
|
|
@@ -109,20 +98,21 @@ const createModelsStorageOperations = params => {
|
|
|
109
98
|
const {
|
|
110
99
|
where
|
|
111
100
|
} = params;
|
|
112
|
-
const
|
|
113
|
-
entity,
|
|
114
|
-
partitionKey: createPartitionKey(where),
|
|
115
|
-
options: {
|
|
116
|
-
gte: " "
|
|
117
|
-
}
|
|
118
|
-
};
|
|
101
|
+
const partitionKey = createPartitionKey(where);
|
|
119
102
|
try {
|
|
120
|
-
const
|
|
121
|
-
|
|
103
|
+
const result = await entity.queryAll({
|
|
104
|
+
partitionKey,
|
|
105
|
+
options: {
|
|
106
|
+
gte: " "
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return result.map(item => {
|
|
110
|
+
return item.data;
|
|
111
|
+
});
|
|
122
112
|
} catch (ex) {
|
|
123
|
-
throw new
|
|
113
|
+
throw new WebinyError(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
|
|
124
114
|
error: ex,
|
|
125
|
-
partitionKey
|
|
115
|
+
partitionKey
|
|
126
116
|
});
|
|
127
117
|
}
|
|
128
118
|
};
|
|
@@ -134,4 +124,5 @@ const createModelsStorageOperations = params => {
|
|
|
134
124
|
list
|
|
135
125
|
};
|
|
136
126
|
};
|
|
137
|
-
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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,MAAM,eAAe;AASvC,SAASC,gBAAgB,QAAQ,eAAe;AAMhD,MAAMC,kBAAkB,GAAIC,MAA2B,IAAa;EAChE,MAAM;IAAEC;EAAO,CAAC,GAAGD,MAAM;EACzB,IAAI,CAACC,MAAM,EAAE;IACT,MAAM,IAAIJ,WAAW,CAAC,2DAA2D,CAAC;EACtF;EACA,OAAO,KAAKI,MAAM,SAAS;AAC/B,CAAC;AAKD,MAAMC,aAAa,GAAIF,MAAqB,IAAa;EACrD,OAAOA,MAAM,CAACG,OAAO;AACzB,CAAC;AAOD,MAAMC,UAAU,GAAIJ,MAA2C,IAAW;EACtE,OAAO;IACHK,EAAE,EAAEN,kBAAkB,CAACC,MAAM,CAAC;IAC9BM,EAAE,EAAEJ,aAAa,CAACF,MAAM,CAAC;IACzBO,UAAU,EAAEP,MAAM,CAACC;EACvB,CAAC;AACL,CAAC;AAED,MAAMO,UAAU,GAAGA,CAAA,KAAc;EAC7B,OAAO,WAAW;AACtB,CAAC;AAKD,OAAO,MAAMC,6BAA6B,GACtCT,MAA2C,IACf;EAC5B,MAAM;IAAEU;EAAO,CAAC,GAAGV,MAAM;EAEzB,MAAMW,MAAM,GAAG,MAAOX,MAA6C,IAAK;IACpE,M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;IACL;EACJ,CAAC;EAED,OAAO;IACHjB,MAAM;IACNQ,MAAM;IACNI,MAAM,EAAED,WAAW;IACnBE,GAAG;IACHE;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-ddb",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.ac6ebf63c6",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"@webiny/api-headless-cms",
|
|
7
8
|
"storage-operations",
|
|
8
9
|
"dynamodb",
|
|
10
|
+
"ddb",
|
|
9
11
|
"cms:ddb"
|
|
10
12
|
],
|
|
11
13
|
"repository": {
|
|
@@ -21,40 +23,31 @@
|
|
|
21
23
|
],
|
|
22
24
|
"license": "MIT",
|
|
23
25
|
"dependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
26
|
-
"@webiny/
|
|
27
|
-
"@webiny/
|
|
28
|
-
"@webiny/
|
|
29
|
-
"@webiny/
|
|
30
|
-
"
|
|
31
|
-
"dataloader": "2.2.
|
|
26
|
+
"@webiny/api": "0.0.0-unstable.ac6ebf63c6",
|
|
27
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.ac6ebf63c6",
|
|
28
|
+
"@webiny/aws-sdk": "0.0.0-unstable.ac6ebf63c6",
|
|
29
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.ac6ebf63c6",
|
|
30
|
+
"@webiny/error": "0.0.0-unstable.ac6ebf63c6",
|
|
31
|
+
"@webiny/handler-db": "0.0.0-unstable.ac6ebf63c6",
|
|
32
|
+
"@webiny/utils": "0.0.0-unstable.ac6ebf63c6",
|
|
33
|
+
"dataloader": "2.2.3",
|
|
34
|
+
"dot-object": "2.1.5",
|
|
32
35
|
"dot-prop": "6.0.1",
|
|
33
|
-
"
|
|
34
|
-
"jsonpack": "1.1.5",
|
|
35
|
-
"lodash": "4.17.21"
|
|
36
|
+
"lodash": "4.17.23"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@webiny/
|
|
43
|
-
"@webiny/plugins": "0.0.0-unstable.aa00eecd97",
|
|
44
|
-
"@webiny/project-utils": "0.0.0-unstable.aa00eecd97",
|
|
45
|
-
"jest": "28.1.3",
|
|
39
|
+
"@types/dot-object": "2.1.6",
|
|
40
|
+
"@types/jsonpack": "1.1.6",
|
|
41
|
+
"@webiny/build-tools": "0.0.0-unstable.ac6ebf63c6",
|
|
42
|
+
"@webiny/plugins": "0.0.0-unstable.ac6ebf63c6",
|
|
43
|
+
"@webiny/project-utils": "0.0.0-unstable.ac6ebf63c6",
|
|
46
44
|
"jest-dynalite": "3.6.1",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"typescript": "4.7.4"
|
|
45
|
+
"typescript": "5.9.3",
|
|
46
|
+
"vitest": "3.2.4"
|
|
50
47
|
},
|
|
51
48
|
"publishConfig": {
|
|
52
49
|
"access": "public",
|
|
53
50
|
"directory": "dist"
|
|
54
51
|
},
|
|
55
|
-
"
|
|
56
|
-
"build": "yarn webiny run build",
|
|
57
|
-
"watch": "yarn webiny run watch"
|
|
58
|
-
},
|
|
59
|
-
"gitHead": "aa00eecd97d16da9bdb0581f33d491487ce43ce9"
|
|
52
|
+
"gitHead": "ac6ebf63c6de308703d41f2c1b375e03cd96b813"
|
|
60
53
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
3
3
|
export interface CreatePathCallableParams {
|
|
4
4
|
field: Partial<CmsModelField> & Pick<CmsModelField, "fieldId" | "storageId" | "id">;
|
|
5
5
|
index?: number;
|
|
@@ -11,12 +11,13 @@ export interface CmsEntryFieldFilterPathPluginParams {
|
|
|
11
11
|
fieldType: string;
|
|
12
12
|
fieldId?: string[];
|
|
13
13
|
path: string | CreatePathCallable;
|
|
14
|
+
canUse?: (field: Pick<CmsModelField, "fieldId" | "type">, parents?: string[]) => boolean;
|
|
14
15
|
}
|
|
15
16
|
export declare class CmsEntryFieldFilterPathPlugin extends Plugin {
|
|
16
17
|
static readonly type: string;
|
|
17
18
|
private readonly config;
|
|
18
19
|
get fieldType(): string;
|
|
19
20
|
constructor(config: CmsEntryFieldFilterPathPluginParams);
|
|
20
|
-
canUse(field: Pick<CmsModelField, "fieldId" | "type"
|
|
21
|
+
canUse(field: Pick<CmsModelField, "fieldId" | "type">, parents: string[]): boolean;
|
|
21
22
|
createPath(params: CreatePathCallableParams): string;
|
|
22
23
|
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.CmsEntryFieldFilterPathPlugin = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
var _Plugin = require("@webiny/plugins/Plugin");
|
|
11
|
-
class CmsEntryFieldFilterPathPlugin extends _Plugin.Plugin {
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
3
|
+
export class CmsEntryFieldFilterPathPlugin extends Plugin {
|
|
4
|
+
static type = "cms-field-filter-path";
|
|
12
5
|
get fieldType() {
|
|
13
6
|
return this.config.fieldType;
|
|
14
7
|
}
|
|
15
8
|
constructor(config) {
|
|
16
9
|
super();
|
|
17
|
-
(0, _defineProperty2.default)(this, "config", void 0);
|
|
18
10
|
this.config = config;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* We expect error here because we know that `this.constructor.type` is defined, but TS does not.
|
|
14
|
+
*/
|
|
15
|
+
// @ts-expect-error
|
|
19
16
|
this.name = `${this.constructor.type}-${this.config.fieldType}`;
|
|
20
17
|
}
|
|
21
|
-
canUse(field) {
|
|
18
|
+
canUse(field, parents) {
|
|
22
19
|
if (field.type !== this.config.fieldType) {
|
|
23
20
|
return false;
|
|
21
|
+
} else if (this.config.canUse) {
|
|
22
|
+
return this.config.canUse(field, parents);
|
|
24
23
|
}
|
|
25
24
|
const fieldId = this.config.fieldId;
|
|
26
25
|
if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {
|
|
@@ -34,8 +33,8 @@ class CmsEntryFieldFilterPathPlugin extends _Plugin.Plugin {
|
|
|
34
33
|
} else if (typeof this.config.path === "string") {
|
|
35
34
|
return this.config.path;
|
|
36
35
|
}
|
|
37
|
-
throw new
|
|
36
|
+
throw new WebinyError(`Missing path in "${this.name}" plugin.`);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=CmsEntryFieldFilterPathPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","Plugin","CmsEntryFieldFilterPathPlugin","type","fieldType","config","constructor","name","canUse","field","parents","fieldId","Array","isArray","length","includes","createPath","params","path"],"sources":["CmsEntryFieldFilterPathPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport interface CreatePathCallableParams {\n field: Partial<CmsModelField> & Pick<CmsModelField, \"fieldId\" | \"storageId\" | \"id\">;\n index?: number;\n}\nexport interface CreatePathCallable {\n (params: CreatePathCallableParams): string;\n}\nexport interface CmsEntryFieldFilterPathPluginParams {\n fieldType: string;\n fieldId?: string[];\n path: string | CreatePathCallable;\n canUse?: (field: Pick<CmsModelField, \"fieldId\" | \"type\">, parents?: string[]) => boolean;\n}\nexport class CmsEntryFieldFilterPathPlugin extends Plugin {\n public static override readonly type: string = \"cms-field-filter-path\";\n\n private readonly config: CmsEntryFieldFilterPathPluginParams;\n\n public get fieldType(): string {\n return this.config.fieldType;\n }\n\n public constructor(config: CmsEntryFieldFilterPathPluginParams) {\n super();\n\n this.config = config;\n\n /**\n * We expect error here because we know that `this.constructor.type` is defined, but TS does not.\n */\n // @ts-expect-error\n this.name = `${this.constructor.type}-${this.config.fieldType}`;\n }\n\n public canUse(field: Pick<CmsModelField, \"fieldId\" | \"type\">, parents: string[]): boolean {\n if (field.type !== this.config.fieldType) {\n return false;\n } else if (this.config.canUse) {\n return this.config.canUse(field, parents);\n }\n const fieldId = this.config.fieldId;\n if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {\n return true;\n }\n return fieldId.includes(field.fieldId);\n }\n\n public createPath(params: CreatePathCallableParams): string {\n if (typeof this.config.path === \"function\") {\n return this.config.path(params);\n } else if (typeof this.config.path === \"string\") {\n return this.config.path;\n }\n throw new WebinyError(`Missing path in \"${this.name}\" plugin.`);\n }\n}\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,MAAM,QAAQ,2BAA2B;AAgBlD,OAAO,MAAMC,6BAA6B,SAASD,MAAM,CAAC;EACtD,OAAgCE,IAAI,GAAW,uBAAuB;EAItE,IAAWC,SAASA,CAAA,EAAW;IAC3B,OAAO,IAAI,CAACC,MAAM,CAACD,SAAS;EAChC;EAEOE,WAAWA,CAACD,MAA2C,EAAE;IAC5D,KAAK,CAAC,CAAC;IAEP,IAAI,CAACA,MAAM,GAAGA,MAAM;;IAEpB;AACR;AACA;IACQ;IACA,IAAI,CAACE,IAAI,GAAG,GAAG,IAAI,CAAC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