/ utils / lazySchema.ts
lazySchema.ts
1  /**
2   * Returns a memoized factory function that constructs the value on first call.
3   * Used to defer Zod schema construction from module init time to first access.
4   */
5  export function lazySchema<T>(factory: () => T): () => T {
6    let cached: T | undefined
7    return () => (cached ??= factory())
8  }