@webiny/api-headless-cms-ddb 0.0.0-unstable.c2780f51fe → 0.0.0-unstable.c7dec08bb0
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/definitions/entry.js +3 -0
- package/definitions/entry.js.map +1 -1
- package/dynamoDb/index.js +2 -1
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +2 -0
- package/dynamoDb/path/locationFolderId.js +41 -0
- package/dynamoDb/path/locationFolderId.js.map +1 -0
- package/dynamoDb/storage/date.js +2 -11
- package/dynamoDb/storage/date.js.map +1 -1
- 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/filtering/createFields.d.ts +3 -1
- package/operations/entry/filtering/createFields.js +72 -72
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +3 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +3 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +3 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/systemFields.js +18 -0
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/where.js +3 -2
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +1 -1
- package/operations/entry/index.js +107 -5
- package/operations/entry/index.js.map +1 -1
- package/package.json +18 -18
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -1
- package/plugins/CmsEntryFieldFilterPathPlugin.js +3 -1
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/types.d.ts +10 -1
- package/types.js.map +1 -1
- package/operations/entry/systemFields.d.ts +0 -2
- package/operations/entry/systemFields.js +0 -72
- package/operations/entry/systemFields.js.map +0 -1
package/definitions/entry.js
CHANGED
package/definitions/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createEntryEntity","params","table","entityName","attributes","Entity","name","PK","type","partitionKey","SK","sortKey","GSI1_PK","GSI1_SK","TYPE","__type","webinyVersion","tenant","entryId","id","createdBy","ownedBy","modifiedBy","createdOn","savedOn","modelId","locale","publishedOn","version","locked","status","values","meta"],"sources":["entry.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\nexport const createEntryEntity = (params: Params): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n type: \"string\",\n partitionKey: true\n },\n SK: {\n type: \"string\",\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n __type: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n entryId: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n ownedBy: {\n type: \"map\"\n },\n modifiedBy: {\n type: \"map\"\n },\n createdOn: {\n type: \"string\"\n },\n savedOn: {\n type: \"string\"\n },\n modelId: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n publishedOn: {\n type: \"string\"\n },\n version: {\n type: \"number\"\n },\n locked: {\n type: \"boolean\"\n },\n status: {\n type: \"string\"\n },\n values: {\n type: \"map\"\n },\n meta: {\n type: \"map\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;AAAA;AAQO,MAAMA,iBAAiB,GAAIC,MAAc,IAAkB;EAC9D,MAAM;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAW,CAAC,GAAGH,MAAM;EAChD,OAAO,IAAII,uBAAM,CAAC;IACdC,IAAI,EAAEH,UAAU;IAChBD,KAAK;IACLE,UAAU;MACNG,EAAE,EAAE;QACAC,IAAI,EAAE,QAAQ;QACdC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAF,IAAI,EAAE,QAAQ;QACdG,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLJ,IAAI,EAAE;MACV,CAAC;MACDK,OAAO,EAAE;QACLL,IAAI,EAAE;MACV,CAAC;MACDM,IAAI,EAAE;QACFN,IAAI,EAAE;MACV,CAAC;MACDO,MAAM,EAAE;QACJP,IAAI,EAAE;MACV,CAAC;MACDQ,aAAa,EAAE;QACXR,IAAI,EAAE;MACV,CAAC;MACDS,MAAM,EAAE;QACJT,IAAI,EAAE;MACV,CAAC;MACDU,OAAO,EAAE;QACLV,IAAI,EAAE;MACV,CAAC;MACDW,EAAE,EAAE;QACAX,IAAI,EAAE;MACV,CAAC;MACDY,SAAS,EAAE;QACPZ,IAAI,EAAE;MACV,CAAC;MACDa,OAAO,EAAE;QACLb,IAAI,EAAE;MACV,CAAC;MACDc,UAAU,EAAE;QACRd,IAAI,EAAE;MACV,CAAC;MACDe,SAAS,EAAE;QACPf,IAAI,EAAE;MACV,CAAC;MACDgB,OAAO,EAAE;QACLhB,IAAI,EAAE;MACV,CAAC;MACDiB,OAAO,EAAE;QACLjB,IAAI,EAAE;MACV,CAAC;MACDkB,MAAM,EAAE;QACJlB,IAAI,EAAE;MACV,CAAC;MACDmB,WAAW,EAAE;QACTnB,IAAI,EAAE;MACV,CAAC;MACDoB,OAAO,EAAE;QACLpB,IAAI,EAAE;MACV,CAAC;MACDqB,MAAM,EAAE;QACJrB,IAAI,EAAE;MACV,CAAC;MACDsB,MAAM,EAAE;QACJtB,IAAI,EAAE;MACV,CAAC;MACDuB,
|
|
1
|
+
{"version":3,"names":["createEntryEntity","params","table","entityName","attributes","Entity","name","PK","type","partitionKey","SK","sortKey","GSI1_PK","GSI1_SK","TYPE","__type","webinyVersion","tenant","entryId","id","createdBy","ownedBy","modifiedBy","createdOn","savedOn","modelId","locale","publishedOn","version","locked","status","location","values","meta"],"sources":["entry.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\nexport const createEntryEntity = (params: Params): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n type: \"string\",\n partitionKey: true\n },\n SK: {\n type: \"string\",\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n __type: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n entryId: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n ownedBy: {\n type: \"map\"\n },\n modifiedBy: {\n type: \"map\"\n },\n createdOn: {\n type: \"string\"\n },\n savedOn: {\n type: \"string\"\n },\n modelId: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n publishedOn: {\n type: \"string\"\n },\n version: {\n type: \"number\"\n },\n locked: {\n type: \"boolean\"\n },\n status: {\n type: \"string\"\n },\n location: {\n type: \"map\"\n },\n values: {\n type: \"map\"\n },\n meta: {\n type: \"map\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;AAAA;AAQO,MAAMA,iBAAiB,GAAIC,MAAc,IAAkB;EAC9D,MAAM;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAW,CAAC,GAAGH,MAAM;EAChD,OAAO,IAAII,uBAAM,CAAC;IACdC,IAAI,EAAEH,UAAU;IAChBD,KAAK;IACLE,UAAU;MACNG,EAAE,EAAE;QACAC,IAAI,EAAE,QAAQ;QACdC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAF,IAAI,EAAE,QAAQ;QACdG,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLJ,IAAI,EAAE;MACV,CAAC;MACDK,OAAO,EAAE;QACLL,IAAI,EAAE;MACV,CAAC;MACDM,IAAI,EAAE;QACFN,IAAI,EAAE;MACV,CAAC;MACDO,MAAM,EAAE;QACJP,IAAI,EAAE;MACV,CAAC;MACDQ,aAAa,EAAE;QACXR,IAAI,EAAE;MACV,CAAC;MACDS,MAAM,EAAE;QACJT,IAAI,EAAE;MACV,CAAC;MACDU,OAAO,EAAE;QACLV,IAAI,EAAE;MACV,CAAC;MACDW,EAAE,EAAE;QACAX,IAAI,EAAE;MACV,CAAC;MACDY,SAAS,EAAE;QACPZ,IAAI,EAAE;MACV,CAAC;MACDa,OAAO,EAAE;QACLb,IAAI,EAAE;MACV,CAAC;MACDc,UAAU,EAAE;QACRd,IAAI,EAAE;MACV,CAAC;MACDe,SAAS,EAAE;QACPf,IAAI,EAAE;MACV,CAAC;MACDgB,OAAO,EAAE;QACLhB,IAAI,EAAE;MACV,CAAC;MACDiB,OAAO,EAAE;QACLjB,IAAI,EAAE;MACV,CAAC;MACDkB,MAAM,EAAE;QACJlB,IAAI,EAAE;MACV,CAAC;MACDmB,WAAW,EAAE;QACTnB,IAAI,EAAE;MACV,CAAC;MACDoB,OAAO,EAAE;QACLpB,IAAI,EAAE;MACV,CAAC;MACDqB,MAAM,EAAE;QACJrB,IAAI,EAAE;MACV,CAAC;MACDsB,MAAM,EAAE;QACJtB,IAAI,EAAE;MACV,CAAC;MACDuB,QAAQ,EAAE;QACNvB,IAAI,EAAE;MACV,CAAC;MACDwB,MAAM,EAAE;QACJxB,IAAI,EAAE;MACV,CAAC;MACDyB,IAAI,EAAE;QACFzB,IAAI,EAAE;MACV;IAAC,GACGJ,UAAU,IAAI,CAAC,CAAC;EAE5B,CAAC,CAAC;AACN,CAAC;AAAC"}
|
package/dynamoDb/index.js
CHANGED
|
@@ -9,5 +9,6 @@ var _longText = require("./storage/longText");
|
|
|
9
9
|
var _date = require("./storage/date");
|
|
10
10
|
var _plainObject = require("./path/plainObject");
|
|
11
11
|
var _datetime = require("./transformValue/datetime");
|
|
12
|
-
var
|
|
12
|
+
var _locationFolderId = require("./path/locationFolderId");
|
|
13
|
+
var _default = () => [(0, _richText.createRichTextStorageTransformPlugin)(), (0, _longText.createLongTextStorageTransformPlugin)(), (0, _date.createDateStorageTransformPlugin)(), (0, _plainObject.createPlainObjectPathPlugin)(), (0, _locationFolderId.createLocationFolderIdPathPlugin)(), (0, _datetime.createDatetimeTransformValuePlugin)()];
|
|
13
14
|
exports.default = _default;
|
package/dynamoDb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createRichTextStorageTransformPlugin","createLongTextStorageTransformPlugin","createDateStorageTransformPlugin","createPlainObjectPathPlugin","createDatetimeTransformValuePlugin"],"sources":["index.ts"],"sourcesContent":["import { createRichTextStorageTransformPlugin } from \"./storage/richText\";\nimport { createLongTextStorageTransformPlugin } from \"./storage/longText\";\nimport { createDateStorageTransformPlugin } from \"./storage/date\";\nimport { createPlainObjectPathPlugin } from \"./path/plainObject\";\nimport { createDatetimeTransformValuePlugin } from \"./transformValue/datetime\";\n\nexport default () => [\n createRichTextStorageTransformPlugin(),\n createLongTextStorageTransformPlugin(),\n createDateStorageTransformPlugin(),\n createPlainObjectPathPlugin(),\n createDatetimeTransformValuePlugin()\n];\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"names":["createRichTextStorageTransformPlugin","createLongTextStorageTransformPlugin","createDateStorageTransformPlugin","createPlainObjectPathPlugin","createLocationFolderIdPathPlugin","createDatetimeTransformValuePlugin"],"sources":["index.ts"],"sourcesContent":["import { createRichTextStorageTransformPlugin } from \"./storage/richText\";\nimport { createLongTextStorageTransformPlugin } from \"./storage/longText\";\nimport { createDateStorageTransformPlugin } from \"./storage/date\";\nimport { createPlainObjectPathPlugin } from \"./path/plainObject\";\nimport { createDatetimeTransformValuePlugin } from \"./transformValue/datetime\";\nimport { createLocationFolderIdPathPlugin } from \"~/dynamoDb/path/locationFolderId\";\n\nexport default () => [\n createRichTextStorageTransformPlugin(),\n createLongTextStorageTransformPlugin(),\n createDateStorageTransformPlugin(),\n createPlainObjectPathPlugin(),\n createLocationFolderIdPathPlugin(),\n createDatetimeTransformValuePlugin()\n];\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAAoF,eAErE,MAAM,CACjB,IAAAA,8CAAoC,GAAE,EACtC,IAAAC,8CAAoC,GAAE,EACtC,IAAAC,sCAAgC,GAAE,EAClC,IAAAC,wCAA2B,GAAE,EAC7B,IAAAC,kDAAgC,GAAE,EAClC,IAAAC,4CAAkC,GAAE,CACvC;AAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createLocationFolderIdPathPlugin = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _CmsEntryFieldFilterPathPlugin = require("../../plugins/CmsEntryFieldFilterPathPlugin");
|
|
10
|
+
/**
|
|
11
|
+
* File is @internal
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const createPath = ({
|
|
15
|
+
field
|
|
16
|
+
}) => {
|
|
17
|
+
const {
|
|
18
|
+
path
|
|
19
|
+
} = field.settings || {};
|
|
20
|
+
if (!path) {
|
|
21
|
+
throw new _error.default("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
|
|
22
|
+
field
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return path;
|
|
26
|
+
};
|
|
27
|
+
const createLocationFolderIdPathPlugin = () => {
|
|
28
|
+
return new _CmsEntryFieldFilterPathPlugin.CmsEntryFieldFilterPathPlugin({
|
|
29
|
+
fieldType: "text",
|
|
30
|
+
path: createPath,
|
|
31
|
+
canUse: (field, parents) => {
|
|
32
|
+
if (field.fieldId !== "folderId") {
|
|
33
|
+
return false;
|
|
34
|
+
} else if (!(parents !== null && parents !== void 0 && parents.length)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return parents[0] === "wbyAco_location";
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
exports.createLocationFolderIdPathPlugin = createLocationFolderIdPathPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPath","field","path","settings","WebinyError","createLocationFolderIdPathPlugin","CmsEntryFieldFilterPathPlugin","fieldType","canUse","parents","fieldId","length"],"sources":["locationFolderId.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsEntryFieldFilterPathPlugin,\n CreatePathCallable\n} from \"~/plugins/CmsEntryFieldFilterPathPlugin\";\n\nconst createPath: CreatePathCallable = ({ field }) => {\n const { path } = field.settings || {};\n if (!path) {\n throw new WebinyError(\"Missing path settings value.\", \"FIELD_SETTINGS_ERROR\", {\n field\n });\n }\n return path;\n};\n\nexport const createLocationFolderIdPathPlugin = (): CmsEntryFieldFilterPathPlugin => {\n return new CmsEntryFieldFilterPathPlugin({\n fieldType: \"text\",\n path: createPath,\n canUse: (field, parents) => {\n if (field.fieldId !== \"folderId\") {\n return false;\n } else if (!parents?.length) {\n return false;\n }\n return parents[0] === \"wbyAco_location\";\n }\n });\n};\n"],"mappings":";;;;;;;AAGA;AACA;AAJA;AACA;AACA;;AAOA,MAAMA,UAA8B,GAAG,CAAC;EAAEC;AAAM,CAAC,KAAK;EAClD,MAAM;IAAEC;EAAK,CAAC,GAAGD,KAAK,CAACE,QAAQ,IAAI,CAAC,CAAC;EACrC,IAAI,CAACD,IAAI,EAAE;IACP,MAAM,IAAIE,cAAW,CAAC,8BAA8B,EAAE,sBAAsB,EAAE;MAC1EH;IACJ,CAAC,CAAC;EACN;EACA,OAAOC,IAAI;AACf,CAAC;AAEM,MAAMG,gCAAgC,GAAG,MAAqC;EACjF,OAAO,IAAIC,4DAA6B,CAAC;IACrCC,SAAS,EAAE,MAAM;IACjBL,IAAI,EAAEF,UAAU;IAChBQ,MAAM,EAAE,CAACP,KAAK,EAAEQ,OAAO,KAAK;MACxB,IAAIR,KAAK,CAACS,OAAO,KAAK,UAAU,EAAE;QAC9B,OAAO,KAAK;MAChB,CAAC,MAAM,IAAI,EAACD,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEE,MAAM,GAAE;QACzB,OAAO,KAAK;MAChB;MACA,OAAOF,OAAO,CAAC,CAAC,CAAC,KAAK,iBAAiB;IAC3C;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
package/dynamoDb/storage/date.js
CHANGED
|
@@ -33,7 +33,7 @@ const convertFromStorage = (field, value) => {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
const convertValueToStorage = (field, value) => {
|
|
36
|
-
if (value.toISOString) {
|
|
36
|
+
if (value instanceof Date || value.toISOString) {
|
|
37
37
|
return value.toISOString();
|
|
38
38
|
} else if (typeof value === "string") {
|
|
39
39
|
return value;
|
|
@@ -75,16 +75,7 @@ const createDateStorageTransformPlugin = () => {
|
|
|
75
75
|
return convertValueToStorage(field, v);
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
return value.toISOString();
|
|
80
|
-
} else if (typeof value === "string") {
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
throw new _error.default("Error converting value to a storage type.", "TO_STORAGE_ERROR", {
|
|
84
|
-
value,
|
|
85
|
-
fieldId: field.fieldId,
|
|
86
|
-
storageId: field.storageId
|
|
87
|
-
});
|
|
78
|
+
return convertValueToStorage(field, value);
|
|
88
79
|
}
|
|
89
80
|
});
|
|
90
81
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["excludeTypes","convertFromStorage","field","value","multipleValues","result","v","push","Date","console","log","convertValueToStorage","toISOString","WebinyError","fieldId","storageId","createDateStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","type","settings","includes","toStorage","filter","map"],"sources":["date.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\nconst excludeTypes = [\"time\", \"dateTimeWithTimezone\"];\n\nconst convertFromStorage = (\n field: Pick<CmsModelField, \"multipleValues\">,\n value: string | string[]\n) => {\n try {\n if (field.multipleValues) {\n const result: Date[] = [];\n for (const v of value) {\n if (!v) {\n continue;\n }\n try {\n result.push(new Date(v));\n } catch {}\n }\n return result;\n }\n return new Date(value as string);\n } catch {\n console.log(`Could not transform from storage for field type`);\n return value;\n }\n};\n\nconst convertValueToStorage = (field: CmsModelField, value: any): any => {\n if ((value as any).toISOString) {\n return (value as Date).toISOString();\n } else if (typeof value === \"string\") {\n return value as string;\n }\n throw new WebinyError(\"Error converting value to a storage type.\", \"TO_STORAGE_ERROR\", {\n value: value,\n fieldId: field.fieldId,\n storageId: field.storageId\n });\n};\n\nexport const createDateStorageTransformPlugin = () => {\n return new StorageTransformPlugin({\n fieldType: \"datetime\",\n fromStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\n }\n return convertFromStorage(field, value);\n },\n toStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\n }\n if (field.multipleValues) {\n const multipleValues = value as (string | Date | null | undefined)[];\n return (multipleValues || [])\n .filter(v => !!v)\n .map(v => {\n return convertValueToStorage(field, v);\n });\n }\n
|
|
1
|
+
{"version":3,"names":["excludeTypes","convertFromStorage","field","value","multipleValues","result","v","push","Date","console","log","convertValueToStorage","toISOString","WebinyError","fieldId","storageId","createDateStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","type","settings","includes","toStorage","filter","map"],"sources":["date.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\nconst excludeTypes = [\"time\", \"dateTimeWithTimezone\"];\n\nconst convertFromStorage = (\n field: Pick<CmsModelField, \"multipleValues\">,\n value: string | string[]\n) => {\n try {\n if (field.multipleValues) {\n const result: Date[] = [];\n for (const v of value) {\n if (!v) {\n continue;\n }\n try {\n result.push(new Date(v));\n } catch {}\n }\n return result;\n }\n return new Date(value as string);\n } catch {\n console.log(`Could not transform from storage for field type`);\n return value;\n }\n};\n\nconst convertValueToStorage = (field: CmsModelField, value: any): any => {\n if (value instanceof Date || (value as any).toISOString) {\n return (value as Date).toISOString();\n } else if (typeof value === \"string\") {\n return value as string;\n }\n throw new WebinyError(\"Error converting value to a storage type.\", \"TO_STORAGE_ERROR\", {\n value: value,\n fieldId: field.fieldId,\n storageId: field.storageId\n });\n};\n\nexport const createDateStorageTransformPlugin = () => {\n return new StorageTransformPlugin({\n fieldType: \"datetime\",\n fromStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\n }\n return convertFromStorage(field, value);\n },\n toStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\n }\n if (field.multipleValues) {\n const multipleValues = value as (string | Date | null | undefined)[];\n return (multipleValues || [])\n .filter(v => !!v)\n .map(v => {\n return convertValueToStorage(field, v);\n });\n }\n return convertValueToStorage(field, value);\n }\n });\n};\n"],"mappings":";;;;;;;AAGA;AACA;AAJA;AACA;AACA;;AAKA,MAAMA,YAAY,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC;AAErD,MAAMC,kBAAkB,GAAG,CACvBC,KAA4C,EAC5CC,KAAwB,KACvB;EACD,IAAI;IACA,IAAID,KAAK,CAACE,cAAc,EAAE;MACtB,MAAMC,MAAc,GAAG,EAAE;MACzB,KAAK,MAAMC,CAAC,IAAIH,KAAK,EAAE;QACnB,IAAI,CAACG,CAA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,MAAM;QAAEkB;MAAK,CAAC,GAAGlB,KAAK,CAACmB,QAAQ,IAAI,CAAC,CAAC;MACrC,IAAI,CAAClB,KAAK,IAAI,CAACiB,IAAI,IAAIpB,YAAY,CAACsB,QAAQ,CAACF,IAAI,CAAC,EAAE;QAChD,OAAOjB,KAAK;MAChB;MACA,IAAID,KAAK,CAACE,cAAc,EAAE;QACtB,MAAMA,cAAc,GAAGD,KAA6C;QACpE,OAAO,CAACC,cAAc,IAAI,EAAE,EACvBoB,MAAM,CAAClB,CAAC,IAAI,CAAC,CAACA,CAAC,CAAC,CAChBmB,GAAG,CAACnB,CAAC,IAAI;UACN,OAAOK,qBAAqB,CAACT,KAAK,EAAEI,CAAC,CAAC;QAC1C,CAAC,CAAC;MACV;MACA,OAAOK,qBAAqB,CAACT,KAAK,EAAEC,KAAK,CAAC;IAC9C;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
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":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AASA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAHA;AACA;AAIO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;EACvE,MAAM;IAAEC,UAAU;IAAEC,KAAK;IAAEC,cAAc;IAAEC,OAAO,EAAEC;EAAY,CAAC,GAAGL,MAAM;EAE1E,MAAMM,aAAa,GAAG,IAAAC,kBAAW,EAAC;IAC9BL,KAAK;IACLC;EACJ,CAAC,CAAC;EAEF,MAAMK,QAAQ,G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AQ,CAACY;IACrB,CAAC,CAAC;IACFG;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -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":";;;;;;;;;AA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
|
|
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,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
|
+
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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