muya 2.5.4 → 2.5.5
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/{src/__tests__ → __tests__}/bench.test.tsx +4 -4
- package/{src/__tests__ → __tests__}/compare.test.tsx +8 -6
- package/{src/__tests__ → __tests__}/create.test.tsx +2 -2
- package/{src/utils/__tests__ → __tests__}/is.test.ts +3 -3
- package/{src/__tests__ → __tests__}/scheduler.test.tsx +1 -1
- package/{src/__tests__ → __tests__}/select.test.tsx +5 -5
- package/{src/utils/__tests__ → __tests__}/shallow.test.ts +1 -1
- package/{src/__tests__ → __tests__}/use-value-loadable.test.tsx +3 -3
- package/{src/__tests__ → __tests__}/use-value.test.tsx +8 -8
- package/build.ts +67 -0
- package/dist/cjs/index.js +1 -0
- package/dist/esm/create.js +1 -0
- package/dist/esm/debug/development-tools.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/select.js +1 -0
- package/{types → dist/types}/create-state.d.ts +1 -0
- package/dist/types/create-state.d.ts.map +1 -0
- package/{types → dist/types}/create.d.ts +1 -0
- package/dist/types/create.d.ts.map +1 -0
- package/dist/types/debug/development-tools.d.ts +13 -0
- package/dist/types/debug/development-tools.d.ts.map +1 -0
- package/{types → dist/types}/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -0
- package/{types → dist/types}/scheduler.d.ts +1 -0
- package/dist/types/scheduler.d.ts.map +1 -0
- package/{types → dist/types}/select.d.ts +1 -0
- package/dist/types/select.d.ts.map +1 -0
- package/{types → dist/types}/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/{types → dist/types}/use-value-loadable.d.ts +1 -0
- package/dist/types/use-value-loadable.d.ts.map +1 -0
- package/{types → dist/types}/use-value.d.ts +2 -1
- package/dist/types/use-value.d.ts.map +1 -0
- package/{types → dist/types}/utils/common.d.ts +1 -0
- package/dist/types/utils/common.d.ts.map +1 -0
- package/{types → dist/types}/utils/create-emitter.d.ts +1 -0
- package/dist/types/utils/create-emitter.d.ts.map +1 -0
- package/{types → dist/types}/utils/id.d.ts +1 -0
- package/dist/types/utils/id.d.ts.map +1 -0
- package/{types → dist/types}/utils/is.d.ts +1 -0
- package/dist/types/utils/is.d.ts.map +1 -0
- package/{types → dist/types}/utils/shallow.d.ts +1 -0
- package/dist/types/utils/shallow.d.ts.map +1 -0
- package/package.json +23 -8
- package/src/create-state.d.ts.map +1 -0
- package/src/create.d.ts.map +1 -0
- package/src/create.ts +7 -2
- package/src/debug/development-tools.d.ts.map +1 -0
- package/src/debug/development-tools.ts +5 -40
- package/src/index.d.ts.map +1 -0
- package/src/index.ts +2 -1
- package/src/scheduler.d.ts.map +1 -0
- package/src/select.d.ts.map +1 -0
- package/src/select.ts +7 -2
- package/src/types.d.ts.map +1 -0
- package/src/use-value-loadable.d.ts.map +1 -0
- package/src/use-value.d.ts.map +1 -0
- package/src/use-value.ts +1 -1
- package/src/utils/common.d.ts.map +1 -0
- package/src/utils/create-emitter.d.ts.map +1 -0
- package/src/utils/id.d.ts.map +1 -0
- package/src/utils/is.d.ts.map +1 -0
- package/src/utils/shallow.d.ts.map +1 -0
- package/tsconfig.build.json +12 -0
- package/cjs/index.js +0 -1
- package/esm/__tests__/test-utils.js +0 -1
- package/esm/create.js +0 -1
- package/esm/debug/development-tools.js +0 -1
- package/esm/index.js +0 -1
- package/esm/select.js +0 -1
- package/esm/sqlite/__tests__/create-sqlite.test.js +0 -1
- package/esm/sqlite/__tests__/map-deque.test.js +0 -1
- package/esm/sqlite/__tests__/table.test.js +0 -1
- package/esm/sqlite/__tests__/tokenizer.test.js +0 -1
- package/esm/sqlite/__tests__/where.test.js +0 -1
- package/esm/sqlite/create-sqlite.js +0 -1
- package/esm/sqlite/index.js +0 -1
- package/esm/sqlite/table/backend.js +0 -1
- package/esm/sqlite/table/bun-backend.js +0 -1
- package/esm/sqlite/table/index.js +0 -1
- package/esm/sqlite/table/map-deque.js +0 -1
- package/esm/sqlite/table/table.js +0 -43
- package/esm/sqlite/table/table.types.js +0 -0
- package/esm/sqlite/table/tokenizer.js +0 -1
- package/esm/sqlite/table/where.js +0 -1
- package/esm/sqlite/use-sqlite-count.js +0 -1
- package/esm/sqlite/use-sqlite.js +0 -1
- package/esm/utils/__tests__/is.test.js +0 -1
- package/esm/utils/__tests__/shallow.test.js +0 -1
- package/src/sqlite/__tests__/create-sqlite.test.ts +0 -264
- package/src/sqlite/__tests__/map-deque.test.ts +0 -61
- package/src/sqlite/__tests__/table.test.ts +0 -351
- package/src/sqlite/__tests__/tokenizer.test.ts +0 -43
- package/src/sqlite/__tests__/use-slite-count.test.tsx +0 -96
- package/src/sqlite/__tests__/use-sqlite.more.test.tsx +0 -637
- package/src/sqlite/__tests__/use-sqlite.test.tsx +0 -1008
- package/src/sqlite/__tests__/where.test.ts +0 -234
- package/src/sqlite/create-sqlite.ts +0 -164
- package/src/sqlite/index.ts +0 -4
- package/src/sqlite/table/backend.ts +0 -21
- package/src/sqlite/table/bun-backend.ts +0 -47
- package/src/sqlite/table/index.ts +0 -6
- package/src/sqlite/table/map-deque.ts +0 -29
- package/src/sqlite/table/table.ts +0 -353
- package/src/sqlite/table/table.types.ts +0 -129
- package/src/sqlite/table/tokenizer.ts +0 -35
- package/src/sqlite/table/where.ts +0 -207
- package/src/sqlite/use-sqlite-count.ts +0 -69
- package/src/sqlite/use-sqlite.ts +0 -250
- package/types/__tests__/test-utils.d.ts +0 -25
- package/types/debug/development-tools.d.ts +0 -8
- package/types/sqlite/create-sqlite.d.ts +0 -31
- package/types/sqlite/index.d.ts +0 -4
- package/types/sqlite/table/backend.d.ts +0 -20
- package/types/sqlite/table/bun-backend.d.ts +0 -6
- package/types/sqlite/table/index.d.ts +0 -6
- package/types/sqlite/table/map-deque.d.ts +0 -5
- package/types/sqlite/table/table.d.ts +0 -21
- package/types/sqlite/table/table.types.d.ts +0 -91
- package/types/sqlite/table/tokenizer.d.ts +0 -11
- package/types/sqlite/table/where.d.ts +0 -37
- package/types/sqlite/use-sqlite-count.d.ts +0 -17
- package/types/sqlite/use-sqlite.d.ts +0 -39
- /package/{src/__tests__ → __tests__}/test-utils.ts +0 -0
- /package/{esm → dist/esm}/create-state.js +0 -0
- /package/{esm → dist/esm}/scheduler.js +0 -0
- /package/{esm → dist/esm}/types.js +0 -0
- /package/{esm → dist/esm}/use-value-loadable.js +0 -0
- /package/{esm → dist/esm}/use-value.js +0 -0
- /package/{esm → dist/esm}/utils/common.js +0 -0
- /package/{esm → dist/esm}/utils/create-emitter.js +0 -0
- /package/{esm → dist/esm}/utils/id.js +0 -0
- /package/{esm → dist/esm}/utils/is.js +0 -0
- /package/{esm → dist/esm}/utils/shallow.js +0 -0
|
@@ -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
|
|
File without changes
|