@interncom/diplomatic 0.0.25 → 0.0.27
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.ts +2 -2
- package/dist/index.mjs +9 -0
- package/dist/state.d.ts +10 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useClientState, useSyncOnResume } from "./useClient";
|
|
2
|
-
import { StateManager, useStateWatcher } from './state';
|
|
2
|
+
import { StateManager, useStateWatcher, opMapApplier } from './state';
|
|
3
3
|
import { localStorageStore } from "./localStorageStore";
|
|
4
4
|
import { idbStore } from "./idbStore";
|
|
5
5
|
import type { IDiplomaticClientState } from "./types";
|
|
@@ -7,5 +7,5 @@ import DiplomaticClient from "./client";
|
|
|
7
7
|
import libsodiumCrypto from "./crypto";
|
|
8
8
|
import { btoh, htob } from "./shared/lib";
|
|
9
9
|
import { type IOp, Verb } from "./shared/types";
|
|
10
|
-
export { useClientState, useSyncOnResume, StateManager, useStateWatcher, localStorageStore, idbStore, DiplomaticClient, libsodiumCrypto, btoh, htob, Verb, };
|
|
10
|
+
export { useClientState, useSyncOnResume, StateManager, useStateWatcher, opMapApplier, localStorageStore, idbStore, DiplomaticClient, libsodiumCrypto, btoh, htob, Verb, };
|
|
11
11
|
export type { IOp, IDiplomaticClientState, };
|
package/dist/index.mjs
CHANGED
|
@@ -101,6 +101,14 @@ function useStateWatcher(mgr, opType, callback) {
|
|
|
101
101
|
}, [mgr, opType, callback]);
|
|
102
102
|
return val;
|
|
103
103
|
}
|
|
104
|
+
function opMapApplier(appliers) {
|
|
105
|
+
return async (op) => {
|
|
106
|
+
const applier = appliers[op.type];
|
|
107
|
+
if (applier?.check(op)) {
|
|
108
|
+
await applier.apply(op);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
104
112
|
|
|
105
113
|
// ../shared/lib.ts
|
|
106
114
|
function btoh(bytes) {
|
|
@@ -9019,6 +9027,7 @@ export {
|
|
|
9019
9027
|
idbStore,
|
|
9020
9028
|
crypto_default as libsodiumCrypto,
|
|
9021
9029
|
localStorageStore,
|
|
9030
|
+
opMapApplier,
|
|
9022
9031
|
useClientState,
|
|
9023
9032
|
useStateWatcher,
|
|
9024
9033
|
useSyncOnResume
|
package/dist/state.d.ts
CHANGED
|
@@ -4,10 +4,19 @@ import type { IOp } from "./shared/types";
|
|
|
4
4
|
export declare class StateManager {
|
|
5
5
|
emitter: EventEmitter;
|
|
6
6
|
applier: Applier;
|
|
7
|
-
clear: () => void
|
|
7
|
+
clear: () => Promise<void>;
|
|
8
8
|
constructor(applier: Applier, clear: () => Promise<void>);
|
|
9
9
|
apply: (op: IOp) => Promise<void>;
|
|
10
10
|
on: (opType: string, listener: () => void) => void;
|
|
11
11
|
off: (opType: string, listener: () => void) => void;
|
|
12
12
|
}
|
|
13
13
|
export declare function useStateWatcher<T>(mgr: StateManager, opType: string, callback: () => T): T;
|
|
14
|
+
interface IApplier<T extends IOp> {
|
|
15
|
+
check: (op: IOp) => op is T;
|
|
16
|
+
apply: (op: T) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
type Appliers<M> = {
|
|
19
|
+
[K in keyof M]: M[K] extends IOp ? IApplier<M[K]> : never;
|
|
20
|
+
};
|
|
21
|
+
export declare function opMapApplier<M>(appliers: Appliers<M>): (op: IOp) => Promise<void>;
|
|
22
|
+
export {};
|