@webiny/api-headless-cms-ddb 5.35.0 → 5.35.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/index.js +6 -4
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +43 -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 +9 -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 +23 -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 +43 -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 +57 -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 +57 -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 +63 -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 +38 -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 +5 -0
- package/operations/entry/dataLoader/types.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +11 -26
- package/operations/entry/dataLoaders.js +42 -205
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/index.d.ts +1 -1
- package/operations/entry/index.js +67 -4
- package/operations/entry/index.js.map +1 -1
- package/package.json +18 -18
- package/types.d.ts +10 -1
- package/types.js.map +1 -1
package/index.js
CHANGED
|
@@ -93,6 +93,10 @@ const createStorageOperations = params => {
|
|
|
93
93
|
* User defined custom plugins.
|
|
94
94
|
*/
|
|
95
95
|
...(userPlugins || [])]);
|
|
96
|
+
const entries = (0, _entry2.createEntriesStorageOperations)({
|
|
97
|
+
entity: entities.entries,
|
|
98
|
+
plugins
|
|
99
|
+
});
|
|
96
100
|
return {
|
|
97
101
|
name: "dynamodb",
|
|
98
102
|
beforeInit: async context => {
|
|
@@ -107,6 +111,7 @@ const createStorageOperations = params => {
|
|
|
107
111
|
* Pass the plugins to the parent context.
|
|
108
112
|
*/
|
|
109
113
|
context.plugins.register([(0, _dynamoDb.default)()]);
|
|
114
|
+
entries.dataLoaders.clearAll();
|
|
110
115
|
},
|
|
111
116
|
getEntities: () => entities,
|
|
112
117
|
getTable: () => tableInstance,
|
|
@@ -123,10 +128,7 @@ const createStorageOperations = params => {
|
|
|
123
128
|
models: (0, _model2.createModelsStorageOperations)({
|
|
124
129
|
entity: entities.models
|
|
125
130
|
}),
|
|
126
|
-
entries
|
|
127
|
-
entity: entities.entries,
|
|
128
|
-
plugins
|
|
129
|
-
})
|
|
131
|
+
entries
|
|
130
132
|
};
|
|
131
133
|
};
|
|
132
134
|
exports.createStorageOperations = createStorageOperations;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createStorageOperations","params","attributes","table","documentClient","plugins","userPlugins","tableInstance","createTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","createFilterCreatePlugins","name","beforeInit","context","types","CmsEntryFieldFilterPathPlugin","type","CmsFieldFilterValueTransformPlugin","CmsEntryFieldFilterPlugin","CmsEntryFieldSortingPlugin","ValueFilterPlugin","StorageOperationsCmsModelPlugin","mergeByType","register","getEntities","getTable","createSystemStorageOperations","
|
|
1
|
+
{"version":3,"names":["createStorageOperations","params","attributes","table","documentClient","plugins","userPlugins","tableInstance","createTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","createFilterCreatePlugins","createEntriesStorageOperations","entity","name","beforeInit","context","types","CmsEntryFieldFilterPathPlugin","type","CmsFieldFilterValueTransformPlugin","CmsEntryFieldFilterPlugin","CmsEntryFieldSortingPlugin","ValueFilterPlugin","StorageOperationsCmsModelPlugin","mergeByType","register","dataLoaders","clearAll","getEntities","getTable","createSystemStorageOperations","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createSystemStorageOperations } from \"~/operations/system\";\nimport { createSettingsStorageOperations } from \"~/operations/settings\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport { createModelsStorageOperations } from \"~/operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\n\nimport { createFilterCreatePlugins } from \"~/operations/entry/filtering/plugins\";\nimport {\n CmsEntryFieldFilterPathPlugin,\n CmsEntryFieldFilterPlugin,\n CmsEntryFieldSortingPlugin,\n CmsFieldFilterValueTransformPlugin\n} from \"~/plugins\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { StorageOperationsCmsModelPlugin } from \"@webiny/api-headless-cms\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const { attributes, table, documentClient, plugins: userPlugins } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Filter create plugins.\n */\n createFilterCreatePlugins(),\n /**\n * User defined custom plugins.\n */\n ...(userPlugins || [])\n ]);\n\n const entries = createEntriesStorageOperations({\n entity: entities.entries,\n plugins\n });\n\n return {\n name: \"dynamodb\",\n beforeInit: async context => {\n const types: string[] = [\n \"cms-model-field-to-graphql\",\n CmsEntryFieldFilterPathPlugin.type,\n CmsFieldFilterValueTransformPlugin.type,\n CmsEntryFieldFilterPlugin.type,\n CmsEntryFieldSortingPlugin.type,\n ValueFilterPlugin.type,\n StorageOperationsCmsModelPlugin.type\n ];\n /**\n * Collect all required plugins from parent context.\n */\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n\n entries.dataLoaders.clearAll();\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models\n }),\n entries\n };\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
export interface CacheKeyParams {
|
|
3
|
+
name: string;
|
|
4
|
+
tenant: string;
|
|
5
|
+
locale: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ClearAllParams {
|
|
8
|
+
tenant: string;
|
|
9
|
+
locale: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class DataLoaderCache {
|
|
12
|
+
private readonly cache;
|
|
13
|
+
getDataLoader<I = any, R = any>(params: CacheKeyParams): DataLoader<I, R> | null;
|
|
14
|
+
setDataLoader(params: CacheKeyParams, dataLoader: DataLoader<any, any>): void;
|
|
15
|
+
clearAll(params?: ClearAllParams): void;
|
|
16
|
+
private createKey;
|
|
17
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.DataLoaderCache = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
class DataLoaderCache {
|
|
11
|
+
constructor() {
|
|
12
|
+
(0, _defineProperty2.default)(this, "cache", {});
|
|
13
|
+
}
|
|
14
|
+
getDataLoader(params) {
|
|
15
|
+
const key = this.createKey(params);
|
|
16
|
+
return this.cache[key] || null;
|
|
17
|
+
}
|
|
18
|
+
setDataLoader(params, dataLoader) {
|
|
19
|
+
const key = this.createKey(params);
|
|
20
|
+
this.cache[key] = dataLoader;
|
|
21
|
+
}
|
|
22
|
+
clearAll(params) {
|
|
23
|
+
if (!params) {
|
|
24
|
+
for (const current in this.cache) {
|
|
25
|
+
this.cache[current].clearAll();
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const key = this.createKey((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
30
|
+
name: ""
|
|
31
|
+
}));
|
|
32
|
+
for (const current in this.cache) {
|
|
33
|
+
if (current.startsWith(key) === false) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
this.cache[current].clearAll();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
createKey(params) {
|
|
40
|
+
return `${params.tenant}_${params.locale}_${params.name}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.DataLoaderCache = DataLoaderCache;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DataLoaderCache","getDataLoader","params","key","createKey","cache","setDataLoader","dataLoader","clearAll","current","name","startsWith","tenant","locale"],"sources":["DataLoaderCache.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\n\nexport interface CacheKeyParams {\n name: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ClearAllParams {\n tenant: string;\n locale: string;\n}\n\nexport class DataLoaderCache {\n private readonly cache: Record<string, DataLoader<any, any>> = {};\n\n public getDataLoader<I = any, R = any>(params: CacheKeyParams): DataLoader<I, R> | null {\n const key = this.createKey(params);\n\n return this.cache[key] || null;\n }\n\n public setDataLoader(params: CacheKeyParams, dataLoader: DataLoader<any, any>): void {\n const key = this.createKey(params);\n this.cache[key] = dataLoader;\n }\n\n public clearAll(params?: ClearAllParams): void {\n if (!params) {\n for (const current in this.cache) {\n this.cache[current].clearAll();\n }\n return;\n }\n const key = this.createKey({\n ...params,\n name: \"\"\n });\n for (const current in this.cache) {\n if (current.startsWith(key) === false) {\n continue;\n }\n this.cache[current].clearAll();\n }\n }\n\n private createKey(params: CacheKeyParams): string {\n return `${params.tenant}_${params.locale}_${params.name}`;\n }\n}\n"],"mappings":";;;;;;;;;AAaO,MAAMA,eAAe,CAAC;EAAA;IAAA,6CACsC,CAAC,CAAC;EAAA;EAE1DC,aAAa,CAAmBC,MAAsB,EAA2B;IACpF,MAAMC,GAAG,GAAG,IAAI,CAACC,SAAS,CAACF,MAAM,CAAC;IAElC,OAAO,IAAI,CAACG,KAAK,CAACF,GAAG,CAAC,IAAI,IAAI;EAClC;EAEOG,aAAa,CAACJ,MAAsB,EAAEK,UAAgC,EAAQ;IACjF,MAAMJ,GAAG,GAAG,IAAI,CAACC,SAAS,CAACF,MAAM,CAAC;IAClC,IAAI,CAACG,KAAK,CAACF,GAAG,CAAC,GAAGI,UAAU;EAChC;EAEOC,QAAQ,CAACN,MAAuB,EAAQ;IAC3C,IAAI,CAACA,MAAM,EAAE;MACT,KAAK,MAAMO,OAAO,IAAI,IAAI,CAACJ,KAAK,EAAE;QAC9B,IAAI,CAACA,KAAK,CAACI,OAAO,CAAC,CAACD,QAAQ,EAAE;MAClC;MACA;IACJ;IACA,MAAML,GAAG,GAAG,IAAI,CAACC,SAAS,6DACnBF,MAAM;MACTQ,IAAI,EAAE;IAAE,GACV;IACF,KAAK,MAAMD,OAAO,IAAI,IAAI,CAACJ,KAAK,EAAE;MAC9B,IAAII,OAAO,CAACE,UAAU,CAACR,GAAG,CAAC,KAAK,KAAK,EAAE;QACnC;MACJ;MACA,IAAI,CAACE,KAAK,CAACI,OAAO,CAAC,CAACD,QAAQ,EAAE;IAClC;EACJ;EAEQJ,SAAS,CAACF,MAAsB,EAAU;IAC9C,OAAQ,GAAEA,MAAM,CAACU,MAAO,IAAGV,MAAM,CAACW,MAAO,IAAGX,MAAM,CAACQ,IAAK,EAAC;EAC7D;AACJ;AAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CMS_ENTRY_BATCH_SCHEDULE_WAIT: number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CMS_ENTRY_BATCH_SCHEDULE_WAIT = void 0;
|
|
7
|
+
const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || "0");
|
|
8
|
+
const CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;
|
|
9
|
+
exports.CMS_ENTRY_BATCH_SCHEDULE_WAIT = CMS_ENTRY_BATCH_SCHEDULE_WAIT;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["batchScheduleWaitEnv","Number","process","env","WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT","CMS_ENTRY_BATCH_SCHEDULE_WAIT","isNaN"],"sources":["constants.ts"],"sourcesContent":["const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || \"0\");\nexport const CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;\n"],"mappings":";;;;;;AAAA,MAAMA,oBAAoB,GAAGC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,wCAAwC,IAAI,GAAG,CAAC;AACzF,MAAMC,6BAA6B,GAAGC,KAAK,CAACN,oBAAoB,CAAC,GAAG,CAAC,GAAGA,oBAAoB;AAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is to be used when user wants to wait for a number of milliseconds before the batch is executed.
|
|
3
|
+
* Intended to be used internally or for a specific user case.
|
|
4
|
+
* Not to be documented and exposed to publish as it can slow the data loading a lot.
|
|
5
|
+
*
|
|
6
|
+
* https://github.com/graphql/dataloader#batch-scheduling
|
|
7
|
+
*/
|
|
8
|
+
export declare const createBatchScheduleFn: () => ((callback: () => void) => void) | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createBatchScheduleFn = void 0;
|
|
7
|
+
var _constants = require("./constants");
|
|
8
|
+
/**
|
|
9
|
+
* This is to be used when user wants to wait for a number of milliseconds before the batch is executed.
|
|
10
|
+
* Intended to be used internally or for a specific user case.
|
|
11
|
+
* Not to be documented and exposed to publish as it can slow the data loading a lot.
|
|
12
|
+
*
|
|
13
|
+
* https://github.com/graphql/dataloader#batch-scheduling
|
|
14
|
+
*/
|
|
15
|
+
const createBatchScheduleFn = () => {
|
|
16
|
+
if (_constants.CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return callback => {
|
|
20
|
+
setTimeout(callback, _constants.CMS_ENTRY_BATCH_SCHEDULE_WAIT);
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.createBatchScheduleFn = createBatchScheduleFn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createBatchScheduleFn","CMS_ENTRY_BATCH_SCHEDULE_WAIT","undefined","callback","setTimeout"],"sources":["createBatchScheduleFn.ts"],"sourcesContent":["import { CMS_ENTRY_BATCH_SCHEDULE_WAIT } from \"./constants\";\n\n/**\n * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.\n * Intended to be used internally or for a specific user case.\n * Not to be documented and exposed to publish as it can slow the data loading a lot.\n *\n * https://github.com/graphql/dataloader#batch-scheduling\n */\nexport const createBatchScheduleFn = () => {\n if (CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {\n return undefined;\n }\n return (callback: () => void) => {\n setTimeout(callback, CMS_ENTRY_BATCH_SCHEDULE_WAIT);\n };\n};\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,qBAAqB,GAAG,MAAM;EACvC,IAAIC,wCAA6B,IAAI,CAAC,EAAE;IACpC,OAAOC,SAAS;EACpB;EACA,OAAQC,QAAoB,IAAK;IAC7BC,UAAU,CAACD,QAAQ,EAAEF,wCAA6B,CAAC;EACvD,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
|
|
3
|
+
import { DataLoaderParams } from "./types";
|
|
4
|
+
export declare const createGetAllEntryRevisions: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createGetAllEntryRevisions = void 0;
|
|
8
|
+
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
9
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
10
|
+
var _keys = require("../keys");
|
|
11
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
12
|
+
var _createBatchScheduleFn = require("./createBatchScheduleFn");
|
|
13
|
+
const createGetAllEntryRevisions = params => {
|
|
14
|
+
const {
|
|
15
|
+
entity,
|
|
16
|
+
locale,
|
|
17
|
+
tenant
|
|
18
|
+
} = params;
|
|
19
|
+
return new _dataloader.default(async ids => {
|
|
20
|
+
const results = {};
|
|
21
|
+
for (const id of ids) {
|
|
22
|
+
const queryAllParams = {
|
|
23
|
+
entity,
|
|
24
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
25
|
+
tenant,
|
|
26
|
+
locale,
|
|
27
|
+
id
|
|
28
|
+
}),
|
|
29
|
+
options: {
|
|
30
|
+
beginsWith: "REV#"
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const items = await (0, _query.queryAll)(queryAllParams);
|
|
34
|
+
results[id] = (0, _cleanup.cleanupItems)(entity, items);
|
|
35
|
+
}
|
|
36
|
+
return ids.map(id => {
|
|
37
|
+
return results[id] || [];
|
|
38
|
+
});
|
|
39
|
+
}, {
|
|
40
|
+
batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.createGetAllEntryRevisions = createGetAllEntryRevisions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createGetAllEntryRevisions","params","entity","locale","tenant","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","batchScheduleFn","createBatchScheduleFn"],"sources":["getAllEntryRevisions.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { createPartitionKey } from \"~/operations/entry/keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { DataLoaderParams } from \"./types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetAllEntryRevisions = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const results: Record<string, CmsStorageEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsStorageEntry>(queryAllParams);\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AACA;AAEA;AAEO,MAAMA,0BAA0B,GAAIC,MAAwB,IAAK;EACpE,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EACzC,OAAO,IAAII,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAA0C,GAAG,CAAC,CAAC;IACrD,KAAK,MAAMC,EAAE,IAAIF,GAAG,EAAE;MAClB,MAAMG,cAA8B,GAAG;QACnCP,MAAM;QACNQ,YAAY,EAAE,IAAAC,wBAAkB,EAAC;UAC7BP,MAAM;UACND,MAAM;UACNK;QACJ,CAAC,CAAC;QACFI,OAAO,EAAE;UACLC,UAAU,EAAE;QAChB;MACJ,CAAC;MACD,MAAMC,KAAK,GAAG,MAAM,IAAAC,eAAQ,EAAkBN,cAAc,CAAC;MAC7DF,OAAO,CAACC,EAAE,CAAC,GAAG,IAAAQ,qBAAY,EAACd,MAAM,EAAEY,KAAK,CAAC;IAC7C;IAEA,OAAOR,GAAG,CAACW,GAAG,CAACT,EAAE,IAAI;MACjB,OAAOD,OAAO,CAACC,EAAE,CAAC,IAAI,EAAE;IAC5B,CAAC,CAAC;EACN,CAAC,EACD;IACIU,eAAe,EAAE,IAAAC,4CAAqB;EAC1C,CAAC,CACJ;AACL,CAAC;AAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
|
|
3
|
+
import { DataLoaderParams } from "./types";
|
|
4
|
+
export declare const createGetLatestRevisionByEntryId: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createGetLatestRevisionByEntryId = void 0;
|
|
8
|
+
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
9
|
+
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
10
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
11
|
+
var _createBatchScheduleFn = require("./createBatchScheduleFn");
|
|
12
|
+
var _keys = require("../keys");
|
|
13
|
+
var _utils = require("@webiny/utils");
|
|
14
|
+
const createGetLatestRevisionByEntryId = params => {
|
|
15
|
+
const {
|
|
16
|
+
entity,
|
|
17
|
+
locale,
|
|
18
|
+
tenant
|
|
19
|
+
} = params;
|
|
20
|
+
const latestKey = (0, _keys.createLatestSortKey)();
|
|
21
|
+
return new _dataloader.default(async ids => {
|
|
22
|
+
const queries = ids.reduce((collection, id) => {
|
|
23
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
24
|
+
tenant,
|
|
25
|
+
locale,
|
|
26
|
+
id
|
|
27
|
+
});
|
|
28
|
+
if (collection[partitionKey]) {
|
|
29
|
+
return collection;
|
|
30
|
+
}
|
|
31
|
+
collection[partitionKey] = entity.getBatch({
|
|
32
|
+
PK: partitionKey,
|
|
33
|
+
SK: latestKey
|
|
34
|
+
});
|
|
35
|
+
return collection;
|
|
36
|
+
/**
|
|
37
|
+
* We cast as any because there is no return type defined.
|
|
38
|
+
*/
|
|
39
|
+
}, {});
|
|
40
|
+
const records = await (0, _batchRead.batchReadAll)({
|
|
41
|
+
table: entity.table,
|
|
42
|
+
items: Object.values(queries)
|
|
43
|
+
});
|
|
44
|
+
const items = (0, _cleanup.cleanupItems)(entity, records);
|
|
45
|
+
return ids.map(id => {
|
|
46
|
+
const {
|
|
47
|
+
id: entryId
|
|
48
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
49
|
+
return items.filter(item => {
|
|
50
|
+
return entryId === item.entryId;
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}, {
|
|
54
|
+
batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
exports.createGetLatestRevisionByEntryId = createGetLatestRevisionByEntryId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createGetLatestRevisionByEntryId","params","entity","locale","tenant","latestKey","createLatestSortKey","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","entryId","parseIdentifier","filter","item","batchScheduleFn","createBatchScheduleFn"],"sources":["getLatestRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\nimport { createLatestSortKey, createPartitionKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\nexport const createGetLatestRevisionByEntryId = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce<Record<string, any>>((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {});\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA;AACA;AAEA;AAEO,MAAMA,gCAAgC,GAAIC,MAAwB,IAAK;EAC1E,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,MAAMI,SAAS,GAAG,IAAAC,yBAAmB,GAAE;EAEvC,OAAO,IAAIC,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CAAsB,CAACC,UAAU,EAAEC,EAAE,KAAK;MAChE,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCV,MAAM;QACND,MAAM;QACNS;MACJ,CAAC,CAAC;MACF,IAAID,UAAU,CAACE,YAAY,CAAC,EAAE;QAC1B,OAAOF,UAAU;MACrB;MACAA,UAAU,CAACE,YAAY,CAAC,GAAGX,MAAM,CAACa,QAAQ,CAAC;QACvCC,EAAE,EAAEH,YAAY;QAChBI,EAAE,EAAEZ;MACR,CAAC,CAAC;MACF,OAAOM,UAAU;MACjB;AAChB;AACA;IACY,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,MAAMO,OAAO,GAAG,MAAM,IAAAC,uBAAY,EAAkB;MAChDC,KAAK,EAAElB,MAAM,CAACkB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACd,OAAO;IAChC,CAAC,CAAC;IACF,MAAMY,KAAK,GAAG,IAAAG,qBAAY,EAACtB,MAAM,EAAEgB,OAAO,CAAC;IAE3C,OAAOV,GAAG,CAACiB,GAAG,CAACb,EAAE,IAAI;MACjB,MAAM;QAAEA,EAAE,EAAEc;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACf,EAAE,CAAC;MAC3C,OAAOS,KAAK,CAACO,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOH,OAAO,KAAKG,IAAI,CAACH,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACII,eAAe,EAAE,IAAAC,4CAAqB;EAC1C,CAAC,CACJ;AACL,CAAC;AAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
|
|
3
|
+
import { DataLoaderParams } from "./types";
|
|
4
|
+
export declare const createGetPublishedRevisionByEntryId: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createGetPublishedRevisionByEntryId = void 0;
|
|
8
|
+
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
9
|
+
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
10
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
11
|
+
var _keys = require("../keys");
|
|
12
|
+
var _utils = require("@webiny/utils");
|
|
13
|
+
var _createBatchScheduleFn = require("./createBatchScheduleFn");
|
|
14
|
+
const createGetPublishedRevisionByEntryId = params => {
|
|
15
|
+
const {
|
|
16
|
+
entity,
|
|
17
|
+
locale,
|
|
18
|
+
tenant
|
|
19
|
+
} = params;
|
|
20
|
+
const publishedKey = (0, _keys.createPublishedSortKey)();
|
|
21
|
+
return new _dataloader.default(async ids => {
|
|
22
|
+
const queries = ids.reduce((collection, id) => {
|
|
23
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
24
|
+
tenant,
|
|
25
|
+
locale,
|
|
26
|
+
id
|
|
27
|
+
});
|
|
28
|
+
if (collection[partitionKey]) {
|
|
29
|
+
return collection;
|
|
30
|
+
}
|
|
31
|
+
collection[partitionKey] = entity.getBatch({
|
|
32
|
+
PK: partitionKey,
|
|
33
|
+
SK: publishedKey
|
|
34
|
+
});
|
|
35
|
+
return collection;
|
|
36
|
+
/**
|
|
37
|
+
* We cast as any because there is no return type defined.
|
|
38
|
+
*/
|
|
39
|
+
}, {});
|
|
40
|
+
const records = await (0, _batchRead.batchReadAll)({
|
|
41
|
+
table: entity.table,
|
|
42
|
+
items: Object.values(queries)
|
|
43
|
+
});
|
|
44
|
+
const items = (0, _cleanup.cleanupItems)(entity, records);
|
|
45
|
+
return ids.map(id => {
|
|
46
|
+
const {
|
|
47
|
+
id: entryId
|
|
48
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
49
|
+
return items.filter(item => {
|
|
50
|
+
return entryId === item.entryId;
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}, {
|
|
54
|
+
batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
exports.createGetPublishedRevisionByEntryId = createGetPublishedRevisionByEntryId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createGetPublishedRevisionByEntryId","params","entity","locale","tenant","publishedKey","createPublishedSortKey","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","entryId","parseIdentifier","filter","item","batchScheduleFn","createBatchScheduleFn"],"sources":["getPublishedRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createPartitionKey, createPublishedSortKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetPublishedRevisionByEntryId = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n const publishedKey = createPublishedSortKey();\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA;AAEA;AACA;AAEO,MAAMA,mCAAmC,GAAIC,MAAwB,IAAK;EAC7E,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,MAAMI,YAAY,GAAG,IAAAC,4BAAsB,GAAE;EAC7C,OAAO,IAAIC,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CAAC,CAACC,UAAU,EAAEC,EAAE,KAAK;MAC3C,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCV,MAAM;QACND,MAAM;QACNS;MACJ,CAAC,CAAC;MACF,IAAID,UAAU,CAACE,YAAY,CAAC,EAAE;QAC1B,OAAOF,UAAU;MACrB;MACAA,UAAU,CAACE,YAAY,CAAC,GAAGX,MAAM,CAACa,QAAQ,CAAC;QACvCC,EAAE,EAAEH,YAAY;QAChBI,EAAE,EAAEZ;MACR,CAAC,CAAC;MACF,OAAOM,UAAU;MACjB;AAChB;AACA;IACY,CAAC,EAAE,CAAC,CAAC,CAAwB;IAE7B,MAAMO,OAAO,GAAG,MAAM,IAAAC,uBAAY,EAAkB;MAChDC,KAAK,EAAElB,MAAM,CAACkB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACd,OAAO;IAChC,CAAC,CAAC;IACF,MAAMY,KAAK,GAAG,IAAAG,qBAAY,EAACtB,MAAM,EAAEgB,OAAO,CAAC;IAE3C,OAAOV,GAAG,CAACiB,GAAG,CAACb,EAAE,IAAI;MACjB,MAAM;QAAEA,EAAE,EAAEc;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACf,EAAE,CAAC;MAC3C,OAAOS,KAAK,CAACO,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOH,OAAO,KAAKG,IAAI,CAACH,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACII,eAAe,EAAE,IAAAC,4CAAqB;EAC1C,CAAC,CACJ;AACL,CAAC;AAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createGetRevisionById = void 0;
|
|
8
|
+
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
9
|
+
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
10
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
11
|
+
var _keys = require("../keys");
|
|
12
|
+
var _utils = require("@webiny/utils");
|
|
13
|
+
var _createBatchScheduleFn = require("./createBatchScheduleFn");
|
|
14
|
+
const createGetRevisionById = params => {
|
|
15
|
+
const {
|
|
16
|
+
entity,
|
|
17
|
+
locale,
|
|
18
|
+
tenant
|
|
19
|
+
} = params;
|
|
20
|
+
return new _dataloader.default(async ids => {
|
|
21
|
+
const queries = ids.reduce((collection, id) => {
|
|
22
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
23
|
+
tenant,
|
|
24
|
+
locale,
|
|
25
|
+
id
|
|
26
|
+
});
|
|
27
|
+
const {
|
|
28
|
+
version
|
|
29
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
30
|
+
if (version === null) {
|
|
31
|
+
return collection;
|
|
32
|
+
}
|
|
33
|
+
const sortKey = (0, _keys.createRevisionSortKey)({
|
|
34
|
+
version
|
|
35
|
+
});
|
|
36
|
+
const keys = `${partitionKey}__${sortKey}`;
|
|
37
|
+
if (collection[keys]) {
|
|
38
|
+
return collection;
|
|
39
|
+
}
|
|
40
|
+
collection[keys] = entity.getBatch({
|
|
41
|
+
PK: partitionKey,
|
|
42
|
+
SK: sortKey
|
|
43
|
+
});
|
|
44
|
+
return collection;
|
|
45
|
+
/**
|
|
46
|
+
* We cast as any because there is no return type defined.
|
|
47
|
+
*/
|
|
48
|
+
}, {});
|
|
49
|
+
const records = await (0, _batchRead.batchReadAll)({
|
|
50
|
+
table: entity.table,
|
|
51
|
+
items: Object.values(queries)
|
|
52
|
+
});
|
|
53
|
+
const items = (0, _cleanup.cleanupItems)(entity, records);
|
|
54
|
+
return ids.map(id => {
|
|
55
|
+
return items.filter(item => {
|
|
56
|
+
return id === item.id;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}, {
|
|
60
|
+
batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
exports.createGetRevisionById = createGetRevisionById;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createGetRevisionById","params","entity","locale","tenant","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","filter","item","batchScheduleFn","createBatchScheduleFn"],"sources":["getRevisionById.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { createPartitionKey, createRevisionSortKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetRevisionById = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AACA;AAEA;AACA;AAEO,MAAMA,qBAAqB,GAAIC,MAAwB,IAAK;EAC/D,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,OAAO,IAAII,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CAAC,CAACC,UAAU,EAAEC,EAAE,KAAK;MAC3C,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCR,MAAM;QACND,MAAM;QACNO;MACJ,CAAC,CAAC;MACF,MAAM;QAAEG;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACJ,EAAE,CAAC;MACvC,IAAIG,OAAO,KAAK,IAAI,EAAE;QAClB,OAAOJ,UAAU;MACrB;MACA,MAAMM,OAAO,GAAG,IAAAC,2BAAqB,EAAC;QAClCH;MACJ,CAAC,CAAC;MACF,MAAMI,IAAI,GAAI,GAAEN,YAAa,KAAII,OAAQ,EAAC;MAC1C,IAAIN,UAAU,CAACQ,IAAI,CAAC,EAAE;QAClB,OAAOR,UAAU;MACrB;MAEAA,UAAU,CAACQ,IAAI,CAAC,GAAGf,MAAM,CAACgB,QAAQ,CAAC;QAC/BC,EAAE,EAAER,YAAY;QAChBS,EAAE,EAAEL;MACR,CAAC,CAAC;MAEF,OAAON,UAAU;MACjB;AAChB;AACA;IACY,CAAC,EAAE,CAAC,CAAC,CAAwB;IAE7B,MAAMY,OAAO,GAAG,MAAM,IAAAC,uBAAY,EAAkB;MAChDC,KAAK,EAAErB,MAAM,CAACqB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACnB,OAAO;IAChC,CAAC,CAAC;IACF,MAAMiB,KAAK,GAAG,IAAAG,qBAAY,EAACzB,MAAM,EAAEmB,OAAO,CAAC;IAE3C,OAAOf,GAAG,CAACsB,GAAG,CAAClB,EAAE,IAAI;MACjB,OAAOc,KAAK,CAACK,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOpB,EAAE,KAAKoB,IAAI,CAACpB,EAAE;MACzB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIqB,eAAe,EAAE,IAAAC,4CAAqB;EAC1C,CAAC,CACJ;AACL,CAAC;AAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
import { DataLoaderParams } from "./types";
|
|
3
|
+
export * from "./DataLoaderCache";
|
|
4
|
+
interface Callable {
|
|
5
|
+
(params: DataLoaderParams): DataLoader<any, any>;
|
|
6
|
+
}
|
|
7
|
+
export declare type DataLoaders = "getAllEntryRevisions" | "getRevisionById" | "getPublishedRevisionByEntryId" | "getLatestRevisionByEntryId";
|
|
8
|
+
export declare const getDataLoaderFactory: (name: string) => Callable;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
getDataLoaderFactory: true
|
|
8
|
+
};
|
|
9
|
+
exports.getDataLoaderFactory = void 0;
|
|
10
|
+
var _getAllEntryRevisions = require("./getAllEntryRevisions");
|
|
11
|
+
var _getLatestRevisionByEntryId = require("./getLatestRevisionByEntryId");
|
|
12
|
+
var _getPublishedRevisionByEntryId = require("./getPublishedRevisionByEntryId");
|
|
13
|
+
var _getRevisionById = require("./getRevisionById");
|
|
14
|
+
var _DataLoaderCache = require("./DataLoaderCache");
|
|
15
|
+
Object.keys(_DataLoaderCache).forEach(function (key) {
|
|
16
|
+
if (key === "default" || key === "__esModule") return;
|
|
17
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
18
|
+
if (key in exports && exports[key] === _DataLoaderCache[key]) return;
|
|
19
|
+
Object.defineProperty(exports, key, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _DataLoaderCache[key];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
const dataLoaders = {
|
|
27
|
+
getAllEntryRevisions: _getAllEntryRevisions.createGetAllEntryRevisions,
|
|
28
|
+
getLatestRevisionByEntryId: _getLatestRevisionByEntryId.createGetLatestRevisionByEntryId,
|
|
29
|
+
getPublishedRevisionByEntryId: _getPublishedRevisionByEntryId.createGetPublishedRevisionByEntryId,
|
|
30
|
+
getRevisionById: _getRevisionById.createGetRevisionById
|
|
31
|
+
};
|
|
32
|
+
const getDataLoaderFactory = name => {
|
|
33
|
+
if (!dataLoaders[name]) {
|
|
34
|
+
throw new Error(`Missing data loader "${name}".`);
|
|
35
|
+
}
|
|
36
|
+
return dataLoaders[name];
|
|
37
|
+
};
|
|
38
|
+
exports.getDataLoaderFactory = getDataLoaderFactory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["dataLoaders","getAllEntryRevisions","createGetAllEntryRevisions","getLatestRevisionByEntryId","createGetLatestRevisionByEntryId","getPublishedRevisionByEntryId","createGetPublishedRevisionByEntryId","getRevisionById","createGetRevisionById","getDataLoaderFactory","name","Error"],"sources":["index.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { DataLoaderParams } from \"./types\";\nimport { createGetAllEntryRevisions } from \"./getAllEntryRevisions\";\nimport { createGetLatestRevisionByEntryId } from \"./getLatestRevisionByEntryId\";\nimport { createGetPublishedRevisionByEntryId } from \"./getPublishedRevisionByEntryId\";\nimport { createGetRevisionById } from \"./getRevisionById\";\n\nexport * from \"./DataLoaderCache\";\n\ninterface Callable {\n (params: DataLoaderParams): DataLoader<any, any>;\n}\n\nconst dataLoaders: Record<string, Callable> = {\n getAllEntryRevisions: createGetAllEntryRevisions,\n getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,\n getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,\n getRevisionById: createGetRevisionById\n};\n\nexport type DataLoaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nexport const getDataLoaderFactory = (name: string) => {\n if (!dataLoaders[name]) {\n throw new Error(`Missing data loader \"${name}\".`);\n }\n return dataLoaders[name];\n};\n"],"mappings":";;;;;;;;;AAEA;AACA;AACA;AACA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAMA,MAAMA,WAAqC,GAAG;EAC1CC,oBAAoB,EAAEC,gDAA0B;EAChDC,0BAA0B,EAAEC,4DAAgC;EAC5DC,6BAA6B,EAAEC,kEAAmC;EAClEC,eAAe,EAAEC;AACrB,CAAC;AAQM,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAClD,IAAI,CAACV,WAAW,CAACU,IAAI,CAAC,EAAE;IACpB,MAAM,IAAIC,KAAK,CAAE,wBAAuBD,IAAK,IAAG,CAAC;EACrD;EACA,OAAOV,WAAW,CAACU,IAAI,CAAC;AAC5B,CAAC;AAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Entity } from \"dynamodb-toolbox\";\n\nexport interface DataLoaderParams {\n entity: Entity<any>;\n tenant: string;\n locale: string;\n}\n"],"mappings":""}
|
|
@@ -1,42 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types";
|
|
2
2
|
import { Entity } from "dynamodb-toolbox";
|
|
3
|
-
|
|
3
|
+
import { DataLoadersHandlerInterface, DataLoadersHandlerInterfaceClearAllParams } from "../../types";
|
|
4
|
+
interface DataLoaderParams {
|
|
5
|
+
model: Pick<CmsModel, "tenant" | "locale" | "modelId">;
|
|
4
6
|
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?: CmsStorageEntry;
|
|
22
7
|
}
|
|
23
8
|
interface DataLoadersHandlerParams {
|
|
24
9
|
entity: Entity<any>;
|
|
25
10
|
}
|
|
26
|
-
export declare class DataLoadersHandler {
|
|
27
|
-
private readonly loaders;
|
|
11
|
+
export declare class DataLoadersHandler implements DataLoadersHandlerInterface {
|
|
28
12
|
private readonly entity;
|
|
13
|
+
private readonly cache;
|
|
29
14
|
constructor(params: DataLoadersHandlerParams);
|
|
30
|
-
getAllEntryRevisions(params:
|
|
31
|
-
getRevisionById(params:
|
|
32
|
-
getPublishedRevisionByEntryId(params:
|
|
33
|
-
getLatestRevisionByEntryId(params:
|
|
15
|
+
getAllEntryRevisions(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
|
|
16
|
+
getRevisionById(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
|
|
17
|
+
getPublishedRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
|
|
18
|
+
getLatestRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
|
|
34
19
|
/**
|
|
35
20
|
* TODO @ts-refactor
|
|
36
21
|
* Maybe pass on the generics to DataLoader definition?
|
|
37
22
|
*/
|
|
38
23
|
private getLoader;
|
|
39
24
|
private loadMany;
|
|
40
|
-
clearAll(params
|
|
25
|
+
clearAll(params?: DataLoadersHandlerInterfaceClearAllParams): void;
|
|
41
26
|
}
|
|
42
27
|
export {};
|