@webiny/api-headless-cms-ddb-es 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7f63ea0744
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 +0 -8
- package/configurations.js.map +1 -1
- package/definitions/entry.js +0 -5
- package/definitions/entry.js.map +1 -1
- package/definitions/entryElasticsearch.js +0 -5
- package/definitions/entryElasticsearch.js.map +1 -1
- package/definitions/group.js +0 -5
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +5 -5
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +0 -5
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +0 -5
- package/definitions/system.js.map +1 -1
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -1
- package/definitions/tableElasticsearch.js +0 -3
- package/definitions/tableElasticsearch.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +0 -5
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/storage/date.d.ts +2 -1
- package/dynamoDb/storage/date.js +1 -16
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/longText.js +7 -17
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/dynamoDb/storage/richText.js +0 -22
- package/dynamoDb/storage/richText.js.map +1 -1
- package/elasticsearch/createElasticsearchIndex.js +0 -11
- package/elasticsearch/createElasticsearchIndex.js.map +1 -1
- package/elasticsearch/deleteElasticsearchIndex.js +0 -7
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
- package/elasticsearch/index.js +0 -5
- package/elasticsearch/index.js.map +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.js +4 -21
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
- package/elasticsearch/indexing/defaultFieldIndexing.js +5 -9
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
- package/elasticsearch/indexing/index.js +0 -9
- package/elasticsearch/indexing/index.js.map +1 -1
- package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
- package/elasticsearch/indexing/longTextIndexing.js +19 -9
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
- package/elasticsearch/indexing/numberIndexing.js +0 -9
- package/elasticsearch/indexing/numberIndexing.js.map +1 -1
- package/elasticsearch/indexing/objectIndexing.js +3 -30
- package/elasticsearch/indexing/objectIndexing.js.map +1 -1
- package/elasticsearch/indexing/richTextIndexing.js +0 -5
- package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
- package/elasticsearch/indices/base.js +0 -3
- package/elasticsearch/indices/base.js.map +1 -1
- package/elasticsearch/indices/index.js +0 -4
- package/elasticsearch/indices/index.js.map +1 -1
- package/elasticsearch/indices/japanese.js +0 -3
- package/elasticsearch/indices/japanese.js.map +1 -1
- package/elasticsearch/search/index.js +0 -4
- package/elasticsearch/search/index.js.map +1 -1
- package/elasticsearch/search/refSearch.js +4 -8
- package/elasticsearch/search/refSearch.js.map +1 -1
- package/elasticsearch/search/timeSearch.js +0 -7
- package/elasticsearch/search/timeSearch.js.map +1 -1
- package/helpers/entryIndexHelpers.js +20 -49
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/index.d.ts +0 -1
- package/helpers/index.js +0 -15
- package/helpers/index.js.map +1 -1
- package/index.js +10 -45
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +0 -52
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +32 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
- package/operations/entry/elasticsearch/body.d.ts +13 -0
- package/operations/entry/elasticsearch/body.js +140 -0
- package/operations/entry/elasticsearch/body.js.map +1 -0
- package/operations/entry/elasticsearch/fields.d.ts +9 -0
- package/operations/entry/elasticsearch/fields.js +229 -0
- package/operations/entry/elasticsearch/fields.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +57 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
- package/operations/entry/elasticsearch/filtering/exec.js +172 -0
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
- package/operations/entry/elasticsearch/filtering/index.js +16 -0
- package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
- package/operations/entry/elasticsearch/filtering/path.js +44 -0
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +28 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.js +13 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +65 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +48 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/populated.js +23 -0
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/values.js +22 -0
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearch.d.ts +12 -0
- package/operations/entry/elasticsearch/fullTextSearch.js +89 -0
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.js +25 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
- package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
- package/operations/entry/elasticsearch/initialQuery.js +103 -0
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
- package/operations/entry/elasticsearch/keyword.d.ts +2 -0
- package/operations/entry/elasticsearch/keyword.js +34 -0
- package/operations/entry/elasticsearch/keyword.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js +16 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
- package/operations/entry/elasticsearch/plugins/operator.js +37 -0
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.js +16 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
- package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +7 -9
- package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js +16 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
- package/operations/entry/elasticsearch/sort.d.ts +12 -0
- package/operations/entry/elasticsearch/sort.js +82 -0
- package/operations/entry/elasticsearch/sort.js.map +1 -0
- package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
- package/{helpers → operations/entry/elasticsearch}/transformValueForSearch.js +7 -6
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
- package/operations/entry/elasticsearch/types.d.ts +41 -0
- package/operations/entry/elasticsearch/types.js +5 -0
- package/operations/entry/elasticsearch/types.js.map +1 -0
- package/operations/entry/index.d.ts +0 -2
- package/operations/entry/index.js +72 -210
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +0 -9
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/recordType.d.ts +3 -0
- package/operations/entry/recordType.js +18 -0
- package/operations/entry/recordType.js.map +1 -0
- package/operations/group/index.js +2 -32
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +0 -33
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +0 -24
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +0 -17
- package/operations/system/index.js.map +1 -1
- package/package.json +16 -16
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +1 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +6 -8
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -6
- package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +28 -0
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +0 -5
- package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +0 -10
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +1 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +6 -8
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +1 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +6 -8
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
- package/plugins/CmsEntryFilterPlugin.js +24 -0
- package/plugins/CmsEntryFilterPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +11 -12
- package/plugins/index.js.map +1 -1
- package/types.js +0 -5
- package/types.js.map +1 -1
- package/helpers/createElasticsearchQueryBody.d.ts +0 -11
- package/helpers/createElasticsearchQueryBody.js +0 -611
- package/helpers/createElasticsearchQueryBody.js.map +0 -1
- package/helpers/fields.d.ts +0 -19
- package/helpers/fields.js +0 -205
- package/helpers/fields.js.map +0 -1
- package/helpers/searchPluginsList.d.ts +0 -6
- package/helpers/searchPluginsList.js.map +0 -1
- package/helpers/transformValueForSearch.d.ts +0 -12
- package/helpers/transformValueForSearch.js.map +0 -1
- package/operations/entry/elasticsearchFields.d.ts +0 -2
- package/operations/entry/elasticsearchFields.js +0 -38
- package/operations/entry/elasticsearchFields.js.map +0 -1
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createLongTextStorageTransformPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
|
|
12
9
|
var _gzip = require("@webiny/utils/compression/gzip");
|
|
13
|
-
|
|
14
10
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
15
|
-
|
|
16
11
|
/**
|
|
17
12
|
* File is @internal
|
|
18
13
|
*/
|
|
14
|
+
|
|
19
15
|
const GZIP = "gzip";
|
|
20
16
|
const TO_STORAGE_ENCODING = "base64";
|
|
21
17
|
const FROM_STORAGE_ENCODING = "utf8";
|
|
22
|
-
|
|
23
18
|
const convertToBuffer = value => {
|
|
24
19
|
if (typeof value === "string") {
|
|
25
20
|
return Buffer.from(value, TO_STORAGE_ENCODING);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
return value;
|
|
29
23
|
};
|
|
30
|
-
|
|
31
24
|
const createLongTextStorageTransformPlugin = () => {
|
|
32
25
|
return new _apiHeadlessCms.StorageTransformPlugin({
|
|
33
26
|
fieldType: "long-text",
|
|
@@ -36,13 +29,11 @@ const createLongTextStorageTransformPlugin = () => {
|
|
|
36
29
|
value: storageValue
|
|
37
30
|
}) => {
|
|
38
31
|
const typeOf = typeof storageValue;
|
|
39
|
-
|
|
40
32
|
if (!storageValue || typeOf === "string" || typeOf === "number" || Array.isArray(storageValue) === true) {
|
|
41
33
|
return storageValue;
|
|
42
34
|
} else if (typeOf !== "object") {
|
|
43
35
|
throw new _error.default(`LongText value received in "fromStorage" function is not an object in field "${field.storageId}" - ${field.fieldId}.`);
|
|
44
36
|
}
|
|
45
|
-
|
|
46
37
|
const {
|
|
47
38
|
compression,
|
|
48
39
|
value,
|
|
@@ -51,7 +42,6 @@ const createLongTextStorageTransformPlugin = () => {
|
|
|
51
42
|
/**
|
|
52
43
|
* Check if possibly undefined, null, empty...
|
|
53
44
|
*/
|
|
54
|
-
|
|
55
45
|
if (!compression) {
|
|
56
46
|
throw new _error.default(`Missing compression in "fromStorage" function in field "${field.storageId}" - ${field.fieldId}.": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
|
|
57
47
|
value: storageValue
|
|
@@ -61,15 +51,12 @@ const createLongTextStorageTransformPlugin = () => {
|
|
|
61
51
|
compression
|
|
62
52
|
});
|
|
63
53
|
}
|
|
64
|
-
|
|
65
54
|
try {
|
|
66
55
|
const buf = await (0, _gzip.decompress)(convertToBuffer(value));
|
|
67
56
|
const result = buf.toString(FROM_STORAGE_ENCODING);
|
|
68
|
-
|
|
69
57
|
if (!isArray) {
|
|
70
58
|
return result;
|
|
71
59
|
}
|
|
72
|
-
|
|
73
60
|
return JSON.parse(result);
|
|
74
61
|
} catch (ex) {
|
|
75
62
|
console.log("Error while transforming long-text.");
|
|
@@ -80,6 +67,12 @@ const createLongTextStorageTransformPlugin = () => {
|
|
|
80
67
|
toStorage: async ({
|
|
81
68
|
value: initialValue
|
|
82
69
|
}) => {
|
|
70
|
+
/**
|
|
71
|
+
* There is a possibility that we are trying to compress already compressed value.
|
|
72
|
+
*/
|
|
73
|
+
if (initialValue && initialValue.hasOwnProperty("compression") === true) {
|
|
74
|
+
return initialValue;
|
|
75
|
+
}
|
|
83
76
|
const isArray = Array.isArray(initialValue);
|
|
84
77
|
const value = isArray ? JSON.stringify(initialValue) : initialValue;
|
|
85
78
|
const compressedValue = await (0, _gzip.compress)(value);
|
|
@@ -87,15 +80,12 @@ const createLongTextStorageTransformPlugin = () => {
|
|
|
87
80
|
compression: GZIP,
|
|
88
81
|
value: compressedValue.toString(TO_STORAGE_ENCODING)
|
|
89
82
|
};
|
|
90
|
-
|
|
91
83
|
if (!isArray) {
|
|
92
84
|
return result;
|
|
93
85
|
}
|
|
94
|
-
|
|
95
86
|
result.isArray = isArray;
|
|
96
87
|
return result;
|
|
97
88
|
}
|
|
98
89
|
});
|
|
99
90
|
};
|
|
100
|
-
|
|
101
91
|
exports.createLongTextStorageTransformPlugin = createLongTextStorageTransformPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","createLongTextStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","typeOf","Array","isArray","WebinyError","storageId","fieldId","compression","JSON","stringify","buf","ungzip","result","toString","parse","ex","console","log","message","toStorage","initialValue","compressedValue","gzip"],"sources":["longText.ts"],"sourcesContent":["/**\n * File is @internal\n */\n\nimport WebinyError from \"@webiny/error\";\nimport { compress as gzip, decompress as ungzip } from \"@webiny/utils/compression/gzip\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nconst GZIP = \"gzip\";\nconst TO_STORAGE_ENCODING = \"base64\";\nconst FROM_STORAGE_ENCODING = \"utf8\";\n\nconst convertToBuffer = (value: string | Buffer): Buffer => {\n if (typeof value === \"string\") {\n return Buffer.from(value, TO_STORAGE_ENCODING);\n }\n return value;\n};\n\nexport interface StorageValue {\n compression: string;\n value: string;\n isArray?: boolean;\n}\n\nexport const createLongTextStorageTransformPlugin = () => {\n return new StorageTransformPlugin<string | string[], StorageValue>({\n fieldType: \"long-text\",\n fromStorage: async ({ field, value: storageValue }) => {\n const typeOf = typeof storageValue;\n if (\n !storageValue ||\n typeOf === \"string\" ||\n typeOf === \"number\" ||\n Array.isArray(storageValue) === true\n ) {\n return storageValue as unknown as string | string[];\n } else if (typeOf !== \"object\") {\n throw new WebinyError(\n `LongText value received in \"fromStorage\" function is not an object in field \"${field.storageId}\" - ${field.fieldId}.`\n );\n }\n const { compression, value, isArray } = storageValue;\n /**\n * Check if possibly undefined, null, empty...\n */\n if (!compression) {\n throw new WebinyError(\n `Missing compression in \"fromStorage\" function in field \"${\n field.storageId\n }\" - ${field.fieldId}.\": ${JSON.stringify(storageValue)}.`,\n \"MISSING_COMPRESSION\",\n {\n value: storageValue\n }\n );\n } else if (compression !== GZIP) {\n throw new WebinyError(\n `This plugin cannot transform something not compressed with \"GZIP\".`,\n \"WRONG_COMPRESSION\",\n {\n compression\n }\n );\n }\n try {\n const buf = await ungzip(convertToBuffer(value));\n const result = buf.toString(FROM_STORAGE_ENCODING);\n if (!isArray) {\n return result;\n }\n return JSON.parse(result);\n } catch (ex) {\n console.log(\"Error while transforming long-text.\");\n console.log(ex.message);\n return \"\";\n }\n },\n toStorage: async ({ value: initialValue }) => {\n const isArray = Array.isArray(initialValue);\n const value = isArray ? JSON.stringify(initialValue) : initialValue;\n const compressedValue = await gzip(value);\n\n const result: StorageValue = {\n compression: GZIP,\n value: compressedValue.toString(TO_STORAGE_ENCODING)\n };\n if (!isArray) {\n return result;\n }\n result.isArray = isArray;\n return result;\n }\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","createLongTextStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","typeOf","Array","isArray","WebinyError","storageId","fieldId","compression","JSON","stringify","buf","ungzip","result","toString","parse","ex","console","log","message","toStorage","initialValue","hasOwnProperty","compressedValue","gzip"],"sources":["longText.ts"],"sourcesContent":["/**\n * File is @internal\n */\n\nimport WebinyError from \"@webiny/error\";\nimport { compress as gzip, decompress as ungzip } from \"@webiny/utils/compression/gzip\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nconst GZIP = \"gzip\";\nconst TO_STORAGE_ENCODING = \"base64\";\nconst FROM_STORAGE_ENCODING = \"utf8\";\n\nconst convertToBuffer = (value: string | Buffer): Buffer => {\n if (typeof value === \"string\") {\n return Buffer.from(value, TO_STORAGE_ENCODING);\n }\n return value;\n};\n\nexport interface StorageValue {\n compression: string;\n value: string;\n isArray?: boolean;\n}\n\nexport const createLongTextStorageTransformPlugin = () => {\n return new StorageTransformPlugin<string | string[], StorageValue>({\n fieldType: \"long-text\",\n fromStorage: async ({ field, value: storageValue }) => {\n const typeOf = typeof storageValue;\n if (\n !storageValue ||\n typeOf === \"string\" ||\n typeOf === \"number\" ||\n Array.isArray(storageValue) === true\n ) {\n return storageValue as unknown as string | string[];\n } else if (typeOf !== \"object\") {\n throw new WebinyError(\n `LongText value received in \"fromStorage\" function is not an object in field \"${field.storageId}\" - ${field.fieldId}.`\n );\n }\n const { compression, value, isArray } = storageValue;\n /**\n * Check if possibly undefined, null, empty...\n */\n if (!compression) {\n throw new WebinyError(\n `Missing compression in \"fromStorage\" function in field \"${\n field.storageId\n }\" - ${field.fieldId}.\": ${JSON.stringify(storageValue)}.`,\n \"MISSING_COMPRESSION\",\n {\n value: storageValue\n }\n );\n } else if (compression !== GZIP) {\n throw new WebinyError(\n `This plugin cannot transform something not compressed with \"GZIP\".`,\n \"WRONG_COMPRESSION\",\n {\n compression\n }\n );\n }\n try {\n const buf = await ungzip(convertToBuffer(value));\n const result = buf.toString(FROM_STORAGE_ENCODING);\n if (!isArray) {\n return result;\n }\n return JSON.parse(result);\n } catch (ex) {\n console.log(\"Error while transforming long-text.\");\n console.log(ex.message);\n return \"\";\n }\n },\n toStorage: async ({ value: initialValue }) => {\n /**\n * There is a possibility that we are trying to compress already compressed value.\n */\n if (initialValue && initialValue.hasOwnProperty(\"compression\") === true) {\n return initialValue as any;\n }\n const isArray = Array.isArray(initialValue);\n const value = isArray ? JSON.stringify(initialValue) : initialValue;\n const compressedValue = await gzip(value);\n\n const result: StorageValue = {\n compression: GZIP,\n value: compressedValue.toString(TO_STORAGE_ENCODING)\n };\n if (!isArray) {\n return result;\n }\n result.isArray = isArray;\n return result;\n }\n });\n};\n"],"mappings":"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"}
|
|
@@ -4,4 +4,4 @@ export interface StorageValue {
|
|
|
4
4
|
compression: string;
|
|
5
5
|
value: any;
|
|
6
6
|
}
|
|
7
|
-
export declare const createRichTextStorageTransformPlugin: () => StorageTransformPlugin<any, any>;
|
|
7
|
+
export declare const createRichTextStorageTransformPlugin: () => StorageTransformPlugin<any, any, import("@webiny/api-headless-cms/types").CmsModelField>;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createRichTextStorageTransformPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _jsonpack = _interopRequireDefault(require("jsonpack"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
15
|
-
|
|
16
11
|
/**
|
|
17
12
|
* Remove when jsonpack gets PR with a fix merged
|
|
18
13
|
* https://github.com/rgcl/jsonpack/pull/25/files
|
|
@@ -23,24 +18,19 @@ const transformArray = value => {
|
|
|
23
18
|
if (!value) {
|
|
24
19
|
return value;
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
let isArray = Array.isArray(value);
|
|
28
22
|
const shouldBeArray = value instanceof Array === false && isArray;
|
|
29
|
-
|
|
30
23
|
if (shouldBeArray) {
|
|
31
24
|
value = Array.from(value);
|
|
32
25
|
isArray = true;
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
if (typeof value === "object" || isArray) {
|
|
36
28
|
for (const k in value) {
|
|
37
29
|
value[k] = transformArray(value[k]);
|
|
38
30
|
}
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
return value;
|
|
42
33
|
};
|
|
43
|
-
|
|
44
34
|
const createRichTextStorageTransformPlugin = () => {
|
|
45
35
|
return new _apiHeadlessCms.StorageTransformPlugin({
|
|
46
36
|
fieldType: "rich-text",
|
|
@@ -57,36 +47,29 @@ const createRichTextStorageTransformPlugin = () => {
|
|
|
57
47
|
* This is to circumvent a bug introduced with 5.8.0 storage operations.
|
|
58
48
|
* Do not remove.
|
|
59
49
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
50
|
if (storageValue.hasOwnProperty("compression") === false) {
|
|
63
51
|
return storageValue;
|
|
64
52
|
}
|
|
65
|
-
|
|
66
53
|
const {
|
|
67
54
|
compression,
|
|
68
55
|
value
|
|
69
56
|
} = storageValue;
|
|
70
|
-
|
|
71
57
|
if (!compression) {
|
|
72
58
|
throw new _error.default(`Missing compression in "fromStorage" function in field "${field.storageId}": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
|
|
73
59
|
value: storageValue
|
|
74
60
|
});
|
|
75
61
|
}
|
|
76
|
-
|
|
77
62
|
if (compression !== "jsonpack") {
|
|
78
63
|
throw new _error.default(`This plugin cannot transform something not packed with "jsonpack".`, "WRONG_COMPRESSION", {
|
|
79
64
|
compression
|
|
80
65
|
});
|
|
81
66
|
}
|
|
82
|
-
|
|
83
67
|
try {
|
|
84
68
|
return _jsonpack.default.unpack(value);
|
|
85
69
|
} catch (ex) {
|
|
86
70
|
if (process.env.DEBUG !== "true") {
|
|
87
71
|
return null;
|
|
88
72
|
}
|
|
89
|
-
|
|
90
73
|
console.log("Error while decompressing rich-text.");
|
|
91
74
|
console.log(ex.message);
|
|
92
75
|
return null;
|
|
@@ -102,21 +85,17 @@ const createRichTextStorageTransformPlugin = () => {
|
|
|
102
85
|
if (value && value.hasOwnProperty("compression") === true) {
|
|
103
86
|
return value;
|
|
104
87
|
}
|
|
105
|
-
|
|
106
88
|
value = transformArray(value);
|
|
107
89
|
let jsonValue = null;
|
|
108
|
-
|
|
109
90
|
try {
|
|
110
91
|
jsonValue = _jsonpack.default.pack(value);
|
|
111
92
|
} catch (ex) {
|
|
112
93
|
if (process.env.DEBUG !== "true") {
|
|
113
94
|
return null;
|
|
114
95
|
}
|
|
115
|
-
|
|
116
96
|
console.log("Error while compressing rich-text.");
|
|
117
97
|
console.log(ex.message);
|
|
118
98
|
}
|
|
119
|
-
|
|
120
99
|
return {
|
|
121
100
|
compression: "jsonpack",
|
|
122
101
|
value: jsonValue
|
|
@@ -124,5 +103,4 @@ const createRichTextStorageTransformPlugin = () => {
|
|
|
124
103
|
}
|
|
125
104
|
});
|
|
126
105
|
};
|
|
127
|
-
|
|
128
106
|
exports.createRichTextStorageTransformPlugin = createRichTextStorageTransformPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["transformArray","value","isArray","Array","shouldBeArray","from","k","createRichTextStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","WebinyError","storageId","hasOwnProperty","compression","JSON","stringify","jsonpack","unpack","ex","process","env","DEBUG","console","log","message","toStorage","jsonValue","pack"],"sources":["richText.ts"],"sourcesContent":["import jsonpack from \"jsonpack\";\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nexport type OriginalValue = Record<string, any> | any[];\n\nexport interface StorageValue {\n compression: string;\n value: any;\n}\n\n/**\n * Remove when jsonpack gets PR with a fix merged\n * https://github.com/rgcl/jsonpack/pull/25/files\n * NOTE 2021-07-28: it seems PR is not going to be merged so keep this.\n */\n// TODO @ts-refactor figure better type\nconst transformArray = (value: any) => {\n if (!value) {\n return value;\n }\n let isArray = Array.isArray(value);\n const shouldBeArray = value instanceof Array === false && isArray;\n if (shouldBeArray) {\n value = Array.from(value as any);\n isArray = true;\n }\n if (typeof value === \"object\" || isArray) {\n for (const k in value) {\n value[k] = transformArray(value[k]);\n }\n }\n return value;\n};\n\nexport const createRichTextStorageTransformPlugin = () => {\n return new StorageTransformPlugin({\n fieldType: \"rich-text\",\n fromStorage: async ({ field, value: storageValue }) => {\n if (!storageValue) {\n return storageValue;\n } else if (typeof storageValue !== \"object\") {\n throw new WebinyError(\n `RichText value received in \"fromStorage\" function is not an object in field \"${field.storageId}\".`\n );\n }\n /**\n * This is to circumvent a bug introduced with 5.8.0 storage operations.\n * Do not remove.\n */\n if (storageValue.hasOwnProperty(\"compression\") === false) {\n return storageValue;\n }\n const { compression, value } = storageValue;\n if (!compression) {\n throw new WebinyError(\n `Missing compression in \"fromStorage\" function in field \"${\n field.storageId\n }\": ${JSON.stringify(storageValue)}.`,\n \"MISSING_COMPRESSION\",\n {\n value: storageValue\n }\n );\n }\n if (compression !== \"jsonpack\") {\n throw new WebinyError(\n `This plugin cannot transform something not packed with \"jsonpack\".`,\n \"WRONG_COMPRESSION\",\n {\n compression\n }\n );\n }\n try {\n return jsonpack.unpack(value);\n } catch (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while decompressing rich-text.\");\n console.log(ex.message);\n return null;\n }\n },\n toStorage: async ({ value }) => {\n /**\n * There is a possibility that we are trying to compress already compressed value.\n * Introduced a bug with 5.8.0 storage operations, so just return the value to correct it.\n */\n if (value && value.hasOwnProperty(\"compression\") === true) {\n return value as any;\n }\n value = transformArray(value);\n\n let jsonValue: string | null = null;\n try {\n jsonValue = jsonpack.pack(value);\n } catch (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while compressing rich-text.\");\n console.log(ex.message);\n }\n return {\n compression: \"jsonpack\",\n value: jsonValue\n };\n }\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["transformArray","value","isArray","Array","shouldBeArray","from","k","createRichTextStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","WebinyError","storageId","hasOwnProperty","compression","JSON","stringify","jsonpack","unpack","ex","process","env","DEBUG","console","log","message","toStorage","jsonValue","pack"],"sources":["richText.ts"],"sourcesContent":["import jsonpack from \"jsonpack\";\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nexport type OriginalValue = Record<string, any> | any[];\n\nexport interface StorageValue {\n compression: string;\n value: any;\n}\n\n/**\n * Remove when jsonpack gets PR with a fix merged\n * https://github.com/rgcl/jsonpack/pull/25/files\n * NOTE 2021-07-28: it seems PR is not going to be merged so keep this.\n */\n// TODO @ts-refactor figure better type\nconst transformArray = (value: any) => {\n if (!value) {\n return value;\n }\n let isArray = Array.isArray(value);\n const shouldBeArray = value instanceof Array === false && isArray;\n if (shouldBeArray) {\n value = Array.from(value as any);\n isArray = true;\n }\n if (typeof value === \"object\" || isArray) {\n for (const k in value) {\n value[k] = transformArray(value[k]);\n }\n }\n return value;\n};\n\nexport const createRichTextStorageTransformPlugin = () => {\n return new StorageTransformPlugin({\n fieldType: \"rich-text\",\n fromStorage: async ({ field, value: storageValue }) => {\n if (!storageValue) {\n return storageValue;\n } else if (typeof storageValue !== \"object\") {\n throw new WebinyError(\n `RichText value received in \"fromStorage\" function is not an object in field \"${field.storageId}\".`\n );\n }\n /**\n * This is to circumvent a bug introduced with 5.8.0 storage operations.\n * Do not remove.\n */\n if (storageValue.hasOwnProperty(\"compression\") === false) {\n return storageValue;\n }\n const { compression, value } = storageValue;\n if (!compression) {\n throw new WebinyError(\n `Missing compression in \"fromStorage\" function in field \"${\n field.storageId\n }\": ${JSON.stringify(storageValue)}.`,\n \"MISSING_COMPRESSION\",\n {\n value: storageValue\n }\n );\n }\n if (compression !== \"jsonpack\") {\n throw new WebinyError(\n `This plugin cannot transform something not packed with \"jsonpack\".`,\n \"WRONG_COMPRESSION\",\n {\n compression\n }\n );\n }\n try {\n return jsonpack.unpack(value);\n } catch (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while decompressing rich-text.\");\n console.log(ex.message);\n return null;\n }\n },\n toStorage: async ({ value }) => {\n /**\n * There is a possibility that we are trying to compress already compressed value.\n * Introduced a bug with 5.8.0 storage operations, so just return the value to correct it.\n */\n if (value && value.hasOwnProperty(\"compression\") === true) {\n return value as any;\n }\n value = transformArray(value);\n\n let jsonValue: string | null = null;\n try {\n jsonValue = jsonpack.pack(value);\n } catch (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while compressing rich-text.\");\n console.log(ex.message);\n }\n return {\n compression: \"jsonpack\",\n value: jsonValue\n };\n }\n });\n};\n"],"mappings":"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"}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createElasticsearchIndex = void 0;
|
|
9
|
-
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
|
|
12
9
|
var _CmsEntryElasticsearchIndexPlugin = require("../plugins/CmsEntryElasticsearchIndexPlugin");
|
|
13
|
-
|
|
14
10
|
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
15
|
-
|
|
16
11
|
var _configurations = require("../configurations");
|
|
17
|
-
|
|
18
12
|
const createElasticsearchIndex = async params => {
|
|
19
13
|
const {
|
|
20
14
|
elasticsearch,
|
|
@@ -26,22 +20,18 @@ const createElasticsearchIndex = async params => {
|
|
|
26
20
|
type: _CmsEntryElasticsearchIndexPlugin.CmsEntryElasticsearchIndexPlugin.type,
|
|
27
21
|
locale: model.locale
|
|
28
22
|
});
|
|
29
|
-
|
|
30
23
|
const {
|
|
31
24
|
index
|
|
32
25
|
} = _configurations.configurations.es({
|
|
33
26
|
model
|
|
34
27
|
});
|
|
35
|
-
|
|
36
28
|
try {
|
|
37
29
|
const response = await elasticsearch.indices.exists({
|
|
38
30
|
index
|
|
39
31
|
});
|
|
40
|
-
|
|
41
32
|
if (response.body) {
|
|
42
33
|
return;
|
|
43
34
|
}
|
|
44
|
-
|
|
45
35
|
await elasticsearch.indices.create({
|
|
46
36
|
index,
|
|
47
37
|
body: plugin.body
|
|
@@ -56,5 +46,4 @@ const createElasticsearchIndex = async params => {
|
|
|
56
46
|
});
|
|
57
47
|
}
|
|
58
48
|
};
|
|
59
|
-
|
|
60
49
|
exports.createElasticsearchIndex = createElasticsearchIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createElasticsearchIndex","params","elasticsearch","plugins","container","model","plugin","getLastAddedIndexPlugin","type","CmsEntryElasticsearchIndexPlugin","locale","index","configurations","es","response","indices","exists","body","create","ex","WebinyError","message","code","error","tenant"],"sources":["createElasticsearchIndex.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryElasticsearchIndexPlugin } from \"~/plugins/CmsEntryElasticsearchIndexPlugin\";\nimport { getLastAddedIndexPlugin } from \"@webiny/api-elasticsearch\";\nimport { configurations } from \"~/configurations\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\nexport interface CreateElasticsearchIndexParams {\n elasticsearch: Client;\n plugins: PluginsContainer;\n model: CmsModel;\n}\n\nexport const createElasticsearchIndex = async (params: CreateElasticsearchIndexParams) => {\n const { elasticsearch, plugins: container, model } = params;\n\n const plugin = getLastAddedIndexPlugin<CmsEntryElasticsearchIndexPlugin>({\n container,\n type: CmsEntryElasticsearchIndexPlugin.type,\n locale: model.locale\n });\n\n const { index } = configurations.es({\n model\n });\n\n try {\n const response = await elasticsearch.indices.exists({\n index\n });\n if (response.body) {\n return;\n }\n await elasticsearch.indices.create({\n index,\n body: plugin.body\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create Elasticsearch index for the Headless CMS model.\",\n ex.code || \"CMS_ELASTICSEARCH_INDEX_ERROR\",\n {\n error: ex,\n type: CmsEntryElasticsearchIndexPlugin.type,\n locale: model.locale,\n tenant: model.tenant,\n body: plugin.body\n }\n );\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["createElasticsearchIndex","params","elasticsearch","plugins","container","model","plugin","getLastAddedIndexPlugin","type","CmsEntryElasticsearchIndexPlugin","locale","index","configurations","es","response","indices","exists","body","create","ex","WebinyError","message","code","error","tenant"],"sources":["createElasticsearchIndex.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryElasticsearchIndexPlugin } from \"~/plugins/CmsEntryElasticsearchIndexPlugin\";\nimport { getLastAddedIndexPlugin } from \"@webiny/api-elasticsearch\";\nimport { configurations } from \"~/configurations\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\nexport interface CreateElasticsearchIndexParams {\n elasticsearch: Client;\n plugins: PluginsContainer;\n model: CmsModel;\n}\n\nexport const createElasticsearchIndex = async (params: CreateElasticsearchIndexParams) => {\n const { elasticsearch, plugins: container, model } = params;\n\n const plugin = getLastAddedIndexPlugin<CmsEntryElasticsearchIndexPlugin>({\n container,\n type: CmsEntryElasticsearchIndexPlugin.type,\n locale: model.locale\n });\n\n const { index } = configurations.es({\n model\n });\n\n try {\n const response = await elasticsearch.indices.exists({\n index\n });\n if (response.body) {\n return;\n }\n await elasticsearch.indices.create({\n index,\n body: plugin.body\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create Elasticsearch index for the Headless CMS model.\",\n ex.code || \"CMS_ELASTICSEARCH_INDEX_ERROR\",\n {\n error: ex,\n type: CmsEntryElasticsearchIndexPlugin.type,\n locale: model.locale,\n tenant: model.tenant,\n body: plugin.body\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA;AAGA;AACA;AACA;AASO,MAAMA,wBAAwB,GAAG,MAAOC,MAAsC,IAAK;EACtF,MAAM;IAAEC,aAAa;IAAEC,OAAO,EAAEC,SAAS;IAAEC;EAAM,CAAC,GAAGJ,MAAM;EAE3D,MAAMK,MAAM,GAAG,IAAAC,yCAAuB,EAAmC;IACrEH,SAAS;IACTI,IAAI,EAAEC,kEAAgC,CAACD,IAAI;IAC3CE,MAAM,EAAEL,KAAK,CAACK;EAClB,CAAC,CAAC;EAEF,MAAM;IAAEC;EAAM,CAAC,GAAGC,8BAAc,CAACC,EAAE,CAAC;IAChCR;EACJ,CAAC,CAAC;EAEF,IAAI;IACA,MAAMS,QAAQ,GAAG,MAAMZ,aAAa,CAACa,OAAO,CAACC,MAAM,CAAC;MAChDL;IACJ,CAAC,CAAC;IACF,IAAIG,QAAQ,CAACG,IAAI,EAAE;MACf;IACJ;IACA,MAAMf,aAAa,CAACa,OAAO,CAACG,MAAM,CAAC;MAC/BP,KAAK;MACLM,IAAI,EAAEX,MAAM,CAACW;IACjB,CAAC,CAAC;EACN,CAAC,CAAC,OAAOE,EAAE,EAAE;IACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,kEAAkE,EAChFF,EAAE,CAACG,IAAI,IAAI,+BAA+B,EAC1C;MACIC,KAAK,EAAEJ,EAAE;MACTX,IAAI,EAAEC,kEAAgC,CAACD,IAAI;MAC3CE,MAAM,EAAEL,KAAK,CAACK,MAAM;MACpBc,MAAM,EAAEnB,KAAK,CAACmB,MAAM;MACpBP,IAAI,EAAEX,MAAM,CAACW;IACjB,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
|
|
@@ -4,31 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deleteElasticsearchIndex = void 0;
|
|
7
|
-
|
|
8
7
|
var _configurations = require("../configurations");
|
|
9
|
-
|
|
10
8
|
const deleteElasticsearchIndex = async params => {
|
|
11
9
|
const {
|
|
12
10
|
elasticsearch,
|
|
13
11
|
model
|
|
14
12
|
} = params;
|
|
15
|
-
|
|
16
13
|
const {
|
|
17
14
|
index
|
|
18
15
|
} = _configurations.configurations.es({
|
|
19
16
|
model
|
|
20
17
|
});
|
|
21
|
-
|
|
22
18
|
const {
|
|
23
19
|
body: exists
|
|
24
20
|
} = await elasticsearch.indices.exists({
|
|
25
21
|
index
|
|
26
22
|
});
|
|
27
|
-
|
|
28
23
|
if (!exists) {
|
|
29
24
|
return;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
try {
|
|
33
27
|
await elasticsearch.indices.delete({
|
|
34
28
|
index,
|
|
@@ -39,5 +33,4 @@ const deleteElasticsearchIndex = async params => {
|
|
|
39
33
|
console.log(ex.message);
|
|
40
34
|
}
|
|
41
35
|
};
|
|
42
|
-
|
|
43
36
|
exports.deleteElasticsearchIndex = deleteElasticsearchIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["deleteElasticsearchIndex","params","elasticsearch","model","index","configurations","es","body","exists","indices","delete","ignore_unavailable","ex","console","log","message"],"sources":["deleteElasticsearchIndex.ts"],"sourcesContent":["import { Client } from \"@elastic/elasticsearch\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { configurations } from \"~/configurations\";\n\ninterface DeleteElasticsearchIndexParams {\n elasticsearch: Client;\n model: CmsModel;\n}\n\nexport const deleteElasticsearchIndex = async (\n params: DeleteElasticsearchIndexParams\n): Promise<void> => {\n const { elasticsearch, model } = params;\n\n const { index } = configurations.es({\n model\n });\n const { body: exists } = await elasticsearch.indices.exists({\n index\n });\n if (!exists) {\n return;\n }\n\n try {\n await elasticsearch.indices.delete({\n index,\n ignore_unavailable: true\n });\n } catch (ex) {\n console.log(`Could not delete Elasticsearch index \"${index}\". Please do it manually.`);\n console.log(ex.message);\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["deleteElasticsearchIndex","params","elasticsearch","model","index","configurations","es","body","exists","indices","delete","ignore_unavailable","ex","console","log","message"],"sources":["deleteElasticsearchIndex.ts"],"sourcesContent":["import { Client } from \"@elastic/elasticsearch\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { configurations } from \"~/configurations\";\n\ninterface DeleteElasticsearchIndexParams {\n elasticsearch: Client;\n model: CmsModel;\n}\n\nexport const deleteElasticsearchIndex = async (\n params: DeleteElasticsearchIndexParams\n): Promise<void> => {\n const { elasticsearch, model } = params;\n\n const { index } = configurations.es({\n model\n });\n const { body: exists } = await elasticsearch.indices.exists({\n index\n });\n if (!exists) {\n return;\n }\n\n try {\n await elasticsearch.indices.delete({\n index,\n ignore_unavailable: true\n });\n } catch (ex) {\n console.log(`Could not delete Elasticsearch index \"${index}\". Please do it manually.`);\n console.log(ex.message);\n }\n};\n"],"mappings":";;;;;;AAEA;AAOO,MAAMA,wBAAwB,GAAG,MACpCC,MAAsC,IACtB;EAChB,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAEvC,MAAM;IAAEG;EAAM,CAAC,GAAGC,8BAAc,CAACC,EAAE,CAAC;IAChCH;EACJ,CAAC,CAAC;EACF,MAAM;IAAEI,IAAI,EAAEC;EAAO,CAAC,GAAG,MAAMN,aAAa,CAACO,OAAO,CAACD,MAAM,CAAC;IACxDJ;EACJ,CAAC,CAAC;EACF,IAAI,CAACI,MAAM,EAAE;IACT;EACJ;EAEA,IAAI;IACA,MAAMN,aAAa,CAACO,OAAO,CAACC,MAAM,CAAC;MAC/BN,KAAK;MACLO,kBAAkB,EAAE;IACxB,CAAC,CAAC;EACN,CAAC,CAAC,OAAOC,EAAE,EAAE;IACTC,OAAO,CAACC,GAAG,CAAE,yCAAwCV,KAAM,2BAA0B,CAAC;IACtFS,OAAO,CAACC,GAAG,CAACF,EAAE,CAACG,OAAO,CAAC;EAC3B;AACJ,CAAC;AAAC"}
|
package/elasticsearch/index.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _indexing = _interopRequireDefault(require("./indexing"));
|
|
11
|
-
|
|
12
9
|
var _search = _interopRequireDefault(require("./search"));
|
|
13
|
-
|
|
14
10
|
var _default = () => [(0, _indexing.default)(), (0, _search.default)()];
|
|
15
|
-
|
|
16
11
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["elasticsearchIndexingPlugins","elasticsearchSearchPlugins"],"sources":["index.ts"],"sourcesContent":["import elasticsearchIndexingPlugins from \"./indexing\";\nimport elasticsearchSearchPlugins from \"./search\";\n\nexport default () => [elasticsearchIndexingPlugins(), elasticsearchSearchPlugins()];\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["elasticsearchIndexingPlugins","elasticsearchSearchPlugins"],"sources":["index.ts"],"sourcesContent":["import elasticsearchIndexingPlugins from \"./indexing\";\nimport elasticsearchSearchPlugins from \"./search\";\n\nexport default () => [elasticsearchIndexingPlugins(), elasticsearchSearchPlugins()];\n"],"mappings":";;;;;;;AAAA;AACA;AAAkD,eAEnC,MAAM,CAAC,IAAAA,iBAA4B,GAAE,EAAE,IAAAC,eAA0B,GAAE,CAAC;AAAA"}
|
|
@@ -4,37 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
const convertTimeToNumber = time => {
|
|
9
8
|
if (!time) {
|
|
10
9
|
return null;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
const [hours, minutes, seconds = 0] = time.split(":").map(Number);
|
|
14
12
|
return hours * 60 * 60 + minutes * 60 + seconds;
|
|
15
13
|
};
|
|
16
|
-
|
|
17
14
|
const convertNumberToTime = value => {
|
|
18
15
|
if (value === undefined || value === null) {
|
|
19
16
|
return null;
|
|
20
|
-
}
|
|
17
|
+
}
|
|
18
|
+
// TODO remove when v5 goes out
|
|
21
19
|
// this is a fix for pre beta.5
|
|
22
|
-
|
|
23
|
-
|
|
24
20
|
if (String(value).match(/^([0-9]{2}):([0-9]{2})/) !== null) {
|
|
25
21
|
return String(value);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
}
|
|
23
|
+
//
|
|
29
24
|
const hours = Math.floor(value / 60 / 60);
|
|
30
25
|
const minutes = Math.floor((value - hours * 60 * 60) / 60);
|
|
31
26
|
const seconds = Math.floor(value - hours * 60 * 60 - minutes * 60);
|
|
32
27
|
return [hours, minutes, seconds].map(v => String(v).padStart(2, "0")).join(":");
|
|
33
28
|
};
|
|
34
|
-
|
|
35
29
|
const convertValueFromIndex = (value, field) => {
|
|
36
30
|
const type = field.settings.type;
|
|
37
|
-
|
|
38
31
|
if (type === "time") {
|
|
39
32
|
return convertNumberToTime(value);
|
|
40
33
|
} else if (!value) {
|
|
@@ -45,20 +38,16 @@ const convertValueFromIndex = (value, field) => {
|
|
|
45
38
|
const dateValue = new Date(value);
|
|
46
39
|
return dateValue.toISOString().slice(0, 10);
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
return new Date(value).toISOString();
|
|
50
42
|
};
|
|
51
|
-
|
|
52
43
|
const convertValueToIndex = (value, field) => {
|
|
53
44
|
if (!value) {
|
|
54
45
|
return null;
|
|
55
46
|
} else if (field.settings.type === "time") {
|
|
56
47
|
return convertTimeToNumber(value);
|
|
57
48
|
}
|
|
58
|
-
|
|
59
49
|
return value;
|
|
60
50
|
};
|
|
61
|
-
|
|
62
51
|
var _default = () => ({
|
|
63
52
|
type: "cms-model-field-to-elastic-search",
|
|
64
53
|
name: "cms-model-field-to-elastic-search-datetime",
|
|
@@ -66,7 +55,6 @@ var _default = () => ({
|
|
|
66
55
|
unmappedType: () => {
|
|
67
56
|
return "date";
|
|
68
57
|
},
|
|
69
|
-
|
|
70
58
|
toIndex({
|
|
71
59
|
field,
|
|
72
60
|
value
|
|
@@ -78,13 +66,11 @@ var _default = () => ({
|
|
|
78
66
|
})
|
|
79
67
|
};
|
|
80
68
|
}
|
|
81
|
-
|
|
82
69
|
const dateValue = convertValueToIndex(value, field);
|
|
83
70
|
return {
|
|
84
71
|
value: dateValue
|
|
85
72
|
};
|
|
86
73
|
},
|
|
87
|
-
|
|
88
74
|
fromIndex({
|
|
89
75
|
field,
|
|
90
76
|
value
|
|
@@ -94,10 +80,7 @@ var _default = () => ({
|
|
|
94
80
|
return convertValueFromIndex(v, field);
|
|
95
81
|
});
|
|
96
82
|
}
|
|
97
|
-
|
|
98
83
|
return convertValueFromIndex(value, field);
|
|
99
84
|
}
|
|
100
|
-
|
|
101
85
|
});
|
|
102
|
-
|
|
103
86
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["convertTimeToNumber","time","hours","minutes","seconds","split","map","Number","convertNumberToTime","value","undefined","String","match","Math","floor","v","padStart","join","convertValueFromIndex","field","type","settings","dateValue","Date","toISOString","slice","convertValueToIndex","name","fieldType","unmappedType","toIndex","Array","isArray","fromIndex"],"sources":["dateTimeIndexing.ts"],"sourcesContent":["import { CmsModelDateTimeField } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\n\nconst convertTimeToNumber = (time?: string): number | null => {\n if (!time) {\n return null;\n }\n const [hours, minutes, seconds = 0] = time.split(\":\").map(Number);\n return hours * 60 * 60 + minutes * 60 + seconds;\n};\n\nconst convertNumberToTime = (value?: number): string | null => {\n if (value === undefined || value === null) {\n return null;\n }\n // TODO remove when v5 goes out\n // this is a fix for pre beta.5\n if (String(value).match(/^([0-9]{2}):([0-9]{2})/) !== null) {\n return String(value);\n }\n //\n const hours = Math.floor(value / 60 / 60);\n\n const minutes = Math.floor((value - hours * 60 * 60) / 60);\n\n const seconds = Math.floor(value - hours * 60 * 60 - minutes * 60);\n\n return [hours, minutes, seconds].map(v => String(v).padStart(2, \"0\")).join(\":\");\n};\n\nconst convertValueFromIndex = (\n value: string | number,\n field: CmsModelDateTimeField\n): string | null => {\n const type = field.settings.type;\n if (type === \"time\") {\n return convertNumberToTime(value as number);\n } else if (!value) {\n return null;\n } else if (type === \"dateTimeWithTimezone\") {\n return value as string;\n } else if (type === \"date\") {\n const dateValue = new Date(value);\n return dateValue.toISOString().slice(0, 10);\n }\n return new Date(value).toISOString();\n};\n\nconst convertValueToIndex = (value: string, field: CmsModelDateTimeField) => {\n if (!value) {\n return null;\n } else if (field.settings.type === \"time\") {\n return convertTimeToNumber(value);\n }\n return value;\n};\n\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-datetime\",\n fieldType: \"datetime\",\n unmappedType: () => {\n return \"date\";\n },\n toIndex({ field, value }) {\n if (Array.isArray(value) === true) {\n return {\n value: value.map((v: string) => {\n return convertValueToIndex(v, field as CmsModelDateTimeField);\n })\n };\n }\n const dateValue = convertValueToIndex(value, field as CmsModelDateTimeField);\n return {\n value: dateValue\n };\n },\n fromIndex({ field, value }) {\n if (Array.isArray(value)) {\n return value.map((v: string) => {\n return convertValueFromIndex(v, field as CmsModelDateTimeField);\n });\n }\n return convertValueFromIndex(value, field as CmsModelDateTimeField);\n }\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["convertTimeToNumber","time","hours","minutes","seconds","split","map","Number","convertNumberToTime","value","undefined","String","match","Math","floor","v","padStart","join","convertValueFromIndex","field","type","settings","dateValue","Date","toISOString","slice","convertValueToIndex","name","fieldType","unmappedType","toIndex","Array","isArray","fromIndex"],"sources":["dateTimeIndexing.ts"],"sourcesContent":["import { CmsModelDateTimeField } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\n\nconst convertTimeToNumber = (time?: string): number | null => {\n if (!time) {\n return null;\n }\n const [hours, minutes, seconds = 0] = time.split(\":\").map(Number);\n return hours * 60 * 60 + minutes * 60 + seconds;\n};\n\nconst convertNumberToTime = (value?: number): string | null => {\n if (value === undefined || value === null) {\n return null;\n }\n // TODO remove when v5 goes out\n // this is a fix for pre beta.5\n if (String(value).match(/^([0-9]{2}):([0-9]{2})/) !== null) {\n return String(value);\n }\n //\n const hours = Math.floor(value / 60 / 60);\n\n const minutes = Math.floor((value - hours * 60 * 60) / 60);\n\n const seconds = Math.floor(value - hours * 60 * 60 - minutes * 60);\n\n return [hours, minutes, seconds].map(v => String(v).padStart(2, \"0\")).join(\":\");\n};\n\nconst convertValueFromIndex = (\n value: string | number,\n field: CmsModelDateTimeField\n): string | null => {\n const type = field.settings.type;\n if (type === \"time\") {\n return convertNumberToTime(value as number);\n } else if (!value) {\n return null;\n } else if (type === \"dateTimeWithTimezone\") {\n return value as string;\n } else if (type === \"date\") {\n const dateValue = new Date(value);\n return dateValue.toISOString().slice(0, 10);\n }\n return new Date(value).toISOString();\n};\n\nconst convertValueToIndex = (value: string, field: CmsModelDateTimeField) => {\n if (!value) {\n return null;\n } else if (field.settings.type === \"time\") {\n return convertTimeToNumber(value);\n }\n return value;\n};\n\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-datetime\",\n fieldType: \"datetime\",\n unmappedType: () => {\n return \"date\";\n },\n toIndex({ field, value }) {\n if (Array.isArray(value) === true) {\n return {\n value: value.map((v: string) => {\n return convertValueToIndex(v, field as CmsModelDateTimeField);\n })\n };\n }\n const dateValue = convertValueToIndex(value, field as CmsModelDateTimeField);\n return {\n value: dateValue\n };\n },\n fromIndex({ field, value }) {\n if (Array.isArray(value)) {\n return value.map((v: string) => {\n return convertValueFromIndex(v, field as CmsModelDateTimeField);\n });\n }\n return convertValueFromIndex(value, field as CmsModelDateTimeField);\n }\n});\n"],"mappings":"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"}
|
|
@@ -4,32 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _default = () => ({
|
|
9
8
|
type: "cms-model-field-to-elastic-search",
|
|
10
9
|
name: "cms-model-field-to-elastic-search-default",
|
|
11
10
|
fieldType: "*",
|
|
12
|
-
|
|
13
11
|
toIndex({
|
|
14
12
|
field,
|
|
15
13
|
getFieldTypePlugin,
|
|
16
14
|
value
|
|
17
15
|
}) {
|
|
18
|
-
const fieldTypePlugin = getFieldTypePlugin(field.type);
|
|
16
|
+
const fieldTypePlugin = getFieldTypePlugin(field.type);
|
|
19
17
|
|
|
18
|
+
// when field is searchable, assign it to `values`
|
|
20
19
|
if (fieldTypePlugin.isSearchable === true) {
|
|
21
20
|
return {
|
|
22
21
|
value
|
|
23
22
|
};
|
|
24
|
-
}
|
|
25
|
-
// `rawValues` is a field in ES index that's not being indexed.
|
|
26
|
-
|
|
23
|
+
}
|
|
27
24
|
|
|
25
|
+
// when field is not searchable, move its value to `rawValues`.
|
|
26
|
+
// `rawValues` is a field in ES index that's not being indexed.
|
|
28
27
|
return {
|
|
29
28
|
rawValue: value
|
|
30
29
|
};
|
|
31
30
|
},
|
|
32
|
-
|
|
33
31
|
fromIndex({
|
|
34
32
|
field,
|
|
35
33
|
getFieldTypePlugin,
|
|
@@ -41,7 +39,5 @@ var _default = () => ({
|
|
|
41
39
|
} = getFieldTypePlugin(field.type);
|
|
42
40
|
return isSearchable === true ? value : rawValue;
|
|
43
41
|
}
|
|
44
|
-
|
|
45
42
|
});
|
|
46
|
-
|
|
47
43
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["type","name","fieldType","toIndex","field","getFieldTypePlugin","value","fieldTypePlugin","isSearchable","rawValue","fromIndex"],"sources":["defaultFieldIndexing.ts"],"sourcesContent":["import { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\n\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-default\",\n fieldType: \"*\",\n toIndex({ field, getFieldTypePlugin, value }) {\n const fieldTypePlugin = getFieldTypePlugin(field.type);\n\n // when field is searchable, assign it to `values`\n if (fieldTypePlugin.isSearchable === true) {\n return { value };\n }\n\n // when field is not searchable, move its value to `rawValues`.\n // `rawValues` is a field in ES index that's not being indexed.\n return { rawValue: value };\n },\n fromIndex({ field, getFieldTypePlugin, value, rawValue }) {\n const { isSearchable } = getFieldTypePlugin(field.type);\n\n return isSearchable === true ? value : rawValue;\n }\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["type","name","fieldType","toIndex","field","getFieldTypePlugin","value","fieldTypePlugin","isSearchable","rawValue","fromIndex"],"sources":["defaultFieldIndexing.ts"],"sourcesContent":["import { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\n\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-default\",\n fieldType: \"*\",\n toIndex({ field, getFieldTypePlugin, value }) {\n const fieldTypePlugin = getFieldTypePlugin(field.type);\n\n // when field is searchable, assign it to `values`\n if (fieldTypePlugin.isSearchable === true) {\n return { value };\n }\n\n // when field is not searchable, move its value to `rawValues`.\n // `rawValues` is a field in ES index that's not being indexed.\n return { rawValue: value };\n },\n fromIndex({ field, getFieldTypePlugin, value, rawValue }) {\n const { isSearchable } = getFieldTypePlugin(field.type);\n\n return isSearchable === true ? value : rawValue;\n }\n});\n"],"mappings":";;;;;;eAEe,OAA2C;EACtDA,IAAI,EAAE,mCAAmC;EACzCC,IAAI,EAAE,2CAA2C;EACjDC,SAAS,EAAE,GAAG;EACdC,OAAO,CAAC;IAAEC,KAAK;IAAEC,kBAAkB;IAAEC;EAAM,CAAC,EAAE;IAC1C,MAAMC,eAAe,GAAGF,kBAAkB,CAACD,KAAK,CAACJ,IAAI,CAAC;;IAEtD;IACA,IAAIO,eAAe,CAACC,YAAY,KAAK,IAAI,EAAE;MACvC,OAAO;QAAEF;MAAM,CAAC;IACpB;;IAEA;IACA;IACA,OAAO;MAAEG,QAAQ,EAAEH;IAAM,CAAC;EAC9B,CAAC;EACDI,SAAS,CAAC;IAAEN,KAAK;IAAEC,kBAAkB;IAAEC,KAAK;IAAEG;EAAS,CAAC,EAAE;IACtD,MAAM;MAAED;IAAa,CAAC,GAAGH,kBAAkB,CAACD,KAAK,CAACJ,IAAI,CAAC;IAEvD,OAAOQ,YAAY,KAAK,IAAI,GAAGF,KAAK,GAAGG,QAAQ;EACnD;AACJ,CAAC,CAAC;AAAA"}
|