Skip to content

Commit

Permalink
Merge branch 'colinhacks:master' into template-literal
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov authored Aug 7, 2023
2 parents b949f2a + 1ecd624 commit e2ba25f
Show file tree
Hide file tree
Showing 31 changed files with 453 additions and 462 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ deno/lib/playground.ts
.eslintcache
workspace.code-workspace
.netlify
bun.lockb
48 changes: 36 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
<a href="https://proxy.com">proxy.com</a>
</td>
</tr>
<tr>
<tr>
<td align="center">
<a href="https://trigger.dev/">
<img src="https://avatars.githubusercontent.com/u/95297378?s=200&v=4" width="200px;" alt="Trigger.dev logo" />
Expand All @@ -257,6 +257,19 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
<p>Simple file processing for developers.</p>
</td>
</tr>
<tr>
<td align="center">
<a href="https://infisical.com">
<img src="https://avatars.githubusercontent.com/u/107880645?s=200&v=4" width="200px;" alt="Infisical logo" />
</a>
<br />
<b>Infisical</b>
<br />
<a href="https://infisical.com">infisical.com</a>
<br/>
<p>Open-source platform for secret<br/>management: sync secrets across your<br/>team/infrastructure and prevent secret leaks.</p>
</td>
</tr>
</table>

#### Silver
Expand Down Expand Up @@ -393,7 +406,7 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
</td>
</tr>
<tr>
<td align="center">
<td align="center">
<a href="https://learnwithjason.dev">
<img src="https://avatars.githubusercontent.com/u/66575486?s=200&v=4" width="100px;" alt="Learn with Jason logo"/>
</a>
Expand Down Expand Up @@ -448,6 +461,7 @@ There are a growing number of tools that are built atop or support Zod natively!

#### Form integrations

- [`conform`](https://conform.guide/api/zod): A progressive enhancement first form validation library for Remix and React Router
- [`react-hook-form`](https://github.com/react-hook-form/resolvers#zod): A first-party Zod resolver for React Hook Form.
- [`zod-validation-error`](https://github.com/causaly/zod-validation-error): Generate user-friendly error messages from `ZodError`s.
- [`zod-formik-adapter`](https://github.com/robertLichtnow/zod-formik-adapter): A community-maintained Formik adapter for Zod.
Expand All @@ -459,7 +473,8 @@ There are a growing number of tools that are built atop or support Zod natively!
- [`@modular-forms/solid`](https://github.com/fabian-hiller/modular-forms): Modular form library for SolidJS that supports Zod for validation.
- [`houseform`](https://github.com/crutchcorn/houseform/): A React form library that uses Zod for validation.
- [`sveltekit-superforms`](https://github.com/ciscoheat/sveltekit-superforms): Supercharged form library for SvelteKit with Zod validation.
- [`mobx-zod-form`](https://github.com/MonoidDev/mobx-zod-form): Data-first form builder based on MobX & Zod
- [`mobx-zod-form`](https://github.com/MonoidDev/mobx-zod-form): Data-first form builder based on MobX & Zod.
- [`@vee-validate/zod`](https://github.com/logaretm/vee-validate/tree/main/packages/zod): Form library for Vue.js with Zod schema validation.

#### Zod to X

Expand All @@ -471,7 +486,8 @@ There are a growing number of tools that are built atop or support Zod natively!
- [`fastify-type-provider-zod`](https://github.com/turkerdev/fastify-type-provider-zod): Create Fastify type providers from Zod schemas.
- [`zod-to-openapi`](https://github.com/asteasolutions/zod-to-openapi): Generate full OpenAPI (Swagger) docs from Zod, including schemas, endpoints & parameters.
- [`nestjs-graphql-zod`](https://github.com/incetarik/nestjs-graphql-zod): Generates NestJS GraphQL model classes from Zod schemas. Provides GraphQL method decorators working with Zod schemas.
- [`zod-openapi`](https://github.com/samchungy/zod-openapi): Create full OpenAPI v3.x documentation from Zod Schemas.
- [`zod-openapi`](https://github.com/samchungy/zod-openapi): Create full OpenAPI v3.x documentation from Zod schemas.
- [`fastify-zod-openapi`](https://github.com/samchungy/fastify-zod-openapi): Fastify type provider, validation, serialization and @fastify/swagger support for Zod schemas.

#### X to Zod

Expand All @@ -496,6 +512,7 @@ There are a growing number of tools that are built atop or support Zod natively!

#### Powered by Zod

- [`freerstore`](https://github.com/JacobWeisenburger/freerstore): Firestore cost optimizer.
- [`slonik`](https://github.com/gajus/slonik/tree/gajus/add-zod-validation-backwards-compatible#runtime-validation-and-static-type-inference): Node.js Postgres client with strong Zod integration.
- [`soly`](https://github.com/mdbetancourt/soly): Create CLI applications with zod.
- [`zod-xlsx`](https://github.com/sidwebworks/zod-xlsx): A xlsx based resource validator using Zod schemas.
Expand Down Expand Up @@ -1190,7 +1207,7 @@ Starting from this object:
```ts
const user = z.object({
email: z.string()
email: z.string(),
username: z.string(),
});
// { email: string; username: string }
Expand Down Expand Up @@ -1254,10 +1271,12 @@ Contrary to the `.partial` method, the `.required` method makes all properties r
Starting from this object:
```ts
const user = z.object({
email: z.string()
username: z.string(),
}).partial();
const user = z
.object({
email: z.string(),
username: z.string(),
})
.partial();
// { email?: string | undefined; username?: string | undefined }
```
Expand Down Expand Up @@ -1511,6 +1530,12 @@ type NumberCache = z.infer<typeof NumberCache>;
This is particularly useful for storing or caching items by ID.
```ts
const userSchema = z.object({ name: z.string() });
const userStoreSchema = z.record(userSchema);

type UserStore = z.infer<typeof userStoreSchema>;
// => type UserStore = { [ x: string ]: { name: string } }

const userStore: UserStore = {};

userStore["77d2586b-9e8e-4ecf-8b21-ea7e0530eadd"] = {
Expand Down Expand Up @@ -2459,7 +2484,7 @@ A convenience method that returns a "nullish" version of a schema. Nullish schem
const nullishString = z.string().nullish(); // string | null | undefined

// equivalent to
z.string().optional().nullable();
z.string().nullable().optional();
```

### `.array`
Expand Down Expand Up @@ -2825,7 +2850,6 @@ Yup is a full-featured library that was implemented first in vanilla JS, and lat

- Supports casting and transforms
- All object fields are optional by default
- Missing object methods: (partial, deepPartial)
<!-- - Missing nonempty arrays with proper typing (`[T, ...T[]]`) -->
- Missing promise schemas
- Missing function schemas
Expand Down Expand Up @@ -2888,7 +2912,7 @@ This more declarative API makes schema definitions vastly more concise.

[https://github.com/pelotom/runtypes](https://github.com/pelotom/runtypes)

Good type inference support, but limited options for object type masking (no `.pick` , `.omit` , `.extend` , etc.). No support for `Record` s (their `Record` is equivalent to Zod's `object` ). They DO support readonly types, which Zod does not.
Good type inference support. They DO support readonly types, which Zod does not.

- Supports "pattern matching": computed properties that distribute over unions
- Supports readonly types
Expand Down
8 changes: 7 additions & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,12 @@ type NumberCache = z.infer<typeof NumberCache>;
这对于按 ID 存储或缓存项目特别有用。

```ts
const userSchema = z.object({ name: z.string() });
const userStoreSchema = z.record(userSchema);

type UserStore = z.infer<typeof userStoreSchema>;
// => type UserStore = { [ x: string ]: { name: string } }

const userStore: UserStore = {};

userStore["77d2586b-9e8e-4ecf-8b21-ea7e0530eadd"] = {
Expand Down Expand Up @@ -1617,7 +1623,7 @@ z.nullable(z.string());
const nullishString = z.string().nullish(); // string | null | undefined

// equivalent to
z.string().optional().nullable();
z.string().nullable().optional();
```

### `.array`
Expand Down
Binary file removed bun.lockb
Binary file not shown.
10 changes: 10 additions & 0 deletions configs/babel-jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rootDir": "..",
"testRegex": "src/.*\\.test\\.ts$",
"transform": {
"^.+\\.tsx?$": ["babel-jest", { "configFile": "./configs/babel.config.js" }]
},
"modulePathIgnorePatterns": ["language-server", "__vitest__"],
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"coverageReporters": ["json-summary", "text", "lcov"]
}
6 changes: 6 additions & 0 deletions configs/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
10 changes: 10 additions & 0 deletions configs/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rootDir": "..",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "src/.*\\.test\\.ts$",
"modulePathIgnorePatterns": ["language-server", "__vitest__"],
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"coverageReporters": ["json-summary", "text", "lcov"]
}
2 changes: 1 addition & 1 deletion rollup.config.js → configs/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default [
],
plugins: [
typescript({
tsconfig: "tsconfig.esm.json",
tsconfig: "./configs/tsconfig.esm.json",
sourceMap: false,
}),
],
Expand Down
10 changes: 10 additions & 0 deletions configs/swc-jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rootDir": "..",
"transform": {
"^.+\\.(t|j)sx?$": "@swc/jest"
},
"testRegex": "src/.*\\.test\\.ts$",
"modulePathIgnorePatterns": ["language-server", "__vitest__"],
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"coverageReporters": ["json-summary", "text", "lcov"]
}
10 changes: 10 additions & 0 deletions configs/ts-jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rootDir": "..",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "src/.*\\.test\\.ts$",
"modulePathIgnorePatterns": ["language-server", "__vitest__"],
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"coverageReporters": ["json-summary", "text", "lcov"]
}
16 changes: 3 additions & 13 deletions tsconfig.base.json → configs/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"compilerOptions": {
"lib": [
"es5",
"es6",
"es7",
"esnext",
"dom"
],
"lib": ["es5", "es6", "es7", "esnext", "dom"],
"target": "es2018",
"removeComments": false,
"esModuleInterop": true,
Expand All @@ -22,9 +16,5 @@
"downlevelIteration": true,
"isolatedModules": true
},
"include": [
"./src/**/*",
"playground.ts",
"./.eslintrc.js"
]
}
"include": ["../src/**/*", "../playground.ts", "../.eslintrc.js"]
}
9 changes: 3 additions & 6 deletions tsconfig.cjs.json → configs/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "lib",
"outDir": "../lib",
"declaration": true,
"declarationMap": false,
"sourceMap": false,
"removeComments": true
},
"exclude": [
"./src/**/__tests__",
"playground.ts"
]
}
"exclude": ["../src/**/__tests__", "../playground.ts"]
}
5 changes: 1 addition & 4 deletions tsconfig.esm.json → configs/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
"declarationMap": false,
"sourceMap": false
},
"exclude": [
"./src/**/__tests__",
"./src/playground.ts"
]
"exclude": ["../src/**/__tests__", "../src/playground.ts"]
}
3 changes: 2 additions & 1 deletion tsconfig.test.json → configs/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"target": "es5",
"declaration": true,
"declarationMap": false,
"sourceMap": false
"sourceMap": false,
"noEmit": true
},
"exclude": []
}
7 changes: 2 additions & 5 deletions tsconfig.types.json → configs/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib/types",
"outDir": "../lib/types",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true
},
"exclude": [
"./src/**/__tests__",
"./src/playground.ts"
]
"exclude": ["../src/**/__tests__", "../src/playground.ts"]
}
12 changes: 12 additions & 0 deletions configs/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
alias: {
"@jest/globals": "vitest",
},
include: ["src/**/*.test.ts"],
isolate: false,
watch: false,
},
});
4 changes: 2 additions & 2 deletions deno/build.mjs → deno-build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const denoLibRoot = join(projectRoot, "deno", "lib");

const skipList = [
join(nodeSrcRoot, "__tests__", "object-in-es5-env.test.ts"),
join(nodeSrcRoot, "__tests__", "languageServerFeatures.test.ts"),
join(nodeSrcRoot, "__tests__", "languageServerFeatures.source.ts"),
join(nodeSrcRoot, "__tests__", "language-server.test.ts"),
join(nodeSrcRoot, "__tests__", "language-server.source.ts"),
];
const walkAndBuild = (/** @type string */ dir) => {
for (const entry of readdirSync(join(nodeSrcRoot, dir), {
Expand Down
Loading

0 comments on commit e2ba25f

Please sign in to comment.