@webiny/api-headless-cms-ddb-es 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c27f4d8a31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -30
- package/configurations.d.ts +12 -6
- package/configurations.js +20 -18
- package/configurations.js.map +1 -1
- package/definitions/entry.d.ts +4 -5
- package/definitions/entry.js +7 -79
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +6 -6
- package/definitions/group.js +7 -59
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +6 -6
- package/definitions/model.js +7 -86
- package/definitions/model.js.map +1 -1
- package/definitions/types.d.ts +60 -0
- package/definitions/types.js +3 -0
- package/definitions/types.js.map +1 -0
- package/dynamoDb/index.d.ts +2 -1
- package/dynamoDb/index.js +7 -10
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/storage/longText.js +15 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +0 -5
- package/dynamoDb/storage/richText.js +29 -86
- package/dynamoDb/storage/richText.js.map +1 -1
- package/elasticsearch/createElasticsearchIndex.d.ts +4 -4
- package/elasticsearch/createElasticsearchIndex.js +23 -40
- package/elasticsearch/createElasticsearchIndex.js.map +1 -1
- package/elasticsearch/deleteElasticsearchIndex.d.ts +3 -3
- package/elasticsearch/deleteElasticsearchIndex.js +8 -13
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
- package/elasticsearch/index.d.ts +1 -1
- package/elasticsearch/index.js +4 -10
- package/elasticsearch/index.js.map +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.d.ts +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.js +5 -16
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
- package/elasticsearch/indexing/defaultFieldIndexing.d.ts +1 -1
- package/elasticsearch/indexing/defaultFieldIndexing.js +3 -8
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
- package/elasticsearch/indexing/index.d.ts +1 -1
- package/elasticsearch/indexing/index.js +9 -14
- package/elasticsearch/indexing/index.js.map +1 -1
- package/elasticsearch/indexing/jsonIndexing.d.ts +2 -0
- package/elasticsearch/indexing/jsonIndexing.js +21 -0
- package/elasticsearch/indexing/jsonIndexing.js.map +1 -0
- package/elasticsearch/indexing/longTextIndexing.d.ts +1 -1
- package/elasticsearch/indexing/longTextIndexing.js +5 -16
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
- package/elasticsearch/indexing/numberIndexing.d.ts +1 -1
- package/elasticsearch/indexing/numberIndexing.js +3 -8
- package/elasticsearch/indexing/numberIndexing.js.map +1 -1
- package/elasticsearch/indexing/objectIndexing.d.ts +1 -1
- package/elasticsearch/indexing/objectIndexing.js +25 -27
- package/elasticsearch/indexing/objectIndexing.js.map +1 -1
- package/elasticsearch/indexing/richTextIndexing.d.ts +1 -1
- package/elasticsearch/indexing/richTextIndexing.js +3 -8
- package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
- package/elasticsearch/indices/base.d.ts +1 -1
- package/elasticsearch/indices/base.js +6 -11
- package/elasticsearch/indices/base.js.map +1 -1
- package/elasticsearch/indices/index.d.ts +1 -1
- package/elasticsearch/indices/index.js +5 -11
- package/elasticsearch/indices/index.js.map +1 -1
- package/elasticsearch/search/index.d.ts +1 -1
- package/elasticsearch/search/index.js +5 -9
- package/elasticsearch/search/index.js.map +1 -1
- package/elasticsearch/search/refSearch.d.ts +1 -1
- package/elasticsearch/search/refSearch.js +5 -10
- package/elasticsearch/search/refSearch.js.map +1 -1
- package/elasticsearch/search/searchableJson.d.ts +2 -0
- package/elasticsearch/search/searchableJson.js +53 -0
- package/elasticsearch/search/searchableJson.js.map +1 -0
- package/elasticsearch/search/timeSearch.d.ts +1 -1
- package/elasticsearch/search/timeSearch.js +6 -12
- package/elasticsearch/search/timeSearch.js.map +1 -1
- package/helpers/entryIndexHelpers.d.ts +10 -10
- package/helpers/entryIndexHelpers.js +61 -40
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/fieldIdentifier.d.ts +6 -0
- package/helpers/fieldIdentifier.js +35 -0
- package/helpers/fieldIdentifier.js.map +1 -0
- package/helpers/index.d.ts +2 -1
- package/helpers/index.js +3 -15
- package/helpers/index.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +119 -147
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +31 -0
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
- package/operations/entry/dataLoader/constants.d.ts +1 -0
- package/operations/entry/dataLoader/constants.js +4 -0
- package/operations/entry/dataLoader/constants.js.map +1 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js +19 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js +35 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +44 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +44 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
- package/operations/entry/dataLoader/getRevisionById.js +54 -0
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
- package/operations/entry/dataLoader/index.d.ts +8 -0
- package/operations/entry/dataLoader/index.js +19 -0
- package/operations/entry/dataLoader/index.js.map +1 -0
- package/operations/entry/dataLoader/types.d.ts +6 -0
- package/operations/entry/dataLoader/types.js +3 -0
- package/operations/entry/dataLoader/types.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +17 -38
- package/operations/entry/dataLoaders.js +59 -264
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +3 -8
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
- package/operations/entry/elasticsearch/body.d.ts +3 -3
- package/operations/entry/elasticsearch/body.js +26 -31
- package/operations/entry/elasticsearch/body.js.map +1 -1
- package/operations/entry/elasticsearch/fields/createSystemField.d.ts +4 -0
- package/operations/entry/elasticsearch/fields/createSystemField.js +10 -0
- package/operations/entry/elasticsearch/fields/createSystemField.js.map +1 -0
- package/operations/entry/elasticsearch/fields/live.d.ts +2 -0
- package/operations/entry/elasticsearch/fields/live.js +45 -0
- package/operations/entry/elasticsearch/fields/live.js.map +1 -0
- package/operations/entry/elasticsearch/fields/location.d.ts +2 -0
- package/operations/entry/elasticsearch/fields/location.js +45 -0
- package/operations/entry/elasticsearch/fields/location.js.map +1 -0
- package/operations/entry/elasticsearch/fields/state.d.ts +2 -0
- package/operations/entry/elasticsearch/fields/state.js +93 -0
- package/operations/entry/elasticsearch/fields/state.js.map +1 -0
- package/operations/entry/elasticsearch/fields.d.ts +6 -5
- package/operations/entry/elasticsearch/fields.js +161 -116
- package/operations/entry/elasticsearch/fields.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +2 -2
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +12 -17
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/exec.d.ts +7 -6
- package/operations/entry/elasticsearch/filtering/exec.js +50 -44
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/index.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/index.js +2 -15
- package/operations/entry/elasticsearch/filtering/index.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/path.d.ts +2 -1
- package/operations/entry/elasticsearch/filtering/path.js +11 -17
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +9 -15
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/index.js +7 -12
- package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +11 -15
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +17 -16
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/populated.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/populated.js +4 -9
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/values.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/values.js +6 -12
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearch.d.ts +5 -4
- package/operations/entry/elasticsearch/fullTextSearch.js +19 -16
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +4 -4
- package/operations/entry/elasticsearch/fullTextSearchFields.js +13 -18
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
- package/operations/entry/elasticsearch/initialQuery.d.ts +2 -2
- package/operations/entry/elasticsearch/initialQuery.js +11 -26
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
- package/operations/entry/elasticsearch/keyword.d.ts +1 -1
- package/operations/entry/elasticsearch/keyword.js +6 -9
- package/operations/entry/elasticsearch/keyword.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +4 -4
- package/operations/entry/elasticsearch/plugins/bodyModifier.js +5 -10
- package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/operator.d.ts +2 -3
- package/operations/entry/elasticsearch/plugins/operator.js +6 -19
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +4 -4
- package/operations/entry/elasticsearch/plugins/queryModifier.js +5 -10
- package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/search.d.ts +2 -2
- package/operations/entry/elasticsearch/plugins/search.js +7 -13
- package/operations/entry/elasticsearch/plugins/search.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +4 -4
- package/operations/entry/elasticsearch/plugins/sortModifier.js +5 -10
- package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -1
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.d.ts +2 -0
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +6 -0
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -0
- package/operations/entry/elasticsearch/sort.d.ts +4 -4
- package/operations/entry/elasticsearch/sort.js +61 -36
- package/operations/entry/elasticsearch/sort.js.map +1 -1
- package/operations/entry/elasticsearch/transformValueForSearch.d.ts +2 -2
- package/operations/entry/elasticsearch/transformValueForSearch.js +6 -9
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
- package/operations/entry/elasticsearch/types.d.ts +8 -8
- package/operations/entry/elasticsearch/types.js +2 -4
- package/operations/entry/elasticsearch/types.js.map +1 -1
- package/operations/entry/index.d.ts +7 -6
- package/operations/entry/index.js +1193 -622
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +31 -1
- package/operations/entry/keys.js +58 -19
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/recordType.js +5 -12
- package/operations/entry/recordType.js.map +1 -1
- package/operations/entry/transformations/convertEntryKeys.d.ts +8 -0
- package/operations/entry/transformations/convertEntryKeys.js +30 -0
- package/operations/entry/transformations/convertEntryKeys.js.map +1 -0
- package/operations/entry/transformations/index.d.ts +29 -0
- package/operations/entry/transformations/index.js +119 -0
- package/operations/entry/transformations/index.js.map +1 -0
- package/operations/entry/transformations/modifyEntryValues.d.ts +52 -0
- package/operations/entry/transformations/modifyEntryValues.js +21 -0
- package/operations/entry/transformations/modifyEntryValues.js.map +1 -0
- package/operations/entry/transformations/transformEntryKeys.d.ts +11 -0
- package/operations/entry/transformations/transformEntryKeys.js +20 -0
- package/operations/entry/transformations/transformEntryKeys.js.map +1 -0
- package/operations/entry/transformations/transformEntryToIndex.d.ts +10 -0
- package/operations/entry/transformations/transformEntryToIndex.js +24 -0
- package/operations/entry/transformations/transformEntryToIndex.js.map +1 -0
- package/operations/group/index.d.ts +6 -5
- package/operations/group/index.js +47 -67
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +4 -4
- package/operations/model/index.js +39 -46
- package/operations/model/index.js.map +1 -1
- package/package.json +35 -37
- package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +69 -0
- package/plugins/CmsElasticsearchModelFieldPlugin.js +46 -0
- package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +3 -2
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +6 -15
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +5 -4
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +6 -15
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +5 -11
- package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +3 -2
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +10 -15
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +3 -2
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +6 -15
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +3 -2
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +6 -15
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchValuesModifier.d.ts +33 -0
- package/plugins/CmsEntryElasticsearchValuesModifier.js +42 -0
- package/plugins/CmsEntryElasticsearchValuesModifier.js.map +1 -0
- package/plugins/CmsEntryFilterPlugin.d.ts +3 -3
- package/plugins/CmsEntryFilterPlugin.js +6 -15
- package/plugins/CmsEntryFilterPlugin.js.map +1 -1
- package/plugins/index.d.ts +8 -7
- package/plugins/index.js +9 -81
- package/plugins/index.js.map +1 -1
- package/tasks/createIndexTaskPlugin.d.ts +2 -0
- package/tasks/createIndexTaskPlugin.js +41 -0
- package/tasks/createIndexTaskPlugin.js.map +1 -0
- package/types.d.ts +38 -36
- package/types.js +9 -12
- package/types.js.map +1 -1
- package/values/NoValueContainer.d.ts +5 -0
- package/values/NoValueContainer.js +13 -0
- package/values/NoValueContainer.js.map +1 -0
- package/definitions/entryElasticsearch.d.ts +0 -8
- package/definitions/entryElasticsearch.js +0 -37
- package/definitions/entryElasticsearch.js.map +0 -1
- package/definitions/settings.d.ts +0 -8
- package/definitions/settings.js +0 -53
- package/definitions/settings.js.map +0 -1
- package/definitions/system.d.ts +0 -8
- package/definitions/system.js +0 -41
- package/definitions/system.js.map +0 -1
- package/definitions/table.d.ts +0 -8
- package/definitions/table.js +0 -21
- package/definitions/table.js.map +0 -1
- package/definitions/tableElasticsearch.d.ts +0 -8
- package/definitions/tableElasticsearch.js +0 -21
- package/definitions/tableElasticsearch.js.map +0 -1
- package/dynamoDb/storage/date.d.ts +0 -3
- package/dynamoDb/storage/date.js +0 -84
- package/dynamoDb/storage/date.js.map +0 -1
- package/elasticsearch/indices/japanese.d.ts +0 -2
- package/elasticsearch/indices/japanese.js +0 -13
- package/elasticsearch/indices/japanese.js.map +0 -1
- package/operations/settings/index.d.ts +0 -6
- package/operations/settings/index.js +0 -111
- package/operations/settings/index.js.map +0 -1
- package/operations/system/index.d.ts +0 -6
- package/operations/system/index.js +0 -82
- package/operations/system/index.js.map +0 -1
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +0 -12
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -18
- package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from "../../plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js";
|
|
2
|
+
import { WebinyError } from "@webiny/error";
|
|
3
|
+
import { NoValueContainer } from "../../values/NoValueContainer.js";
|
|
4
|
+
const getKey = params => {
|
|
5
|
+
const {
|
|
6
|
+
field,
|
|
7
|
+
value
|
|
8
|
+
} = params;
|
|
9
|
+
const keys = Object.keys(value);
|
|
10
|
+
if (keys.length === 0) {
|
|
11
|
+
throw new WebinyError(`Searchable JSON field "${field.fieldId}" cannot be empty.`, "EMPTY_SEARCHABLE_JSON_FIELD", {
|
|
12
|
+
field,
|
|
13
|
+
value
|
|
14
|
+
});
|
|
15
|
+
} else if (keys.length > 1) {
|
|
16
|
+
throw new WebinyError(`Searchable JSON field "${field.fieldId}" can only have one key.`, "MULTIPLE_KEYS_IN_SEARCHABLE_JSON_FIELD", {
|
|
17
|
+
field,
|
|
18
|
+
value,
|
|
19
|
+
keys
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return keys[0];
|
|
23
|
+
};
|
|
24
|
+
export const createSearchableJsonSearchPlugin = () => {
|
|
25
|
+
return new CmsEntryElasticsearchQueryBuilderValueSearchPlugin({
|
|
26
|
+
fieldType: "searchable-json",
|
|
27
|
+
transform: params => {
|
|
28
|
+
const {
|
|
29
|
+
value
|
|
30
|
+
} = params;
|
|
31
|
+
if (NoValueContainer.is(value)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const key = getKey(params);
|
|
35
|
+
return value[key] || null;
|
|
36
|
+
},
|
|
37
|
+
path: params => {
|
|
38
|
+
const {
|
|
39
|
+
field
|
|
40
|
+
} = params;
|
|
41
|
+
if (NoValueContainer.is(params.originalValue)) {
|
|
42
|
+
return `${field.storageId}.unknown`;
|
|
43
|
+
}
|
|
44
|
+
const key = getKey({
|
|
45
|
+
field,
|
|
46
|
+
value: params.originalValue
|
|
47
|
+
});
|
|
48
|
+
return `${field.storageId}.${key}`;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=searchableJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CmsEntryElasticsearchQueryBuilderValueSearchPlugin","WebinyError","NoValueContainer","getKey","params","field","value","keys","Object","length","fieldId","createSearchableJsonSearchPlugin","fieldType","transform","is","key","path","originalValue","storageId"],"sources":["searchableJson.ts"],"sourcesContent":["import { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { NoValueContainer } from \"~/values/NoValueContainer.js\";\n\ninterface IGetKeyParams {\n field: CmsModelField;\n value: {\n [key: string]: any;\n };\n}\n\nconst getKey = (params: IGetKeyParams): string => {\n const { field, value } = params;\n const keys = Object.keys(value);\n if (keys.length === 0) {\n throw new WebinyError(\n `Searchable JSON field \"${field.fieldId}\" cannot be empty.`,\n \"EMPTY_SEARCHABLE_JSON_FIELD\",\n {\n field,\n value\n }\n );\n } else if (keys.length > 1) {\n throw new WebinyError(\n `Searchable JSON field \"${field.fieldId}\" can only have one key.`,\n \"MULTIPLE_KEYS_IN_SEARCHABLE_JSON_FIELD\",\n {\n field,\n value,\n keys\n }\n );\n }\n return keys[0];\n};\n\nexport const createSearchableJsonSearchPlugin =\n (): CmsEntryElasticsearchQueryBuilderValueSearchPlugin => {\n return new CmsEntryElasticsearchQueryBuilderValueSearchPlugin({\n fieldType: \"searchable-json\",\n transform: params => {\n const { value } = params;\n\n if (NoValueContainer.is(value)) {\n return null;\n }\n\n const key = getKey(params);\n return value[key] || null;\n },\n path: params => {\n const { field } = params;\n\n if (NoValueContainer.is(params.originalValue)) {\n return `${field.storageId}.unknown`;\n }\n\n const key = getKey({\n field,\n value: params.originalValue\n });\n\n return `${field.storageId}.${key}`;\n }\n });\n };\n"],"mappings":"AAAA,SAASA,kDAAkD;AAC3D,SAASC,WAAW,QAAQ,eAAe;AAE3C,SAASC,gBAAgB;AASzB,MAAMC,MAAM,GAAIC,MAAqB,IAAa;EAC9C,MAAM;IAAEC,KAAK;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAC/B,MAAMG,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACD,KAAK,CAAC;EAC/B,IAAIC,IAAI,CAACE,MAAM,KAAK,CAAC,EAAE;IACnB,MAAM,IAAIR,WAAW,CACjB,0BAA0BI,KAAK,CAACK,OAAO,oBAAoB,EAC3D,6BAA6B,EAC7B;MACIL,KAAK;MACLC;IACJ,CACJ,CAAC;EACL,CAAC,MAAM,IAAIC,IAAI,CAACE,MAAM,GAAG,CAAC,EAAE;IACxB,MAAM,IAAIR,WAAW,CACjB,0BAA0BI,KAAK,CAACK,OAAO,0BAA0B,EACjE,wCAAwC,EACxC;MACIL,KAAK;MACLC,KAAK;MACLC;IACJ,CACJ,CAAC;EACL;EACA,OAAOA,IAAI,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,MAAMI,gCAAgC,GACzCA,CAAA,KAA0D;EACtD,OAAO,IAAIX,kDAAkD,CAAC;IAC1DY,SAAS,EAAE,iBAAiB;IAC5BC,SAAS,EAAET,MAAM,IAAI;MACjB,MAAM;QAAEE;MAAM,CAAC,GAAGF,MAAM;MAExB,IAAIF,gBAAgB,CAACY,EAAE,CAACR,KAAK,CAAC,EAAE;QAC5B,OAAO,IAAI;MACf;MAEA,MAAMS,GAAG,GAAGZ,MAAM,CAACC,MAAM,CAAC;MAC1B,OAAOE,KAAK,CAACS,GAAG,CAAC,IAAI,IAAI;IAC7B,CAAC;IACDC,IAAI,EAAEZ,MAAM,IAAI;MACZ,MAAM;QAAEC;MAAM,CAAC,GAAGD,MAAM;MAExB,IAAIF,gBAAgB,CAACY,EAAE,CAACV,MAAM,CAACa,aAAa,CAAC,EAAE;QAC3C,OAAO,GAAGZ,KAAK,CAACa,SAAS,UAAU;MACvC;MAEA,MAAMH,GAAG,GAAGZ,MAAM,CAAC;QACfE,KAAK;QACLC,KAAK,EAAEF,MAAM,CAACa;MAClB,CAAC,CAAC;MAEF,OAAO,GAAGZ,KAAK,CAACa,SAAS,IAAIH,GAAG,EAAE;IACtC;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from "../../plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin";
|
|
1
|
+
import { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from "../../plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js";
|
|
2
2
|
export declare const createTimeSearchPlugin: () => CmsEntryElasticsearchQueryBuilderValueSearchPlugin;
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createTimeSearchPlugin = void 0;
|
|
7
|
-
var _CmsEntryElasticsearchQueryBuilderValueSearchPlugin = require("../../plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin");
|
|
1
|
+
import { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from "../../plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js";
|
|
8
2
|
const transform = params => {
|
|
9
|
-
var _field$settings;
|
|
10
3
|
const {
|
|
11
4
|
field,
|
|
12
5
|
value
|
|
13
6
|
} = params;
|
|
14
|
-
if (!value ||
|
|
7
|
+
if (!value || field.settings?.type !== "time") {
|
|
15
8
|
return value;
|
|
16
9
|
}
|
|
17
10
|
const [hours, minutes, seconds = 0] = value.split(":").map(Number);
|
|
18
11
|
return hours * 60 * 60 + minutes * 60 + seconds;
|
|
19
12
|
};
|
|
20
|
-
const createTimeSearchPlugin = () => {
|
|
21
|
-
return new
|
|
13
|
+
export const createTimeSearchPlugin = () => {
|
|
14
|
+
return new CmsEntryElasticsearchQueryBuilderValueSearchPlugin({
|
|
22
15
|
fieldType: "datetime",
|
|
23
16
|
transform
|
|
24
17
|
});
|
|
25
18
|
};
|
|
26
|
-
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=timeSearch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["transform","params","field","value","settings","type","hours","minutes","seconds","split","map","Number","createTimeSearchPlugin","
|
|
1
|
+
{"version":3,"names":["CmsEntryElasticsearchQueryBuilderValueSearchPlugin","transform","params","field","value","settings","type","hours","minutes","seconds","split","map","Number","createTimeSearchPlugin","fieldType"],"sources":["timeSearch.ts"],"sourcesContent":["import type { TransformCallable } from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js\";\nimport { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js\";\n\nconst transform: TransformCallable = params => {\n const { field, value } = params;\n if (!value || field.settings?.type !== \"time\") {\n return value;\n }\n const [hours, minutes, seconds = 0] = value.split(\":\").map(Number);\n return hours * 60 * 60 + minutes * 60 + seconds;\n};\n\nexport const createTimeSearchPlugin = (): CmsEntryElasticsearchQueryBuilderValueSearchPlugin => {\n return new CmsEntryElasticsearchQueryBuilderValueSearchPlugin({\n fieldType: \"datetime\",\n transform\n });\n};\n"],"mappings":"AACA,SAASA,kDAAkD;AAE3D,MAAMC,SAA4B,GAAGC,MAAM,IAAI;EAC3C,MAAM;IAAEC,KAAK;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAC/B,IAAI,CAACE,KAAK,IAAID,KAAK,CAACE,QAAQ,EAAEC,IAAI,KAAK,MAAM,EAAE;IAC3C,OAAOF,KAAK;EAChB;EACA,MAAM,CAACG,KAAK,EAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,GAAGL,KAAK,CAACM,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAACC,MAAM,CAAC;EAClE,OAAOL,KAAK,GAAG,EAAE,GAAG,EAAE,GAAGC,OAAO,GAAG,EAAE,GAAGC,OAAO;AACnD,CAAC;AAED,OAAO,MAAMI,sBAAsB,GAAGA,CAAA,KAA0D;EAC5F,OAAO,IAAIb,kDAAkD,CAAC;IAC1Dc,SAAS,EAAE,UAAU;IACrBb;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import { CmsIndexEntry } from "../types";
|
|
3
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
1
|
+
import type { CmsEntry, CmsEntryValues, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { CmsIndexEntry } from "../types.js";
|
|
3
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
4
|
interface SetupEntriesIndexHelpersParams {
|
|
5
5
|
plugins: PluginsContainer;
|
|
6
6
|
}
|
|
7
|
-
interface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {
|
|
7
|
+
interface ExtractEntriesFromIndexParams<T extends CmsEntryValues = CmsEntryValues> extends SetupEntriesIndexHelpersParams {
|
|
8
8
|
model: CmsModel;
|
|
9
|
-
entries: CmsIndexEntry[];
|
|
9
|
+
entries: CmsIndexEntry<T>[];
|
|
10
10
|
}
|
|
11
|
-
interface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {
|
|
11
|
+
interface PrepareElasticsearchDataParams<T extends CmsEntryValues = CmsEntryValues> extends SetupEntriesIndexHelpersParams {
|
|
12
12
|
model: CmsModel;
|
|
13
|
-
entry: CmsEntry
|
|
14
|
-
storageEntry: CmsEntry
|
|
13
|
+
entry: CmsEntry<T>;
|
|
14
|
+
storageEntry: CmsEntry<T>;
|
|
15
15
|
}
|
|
16
|
-
export declare const prepareEntryToIndex: (params: PrepareElasticsearchDataParams) => CmsIndexEntry
|
|
17
|
-
export declare const extractEntriesFromIndex: ({ plugins, entries, model }: ExtractEntriesFromIndexParams) => CmsEntry[];
|
|
16
|
+
export declare const prepareEntryToIndex: <T extends CmsEntryValues = CmsEntryValues>(params: PrepareElasticsearchDataParams<T>) => CmsIndexEntry<T>;
|
|
17
|
+
export declare const extractEntriesFromIndex: <T extends CmsEntryValues = CmsEntryValues>({ plugins, entries, model }: ExtractEntriesFromIndexParams<T>) => CmsEntry<T>[];
|
|
18
18
|
export {};
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.prepareEntryToIndex = exports.extractEntriesFromIndex = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
const prepareEntryToIndex = params => {
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { getFieldIdentifier, getFieldIdentifiers } from "./fieldIdentifier.js";
|
|
3
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
4
|
+
export const prepareEntryToIndex = params => {
|
|
11
5
|
const {
|
|
12
6
|
plugins,
|
|
13
7
|
storageEntry,
|
|
@@ -21,15 +15,21 @@ const prepareEntryToIndex = params => {
|
|
|
21
15
|
} = setupEntriesIndexHelpers({
|
|
22
16
|
plugins
|
|
23
17
|
});
|
|
24
|
-
function getFieldIndexPlugin(
|
|
18
|
+
function getFieldIndexPlugin(type) {
|
|
19
|
+
const fieldType = getBaseFieldType({
|
|
20
|
+
type
|
|
21
|
+
});
|
|
25
22
|
return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;
|
|
26
23
|
}
|
|
27
|
-
function getFieldTypePlugin(
|
|
24
|
+
function getFieldTypePlugin(type) {
|
|
25
|
+
const fieldType = getBaseFieldType({
|
|
26
|
+
type
|
|
27
|
+
});
|
|
28
28
|
const pl = fieldTypePlugins[fieldType];
|
|
29
29
|
if (pl) {
|
|
30
30
|
return pl;
|
|
31
31
|
}
|
|
32
|
-
throw new
|
|
32
|
+
throw new WebinyError(`Missing field type plugin "${fieldType}". Prepare entry for index.`);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// These objects will contain values processed by field index plugins
|
|
@@ -38,7 +38,8 @@ const prepareEntryToIndex = params => {
|
|
|
38
38
|
|
|
39
39
|
// We're only interested in current model fields.
|
|
40
40
|
for (const field of model.fields) {
|
|
41
|
-
|
|
41
|
+
const identifier = getFieldIdentifier(storageEntry.values, field);
|
|
42
|
+
if (!identifier) {
|
|
42
43
|
continue;
|
|
43
44
|
}
|
|
44
45
|
const targetFieldPlugin = getFieldIndexPlugin(field.type);
|
|
@@ -54,24 +55,24 @@ const prepareEntryToIndex = params => {
|
|
|
54
55
|
plugins,
|
|
55
56
|
model,
|
|
56
57
|
field,
|
|
57
|
-
rawValue: entry.values[
|
|
58
|
-
value: storageEntry.values[
|
|
58
|
+
rawValue: entry.values[identifier],
|
|
59
|
+
value: storageEntry.values[identifier],
|
|
59
60
|
getFieldIndexPlugin,
|
|
60
61
|
getFieldTypePlugin
|
|
61
62
|
});
|
|
62
63
|
if (typeof value !== "undefined") {
|
|
63
|
-
values[
|
|
64
|
+
values[identifier] = value;
|
|
64
65
|
}
|
|
65
66
|
if (typeof rawValue !== "undefined") {
|
|
66
|
-
rawValues[
|
|
67
|
+
rawValues[identifier] = rawValue;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
return
|
|
70
|
+
return {
|
|
71
|
+
...storageEntry,
|
|
70
72
|
values,
|
|
71
73
|
rawValues
|
|
72
|
-
}
|
|
74
|
+
};
|
|
73
75
|
};
|
|
74
|
-
exports.prepareEntryToIndex = prepareEntryToIndex;
|
|
75
76
|
const setupEntriesIndexHelpers = ({
|
|
76
77
|
plugins: pluginsContainer
|
|
77
78
|
}) => {
|
|
@@ -87,7 +88,8 @@ const setupEntriesIndexHelpers = ({
|
|
|
87
88
|
const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === "*");
|
|
88
89
|
|
|
89
90
|
// CmsModelFieldToGraphQLPlugin plugins
|
|
90
|
-
const fieldTypePlugins = pluginsContainer.byType("cms-model-field-to-graphql").reduce((plugins, plugin) => (
|
|
91
|
+
const fieldTypePlugins = pluginsContainer.byType("cms-model-field-to-graphql").reduce((plugins, plugin) => ({
|
|
92
|
+
...plugins,
|
|
91
93
|
[plugin.fieldType]: plugin
|
|
92
94
|
}), {});
|
|
93
95
|
return {
|
|
@@ -96,7 +98,7 @@ const setupEntriesIndexHelpers = ({
|
|
|
96
98
|
fieldTypePlugins
|
|
97
99
|
};
|
|
98
100
|
};
|
|
99
|
-
const extractEntriesFromIndex = ({
|
|
101
|
+
export const extractEntriesFromIndex = ({
|
|
100
102
|
plugins,
|
|
101
103
|
entries,
|
|
102
104
|
model
|
|
@@ -108,10 +110,16 @@ const extractEntriesFromIndex = ({
|
|
|
108
110
|
} = setupEntriesIndexHelpers({
|
|
109
111
|
plugins
|
|
110
112
|
});
|
|
111
|
-
function getFieldIndexPlugin(
|
|
113
|
+
function getFieldIndexPlugin(type) {
|
|
114
|
+
const fieldType = getBaseFieldType({
|
|
115
|
+
type
|
|
116
|
+
});
|
|
112
117
|
return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;
|
|
113
118
|
}
|
|
114
|
-
function getFieldTypePlugin(
|
|
119
|
+
function getFieldTypePlugin(type) {
|
|
120
|
+
const fieldType = getBaseFieldType({
|
|
121
|
+
type
|
|
122
|
+
});
|
|
115
123
|
return fieldTypePlugins[fieldType];
|
|
116
124
|
}
|
|
117
125
|
const list = [];
|
|
@@ -121,29 +129,38 @@ const extractEntriesFromIndex = ({
|
|
|
121
129
|
|
|
122
130
|
// We only consider fields that are present in the model
|
|
123
131
|
for (const field of model.fields) {
|
|
124
|
-
const fieldTypePlugin =
|
|
132
|
+
const fieldTypePlugin = getFieldTypePlugin(field.type);
|
|
125
133
|
if (!fieldTypePlugin) {
|
|
126
|
-
throw new
|
|
134
|
+
throw new WebinyError(`Missing field type plugin "${field.type}". Extract entries from index.`);
|
|
127
135
|
}
|
|
128
136
|
const targetFieldPlugin = getFieldIndexPlugin(field.type);
|
|
129
137
|
if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {
|
|
130
138
|
continue;
|
|
131
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* We can safely cast as the code will not continue in case of no identifiers.
|
|
142
|
+
*/
|
|
143
|
+
const identifiers = getFieldIdentifiers(entry.values, entry.rawValues, field);
|
|
144
|
+
if (!identifiers) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
132
147
|
try {
|
|
133
|
-
|
|
148
|
+
const key = identifiers.valueIdentifier;
|
|
149
|
+
const rawKey = identifiers.rawValueIdentifier;
|
|
150
|
+
indexValues[key] = targetFieldPlugin.fromIndex({
|
|
134
151
|
plugins,
|
|
135
152
|
model,
|
|
136
153
|
field,
|
|
137
154
|
getFieldIndexPlugin,
|
|
138
155
|
getFieldTypePlugin,
|
|
139
|
-
value: entry.values[
|
|
156
|
+
value: entry.values[key || rawKey],
|
|
140
157
|
/**
|
|
141
158
|
* Possibly no rawValues so we must check for the existence of the field.
|
|
142
159
|
*/
|
|
143
|
-
rawValue: entry.rawValues ? entry.rawValues[
|
|
160
|
+
rawValue: entry.rawValues ? entry.rawValues[rawKey || key] : null
|
|
144
161
|
});
|
|
145
162
|
} catch (ex) {
|
|
146
|
-
throw new
|
|
163
|
+
throw new WebinyError(ex.message || "Could not transform entry field from index.", ex.code || "FIELD_FROM_INDEX_ERROR", {
|
|
147
164
|
field,
|
|
148
165
|
entry
|
|
149
166
|
});
|
|
@@ -152,24 +169,28 @@ const extractEntriesFromIndex = ({
|
|
|
152
169
|
/**
|
|
153
170
|
* Let's have a new entry so we do not modify the original one.
|
|
154
171
|
*/
|
|
155
|
-
const newEntry =
|
|
172
|
+
const newEntry = {
|
|
173
|
+
...entry,
|
|
156
174
|
values: indexValues
|
|
157
|
-
}
|
|
175
|
+
};
|
|
158
176
|
/**
|
|
159
177
|
* If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.
|
|
160
178
|
*/
|
|
161
|
-
// @ts-
|
|
179
|
+
// @ts-expect-error
|
|
162
180
|
delete newEntry["rawValues"];
|
|
163
|
-
// @ts-
|
|
181
|
+
// @ts-expect-error
|
|
164
182
|
delete newEntry["TYPE"];
|
|
165
|
-
// @ts-
|
|
183
|
+
// @ts-expect-error
|
|
166
184
|
delete newEntry["__type"];
|
|
167
|
-
// @ts-
|
|
185
|
+
// @ts-expect-error
|
|
168
186
|
delete newEntry["latest"];
|
|
169
|
-
// @ts-
|
|
187
|
+
// @ts-expect-error
|
|
170
188
|
delete newEntry["published"];
|
|
171
|
-
list.push(
|
|
189
|
+
list.push({
|
|
190
|
+
...newEntry
|
|
191
|
+
});
|
|
172
192
|
}
|
|
173
193
|
return list;
|
|
174
194
|
};
|
|
175
|
-
|
|
195
|
+
|
|
196
|
+
//# sourceMappingURL=entryIndexHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["prepareEntryToIndex","params","plugins","storageEntry","entry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","fieldType","getFieldTypePlugin","pl","WebinyError","values","rawValues","field","fields","hasOwnProperty","storageId","targetFieldPlugin","type","toIndex","value","rawValue","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","ex","message","code","newEntry","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface SetupEntriesIndexHelpersParams {\n plugins: PluginsContainer;\n}\n\ninterface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entries: CmsIndexEntry[];\n}\n\ninterface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entry: CmsEntry;\n storageEntry: CmsEntry;\n}\n\nexport const prepareEntryToIndex = (params: PrepareElasticsearchDataParams): CmsIndexEntry => {\n const { plugins, storageEntry, entry, model } = params;\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n const pl = fieldTypePlugins[fieldType];\n if (pl) {\n return pl;\n }\n throw new WebinyError(`Missing field type plugin \"${fieldType}\". Prepare entry for index.`);\n }\n\n // These objects will contain values processed by field index plugins\n const values: Record<string, string> = {};\n const rawValues: Record<string, string> = {};\n\n // We're only interested in current model fields.\n for (const field of model.fields) {\n if (storageEntry.values.hasOwnProperty(field.storageId) === false) {\n continue;\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n\n // TODO: remove this `if` once we convert this plugin to proper plugin class\n if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {\n continue;\n }\n\n const { value, rawValue } = targetFieldPlugin.toIndex({\n plugins,\n model,\n field,\n rawValue: entry.values[field.storageId],\n value: storageEntry.values[field.storageId],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[field.storageId] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[field.storageId] = rawValue;\n }\n }\n return {\n ...storageEntry,\n values,\n rawValues\n } as CmsIndexEntry;\n};\n\nconst setupEntriesIndexHelpers = ({\n plugins: pluginsContainer\n}: SetupEntriesIndexHelpersParams) => {\n const plugins = pluginsContainer.byType<CmsModelFieldToElasticsearchPlugin>(\n \"cms-model-field-to-elastic-search\"\n );\n\n const fieldIndexPlugins: Record<string, CmsModelFieldToElasticsearchPlugin> = {};\n for (const plugin of plugins.reverse()) {\n if (fieldIndexPlugins[plugin.fieldType]) {\n continue;\n }\n fieldIndexPlugins[plugin.fieldType] = plugin;\n }\n // we will use this plugin if no targeted plugin found\n const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === \"*\");\n\n // CmsModelFieldToGraphQLPlugin plugins\n const fieldTypePlugins: Record<string, CmsModelFieldToGraphQLPlugin> = pluginsContainer\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((plugins, plugin) => ({ ...plugins, [plugin.fieldType]: plugin }), {});\n\n return {\n fieldIndexPlugins,\n defaultIndexFieldPlugin,\n fieldTypePlugins\n };\n};\n\nexport const extractEntriesFromIndex = ({\n plugins,\n entries,\n model\n}: ExtractEntriesFromIndexParams): CmsEntry[] => {\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n return fieldTypePlugins[fieldType];\n }\n\n const list: CmsEntry[] = [];\n\n for (const entry of entries) {\n // This object will contain values processed by field index plugins\n const indexValues: Record<string, string> = {};\n\n // We only consider fields that are present in the model\n for (const field of model.fields) {\n const fieldTypePlugin = fieldTypePlugins[field.type];\n if (!fieldTypePlugin) {\n throw new WebinyError(\n `Missing field type plugin \"${field.type}\". Extract entries from index.`\n );\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {\n continue;\n }\n try {\n indexValues[field.storageId] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[field.storageId],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues ? entry.rawValues[field.storageId] : null\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not transform entry field from index.\",\n ex.code || \"FIELD_FROM_INDEX_ERROR\",\n {\n field,\n entry\n }\n );\n }\n }\n /**\n * Let's have a new entry so we do not modify the original one.\n */\n const newEntry: CmsEntry = {\n ...entry,\n values: indexValues\n };\n /**\n * If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.\n */\n // @ts-ignore\n delete newEntry[\"rawValues\"];\n // @ts-ignore\n delete newEntry[\"TYPE\"];\n // @ts-ignore\n delete newEntry[\"__type\"];\n // @ts-ignore\n delete newEntry[\"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QACnE,CAAC,CAAC;MACN,CAAC,CAAC,OAAOkB,EAAE,EAAE;QACT,MAAM,IAAIxB,cAAW,CACjBwB,EAAE,CAACC,OAAO,IAAI,6CAA6C,EAC3DD,EAAE,CAACE,IAAI,IAAI,wBAAwB,EACnC;UACIvB,KAAK;UACLb;QACJ,CAAC,CACJ;MACL;IACJ;IACA;AACR;AACA;IACQ,MAAMqC,QAAkB,+DACjBrC,KAAK;MACRW,MAAM,EAAEoB;IAAW,EACtB;IACD;AACR;AACA;IACQ;IACA,OAAOM,QAAQ,CAAC,WAAW,CAAC;IAC5B;IACA,OAAOA,QAAQ,CAAC,MAAM,CAAC;IACvB;IACA,OAAOA,QAAQ,CAAC,QAAQ,CAAC;IACzB;IACA,OAAOA,QAAQ,CAAC,QAAQ,CAAC;IACzB;IACA,OAAOA,QAAQ,CAAC,WAAW,CAAC;IAC5BP,IAAI,CAACQ,IAAI,iCAAMD,QAAQ,EAAG;EAC9B;EAEA,OAAOP,IAAI;AACf,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["WebinyError","getFieldIdentifier","getFieldIdentifiers","getBaseFieldType","prepareEntryToIndex","params","plugins","storageEntry","entry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","type","fieldType","getFieldTypePlugin","pl","values","rawValues","field","fields","identifier","targetFieldPlugin","toIndex","value","rawValue","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","identifiers","key","valueIdentifier","rawKey","rawValueIdentifier","ex","message","code","newEntry","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelFieldToGraphQLPlugin\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { getFieldIdentifier, getFieldIdentifiers } from \"~/helpers/fieldIdentifier.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface SetupEntriesIndexHelpersParams {\n plugins: PluginsContainer;\n}\n\ninterface ExtractEntriesFromIndexParams<T extends CmsEntryValues = CmsEntryValues>\n extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entries: CmsIndexEntry<T>[];\n}\n\ninterface PrepareElasticsearchDataParams<T extends CmsEntryValues = CmsEntryValues>\n extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entry: CmsEntry<T>;\n storageEntry: CmsEntry<T>;\n}\n\nexport const prepareEntryToIndex = <T extends CmsEntryValues = CmsEntryValues>(\n params: PrepareElasticsearchDataParams<T>\n): CmsIndexEntry<T> => {\n const { plugins, storageEntry, entry, model } = params;\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(type: string) {\n const fieldType = getBaseFieldType({\n type\n });\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(type: string) {\n const fieldType = getBaseFieldType({\n type\n });\n const pl = fieldTypePlugins[fieldType];\n if (pl) {\n return pl;\n }\n throw new WebinyError(`Missing field type plugin \"${fieldType}\". Prepare entry for index.`);\n }\n\n // These objects will contain values processed by field index plugins\n const values: T = {} as T;\n const rawValues: T = {} as T;\n\n // We're only interested in current model fields.\n for (const field of model.fields) {\n const identifier = getFieldIdentifier(storageEntry.values, field) as keyof T;\n if (!identifier) {\n continue;\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n\n // TODO: remove this `if` once we convert this plugin to proper plugin class\n if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {\n continue;\n }\n\n const { value, rawValue } = targetFieldPlugin.toIndex({\n plugins,\n model,\n field,\n rawValue: entry.values[identifier],\n value: storageEntry.values[identifier],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[identifier] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[identifier] = rawValue;\n }\n }\n return {\n ...storageEntry,\n values,\n rawValues\n };\n};\n\nconst setupEntriesIndexHelpers = ({\n plugins: pluginsContainer\n}: SetupEntriesIndexHelpersParams) => {\n const plugins = pluginsContainer.byType<CmsModelFieldToElasticsearchPlugin>(\n \"cms-model-field-to-elastic-search\"\n );\n\n const fieldIndexPlugins: Record<string, CmsModelFieldToElasticsearchPlugin> = {};\n for (const plugin of plugins.reverse()) {\n if (fieldIndexPlugins[plugin.fieldType]) {\n continue;\n }\n fieldIndexPlugins[plugin.fieldType] = plugin;\n }\n // we will use this plugin if no targeted plugin found\n const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === \"*\");\n\n // CmsModelFieldToGraphQLPlugin plugins\n const fieldTypePlugins: Record<string, CmsModelFieldToGraphQLPlugin> = pluginsContainer\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((plugins, plugin) => ({ ...plugins, [plugin.fieldType]: plugin }), {});\n\n return {\n fieldIndexPlugins,\n defaultIndexFieldPlugin,\n fieldTypePlugins\n };\n};\n\nexport const extractEntriesFromIndex = <T extends CmsEntryValues = CmsEntryValues>({\n plugins,\n entries,\n model\n}: ExtractEntriesFromIndexParams<T>): CmsEntry<T>[] => {\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(type: string) {\n const fieldType = getBaseFieldType({\n type\n });\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(type: string) {\n const fieldType = getBaseFieldType({\n type\n });\n return fieldTypePlugins[fieldType];\n }\n\n const list: CmsEntry<T>[] = [];\n\n for (const entry of entries) {\n // This object will contain values processed by field index plugins\n const indexValues: T = {} as T;\n\n // We only consider fields that are present in the model\n for (const field of model.fields) {\n const fieldTypePlugin = getFieldTypePlugin(field.type);\n if (!fieldTypePlugin) {\n throw new WebinyError(\n `Missing field type plugin \"${field.type}\". Extract entries from index.`\n );\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {\n continue;\n }\n /**\n * We can safely cast as the code will not continue in case of no identifiers.\n */\n const identifiers = getFieldIdentifiers(entry.values, entry.rawValues, field);\n if (!identifiers) {\n continue;\n }\n\n try {\n const key = identifiers.valueIdentifier as keyof T;\n const rawKey = identifiers.rawValueIdentifier as keyof T;\n indexValues[key] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[key || rawKey],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues ? entry.rawValues[rawKey || key] : null\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not transform entry field from index.\",\n ex.code || \"FIELD_FROM_INDEX_ERROR\",\n {\n field,\n entry\n }\n );\n }\n }\n /**\n * Let's have a new entry so we do not modify the original one.\n */\n const newEntry: CmsEntry<T> = {\n ...entry,\n values: indexValues\n };\n /**\n * If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.\n */\n // @ts-expect-error\n delete newEntry[\"rawValues\"];\n // @ts-expect-error\n delete newEntry[\"TYPE\"];\n // @ts-expect-error\n delete newEntry[\"__type\"];\n // @ts-expect-error\n delete newEntry[\"latest\"];\n // @ts-expect-error\n delete newEntry[\"published\"];\n list.push({\n ...newEntry\n });\n }\n\n return list;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AASvC,SAASC,kBAAkB,EAAEC,mBAAmB;AAChD,SAASC,gBAAgB,QAAQ,oDAAoD;AAmBrF,OAAO,MAAMC,mBAAmB,GAC5BC,MAAyC,IACtB;EACnB,MAAM;IAAEC,OAAO;IAAEC,YAA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xDP,WAAW,CAACI,GAAG,CAAC,GAAGjB,iBAAiB,CAACe,SAAS,CAAC;UAC3CjC,OAAO;UACPG,KAAK;UACLY,KAAK;UACLP,mBAAmB;UACnBG,kBAAkB;UAClBS,KAAK,EAAElB,KAAK,CAACW,MAAM,CAACsB,GAAG,IAAIE,MAAM,CAAC;UAClC;AACpB;AACA;UACoBhB,QAAQ,EAAEnB,KAAK,CAACY,SAAS,GAAGZ,KAAK,CAACY,SAAS,CAACuB,MAAM,IAAIF,GAAG,CAAC,GAAG;QACjE,CAAC,CAAC;MACN,CAAC,CAAC,OAAOI,EAAE,EAAE;QACT,MAAM,IAAI7C,WAAW,CACjB6C,EAAE,CAACC,OAAO,IAAI,6CAA6C,EAC3DD,EAAE,CAACE,IAAI,IAAI,wBAAwB,EACnC;UACI1B,KAAK;UACLb;QACJ,CACJ,CAAC;MACL;IACJ;IACA;AACR;AACA;IACQ,MAAMwC,QAAqB,GAAG;MAC1B,GAAGxC,KAAK;MACRW,MAAM,EAAEkB;IACZ,CAAC;IACD;AACR;AACA;IACQ;IACA,OAAOW,QAAQ,CAAC,WAAW,CAAC;IAC5B;IACA,OAAOA,QAAQ,CAAC,MAAM,CAAC;IACvB;IACA,OAAOA,QAAQ,CAAC,QAAQ,CAAC;IACzB;IACA,OAAOA,QAAQ,CAAC,QAAQ,CAAC;IACzB;IACA,OAAOA,QAAQ,CAAC,WAAW,CAAC;IAC5BZ,IAAI,CAACa,IAAI,CAAC;MACN,GAAGD;IACP,CAAC,CAAC;EACN;EAEA,OAAOZ,IAAI;AACf,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CmsEntryValues, CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
export declare const getFieldIdentifier: (values: CmsEntryValues | null | undefined, field: CmsModelField) => string | undefined;
|
|
3
|
+
export declare const getFieldIdentifiers: (values: CmsEntryValues, rawValues: CmsEntryValues | null | undefined, field: CmsModelField) => {
|
|
4
|
+
valueIdentifier: string;
|
|
5
|
+
rawValueIdentifier: string;
|
|
6
|
+
} | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const hasOwnProperty = (values = {}, property) => {
|
|
2
|
+
if (!values) {
|
|
3
|
+
return false;
|
|
4
|
+
} else if (values.hasOwnProperty) {
|
|
5
|
+
return values.hasOwnProperty(property);
|
|
6
|
+
}
|
|
7
|
+
return values[property] !== undefined;
|
|
8
|
+
};
|
|
9
|
+
export const getFieldIdentifier = (values, field) => {
|
|
10
|
+
if (field.storageId && hasOwnProperty(values, field.storageId)) {
|
|
11
|
+
return field.storageId;
|
|
12
|
+
} else if (hasOwnProperty(values, field.fieldId)) {
|
|
13
|
+
return field.fieldId;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
};
|
|
17
|
+
export const getFieldIdentifiers = (values, rawValues, field) => {
|
|
18
|
+
let valueIdentifier = getFieldIdentifier(values, field);
|
|
19
|
+
let rawValueIdentifier = getFieldIdentifier(rawValues, field);
|
|
20
|
+
if (!valueIdentifier && !rawValueIdentifier) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (!valueIdentifier) {
|
|
24
|
+
valueIdentifier = rawValueIdentifier;
|
|
25
|
+
}
|
|
26
|
+
if (!rawValueIdentifier) {
|
|
27
|
+
rawValueIdentifier = valueIdentifier;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
valueIdentifier,
|
|
31
|
+
rawValueIdentifier
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=fieldIdentifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["hasOwnProperty","values","property","undefined","getFieldIdentifier","field","storageId","fieldId","getFieldIdentifiers","rawValues","valueIdentifier","rawValueIdentifier"],"sources":["fieldIdentifier.ts"],"sourcesContent":["import type { CmsEntryValues, CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst hasOwnProperty = (\n values: CmsEntryValues | null | undefined = {},\n property: string\n): boolean => {\n if (!values) {\n return false;\n } else if (values.hasOwnProperty) {\n return values.hasOwnProperty(property);\n }\n return values[property] !== undefined;\n};\n\nexport const getFieldIdentifier = (\n values: CmsEntryValues | null | undefined,\n field: CmsModelField\n): string | undefined => {\n if (field.storageId && hasOwnProperty(values, field.storageId)) {\n return field.storageId;\n } else if (hasOwnProperty(values, field.fieldId)) {\n return field.fieldId;\n }\n return undefined;\n};\n\nexport const getFieldIdentifiers = (\n values: CmsEntryValues,\n rawValues: CmsEntryValues | null | undefined,\n field: CmsModelField\n) => {\n let valueIdentifier = getFieldIdentifier(values, field);\n let rawValueIdentifier = getFieldIdentifier(rawValues, field);\n if (!valueIdentifier && !rawValueIdentifier) {\n return null;\n }\n if (!valueIdentifier) {\n valueIdentifier = rawValueIdentifier as string;\n }\n if (!rawValueIdentifier) {\n rawValueIdentifier = valueIdentifier as string;\n }\n return {\n valueIdentifier,\n rawValueIdentifier\n };\n};\n"],"mappings":"AAEA,MAAMA,cAAc,GAAGA,CACnBC,MAAyC,GAAG,CAAC,CAAC,EAC9CC,QAAgB,KACN;EACV,IAAI,CAACD,MAAM,EAAE;IACT,OAAO,KAAK;EAChB,CAAC,MAAM,IAAIA,MAAM,CAACD,cAAc,EAAE;IAC9B,OAAOC,MAAM,CAACD,cAAc,CAACE,QAAQ,CAAC;EAC1C;EACA,OAAOD,MAAM,CAACC,QAAQ,CAAC,KAAKC,SAAS;AACzC,CAAC;AAED,OAAO,MAAMC,kBAAkB,GAAGA,CAC9BH,MAAyC,EACzCI,KAAoB,KACC;EACrB,IAAIA,KAAK,CAACC,SAAS,IAAIN,cAAc,CAACC,MAAM,EAAEI,KAAK,CAACC,SAAS,CAAC,EAAE;IAC5D,OAAOD,KAAK,CAACC,SAAS;EAC1B,CAAC,MAAM,IAAIN,cAAc,CAACC,MAAM,EAAEI,KAAK,CAACE,OAAO,CAAC,EAAE;IAC9C,OAAOF,KAAK,CAACE,OAAO;EACxB;EACA,OAAOJ,SAAS;AACpB,CAAC;AAED,OAAO,MAAMK,mBAAmB,GAAGA,CAC/BP,MAAsB,EACtBQ,SAA4C,EAC5CJ,KAAoB,KACnB;EACD,IAAIK,eAAe,GAAGN,kBAAkB,CAACH,MAAM,EAAEI,KAAK,CAAC;EACvD,IAAIM,kBAAkB,GAAGP,kBAAkB,CAACK,SAAS,EAAEJ,KAAK,CAAC;EAC7D,IAAI,CAACK,eAAe,IAAI,CAACC,kBAAkB,EAAE;IACzC,OAAO,IAAI;EACf;EACA,IAAI,CAACD,eAAe,EAAE;IAClBA,eAAe,GAAGC,kBAA4B;EAClD;EACA,IAAI,CAACA,kBAAkB,EAAE;IACrBA,kBAAkB,GAAGD,eAAyB;EAClD;EACA,OAAO;IACHA,eAAe;IACfC;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
package/helpers/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./entryIndexHelpers";
|
|
1
|
+
export * from "./entryIndexHelpers.js";
|
|
2
|
+
export * from "./fieldIdentifier.js";
|
package/helpers/index.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export * from "./entryIndexHelpers.js";
|
|
2
|
+
export * from "./fieldIdentifier.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _entryIndexHelpers = require("./entryIndexHelpers");
|
|
7
|
-
Object.keys(_entryIndexHelpers).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _entryIndexHelpers[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _entryIndexHelpers[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
package/helpers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./entryIndexHelpers\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./entryIndexHelpers.js\";\nexport * from \"./fieldIdentifier.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { StorageOperationsFactory } from "./types";
|
|
2
|
-
export * from "./plugins";
|
|
1
|
+
import type { StorageOperationsFactory } from "./types.js";
|
|
2
|
+
export * from "./plugins/index.js";
|
|
3
3
|
export declare const createStorageOperations: StorageOperationsFactory;
|