muya 2.3.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muya",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "author": "samuel.gjabel@gmail.com",
5
5
  "repository": "https://github.com/samuelgjabel/muya",
6
6
  "main": "cjs/index.js",
@@ -79,11 +79,11 @@ describe('use-sqlite-state', () => {
79
79
  const { result } = renderHook(() => {
80
80
  reRenders++
81
81
  const [minAge, setMinAge] = useState(20)
82
- return [useSqliteValue(sql, { where: { age: { gt: minAge } }, sorBy: 'age' }, [minAge]), setMinAge] as const
82
+ return [useSqliteValue(sql, { where: { age: { gt: minAge } }, sortBy: 'age' }, [minAge]), setMinAge] as const
83
83
  })
84
84
 
85
85
  await waitFor(() => {
86
- expect(result.current[0][0].map((p) => p.name)).toEqual(['Alice', 'Bob', 'Carol'])
86
+ expect(result.current[0][0].map((p) => p.name)).toEqual(['Bob', 'Alice', 'Carol'])
87
87
  expect(reRenders).toBe(2)
88
88
  })
89
89
 
@@ -132,17 +132,17 @@ describe('use-sqlite-state', () => {
132
132
  { id: '3', name: 'Carol', age: 40 },
133
133
  ])
134
134
  const { result, rerender } = renderHook(
135
- ({ order, limit }) => useSqliteValue(sql, { sorBy: 'age', order, limit }, [order, limit]),
135
+ ({ order, limit }) => useSqliteValue(sql, { sortBy: 'age', order, limit }, [order, limit]),
136
136
  { initialProps: { order: 'asc' as 'asc' | 'desc', limit: 2 } },
137
137
  )
138
138
  await waitFor(() => {
139
- expect(result.current[0].map((p) => p.name)).toEqual(['Alice', 'Bob'])
139
+ expect(result.current[0].map((p) => p.name)).toEqual(['Bob', 'Alice'])
140
140
  })
141
141
  act(() => {
142
142
  rerender({ order: 'desc', limit: 2 })
143
143
  })
144
144
  await waitFor(() => {
145
- expect(result.current[0].map((p) => p.name)).toEqual(['Alice', 'Bob'])
145
+ expect(result.current[0].map((p) => p.name)).toEqual(['Carol', 'Alice'])
146
146
  })
147
147
  act(() => {
148
148
  rerender({ order: 'desc', limit: 1 })
@@ -243,11 +243,11 @@ describe('use-sqlite-state', () => {
243
243
  people.push({ id: index.toString(), name: `Person${index}`, age: 20 + (index % 50) })
244
244
  }
245
245
  await sql.batchSet(people)
246
- const { result, rerender } = renderHook(({ order }) => useSqliteValue(sql, { sorBy: 'age', order }, [order]), {
246
+ const { result, rerender } = renderHook(({ order }) => useSqliteValue(sql, { sortBy: 'age', order }, [order]), {
247
247
  initialProps: { order: 'asc' as 'asc' | 'desc' },
248
248
  })
249
249
  await waitFor(() => {
250
- expect(result.current[0][0].age).toBe(21)
250
+ expect(result.current[0][0].age).toBe(20)
251
251
  })
252
252
  act(() => {
253
253
  rerender({ order: 'desc' })
@@ -268,14 +268,14 @@ describe('use-sqlite-state', () => {
268
268
  useSqliteValue(
269
269
  sql,
270
270
  {
271
- sorBy: 'age',
271
+ sortBy: 'age',
272
272
  select: (d) => d.name,
273
273
  },
274
274
  [],
275
275
  ),
276
276
  )
277
277
  await waitFor(() => {
278
- expect(result.current[0]).toEqual(['Alice', 'Bob', 'Carol'])
278
+ expect(result.current[0]).toEqual(['Bob', 'Alice', 'Carol'])
279
279
  })
280
280
  })
281
281
  it('should add 50 documents and then load with another hook', async () => {
@@ -286,7 +286,7 @@ describe('use-sqlite-state', () => {
286
286
  return useSqliteValue(
287
287
  sql,
288
288
  {
289
- sorBy: 'age',
289
+ sortBy: 'age',
290
290
  order: 'desc',
291
291
  },
292
292
  [],
@@ -1,13 +1,13 @@
1
1
  import { createState } from '../create-state'
2
2
  import type { GetState } from '../types'
3
3
  import type { SyncTable } from './create-sqlite'
4
- import type { DocType } from './table/table.types'
4
+ import type { DocType, DotPath } from './table/table.types'
5
5
  import type { Where } from './table/where'
6
6
 
7
7
  export type CreateState<Document, Params extends unknown[]> = (...params: Params) => GetState<Document[]>
8
8
 
9
9
  export interface SqlSeachOptions<Document extends DocType> {
10
- readonly sorBy?: keyof Document
10
+ readonly sortBy?: DotPath<Document>
11
11
  readonly order?: 'asc' | 'desc'
12
12
  readonly limit?: number
13
13
  readonly offset?: number
@@ -1,4 +1,5 @@
1
1
  // table.types.ts
2
+ import type { SqlSeachOptions } from '../select-sql'
2
3
  import type { Backend } from './backend'
3
4
  import type { Where } from './where'
4
5
 
@@ -27,13 +28,7 @@ export interface DbOptions<Document extends DocType> {
27
28
  readonly disablePragmaOptimization?: boolean
28
29
  }
29
30
 
30
- export interface SearchOptions<Document extends DocType, Selected = Document> {
31
- readonly sortBy?: DotPath<Document>
32
- readonly order?: 'asc' | 'desc'
33
- readonly limit?: number
34
- readonly offset?: number
35
- readonly where?: Where<Document>
36
- readonly stepSize?: number
31
+ export interface SearchOptions<Document extends DocType, Selected = Document> extends SqlSeachOptions<Document> {
37
32
  readonly select?: (document: Document, meta: { rowId: number }) => Selected
38
33
  }
39
34
 
@@ -1,10 +1,10 @@
1
1
  import type { GetState } from '../types';
2
2
  import type { SyncTable } from './create-sqlite';
3
- import type { DocType } from './table/table.types';
3
+ import type { DocType, DotPath } from './table/table.types';
4
4
  import type { Where } from './table/where';
5
5
  export type CreateState<Document, Params extends unknown[]> = (...params: Params) => GetState<Document[]>;
6
6
  export interface SqlSeachOptions<Document extends DocType> {
7
- readonly sorBy?: keyof Document;
7
+ readonly sortBy?: DotPath<Document>;
8
8
  readonly order?: 'asc' | 'desc';
9
9
  readonly limit?: number;
10
10
  readonly offset?: number;
@@ -1,3 +1,4 @@
1
+ import type { SqlSeachOptions } from '../select-sql';
1
2
  import type { Backend } from './backend';
2
3
  import type { Where } from './where';
3
4
  export type DocType = {
@@ -16,13 +17,7 @@ export interface DbOptions<Document extends DocType> {
16
17
  readonly key?: DotPath<Document>;
17
18
  readonly disablePragmaOptimization?: boolean;
18
19
  }
19
- export interface SearchOptions<Document extends DocType, Selected = Document> {
20
- readonly sortBy?: DotPath<Document>;
21
- readonly order?: 'asc' | 'desc';
22
- readonly limit?: number;
23
- readonly offset?: number;
24
- readonly where?: Where<Document>;
25
- readonly stepSize?: number;
20
+ export interface SearchOptions<Document extends DocType, Selected = Document> extends SqlSeachOptions<Document> {
26
21
  readonly select?: (document: Document, meta: {
27
22
  rowId: number;
28
23
  }) => Selected;