Open History to see the last commit
1import { vi } from 'vitest'
2import type {
3 CreateOperation,
4 DeleteOperation,
5 Event,
6 FilterOrComposite,
7 ListOperation,
8 ListOpts,
9 ListResponse,
10 Pagination,
11 ReadOperation,
12 ReadOpts,
13 RecordApi,
14 RecordId,
15 SubscribeOpts,
16 UpdateOperation,
17} from 'trailbase'
18
19export class MockRecordApi<T> implements RecordApi<T> {
20 list = vi.fn(
21 (_opts?: {
22 pagination?: Pagination
23 order?: Array<string>
24 filters?: Array<FilterOrComposite>
25 count?: boolean
26 expand?: Array<string>
27 }): Promise<ListResponse<T>> => {
28 return Promise.resolve({ records: [] })
29 },
30 )
31 listOp = vi.fn((_opts?: ListOpts): ListOperation<T> => {
32 throw `listOp`
33 })
34 listGeoOp = vi.fn((_geometryColumn: string, _opts?: ListOpts) => {
35 throw `listGeoOp`
36 })
37
38 read = vi.fn(
39 (
40 _id: string | number,
41 _opt?: {
42 expand?: Array<string>
43 },
44 ): Promise<T> => {
45 throw `read`
46 },
47 )
48 readOp = vi.fn((_id: RecordId, _opt?: ReadOpts): ReadOperation<T> => {
49 throw `readOp`
50 })
51
52 create = vi.fn((_record: T): Promise<string | number> => {
53 throw `create`
54 })
55 createBulk = vi.fn((_records: Array<T>): Promise<Array<string | number>> => {
56 throw `createBulk`
57 })
58 createOp = vi.fn((_record: T): CreateOperation<T> => {
59 throw `createOp`
60 })
61
62 update = vi.fn((_id: string | number, _record: Partial<T>): Promise<void> => {
63 throw `update`
64 })
65 updateOp = vi.fn((_id: RecordId, _record: Partial<T>): UpdateOperation => {
66 throw `updateOp`
67 })
68
69 delete = vi.fn((_id: string | number): Promise<void> => {
70 throw `delete`
71 })
72 deleteOp = vi.fn((_id: RecordId): DeleteOperation => {
73 throw `deleteOp`
74 })
75
76 subscribe = vi.fn((_id: string | number): Promise<ReadableStream<Event>> => {
77 return Promise.resolve(
78 new ReadableStream({
79 start: (controller: ReadableStreamDefaultController<Event>) => {
80 controller.close()
81 },
82 }),
83 )
84 })
85 subscribeAll = vi.fn(
86 (_opts?: SubscribeOpts): Promise<ReadableStream<Event>> => {
87 throw `subscribeAll`
88 },
89 )
90}