@baukit/sync-client 0.18.2 → 0.19.0
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/browser.d.ts.map +1 -1
- package/dist/browser.js +9 -7
- package/dist/browser.js.map +1 -1
- package/dist/conformance-cases.d.ts +4 -0
- package/dist/conformance-cases.d.ts.map +1 -0
- package/dist/conformance-cases.js +242 -0
- package/dist/conformance-cases.js.map +1 -0
- package/dist/conformance-kit.d.ts +23 -0
- package/dist/conformance-kit.d.ts.map +1 -0
- package/dist/conformance-kit.js +85 -0
- package/dist/conformance-kit.js.map +1 -0
- package/dist/conformance-resync-cases.d.ts +4 -0
- package/dist/conformance-resync-cases.d.ts.map +1 -0
- package/dist/conformance-resync-cases.js +143 -0
- package/dist/conformance-resync-cases.js.map +1 -0
- package/dist/conformance-support.d.ts +17 -0
- package/dist/conformance-support.d.ts.map +1 -0
- package/dist/conformance-support.js +62 -0
- package/dist/conformance-support.js.map +1 -0
- package/dist/conformance.d.ts.map +1 -1
- package/dist/conformance.js +6 -437
- package/dist/conformance.js.map +1 -1
- package/dist/expo.d.ts.map +1 -1
- package/dist/expo.js +3 -2
- package/dist/expo.js.map +1 -1
- package/dist/push-batch.js +1 -1
- package/dist/push-batch.js.map +1 -1
- package/dist/timer-handles.d.ts +12 -0
- package/dist/timer-handles.d.ts.map +1 -0
- package/dist/timer-handles.js +19 -0
- package/dist/timer-handles.js.map +1 -0
- package/dist/transport.js +1 -1
- package/dist/transport.js.map +1 -1
- package/package.json +3 -3
- package/src/browser.ts +11 -8
- package/src/conformance-cases.ts +496 -0
- package/src/conformance-kit.ts +159 -0
- package/src/conformance-resync-cases.ts +378 -0
- package/src/conformance-support.ts +91 -0
- package/src/conformance.ts +6 -671
- package/src/expo.ts +6 -6
- package/src/push-batch.ts +1 -1
- package/src/timer-handles.test.ts +33 -0
- package/src/timer-handles.ts +31 -0
- package/src/transport.ts +1 -1
package/src/expo.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as Network from 'expo-network';
|
|
|
2
2
|
import { AppState, Platform } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import type { SyncSchedulerEnvironment, SyncSchedulerTimer } from './scheduler.js';
|
|
5
|
+
import { createOpaqueIntervalTimers } from './timer-handles.js';
|
|
5
6
|
|
|
6
7
|
export interface ExpoSyncTimers {
|
|
7
8
|
setInterval(callback: () => void, milliseconds: number): SyncSchedulerTimer;
|
|
@@ -18,13 +19,12 @@ interface ExpoNetworkModule {
|
|
|
18
19
|
addNetworkStateListener?: (listener: (state: Network.NetworkState) => void) => { remove(): void };
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
const defaultTimers: ExpoSyncTimers = {
|
|
22
|
-
setInterval: (callback, milliseconds) =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
globalThis.clearInterval(handle as unknown as ReturnType<typeof globalThis.setInterval>);
|
|
22
|
+
const defaultTimers: ExpoSyncTimers = createOpaqueIntervalTimers({
|
|
23
|
+
setInterval: (callback, milliseconds) => globalThis.setInterval(callback, milliseconds),
|
|
24
|
+
clearInterval: (handle: ReturnType<typeof globalThis.setInterval>) => {
|
|
25
|
+
globalThis.clearInterval(handle);
|
|
26
26
|
},
|
|
27
|
-
};
|
|
27
|
+
});
|
|
28
28
|
|
|
29
29
|
function isUsableNetwork(state: Network.NetworkState): boolean {
|
|
30
30
|
return state.isConnected === true && state.isInternetReachable !== false;
|
package/src/push-batch.ts
CHANGED
|
@@ -96,7 +96,7 @@ export function rankPushBatch<T extends PushCandidate>(
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
return [...grouped.values()]
|
|
99
|
-
.filter(({ change }) =>
|
|
99
|
+
.filter(({ change }) => isHeldBack?.(change) !== true)
|
|
100
100
|
.sort(
|
|
101
101
|
(left, right) =>
|
|
102
102
|
rank(left.change.entityType) - rank(right.change.entityType) || left.order - right.order,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createOpaqueIntervalTimers } from './timer-handles.js';
|
|
4
|
+
|
|
5
|
+
describe('createOpaqueIntervalTimers', () => {
|
|
6
|
+
it('returns an object handle and clears the matching host id', () => {
|
|
7
|
+
const host = { setInterval: vi.fn(() => 42), clearInterval: vi.fn() };
|
|
8
|
+
const timers = createOpaqueIntervalTimers(host);
|
|
9
|
+
const callback = vi.fn();
|
|
10
|
+
|
|
11
|
+
const handle = timers.setInterval(callback, 500);
|
|
12
|
+
timers.clearInterval(handle);
|
|
13
|
+
|
|
14
|
+
expect(typeof handle).toBe('object');
|
|
15
|
+
expect(host.setInterval).toHaveBeenCalledWith(callback, 500);
|
|
16
|
+
expect(host.clearInterval).toHaveBeenCalledWith(42);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('keeps distinct handles for repeated host ids and ignores unknown or cleared handles', () => {
|
|
20
|
+
const host = { setInterval: vi.fn(() => 0), clearInterval: vi.fn() };
|
|
21
|
+
const timers = createOpaqueIntervalTimers(host);
|
|
22
|
+
|
|
23
|
+
const first = timers.setInterval(vi.fn(), 1);
|
|
24
|
+
const second = timers.setInterval(vi.fn(), 1);
|
|
25
|
+
timers.clearInterval(first);
|
|
26
|
+
timers.clearInterval(first);
|
|
27
|
+
timers.clearInterval({});
|
|
28
|
+
|
|
29
|
+
expect(first).not.toBe(second);
|
|
30
|
+
expect(host.clearInterval).toHaveBeenCalledTimes(1);
|
|
31
|
+
expect(host.clearInterval).toHaveBeenCalledWith(0);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SyncSchedulerTimer } from './scheduler.js';
|
|
2
|
+
|
|
3
|
+
export interface HostIntervalTimers<THandle> {
|
|
4
|
+
setInterval(callback: () => void, milliseconds: number): THandle;
|
|
5
|
+
clearInterval(handle: THandle): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface OpaqueIntervalTimers {
|
|
9
|
+
setInterval(callback: () => void, milliseconds: number): SyncSchedulerTimer;
|
|
10
|
+
clearInterval(handle: SyncSchedulerTimer): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Wraps host interval ids, whatever their runtime type, in opaque object handles. */
|
|
14
|
+
export function createOpaqueIntervalTimers<THandle>(
|
|
15
|
+
host: HostIntervalTimers<THandle>,
|
|
16
|
+
): OpaqueIntervalTimers {
|
|
17
|
+
const hostHandles = new WeakMap<SyncSchedulerTimer, { readonly id: THandle }>();
|
|
18
|
+
return {
|
|
19
|
+
setInterval(callback, milliseconds) {
|
|
20
|
+
const handle: SyncSchedulerTimer = {};
|
|
21
|
+
hostHandles.set(handle, { id: host.setInterval(callback, milliseconds) });
|
|
22
|
+
return handle;
|
|
23
|
+
},
|
|
24
|
+
clearInterval(handle) {
|
|
25
|
+
const hostHandle = hostHandles.get(handle);
|
|
26
|
+
if (hostHandle === undefined) return;
|
|
27
|
+
hostHandles.delete(handle);
|
|
28
|
+
host.clearInterval(hostHandle.id);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
package/src/transport.ts
CHANGED
|
@@ -278,7 +278,7 @@ export class SyncTransport {
|
|
|
278
278
|
const forwardAbort = (): void => {
|
|
279
279
|
controller.abort(callerSignal?.reason);
|
|
280
280
|
};
|
|
281
|
-
if (callerSignal?.aborted) forwardAbort();
|
|
281
|
+
if (callerSignal?.aborted === true) forwardAbort();
|
|
282
282
|
callerSignal?.addEventListener('abort', forwardAbort, { once: true });
|
|
283
283
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
284
284
|
const deadline = new Promise<never>((_, reject) => {
|