moonflower 1.4.3 → 1.4.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,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),a=require("../utils/getValueAsNullableString.cjs");function c(e,r){try{const t=o(e,r),n=s(e,r),u=l(e,n);return{validated:t&&u,parsedValue:n,exception:null}}catch(t){return{validated:!1,parsedValue:null,exception:f(t)}}}function o(e,r){return"prevalidate"in e&&typeof e.prevalidate=="function"?e.prevalidate(a.getValueAsNullableString(r)):!0}function s(e,r){if(e instanceof i.ZodType){const t=(()=>{try{return typeof r=="string"?JSON.parse(r):r}catch{return r}})();return e.parse(t)}return e.parse(a.getValueAsNullableString(r))}function l(e,r){return"validate"in e&&typeof e.validate=="function"?e.validate(r):!0}function f(e){return e instanceof i.ZodError?i.treeifyError(e).errors.join("; ").replace("Invalid input: ",""):"Validation failed"}exports.validateParam=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("zod"),o=require("../utils/getValueAsNullableString.cjs");function c(r,e){try{const t=s(r,e),i=l(r,e),a=p(r,i);return{validated:t&&a,parsedValue:i,exception:null}}catch(t){return{validated:!1,parsedValue:null,exception:d(t)}}}function s(r,e){return"prevalidate"in r&&typeof r.prevalidate=="function"?r.prevalidate(o.getValueAsNullableString(e)):!0}function f(r){return r instanceof n.ZodArray?!0:r instanceof n.ZodOptional?r.unwrap()instanceof n.ZodArray:!1}function l(r,e){if(r instanceof n.ZodType){const t=f(r),i=(()=>{if(typeof e!="string")return e;try{const a=JSON.parse(e);return t&&!Array.isArray(a)?u(e):a}catch{return t?u(e):e}})();return r.parse(i)}return r.parse(o.getValueAsNullableString(e))}function u(r){return r.split(",").map(e=>{const t=e.trim();try{return JSON.parse(t)}catch{return t}})}function p(r,e){return"validate"in r&&typeof r.validate=="function"?r.validate(e):!0}function d(r){return r instanceof n.ZodError?n.treeifyError(r).errors.join("; ").replace("Invalid input: ",""):"Validation failed"}exports.validateParam=c;
2
2
  //# sourceMappingURL=validateParam.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateParam.cjs","sources":["../../src/validators/validateParam.ts"],"sourcesContent":["import z, { ZodError } from 'zod'\n\nimport { getValueAsNullableString } from '../utils/getValueAsNullableString'\nimport { ValidatorUnion } from './types'\n\nexport function validateParam(\n\tvalidator: ValidatorUnion,\n\tvalue: string | number | boolean | object | null,\n): {\n\tvalidated: boolean\n\tparsedValue: unknown\n\texception: string | null\n} {\n\ttry {\n\t\tconst prevalidatorSuccess = runPrevalidator(validator, value)\n\t\tconst parsedValue = runParser(validator, value)\n\t\tconst validatorSuccess = runValidator(validator, parsedValue)\n\n\t\treturn {\n\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\tparsedValue,\n\t\t\texception: null,\n\t\t}\n\t} catch (error) {\n\t\tconst exception = getErrorMessage(error)\n\t\treturn { validated: false, parsedValue: null, exception }\n\t}\n}\n\nfunction runPrevalidator(validator: ValidatorUnion, value: string | number | boolean | object | null) {\n\t// Legacy validator\n\tif ('prevalidate' in validator && typeof validator.prevalidate === 'function') {\n\t\treturn validator.prevalidate(getValueAsNullableString(value))\n\t}\n\t// Zod (skip)\n\treturn true\n}\n\nfunction runParser(validator: ValidatorUnion, value: string | number | boolean | object | null) {\n\t// Zod validator\n\tif (validator instanceof z.ZodType) {\n\t\tconst coercedValue = (() => {\n\t\t\ttry {\n\t\t\t\treturn typeof value === 'string' ? JSON.parse(value) : value\n\t\t\t} catch {\n\t\t\t\treturn value\n\t\t\t}\n\t\t})()\n\t\treturn validator.parse(coercedValue)\n\t}\n\t// Legacy validator\n\treturn validator.parse(getValueAsNullableString(value))\n}\n\nfunction runValidator(validator: ValidatorUnion, parsedValue: unknown) {\n\t// Legacy validator\n\tif ('validate' in validator && typeof validator.validate === 'function') {\n\t\treturn validator.validate(parsedValue)\n\t}\n\t// Zod (skip)\n\treturn true\n}\n\nfunction getErrorMessage(error: unknown) {\n\tif (error instanceof ZodError) {\n\t\treturn z.treeifyError(error).errors.join('; ').replace('Invalid input: ', '')\n\t}\n\treturn 'Validation failed'\n}\n"],"names":["validateParam","validator","value","prevalidatorSuccess","runPrevalidator","parsedValue","runParser","validatorSuccess","runValidator","error","getErrorMessage","getValueAsNullableString","z","coercedValue","ZodError"],"mappings":"0JAKgB,SAAAA,EACfC,EACAC,EAKC,CACG,GAAA,CACG,MAAAC,EAAsBC,EAAgBH,EAAWC,CAAK,EACtDG,EAAcC,EAAUL,EAAWC,CAAK,EACxCK,EAAmBC,EAAaP,EAAWI,CAAW,EAErD,MAAA,CACN,UAAWF,GAAuBI,EAClC,YAAAF,EACA,UAAW,IACZ,QACQI,EAAO,CAEf,MAAO,CAAE,UAAW,GAAO,YAAa,KAAM,UAD5BC,EAAgBD,CAAK,CACiB,CAAA,CAE1D,CAEA,SAASL,EAAgBH,EAA2BC,EAAkD,CAErG,MAAI,gBAAiBD,GAAa,OAAOA,EAAU,aAAgB,WAC3DA,EAAU,YAAYU,EAAyB,yBAAAT,CAAK,CAAC,EAGtD,EACR,CAEA,SAASI,EAAUL,EAA2BC,EAAkD,CAE3F,GAAAD,aAAqBW,EAAE,QAAS,CACnC,MAAMC,GAAgB,IAAM,CACvB,GAAA,CACH,OAAO,OAAOX,GAAU,SAAW,KAAK,MAAMA,CAAK,EAAIA,CAAA,MAChD,CACA,OAAAA,CAAA,CACR,GACE,EACI,OAAAD,EAAU,MAAMY,CAAY,CAAA,CAGpC,OAAOZ,EAAU,MAAMU,EAAyB,yBAAAT,CAAK,CAAC,CACvD,CAEA,SAASM,EAAaP,EAA2BI,EAAsB,CAEtE,MAAI,aAAcJ,GAAa,OAAOA,EAAU,UAAa,WACrDA,EAAU,SAASI,CAAW,EAG/B,EACR,CAEA,SAASK,EAAgBD,EAAgB,CACxC,OAAIA,aAAiBK,EAAAA,SACbF,EAAE,aAAaH,CAAK,EAAE,OAAO,KAAK,IAAI,EAAE,QAAQ,kBAAmB,EAAE,EAEtE,mBACR"}
1
+ {"version":3,"file":"validateParam.cjs","sources":["../../src/validators/validateParam.ts"],"sourcesContent":["import z, { ZodError } from 'zod'\n\nimport { getValueAsNullableString } from '../utils/getValueAsNullableString'\nimport { ValidatorUnion } from './types'\n\nexport function validateParam(\n\tvalidator: ValidatorUnion,\n\tvalue: string | number | boolean | object | null,\n): {\n\tvalidated: boolean\n\tparsedValue: unknown\n\texception: string | null\n} {\n\ttry {\n\t\tconst prevalidatorSuccess = runPrevalidator(validator, value)\n\t\tconst parsedValue = runParser(validator, value)\n\t\tconst validatorSuccess = runValidator(validator, parsedValue)\n\n\t\treturn {\n\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\tparsedValue,\n\t\t\texception: null,\n\t\t}\n\t} catch (error) {\n\t\tconst exception = getErrorMessage(error)\n\t\treturn { validated: false, parsedValue: null, exception }\n\t}\n}\n\nfunction runPrevalidator(validator: ValidatorUnion, value: string | number | boolean | object | null) {\n\t// Legacy validator\n\tif ('prevalidate' in validator && typeof validator.prevalidate === 'function') {\n\t\treturn validator.prevalidate(getValueAsNullableString(value))\n\t}\n\t// Zod (skip)\n\treturn true\n}\n\nfunction isZodArrayValidator(validator: z.ZodType): boolean {\n\tif (validator instanceof z.ZodArray) return true\n\tif (validator instanceof z.ZodOptional) return validator.unwrap() instanceof z.ZodArray\n\treturn false\n}\n\nfunction runParser(validator: ValidatorUnion, value: string | number | boolean | object | null) {\n\t// Zod validator\n\tif (validator instanceof z.ZodType) {\n\t\tconst isArrayValidator = isZodArrayValidator(validator)\n\t\tconst coercedValue = (() => {\n\t\t\tif (typeof value !== 'string') return value\n\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(value)\n\t\t\t\tif (isArrayValidator && !Array.isArray(parsed)) {\n\t\t\t\t\treturn coerceCommaSeparatedToArray(value)\n\t\t\t\t}\n\t\t\t\treturn parsed\n\t\t\t} catch {\n\t\t\t\tif (isArrayValidator) {\n\t\t\t\t\treturn coerceCommaSeparatedToArray(value)\n\t\t\t\t}\n\t\t\t\treturn value\n\t\t\t}\n\t\t})()\n\t\treturn validator.parse(coercedValue)\n\t}\n\t// Legacy validator\n\treturn validator.parse(getValueAsNullableString(value))\n}\n\nfunction coerceCommaSeparatedToArray(value: string): unknown[] {\n\treturn value.split(',').map((element) => {\n\t\tconst trimmed = element.trim()\n\t\ttry {\n\t\t\treturn JSON.parse(trimmed)\n\t\t} catch {\n\t\t\treturn trimmed\n\t\t}\n\t})\n}\n\nfunction runValidator(validator: ValidatorUnion, parsedValue: unknown) {\n\t// Legacy validator\n\tif ('validate' in validator && typeof validator.validate === 'function') {\n\t\treturn validator.validate(parsedValue)\n\t}\n\t// Zod (skip)\n\treturn true\n}\n\nfunction getErrorMessage(error: unknown) {\n\tif (error instanceof ZodError) {\n\t\treturn z.treeifyError(error).errors.join('; ').replace('Invalid input: ', '')\n\t}\n\treturn 'Validation failed'\n}\n"],"names":["validateParam","validator","value","prevalidatorSuccess","runPrevalidator","parsedValue","runParser","validatorSuccess","runValidator","error","getErrorMessage","getValueAsNullableString","isZodArrayValidator","z","isArrayValidator","coercedValue","parsed","coerceCommaSeparatedToArray","element","trimmed","ZodError"],"mappings":"0JAKgB,SAAAA,EACfC,EACAC,EAKC,CACG,GAAA,CACG,MAAAC,EAAsBC,EAAgBH,EAAWC,CAAK,EACtDG,EAAcC,EAAUL,EAAWC,CAAK,EACxCK,EAAmBC,EAAaP,EAAWI,CAAW,EAErD,MAAA,CACN,UAAWF,GAAuBI,EAClC,YAAAF,EACA,UAAW,IACZ,QACQI,EAAO,CAEf,MAAO,CAAE,UAAW,GAAO,YAAa,KAAM,UAD5BC,EAAgBD,CAAK,CACiB,CAAA,CAE1D,CAEA,SAASL,EAAgBH,EAA2BC,EAAkD,CAErG,MAAI,gBAAiBD,GAAa,OAAOA,EAAU,aAAgB,WAC3DA,EAAU,YAAYU,EAAyB,yBAAAT,CAAK,CAAC,EAGtD,EACR,CAEA,SAASU,EAAoBX,EAA+B,CACvD,OAAAA,aAAqBY,EAAE,SAAiB,GACxCZ,aAAqBY,EAAE,YAAoBZ,EAAU,OAAA,YAAoBY,EAAE,SACxE,EACR,CAEA,SAASP,EAAUL,EAA2BC,EAAkD,CAE3F,GAAAD,aAAqBY,EAAE,QAAS,CAC7B,MAAAC,EAAmBF,EAAoBX,CAAS,EAChDc,GAAgB,IAAM,CACvB,GAAA,OAAOb,GAAU,SAAiB,OAAAA,EAElC,GAAA,CACG,MAAAc,EAAS,KAAK,MAAMd,CAAK,EAC/B,OAAIY,GAAoB,CAAC,MAAM,QAAQE,CAAM,EACrCC,EAA4Bf,CAAK,EAElCc,CAAA,MACA,CACP,OAAIF,EACIG,EAA4Bf,CAAK,EAElCA,CAAA,CACR,GACE,EACI,OAAAD,EAAU,MAAMc,CAAY,CAAA,CAGpC,OAAOd,EAAU,MAAMU,EAAyB,yBAAAT,CAAK,CAAC,CACvD,CAEA,SAASe,EAA4Bf,EAA0B,CAC9D,OAAOA,EAAM,MAAM,GAAG,EAAE,IAAKgB,GAAY,CAClC,MAAAC,EAAUD,EAAQ,KAAK,EACzB,GAAA,CACI,OAAA,KAAK,MAAMC,CAAO,CAAA,MAClB,CACA,OAAAA,CAAA,CACR,CACA,CACF,CAEA,SAASX,EAAaP,EAA2BI,EAAsB,CAEtE,MAAI,aAAcJ,GAAa,OAAOA,EAAU,UAAa,WACrDA,EAAU,SAASI,CAAW,EAG/B,EACR,CAEA,SAASK,EAAgBD,EAAgB,CACxC,OAAIA,aAAiBW,EAAAA,SACbP,EAAE,aAAaJ,CAAK,EAAE,OAAO,KAAK,IAAI,EAAE,QAAQ,kBAAmB,EAAE,EAEtE,mBACR"}
@@ -1,40 +1,55 @@
1
1
  import i, { ZodError as u } from "zod";
2
- import { getValueAsNullableString as o } from "../utils/getValueAsNullableString.mjs";
3
- function y(e, r) {
2
+ import { getValueAsNullableString as c } from "../utils/getValueAsNullableString.mjs";
3
+ function A(r, e) {
4
4
  try {
5
- const t = c(e, r), n = s(e, r), a = f(e, n);
5
+ const t = s(r, e), n = p(r, e), a = d(r, n);
6
6
  return {
7
7
  validated: t && a,
8
8
  parsedValue: n,
9
9
  exception: null
10
10
  };
11
11
  } catch (t) {
12
- return { validated: !1, parsedValue: null, exception: p(t) };
12
+ return { validated: !1, parsedValue: null, exception: l(t) };
13
13
  }
14
14
  }
15
- function c(e, r) {
16
- return "prevalidate" in e && typeof e.prevalidate == "function" ? e.prevalidate(o(r)) : !0;
15
+ function s(r, e) {
16
+ return "prevalidate" in r && typeof r.prevalidate == "function" ? r.prevalidate(c(e)) : !0;
17
17
  }
18
- function s(e, r) {
19
- if (e instanceof i.ZodType) {
20
- const t = (() => {
18
+ function f(r) {
19
+ return r instanceof i.ZodArray ? !0 : r instanceof i.ZodOptional ? r.unwrap() instanceof i.ZodArray : !1;
20
+ }
21
+ function p(r, e) {
22
+ if (r instanceof i.ZodType) {
23
+ const t = f(r), n = (() => {
24
+ if (typeof e != "string") return e;
21
25
  try {
22
- return typeof r == "string" ? JSON.parse(r) : r;
26
+ const a = JSON.parse(e);
27
+ return t && !Array.isArray(a) ? o(e) : a;
23
28
  } catch {
24
- return r;
29
+ return t ? o(e) : e;
25
30
  }
26
31
  })();
27
- return e.parse(t);
32
+ return r.parse(n);
28
33
  }
29
- return e.parse(o(r));
34
+ return r.parse(c(e));
35
+ }
36
+ function o(r) {
37
+ return r.split(",").map((e) => {
38
+ const t = e.trim();
39
+ try {
40
+ return JSON.parse(t);
41
+ } catch {
42
+ return t;
43
+ }
44
+ });
30
45
  }
31
- function f(e, r) {
32
- return "validate" in e && typeof e.validate == "function" ? e.validate(r) : !0;
46
+ function d(r, e) {
47
+ return "validate" in r && typeof r.validate == "function" ? r.validate(e) : !0;
33
48
  }
34
- function p(e) {
35
- return e instanceof u ? i.treeifyError(e).errors.join("; ").replace("Invalid input: ", "") : "Validation failed";
49
+ function l(r) {
50
+ return r instanceof u ? i.treeifyError(r).errors.join("; ").replace("Invalid input: ", "") : "Validation failed";
36
51
  }
37
52
  export {
38
- y as validateParam
53
+ A as validateParam
39
54
  };
40
55
  //# sourceMappingURL=validateParam.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateParam.mjs","sources":["../../src/validators/validateParam.ts"],"sourcesContent":["import z, { ZodError } from 'zod'\n\nimport { getValueAsNullableString } from '../utils/getValueAsNullableString'\nimport { ValidatorUnion } from './types'\n\nexport function validateParam(\n\tvalidator: ValidatorUnion,\n\tvalue: string | number | boolean | object | null,\n): {\n\tvalidated: boolean\n\tparsedValue: unknown\n\texception: string | null\n} {\n\ttry {\n\t\tconst prevalidatorSuccess = runPrevalidator(validator, value)\n\t\tconst parsedValue = runParser(validator, value)\n\t\tconst validatorSuccess = runValidator(validator, parsedValue)\n\n\t\treturn {\n\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\tparsedValue,\n\t\t\texception: null,\n\t\t}\n\t} catch (error) {\n\t\tconst exception = getErrorMessage(error)\n\t\treturn { validated: false, parsedValue: null, exception }\n\t}\n}\n\nfunction runPrevalidator(validator: ValidatorUnion, value: string | number | boolean | object | null) {\n\t// Legacy validator\n\tif ('prevalidate' in validator && typeof validator.prevalidate === 'function') {\n\t\treturn validator.prevalidate(getValueAsNullableString(value))\n\t}\n\t// Zod (skip)\n\treturn true\n}\n\nfunction runParser(validator: ValidatorUnion, value: string | number | boolean | object | null) {\n\t// Zod validator\n\tif (validator instanceof z.ZodType) {\n\t\tconst coercedValue = (() => {\n\t\t\ttry {\n\t\t\t\treturn typeof value === 'string' ? JSON.parse(value) : value\n\t\t\t} catch {\n\t\t\t\treturn value\n\t\t\t}\n\t\t})()\n\t\treturn validator.parse(coercedValue)\n\t}\n\t// Legacy validator\n\treturn validator.parse(getValueAsNullableString(value))\n}\n\nfunction runValidator(validator: ValidatorUnion, parsedValue: unknown) {\n\t// Legacy validator\n\tif ('validate' in validator && typeof validator.validate === 'function') {\n\t\treturn validator.validate(parsedValue)\n\t}\n\t// Zod (skip)\n\treturn true\n}\n\nfunction getErrorMessage(error: unknown) {\n\tif (error instanceof ZodError) {\n\t\treturn z.treeifyError(error).errors.join('; ').replace('Invalid input: ', '')\n\t}\n\treturn 'Validation failed'\n}\n"],"names":["validateParam","validator","value","prevalidatorSuccess","runPrevalidator","parsedValue","runParser","validatorSuccess","runValidator","error","getErrorMessage","getValueAsNullableString","z","coercedValue","ZodError"],"mappings":";;AAKgB,SAAAA,EACfC,GACAC,GAKC;AACG,MAAA;AACG,UAAAC,IAAsBC,EAAgBH,GAAWC,CAAK,GACtDG,IAAcC,EAAUL,GAAWC,CAAK,GACxCK,IAAmBC,EAAaP,GAAWI,CAAW;AAErD,WAAA;AAAA,MACN,WAAWF,KAAuBI;AAAA,MAClC,aAAAF;AAAA,MACA,WAAW;AAAA,IACZ;AAAA,WACQI,GAAO;AAEf,WAAO,EAAE,WAAW,IAAO,aAAa,MAAM,WAD5BC,EAAgBD,CAAK,EACiB;AAAA,EAAA;AAE1D;AAEA,SAASL,EAAgBH,GAA2BC,GAAkD;AAErG,SAAI,iBAAiBD,KAAa,OAAOA,EAAU,eAAgB,aAC3DA,EAAU,YAAYU,EAAyBT,CAAK,CAAC,IAGtD;AACR;AAEA,SAASI,EAAUL,GAA2BC,GAAkD;AAE3F,MAAAD,aAAqBW,EAAE,SAAS;AACnC,UAAMC,KAAgB,MAAM;AACvB,UAAA;AACH,eAAO,OAAOX,KAAU,WAAW,KAAK,MAAMA,CAAK,IAAIA;AAAA,MAAA,QAChD;AACA,eAAAA;AAAA,MAAA;AAAA,IACR,GACE;AACI,WAAAD,EAAU,MAAMY,CAAY;AAAA,EAAA;AAGpC,SAAOZ,EAAU,MAAMU,EAAyBT,CAAK,CAAC;AACvD;AAEA,SAASM,EAAaP,GAA2BI,GAAsB;AAEtE,SAAI,cAAcJ,KAAa,OAAOA,EAAU,YAAa,aACrDA,EAAU,SAASI,CAAW,IAG/B;AACR;AAEA,SAASK,EAAgBD,GAAgB;AACxC,SAAIA,aAAiBK,IACbF,EAAE,aAAaH,CAAK,EAAE,OAAO,KAAK,IAAI,EAAE,QAAQ,mBAAmB,EAAE,IAEtE;AACR;"}
1
+ {"version":3,"file":"validateParam.mjs","sources":["../../src/validators/validateParam.ts"],"sourcesContent":["import z, { ZodError } from 'zod'\n\nimport { getValueAsNullableString } from '../utils/getValueAsNullableString'\nimport { ValidatorUnion } from './types'\n\nexport function validateParam(\n\tvalidator: ValidatorUnion,\n\tvalue: string | number | boolean | object | null,\n): {\n\tvalidated: boolean\n\tparsedValue: unknown\n\texception: string | null\n} {\n\ttry {\n\t\tconst prevalidatorSuccess = runPrevalidator(validator, value)\n\t\tconst parsedValue = runParser(validator, value)\n\t\tconst validatorSuccess = runValidator(validator, parsedValue)\n\n\t\treturn {\n\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\tparsedValue,\n\t\t\texception: null,\n\t\t}\n\t} catch (error) {\n\t\tconst exception = getErrorMessage(error)\n\t\treturn { validated: false, parsedValue: null, exception }\n\t}\n}\n\nfunction runPrevalidator(validator: ValidatorUnion, value: string | number | boolean | object | null) {\n\t// Legacy validator\n\tif ('prevalidate' in validator && typeof validator.prevalidate === 'function') {\n\t\treturn validator.prevalidate(getValueAsNullableString(value))\n\t}\n\t// Zod (skip)\n\treturn true\n}\n\nfunction isZodArrayValidator(validator: z.ZodType): boolean {\n\tif (validator instanceof z.ZodArray) return true\n\tif (validator instanceof z.ZodOptional) return validator.unwrap() instanceof z.ZodArray\n\treturn false\n}\n\nfunction runParser(validator: ValidatorUnion, value: string | number | boolean | object | null) {\n\t// Zod validator\n\tif (validator instanceof z.ZodType) {\n\t\tconst isArrayValidator = isZodArrayValidator(validator)\n\t\tconst coercedValue = (() => {\n\t\t\tif (typeof value !== 'string') return value\n\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(value)\n\t\t\t\tif (isArrayValidator && !Array.isArray(parsed)) {\n\t\t\t\t\treturn coerceCommaSeparatedToArray(value)\n\t\t\t\t}\n\t\t\t\treturn parsed\n\t\t\t} catch {\n\t\t\t\tif (isArrayValidator) {\n\t\t\t\t\treturn coerceCommaSeparatedToArray(value)\n\t\t\t\t}\n\t\t\t\treturn value\n\t\t\t}\n\t\t})()\n\t\treturn validator.parse(coercedValue)\n\t}\n\t// Legacy validator\n\treturn validator.parse(getValueAsNullableString(value))\n}\n\nfunction coerceCommaSeparatedToArray(value: string): unknown[] {\n\treturn value.split(',').map((element) => {\n\t\tconst trimmed = element.trim()\n\t\ttry {\n\t\t\treturn JSON.parse(trimmed)\n\t\t} catch {\n\t\t\treturn trimmed\n\t\t}\n\t})\n}\n\nfunction runValidator(validator: ValidatorUnion, parsedValue: unknown) {\n\t// Legacy validator\n\tif ('validate' in validator && typeof validator.validate === 'function') {\n\t\treturn validator.validate(parsedValue)\n\t}\n\t// Zod (skip)\n\treturn true\n}\n\nfunction getErrorMessage(error: unknown) {\n\tif (error instanceof ZodError) {\n\t\treturn z.treeifyError(error).errors.join('; ').replace('Invalid input: ', '')\n\t}\n\treturn 'Validation failed'\n}\n"],"names":["validateParam","validator","value","prevalidatorSuccess","runPrevalidator","parsedValue","runParser","validatorSuccess","runValidator","error","getErrorMessage","getValueAsNullableString","isZodArrayValidator","z","isArrayValidator","coercedValue","parsed","coerceCommaSeparatedToArray","element","trimmed","ZodError"],"mappings":";;AAKgB,SAAAA,EACfC,GACAC,GAKC;AACG,MAAA;AACG,UAAAC,IAAsBC,EAAgBH,GAAWC,CAAK,GACtDG,IAAcC,EAAUL,GAAWC,CAAK,GACxCK,IAAmBC,EAAaP,GAAWI,CAAW;AAErD,WAAA;AAAA,MACN,WAAWF,KAAuBI;AAAA,MAClC,aAAAF;AAAA,MACA,WAAW;AAAA,IACZ;AAAA,WACQI,GAAO;AAEf,WAAO,EAAE,WAAW,IAAO,aAAa,MAAM,WAD5BC,EAAgBD,CAAK,EACiB;AAAA,EAAA;AAE1D;AAEA,SAASL,EAAgBH,GAA2BC,GAAkD;AAErG,SAAI,iBAAiBD,KAAa,OAAOA,EAAU,eAAgB,aAC3DA,EAAU,YAAYU,EAAyBT,CAAK,CAAC,IAGtD;AACR;AAEA,SAASU,EAAoBX,GAA+B;AACvD,SAAAA,aAAqBY,EAAE,WAAiB,KACxCZ,aAAqBY,EAAE,cAAoBZ,EAAU,OAAA,aAAoBY,EAAE,WACxE;AACR;AAEA,SAASP,EAAUL,GAA2BC,GAAkD;AAE3F,MAAAD,aAAqBY,EAAE,SAAS;AAC7B,UAAAC,IAAmBF,EAAoBX,CAAS,GAChDc,KAAgB,MAAM;AACvB,UAAA,OAAOb,KAAU,SAAiB,QAAAA;AAElC,UAAA;AACG,cAAAc,IAAS,KAAK,MAAMd,CAAK;AAC/B,eAAIY,KAAoB,CAAC,MAAM,QAAQE,CAAM,IACrCC,EAA4Bf,CAAK,IAElCc;AAAA,MAAA,QACA;AACP,eAAIF,IACIG,EAA4Bf,CAAK,IAElCA;AAAA,MAAA;AAAA,IACR,GACE;AACI,WAAAD,EAAU,MAAMc,CAAY;AAAA,EAAA;AAGpC,SAAOd,EAAU,MAAMU,EAAyBT,CAAK,CAAC;AACvD;AAEA,SAASe,EAA4Bf,GAA0B;AAC9D,SAAOA,EAAM,MAAM,GAAG,EAAE,IAAI,CAACgB,MAAY;AAClC,UAAAC,IAAUD,EAAQ,KAAK;AACzB,QAAA;AACI,aAAA,KAAK,MAAMC,CAAO;AAAA,IAAA,QAClB;AACA,aAAAA;AAAA,IAAA;AAAA,EACR,CACA;AACF;AAEA,SAASX,EAAaP,GAA2BI,GAAsB;AAEtE,SAAI,cAAcJ,KAAa,OAAOA,EAAU,YAAa,aACrDA,EAAU,SAASI,CAAW,IAG/B;AACR;AAEA,SAASK,EAAgBD,GAAgB;AACxC,SAAIA,aAAiBW,IACbP,EAAE,aAAaJ,CAAK,EAAE,OAAO,KAAK,IAAI,EAAE,QAAQ,mBAAmB,EAAE,IAEtE;AACR;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moonflower",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "",
5
5
  "author": "tenebrie",
6
6
  "license": "MIT",
@@ -321,4 +321,275 @@ describe('useQueryParams', () => {
321
321
  expectTypeOf(params.numberParam).toEqualTypeOf<number | undefined>()
322
322
  })
323
323
  })
324
+
325
+ describe('legacy array validators', () => {
326
+ it('parses JSON string array with legacy validator', () => {
327
+ const ctx = mockContextQuery(mockContext(), {
328
+ nodes: JSON.stringify(['node1', 'node2']),
329
+ })
330
+
331
+ const params = useQueryParams(ctx, {
332
+ nodes: RequiredParam<string[]>({
333
+ parse: (v) => JSON.parse(String(v)),
334
+ }),
335
+ })
336
+
337
+ expect(params.nodes).toEqual(['node1', 'node2'])
338
+ })
339
+
340
+ it('parses comma-separated array with legacy validator', () => {
341
+ const ctx = mockContextQuery(mockContext(), {
342
+ nodes: 'node1,node2,node3',
343
+ })
344
+
345
+ const params = useQueryParams(ctx, {
346
+ nodes: RequiredParam<string[]>({
347
+ parse: (v) => String(v).split(','),
348
+ }),
349
+ })
350
+
351
+ expect(params.nodes).toEqual(['node1', 'node2', 'node3'])
352
+ })
353
+
354
+ it('fails validation on invalid legacy array param', () => {
355
+ const test = () => {
356
+ const ctx = mockContextQuery(mockContext(), {
357
+ nodes: 'not valid json array',
358
+ })
359
+
360
+ useQueryParams(ctx, {
361
+ nodes: RequiredParam<string[]>({
362
+ parse: (v) => JSON.parse(String(v)),
363
+ }),
364
+ })
365
+ }
366
+
367
+ expect(test).toThrow(ValidationError)
368
+ expect(test).toThrow("Failed query param validation: 'nodes'")
369
+ })
370
+
371
+ it('allows missing optional legacy array param', () => {
372
+ const ctx = mockContextQuery(mockContext(), {})
373
+
374
+ const params = useQueryParams(ctx, {
375
+ nodes: OptionalParam<string[]>({
376
+ parse: (v) => JSON.parse(String(v)),
377
+ }),
378
+ })
379
+
380
+ expect(params.nodes).toEqual(undefined)
381
+ })
382
+ })
383
+
384
+ describe('zod array validators', () => {
385
+ it('parses JSON string array', () => {
386
+ const ctx = mockContextQuery(mockContext(), {
387
+ nodes: JSON.stringify(['node1', 'node2']),
388
+ })
389
+
390
+ const params = useQueryParams(ctx, {
391
+ nodes: z.array(z.string()),
392
+ })
393
+
394
+ expect(params.nodes).toEqual(['node1', 'node2'])
395
+ })
396
+
397
+ it('parses JSON number array', () => {
398
+ const ctx = mockContextQuery(mockContext(), {
399
+ ids: JSON.stringify([1, 2, 3]),
400
+ })
401
+
402
+ const params = useQueryParams(ctx, {
403
+ ids: z.array(z.number()),
404
+ })
405
+
406
+ expect(params.ids).toEqual([1, 2, 3])
407
+ })
408
+
409
+ it('parses JSON object array', () => {
410
+ const ctx = mockContextQuery(mockContext(), {
411
+ items: JSON.stringify([
412
+ { name: 'first', value: 1 },
413
+ { name: 'second', value: 2 },
414
+ ]),
415
+ })
416
+
417
+ const params = useQueryParams(ctx, {
418
+ items: z.array(z.object({ name: z.string(), value: z.number() })),
419
+ })
420
+
421
+ expect(params.items).toEqual([
422
+ { name: 'first', value: 1 },
423
+ { name: 'second', value: 2 },
424
+ ])
425
+ })
426
+
427
+ it('parses comma-separated string array', () => {
428
+ const ctx = mockContextQuery(mockContext(), {
429
+ nodes: 'node1,node2,node3',
430
+ })
431
+
432
+ const params = useQueryParams(ctx, {
433
+ nodes: z.array(z.string()),
434
+ })
435
+
436
+ expect(params.nodes).toEqual(['node1', 'node2', 'node3'])
437
+ })
438
+
439
+ it('parses comma-separated number array', () => {
440
+ const ctx = mockContextQuery(mockContext(), {
441
+ ids: '1,2,3',
442
+ })
443
+
444
+ const params = useQueryParams(ctx, {
445
+ ids: z.array(z.number()),
446
+ })
447
+
448
+ expect(params.ids).toEqual([1, 2, 3])
449
+ })
450
+
451
+ it('parses comma-separated boolean array', () => {
452
+ const ctx = mockContextQuery(mockContext(), {
453
+ flags: 'true,false,true',
454
+ })
455
+
456
+ const params = useQueryParams(ctx, {
457
+ flags: z.array(z.boolean()),
458
+ })
459
+
460
+ expect(params.flags).toEqual([true, false, true])
461
+ })
462
+
463
+ it('parses comma-separated values with whitespace', () => {
464
+ const ctx = mockContextQuery(mockContext(), {
465
+ nodes: 'node1, node2 , node3',
466
+ })
467
+
468
+ const params = useQueryParams(ctx, {
469
+ nodes: z.array(z.string()),
470
+ })
471
+
472
+ expect(params.nodes).toEqual(['node1', 'node2', 'node3'])
473
+ })
474
+
475
+ it('parses single value as string array', () => {
476
+ const ctx = mockContextQuery(mockContext(), {
477
+ nodes: 'single',
478
+ })
479
+
480
+ const params = useQueryParams(ctx, {
481
+ nodes: z.array(z.string()),
482
+ })
483
+
484
+ expect(params.nodes).toEqual(['single'])
485
+ })
486
+
487
+ it('parses single value as number array', () => {
488
+ const ctx = mockContextQuery(mockContext(), {
489
+ ids: '42',
490
+ })
491
+
492
+ const params = useQueryParams(ctx, {
493
+ ids: z.array(z.number()),
494
+ })
495
+
496
+ expect(params.ids).toEqual([42])
497
+ })
498
+
499
+ it('fails validation on invalid array element', () => {
500
+ const test = () => {
501
+ const ctx = mockContextQuery(mockContext(), {
502
+ ids: 'abc,def',
503
+ })
504
+
505
+ useQueryParams(ctx, {
506
+ ids: z.array(z.number()),
507
+ })
508
+ }
509
+
510
+ expect(test).toThrow(ValidationError)
511
+ expect(test).toThrow("Failed query param validation: 'ids'")
512
+ })
513
+
514
+ it('fails when required array is missing', () => {
515
+ const test = () => {
516
+ const ctx = mockContextQuery(mockContext(), {})
517
+
518
+ useQueryParams(ctx, {
519
+ nodes: z.array(z.string()),
520
+ })
521
+ }
522
+
523
+ expect(test).toThrow(ValidationError)
524
+ expect(test).toThrow("Missing query params: 'nodes'")
525
+ })
526
+
527
+ it('parses optional array when missing', () => {
528
+ const ctx = mockContextQuery(mockContext(), {})
529
+
530
+ const params = useQueryParams(ctx, {
531
+ nodes: z.array(z.string()).optional(),
532
+ })
533
+
534
+ expect(params.nodes).toEqual(undefined)
535
+ })
536
+
537
+ it('parses optional array when present', () => {
538
+ const ctx = mockContextQuery(mockContext(), {
539
+ nodes: 'node1,node2',
540
+ })
541
+
542
+ const params = useQueryParams(ctx, {
543
+ nodes: z.array(z.string()).optional(),
544
+ })
545
+
546
+ expect(params.nodes).toEqual(['node1', 'node2'])
547
+ })
548
+
549
+ it('infers return type of string array', () => {
550
+ const ctx = mockContextQuery(mockContext(), {
551
+ nodes: 'a,b',
552
+ })
553
+
554
+ const params = useQueryParams(ctx, {
555
+ nodes: z.array(z.string()),
556
+ })
557
+
558
+ expectTypeOf(params.nodes).toEqualTypeOf<string[]>()
559
+ })
560
+
561
+ it('infers return type of number array', () => {
562
+ const ctx = mockContextQuery(mockContext(), {
563
+ ids: '1,2',
564
+ })
565
+
566
+ const params = useQueryParams(ctx, {
567
+ ids: z.array(z.number()),
568
+ })
569
+
570
+ expectTypeOf(params.ids).toEqualTypeOf<number[]>()
571
+ })
572
+
573
+ it('infers return type of object array', () => {
574
+ const ctx = mockContextQuery(mockContext(), {
575
+ items: JSON.stringify([{ name: 'a' }]),
576
+ })
577
+
578
+ const params = useQueryParams(ctx, {
579
+ items: z.array(z.object({ name: z.string() })),
580
+ })
581
+
582
+ expectTypeOf(params.items).toEqualTypeOf<{ name: string }[]>()
583
+ })
584
+
585
+ it('infers return type of optional array', () => {
586
+ const ctx = mockContextQuery(mockContext(), {})
587
+
588
+ const params = useQueryParams(ctx, {
589
+ nodes: z.array(z.string()).optional(),
590
+ })
591
+
592
+ expectTypeOf(params.nodes).toEqualTypeOf<string[] | undefined>()
593
+ })
594
+ })
324
595
  })
@@ -36,13 +36,29 @@ function runPrevalidator(validator: ValidatorUnion, value: string | number | boo
36
36
  return true
37
37
  }
38
38
 
39
+ function isZodArrayValidator(validator: z.ZodType): boolean {
40
+ if (validator instanceof z.ZodArray) return true
41
+ if (validator instanceof z.ZodOptional) return validator.unwrap() instanceof z.ZodArray
42
+ return false
43
+ }
44
+
39
45
  function runParser(validator: ValidatorUnion, value: string | number | boolean | object | null) {
40
46
  // Zod validator
41
47
  if (validator instanceof z.ZodType) {
48
+ const isArrayValidator = isZodArrayValidator(validator)
42
49
  const coercedValue = (() => {
50
+ if (typeof value !== 'string') return value
51
+
43
52
  try {
44
- return typeof value === 'string' ? JSON.parse(value) : value
53
+ const parsed = JSON.parse(value)
54
+ if (isArrayValidator && !Array.isArray(parsed)) {
55
+ return coerceCommaSeparatedToArray(value)
56
+ }
57
+ return parsed
45
58
  } catch {
59
+ if (isArrayValidator) {
60
+ return coerceCommaSeparatedToArray(value)
61
+ }
46
62
  return value
47
63
  }
48
64
  })()
@@ -52,6 +68,17 @@ function runParser(validator: ValidatorUnion, value: string | number | boolean |
52
68
  return validator.parse(getValueAsNullableString(value))
53
69
  }
54
70
 
71
+ function coerceCommaSeparatedToArray(value: string): unknown[] {
72
+ return value.split(',').map((element) => {
73
+ const trimmed = element.trim()
74
+ try {
75
+ return JSON.parse(trimmed)
76
+ } catch {
77
+ return trimmed
78
+ }
79
+ })
80
+ }
81
+
55
82
  function runValidator(validator: ValidatorUnion, parsedValue: unknown) {
56
83
  // Legacy validator
57
84
  if ('validate' in validator && typeof validator.validate === 'function') {