@webiny/api-headless-cms-ddb 0.0.0-ee-vpcs.549378cf03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/definitions/entry.d.ts +9 -0
- package/definitions/entry.js +96 -0
- package/definitions/entry.js.map +1 -0
- package/definitions/group.d.ts +9 -0
- package/definitions/group.js +70 -0
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +9 -0
- package/definitions/model.js +97 -0
- package/definitions/model.js.map +1 -0
- package/definitions/settings.d.ts +9 -0
- package/definitions/settings.js +58 -0
- package/definitions/settings.js.map +1 -0
- package/definitions/system.d.ts +9 -0
- package/definitions/system.js +46 -0
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +9 -0
- package/definitions/table.js +30 -0
- package/definitions/table.js.map +1 -0
- package/dynamoDb/index.d.ts +2 -0
- package/dynamoDb/index.js +20 -0
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +2 -0
- package/dynamoDb/path/plainObject.js +40 -0
- package/dynamoDb/path/plainObject.js.map +1 -0
- package/dynamoDb/storage/date.d.ts +3 -0
- package/dynamoDb/storage/date.js +109 -0
- package/dynamoDb/storage/date.js.map +1 -0
- package/dynamoDb/storage/longText.d.ts +10 -0
- package/dynamoDb/storage/longText.js +108 -0
- package/dynamoDb/storage/longText.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +2 -0
- package/dynamoDb/storage/richText.js +113 -0
- package/dynamoDb/storage/richText.js.map +1 -0
- package/dynamoDb/transformValue/datetime.d.ts +5 -0
- package/dynamoDb/transformValue/datetime.js +52 -0
- package/dynamoDb/transformValue/datetime.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +150 -0
- package/index.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +42 -0
- package/operations/entry/dataLoaders.js +321 -0
- package/operations/entry/dataLoaders.js.map +1 -0
- package/operations/entry/filtering/createExpressions.d.ts +26 -0
- package/operations/entry/filtering/createExpressions.js +217 -0
- package/operations/entry/filtering/createExpressions.js.map +1 -0
- package/operations/entry/filtering/createFields.d.ts +14 -0
- package/operations/entry/filtering/createFields.js +123 -0
- package/operations/entry/filtering/createFields.js.map +1 -0
- package/operations/entry/filtering/extractSort.d.ts +13 -0
- package/operations/entry/filtering/extractSort.js +55 -0
- package/operations/entry/filtering/extractSort.js.map +1 -0
- package/operations/entry/filtering/filter.d.ts +15 -0
- package/operations/entry/filtering/filter.js +178 -0
- package/operations/entry/filtering/filter.js.map +1 -0
- package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
- package/operations/entry/filtering/fullTextSearch.js +60 -0
- package/operations/entry/filtering/fullTextSearch.js.map +1 -0
- package/operations/entry/filtering/getValue.d.ts +5 -0
- package/operations/entry/filtering/getValue.js +81 -0
- package/operations/entry/filtering/getValue.js.map +1 -0
- package/operations/entry/filtering/index.d.ts +2 -0
- package/operations/entry/filtering/index.js +21 -0
- package/operations/entry/filtering/index.js.map +1 -0
- package/operations/entry/filtering/mapPlugins.d.ts +8 -0
- package/operations/entry/filtering/mapPlugins.js +39 -0
- package/operations/entry/filtering/mapPlugins.js.map +1 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +48 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/filtering/plugins/index.js +18 -0
- package/operations/entry/filtering/plugins/index.js.map +1 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js +107 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js +89 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +9 -0
- package/operations/entry/filtering/sort.js +80 -0
- package/operations/entry/filtering/sort.js.map +1 -0
- package/operations/entry/filtering/systemFields.d.ts +4 -0
- package/operations/entry/filtering/systemFields.js +72 -0
- package/operations/entry/filtering/systemFields.js.map +1 -0
- package/operations/entry/filtering/transform.d.ts +6 -0
- package/operations/entry/filtering/transform.js +19 -0
- package/operations/entry/filtering/transform.js.map +1 -0
- package/operations/entry/filtering/types.d.ts +40 -0
- package/operations/entry/filtering/types.js +5 -0
- package/operations/entry/filtering/types.js.map +1 -0
- package/operations/entry/filtering/values.d.ts +2 -0
- package/operations/entry/filtering/values.js +28 -0
- package/operations/entry/filtering/values.js.map +1 -0
- package/operations/entry/filtering/where.d.ts +5 -0
- package/operations/entry/filtering/where.js +38 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.d.ts +8 -0
- package/operations/entry/index.js +872 -0
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/keys.d.ts +25 -0
- package/operations/entry/keys.js +73 -0
- package/operations/entry/keys.js.map +1 -0
- package/operations/entry/systemFields.d.ts +2 -0
- package/operations/entry/systemFields.js +74 -0
- package/operations/entry/systemFields.js.map +1 -0
- package/operations/group/index.d.ts +9 -0
- package/operations/group/index.js +192 -0
- package/operations/group/index.js.map +1 -0
- package/operations/model/index.d.ts +7 -0
- package/operations/model/index.js +162 -0
- package/operations/model/index.js.map +1 -0
- package/operations/settings/index.d.ts +7 -0
- package/operations/settings/index.js +135 -0
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +7 -0
- package/operations/system/index.js +99 -0
- package/operations/system/index.js.map +1 -0
- package/package.json +60 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +22 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js +55 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/plugins/index.js.map +1 -0
- package/types.d.ts +53 -0
- package/types.js +16 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createDateStorageTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* File is @internal
|
|
16
|
+
*/
|
|
17
|
+
const excludeTypes = ["time", "dateTimeWithTimezone"];
|
|
18
|
+
|
|
19
|
+
const convertFromStorage = (field, value) => {
|
|
20
|
+
try {
|
|
21
|
+
if (field.multipleValues) {
|
|
22
|
+
const result = [];
|
|
23
|
+
|
|
24
|
+
for (const v of value) {
|
|
25
|
+
if (!v) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
result.push(new Date(v));
|
|
31
|
+
} catch {}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return new Date(value);
|
|
38
|
+
} catch {
|
|
39
|
+
console.log(`Could not transform from storage for field type`);
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const convertValueToStorage = (field, value) => {
|
|
45
|
+
if (value.toISOString) {
|
|
46
|
+
return value.toISOString();
|
|
47
|
+
} else if (typeof value === "string") {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
throw new _error.default("Error converting value to a storage type.", "TO_STORAGE_ERROR", {
|
|
52
|
+
value: value,
|
|
53
|
+
fieldId: field.fieldId,
|
|
54
|
+
storageId: field.storageId
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const createDateStorageTransformPlugin = () => {
|
|
59
|
+
return new _apiHeadlessCms.StorageTransformPlugin({
|
|
60
|
+
fieldType: "datetime",
|
|
61
|
+
fromStorage: async ({
|
|
62
|
+
value,
|
|
63
|
+
field
|
|
64
|
+
}) => {
|
|
65
|
+
const {
|
|
66
|
+
type
|
|
67
|
+
} = field.settings || {};
|
|
68
|
+
|
|
69
|
+
if (!value || !type || excludeTypes.includes(type)) {
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return convertFromStorage(field, value);
|
|
74
|
+
},
|
|
75
|
+
toStorage: async ({
|
|
76
|
+
value,
|
|
77
|
+
field
|
|
78
|
+
}) => {
|
|
79
|
+
const {
|
|
80
|
+
type
|
|
81
|
+
} = field.settings || {};
|
|
82
|
+
|
|
83
|
+
if (!value || !type || excludeTypes.includes(type)) {
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (field.multipleValues) {
|
|
88
|
+
const multipleValues = value;
|
|
89
|
+
return (multipleValues || []).filter(v => !!v).map(v => {
|
|
90
|
+
return convertValueToStorage(field, v);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (value.toISOString) {
|
|
95
|
+
return value.toISOString();
|
|
96
|
+
} else if (typeof value === "string") {
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
throw new _error.default("Error converting value to a storage type.", "TO_STORAGE_ERROR", {
|
|
101
|
+
value,
|
|
102
|
+
fieldId: field.fieldId,
|
|
103
|
+
storageId: field.storageId
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
exports.createDateStorageTransformPlugin = createDateStorageTransformPlugin;
|
|
@@ -0,0 +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 if ((value as any).toISOString) {\n return (value as Date).toISOString();\n } else if (typeof value === \"string\") {\n return value as string;\n }\n throw new WebinyError(\"Error converting value to a storage type.\", \"TO_STORAGE_ERROR\", {\n value,\n fieldId: field.fieldId,\n storageId: field.storageId\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAKA,MAAMA,YAAY,GAAG,CAAC,MAAD,EAAS,sBAAT,CAArB;;AAEA,MAAMC,kBAAkB,GAAG,CACvBC,KADuB,EAEvBC,KAFuB,KAGtB;EACD,IAAI;IACA,IAAID,KAAK,CAACE,cAAV,EAA0B;MACtB,MAAMC,MAAc,GAAG,EAAvB;;MACA,KAAK,MAAMC,CAAX,IAAgBH,KAAhB,EAAuB;QACnB,IAAI,CAACG,CAAL,EAAQ;UACJ;QACH;;QACD,IAAI;UACAD,MAAM,CAACE,IAAP,CAAY,IAAIC,IAAJ,CAASF,CAAT,CAAZ;QACH,CAFD,CAEE,MAAM,CAAE;MACb;;MACD,OAAOD,MAAP;IACH;;IACD,OAAO,IAAIG,IAAJ,CAASL,KAAT,CAAP;EACH,CAdD,CAcE,MAAM;IACJM,OAAO,CAACC,GAAR,CAAa,iDAAb;IACA,OAAOP,KAAP;EACH;AACJ,CAtBD;;AAwBA,MAAMQ,qBAAqB,GAAG,CAACT,KAAD,EAAuBC,KAAvB,KAA2C;EACrE,IAAKA,KAAD,CAAeS,WAAnB,EAAgC;IAC5B,OAAQT,KAAD,CAAgBS,WAAhB,EAAP;EACH,CAFD,MAEO,IAAI,OAAOT,KAAP,KAAiB,QAArB,EAA+B;IAClC,OAAOA,KAAP;EACH;;EACD,MAAM,IAAIU,cAAJ,CAAgB,2CAAhB,EAA6D,kBAA7D,EAAiF;IACnFV,KAAK,EAAEA,KAD4E;IAEnFW,OAAO,EAAEZ,KAAK,CAACY,OAFoE;IAGnFC,SAAS,EAAEb,KAAK,CAACa;EAHkE,CAAjF,CAAN;AAKH,CAXD;;AAaO,MAAMC,gCAAgC,GAAG,MA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KAAK,CAACa;MAHkE,CAAjF,CAAN;IAKH;EAhC6B,CAA3B,CAAP;AAkCH,CAnCM"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File is @internal
|
|
3
|
+
*/
|
|
4
|
+
import { StorageTransformPlugin } from "@webiny/api-headless-cms";
|
|
5
|
+
export interface StorageValue {
|
|
6
|
+
compression: string;
|
|
7
|
+
value: string;
|
|
8
|
+
isArray?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const createLongTextStorageTransformPlugin: () => StorageTransformPlugin<string | string[], StorageValue, import("@webiny/api-headless-cms/types").CmsModelField>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createLongTextStorageTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _gzip = require("@webiny/utils/compression/gzip");
|
|
13
|
+
|
|
14
|
+
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* File is @internal
|
|
18
|
+
*/
|
|
19
|
+
const GZIP = "gzip";
|
|
20
|
+
const TO_STORAGE_ENCODING = "base64";
|
|
21
|
+
const FROM_STORAGE_ENCODING = "utf8";
|
|
22
|
+
|
|
23
|
+
const convertToBuffer = value => {
|
|
24
|
+
if (typeof value === "string") {
|
|
25
|
+
return Buffer.from(value, TO_STORAGE_ENCODING);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const createLongTextStorageTransformPlugin = () => {
|
|
32
|
+
return new _apiHeadlessCms.StorageTransformPlugin({
|
|
33
|
+
fieldType: "long-text",
|
|
34
|
+
fromStorage: async ({
|
|
35
|
+
field,
|
|
36
|
+
value: storageValue
|
|
37
|
+
}) => {
|
|
38
|
+
const typeOf = typeof storageValue;
|
|
39
|
+
|
|
40
|
+
if (!storageValue || typeOf === "string" || typeOf === "number" || Array.isArray(storageValue) === true) {
|
|
41
|
+
return storageValue;
|
|
42
|
+
} else if (typeOf !== "object") {
|
|
43
|
+
throw new _error.default(`LongText value received in "fromStorage" function is not an object in field "${field.storageId}" - ${field.fieldId}.`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
compression,
|
|
48
|
+
value,
|
|
49
|
+
isArray
|
|
50
|
+
} = storageValue;
|
|
51
|
+
/**
|
|
52
|
+
* Check if possibly undefined, null, empty...
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
if (!compression) {
|
|
56
|
+
throw new _error.default(`Missing compression in "fromStorage" function in field "${field.storageId}" - ${field.fieldId}.": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
|
|
57
|
+
value: storageValue
|
|
58
|
+
});
|
|
59
|
+
} else if (compression !== GZIP) {
|
|
60
|
+
throw new _error.default(`This plugin cannot transform something not compressed with "GZIP".`, "WRONG_COMPRESSION", {
|
|
61
|
+
compression
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const buf = await (0, _gzip.decompress)(convertToBuffer(value));
|
|
67
|
+
const result = buf.toString(FROM_STORAGE_ENCODING);
|
|
68
|
+
|
|
69
|
+
if (!isArray) {
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return JSON.parse(result);
|
|
74
|
+
} catch (ex) {
|
|
75
|
+
console.log("Error while transforming long-text.");
|
|
76
|
+
console.log(ex.message);
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
toStorage: async ({
|
|
81
|
+
value: initialValue
|
|
82
|
+
}) => {
|
|
83
|
+
/**
|
|
84
|
+
* There is a possibility that we are trying to compress already compressed value.
|
|
85
|
+
*/
|
|
86
|
+
if (initialValue && initialValue.hasOwnProperty("compression") === true) {
|
|
87
|
+
return initialValue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const isArray = Array.isArray(initialValue);
|
|
91
|
+
const value = isArray ? JSON.stringify(initialValue) : initialValue;
|
|
92
|
+
const compressedValue = await (0, _gzip.compress)(value);
|
|
93
|
+
const result = {
|
|
94
|
+
compression: GZIP,
|
|
95
|
+
value: compressedValue.toString(TO_STORAGE_ENCODING)
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (!isArray) {
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
result.isArray = isArray;
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
exports.createLongTextStorageTransformPlugin = createLongTextStorageTransformPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","createLongTextStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","typeOf","Array","isArray","WebinyError","storageId","fieldId","compression","JSON","stringify","buf","ungzip","result","toString","parse","ex","console","log","message","toStorage","initialValue","hasOwnProperty","compressedValue","gzip"],"sources":["longText.ts"],"sourcesContent":["/**\n * File is @internal\n */\n\nimport WebinyError from \"@webiny/error\";\nimport { compress as gzip, decompress as ungzip } from \"@webiny/utils/compression/gzip\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nconst GZIP = \"gzip\";\nconst TO_STORAGE_ENCODING = \"base64\";\nconst FROM_STORAGE_ENCODING = \"utf8\";\n\nconst convertToBuffer = (value: string | Buffer): Buffer => {\n if (typeof value === \"string\") {\n return Buffer.from(value, TO_STORAGE_ENCODING);\n }\n return value;\n};\n\nexport interface StorageValue {\n compression: string;\n value: string;\n isArray?: boolean;\n}\n\nexport const createLongTextStorageTransformPlugin = () => {\n return new StorageTransformPlugin<string | string[], StorageValue>({\n fieldType: \"long-text\",\n fromStorage: async ({ field, value: storageValue }) => {\n const typeOf = typeof storageValue;\n if (\n !storageValue ||\n typeOf === \"string\" ||\n typeOf === \"number\" ||\n Array.isArray(storageValue) === true\n ) {\n return storageValue as unknown as string | string[];\n } else if (typeOf !== \"object\") {\n throw new WebinyError(\n `LongText value received in \"fromStorage\" function is not an object in field \"${field.storageId}\" - ${field.fieldId}.`\n );\n }\n const { compression, value, isArray } = storageValue;\n /**\n * Check if possibly undefined, null, empty...\n */\n if (!compression) {\n throw new WebinyError(\n `Missing compression in \"fromStorage\" function in field \"${\n field.storageId\n }\" - ${field.fieldId}.\": ${JSON.stringify(storageValue)}.`,\n \"MISSING_COMPRESSION\",\n {\n value: storageValue\n }\n );\n } else if (compression !== GZIP) {\n throw new WebinyError(\n `This plugin cannot transform something not compressed with \"GZIP\".`,\n \"WRONG_COMPRESSION\",\n {\n compression\n }\n );\n }\n try {\n const buf = await ungzip(convertToBuffer(value));\n const result = buf.toString(FROM_STORAGE_ENCODING);\n if (!isArray) {\n return result;\n }\n return JSON.parse(result);\n } catch (ex) {\n console.log(\"Error while transforming long-text.\");\n console.log(ex.message);\n return \"\";\n }\n },\n toStorage: async ({ value: initialValue }) => {\n /**\n * There is a possibility that we are trying to compress already compressed value.\n */\n if (initialValue && initialValue.hasOwnProperty(\"compression\") === true) {\n return initialValue as any;\n }\n const isArray = Array.isArray(initialValue);\n const value = isArray ? JSON.stringify(initialValue) : initialValue;\n const compressedValue = await gzip(value);\n\n const result: StorageValue = {\n compression: GZIP,\n value: compressedValue.toString(TO_STORAGE_ENCODING)\n };\n if (!isArray) {\n return result;\n }\n result.isArray = isArray;\n return result;\n }\n });\n};\n"],"mappings":";;;;;;;;;AAIA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,MAAMA,IAAI,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ireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createRichTextStorageTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _jsonpack = _interopRequireDefault(require("jsonpack"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* File is @internal
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Remove when jsonpack gets PR with a fix merged
|
|
22
|
+
* https://github.com/rgcl/jsonpack/pull/25/files
|
|
23
|
+
* NOTE 2021-07-28: it seems PR is not going to be merged so keep this.
|
|
24
|
+
*/
|
|
25
|
+
// TODO @ts-refactor figure better type
|
|
26
|
+
const transformArray = value => {
|
|
27
|
+
if (!value) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let isArray = Array.isArray(value);
|
|
32
|
+
const shouldBeArray = value instanceof Array === false && isArray;
|
|
33
|
+
|
|
34
|
+
if (shouldBeArray) {
|
|
35
|
+
value = Array.from(value);
|
|
36
|
+
isArray = true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof value === "object" || isArray) {
|
|
40
|
+
for (const k in value) {
|
|
41
|
+
value[k] = transformArray(value[k]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return value;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const createRichTextStorageTransformPlugin = () => {
|
|
49
|
+
return new _apiHeadlessCms.StorageTransformPlugin({
|
|
50
|
+
fieldType: "rich-text",
|
|
51
|
+
fromStorage: async ({
|
|
52
|
+
field,
|
|
53
|
+
value: storageValue
|
|
54
|
+
}) => {
|
|
55
|
+
if (!storageValue) {
|
|
56
|
+
return storageValue;
|
|
57
|
+
} else if (typeof storageValue !== "object") {
|
|
58
|
+
throw new _error.default(`RichText value received in "fromStorage" function is not an object in field "${field.storageId}" - ${field.fieldId}.`);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* This is to circumvent a bug introduced with 5.8.0 storage operations.
|
|
62
|
+
* Do not remove.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if (storageValue.hasOwnProperty("compression") === false) {
|
|
67
|
+
return storageValue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
compression,
|
|
72
|
+
value
|
|
73
|
+
} = storageValue;
|
|
74
|
+
|
|
75
|
+
if (!compression) {
|
|
76
|
+
throw new _error.default(`Missing compression in "fromStorage" function in field "${field.fieldId}": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
|
|
77
|
+
value: storageValue
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (compression !== "jsonpack") {
|
|
82
|
+
throw new _error.default(`This plugin cannot transform something not packed with "jsonpack".`, "WRONG_COMPRESSION", {
|
|
83
|
+
compression
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
return _jsonpack.default.unpack(value);
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
toStorage: async ({
|
|
94
|
+
value
|
|
95
|
+
}) => {
|
|
96
|
+
/**
|
|
97
|
+
* There is a possibility that we are trying to compress already compressed value.
|
|
98
|
+
* Introduced a bug with 5.8.0 storage operations, so just return the value to correct it.
|
|
99
|
+
*/
|
|
100
|
+
if (value && value.hasOwnProperty("compression") === true) {
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
value = transformArray(value);
|
|
105
|
+
return {
|
|
106
|
+
compression: "jsonpack",
|
|
107
|
+
value: value ? _jsonpack.default.pack(value) : value
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
exports.createRichTextStorageTransformPlugin = createRichTextStorageTransformPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["transformArray","value","isArray","Array","shouldBeArray","from","k","createRichTextStorageTransformPlugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","WebinyError","storageId","fieldId","hasOwnProperty","compression","JSON","stringify","jsonpack","unpack","toStorage","pack"],"sources":["richText.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport jsonpack from \"jsonpack\";\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\n/**\n * Remove when jsonpack gets PR with a fix merged\n * https://github.com/rgcl/jsonpack/pull/25/files\n * NOTE 2021-07-28: it seems PR is not going to be merged so keep this.\n */\n// TODO @ts-refactor figure better type\nconst transformArray = (value: any) => {\n if (!value) {\n return value;\n }\n let isArray = Array.isArray(value);\n const shouldBeArray = value instanceof Array === false && isArray;\n if (shouldBeArray) {\n value = Array.from(value);\n isArray = true;\n }\n if (typeof value === \"object\" || isArray) {\n for (const k in value) {\n value[k] = transformArray(value[k]);\n }\n }\n return value;\n};\n\nexport const createRichTextStorageTransformPlugin = () => {\n return new StorageTransformPlugin({\n fieldType: \"rich-text\",\n fromStorage: async ({ field, value: storageValue }) => {\n if (!storageValue) {\n return storageValue;\n } else if (typeof storageValue !== \"object\") {\n throw new WebinyError(\n `RichText value received in \"fromStorage\" function is not an object in field \"${field.storageId}\" - ${field.fieldId}.`\n );\n }\n /**\n * This is to circumvent a bug introduced with 5.8.0 storage operations.\n * Do not remove.\n */\n if (storageValue.hasOwnProperty(\"compression\") === false) {\n return storageValue;\n }\n const { compression, value } = storageValue;\n if (!compression) {\n throw new WebinyError(\n `Missing compression in \"fromStorage\" function in field \"${\n field.fieldId\n }\": ${JSON.stringify(storageValue)}.`,\n \"MISSING_COMPRESSION\",\n {\n value: storageValue\n }\n );\n }\n if (compression !== \"jsonpack\") {\n throw new WebinyError(\n `This plugin cannot transform something not packed with \"jsonpack\".`,\n \"WRONG_COMPRESSION\",\n {\n compression\n }\n );\n }\n try {\n return jsonpack.unpack(value);\n } catch {\n return null;\n }\n },\n toStorage: async ({ value }) => {\n /**\n * There is a possibility that we are trying to compress already compressed value.\n * Introduced a bug with 5.8.0 storage operations, so just return the value to correct it.\n */\n if (value && value.hasOwnProperty(\"compression\") === true) {\n return value;\n }\n value = transformArray(value);\n return {\n compression: \"jsonpack\",\n value: value ? jsonpack.pack(value) : value\n };\n }\n });\n};\n"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,cAAc,GAAIC,KAAD,IAAgB;EACnC,IAAI,CAACA,KAAL,EAAY;IACR,OAAOA,KAAP;EACH;;EACD,IAAIC,OAAO,GAAGC,KAAK,CAACD,OAAN,CAAcD,KAAd,CAAd;EACA,MAAMG,aAAa,GAAGH,KAAK,YAAYE,KAAjB,KAA2B,KAA3B,IAAoCD,OAA1D;;EACA,IAAIE,aAAJ,EAAmB;IACfH,KAAK,GAAGE,KAAK,CAACE,IAAN,CAAWJ,KAAX,CAAR;IACAC,OAAO,GAAG,IAAV;EACH;;EACD,IAAI,OAAOD,KAAP,KAAiB,QAAjB,IAA6BC,OAAjC,EAA0C;IACtC,KAAK,MAAMI,CAAX,IAAgBL,KAAhB,EAAuB;MACnBA,KAAK,CAACK,CAAD,CAAL,GAAWN,cAAc,CAACC,KAAK,CAACK,CAAD,CAAN,CAAzB;IACH;EACJ;;EACD,OAAOL,KAAP;AACH,CAhBD;;AAkBO,MAAMM,oCAAoC,GAAG,MAAM;EACtD,OAAO,IAAIC,sCAAJ,CAA2B;IAC9BC,SAAS,EAAE,WADmB;IAE9BC,WAAW,EAAE,OAAO;MAAEC,KAAF;MAASV,KAAK,EAAEW;IAAhB,CAAP,KAA0C;MAC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@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDatetimeTransformValuePlugin = void 0;
|
|
7
|
+
|
|
8
|
+
var _TimeTransformPlugin = require("@webiny/db-dynamodb/plugins/definitions/TimeTransformPlugin");
|
|
9
|
+
|
|
10
|
+
var _DateTimeTransformPlugin = require("@webiny/db-dynamodb/plugins/definitions/DateTimeTransformPlugin");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* File is @internal
|
|
14
|
+
*/
|
|
15
|
+
const timeTransformer = new _TimeTransformPlugin.TimeTransformPlugin({
|
|
16
|
+
fields: ["*"]
|
|
17
|
+
});
|
|
18
|
+
const dateTimeTransformer = new _DateTimeTransformPlugin.DateTimeTransformPlugin({
|
|
19
|
+
fields: ["*"]
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const createDatetimeTransformValuePlugin = () => {
|
|
23
|
+
return {
|
|
24
|
+
type: "cms-field-filter-value-transform",
|
|
25
|
+
name: "cms-field-value-filter-transform-datetime",
|
|
26
|
+
fieldType: "datetime",
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Always transform into the milliseconds.
|
|
30
|
+
*/
|
|
31
|
+
transform: ({
|
|
32
|
+
field,
|
|
33
|
+
value
|
|
34
|
+
}) => {
|
|
35
|
+
const {
|
|
36
|
+
type
|
|
37
|
+
} = field.settings || {};
|
|
38
|
+
|
|
39
|
+
if (type === "time") {
|
|
40
|
+
return timeTransformer.transform({
|
|
41
|
+
value
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return dateTimeTransformer.transform({
|
|
46
|
+
value
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.createDatetimeTransformValuePlugin = createDatetimeTransformValuePlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["timeTransformer","TimeTransformPlugin","fields","dateTimeTransformer","DateTimeTransformPlugin","createDatetimeTransformValuePlugin","type","name","fieldType","transform","field","value","settings"],"sources":["datetime.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { TimeTransformPlugin } from \"@webiny/db-dynamodb/plugins/definitions/TimeTransformPlugin\";\nimport { DateTimeTransformPlugin } from \"@webiny/db-dynamodb/plugins/definitions/DateTimeTransformPlugin\";\n\nconst timeTransformer = new TimeTransformPlugin({\n fields: [\"*\"]\n});\nconst dateTimeTransformer = new DateTimeTransformPlugin({\n fields: [\"*\"]\n});\n\nexport const createDatetimeTransformValuePlugin = (): CmsFieldFilterValueTransformPlugin => {\n return {\n type: \"cms-field-filter-value-transform\",\n name: \"cms-field-value-filter-transform-datetime\",\n fieldType: \"datetime\",\n /**\n * Always transform into the milliseconds.\n */\n transform: ({ field, value }) => {\n const { type } = field.settings || {};\n if (type === \"time\") {\n return timeTransformer.transform({\n value\n });\n }\n return dateTimeTransformer.transform({\n value\n });\n }\n };\n};\n"],"mappings":";;;;;;;AAIA;;AACA;;AALA;AACA;AACA;AAKA,MAAMA,eAAe,GAAG,IAAIC,wCAAJ,CAAwB;EAC5CC,MAAM,EAAE,CAAC,GAAD;AADoC,CAAxB,CAAxB;AAGA,MAAMC,mBAAmB,GAAG,IAAIC,gDAAJ,CAA4B;EACpDF,MAAM,EAAE,CAAC,GAAD;AAD4C,CAA5B,CAA5B;;AAIO,MAAMG,kCAAkC,GAAG,MAA0C;EACxF,OAAO;IACHC,IAAI,EAAE,kCADH;IAEHC,IAAI,EAAE,2CAFH;IAGHC,SAAS,EAAE,UAHR;;IAIH;AACR;AACA;IACQC,SAAS,EAAE,CAAC;MAAEC,KAAF;MAASC;IAAT,CAAD,KAAsB;MAC7B,MAAM;QAAEL;MAAF,IAAWI,KAAK,CAACE,QAAN,IAAkB,EAAnC;;MACA,IAAIN,IAAI,KAAK,MAAb,EAAqB;QACjB,OAAON,eAAe,CAACS,SAAhB,CAA0B;UAC7BE;QAD6B,CAA1B,CAAP;MAGH;;MACD,OAAOR,mBAAmB,CAACM,SAApB,CAA8B;QACjCE;MADiC,CAA9B,CAAP;IAGH;EAjBE,CAAP;AAmBH,CApBM"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
var _exportNames = {
|
|
9
|
+
createStorageOperations: true
|
|
10
|
+
};
|
|
11
|
+
exports.createStorageOperations = void 0;
|
|
12
|
+
|
|
13
|
+
var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
|
|
14
|
+
|
|
15
|
+
var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
|
|
16
|
+
|
|
17
|
+
var _types = require("./types");
|
|
18
|
+
|
|
19
|
+
var _table = require("./definitions/table");
|
|
20
|
+
|
|
21
|
+
var _settings = require("./definitions/settings");
|
|
22
|
+
|
|
23
|
+
var _system = require("./definitions/system");
|
|
24
|
+
|
|
25
|
+
var _group = require("./definitions/group");
|
|
26
|
+
|
|
27
|
+
var _model = require("./definitions/model");
|
|
28
|
+
|
|
29
|
+
var _entry = require("./definitions/entry");
|
|
30
|
+
|
|
31
|
+
var _plugins = require("@webiny/plugins");
|
|
32
|
+
|
|
33
|
+
var _system2 = require("./operations/system");
|
|
34
|
+
|
|
35
|
+
var _settings2 = require("./operations/settings");
|
|
36
|
+
|
|
37
|
+
var _group2 = require("./operations/group");
|
|
38
|
+
|
|
39
|
+
var _model2 = require("./operations/model");
|
|
40
|
+
|
|
41
|
+
var _entry2 = require("./operations/entry");
|
|
42
|
+
|
|
43
|
+
var _plugins2 = require("./operations/entry/filtering/plugins");
|
|
44
|
+
|
|
45
|
+
var _plugins3 = require("./plugins");
|
|
46
|
+
|
|
47
|
+
Object.keys(_plugins3).forEach(function (key) {
|
|
48
|
+
if (key === "default" || key === "__esModule") return;
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
50
|
+
if (key in exports && exports[key] === _plugins3[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _plugins3[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const createStorageOperations = params => {
|
|
60
|
+
const {
|
|
61
|
+
attributes,
|
|
62
|
+
table,
|
|
63
|
+
documentClient,
|
|
64
|
+
plugins: userPlugins
|
|
65
|
+
} = params;
|
|
66
|
+
const tableInstance = (0, _table.createTable)({
|
|
67
|
+
table,
|
|
68
|
+
documentClient
|
|
69
|
+
});
|
|
70
|
+
const entities = {
|
|
71
|
+
settings: (0, _settings.createSettingsEntity)({
|
|
72
|
+
entityName: _types.ENTITIES.SETTINGS,
|
|
73
|
+
table: tableInstance,
|
|
74
|
+
attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
|
|
75
|
+
}),
|
|
76
|
+
system: (0, _system.createSystemEntity)({
|
|
77
|
+
entityName: _types.ENTITIES.SYSTEM,
|
|
78
|
+
table: tableInstance,
|
|
79
|
+
attributes: attributes ? attributes[_types.ENTITIES.SYSTEM] : {}
|
|
80
|
+
}),
|
|
81
|
+
groups: (0, _group.createGroupEntity)({
|
|
82
|
+
entityName: _types.ENTITIES.GROUPS,
|
|
83
|
+
table: tableInstance,
|
|
84
|
+
attributes: attributes ? attributes[_types.ENTITIES.GROUPS] : {}
|
|
85
|
+
}),
|
|
86
|
+
models: (0, _model.createModelEntity)({
|
|
87
|
+
entityName: _types.ENTITIES.MODELS,
|
|
88
|
+
table: tableInstance,
|
|
89
|
+
attributes: attributes ? attributes[_types.ENTITIES.MODELS] : {}
|
|
90
|
+
}),
|
|
91
|
+
entries: (0, _entry.createEntryEntity)({
|
|
92
|
+
entityName: _types.ENTITIES.ENTRIES,
|
|
93
|
+
table: tableInstance,
|
|
94
|
+
attributes: attributes ? attributes[_types.ENTITIES.ENTRIES] : {}
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
const plugins = new _plugins.PluginsContainer([
|
|
98
|
+
/**
|
|
99
|
+
* DynamoDB filter plugins for the where conditions.
|
|
100
|
+
*/
|
|
101
|
+
(0, _filters.default)(),
|
|
102
|
+
/**
|
|
103
|
+
* Field plugins for DynamoDB.
|
|
104
|
+
*/
|
|
105
|
+
(0, _dynamoDb.default)(),
|
|
106
|
+
/**
|
|
107
|
+
* Filter create plugins.
|
|
108
|
+
*/
|
|
109
|
+
(0, _plugins2.createFilterCreatePlugins)(),
|
|
110
|
+
/**
|
|
111
|
+
* User defined custom plugins.
|
|
112
|
+
*/
|
|
113
|
+
...(userPlugins || [])]);
|
|
114
|
+
return {
|
|
115
|
+
name: "dynamodb",
|
|
116
|
+
beforeInit: async context => {
|
|
117
|
+
/**
|
|
118
|
+
* Collect all required plugins from parent context.
|
|
119
|
+
*/
|
|
120
|
+
const fieldPlugins = context.plugins.byType("cms-model-field-to-graphql");
|
|
121
|
+
plugins.register(fieldPlugins);
|
|
122
|
+
/**
|
|
123
|
+
* Pass the plugins to the parent context.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
context.plugins.register([(0, _dynamoDb.default)()]);
|
|
127
|
+
},
|
|
128
|
+
getEntities: () => entities,
|
|
129
|
+
getTable: () => tableInstance,
|
|
130
|
+
system: (0, _system2.createSystemStorageOperations)({
|
|
131
|
+
entity: entities.system
|
|
132
|
+
}),
|
|
133
|
+
settings: (0, _settings2.createSettingsStorageOperations)({
|
|
134
|
+
entity: entities.settings
|
|
135
|
+
}),
|
|
136
|
+
groups: (0, _group2.createGroupsStorageOperations)({
|
|
137
|
+
entity: entities.groups,
|
|
138
|
+
plugins
|
|
139
|
+
}),
|
|
140
|
+
models: (0, _model2.createModelsStorageOperations)({
|
|
141
|
+
entity: entities.models
|
|
142
|
+
}),
|
|
143
|
+
entries: (0, _entry2.createEntriesStorageOperations)({
|
|
144
|
+
entity: entities.entries,
|
|
145
|
+
plugins
|
|
146
|
+
})
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
exports.createStorageOperations = createStorageOperations;
|
package/index.js.map
ADDED
|
@@ -0,0 +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","fieldPlugins","byType","register","getEntities","getTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations"],"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\";\nimport { CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\n\nimport { createFilterCreatePlugins } from \"~/operations/entry/filtering/plugins\";\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 return {\n name: \"dynamodb\",\n beforeInit: async context => {\n /**\n * Collect all required plugins from parent context.\n */\n const fieldPlugins = context.plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n plugins.register(fieldPlugins);\n\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\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: createEntriesStorageOperations({\n entity: entities.entries,\n plugins\n })\n };\n};\n"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;EACvE,MAAM;IAAEC,UAAF;IAAcC,KAAd;IAAqBC,cAArB;IAAqCC,OAAO,EAAEC;EAA9C,IAA8DL,MAApE;EAEA,MAAMM,aAAa,GAAG,IAAAC,kBAAA,EAAY;IAC9BL,KAD8B;IAE9BC;EAF8B,CAAZ,CAAtB;EAKA,MAAMK,QAAQ,GAAG;IACbC,QAAQ,EAAE,IAAAC,8BAAA,EAAqB;MAC3BC,UAAU,EAAEC,eAAA,CAASC,QADM;MAE3BX,KAAK,EAAEI,aAFoB;MAG3BL,UAAU,EAAEA,UAAU,GAAGA,UAAU,CAACW,eAAA,CAASC,QAAV,CAAb,GAAmC;IAH9B,CAArB,CADG;IAMbC,MAAM,EAAE,IAAAC,0BAAA,EAAmB;MACvBJ,UAAU,EAAEC,eAAA,CAASI,MADE;MAEvBd,KAAK,EAAEI,aAFgB;MAGvBL,UAAU,EAAEA,UAAU,GAAGA,UAAU,CAACW,eAAA,CAASI,MAAV,CAAb,GAAiC;IAHhC,CAAnB,CANK;IAWbC,MAAM,EAAE,IAAAC,wBAAA,EAAkB;MACtBP,UAAU,EAAEC,eAAA,CAASO,MADC;MAEtBjB,KAAK,EAAEI,aAFe;MAGtBL,UAAU,EAAEA,UAAU,GAAGA,UAAU,CAACW,eAAA,CAASO,MAAV,CAAb,GAAiC;IAHjC,CAAlB,CAXK;IAgBbC,MAAM,EAAE,IAAAC,wBAAA,EAAkB;MACtBV,UAAU,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wBHQ,MAAM,EAAE,IAAAwB,qCAAA,EAA8B;MAClCF,MAAM,EAAE/B,QAAQ,CAACS,MADiB;MAElCb;IAFkC,CAA9B,CAxBL;IA4BHgB,MAAM,EAAE,IAAAsB,qCAAA,EAA8B;MAClCH,MAAM,EAAE/B,QAAQ,CAACY;IADiB,CAA9B,CA5BL;IA+BHG,OAAO,EAAE,IAAAoB,sCAAA,EAA+B;MACpCJ,MAAM,EAAE/B,QAAQ,CAACe,OADmB;MAEpCnB;IAFoC,CAA/B;EA/BN,CAAP;AAoCH,CA3FM"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CmsStorageEntry, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Entity } from "dynamodb-toolbox";
|
|
3
|
+
export interface GetAllEntryRevisionsParams {
|
|
4
|
+
ids: readonly string[];
|
|
5
|
+
model: CmsModel;
|
|
6
|
+
}
|
|
7
|
+
export interface GetRevisionByIdParams {
|
|
8
|
+
ids: readonly string[];
|
|
9
|
+
model: CmsModel;
|
|
10
|
+
}
|
|
11
|
+
export interface GetPublishedRevisionByEntryIdParams {
|
|
12
|
+
ids: readonly string[];
|
|
13
|
+
model: CmsModel;
|
|
14
|
+
}
|
|
15
|
+
export interface GetLatestRevisionByEntryIdParams {
|
|
16
|
+
ids: readonly string[];
|
|
17
|
+
model: CmsModel;
|
|
18
|
+
}
|
|
19
|
+
interface ClearLoaderParams {
|
|
20
|
+
model: CmsModel;
|
|
21
|
+
entry?: CmsStorageEntry;
|
|
22
|
+
}
|
|
23
|
+
interface DataLoadersHandlerParams {
|
|
24
|
+
entity: Entity<any>;
|
|
25
|
+
}
|
|
26
|
+
export declare class DataLoadersHandler {
|
|
27
|
+
private readonly loaders;
|
|
28
|
+
private readonly entity;
|
|
29
|
+
constructor(params: DataLoadersHandlerParams);
|
|
30
|
+
getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsStorageEntry[]>;
|
|
31
|
+
getRevisionById(params: GetRevisionByIdParams): Promise<CmsStorageEntry[]>;
|
|
32
|
+
getPublishedRevisionByEntryId(params: GetPublishedRevisionByEntryIdParams): Promise<CmsStorageEntry[]>;
|
|
33
|
+
getLatestRevisionByEntryId(params: GetLatestRevisionByEntryIdParams): Promise<CmsStorageEntry[]>;
|
|
34
|
+
/**
|
|
35
|
+
* TODO @ts-refactor
|
|
36
|
+
* Maybe pass on the generics to DataLoader definition?
|
|
37
|
+
*/
|
|
38
|
+
private getLoader;
|
|
39
|
+
private loadMany;
|
|
40
|
+
clearAll(params: Omit<ClearLoaderParams, "entry">): void;
|
|
41
|
+
}
|
|
42
|
+
export {};
|