@webiny/api-headless-cms-ddb-es 5.29.0 → 5.30.0

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.
@@ -83,6 +83,9 @@ const createEntryEntity = params => {
83
83
  },
84
84
  values: {
85
85
  type: "map"
86
+ },
87
+ meta: {
88
+ type: "map"
86
89
  }
87
90
  }, attributes || {})
88
91
  });
@@ -1 +1 @@
1
- {"version":3,"names":["createEntryEntity","params","table","entityName","attributes","Entity","name","PK","type","partitionKey","SK","sortKey","TYPE","__type","webinyVersion","tenant","entryId","id","createdBy","ownedBy","createdOn","savedOn","modelId","locale","publishedOn","version","locked","status","values"],"sources":["entry.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\nexport interface CreateEntryEntityParams {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\nexport const createEntryEntity = (params: CreateEntryEntityParams): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n type: \"string\",\n partitionKey: true\n },\n SK: {\n type: \"string\",\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n __type: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n entryId: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n ownedBy: {\n type: \"map\"\n },\n createdOn: {\n type: \"string\"\n },\n savedOn: {\n type: \"string\"\n },\n modelId: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n publishedOn: {\n type: \"string\"\n },\n version: {\n type: \"number\"\n },\n locked: {\n type: \"boolean\"\n },\n status: {\n type: \"string\"\n },\n values: {\n type: \"map\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAQO,MAAMA,iBAAiB,GAAIC,MAAD,IAAkD;EAC/E,MAAM;IAAEC,KA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Name","attributes","Entity","name","PK","type","partitionKey","SK","sortKey","TYPE","__type","webinyVersion","tenant","entryId","id","createdBy","ownedBy","createdOn","savedOn","modelId","locale","publishedOn","version","locked","status","values","meta"],"sources":["entry.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\nexport interface CreateEntryEntityParams {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\nexport const createEntryEntity = (params: CreateEntryEntityParams): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n type: \"string\",\n partitionKey: true\n },\n SK: {\n type: \"string\",\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n __type: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n entryId: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n ownedBy: {\n type: \"map\"\n },\n createdOn: {\n type: \"string\"\n },\n savedOn: {\n type: \"string\"\n },\n modelId: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n publishedOn: {\n type: \"string\"\n },\n version: {\n type: \"number\"\n },\n locked: {\n type: \"boolean\"\n },\n status: {\n type: \"string\"\n },\n values: {\n type: \"map\"\n },\n meta: {\n type: \"map\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAQO,MAAMA,iBAAiB,GAAIC,MAAD,IAAkD;EAC/E,MAAM;IAAEC,KAAF;IAASC,UAAT;IAAqBC;EAArB,IAAoCH,MAA1C;EACA,OAAO,IAAII,uBAAJ,CAAW;IACdC,IAAI,EAAEH,UADQ;IAEdD,KAFc;IAGdE,UAAU;MACNG,EAAE,EAAE;QACAC,IAAI,EAAE,QADN;QAEAC,YAAY,EAAE;MAFd,CADE;MAKNC,EAAE,EAAE;QACAF,IAAI,EAAE,QADN;QAEAG,OAAO,EAAE;MAFT,CALE;MASNC,IAAI,EAAE;QACFJ,IAAI,EAAE;MADJ,CATA;MAYNK,MAAM,EAAE;QACJL,IAAI,EAAE;MADF,CAZF;MAeNM,aAAa,EAAE;QACXN,IAAI,EAAE;MADK,CAfT;MAkBNO,MAAM,EAAE;QACJP,IAAI,EAAE;MADF,CAlBF;MAqBNQ,OAAO,EAAE;QACLR,IAAI,EAAE;MADD,CArBH;MAwBNS,EAAE,EAAE;QACAT,IAAI,EAAE;MADN,CAxBE;MA2BNU,SAAS,EAAE;QACPV,IAAI,EAAE;MADC,CA3BL;MA8BNW,OAAO,EAAE;QACLX,IAAI,EAAE;MADD,CA9BH;MAiCNY,SAAS,EAAE;QACPZ,IAAI,EAAE;MADC,CAjCL;MAoCNa,OAAO,EAAE;QACLb,IAAI,EAAE;MADD,CApCH;MAuCNc,OAAO,EAAE;QACLd,IAAI,EAAE;MADD,CAvCH;MA0CNe,MAAM,EAAE;QACJf,IAAI,EAAE;MADF,CA1CF;MA6CNgB,WAAW,EAAE;QACThB,IAAI,EAAE;MADG,CA7CP;MAgDNiB,OAAO,EAAE;QACLjB,IAAI,EAAE;MADD,CAhDH;MAmDNkB,MAAM,EAAE;QACJlB,IAAI,EAAE;MADF,CAnDF;MAsDNmB,MAAM,EAAE;QACJnB,IAAI,EAAE;MADF,CAtDF;MAyDNoB,MAAM,EAAE;QACJpB,IAAI,EAAE;MADF,CAzDF;MA4DNqB,IAAI,EAAE;QACFrB,IAAI,EAAE;MADJ;IA5DA,GA+DFJ,UAAU,IAAI,EA/DZ;EAHI,CAAX,CAAP;AAqEH,CAvEM"}
@@ -1,2 +1,2 @@
1
- declare const _default: () => import("@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin").StorageTransformPlugin<any, any>[];
1
+ declare const _default: () => import("@webiny/api-headless-cms").StorageTransformPlugin<any, any>[];
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
- import { StorageTransformPlugin } from "@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin";
1
+ import { StorageTransformPlugin } from "@webiny/api-headless-cms";
2
2
  declare const _default: () => StorageTransformPlugin<any, any>;
3
3
  export default _default;
@@ -9,10 +9,10 @@ exports.default = void 0;
9
9
 
10
10
  var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
12
- var _StorageTransformPlugin = require("@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin");
12
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
13
13
 
14
14
  const excludeTypes = ["time", "dateTimeWithTimezone"];
15
- const plugin = new _StorageTransformPlugin.StorageTransformPlugin({
15
+ const plugin = new _apiHeadlessCms.StorageTransformPlugin({
16
16
  fieldType: "datetime",
17
17
  fromStorage: async ({
18
18
  value,
@@ -1 +1 @@
1
- {"version":3,"names":["excludeTypes","plugin","StorageTransformPlugin","fieldType","fromStorage","value","field","type","settings","includes","Date","console","log","toStorage","toISOString","WebinyError","fieldId"],"sources":["date.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin\";\n\nconst excludeTypes = [\"time\", \"dateTimeWithTimezone\"];\n\nconst plugin = 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 try {\n return new Date(value);\n } catch {\n console.log(`Could not transform from storage for field type`);\n return value;\n }\n },\n toStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\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 });\n }\n});\n\nexport default () => {\n return plugin;\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA,MAAMA,YAAY,GAAG,CAAC,MAAD,EAAS,sBAAT,CAArB;AAEA,MAAMC,MAAM,GAAG,IAAIC,8CAAJ,CAA2B;EACtCC,SAAS,EAAE,UAD2B;EAEtCC,WAAW,EAAE,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA4B;IACrC,MAAM;MAAEC;IAAF,IAAWD,KAAK,CAACE,QAAN,IAAkB,EAAnC;;IACA,IAAI,CAACH,KAAD,IAAU,CAACE,IAAX,IAAmBP,YAAY,CAACS,QAAb,CAAsBF,IAAtB,CAAvB,EAAoD;MAChD,OAAOF,KAAP;IACH;;IACD,IAAI;MACA,OAAO,IAAIK,IAAJ,CAASL,KAAT,CAAP;IACH,CAFD,CAEE,MAAM;MACJM,OAAO,CAACC,GAAR,CAAa,iDAAb;MACA,OAAOP,KAAP;IACH;EACJ,CAbqC;EActCQ,SAAS,EAAE,OAAO;IAAER,KAAF;IAASC;EAAT,CAAP,KAA4B;IACnC,MAAM;MAAEC;IAAF,IAAWD,KAAK,CAACE,QAAN,IAAkB,EAAnC;;IACA,IAAI,CAACH,KAAD,IAAU,CAACE,IAAX,IAAmBP,YAAY,CAACS,QAAb,CAAsBF,IAAtB,CAAvB,EAAoD;MAChD,OAAOF,KAAP;IACH;;IACD,IAAKA,KAAD,CAAeS,WAAnB,EAAgC;MAC5B,OAAQT,KAAD,CAAgBS,WAAhB,EAAP;IACH,CAFD,MAEO,IAAI,OAAOT,KAAP,KAAiB,QAArB,EAA+B;MAClC,OAAOA,KAAP;IACH;;IACD,MAAM,IAAIU,cAAJ,CAAgB,2CAAhB,EAA6D,kBAA7D,EAAiF;MACnFV,KADmF;MAEnFW,OAAO,EAAEV,KAAK,CAACU;IAFoE,CAAjF,CAAN;EAIH;AA5BqC,CAA3B,CAAf;;eA+Be,MAAM;EACjB,OAAOf,MAAP;AACH,C"}
1
+ {"version":3,"names":["excludeTypes","plugin","StorageTransformPlugin","fieldType","fromStorage","value","field","type","settings","includes","Date","console","log","toStorage","toISOString","WebinyError","fieldId"],"sources":["date.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nconst excludeTypes = [\"time\", \"dateTimeWithTimezone\"];\n\nconst plugin = 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 try {\n return new Date(value);\n } catch {\n console.log(`Could not transform from storage for field type`);\n return value;\n }\n },\n toStorage: async ({ value, field }) => {\n const { type } = field.settings || {};\n if (!value || !type || excludeTypes.includes(type)) {\n return value;\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 });\n }\n});\n\nexport default () => {\n return plugin;\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA,MAAMA,YAAY,GAAG,CAAC,MAAD,EAAS,sBAAT,CAArB;AAEA,MAAMC,MAAM,GAAG,IAAIC,sCAAJ,CAA2B;EACtCC,SAAS,EAAE,UAD2B;EAEtCC,WAAW,EAAE,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA4B;IACrC,MAAM;MAAEC;IAAF,IAAWD,KAAK,CAACE,QAAN,IAAkB,EAAnC;;IACA,IAAI,CAACH,KAAD,IAAU,CAACE,IAAX,IAAmBP,YAAY,CAACS,QAAb,CAAsBF,IAAtB,CAAvB,EAAoD;MAChD,OAAOF,KAAP;IACH;;IACD,IAAI;MACA,OAAO,IAAIK,IAAJ,CAASL,KAAT,CAAP;IACH,CAFD,CAEE,MAAM;MACJM,OAAO,CAACC,GAAR,CAAa,iDAAb;MACA,OAAOP,KAAP;IACH;EACJ,CAbqC;EActCQ,SAAS,EAAE,OAAO;IAAER,KAAF;IAASC;EAAT,CAAP,KAA4B;IACnC,MAAM;MAAEC;IAAF,IAAWD,KAAK,CAACE,QAAN,IAAkB,EAAnC;;IACA,IAAI,CAACH,KAAD,IAAU,CAACE,IAAX,IAAmBP,YAAY,CAACS,QAAb,CAAsBF,IAAtB,CAAvB,EAAoD;MAChD,OAAOF,KAAP;IACH;;IACD,IAAKA,KAAD,CAAeS,WAAnB,EAAgC;MAC5B,OAAQT,KAAD,CAAgBS,WAAhB,EAAP;IACH,CAFD,MAEO,IAAI,OAAOT,KAAP,KAAiB,QAArB,EAA+B;MAClC,OAAOA,KAAP;IACH;;IACD,MAAM,IAAIU,cAAJ,CAAgB,2CAAhB,EAA6D,kBAA7D,EAAiF;MACnFV,KADmF;MAEnFW,OAAO,EAAEV,KAAK,CAACU;IAFoE,CAAjF,CAAN;EAIH;AA5BqC,CAA3B,CAAf;;eA+Be,MAAM;EACjB,OAAOf,MAAP;AACH,C"}
@@ -1,4 +1,4 @@
1
- import { StorageTransformPlugin } from "@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin";
1
+ import { StorageTransformPlugin } from "@webiny/api-headless-cms";
2
2
  export interface StorageValue {
3
3
  compression: string;
4
4
  value: any;
@@ -11,7 +11,7 @@ var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
12
12
  var _gzip = require("@webiny/utils/compression/gzip");
13
13
 
14
- var _StorageTransformPlugin = require("@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin");
14
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
15
15
 
16
16
  const GZIP = "gzip";
17
17
  const TO_STORAGE_ENCODING = "base64";
@@ -25,7 +25,7 @@ const convertToBuffer = value => {
25
25
  return value;
26
26
  };
27
27
 
28
- const plugin = new _StorageTransformPlugin.StorageTransformPlugin({
28
+ const plugin = new _apiHeadlessCms.StorageTransformPlugin({
29
29
  fieldType: "long-text",
30
30
  fromStorage: async ({
31
31
  field,
@@ -1 +1 @@
1
- {"version":3,"names":["GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","plugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","typeOf","WebinyError","fieldId","compression","JSON","stringify","buf","ungzip","toString","ex","process","env","DEBUG","console","log","message","toStorage","compressedValue","gzip"],"sources":["longText.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { compress as gzip, decompress as ungzip } from \"@webiny/utils/compression/gzip\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin\";\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: any;\n}\n\nconst plugin = new StorageTransformPlugin<string, StorageValue>({\n fieldType: \"long-text\",\n fromStorage: async ({ field, value: storageValue }) => {\n const typeOf = typeof storageValue;\n if (!storageValue || typeOf === \"string\" || typeOf === \"number\") {\n return storageValue as any;\n } else if (typeof storageValue !== \"object\") {\n throw new WebinyError(\n `LongText value received in \"fromStorage\" function is not an object in field \"${field.fieldId}\".`\n );\n }\n const { compression, value } = 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.fieldId\n }\": ${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 return buf.toString(FROM_STORAGE_ENCODING);\n } catch (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while decompressing long-text.\");\n console.log(ex.message);\n return null;\n }\n },\n toStorage: async ({ value }) => {\n const compressedValue = await gzip(value);\n\n return {\n compression: GZIP,\n value: compressedValue.toString(TO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AAI;MACA,MAAMG,GAAG,GAAG,MAAM,IAAAC,gBAAA,EAAOjB,eAAe,CAACC,KAAD,CAAtB,CAAlB;MACA,OAAOe,GAAG,CAACE,QAAJ,CAAanB,qBAAb,CAAP;IACH,CAHD,CAGE,OAAOoB,EAAP,EAAW;MACT,IAAIC,OAAO,CAACC,GAAR,CAAYC,KAAZ,KAAsB,MAA1B,EAAkC;QAC9B,OAAO,IAAP;MACH;;MACDC,OAAO,CAACC,GAAR,CAAY,sCAAZ;MACAD,OAAO,CAACC,GAAR,CAAYL,EAAE,CAACM,OAAf;MACA,OAAO,IAAP;IACH;EACJ,CA7C2D;EA8C5DC,SAAS,EAAE,OAAO;IAAEzB;EAAF,CAAP,KAAqB;IAC5B,MAAM0B,eAAe,GAAG,MAAM,IAAAC,cAAA,EAAK3B,KAAL,CAA9B;IAEA,OAAO;MACHY,WAAW,EAAEhB,IADV;MAEHI,KAAK,EAAE0B,eAAe,CAACT,QAAhB,CAAyBpB,mBAAzB;IAFJ,CAAP;EAIH;AArD2D,CAAjD,CAAf;;eAwDe,MAAM;EACjB,OAAOM,MAAP;AACH,C"}
1
+ {"version":3,"names":["GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","plugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","typeOf","WebinyError","fieldId","compression","JSON","stringify","buf","ungzip","toString","ex","process","env","DEBUG","console","log","message","toStorage","compressedValue","gzip"],"sources":["longText.ts"],"sourcesContent":["import 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: any;\n}\n\nconst plugin = new StorageTransformPlugin<string, StorageValue>({\n fieldType: \"long-text\",\n fromStorage: async ({ field, value: storageValue }) => {\n const typeOf = typeof storageValue;\n if (!storageValue || typeOf === \"string\" || typeOf === \"number\") {\n return storageValue as any;\n } else if (typeof storageValue !== \"object\") {\n throw new WebinyError(\n `LongText value received in \"fromStorage\" function is not an object in field \"${field.fieldId}\".`\n );\n }\n const { compression, value } = 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.fieldId\n }\": ${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 return buf.toString(FROM_STORAGE_ENCODING);\n } catch (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while decompressing long-text.\");\n console.log(ex.message);\n return null;\n }\n },\n toStorage: async ({ value }) => {\n const compressedValue = await gzip(value);\n\n return {\n compression: GZIP,\n value: compressedValue.toString(TO_STORAGE_ENCODING)\n };\n }\n});\n\nexport default () => {\n return plugin;\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,IAAI,GAAG,MAAb;AACA,MAAMC,mBAAmB,GAAG,QAA5B;AACA,MAAMC,qBAAqB,GAAG,MAA9B;;AAEA,MAAMC,eAAe,GAAIC,KAAD,IAAoC;EACxD,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC3B,OAAOC,MAAM,CAACC,IAAP,CAAYF,KAAZ,EAAmBH,mBAAnB,CAAP;EACH;;EACD,OAAOG,KAAP;AACH,CALD;;AAYA,MAAMG,MAAM,GAAG,IAAIC,sCAAJ,CAAiD;EAC5D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,CAAP,KAAqB;IAC5B,MAAM0B,eAAe,GAAG,MAAM,IAAAC,cAAA,EAAK3B,KAAL,CAA9B;IAEA,OAAO;MACHY,WAAW,EAAEhB,IADV;MAEHI,KAAK,EAAE0B,eAAe,CAACT,QAAhB,CAAyBpB,mBAAzB;IAFJ,CAAP;EAIH;AArD2D,CAAjD,CAAf;;eAwDe,MAAM;EACjB,OAAOM,MAAP;AACH,C"}
@@ -1,4 +1,4 @@
1
- import { StorageTransformPlugin } from "@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin";
1
+ import { StorageTransformPlugin } from "@webiny/api-headless-cms";
2
2
  export declare type OriginalValue = Record<string, any> | any[];
3
3
  export interface StorageValue {
4
4
  compression: string;
@@ -11,7 +11,7 @@ var _jsonpack = _interopRequireDefault(require("jsonpack"));
11
11
 
12
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
13
 
14
- var _StorageTransformPlugin = require("@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin");
14
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
15
15
 
16
16
  /**
17
17
  * Remove when jsonpack gets PR with a fix merged
@@ -41,7 +41,7 @@ const transformArray = value => {
41
41
  return value;
42
42
  };
43
43
 
44
- const plugin = new _StorageTransformPlugin.StorageTransformPlugin({
44
+ const plugin = new _apiHeadlessCms.StorageTransformPlugin({
45
45
  fieldType: "rich-text",
46
46
  fromStorage: async ({
47
47
  field,
@@ -1 +1 @@
1
- {"version":3,"names":["transformArray","value","isArray","Array","shouldBeArray","from","k","plugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","WebinyError","fieldId","hasOwnProperty","compression","JSON","stringify","jsonpack","unpack","ex","process","env","DEBUG","console","log","message","toStorage","jsonValue","pack"],"sources":["richText.ts"],"sourcesContent":["import jsonpack from \"jsonpack\";\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms/content/plugins/storage/StorageTransformPlugin\";\n\nexport type OriginalValue = Record<string, any> | any[];\n\nexport interface StorageValue {\n compression: string;\n value: any;\n}\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 as any);\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\nconst plugin = 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.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 (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while decompressing rich-text.\");\n console.log(ex.message);\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 as any;\n }\n value = transformArray(value);\n\n let jsonValue: string | null = null;\n try {\n jsonValue = jsonpack.pack(value);\n } catch (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while compressing rich-text.\");\n console.log(ex.message);\n }\n return {\n compression: \"jsonpack\",\n value: jsonValue\n };\n }\n});\n\nexport default () => {\n return plugin;\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AASA;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;;AAkBA,MAAMM,MAAM,GAAG,IAAIC,8CAAJ,CAA2B;EACtCC,SAAS,EAAE,WAD2B;EAEtCC,WAAW,EAAE,OAAO;IAAEC,KAAF;IAASV,KAAK,EAAEW;EAAhB,CAAP,KAA0C;IACnD,IAAI,CAACA,YAAL,EAAmB;MACf,OAAOA,YAAP;IACH,CAFD,MAEO,IAAI,OAAOA,YAAP,KAAwB,QAA5B,EAAsC;MACzC,MAAM,IAAIC,cAAJ,CACD,gFAA+EF,KAAK,CAACG,OAAQ,IAD5F,CAAN;IAGH;IACD;AACR;AACA;AACA;;;IACQ,IAAIF,YAAY,CAACG,cAAb,CAA4B,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CAAY,oCAAZ;MACAD,OAAO,CAACC,GAAR,CAAYL,EAAE,CAACM,OAAf;IACH;;IACD,OAAO;MACHX,WAAW,EAAE,UADV;MAEHf,KAAK,EAAE4B;IAFJ,CAAP;EAIH;AAzEqC,CAA3B,CAAf;;eA4Ee,MAAM;EACjB,OAAOtB,MAAP;AACH,C"}
1
+ {"version":3,"names":["transformArray","value","isArray","Array","shouldBeArray","from","k","plugin","StorageTransformPlugin","fieldType","fromStorage","field","storageValue","WebinyError","fieldId","hasOwnProperty","compression","JSON","stringify","jsonpack","unpack","ex","process","env","DEBUG","console","log","message","toStorage","jsonValue","pack"],"sources":["richText.ts"],"sourcesContent":["import jsonpack from \"jsonpack\";\nimport WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nexport type OriginalValue = Record<string, any> | any[];\n\nexport interface StorageValue {\n compression: string;\n value: any;\n}\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 as any);\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\nconst plugin = 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.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 (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while decompressing rich-text.\");\n console.log(ex.message);\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 as any;\n }\n value = transformArray(value);\n\n let jsonValue: string | null = null;\n try {\n jsonValue = jsonpack.pack(value);\n } catch (ex) {\n if (process.env.DEBUG !== \"true\") {\n return null;\n }\n console.log(\"Error while compressing rich-text.\");\n console.log(ex.message);\n }\n return {\n compression: \"jsonpack\",\n value: jsonValue\n };\n }\n});\n\nexport default () => {\n return plugin;\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AASA;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,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ACA,OAAO,IAAP;IACH;EACJ,CAhDqC;EAiDtCC,SAAS,EAAE,OAAO;IAAE3B;EAAF,CAAP,KAAqB;IAC5B;AACR;AACA;AACA;IACQ,IAAIA,KAAK,IAAIA,KAAK,CAACc,cAAN,CAAqB,aAArB,MAAwC,IAArD,EAA2D;MACvD,OAAOd,KAAP;IACH;;IACDA,KAAK,GAAGD,cAAc,CAACC,KAAD,CAAtB;IAEA,IAAI4B,SAAwB,GAAG,IAA/B;;IACA,IAAI;MACAA,SAAS,GAAGV,iBAAA,CAASW,IAAT,CAAc7B,KAAd,CAAZ;IACH,CAFD,CAEE,OAAOoB,EAAP,EAAW;MACT,IAAIC,OAAO,CAACC,GAAR,CAAYC,KAAZ,KAAsB,MAA1B,EAAkC;QAC9B,OAAO,IAAP;MACH;;MACDC,OAAO,CAACC,GAAR,CAAY,oCAAZ;MACAD,OAAO,CAACC,GAAR,CAAYL,EAAE,CAACM,OAAf;IACH;;IACD,OAAO;MACHX,WAAW,EAAE,UADV;MAEHf,KAAK,EAAE4B;IAFJ,CAAP;EAIH;AAzEqC,CAA3B,CAAf;;eA4Ee,MAAM;EACjB,OAAOtB,MAAP;AACH,C"}
@@ -177,10 +177,30 @@ const extractEntriesFromIndex = ({
177
177
  });
178
178
  }
179
179
  }
180
+ /**
181
+ * Let's have a new entry so we do not modify the original one.
182
+ */
180
183
 
181
- list.push(_objectSpread(_objectSpread({}, entry), {}, {
184
+
185
+ const newEntry = _objectSpread(_objectSpread({}, entry), {}, {
182
186
  values: indexValues
183
- }));
187
+ });
188
+ /**
189
+ * If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.
190
+ */
191
+ // @ts-ignore
192
+
193
+
194
+ delete newEntry["rawValues"]; // @ts-ignore
195
+
196
+ delete newEntry["TYPE"]; // @ts-ignore
197
+
198
+ delete newEntry["__type"]; // @ts-ignore
199
+
200
+ delete newEntry["latest"]; // @ts-ignore
201
+
202
+ delete newEntry["published"];
203
+ list.push(_objectSpread({}, newEntry));
184
204
  }
185
205
 
186
206
  return list;
@@ -1 +1 @@
1
- {"version":3,"names":["prepareEntryToIndex","params","plugins","storageEntry","entry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","fieldType","getFieldTypePlugin","pl","WebinyError","values","rawValues","field","fields","hasOwnProperty","fieldId","targetFieldPlugin","type","toIndex","value","rawValue","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","ex","message","code","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface SetupEntriesIndexHelpersParams {\n plugins: PluginsContainer;\n}\n\ninterface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entries: CmsIndexEntry[];\n}\n\ninterface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entry: CmsEntry;\n storageEntry: CmsEntry;\n}\n\nexport const prepareEntryToIndex = (params: PrepareElasticsearchDataParams): CmsIndexEntry => {\n const { plugins, storageEntry, entry, model } = params;\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n const pl = fieldTypePlugins[fieldType];\n if (pl) {\n return pl;\n }\n throw new WebinyError(`Missing field type plugin \"${fieldType}\". Prepare entry for index.`);\n }\n\n // These objects will contain values processed by field index plugins\n const values: Record<string, string> = {};\n const rawValues: Record<string, string> = {};\n\n // We're only interested in current model fields.\n for (const field of model.fields) {\n if (storageEntry.values.hasOwnProperty(field.fieldId) === false) {\n continue;\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n\n // TODO: remove this `if` once we convert this plugin to proper plugin class\n if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {\n continue;\n }\n\n const { value, rawValue } = targetFieldPlugin.toIndex({\n plugins,\n model,\n field,\n rawValue: entry.values[field.fieldId],\n value: storageEntry.values[field.fieldId],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[field.fieldId] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[field.fieldId] = rawValue;\n }\n }\n return {\n ...storageEntry,\n values,\n rawValues\n } as CmsIndexEntry;\n};\n\nconst setupEntriesIndexHelpers = ({\n plugins: pluginsContainer\n}: SetupEntriesIndexHelpersParams) => {\n const plugins = pluginsContainer.byType<CmsModelFieldToElasticsearchPlugin>(\n \"cms-model-field-to-elastic-search\"\n );\n\n const fieldIndexPlugins: Record<string, CmsModelFieldToElasticsearchPlugin> = {};\n for (const plugin of plugins.reverse()) {\n if (fieldIndexPlugins[plugin.fieldType]) {\n continue;\n }\n fieldIndexPlugins[plugin.fieldType] = plugin;\n }\n // we will use this plugin if no targeted plugin found\n const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === \"*\");\n\n // CmsModelFieldToGraphQLPlugin plugins\n const fieldTypePlugins: Record<string, CmsModelFieldToGraphQLPlugin> = pluginsContainer\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((plugins, plugin) => ({ ...plugins, [plugin.fieldType]: plugin }), {});\n\n return {\n fieldIndexPlugins,\n defaultIndexFieldPlugin,\n fieldTypePlugins\n };\n};\n\nexport const extractEntriesFromIndex = ({\n plugins,\n entries,\n model\n}: ExtractEntriesFromIndexParams): CmsEntry[] => {\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n return fieldTypePlugins[fieldType];\n }\n\n const list: CmsEntry[] = [];\n\n for (const entry of entries) {\n // This object will contain values processed by field index plugins\n const indexValues: Record<string, string> = {};\n\n // We only consider fields that are present in the model\n for (const field of model.fields) {\n const fieldTypePlugin = fieldTypePlugins[field.type];\n if (!fieldTypePlugin) {\n throw new WebinyError(\n `Missing field type plugin \"${field.type}\". Extract entries from index.`\n );\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {\n continue;\n }\n try {\n indexValues[field.fieldId] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[field.fieldId],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues ? entry.rawValues[field.fieldId] : null\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not transform entry field from index.\",\n ex.code || \"FIELD_FROM_INDEX_ERROR\",\n {\n field,\n entry\n }\n );\n }\n }\n list.push({ ...entry, values: indexValues });\n }\n\n return list;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAoBO,MAAMA,mBAAmB,GAAIC,MAAD,IAA2D;EAC1F,MAAM;IAAEC,OAAF;IAAWC,YAAX;IAAyBC,KAAzB;IAAgCC;EAAhC,IAA0CJ,MAAhD;EACA,MAAM;IAAEK,iBAAF;IAAqBC,uBAArB;IAA8CC;EAA9C,IACFC,wBAAwB,CAAC;IAAEP;EAAF,CAAD,CAD5B;;EAGA,SAASQ,mBAAT,CAA6BC,SAA7B,EAAgD;IAC5C,OAAOL,iBAAiB,CAACK,SAAD,CAAjB,IAAgCJ,uBAAvC;EACH;;EAED,SAASK,kBAAT,CAA4BD,SAA5B,EAA+C;IAC3C,MAAME,EAAE,GA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ry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","fieldType","getFieldTypePlugin","pl","WebinyError","values","rawValues","field","fields","hasOwnProperty","fieldId","targetFieldPlugin","type","toIndex","value","rawValue","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","ex","message","code","newEntry","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface SetupEntriesIndexHelpersParams {\n plugins: PluginsContainer;\n}\n\ninterface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entries: CmsIndexEntry[];\n}\n\ninterface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entry: CmsEntry;\n storageEntry: CmsEntry;\n}\n\nexport const prepareEntryToIndex = (params: PrepareElasticsearchDataParams): CmsIndexEntry => {\n const { plugins, storageEntry, entry, model } = params;\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n const pl = fieldTypePlugins[fieldType];\n if (pl) {\n return pl;\n }\n throw new WebinyError(`Missing field type plugin \"${fieldType}\". Prepare entry for index.`);\n }\n\n // These objects will contain values processed by field index plugins\n const values: Record<string, string> = {};\n const rawValues: Record<string, string> = {};\n\n // We're only interested in current model fields.\n for (const field of model.fields) {\n if (storageEntry.values.hasOwnProperty(field.fieldId) === false) {\n continue;\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n\n // TODO: remove this `if` once we convert this plugin to proper plugin class\n if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {\n continue;\n }\n\n const { value, rawValue } = targetFieldPlugin.toIndex({\n plugins,\n model,\n field,\n rawValue: entry.values[field.fieldId],\n value: storageEntry.values[field.fieldId],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[field.fieldId] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[field.fieldId] = rawValue;\n }\n }\n return {\n ...storageEntry,\n values,\n rawValues\n } as CmsIndexEntry;\n};\n\nconst setupEntriesIndexHelpers = ({\n plugins: pluginsContainer\n}: SetupEntriesIndexHelpersParams) => {\n const plugins = pluginsContainer.byType<CmsModelFieldToElasticsearchPlugin>(\n \"cms-model-field-to-elastic-search\"\n );\n\n const fieldIndexPlugins: Record<string, CmsModelFieldToElasticsearchPlugin> = {};\n for (const plugin of plugins.reverse()) {\n if (fieldIndexPlugins[plugin.fieldType]) {\n continue;\n }\n fieldIndexPlugins[plugin.fieldType] = plugin;\n }\n // we will use this plugin if no targeted plugin found\n const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === \"*\");\n\n // CmsModelFieldToGraphQLPlugin plugins\n const fieldTypePlugins: Record<string, CmsModelFieldToGraphQLPlugin> = pluginsContainer\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((plugins, plugin) => ({ ...plugins, [plugin.fieldType]: plugin }), {});\n\n return {\n fieldIndexPlugins,\n defaultIndexFieldPlugin,\n fieldTypePlugins\n };\n};\n\nexport const extractEntriesFromIndex = ({\n plugins,\n entries,\n model\n}: ExtractEntriesFromIndexParams): CmsEntry[] => {\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n return fieldTypePlugins[fieldType];\n }\n\n const list: CmsEntry[] = [];\n\n for (const entry of entries) {\n // This object will contain values processed by field index plugins\n const indexValues: Record<string, string> = {};\n\n // We only consider fields that are present in the model\n for (const field of model.fields) {\n const fieldTypePlugin = fieldTypePlugins[field.type];\n if (!fieldTypePlugin) {\n throw new WebinyError(\n `Missing field type plugin \"${field.type}\". Extract entries from index.`\n );\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {\n continue;\n }\n try {\n indexValues[field.fieldId] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[field.fieldId],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues ? entry.rawValues[field.fieldId] : null\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not transform entry field from index.\",\n ex.code || \"FIELD_FROM_INDEX_ERROR\",\n {\n field,\n entry\n }\n );\n }\n }\n /**\n * Let's have a new entry so we do not modify the original one.\n */\n const newEntry: CmsEntry = {\n ...entry,\n values: indexValues\n };\n /**\n * If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.\n */\n // @ts-ignore\n delete newEntry[\"rawValues\"];\n // @ts-ignore\n delete newEntry[\"TYPE\"];\n // @ts-ignore\n delete newEntry[\"__type\"];\n // @ts-ignore\n delete newEntry[\"latest\"];\n // @ts-ignore\n delete newEntry[\"published\"];\n list.push({ ...newEntry });\n }\n\n return list;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAoBO,MAAMA,mBAAmB,GAAIC,MAAD,IAA2D;EAC1F,MAAM;IAAEC,OAAF;IAAWC,YAAX;IAAyBC,KAAzB;IAAgCC;EAAhC,IAA0CJ,MAAhD;EACA,MAAM;IAAEK,iBAAF;IAAqBC,uBAArB;IAA8CC;EAA9C,IACFC,wBAAwB,CAAC;IAA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;UAEIb;QAFJ,CAHE,CAAN;MAQH;IACJ;IACD;AACR;AACA;;;IACQ,MAAMqC,QAAkB,mCACjBrC,KADiB;MAEpBW,MAAM,EAAEoB;IAFY,EAAxB;IAIA;AACR;AACA;IACQ;;;IACA,OAAOM,QAAQ,CAAC,WAAD,CAAf,CApDyB,CAqDzB;;IACA,OAAOA,QAAQ,CAAC,MAAD,CAAf,CAtDyB,CAuDzB;;IACA,OAAOA,QAAQ,CAAC,QAAD,CAAf,CAxDyB,CAyDzB;;IACA,OAAOA,QAAQ,CAAC,QAAD,CAAf,CA1DyB,CA2DzB;;IACA,OAAOA,QAAQ,CAAC,WAAD,CAAf;IACAP,IAAI,CAACQ,IAAL,mBAAeD,QAAf;EACH;;EAED,OAAOP,IAAP;AACH,CAnFM"}
package/index.js CHANGED
@@ -60,8 +60,7 @@ const createStorageOperations = params => {
60
60
  esTable,
61
61
  documentClient,
62
62
  elasticsearch,
63
- plugins: userPlugins,
64
- modelFieldToGraphQLPlugins
63
+ plugins: userPlugins
65
64
  } = params;
66
65
  const tableInstance = (0, _table.createTable)({
67
66
  table,
@@ -111,7 +110,7 @@ const createStorageOperations = params => {
111
110
  /**
112
111
  * Plugins of type CmsModelFieldToGraphQLPlugin.
113
112
  */
114
- modelFieldToGraphQLPlugins,
113
+
115
114
  /**
116
115
  * Elasticsearch field definitions for the entry record.
117
116
  */
@@ -138,12 +137,16 @@ const createStorageOperations = params => {
138
137
  (0, _indices.elasticsearchIndexPlugins)()]);
139
138
  return {
140
139
  beforeInit: async context => {
141
- context.plugins.register([
142
140
  /**
143
- * Field plugins for DynamoDB.
144
- * We must pass them to the base application.
141
+ * Collect all required plugins from parent context.
142
+ */
143
+ const fieldPlugins = context.plugins.byType("cms-model-field-to-graphql");
144
+ plugins.register(fieldPlugins);
145
+ /**
146
+ * Pass the plugins to the parent context.
145
147
  */
146
- (0, _dynamoDb.default)()]);
148
+
149
+ context.plugins.register([(0, _dynamoDb.default)()]);
147
150
  },
148
151
  init: async context => {
149
152
  /**
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","modelFieldToGraphQLPlugins","tableInstance","createTable","tableElasticsearchInstance","createElasticsearchTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","entriesEs","createEntryElasticsearchEntity","ENTRIES_ES","PluginsContainer","cmsEntryElasticsearchFields","dynamoDbValueFilters","getElasticsearchOperators","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","beforeInit","context","register","init","cms","onBeforeModelCreate","subscribe","model","createElasticsearchIndex","onBeforeModelCreateFrom","onAfterModelDelete","deleteElasticsearchIndex","getEntities","getTable","getEsTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations","esEntity"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport { getElasticsearchOperators } from \"@webiny/api-elasticsearch/operators\";\nimport { elasticsearchFields as cmsEntryElasticsearchFields } from \"~/operations/entry/elasticsearchFields\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins,\n modelFieldToGraphQLPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\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 entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * User defined custom plugins.\n */\n ...(userPlugins || []),\n /**\n * Plugins of type CmsModelFieldToGraphQLPlugin.\n */\n modelFieldToGraphQLPlugins,\n /**\n * Elasticsearch field definitions for the entry record.\n */\n cmsEntryElasticsearchFields,\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins()\n ]);\n\n return {\n beforeInit: async context => {\n context.plugins.register([\n /**\n * Field plugins for DynamoDB.\n * We must pass them to the base application.\n */\n dynamoDbPlugins()\n ]);\n },\n init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onBeforeModelCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onBeforeModelCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onAfterModelDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\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 elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;EACvE,MAAM;IACFC,UADE;IAEFC,KAFE;IAGFC,OAHE;IAIFC,cAJE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AAO;QAAEC;MAAF,CAAP,KAAqB;QAC/D,MAAM,IAAAC,kDAAA,EAAyB;UAC3B5C,aAD2B;UAE3B2C,KAF2B;UAG3B1C;QAH2B,CAAzB,CAAN;MAKH,CAND;MAOAoC,OAAO,CAACG,GAAR,CAAYM,kBAAZ,CAA+BJ,SAA/B,CAAyC,OAAO;QAAEC;MAAF,CAAP,KAAqB;QAC1D,MAAM,IAAAI,kDAAA,EAAyB;UAC3B/C,aAD2B;UAE3B2C;QAF2B,CAAzB,CAAN;MAIH,CALD;IAMH,CAnCE;IAoCHK,WAAW,EAAE,MAAMxC,QApChB;IAqCHyC,QAAQ,EAAE,MAAM7C,aArCb;IAsCH8C,UAAU,EAAE,MAAM5C,0BAtCf;IAuCHQ,MAAM,EAAE,IAAAqC,qCAAA,EAA8B;MAClCC,MAAM,EAAE5C,QAAQ,CAACM;IADiB,CAA9B,CAvCL;IA0CHL,QAAQ,EAAE,IAAA4C,yCAAA,EAAgC;MACtCD,MAAM,EAAE5C,QAAQ,CAACC;IADqB,CAAhC,CA1CP;IA6CHQ,MAAM,EAAE,IAAAqC,qCAAA,EAA8B;MAClCF,MAAM,EAAE5C,QAAQ,CAACS,MADiB;MAElChB;IAFkC,CAA9B,CA7CL;IAiDHmB,MAAM,EAAE,IAAAmC,oCAAA,EAA8B;MAClCH,MAAM,EAAE5C,QAAQ,CAACY,MADiB;MAElCpB;IAFkC,CAA9B,CAjDL;IAqDHuB,OAAO,EAAE,IAAAiC,qCAAA,EAA+B;MACpCJ,MAAM,EAAE5C,QAAQ,CAACe,OADmB;MAEpCkC,QAAQ,EAAEjD,QAAQ,CAACkB,SAFiB;MAGpCzB,OAHoC;MAIpCD;IAJoC,CAA/B;EArDN,CAAP;AA4DH,CApJM"}
1
+ {"version":3,"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","tableInstance","createTable","tableElasticsearchInstance","createElasticsearchTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","entriesEs","createEntryElasticsearchEntity","ENTRIES_ES","PluginsContainer","cmsEntryElasticsearchFields","dynamoDbValueFilters","getElasticsearchOperators","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","beforeInit","context","fieldPlugins","byType","register","init","cms","onBeforeModelCreate","subscribe","model","createElasticsearchIndex","onBeforeModelCreateFrom","onAfterModelDelete","deleteElasticsearchIndex","getEntities","getTable","getEsTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations","esEntity"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport { getElasticsearchOperators } from \"@webiny/api-elasticsearch/operators\";\nimport { elasticsearchFields as cmsEntryElasticsearchFields } from \"~/operations/entry/elasticsearchFields\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\nimport { CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\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 entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * User defined custom plugins.\n */\n ...(userPlugins || []),\n /**\n * Plugins of type CmsModelFieldToGraphQLPlugin.\n */\n /**\n * Elasticsearch field definitions for the entry record.\n */\n cmsEntryElasticsearchFields,\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins()\n ]);\n\n return {\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 init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onBeforeModelCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onBeforeModelCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onAfterModelDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\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 elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;EACvE,MAAM;IACFC,UADE;IAEFC,KAFE;IAGFC,OAHE;IAIFC,cAJE;IAKFC,aALE;IAMFC,OAAO,EAAEC;EANP,IAOFP,MAPJ;EASA,MAAMQ,aAAa,GAAG,IAAAC,kBA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"main": "index.js",
5
5
  "keywords": [
6
6
  "@webiny/api-headless-cms",
@@ -22,16 +22,16 @@
22
22
  ],
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
- "@babel/runtime": "7.18.3",
26
- "@webiny/api-elasticsearch": "5.29.0",
27
- "@webiny/api-headless-cms": "5.29.0",
28
- "@webiny/db-dynamodb": "5.29.0",
29
- "@webiny/error": "5.29.0",
30
- "@webiny/handler": "5.29.0",
31
- "@webiny/handler-aws": "5.29.0",
32
- "@webiny/handler-db": "5.29.0",
33
- "@webiny/plugins": "5.29.0",
34
- "@webiny/utils": "5.29.0",
25
+ "@babel/runtime": "7.18.6",
26
+ "@webiny/api-elasticsearch": "5.30.0",
27
+ "@webiny/api-headless-cms": "5.30.0",
28
+ "@webiny/db-dynamodb": "5.30.0",
29
+ "@webiny/error": "5.30.0",
30
+ "@webiny/handler": "5.30.0",
31
+ "@webiny/handler-aws": "5.30.0",
32
+ "@webiny/handler-db": "5.30.0",
33
+ "@webiny/plugins": "5.30.0",
34
+ "@webiny/utils": "5.30.0",
35
35
  "dataloader": "2.1.0",
36
36
  "dynamodb-toolbox": "0.3.5",
37
37
  "jsonpack": "1.1.5",
@@ -44,10 +44,10 @@
44
44
  "@babel/preset-flow": "^7.16.0",
45
45
  "@elastic/elasticsearch": "7.12.0",
46
46
  "@types/jsonpack": "^1.1.0",
47
- "@webiny/api-dynamodb-to-elasticsearch": "^5.29.0",
48
- "@webiny/cli": "^5.29.0",
49
- "@webiny/project-utils": "^5.29.0",
50
- "jest": "^26.6.3",
47
+ "@webiny/api-dynamodb-to-elasticsearch": "^5.30.0",
48
+ "@webiny/cli": "^5.30.0",
49
+ "@webiny/project-utils": "^5.30.0",
50
+ "jest": "^28.1.0",
51
51
  "jest-dynalite": "^3.2.0",
52
52
  "jest-environment-node": "^26.6.2",
53
53
  "mdbid": "^1.0.0",
@@ -55,7 +55,7 @@
55
55
  "rimraf": "^3.0.2",
56
56
  "sinon": "^9.0.2",
57
57
  "ttypescript": "^1.5.12",
58
- "typescript": "4.5.5"
58
+ "typescript": "4.7.4"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",
@@ -65,5 +65,5 @@
65
65
  "build": "yarn webiny run build",
66
66
  "watch": "yarn webiny run watch"
67
67
  },
68
- "gitHead": "8cf3d623d56105ad5a4bacbcb4140959e11477e6"
68
+ "gitHead": "3cadc5d26e565586b28772afbc18ae554ce7b782"
69
69
  }
package/types.d.ts CHANGED
@@ -147,7 +147,6 @@ export interface StorageOperationsFactoryParams {
147
147
  elasticsearch: Client;
148
148
  table?: TableModifier;
149
149
  esTable?: TableModifier;
150
- modelFieldToGraphQLPlugins: CmsModelFieldToGraphQLPlugin[];
151
150
  attributes?: Record<ENTITIES, Attributes>;
152
151
  plugins?: PluginCollection;
153
152
  }
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["ENTITIES"],"sources":["types.ts"],"sourcesContent":["import { Plugin, PluginCollection } from \"@webiny/plugins/types\";\nimport {\n CmsEntry,\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n HeadlessCmsStorageOperations as BaseHeadlessCmsStorageOperations\n} from \"@webiny/api-headless-cms/types\";\nimport { DynamoDBTypes, TableConstructor } from \"dynamodb-toolbox/dist/classes/Table\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport {\n EntityAttributeConfig,\n EntityCompositeAttributes\n} from \"dynamodb-toolbox/dist/classes/Entity\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * A definition of the entry that is being prepared for the Elasticsearch.\n *\n * @category Elasticsearch\n * @category CmsEntry\n */\nexport interface CmsIndexEntry extends CmsEntry {\n /**\n * Values that are not going to be indexed.\n */\n rawValues: Record<string, any>;\n /**\n * A first part of the ID, without the revision.\n * For example, we can search for all the revisions of the given entry.\n */\n primaryId: string;\n /**\n * Dev can add what ever keys they want and need. Just need to be careful not to break the entry.\n */\n [key: string]: any;\n}\n\n/**\n * Arguments for the method that is transforming content entry in its original form to the one we are storing to the Elasticsearch.\n *\n * @category Elasticsearch\n * @category CmsEntry\n */\ninterface CmsModelFieldToElasticsearchToParams {\n plugins: PluginsContainer;\n model: CmsModel;\n field: CmsModelField;\n /**\n * Raw value on the entry - before prepare for storage.\n */\n rawValue: any;\n /**\n * Value prepared for storage received from base api-headless-cms package.\n */\n value: any;\n getFieldIndexPlugin(fieldType: string): CmsModelFieldToElasticsearchPlugin;\n getFieldTypePlugin(fieldType: string): CmsModelFieldToGraphQLPlugin;\n}\n\n/**\n * Arguments for the method that is transforming content entry from Elasticsearch into the original one.\n *\n * @category Elasticsearch\n * @category CmsEntry\n */\ninterface CmsModelFieldToElasticsearchFromParams {\n plugins: PluginsContainer;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n rawValue: any;\n getFieldIndexPlugin(fieldType: string): CmsModelFieldToElasticsearchPlugin;\n getFieldTypePlugin(fieldType: string): CmsModelFieldToGraphQLPlugin;\n}\n\ninterface ToIndexValue {\n /**\n * Use this key to store value for indexing.\n */\n value?: any;\n /**\n * Use this key to tell ES that this value should not be indexed.\n */\n rawValue?: any;\n}\n\n/**\n * A plugin defining transformation of entry for Elasticsearch.\n *\n * @category Plugin\n * @category ContentModelField\n * @category CmsEntry\n * @category Elasticsearch\n */\nexport interface CmsModelFieldToElasticsearchPlugin extends Plugin {\n /**\n * A plugin type\n */\n type: \"cms-model-field-to-elastic-search\";\n /**\n * A unique identifier of the field type (text, number, json, myField, ...).\n *\n * ```ts\n * fieldType: \"myField\"\n * ```\n */\n fieldType: string;\n /**\n * If you need to define a type when building an Elasticsearch query.\n * Check [dateTimeIndexing](https://github.com/webiny/webiny-js/blob/3074165701b8b45e5fc6ac2444caace7d04ada66/packages/api-headless-cms/src/content/plugins/es/indexing/dateTimeIndexing.ts) plugin for usage example.\n *\n * ```ts\n * unmappedType: \"date\"\n * ```\n */\n unmappedType?: (field: CmsModelField) => string;\n /**\n * This is meant to do some transformation of the entry, preferably only to fieldType it was defined for. Nothing is stopping you to do anything you want to other fields, but try to separate field transformations.\n * It returns `Partial<CmsContentIndexEntryType>`. Always return a top-level property of the entry since it is merged via spread operator.\n *\n * ```ts\n * toIndex({ value }) {\n * return {\n * value: value, // This will be stored and indexed\n * rawValue: JSON.stringify(value) // This will be stored but excluded from indexing\n * };\n * }\n * ```\n */\n toIndex?: (params: CmsModelFieldToElasticsearchToParams) => ToIndexValue;\n /**\n * This is meant to revert a transformation done in the `toIndex` method.\n * You have access to \"value\" or a \"rawValue\", depending on what you returned from `toIndex`.\n *\n * ```ts\n * fromIndex({ value, rawValue }) {\n * return JSON.parse(rawValue);\n * }\n * ```\n */\n fromIndex?: (params: CmsModelFieldToElasticsearchFromParams) => any;\n}\n\nexport type AttributeDefinition = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;\n\nexport type Attributes = Record<string, AttributeDefinition>;\n\nexport enum ENTITIES {\n SYSTEM = \"CmsSystem\",\n SETTINGS = \"CmsSettings\",\n GROUPS = \"CmsGroups\",\n MODELS = \"CmsModels\",\n ENTRIES = \"CmsEntries\",\n ENTRIES_ES = \"CmsEntriesElasticsearch\"\n}\n\nexport interface TableModifier {\n (table: TableConstructor): TableConstructor;\n}\n\nexport interface StorageOperationsFactoryParams {\n documentClient: DocumentClient;\n elasticsearch: Client;\n table?: TableModifier;\n esTable?: TableModifier;\n modelFieldToGraphQLPlugins: CmsModelFieldToGraphQLPlugin[];\n attributes?: Record<ENTITIES, Attributes>;\n plugins?: PluginCollection;\n}\n\nexport interface HeadlessCmsStorageOperations extends BaseHeadlessCmsStorageOperations {\n getTable: () => Table;\n getEsTable: () => Table;\n getEntities: () => Record<\n \"system\" | \"settings\" | \"groups\" | \"models\" | \"entries\" | \"entriesEs\",\n Entity<any>\n >;\n}\n\nexport interface StorageOperationsFactory {\n (params: StorageOperationsFactoryParams): HeadlessCmsStorageOperations;\n}\n"],"mappings":";;;;;;;AAkBA;AACA;AACA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;AACA;AACA;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IAsDYA,Q;;;WAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;GAAAA,Q,wBAAAA,Q"}
1
+ {"version":3,"names":["ENTITIES"],"sources":["types.ts"],"sourcesContent":["import { Plugin, PluginCollection } from \"@webiny/plugins/types\";\nimport {\n CmsEntry,\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n HeadlessCmsStorageOperations as BaseHeadlessCmsStorageOperations\n} from \"@webiny/api-headless-cms/types\";\nimport { DynamoDBTypes, TableConstructor } from \"dynamodb-toolbox/dist/classes/Table\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport {\n EntityAttributeConfig,\n EntityCompositeAttributes\n} from \"dynamodb-toolbox/dist/classes/Entity\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * A definition of the entry that is being prepared for the Elasticsearch.\n *\n * @category Elasticsearch\n * @category CmsEntry\n */\nexport interface CmsIndexEntry extends CmsEntry {\n /**\n * Values that are not going to be indexed.\n */\n rawValues: Record<string, any>;\n /**\n * A first part of the ID, without the revision.\n * For example, we can search for all the revisions of the given entry.\n */\n primaryId: string;\n /**\n * Dev can add what ever keys they want and need. Just need to be careful not to break the entry.\n */\n [key: string]: any;\n}\n\n/**\n * Arguments for the method that is transforming content entry in its original form to the one we are storing to the Elasticsearch.\n *\n * @category Elasticsearch\n * @category CmsEntry\n */\ninterface CmsModelFieldToElasticsearchToParams {\n plugins: PluginsContainer;\n model: CmsModel;\n field: CmsModelField;\n /**\n * Raw value on the entry - before prepare for storage.\n */\n rawValue: any;\n /**\n * Value prepared for storage received from base api-headless-cms package.\n */\n value: any;\n getFieldIndexPlugin(fieldType: string): CmsModelFieldToElasticsearchPlugin;\n getFieldTypePlugin(fieldType: string): CmsModelFieldToGraphQLPlugin;\n}\n\n/**\n * Arguments for the method that is transforming content entry from Elasticsearch into the original one.\n *\n * @category Elasticsearch\n * @category CmsEntry\n */\ninterface CmsModelFieldToElasticsearchFromParams {\n plugins: PluginsContainer;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n rawValue: any;\n getFieldIndexPlugin(fieldType: string): CmsModelFieldToElasticsearchPlugin;\n getFieldTypePlugin(fieldType: string): CmsModelFieldToGraphQLPlugin;\n}\n\ninterface ToIndexValue {\n /**\n * Use this key to store value for indexing.\n */\n value?: any;\n /**\n * Use this key to tell ES that this value should not be indexed.\n */\n rawValue?: any;\n}\n\n/**\n * A plugin defining transformation of entry for Elasticsearch.\n *\n * @category Plugin\n * @category ContentModelField\n * @category CmsEntry\n * @category Elasticsearch\n */\nexport interface CmsModelFieldToElasticsearchPlugin extends Plugin {\n /**\n * A plugin type\n */\n type: \"cms-model-field-to-elastic-search\";\n /**\n * A unique identifier of the field type (text, number, json, myField, ...).\n *\n * ```ts\n * fieldType: \"myField\"\n * ```\n */\n fieldType: string;\n /**\n * If you need to define a type when building an Elasticsearch query.\n * Check [dateTimeIndexing](https://github.com/webiny/webiny-js/blob/3074165701b8b45e5fc6ac2444caace7d04ada66/packages/api-headless-cms/src/content/plugins/es/indexing/dateTimeIndexing.ts) plugin for usage example.\n *\n * ```ts\n * unmappedType: \"date\"\n * ```\n */\n unmappedType?: (field: CmsModelField) => string;\n /**\n * This is meant to do some transformation of the entry, preferably only to fieldType it was defined for. Nothing is stopping you to do anything you want to other fields, but try to separate field transformations.\n * It returns `Partial<CmsContentIndexEntryType>`. Always return a top-level property of the entry since it is merged via spread operator.\n *\n * ```ts\n * toIndex({ value }) {\n * return {\n * value: value, // This will be stored and indexed\n * rawValue: JSON.stringify(value) // This will be stored but excluded from indexing\n * };\n * }\n * ```\n */\n toIndex?: (params: CmsModelFieldToElasticsearchToParams) => ToIndexValue;\n /**\n * This is meant to revert a transformation done in the `toIndex` method.\n * You have access to \"value\" or a \"rawValue\", depending on what you returned from `toIndex`.\n *\n * ```ts\n * fromIndex({ value, rawValue }) {\n * return JSON.parse(rawValue);\n * }\n * ```\n */\n fromIndex?: (params: CmsModelFieldToElasticsearchFromParams) => any;\n}\n\nexport type AttributeDefinition = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;\n\nexport type Attributes = Record<string, AttributeDefinition>;\n\nexport enum ENTITIES {\n SYSTEM = \"CmsSystem\",\n SETTINGS = \"CmsSettings\",\n GROUPS = \"CmsGroups\",\n MODELS = \"CmsModels\",\n ENTRIES = \"CmsEntries\",\n ENTRIES_ES = \"CmsEntriesElasticsearch\"\n}\n\nexport interface TableModifier {\n (table: TableConstructor): TableConstructor;\n}\n\nexport interface StorageOperationsFactoryParams {\n documentClient: DocumentClient;\n elasticsearch: Client;\n table?: TableModifier;\n esTable?: TableModifier;\n attributes?: Record<ENTITIES, Attributes>;\n plugins?: PluginCollection;\n}\n\nexport interface HeadlessCmsStorageOperations extends BaseHeadlessCmsStorageOperations {\n getTable: () => Table;\n getEsTable: () => Table;\n getEntities: () => Record<\n \"system\" | \"settings\" | \"groups\" | \"models\" | \"entries\" | \"entriesEs\",\n Entity<any>\n >;\n}\n\nexport interface StorageOperationsFactory {\n (params: StorageOperationsFactoryParams): HeadlessCmsStorageOperations;\n}\n"],"mappings":";;;;;;;AAkBA;AACA;AACA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;AACA;AACA;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IAsDYA,Q;;;WAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;GAAAA,Q,wBAAAA,Q"}