66 createCRUDBuilder ,
77 createSchema ,
88 defineMutator ,
9- defineMutators ,
10- defineQueries ,
9+ defineMutatorsWithType ,
10+ defineQueriesWithType ,
1111 defineQuery ,
1212 number ,
1313 relationships ,
@@ -21,13 +21,6 @@ import z from 'zod'
2121import { addContextToQuery } from './query'
2222import { VueView , vueViewFactory } from './view'
2323
24- type AllSchemas = typeof simpleSchema & typeof collapseSchema & typeof treeSchema
25- declare module '@rocicorp/zero' {
26- interface DefaultTypes {
27- schema : AllSchemas
28- }
29- }
30-
3124const simpleSchema = createSchema ( {
3225 tables : [
3326 table ( 'table' )
@@ -40,7 +33,8 @@ const simpleSchema = createSchema({
4033} )
4134
4235function setupSimple ( ) {
43- const crud = createCRUDBuilder < AllSchemas > ( simpleSchema )
36+ const crud = createCRUDBuilder ( simpleSchema )
37+ const defineMutators = defineMutatorsWithType < typeof simpleSchema > ( )
4438 const mutators = defineMutators ( {
4539 insert : defineMutator (
4640 z . object ( { a : z . number ( ) , b : z . string ( ) } ) ,
@@ -73,6 +67,7 @@ function setupSimple() {
7367 } )
7468
7569 const zql = createBuilder ( simpleSchema )
70+ const defineQueries = defineQueriesWithType < typeof simpleSchema > ( )
7671 const queries = defineQueries ( {
7772 table : defineQuery ( ( ) => zql . table ) ,
7873 } )
@@ -105,7 +100,8 @@ const treeSchema = createSchema({
105100} )
106101
107102function setupTree ( ) {
108- const crud = createCRUDBuilder < AllSchemas > ( treeSchema )
103+ const crud = createCRUDBuilder ( treeSchema )
104+ const defineMutators = defineMutatorsWithType < typeof treeSchema > ( )
109105 const mutators = defineMutators ( {
110106 insert : defineMutator (
111107 z . object ( { id : z . number ( ) , name : z . string ( ) , data : z . string ( ) . optional ( ) . nullable ( ) , childID : z . number ( ) . nullable ( ) } ) ,
@@ -146,6 +142,7 @@ function setupTree() {
146142 } )
147143
148144 const zql = createBuilder ( treeSchema )
145+ const defineQueries = defineQueriesWithType < typeof treeSchema > ( )
149146 const queries = defineQueries ( {
150147 table : defineQuery ( ( ) => zql . tree . related ( 'children' ) ) ,
151148 one : defineQuery ( ( ) => zql . tree . related ( 'children' ) . one ( ) ) ,
@@ -211,6 +208,7 @@ function setupCollapse() {
211208 } )
212209
213210 const zql = createBuilder ( collapseSchema )
211+ const defineQueries = defineQueriesWithType < typeof collapseSchema > ( )
214212 const queries = defineQueries ( {
215213 issuesWithLabelsQuery : defineQuery ( ( ) => zql . issue . related ( 'labels' ) ) ,
216214 } )
@@ -224,9 +222,7 @@ describe('vueView', () => {
224222 it ( 'basics' , async ( ) => {
225223 const { zero, mutators, tableQuery } = setupSimple ( )
226224
227- // @ts -expect-error - We can't augment the zero instance with the schema, because we're using multiple schemas
228225 await zero . mutate ( mutators . insert ( { a : 1 , b : 'a' } ) ) . client
229- // @ts -expect-error - We can't augment the zero instance with the schema, because we're using multiple schemas
230226 await zero . mutate ( mutators . insert ( { a : 2 , b : 'b' } ) ) . client
231227
232228 const view = zero . materialize (
@@ -252,7 +248,6 @@ describe('vueView', () => {
252248 // TODO: Test with a real resolver
253249 // expect(view.status).toEqual("complete");
254250
255- // @ts -expect-error - We can't augment the zero instance with the schema, because we're using multiple schemas
256251 await zero . mutate ( mutators . insert ( { a : 3 , b : 'c' } ) ) . client
257252
258253 expect ( view . data ) . toMatchInlineSnapshot ( `
@@ -275,9 +270,7 @@ describe('vueView', () => {
275270 ]
276271 ` )
277272
278- // @ts -expect-error - We can't augment the zero instance with the schema, because we're using multiple schemas
279273 await zero . mutate ( mutators . delete ( { a : 1 } ) ) . client
280- // @ts -expect-error - We can't augment the zero instance with the schema, because we're using multiple schemas
281274 await zero . mutate ( mutators . delete ( { a : 2 } ) ) . client
282275
283276 expect ( view . data ) . toMatchInlineSnapshot ( `
@@ -290,7 +283,6 @@ describe('vueView', () => {
290283 ]
291284 ` )
292285
293- // @ts -expect-error - We can't augment the zero instance with the schema, because we're using multiple schemas
294286 await zero . mutate ( mutators . delete ( { a : 3 } ) ) . client
295287
296288 expect ( view . data ) . toEqual ( [ ] )
@@ -305,7 +297,6 @@ describe('vueView', () => {
305297 expect ( view . data ?. length ) . toBe ( 0 )
306298
307299 for ( const i in [ ...Array . from ( { length : iterations } ) . keys ( ) ] ) {
308- // @ts -expect-error - We can't augment the zero instance with the schema, because we're using multiple schemas
309300 await zero . mutate ( mutators . insert ( { a : Number ( i ) , b : 'a' } ) ) . client
310301 }
311302
0 commit comments