@syncular/client-react 0.0.6-73 → 0.0.6-80
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/use-cached-async-value.d.ts.map +1 -1
- package/dist/use-cached-async-value.js +2 -1
- package/dist/use-cached-async-value.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/integration/provider-reconfig.test.ts +10 -3
- package/src/__tests__/test-utils.ts +8 -8
- package/src/use-cached-async-value.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-cached-async-value.d.ts","sourceRoot":"","sources":["../src/use-cached-async-value.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-cached-async-value.d.ts","sourceRoot":"","sources":["../src/use-cached-async-value.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,0BAA0B,CAAC,IAAI,GAAG,OAAO;IACxD;;;OAGG;IACH,GAAG,CAAC,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,GAAG,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,EACnC,OAAO,CAAC,EAAE,0BAA0B,GACnC,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,CAgCxC;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAE7D;AAED,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
|
|
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import { createAsyncInitRegistry } from './async-init-registry.js';
|
|
3
3
|
const cachedAsyncValueRegistry = createAsyncInitRegistry();
|
|
4
4
|
const EMPTY_DEPS = Object.freeze([]);
|
|
5
|
+
const DEFAULT_KEY = 'default';
|
|
5
6
|
/**
|
|
6
7
|
* Resolve an async value with a process-wide cache outside component state.
|
|
7
8
|
* Returns the resolved value and error tuple: [value, error].
|
|
@@ -11,7 +12,7 @@ export function useCachedAsyncValue(run, options) {
|
|
|
11
12
|
const [error, setError] = useState(null);
|
|
12
13
|
const runRef = useRef(run);
|
|
13
14
|
runRef.current = run;
|
|
14
|
-
const key = options?.key ??
|
|
15
|
+
const key = options?.key ?? DEFAULT_KEY;
|
|
15
16
|
const deps = options?.deps ?? EMPTY_DEPS;
|
|
16
17
|
useEffect(() => {
|
|
17
18
|
let cancelled = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-cached-async-value.js","sourceRoot":"","sources":["../src/use-cached-async-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,wBAAwB,GAAG,uBAAuB,EAAoB,CAAC;AAE7E,MAAM,UAAU,GAAuB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-cached-async-value.js","sourceRoot":"","sources":["../src/use-cached-async-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,wBAAwB,GAAG,uBAAuB,EAAoB,CAAC;AAE7E,MAAM,UAAU,GAAuB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACzD,MAAM,WAAW,GAAG,SAAS,CAAC;AAc9B;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAmC,EACnC,OAAoC,EACI;IACxC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC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UAAU,sBAAsB,GAAS;IAC7C,wBAAwB,CAAC,KAAK,EAAE,CAAC;AAAA,CAClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client-react",
|
|
3
|
-
"version": "0.0.6-
|
|
3
|
+
"version": "0.0.6-80",
|
|
4
4
|
"description": "React hooks and bindings for the Syncular client",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"release": "bunx syncular-publish"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@syncular/client": "0.0.6-
|
|
47
|
+
"@syncular/client": "0.0.6-80"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"kysely": "^0.28.0",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@happy-dom/global-registrator": "^20.6.3",
|
|
55
55
|
"@syncular/config": "0.0.0",
|
|
56
|
-
"@syncular/
|
|
57
|
-
"@syncular/
|
|
56
|
+
"@syncular/core": "0.0.6-80",
|
|
57
|
+
"@syncular/dialect-bun-sqlite": "0.0.6-80",
|
|
58
|
+
"@syncular/testkit": "0.0.6-80",
|
|
58
59
|
"@testing-library/react": "^16.3.2",
|
|
59
60
|
"@types/react": "^19.2.14",
|
|
60
61
|
"happy-dom": "^20.6.3",
|
|
61
62
|
"kysely": "*",
|
|
62
|
-
"kysely-bun-sqlite": "^0.4.0",
|
|
63
63
|
"react": "^19.2.4",
|
|
64
64
|
"react-dom": "^19.2.4"
|
|
65
65
|
},
|
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
type SyncClientDb,
|
|
12
12
|
SyncEngine,
|
|
13
13
|
} from '@syncular/client';
|
|
14
|
-
import {
|
|
14
|
+
import { createDatabase } from '@syncular/core';
|
|
15
|
+
import { createBunSqliteDialect } from '@syncular/dialect-bun-sqlite';
|
|
15
16
|
import { cleanup, render } from '@testing-library/react';
|
|
16
17
|
import type { Kysely } from 'kysely';
|
|
17
18
|
import { createElement } from 'react';
|
|
@@ -50,7 +51,10 @@ describe('SyncProvider Reconfiguration', () => {
|
|
|
50
51
|
|
|
51
52
|
beforeEach(async () => {
|
|
52
53
|
server = await createTestServer();
|
|
53
|
-
db =
|
|
54
|
+
db = createDatabase<ClientDb>({
|
|
55
|
+
dialect: createBunSqliteDialect({ path: ':memory:' }),
|
|
56
|
+
family: 'sqlite',
|
|
57
|
+
});
|
|
54
58
|
mockHandlers = createMockClientHandlers();
|
|
55
59
|
|
|
56
60
|
await ensureClientSyncSchema(db);
|
|
@@ -201,7 +205,10 @@ describe('SyncProvider React render tests', () => {
|
|
|
201
205
|
};
|
|
202
206
|
|
|
203
207
|
beforeEach(async () => {
|
|
204
|
-
db =
|
|
208
|
+
db = createDatabase<ClientDb>({
|
|
209
|
+
dialect: createBunSqliteDialect({ path: ':memory:' }),
|
|
210
|
+
family: 'sqlite',
|
|
211
|
+
});
|
|
205
212
|
mockHandlers = [];
|
|
206
213
|
await ensureClientSyncSchema(db);
|
|
207
214
|
});
|
|
@@ -98,14 +98,14 @@ export async function createMockDb<
|
|
|
98
98
|
DB extends SyncClientDb = SyncClientDb,
|
|
99
99
|
>(): Promise<Kysely<DB>> {
|
|
100
100
|
// Dynamic import to avoid bundling issues
|
|
101
|
-
const {
|
|
102
|
-
const {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
const { createDatabase } = await import('@syncular/core');
|
|
102
|
+
const { createBunSqliteDialect } = await import(
|
|
103
|
+
'@syncular/dialect-bun-sqlite'
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const db = createDatabase<DB>({
|
|
107
|
+
dialect: createBunSqliteDialect({ path: ':memory:' }),
|
|
108
|
+
family: 'sqlite',
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
// Create sync tables
|
|
@@ -4,6 +4,7 @@ import { createAsyncInitRegistry } from './async-init-registry';
|
|
|
4
4
|
const cachedAsyncValueRegistry = createAsyncInitRegistry<unknown, unknown>();
|
|
5
5
|
|
|
6
6
|
const EMPTY_DEPS: readonly unknown[] = Object.freeze([]);
|
|
7
|
+
const DEFAULT_KEY = 'default';
|
|
7
8
|
|
|
8
9
|
export interface UseCachedAsyncValueOptions<TKey = unknown> {
|
|
9
10
|
/**
|
|
@@ -31,7 +32,7 @@ export function useCachedAsyncValue<TValue>(
|
|
|
31
32
|
const runRef = useRef(run);
|
|
32
33
|
runRef.current = run;
|
|
33
34
|
|
|
34
|
-
const key = options?.key ??
|
|
35
|
+
const key = options?.key ?? DEFAULT_KEY;
|
|
35
36
|
const deps = options?.deps ?? EMPTY_DEPS;
|
|
36
37
|
|
|
37
38
|
useEffect(() => {
|