@webiny/api-headless-cms-ddb 0.0.0-unstable.df7a8bb475 → 0.0.0-unstable.e1999482d0
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/abstractions/CmsDdbDataLoaders.d.ts +5 -0
- package/abstractions/CmsDdbDataLoaders.js +5 -0
- package/abstractions/CmsDdbDataLoaders.js.map +1 -0
- package/abstractions/CmsDdbEntryEntity.d.ts +5 -0
- package/abstractions/CmsDdbEntryEntity.js +5 -0
- package/abstractions/CmsDdbEntryEntity.js.map +1 -0
- package/abstractions/CmsDdbGroupEntity.d.ts +5 -0
- package/abstractions/CmsDdbGroupEntity.js +5 -0
- package/abstractions/CmsDdbGroupEntity.js.map +1 -0
- package/abstractions/CmsDdbModelEntity.d.ts +5 -0
- package/abstractions/CmsDdbModelEntity.js +5 -0
- package/abstractions/CmsDdbModelEntity.js.map +1 -0
- package/abstractions/CmsDdbTable.d.ts +5 -0
- package/abstractions/CmsDdbTable.js +5 -0
- package/abstractions/CmsDdbTable.js.map +1 -0
- package/definitions/entry.js +7 -9
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +7 -9
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +7 -9
- package/definitions/model.js.map +1 -1
- package/definitions/table.js +6 -7
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +11 -5
- package/definitions/types.js +0 -3
- package/index.d.ts +10 -3
- package/index.js +40 -85
- package/index.js.map +1 -1
- package/operations/entry/DdbCreateEntry.d.ts +16 -0
- package/operations/entry/DdbCreateEntry.js +77 -0
- package/operations/entry/DdbCreateEntry.js.map +1 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.d.ts +16 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.js +85 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.js.map +1 -0
- package/operations/entry/DdbDeleteEntry.d.ts +16 -0
- package/operations/entry/DdbDeleteEntry.js +65 -0
- package/operations/entry/DdbDeleteEntry.js.map +1 -0
- package/operations/entry/DdbDeleteEntryRevision.d.ts +17 -0
- package/operations/entry/DdbDeleteEntryRevision.js +91 -0
- package/operations/entry/DdbDeleteEntryRevision.js.map +1 -0
- package/operations/entry/DdbDeleteMultipleEntries.d.ts +16 -0
- package/operations/entry/DdbDeleteMultipleEntries.js +59 -0
- package/operations/entry/DdbDeleteMultipleEntries.js.map +1 -0
- package/operations/entry/DdbGetEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetEntriesByIds.js +31 -0
- package/operations/entry/DdbGetEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetEntry.d.ts +14 -0
- package/operations/entry/DdbGetEntry.js +27 -0
- package/operations/entry/DdbGetEntry.js.map +1 -0
- package/operations/entry/DdbGetLatestEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetLatestEntriesByIds.js +31 -0
- package/operations/entry/DdbGetLatestEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.d.ts +14 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.js +35 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/DdbGetPreviousRevision.d.ts +14 -0
- package/operations/entry/DdbGetPreviousRevision.js +53 -0
- package/operations/entry/DdbGetPreviousRevision.js.map +1 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.js +31 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.d.ts +14 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.js +35 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/DdbGetRevisionById.d.ts +14 -0
- package/operations/entry/DdbGetRevisionById.js +34 -0
- package/operations/entry/DdbGetRevisionById.js.map +1 -0
- package/operations/entry/DdbGetRevisions.d.ts +14 -0
- package/operations/entry/DdbGetRevisions.js +33 -0
- package/operations/entry/DdbGetRevisions.js.map +1 -0
- package/operations/entry/DdbGetUniqueFieldValues.d.ts +12 -0
- package/operations/entry/DdbGetUniqueFieldValues.js +31 -0
- package/operations/entry/DdbGetUniqueFieldValues.js.map +1 -0
- package/operations/entry/DdbListEntries.d.ts +30 -0
- package/operations/entry/DdbListEntries.js +133 -0
- package/operations/entry/DdbListEntries.js.map +1 -0
- package/operations/entry/DdbMoveEntry.d.ts +16 -0
- package/operations/entry/DdbMoveEntry.js +63 -0
- package/operations/entry/DdbMoveEntry.js.map +1 -0
- package/operations/entry/DdbMoveToBin.d.ts +16 -0
- package/operations/entry/DdbMoveToBin.js +77 -0
- package/operations/entry/DdbMoveToBin.js.map +1 -0
- package/operations/entry/DdbPublishEntry.d.ts +18 -0
- package/operations/entry/DdbPublishEntry.js +162 -0
- package/operations/entry/DdbPublishEntry.js.map +1 -0
- package/operations/entry/DdbRestoreFromBin.d.ts +16 -0
- package/operations/entry/DdbRestoreFromBin.js +78 -0
- package/operations/entry/DdbRestoreFromBin.js.map +1 -0
- package/operations/entry/DdbUnpublishEntry.d.ts +17 -0
- package/operations/entry/DdbUnpublishEntry.js +112 -0
- package/operations/entry/DdbUnpublishEntry.js.map +1 -0
- package/operations/entry/DdbUpdateEntry.d.ts +17 -0
- package/operations/entry/DdbUpdateEntry.js +105 -0
- package/operations/entry/DdbUpdateEntry.js.map +1 -0
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +22 -29
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +2 -1
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -26
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +32 -38
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +32 -38
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.js +34 -44
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.js +8 -9
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +1 -0
- package/operations/entry/dataLoader/types.js +0 -3
- package/operations/entry/dataLoaders.d.ts +7 -6
- package/operations/entry/dataLoaders.js +89 -97
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/feature.d.ts +4 -0
- package/operations/entry/feature.js +55 -0
- package/operations/entry/feature.js.map +1 -0
- package/operations/entry/keys.d.ts +6 -0
- package/operations/entry/keys.js +57 -77
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/storageEntryUtils.d.ts +8 -0
- package/operations/entry/storageEntryUtils.js +25 -0
- package/operations/entry/storageEntryUtils.js.map +1 -0
- package/operations/group/DdbCreateGroup.d.ts +12 -0
- package/operations/group/DdbCreateGroup.js +35 -0
- package/operations/group/DdbCreateGroup.js.map +1 -0
- package/operations/group/DdbDeleteGroup.d.ts +12 -0
- package/operations/group/DdbDeleteGroup.js +31 -0
- package/operations/group/DdbDeleteGroup.js.map +1 -0
- package/operations/group/DdbGetGroup.d.ts +12 -0
- package/operations/group/DdbGetGroup.js +31 -0
- package/operations/group/DdbGetGroup.js.map +1 -0
- package/operations/group/DdbListGroups.d.ts +14 -0
- package/operations/group/DdbListGroups.js +52 -0
- package/operations/group/DdbListGroups.js.map +1 -0
- package/operations/group/DdbUpdateGroup.d.ts +12 -0
- package/operations/group/DdbUpdateGroup.js +35 -0
- package/operations/group/DdbUpdateGroup.js.map +1 -0
- package/operations/group/feature.d.ts +4 -0
- package/operations/group/feature.js +19 -0
- package/operations/group/feature.js.map +1 -0
- package/operations/group/keys.d.ts +15 -0
- package/operations/group/keys.js +17 -0
- package/operations/group/keys.js.map +1 -0
- package/operations/model/DdbCreateModel.d.ts +12 -0
- package/operations/model/DdbCreateModel.js +37 -0
- package/operations/model/DdbCreateModel.js.map +1 -0
- package/operations/model/DdbDeleteModel.d.ts +12 -0
- package/operations/model/DdbDeleteModel.js +31 -0
- package/operations/model/DdbDeleteModel.js.map +1 -0
- package/operations/model/DdbGetModel.d.ts +12 -0
- package/operations/model/DdbGetModel.js +30 -0
- package/operations/model/DdbGetModel.js.map +1 -0
- package/operations/model/DdbListModels.d.ts +12 -0
- package/operations/model/DdbListModels.js +36 -0
- package/operations/model/DdbListModels.js.map +1 -0
- package/operations/model/DdbUpdateModel.d.ts +12 -0
- package/operations/model/DdbUpdateModel.js +36 -0
- package/operations/model/DdbUpdateModel.js.map +1 -0
- package/operations/model/feature.d.ts +4 -0
- package/operations/model/feature.js +19 -0
- package/operations/model/feature.js.map +1 -0
- package/operations/model/keys.d.ts +15 -0
- package/operations/model/keys.js +16 -0
- package/operations/model/keys.js.map +1 -0
- package/package.json +26 -22
- package/types.d.ts +10 -48
- package/types.js +6 -5
- package/types.js.map +1 -1
- package/definitions/types.js.map +0 -1
- package/dynamoDb/index.d.ts +0 -2
- package/dynamoDb/index.js +0 -8
- package/dynamoDb/index.js.map +0 -1
- package/dynamoDb/path/locationFolderId.d.ts +0 -2
- package/dynamoDb/path/locationFolderId.js +0 -34
- package/dynamoDb/path/locationFolderId.js.map +0 -1
- package/dynamoDb/path/plainObject.d.ts +0 -2
- package/dynamoDb/path/plainObject.js +0 -26
- package/dynamoDb/path/plainObject.js.map +0 -1
- package/dynamoDb/storage/longText.d.ts +0 -10
- package/dynamoDb/storage/longText.js +0 -86
- package/dynamoDb/storage/longText.js.map +0 -1
- package/dynamoDb/storage/richText.d.ts +0 -2
- package/dynamoDb/storage/richText.js +0 -52
- package/dynamoDb/storage/richText.js.map +0 -1
- package/dynamoDb/transformValue/datetime.d.ts +0 -5
- package/dynamoDb/transformValue/datetime.js +0 -40
- package/dynamoDb/transformValue/datetime.js.map +0 -1
- package/operations/entry/dataLoader/types.js.map +0 -1
- package/operations/entry/filtering/createExpressions.d.ts +0 -26
- package/operations/entry/filtering/createExpressions.js +0 -175
- package/operations/entry/filtering/createExpressions.js.map +0 -1
- package/operations/entry/filtering/createFields.d.ts +0 -16
- package/operations/entry/filtering/createFields.js +0 -106
- package/operations/entry/filtering/createFields.js.map +0 -1
- package/operations/entry/filtering/extractSort.d.ts +0 -17
- package/operations/entry/filtering/extractSort.js +0 -84
- package/operations/entry/filtering/extractSort.js.map +0 -1
- package/operations/entry/filtering/filter.d.ts +0 -15
- package/operations/entry/filtering/filter.js +0 -150
- package/operations/entry/filtering/filter.js.map +0 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +0 -14
- package/operations/entry/filtering/fullTextSearch.js +0 -42
- package/operations/entry/filtering/fullTextSearch.js.map +0 -1
- package/operations/entry/filtering/getValue.d.ts +0 -5
- package/operations/entry/filtering/getValue.js +0 -59
- package/operations/entry/filtering/getValue.js.map +0 -1
- package/operations/entry/filtering/index.d.ts +0 -2
- package/operations/entry/filtering/index.js +0 -4
- package/operations/entry/filtering/index.js.map +0 -1
- package/operations/entry/filtering/mapPlugins.d.ts +0 -8
- package/operations/entry/filtering/mapPlugins.js +0 -25
- package/operations/entry/filtering/mapPlugins.js.map +0 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -37
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/index.d.ts +0 -1
- package/operations/entry/filtering/plugins/index.js +0 -9
- package/operations/entry/filtering/plugins/index.js.map +0 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -84
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +0 -3
- package/operations/entry/filtering/plugins/refFilterCreate.js +0 -74
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +0 -57
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +0 -1
- package/operations/entry/filtering/sort.d.ts +0 -12
- package/operations/entry/filtering/sort.js +0 -67
- package/operations/entry/filtering/sort.js.map +0 -1
- package/operations/entry/filtering/systemFields.d.ts +0 -2
- package/operations/entry/filtering/systemFields.js +0 -116
- package/operations/entry/filtering/systemFields.js.map +0 -1
- package/operations/entry/filtering/transform.d.ts +0 -6
- package/operations/entry/filtering/transform.js +0 -11
- package/operations/entry/filtering/transform.js.map +0 -1
- package/operations/entry/filtering/types.d.ts +0 -40
- package/operations/entry/filtering/types.js +0 -3
- package/operations/entry/filtering/types.js.map +0 -1
- package/operations/entry/filtering/values.d.ts +0 -2
- package/operations/entry/filtering/values.js +0 -16
- package/operations/entry/filtering/values.js.map +0 -1
- package/operations/entry/filtering/where.d.ts +0 -5
- package/operations/entry/filtering/where.js +0 -28
- package/operations/entry/filtering/where.js.map +0 -1
- package/operations/entry/index.d.ts +0 -7
- package/operations/entry/index.js +0 -1196
- package/operations/entry/index.js.map +0 -1
- package/operations/group/index.d.ts +0 -9
- package/operations/group/index.js +0 -145
- package/operations/group/index.js.map +0 -1
- package/operations/model/index.d.ts +0 -7
- package/operations/model/index.js +0 -128
- package/operations/model/index.js.map +0 -1
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +0 -23
- package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -40
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +0 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +0 -43
- package/plugins/CmsEntryFieldFilterPlugin.js +0 -21
- package/plugins/CmsEntryFieldFilterPlugin.js.map +0 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +0 -42
- package/plugins/CmsEntryFieldSortingPlugin.js +0 -19
- package/plugins/CmsEntryFieldSortingPlugin.js.map +0 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +0 -11
- package/plugins/CmsFieldFilterValueTransformPlugin.js +0 -16
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +0 -1
- package/plugins/index.d.ts +0 -4
- package/plugins/index.js +0 -6
- package/plugins/index.js.map +0 -1
|
@@ -1,10 +0,0 @@
|
|
|
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>;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File is @internal
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import WebinyError from "@webiny/error";
|
|
6
|
-
import { compress as gzip, decompress as ungzip } from "@webiny/utils/compression/gzip.js";
|
|
7
|
-
import { StorageTransformPlugin } from "@webiny/api-headless-cms";
|
|
8
|
-
const GZIP = "gzip";
|
|
9
|
-
const TO_STORAGE_ENCODING = "base64";
|
|
10
|
-
const FROM_STORAGE_ENCODING = "utf8";
|
|
11
|
-
const convertToBuffer = value => {
|
|
12
|
-
if (typeof value === "string") {
|
|
13
|
-
return Buffer.from(value, TO_STORAGE_ENCODING);
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
};
|
|
17
|
-
export const createLongTextStorageTransformPlugin = () => {
|
|
18
|
-
return new StorageTransformPlugin({
|
|
19
|
-
name: "headless-cms.storage-transform.long-text.default",
|
|
20
|
-
fieldType: "long-text",
|
|
21
|
-
fromStorage: async ({
|
|
22
|
-
field,
|
|
23
|
-
value: storageValue
|
|
24
|
-
}) => {
|
|
25
|
-
const typeOf = typeof storageValue;
|
|
26
|
-
if (!storageValue || typeOf === "string" || typeOf === "number" || Array.isArray(storageValue) === true) {
|
|
27
|
-
return storageValue;
|
|
28
|
-
} else if (typeOf !== "object") {
|
|
29
|
-
throw new WebinyError(`LongText value received in "fromStorage" function is not an object in field "${field.storageId}" - ${field.fieldId}.`);
|
|
30
|
-
}
|
|
31
|
-
const {
|
|
32
|
-
compression,
|
|
33
|
-
value,
|
|
34
|
-
isArray
|
|
35
|
-
} = storageValue;
|
|
36
|
-
/**
|
|
37
|
-
* Check if possibly undefined, null, empty...
|
|
38
|
-
*/
|
|
39
|
-
if (!compression) {
|
|
40
|
-
throw new WebinyError(`Missing compression in "fromStorage" function in field "${field.storageId}" - ${field.fieldId}.": ${JSON.stringify(storageValue)}.`, "MISSING_COMPRESSION", {
|
|
41
|
-
value: storageValue
|
|
42
|
-
});
|
|
43
|
-
} else if (compression !== GZIP) {
|
|
44
|
-
throw new WebinyError(`This plugin cannot transform something not compressed with "GZIP".`, "WRONG_COMPRESSION", {
|
|
45
|
-
compression
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
const buf = await ungzip(convertToBuffer(value));
|
|
50
|
-
const result = buf.toString(FROM_STORAGE_ENCODING);
|
|
51
|
-
if (!isArray) {
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
return JSON.parse(result);
|
|
55
|
-
} catch (ex) {
|
|
56
|
-
console.log("Error while transforming long-text.");
|
|
57
|
-
console.log(ex.message);
|
|
58
|
-
return "";
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
toStorage: async ({
|
|
62
|
-
value: initialValue
|
|
63
|
-
}) => {
|
|
64
|
-
/**
|
|
65
|
-
* There is a possibility that we are trying to compress already compressed value.
|
|
66
|
-
*/
|
|
67
|
-
if (initialValue && initialValue.hasOwnProperty("compression") === true) {
|
|
68
|
-
return initialValue;
|
|
69
|
-
}
|
|
70
|
-
const isArray = Array.isArray(initialValue);
|
|
71
|
-
const value = isArray ? JSON.stringify(initialValue) : initialValue;
|
|
72
|
-
const compressedValue = await gzip(value);
|
|
73
|
-
const result = {
|
|
74
|
-
compression: GZIP,
|
|
75
|
-
value: compressedValue.toString(TO_STORAGE_ENCODING)
|
|
76
|
-
};
|
|
77
|
-
if (!isArray) {
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
result.isArray = isArray;
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
//# sourceMappingURL=longText.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["WebinyError","compress","gzip","decompress","ungzip","StorageTransformPlugin","GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","createLongTextStorageTransformPlugin","name","fieldType","fromStorage","field","storageValue","typeOf","Array","isArray","storageId","fieldId","compression","JSON","stringify","buf","result","toString","parse","ex","console","log","message","toStorage","initialValue","hasOwnProperty","compressedValue"],"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.js\";\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 name: \"headless-cms.storage-transform.long-text.default\",\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 unknown as StorageValue;\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":"AAAA;AACA;AACA;;AAEA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,QAAQ,IAAIC,IAAI,EAAEC,UAAU,IAAIC,MAAM,QAAQ,mCAAmC;AAC1F,SAASC,sBAAsB,QAAQ,0BAA0B;A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
|
2
|
-
* File is @internal
|
|
3
|
-
*/
|
|
4
|
-
import WebinyError from "@webiny/error";
|
|
5
|
-
import { StorageTransformPlugin } from "@webiny/api-headless-cms";
|
|
6
|
-
import { CompressorPlugin } from "@webiny/api";
|
|
7
|
-
export const createRichTextStorageTransformPlugin = () => {
|
|
8
|
-
return new StorageTransformPlugin({
|
|
9
|
-
name: "headless-cms.storage-transform.rich-text.default",
|
|
10
|
-
fieldType: "rich-text",
|
|
11
|
-
fromStorage: async ({
|
|
12
|
-
field,
|
|
13
|
-
value: storageValue,
|
|
14
|
-
plugins
|
|
15
|
-
}) => {
|
|
16
|
-
if (!storageValue) {
|
|
17
|
-
return storageValue;
|
|
18
|
-
} else if (typeof storageValue !== "object") {
|
|
19
|
-
throw new WebinyError(`RichText value received in "fromStorage" function is not an object in field "${field.storageId}" - ${field.fieldId}.`);
|
|
20
|
-
}
|
|
21
|
-
let compressor;
|
|
22
|
-
try {
|
|
23
|
-
compressor = plugins.oneByType(CompressorPlugin.type);
|
|
24
|
-
} catch {
|
|
25
|
-
return storageValue;
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
return await compressor.getCompressor().decompress(storageValue);
|
|
29
|
-
} catch {
|
|
30
|
-
return storageValue;
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
toStorage: async ({
|
|
34
|
-
value,
|
|
35
|
-
plugins
|
|
36
|
-
}) => {
|
|
37
|
-
let compressor;
|
|
38
|
-
try {
|
|
39
|
-
compressor = plugins.oneByType(CompressorPlugin.type);
|
|
40
|
-
} catch {
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
return await compressor.getCompressor().compress(value);
|
|
45
|
-
} catch {
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=richText.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["WebinyError","StorageTransformPlugin","CompressorPlugin","createRichTextStorageTransformPlugin","name","fieldType","fromStorage","field","value","storageValue","plugins","storageId","fieldId","compressor","oneByType","type","getCompressor","decompress","toStorage","compress"],"sources":["richText.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\nimport { CompressorPlugin } from \"@webiny/api\";\n\nexport const createRichTextStorageTransformPlugin = () => {\n return new StorageTransformPlugin({\n name: \"headless-cms.storage-transform.rich-text.default\",\n fieldType: \"rich-text\",\n fromStorage: async ({ field, value: storageValue, plugins }) => {\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 let compressor: CompressorPlugin;\n\n try {\n compressor = plugins.oneByType<CompressorPlugin>(CompressorPlugin.type);\n } catch {\n return storageValue;\n }\n\n try {\n return await compressor.getCompressor().decompress(storageValue);\n } catch {\n return storageValue;\n }\n },\n toStorage: async ({ value, plugins }) => {\n let compressor: CompressorPlugin;\n\n try {\n compressor = plugins.oneByType<CompressorPlugin>(CompressorPlugin.type);\n } catch {\n return value;\n }\n try {\n return await compressor.getCompressor().compress(value);\n } catch {\n return value;\n }\n }\n });\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,sBAAsB,QAAQ,0BAA0B;AACjE,SAASC,gBAAgB,QAAQ,aAAa;AAE9C,OAAO,MAAMC,oCAAoC,GAAGA,CAAA,KAAM;EACtD,OAAO,IAAIF,sBAAsB,CAAC;IAC9BG,IAAI,EAAE,kDAAkD;IACxDC,SAAS,EAAE,WAAW;IACtBC,WAAW,EAAE,MAAAA,CAAO;MAAEC,KAAK;MAAEC,KAAK,EAAEC,YAAY;MAAEC;IAAQ,CAAC,KAAK;MAC5D,IAAI,CAACD,YAAY,EAAE;QACf,OAAOA,YAAY;MACvB,CAAC,MAAM,IAAI,OAAOA,YAAY,KAAK,QAAQ,EAAE;QACzC,MAAM,IAAIT,WAAW,CACjB,gFAAgFO,KAAK,CAACI,SAAS,OAAOJ,KAAK,CAACK,OAAO,GACvH,CAAC;MACL;MAEA,IAAIC,UAA4B;MAEhC,IAAI;QACAA,UAAU,GAAGH,OAAO,CAACI,SAAS,CAAmBZ,gBAAgB,CAACa,IAAI,CAAC;MAC3E,CAAC,CAAC,MAAM;QACJ,OAAON,YAAY;MACvB;MAEA,IAAI;QACA,OAAO,MAAMI,UAAU,CAACG,aAAa,CAAC,CAAC,CAACC,UAAU,CAACR,YAAY,CAAC;MACpE,CAAC,CAAC,MAAM;QACJ,OAAOA,YAAY;MACvB;IACJ,CAAC;IACDS,SAAS,EAAE,MAAAA,CAAO;MAAEV,KAAK;MAAEE;IAAQ,CAAC,KAAK;MACrC,IAAIG,UAA4B;MAEhC,IAAI;QACAA,UAAU,GAAGH,OAAO,CAACI,SAAS,CAAmBZ,gBAAgB,CAACa,IAAI,CAAC;MAC3E,CAAC,CAAC,MAAM;QACJ,OAAOP,KAAK;MAChB;MACA,IAAI;QACA,OAAO,MAAMK,UAAU,CAACG,aAAa,CAAC,CAAC,CAACG,QAAQ,CAACX,KAAK,CAAC;MAC3D,CAAC,CAAC,MAAM;QACJ,OAAOA,KAAK;MAChB;IACJ;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File is @internal
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { TimeTransformPlugin } from "@webiny/db-dynamodb/plugins/definitions/TimeTransformPlugin.js";
|
|
6
|
-
import { DateTimeTransformPlugin } from "@webiny/db-dynamodb/plugins/definitions/DateTimeTransformPlugin.js";
|
|
7
|
-
const timeTransformer = new TimeTransformPlugin({
|
|
8
|
-
fields: ["*"]
|
|
9
|
-
});
|
|
10
|
-
const dateTimeTransformer = new DateTimeTransformPlugin({
|
|
11
|
-
fields: ["*"]
|
|
12
|
-
});
|
|
13
|
-
export const createDatetimeTransformValuePlugin = () => {
|
|
14
|
-
return {
|
|
15
|
-
type: "cms-field-filter-value-transform",
|
|
16
|
-
name: "cms-field-value-filter-transform-datetime",
|
|
17
|
-
fieldType: "datetime",
|
|
18
|
-
/**
|
|
19
|
-
* Always transform into the milliseconds.
|
|
20
|
-
*/
|
|
21
|
-
transform: ({
|
|
22
|
-
field,
|
|
23
|
-
value
|
|
24
|
-
}) => {
|
|
25
|
-
const {
|
|
26
|
-
type
|
|
27
|
-
} = field.settings || {};
|
|
28
|
-
if (type === "time") {
|
|
29
|
-
return timeTransformer.transform({
|
|
30
|
-
value
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return dateTimeTransformer.transform({
|
|
34
|
-
value
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
//# sourceMappingURL=datetime.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["TimeTransformPlugin","DateTimeTransformPlugin","timeTransformer","fields","dateTimeTransformer","createDatetimeTransformValuePlugin","type","name","fieldType","transform","field","value","settings"],"sources":["datetime.ts"],"sourcesContent":["/**\n * File is @internal\n */\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { TimeTransformPlugin } from \"@webiny/db-dynamodb/plugins/definitions/TimeTransformPlugin.js\";\nimport { DateTimeTransformPlugin } from \"@webiny/db-dynamodb/plugins/definitions/DateTimeTransformPlugin.js\";\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":"AAAA;AACA;AACA;;AAEA,SAASA,mBAAmB,QAAQ,gEAAgE;AACpG,SAASC,uBAAuB,QAAQ,oEAAoE;AAE5G,MAAMC,eAAe,GAAG,IAAIF,mBAAmB,CAAC;EAC5CG,MAAM,EAAE,CAAC,GAAG;AAChB,CAAC,CAAC;AACF,MAAMC,mBAAmB,GAAG,IAAIH,uBAAuB,CAAC;EACpDE,MAAM,EAAE,CAAC,GAAG;AAChB,CAAC,CAAC;AAEF,OAAO,MAAME,kCAAkC,GAAGA,CAAA,KAA0C;EACxF,OAAO;IACHC,IAAI,EAAE,kCAAkC;IACxCC,IAAI,EAAE,2CAA2C;IACjDC,SAAS,EAAE,UAAU;IACrB;AACR;AACA;IACQC,SAAS,EAAEA,CAAC;MAAEC,KAAK;MAAEC;IAAM,CAAC,KAAK;MAC7B,MAAM;QAAEL;MAAK,CAAC,GAAGI,KAAK,CAACE,QAAQ,IAAI,CAAC,CAAC;MACrC,IAAIN,IAAI,KAAK,MAAM,EAAE;QACjB,OAAOJ,eAAe,CAACO,SAAS,CAAC;UAC7BE;QACJ,CAAC,CAAC;MACN;MACA,OAAOP,mBAAmB,CAACK,SAAS,CAAC;QACjCE;MACJ,CAAC,CAAC;IACN;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntryEntity } from \"~/definitions/types.js\";\n\nexport interface IDataLoaderParams {\n entity: IEntryEntity;\n tenant: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { CmsEntryListWhere } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
-
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
3
|
-
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
|
-
import type { Field } from "./types.js";
|
|
5
|
-
interface Params {
|
|
6
|
-
plugins: PluginsContainer;
|
|
7
|
-
where: Partial<CmsEntryListWhere>;
|
|
8
|
-
fields: Record<string, Field>;
|
|
9
|
-
}
|
|
10
|
-
export type ExpressionCondition = "AND" | "OR";
|
|
11
|
-
export interface Expression {
|
|
12
|
-
expressions: Expression[];
|
|
13
|
-
filters: Filter[];
|
|
14
|
-
condition: ExpressionCondition;
|
|
15
|
-
}
|
|
16
|
-
export interface Filter {
|
|
17
|
-
field: Field;
|
|
18
|
-
path: string;
|
|
19
|
-
fieldPathId: string;
|
|
20
|
-
plugin: ValueFilterPlugin;
|
|
21
|
-
negate: boolean;
|
|
22
|
-
compareValue: any;
|
|
23
|
-
transformValue: <I = any, O = any>(value: I) => O;
|
|
24
|
-
}
|
|
25
|
-
export declare const createExpressions: (params: Params) => Expression;
|
|
26
|
-
export {};
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import WebinyError from "@webiny/error";
|
|
2
|
-
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
3
|
-
import { getMappedPlugins } from "./mapPlugins.js";
|
|
4
|
-
import { extractWhereParams } from "./where.js";
|
|
5
|
-
import { transformValue } from "./transform.js";
|
|
6
|
-
import { CmsEntryFieldFilterPlugin } from "../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
7
|
-
import { getWhereValues } from "./values.js";
|
|
8
|
-
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
9
|
-
export const createExpressions = params => {
|
|
10
|
-
const {
|
|
11
|
-
where,
|
|
12
|
-
plugins,
|
|
13
|
-
fields
|
|
14
|
-
} = params;
|
|
15
|
-
const filterPlugins = getMappedPlugins({
|
|
16
|
-
plugins,
|
|
17
|
-
type: ValueFilterPlugin.type,
|
|
18
|
-
property: "operation"
|
|
19
|
-
});
|
|
20
|
-
const transformValuePlugins = getMappedPlugins({
|
|
21
|
-
plugins,
|
|
22
|
-
type: "cms-field-filter-value-transform",
|
|
23
|
-
property: "fieldType"
|
|
24
|
-
});
|
|
25
|
-
const fieldFilterCreatePlugins = getMappedPlugins({
|
|
26
|
-
plugins,
|
|
27
|
-
type: CmsEntryFieldFilterPlugin.type,
|
|
28
|
-
property: "fieldType"
|
|
29
|
-
});
|
|
30
|
-
const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
|
|
31
|
-
const getFilterCreatePlugin = type => {
|
|
32
|
-
const fieldType = getBaseFieldType({
|
|
33
|
-
type
|
|
34
|
-
});
|
|
35
|
-
const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;
|
|
36
|
-
if (filterCreatePlugin) {
|
|
37
|
-
return filterCreatePlugin;
|
|
38
|
-
}
|
|
39
|
-
throw new WebinyError(`There is no filter create plugin for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_PLUGIN", {
|
|
40
|
-
fieldType
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
const createExpression = ({
|
|
44
|
-
where,
|
|
45
|
-
condition
|
|
46
|
-
}) => {
|
|
47
|
-
const expression = {
|
|
48
|
-
filters: [],
|
|
49
|
-
expressions: [],
|
|
50
|
-
condition
|
|
51
|
-
};
|
|
52
|
-
for (const key in where) {
|
|
53
|
-
const value = where[key];
|
|
54
|
-
if (value === undefined) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* If there are "AND" or "OR" keys, let's sort them out first.
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* AND conditional
|
|
63
|
-
*/
|
|
64
|
-
if (key === "AND") {
|
|
65
|
-
const childWhereList = getWhereValues(value, key);
|
|
66
|
-
const childExpression = {
|
|
67
|
-
condition: "AND",
|
|
68
|
-
filters: [],
|
|
69
|
-
expressions: []
|
|
70
|
-
};
|
|
71
|
-
for (const childWhere of childWhereList) {
|
|
72
|
-
const result = createExpression({
|
|
73
|
-
where: childWhere,
|
|
74
|
-
condition: "AND"
|
|
75
|
-
});
|
|
76
|
-
childExpression.expressions.push(result);
|
|
77
|
-
}
|
|
78
|
-
expression.expressions.push(childExpression);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* OR conditional
|
|
83
|
-
*/
|
|
84
|
-
if (key === "OR") {
|
|
85
|
-
const childWhereList = getWhereValues(value, key);
|
|
86
|
-
const childExpression = {
|
|
87
|
-
condition: "OR",
|
|
88
|
-
filters: [],
|
|
89
|
-
expressions: []
|
|
90
|
-
};
|
|
91
|
-
for (const childWhere of childWhereList) {
|
|
92
|
-
const result = createExpression({
|
|
93
|
-
where: childWhere,
|
|
94
|
-
condition: "AND"
|
|
95
|
-
});
|
|
96
|
-
childExpression.expressions.push(result);
|
|
97
|
-
}
|
|
98
|
-
expression.expressions.push(childExpression);
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const whereParams = extractWhereParams(key);
|
|
102
|
-
if (!whereParams) {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
const {
|
|
106
|
-
fieldId,
|
|
107
|
-
operation,
|
|
108
|
-
negate
|
|
109
|
-
} = whereParams;
|
|
110
|
-
const field = fields[fieldId];
|
|
111
|
-
if (!field) {
|
|
112
|
-
throw new WebinyError(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
|
|
113
|
-
fieldId
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* We need a filter create plugin for this type.
|
|
119
|
-
*/
|
|
120
|
-
const filterCreatePlugin = getFilterCreatePlugin(field.type);
|
|
121
|
-
const fieldType = getBaseFieldType(field);
|
|
122
|
-
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
123
|
-
const transformValueCallable = value => {
|
|
124
|
-
if (!transformValuePlugin) {
|
|
125
|
-
return value;
|
|
126
|
-
}
|
|
127
|
-
return transformValuePlugin.transform({
|
|
128
|
-
field,
|
|
129
|
-
value
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
const result = filterCreatePlugin.create({
|
|
133
|
-
key,
|
|
134
|
-
value,
|
|
135
|
-
valueFilterPlugins: filterPlugins,
|
|
136
|
-
transformValuePlugins,
|
|
137
|
-
getFilterCreatePlugin,
|
|
138
|
-
operation,
|
|
139
|
-
negate,
|
|
140
|
-
field,
|
|
141
|
-
fields,
|
|
142
|
-
compareValue: transformValue({
|
|
143
|
-
value,
|
|
144
|
-
transform: transformValueCallable
|
|
145
|
-
}),
|
|
146
|
-
transformValue: transformValueCallable
|
|
147
|
-
});
|
|
148
|
-
/**
|
|
149
|
-
* There is a possibility of
|
|
150
|
-
* - no result
|
|
151
|
-
* - result being an array
|
|
152
|
-
* - result being an object
|
|
153
|
-
*/
|
|
154
|
-
if (!result || Array.isArray(result) && result.length === 0) {
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
expression.filters.push(...(Array.isArray(result) ? result : [result]));
|
|
158
|
-
}
|
|
159
|
-
return expression;
|
|
160
|
-
};
|
|
161
|
-
const expression = createExpression({
|
|
162
|
-
where,
|
|
163
|
-
condition: "AND"
|
|
164
|
-
});
|
|
165
|
-
/**
|
|
166
|
-
* If the first expression has no filters and has only one expression, put that expression as main one.
|
|
167
|
-
* This will mostly be used when having an OR condition as the single expression in the root level of the where
|
|
168
|
-
*/
|
|
169
|
-
if (expression.filters.length > 0 || expression.expressions.length !== 1) {
|
|
170
|
-
return expression;
|
|
171
|
-
}
|
|
172
|
-
return expression.expressions[0];
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
//# sourceMappingURL=createExpressions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["WebinyError","ValueFilterPlugin","getMappedPlugins","extractWhereParams","transformValue","CmsEntryFieldFilterPlugin","getWhereValues","getBaseFieldType","createExpressions","params","where","plugins","fields","filterPlugins","type","property","transformValuePlugins","fieldFilterCreatePlugins","defaultFilterCreatePlugin","getFilterCreatePlugin","fieldType","filterCreatePlugin","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","childExpression","childWhere","result","push","whereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { extractWhereParams } from \"./where.js\";\nimport { transformValue } from \"./transform.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n plugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: Params): Expression => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const fieldType = getBaseFieldType({\n type\n });\n const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${fieldType}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n fieldType\n }\n );\n };\n\n const createExpression = ({ where, condition }: CreateExpressionParams): Expression => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const fieldType = getBaseFieldType(field);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[fieldType];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins: filterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAEvC,SAASC,iBAAiB,QAAQ,8DAA8D;AAIhG,SAASC,gBAAgB;AACzB,SAASC,kBAAkB;AAC3B,SAASC,cAAc;AACvB,SAASC,yBAAyB;AAClC,SAASC,cAAc;AACvB,SAASC,gBAAgB,QAAQ,oDAAoD;AA+BrF,OAAO,MAAMC,iBAAiB,GAAIC,MAAc,IAAiB;EAC7D,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC;EAAO,CAAC,GAAGH,MAAM;EACzC,MAAMI,aAAa,GAAGX,gBAAgB,CAAoB;IACtDS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,EAAE;IACtE,OAAOxB,UAAU;EACrB;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC","ignoreList":[]}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
-
import type { Field } from "./types.js";
|
|
3
|
-
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
|
-
interface Params {
|
|
5
|
-
fields: CmsModelField[];
|
|
6
|
-
plugins: PluginsContainer;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
10
|
-
*
|
|
11
|
-
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
12
|
-
*/
|
|
13
|
-
export declare const createFields: (params: Params) => {
|
|
14
|
-
[x: string]: Field;
|
|
15
|
-
};
|
|
16
|
-
export {};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { createSystemFields } from "./systemFields.js";
|
|
2
|
-
import { CmsEntryFieldFilterPathPlugin } from "../../../plugins/index.js";
|
|
3
|
-
import { getMappedPlugins } from "./mapPlugins.js";
|
|
4
|
-
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
5
|
-
const createFieldCollection = params => {
|
|
6
|
-
const {
|
|
7
|
-
fields,
|
|
8
|
-
parents,
|
|
9
|
-
transformValuePlugins,
|
|
10
|
-
valuePathPlugins,
|
|
11
|
-
system
|
|
12
|
-
} = params;
|
|
13
|
-
return fields.reduce((collection, field) => {
|
|
14
|
-
const fieldType = getBaseFieldType(field);
|
|
15
|
-
const transformPlugin = transformValuePlugins[fieldType];
|
|
16
|
-
const valuePathPlugin = valuePathPlugins[fieldType];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
20
|
-
*/
|
|
21
|
-
const fieldId = [...parents, {
|
|
22
|
-
fieldId: field.fieldId,
|
|
23
|
-
list: field.list
|
|
24
|
-
}].map(f => f.fieldId).join(".");
|
|
25
|
-
collection[fieldId] = {
|
|
26
|
-
...field,
|
|
27
|
-
parents,
|
|
28
|
-
system,
|
|
29
|
-
createPath: params => {
|
|
30
|
-
if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map(p => p.fieldId))) {
|
|
31
|
-
return valuePathPlugin.createPath(params);
|
|
32
|
-
}
|
|
33
|
-
return parents.map(parent => parent.fieldId).concat([params.field.fieldId]).join(".");
|
|
34
|
-
},
|
|
35
|
-
transform: value => {
|
|
36
|
-
if (!transformPlugin) {
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
return transformPlugin.transform({
|
|
40
|
-
field,
|
|
41
|
-
value
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const childFields = field.settings?.fields;
|
|
46
|
-
if (!childFields?.length) {
|
|
47
|
-
return collection;
|
|
48
|
-
}
|
|
49
|
-
const result = createFieldCollection({
|
|
50
|
-
fields: childFields,
|
|
51
|
-
parents: [...parents, {
|
|
52
|
-
fieldId: field.fieldId,
|
|
53
|
-
list: field.list
|
|
54
|
-
}],
|
|
55
|
-
transformValuePlugins,
|
|
56
|
-
valuePathPlugins,
|
|
57
|
-
system
|
|
58
|
-
});
|
|
59
|
-
Object.assign(collection, result);
|
|
60
|
-
return collection;
|
|
61
|
-
}, {});
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
65
|
-
*
|
|
66
|
-
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
67
|
-
*/
|
|
68
|
-
export const createFields = params => {
|
|
69
|
-
const {
|
|
70
|
-
fields,
|
|
71
|
-
plugins
|
|
72
|
-
} = params;
|
|
73
|
-
const transformValuePlugins = getMappedPlugins({
|
|
74
|
-
plugins,
|
|
75
|
-
type: "cms-field-filter-value-transform",
|
|
76
|
-
property: "fieldType"
|
|
77
|
-
});
|
|
78
|
-
const valuePathPlugins = getMappedPlugins({
|
|
79
|
-
plugins,
|
|
80
|
-
type: CmsEntryFieldFilterPathPlugin.type,
|
|
81
|
-
property: "fieldType"
|
|
82
|
-
});
|
|
83
|
-
const collection = createFieldCollection({
|
|
84
|
-
fields: createSystemFields(),
|
|
85
|
-
transformValuePlugins,
|
|
86
|
-
valuePathPlugins,
|
|
87
|
-
parents: [],
|
|
88
|
-
system: true
|
|
89
|
-
});
|
|
90
|
-
const result = createFieldCollection({
|
|
91
|
-
fields,
|
|
92
|
-
transformValuePlugins,
|
|
93
|
-
valuePathPlugins,
|
|
94
|
-
parents: [{
|
|
95
|
-
fieldId: "values",
|
|
96
|
-
list: false
|
|
97
|
-
}],
|
|
98
|
-
system: false
|
|
99
|
-
});
|
|
100
|
-
return {
|
|
101
|
-
...collection,
|
|
102
|
-
...result
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
//# sourceMappingURL=createFields.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createSystemFields","CmsEntryFieldFilterPathPlugin","getMappedPlugins","getBaseFieldType","createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","reduce","collection","field","fieldType","transformPlugin","valuePathPlugin","fieldId","list","map","f","join","createPath","canUse","p","parent","concat","transform","value","childFields","settings","length","result","Object","assign","createFields","plugins","type","property"],"sources":["createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins/index.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;\n valuePathPlugins: Record<string, CmsEntryFieldFilterPathPlugin>;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const fieldType = getBaseFieldType(field);\n const transformPlugin = transformValuePlugins[fieldType];\n const valuePathPlugin = valuePathPlugins[fieldType];\n\n /**\n * The required fieldId is a product of all of its parents and its own fieldId.\n */\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n list: field.list\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system,\n createPath: params => {\n if (\n valuePathPlugin &&\n valuePathPlugin.canUse(\n field,\n parents.map(p => p.fieldId)\n )\n ) {\n return valuePathPlugin.createPath(params);\n }\n\n return parents\n .map(parent => parent.fieldId)\n .concat([params.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n const childFields = field.settings?.fields;\n if (!childFields?.length) {\n return collection;\n }\n\n const result = createFieldCollection({\n fields: childFields,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n list: field.list\n }\n ],\n transformValuePlugins,\n valuePathPlugins,\n system\n });\n Object.assign(collection, result);\n return collection;\n }, {});\n};\n/**\n * This method will map the fieldId (fieldId -> field) to the actual field.\n *\n * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).\n */\nexport const createFields = (params: Params) => {\n const { fields, plugins } = params;\n\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const collection = createFieldCollection({\n fields: createSystemFields(),\n transformValuePlugins,\n valuePathPlugins,\n parents: [],\n system: true\n });\n\n const result = createFieldCollection({\n fields,\n transformValuePlugins,\n valuePathPlugins,\n parents: [\n {\n fieldId: \"values\",\n list: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"mappings":"AACA,SAASA,kBAAkB;AAI3B,SAASC,6BAA6B;AACtC,SAASC,gBAAgB;AACzB,SAASC,gBAAgB,QAAQ,oDAAoD;AAmBrF,MAAMC,qBAAqB,GAAIC,MAAmC,IAAsB;EACpF,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC,qBAAqB;IAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACnF,OAAOC,MAAM,CAACK,MAAM,CAAkB,CAACC,UAAU,EAAEC,KAAK,KAAK;IACzD,MAAMC,SAAS,GAAGX,gBAAgB,CAACU,KAAK,CAAC;IACzC,MAAME,eAAe,GAAGP,qBAAqB,CAACM,SAAS,CAAC;IACxD,MAAME,eAAe,GAAGP,gBAAgB,CAACK,SAAS,CAAC;;IAEnD;AACR;AACA;IACQ,MAAMG,OAAO,GAAG,CACZ,GAAGV,OAAO,EACV;MACIU,OAAO,EAAEJ,KAAK,CAACI,OAAO;MACtBC,IAAI,EAAEL,KAAK,CAACK;IAChB,CAAC,CACJ,CACIC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACH,OAAO,CAAC,CACnBI,IAAI,CAAC,GAAG,CAAC;IAEdT,UAAU,CAACK,OAAO,CAAC,GAAG;MAClB,GAAGJ,KAAK;MACRN,OAAO;MACPG,MAAM;MACNY,UAAU,EAAEjB,MAAM,IAAI;QAClB,IACIW,eAAe,IACfA,eAAe,CAACO,MAAM,CAClBV,KAAK,EACLN,OAAO,C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CC,QAAQ,EAAE;EACd,CAAC,CAAC;EACF,MAAM7B,gBAAgB,GAAGP,gBAAgB,CAAgC;IACrEkC,OAAO;IACPC,IAAI,EAAEpC,6BAA6B,CAACoC,IAAI;IACxCC,QAAQ,EAAE;EACd,CAAC,CAAC;EAEF,MAAM1B,UAAU,GAAGR,qBAAqB,CAAC;IACrCE,MAAM,EAAEN,kBAAkB,CAAC,CAAC;IAC5BQ,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,EAAE;IACXG,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,MAAMsB,MAAM,GAAG5B,qBAAqB,CAAC;IACjCE,MAAM;IACNE,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,CACL;MACIU,OAAO,EAAE,QAAQ;MACjBC,IAAI,EAAE;IACV,CAAC,CACJ;IACDR,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,OAAO;IACH,GAAGE,UAAU;IACb,GAAGoB;EACP,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Field } from "./types.js";
|
|
2
|
-
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
-
interface IResponse {
|
|
5
|
-
valuePath: string;
|
|
6
|
-
reverse: boolean;
|
|
7
|
-
fieldId: string;
|
|
8
|
-
field: Field;
|
|
9
|
-
}
|
|
10
|
-
interface IParams {
|
|
11
|
-
model: CmsModel;
|
|
12
|
-
sortBy: string;
|
|
13
|
-
fields: Record<string, Field>;
|
|
14
|
-
plugins: PluginsContainer;
|
|
15
|
-
}
|
|
16
|
-
export declare const extractSort: (params: IParams) => IResponse;
|
|
17
|
-
export {};
|