From 143886151bba3930bdcc10d34a1cff4bf9103ba8 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Thu, 2 May 2024 17:00:35 -0700 Subject: [PATCH] Add copper tier (#3460) * Copper tier * Update --- README.md | 52 +++++++++++++-------------- deno/lib/README.md | 55 ++++++++++++++--------------- deno/lib/__tests__/readonly.test.ts | 50 ++++++++++++++++++++++++++ deno/lib/types.ts | 13 ++++--- 4 files changed, 111 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index a8bee663f..89877cc8e 100644 --- a/README.md +++ b/README.md @@ -284,11 +284,6 @@ Sponsorship at any level is appreciated and encouraged. For individual developer #### Bronze - - @@ -298,34 +293,37 @@ each td should contain a ul - - - + +
Numeric
Bamboo CreativeBrandon BayerJiří BrabecAlex Johansson
+ +#### Copper + + + + + + + + + + + + + - - - - + + + + - + + + +
Brandon BayerJiří BrabecAlex JohanssonFungible Systems
AdaptableAvana WalletJason LengstorfGlobal Illumination, Inc.
Learn with JasonRyan PalmerMichael SweeneyConnor SinnottMasterBornRyan PalmerMichael SweeneyNextbase
Mohammad-Ali A'râbiRemotionConnor SinnottMohammad-Ali A'râbiSupatool
- ### Ecosystem diff --git a/deno/lib/README.md b/deno/lib/README.md index fe8f1d4d5..89877cc8e 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -284,11 +284,6 @@ Sponsorship at any level is appreciated and encouraged. For individual developer #### Bronze - - @@ -298,34 +293,37 @@ each td should contain a ul - - - + +
Numeric
Bamboo CreativeBrandon BayerJiří BrabecAlex Johansson
+ +#### Copper + + + + + + + + + + + + + - - - - + + + + - + + + +
Brandon BayerJiří BrabecAlex JohanssonFungible Systems
AdaptableAvana WalletJason LengstorfGlobal Illumination, Inc.
Learn with JasonRyan PalmerMichael SweeneyConnor SinnottMasterBornRyan PalmerMichael SweeneyNextbase
Mohammad-Ali A'râbiRemotionConnor SinnottMohammad-Ali A'râbiSupatool
- ### Ecosystem @@ -417,6 +415,7 @@ There are a growing number of tools that are built atop or support Zod natively! #### Utilities for Zod - [`zod_utilz`](https://github.com/JacobWeisenburger/zod_utilz): Framework agnostic utilities for Zod. +- [`zod-playground`](https://github.com/marilari88/zod-playground): A tool for learning and testing Zod schema validation functionalities. [Link](https://zod-playground.vercel.app/). - [`zod-sandbox`](https://github.com/nereumelo/zod-sandbox): Controlled environment for testing zod schemas. [Live demo](https://zod-sandbox.vercel.app/). - [`zod-dev`](https://github.com/schalkventer/zod-dev): Conditionally disables Zod runtime parsing in production. - [`zod-accelerator`](https://github.com/duplojs/duplojs-zod-accelerator): Accelerates Zod's throughput up to ~100x. @@ -2445,7 +2444,7 @@ Note that branded types do not affect the runtime result of `.parse`. It is a st This method returns a `ZodReadonly` schema instance that parses the input using the base schema, then calls `Object.freeze()` on the result. The inferred type is also marked as `readonly`. ```ts -const schema = z.object({ name: string }).readonly(); +const schema = z.object({ name: z.string() }).readonly(); type schema = z.infer; // Readonly<{name: string}> diff --git a/deno/lib/__tests__/readonly.test.ts b/deno/lib/__tests__/readonly.test.ts index 27d2e0c9c..bd1d4cdf2 100644 --- a/deno/lib/__tests__/readonly.test.ts +++ b/deno/lib/__tests__/readonly.test.ts @@ -203,3 +203,53 @@ test("object freezing", () => { ) ).toBe(true); }); + +test("async object freezing", async () => { + expect( + Object.isFrozen(await z.array(z.string()).readonly().parseAsync(["a"])) + ).toBe(true); + expect( + Object.isFrozen( + await z.tuple([z.string(), z.number()]).readonly().parseAsync(["a", 1]) + ) + ).toBe(true); + expect( + Object.isFrozen( + await z + .map(z.string(), z.date()) + .readonly() + .parseAsync(new Map([["a", new Date()]])) + ) + ).toBe(true); + expect( + Object.isFrozen( + await z + .set(z.promise(z.string())) + .readonly() + .parseAsync(new Set([Promise.resolve("a")])) + ) + ).toBe(true); + expect( + Object.isFrozen( + await z.record(z.string()).readonly().parseAsync({ a: "b" }) + ) + ).toBe(true); + expect( + Object.isFrozen( + await z.record(z.string(), z.number()).readonly().parseAsync({ a: 1 }) + ) + ).toBe(true); + expect( + Object.isFrozen( + await z + .object({ a: z.string(), 1: z.number() }) + .readonly() + .parseAsync({ a: "b", 1: 2 }) + ) + ).toBe(true); + expect( + Object.isFrozen( + await z.promise(z.string()).readonly().parseAsync(Promise.resolve("a")) + ) + ).toBe(true); +}); diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 199d1eafe..c1364a9b5 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -5041,10 +5041,15 @@ export class ZodReadonly extends ZodType< > { _parse(input: ParseInput): ParseReturnType { const result = this._def.innerType._parse(input); - if (isValid(result)) { - result.value = Object.freeze(result.value); - } - return result; + const freeze = (data: ParseReturnType) => { + if (isValid(data)) { + data.value = Object.freeze(data.value); + } + return data; + }; + return isAsync(result) + ? result.then((data) => freeze(data)) + : freeze(result); } static create = (