muya 2.5.4 → 2.5.6

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.
Files changed (123) hide show
  1. package/{src/__tests__ → __tests__}/bench.test.tsx +4 -4
  2. package/{src/__tests__ → __tests__}/compare.test.tsx +8 -6
  3. package/{src/__tests__ → __tests__}/create.test.tsx +2 -2
  4. package/{src/utils/__tests__ → __tests__}/is.test.ts +3 -3
  5. package/{src/__tests__ → __tests__}/scheduler.test.tsx +1 -1
  6. package/{src/__tests__ → __tests__}/select.test.tsx +5 -5
  7. package/{src/utils/__tests__ → __tests__}/shallow.test.ts +1 -1
  8. package/{src/__tests__ → __tests__}/use-value-loadable.test.tsx +3 -3
  9. package/{src/__tests__ → __tests__}/use-value.test.tsx +8 -8
  10. package/build.ts +67 -0
  11. package/dist/cjs/index.js +14 -0
  12. package/dist/esm/create.js +1 -0
  13. package/dist/esm/debug/development-tools.js +1 -0
  14. package/dist/esm/index.js +1 -0
  15. package/dist/esm/scheduler.js +1 -0
  16. package/dist/esm/select.js +1 -0
  17. package/{types → dist/types}/create-state.d.ts +1 -0
  18. package/dist/types/create-state.d.ts.map +1 -0
  19. package/{types → dist/types}/create.d.ts +2 -4
  20. package/dist/types/create.d.ts.map +1 -0
  21. package/dist/types/debug/development-tools.d.ts +13 -0
  22. package/dist/types/debug/development-tools.d.ts.map +1 -0
  23. package/{types → dist/types}/index.d.ts +3 -1
  24. package/dist/types/index.d.ts.map +1 -0
  25. package/dist/types/scheduler.d.ts +25 -0
  26. package/dist/types/scheduler.d.ts.map +1 -0
  27. package/{types → dist/types}/select.d.ts +1 -0
  28. package/dist/types/select.d.ts.map +1 -0
  29. package/{types → dist/types}/types.d.ts +1 -0
  30. package/dist/types/types.d.ts.map +1 -0
  31. package/{types → dist/types}/use-value-loadable.d.ts +1 -0
  32. package/dist/types/use-value-loadable.d.ts.map +1 -0
  33. package/{types → dist/types}/use-value.d.ts +2 -1
  34. package/dist/types/use-value.d.ts.map +1 -0
  35. package/{types → dist/types}/utils/common.d.ts +1 -0
  36. package/dist/types/utils/common.d.ts.map +1 -0
  37. package/{types → dist/types}/utils/create-emitter.d.ts +1 -0
  38. package/dist/types/utils/create-emitter.d.ts.map +1 -0
  39. package/{types → dist/types}/utils/id.d.ts +1 -0
  40. package/dist/types/utils/id.d.ts.map +1 -0
  41. package/{types → dist/types}/utils/is.d.ts +1 -0
  42. package/dist/types/utils/is.d.ts.map +1 -0
  43. package/{types → dist/types}/utils/shallow.d.ts +1 -0
  44. package/dist/types/utils/shallow.d.ts.map +1 -0
  45. package/package.json +31 -8
  46. package/src/create.ts +7 -2
  47. package/src/debug/development-tools.ts +5 -40
  48. package/src/index.ts +2 -1
  49. package/src/scheduler.ts +77 -71
  50. package/src/select.ts +7 -2
  51. package/src/use-value.ts +1 -1
  52. package/tsconfig.build.json +12 -0
  53. package/cjs/index.js +0 -1
  54. package/esm/__tests__/test-utils.js +0 -1
  55. package/esm/create.js +0 -1
  56. package/esm/debug/development-tools.js +0 -1
  57. package/esm/index.js +0 -1
  58. package/esm/scheduler.js +0 -1
  59. package/esm/select.js +0 -1
  60. package/esm/sqlite/__tests__/create-sqlite.test.js +0 -1
  61. package/esm/sqlite/__tests__/map-deque.test.js +0 -1
  62. package/esm/sqlite/__tests__/table.test.js +0 -1
  63. package/esm/sqlite/__tests__/tokenizer.test.js +0 -1
  64. package/esm/sqlite/__tests__/where.test.js +0 -1
  65. package/esm/sqlite/create-sqlite.js +0 -1
  66. package/esm/sqlite/index.js +0 -1
  67. package/esm/sqlite/table/backend.js +0 -1
  68. package/esm/sqlite/table/bun-backend.js +0 -1
  69. package/esm/sqlite/table/index.js +0 -1
  70. package/esm/sqlite/table/map-deque.js +0 -1
  71. package/esm/sqlite/table/table.js +0 -43
  72. package/esm/sqlite/table/table.types.js +0 -0
  73. package/esm/sqlite/table/tokenizer.js +0 -1
  74. package/esm/sqlite/table/where.js +0 -1
  75. package/esm/sqlite/use-sqlite-count.js +0 -1
  76. package/esm/sqlite/use-sqlite.js +0 -1
  77. package/esm/utils/__tests__/is.test.js +0 -1
  78. package/esm/utils/__tests__/shallow.test.js +0 -1
  79. package/src/sqlite/__tests__/create-sqlite.test.ts +0 -264
  80. package/src/sqlite/__tests__/map-deque.test.ts +0 -61
  81. package/src/sqlite/__tests__/table.test.ts +0 -351
  82. package/src/sqlite/__tests__/tokenizer.test.ts +0 -43
  83. package/src/sqlite/__tests__/use-slite-count.test.tsx +0 -96
  84. package/src/sqlite/__tests__/use-sqlite.more.test.tsx +0 -637
  85. package/src/sqlite/__tests__/use-sqlite.test.tsx +0 -1008
  86. package/src/sqlite/__tests__/where.test.ts +0 -234
  87. package/src/sqlite/create-sqlite.ts +0 -164
  88. package/src/sqlite/index.ts +0 -4
  89. package/src/sqlite/table/backend.ts +0 -21
  90. package/src/sqlite/table/bun-backend.ts +0 -47
  91. package/src/sqlite/table/index.ts +0 -6
  92. package/src/sqlite/table/map-deque.ts +0 -29
  93. package/src/sqlite/table/table.ts +0 -353
  94. package/src/sqlite/table/table.types.ts +0 -129
  95. package/src/sqlite/table/tokenizer.ts +0 -35
  96. package/src/sqlite/table/where.ts +0 -207
  97. package/src/sqlite/use-sqlite-count.ts +0 -69
  98. package/src/sqlite/use-sqlite.ts +0 -250
  99. package/types/__tests__/test-utils.d.ts +0 -25
  100. package/types/debug/development-tools.d.ts +0 -8
  101. package/types/scheduler.d.ts +0 -20
  102. package/types/sqlite/create-sqlite.d.ts +0 -31
  103. package/types/sqlite/index.d.ts +0 -4
  104. package/types/sqlite/table/backend.d.ts +0 -20
  105. package/types/sqlite/table/bun-backend.d.ts +0 -6
  106. package/types/sqlite/table/index.d.ts +0 -6
  107. package/types/sqlite/table/map-deque.d.ts +0 -5
  108. package/types/sqlite/table/table.d.ts +0 -21
  109. package/types/sqlite/table/table.types.d.ts +0 -91
  110. package/types/sqlite/table/tokenizer.d.ts +0 -11
  111. package/types/sqlite/table/where.d.ts +0 -37
  112. package/types/sqlite/use-sqlite-count.d.ts +0 -17
  113. package/types/sqlite/use-sqlite.d.ts +0 -39
  114. /package/{src/__tests__ → __tests__}/test-utils.ts +0 -0
  115. /package/{esm → dist/esm}/create-state.js +0 -0
  116. /package/{esm → dist/esm}/types.js +0 -0
  117. /package/{esm → dist/esm}/use-value-loadable.js +0 -0
  118. /package/{esm → dist/esm}/use-value.js +0 -0
  119. /package/{esm → dist/esm}/utils/common.js +0 -0
  120. /package/{esm → dist/esm}/utils/create-emitter.js +0 -0
  121. /package/{esm → dist/esm}/utils/id.js +0 -0
  122. /package/{esm → dist/esm}/utils/is.js +0 -0
  123. /package/{esm → dist/esm}/utils/shallow.js +0 -0
@@ -1,21 +0,0 @@
1
- import type { Table, DbOptions, DocType } from './table.types';
2
- export declare const DEFAULT_PAGE_SIZE = 100;
3
- /**
4
- * Convert a dot-separated path to a JSON path
5
- * @param dot The dot-separated path string
6
- * @returns The JSON path string
7
- */
8
- export declare function toJsonPath(dot: string): string;
9
- /**
10
- * Get a nested value from an object using a dot-separated path
11
- * @param object The object to retrieve the value from
12
- * @param path The dot-separated path string
13
- * @returns The value at the specified path, or undefined if not found
14
- */
15
- export declare function getByPath<T extends object>(object: T, path: string): unknown;
16
- /**
17
- * Create and initialize a table in the database with the specified options
18
- * @param options The options for creating the table, including table name, indexes, backend, and key
19
- * @returns A promise that resolves to the created Table instance
20
- */
21
- export declare function createTable<Document extends DocType>(options: DbOptions<Document>): Promise<Table<Document>>;
@@ -1,91 +0,0 @@
1
- import type { Backend } from './backend';
2
- import type { FtsTokenizerOptions } from './tokenizer';
3
- import type { Where } from './where';
4
- export type DocType = {
5
- [key: string]: any;
6
- };
7
- export type KeyTypeAvailable = 'string' | 'number';
8
- export interface SqlSeachOptions<Document extends DocType> {
9
- readonly sortBy?: DotPath<Document>;
10
- readonly order?: 'asc' | 'desc';
11
- readonly limit?: number;
12
- readonly offset?: number;
13
- readonly where?: Where<Document>;
14
- readonly pageSize?: number;
15
- }
16
- export type DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;
17
- type Previous = [never, 0, 1, 2, 3, 4, 5];
18
- type DotPathRaw<T, D extends number = 5> = [D] extends [never] ? never : T extends object ? {
19
- [K in Extract<keyof T, string>]: T[K] extends object ? K | `${K}.${DotPathRaw<T[K], Previous[D]>}` : K;
20
- }[Extract<keyof T, string>] : never;
21
- export type DotPath<T> = DotPathRaw<MakeAllFieldAsRequired<T>>;
22
- /**
23
- * Extract the value type at a given dot path
24
- * e.g., GetFieldType<{ user: { name: string } }, 'user.name'> = string
25
- */
26
- export type GetFieldType<T, Path extends string> = Path extends `${infer First}.${infer Rest}` ? First extends keyof T ? GetFieldType<T[First], Rest> : never : Path extends keyof T ? T[Path] : never;
27
- export type FtsTokenizer = 'porter' | 'simple' | 'icu' | 'unicode61' | FtsTokenizerOptions;
28
- export interface FtsType<Document extends DocType> {
29
- readonly type: 'fts';
30
- readonly path: DotPath<Document>;
31
- readonly tokenizer?: FtsTokenizer;
32
- }
33
- export type IndexDeclaration<Document extends DocType> = DotPath<Document> | `fts:${DotPath<Document>}` | FtsType<Document>;
34
- export interface DbOptions<Document extends DocType> {
35
- readonly tableName: string;
36
- readonly indexes?: Array<IndexDeclaration<Document>>;
37
- readonly backend: Backend;
38
- readonly key?: DotPath<Document>;
39
- readonly disablePragmaOptimization?: boolean;
40
- }
41
- export interface SearchOptions<Document extends DocType, Selected = Document> extends SqlSeachOptions<Document> {
42
- readonly select?: (document: Document, meta: {
43
- rowId: number;
44
- key: Key;
45
- }) => Selected;
46
- }
47
- interface DbNotGeneric {
48
- readonly backend: Backend;
49
- }
50
- export type Key = string | number;
51
- export type MutationOp = 'insert' | 'update' | 'delete';
52
- interface MutationResultBase<T> {
53
- key: Key;
54
- op: MutationOp;
55
- document?: T;
56
- }
57
- interface MutationResultDelete<T> extends MutationResultBase<T> {
58
- key: Key;
59
- op: 'delete';
60
- }
61
- interface MutationResultUpdateInsert<T> extends MutationResultBase<T> {
62
- key: Key;
63
- op: 'update' | 'insert';
64
- document: T;
65
- }
66
- export type MutationResult<T> = MutationResultDelete<T> | MutationResultUpdateInsert<T>;
67
- export interface GroupByResult<K> {
68
- readonly key: K;
69
- readonly count: number;
70
- }
71
- export interface GroupByOptions<Document extends DocType> {
72
- readonly where?: Where<Document>;
73
- }
74
- export interface Table<Document extends DocType> extends DbNotGeneric {
75
- readonly set: (document: Document, backendOverride?: Backend) => Promise<MutationResult<Document>>;
76
- readonly batchSet: (documents: Document[]) => Promise<MutationResult<Document>[]>;
77
- readonly batchDelete: (keys: Key[]) => Promise<MutationResult<Document>[]>;
78
- readonly get: <Selected = Document>(key: Key, selector?: (document: Document) => Selected) => Promise<Selected | undefined>;
79
- readonly delete: (key: Key, backendOverride?: Backend) => Promise<MutationResult<Document> | undefined>;
80
- readonly search: <Selected = Document>(options?: SearchOptions<Document, Selected>) => AsyncIterableIterator<Selected>;
81
- readonly count: (options?: {
82
- where?: Where<Document>;
83
- }) => Promise<number>;
84
- readonly deleteBy: (where: Where<Document>) => Promise<MutationResult<Document>[]>;
85
- readonly clear: () => Promise<void>;
86
- readonly groupBy: <Field extends DotPath<Document>>(field: Field, options?: GroupByOptions<Document>) => Promise<Array<GroupByResult<GetFieldType<Document, Field>>>>;
87
- }
88
- export type MakeAllFieldAsRequired<T> = {
89
- [K in keyof T]-?: T[K] extends object ? MakeAllFieldAsRequired<T[K]> : T[K];
90
- };
91
- export {};
@@ -1,11 +0,0 @@
1
- export interface FtsTokenizerOptions {
2
- readonly removeDiacritics?: 0 | 1 | 2;
3
- readonly tokenChars?: string;
4
- readonly separators?: string;
5
- }
6
- /**
7
- * Create a custom FTS5 tokenizer string based on the provided options
8
- * @param options Options to customize the tokenizer
9
- * @returns A string representing the FTS5 tokenizer configuration
10
- */
11
- export declare function unicodeTokenizer(options?: FtsTokenizerOptions): string;
@@ -1,37 +0,0 @@
1
- import type { MakeAllFieldAsRequired } from './table.types';
2
- interface Condition<T> {
3
- readonly is?: T | T[];
4
- readonly isNot?: T | T[];
5
- readonly gt?: T;
6
- readonly gte?: T;
7
- readonly lt?: T;
8
- readonly lte?: T;
9
- readonly in?: T[];
10
- readonly notIn?: T[];
11
- readonly like?: T | T[];
12
- readonly fts?: string | string[];
13
- }
14
- type WhereRaw<T extends Record<string, unknown>> = {
15
- [K in keyof T]?: T[K] extends Record<string, unknown> ? WhereRaw<T[K]> : Condition<T[K]> | T[K] | T[K][];
16
- } | {
17
- readonly AND?: Array<WhereRaw<T>>;
18
- readonly OR?: Array<WhereRaw<T>>;
19
- readonly NOT?: WhereRaw<T>;
20
- };
21
- export type Where<T extends Record<string, unknown>> = WhereRaw<MakeAllFieldAsRequired<T>>;
22
- /**
23
- * Write SQL WHERE clause from a Where object
24
- * @param where The Where object defining the conditions
25
- * @param tableAlias Optional table alias to prefix field names
26
- * @param tableName Optional table name (required for FTS conditions)
27
- * @returns The SQL WHERE clause string (without the "WHERE" keyword)
28
- */
29
- export declare function getWhere<T extends Record<string, unknown>>(where: Where<T>, tableAlias?: string, tableName?: string): string;
30
- /**
31
- * Get SQL WHERE clause from a Where object
32
- * @param where The Where object defining the conditions
33
- * @param tableName Optional table name (required for FTS conditions)
34
- * @returns The SQL WHERE clause string (without the "WHERE" keyword)
35
- */
36
- export declare function getWhereQuery<T extends Record<string, unknown>>(where?: Where<T>, tableName?: string): string;
37
- export {};
@@ -1,17 +0,0 @@
1
- import { type DependencyList } from 'react';
2
- import type { SyncTable } from './create-sqlite';
3
- import type { DocType } from './table/table.types';
4
- import type { Where } from './table/where';
5
- /**
6
- * A React hook to count the number of items in a SyncTable reactively.
7
- * It updates the count when items are inserted or deleted, but ignores updates.
8
- * Supports filtering the count using a `where` clause.
9
- * @param state The SyncTable instance to observe.
10
- * @param options Optional filtering options.
11
- * @param options.where A `where` clause to filter the count.
12
- * @param deps Dependency list to control when to re-run the effect.
13
- * @returns The current count of items in the table.
14
- */
15
- export declare function useSqliteCount<Document extends DocType>(state: SyncTable<Document>, options?: {
16
- where?: Where<Document>;
17
- }, deps?: DependencyList): number;
@@ -1,39 +0,0 @@
1
- import { type DependencyList } from 'react';
2
- import type { SyncTable } from './create-sqlite';
3
- import type { DocType, Key, SqlSeachOptions } from './table/table.types';
4
- export interface SqLiteActions {
5
- /**
6
- * Load the next page of results and return if isDone to show more results.
7
- * @returns isDone: boolean
8
- */
9
- readonly nextPage: () => Promise<boolean>;
10
- /**
11
- * Reset the pagination and load the first page of results.
12
- * @returns void
13
- */
14
- readonly reset: () => Promise<void>;
15
- /**
16
- * Map of document keys to their index in the results array.
17
- */
18
- readonly keysIndex: Map<Key, number>;
19
- /**
20
- * True when deps changed but fresh data hasn't loaded yet.
21
- * Use this to show stale/dimmed UI while new results are loading.
22
- */
23
- readonly isStale: boolean;
24
- }
25
- export interface UseSearchOptions<Document extends DocType, Selected = Document> extends SqlSeachOptions<Document> {
26
- /**
27
- * Naive projection. Prefer specialized queries for heavy fan-out graphs.
28
- */
29
- readonly select?: (document: Document) => Selected;
30
- }
31
- /**
32
- * A React hook to perform paginated searches on a SyncTable and reactively update the results.
33
- * It supports pagination, resetting the search, and selecting specific fields from the documents.
34
- * @param state The SyncTable instance to perform searches on.
35
- * @param options Options to customize the search behavior, including pagination size and selection function.
36
- * @param deps Dependency list to control when to re-run the search and reset the iterator.
37
- * @returns A tuple containing the current list of results and an object with actions to manage pagination and resetting.
38
- */
39
- export declare function useSqliteValue<Document extends DocType, Selected = Document>(state: SyncTable<Document>, options?: UseSearchOptions<Document, Selected>, deps?: DependencyList): [(undefined extends Selected ? Document[] : Selected[]) | null, SqLiteActions];
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes