@taladb/react 0.9.2 → 0.9.3
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 +54 -9
- package/dist/index.d.ts +54 -9
- package/dist/index.js +33 -4
- package/dist/index.mjs +56 -21
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { TalaDB, OpenDBOptions,
|
|
3
|
+
import { CollectionOptions, Document, TalaDB, OpenDBOptions, Collection, Filter } from 'taladb';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Per-collection options (`schema`, `syncSchema`, `migrateDocument`, …), keyed by
|
|
7
|
+
* collection name.
|
|
8
|
+
*
|
|
9
|
+
* Register them once on the provider and every hook below it — `useCollection`,
|
|
10
|
+
* and therefore `useFind`, `useQuery` and `useMutation` — resolves a *configured*
|
|
11
|
+
* collection. Without this, those hooks call `db.collection(name)` with no
|
|
12
|
+
* options, so a hook-driven write silently skips the strict `schema` validation
|
|
13
|
+
* and the `_v` stamp that `db.collection(name, { … })` would have applied.
|
|
14
|
+
*/
|
|
15
|
+
type CollectionRegistry = Record<string, CollectionOptions<any>>;
|
|
16
|
+
/** Resolves the registered options for a collection. Stable across renders. */
|
|
17
|
+
interface CollectionResolver {
|
|
18
|
+
get<T extends Document>(name: string): CollectionOptions<T> | undefined;
|
|
19
|
+
}
|
|
20
|
+
declare function useCollectionOptions(): CollectionResolver;
|
|
21
|
+
type SharedProps = {
|
|
6
22
|
children: ReactNode;
|
|
7
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Per-collection options, keyed by collection name — see {@link CollectionRegistry}.
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <TalaDBProvider
|
|
28
|
+
* name="app.db"
|
|
29
|
+
* collections={{
|
|
30
|
+
* bookings: { schema: BookingSchema, syncSchema: { version: 1 } },
|
|
31
|
+
* }}
|
|
32
|
+
* >
|
|
33
|
+
* ```
|
|
34
|
+
* Treated as static configuration: read when a collection handle is first
|
|
35
|
+
* created, so an inline object here does not thrash live queries.
|
|
36
|
+
*/
|
|
37
|
+
collections?: CollectionRegistry;
|
|
38
|
+
};
|
|
39
|
+
type TalaDBProviderProps = SharedProps & ({
|
|
8
40
|
/** A TalaDB instance you opened yourself with `openDB()`. */
|
|
9
41
|
db: TalaDB;
|
|
10
42
|
name?: never;
|
|
@@ -57,17 +89,30 @@ declare function useTalaDB(): TalaDB;
|
|
|
57
89
|
/**
|
|
58
90
|
* Returns a stable `Collection<T>` handle from the nearest `<TalaDBProvider>`.
|
|
59
91
|
*
|
|
60
|
-
* The
|
|
61
|
-
*
|
|
62
|
-
*
|
|
92
|
+
* The collection is opened **with its registered options** — the `schema`,
|
|
93
|
+
* `syncSchema` and `migrateDocument` declared in the provider's `collections`
|
|
94
|
+
* prop, or the `options` passed here (which win). That is what makes a write
|
|
95
|
+
* through `useMutation` hard-fail on an invalid document and carry its `_v`
|
|
96
|
+
* shape version, exactly as `db.collection(name, { … })` does. Without it the
|
|
97
|
+
* hooks resolve a bare, unconfigured handle and silently skip validation.
|
|
63
98
|
*
|
|
64
|
-
*
|
|
99
|
+
* The returned collection is memoised — the same object reference is returned on
|
|
100
|
+
* every render unless the db instance or collection name changes. Pass it
|
|
101
|
+
* directly to `useFind` or `useFindOne` without wrapping in `useMemo`. Options
|
|
102
|
+
* are read when the handle is first created and treated as static configuration,
|
|
103
|
+
* so an inline `{ schema }` object cannot thrash live-query subscriptions.
|
|
104
|
+
*
|
|
105
|
+
* @param name The collection name (e.g. `'articles'`).
|
|
106
|
+
* @param options Per-call options; overrides the provider's registry entry.
|
|
65
107
|
*
|
|
66
108
|
* @example
|
|
109
|
+
* // Registered once on the provider — every hook below it picks this up:
|
|
110
|
+
* <TalaDBProvider name="app.db" collections={{ articles: { schema: Article } }}>
|
|
111
|
+
*
|
|
67
112
|
* const articles = useCollection<Article>('articles')
|
|
68
113
|
* const { data, loading } = useFind(articles, { locale: 'en' })
|
|
69
114
|
*/
|
|
70
|
-
declare function useCollection<T extends Document>(name: string): Collection<T>;
|
|
115
|
+
declare function useCollection<T extends Document>(name: string, options?: CollectionOptions<T>): Collection<T>;
|
|
71
116
|
|
|
72
117
|
interface FindResult<T> {
|
|
73
118
|
/** The current matching documents. Empty array while loading. */
|
|
@@ -347,4 +392,4 @@ interface MutationResult<T extends Document> {
|
|
|
347
392
|
*/
|
|
348
393
|
declare function useMutation<T extends Document>(options: UseMutationOptions): MutationResult<T>;
|
|
349
394
|
|
|
350
|
-
export { type FindOneResult, type FindResult, type MutationResult, type PrefetchEntry, type PrefetchMode, type PrefetchSlice, type QueryResult, type ReadSource, type ReplicationConfig, ReplicationProvider, type ReplicationProviderProps, TalaDBProvider, type TalaDBProviderProps, type UseMutationOptions, type UseQueryOptions, type WriteOp, useCollection, useFind, useFindOne, useMutation, useQueries, useQuery, useReplicationConfig, useTalaDB };
|
|
395
|
+
export { type CollectionRegistry, type CollectionResolver, type FindOneResult, type FindResult, type MutationResult, type PrefetchEntry, type PrefetchMode, type PrefetchSlice, type QueryResult, type ReadSource, type ReplicationConfig, ReplicationProvider, type ReplicationProviderProps, TalaDBProvider, type TalaDBProviderProps, type UseMutationOptions, type UseQueryOptions, type WriteOp, useCollection, useCollectionOptions, useFind, useFindOne, useMutation, useQueries, useQuery, useReplicationConfig, useTalaDB };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { TalaDB, OpenDBOptions,
|
|
3
|
+
import { CollectionOptions, Document, TalaDB, OpenDBOptions, Collection, Filter } from 'taladb';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Per-collection options (`schema`, `syncSchema`, `migrateDocument`, …), keyed by
|
|
7
|
+
* collection name.
|
|
8
|
+
*
|
|
9
|
+
* Register them once on the provider and every hook below it — `useCollection`,
|
|
10
|
+
* and therefore `useFind`, `useQuery` and `useMutation` — resolves a *configured*
|
|
11
|
+
* collection. Without this, those hooks call `db.collection(name)` with no
|
|
12
|
+
* options, so a hook-driven write silently skips the strict `schema` validation
|
|
13
|
+
* and the `_v` stamp that `db.collection(name, { … })` would have applied.
|
|
14
|
+
*/
|
|
15
|
+
type CollectionRegistry = Record<string, CollectionOptions<any>>;
|
|
16
|
+
/** Resolves the registered options for a collection. Stable across renders. */
|
|
17
|
+
interface CollectionResolver {
|
|
18
|
+
get<T extends Document>(name: string): CollectionOptions<T> | undefined;
|
|
19
|
+
}
|
|
20
|
+
declare function useCollectionOptions(): CollectionResolver;
|
|
21
|
+
type SharedProps = {
|
|
6
22
|
children: ReactNode;
|
|
7
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Per-collection options, keyed by collection name — see {@link CollectionRegistry}.
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <TalaDBProvider
|
|
28
|
+
* name="app.db"
|
|
29
|
+
* collections={{
|
|
30
|
+
* bookings: { schema: BookingSchema, syncSchema: { version: 1 } },
|
|
31
|
+
* }}
|
|
32
|
+
* >
|
|
33
|
+
* ```
|
|
34
|
+
* Treated as static configuration: read when a collection handle is first
|
|
35
|
+
* created, so an inline object here does not thrash live queries.
|
|
36
|
+
*/
|
|
37
|
+
collections?: CollectionRegistry;
|
|
38
|
+
};
|
|
39
|
+
type TalaDBProviderProps = SharedProps & ({
|
|
8
40
|
/** A TalaDB instance you opened yourself with `openDB()`. */
|
|
9
41
|
db: TalaDB;
|
|
10
42
|
name?: never;
|
|
@@ -57,17 +89,30 @@ declare function useTalaDB(): TalaDB;
|
|
|
57
89
|
/**
|
|
58
90
|
* Returns a stable `Collection<T>` handle from the nearest `<TalaDBProvider>`.
|
|
59
91
|
*
|
|
60
|
-
* The
|
|
61
|
-
*
|
|
62
|
-
*
|
|
92
|
+
* The collection is opened **with its registered options** — the `schema`,
|
|
93
|
+
* `syncSchema` and `migrateDocument` declared in the provider's `collections`
|
|
94
|
+
* prop, or the `options` passed here (which win). That is what makes a write
|
|
95
|
+
* through `useMutation` hard-fail on an invalid document and carry its `_v`
|
|
96
|
+
* shape version, exactly as `db.collection(name, { … })` does. Without it the
|
|
97
|
+
* hooks resolve a bare, unconfigured handle and silently skip validation.
|
|
63
98
|
*
|
|
64
|
-
*
|
|
99
|
+
* The returned collection is memoised — the same object reference is returned on
|
|
100
|
+
* every render unless the db instance or collection name changes. Pass it
|
|
101
|
+
* directly to `useFind` or `useFindOne` without wrapping in `useMemo`. Options
|
|
102
|
+
* are read when the handle is first created and treated as static configuration,
|
|
103
|
+
* so an inline `{ schema }` object cannot thrash live-query subscriptions.
|
|
104
|
+
*
|
|
105
|
+
* @param name The collection name (e.g. `'articles'`).
|
|
106
|
+
* @param options Per-call options; overrides the provider's registry entry.
|
|
65
107
|
*
|
|
66
108
|
* @example
|
|
109
|
+
* // Registered once on the provider — every hook below it picks this up:
|
|
110
|
+
* <TalaDBProvider name="app.db" collections={{ articles: { schema: Article } }}>
|
|
111
|
+
*
|
|
67
112
|
* const articles = useCollection<Article>('articles')
|
|
68
113
|
* const { data, loading } = useFind(articles, { locale: 'en' })
|
|
69
114
|
*/
|
|
70
|
-
declare function useCollection<T extends Document>(name: string): Collection<T>;
|
|
115
|
+
declare function useCollection<T extends Document>(name: string, options?: CollectionOptions<T>): Collection<T>;
|
|
71
116
|
|
|
72
117
|
interface FindResult<T> {
|
|
73
118
|
/** The current matching documents. Empty array while loading. */
|
|
@@ -347,4 +392,4 @@ interface MutationResult<T extends Document> {
|
|
|
347
392
|
*/
|
|
348
393
|
declare function useMutation<T extends Document>(options: UseMutationOptions): MutationResult<T>;
|
|
349
394
|
|
|
350
|
-
export { type FindOneResult, type FindResult, type MutationResult, type PrefetchEntry, type PrefetchMode, type PrefetchSlice, type QueryResult, type ReadSource, type ReplicationConfig, ReplicationProvider, type ReplicationProviderProps, TalaDBProvider, type TalaDBProviderProps, type UseMutationOptions, type UseQueryOptions, type WriteOp, useCollection, useFind, useFindOne, useMutation, useQueries, useQuery, useReplicationConfig, useTalaDB };
|
|
395
|
+
export { type CollectionRegistry, type CollectionResolver, type FindOneResult, type FindResult, type MutationResult, type PrefetchEntry, type PrefetchMode, type PrefetchSlice, type QueryResult, type ReadSource, type ReplicationConfig, ReplicationProvider, type ReplicationProviderProps, TalaDBProvider, type TalaDBProviderProps, type UseMutationOptions, type UseQueryOptions, type WriteOp, useCollection, useCollectionOptions, useFind, useFindOne, useMutation, useQueries, useQuery, useReplicationConfig, useTalaDB };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
ReplicationProvider: () => ReplicationProvider,
|
|
35
35
|
TalaDBProvider: () => TalaDBProvider,
|
|
36
36
|
useCollection: () => useCollection,
|
|
37
|
+
useCollectionOptions: () => useCollectionOptions,
|
|
37
38
|
useFind: () => useFind,
|
|
38
39
|
useFindOne: () => useFindOne,
|
|
39
40
|
useMutation: () => useMutation,
|
|
@@ -48,9 +49,29 @@ module.exports = __toCommonJS(index_exports);
|
|
|
48
49
|
var import_react = require("react");
|
|
49
50
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
50
51
|
var TalaDBContext = (0, import_react.createContext)(null);
|
|
52
|
+
var CollectionOptionsContext = (0, import_react.createContext)({
|
|
53
|
+
get: () => void 0
|
|
54
|
+
});
|
|
55
|
+
function useCollectionOptions() {
|
|
56
|
+
return (0, import_react.useContext)(CollectionOptionsContext);
|
|
57
|
+
}
|
|
58
|
+
function CollectionOptionsProvider({
|
|
59
|
+
collections,
|
|
60
|
+
children
|
|
61
|
+
}) {
|
|
62
|
+
const latest = (0, import_react.useRef)(collections);
|
|
63
|
+
latest.current = collections;
|
|
64
|
+
const resolver = (0, import_react.useMemo)(
|
|
65
|
+
() => ({
|
|
66
|
+
get: (name) => latest.current?.[name]
|
|
67
|
+
}),
|
|
68
|
+
[]
|
|
69
|
+
);
|
|
70
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionOptionsContext.Provider, { value: resolver, children });
|
|
71
|
+
}
|
|
51
72
|
function TalaDBProvider(props) {
|
|
52
73
|
if ("db" in props && props.db) {
|
|
53
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TalaDBContext.Provider, { value: props.db, children: props.children });
|
|
74
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TalaDBContext.Provider, { value: props.db, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionOptionsProvider, { collections: props.collections, children: props.children }) });
|
|
54
75
|
}
|
|
55
76
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NamedProvider, { ...props });
|
|
56
77
|
}
|
|
@@ -58,6 +79,7 @@ function NamedProvider({
|
|
|
58
79
|
name,
|
|
59
80
|
options,
|
|
60
81
|
fallback = null,
|
|
82
|
+
collections,
|
|
61
83
|
children
|
|
62
84
|
}) {
|
|
63
85
|
const [db, setDb] = (0, import_react.useState)(null);
|
|
@@ -85,7 +107,7 @@ function NamedProvider({
|
|
|
85
107
|
}, [name, optionsKey]);
|
|
86
108
|
if (error !== null) throw error;
|
|
87
109
|
if (db === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: fallback });
|
|
88
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TalaDBContext.Provider, { value: db, children });
|
|
110
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TalaDBContext.Provider, { value: db, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionOptionsProvider, { collections, children }) });
|
|
89
111
|
}
|
|
90
112
|
function useTalaDB() {
|
|
91
113
|
const db = (0, import_react.useContext)(TalaDBContext);
|
|
@@ -97,9 +119,15 @@ function useTalaDB() {
|
|
|
97
119
|
|
|
98
120
|
// src/useCollection.ts
|
|
99
121
|
var import_react2 = require("react");
|
|
100
|
-
function useCollection(name) {
|
|
122
|
+
function useCollection(name, options) {
|
|
101
123
|
const db = useTalaDB();
|
|
102
|
-
|
|
124
|
+
const registry = useCollectionOptions();
|
|
125
|
+
const explicit = (0, import_react2.useRef)(options);
|
|
126
|
+
explicit.current = options;
|
|
127
|
+
return (0, import_react2.useMemo)(
|
|
128
|
+
() => db.collection(name, explicit.current ?? registry.get(name)),
|
|
129
|
+
[db, name, registry]
|
|
130
|
+
);
|
|
103
131
|
}
|
|
104
132
|
|
|
105
133
|
// src/useFind.ts
|
|
@@ -541,6 +569,7 @@ function useMutation(options) {
|
|
|
541
569
|
ReplicationProvider,
|
|
542
570
|
TalaDBProvider,
|
|
543
571
|
useCollection,
|
|
572
|
+
useCollectionOptions,
|
|
544
573
|
useFind,
|
|
545
574
|
useFindOne,
|
|
546
575
|
useMutation,
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
// src/context.tsx
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState
|
|
11
|
+
} from "react";
|
|
5
12
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6
13
|
var TalaDBContext = createContext(null);
|
|
14
|
+
var CollectionOptionsContext = createContext({
|
|
15
|
+
get: () => void 0
|
|
16
|
+
});
|
|
17
|
+
function useCollectionOptions() {
|
|
18
|
+
return useContext(CollectionOptionsContext);
|
|
19
|
+
}
|
|
20
|
+
function CollectionOptionsProvider({
|
|
21
|
+
collections,
|
|
22
|
+
children
|
|
23
|
+
}) {
|
|
24
|
+
const latest = useRef(collections);
|
|
25
|
+
latest.current = collections;
|
|
26
|
+
const resolver = useMemo(
|
|
27
|
+
() => ({
|
|
28
|
+
get: (name) => latest.current?.[name]
|
|
29
|
+
}),
|
|
30
|
+
[]
|
|
31
|
+
);
|
|
32
|
+
return /* @__PURE__ */ jsx(CollectionOptionsContext.Provider, { value: resolver, children });
|
|
33
|
+
}
|
|
7
34
|
function TalaDBProvider(props) {
|
|
8
35
|
if ("db" in props && props.db) {
|
|
9
|
-
return /* @__PURE__ */ jsx(TalaDBContext.Provider, { value: props.db, children: props.children });
|
|
36
|
+
return /* @__PURE__ */ jsx(TalaDBContext.Provider, { value: props.db, children: /* @__PURE__ */ jsx(CollectionOptionsProvider, { collections: props.collections, children: props.children }) });
|
|
10
37
|
}
|
|
11
38
|
return /* @__PURE__ */ jsx(NamedProvider, { ...props });
|
|
12
39
|
}
|
|
@@ -14,6 +41,7 @@ function NamedProvider({
|
|
|
14
41
|
name,
|
|
15
42
|
options,
|
|
16
43
|
fallback = null,
|
|
44
|
+
collections,
|
|
17
45
|
children
|
|
18
46
|
}) {
|
|
19
47
|
const [db, setDb] = useState(null);
|
|
@@ -41,7 +69,7 @@ function NamedProvider({
|
|
|
41
69
|
}, [name, optionsKey]);
|
|
42
70
|
if (error !== null) throw error;
|
|
43
71
|
if (db === null) return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
44
|
-
return /* @__PURE__ */ jsx(TalaDBContext.Provider, { value: db, children });
|
|
72
|
+
return /* @__PURE__ */ jsx(TalaDBContext.Provider, { value: db, children: /* @__PURE__ */ jsx(CollectionOptionsProvider, { collections, children }) });
|
|
45
73
|
}
|
|
46
74
|
function useTalaDB() {
|
|
47
75
|
const db = useContext(TalaDBContext);
|
|
@@ -52,16 +80,22 @@ function useTalaDB() {
|
|
|
52
80
|
}
|
|
53
81
|
|
|
54
82
|
// src/useCollection.ts
|
|
55
|
-
import { useMemo } from "react";
|
|
56
|
-
function useCollection(name) {
|
|
83
|
+
import { useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
84
|
+
function useCollection(name, options) {
|
|
57
85
|
const db = useTalaDB();
|
|
58
|
-
|
|
86
|
+
const registry = useCollectionOptions();
|
|
87
|
+
const explicit = useRef2(options);
|
|
88
|
+
explicit.current = options;
|
|
89
|
+
return useMemo2(
|
|
90
|
+
() => db.collection(name, explicit.current ?? registry.get(name)),
|
|
91
|
+
[db, name, registry]
|
|
92
|
+
);
|
|
59
93
|
}
|
|
60
94
|
|
|
61
95
|
// src/useFind.ts
|
|
62
|
-
import { useCallback, useRef, useSyncExternalStore } from "react";
|
|
96
|
+
import { useCallback, useRef as useRef3, useSyncExternalStore } from "react";
|
|
63
97
|
function useFind(collection, filter) {
|
|
64
|
-
const snapshotRef =
|
|
98
|
+
const snapshotRef = useRef3({ data: [], loading: true, error: null });
|
|
65
99
|
const filterKey = JSON.stringify(filter ?? null);
|
|
66
100
|
const subscribe = useCallback(
|
|
67
101
|
(notify) => {
|
|
@@ -83,9 +117,9 @@ function useFind(collection, filter) {
|
|
|
83
117
|
}
|
|
84
118
|
|
|
85
119
|
// src/useFindOne.ts
|
|
86
|
-
import { useCallback as useCallback2, useRef as
|
|
120
|
+
import { useCallback as useCallback2, useRef as useRef4, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
87
121
|
function useFindOne(collection, filter) {
|
|
88
|
-
const snapshotRef =
|
|
122
|
+
const snapshotRef = useRef4({ data: null, loading: true, error: null });
|
|
89
123
|
const filterKey = JSON.stringify(filter);
|
|
90
124
|
const subscribe = useCallback2(
|
|
91
125
|
(notify) => {
|
|
@@ -110,8 +144,8 @@ import {
|
|
|
110
144
|
createContext as createContext2,
|
|
111
145
|
useContext as useContext2,
|
|
112
146
|
useEffect as useEffect2,
|
|
113
|
-
useMemo as
|
|
114
|
-
useRef as
|
|
147
|
+
useMemo as useMemo3,
|
|
148
|
+
useRef as useRef5
|
|
115
149
|
} from "react";
|
|
116
150
|
|
|
117
151
|
// src/replication/engine.ts
|
|
@@ -170,7 +204,7 @@ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
|
170
204
|
var ReplicationContext = createContext2(null);
|
|
171
205
|
function ReplicationProvider({ children, ...config }) {
|
|
172
206
|
const key = `${config.endpoint}|${config.pollMs ?? ""}|${JSON.stringify(config.paths ?? null)}|${JSON.stringify(config.prefetch ?? null)}|${config.prefetchMode ?? ""}|${config.prefetchConcurrency ?? ""}`;
|
|
173
|
-
const value =
|
|
207
|
+
const value = useMemo3(
|
|
174
208
|
() => config,
|
|
175
209
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
176
210
|
[key]
|
|
@@ -228,7 +262,7 @@ function PrefetchRunner() {
|
|
|
228
262
|
const slices = normalizePrefetch(base?.prefetch);
|
|
229
263
|
const mode = base?.prefetchMode ?? "once";
|
|
230
264
|
const concurrency = Math.max(1, base?.prefetchConcurrency ?? 2);
|
|
231
|
-
const baseRef =
|
|
265
|
+
const baseRef = useRef5(base);
|
|
232
266
|
baseRef.current = base;
|
|
233
267
|
const sig = JSON.stringify({ slices, mode, concurrency, endpoint: base?.endpoint ?? null });
|
|
234
268
|
useEffect2(() => {
|
|
@@ -267,7 +301,7 @@ function PrefetchRunner() {
|
|
|
267
301
|
}
|
|
268
302
|
|
|
269
303
|
// src/useQuery.ts
|
|
270
|
-
import { useCallback as useCallback3, useEffect as useEffect3, useRef as
|
|
304
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef6, useState as useState2 } from "react";
|
|
271
305
|
function useQuery(options) {
|
|
272
306
|
const { collection, filter, source = "local-first" } = options;
|
|
273
307
|
const networked = source !== "local-only";
|
|
@@ -281,7 +315,7 @@ function useQuery(options) {
|
|
|
281
315
|
paths: options.paths,
|
|
282
316
|
pollMs: options.pollMs
|
|
283
317
|
});
|
|
284
|
-
const configRef =
|
|
318
|
+
const configRef = useRef6(config);
|
|
285
319
|
configRef.current = config;
|
|
286
320
|
const [syncing, setSyncing] = useState2(false);
|
|
287
321
|
const [syncError, setSyncError] = useState2(null);
|
|
@@ -320,7 +354,7 @@ function useQuery(options) {
|
|
|
320
354
|
}
|
|
321
355
|
|
|
322
356
|
// src/useQueries.ts
|
|
323
|
-
import { useEffect as useEffect4, useRef as
|
|
357
|
+
import { useEffect as useEffect4, useRef as useRef7, useState as useState3 } from "react";
|
|
324
358
|
var NOOP_REFETCH = async () => {
|
|
325
359
|
};
|
|
326
360
|
function emptyResult() {
|
|
@@ -346,9 +380,9 @@ function useQueries(queries) {
|
|
|
346
380
|
pollMs: q.pollMs ?? null
|
|
347
381
|
}))
|
|
348
382
|
);
|
|
349
|
-
const queriesRef =
|
|
383
|
+
const queriesRef = useRef7(queries);
|
|
350
384
|
queriesRef.current = queries;
|
|
351
|
-
const baseRef =
|
|
385
|
+
const baseRef = useRef7(base);
|
|
352
386
|
baseRef.current = base;
|
|
353
387
|
const [results, setResults] = useState3(
|
|
354
388
|
() => queries.map(() => emptyResult())
|
|
@@ -426,7 +460,7 @@ function useQueries(queries) {
|
|
|
426
460
|
}
|
|
427
461
|
|
|
428
462
|
// src/useMutation.ts
|
|
429
|
-
import { useCallback as useCallback4, useEffect as useEffect5, useRef as
|
|
463
|
+
import { useCallback as useCallback4, useEffect as useEffect5, useRef as useRef8, useState as useState4 } from "react";
|
|
430
464
|
function useMutation(options) {
|
|
431
465
|
const { collection, direction = "push", drainOnMount = true } = options;
|
|
432
466
|
const db = useTalaDB();
|
|
@@ -437,7 +471,7 @@ function useMutation(options) {
|
|
|
437
471
|
fetch: options.fetch,
|
|
438
472
|
paths: options.paths
|
|
439
473
|
});
|
|
440
|
-
const configRef =
|
|
474
|
+
const configRef = useRef8(config);
|
|
441
475
|
configRef.current = config;
|
|
442
476
|
const [pending, setPending] = useState4(false);
|
|
443
477
|
const [error, setError] = useState4(null);
|
|
@@ -502,6 +536,7 @@ export {
|
|
|
502
536
|
ReplicationProvider,
|
|
503
537
|
TalaDBProvider,
|
|
504
538
|
useCollection,
|
|
539
|
+
useCollectionOptions,
|
|
505
540
|
useFind,
|
|
506
541
|
useFindOne,
|
|
507
542
|
useMutation,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taladb/react",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "React hooks for TalaDB — useFind, useFindOne, and useCollection for React and React Native",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=18.0.0",
|
|
44
|
-
"taladb": "^0.9.
|
|
44
|
+
"taladb": "^0.9.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@testing-library/react": "^16.0.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"tsup": "^8.0.0",
|
|
54
54
|
"typescript": "^5.9.3",
|
|
55
55
|
"vitest": "^3.2.0",
|
|
56
|
-
"taladb": "0.9.
|
|
56
|
+
"taladb": "0.9.3"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup",
|