@webiny/api-headless-cms-ddb-es 0.0.0-mt-1
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/LICENSE +21 -0
- package/README.md +35 -0
- package/configurations.d.ts +12 -0
- package/configurations.js +32 -0
- package/definitions/entry.d.ts +8 -0
- package/definitions/entry.js +91 -0
- package/definitions/entryElasticsearch.d.ts +8 -0
- package/definitions/entryElasticsearch.js +46 -0
- package/definitions/group.d.ts +8 -0
- package/definitions/group.js +74 -0
- package/definitions/model.d.ts +8 -0
- package/definitions/model.js +96 -0
- package/definitions/settings.d.ts +8 -0
- package/definitions/settings.js +62 -0
- package/definitions/system.d.ts +8 -0
- package/definitions/system.js +50 -0
- package/definitions/table.d.ts +8 -0
- package/definitions/table.js +24 -0
- package/definitions/tableElasticsearch.d.ts +8 -0
- package/definitions/tableElasticsearch.js +24 -0
- package/dynamoDb/index.d.ts +2 -0
- package/dynamoDb/index.js +18 -0
- package/dynamoDb/storage/date.d.ts +3 -0
- package/dynamoDb/storage/date.js +65 -0
- package/dynamoDb/storage/longText.d.ts +7 -0
- package/dynamoDb/storage/longText.js +83 -0
- package/dynamoDb/storage/richText.d.ts +8 -0
- package/dynamoDb/storage/richText.js +110 -0
- package/elasticsearch/index.d.ts +2 -0
- package/elasticsearch/index.js +16 -0
- package/elasticsearch/indexing/dateTimeIndexing.d.ts +3 -0
- package/elasticsearch/indexing/dateTimeIndexing.js +89 -0
- package/elasticsearch/indexing/defaultFieldIndexing.d.ts +3 -0
- package/elasticsearch/indexing/defaultFieldIndexing.js +47 -0
- package/elasticsearch/indexing/index.d.ts +2 -0
- package/elasticsearch/indexing/index.js +24 -0
- package/elasticsearch/indexing/longTextIndexing.d.ts +3 -0
- package/elasticsearch/indexing/longTextIndexing.js +36 -0
- package/elasticsearch/indexing/numberIndexing.d.ts +3 -0
- package/elasticsearch/indexing/numberIndexing.js +48 -0
- package/elasticsearch/indexing/objectIndexing.d.ts +3 -0
- package/elasticsearch/indexing/objectIndexing.js +200 -0
- package/elasticsearch/indexing/richTextIndexing.d.ts +3 -0
- package/elasticsearch/indexing/richTextIndexing.js +34 -0
- package/elasticsearch/search/index.d.ts +3 -0
- package/elasticsearch/search/index.js +16 -0
- package/elasticsearch/search/refSearch.d.ts +3 -0
- package/elasticsearch/search/refSearch.js +24 -0
- package/elasticsearch/search/timeSearch.d.ts +3 -0
- package/elasticsearch/search/timeSearch.js +25 -0
- package/helpers/createElasticsearchQueryBody.d.ts +11 -0
- package/helpers/createElasticsearchQueryBody.js +375 -0
- package/helpers/entryIndexHelpers.d.ts +18 -0
- package/helpers/entryIndexHelpers.js +189 -0
- package/helpers/fields.d.ts +77 -0
- package/helpers/fields.js +174 -0
- package/helpers/index.d.ts +2 -0
- package/helpers/index.js +31 -0
- package/helpers/operatorPluginsList.d.ts +7 -0
- package/helpers/operatorPluginsList.js +30 -0
- package/helpers/searchPluginsList.d.ts +6 -0
- package/helpers/searchPluginsList.js +26 -0
- package/helpers/transformValueForSearch.d.ts +9 -0
- package/helpers/transformValueForSearch.js +26 -0
- package/index.d.ts +2 -0
- package/index.js +171 -0
- package/operations/entry/dataLoaders.d.ts +47 -0
- package/operations/entry/dataLoaders.js +347 -0
- package/operations/entry/elasticsearchFields.d.ts +2 -0
- package/operations/entry/elasticsearchFields.js +32 -0
- package/operations/entry/fields.d.ts +3 -0
- package/operations/entry/fields.js +60 -0
- package/operations/entry/index.d.ts +13 -0
- package/operations/entry/index.js +1152 -0
- package/operations/entry/keys.d.ts +12 -0
- package/operations/entry/keys.js +40 -0
- package/operations/group/index.d.ts +8 -0
- package/operations/group/index.js +202 -0
- package/operations/model/index.d.ts +8 -0
- package/operations/model/index.js +205 -0
- package/operations/settings/index.d.ts +6 -0
- package/operations/settings/index.js +141 -0
- package/operations/system/createElasticsearchTemplate.d.ts +5 -0
- package/operations/system/createElasticsearchTemplate.js +62 -0
- package/operations/system/index.d.ts +6 -0
- package/operations/system/index.js +105 -0
- package/package.json +73 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +12 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +24 -0
- package/types.d.ts +191 -0
- package/types.js +60 -0
- package/upgrades/index.d.ts +2 -0
- package/upgrades/index.js +16 -0
- package/upgrades/utils.d.ts +1 -0
- package/upgrades/utils.js +16 -0
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +6 -0
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +16 -0
- package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +2 -0
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +12 -0
- package/upgrades/v5.0.0/entryValueFixer.d.ts +4 -0
- package/upgrades/v5.0.0/entryValueFixer.js +124 -0
- package/upgrades/v5.0.0/fieldFinder.d.ts +6 -0
- package/upgrades/v5.0.0/fieldFinder.js +42 -0
- package/upgrades/v5.0.0/helpers.d.ts +4 -0
- package/upgrades/v5.0.0/helpers.js +57 -0
- package/upgrades/v5.0.0/index.d.ts +4 -0
- package/upgrades/v5.0.0/index.js +232 -0
- package/upgrades/v5.8.0/index.d.ts +4 -0
- package/upgrades/v5.8.0/index.js +426 -0
package/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
|
|
11
|
+
|
|
12
|
+
var _elasticsearch = _interopRequireDefault(require("./elasticsearch"));
|
|
13
|
+
|
|
14
|
+
var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
|
|
15
|
+
|
|
16
|
+
var _settings = require("./operations/settings");
|
|
17
|
+
|
|
18
|
+
var _system = require("./operations/system");
|
|
19
|
+
|
|
20
|
+
var _model = require("./operations/model");
|
|
21
|
+
|
|
22
|
+
var _entry = require("./operations/entry");
|
|
23
|
+
|
|
24
|
+
var _types = require("./types");
|
|
25
|
+
|
|
26
|
+
var _table = require("./definitions/table");
|
|
27
|
+
|
|
28
|
+
var _tableElasticsearch = require("./definitions/tableElasticsearch");
|
|
29
|
+
|
|
30
|
+
var _group = require("./definitions/group");
|
|
31
|
+
|
|
32
|
+
var _model2 = require("./definitions/model");
|
|
33
|
+
|
|
34
|
+
var _entry2 = require("./definitions/entry");
|
|
35
|
+
|
|
36
|
+
var _entryElasticsearch = require("./definitions/entryElasticsearch");
|
|
37
|
+
|
|
38
|
+
var _system2 = require("./definitions/system");
|
|
39
|
+
|
|
40
|
+
var _settings2 = require("./definitions/settings");
|
|
41
|
+
|
|
42
|
+
var _createElasticsearchTemplate = require("./operations/system/createElasticsearchTemplate");
|
|
43
|
+
|
|
44
|
+
var _plugins = require("@webiny/plugins");
|
|
45
|
+
|
|
46
|
+
var _group2 = require("./operations/group");
|
|
47
|
+
|
|
48
|
+
var _operators = require("@webiny/api-elasticsearch/operators");
|
|
49
|
+
|
|
50
|
+
var _elasticsearchFields = require("./operations/entry/elasticsearchFields");
|
|
51
|
+
|
|
52
|
+
const createStorageOperations = params => {
|
|
53
|
+
const {
|
|
54
|
+
attributes = {},
|
|
55
|
+
table,
|
|
56
|
+
esTable,
|
|
57
|
+
documentClient,
|
|
58
|
+
elasticsearch,
|
|
59
|
+
plugins: customPlugins,
|
|
60
|
+
modelFieldToGraphQLPlugins
|
|
61
|
+
} = params;
|
|
62
|
+
const tableInstance = (0, _table.createTable)({
|
|
63
|
+
table,
|
|
64
|
+
documentClient
|
|
65
|
+
});
|
|
66
|
+
const tableElasticsearchInstance = (0, _tableElasticsearch.createElasticsearchTable)({
|
|
67
|
+
table: esTable,
|
|
68
|
+
documentClient
|
|
69
|
+
});
|
|
70
|
+
const entities = {
|
|
71
|
+
settings: (0, _settings2.createSettingsEntity)({
|
|
72
|
+
entityName: _types.ENTITIES.SETTINGS,
|
|
73
|
+
table: tableInstance,
|
|
74
|
+
attributes: attributes[_types.ENTITIES.SETTINGS]
|
|
75
|
+
}),
|
|
76
|
+
system: (0, _system2.createSystemEntity)({
|
|
77
|
+
entityName: _types.ENTITIES.SYSTEM,
|
|
78
|
+
table: tableInstance,
|
|
79
|
+
attributes: attributes[_types.ENTITIES.SYSTEM]
|
|
80
|
+
}),
|
|
81
|
+
groups: (0, _group.createGroupEntity)({
|
|
82
|
+
entityName: _types.ENTITIES.GROUPS,
|
|
83
|
+
table: tableInstance,
|
|
84
|
+
attributes: attributes[_types.ENTITIES.GROUPS]
|
|
85
|
+
}),
|
|
86
|
+
models: (0, _model2.createModelEntity)({
|
|
87
|
+
entityName: _types.ENTITIES.MODELS,
|
|
88
|
+
table: tableInstance,
|
|
89
|
+
attributes: attributes[_types.ENTITIES.MODELS]
|
|
90
|
+
}),
|
|
91
|
+
entries: (0, _entry2.createEntryEntity)({
|
|
92
|
+
entityName: _types.ENTITIES.ENTRIES,
|
|
93
|
+
table: tableInstance,
|
|
94
|
+
attributes: attributes[_types.ENTITIES.ENTRIES]
|
|
95
|
+
}),
|
|
96
|
+
entriesEs: (0, _entryElasticsearch.createEntryElasticsearchEntity)({
|
|
97
|
+
entityName: _types.ENTITIES.ENTRIES_ES,
|
|
98
|
+
table: tableElasticsearchInstance,
|
|
99
|
+
attributes: attributes[_types.ENTITIES.ENTRIES_ES]
|
|
100
|
+
})
|
|
101
|
+
};
|
|
102
|
+
const plugins = new _plugins.PluginsContainer([
|
|
103
|
+
/**
|
|
104
|
+
* User defined custom plugins.
|
|
105
|
+
*/
|
|
106
|
+
...(customPlugins || []),
|
|
107
|
+
/**
|
|
108
|
+
* Plugins of type CmsModelFieldToGraphQLPlugin.
|
|
109
|
+
*/
|
|
110
|
+
modelFieldToGraphQLPlugins,
|
|
111
|
+
/**
|
|
112
|
+
* Elasticsearch field definitions for the entry record.
|
|
113
|
+
*/
|
|
114
|
+
_elasticsearchFields.elasticsearchFields,
|
|
115
|
+
/**
|
|
116
|
+
* DynamoDB filter plugins for the where conditions.
|
|
117
|
+
*/
|
|
118
|
+
(0, _filters.default)(),
|
|
119
|
+
/**
|
|
120
|
+
* Elasticsearch operators.
|
|
121
|
+
*/
|
|
122
|
+
(0, _operators.getElasticsearchOperators)(),
|
|
123
|
+
/**
|
|
124
|
+
* Field plugins for DynamoDB.
|
|
125
|
+
*/
|
|
126
|
+
(0, _dynamoDb.default)(),
|
|
127
|
+
/**
|
|
128
|
+
* Field plugins for Elasticsearch.
|
|
129
|
+
*/
|
|
130
|
+
(0, _elasticsearch.default)()]);
|
|
131
|
+
return {
|
|
132
|
+
init: async cms => {
|
|
133
|
+
cms.onBeforeSystemInstall.subscribe(async () => {
|
|
134
|
+
await (0, _createElasticsearchTemplate.createElasticsearchTemplate)({
|
|
135
|
+
elasticsearch
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
plugins: [
|
|
140
|
+
/**
|
|
141
|
+
* Field plugins for DynamoDB.
|
|
142
|
+
* We must pass them to the base application.
|
|
143
|
+
*/
|
|
144
|
+
(0, _dynamoDb.default)()],
|
|
145
|
+
getEntities: () => entities,
|
|
146
|
+
getTable: () => tableInstance,
|
|
147
|
+
getEsTable: () => tableElasticsearchInstance,
|
|
148
|
+
system: (0, _system.createSystemStorageOperations)({
|
|
149
|
+
entity: entities.system
|
|
150
|
+
}),
|
|
151
|
+
settings: (0, _settings.createSettingsStorageOperations)({
|
|
152
|
+
entity: entities.settings
|
|
153
|
+
}),
|
|
154
|
+
groups: (0, _group2.createGroupsStorageOperations)({
|
|
155
|
+
entity: entities.groups,
|
|
156
|
+
plugins
|
|
157
|
+
}),
|
|
158
|
+
models: (0, _model.createModelsStorageOperations)({
|
|
159
|
+
entity: entities.models,
|
|
160
|
+
elasticsearch
|
|
161
|
+
}),
|
|
162
|
+
entries: (0, _entry.createEntriesStorageOperations)({
|
|
163
|
+
entity: entities.entries,
|
|
164
|
+
esEntity: entities.entriesEs,
|
|
165
|
+
plugins,
|
|
166
|
+
elasticsearch
|
|
167
|
+
})
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
exports.createStorageOperations = createStorageOperations;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Entity } from "dynamodb-toolbox";
|
|
3
|
+
export interface GetAllEntryRevisionsParams {
|
|
4
|
+
ids: readonly string[];
|
|
5
|
+
model: CmsModel;
|
|
6
|
+
}
|
|
7
|
+
export interface GetRevisionByIdParams {
|
|
8
|
+
ids: readonly string[];
|
|
9
|
+
model: CmsModel;
|
|
10
|
+
}
|
|
11
|
+
export interface GetPublishedRevisionByEntryIdParams {
|
|
12
|
+
ids: readonly string[];
|
|
13
|
+
model: CmsModel;
|
|
14
|
+
}
|
|
15
|
+
export interface GetLatestRevisionByEntryIdParams {
|
|
16
|
+
ids: readonly string[];
|
|
17
|
+
model: CmsModel;
|
|
18
|
+
}
|
|
19
|
+
interface ClearLoaderParams {
|
|
20
|
+
model: CmsModel;
|
|
21
|
+
entry?: CmsEntry;
|
|
22
|
+
}
|
|
23
|
+
export interface Params {
|
|
24
|
+
entity: Entity<any>;
|
|
25
|
+
}
|
|
26
|
+
export declare class DataLoadersHandler {
|
|
27
|
+
private readonly loaders;
|
|
28
|
+
private readonly entity;
|
|
29
|
+
constructor(params: any);
|
|
30
|
+
getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsEntry[]>;
|
|
31
|
+
clearAllEntryRevisions(params: ClearLoaderParams): void;
|
|
32
|
+
getRevisionById(params: GetRevisionByIdParams): Promise<CmsEntry[]>;
|
|
33
|
+
clearRevisionById(params: ClearLoaderParams): void;
|
|
34
|
+
getPublishedRevisionByEntryId(params: GetPublishedRevisionByEntryIdParams): Promise<CmsEntry[]>;
|
|
35
|
+
clearPublishedRevisionByEntryId(params: ClearLoaderParams): void;
|
|
36
|
+
getLatestRevisionByEntryId(params: GetLatestRevisionByEntryIdParams): Promise<CmsEntry[]>;
|
|
37
|
+
clearLatestRevisionByEntryId(params: ClearLoaderParams): void;
|
|
38
|
+
private getLoader;
|
|
39
|
+
private loadMany;
|
|
40
|
+
clearAll(params: Omit<ClearLoaderParams, "entry">): void;
|
|
41
|
+
/**
|
|
42
|
+
* Helper to clear the cache for certain data loader.
|
|
43
|
+
* If entry is passed then clear target key only.
|
|
44
|
+
*/
|
|
45
|
+
private clear;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.DataLoadersHandler = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
17
|
+
|
|
18
|
+
var _keys = require("./keys");
|
|
19
|
+
|
|
20
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
21
|
+
|
|
22
|
+
var _utils = require("@webiny/utils");
|
|
23
|
+
|
|
24
|
+
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
29
|
+
|
|
30
|
+
const getAllEntryRevisions = params => {
|
|
31
|
+
const {
|
|
32
|
+
entity,
|
|
33
|
+
model
|
|
34
|
+
} = params;
|
|
35
|
+
const {
|
|
36
|
+
tenant,
|
|
37
|
+
locale
|
|
38
|
+
} = model;
|
|
39
|
+
return new _dataloader.default(async ids => {
|
|
40
|
+
const results = [];
|
|
41
|
+
|
|
42
|
+
for (const id of ids) {
|
|
43
|
+
const queryAllParams = {
|
|
44
|
+
entity,
|
|
45
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
46
|
+
tenant,
|
|
47
|
+
locale,
|
|
48
|
+
id
|
|
49
|
+
}),
|
|
50
|
+
options: {
|
|
51
|
+
beginsWith: "REV#"
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const items = await (0, _query.queryAll)(queryAllParams);
|
|
55
|
+
const entries = (0, _cleanup.cleanupItems)(entity, items);
|
|
56
|
+
results.push(entries);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return results;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getRevisionById = params => {
|
|
64
|
+
const {
|
|
65
|
+
entity,
|
|
66
|
+
model
|
|
67
|
+
} = params;
|
|
68
|
+
const {
|
|
69
|
+
locale,
|
|
70
|
+
tenant
|
|
71
|
+
} = model;
|
|
72
|
+
return new _dataloader.default(async ids => {
|
|
73
|
+
const queries = ids.reduce((collection, id) => {
|
|
74
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
75
|
+
tenant,
|
|
76
|
+
locale,
|
|
77
|
+
id
|
|
78
|
+
});
|
|
79
|
+
const {
|
|
80
|
+
version
|
|
81
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
82
|
+
const sortKey = (0, _keys.createRevisionSortKey)({
|
|
83
|
+
version
|
|
84
|
+
});
|
|
85
|
+
const keys = `${partitionKey}__${sortKey}`;
|
|
86
|
+
|
|
87
|
+
if (collection[keys]) {
|
|
88
|
+
return collection;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
collection[keys] = entity.getBatch({
|
|
92
|
+
PK: partitionKey,
|
|
93
|
+
SK: sortKey
|
|
94
|
+
});
|
|
95
|
+
return collection;
|
|
96
|
+
}, {});
|
|
97
|
+
const records = await (0, _batchRead.batchReadAll)({
|
|
98
|
+
table: entity.table,
|
|
99
|
+
items: Object.values(queries)
|
|
100
|
+
});
|
|
101
|
+
const items = (0, _cleanup.cleanupItems)(entity, records);
|
|
102
|
+
return ids.map(id => {
|
|
103
|
+
return items.filter(item => {
|
|
104
|
+
return id === item.id;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const getPublishedRevisionByEntryId = params => {
|
|
111
|
+
const {
|
|
112
|
+
entity,
|
|
113
|
+
model
|
|
114
|
+
} = params;
|
|
115
|
+
const {
|
|
116
|
+
locale,
|
|
117
|
+
tenant
|
|
118
|
+
} = model;
|
|
119
|
+
const publishedKey = (0, _keys.createPublishedSortKey)();
|
|
120
|
+
return new _dataloader.default(async ids => {
|
|
121
|
+
const queries = ids.reduce((collection, id) => {
|
|
122
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
123
|
+
tenant,
|
|
124
|
+
locale,
|
|
125
|
+
id
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (collection[partitionKey]) {
|
|
129
|
+
return collection;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
collection[partitionKey] = entity.getBatch({
|
|
133
|
+
PK: partitionKey,
|
|
134
|
+
SK: publishedKey
|
|
135
|
+
});
|
|
136
|
+
return collection;
|
|
137
|
+
}, {});
|
|
138
|
+
const records = await (0, _batchRead.batchReadAll)({
|
|
139
|
+
table: entity.table,
|
|
140
|
+
items: Object.values(queries)
|
|
141
|
+
});
|
|
142
|
+
const items = (0, _cleanup.cleanupItems)(entity, records);
|
|
143
|
+
return ids.map(id => {
|
|
144
|
+
const {
|
|
145
|
+
id: entryId
|
|
146
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
147
|
+
return items.filter(item => {
|
|
148
|
+
return entryId === item.entryId;
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const getLatestRevisionByEntryId = params => {
|
|
155
|
+
const {
|
|
156
|
+
entity,
|
|
157
|
+
model
|
|
158
|
+
} = params;
|
|
159
|
+
const {
|
|
160
|
+
locale,
|
|
161
|
+
tenant
|
|
162
|
+
} = model;
|
|
163
|
+
const latestKey = (0, _keys.createLatestSortKey)();
|
|
164
|
+
return new _dataloader.default(async ids => {
|
|
165
|
+
const queries = ids.reduce((collection, id) => {
|
|
166
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
167
|
+
tenant,
|
|
168
|
+
locale,
|
|
169
|
+
id
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (collection[partitionKey]) {
|
|
173
|
+
return collection;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
collection[partitionKey] = entity.getBatch({
|
|
177
|
+
PK: partitionKey,
|
|
178
|
+
SK: latestKey
|
|
179
|
+
});
|
|
180
|
+
return collection;
|
|
181
|
+
}, {});
|
|
182
|
+
const records = await (0, _batchRead.batchReadAll)({
|
|
183
|
+
table: entity.table,
|
|
184
|
+
items: Object.values(queries)
|
|
185
|
+
});
|
|
186
|
+
const items = (0, _cleanup.cleanupItems)(entity, records);
|
|
187
|
+
return ids.map(id => {
|
|
188
|
+
const {
|
|
189
|
+
id: entryId
|
|
190
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
191
|
+
return items.filter(item => {
|
|
192
|
+
return entryId === item.entryId;
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const dataLoaders = {
|
|
199
|
+
getAllEntryRevisions,
|
|
200
|
+
getRevisionById,
|
|
201
|
+
getPublishedRevisionByEntryId,
|
|
202
|
+
getLatestRevisionByEntryId
|
|
203
|
+
};
|
|
204
|
+
const loaderNames = Object.keys(dataLoaders);
|
|
205
|
+
|
|
206
|
+
class DataLoadersHandler {
|
|
207
|
+
constructor(params) {
|
|
208
|
+
(0, _defineProperty2.default)(this, "loaders", new Map());
|
|
209
|
+
(0, _defineProperty2.default)(this, "entity", void 0);
|
|
210
|
+
this.entity = params.entity;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async getAllEntryRevisions(params) {
|
|
214
|
+
return await this.loadMany("getAllEntryRevisions", params, params.ids);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
clearAllEntryRevisions(params) {
|
|
218
|
+
this.clear("getAllEntryRevisions", params);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async getRevisionById(params) {
|
|
222
|
+
return await this.loadMany("getRevisionById", params, params.ids);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
clearRevisionById(params) {
|
|
226
|
+
this.clear("getRevisionById", params);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async getPublishedRevisionByEntryId(params) {
|
|
230
|
+
return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
clearPublishedRevisionByEntryId(params) {
|
|
234
|
+
this.clear("getPublishedRevisionByEntryId", params);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async getLatestRevisionByEntryId(params) {
|
|
238
|
+
return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
clearLatestRevisionByEntryId(params) {
|
|
242
|
+
this.clear("getLatestRevisionByEntryId", params);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
getLoader(name, params) {
|
|
246
|
+
if (!dataLoaders[name]) {
|
|
247
|
+
throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
|
|
248
|
+
name
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const {
|
|
253
|
+
model
|
|
254
|
+
} = params;
|
|
255
|
+
const {
|
|
256
|
+
tenant,
|
|
257
|
+
locale
|
|
258
|
+
} = model;
|
|
259
|
+
const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
|
|
260
|
+
|
|
261
|
+
if (!this.loaders.has(loaderKey)) {
|
|
262
|
+
this.loaders.set(loaderKey, dataLoaders[name](_objectSpread(_objectSpread({}, params), {}, {
|
|
263
|
+
entity: this.entity
|
|
264
|
+
})));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return this.loaders.get(loaderKey);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async loadMany(loader, params, ids) {
|
|
271
|
+
let results;
|
|
272
|
+
|
|
273
|
+
try {
|
|
274
|
+
results = await this.getLoader(loader, params).loadMany(ids);
|
|
275
|
+
|
|
276
|
+
if (Array.isArray(results) === true) {
|
|
277
|
+
return results.reduce((acc, res) => {
|
|
278
|
+
if (Array.isArray(res) === false) {
|
|
279
|
+
if (res && res.message) {
|
|
280
|
+
throw new _error.default(res.message, res.code, _objectSpread(_objectSpread({}, res), {}, {
|
|
281
|
+
data: JSON.stringify(res.data || {})
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", _objectSpread(_objectSpread({}, params), {}, {
|
|
286
|
+
loader
|
|
287
|
+
}));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
acc.push(...res);
|
|
291
|
+
return acc;
|
|
292
|
+
}, []);
|
|
293
|
+
}
|
|
294
|
+
} catch (ex) {
|
|
295
|
+
throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", _objectSpread(_objectSpread({
|
|
296
|
+
error: ex
|
|
297
|
+
}, params), {}, {
|
|
298
|
+
loader,
|
|
299
|
+
ids
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
|
|
304
|
+
loader,
|
|
305
|
+
ids,
|
|
306
|
+
results
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
clearAll(params) {
|
|
311
|
+
for (const name of loaderNames) {
|
|
312
|
+
const loader = this.getLoader(name, params);
|
|
313
|
+
loader.clearAll();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Helper to clear the cache for certain data loader.
|
|
318
|
+
* If entry is passed then clear target key only.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
clear(name, params) {
|
|
323
|
+
const {
|
|
324
|
+
entry
|
|
325
|
+
} = params;
|
|
326
|
+
const loader = this.getLoader(name, params);
|
|
327
|
+
|
|
328
|
+
if (!entry) {
|
|
329
|
+
loader.clearAll();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
loader.clear(entry.id);
|
|
334
|
+
const {
|
|
335
|
+
tenant,
|
|
336
|
+
locale
|
|
337
|
+
} = params.model;
|
|
338
|
+
loader.clear((0, _keys.createPartitionKey)({
|
|
339
|
+
tenant,
|
|
340
|
+
locale,
|
|
341
|
+
id: entry.id
|
|
342
|
+
}));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
exports.DataLoadersHandler = DataLoadersHandler;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.elasticsearchFields = void 0;
|
|
7
|
+
|
|
8
|
+
var _CmsEntryElasticsearchFieldPlugin = require("../../plugins/CmsEntryElasticsearchFieldPlugin");
|
|
9
|
+
|
|
10
|
+
const elasticsearchFields = [new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
11
|
+
field: "createdOn",
|
|
12
|
+
unmappedType: "date"
|
|
13
|
+
}), new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
14
|
+
field: "savedOn",
|
|
15
|
+
unmappedType: "date"
|
|
16
|
+
}), new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
17
|
+
field: "publishedOn",
|
|
18
|
+
unmappedType: "date"
|
|
19
|
+
}), new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
20
|
+
field: "ownedBy",
|
|
21
|
+
path: "ownedBy.id"
|
|
22
|
+
}), new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
23
|
+
field: "createdBy",
|
|
24
|
+
path: "createdBy.id"
|
|
25
|
+
}),
|
|
26
|
+
/**
|
|
27
|
+
* Always add the ALL fields plugin because of the keyword/path build.
|
|
28
|
+
*/
|
|
29
|
+
new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
30
|
+
field: _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin.ALL
|
|
31
|
+
})];
|
|
32
|
+
exports.elasticsearchFields = elasticsearchFields;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { CmsEntryElasticsearchFieldPlugin } from "../../plugins/CmsEntryElasticsearchFieldPlugin";
|
|
3
|
+
export declare const createElasticsearchFields: (model: CmsModel) => Record<string, CmsEntryElasticsearchFieldPlugin>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createElasticsearchFields = void 0;
|
|
7
|
+
|
|
8
|
+
var _CmsEntryElasticsearchFieldPlugin = require("../../plugins/CmsEntryElasticsearchFieldPlugin");
|
|
9
|
+
|
|
10
|
+
const fieldsWithKeywords = ["text", "long-text", "rich-text", "id", "ref"];
|
|
11
|
+
/**
|
|
12
|
+
* We need to map entry system fields that have different paths, no keyword or not sortable.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const systemFields = {
|
|
16
|
+
createdBy: new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
17
|
+
field: "createdBy",
|
|
18
|
+
path: "createdBy.id",
|
|
19
|
+
searchable: true,
|
|
20
|
+
keyword: true,
|
|
21
|
+
sortable: false
|
|
22
|
+
}),
|
|
23
|
+
ownedBy: new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
24
|
+
field: "ownedBy",
|
|
25
|
+
path: "ownedBy.id",
|
|
26
|
+
searchable: true,
|
|
27
|
+
keyword: true,
|
|
28
|
+
sortable: false
|
|
29
|
+
}),
|
|
30
|
+
createdOn: new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
31
|
+
field: "createdOn",
|
|
32
|
+
path: "createdOn",
|
|
33
|
+
searchable: true,
|
|
34
|
+
keyword: false,
|
|
35
|
+
sortable: false,
|
|
36
|
+
unmappedType: "date"
|
|
37
|
+
}),
|
|
38
|
+
savedOn: new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
39
|
+
field: "savedOn",
|
|
40
|
+
path: "savedOn",
|
|
41
|
+
searchable: true,
|
|
42
|
+
keyword: false,
|
|
43
|
+
sortable: false,
|
|
44
|
+
unmappedType: "date"
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const createElasticsearchFields = model => {
|
|
49
|
+
return model.fields.reduce((fields, field) => {
|
|
50
|
+
fields[field.fieldId] = new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
51
|
+
field: field.fieldId,
|
|
52
|
+
path: `values.${field.fieldId}`,
|
|
53
|
+
searchable: true,
|
|
54
|
+
keyword: fieldsWithKeywords.includes(field.type)
|
|
55
|
+
});
|
|
56
|
+
return fields;
|
|
57
|
+
}, systemFields);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.createElasticsearchFields = createElasticsearchFields;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CmsEntryStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Entity } from "dynamodb-toolbox";
|
|
3
|
+
import { Client } from "@elastic/elasticsearch";
|
|
4
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
5
|
+
export declare const createLatestType: () => string;
|
|
6
|
+
export declare const createPublishedType: () => string;
|
|
7
|
+
export interface Params {
|
|
8
|
+
entity: Entity<any>;
|
|
9
|
+
esEntity: Entity<any>;
|
|
10
|
+
elasticsearch: Client;
|
|
11
|
+
plugins: PluginsContainer;
|
|
12
|
+
}
|
|
13
|
+
export declare const createEntriesStorageOperations: (params: Params) => CmsEntryStorageOperations;
|