@eloxiv/client 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/Account.d.ts +131 -0
- package/dist/Account.d.ts.map +1 -0
- package/dist/Account.js +169 -0
- package/dist/Account.js.map +1 -0
- package/dist/Agent.d.ts +496 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +228 -0
- package/dist/Agent.js.map +1 -0
- package/dist/AgentSync.d.ts +990 -0
- package/dist/AgentSync.d.ts.map +1 -0
- package/dist/AgentSync.js +46 -0
- package/dist/AgentSync.js.map +1 -0
- package/dist/AppState.d.ts +127 -0
- package/dist/AppState.d.ts.map +1 -0
- package/dist/AppState.js +145 -0
- package/dist/AppState.js.map +1 -0
- package/dist/AppStateSync.d.ts +193 -0
- package/dist/AppStateSync.d.ts.map +1 -0
- package/dist/AppStateSync.js +23 -0
- package/dist/AppStateSync.js.map +1 -0
- package/dist/Auth.d.ts +95 -0
- package/dist/Auth.d.ts.map +1 -0
- package/dist/Auth.js +139 -0
- package/dist/Auth.js.map +1 -0
- package/dist/Avatars.d.ts +53 -0
- package/dist/Avatars.d.ts.map +1 -0
- package/dist/Avatars.js +121 -0
- package/dist/Avatars.js.map +1 -0
- package/dist/BrowserAnalytics.d.ts +56 -0
- package/dist/BrowserAnalytics.d.ts.map +1 -0
- package/dist/BrowserAnalytics.js +94 -0
- package/dist/BrowserAnalytics.js.map +1 -0
- package/dist/Chat.d.ts +712 -0
- package/dist/Chat.d.ts.map +1 -0
- package/dist/Chat.js +883 -0
- package/dist/Chat.js.map +1 -0
- package/dist/ChatIntegrity.d.ts +63 -0
- package/dist/ChatIntegrity.d.ts.map +1 -0
- package/dist/ChatIntegrity.js +89 -0
- package/dist/ChatIntegrity.js.map +1 -0
- package/dist/ChatSends.d.ts +103 -0
- package/dist/ChatSends.d.ts.map +1 -0
- package/dist/ChatSends.js +157 -0
- package/dist/ChatSends.js.map +1 -0
- package/dist/Client.d.ts +113 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +189 -0
- package/dist/Client.js.map +1 -0
- package/dist/Collab.d.ts +138 -0
- package/dist/Collab.d.ts.map +1 -0
- package/dist/Collab.js +454 -0
- package/dist/Collab.js.map +1 -0
- package/dist/CollabTools.d.ts +129 -0
- package/dist/CollabTools.d.ts.map +1 -0
- package/dist/CollabTools.js +277 -0
- package/dist/CollabTools.js.map +1 -0
- package/dist/Connections.d.ts +288 -0
- package/dist/Connections.d.ts.map +1 -0
- package/dist/Connections.js +316 -0
- package/dist/Connections.js.map +1 -0
- package/dist/Consent.d.ts +338 -0
- package/dist/Consent.d.ts.map +1 -0
- package/dist/Consent.js +142 -0
- package/dist/Consent.js.map +1 -0
- package/dist/Desktop.d.ts +61 -0
- package/dist/Desktop.d.ts.map +1 -0
- package/dist/Desktop.js +101 -0
- package/dist/Desktop.js.map +1 -0
- package/dist/Directory.d.ts +36 -0
- package/dist/Directory.d.ts.map +1 -0
- package/dist/Directory.js +42 -0
- package/dist/Directory.js.map +1 -0
- package/dist/ErrorReporter.d.ts +48 -0
- package/dist/ErrorReporter.d.ts.map +1 -0
- package/dist/ErrorReporter.js +70 -0
- package/dist/ErrorReporter.js.map +1 -0
- package/dist/ExpoSqlite.d.ts +7 -0
- package/dist/ExpoSqlite.d.ts.map +1 -0
- package/dist/ExpoSqlite.js +7 -0
- package/dist/ExpoSqlite.js.map +1 -0
- package/dist/FileSync.d.ts +265 -0
- package/dist/FileSync.d.ts.map +1 -0
- package/dist/FileSync.js +29 -0
- package/dist/FileSync.js.map +1 -0
- package/dist/FileTables.gen.d.ts +109 -0
- package/dist/FileTables.gen.d.ts.map +1 -0
- package/dist/FileTables.gen.js +23 -0
- package/dist/FileTables.gen.js.map +1 -0
- package/dist/Foldkit.d.ts +487 -0
- package/dist/Foldkit.d.ts.map +1 -0
- package/dist/Foldkit.js +617 -0
- package/dist/Foldkit.js.map +1 -0
- package/dist/History.d.ts +133 -0
- package/dist/History.d.ts.map +1 -0
- package/dist/History.js +210 -0
- package/dist/History.js.map +1 -0
- package/dist/InboxSync.d.ts +428 -0
- package/dist/InboxSync.d.ts.map +1 -0
- package/dist/InboxSync.js +37 -0
- package/dist/InboxSync.js.map +1 -0
- package/dist/KernelTables.gen.d.ts +1522 -0
- package/dist/KernelTables.gen.d.ts.map +1 -0
- package/dist/KernelTables.gen.js +307 -0
- package/dist/KernelTables.gen.js.map +1 -0
- package/dist/Make.d.ts +75 -0
- package/dist/Make.d.ts.map +1 -0
- package/dist/Make.js +70 -0
- package/dist/Make.js.map +1 -0
- package/dist/Models.d.ts +88 -0
- package/dist/Models.d.ts.map +1 -0
- package/dist/Models.js +80 -0
- package/dist/Models.js.map +1 -0
- package/dist/Optimistic.d.ts +120 -0
- package/dist/Optimistic.d.ts.map +1 -0
- package/dist/Optimistic.js +231 -0
- package/dist/Optimistic.js.map +1 -0
- package/dist/PlatformSync.d.ts +273 -0
- package/dist/PlatformSync.d.ts.map +1 -0
- package/dist/PlatformSync.js +92 -0
- package/dist/PlatformSync.js.map +1 -0
- package/dist/Poll.d.ts +113 -0
- package/dist/Poll.d.ts.map +1 -0
- package/dist/Poll.js +179 -0
- package/dist/Poll.js.map +1 -0
- package/dist/Preferences.d.ts +18 -0
- package/dist/Preferences.d.ts.map +1 -0
- package/dist/Preferences.js +22 -0
- package/dist/Preferences.js.map +1 -0
- package/dist/Proposals.d.ts +29 -0
- package/dist/Proposals.d.ts.map +1 -0
- package/dist/Proposals.js +41 -0
- package/dist/Proposals.js.map +1 -0
- package/dist/React.d.ts +17 -0
- package/dist/React.d.ts.map +1 -0
- package/dist/React.js +17 -0
- package/dist/React.js.map +1 -0
- package/dist/Reader.d.ts +35 -0
- package/dist/Reader.d.ts.map +1 -0
- package/dist/Reader.js +136 -0
- package/dist/Reader.js.map +1 -0
- package/dist/Resources.d.ts +98 -0
- package/dist/Resources.d.ts.map +1 -0
- package/dist/Resources.js +161 -0
- package/dist/Resources.js.map +1 -0
- package/dist/Rows.d.ts +4 -0
- package/dist/Rows.d.ts.map +1 -0
- package/dist/Rows.js +16 -0
- package/dist/Rows.js.map +1 -0
- package/dist/Runtime.d.ts +254 -0
- package/dist/Runtime.d.ts.map +1 -0
- package/dist/Runtime.js +1249 -0
- package/dist/Runtime.js.map +1 -0
- package/dist/RuntimeRuns.d.ts +74 -0
- package/dist/RuntimeRuns.d.ts.map +1 -0
- package/dist/RuntimeRuns.js +118 -0
- package/dist/RuntimeRuns.js.map +1 -0
- package/dist/ServicesSync.d.ts +286 -0
- package/dist/ServicesSync.d.ts.map +1 -0
- package/dist/ServicesSync.js +40 -0
- package/dist/ServicesSync.js.map +1 -0
- package/dist/Session.d.ts +226 -0
- package/dist/Session.d.ts.map +1 -0
- package/dist/Session.js +763 -0
- package/dist/Session.js.map +1 -0
- package/dist/ShareGrant.d.ts +47 -0
- package/dist/ShareGrant.d.ts.map +1 -0
- package/dist/ShareGrant.js +20 -0
- package/dist/ShareGrant.js.map +1 -0
- package/dist/Sharing.d.ts +203 -0
- package/dist/Sharing.d.ts.map +1 -0
- package/dist/Sharing.js +520 -0
- package/dist/Sharing.js.map +1 -0
- package/dist/Skew.d.ts +52 -0
- package/dist/Skew.d.ts.map +1 -0
- package/dist/Skew.js +77 -0
- package/dist/Skew.js.map +1 -0
- package/dist/SpacesSync.d.ts +247 -0
- package/dist/SpacesSync.d.ts.map +1 -0
- package/dist/SpacesSync.js +30 -0
- package/dist/SpacesSync.js.map +1 -0
- package/dist/Storage.d.ts +51 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/Storage.js +107 -0
- package/dist/Storage.js.map +1 -0
- package/dist/Sync.d.ts +48 -0
- package/dist/Sync.d.ts.map +1 -0
- package/dist/Sync.js +48 -0
- package/dist/Sync.js.map +1 -0
- package/dist/SyncTables.d.ts +13 -0
- package/dist/SyncTables.d.ts.map +1 -0
- package/dist/SyncTables.js +13 -0
- package/dist/SyncTables.js.map +1 -0
- package/dist/Tab.d.ts +36 -0
- package/dist/Tab.d.ts.map +1 -0
- package/dist/Tab.js +44 -0
- package/dist/Tab.js.map +1 -0
- package/dist/Transport.d.ts +139 -0
- package/dist/Transport.d.ts.map +1 -0
- package/dist/Transport.js +232 -0
- package/dist/Transport.js.map +1 -0
- package/dist/Upload.d.ts +41 -0
- package/dist/Upload.d.ts.map +1 -0
- package/dist/Upload.js +93 -0
- package/dist/Upload.js.map +1 -0
- package/dist/WebMcp.d.ts +78 -0
- package/dist/WebMcp.d.ts.map +1 -0
- package/dist/WebMcp.js +204 -0
- package/dist/WebMcp.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/package.json +97 -3
- package/src/Account.ts +249 -0
- package/src/Agent.ts +387 -0
- package/src/AgentSync.ts +59 -0
- package/src/AppState.ts +222 -0
- package/src/AppStateSync.ts +26 -0
- package/src/Auth.ts +225 -0
- package/src/Avatars.ts +144 -0
- package/src/BrowserAnalytics.ts +133 -0
- package/src/Chat.ts +1150 -0
- package/src/ChatIntegrity.ts +130 -0
- package/src/ChatSends.ts +209 -0
- package/src/Client.ts +319 -0
- package/src/Collab.ts +524 -0
- package/src/CollabTools.ts +381 -0
- package/src/Connections.ts +517 -0
- package/src/Consent.ts +176 -0
- package/src/Desktop.ts +139 -0
- package/src/Directory.ts +71 -0
- package/src/ErrorReporter.ts +112 -0
- package/src/ExpoSqlite.ts +6 -0
- package/src/FileSync.ts +34 -0
- package/src/FileTables.gen.ts +23 -0
- package/src/Foldkit.ts +960 -0
- package/src/History.ts +337 -0
- package/src/InboxSync.ts +47 -0
- package/src/KernelTables.gen.ts +329 -0
- package/src/Make.ts +120 -0
- package/src/Models.ts +134 -0
- package/src/Optimistic.ts +364 -0
- package/src/PlatformSync.ts +156 -0
- package/src/Poll.ts +227 -0
- package/src/Preferences.ts +42 -0
- package/src/Proposals.ts +57 -0
- package/src/React.ts +26 -0
- package/src/Reader.ts +180 -0
- package/src/Resources.ts +257 -0
- package/src/Rows.ts +16 -0
- package/src/Runtime.ts +1409 -0
- package/src/RuntimeRuns.ts +180 -0
- package/src/ServicesSync.ts +58 -0
- package/src/Session.ts +814 -0
- package/src/ShareGrant.ts +20 -0
- package/src/Sharing.ts +696 -0
- package/src/Skew.ts +97 -0
- package/src/SpacesSync.ts +61 -0
- package/src/Storage.ts +167 -0
- package/src/Sync.ts +125 -0
- package/src/SyncTables.ts +12 -0
- package/src/Tab.ts +59 -0
- package/src/Transport.ts +321 -0
- package/src/Upload.ts +125 -0
- package/src/WebMcp.ts +279 -0
- package/src/index.ts +26 -0
- package/src/web-globals.d.ts +103 -0
package/dist/Skew.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { satisfiesRange } from "@eloxiv/contracts";
|
|
2
|
+
import { isClientOutdated } from "./Client.js";
|
|
3
|
+
/** The kernel's release, past any HTTP cache (a query no cache has seen, and `no-store`). */
|
|
4
|
+
export const fetchFreshRelease = async (baseUrl) => {
|
|
5
|
+
const response = await fetch(`${baseUrl}/release?fresh=${Date.now().toString(36)}`, {
|
|
6
|
+
headers: { "cache-control": "no-store" },
|
|
7
|
+
});
|
|
8
|
+
if (!response.ok)
|
|
9
|
+
throw new Error(`/release answered ${response.status}`);
|
|
10
|
+
return (await response.json());
|
|
11
|
+
};
|
|
12
|
+
export const skewRecovery = (options) => {
|
|
13
|
+
let state = { kind: "current" };
|
|
14
|
+
const kept = [];
|
|
15
|
+
const listeners = new Set();
|
|
16
|
+
const set = (next) => {
|
|
17
|
+
state = next;
|
|
18
|
+
for (const listener of listeners)
|
|
19
|
+
listener(state);
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
state: () => state,
|
|
23
|
+
subscribe: (listener) => {
|
|
24
|
+
listeners.add(listener);
|
|
25
|
+
return () => {
|
|
26
|
+
listeners.delete(listener);
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Run a write; if the kernel refuses it as from an outdated build, keep it (`again` sends it again, with the
|
|
31
|
+
* same idempotency key) and offer the reload. Resolves with the write's result, or `undefined` when it was
|
|
32
|
+
* kept; any other failure is the write's own.
|
|
33
|
+
*/
|
|
34
|
+
write: async (again) => {
|
|
35
|
+
try {
|
|
36
|
+
return await again();
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (!isClientOutdated(error))
|
|
40
|
+
throw error;
|
|
41
|
+
kept.push(again);
|
|
42
|
+
// A typed call's error carries the minimum itself; a `send` or a batch read's, in its `error`.
|
|
43
|
+
const failure = error;
|
|
44
|
+
const stated = failure.minClientVersion ?? failure.error?.minClientVersion;
|
|
45
|
+
const minimum = typeof stated === "string" ? stated : "";
|
|
46
|
+
set({ kind: "reload-offered", minClientVersion: minimum, kept: kept.length });
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
/** The person chose to reload. The kept writes go with the page; the new build's screens are theirs to redo. */
|
|
51
|
+
reload: () => options.reload(),
|
|
52
|
+
/** The person declined the reload: the kept writes stay, for an explicit retry. */
|
|
53
|
+
decline: () => {
|
|
54
|
+
if (state.kind === "reload-offered")
|
|
55
|
+
set({ ...state, kind: "reload-declined" });
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Read the release afresh: if this build is accepted, send the kept writes again (in order) and return to
|
|
59
|
+
* `current`; if not, offer the reload again. Resolves with how many kept writes were sent.
|
|
60
|
+
*/
|
|
61
|
+
retry: async () => {
|
|
62
|
+
const release = await options.release();
|
|
63
|
+
const minimum = release.minClientVersion;
|
|
64
|
+
const accepted = minimum === null || satisfiesRange(options.clientVersion, `>=${minimum}`) === true;
|
|
65
|
+
if (!accepted) {
|
|
66
|
+
set({ kind: "reload-offered", minClientVersion: minimum ?? "", kept: kept.length });
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
const sending = kept.splice(0);
|
|
70
|
+
set({ kind: "current" });
|
|
71
|
+
for (const again of sending)
|
|
72
|
+
await again();
|
|
73
|
+
return sending.length;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=Skew.js.map
|
package/dist/Skew.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Skew.js","sourceRoot":"","sources":["../src/Skew.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAgB9C,6FAA6F;AAC7F,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAe,EAAwB,EAAE;IAC/E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,kBAAkB,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE;QAClF,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE;KACzC,CAAC,CAAA;IACF,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IACzE,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAgB,CAAA;AAC/C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAA4B,EAAE,EAAE;IAC3D,IAAI,KAAK,GAAc,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;IAC1C,MAAM,IAAI,GAAkC,EAAE,CAAA;IAC9C,MAAM,SAAS,GAAG,IAAI,GAAG,EAA8B,CAAA;IACvD,MAAM,GAAG,GAAG,CAAC,IAAe,EAAE,EAAE;QAC9B,KAAK,GAAG,IAAI,CAAA;QACZ,KAAK,MAAM,QAAQ,IAAI,SAAS;YAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;IACnD,CAAC,C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ACH,KAAK,EAAE,KAAK,IAAqB,EAAE;YACjC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,CAAA;YACvC,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAA;YACxC,MAAM,QAAQ,GAAG,OAAO,KAAK,IAAI,IAAI,cAAc,CAAC,OAAO,CAAC,aAAa,EAAE,KAAK,OAAO,EAAE,CAAC,KAAK,IAAI,CAAA;YACnG,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,GAAG,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;gBACnF,OAAO,CAAC,CAAA;YACV,CAAC;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;YAC9B,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;YACxB,KAAK,MAAM,KAAK,IAAI,OAAO;gBAAE,MAAM,KAAK,EAAE,CAAA;YAC1C,OAAO,OAAO,CAAC,MAAM,CAAA;QACvB,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { spaceGrantTable, spacePreferenceTable } from "./KernelTables.gen.ts";
|
|
2
|
+
export { spaceGrantTable, spacePreferenceTable };
|
|
3
|
+
export declare const spacesTables: readonly [import("@rocicorp/zero").TableBuilderWithColumns<{
|
|
4
|
+
name: "spaceGrant";
|
|
5
|
+
columns: {
|
|
6
|
+
readonly id: {
|
|
7
|
+
type: "string";
|
|
8
|
+
optional: false;
|
|
9
|
+
customType: string;
|
|
10
|
+
};
|
|
11
|
+
readonly spaceId: {
|
|
12
|
+
type: "string";
|
|
13
|
+
optional: false;
|
|
14
|
+
customType: string;
|
|
15
|
+
} & {
|
|
16
|
+
serverName: string;
|
|
17
|
+
};
|
|
18
|
+
readonly orgId: {
|
|
19
|
+
type: "string";
|
|
20
|
+
optional: false;
|
|
21
|
+
customType: string;
|
|
22
|
+
} & {
|
|
23
|
+
serverName: string;
|
|
24
|
+
};
|
|
25
|
+
readonly audience: {
|
|
26
|
+
type: "string";
|
|
27
|
+
optional: false;
|
|
28
|
+
customType: string;
|
|
29
|
+
};
|
|
30
|
+
readonly title: {
|
|
31
|
+
type: "string";
|
|
32
|
+
optional: false;
|
|
33
|
+
customType: string;
|
|
34
|
+
};
|
|
35
|
+
readonly description: Omit<{
|
|
36
|
+
type: "string";
|
|
37
|
+
optional: false;
|
|
38
|
+
customType: string;
|
|
39
|
+
}, "optional"> & {
|
|
40
|
+
optional: true;
|
|
41
|
+
};
|
|
42
|
+
readonly icon: Omit<{
|
|
43
|
+
type: "string";
|
|
44
|
+
optional: false;
|
|
45
|
+
customType: string;
|
|
46
|
+
}, "optional"> & {
|
|
47
|
+
optional: true;
|
|
48
|
+
};
|
|
49
|
+
readonly entries: {
|
|
50
|
+
type: "json";
|
|
51
|
+
optional: false;
|
|
52
|
+
customType: import("@rocicorp/zero").ReadonlyJSONValue;
|
|
53
|
+
};
|
|
54
|
+
readonly position: {
|
|
55
|
+
type: "number";
|
|
56
|
+
optional: false;
|
|
57
|
+
customType: number;
|
|
58
|
+
};
|
|
59
|
+
readonly withdrawn: {
|
|
60
|
+
type: "boolean";
|
|
61
|
+
optional: false;
|
|
62
|
+
customType: boolean;
|
|
63
|
+
};
|
|
64
|
+
readonly updatedBy: {
|
|
65
|
+
type: "string";
|
|
66
|
+
optional: false;
|
|
67
|
+
customType: string;
|
|
68
|
+
} & {
|
|
69
|
+
serverName: string;
|
|
70
|
+
};
|
|
71
|
+
readonly updatedAt: {
|
|
72
|
+
type: "number";
|
|
73
|
+
optional: false;
|
|
74
|
+
customType: number;
|
|
75
|
+
} & {
|
|
76
|
+
serverName: string;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
primaryKey: readonly [string, ...string[]];
|
|
80
|
+
} & {
|
|
81
|
+
primaryKey: ["id"];
|
|
82
|
+
}>, import("@rocicorp/zero").TableBuilderWithColumns<{
|
|
83
|
+
name: "spacePreference";
|
|
84
|
+
columns: {
|
|
85
|
+
readonly id: {
|
|
86
|
+
type: "string";
|
|
87
|
+
optional: false;
|
|
88
|
+
customType: string;
|
|
89
|
+
};
|
|
90
|
+
readonly orgId: {
|
|
91
|
+
type: "string";
|
|
92
|
+
optional: false;
|
|
93
|
+
customType: string;
|
|
94
|
+
} & {
|
|
95
|
+
serverName: string;
|
|
96
|
+
};
|
|
97
|
+
readonly userId: {
|
|
98
|
+
type: "string";
|
|
99
|
+
optional: false;
|
|
100
|
+
customType: string;
|
|
101
|
+
} & {
|
|
102
|
+
serverName: string;
|
|
103
|
+
};
|
|
104
|
+
readonly spaceId: {
|
|
105
|
+
type: "string";
|
|
106
|
+
optional: false;
|
|
107
|
+
customType: string;
|
|
108
|
+
} & {
|
|
109
|
+
serverName: string;
|
|
110
|
+
};
|
|
111
|
+
readonly grantId: {
|
|
112
|
+
type: "string";
|
|
113
|
+
optional: false;
|
|
114
|
+
customType: string;
|
|
115
|
+
} & {
|
|
116
|
+
serverName: string;
|
|
117
|
+
};
|
|
118
|
+
readonly pinned: Omit<{
|
|
119
|
+
type: "boolean";
|
|
120
|
+
optional: false;
|
|
121
|
+
customType: boolean;
|
|
122
|
+
}, "optional"> & {
|
|
123
|
+
optional: true;
|
|
124
|
+
};
|
|
125
|
+
readonly hidden: Omit<{
|
|
126
|
+
type: "boolean";
|
|
127
|
+
optional: false;
|
|
128
|
+
customType: boolean;
|
|
129
|
+
}, "optional"> & {
|
|
130
|
+
optional: true;
|
|
131
|
+
};
|
|
132
|
+
readonly position: Omit<{
|
|
133
|
+
type: "number";
|
|
134
|
+
optional: false;
|
|
135
|
+
customType: number;
|
|
136
|
+
}, "optional"> & {
|
|
137
|
+
optional: true;
|
|
138
|
+
};
|
|
139
|
+
readonly entryOrder: Omit<{
|
|
140
|
+
type: "json";
|
|
141
|
+
optional: false;
|
|
142
|
+
customType: import("@rocicorp/zero").ReadonlyJSONValue;
|
|
143
|
+
} & {
|
|
144
|
+
serverName: string;
|
|
145
|
+
}, "optional"> & {
|
|
146
|
+
optional: true;
|
|
147
|
+
};
|
|
148
|
+
readonly hiddenEntries: Omit<{
|
|
149
|
+
type: "json";
|
|
150
|
+
optional: false;
|
|
151
|
+
customType: import("@rocicorp/zero").ReadonlyJSONValue;
|
|
152
|
+
} & {
|
|
153
|
+
serverName: string;
|
|
154
|
+
}, "optional"> & {
|
|
155
|
+
optional: true;
|
|
156
|
+
};
|
|
157
|
+
readonly updatedAt: {
|
|
158
|
+
type: "number";
|
|
159
|
+
optional: false;
|
|
160
|
+
customType: number;
|
|
161
|
+
} & {
|
|
162
|
+
serverName: string;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
primaryKey: readonly [string, ...string[]];
|
|
166
|
+
} & {
|
|
167
|
+
primaryKey: ["id"];
|
|
168
|
+
}>];
|
|
169
|
+
export declare const spacesRelationships: readonly [{
|
|
170
|
+
name: "spaceGrant";
|
|
171
|
+
relationships: {
|
|
172
|
+
preferences: [{
|
|
173
|
+
readonly sourceField: readonly ("audience" | "description" | "entries" | "icon" | "id" | "orgId" | "position" | "spaceId" | "title" | "updatedAt" | "updatedBy" | "withdrawn")[];
|
|
174
|
+
readonly destField: readonly ("entryOrder" | "grantId" | "hidden" | "hiddenEntries" | "id" | "orgId" | "pinned" | "position" | "spaceId" | "updatedAt" | "userId")[];
|
|
175
|
+
readonly destSchema: "spacePreference";
|
|
176
|
+
readonly cardinality: 'many';
|
|
177
|
+
}];
|
|
178
|
+
};
|
|
179
|
+
}, {
|
|
180
|
+
name: "spacePreference";
|
|
181
|
+
relationships: {
|
|
182
|
+
grant: [{
|
|
183
|
+
readonly sourceField: readonly ("entryOrder" | "grantId" | "hidden" | "hiddenEntries" | "id" | "orgId" | "pinned" | "position" | "spaceId" | "updatedAt" | "userId")[];
|
|
184
|
+
readonly destField: readonly ("audience" | "description" | "entries" | "icon" | "id" | "orgId" | "position" | "spaceId" | "title" | "updatedAt" | "updatedBy" | "withdrawn")[];
|
|
185
|
+
readonly destSchema: "spaceGrant";
|
|
186
|
+
readonly cardinality: 'one';
|
|
187
|
+
}];
|
|
188
|
+
};
|
|
189
|
+
}];
|
|
190
|
+
/** Named queries, namespaced like a module's (`spaces.granted`, `spaces.preferences`). */
|
|
191
|
+
export declare const spacesQueries: {
|
|
192
|
+
spaces: {
|
|
193
|
+
/** Every space granted to you in the organisation you act in (the kernel adds the filter). */
|
|
194
|
+
granted: import("@rocicorp/zero").QueryDefinition<"spaceGrant", import("@rocicorp/zero").ReadonlyJSONValue | undefined, import("@rocicorp/zero").ReadonlyJSONValue | undefined, {
|
|
195
|
+
readonly id: string;
|
|
196
|
+
readonly spaceId: string;
|
|
197
|
+
readonly orgId: string;
|
|
198
|
+
readonly audience: string;
|
|
199
|
+
readonly title: string;
|
|
200
|
+
readonly description: string | null;
|
|
201
|
+
readonly icon: string | null;
|
|
202
|
+
readonly entries: import("@rocicorp/zero").ReadonlyJSONValue;
|
|
203
|
+
readonly position: number;
|
|
204
|
+
readonly withdrawn: boolean;
|
|
205
|
+
readonly updatedBy: string;
|
|
206
|
+
readonly updatedAt: number;
|
|
207
|
+
}, unknown>;
|
|
208
|
+
/** Your own preferences for your spaces. */
|
|
209
|
+
preferences: import("@rocicorp/zero").QueryDefinition<"spacePreference", import("@rocicorp/zero").ReadonlyJSONValue | undefined, import("@rocicorp/zero").ReadonlyJSONValue | undefined, {
|
|
210
|
+
readonly id: string;
|
|
211
|
+
readonly orgId: string;
|
|
212
|
+
readonly userId: string;
|
|
213
|
+
readonly spaceId: string;
|
|
214
|
+
readonly grantId: string;
|
|
215
|
+
readonly pinned: boolean | null;
|
|
216
|
+
readonly hidden: boolean | null;
|
|
217
|
+
readonly position: number | null;
|
|
218
|
+
readonly entryOrder: import("@rocicorp/zero").ReadonlyJSONValue;
|
|
219
|
+
readonly hiddenEntries: import("@rocicorp/zero").ReadonlyJSONValue;
|
|
220
|
+
readonly updatedAt: number;
|
|
221
|
+
}, unknown>;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
/** A grant row as the replica holds it (the columns `resolveSpaces` reads). */
|
|
225
|
+
export interface SpaceGrantRow {
|
|
226
|
+
readonly spaceId: string;
|
|
227
|
+
readonly title: string;
|
|
228
|
+
readonly description?: string | null | undefined;
|
|
229
|
+
readonly icon?: string | null | undefined;
|
|
230
|
+
readonly entries: ReadonlyArray<{
|
|
231
|
+
readonly view: string;
|
|
232
|
+
}>;
|
|
233
|
+
readonly position: number;
|
|
234
|
+
readonly updatedAt: number;
|
|
235
|
+
}
|
|
236
|
+
/** A preference row as the replica holds it. */
|
|
237
|
+
export interface SpacePreferenceRow {
|
|
238
|
+
readonly spaceId: string;
|
|
239
|
+
/** When set (the newest of a space's rows wins when it was set through several grants). */
|
|
240
|
+
readonly updatedAt?: number | undefined;
|
|
241
|
+
readonly pinned?: boolean | null | undefined;
|
|
242
|
+
readonly hidden?: boolean | null | undefined;
|
|
243
|
+
readonly position?: number | null | undefined;
|
|
244
|
+
readonly entryOrder?: ReadonlyArray<string> | null | undefined;
|
|
245
|
+
readonly hiddenEntries?: ReadonlyArray<string> | null | undefined;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=SpacesSync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpacesSync.d.ts","sourceRoot":"","sources":["../src/SpacesSync.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,eAAe,EAEf,oBAAoB,EACrB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAA;AAEhD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC9D,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;CAClE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spaces in each person's replica (the Space contract): the kernel-provided `spaces` module's synced tables
|
|
3
|
+
* (generated from its Drizzle tables, `KernelTables.gen.ts`) and named queries. An app that installs
|
|
4
|
+
* `spacesModule` adds `spacesTables`, `spacesRelationships` and `spacesQueries` to its sync schema;
|
|
5
|
+
* `@eloxiv/shell-core`'s `resolveSpaces` turns the rows into the person's spaces.
|
|
6
|
+
*
|
|
7
|
+
* The kernel filters every query by the entity's read policy, in the organisation the replica acts in:
|
|
8
|
+
* - grants (`spaceGrant`): one row per space and audience, synced only where the audience is everyone or a role
|
|
9
|
+
* the person holds (live: losing the role takes the row off the replica), never once withdrawn;
|
|
10
|
+
* - preferences (`spacePreference`): the person's own, one per grant they were set through, synced only while that
|
|
11
|
+
* grant reaches them; never anyone else's.
|
|
12
|
+
*/
|
|
13
|
+
import { createBuilder, createSchema, defineQueryWithType } from "@rocicorp/zero";
|
|
14
|
+
import { spaceGrantRelationships, spaceGrantTable, spacePreferenceRelationships, spacePreferenceTable, } from "./KernelTables.gen.js";
|
|
15
|
+
export { spaceGrantTable, spacePreferenceTable };
|
|
16
|
+
export const spacesTables = [spaceGrantTable, spacePreferenceTable];
|
|
17
|
+
export const spacesRelationships = [spaceGrantRelationships, spacePreferenceRelationships];
|
|
18
|
+
const localSchema = createSchema({ tables: [spaceGrantTable, spacePreferenceTable] });
|
|
19
|
+
const zql = createBuilder(localSchema);
|
|
20
|
+
const defineQuery = defineQueryWithType();
|
|
21
|
+
/** Named queries, namespaced like a module's (`spaces.granted`, `spaces.preferences`). */
|
|
22
|
+
export const spacesQueries = {
|
|
23
|
+
spaces: {
|
|
24
|
+
/** Every space granted to you in the organisation you act in (the kernel adds the filter). */
|
|
25
|
+
granted: defineQuery(() => zql.spaceGrant),
|
|
26
|
+
/** Your own preferences for your spaces. */
|
|
27
|
+
preferences: defineQuery(() => zql.spacePreference),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=SpacesSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpacesSync.js","sourceRoot":"","sources":["../src/SpacesSync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACjF,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAA;AAEhD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,eAAe,EAAE,oBAAoB,CAAU,CAAA;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,uBAAuB,EAAE,4BAA4B,CAAU,CAAA;AAEnG,MAAM,WAAW,GAAG,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC,eAAe,EAAE,oBAAoB,CAAC,EAAE,CAAC,CAAA;AACrF,MAAM,GAAG,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA;AACtC,MAAM,WAAW,GAAG,mBAAmB,EAAsB,CAAA;AAE7D,0FAA0F;AAC1F,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE;QACN,8FAA8F;QAC9F,OAAO,EAAE,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC;QAC1C,4CAA4C;QAC5C,WAAW,EAAE,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC;KACpD;CACF,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The StorageAdapter contract (decision 7; docs/contracts/storage-adapter.md): where the local replica lives.
|
|
3
|
+
* Each adapter is what `connectSync({ storage })` takes, with what it is:
|
|
4
|
+
*
|
|
5
|
+
* - `indexedDbStorage()`: IndexedDB, in browsers and webviews (Tauri's included). Durable.
|
|
6
|
+
* - `sqliteStorage(open)`: SQLite through any synchronous SQLite database (Bun's `bun:sqlite`, Node's
|
|
7
|
+
* `node:sqlite`, or another binding with the same shape), on desktop, servers and the daemon. Durable. On
|
|
8
|
+
* React Native, `expoSQLiteStoreProvider` from `@eloxiv/client/expo-sqlite` is the SQLite adapter.
|
|
9
|
+
* - `memoryStorage()`: memory only; nothing is kept (tests, short-lived processes).
|
|
10
|
+
*
|
|
11
|
+
* The SDK imports no SQLite binding itself (it runs everywhere); the caller passes one:
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { Database } from "bun:sqlite"
|
|
14
|
+
* connectSync({ ..., storage: sqliteStorage((file) => new Database(file), { directory }).storage })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import type { StorageAdapterInfo } from "@eloxiv/contracts";
|
|
18
|
+
import { type StoreProvider } from "@rocicorp/zero/sqlite";
|
|
19
|
+
import type { SyncStorage } from "./Sync.ts";
|
|
20
|
+
export interface StorageAdapter {
|
|
21
|
+
readonly info: StorageAdapterInfo;
|
|
22
|
+
/** What `connectSync` takes as `storage`. */
|
|
23
|
+
readonly storage: SyncStorage;
|
|
24
|
+
}
|
|
25
|
+
export declare const memoryStorage: () => StorageAdapter;
|
|
26
|
+
export declare const indexedDbStorage: () => StorageAdapter;
|
|
27
|
+
/** A prepared statement of a synchronous SQLite binding (`bun:sqlite`'s and `node:sqlite`'s have this shape). */
|
|
28
|
+
export interface SyncSqliteStatement {
|
|
29
|
+
run(...params: ReadonlyArray<string>): unknown;
|
|
30
|
+
all(...params: ReadonlyArray<string>): ReadonlyArray<unknown>;
|
|
31
|
+
}
|
|
32
|
+
/** A synchronous SQLite database (`new Database(file)` in Bun, `new DatabaseSync(file)` in Node). */
|
|
33
|
+
export interface SyncSqliteDatabase {
|
|
34
|
+
exec(sql: string): unknown;
|
|
35
|
+
prepare(sql: string): SyncSqliteStatement;
|
|
36
|
+
close(): unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface SqliteStorageOptions {
|
|
39
|
+
/** The directory the replica files live in (one file per person and organisation). */
|
|
40
|
+
readonly directory?: string | undefined;
|
|
41
|
+
readonly busyTimeout?: number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Also delete a dropped replica's files (the database and its WAL and shared-memory files). Without it, `drop`
|
|
44
|
+
* still wipes the replica in place (its table dropped and the file vacuumed), so nothing of it can be read back.
|
|
45
|
+
*/
|
|
46
|
+
readonly remove?: ((path: string) => void) | undefined;
|
|
47
|
+
}
|
|
48
|
+
export declare const sqliteStorage: (open: (path: string) => SyncSqliteDatabase, options?: SqliteStorageOptions) => StorageAdapter & {
|
|
49
|
+
readonly provider: StoreProvider;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=Storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE5C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;IACjC,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;CAC9B;AAED,eAAO,MAAM,aAAa,QAAO,cAG/B,CAAA;AAEF,eAAO,MAAM,gBAAgB,QAAO,cAGlC,CAAA;AAEF,iHAAiH;AACjH,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,GAAG,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,OAAO,CAAA;IAC9C,GAAG,CAAC,GAAG,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;CAC9D;AAED,qGAAqG;AACrG,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IAC1B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAAA;IACzC,KAAK,IAAI,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,sFAAsF;IACtF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;CACvD;AAmED,eAAO,MAAM,aAAa,SAClB,CAAC,IAAI,EAAE,MAAM,KAAK,kBAAkB,YACjC,oBAAoB,KAC5B,cAAc,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAA;CA+BrD,CAAA"}
|
package/dist/Storage.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { dropStore, SQLiteStore, } from "@rocicorp/zero/sqlite";
|
|
2
|
+
export const memoryStorage = () => ({
|
|
3
|
+
info: { kind: "memory", durable: false, platforms: ["web", "desktop", "mobile", "server"] },
|
|
4
|
+
storage: "mem",
|
|
5
|
+
});
|
|
6
|
+
export const indexedDbStorage = () => ({
|
|
7
|
+
info: { kind: "indexeddb", durable: true, platforms: ["web", "desktop"] },
|
|
8
|
+
storage: "idb",
|
|
9
|
+
});
|
|
10
|
+
/** A row as an array in column order (the store reads positions; bindings return objects or arrays). */
|
|
11
|
+
const asArray = (row) => Array.isArray(row) ? row : row !== null && typeof row === "object" ? Object.values(row) : [row];
|
|
12
|
+
class SyncStatement {
|
|
13
|
+
#statement;
|
|
14
|
+
constructor(statement) {
|
|
15
|
+
this.#statement = statement;
|
|
16
|
+
}
|
|
17
|
+
// A synchronous binding runs each call to completion, so no other caller can rebind the statement between
|
|
18
|
+
// executing it and reading its rows (the atomicity SQLiteStore requires of a shared statement).
|
|
19
|
+
exec(params) {
|
|
20
|
+
this.#statement.run(...params);
|
|
21
|
+
return Promise.resolve();
|
|
22
|
+
}
|
|
23
|
+
all(params) {
|
|
24
|
+
return Promise.resolve(this.#statement.all(...params).map(asArray));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The replica's table (Zero's SQLite store keeps every key in it). */
|
|
28
|
+
const ENTRY_TABLE = "entry";
|
|
29
|
+
/** Wipe a replica's file in place: its table dropped, the file vacuumed (freed pages gone), the WAL truncated. */
|
|
30
|
+
const wipe = (open, path) => {
|
|
31
|
+
const db = open(path);
|
|
32
|
+
try {
|
|
33
|
+
db.exec(`DROP TABLE IF EXISTS ${ENTRY_TABLE}`);
|
|
34
|
+
db.exec("VACUUM");
|
|
35
|
+
db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
db.close();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
class SyncDatabase {
|
|
42
|
+
#db;
|
|
43
|
+
#open;
|
|
44
|
+
#path;
|
|
45
|
+
#remove;
|
|
46
|
+
constructor(open, path, remove) {
|
|
47
|
+
this.#db = open(path);
|
|
48
|
+
this.#open = open;
|
|
49
|
+
this.#path = path;
|
|
50
|
+
this.#remove = remove;
|
|
51
|
+
}
|
|
52
|
+
#closed = false;
|
|
53
|
+
close() {
|
|
54
|
+
if (this.#closed)
|
|
55
|
+
return;
|
|
56
|
+
this.#closed = true;
|
|
57
|
+
this.#db.close();
|
|
58
|
+
}
|
|
59
|
+
destroy() {
|
|
60
|
+
this.close();
|
|
61
|
+
wipe(this.#open, this.#path);
|
|
62
|
+
for (const suffix of ["", "-wal", "-shm"])
|
|
63
|
+
this.#remove?.(`${this.#path}${suffix}`);
|
|
64
|
+
}
|
|
65
|
+
prepare(sql) {
|
|
66
|
+
return new SyncStatement(this.#db.prepare(sql));
|
|
67
|
+
}
|
|
68
|
+
execSync(sql) {
|
|
69
|
+
this.#db.exec(sql);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export const sqliteStorage = (open, options = {}) => {
|
|
73
|
+
const storeOptions = {
|
|
74
|
+
...(options.directory === undefined ? {} : { directory: options.directory }),
|
|
75
|
+
...(options.busyTimeout === undefined ? {} : { busyTimeout: options.busyTimeout }),
|
|
76
|
+
};
|
|
77
|
+
const create = (path) => new SyncDatabase(open, path, options.remove);
|
|
78
|
+
const pathOf = (name) => {
|
|
79
|
+
const file = name.replace(/[^a-zA-Z0-9]/g, "_");
|
|
80
|
+
return options.directory === undefined ? file : `${options.directory}/${file}`;
|
|
81
|
+
};
|
|
82
|
+
const provider = {
|
|
83
|
+
create: (name) => new SQLiteStore(name, create, storeOptions, "sqlite"),
|
|
84
|
+
drop: async (name) => {
|
|
85
|
+
// Zero's dropStore closes the shared connection, then destroys the file, but ignores a failure to: check.
|
|
86
|
+
await dropStore(name, create, storeOptions);
|
|
87
|
+
const db = open(pathOf(name));
|
|
88
|
+
try {
|
|
89
|
+
const left = db.prepare(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`).all(ENTRY_TABLE);
|
|
90
|
+
if (left.length > 0)
|
|
91
|
+
throw new Error(`The replica ${name} could not be dropped`);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
db.close();
|
|
95
|
+
if (options.remove !== undefined)
|
|
96
|
+
for (const suffix of ["", "-wal", "-shm"])
|
|
97
|
+
options.remove(`${pathOf(name)}${suffix}`);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
info: { kind: "sqlite", durable: true, platforms: ["desktop", "mobile", "server"] },
|
|
103
|
+
storage: provider,
|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type AnyMutatorRegistry, type Schema } from "@rocicorp/zero";
|
|
2
|
+
export { boolean, createBuilder, createSchema, defineQueries, defineQueriesWithType, defineQuery, defineQueryWithType, enumeration, escapeLike, json, number, relationships, string, table, } from "@rocicorp/zero";
|
|
3
|
+
export type { AnyQueryRegistry, HumanReadable, PullRow, Query, QueryRequest, QueryResultType, QueryRowType, ReadonlyJSONObject, ReadonlyJSONValue, Row, RunOptions, TTL, TableSchema, } from "@rocicorp/zero";
|
|
4
|
+
/** An app's sync schema: what `eloxiv.sync.ts` generates (`typeof schema`). */
|
|
5
|
+
export type SyncSchema = Schema;
|
|
6
|
+
/** A replica over the app's sync schema `S`: queries, results and rows are typed by it. */
|
|
7
|
+
export type SyncClient<S extends SyncSchema = SyncSchema> = Zero<S>;
|
|
8
|
+
/**
|
|
9
|
+
* Where the replica lives: `"idb"` (IndexedDB, browsers and webviews), `"mem"` (memory only), or a Zero store
|
|
10
|
+
* provider, such as SQLite on React Native (`expoSQLiteStoreProvider` from `@eloxiv/client/expo-sqlite`).
|
|
11
|
+
*/
|
|
12
|
+
export type SyncStorage = NonNullable<ConstructorParameters<typeof Zero>[0]["kvStore"]>;
|
|
13
|
+
export interface SyncOptions<S extends SyncSchema = SyncSchema> {
|
|
14
|
+
/** zero-cache URL, e.g. `http://localhost:4848`. */
|
|
15
|
+
readonly server: string;
|
|
16
|
+
/** The app's generated sync schema (`schema` from `eloxiv.sync.ts`). */
|
|
17
|
+
readonly schema: S;
|
|
18
|
+
readonly userId: string;
|
|
19
|
+
/** Bearer token forwarded by zero-cache to the kernel's query endpoint. */
|
|
20
|
+
readonly token: string;
|
|
21
|
+
/**
|
|
22
|
+
* Organisation to sync, as for action calls (`x-eloxiv-org`). The kernel checks
|
|
23
|
+
* membership; each (user, organisation) pair gets its own replica storage.
|
|
24
|
+
*/
|
|
25
|
+
readonly orgId?: string | undefined;
|
|
26
|
+
/** Replica storage (default memory). Browsers use IndexedDB; React Native uses SQLite (decision 7). */
|
|
27
|
+
readonly storage?: SyncStorage | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* The app's mutators (`mutators` from `eloxiv.sync.ts`), for optimistic writes (`write`). A replica that writes
|
|
30
|
+
* names its organisation (`orgId`): its predictions are made for it.
|
|
31
|
+
*/
|
|
32
|
+
readonly mutators?: AnyMutatorRegistry | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* This client's version (the app build), sent with each pushed write as `x-eloxiv-client-version`, as the typed
|
|
35
|
+
* client sends it: the kernel refuses writes from versions older than its minimum (`ClientOutdated`).
|
|
36
|
+
*/
|
|
37
|
+
readonly clientVersion?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Diagnostics: every line the sync engine logs, debug level included, instead of the console's warnings (a test
|
|
40
|
+
* keeps them for its failure report). Off by default.
|
|
41
|
+
*/
|
|
42
|
+
readonly log?: ((level: string, ...args: ReadonlyArray<unknown>) => void) | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** Header naming the organisation, forwarded by zero-cache to the kernel's query endpoint. */
|
|
45
|
+
export declare const ORG_HEADER = "x-eloxiv-org";
|
|
46
|
+
/** Open the replica of one user in one organisation, typed by the app's schema. */
|
|
47
|
+
export declare const connectSync: <const S extends SyncSchema>(options: SyncOptions<S>) => SyncClient<S>;
|
|
48
|
+
//# sourceMappingURL=Sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sync.d.ts","sourceRoot":"","sources":["../src/Sync.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAE,KAAK,kBAAkB,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE3E,OAAO,EACL,OAAO,EACP,aAAa,EACb,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,IAAI,EACJ,MAAM,EACN,aAAa,EACb,MAAM,EACN,KAAK,GACN,MAAM,gBAAgB,CAAA;AACvB,YAAY,EACV,gBAAg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tF;AAED,8FAA8F;AAC9F,eAAO,MAAM,UAAU,iBAAiB,CAAA;AAExC,mFAAmF;AACnF,eAAO,MAAM,WAAW,GAAI,KAAK,CAAC,CAAC,SAAS,UAAU,WAAW,WAAW,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAmC7F,CAAA"}
|
package/dist/Sync.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client's local replica and the sync API modules and UI use (decision 9: sync only through
|
|
3
|
+
* `@eloxiv/client`). Queries keep ZQL's shape: this re-exports Zero's query builder, named-query definitions,
|
|
4
|
+
* schema builders (for the generated sync tables) and row types, and `connectSync` opens a replica typed by the
|
|
5
|
+
* app's generated schema (`eloxiv.sync.ts`). React bindings are in `@eloxiv/client/react`.
|
|
6
|
+
*/
|
|
7
|
+
import { CLIENT_VERSION_HEADER } from "@eloxiv/contracts";
|
|
8
|
+
import { Zero } from "@rocicorp/zero";
|
|
9
|
+
export { boolean, createBuilder, createSchema, defineQueries, defineQueriesWithType, defineQuery, defineQueryWithType, enumeration, escapeLike, json, number, relationships, string, table, } from "@rocicorp/zero";
|
|
10
|
+
/** Header naming the organisation, forwarded by zero-cache to the kernel's query endpoint. */
|
|
11
|
+
export const ORG_HEADER = "x-eloxiv-org";
|
|
12
|
+
/** Open the replica of one user in one organisation, typed by the app's schema. */
|
|
13
|
+
export const connectSync = (options) => {
|
|
14
|
+
const orgId = options.orgId;
|
|
15
|
+
if (options.mutators !== undefined && orgId === undefined) {
|
|
16
|
+
throw new Error("A replica that writes optimistically names its organisation (connectSync({ orgId }))");
|
|
17
|
+
}
|
|
18
|
+
const headers = orgId === undefined ? {} : { [ORG_HEADER]: orgId };
|
|
19
|
+
const mutateHeaders = options.clientVersion === undefined ? headers : { ...headers, [CLIENT_VERSION_HEADER]: options.clientVersion };
|
|
20
|
+
const zero = new Zero({
|
|
21
|
+
server: options.server,
|
|
22
|
+
schema: options.schema,
|
|
23
|
+
userID: options.userId,
|
|
24
|
+
auth: options.token,
|
|
25
|
+
kvStore: options.storage ?? "mem",
|
|
26
|
+
...(options.log === undefined
|
|
27
|
+
? {}
|
|
28
|
+
: {
|
|
29
|
+
logLevel: "debug",
|
|
30
|
+
logSink: { log: (level, _context, ...args) => options.log(level, ...args) },
|
|
31
|
+
}),
|
|
32
|
+
...(orgId === undefined ? {} : { queryHeaders: headers, storageKey: `org:${orgId}` }),
|
|
33
|
+
// The replica pushes only the person's writes, never anything of its own: a push zero-cache forwards after the
|
|
34
|
+
// session ended is refused for its credential, and zero-cache then drops the connection, before the sign-out's
|
|
35
|
+
// withdrawal of the rows the replica holds could reach it (docs/contracts/sync.md, guarantee 8). Its client group
|
|
36
|
+
// is recorded from its queries' transforms instead (docs/contracts/privacy.md).
|
|
37
|
+
...(options.mutators === undefined || orgId === undefined
|
|
38
|
+
? {}
|
|
39
|
+
: {
|
|
40
|
+
mutators: options.mutators,
|
|
41
|
+
mutateHeaders,
|
|
42
|
+
// What each prediction is made for (OptimisticContext): the kernel acts as this user, in this organisation.
|
|
43
|
+
context: { userId: options.userId, orgId },
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
return zero;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=Sync.js.map
|
package/dist/Sync.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sync.js","sourceRoot":"","sources":["../src/Sync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,IAAI,EAAwC,MAAM,gBAAgB,CAAA;AAE3E,OAAO,EACL,OAAO,EACP,aAAa,EACb,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,IAAI,EACJ,MAAM,EACN,aAAa,EACb,MAAM,EACN,KAAK,GACN,MAAM,gBAAgB,CAAA;AA6DvB,8F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