Skip to content

Commit

Permalink
fix: docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosLozanoHealthCaters authored and avaly committed Jan 15, 2024
1 parent 232ef3f commit 07aea7f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions docs/api/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ const userSchema = schema({

export type UserDocument = (typeof userSchema)[0];
export type UserOptions = (typeof userSchema)[1];
```

**Example with static defaults, timestamps and validation options:**

```ts
const orderSchema = schema(
{
_id: types.number({ required: true }),
Expand All @@ -65,3 +69,51 @@ const orderSchema = schema(
export type OrderDocument = (typeof orderSchema)[0];
export type OrderOptions = (typeof orderSchema)[1];
```

**Example with dynamic defaults:**

```ts
import { schema, types } from 'papr';

const userSchema = schema({
active: types.boolean(),
birthDate: types.date(),
firstName: types.string({ required: true }),
lastName: types.string({ required: true }),
}, {
defaults: () => ({
birthDate: new Date();
})
});

export type UserDocument = (typeof userSchema)[0];
export type UserOptions = (typeof userSchema)[1];
```

**Example with async dynamic defaults:**

```ts
import { schema, types } from 'papr';

function getDateAsync(): Promise<Date> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(new Date());
}, 2000);
});
}

const userSchema = schema({
active: types.boolean(),
birthDate: types.date(),
firstName: types.string({ required: true }),
lastName: types.string({ required: true }),
}, {
defaults: async () => ({
birthDate: await getDateAsync();
})
});

export type UserDocument = (typeof userSchema)[0];
export type UserOptions = (typeof userSchema)[1];
```

0 comments on commit 07aea7f

Please sign in to comment.