Coder Social home page Coder Social logo

iforge-uos / edgedb-zod Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sikarii/edgedb-zod

0.0 0.0 0.0 81 KB

Creates Zod schemas for your EdgeDB types

Home Page: https://npmjs.com/package/edgedb-zod

License: MIT License

JavaScript 4.94% TypeScript 78.42% EdgeQL 16.63%

edgedb-zod's Introduction

edgedb-zod

edgedb-zod is a code generator for Zod schemas from your EdgeDB database schema.

2 types of schemas will be generated:

  • Create: All properties excluding link properties
  • Update: All properties excluding link and readonly properties

CLI

To run the CLI: edgedb-zod [options]

Currently the supported options are:

  • --outputDir: The output directory relative from your edgedb.toml
  • --target ts|mts: If set to mts will include .js in import statements

Supported features

Feature Status
Most scalars ✔️
Ranges
Arrays, tuples ✔️
Union types
Abstract objects ✔️
Overloaded properties ✔️
Regex constraints ✔️
Min, max constraints
Custom validators
Property annotations

Example output

Partial output of edgedb-zod/modules/default.ts:

// #region default::User
export const CreateUserSchema = z.
  object({ // default::HasTimestamps
    createdAt: z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?)?Z?$/).optional(), // std::datetime
    updatedAt: z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?)?Z?$/).optional(), // std::datetime
  })
  .extend({ // default::User
    name: z.string(), // std::str
    emailAddress: z.string().regex(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/), // std::str
    password: z.string(), // std::str
  });

export const UpdateUserSchema = z.
  object({ // default::HasTimestamps
    updatedAt: z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?)?Z?$/).optional(), // std::datetime
  })
  .extend({ // default::User
    name: z.string(), // std::str
    emailAddress: z.string().regex(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/), // std::str
    password: z.string(), // std::str
  });
// #endregion

edgedb-zod's People

Contributors

sikarii avatar gobot1234 avatar zwj-cheer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.