untyped icon indicating copy to clipboard operation
untyped copied to clipboard

rewamp untyped into a runtime-friendly lib

Open pi0 opened this issue 11 months ago • 3 comments

Background

Back in time I was developing the untyped library, the idea was to make a unified (build-time) solution to merge type and runtime validation from one source with little or no extra code and use JSON Schema as a unified schema format mainly for handling nuxt config schema.

Currently untyped:

  • Is designed as a build-time utility
  • Uses a superset of JSON Schema for scheme definitions
  • Can Transform source to combine JSDocs and runtime validator into one schema
  • Can Generate TypeScript types and markdown from schema
  • Can normalize an input object with schema and defaults
  • Supports both object schema and function schema

However, it has some limitations:

  • It is not designed with minimum bundle impact to be a runtime library
  • Does not provide convenience API to define the schema (previous proposal: #91)
  • Cannot directly infer typescript types from schema without a build step
  • Does not provide compatibility with other schema validation libraries
  • Does not provide utils uses for validating schema

Future Vision

Untyped should:

  • Provide an (end) user-friendly DX to easily define and validate the schema
  • Be runtime-friendly with minimum bundle impact
  • Provide a way for compatibility with other schema validation libraries
  • Use a unified schema object for validation and definitions

At this point, I am not sure how to make the perfect solution to meet the above criteria. I might also end-up with making a new library if not fitting for one lib. Share the main vision and ideas publicly to gather ideas and myself taking notes.

Similar efforts

Recently I have found out about the (amazing) typeschema project which tries to almost do the same of unifying schema validation libraries. I love it but it has some implementation drawbacks that are not fully tree-shakable (it is fixable with some major changes) but also is not itself trying to make a standard schema nor provide build-time utils like currently untyped does.

There is also JsonTypeDef Standard (RFC) which could be a nice replacement for JSON Schema as a current source of trust.

Schema Validation Libs

Zod

  • Website: https://zod.dev/
  • Repo: https://github.com/colinhacks/zod

Joi

  • Repo: https://github.com/hapijs/joi

Yup

  • Repo: https://github.com/jquense/yup

io-ts

  • Repo: https://github.com/gcanti/io-ts

Runtypes

  • Repo: https://github.com/pelotom/runtypes

Valibot

  • Website: https://valibot.dev/
  • Repo: https://github.com/fabian-hiller/valibot

AJV

  • Website: https://ajv.js.org/

Superstruct

  • Website: https://docs.superstructjs.org/

OW

  • Website: https://sindresorhus.com/ow/

Typebox

  • Repo: https://github.com/sinclairzx81/typebox

Typia

  • Website: https://typia.io/docs/

Deepkit/type

  • Website: https://deepkit.io/library/type

Arktype

  • Website: https://arktype.io/

pi0 avatar Jul 25 '23 16:07 pi0