@foretag/tanstack-db-surrealdb 0.3.0 → 0.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/dist/index.d.mts +20 -19
- package/dist/index.d.ts +20 -19
- package/dist/index.js +180 -487
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +175 -465
- package/dist/index.mjs.map +1 -0
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CollectionConfig, UtilsRecord } from '@tanstack/db';
|
|
2
2
|
import { Container } from 'loro-crdt';
|
|
3
|
+
import { QueryClient } from '@tanstack/query-core';
|
|
3
4
|
import { RecordId, Surreal, ExprLike } from 'surrealdb';
|
|
4
5
|
|
|
5
6
|
type WithId<T> = T & {
|
|
@@ -7,9 +8,22 @@ type WithId<T> = T & {
|
|
|
7
8
|
};
|
|
8
9
|
type SyncedTable<T> = WithId<T & {
|
|
9
10
|
sync_deleted?: boolean;
|
|
10
|
-
updated_at?: Date;
|
|
11
|
+
updated_at?: Date | number | string;
|
|
11
12
|
}>;
|
|
12
|
-
type
|
|
13
|
+
type SurrealField<T> = Extract<keyof T, string> | (string & {});
|
|
14
|
+
type FieldList<T> = '*' | ReadonlyArray<SurrealField<T>>;
|
|
15
|
+
type SurrealSubset = {
|
|
16
|
+
where?: ExprLike;
|
|
17
|
+
orderBy?: string | readonly string[];
|
|
18
|
+
limit?: number;
|
|
19
|
+
offset?: number;
|
|
20
|
+
};
|
|
21
|
+
type TableOptions<T> = {
|
|
22
|
+
name: string;
|
|
23
|
+
fields?: FieldList<T>;
|
|
24
|
+
where?: ExprLike;
|
|
25
|
+
};
|
|
26
|
+
type SyncMode = 'eager' | 'on-demand';
|
|
13
27
|
type SurrealCollectionConfig<T extends {
|
|
14
28
|
id: string | RecordId;
|
|
15
29
|
}> = {
|
|
@@ -17,27 +31,14 @@ type SurrealCollectionConfig<T extends {
|
|
|
17
31
|
db: Surreal;
|
|
18
32
|
table: TableOptions<T>;
|
|
19
33
|
syncMode?: SyncMode;
|
|
34
|
+
queryKey: readonly unknown[];
|
|
35
|
+
queryClient?: QueryClient;
|
|
20
36
|
useLoro?: boolean;
|
|
21
37
|
onError?: (e: unknown) => void;
|
|
22
38
|
};
|
|
23
|
-
type Field<I> = keyof I | (string & {});
|
|
24
|
-
type FieldList<I> = '*' | ReadonlyArray<Field<I>>;
|
|
25
|
-
type TableOptions<T> = {
|
|
26
|
-
name: string;
|
|
27
|
-
fields?: FieldList<T>;
|
|
28
|
-
where?: ExprLike;
|
|
29
|
-
pageSize?: number;
|
|
30
|
-
initialPageSize?: number;
|
|
31
|
-
onProgress?: (info: {
|
|
32
|
-
table: string;
|
|
33
|
-
loaded: number;
|
|
34
|
-
lastBatch: number;
|
|
35
|
-
done: boolean;
|
|
36
|
-
}) => void;
|
|
37
|
-
};
|
|
38
39
|
|
|
39
40
|
declare function surrealCollectionOptions<T extends SyncedTable<object>, S extends Record<string, Container> = {
|
|
40
41
|
[k: string]: never;
|
|
41
|
-
}>({ id, useLoro, onError, db, syncMode, ...config }: SurrealCollectionConfig<T>): CollectionConfig<T, string | number, never, UtilsRecord>;
|
|
42
|
+
}>({ id, useLoro, onError, db, queryClient, queryKey, syncMode, ...config }: SurrealCollectionConfig<T>): CollectionConfig<T, string | number, never, UtilsRecord>;
|
|
42
43
|
|
|
43
|
-
export { surrealCollectionOptions };
|
|
44
|
+
export { type SurrealSubset, surrealCollectionOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CollectionConfig, UtilsRecord } from '@tanstack/db';
|
|
2
2
|
import { Container } from 'loro-crdt';
|
|
3
|
+
import { QueryClient } from '@tanstack/query-core';
|
|
3
4
|
import { RecordId, Surreal, ExprLike } from 'surrealdb';
|
|
4
5
|
|
|
5
6
|
type WithId<T> = T & {
|
|
@@ -7,9 +8,22 @@ type WithId<T> = T & {
|
|
|
7
8
|
};
|
|
8
9
|
type SyncedTable<T> = WithId<T & {
|
|
9
10
|
sync_deleted?: boolean;
|
|
10
|
-
updated_at?: Date;
|
|
11
|
+
updated_at?: Date | number | string;
|
|
11
12
|
}>;
|
|
12
|
-
type
|
|
13
|
+
type SurrealField<T> = Extract<keyof T, string> | (string & {});
|
|
14
|
+
type FieldList<T> = '*' | ReadonlyArray<SurrealField<T>>;
|
|
15
|
+
type SurrealSubset = {
|
|
16
|
+
where?: ExprLike;
|
|
17
|
+
orderBy?: string | readonly string[];
|
|
18
|
+
limit?: number;
|
|
19
|
+
offset?: number;
|
|
20
|
+
};
|
|
21
|
+
type TableOptions<T> = {
|
|
22
|
+
name: string;
|
|
23
|
+
fields?: FieldList<T>;
|
|
24
|
+
where?: ExprLike;
|
|
25
|
+
};
|
|
26
|
+
type SyncMode = 'eager' | 'on-demand';
|
|
13
27
|
type SurrealCollectionConfig<T extends {
|
|
14
28
|
id: string | RecordId;
|
|
15
29
|
}> = {
|
|
@@ -17,27 +31,14 @@ type SurrealCollectionConfig<T extends {
|
|
|
17
31
|
db: Surreal;
|
|
18
32
|
table: TableOptions<T>;
|
|
19
33
|
syncMode?: SyncMode;
|
|
34
|
+
queryKey: readonly unknown[];
|
|
35
|
+
queryClient?: QueryClient;
|
|
20
36
|
useLoro?: boolean;
|
|
21
37
|
onError?: (e: unknown) => void;
|
|
22
38
|
};
|
|
23
|
-
type Field<I> = keyof I | (string & {});
|
|
24
|
-
type FieldList<I> = '*' | ReadonlyArray<Field<I>>;
|
|
25
|
-
type TableOptions<T> = {
|
|
26
|
-
name: string;
|
|
27
|
-
fields?: FieldList<T>;
|
|
28
|
-
where?: ExprLike;
|
|
29
|
-
pageSize?: number;
|
|
30
|
-
initialPageSize?: number;
|
|
31
|
-
onProgress?: (info: {
|
|
32
|
-
table: string;
|
|
33
|
-
loaded: number;
|
|
34
|
-
lastBatch: number;
|
|
35
|
-
done: boolean;
|
|
36
|
-
}) => void;
|
|
37
|
-
};
|
|
38
39
|
|
|
39
40
|
declare function surrealCollectionOptions<T extends SyncedTable<object>, S extends Record<string, Container> = {
|
|
40
41
|
[k: string]: never;
|
|
41
|
-
}>({ id, useLoro, onError, db, syncMode, ...config }: SurrealCollectionConfig<T>): CollectionConfig<T, string | number, never, UtilsRecord>;
|
|
42
|
+
}>({ id, useLoro, onError, db, queryClient, queryKey, syncMode, ...config }: SurrealCollectionConfig<T>): CollectionConfig<T, string | number, never, UtilsRecord>;
|
|
42
43
|
|
|
43
|
-
export { surrealCollectionOptions };
|
|
44
|
+
export { type SurrealSubset, surrealCollectionOptions };
|