@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.2af142b57e
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.d.ts +2 -2
- package/configurations.js +13 -10
- package/configurations.js.map +1 -0
- package/definitions/entry.d.ts +2 -2
- package/definitions/entry.js +6 -12
- package/definitions/entry.js.map +1 -0
- package/definitions/entryElasticsearch.d.ts +2 -2
- package/definitions/entryElasticsearch.js +3 -12
- package/definitions/entryElasticsearch.js.map +1 -0
- package/definitions/group.d.ts +2 -2
- package/definitions/group.js +3 -12
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +2 -2
- package/definitions/model.js +8 -12
- package/definitions/model.js.map +1 -0
- package/definitions/settings.d.ts +2 -2
- package/definitions/settings.js +3 -12
- package/definitions/settings.js.map +1 -0
- package/definitions/system.d.ts +2 -2
- package/definitions/system.js +3 -12
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +2 -2
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.d.ts +2 -2
- package/definitions/tableElasticsearch.js +0 -3
- package/definitions/tableElasticsearch.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +4 -11
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/storage/date.d.ts +3 -3
- package/dynamoDb/storage/date.js +73 -54
- package/dynamoDb/storage/date.js.map +1 -0
- package/dynamoDb/storage/longText.d.ts +7 -4
- package/dynamoDb/storage/longText.js +72 -64
- package/dynamoDb/storage/longText.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +2 -3
- package/dynamoDb/storage/richText.js +74 -78
- package/dynamoDb/storage/richText.js.map +1 -0
- package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
- package/elasticsearch/createElasticsearchIndex.js +49 -0
- package/elasticsearch/createElasticsearchIndex.js.map +1 -0
- package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
- package/elasticsearch/deleteElasticsearchIndex.js +36 -0
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
- package/elasticsearch/index.d.ts +1 -1
- package/elasticsearch/index.js +1 -6
- package/elasticsearch/index.js.map +1 -0
- package/elasticsearch/indexing/dateTimeIndexing.js +17 -20
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
- package/elasticsearch/indexing/defaultFieldIndexing.js +5 -9
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
- package/elasticsearch/indexing/index.js +1 -10
- package/elasticsearch/indexing/index.js.map +1 -0
- package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
- package/elasticsearch/indexing/longTextIndexing.js +19 -9
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
- package/elasticsearch/indexing/numberIndexing.js +0 -9
- package/elasticsearch/indexing/numberIndexing.js.map +1 -0
- package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
- package/elasticsearch/indexing/objectIndexing.js +26 -30
- package/elasticsearch/indexing/objectIndexing.js.map +1 -0
- package/elasticsearch/indexing/richTextIndexing.js +0 -5
- package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
- package/elasticsearch/indices/base.d.ts +2 -0
- package/elasticsearch/indices/base.js +12 -0
- package/elasticsearch/indices/base.js.map +1 -0
- package/elasticsearch/indices/index.d.ts +1 -0
- package/elasticsearch/indices/index.js +12 -0
- package/elasticsearch/indices/index.js.map +1 -0
- package/elasticsearch/indices/japanese.d.ts +2 -0
- package/elasticsearch/indices/japanese.js +13 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/elasticsearch/search/index.d.ts +2 -2
- package/elasticsearch/search/index.js +3 -9
- package/elasticsearch/search/index.js.map +1 -0
- package/elasticsearch/search/refSearch.d.ts +2 -3
- package/elasticsearch/search/refSearch.js +23 -18
- package/elasticsearch/search/refSearch.js.map +1 -0
- package/elasticsearch/search/timeSearch.d.ts +2 -3
- package/elasticsearch/search/timeSearch.js +18 -17
- package/elasticsearch/search/timeSearch.js.map +1 -0
- package/helpers/entryIndexHelpers.js +43 -57
- package/helpers/entryIndexHelpers.js.map +1 -0
- package/helpers/index.d.ts +0 -1
- package/helpers/index.js +0 -15
- package/helpers/index.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +120 -58
- package/index.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +6 -2
- package/operations/entry/dataLoaders.js +27 -61
- package/operations/entry/dataLoaders.js.map +1 -0
- 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} +8 -10
- 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/operations/entry/elasticsearch/transformValueForSearch.js +30 -0
- 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 +2 -4
- package/operations/entry/index.js +457 -481
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/keys.js +0 -9
- package/operations/entry/keys.js.map +1 -0
- 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.d.ts +2 -2
- package/operations/group/index.js +10 -47
- package/operations/group/index.js.map +1 -0
- package/operations/model/index.d.ts +2 -2
- package/operations/model/index.js +34 -68
- package/operations/model/index.js.map +1 -0
- package/operations/settings/index.d.ts +2 -2
- package/operations/settings/index.js +7 -37
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js +5 -28
- package/operations/system/index.js.map +1 -0
- package/package.json +24 -29
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +7 -3
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +9 -11
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +3 -3
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +3 -9
- package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +28 -0
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +12 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +30 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +33 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +4 -3
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +9 -11
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +4 -3
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +9 -11
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
- 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 +7 -0
- package/plugins/index.js +82 -0
- package/plugins/index.js.map +1 -0
- package/types.d.ts +7 -34
- package/types.js +0 -18
- package/types.js.map +1 -0
- package/helpers/createElasticsearchQueryBody.d.ts +0 -11
- package/helpers/createElasticsearchQueryBody.js +0 -375
- package/helpers/fields.d.ts +0 -77
- package/helpers/fields.js +0 -174
- package/helpers/operatorPluginsList.d.ts +0 -7
- package/helpers/operatorPluginsList.js +0 -30
- package/helpers/searchPluginsList.d.ts +0 -6
- package/helpers/transformValueForSearch.d.ts +0 -9
- package/helpers/transformValueForSearch.js +0 -26
- package/operations/entry/elasticsearchFields.d.ts +0 -2
- package/operations/entry/elasticsearchFields.js +0 -32
- package/operations/entry/fields.d.ts +0 -3
- package/operations/entry/fields.js +0 -60
- package/operations/system/createElasticsearchTemplate.d.ts +0 -5
- package/operations/system/createElasticsearchTemplate.js +0 -62
- package/upgrades/index.d.ts +0 -2
- package/upgrades/index.js +0 -16
- package/upgrades/utils.d.ts +0 -1
- package/upgrades/utils.js +0 -16
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
- package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
- package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
- package/upgrades/v5.0.0/entryValueFixer.js +0 -124
- package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
- package/upgrades/v5.0.0/fieldFinder.js +0 -42
- package/upgrades/v5.0.0/helpers.d.ts +0 -4
- package/upgrades/v5.0.0/helpers.js +0 -57
- package/upgrades/v5.0.0/index.d.ts +0 -4
- package/upgrades/v5.0.0/index.js +0 -232
- package/upgrades/v5.8.0/index.d.ts +0 -4
- package/upgrades/v5.8.0/index.js +0 -426
package/dynamoDb/storage/date.js
CHANGED
|
@@ -1,65 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
9
|
-
|
|
7
|
+
exports.createDateStorageTransformPlugin = void 0;
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
10
|
+
/**
|
|
11
|
+
* File is @internal
|
|
12
|
+
*/
|
|
13
13
|
|
|
14
14
|
const excludeTypes = ["time", "dateTimeWithTimezone"];
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
type
|
|
23
|
-
} = field.settings || {};
|
|
24
|
-
|
|
25
|
-
if (!value || !type || excludeTypes.includes(type)) {
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
return new Date(value);
|
|
31
|
-
} catch {
|
|
32
|
-
console.log(`Could not transform from storage for field type`);
|
|
33
|
-
return value;
|
|
15
|
+
const convertFromStorage = (field, value) => {
|
|
16
|
+
try {
|
|
17
|
+
if (field.multipleValues) {
|
|
18
|
+
return (value || []).filter(v => !!v).map(v => {
|
|
19
|
+
return new Date(v);
|
|
20
|
+
});
|
|
34
21
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}) => {
|
|
40
|
-
const {
|
|
41
|
-
type
|
|
42
|
-
} = field.settings || {};
|
|
43
|
-
|
|
44
|
-
if (!value || !type || excludeTypes.includes(type)) {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (value.toISOString) {
|
|
49
|
-
return value.toISOString();
|
|
50
|
-
} else if (typeof value === "string") {
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
throw new _error.default("Error converting value to a storage type.", "TO_STORAGE_ERROR", {
|
|
55
|
-
value,
|
|
56
|
-
fieldId: field.fieldId
|
|
57
|
-
});
|
|
22
|
+
return new Date(value);
|
|
23
|
+
} catch {
|
|
24
|
+
console.log(`Could not transform from storage for field type`);
|
|
25
|
+
return value;
|
|
58
26
|
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
var _default = () => {
|
|
62
|
-
return plugin;
|
|
63
27
|
};
|
|
64
|
-
|
|
65
|
-
|
|
28
|
+
const convertValueToStorage = (field, value) => {
|
|
29
|
+
if (value.toISOString) {
|
|
30
|
+
return value.toISOString();
|
|
31
|
+
} else if (typeof value === "string") {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
throw new _error.default("Error converting value to a storage type.", "TO_STORAGE_ERROR", {
|
|
35
|
+
value: value,
|
|
36
|
+
fieldId: field.fieldId,
|
|
37
|
+
storageId: field.storageId
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const createDateStorageTransformPlugin = () => {
|
|
41
|
+
return new _apiHeadlessCms.StorageTransformPlugin({
|
|
42
|
+
fieldType: "datetime",
|
|
43
|
+
fromStorage: async ({
|
|
44
|
+
value,
|
|
45
|
+
field
|
|
46
|
+
}) => {
|
|
47
|
+
const {
|
|
48
|
+
type
|
|
49
|
+
} = field.settings || {};
|
|
50
|
+
if (!value || !type || excludeTypes.includes(type)) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
return convertFromStorage(field, value);
|
|
54
|
+
},
|
|
55
|
+
toStorage: async ({
|
|
56
|
+
value,
|
|
57
|
+
field
|
|
58
|
+
}) => {
|
|
59
|
+
const {
|
|
60
|
+
type
|
|
61
|
+
} = field.settings || {};
|
|
62
|
+
if (!value || !type || excludeTypes.includes(type)) {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
if (field.multipleValues) {
|
|
66
|
+
const multipleValues = value;
|
|
67
|
+
return (multipleValues || []).filter(v => !!v).map(v => {
|
|
68
|
+
return convertValueToStorage(field, v);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (value.toISOString) {
|
|
72
|
+
return value.toISOString();
|
|
73
|
+
} else if (typeof value === "string") {
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
throw new _error.default("Error converting value to a storage type.", "TO_STORAGE_ERROR", {
|
|
77
|
+
value,
|
|
78
|
+
fieldId: field.fieldId,
|
|
79
|
+
storageId: field.storageId
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
exports.createDateStorageTransformPlugin = createDateStorageTransformPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["excludeTypes","convertFromStorage","field","value","multipleValues","filter","v","map","Date","console","log","convertValueToStorage","toISOString","WebinyError","fieldId","storageId","createDateStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","type","settings","includes","toStorage"],"sources":["date.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\ntype PartialCmsModelField = Pick<CmsModelField, \"fieldId\" | \"storageId\" | \"multipleValues\">;\n\nconst excludeTypes = [\"time\", \"dateTimeWithTimezone\"];\n\nconst convertFromStorage = (field: PartialCmsModelField, value: string | string[]) => {\n try {\n if (field.multipleValues) {\n return ((value as string[]) || [])\n .filter(v => !!v)\n .map((v: string) => {\n return new Date(v);\n });\n }\n return new Date(value as string);\n } catch {\n console.log(`Could not transform from storage for field type`);\n return value;\n }\n};\n\nconst convertValueToStorage = (field: PartialCmsModelField, value: any): any => {\n if ((value as any).toISOString) {\n return (value as Date).toISOString();\n } else if (typeof value === \"string\") {\n return value as string;\n }\n throw new WebinyError(\"Error converting value to a storage type.\", \"TO_STORAGE_ERROR\", {\n value: value,\n fieldId: field.fieldId,\n storageId: field.storageId\n });\n};\n\nexport const createDateStorageTransformPlugin = () => {\n return new StorageTransformPlugin({\n fieldType: \"datetime\",\n fromStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\n }\n return convertFromStorage(field, value);\n },\n toStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\n }\n if (field.multipleValues) {\n const multipleValues = value as (string | Date | null | undefined)[];\n return (multipleValues || [])\n .filter(v => !!v)\n .map(v => {\n return convertValueToStorage(field, v);\n });\n }\n if ((value as any).toISOString) {\n return (value as Date).toISOString();\n } else if (typeof value === \"string\") {\n return value as string;\n }\n throw new WebinyError(\"Error converting value to a storage type.\", \"TO_STORAGE_ERROR\", {\n value,\n fieldId: field.fieldId,\n storageId: field.storageId\n });\n }\n });\n};\n"],"mappings":";;;;;;;AAGA;AACA;AAJA;AACA;AACA;;AAOA,MAAMA,YAAY,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC;AAErD,MAAMC,kBAAkB,GAAG,CAACC,KAA2B,EAAEC,KAAwB,KAAK;EAClF,IAAI;IACA,IAAID,KAAK,CAACE,cAAc,EAAE;MACtB,OAAO,CAAED,KAAK,IAAiB,EAAE,EAC5BE,MAAM,CAACC,CAAC,IAAI,CAAC,CAACA,CAAC,CAAC,CAChBC,GAAG,CAAED,CAAS,IAAK;QAChB,OAAO,IAAIE,IAAI,CAACF,CAAC,CAAC;MACtB,CAAC,CAAC;IACV;IACA,OAAO,IAAIE,IAAI,CAACL,KAAK,CAAW;EACpC,CAAC,CAAC,MAAM;IACJM,OAAO,CAACC,GAAG,CAAE,iDAAgD,CAAC;IAC9D,OAAOP,KAAK;EAChB;AACJ,CAAC;AAED,MAAMQ,qBAAqB,GAAG,CAACT,KAA2B,EAAEC,KAAU,KAAU;EAC5E,IAAKA,KAAK,CAASS,WA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,EAAEI,CAAC,CAAC;QAC1C,CAAC,CAAC;MACV;MACA,IAAKH,KAAK,CAASS,WAAW,EAAE;QAC5B,OAAQT,KAAK,CAAUS,WAAW,EAAE;MACxC,CAAC,MAAM,IAAI,OAAOT,KAAK,KAAK,QAAQ,EAAE;QAClC,OAAOA,KAAK;MAChB;MACA,MAAM,IAAIU,cAAW,CAAC,2CAA2C,EAAE,kBAAkB,EAAE;QACnFV,KAAK;QACLW,OAAO,EAAEZ,KAAK,CAACY,OAAO;QACtBC,SAAS,EAAEb,KAAK,CAACa;MACrB,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* File is @internal
|
|
3
|
+
*/
|
|
4
|
+
import { StorageTransformPlugin } from "@webiny/api-headless-cms";
|
|
2
5
|
export interface StorageValue {
|
|
3
6
|
compression: string;
|
|
4
|
-
value:
|
|
7
|
+
value: string;
|
|
8
|
+
isArray?: boolean;
|
|
5
9
|
}
|
|
6
|
-
declare const
|
|
7
|
-
export default _default;
|
|
10
|
+
export declare const createLongTextStorageTransformPlugin: () => StorageTransformPlugin<string | string[], StorageValue, import("@webiny/api-headless-cms/types").CmsModelField>;
|
|
@@ -1,83 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
9
|
-
|
|
7
|
+
exports.createLongTextStorageTransformPlugin = void 0;
|
|
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");
|
|
11
|
+
/**
|
|
12
|
+
* File is @internal
|
|
13
|
+
*/
|
|
15
14
|
|
|
16
15
|
const GZIP = "gzip";
|
|
17
16
|
const TO_STORAGE_ENCODING = "base64";
|
|
18
17
|
const FROM_STORAGE_ENCODING = "utf8";
|
|
19
|
-
|
|
20
18
|
const convertToBuffer = value => {
|
|
21
19
|
if (typeof value === "string") {
|
|
22
20
|
return Buffer.from(value, TO_STORAGE_ENCODING);
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
return value;
|
|
26
23
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
const createLongTextStorageTransformPlugin = () => {
|
|
25
|
+
return new _apiHeadlessCms.StorageTransformPlugin({
|
|
26
|
+
fieldType: "long-text",
|
|
27
|
+
fromStorage: async ({
|
|
28
|
+
field,
|
|
29
|
+
value: storageValue
|
|
30
|
+
}) => {
|
|
31
|
+
const typeOf = typeof storageValue;
|
|
32
|
+
if (!storageValue || typeOf === "string" || typeOf === "number" || Array.isArray(storageValue) === true) {
|
|
33
|
+
return storageValue;
|
|
34
|
+
} else if (typeOf !== "object") {
|
|
35
|
+
throw new _error.default(`LongText value received in "fromStorage" function is not an object in field "${field.storageId}" - ${field.fieldId}.`);
|
|
36
|
+
}
|
|
37
|
+
const {
|
|
38
|
+
compression,
|
|
39
|
+
value,
|
|
40
|
+
isArray
|
|
41
|
+
} = storageValue;
|
|
42
|
+
/**
|
|
43
|
+
* Check if possibly undefined, null, empty...
|
|
44
|
+
*/
|
|
45
|
+
if (!compression) {
|
|
46
|
+
throw new _error.default(`Missing compression in "fromStorage" function in field "${field.storageId}" - ${field.fieldId}.": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
|
|
47
|
+
value: storageValue
|
|
48
|
+
});
|
|
49
|
+
} else if (compression !== GZIP) {
|
|
50
|
+
throw new _error.default(`This plugin cannot transform something not compressed with "GZIP".`, "WRONG_COMPRESSION", {
|
|
51
|
+
compression
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const buf = await (0, _gzip.decompress)(convertToBuffer(value));
|
|
56
|
+
const result = buf.toString(FROM_STORAGE_ENCODING);
|
|
57
|
+
if (!isArray) {
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
return JSON.parse(result);
|
|
61
|
+
} catch (ex) {
|
|
62
|
+
console.log("Error while transforming long-text.");
|
|
63
|
+
console.log(ex.message);
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
toStorage: async ({
|
|
68
|
+
value: initialValue
|
|
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
|
+
}
|
|
76
|
+
const isArray = Array.isArray(initialValue);
|
|
77
|
+
const value = isArray ? JSON.stringify(initialValue) : initialValue;
|
|
78
|
+
const compressedValue = await (0, _gzip.compress)(value);
|
|
79
|
+
const result = {
|
|
80
|
+
compression: GZIP,
|
|
81
|
+
value: compressedValue.toString(TO_STORAGE_ENCODING)
|
|
82
|
+
};
|
|
83
|
+
if (!isArray) {
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
result.isArray = isArray;
|
|
87
|
+
return result;
|
|
40
88
|
}
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
compression,
|
|
44
|
-
value
|
|
45
|
-
} = storageValue;
|
|
46
|
-
/**
|
|
47
|
-
* Check if possibly undefined, null, empty...
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
if (!compression) {
|
|
51
|
-
throw new _error.default(`Missing compression in "fromStorage" function in field "${field.fieldId}": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
|
|
52
|
-
value: storageValue
|
|
53
|
-
});
|
|
54
|
-
} else if (compression !== GZIP) {
|
|
55
|
-
throw new _error.default(`This plugin cannot transform something not compressed with "GZIP".`, "WRONG_COMPRESSION", {
|
|
56
|
-
compression
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const buf = await (0, _gzip.decompress)(convertToBuffer(value));
|
|
62
|
-
return buf.toString(FROM_STORAGE_ENCODING);
|
|
63
|
-
} catch (ex) {
|
|
64
|
-
console.log(ex.message);
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
toStorage: async ({
|
|
69
|
-
value
|
|
70
|
-
}) => {
|
|
71
|
-
const compressedValue = await (0, _gzip.compress)(value);
|
|
72
|
-
return {
|
|
73
|
-
compression: GZIP,
|
|
74
|
-
value: compressedValue.toString(TO_STORAGE_ENCODING)
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
var _default = () => {
|
|
80
|
-
return plugin;
|
|
89
|
+
});
|
|
81
90
|
};
|
|
82
|
-
|
|
83
|
-
exports.default = _default;
|
|
91
|
+
exports.createLongTextStorageTransformPlugin = createLongTextStorageTransformPlugin;
|
|
@@ -0,0 +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","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":";;;;;;;AAIA;AACA;AACA;AANA;AACA;AACA;;AAMA,MAAMA,IAAI,GAAG,MAAM;AACnB,MAAMC,mBAAmB,GAAG,QAAQ;AACpC,MAAMC,qBAAqB,GAAG,MAAM;AAEpC,MAAMC,eAAe,GAAIC,KAAsB,IAAa;EACxD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOC,MAAM,CAACC,IAAI,CAACF,KAAK,EAAEH,mBAAmB,CAAC;EAClD;EACA,OAAOG,KAAK;AAChB,CAAC;AAQM,MAAMG,oCAAoC,GAAG,MAAM;EACtD,OAAO,IAAIC,sCAAsB,CAAkC;IAC/DC,SAAS,EAAE,WAAW;IACtBC,WAAW,EAAE,OAAO;MAAEC,KAAK;MAAEP,KAAK,EAAEQ;IAAa,CAAC,KAAK;MACnD,MAAMC,MAAM,GAAG,OAAOD,YAAY;MAClC,IACI,CAACA,YAAY,IACbC,MAAM,KAAK,QAAQ,IACnBA,MAAM,KAAK,QAAQ,IACnBC,KAAK,CAACC,OAAO,CAACH,YAAY,CAAC,KAAK,IAAI,EACtC;QACE,OAAOA,YAAY;MACvB,CAAC,MAAM,IAAIC,MAAM,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAIG,cAAW,CAChB,gFAA+EL,KAAK,CAACM,SAAU,OAAMN,KAAK,CAACO,OAAQ,GAAE,CACzH;MACL;MACA,MAAM;QAAEC,WAAW;QAAEf,KAAK;QAAEW;MAAQ,CAAC,GAAGH,YAAY;MACpD;AACZ;AACA;MACY,IAAI,CAACO,WAAW,EAAE;QACd,MAAM,IAAIH,cAAW,CAChB,2DACGL,KAAK,CAACM,SACT,OAAMN,KAAK,CAACO,OAAQ,OAAME,IAAI,C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E;QACV,OAAOS,MAAM;MACjB;MACAA,MAAM,CAACT,OAAO,GAAGA,OAAO;MACxB,OAAOS,MAAM;IACjB;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { StorageTransformPlugin } from "@webiny/api-headless-cms
|
|
1
|
+
import { StorageTransformPlugin } from "@webiny/api-headless-cms";
|
|
2
2
|
export declare type OriginalValue = Record<string, any> | any[];
|
|
3
3
|
export interface StorageValue {
|
|
4
4
|
compression: string;
|
|
5
5
|
value: any;
|
|
6
6
|
}
|
|
7
|
-
declare const
|
|
8
|
-
export default _default;
|
|
7
|
+
export declare const createRichTextStorageTransformPlugin: () => StorageTransformPlugin<any, any, import("@webiny/api-headless-cms/types").CmsModelField>;
|
|
@@ -1,110 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
9
|
-
|
|
7
|
+
exports.createRichTextStorageTransformPlugin = void 0;
|
|
10
8
|
var _jsonpack = _interopRequireDefault(require("jsonpack"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
|
-
var _StorageTransformPlugin = require("@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin");
|
|
15
|
-
|
|
10
|
+
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
16
11
|
/**
|
|
17
12
|
* Remove when jsonpack gets PR with a fix merged
|
|
18
13
|
* https://github.com/rgcl/jsonpack/pull/25/files
|
|
19
14
|
* NOTE 2021-07-28: it seems PR is not going to be merged so keep this.
|
|
20
15
|
*/
|
|
16
|
+
// TODO @ts-refactor figure better type
|
|
21
17
|
const transformArray = value => {
|
|
22
18
|
if (!value) {
|
|
23
19
|
return value;
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
let isArray = Array.isArray(value);
|
|
27
22
|
const shouldBeArray = value instanceof Array === false && isArray;
|
|
28
|
-
|
|
29
23
|
if (shouldBeArray) {
|
|
30
24
|
value = Array.from(value);
|
|
31
25
|
isArray = true;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
if (typeof value === "object" || isArray) {
|
|
35
28
|
for (const k in value) {
|
|
36
29
|
value[k] = transformArray(value[k]);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
|
-
|
|
40
32
|
return value;
|
|
41
33
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
compression
|
|
34
|
+
const createRichTextStorageTransformPlugin = () => {
|
|
35
|
+
return new _apiHeadlessCms.StorageTransformPlugin({
|
|
36
|
+
fieldType: "rich-text",
|
|
37
|
+
fromStorage: async ({
|
|
38
|
+
field,
|
|
39
|
+
value: storageValue
|
|
40
|
+
}) => {
|
|
41
|
+
if (!storageValue) {
|
|
42
|
+
return storageValue;
|
|
43
|
+
} else if (typeof storageValue !== "object") {
|
|
44
|
+
throw new _error.default(`RichText value received in "fromStorage" function is not an object in field "${field.storageId}".`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This is to circumvent a bug introduced with 5.8.0 storage operations.
|
|
48
|
+
* Do not remove.
|
|
49
|
+
*/
|
|
50
|
+
if (storageValue.hasOwnProperty("compression") === false) {
|
|
51
|
+
return storageValue;
|
|
52
|
+
}
|
|
53
|
+
const {
|
|
54
|
+
compression,
|
|
55
|
+
value
|
|
56
|
+
} = storageValue;
|
|
57
|
+
if (!compression) {
|
|
58
|
+
throw new _error.default(`Missing compression in "fromStorage" function in field "${field.storageId}": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
|
|
59
|
+
value: storageValue
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (compression !== "jsonpack") {
|
|
63
|
+
throw new _error.default(`This plugin cannot transform something not packed with "jsonpack".`, "WRONG_COMPRESSION", {
|
|
64
|
+
compression
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
return _jsonpack.default.unpack(value);
|
|
69
|
+
} catch (ex) {
|
|
70
|
+
if (process.env.DEBUG !== "true") {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
console.log("Error while decompressing rich-text.");
|
|
74
|
+
console.log(ex.message);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
toStorage: async ({
|
|
66
79
|
value
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
}) => {
|
|
81
|
+
/**
|
|
82
|
+
* There is a possibility that we are trying to compress already compressed value.
|
|
83
|
+
* Introduced a bug with 5.8.0 storage operations, so just return the value to correct it.
|
|
84
|
+
*/
|
|
85
|
+
if (value && value.hasOwnProperty("compression") === true) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
value = transformArray(value);
|
|
89
|
+
let jsonValue = null;
|
|
90
|
+
try {
|
|
91
|
+
jsonValue = _jsonpack.default.pack(value);
|
|
92
|
+
} catch (ex) {
|
|
93
|
+
if (process.env.DEBUG !== "true") {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
console.log("Error while compressing rich-text.");
|
|
97
|
+
console.log(ex.message);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
compression: "jsonpack",
|
|
101
|
+
value: jsonValue
|
|
102
|
+
};
|
|
85
103
|
}
|
|
86
|
-
}
|
|
87
|
-
toStorage: async ({
|
|
88
|
-
value
|
|
89
|
-
}) => {
|
|
90
|
-
/**
|
|
91
|
-
* There is a possibility that we are trying to compress already compressed value.
|
|
92
|
-
* Introduced a bug with 5.8.0 storage operations, so just return the value to correct it.
|
|
93
|
-
*/
|
|
94
|
-
if (value && value.hasOwnProperty("compression") === true) {
|
|
95
|
-
return value;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
value = transformArray(value);
|
|
99
|
-
return {
|
|
100
|
-
compression: "jsonpack",
|
|
101
|
-
value: value ? _jsonpack.default.pack(value) : value
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
var _default = () => {
|
|
107
|
-
return plugin;
|
|
104
|
+
});
|
|
108
105
|
};
|
|
109
|
-
|
|
110
|
-
exports.default = _default;
|
|
106
|
+
exports.createRichTextStorageTransformPlugin = createRichTextStorageTransformPlugin;
|
|
@@ -0,0 +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":";;;;;;;AAAA;AACA;AACA;AASA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,cAAc,GAAIC,KAAU,IAAK;EACnC,IAAI,CAACA,KAAK,EAAE;IACR,OAAOA,KAAK;EAChB;EACA,IAAIC,OAAO,GAAGC,KAAK,CAACD,OAAO,CAACD,KAAK,CAAC;EAClC,MAAMG,aAAa,GAAGH,KAAK,YAAYE,KAAK,KAAK,KAAK,IAAID,OAAO;EACjE,IAAIE,aAAa,EAAE;IACfH,KAAK,GAAGE,KAAK,CAACE,IAAI,CAACJ,KAAK,CAAQ;IAChCC,OAAO,GAAG,IAAI;EAClB;EACA,IAAI,OAAOD,KAAK,KAAK,QAAQ,IAAIC,OAAO,EAAE;IACtC,KAAK,MAAMI,CAAC,IAAIL,KAAK,EAAE;MACnBA,KAAK,CAACK,CAAC,CAAC,GAAGN,cAAc,CAACC,KAAK,CAACK,CAAC,CAAC,CAAC;IACvC;EACJ;EACA,OAAOL,KAAK;AAChB,CAAC;AAEM,MAAMM,oCAAoC,GAAG,MAAM;EACtD,OAAO,IAAIC,sCAAsB,CAAC;IAC9BC,SAAS,EAAE,WAAW;IACtBC,WAAW,EAAE,OAAO;MAAEC,KAAK;MAAEV,KAAK,EAAEW;IAAa,CAAC,KAAK;MACnD,IAAI,CAACA,YAAY,EAAE;QACf,OAAOA,YAAY;MACvB,CAAC,MAAM,IAAI,OAAOA,YAAY,KAAK,QAAQ,EAAE;QACzC,MAAM,IAAIC,cAAW,CAChB,gFAA+EF,KAAK,CAACG,SAAU,IAAG,CACtG;MACL;MACA;AACZ;AACA;AACA;MACY,IAAIF,YAAY,CAACG,cAAc,CAAC,aAAa,CAAC,KAAK,KAAK,EAAE;QACtD,OAAOH,YAAY;MACvB;MACA,MAAM;QAAEI,WAAW;QAAEf;MAAM,CAAC,GAA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EAAE,UAAU;QACvBf,KAAK,EAAE4B;MACX,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from "@elastic/elasticsearch";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import { CmsModel } from "@webiny/api-headless-cms/types";
|
|
4
|
+
export interface CreateElasticsearchIndexParams {
|
|
5
|
+
elasticsearch: Client;
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
model: CmsModel;
|
|
8
|
+
}
|
|
9
|
+
export declare const createElasticsearchIndex: (params: CreateElasticsearchIndexParams) => Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createElasticsearchIndex = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _CmsEntryElasticsearchIndexPlugin = require("../plugins/CmsEntryElasticsearchIndexPlugin");
|
|
10
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
11
|
+
var _configurations = require("../configurations");
|
|
12
|
+
const createElasticsearchIndex = async params => {
|
|
13
|
+
const {
|
|
14
|
+
elasticsearch,
|
|
15
|
+
plugins: container,
|
|
16
|
+
model
|
|
17
|
+
} = params;
|
|
18
|
+
const plugin = (0, _apiElasticsearch.getLastAddedIndexPlugin)({
|
|
19
|
+
container,
|
|
20
|
+
type: _CmsEntryElasticsearchIndexPlugin.CmsEntryElasticsearchIndexPlugin.type,
|
|
21
|
+
locale: model.locale
|
|
22
|
+
});
|
|
23
|
+
const {
|
|
24
|
+
index
|
|
25
|
+
} = _configurations.configurations.es({
|
|
26
|
+
model
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
const response = await elasticsearch.indices.exists({
|
|
30
|
+
index
|
|
31
|
+
});
|
|
32
|
+
if (response.body) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await elasticsearch.indices.create({
|
|
36
|
+
index,
|
|
37
|
+
body: plugin.body
|
|
38
|
+
});
|
|
39
|
+
} catch (ex) {
|
|
40
|
+
throw new _error.default(ex.message || "Could not create Elasticsearch index for the Headless CMS model.", ex.code || "CMS_ELASTICSEARCH_INDEX_ERROR", {
|
|
41
|
+
error: ex,
|
|
42
|
+
type: _CmsEntryElasticsearchIndexPlugin.CmsEntryElasticsearchIndexPlugin.type,
|
|
43
|
+
locale: model.locale,
|
|
44
|
+
tenant: model.tenant,
|
|
45
|
+
body: plugin.body
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.createElasticsearchIndex = createElasticsearchIndex;
|
|
@@ -0,0 +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":";;;;;;;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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Client } from "@elastic/elasticsearch";
|
|
2
|
+
import { CmsModel } from "@webiny/api-headless-cms/types";
|
|
3
|
+
interface DeleteElasticsearchIndexParams {
|
|
4
|
+
elasticsearch: Client;
|
|
5
|
+
model: CmsModel;
|
|
6
|
+
}
|
|
7
|
+
export declare const deleteElasticsearchIndex: (params: DeleteElasticsearchIndexParams) => Promise<void>;
|
|
8
|
+
export {};
|