@foretag/tanstack-db-surrealdb 0.2.2 → 0.3.1
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/README.md +2 -8
- package/dist/index.d.mts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +1950 -290
- package/dist/index.mjs +1948 -290
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -17,14 +17,6 @@ npm install @foretag/tanstack-db-surrealdb
|
|
|
17
17
|
bun install @foretag/tanstack-db-surrealdb
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
### JSR
|
|
21
|
-
```sh
|
|
22
|
-
# NPM
|
|
23
|
-
npx jsr add @foretag/tanstack-db-surrealdb
|
|
24
|
-
# Bun
|
|
25
|
-
bunx jsr add @foretag/tanstack-db-surrealdb
|
|
26
|
-
```
|
|
27
|
-
|
|
28
20
|
## Usage
|
|
29
21
|
```ts
|
|
30
22
|
// db.ts
|
|
@@ -60,6 +52,8 @@ export const products = createCollection(
|
|
|
60
52
|
)
|
|
61
53
|
```
|
|
62
54
|
|
|
55
|
+
For syncModes, please see [Example](https://github.com/ForetagInc/tanstack-db-surrealdb/blob/master/examples/syncMode.ts)
|
|
56
|
+
|
|
63
57
|
## Vite / Next.JS
|
|
64
58
|
|
|
65
59
|
### Vite
|
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,25 +8,37 @@ 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
|
}>;
|
|
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
|
+
};
|
|
12
21
|
type TableOptions<T> = {
|
|
13
22
|
name: string;
|
|
14
|
-
fields?:
|
|
23
|
+
fields?: FieldList<T>;
|
|
15
24
|
where?: ExprLike;
|
|
16
25
|
};
|
|
26
|
+
type SyncMode = 'eager' | 'on-demand';
|
|
17
27
|
type SurrealCollectionConfig<T extends {
|
|
18
28
|
id: string | RecordId;
|
|
19
29
|
}> = {
|
|
20
30
|
id?: string;
|
|
21
31
|
db: Surreal;
|
|
22
32
|
table: TableOptions<T>;
|
|
33
|
+
syncMode?: SyncMode;
|
|
34
|
+
queryKey: readonly unknown[];
|
|
35
|
+
queryClient?: QueryClient;
|
|
23
36
|
useLoro?: boolean;
|
|
24
37
|
onError?: (e: unknown) => void;
|
|
25
38
|
};
|
|
26
39
|
|
|
27
40
|
declare function surrealCollectionOptions<T extends SyncedTable<object>, S extends Record<string, Container> = {
|
|
28
41
|
[k: string]: never;
|
|
29
|
-
}>({ id, useLoro, onError, db, ...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>;
|
|
30
43
|
|
|
31
|
-
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,25 +8,37 @@ 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
|
}>;
|
|
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
|
+
};
|
|
12
21
|
type TableOptions<T> = {
|
|
13
22
|
name: string;
|
|
14
|
-
fields?:
|
|
23
|
+
fields?: FieldList<T>;
|
|
15
24
|
where?: ExprLike;
|
|
16
25
|
};
|
|
26
|
+
type SyncMode = 'eager' | 'on-demand';
|
|
17
27
|
type SurrealCollectionConfig<T extends {
|
|
18
28
|
id: string | RecordId;
|
|
19
29
|
}> = {
|
|
20
30
|
id?: string;
|
|
21
31
|
db: Surreal;
|
|
22
32
|
table: TableOptions<T>;
|
|
33
|
+
syncMode?: SyncMode;
|
|
34
|
+
queryKey: readonly unknown[];
|
|
35
|
+
queryClient?: QueryClient;
|
|
23
36
|
useLoro?: boolean;
|
|
24
37
|
onError?: (e: unknown) => void;
|
|
25
38
|
};
|
|
26
39
|
|
|
27
40
|
declare function surrealCollectionOptions<T extends SyncedTable<object>, S extends Record<string, Container> = {
|
|
28
41
|
[k: string]: never;
|
|
29
|
-
}>({ id, useLoro, onError, db, ...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>;
|
|
30
43
|
|
|
31
|
-
export { surrealCollectionOptions };
|
|
44
|
+
export { type SurrealSubset, surrealCollectionOptions };
|