Skip to content
Français

defineJsonArtifact

import { defineJsonArtifact } from "@elie-laloum/outpost";

Declare a named, versioned contract for a lossless JSON value; schema validates it on publish and again on read. Throws when name or version is empty or longer than 1024 characters.

Complete example and detailed rules.

  • optionsRequired
    JsonArtifactOptions<T>
    Contract name, version and the schema applied on publish and on read.
  • options.nameRequired
    string
    Contract name, nonempty and at most 1024 characters. A read requires the same name.
  • options.versionRequired
    string
    Contract version you choose, nonempty and at most 1024 characters. A read requires the same version, so change it when the format changes.
  • options.schemaRequired
    StandardValidator<T> | ((input: unknown) => T | Promise<T>)
    Standard Schema validator (Zod, Valibot…) or a function that returns the checked value or throws. Runs before encoding and after decoding; its output is the value stored and returned.

ArtifactContract<T>

export declare function defineJsonArtifact<T>(
  options: JsonArtifactOptions<T>,
): ArtifactContract<T>;