MCPcopy
hub / github.com/colinhacks/zod / ZodReadonly

Class ZodReadonly

packages/zod/src/v3/types.ts:4872–4899  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4870}
4871
4872export class ZodReadonly<T extends ZodTypeAny> extends ZodType<
4873 MakeReadonly<T["_output"]>,
4874 ZodReadonlyDef<T>,
4875 MakeReadonly<T["_input"]>
4876> {
4877 _parse(input: ParseInput): ParseReturnType<this["_output"]> {
4878 const result = this._def.innerType._parse(input);
4879 const freeze = (data: ParseReturnType<this["_output"]>) => {
4880 if (isValid(data)) {
4881 data.value = Object.freeze(data.value);
4882 }
4883 return data;
4884 };
4885 return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
4886 }
4887
4888 static create = <Inner extends ZodTypeAny>(type: Inner, params?: RawCreateParams): ZodReadonly<Inner> => {
4889 return new ZodReadonly({
4890 innerType: type,
4891 typeName: ZodFirstPartyTypeKind.ZodReadonly,
4892 ...processCreateParams(params),
4893 }) as any;
4894 };
4895
4896 unwrap() {
4897 return this._def.innerType;
4898 }
4899}
4900
4901////////////////////////////////////////
4902////////////////////////////////////////

Callers

nothing calls this directly

Calls 1

processCreateParamsFunction · 0.85

Tested by

no test coverage detected