@infra-blocks/zod-utils 0.1.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.
- package/README.md +30 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/json.d.ts +9 -0
- package/lib/json.js +21 -0
- package/lib/json.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ts-lib-template
|
|
2
|
+
[](https://github.com/infrastructure-blocks/ts-zod-utils/actions/workflows/build.yml)
|
|
3
|
+
[](https://github.com/infrastructure-blocks/ts-zod-utils/actions/workflows/npm-publish-release-from-label.yml)
|
|
4
|
+
[](https://github.com/infrastructure-blocks/ts-zod-utils/actions/workflows/update-from-template.yml)
|
|
5
|
+
[](https://codecov.io/gh/infrastructure-blocks/ts-zod-utils)
|
|
6
|
+
|
|
7
|
+
This package exposes various utilities extending the [zod](https://www.npmjs.com/package/zod) package.
|
|
8
|
+
|
|
9
|
+
## Development
|
|
10
|
+
|
|
11
|
+
### Repo init
|
|
12
|
+
|
|
13
|
+
This repository leverages [nvm](https://github.com/nvm-sh/nvm) and users should have it installed in their local environment.
|
|
14
|
+
In addition, it is recommended that users install a [shell hook](https://github.com/nvm-sh/nvm#deeper-shell-integration)
|
|
15
|
+
so that `nvm use` is run upon changing into a project that utilises `nvm`.
|
|
16
|
+
|
|
17
|
+
Upon checking out the repository, run the following commands:
|
|
18
|
+
```shell
|
|
19
|
+
nvm install
|
|
20
|
+
npm install
|
|
21
|
+
npm run compile
|
|
22
|
+
npm run lint
|
|
23
|
+
npm run test
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Package publication
|
|
27
|
+
|
|
28
|
+
Package publication is fully automated at the CI level. This repository leverages the
|
|
29
|
+
[npm-publish-from-label-workflow](https://github.com/infrastructure-blocks/npm-publish-from-label-workflow)
|
|
30
|
+
workflow as a turnkey, automated mechanism for publishing packages. Refer to its documentation for usage information.
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,EAAE,GAAG;IACT,IAAI;IACJ,cAAc;CACf,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,CAAC"}
|
package/lib/json.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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/json.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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/json.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@infra-blocks/zod-utils",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Extensions to the zod package.",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": "./lib/index.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"lib/**/*.{js,d.ts,map}"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "npm run clean && tsc --project tsconfig.build.json",
|
|
14
|
+
"clean": "rm -rf lib && rm -f infra-blocks-*.tgz",
|
|
15
|
+
"compile": "tsc",
|
|
16
|
+
"lint": "eslint --ext .js,.cjs,.mjs,.json,.ts --max-warnings 0 .",
|
|
17
|
+
"prepack": "npm run build",
|
|
18
|
+
"test": "npm run test:unit",
|
|
19
|
+
"test:coverage": "c8 npm run test",
|
|
20
|
+
"test:coverage:lcov": "c8 --reporter=lcov npm run test",
|
|
21
|
+
"test:integration": "mocha --config test/integration/.mocharc.js 'test/integration/**/*.spec.ts'",
|
|
22
|
+
"test:unit": "mocha --config test/unit/.mocharc.cjs 'test/unit/**/*.spec.ts'"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"zod": "^3.22.4"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@infra-blocks/test": "^0.1.1",
|
|
29
|
+
"@types/mocha": "^10.0.1",
|
|
30
|
+
"@types/node": "^20.10.3",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
|
32
|
+
"@typescript-eslint/parser": "^5.59.8",
|
|
33
|
+
"c8": "^8.0.0",
|
|
34
|
+
"eslint": "^8.41.0",
|
|
35
|
+
"eslint-config-prettier": "^8.8.0",
|
|
36
|
+
"eslint-plugin-json-format": "^2.0.1",
|
|
37
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
38
|
+
"mocha": "^10.2.0",
|
|
39
|
+
"prettier": "^2.8.8",
|
|
40
|
+
"ts-node": "^10.9.1",
|
|
41
|
+
"typescript": "^5.0.4"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
}
|
|
46
|
+
}
|