Skip to content

Use Schema type consistently in custom-mutators.mdx #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions contents/docs/custom-mutators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ By convention, the client mutators are defined with a function called `createMut
```ts
// mutators.ts
import {CustomMutatorDefs} from '@rocicorp/zero';
import {schema} from './schema';
import {Schema} from './schema';

export function createMutators() {
return {
Expand All @@ -172,7 +172,7 @@ export function createMutators() {
await tx.mutate.issue.update({id, title});
},
},
} as const satisfies CustomMutatorDefs<typeof schema>;
} as const satisfies CustomMutatorDefs<Schema>;
}
```

Expand Down Expand Up @@ -232,6 +232,8 @@ See [the CRUD docs](./writing-data) for detailed semantics on these methods.
You can read data within a client mutator using [ZQL](./reading-data):

```ts
import {Schema} from './schema';

export function createMutators() {
return {
issue: {
Expand All @@ -247,7 +249,7 @@ export function createMutators() {
await tx.mutate.issue.update({id, title});
},
},
} as const satisfies CustomMutatorDefs<typeof schema>;
} as const satisfies CustomMutatorDefs<Schema>;
}
```

Expand Down Expand Up @@ -444,10 +446,10 @@ An approach we like is to create a separate `server-mutators.ts` file that wraps
```ts
// server-mutators.ts
import {CustomMutatorDefs} from '@rocicorp/zero';
import {schema} from './schema';
import {Schema} from './schema';

export function createMutators(
clientMutators: CustomMutatorDefs<typeof schema>,
clientMutators: CustomMutatorDefs<Schema>,
) {
return {
// Reuse all client mutators except the ones in `issue`
Expand All @@ -472,7 +474,7 @@ export function createMutators(
});
},
},
} as const satisfies CustomMutatorDefs<typeof schema>;
} as const satisfies CustomMutatorDefs<Schema>;
}
```

Expand Down Expand Up @@ -502,6 +504,8 @@ We hope to build [custom queries](https://bugs.rocicorp.dev/issue/3453) next –
In order to do permission checks, you'll need to know what user is making the request. You can pass this information to your mutators by adding a `AuthData` parameter to the `createMutators` function:

```ts
import {Schema} from './schema';

type AuthData = {
sub: string;
};
Expand All @@ -523,7 +527,7 @@ export function createMutators(authData: AuthData | undefined) {
}
},
},
} as const satisfies CustomMutatorDefs<typeof schema>;
} as const satisfies CustomMutatorDefs<Schema>;
}
```

Expand Down Expand Up @@ -622,6 +626,8 @@ It is bad practice to hold open database transactions while talking over the net
There is no specific support for this in custom mutators, but since mutators are just code, it’s easy to do:

```ts
import {Schema} from './schema';

// server-mutators.ts
export function createMutators(
authData: AuthData,
Expand All @@ -637,7 +643,7 @@ export function createMutators(
});
},
},
} as const satisfies CustomMutatorDefs<typeof schema>;
} as const satisfies CustomMutatorDefs<Schema>;
}
```

Expand Down