@webiny/api-headless-cms-ddb-es 6.3.0-beta.4 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configurations.js +27 -35
- package/configurations.js.map +1 -1
- 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/types.d.ts +1 -0
- package/definitions/types.js +0 -3
- package/elasticsearch/createElasticsearchIndex.js +50 -67
- package/elasticsearch/createElasticsearchIndex.js.map +1 -1
- package/elasticsearch/deleteElasticsearchIndex.js +18 -26
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
- package/exports/api/cms/opensearch.js +2 -4
- package/feature.js +144 -153
- package/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchBodyModifier/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchBodyModifier/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchBodyModifier/index.js +0 -2
- package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js +28 -27
- package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js +2 -1
- package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js +2 -1
- package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/constants.js +2 -1
- package/features/CmsEntryOpenSearchFieldIndex/constants.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/feature.js +13 -12
- package/features/CmsEntryOpenSearchFieldIndex/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js +48 -65
- package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js +20 -30
- package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js +15 -16
- package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js +15 -18
- package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js +24 -29
- package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js +99 -144
- package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js +15 -16
- package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/index.js +0 -2
- package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js +26 -28
- package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js +2 -1
- package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js +2 -1
- package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/constants.js +2 -1
- package/features/CmsEntryOpenSearchFilter/constants.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/feature.js +9 -8
- package/features/CmsEntryOpenSearchFilter/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js +18 -15
- package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js +35 -53
- package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js +27 -40
- package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/index.js +0 -2
- package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchFullTextSearch/index.js +0 -2
- package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js +10 -9
- package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchIndex/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchIndex/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchIndex/feature.js +6 -5
- package/features/CmsEntryOpenSearchIndex/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchIndex/index.js +0 -2
- package/features/CmsEntryOpenSearchQueryModifier/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchQueryModifier/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchQueryModifier/index.js +0 -2
- package/features/CmsEntryOpenSearchSortModifier/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchSortModifier/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchSortModifier/index.js +0 -2
- package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js +24 -20
- package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js +2 -1
- package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js +2 -1
- package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/feature.js +9 -8
- package/features/CmsEntryOpenSearchValueSearch/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js +14 -16
- package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js +31 -42
- package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js +15 -17
- package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/index.js +0 -2
- package/features/CmsEntryOpenSearchValuesModifier/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchValuesModifier/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchValuesModifier/index.js +0 -2
- package/helpers/entryIndexHelpers.js +71 -123
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/fieldIdentifier.js +18 -30
- package/helpers/fieldIdentifier.js.map +1 -1
- package/helpers/index.js +0 -2
- package/index.js +0 -2
- 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 +27 -37
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +27 -37
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.js +32 -46
- 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/elasticsearch/assignMinimumShouldMatchToQuery.js +6 -24
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
- package/operations/entry/elasticsearch/body.js +74 -125
- package/operations/entry/elasticsearch/body.js.map +1 -1
- package/operations/entry/elasticsearch/fields/createSystemField.js +6 -7
- package/operations/entry/elasticsearch/fields/createSystemField.js.map +1 -1
- package/operations/entry/elasticsearch/fields/live.js +45 -40
- package/operations/entry/elasticsearch/fields/live.js.map +1 -1
- package/operations/entry/elasticsearch/fields/location.js +45 -40
- package/operations/entry/elasticsearch/fields/location.js.map +1 -1
- package/operations/entry/elasticsearch/fields/state.js +99 -88
- package/operations/entry/elasticsearch/fields/state.js.map +1 -1
- package/operations/entry/elasticsearch/fields.js +193 -217
- package/operations/entry/elasticsearch/fields.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +32 -45
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/exec.js +85 -114
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/index.js +0 -2
- package/operations/entry/elasticsearch/filtering/path.js +24 -33
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/populated.js +8 -14
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/values.js +11 -12
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearch.js +43 -80
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearchFields.js +7 -17
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
- package/operations/entry/elasticsearch/initialQuery.js +37 -80
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
- package/operations/entry/elasticsearch/keyword.js +13 -27
- package/operations/entry/elasticsearch/keyword.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/operator.js +9 -20
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +6 -4
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -1
- package/operations/entry/elasticsearch/sort.js +69 -92
- package/operations/entry/elasticsearch/sort.js.map +1 -1
- package/operations/entry/elasticsearch/transformValueForSearch.js +9 -14
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
- package/operations/entry/elasticsearch/types.js +0 -3
- package/operations/entry/index.js +1322 -1709
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +43 -63
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/recordType.js +4 -9
- package/operations/entry/recordType.js.map +1 -1
- package/operations/entry/transformations/convertEntryKeys.js +21 -26
- package/operations/entry/transformations/convertEntryKeys.js.map +1 -1
- package/operations/entry/transformations/index.js +85 -114
- package/operations/entry/transformations/index.js.map +1 -1
- package/operations/entry/transformations/modifyEntryValues.d.ts +1 -1
- package/operations/entry/transformations/modifyEntryValues.js +12 -17
- package/operations/entry/transformations/modifyEntryValues.js.map +1 -1
- package/operations/entry/transformations/transformEntryKeys.js +13 -16
- package/operations/entry/transformations/transformEntryKeys.js.map +1 -1
- package/operations/entry/transformations/transformEntryToIndex.js +17 -22
- package/operations/entry/transformations/transformEntryToIndex.js.map +1 -1
- package/operations/group/index.js +113 -134
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +128 -156
- package/operations/model/index.js.map +1 -1
- package/package.json +23 -23
- package/tasks/createIndexTaskPlugin.js +35 -38
- package/tasks/createIndexTaskPlugin.js.map +1 -1
- package/types.js +7 -13
- package/types.js.map +1 -1
- package/values/NoValueContainer.js +8 -10
- package/values/NoValueContainer.js.map +1 -1
- package/definitions/types.js.map +0 -1
- package/exports/api/cms/opensearch.js.map +0 -1
- package/features/CmsEntryOpenSearchBodyModifier/index.js.map +0 -1
- package/features/CmsEntryOpenSearchFieldIndex/index.js.map +0 -1
- package/features/CmsEntryOpenSearchFilter/index.js.map +0 -1
- package/features/CmsEntryOpenSearchFullTextSearch/index.js.map +0 -1
- package/features/CmsEntryOpenSearchIndex/index.js.map +0 -1
- package/features/CmsEntryOpenSearchQueryModifier/index.js.map +0 -1
- package/features/CmsEntryOpenSearchSortModifier/index.js.map +0 -1
- package/features/CmsEntryOpenSearchValueSearch/index.js.map +0 -1
- package/features/CmsEntryOpenSearchValuesModifier/index.js.map +0 -1
- package/helpers/index.js.map +0 -1
- package/index.js.map +0 -1
- package/operations/entry/dataLoader/types.js.map +0 -1
- package/operations/entry/elasticsearch/filtering/index.js.map +0 -1
- package/operations/entry/elasticsearch/types.js.map +0 -1
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import { prepareEntryToIndex } from "../../../helpers/index.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
delete result["SK"];
|
|
19
|
-
delete result["GSI1_PK"];
|
|
20
|
-
delete result["GSI1_SK"];
|
|
21
|
-
delete result["published"];
|
|
22
|
-
delete result["latest"];
|
|
23
|
-
return result;
|
|
2
|
+
const transformEntryToIndex = (params)=>{
|
|
3
|
+
const { model, entry, storageEntry, fieldRegistry, fieldIndexRegistry } = params;
|
|
4
|
+
const result = prepareEntryToIndex({
|
|
5
|
+
model,
|
|
6
|
+
entry: structuredClone(entry),
|
|
7
|
+
storageEntry: structuredClone(storageEntry),
|
|
8
|
+
fieldRegistry,
|
|
9
|
+
fieldIndexRegistry
|
|
10
|
+
});
|
|
11
|
+
delete result["PK"];
|
|
12
|
+
delete result["SK"];
|
|
13
|
+
delete result["GSI1_PK"];
|
|
14
|
+
delete result["GSI1_SK"];
|
|
15
|
+
delete result["published"];
|
|
16
|
+
delete result["latest"];
|
|
17
|
+
return result;
|
|
24
18
|
};
|
|
19
|
+
export { transformEntryToIndex };
|
|
25
20
|
|
|
26
21
|
//# sourceMappingURL=transformEntryToIndex.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/transformations/transformEntryToIndex.js","sources":["../../../../src/operations/entry/transformations/transformEntryToIndex.ts"],"sourcesContent":["import type {\n CmsEntry,\n CmsEntryValues,\n CmsStorageEntry,\n StorageOperationsCmsModel\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { prepareEntryToIndex } from \"~/helpers/index.js\";\nimport type { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/features/graphql/index.js\";\nimport type { CmsEntryOpenSearchFieldIndexRegistry } from \"~/features/CmsEntryOpenSearchFieldIndex/index.js\";\n\ninterface TransformEntryToIndexParams<T extends CmsEntryValues = CmsEntryValues> {\n model: StorageOperationsCmsModel<T>;\n entry: CmsEntry<T>;\n storageEntry: CmsStorageEntry<T>;\n fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;\n fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface;\n}\n\nexport const transformEntryToIndex = <T extends CmsEntryValues = CmsEntryValues>(\n params: TransformEntryToIndexParams<T>\n) => {\n const { model, entry, storageEntry, fieldRegistry, fieldIndexRegistry } = params;\n const result = prepareEntryToIndex<T>({\n model,\n entry: structuredClone(entry),\n storageEntry: structuredClone(storageEntry),\n fieldRegistry,\n fieldIndexRegistry\n });\n\n delete result[\"PK\"];\n delete result[\"SK\"];\n delete result[\"GSI1_PK\"];\n delete result[\"GSI1_SK\"];\n delete result[\"published\"];\n delete result[\"latest\"];\n\n return result;\n};\n"],"names":["transformEntryToIndex","params","model","entry","storageEntry","fieldRegistry","fieldIndexRegistry","result","prepareEntryToIndex","structuredClone"],"mappings":";AAkBO,MAAMA,wBAAwB,CACjCC;IAEA,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEC,YAAY,EAAEC,aAAa,EAAEC,kBAAkB,EAAE,GAAGL;IAC1E,MAAMM,SAASC,oBAAuB;QAClCN;QACA,OAAOO,gBAAgBN;QACvB,cAAcM,gBAAgBL;QAC9BC;QACAC;IACJ;IAEA,OAAOC,MAAM,CAAC,KAAK;IACnB,OAAOA,MAAM,CAAC,KAAK;IACnB,OAAOA,MAAM,CAAC,UAAU;IACxB,OAAOA,MAAM,CAAC,UAAU;IACxB,OAAOA,MAAM,CAAC,YAAY;IAC1B,OAAOA,MAAM,CAAC,SAAS;IAEvB,OAAOA;AACX"}
|
|
@@ -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/exports/api/db.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 ? 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 ? 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 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 { IGroupEntity } from \"~/definitions/types.js\";\nimport { FilterUtil } from \"@webiny/db-dynamodb/exports/api/db.js\";\nimport type { CmsContext } from \"~/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 IDynamoDbTableKeys {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n}\nconst createKeys = (params: PartitionKeyParams & SortKeyParams): IDynamoDbTableKeys => {\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\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 ? 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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"}
|
|
@@ -1,163 +1,135 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _webiny_error from "@webiny/error";
|
|
2
2
|
import { configurations } from "../../configurations.js";
|
|
3
|
-
const createPartitionKey = params
|
|
4
|
-
|
|
5
|
-
tenant
|
|
6
|
-
} = params;
|
|
7
|
-
return `T#${tenant}#CMS#CM`;
|
|
3
|
+
const createPartitionKey = (params)=>{
|
|
4
|
+
const { tenant } = params;
|
|
5
|
+
return `T#${tenant}#CMS#CM`;
|
|
8
6
|
};
|
|
9
|
-
const createSortKey = params
|
|
10
|
-
|
|
7
|
+
const createSortKey = (params)=>params.modelId;
|
|
8
|
+
const createKeys = (params)=>{
|
|
9
|
+
if (!params.tenant) throw new Error("Missing tenant when creating model keys!");
|
|
10
|
+
return {
|
|
11
|
+
PK: createPartitionKey(params),
|
|
12
|
+
SK: createSortKey(params),
|
|
13
|
+
GSI_TENANT: params.tenant
|
|
14
|
+
};
|
|
11
15
|
};
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
const get = async params => {
|
|
123
|
-
const keys = createKeys(params);
|
|
124
|
-
try {
|
|
125
|
-
const result = await entity.get(keys);
|
|
126
|
-
return result ? result.data : null;
|
|
127
|
-
} catch (ex) {
|
|
128
|
-
throw new WebinyError(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
|
|
129
|
-
error: ex,
|
|
130
|
-
keys
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const list = async params => {
|
|
135
|
-
const {
|
|
136
|
-
where
|
|
137
|
-
} = params;
|
|
138
|
-
const partitionKey = createPartitionKey(where);
|
|
139
|
-
try {
|
|
140
|
-
const result = await entity.queryAll({
|
|
141
|
-
partitionKey,
|
|
142
|
-
options: {
|
|
143
|
-
gte: " "
|
|
16
|
+
const createType = ()=>"cms.model";
|
|
17
|
+
const createModelsStorageOperations = (params)=>{
|
|
18
|
+
const { entity, elasticsearch } = params;
|
|
19
|
+
const create = async (params)=>{
|
|
20
|
+
const { model } = params;
|
|
21
|
+
const { index } = configurations.es({
|
|
22
|
+
model
|
|
23
|
+
});
|
|
24
|
+
const keys = createKeys(model);
|
|
25
|
+
let error;
|
|
26
|
+
try {
|
|
27
|
+
await entity.put({
|
|
28
|
+
data: model,
|
|
29
|
+
...keys,
|
|
30
|
+
TYPE: createType()
|
|
31
|
+
});
|
|
32
|
+
return model;
|
|
33
|
+
} catch (ex) {
|
|
34
|
+
error = ex;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await elasticsearch.indices.delete({
|
|
38
|
+
index,
|
|
39
|
+
ignore_unavailable: true
|
|
40
|
+
});
|
|
41
|
+
} catch (ex) {
|
|
42
|
+
throw new _webiny_error(`Could not delete elasticsearch index "${index}" after model record failed to be created.`, "DELETE_MODEL_INDEX_ERROR", {
|
|
43
|
+
dynamodbError: error,
|
|
44
|
+
elasticsearchError: ex
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
};
|
|
49
|
+
const update = async (params)=>{
|
|
50
|
+
const { model } = params;
|
|
51
|
+
const keys = createKeys(model);
|
|
52
|
+
try {
|
|
53
|
+
await entity.put({
|
|
54
|
+
data: model,
|
|
55
|
+
...keys,
|
|
56
|
+
TYPE: createType()
|
|
57
|
+
});
|
|
58
|
+
return model;
|
|
59
|
+
} catch (ex) {
|
|
60
|
+
throw new _webiny_error(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
|
|
61
|
+
error: ex,
|
|
62
|
+
model,
|
|
63
|
+
keys
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const deleteModel = async (params)=>{
|
|
68
|
+
const { model } = params;
|
|
69
|
+
const keys = createKeys(model);
|
|
70
|
+
const { index } = configurations.es({
|
|
71
|
+
model
|
|
72
|
+
});
|
|
73
|
+
try {
|
|
74
|
+
await entity.delete(keys);
|
|
75
|
+
} catch (ex) {
|
|
76
|
+
throw new _webiny_error(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
|
|
77
|
+
error: ex,
|
|
78
|
+
model,
|
|
79
|
+
keys
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
await elasticsearch.indices.delete({
|
|
84
|
+
index,
|
|
85
|
+
ignore_unavailable: true
|
|
86
|
+
});
|
|
87
|
+
} catch (ex) {
|
|
88
|
+
throw new _webiny_error(`Could not delete elasticsearch index "${index}" after model record delete.`, "DELETE_MODEL_INDEX_ERROR", {
|
|
89
|
+
error: ex,
|
|
90
|
+
index,
|
|
91
|
+
model
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const get = async (params)=>{
|
|
96
|
+
const keys = createKeys(params);
|
|
97
|
+
try {
|
|
98
|
+
const result = await entity.get(keys);
|
|
99
|
+
return result ? result.data : null;
|
|
100
|
+
} catch (ex) {
|
|
101
|
+
throw new _webiny_error(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
|
|
102
|
+
error: ex,
|
|
103
|
+
keys
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const list = async (params)=>{
|
|
108
|
+
const { where } = params;
|
|
109
|
+
const partitionKey = createPartitionKey(where);
|
|
110
|
+
try {
|
|
111
|
+
const result = await entity.queryAll({
|
|
112
|
+
partitionKey,
|
|
113
|
+
options: {
|
|
114
|
+
gte: " "
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return result ? result.map((item)=>item.data) : [];
|
|
118
|
+
} catch (ex) {
|
|
119
|
+
throw new _webiny_error(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
|
|
120
|
+
error: ex,
|
|
121
|
+
partitionKey
|
|
122
|
+
});
|
|
144
123
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
return {
|
|
155
|
-
create,
|
|
156
|
-
update,
|
|
157
|
-
delete: deleteModel,
|
|
158
|
-
get,
|
|
159
|
-
list
|
|
160
|
-
};
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
create,
|
|
127
|
+
update,
|
|
128
|
+
delete: deleteModel,
|
|
129
|
+
get,
|
|
130
|
+
list
|
|
131
|
+
};
|
|
161
132
|
};
|
|
133
|
+
export { createModelsStorageOperations };
|
|
162
134
|
|
|
163
135
|
//# sourceMappingURL=index.js.map
|