@infra-blocks/zod-utils 0.1.0-alpha.3 → 0.1.0-alpha.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.
- package/README.md +49 -1
- package/lib/cjs/index.d.ts +5 -3
- package/lib/cjs/index.js +2 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/json/index.d.ts +7 -0
- package/lib/cjs/json/index.js +14 -0
- package/lib/cjs/json/index.js.map +1 -0
- package/lib/cjs/json/json.d.ts +11 -0
- package/lib/cjs/json/json.js +30 -0
- package/lib/cjs/json/json.js.map +1 -0
- package/lib/cjs/json/types.d.ts +1 -0
- package/lib/cjs/json/types.js +3 -0
- package/lib/cjs/json/types.js.map +1 -0
- package/lib/esm/index.d.ts +5 -3
- package/lib/esm/index.js +1 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/json/index.d.ts +7 -0
- package/lib/esm/json/index.js +11 -0
- package/lib/esm/json/index.js.map +1 -0
- package/lib/esm/json/json.d.ts +11 -0
- package/lib/esm/json/json.js +24 -0
- package/lib/esm/json/json.js.map +1 -0
- package/lib/esm/json/types.d.ts +1 -0
- package/lib/esm/json/types.js +2 -0
- package/lib/esm/json/types.js.map +1 -0
- package/package.json +11 -4
- package/lib/cjs/json.d.ts +0 -9
- package/lib/cjs/json.js +0 -26
- package/lib/cjs/json.js.map +0 -1
- package/lib/esm/json.d.ts +0 -9
- package/lib/esm/json.js +0 -21
- package/lib/esm/json.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ts-
|
|
1
|
+
# ts-zod-utils
|
|
2
2
|
[](https://github.com/infrastructure-blocks/ts-zod-utils/actions/workflows/build.yml)
|
|
3
3
|
[](https://github.com/infrastructure-blocks/ts-zod-utils/actions/workflows/npm-publish-release-from-label.yml)
|
|
4
4
|
[](https://github.com/infrastructure-blocks/ts-zod-utils/actions/workflows/update-from-template.yml)
|
|
@@ -6,6 +6,54 @@
|
|
|
6
6
|
|
|
7
7
|
This package exposes various utilities extending the [zod](https://www.npmjs.com/package/zod) package.
|
|
8
8
|
|
|
9
|
+
## API
|
|
10
|
+
|
|
11
|
+
- [json](#json)
|
|
12
|
+
|
|
13
|
+
### JSON
|
|
14
|
+
|
|
15
|
+
The `json` module contains utilities to validate JSON objects and stringified JSON objects.
|
|
16
|
+
|
|
17
|
+
````typescript
|
|
18
|
+
import { zu } from "@infra-blocks/zod-utils";
|
|
19
|
+
|
|
20
|
+
// Works with any scalar
|
|
21
|
+
zu.json().parse(0);
|
|
22
|
+
zu.json().parse("hello");
|
|
23
|
+
zu.json().parse(true);
|
|
24
|
+
zu.json().parse(null);
|
|
25
|
+
// With arrays and objects too.
|
|
26
|
+
zu.json().parse([1, "bye", false, null, ["nested"]]);
|
|
27
|
+
zu.json().parse({
|
|
28
|
+
number: 42,
|
|
29
|
+
string: "hello again, I guess",
|
|
30
|
+
boolean: true,
|
|
31
|
+
null: null,
|
|
32
|
+
array: [1, "bye", false, null],
|
|
33
|
+
nested: {
|
|
34
|
+
someField: "you get it"
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
// Throws for bullshit.
|
|
38
|
+
zu.json().parse(undefined);
|
|
39
|
+
zu.json().parse(Symbol("nope"));
|
|
40
|
+
zu.json().parse(new Set());
|
|
41
|
+
// etc...
|
|
42
|
+
|
|
43
|
+
// You can also parse stringified JSON!
|
|
44
|
+
zu.json.stringified().parse("5"); // Returns the number 5.
|
|
45
|
+
zu.json.stringified().parse('"JSON string"'); // Returns "JSON string". Note the quotes were removed.
|
|
46
|
+
zu.json.stringified().parse(JSON.strinfify({ field: "value" })); // Returns {field: "value"}.
|
|
47
|
+
|
|
48
|
+
// Inferred types are exported for convenience.
|
|
49
|
+
import { Json, Literal } from "@infra-blocks/zod-utils/json";
|
|
50
|
+
|
|
51
|
+
// Compiles.
|
|
52
|
+
const myJson: Json = { hello: "world" };
|
|
53
|
+
// Doesn't compile.
|
|
54
|
+
const boom: Json = { nope: undefined };
|
|
55
|
+
````
|
|
56
|
+
|
|
9
57
|
## Development
|
|
10
58
|
|
|
11
59
|
### Repo init
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { json, jsonFromString } from "./json.js";
|
|
2
1
|
declare const zu: {
|
|
3
|
-
json:
|
|
4
|
-
|
|
2
|
+
json: {
|
|
3
|
+
(): import("zod").ZodType<import("./json/json.js").Json, import("zod").ZodTypeDef, import("./json/json.js").Json>;
|
|
4
|
+
stringified: typeof import("./json/json.js").stringifiedJson;
|
|
5
|
+
literal: typeof import("./json/json.js").literal;
|
|
6
|
+
};
|
|
5
7
|
};
|
|
6
8
|
export { zu };
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zu = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("./json/index.js");
|
|
5
5
|
const zu = {
|
|
6
|
-
json:
|
|
7
|
-
jsonFromString: json_js_1.jsonFromString,
|
|
6
|
+
json: index_js_1.json,
|
|
8
7
|
};
|
|
9
8
|
exports.zu = zu;
|
|
10
9
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,8CAAuC;AAEvC,MAAM,EAAE,GAAG;IACT,IAAI,EAAJ,eAAI;CACL,CAAC;AAEO,gBAAE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { literal, stringifiedJson } from "./json.js";
|
|
2
|
+
declare const module: {
|
|
3
|
+
(): import("zod").ZodType<import("./json.js").Json, import("zod").ZodTypeDef, import("./json.js").Json>;
|
|
4
|
+
stringified: typeof stringifiedJson;
|
|
5
|
+
literal: typeof literal;
|
|
6
|
+
};
|
|
7
|
+
export { module as json };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.json = void 0;
|
|
4
|
+
const json_js_1 = require("./json.js");
|
|
5
|
+
const module = (() => {
|
|
6
|
+
function module() {
|
|
7
|
+
return (0, json_js_1.json)();
|
|
8
|
+
}
|
|
9
|
+
module.stringified = json_js_1.stringifiedJson;
|
|
10
|
+
module.literal = json_js_1.literal;
|
|
11
|
+
return module;
|
|
12
|
+
})();
|
|
13
|
+
exports.json = module;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/json/index.ts"],"names":[],"mappings":";;;AAAA,uCAA2D;AAE3D,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;IACnB,SAAS,MAAM;QACb,OAAO,IAAA,cAAI,GAAE,CAAC;IAChB,CAAC;IACD,MAAM,CAAC,WAAW,GAAG,yBAAe,CAAC;IACrC,MAAM,CAAC,OAAO,GAAG,iBAAO,CAAC;IAEzB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,EAAE,CAAC;AAEc,sBAAI"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const literalSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
3
|
+
export type Literal = z.infer<typeof literalSchema>;
|
|
4
|
+
export declare function literal(): z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
5
|
+
export type Json = Literal | {
|
|
6
|
+
[key: string]: Json;
|
|
7
|
+
} | Json[];
|
|
8
|
+
export declare function json(): z.ZodType<Json, z.ZodTypeDef, Json>;
|
|
9
|
+
export declare const stringifiedJsonSchema: z.ZodType<Json, z.ZodTypeDef, string>;
|
|
10
|
+
export declare function stringifiedJson(): z.ZodType<Json, z.ZodTypeDef, string>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringifiedJson = exports.stringifiedJsonSchema = exports.json = exports.literal = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const literalSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean(), zod_1.z.null()]);
|
|
6
|
+
function literal() {
|
|
7
|
+
return literalSchema;
|
|
8
|
+
}
|
|
9
|
+
exports.literal = literal;
|
|
10
|
+
const jsonSchema = zod_1.z.lazy(() => zod_1.z.union([literal(), zod_1.z.array(jsonSchema), zod_1.z.record(jsonSchema)]));
|
|
11
|
+
function json() {
|
|
12
|
+
return jsonSchema;
|
|
13
|
+
}
|
|
14
|
+
exports.json = json;
|
|
15
|
+
exports.stringifiedJsonSchema = zod_1.z
|
|
16
|
+
.string()
|
|
17
|
+
.transform((str, ctx) => {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(str);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
ctx.addIssue({ code: "custom", message: "Invalid JSON" });
|
|
23
|
+
return zod_1.z.NEVER;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
function stringifiedJson() {
|
|
27
|
+
return exports.stringifiedJsonSchema;
|
|
28
|
+
}
|
|
29
|
+
exports.stringifiedJson = stringifiedJson;
|
|
30
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/json/json.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,MAAM,aAAa,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,OAAO,EAAE,EAAE,OAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAE/E,SAAgB,OAAO;IACrB,OAAO,aAAa,CAAC;AACvB,CAAC;AAFD,0BAEC;AAGD,MAAM,UAAU,GAAoB,OAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAC9C,OAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,OAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAChE,CAAC;AACF,SAAgB,IAAI;IAClB,OAAO,UAAU,CAAC;AACpB,CAAC;AAFD,oBAEC;AAEY,QAAA,qBAAqB,GAA0C,OAAC;KAC1E,MAAM,EAAE;KACR,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACtB,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAS,CAAC;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;QAC1D,OAAO,OAAC,CAAC,KAAK,CAAC;KAChB;AACH,CAAC,CAAC,CAAC;AAEL,SAAgB,eAAe;IAC7B,OAAO,6BAAqB,CAAC;AAC/B,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { Literal, Json } from "./json.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/json/types.ts"],"names":[],"mappings":""}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { json, jsonFromString } from "./json.js";
|
|
2
1
|
declare const zu: {
|
|
3
|
-
json:
|
|
4
|
-
|
|
2
|
+
json: {
|
|
3
|
+
(): import("zod").ZodType<import("./json/json.js").Json, import("zod").ZodTypeDef, import("./json/json.js").Json>;
|
|
4
|
+
stringified: typeof import("./json/json.js").stringifiedJson;
|
|
5
|
+
literal: typeof import("./json/json.js").literal;
|
|
6
|
+
};
|
|
5
7
|
};
|
|
6
8
|
export { zu };
|
package/lib/esm/index.js
CHANGED
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,MAAM,EAAE,GAAG;IACT,IAAI;CACL,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { literal, stringifiedJson } from "./json.js";
|
|
2
|
+
declare const module: {
|
|
3
|
+
(): import("zod").ZodType<import("./json.js").Json, import("zod").ZodTypeDef, import("./json.js").Json>;
|
|
4
|
+
stringified: typeof stringifiedJson;
|
|
5
|
+
literal: typeof literal;
|
|
6
|
+
};
|
|
7
|
+
export { module as json };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { json, literal, stringifiedJson } from "./json.js";
|
|
2
|
+
const module = (() => {
|
|
3
|
+
function module() {
|
|
4
|
+
return json();
|
|
5
|
+
}
|
|
6
|
+
module.stringified = stringifiedJson;
|
|
7
|
+
module.literal = literal;
|
|
8
|
+
return module;
|
|
9
|
+
})();
|
|
10
|
+
export { module as json };
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/json/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;IACnB,SAAS,MAAM;QACb,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IACD,MAAM,CAAC,WAAW,GAAG,eAAe,CAAC;IACrC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAEzB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,EAAE,CAAC;AAEL,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const literalSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
3
|
+
export type Literal = z.infer<typeof literalSchema>;
|
|
4
|
+
export declare function literal(): z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
5
|
+
export type Json = Literal | {
|
|
6
|
+
[key: string]: Json;
|
|
7
|
+
} | Json[];
|
|
8
|
+
export declare function json(): z.ZodType<Json, z.ZodTypeDef, Json>;
|
|
9
|
+
export declare const stringifiedJsonSchema: z.ZodType<Json, z.ZodTypeDef, string>;
|
|
10
|
+
export declare function stringifiedJson(): z.ZodType<Json, z.ZodTypeDef, string>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
3
|
+
export function literal() {
|
|
4
|
+
return literalSchema;
|
|
5
|
+
}
|
|
6
|
+
const jsonSchema = z.lazy(() => z.union([literal(), z.array(jsonSchema), z.record(jsonSchema)]));
|
|
7
|
+
export function json() {
|
|
8
|
+
return jsonSchema;
|
|
9
|
+
}
|
|
10
|
+
export const stringifiedJsonSchema = z
|
|
11
|
+
.string()
|
|
12
|
+
.transform((str, ctx) => {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(str);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
ctx.addIssue({ code: "custom", message: "Invalid JSON" });
|
|
18
|
+
return z.NEVER;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export function stringifiedJson() {
|
|
22
|
+
return stringifiedJsonSchema;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +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,aAAa,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;AAE/E,MAAM,UAAU,OAAO;IACrB,OAAO,aAAa,CAAC;AACvB,CAAC;AAGD,MAAM,UAAU,GAAoB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAC9C,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAChE,CAAC;AACF,MAAM,UAAU,IAAI;IAClB,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,MAAM,qBAAqB,GAA0C,CAAC;KAC1E,MAAM,EAAE;KACR,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACtB,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAS,CAAC;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,CAAC,KAAK,CAAC;KAChB;AACH,CAAC,CAAC,CAAC;AAEL,MAAM,UAAU,eAAe;IAC7B,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { Literal, Json } from "./json.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/json/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infra-blocks/zod-utils",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.4",
|
|
4
4
|
"description": "Extensions to the zod package.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./lib/esm/index.js",
|
|
11
|
+
"require": "./lib/cjs/index.js",
|
|
12
|
+
"default": "./lib/esm/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./json": {
|
|
15
|
+
"import": "./lib/esm/json/types.js",
|
|
16
|
+
"require": "./lib/cjs/json/types.js",
|
|
17
|
+
"default": "./lib/esm/json/types.js"
|
|
18
|
+
}
|
|
12
19
|
},
|
|
13
20
|
"files": [
|
|
14
21
|
"lib/**/*.{js,cjs,mjs,json,d.ts,map}"
|
package/lib/cjs/json.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
declare const LITERAL_SCHEMA: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
3
|
-
type Literal = z.infer<typeof LITERAL_SCHEMA>;
|
|
4
|
-
type Json = Literal | {
|
|
5
|
-
[key: string]: Json;
|
|
6
|
-
} | Json[];
|
|
7
|
-
export declare function json(): z.ZodType<Json, z.ZodTypeDef, Json>;
|
|
8
|
-
export declare function jsonFromString(): z.ZodType<Json, z.ZodTypeDef, string>;
|
|
9
|
-
export {};
|
package/lib/cjs/json.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jsonFromString = exports.json = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const LITERAL_SCHEMA = zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean(), zod_1.z.null()]);
|
|
6
|
-
const JSON_SCHEMA = zod_1.z.lazy(() => zod_1.z.union([LITERAL_SCHEMA, zod_1.z.array(JSON_SCHEMA), zod_1.z.record(JSON_SCHEMA)]));
|
|
7
|
-
function json() {
|
|
8
|
-
return JSON_SCHEMA;
|
|
9
|
-
}
|
|
10
|
-
exports.json = json;
|
|
11
|
-
const JSON_FROM_STRING_SCHEMA = zod_1.z
|
|
12
|
-
.string()
|
|
13
|
-
.transform((str, ctx) => {
|
|
14
|
-
try {
|
|
15
|
-
return JSON.parse(str);
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
ctx.addIssue({ code: "custom", message: "Invalid JSON" });
|
|
19
|
-
return zod_1.z.NEVER;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
function jsonFromString() {
|
|
23
|
-
return JSON_FROM_STRING_SCHEMA;
|
|
24
|
-
}
|
|
25
|
-
exports.jsonFromString = jsonFromString;
|
|
26
|
-
//# sourceMappingURL=json.js.map
|
package/lib/cjs/json.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/json.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,MAAM,cAAc,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,OAAO,EAAE,EAAE,OAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAIhF,MAAM,WAAW,GAAoB,OAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAC/C,OAAC,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,OAAC,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,OAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CACvE,CAAC;AACF,SAAgB,IAAI;IAClB,OAAO,WAAW,CAAC;AACrB,CAAC;AAFD,oBAEC;AAED,MAAM,uBAAuB,GAA0C,OAAC;KACrE,MAAM,EAAE;KACR,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACtB,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAS,CAAC;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;QAC1D,OAAO,OAAC,CAAC,KAAK,CAAC;KAChB;AACH,CAAC,CAAC,CAAC;AAEL,SAAgB,cAAc;IAC5B,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAFD,wCAEC"}
|
package/lib/esm/json.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
declare const LITERAL_SCHEMA: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
3
|
-
type Literal = z.infer<typeof LITERAL_SCHEMA>;
|
|
4
|
-
type Json = Literal | {
|
|
5
|
-
[key: string]: Json;
|
|
6
|
-
} | Json[];
|
|
7
|
-
export declare function json(): z.ZodType<Json, z.ZodTypeDef, Json>;
|
|
8
|
-
export declare function jsonFromString(): z.ZodType<Json, z.ZodTypeDef, string>;
|
|
9
|
-
export {};
|
package/lib/esm/json.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
const LITERAL_SCHEMA = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
3
|
-
const JSON_SCHEMA = z.lazy(() => z.union([LITERAL_SCHEMA, z.array(JSON_SCHEMA), z.record(JSON_SCHEMA)]));
|
|
4
|
-
export function json() {
|
|
5
|
-
return JSON_SCHEMA;
|
|
6
|
-
}
|
|
7
|
-
const JSON_FROM_STRING_SCHEMA = z
|
|
8
|
-
.string()
|
|
9
|
-
.transform((str, ctx) => {
|
|
10
|
-
try {
|
|
11
|
-
return JSON.parse(str);
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
ctx.addIssue({ code: "custom", message: "Invalid JSON" });
|
|
15
|
-
return z.NEVER;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
export function jsonFromString() {
|
|
19
|
-
return JSON_FROM_STRING_SCHEMA;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=json.js.map
|
package/lib/esm/json.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,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;AAIhF,MAAM,WAAW,GAAoB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAC/C,CAAC,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CACvE,CAAC;AACF,MAAM,UAAU,IAAI;IAClB,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,uBAAuB,GAA0C,CAAC;KACrE,MAAM,EAAE;KACR,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACtB,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAS,CAAC;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,CAAC,KAAK,CAAC;KAChB;AACH,CAAC,CAAC,CAAC;AAEL,MAAM,UAAU,cAAc;IAC5B,OAAO,uBAAuB,CAAC;AACjC,CAAC"}
|