Skip to content

Commit

Permalink
[types][docs] Add docs for UpdateParams and LinkParams (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
stopachka authored Dec 23, 2024
1 parent d756eca commit f66e207
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const db = init({
schema,
});

type Collection = keyof typeof schema.entities;
type Collection = keyof AppSchema['entities'];

type EntityUpdate<T extends Collection> = UpdateParams<typeof schema, T>;

Expand Down
42 changes: 41 additions & 1 deletion client/www/pages/docs/instaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,52 @@ const _schema = i.schema({
},
// ...
});
// ...
```

Instant will enforce that `todos.dueDate` are actually dates, and you'll get intellisense to boot:
Instant will enforce that `todos.dueDate` are actually dates, and you'll get some nice intellisense to boot:

{% screenshot src="/img/docs/instaml-due-date.png" /%}

Instant also comes with a few utility types, which can help you write abstractions over `transact`. For example, say you wanted to write a custom `update` function:

```typescript
// Goal
myCustomUpdate('todos', { dueDate: Date.now() } );
```

You can use the `UpdateParams` utility to make sure arguments follow the schema:

```typescript
import { UpdateParams } from '@instantdb/react';
import { AppSchema } from '../instant.schema.ts';

type EntityTypes = keyof AppSchema['entities'];

function myCustomUpdate<EType extends EntityTypes>(
etype: EType,
args: UpdateParams<AppSchema, EType>,
) {
// ..
}
```

And the `LinkParams` utility do the same for links:

```typescript
import { UpdateParams } from '@instantdb/react';
import { AppSchema } from '../instant.schema.ts';

type EntityTypes = keyof AppSchema['entities'];

function myCustomLink<EType extends EntityTypes>(
etype: EType,
args: LinkParams<AppSchema, EType>,
) {
// ..
}
```

To learn more about writing schemas, check out the [Modeling Data](/docs/modeling-data) section.

## Batching transactions
Expand Down

0 comments on commit f66e207

Please sign in to comment.