Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Standard Schema: スキーマライブラリの統一企画とは何か

Standard Schema: スキーマライブラリの統一企画とは何か

TSKaigi 2025 の登壇資料です

Avatar for Nozomu Ikuta

Nozomu Ikuta

May 24, 2025
Tweet

More Decks by Nozomu Ikuta

Other Decks in Technology

Transcript

  1. Tierͷߟ͑ํ Tier 1 : ͜ΕΛࣺͯΔ࣌͸ίʔυΛҰ͔Β ॻ͖௚֮͢ޛΛ࣋ͭʮ৺த͢Δʯ૬ख Tier 2 : ࠩ͠ସ͑ʹ͸େ͖ͳ࿑ྗΛඞཁͱ

    ͢Δʮڧ͘ґଘ͢Δʯ૬ख Tier 3 : ͍ͣΕࠩ͠ସ͑Δ͜ͱΛ૝ఆͨ͠ ʮґଘΛܰ͘͢Δʯ૬ख Communication Design 32 Modular Monolith Monorepo ~ γϯϓϧ͞Λอͪͳ͕ΒmonorepoͷϝϦοτΛ࠷େԽ͢Δ ~ JSConf 2024 ΑΓ
  2. interface StandardSchemaV1<Input = unknown, Output = Input> { readonly '~standard':

    StandardSchemaV1.Props<Input, Output>; } export declare namespace StandardSchemaV1 { // ϓϩύςΟఆٛ
 } • APIίϯϑϦΫτճආͷͨΊ `~standard` ϓϩύςΟ഑Լʹ͢΂ͯఆٛ͢Δ
  3. interface Props<Input = unknown, Output = Input> { readonly version:

    1; readonly vendor: string; readonly validate: ( value: unknown ) => Result<Output> | Promise<Result<Output>>; readonly types?: Types<Input, Output> | unde fi ned; } • όϦσʔγϣϯؔ਺ • εΩʔϚͷܕਪ࿦
  4. type Result<Output> = SuccessResult<Output> | FailureResult; interface SuccessResult<Output> { readonly

    value: Output; readonly issues?: unde fi ned; } interface FailureResult { readonly issues: ReadonlyArray<Issue>; } • όϦσʔγϣϯͷResultܕ • Τϥʔ͸issuesͱ͍͏഑ྻͰදݱ͢Δ
  5. interface Issue { readonly message: string; readonly path?: ReadonlyArray<PropertyKey |

    PathSegment> | unde fi ned; } interface PathSegment { readonly key: PropertyKey; } • όϦσʔγϣϯΤϥʔ • ͻͱͭͷΤϥʔ͸ϝοηʔδͱϓϩύςΟΩʔͰදݱ͢Δ
  6. interface Types<Input = unknown, Output = Input> { readonly input:

    Input; readonly output: Output; } type InferInput<Schema extends StandardSchemaV1> = NonNullable< Schema['~standard']['types'] >['input']; type InferOutput<Schema extends StandardSchemaV1> = NonNullable< Schema['~standard']['types'] >['output']; • εΩʔϚͷܕਪ࿦
  7. ࢀߟจݙ • https://github.com/standard-schema • https://github.com/colinhacks/zod • https://github.com/fabian-hiller/valibot • https://github.com/arktypeio/arktype •

    https://speakerdeck.com/yuisakamoto/modular-monolith-monorepo- sinpurusawobao-tinagaramonoreponomeritutowozui-da-hua-suru