@infra-blocks/zod-utils 0.20.0 → 0.21.0-alpha.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.
Files changed (90) hide show
  1. package/README.md +38 -7
  2. package/lib/cjs/codec/csv.d.ts +3 -3
  3. package/lib/cjs/codec/csv.js +4 -6
  4. package/lib/cjs/codec/csv.js.map +1 -1
  5. package/lib/cjs/codec/index.d.ts +2 -0
  6. package/lib/cjs/codec/index.js +5 -1
  7. package/lib/cjs/codec/index.js.map +1 -1
  8. package/lib/cjs/codec/json-parse.d.ts +10 -0
  9. package/lib/cjs/codec/json-parse.js +20 -0
  10. package/lib/cjs/codec/json-parse.js.map +1 -0
  11. package/lib/cjs/codec/string-split.d.ts +13 -0
  12. package/lib/cjs/codec/string-split.js +21 -0
  13. package/lib/cjs/codec/string-split.js.map +1 -0
  14. package/lib/cjs/codec/string-to-integer.d.ts +1 -1
  15. package/lib/cjs/codec/string-to-integer.js +4 -4
  16. package/lib/cjs/codec/string-to-integer.js.map +1 -1
  17. package/lib/cjs/codec/string-to-json.d.ts +6 -0
  18. package/lib/cjs/codec/string-to-json.js +14 -0
  19. package/lib/cjs/codec/string-to-json.js.map +1 -0
  20. package/lib/cjs/codec/string-to-url.js +2 -2
  21. package/lib/cjs/codec/string-to-url.js.map +1 -1
  22. package/lib/cjs/index.d.ts +7 -5
  23. package/lib/cjs/json/array.d.ts +4 -0
  24. package/lib/cjs/json/array.js +9 -0
  25. package/lib/cjs/json/array.js.map +1 -0
  26. package/lib/cjs/json/index.d.ts +4 -6
  27. package/lib/cjs/json/index.js +6 -4
  28. package/lib/cjs/json/index.js.map +1 -1
  29. package/lib/cjs/json/json.d.ts +4 -13
  30. package/lib/cjs/json/json.js +5 -42
  31. package/lib/cjs/json/json.js.map +1 -1
  32. package/lib/cjs/json/object.d.ts +6 -0
  33. package/lib/cjs/json/object.js +9 -0
  34. package/lib/cjs/json/object.js.map +1 -0
  35. package/lib/cjs/json/primitive.d.ts +5 -0
  36. package/lib/cjs/json/primitive.js +8 -0
  37. package/lib/cjs/json/primitive.js.map +1 -0
  38. package/lib/cjs/json/types.d.ts +4 -1
  39. package/lib/cjs/string/index.d.ts +1 -0
  40. package/lib/cjs/string/index.js +2 -0
  41. package/lib/cjs/string/index.js.map +1 -1
  42. package/lib/cjs/string/json.d.ts +9 -0
  43. package/lib/cjs/string/json.js +23 -0
  44. package/lib/cjs/string/json.js.map +1 -0
  45. package/lib/cjs/string/types.d.ts +1 -0
  46. package/lib/esm/codec/csv.d.ts +3 -3
  47. package/lib/esm/codec/csv.js +4 -6
  48. package/lib/esm/codec/csv.js.map +1 -1
  49. package/lib/esm/codec/index.d.ts +2 -0
  50. package/lib/esm/codec/index.js +6 -2
  51. package/lib/esm/codec/index.js.map +1 -1
  52. package/lib/esm/codec/json-parse.d.ts +10 -0
  53. package/lib/esm/codec/json-parse.js +16 -0
  54. package/lib/esm/codec/json-parse.js.map +1 -0
  55. package/lib/esm/codec/string-split.d.ts +13 -0
  56. package/lib/esm/codec/string-split.js +17 -0
  57. package/lib/esm/codec/string-split.js.map +1 -0
  58. package/lib/esm/codec/string-to-integer.d.ts +1 -1
  59. package/lib/esm/codec/string-to-integer.js +2 -2
  60. package/lib/esm/codec/string-to-integer.js.map +1 -1
  61. package/lib/esm/codec/string-to-json.d.ts +6 -0
  62. package/lib/esm/codec/string-to-json.js +10 -0
  63. package/lib/esm/codec/string-to-json.js.map +1 -0
  64. package/lib/esm/codec/string-to-url.js +2 -2
  65. package/lib/esm/codec/string-to-url.js.map +1 -1
  66. package/lib/esm/index.d.ts +7 -5
  67. package/lib/esm/json/array.d.ts +4 -0
  68. package/lib/esm/json/array.js +5 -0
  69. package/lib/esm/json/array.js.map +1 -0
  70. package/lib/esm/json/index.d.ts +4 -6
  71. package/lib/esm/json/index.js +4 -2
  72. package/lib/esm/json/index.js.map +1 -1
  73. package/lib/esm/json/json.d.ts +4 -13
  74. package/lib/esm/json/json.js +3 -36
  75. package/lib/esm/json/json.js.map +1 -1
  76. package/lib/esm/json/object.d.ts +6 -0
  77. package/lib/esm/json/object.js +5 -0
  78. package/lib/esm/json/object.js.map +1 -0
  79. package/lib/esm/json/primitive.d.ts +5 -0
  80. package/lib/esm/json/primitive.js +4 -0
  81. package/lib/esm/json/primitive.js.map +1 -0
  82. package/lib/esm/json/types.d.ts +4 -1
  83. package/lib/esm/string/index.d.ts +1 -0
  84. package/lib/esm/string/index.js +2 -0
  85. package/lib/esm/string/index.js.map +1 -1
  86. package/lib/esm/string/json.d.ts +9 -0
  87. package/lib/esm/string/json.js +19 -0
  88. package/lib/esm/string/json.js.map +1 -0
  89. package/lib/esm/string/types.d.ts +1 -0
  90. package/package.json +1 -1
@@ -1,2 +1,3 @@
1
1
  export { IntegerString } from "./integer.js";
2
+ export { JsonString } from "./json.js";
2
3
  export { UrlString } from "./url.js";
@@ -1,9 +1,9 @@
1
- import { z } from "zod";
2
1
  /**
3
2
  * Returns a codec that takes in a CSV string and outputs a string array.
4
3
  *
5
- * The string is splitted on the "," character.
4
+ * The string is splitted on the "," character. It uses `stringSplit(",")`
5
+ * internally.
6
6
  *
7
7
  * @returns A CSV codec.
8
8
  */
9
- export declare const csv: () => z.ZodCodec<z.ZodString, z.ZodArray<z.ZodString>>;
9
+ export declare const csv: () => import("zod").ZodCodec<import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString>>;
@@ -1,12 +1,10 @@
1
- import { z } from "zod";
2
- const codec = z.codec(z.string(), z.array(z.string()), {
3
- decode: (str) => str.split(","),
4
- encode: (arr) => arr.join(","),
5
- });
1
+ import { stringSplit } from "./string-split.js";
2
+ const codec = stringSplit(",");
6
3
  /**
7
4
  * Returns a codec that takes in a CSV string and outputs a string array.
8
5
  *
9
- * The string is splitted on the "," character.
6
+ * The string is splitted on the "," character. It uses `stringSplit(",")`
7
+ * internally.
10
8
  *
11
9
  * @returns A CSV codec.
12
10
  */
@@ -1 +1 @@
1
- {"version":3,"file":"csv.js","sourceRoot":"","sources":["../../../src/codec/csv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;IACrD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC;IAC/B,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;CAC/B,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC"}
1
+ {"version":3,"file":"csv.js","sourceRoot":"","sources":["../../../src/codec/csv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC"}
@@ -1,6 +1,8 @@
1
1
  declare const codec: {
2
2
  csv: () => import("zod").ZodCodec<import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString>>;
3
+ jsonParse: <S extends import("zod").ZodType>(schema: S) => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">, S>;
3
4
  stringtoInteger: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "IntegerString">, import("zod/v4/core").$ZodBranded<import("zod").ZodInt, "Integer">>;
5
+ stringToJson: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">, import("zod").ZodType<import("../json/json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("../json/json.js").Json, unknown>>>;
4
6
  stringToUrl: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodURL, "UrlString">, import("zod").ZodCustom<import("url").URL, import("url").URL>>;
5
7
  };
6
8
  export { codec };
@@ -1,9 +1,13 @@
1
1
  import { csv } from "./csv.js";
2
- import { stringtoInteger } from "./string-to-integer.js";
2
+ import { jsonParse } from "./json-parse.js";
3
+ import { stringToInteger } from "./string-to-integer.js";
4
+ import { stringToJson } from "./string-to-json.js";
3
5
  import { stringToUrl } from "./string-to-url.js";
4
6
  const codec = {
5
7
  csv,
6
- stringtoInteger,
8
+ jsonParse,
9
+ stringtoInteger: stringToInteger,
10
+ stringToJson,
7
11
  stringToUrl,
8
12
  };
9
13
  export { codec };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,KAAK,GAAG;IACZ,GAAG;IACH,eAAe;IACf,WAAW;CACZ,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,KAAK,GAAG;IACZ,GAAG;IACH,SAAS;IACT,eAAe,EAAE,eAAe;IAChC,YAAY;IACZ,WAAW;CACZ,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * A codec factory that returns a codec that expects a valid JSON string
4
+ * as input, parses it using JSON.parse, then passes the result to the
5
+ * provided schema.
6
+ *
7
+ * @returns A codec where the first schema is {@link string.json}, and the
8
+ * second one is the provided input.
9
+ */
10
+ export declare const jsonParse: <S extends z.ZodType>(schema: S) => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "JsonString">, S>;
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ import { trusted } from "../lib.js";
3
+ import { string } from "../string/index.js";
4
+ /**
5
+ * A codec factory that returns a codec that expects a valid JSON string
6
+ * as input, parses it using JSON.parse, then passes the result to the
7
+ * provided schema.
8
+ *
9
+ * @returns A codec where the first schema is {@link string.json}, and the
10
+ * second one is the provided input.
11
+ */
12
+ export const jsonParse = (schema) => z.codec(string.json(), schema, {
13
+ decode: (str) => JSON.parse(str),
14
+ encode: (json) => trusted(JSON.stringify(json)),
15
+ });
16
+ //# sourceMappingURL=json-parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-parse.js","sourceRoot":"","sources":["../../../src/codec/json-parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAsB,MAAS,EAAE,EAAE,CAC1D,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE;IAC7B,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAChC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;CAChD,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * A codec factory that returns a codec that expects a string
4
+ * as input, splits it using {@link String.split} with the provided
5
+ * seperator, then passes the result to the provided schema.
6
+ *
7
+ * When encoding, the array is joined with the same separator provided.
8
+ *
9
+ * @returns A codec where the first schema is {@link z.string}, the
10
+ * second one is `z.array(z.string())`, and the transformations are
11
+ * done using {@link String.split} and {@link Array.join}
12
+ */
13
+ export declare const stringSplit: (separator: string) => z.ZodCodec<z.ZodString, z.ZodArray<z.ZodString>>;
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * A codec factory that returns a codec that expects a string
4
+ * as input, splits it using {@link String.split} with the provided
5
+ * seperator, then passes the result to the provided schema.
6
+ *
7
+ * When encoding, the array is joined with the same separator provided.
8
+ *
9
+ * @returns A codec where the first schema is {@link z.string}, the
10
+ * second one is `z.array(z.string())`, and the transformations are
11
+ * done using {@link String.split} and {@link Array.join}
12
+ */
13
+ export const stringSplit = (separator) => z.codec(z.string(), z.array(z.string()), {
14
+ decode: (str) => str.split(separator),
15
+ encode: (arr) => arr.join(separator),
16
+ });
17
+ //# sourceMappingURL=string-split.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-split.js","sourceRoot":"","sources":["../../../src/codec/string-split.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAE,EAAE,CAC/C,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;IACvC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;IACrC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;CACrC,CAAC,CAAC"}
@@ -10,4 +10,4 @@ import { z } from "zod";
10
10
  *
11
11
  * @see https://zod.dev/codecs#stringtoint
12
12
  */
13
- export declare const stringtoInteger: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "IntegerString">, z.core.$ZodBranded<z.ZodInt, "Integer">>;
13
+ export declare const stringToInteger: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "IntegerString">, z.core.$ZodBranded<z.ZodInt, "Integer">>;
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { trusted } from "../lib.js";
3
3
  import { number } from "../number/index.js";
4
4
  import { string } from "../string/index.js";
5
- const stringToIntegerCodec = z.codec(string.integer(), number.integer(), {
5
+ const codec = z.codec(string.integer(), number.integer(), {
6
6
  decode: (str) => Number.parseInt(str, 10),
7
7
  encode: (num) => trusted(num.toString()),
8
8
  });
@@ -17,5 +17,5 @@ const stringToIntegerCodec = z.codec(string.integer(), number.integer(), {
17
17
  *
18
18
  * @see https://zod.dev/codecs#stringtoint
19
19
  */
20
- export const stringtoInteger = () => stringToIntegerCodec;
20
+ export const stringToInteger = () => codec;
21
21
  //# sourceMappingURL=string-to-integer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string-to-integer.js","sourceRoot":"","sources":["../../../src/codec/string-to-integer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE;IACvE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,oBAAoB,CAAC"}
1
+ {"version":3,"file":"string-to-integer.js","sourceRoot":"","sources":["../../../src/codec/string-to-integer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE;IACxD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A string to JSON codec.
3
+ *
4
+ * @returns A string to JSON codec.
5
+ */
6
+ export declare const stringToJson: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">, import("zod").ZodType<import("../json/json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("../json/json.js").Json, unknown>>>;
@@ -0,0 +1,10 @@
1
+ import { json } from "../json/index.js";
2
+ import { jsonParse } from "./json-parse.js";
3
+ const codec = jsonParse(json());
4
+ /**
5
+ * A string to JSON codec.
6
+ *
7
+ * @returns A string to JSON codec.
8
+ */
9
+ export const stringToJson = () => codec;
10
+ //# sourceMappingURL=string-to-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-to-json.js","sourceRoot":"","sources":["../../../src/codec/string-to-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;AAEhC;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { trusted } from "../lib.js";
3
3
  import { string } from "../string/index.js";
4
- const stringToURLCodec = z.codec(string.url(), z.instanceof(URL), {
4
+ const codec = z.codec(string.url(), z.instanceof(URL), {
5
5
  decode: (urlString) => new URL(urlString),
6
6
  encode: (url) => trusted(url.href),
7
7
  });
@@ -12,5 +12,5 @@ const stringToURLCodec = z.codec(string.url(), z.instanceof(URL), {
12
12
  *
13
13
  * @see https://zod.dev/codecs#stringtourl
14
14
  */
15
- export const stringToUrl = () => stringToURLCodec;
15
+ export const stringToUrl = () => codec;
16
16
  //# sourceMappingURL=string-to-url.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string-to-url.js","sourceRoot":"","sources":["../../../src/codec/string-to-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;IAChE,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;CACnC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,gBAAgB,CAAC"}
1
+ {"version":3,"file":"string-to-url.js","sourceRoot":"","sources":["../../../src/codec/string-to-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;IACrD,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;CACnC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC"}
@@ -38,7 +38,9 @@ declare const zu: {
38
38
  };
39
39
  codec: {
40
40
  csv: () => z.ZodCodec<z.ZodString, z.ZodArray<z.ZodString>>;
41
+ jsonParse: <S extends z.ZodType>(schema: S) => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "JsonString">, S>;
41
42
  stringtoInteger: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "IntegerString">, z.core.$ZodBranded<z.ZodInt, "Integer">>;
43
+ stringToJson: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "JsonString">, z.ZodType<import("./json/json.js").Json, unknown, z.core.$ZodTypeInternals<import("./json/json.js").Json, unknown>>>;
42
44
  stringToUrl: () => z.ZodCodec<z.core.$ZodBranded<z.ZodURL, "UrlString">, z.ZodCustom<import("url").URL, import("url").URL>>;
43
45
  };
44
46
  geojson: typeof import("./geojson/geojson.js").geojson & {
@@ -64,17 +66,17 @@ declare const zu: {
64
66
  }>, "IsoAlpha3CountryCode">;
65
67
  };
66
68
  };
67
- json: typeof import("./json/json.js").json & {
68
- array: typeof import("./json/json.js").array;
69
- object: typeof import("./json/json.js").object;
70
- primitive: typeof import("./json/json.js").primitive;
71
- stringified: typeof import("./json/json.js").stringifiedJson;
69
+ json: (() => z.ZodType<import("./json/json.js").Json, unknown, z.core.$ZodTypeInternals<import("./json/json.js").Json, unknown>>) & {
70
+ array: () => z.ZodArray<z.ZodType<import("./json/json.js").Json, unknown, z.core.$ZodTypeInternals<import("./json/json.js").Json, unknown>>>;
71
+ object: () => z.ZodRecord<z.ZodString, z.ZodType<import("./json/json.js").Json, unknown, z.core.$ZodTypeInternals<import("./json/json.js").Json, unknown>>>;
72
+ primitive: () => z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
72
73
  };
73
74
  number: {
74
75
  integer: () => z.core.$ZodBranded<z.ZodInt, "Integer">;
75
76
  };
76
77
  string: {
77
78
  integer: () => z.core.$ZodBranded<z.ZodString, "IntegerString">;
79
+ json: () => z.core.$ZodBranded<z.ZodString, "JsonString">;
78
80
  url: () => z.core.$ZodBranded<z.ZodURL, "UrlString">;
79
81
  };
80
82
  isValid: typeof isValid;
@@ -0,0 +1,4 @@
1
+ import { z } from "zod";
2
+ import { type Json } from "./json.js";
3
+ export type JsonArray = Array<Json>;
4
+ export declare const array: () => z.ZodArray<z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>;
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ import { json } from "./json.js";
3
+ const schema = z.array(json());
4
+ export const array = () => schema;
5
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/json/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,IAAI,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AAI/B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC"}
@@ -1,8 +1,6 @@
1
- import { array, json, object, primitive, stringifiedJson } from "./json.js";
2
- declare const module: typeof json & {
3
- array: typeof array;
4
- object: typeof object;
5
- primitive: typeof primitive;
6
- stringified: typeof stringifiedJson;
1
+ declare const module: (() => import("zod").ZodType<import("./json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("./json.js").Json, unknown>>) & {
2
+ array: () => import("zod").ZodArray<import("zod").ZodType<import("./json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("./json.js").Json, unknown>>>;
3
+ object: () => import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodType<import("./json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("./json.js").Json, unknown>>>;
4
+ primitive: () => import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodBoolean, import("zod").ZodNull]>;
7
5
  };
8
6
  export { module as json };
@@ -1,9 +1,11 @@
1
- import { array, json, object, primitive, stringifiedJson } from "./json.js";
1
+ import { array } from "./array.js";
2
+ import { json } from "./json.js";
3
+ import { object } from "./object.js";
4
+ import { primitive } from "./primitive.js";
2
5
  const module = Object.assign(json, {
3
6
  array,
4
7
  object,
5
8
  primitive,
6
- stringified: stringifiedJson,
7
9
  });
8
10
  export { module as json };
9
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/json/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5E,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;IACjC,KAAK;IACL,MAAM;IACN,SAAS;IACT,WAAW,EAAE,eAAe;CAC7B,CAAC,CAAC;AAEH,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/json/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;IACjC,KAAK;IACL,MAAM;IACN,SAAS;CACV,CAAC,CAAC;AAEH,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE,CAAC"}
@@ -1,15 +1,6 @@
1
1
  import { z } from "zod";
2
- declare const primitiveSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
3
- export type JsonPrimitive = z.infer<typeof primitiveSchema>;
4
- export declare function primitive(): z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
5
- export type JsonObject = {
6
- [key: string]: Json;
7
- };
8
- export type JsonArray = Array<Json>;
2
+ import type { JsonArray } from "./array.js";
3
+ import type { JsonObject } from "./object.js";
4
+ import { type JsonPrimitive } from "./primitive.js";
9
5
  export type Json = JsonPrimitive | JsonObject | JsonArray;
10
- export declare function json(): z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>;
11
- export declare function object(): z.ZodRecord<z.ZodString, z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>;
12
- export declare function array(): z.ZodArray<z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>;
13
- export declare const stringifiedJsonSchema: z.ZodType<Json, string>;
14
- export declare function stringifiedJson(): z.ZodType<Json, string, z.core.$ZodTypeInternals<Json, string>>;
15
- export {};
6
+ export declare const json: () => z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>;
@@ -1,38 +1,5 @@
1
1
  import { z } from "zod";
2
- const primitiveSchema = z.union([
3
- z.string(),
4
- z.number(),
5
- z.boolean(),
6
- z.null(),
7
- ]);
8
- export function primitive() {
9
- return primitiveSchema;
10
- }
11
- const jsonSchema = z.lazy(() => z.union([primitive(), z.array(jsonSchema), z.record(z.string(), jsonSchema)]));
12
- export function json() {
13
- return jsonSchema;
14
- }
15
- const objectSchema = z.record(z.string(), jsonSchema);
16
- export function object() {
17
- return objectSchema;
18
- }
19
- const arraySchema = z.array(jsonSchema);
20
- export function array() {
21
- return arraySchema;
22
- }
23
- // TODO: codec stringToJson.
24
- export const stringifiedJsonSchema = z
25
- .string()
26
- .transform((str, ctx) => {
27
- try {
28
- return JSON.parse(str);
29
- }
30
- catch {
31
- ctx.addIssue({ code: "custom", message: "Invalid JSON" });
32
- return z.NEVER;
33
- }
34
- });
35
- export function stringifiedJson() {
36
- return stringifiedJsonSchema;
37
- }
2
+ import { primitive } from "./primitive.js";
3
+ const schema = z.lazy(() => z.union([primitive(), z.array(schema), z.record(z.string(), schema)]));
4
+ export const json = () => schema;
38
5
  //# sourceMappingURL=json.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/json/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC;IAC9B,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,OAAO,EAAE;IACX,CAAC,CAAC,IAAI,EAAE;CACT,CAAC,CAAC;AAEH,MAAM,UAAU,SAAS;IACvB,OAAO,eAAe,CAAC;AACzB,CAAC;AAMD,MAAM,UAAU,GAAoB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAC9C,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CAC9E,CAAC;AACF,MAAM,UAAU,IAAI;IAClB,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;AACtD,MAAM,UAAU,MAAM;IACpB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AACxC,MAAM,UAAU,KAAK;IACnB,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,qBAAqB,GAA4B,CAAC;KAC5D,MAAM,EAAE;KACR,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACtB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAS,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,CAAC,KAAK,CAAC;IACjB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,MAAM,UAAU,eAAe;IAC7B,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/json/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAsB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE/D,MAAM,MAAM,GAAoB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAC1C,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CACtE,CAAC;AAIF,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ import { type Json } from "./json.js";
3
+ export type JsonObject = {
4
+ [key: string]: Json;
5
+ };
6
+ export declare const object: () => z.ZodRecord<z.ZodString, z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>;
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ import { json } from "./json.js";
3
+ const schema = z.record(z.string(), json());
4
+ export const object = () => schema;
5
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/json/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,IAAI,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAI5C,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ declare const schema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
3
+ export type JsonPrimitive = z.infer<typeof schema>;
4
+ export declare const primitive: () => z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
5
+ export {};
@@ -0,0 +1,4 @@
1
+ import { z } from "zod";
2
+ const schema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
3
+ export const primitive = () => schema;
4
+ //# sourceMappingURL=primitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive.js","sourceRoot":"","sources":["../../../src/json/primitive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAIxE,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC"}
@@ -1 +1,4 @@
1
- export type { Json, JsonArray, JsonObject, JsonPrimitive } from "./json.js";
1
+ export type { JsonArray } from "./array.js";
2
+ export type { Json } from "./json.js";
3
+ export type { JsonObject } from "./object.js";
4
+ export type { JsonPrimitive } from "./primitive.js";
@@ -1,5 +1,6 @@
1
1
  declare const string: {
2
2
  integer: () => import("zod/v4/core").$ZodBranded<import("zod").ZodString, "IntegerString">;
3
+ json: () => import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">;
3
4
  url: () => import("zod/v4/core").$ZodBranded<import("zod").ZodURL, "UrlString">;
4
5
  };
5
6
  export { string };
@@ -1,7 +1,9 @@
1
1
  import { integer } from "./integer.js";
2
+ import { json } from "./json.js";
2
3
  import { url } from "./url.js";
3
4
  const string = {
4
5
  integer,
6
+ json,
5
7
  url,
6
8
  };
7
9
  export { string };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/string/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,MAAM,GAAG;IACb,OAAO;IACP,GAAG;CACJ,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/string/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,MAAM,GAAG;IACb,OAAO;IACP,IAAI;IACJ,GAAG;CACJ,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodString, "JsonString">;
3
+ export type JsonString = z.infer<typeof schema>;
4
+ /**
5
+ * @returns A schema that validates its input as a JSON string and returns a {@link JsonString}
6
+ * upon success.
7
+ */
8
+ export declare const json: () => z.core.$ZodBranded<z.ZodString, "JsonString">;
9
+ export {};
@@ -0,0 +1,19 @@
1
+ import { z } from "zod";
2
+ const schema = z
3
+ .string()
4
+ .refine((s) => {
5
+ try {
6
+ JSON.parse(s);
7
+ return true;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }, { error: "invalid JSON string" })
13
+ .brand("JsonString");
14
+ /**
15
+ * @returns A schema that validates its input as a JSON string and returns a {@link JsonString}
16
+ * upon success.
17
+ */
18
+ export const json = () => schema;
19
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/string/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,GAAG,CAAC;KACb,MAAM,EAAE;KACR,MAAM,CACL,CAAC,CAAC,EAAE,EAAE;IACJ,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,EACD,EAAE,KAAK,EAAE,qBAAqB,EAAE,CACjC;KACA,KAAK,CAAC,YAAY,CAAC,CAAC;AAIvB;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { IntegerString } from "./integer.js";
2
+ export { JsonString } from "./json.js";
2
3
  export { UrlString } from "./url.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infra-blocks/zod-utils",
3
- "version": "0.20.0",
3
+ "version": "0.21.0-alpha.0",
4
4
  "description": "Extensions to the zod package.",
5
5
  "keywords": [
6
6
  "zod",