@webiny/api-headless-cms 6.4.4-beta.2 → 6.4.4-beta.4

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.
@@ -1,26 +1,48 @@
1
+ const FORBIDDEN_KEYS = new Set([
2
+ "__proto__",
3
+ "prototype",
4
+ "constructor"
5
+ ]);
1
6
  const transformWhereToNested = (where)=>{
2
7
  if (!where) return;
3
- const result = {};
4
- for (const [key, value] of Object.entries(where)){
8
+ return Object.entries(where).reduce((result, [key, value])=>{
5
9
  if ("AND" === key || "OR" === key) {
6
- if (Array.isArray(value)) result[key] = value.map((item)=>transformWhereToNested(item));
7
- else result[key] = value;
8
- continue;
10
+ if (!Array.isArray(value)) return {
11
+ ...result,
12
+ [key]: value
13
+ };
14
+ return {
15
+ ...result,
16
+ [key]: value.map((item)=>transformWhereToNested(item))
17
+ };
9
18
  }
10
19
  const dotIndex = key.indexOf(".");
11
- if (-1 === dotIndex) result[key] = value;
12
- else {
13
- const head = key.slice(0, dotIndex);
14
- const tail = key.slice(dotIndex + 1);
15
- if (void 0 === result[head]) result[head] = {};
16
- const nested = result[head];
17
- const expanded = transformWhereToNested({
18
- [tail]: value
19
- });
20
- Object.assign(nested, expanded);
20
+ if (-1 === dotIndex) {
21
+ if (FORBIDDEN_KEYS.has(key)) throw new Error(`Invalid where key: "${key}".`);
22
+ return {
23
+ ...result,
24
+ [key]: value
25
+ };
21
26
  }
22
- }
23
- return result;
27
+ const head = key.slice(0, dotIndex);
28
+ const tail = key.slice(dotIndex + 1);
29
+ if (FORBIDDEN_KEYS.has(head)) throw new Error(`Invalid where key: "${head}".`);
30
+ if (Object.hasOwn(result, head)) return {
31
+ ...result,
32
+ [head]: {
33
+ ...result[head],
34
+ ...transformWhereToNested({
35
+ [tail]: value
36
+ })
37
+ }
38
+ };
39
+ return {
40
+ ...result,
41
+ [head]: transformWhereToNested({
42
+ [tail]: value
43
+ })
44
+ };
45
+ }, {});
24
46
  };
25
47
  export { transformWhereToNested };
26
48
 
@@ -1 +1 @@
1
- {"version":3,"file":"graphql/schema/cms/helpers/transformWhereToNested.js","sources":["../../../../../src/graphql/schema/cms/helpers/transformWhereToNested.ts"],"sourcesContent":["/**\n * Transforms a flat where object with dot-notation keys into a nested object.\n * Keys without dots are passed through unchanged.\n * Handles logical operators (AND, OR) recursively.\n *\n * @param where - Where clause object potentially containing dot-notation keys\n * @returns Nested where object compatible with the GraphQL ListWhereInput type\n *\n * @example\n * transformWhereToNested({ \"values.name\": \"Keyboard\", id: \"abc\" })\n * // Returns: { values: { name: \"Keyboard\" }, id: \"abc\" }\n *\n * @example\n * transformWhereToNested({ \"values.price_gt\": 100, \"values.name_contains\": \"board\" })\n * // Returns: { values: { price_gt: 100, name_contains: \"board\" } }\n */\nexport const transformWhereToNested = (\n where?: Record<string, unknown>\n): Record<string, unknown> | undefined => {\n if (!where) {\n return undefined;\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(where)) {\n // Handle logical operators recursively.\n if (key === \"AND\" || key === \"OR\") {\n if (Array.isArray(value)) {\n result[key] = value.map(item =>\n transformWhereToNested(item as Record<string, unknown>)\n );\n } else {\n result[key] = value;\n }\n continue;\n }\n\n const dotIndex = key.indexOf(\".\");\n if (dotIndex === -1) {\n // No dot pass through unchanged.\n result[key] = value;\n } else {\n // Dot-notation key — expand into nested object.\n const head = key.slice(0, dotIndex);\n const tail = key.slice(dotIndex + 1);\n\n if (result[head] === undefined) {\n result[head] = {};\n }\n\n const nested = result[head] as Record<string, unknown>;\n // Recursively expand in case of multiple levels of nesting.\n const expanded = transformWhereToNested({ [tail]: value }) as Record<string, unknown>;\n Object.assign(nested, expanded);\n }\n }\n\n return result;\n};\n"],"names":["transformWhereToNested","where","result","key","value","Object","Array","item","dotIndex","head","tail","undefined","nested","expanded"],"mappings":"AAgBO,MAAMA,yBAAyB,CAClCC;IAEA,IAAI,CAACA,OACD;IAGJ,MAAMC,SAAkC,CAAC;IAEzC,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAO,OAAO,CAACJ,OAAQ;QAE9C,IAAIE,AAAQ,UAARA,OAAiBA,AAAQ,SAARA,KAAc;YAC/B,IAAIG,MAAM,OAAO,CAACF,QACdF,MAAM,CAACC,IAAI,GAAGC,MAAM,GAAG,CAACG,CAAAA,OACpBP,uBAAuBO;iBAG3BL,MAAM,CAACC,IAAI,GAAGC;YAElB;QACJ;QAEA,MAAMI,WAAWL,IAAI,OAAO,CAAC;QAC7B,IAAIK,AAAa,OAAbA,UAEAN,MAAM,CAACC,IAAI,GAAGC;aACX;YAEH,MAAMK,OAAON,IAAI,KAAK,CAAC,GAAGK;YAC1B,MAAME,OAAOP,IAAI,KAAK,CAACK,WAAW;YAElC,IAAIN,AAAiBS,WAAjBT,MAAM,CAACO,KAAK,EACZP,MAAM,CAACO,KAAK,GAAG,CAAC;YAGpB,MAAMG,SAASV,MAAM,CAACO,KAAK;YAE3B,MAAMI,WAAWb,uBAAuB;gBAAE,CAACU,KAAK,EAAEN;YAAM;YACxDC,OAAO,MAAM,CAACO,QAAQC;QAC1B;IACJ;IAEA,OAAOX;AACX"}
1
+ {"version":3,"file":"graphql/schema/cms/helpers/transformWhereToNested.js","sources":["../../../../../src/graphql/schema/cms/helpers/transformWhereToNested.ts"],"sourcesContent":["const FORBIDDEN_KEYS = new Set([\"__proto__\", \"prototype\", \"constructor\"]);\n\n/**\n * Transforms a flat where object with dot-notation keys into a nested object.\n * Keys without dots are passed through unchanged.\n * Handles logical operators (AND, OR) recursively.\n *\n * @param where - Where clause object potentially containing dot-notation keys\n * @returns Nested where object compatible with the GraphQL ListWhereInput type\n *\n * @example\n * transformWhereToNested({ \"values.name\": \"Keyboard\", id: \"abc\" })\n * // Returns: { values: { name: \"Keyboard\" }, id: \"abc\" }\n *\n * @example\n * transformWhereToNested({ \"values.price_gt\": 100, \"values.name_contains\": \"board\" })\n * // Returns: { values: { price_gt: 100, name_contains: \"board\" } }\n */\nexport const transformWhereToNested = (\n where?: Record<string, unknown>\n): Record<string, unknown> | undefined => {\n if (!where) {\n return undefined;\n }\n\n return Object.entries(where).reduce<Record<string, unknown>>((result, [key, value]) => {\n if (key === \"AND\" || key === \"OR\") {\n if (!Array.isArray(value)) {\n return {\n ...result,\n [key]: value\n };\n }\n return {\n ...result,\n [key]: value.map(item => transformWhereToNested(item))\n };\n }\n\n const dotIndex = key.indexOf(\".\");\n\n if (dotIndex === -1) {\n if (FORBIDDEN_KEYS.has(key)) {\n throw new Error(`Invalid where key: \"${key}\".`);\n }\n return {\n ...result,\n [key]: value\n };\n }\n\n const head = key.slice(0, dotIndex);\n const tail = key.slice(dotIndex + 1);\n\n if (FORBIDDEN_KEYS.has(head)) {\n throw new Error(`Invalid where key: \"${head}\".`);\n }\n\n if (Object.hasOwn(result, head)) {\n return {\n ...result,\n [head]: {\n ...(result[head] as Record<string, unknown>),\n ...transformWhereToNested({ [tail]: value })\n }\n };\n }\n\n return {\n ...result,\n [head]: transformWhereToNested({ [tail]: value })\n };\n }, {});\n};\n"],"names":["FORBIDDEN_KEYS","Set","transformWhereToNested","where","Object","result","key","value","Array","item","dotIndex","Error","head","tail"],"mappings":"AAAA,MAAMA,iBAAiB,IAAIC,IAAI;IAAC;IAAa;IAAa;CAAc;AAkBjE,MAAMC,yBAAyB,CAClCC;IAEA,IAAI,CAACA,OACD;IAGJ,OAAOC,OAAO,OAAO,CAACD,OAAO,MAAM,CAA0B,CAACE,QAAQ,CAACC,KAAKC,MAAM;QAC9E,IAAID,AAAQ,UAARA,OAAiBA,AAAQ,SAARA,KAAc;YAC/B,IAAI,CAACE,MAAM,OAAO,CAACD,QACf,OAAO;gBACH,GAAGF,MAAM;gBACT,CAACC,IAAI,EAAEC;YACX;YAEJ,OAAO;gBACH,GAAGF,MAAM;gBACT,CAACC,IAAI,EAAEC,MAAM,GAAG,CAACE,CAAAA,OAAQP,uBAAuBO;YACpD;QACJ;QAEA,MAAMC,WAAWJ,IAAI,OAAO,CAAC;QAE7B,IAAII,AAAa,OAAbA,UAAiB;YACjB,IAAIV,eAAe,GAAG,CAACM,MACnB,MAAM,IAAIK,MAAM,CAAC,oBAAoB,EAAEL,IAAI,EAAE,CAAC;YAElD,OAAO;gBACH,GAAGD,MAAM;gBACT,CAACC,IAAI,EAAEC;YACX;QACJ;QAEA,MAAMK,OAAON,IAAI,KAAK,CAAC,GAAGI;QAC1B,MAAMG,OAAOP,IAAI,KAAK,CAACI,WAAW;QAElC,IAAIV,eAAe,GAAG,CAACY,OACnB,MAAM,IAAID,MAAM,CAAC,oBAAoB,EAAEC,KAAK,EAAE,CAAC;QAGnD,IAAIR,OAAO,MAAM,CAACC,QAAQO,OACtB,OAAO;YACH,GAAGP,MAAM;YACT,CAACO,KAAK,EAAE;gBACJ,GAAIP,MAAM,CAACO,KAAK;gBAChB,GAAGV,uBAAuB;oBAAE,CAACW,KAAK,EAAEN;gBAAM,EAAE;YAChD;QACJ;QAGJ,OAAO;YACH,GAAGF,MAAM;YACT,CAACO,KAAK,EAAEV,uBAAuB;gBAAE,CAACW,KAAK,EAAEN;YAAM;QACnD;IACJ,GAAG,CAAC;AACR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms",
3
- "version": "6.4.4-beta.2",
3
+ "version": "6.4.4-beta.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -25,19 +25,19 @@
25
25
  "@babel/code-frame": "7.29.7",
26
26
  "@graphql-tools/merge": "9.1.9",
27
27
  "@graphql-tools/schema": "10.0.33",
28
- "@webiny/api": "6.4.4-beta.2",
29
- "@webiny/api-core": "6.4.4-beta.2",
28
+ "@webiny/api": "6.4.4-beta.4",
29
+ "@webiny/api-core": "6.4.4-beta.4",
30
30
  "@webiny/di": "1.0.1",
31
- "@webiny/error": "6.4.4-beta.2",
32
- "@webiny/feature": "6.4.4-beta.2",
33
- "@webiny/handler": "6.4.4-beta.2",
34
- "@webiny/handler-aws": "6.4.4-beta.2",
35
- "@webiny/handler-db": "6.4.4-beta.2",
36
- "@webiny/handler-graphql": "6.4.4-beta.2",
37
- "@webiny/plugins": "6.4.4-beta.2",
38
- "@webiny/project": "6.4.4-beta.2",
39
- "@webiny/utils": "6.4.4-beta.2",
40
- "@webiny/validation": "6.4.4-beta.2",
31
+ "@webiny/error": "6.4.4-beta.4",
32
+ "@webiny/feature": "6.4.4-beta.4",
33
+ "@webiny/handler": "6.4.4-beta.4",
34
+ "@webiny/handler-aws": "6.4.4-beta.4",
35
+ "@webiny/handler-db": "6.4.4-beta.4",
36
+ "@webiny/handler-graphql": "6.4.4-beta.4",
37
+ "@webiny/plugins": "6.4.4-beta.4",
38
+ "@webiny/project": "6.4.4-beta.4",
39
+ "@webiny/utils": "6.4.4-beta.4",
40
+ "@webiny/validation": "6.4.4-beta.4",
41
41
  "dot-prop-immutable": "2.1.1",
42
42
  "graphql": "16.14.2",
43
43
  "graphql-tag": "2.12.6",
@@ -51,13 +51,13 @@
51
51
  "devDependencies": {
52
52
  "@types/babel__code-frame": "7.27.0",
53
53
  "@types/pluralize": "0.0.33",
54
- "@webiny/aws-sdk": "6.4.4-beta.2",
55
- "@webiny/build-tools": "6.4.4-beta.2",
56
- "@webiny/db-dynamodb": "6.4.4-beta.2",
57
- "@webiny/handler-db": "6.4.4-beta.2",
58
- "@webiny/project-utils": "6.4.4-beta.2",
59
- "@webiny/sdk": "6.4.4-beta.2",
60
- "@webiny/wcp": "6.4.4-beta.2",
54
+ "@webiny/aws-sdk": "6.4.4-beta.4",
55
+ "@webiny/build-tools": "6.4.4-beta.4",
56
+ "@webiny/db-dynamodb": "6.4.4-beta.4",
57
+ "@webiny/handler-db": "6.4.4-beta.4",
58
+ "@webiny/project-utils": "6.4.4-beta.4",
59
+ "@webiny/sdk": "6.4.4-beta.4",
60
+ "@webiny/wcp": "6.4.4-beta.4",
61
61
  "apollo-graphql": "0.9.7",
62
62
  "graphql": "16.14.2",
63
63
  "oxfmt": "0.51.0",