1.4.0 • Published 7 months ago

kanel-zod v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Zod extension for Kanel

Generate Zod schemas directly from your Postgres database. This packages extends Kanel with some Zod specific features.

/** Zod schema for actor */
export const actor = z.object({
  actor_id: z.number(),
  first_name: z.string(),
  last_name: z.string(),
  last_update: z.date(),
});

Assuming you already have Kanel installed, add this with

$ npm i -D kanel-zod

generateZodSchemas

This pre-render hook will generate zod schemas for all your types. The default setup will convert the table name into camelCase which is a semi-standard Typescript convention for items that aren't types.

The

To use it, add it to your .kanelrc.js file:

const { generateZodSchemas } = require("kanel-zod");

module.exports = {
  // ... your config here.

  preRenderHooks: [generateZodSchemas],
};

Usage with zodCamelCaseHook

This pre-render hook will transform all zod object properties to camelCase, for example:

/**Before the hook  */
export const actor = z.object({
  actor_id: z.number(),
  first_name: z.string(),
  last_name: z.string(),
  last_update: z.date(),
});

/**After the hook  */
export const actor = z.object({
  actorId: z.number(),
  firstName: z.string(),
  lastName: z.string(),
  lastUpdate: z.date(),
});

To use it, add it to your .kanelrc.js file:

const { zodCamelCaseHook } = require("kanel-zod");

module.exports = {
  // ... your config here.

  preRenderHooks: [generateZodSchemas, zodCamelCaseHook],
};
1.4.0

7 months ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

2 years ago

1.3.1

2 years ago

1.2.3

2 years ago

1.3.0

2 years ago

1.2.2

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.3

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.2

3 years ago

0.0.1

3 years ago