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

Function _installLazyMethods

packages/zod/src/v4/classic/schemas.ts:34–68  ·  view source on GitHub ↗
(inst: T, group: string, methods: _LazyMethodsOf<T>)

Source from the content-addressed store, hash-verified

32}>;
33
34function _installLazyMethods<T extends object>(inst: T, group: string, methods: _LazyMethodsOf<T>): void {
35 const proto = Object.getPrototypeOf(inst);
36 let installed = _installedGroups.get(proto);
37 if (!installed) {
38 installed = new Set();
39 _installedGroups.set(proto, installed);
40 }
41 if (installed.has(group)) return;
42 installed.add(group);
43 for (const key in methods) {
44 const fn = methods[key]!;
45 Object.defineProperty(proto, key, {
46 configurable: true,
47 enumerable: false,
48 get(this: any) {
49 const bound = fn.bind(this);
50 Object.defineProperty(this, key, {
51 configurable: true,
52 writable: true,
53 enumerable: true,
54 value: bound,
55 });
56 return bound;
57 },
58 set(this: any, v: unknown) {
59 Object.defineProperty(this, key, {
60 configurable: true,
61 writable: true,
62 enumerable: true,
63 value: v,
64 });
65 },
66 });
67 }
68}
69
70///////////////////////////////////////////
71///////////////////////////////////////////

Callers 1

schemas.tsFile · 0.85

Calls 3

getMethod · 0.80
hasMethod · 0.80
addMethod · 0.80

Tested by

no test coverage detected