@traversable/schema
    Preparing search index...

    Function deepReadonly

    • Converts an arbitrary zod schema into its "deeply-readonly" form.

      That just means that the schema will be traversed, and wrap all z.object z.object properties with z.readonly z.readonly.

      Any properties that were already readonly will be left as-is, since re-wrapping again doesn't do much besides make the schema's type harder to read.

      zx.deepReadonly's behavior is configurable at the typelevel via the defaults.typelevel options.typelevel property:

      • defaults.typelevel "semantic" (default): leave the schema untouched, but wrap it in a no-op interface (deepReadonly.Semantic) to make things explicit

      • defaults.typelevel "applyToTypesOnly": apply the transformation to the schema's output type and wrap it in z.ZodType z.ZodType

      • defaults.typelevel "preserveSchemaType": zx.deepReadonly will return what it got, type untouched

      Type Parameters

      • T extends
            | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
            | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

      Parameters

      • type: T
      • options: "preserveSchemaType"

      Returns T

      import * as vi from "vitest"
      import { z } from "zod"
      import { zx } from "@traversable/zod"

      // Using `zx.deepReadonly.writeable` here to make it easier to visualize `zx.deepReadonly`'s behavior:
      vi.expect.soft(zx.deepReadonly.writeable(
      z.object({
      a: z.number(),
      b: z.readonly(z.string()),
      c: z.object({
      d: z.array(z.object({
      e: z.number().max(1),
      f: z.boolean()
      })).length(10)
      })
      })
      )).toMatchInlineSnapshot
      (`
      "z.object({
      a: z.number().readonly(),
      b: z.string().readonly(),
      c: z.object({
      d: z.array(z.object({
      e: z.number().max(1).readonly(),
      f: z.boolean().readonly()
      })).length(10).readonly()
      }).readonly()
      })"
      `)
    • Converts an arbitrary zod schema into its "deeply-readonly" form.

      That just means that the schema will be traversed, and wrap all z.object z.object properties with z.readonly z.readonly.

      Any properties that were already readonly will be left as-is, since re-wrapping again doesn't do much besides make the schema's type harder to read.

      zx.deepReadonly's behavior is configurable at the typelevel via the defaults.typelevel options.typelevel property:

      • defaults.typelevel "semantic" (default): leave the schema untouched, but wrap it in a no-op interface (deepReadonly.Semantic) to make things explicit

      • defaults.typelevel "applyToTypesOnly": apply the transformation to the schema's output type and wrap it in z.ZodType z.ZodType

      • defaults.typelevel "preserveSchemaType": zx.deepReadonly will return what it got, type untouched

      Type Parameters

      • T extends
            | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
            | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

      Parameters

      • type: T
      • options: "applyToOutputType"

      Returns ZodType<deepReadonly<output<T>, Function | RegExp | Date>>

      import * as vi from "vitest"
      import { z } from "zod"
      import { zx } from "@traversable/zod"

      // Using `zx.deepReadonly.writeable` here to make it easier to visualize `zx.deepReadonly`'s behavior:
      vi.expect.soft(zx.deepReadonly.writeable(
      z.object({
      a: z.number(),
      b: z.readonly(z.string()),
      c: z.object({
      d: z.array(z.object({
      e: z.number().max(1),
      f: z.boolean()
      })).length(10)
      })
      })
      )).toMatchInlineSnapshot
      (`
      "z.object({
      a: z.number().readonly(),
      b: z.string().readonly(),
      c: z.object({
      d: z.array(z.object({
      e: z.number().max(1).readonly(),
      f: z.boolean().readonly()
      })).length(10).readonly()
      }).readonly()
      })"
      `)
    • Converts an arbitrary zod schema into its "deeply-readonly" form.

      That just means that the schema will be traversed, and wrap all z.object z.object properties with z.readonly z.readonly.

      Any properties that were already readonly will be left as-is, since re-wrapping again doesn't do much besides make the schema's type harder to read.

      zx.deepReadonly's behavior is configurable at the typelevel via the defaults.typelevel options.typelevel property:

      • defaults.typelevel "semantic" (default): leave the schema untouched, but wrap it in a no-op interface (deepReadonly.Semantic) to make things explicit

      • defaults.typelevel "applyToTypesOnly": apply the transformation to the schema's output type and wrap it in z.ZodType z.ZodType

      • defaults.typelevel "preserveSchemaType": zx.deepReadonly will return what it got, type untouched

      Type Parameters

      • T extends
            | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
            | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

      Parameters

      • type: T
      • options: "semantic"

      Returns deepReadonly.Semantic<T>

      import * as vi from "vitest"
      import { z } from "zod"
      import { zx } from "@traversable/zod"

      // Using `zx.deepReadonly.writeable` here to make it easier to visualize `zx.deepReadonly`'s behavior:
      vi.expect.soft(zx.deepReadonly.writeable(
      z.object({
      a: z.number(),
      b: z.readonly(z.string()),
      c: z.object({
      d: z.array(z.object({
      e: z.number().max(1),
      f: z.boolean()
      })).length(10)
      })
      })
      )).toMatchInlineSnapshot
      (`
      "z.object({
      a: z.number().readonly(),
      b: z.string().readonly(),
      c: z.object({
      d: z.array(z.object({
      e: z.number().max(1).readonly(),
      f: z.boolean().readonly()
      })).length(10).readonly()
      }).readonly()
      })"
      `)
    • Converts an arbitrary zod schema into its "deeply-readonly" form.

      That just means that the schema will be traversed, and wrap all z.object z.object properties with z.readonly z.readonly.

      Any properties that were already readonly will be left as-is, since re-wrapping again doesn't do much besides make the schema's type harder to read.

      zx.deepReadonly's behavior is configurable at the typelevel via the defaults.typelevel options.typelevel property:

      • defaults.typelevel "semantic" (default): leave the schema untouched, but wrap it in a no-op interface (deepReadonly.Semantic) to make things explicit

      • defaults.typelevel "applyToTypesOnly": apply the transformation to the schema's output type and wrap it in z.ZodType z.ZodType

      • defaults.typelevel "preserveSchemaType": zx.deepReadonly will return what it got, type untouched

      Type Parameters

      • T extends
            | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
            | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

      Parameters

      • type: T

      Returns deepReadonly.Semantic<T>

      import * as vi from "vitest"
      import { z } from "zod"
      import { zx } from "@traversable/zod"

      // Using `zx.deepReadonly.writeable` here to make it easier to visualize `zx.deepReadonly`'s behavior:
      vi.expect.soft(zx.deepReadonly.writeable(
      z.object({
      a: z.number(),
      b: z.readonly(z.string()),
      c: z.object({
      d: z.array(z.object({
      e: z.number().max(1),
      f: z.boolean()
      })).length(10)
      })
      })
      )).toMatchInlineSnapshot
      (`
      "z.object({
      a: z.number().readonly(),
      b: z.string().readonly(),
      c: z.object({
      d: z.array(z.object({
      e: z.number().max(1).readonly(),
      f: z.boolean().readonly()
      })).length(10).readonly()
      }).readonly()
      })"
      `)