UNPKG

ponder-client

Version:
40 lines (35 loc) 963 B
import { createSchema } from '@ponder/core'; import { assertType, describe, it, expectTypeOf } from 'vitest'; import { one, type QueryPart } from './index.js'; const schema = createSchema((p) => ({ Item: p.createTable({ id: p.string(), address: p.hex(), chainId: p.int(), factory: p.hex(), values: p.hex().list(), }), })); describe('one', () => { it('should return a function', () => { const queryPart = one< 'Item', (typeof schema.tables)['Item'], { id: true; address: true; chainId: true } >('Item')( { id: '80001-0x0011a9df49622ab6c8c7ca24f44c3c5c3f4228e8', }, { id: true, address: true, chainId: true, }, ); expectTypeOf<QueryPart<'Item', (typeof schema.tables)['Item']>>(queryPart); assertType<QueryPart<'InvalidItem', (typeof schema.tables)['Item']>>( // @ts-expect-error "Invalid table name" queryPart, ); }); });