Open History to see the last commit
1import { describe, expectTypeOf, it } from 'vitest'
2import { Schema, Table, column } from '@powersync/node'
3import { createCollection } from '@tanstack/db'
4import { powerSyncCollectionOptions } from '../src'
5import type { PowerSyncCollectionUtils } from '../src'
6import type { AbstractPowerSyncDatabase } from '@powersync/node'
7
8const APP_SCHEMA = new Schema({
9 documents: new Table({
10 name: column.text,
11 author: column.text,
12 }),
13})
14
15describe(`PowerSync collection type tests`, () => {
16 it(`should type collection.utils as PowerSyncCollectionUtils after createCollection`, () => {
17 const collection = createCollection(
18 powerSyncCollectionOptions({
19 database: {} as AbstractPowerSyncDatabase,
20 table: APP_SCHEMA.props.documents,
21 }),
22 )
23
24 // Verify that collection.utils is typed as PowerSyncCollectionUtils, not UtilsRecord
25 const utils: PowerSyncCollectionUtils<
26 (typeof APP_SCHEMA.props)['documents']
27 > = collection.utils
28 expectTypeOf(utils.getMeta).toBeFunction()
29 expectTypeOf(collection.utils.getMeta).toBeFunction()
30 })
31})