Skip to content

Commit

Permalink
chore(zero-client): review nits (#3648, #3645)
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Jan 31, 2025
1 parent f07163a commit a7a195d
Show file tree
Hide file tree
Showing 5 changed files with 1,340 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/zero-client/src/client/custom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ test('argument types are preserved on the generated mutator interface', () => {
}>();
});

test('cannot support non-namespace custom mutators', () => {
({
// @ts-expect-error - all mutators must be in a namespace
setTitle: (_tx, _a: {id: string; title: string}) => {
throw new Error('not implemented');
},
}) satisfies CustomMutatorDefs<Schema>;
});

test('custom mutators write to the local store', async () => {
const z = zeroForTest({
logLevel: 'debug',
Expand Down
6 changes: 3 additions & 3 deletions packages/zero-client/src/client/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export type MakeCustomMutatorInterface<
export type TransactionReason = 'optimistic' | 'rebase';

/**
* WriteTransactions are used with *mutators* which are registered using
* {@link ReplicacheOptions.mutators} and allows read and write operations on the
* database.
* An instance of this is passed to custom mutator implementations and
* allows reading and writing to the database and IVM at the head
* at which the mutator is being applied.
*/
export interface Transaction<S extends Schema> {
readonly clientID: ClientID;
Expand Down
29 changes: 29 additions & 0 deletions repro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "repro",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"check-types": "tsc && tsc -p tsconfig.node.json",
"check-types:watch": "tsc --watch",
"format": "prettier --write .",
"check-format": "prettier --check .",
"lint": "eslint --ext .ts,.tsx,.js,.jsx src/",
"preview": "vite preview",
"zero": "npm run zero-build-schema && tsx ../../packages/zero-cache/src/server/multi/main.ts",
"zero-brk": "npm run zero-build-schema && tsx --inspect-brk ../../packages/zero-cache/src/server/debug/single.ts",
"transform-query": "npm run zero-build-schema && tsx ../../packages/zero-cache/src/scripts/transform-query.ts",
"run-query": "npm run zero-build-schema && tsx ../../packages/zero-cache/src/scripts/run-query.ts",
"run-query-brk": "npm run zero-build-schema && tsx --inspect-brk ../../packages/zero-cache/src/scripts/run-query.ts",
"zero-build-schema": "tsx ../../packages/zero-schema/src/build-schema.ts",
"test": "vitest run",
"test:watch": "vitest",
"analyze": "analyze -c vite.config.ts"
},
"eslintConfig": {
"extends": "../../eslint-config.json"
},
"prettier": "@rocicorp/prettier-config"
}
Loading

0 comments on commit a7a195d

Please sign in to comment.