Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions examples/react/todo/src/lib/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export const trailBaseTodoCollection = createCollection(
trailBaseCollectionOptions<SelectTodo, Todo>({
id: `todos`,
getKey: (item) => item.id,
schema: selectTodoSchema,
recordApi: trailBaseClient.records(`todos`),
// Re-using the example's drizzle-schema requires remapping the items.
parse: {
Expand Down Expand Up @@ -233,7 +232,6 @@ export const trailBaseConfigCollection = createCollection(
trailBaseCollectionOptions<SelectConfig, Config>({
id: `config`,
getKey: (item) => item.id,
schema: selectConfigSchema,
recordApi: trailBaseClient.records(`config`),
// Re-using the example's drizzle-schema requires remapping the items.
parse: {
Expand Down
2 changes: 0 additions & 2 deletions examples/solid/todo/src/lib/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export const trailBaseTodoCollection = createCollection(
trailBaseCollectionOptions<SelectTodo, Todo>({
id: `todos`,
getKey: (item) => item.id,
schema: selectTodoSchema,
recordApi: trailBaseClient.records(`todos`),
// Re-using the example's drizzle-schema requires remapping the items.
parse: {
Expand Down Expand Up @@ -215,7 +214,6 @@ export const trailBaseConfigCollection = createCollection(
trailBaseCollectionOptions<SelectConfig, Config>({
id: `config`,
getKey: (item) => item.id,
schema: selectConfigSchema,
recordApi: trailBaseClient.records(`config`),
// Re-using the example's drizzle-schema requires remapping the items.
parse: {
Expand Down
31 changes: 31 additions & 0 deletions packages/trailbase-db-collection/tests/trailbase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import { describe, expect, it, vi } from 'vitest'
import { createCollection } from '@tanstack/db'
import { trailBaseCollectionOptions } from '../src/trailbase'
import type {
CreateOperation,
DeleteOperation,
Event,
FilterOrComposite,
ListOperation,
ListOpts,
ListResponse,
Pagination,
ReadOperation,
ReadOpts,
RecordApi,
RecordId,
SubscribeOpts,
UpdateOperation,
} from 'trailbase'

type Data = {
Expand All @@ -27,6 +36,9 @@ class MockRecordApi<T> implements RecordApi<T> {
return Promise.resolve({ records: [] })
},
)
listOp = vi.fn((_opts?: ListOpts): ListOperation<T> => {
throw `listOp`
})

read = vi.fn(
(
Expand All @@ -38,20 +50,34 @@ class MockRecordApi<T> implements RecordApi<T> {
throw `read`
},
)
readOp = vi.fn((_id: RecordId, _opt?: ReadOpts): ReadOperation<T> => {
throw `readOp`
})

create = vi.fn((_record: T): Promise<string | number> => {
throw `create`
})
createBulk = vi.fn((_records: Array<T>): Promise<Array<string | number>> => {
throw `createBulk`
})
createOp = vi.fn((_record: T): CreateOperation<T> => {
throw `createOp`
})

update = vi.fn((_id: string | number, _record: Partial<T>): Promise<void> => {
throw `update`
})
updateOp = vi.fn((_id: RecordId, _record: Partial<T>): UpdateOperation => {
throw `updateOp`
})

delete = vi.fn((_id: string | number): Promise<void> => {
throw `delete`
})
deleteOp = vi.fn((_id: RecordId): DeleteOperation => {
throw `deleteOp`
})

subscribe = vi.fn((_id: string | number): Promise<ReadableStream<Event>> => {
return Promise.resolve(
new ReadableStream({
Expand All @@ -61,6 +87,11 @@ class MockRecordApi<T> implements RecordApi<T> {
}),
)
})
subscribeAll = vi.fn(
(_opts?: SubscribeOpts): Promise<ReadableStream<Event>> => {
throw `subscribeAll`
},
)
}

function setUp(recordApi: MockRecordApi<Data>) {
Expand Down
Loading