@drakkar.software/starfish-client 1.19.0 → 1.19.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/dist/bindings/legend.js +60 -60
- package/dist/bindings/legend.js.map +7 -0
- package/dist/bindings/zustand.js +565 -250
- package/dist/bindings/zustand.js.map +7 -0
- package/dist/broadcast.js +69 -79
- package/dist/broadcast.js.map +7 -0
- package/dist/fetch.js +131 -156
- package/dist/fetch.js.map +7 -0
- package/dist/group-crypto.js +188 -213
- package/dist/group-crypto.js.map +7 -0
- package/dist/identity.js +346 -154
- package/dist/identity.js.map +7 -0
- package/dist/index.js +1344 -25
- package/dist/index.js.map +7 -0
- package/dist/testing.js +64 -83
- package/dist/testing.js.map +7 -0
- package/package.json +3 -2
package/dist/bindings/legend.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
+
// src/bindings/legend.ts
|
|
1
2
|
import { observable } from "@legendapp/state";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
function createStarfishObservable(options) {
|
|
4
|
+
const state = observable({
|
|
5
|
+
data: {},
|
|
6
|
+
syncing: false,
|
|
7
|
+
online: true,
|
|
8
|
+
dirty: false,
|
|
9
|
+
error: null
|
|
10
|
+
});
|
|
11
|
+
const flush = async () => {
|
|
12
|
+
if (state.syncing.get() || !state.dirty.get()) return;
|
|
13
|
+
state.syncing.set(true);
|
|
14
|
+
state.error.set(null);
|
|
15
|
+
try {
|
|
16
|
+
await options.syncManager.push(state.data.get());
|
|
17
|
+
state.data.set(options.syncManager.getData());
|
|
18
|
+
state.dirty.set(false);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
state.error.set(err instanceof Error ? err.message : String(err));
|
|
21
|
+
} finally {
|
|
22
|
+
state.syncing.set(false);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const pull = async () => {
|
|
26
|
+
state.syncing.set(true);
|
|
27
|
+
state.error.set(null);
|
|
28
|
+
try {
|
|
29
|
+
await options.syncManager.pull();
|
|
30
|
+
state.data.set(options.syncManager.getData());
|
|
31
|
+
} catch (err) {
|
|
32
|
+
state.error.set(err instanceof Error ? err.message : String(err));
|
|
33
|
+
} finally {
|
|
34
|
+
state.syncing.set(false);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const set = (modifier) => {
|
|
38
|
+
try {
|
|
39
|
+
const current = state.data.get();
|
|
40
|
+
const next = options.produce ? options.produce(
|
|
41
|
+
current,
|
|
42
|
+
modifier
|
|
43
|
+
) : modifier(current);
|
|
44
|
+
state.data.set(next);
|
|
45
|
+
state.dirty.set(true);
|
|
46
|
+
state.error.set(null);
|
|
47
|
+
if (state.online.get()) flush().catch(() => {
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
state.error.set(err instanceof Error ? err.message : String(err));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const setOnline = (online) => {
|
|
54
|
+
state.online.set(online);
|
|
55
|
+
if (online && state.dirty.get()) flush().catch(() => {
|
|
9
56
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return;
|
|
13
|
-
state.syncing.set(true);
|
|
14
|
-
state.error.set(null);
|
|
15
|
-
try {
|
|
16
|
-
await options.syncManager.push(state.data.get());
|
|
17
|
-
state.data.set(options.syncManager.getData());
|
|
18
|
-
state.dirty.set(false);
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
state.error.set(err instanceof Error ? err.message : String(err));
|
|
22
|
-
}
|
|
23
|
-
finally {
|
|
24
|
-
state.syncing.set(false);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const pull = async () => {
|
|
28
|
-
state.syncing.set(true);
|
|
29
|
-
state.error.set(null);
|
|
30
|
-
try {
|
|
31
|
-
await options.syncManager.pull();
|
|
32
|
-
state.data.set(options.syncManager.getData());
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
state.error.set(err instanceof Error ? err.message : String(err));
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
state.syncing.set(false);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const set = (modifier) => {
|
|
42
|
-
try {
|
|
43
|
-
const current = state.data.get();
|
|
44
|
-
const next = options.produce
|
|
45
|
-
? options.produce(current, modifier)
|
|
46
|
-
: modifier(current);
|
|
47
|
-
state.data.set(next);
|
|
48
|
-
state.dirty.set(true);
|
|
49
|
-
state.error.set(null);
|
|
50
|
-
if (state.online.get())
|
|
51
|
-
flush().catch(() => { });
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
state.error.set(err instanceof Error ? err.message : String(err));
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const setOnline = (online) => {
|
|
58
|
-
state.online.set(online);
|
|
59
|
-
if (online && state.dirty.get())
|
|
60
|
-
flush().catch(() => { });
|
|
61
|
-
};
|
|
62
|
-
return { state, pull, set, flush, setOnline };
|
|
57
|
+
};
|
|
58
|
+
return { state, pull, set, flush, setOnline };
|
|
63
59
|
}
|
|
60
|
+
export {
|
|
61
|
+
createStarfishObservable
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=legend.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/bindings/legend.ts"],
|
|
4
|
+
"sourcesContent": ["import { observable } from \"@legendapp/state\"\nimport type { Observable } from \"@legendapp/state\"\nimport type { SyncManager } from \"../sync.js\"\n\nexport interface StarfishLegendState {\n data: Record<string, unknown>\n syncing: boolean\n online: boolean\n dirty: boolean\n error: string | null\n}\n\nexport interface StarfishLegendStore {\n /** The observable state tree \u2014 read fields with `.get()` inside `observer` components. */\n state: Observable<StarfishLegendState>\n pull: () => Promise<void>\n set: (modifier: (current: Record<string, unknown>) => Record<string, unknown>) => void\n flush: () => Promise<void>\n setOnline: (online: boolean) => void\n}\n\nexport interface CreateStarfishObservableOptions {\n /** Unique name for this collection (used for persistence keys when applicable). */\n name: string\n syncManager: SyncManager\n /** Pass `produce` from `immer` to enable draft-based mutations in `set()`. */\n produce?: <T>(base: T, recipe: (draft: T) => T | void) => T\n}\n\nexport function createStarfishObservable(\n options: CreateStarfishObservableOptions,\n): StarfishLegendStore {\n const state = observable<StarfishLegendState>({\n data: {},\n syncing: false,\n online: true,\n dirty: false,\n error: null,\n })\n\n const flush = async (): Promise<void> => {\n if (state.syncing.get() || !state.dirty.get()) return\n state.syncing.set(true)\n state.error.set(null)\n try {\n await options.syncManager.push(state.data.get())\n state.data.set(options.syncManager.getData())\n state.dirty.set(false)\n } catch (err) {\n state.error.set(err instanceof Error ? err.message : String(err))\n } finally {\n state.syncing.set(false)\n }\n }\n\n const pull = async (): Promise<void> => {\n state.syncing.set(true)\n state.error.set(null)\n try {\n await options.syncManager.pull()\n state.data.set(options.syncManager.getData())\n } catch (err) {\n state.error.set(err instanceof Error ? err.message : String(err))\n } finally {\n state.syncing.set(false)\n }\n }\n\n const set = (\n modifier: (current: Record<string, unknown>) => Record<string, unknown>,\n ): void => {\n try {\n const current = state.data.get()\n const next = options.produce\n ? options.produce(\n current,\n modifier as (draft: Record<string, unknown>) => Record<string, unknown> | void,\n )\n : modifier(current)\n state.data.set(next)\n state.dirty.set(true)\n state.error.set(null)\n if (state.online.get()) flush().catch(() => {})\n } catch (err) {\n state.error.set(err instanceof Error ? err.message : String(err))\n }\n }\n\n const setOnline = (online: boolean): void => {\n state.online.set(online)\n if (online && state.dirty.get()) flush().catch(() => {})\n }\n\n return { state, pull, set, flush, setOnline }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,kBAAkB;AA6BpB,SAAS,yBACd,SACqB;AACrB,QAAM,QAAQ,WAAgC;AAAA,IAC5C,MAAM,CAAC;AAAA,IACP,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AA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