nolo-cli 0.103.0-alpha.1 → 0.103.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/README.md +1 -1
- package/{_executeModel-3UCNJCQA.js → _executeModel-7J7Q3WXY.js} +75 -68
- package/action-C4KMTCJF.js +20 -0
- package/{addContentAction-O7R66HEX.js → addContentAction-7TNIOVZI.js} +12 -11
- package/{addDialogAgentAction-74OA7KYP.js → addDialogAgentAction-O47J3MVW.js} +18 -19
- package/{agentDeleteCommand-2YAHAZFJ.js → agentDeleteCommand-YPJHK7JA.js} +117 -42
- package/{agentEmailCommands-WLYF3JRS.js → agentEmailCommands-AWEXOHWM.js} +98 -88
- package/agentListCommands-2DTLLJZD.js +742 -0
- package/{agentMachineCommands-HNGAR5GI.js → agentMachineCommands-PGEEQ4JJ.js} +48 -43
- package/{agentProviderCommands-GNPTL5XR.js → agentProviderCommands-XPJYZSCE.js} +97 -2
- package/{agentPullCommand-O5MPVJ5E.js → agentPullCommand-B4T2DJ5H.js} +1 -1
- package/agentRecordCommands-DZVLCPLJ.js +138 -0
- package/agentRunCommand-AX5CYQ46.js +167 -0
- package/{agentRunControl-AVJR4JW4.js → agentRunControl-3HWA2LLQ.js} +2 -2
- package/{agentRuntimeLocal-VXZSDIGT.js → agentRuntimeLocal-PITRQ2EU.js} +48 -39
- package/{agentSlice-SICQBMCM.js → agentSlice-4TLSG6FB.js} +14 -13
- package/{appDeleteCommands-32MHLR4L.js → appDeleteCommands-UC2JW5FJ.js} +46 -41
- package/{appDeployCommands-WCQOUSOB.js → appDeployCommands-OL2RKVJ3.js} +46 -41
- package/{appDeployStatusCommands-6QKB7DYN.js → appDeployStatusCommands-B3PLC62M.js} +46 -41
- package/{appGetCommands-SFAPP5PB.js → appGetCommands-REESA2XQ.js} +46 -41
- package/{appListCommands-EKUBDRUO.js → appListCommands-UF6XX7HR.js} +46 -41
- package/{authCommand-F4EFRRX6.js → authCommand-NQPMGYHP.js} +118 -24
- package/{authCommands-RGOGCPP6.js → authCommands-LWLOZETU.js} +7 -5
- package/{builtinSkillRegistry-FUAVTRVZ.js → builtinSkillRegistry-GFY77VRN.js} +10 -8
- package/{chromeCommands-FZYAU75D.js → chromeCommands-K27J4OVZ.js} +124 -28
- package/{chromeOpsCommands-62P2Q2YB.js → chromeOpsCommands-IXRLN57H.js} +4 -3
- package/{chunk-UKZDAFYT.js → chunk-22RVE2PC.js} +6 -10
- package/{chunk-6OZ36FXI.js → chunk-27ONFIEY.js} +22 -4
- package/{chunk-HVURBGF3.js → chunk-2H6SEVDS.js} +6 -6
- package/{chunk-TOP2VXOR.js → chunk-2K4TM6AW.js} +5 -5
- package/{chunk-JEDZAO7L.js → chunk-2SYTUTLI.js} +257 -37
- package/{chunk-53HEEOTT.js → chunk-2WJ57RJA.js} +83 -16
- package/{chunk-OIVSQH2O.js → chunk-3BXNTXYI.js} +299 -5
- package/chunk-4A2R7KHG.js +13545 -0
- package/{chunk-EYAQT56M.js → chunk-4DPP773Q.js} +2 -2
- package/{chunk-JRQFUXY7.js → chunk-4G4C5SXT.js} +99 -22
- package/{chunk-DHDMC6FO.js → chunk-4HTMUQIZ.js} +14 -9
- package/{chunk-B3TVQ6PI.js → chunk-4IVA6UUE.js} +20 -11
- package/chunk-4LCOCOR5.js +50 -0
- package/{chunk-2GRGFCF6.js → chunk-4VJAC32I.js} +2 -1
- package/{chunk-MC4XLIJ7.js → chunk-523DITKR.js} +1 -1
- package/{chunk-H62HCIUP.js → chunk-56HJ2LAA.js} +35 -22
- package/{chunk-V4MJDUSR.js → chunk-5EPHWMP5.js} +2 -2
- package/{chunk-E4MARS3Q.js → chunk-5GVBDNTO.js} +1 -1
- package/{chunk-3WLK2JQ5.js → chunk-5IWONK6X.js} +68 -46
- package/chunk-5J3PYNUP.js +255 -0
- package/chunk-5MMAK75Q.js +15 -0
- package/{chunk-LW4VFPAY.js → chunk-5ZDLVKNG.js} +873 -228
- package/{chunk-42V6BK2E.js → chunk-62IL3KQV.js} +4 -34
- package/{chunk-AEOE4Z6Q.js → chunk-6UEJDFF7.js} +39 -15
- package/{chunk-JPGCXHNM.js → chunk-7JWCVINR.js} +1 -1
- package/{chunk-GQBOR3G6.js → chunk-7KVZ5LDQ.js} +2 -2
- package/{chunk-IIVGDG4I.js → chunk-7KWFIKKK.js} +13 -7
- package/chunk-A4SQRTZ6.js +15 -0
- package/chunk-AGIM7IMJ.js +147 -0
- package/{chunk-5UTFL4QJ.js → chunk-AOTBKDRK.js} +7 -0
- package/{chunk-L5UXH3B2.js → chunk-B455PEFD.js} +27 -8
- package/{chunk-XS5SWEDQ.js → chunk-BELZY72F.js} +1 -1
- package/chunk-BMQ2MJUK.js +153 -0
- package/{chunk-6YTOJY35.js → chunk-BZ7NPA6G.js} +35 -2
- package/chunk-CHOZJMJS.js +78 -0
- package/{chunk-3BMYXEUW.js → chunk-CUF4MYKI.js} +1 -1
- package/{chunk-ACTMNVHM.js → chunk-CYSYR67N.js} +1 -1
- package/{chunk-WV42OMV7.js → chunk-D2GQE6AF.js} +8 -8
- package/{chunk-GBRG75BQ.js → chunk-D2MDMY2M.js} +1 -0
- package/chunk-DZ7R5V3Y.js +164 -0
- package/{chunk-3VNWWVKB.js → chunk-E3YWHWCR.js} +50 -18
- package/{chunk-KQ4ONNQD.js → chunk-EKPKW6RM.js} +155 -8
- package/{chunk-ABQYVJBJ.js → chunk-EV235ILT.js} +5 -5
- package/{chunk-TRV2MIDW.js → chunk-EXAJ6DCR.js} +1 -0
- package/{chunk-AGVEIAQA.js → chunk-F442UK5V.js} +29 -78
- package/{chunk-HJUYAD4A.js → chunk-FBTNYNAL.js} +5 -5
- package/{chunk-2F7RJC6L.js → chunk-FOXQ7BAB.js} +1 -1
- package/{chunk-ETI2NYVF.js → chunk-GCTKWVLU.js} +4 -4
- package/chunk-GMZLP5DV.js +82 -0
- package/{chunk-FDTR4QJ6.js → chunk-H6A6X4EK.js} +32 -1
- package/{chunk-6VFARHZW.js → chunk-H7TQORR4.js} +994 -1079
- package/{chunk-5H7KJX7J.js → chunk-HD3S2F7U.js} +5 -5
- package/chunk-HDJRLWTG.js +8002 -0
- package/{chunk-DVINR3PL.js → chunk-HDLLCBRF.js} +1 -1
- package/{chunk-QOKAKDPE.js → chunk-HIM3FCLF.js} +0 -1
- package/{chunk-ONXOABJR.js → chunk-HNGRBWYF.js} +3 -0
- package/{chunk-VLTIYV3X.js → chunk-HP57OUJO.js} +4 -4
- package/{chunk-4OEFYTWL.js → chunk-IRZTHHNM.js} +67 -48
- package/{chunk-GPCZ7UXG.js → chunk-K6U4NKFJ.js} +1 -1
- package/{chunk-OZGZPSEG.js → chunk-KGRP4VOK.js} +47 -67
- package/{chunk-DNCEALKX.js → chunk-LB5A6JTU.js} +22 -29
- package/{chunk-LS2ZANRJ.js → chunk-LOCNXNOU.js} +1 -1
- package/{chunk-PUOC4YRO.js → chunk-M7VLQGQP.js} +11 -0
- package/{chunk-Z77CRGTW.js → chunk-MSFZ7FMO.js} +1 -1
- package/chunk-NKWIS6G2.js +442 -0
- package/{chunk-BFU6C242.js → chunk-NMFV26UG.js} +1 -1
- package/{chunk-FZGV4FGK.js → chunk-NUHHBEJC.js} +378 -187
- package/chunk-NWENLDMM.js +42 -0
- package/chunk-O7SVKKLY.js +875 -0
- package/chunk-OCZKATRC.js +129 -0
- package/{chunk-PQFHGD77.js → chunk-OM2RUOEU.js} +161 -14
- package/{chunk-KQHGZWSV.js → chunk-OXME3PEE.js} +1 -1
- package/{chunk-TQBHNYVR.js → chunk-PLRFCQ7C.js} +567 -519
- package/{chunk-6D6VBVEW.js → chunk-Q7O72MF5.js} +80 -14
- package/{chunk-J4MOO56S.js → chunk-RILRSUGC.js} +10 -2
- package/{chunk-RSONHHPE.js → chunk-RNUDNZJW.js} +10 -10
- package/{chunk-3N3W7KBB.js → chunk-RZJAZVCF.js} +11 -9
- package/{chunk-BYMV6QZG.js → chunk-TNIX77YM.js} +4 -0
- package/{chunk-GEPUP7OO.js → chunk-TSXNDTXL.js} +3 -3
- package/chunk-TY3TIUJK.js +89 -0
- package/{chunk-I3TQJXQ7.js → chunk-U3C3IA32.js} +9 -2
- package/{chunk-UZGQNTVW.js → chunk-UA324D4O.js} +8 -6
- package/{chunk-YYLHWIW6.js → chunk-UKZX3NHN.js} +1 -1
- package/{chunk-BP4XNZRM.js → chunk-UNAOTLKO.js} +4 -4
- package/{chunk-CUQEXCAU.js → chunk-UQ5P2WHS.js} +29 -9
- package/{chunk-NA35QHCF.js → chunk-V6YASAZR.js} +1 -1
- package/{chunk-3DII57IT.js → chunk-VCAQFMVN.js} +1 -1
- package/chunk-VIWDGTDA.js +8 -0
- package/chunk-VJVNU77E.js +83 -0
- package/{chunk-ZCYXJSTU.js → chunk-VL3H5ZU3.js} +66 -94
- package/{chunk-Q554LLSI.js → chunk-VLGL7FOL.js} +1 -1
- package/{chunk-UKWGR5SS.js → chunk-VY6VFGKR.js} +194 -1144
- package/{chunk-4EG4QFTK.js → chunk-WI6TUGLJ.js} +19 -17
- package/{chunk-QDSINZM3.js → chunk-WJ3B6FX6.js} +1 -14
- package/{chunk-OEVAY4J6.js → chunk-XMUZHRSB.js} +18 -20
- package/{chunk-O6OSWFZQ.js → chunk-XUWRURDF.js} +6 -0
- package/{chunk-Q67DOFOO.js → chunk-Y3PMXGLH.js} +2 -0
- package/{chunk-7S4YWN7P.js → chunk-YDO5ERB4.js} +4 -4
- package/chunk-YK5MHOWM.js +915 -0
- package/{chunk-SH43IESU.js → chunk-YUNJN43V.js} +44 -9
- package/chunk-YV25TM3R.js +780 -0
- package/{chunk-IONPPCL5.js → chunk-YZZREBID.js} +86 -16
- package/{chunk-DNUUJ45N.js → chunk-Z3WSAK6A.js} +23 -28
- package/chunk-ZRAU6T47.js +56 -0
- package/commandRegistry-VQPFWVDH.js +833 -0
- package/{contentThunks-S4S7QPSO.js → contentThunks-A26ME6OJ.js} +37 -35
- package/{cooldownCommands-REAWYVTY.js → cooldownCommands-ZLEPIB4A.js} +2 -2
- package/{createAgentAutomationAction-ODGL2YGP.js → createAgentAutomationAction-BSAMZJ5W.js} +39 -37
- package/createDialogAction-CMCQXYHD.js +69 -0
- package/{createPageAction-FBV3OWX7.js → createPageAction-ANGKJTK2.js} +46 -43
- package/{chunk-F2RNI7ZR.js → cursorProvider-YGGNMVWX.js} +2496 -9897
- package/{dbSlice-XVWBAGYN.js → dbSlice-QOLNF5GN.js} +11 -10
- package/{deleteFile-YG6QMJLU.js → deleteFile-KESP65GC.js} +7 -6
- package/{dialogCommands-5J56DFWN.js → dialogCommands-AMPAWLX4.js} +49 -45
- package/{dialogSlice-LEO27SQG.js → dialogSlice-DGWDEBYC.js} +41 -34
- package/{dist-VODFSGNG.js → dist-NJC2W7I4.js} +61 -54
- package/{docCreateCommands-KYI2DC2U.js → docCreateCommands-7NMIYL5D.js} +48 -43
- package/{docDeleteCommands-67REUSRY.js → docDeleteCommands-BD4OM5PV.js} +49 -44
- package/{docReadCommands-HOSVSBDJ.js → docReadCommands-5IOVAKU2.js} +47 -42
- package/{docStore-MNX5MHA5.js → docStore-TP4QDER4.js} +16 -12
- package/{docUpdateCommands-EMGCSMXY.js → docUpdateCommands-ZTKJ6UPC.js} +48 -43
- package/{fetchMessages-EIU7UFFK.js → fetchMessages-5L7OVM5Y.js} +5 -5
- package/{getPricing-LUSEABA6.js → getPricing-NMMFT3YI.js} +4 -4
- package/{handleSendMessageAction-YB6KQFJS.js → handleSendMessageAction-N4WKFRSQ.js} +111 -87
- package/index.js +87 -884
- package/{lib-FRRS27KN.js → lib-PU2G2MSO.js} +523 -191
- package/{localDialogRead-BTFJ4V2I.js → localDialogRead-O5A26FDK.js} +2 -2
- package/{localRuntimeAuthority-6IR6BBXE.js → localRuntimeAuthority-TU6OBC76.js} +9 -6
- package/{localRuntimeDb-SYQGUF4U.js → localRuntimeDb-VKWVOPPI.js} +1 -1
- package/{machineCommands-7GVQCUAK.js → machineCommands-47WKGY5Z.js} +92 -82
- package/machineWsRunDispatch-CYW5FJ52.js +154 -0
- package/{memberThunks-QGFLFVCI.js → memberThunks-25K6DDRA.js} +20 -18
- package/{models-T3SG6MJ5.js → models-ZPU5EDF4.js} +2 -2
- package/oauthTokenStore-ITEB663N.js +23 -0
- package/package.json +1 -1
- package/pdf-U6KSUEZZ.js +26435 -0
- package/processSpawn-SOAV3FEV.js +11 -0
- package/profileConfig-ZGOFORWV.js +43 -0
- package/{providerPresetApply-FG6NZ57W.js → providerPresetApply-TEBH7FDX.js} +7 -7
- package/{providerRegistry-757OWH3O.js → providerRegistry-CBJLNCET.js} +11 -7
- package/{read-COE3ZYR6.js → read-PJIT2YEJ.js} +7 -6
- package/{readDocTool-5USN4A6V.js → readDocTool-DRSXHGNL.js} +5 -3
- package/{readlineWorkspace-WA7JNI6J.js → readlineWorkspace-CK7GOVOC.js} +2698 -2055
- package/{removeDialogAgentAction-IX3MN2ZO.js → removeDialogAgentAction-VIWJL6MX.js} +21 -25
- package/{runAgentClientLoop-JGFQ6KIR.js → runAgentClientLoop-BGHGP5AR.js} +76 -70
- package/{runtimeDoctorCommands-X6WDBEQX.js → runtimeDoctorCommands-PIVSBZRZ.js} +4 -4
- package/runtimeModeArgs-2Y7BALTO.js +31 -0
- package/{setDialogExtraReferencesAction-X4HCPNZL.js → setDialogExtraReferencesAction-A7VA3NFM.js} +15 -13
- package/{setPrimaryDialogAgentAction-4GMIQLOD.js → setPrimaryDialogAgentAction-B4P7YQX2.js} +22 -26
- package/{chunk-AFUORTY4.js → settingThunks-KOYSAT65.js} +226 -940
- package/{skillDiscovery-CYUCJMAG.js → skillDiscovery-ZBU76COE.js} +3 -3
- package/{slateUtils-RIZES3PV.js → slateUtils-NGV2NMKM.js} +1 -1
- package/{spaceCommands-NKJVJCQQ.js → spaceCommands-QJCYG27F.js} +51 -46
- package/{streamAgentChatTurn-XLFZ66UC.js → streamAgentChatTurn-ANE7OTCZ.js} +214 -108
- package/{switchDialogAgentAction-N52LRPA3.js → switchDialogAgentAction-3VYWHZKH.js} +18 -19
- package/{tableCommands-O6NWHFKV.js → tableCommands-6U4BMLRR.js} +10 -10
- package/{toolApiClient-QVJ6HDNN.js → toolApiClient-EJT6TMFG.js} +3 -3
- package/tools-WPOVVP7M.js +116 -0
- package/{tuiSummaryLlmCaller-WFRWERGK.js → tuiSummaryLlmCaller-QCHCULPM.js} +25 -22
- package/{updateCommands-2M74UL7P.js → updateCommands-4EHDLF5J.js} +3 -3
- package/{updateDialogTitleAction-6MBTD4UE.js → updateDialogTitleAction-C4GRCXL4.js} +82 -44
- package/action-YVYQEAAV.js +0 -31
- package/agentListCommands-JP7S7PT2.js +0 -469
- package/agentRecordCommands-SXFPW3DL.js +0 -128
- package/agentRunCommand-JIQ4HY4D.js +0 -155
- package/browser-image-compression-MFDTD7K6.js +0 -1763
- package/chatQueueReduxAdapter-HHMUDNXL.js +0 -186
- package/chunk-CQ3WA2NE.js +0 -299
- package/chunk-M76ECQRD.js +0 -13658
- package/chunk-MEYIRKDN.js +0 -8967
- package/chunk-Q5FJJ6XI.js +0 -103
- package/chunk-S7Z2HMCN.js +0 -25
- package/chunk-XVZ22N6C.js +0 -20782
- package/chunk-Y5GCAMGP.js +0 -9
- package/chunk-YPREESF4.js +0 -225
- package/createDialogAction-GFKRXTK4.js +0 -65
- package/machineWsRunDispatch-XA7TD7Z7.js +0 -144
- package/settingSlice-ZQZVUPKK.js +0 -204
- package/syncMapping-N6RGXGBW.js +0 -437
- package/tools-NF5AB34X.js +0 -110
- package/{chunk-VMFTFOWF.js → chunk-ODAPITXL.js} +7 -7
- package/{chunk-X7HHHIOZ.js → chunk-Y6ROFCZO.js} +0 -0
- package/{db-WK5MDZVN.js → db-VQSAOWAO.js} +1 -1
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRecord
|
|
3
|
+
} from "./chunk-KUG52IAP.js";
|
|
4
|
+
import {
|
|
5
|
+
createSelector,
|
|
6
|
+
noloDeleteRequest,
|
|
7
|
+
noloPatchRequest,
|
|
8
|
+
noloUploadRequest,
|
|
9
|
+
noloWriteRequest,
|
|
10
|
+
syncWithServers
|
|
11
|
+
} from "./chunk-VY6VFGKR.js";
|
|
12
|
+
import {
|
|
13
|
+
getAllServers,
|
|
14
|
+
getIsDesktopApp
|
|
15
|
+
} from "./chunk-HIM3FCLF.js";
|
|
16
|
+
import {
|
|
17
|
+
selectIdentityToken,
|
|
18
|
+
selectIdentityUser,
|
|
19
|
+
selectIdentityUserId
|
|
20
|
+
} from "./chunk-SEJ5OS6F.js";
|
|
21
|
+
import {
|
|
22
|
+
asOptionalPositiveFiniteNumber
|
|
23
|
+
} from "./chunk-U6VC4MU4.js";
|
|
24
|
+
import {
|
|
25
|
+
asTrimmedString
|
|
26
|
+
} from "./chunk-3EUW3WEO.js";
|
|
27
|
+
import {
|
|
28
|
+
SERVERS,
|
|
29
|
+
normalizeKnownServerOrigin
|
|
30
|
+
} from "./chunk-LCBAMY2M.js";
|
|
31
|
+
import {
|
|
32
|
+
isLocalServerUrl
|
|
33
|
+
} from "./chunk-4SN6J65J.js";
|
|
34
|
+
import {
|
|
35
|
+
normalizeServerOrigin
|
|
36
|
+
} from "./chunk-CF7PE763.js";
|
|
37
|
+
import {
|
|
38
|
+
asOptionalTrimmedString
|
|
39
|
+
} from "./chunk-G3SUCT4W.js";
|
|
40
|
+
|
|
41
|
+
// packages/app/stateViews/runtime.ts
|
|
42
|
+
var selectCurrentToken = (state) => {
|
|
43
|
+
const token = selectIdentityToken(state);
|
|
44
|
+
return typeof token === "string" ? token : void 0;
|
|
45
|
+
};
|
|
46
|
+
var selectCurrentUserId = (state) => {
|
|
47
|
+
const userId = selectIdentityUserId(state);
|
|
48
|
+
return typeof userId === "string" ? userId : void 0;
|
|
49
|
+
};
|
|
50
|
+
var EMPTY_SYNC_SERVERS = [];
|
|
51
|
+
var selectRuntimeRemoteServer = (state) => {
|
|
52
|
+
const configuredServer = normalizeKnownServerOrigin(state.settings?.currentServer) ?? void 0;
|
|
53
|
+
if (!getIsDesktopApp()) return configuredServer || SERVERS.MAIN;
|
|
54
|
+
return isLocalServerUrl(configuredServer) ? SERVERS.MAIN : configuredServer || SERVERS.MAIN;
|
|
55
|
+
};
|
|
56
|
+
var selectConfiguredSyncServers = (state) => state.settings?.syncServers;
|
|
57
|
+
var selectRuntimeRemoteSyncServers = createSelector(
|
|
58
|
+
[selectConfiguredSyncServers],
|
|
59
|
+
(syncServers) => {
|
|
60
|
+
if (!Array.isArray(syncServers) || syncServers.length === 0) {
|
|
61
|
+
return EMPTY_SYNC_SERVERS;
|
|
62
|
+
}
|
|
63
|
+
const normalized = syncServers.map(normalizeKnownServerOrigin).filter((server) => !!server);
|
|
64
|
+
if (!getIsDesktopApp()) return normalized;
|
|
65
|
+
return normalized.filter((server) => !isLocalServerUrl(server));
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
var selectLocalRuntimeOrigin = () => {
|
|
69
|
+
if (typeof window !== "undefined" && typeof window.location?.origin === "string" && /^https?:\/\//.test(window.location.origin)) {
|
|
70
|
+
return window.location.origin.replace(/\/+$/, "");
|
|
71
|
+
}
|
|
72
|
+
return void 0;
|
|
73
|
+
};
|
|
74
|
+
var selectRuntimeSnapshot = createSelector(
|
|
75
|
+
[
|
|
76
|
+
selectCurrentToken,
|
|
77
|
+
selectCurrentUserId,
|
|
78
|
+
selectRuntimeRemoteServer,
|
|
79
|
+
selectRuntimeRemoteSyncServers,
|
|
80
|
+
selectLocalRuntimeOrigin
|
|
81
|
+
],
|
|
82
|
+
(currentToken, currentUserId, currentServer, syncServers, localRuntimeOrigin) => ({
|
|
83
|
+
currentToken,
|
|
84
|
+
currentUserId,
|
|
85
|
+
currentServer,
|
|
86
|
+
syncServers,
|
|
87
|
+
localRuntimeOrigin
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
var selectRuntimeCurrentServer = createSelector(
|
|
91
|
+
[selectRuntimeSnapshot],
|
|
92
|
+
(runtime) => runtime.currentServer
|
|
93
|
+
);
|
|
94
|
+
var selectRuntimeRemoteServers = createSelector(
|
|
95
|
+
[selectRuntimeSnapshot],
|
|
96
|
+
(runtime) => getAllServers(runtime.currentServer, runtime.syncServers)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// packages/database/runtimeServerContext.ts
|
|
100
|
+
var getRuntimeServerContext = (state, preferredServerOrigin) => {
|
|
101
|
+
const {
|
|
102
|
+
currentToken,
|
|
103
|
+
currentUserId,
|
|
104
|
+
currentServer,
|
|
105
|
+
syncServers = []
|
|
106
|
+
} = selectRuntimeSnapshot(state);
|
|
107
|
+
return {
|
|
108
|
+
currentToken,
|
|
109
|
+
currentUserId,
|
|
110
|
+
currentServer,
|
|
111
|
+
syncServers,
|
|
112
|
+
userAuthorityRegistry: resolveRuntimeUserAuthorityRegistry(state),
|
|
113
|
+
remoteServers: getAllServers(
|
|
114
|
+
currentServer,
|
|
115
|
+
syncServers,
|
|
116
|
+
preferredServerOrigin
|
|
117
|
+
)
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
var resolveRuntimeUserAuthorityRegistry = (state) => {
|
|
121
|
+
const settingsRegistry = state.settings?.userAuthorityRegistry;
|
|
122
|
+
if (settingsRegistry && typeof settingsRegistry === "object") {
|
|
123
|
+
return settingsRegistry;
|
|
124
|
+
}
|
|
125
|
+
const userRegistry = selectIdentityUser(state)?.authorityRegistry;
|
|
126
|
+
if (userRegistry && typeof userRegistry === "object") {
|
|
127
|
+
return userRegistry;
|
|
128
|
+
}
|
|
129
|
+
return void 0;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// packages/database/authority/ownerKey.ts
|
|
133
|
+
var USER_OWNED_SECOND_SEGMENT_PREFIXES = /* @__PURE__ */ new Set([
|
|
134
|
+
"agent",
|
|
135
|
+
"dialog",
|
|
136
|
+
"page",
|
|
137
|
+
"doc",
|
|
138
|
+
"notification",
|
|
139
|
+
"email",
|
|
140
|
+
"meta",
|
|
141
|
+
"row",
|
|
142
|
+
"view",
|
|
143
|
+
"file",
|
|
144
|
+
"job"
|
|
145
|
+
]);
|
|
146
|
+
var PUBLIC_OWNER_SENTINELS = /* @__PURE__ */ new Set(["pub", "id", "stats", "index"]);
|
|
147
|
+
var cleanSegment = (value) => {
|
|
148
|
+
const trimmed = asTrimmedString(value);
|
|
149
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
150
|
+
};
|
|
151
|
+
var normalizeCandidateOwners = (candidateOwnerUserIds) => {
|
|
152
|
+
const out = [];
|
|
153
|
+
for (const candidate of candidateOwnerUserIds ?? []) {
|
|
154
|
+
const normalized = cleanSegment(candidate ?? void 0);
|
|
155
|
+
if (!normalized || PUBLIC_OWNER_SENTINELS.has(normalized)) continue;
|
|
156
|
+
if (!out.includes(normalized)) out.push(normalized);
|
|
157
|
+
}
|
|
158
|
+
return out.sort((left, right) => right.length - left.length);
|
|
159
|
+
};
|
|
160
|
+
var resolveCandidateOwnerFromKeyRemainder = (remainder, candidateOwnerUserIds) => {
|
|
161
|
+
const normalizedRemainder = cleanSegment(remainder);
|
|
162
|
+
if (!normalizedRemainder) return null;
|
|
163
|
+
for (const candidate of normalizeCandidateOwners(candidateOwnerUserIds)) {
|
|
164
|
+
if (normalizedRemainder === candidate || normalizedRemainder.startsWith(`${candidate}-`)) {
|
|
165
|
+
return candidate;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
};
|
|
170
|
+
var parseOwnerUserIdFromDbKey = (dbKey, options = {}) => {
|
|
171
|
+
const normalized = cleanSegment(dbKey);
|
|
172
|
+
if (!normalized) return null;
|
|
173
|
+
const parts = normalized.split("-");
|
|
174
|
+
const [prefix] = parts;
|
|
175
|
+
if (!prefix) return null;
|
|
176
|
+
if (!USER_OWNED_SECOND_SEGMENT_PREFIXES.has(prefix)) {
|
|
177
|
+
if (prefix === "grant" && parts[1] === "agent" && parts.length >= 5) {
|
|
178
|
+
const ownerAndRest2 = normalized.slice(prefix.length + 1 + parts[1].length + 1);
|
|
179
|
+
const [owner2] = ownerAndRest2.split("-");
|
|
180
|
+
return cleanSegment(owner2);
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
if (parts[0] === "dialog" && parts[2] === "msg") {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const ownerAndRest = normalized.slice(prefix.length + 1);
|
|
188
|
+
const candidateOwner = resolveCandidateOwnerFromKeyRemainder(
|
|
189
|
+
ownerAndRest,
|
|
190
|
+
options.candidateOwnerUserIds
|
|
191
|
+
);
|
|
192
|
+
if (candidateOwner) return candidateOwner;
|
|
193
|
+
const [owner] = ownerAndRest.split("-");
|
|
194
|
+
const ownerUserId = cleanSegment(owner);
|
|
195
|
+
if (!ownerUserId) return null;
|
|
196
|
+
if (PUBLIC_OWNER_SENTINELS.has(ownerUserId)) return null;
|
|
197
|
+
return ownerUserId;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// packages/database/authority/userAuthorityRegistry.ts
|
|
201
|
+
var normalizeAuthorityServerOrigin = (value) => {
|
|
202
|
+
const normalized = normalizeServerOrigin(value);
|
|
203
|
+
return /^https?:\/\//i.test(normalized) ? normalized : null;
|
|
204
|
+
};
|
|
205
|
+
var normalizeUserId = (value) => asOptionalTrimmedString(value) ?? null;
|
|
206
|
+
var readEntryAuthorityServer = (entry) => {
|
|
207
|
+
if (typeof entry === "string") {
|
|
208
|
+
return normalizeAuthorityServerOrigin(entry);
|
|
209
|
+
}
|
|
210
|
+
if (!isRecord(entry)) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
return normalizeAuthorityServerOrigin(entry.authorityServer) ?? normalizeAuthorityServerOrigin(entry.homeServer) ?? normalizeAuthorityServerOrigin(entry.primaryServer);
|
|
214
|
+
};
|
|
215
|
+
var resolveUserAuthorityServer = ({
|
|
216
|
+
ownerUserId,
|
|
217
|
+
registry
|
|
218
|
+
}) => {
|
|
219
|
+
const normalizedOwner = normalizeUserId(ownerUserId);
|
|
220
|
+
if (!normalizedOwner || !registry || typeof registry !== "object") {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
return readEntryAuthorityServer(registry[normalizedOwner]);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// packages/database/authority/recordAuthority.ts
|
|
227
|
+
var normalizeUserId2 = (value) => asOptionalTrimmedString(value) ?? null;
|
|
228
|
+
var getRegistryOwnerCandidates = (registry) => isRecord(registry) ? Object.keys(registry) : [];
|
|
229
|
+
var resolveRecordAuthority = ({
|
|
230
|
+
dbKey,
|
|
231
|
+
record,
|
|
232
|
+
currentUserId,
|
|
233
|
+
currentServer,
|
|
234
|
+
userAuthorityRegistry
|
|
235
|
+
}) => {
|
|
236
|
+
const ownerUserId = parseOwnerUserIdFromDbKey(dbKey, {
|
|
237
|
+
candidateOwnerUserIds: [
|
|
238
|
+
normalizeUserId2(record?.userId),
|
|
239
|
+
normalizeUserId2(currentUserId),
|
|
240
|
+
...getRegistryOwnerCandidates(userAuthorityRegistry)
|
|
241
|
+
]
|
|
242
|
+
}) ?? normalizeUserId2(record?.userId);
|
|
243
|
+
const serverOrigin = normalizeAuthorityServerOrigin(record?.serverOrigin);
|
|
244
|
+
const explicitAuthority = normalizeAuthorityServerOrigin(record?.authorityServer);
|
|
245
|
+
const registryAuthority = resolveUserAuthorityServer({
|
|
246
|
+
ownerUserId,
|
|
247
|
+
registry: userAuthorityRegistry
|
|
248
|
+
});
|
|
249
|
+
const currentUserAuthority = ownerUserId && ownerUserId === normalizeUserId2(currentUserId) ? normalizeAuthorityServerOrigin(currentServer) : null;
|
|
250
|
+
return {
|
|
251
|
+
ownerUserId,
|
|
252
|
+
authorityServer: explicitAuthority ?? registryAuthority ?? currentUserAuthority ?? serverOrigin,
|
|
253
|
+
serverOrigin
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// packages/database/actions/readResolution.ts
|
|
258
|
+
var toComparableTimestamp = (data) => {
|
|
259
|
+
if (!data || typeof data !== "object") return 0;
|
|
260
|
+
const updatedAtMs = asOptionalPositiveFiniteNumber(
|
|
261
|
+
new Date(data.updatedAt).getTime()
|
|
262
|
+
);
|
|
263
|
+
if (updatedAtMs !== void 0) return updatedAtMs;
|
|
264
|
+
const createdAtMs = asOptionalPositiveFiniteNumber(
|
|
265
|
+
new Date(data.createdAt).getTime()
|
|
266
|
+
);
|
|
267
|
+
if (createdAtMs !== void 0) return createdAtMs;
|
|
268
|
+
return asOptionalPositiveFiniteNumber(Number(data?.meta?.createdAt)) ?? 0;
|
|
269
|
+
};
|
|
270
|
+
var partitionReadServers = ({
|
|
271
|
+
allServers,
|
|
272
|
+
preferredServerOrigin
|
|
273
|
+
}) => {
|
|
274
|
+
const preferredServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : null;
|
|
275
|
+
const fallbackServers = preferredServer ? allServers.filter(
|
|
276
|
+
(server) => normalizeServerOrigin(server) !== preferredServer
|
|
277
|
+
) : allServers;
|
|
278
|
+
return {
|
|
279
|
+
preferredServer,
|
|
280
|
+
fallbackServers,
|
|
281
|
+
orderedServersForLocalHit: preferredServer ? [preferredServer, ...fallbackServers] : fallbackServers
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
var compareRemoteRecordsByComparableTime = (left, right) => toComparableTimestamp(left) - toComparableTimestamp(right);
|
|
285
|
+
var pickBestSettledRemoteRecord = ({
|
|
286
|
+
settledResults,
|
|
287
|
+
isBetterCandidate
|
|
288
|
+
}) => {
|
|
289
|
+
const validResults = settledResults.map((result, index) => ({
|
|
290
|
+
data: result.status === "fulfilled" ? result.value : null,
|
|
291
|
+
index
|
|
292
|
+
})).filter((item) => item.data !== null && typeof item.data === "object");
|
|
293
|
+
if (validResults.length === 0) return null;
|
|
294
|
+
const latest = validResults.reduce(
|
|
295
|
+
(best, current) => isBetterCandidate(current.data, best.data) ? current : best
|
|
296
|
+
);
|
|
297
|
+
return { index: latest.index, data: latest.data };
|
|
298
|
+
};
|
|
299
|
+
var shouldReplaceLocalWithRemoteRecord = ({
|
|
300
|
+
localData,
|
|
301
|
+
remoteData,
|
|
302
|
+
isRemoteNewer
|
|
303
|
+
}) => {
|
|
304
|
+
if (!remoteData || typeof remoteData !== "object") return false;
|
|
305
|
+
if (!localData || typeof localData !== "object") return true;
|
|
306
|
+
return isRemoteNewer(remoteData, localData);
|
|
307
|
+
};
|
|
308
|
+
var shouldReplicateLocalRecord = ({
|
|
309
|
+
localData,
|
|
310
|
+
remoteData,
|
|
311
|
+
remoteTargetCount
|
|
312
|
+
}) => !!localData && !remoteData && remoteTargetCount > 0;
|
|
313
|
+
var compactUniqueServers = (servers) => {
|
|
314
|
+
const out = [];
|
|
315
|
+
for (const server of servers) {
|
|
316
|
+
if (typeof server !== "string" || server.trim().length === 0) continue;
|
|
317
|
+
const normalized = normalizeServerOrigin(server);
|
|
318
|
+
if (!out.includes(normalized)) out.push(normalized);
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
};
|
|
322
|
+
var planAuthorityReadServers = ({
|
|
323
|
+
allServers,
|
|
324
|
+
authorityServer,
|
|
325
|
+
serverOrigin
|
|
326
|
+
}) => compactUniqueServers([authorityServer, serverOrigin, ...allServers]);
|
|
327
|
+
|
|
328
|
+
// packages/core/fnv1a32.ts
|
|
329
|
+
var fnv1a32 = (str) => {
|
|
330
|
+
let hash = 2166136261;
|
|
331
|
+
for (let i = 0; i < str.length; i++) {
|
|
332
|
+
hash ^= str.charCodeAt(i);
|
|
333
|
+
hash = hash * 16777619 >>> 0;
|
|
334
|
+
}
|
|
335
|
+
return hash >>> 0;
|
|
336
|
+
};
|
|
337
|
+
var fnv1a32Hex = (str) => fnv1a32(str).toString(16).padStart(8, "0");
|
|
338
|
+
|
|
339
|
+
// packages/database/fileRing.ts
|
|
340
|
+
var chooseServersByKey = (allServers, key, replicaCount) => {
|
|
341
|
+
if (!allServers.length || replicaCount <= 0) return [];
|
|
342
|
+
const uniqueServers = Array.from(new Set(allServers)).filter((s) => !!s);
|
|
343
|
+
if (uniqueServers.length === 0) return [];
|
|
344
|
+
const scored = uniqueServers.map((server) => ({
|
|
345
|
+
server,
|
|
346
|
+
score: fnv1a32(`${server}::${key}`)
|
|
347
|
+
}));
|
|
348
|
+
scored.sort((a, b) => a.score - b.score);
|
|
349
|
+
const limit = Math.min(replicaCount, scored.length);
|
|
350
|
+
return scored.slice(0, limit).map((item) => item.server);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// packages/database/tenantPlacement.ts
|
|
354
|
+
var TENANT_REPLICA_COUNT = 2;
|
|
355
|
+
var planServersForTenant = (allServers, currentServer, tenantId) => {
|
|
356
|
+
const uniqueServers = Array.from(new Set(allServers)).filter(Boolean);
|
|
357
|
+
if (!uniqueServers.length) return [];
|
|
358
|
+
const key = asOptionalTrimmedString(tenantId) ?? "default-tenant";
|
|
359
|
+
const fromRing = chooseServersByKey(
|
|
360
|
+
uniqueServers,
|
|
361
|
+
key,
|
|
362
|
+
TENANT_REPLICA_COUNT
|
|
363
|
+
);
|
|
364
|
+
const set = new Set(fromRing);
|
|
365
|
+
if (currentServer && uniqueServers.includes(currentServer)) {
|
|
366
|
+
set.add(currentServer);
|
|
367
|
+
}
|
|
368
|
+
return Array.from(set);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// packages/database/authority/deviceLocal.ts
|
|
372
|
+
var DEVICE_LOCAL_OWNER_ID = "local";
|
|
373
|
+
var DEVICE_LOCAL_DB_KEY_PREFIXES = [
|
|
374
|
+
"dialog-local-",
|
|
375
|
+
"agent-local-"
|
|
376
|
+
];
|
|
377
|
+
var clean = (value) => asOptionalTrimmedString(value) ?? null;
|
|
378
|
+
var isDeviceLocalOwnerId = (userId) => clean(userId) === DEVICE_LOCAL_OWNER_ID;
|
|
379
|
+
var resolveEffectiveSpaceActorId = (accountUserId) => {
|
|
380
|
+
const cleaned = clean(accountUserId);
|
|
381
|
+
if (!cleaned || isDeviceLocalOwnerId(cleaned)) {
|
|
382
|
+
return DEVICE_LOCAL_OWNER_ID;
|
|
383
|
+
}
|
|
384
|
+
return cleaned;
|
|
385
|
+
};
|
|
386
|
+
var isDeviceLocalSpaceMembership = (membership) => isDeviceLocalOwnerId(membership?.userId);
|
|
387
|
+
var isDeviceLocalSpaceBody = (space) => isDeviceLocalOwnerId(space?.userId) || isDeviceLocalOwnerId(space?.ownerId);
|
|
388
|
+
var isDeviceLocalDbKey = (dbKey) => {
|
|
389
|
+
const key = clean(dbKey);
|
|
390
|
+
if (!key) return false;
|
|
391
|
+
for (const prefix of DEVICE_LOCAL_DB_KEY_PREFIXES) {
|
|
392
|
+
if (key.startsWith(prefix)) return true;
|
|
393
|
+
}
|
|
394
|
+
return parseOwnerUserIdFromDbKey(key, {
|
|
395
|
+
candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
|
|
396
|
+
}) === DEVICE_LOCAL_OWNER_ID;
|
|
397
|
+
};
|
|
398
|
+
var resolveRecordOwnerUserId = (record) => {
|
|
399
|
+
if (!record) return null;
|
|
400
|
+
const explicit = clean(record.userId);
|
|
401
|
+
if (explicit) return explicit;
|
|
402
|
+
if (isDeviceLocalDbKey(record.dbKey) || isDeviceLocalDbKey(record.id)) {
|
|
403
|
+
return DEVICE_LOCAL_OWNER_ID;
|
|
404
|
+
}
|
|
405
|
+
const fromKey = parseOwnerUserIdFromDbKey(clean(record.dbKey) ?? "", {
|
|
406
|
+
candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
|
|
407
|
+
}) ?? parseOwnerUserIdFromDbKey(clean(record.id) ?? "", {
|
|
408
|
+
candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
|
|
409
|
+
});
|
|
410
|
+
return fromKey;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// packages/database/actions/writeAck.ts
|
|
414
|
+
var ACK_ENTRY_RETENTION_MS = 1e4;
|
|
415
|
+
var ACK_ENTRY_MAX = 256;
|
|
416
|
+
var replicationTargetKey = (server) => normalizeKnownServerOrigin(server) ?? normalizeServerOrigin(server);
|
|
417
|
+
var ackEntries = /* @__PURE__ */ new Map();
|
|
418
|
+
var sweepAckEntries = () => {
|
|
419
|
+
const wallClock = Date.now();
|
|
420
|
+
for (const [key, entry] of ackEntries) {
|
|
421
|
+
if (entry.settledAt !== null && wallClock - entry.settledAt > ACK_ENTRY_RETENTION_MS) {
|
|
422
|
+
ackEntries.delete(key);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
while (ackEntries.size > ACK_ENTRY_MAX) {
|
|
426
|
+
const oldest = ackEntries.keys().next().value;
|
|
427
|
+
if (oldest === void 0) break;
|
|
428
|
+
ackEntries.delete(oldest);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var isReplicationAckHandle = (value) => {
|
|
432
|
+
if (!value || typeof value !== "object") return false;
|
|
433
|
+
const handle = value;
|
|
434
|
+
return typeof handle.primary?.then === "function" && handle.targets instanceof Map;
|
|
435
|
+
};
|
|
436
|
+
var asAckStatus = (ack) => ack.then(
|
|
437
|
+
(ok) => ok ? "acked" : "failed",
|
|
438
|
+
() => "failed"
|
|
439
|
+
);
|
|
440
|
+
var beginWriteAck = (dbKey) => {
|
|
441
|
+
let resolveOutcome = () => {
|
|
442
|
+
};
|
|
443
|
+
const promise = new Promise((resolve) => {
|
|
444
|
+
resolveOutcome = resolve;
|
|
445
|
+
});
|
|
446
|
+
const entry = {
|
|
447
|
+
promise,
|
|
448
|
+
settledAt: null,
|
|
449
|
+
servers: [],
|
|
450
|
+
primaryTargetKey: null,
|
|
451
|
+
planRegistered: false,
|
|
452
|
+
targetAcks: /* @__PURE__ */ new Map(),
|
|
453
|
+
settle: (status) => {
|
|
454
|
+
entry.settledAt = Date.now();
|
|
455
|
+
resolveOutcome(status);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
ackEntries.set(dbKey, entry);
|
|
459
|
+
sweepAckEntries();
|
|
460
|
+
return {
|
|
461
|
+
settleWithReplication: (replication) => {
|
|
462
|
+
if (isReplicationAckHandle(replication)) {
|
|
463
|
+
entry.planRegistered = true;
|
|
464
|
+
entry.servers = [...replication.servers];
|
|
465
|
+
entry.primaryTargetKey = replicationTargetKey(replication.servers[0]);
|
|
466
|
+
for (const [key, ack] of replication.targets) {
|
|
467
|
+
entry.targetAcks.set(key, asAckStatus(ack));
|
|
468
|
+
}
|
|
469
|
+
void asAckStatus(replication.primary).then(
|
|
470
|
+
(status) => entry.settle(status)
|
|
471
|
+
);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (replication && typeof replication.then === "function") {
|
|
475
|
+
void asAckStatus(replication).then(
|
|
476
|
+
(status) => entry.settle(status)
|
|
477
|
+
);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
entry.settle("not-replicated");
|
|
481
|
+
},
|
|
482
|
+
markNotReplicated: () => entry.settle("not-replicated"),
|
|
483
|
+
markAborted: () => entry.settle("aborted")
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// packages/database/actions/replication.ts
|
|
488
|
+
var isReadonlyPublicRecordKey = (dbKey) => dbKey.startsWith("agent-pub-");
|
|
489
|
+
var normalizeCurrentUserId = (state) => {
|
|
490
|
+
const userId = selectIdentityUserId(state);
|
|
491
|
+
return asOptionalTrimmedString(userId) ?? null;
|
|
492
|
+
};
|
|
493
|
+
var resolveReplicationServers = (currentServer, syncServers, preferredServerOrigin) => getAllServers(currentServer, syncServers, preferredServerOrigin);
|
|
494
|
+
var resolveAuthorityReplicationServers = ({
|
|
495
|
+
currentServer,
|
|
496
|
+
syncServers,
|
|
497
|
+
preferredServerOrigin,
|
|
498
|
+
dbKey,
|
|
499
|
+
record,
|
|
500
|
+
state
|
|
501
|
+
}) => {
|
|
502
|
+
const allServers = resolveReplicationServers(
|
|
503
|
+
currentServer,
|
|
504
|
+
syncServers,
|
|
505
|
+
preferredServerOrigin
|
|
506
|
+
);
|
|
507
|
+
const authority = resolveRecordAuthority({
|
|
508
|
+
dbKey,
|
|
509
|
+
record,
|
|
510
|
+
currentUserId: selectIdentityUserId(state),
|
|
511
|
+
currentServer,
|
|
512
|
+
userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? selectIdentityUser(state)?.authorityRegistry
|
|
513
|
+
});
|
|
514
|
+
if (isDeviceLocalOwnerId(authority.ownerUserId) || isDeviceLocalOwnerId(record?.userId) || isDeviceLocalDbKey(dbKey)) {
|
|
515
|
+
return [];
|
|
516
|
+
}
|
|
517
|
+
return planAuthorityReadServers({
|
|
518
|
+
allServers,
|
|
519
|
+
authorityServer: preferredServerOrigin ?? authority.authorityServer,
|
|
520
|
+
serverOrigin: authority.serverOrigin
|
|
521
|
+
});
|
|
522
|
+
};
|
|
523
|
+
var scheduleWriteReplication = (servers, request, state) => {
|
|
524
|
+
if (servers.length === 0) return null;
|
|
525
|
+
const [primaryServer, ...backupServers] = servers;
|
|
526
|
+
const targets = /* @__PURE__ */ new Map();
|
|
527
|
+
const settleTarget = /* @__PURE__ */ new Map();
|
|
528
|
+
for (const server of servers) {
|
|
529
|
+
const key = replicationTargetKey(server);
|
|
530
|
+
if (!key || targets.has(key)) continue;
|
|
531
|
+
targets.set(
|
|
532
|
+
key,
|
|
533
|
+
new Promise((resolve) => {
|
|
534
|
+
settleTarget.set(key, resolve);
|
|
535
|
+
})
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
const settleTargetFor = (server, ok) => {
|
|
539
|
+
const key = replicationTargetKey(server);
|
|
540
|
+
const resolve = settleTarget.get(key);
|
|
541
|
+
if (!resolve) return;
|
|
542
|
+
settleTarget.delete(key);
|
|
543
|
+
resolve(ok);
|
|
544
|
+
};
|
|
545
|
+
const primaryAck = Promise.resolve().then(async () => {
|
|
546
|
+
let primarySucceeded = false;
|
|
547
|
+
try {
|
|
548
|
+
primarySucceeded = await noloWriteRequest(primaryServer, request, state);
|
|
549
|
+
} finally {
|
|
550
|
+
settleTargetFor(primaryServer, primarySucceeded);
|
|
551
|
+
}
|
|
552
|
+
if (!primarySucceeded) {
|
|
553
|
+
console.warn(`Primary write sync failed for ${request.customKey} on ${primaryServer}`);
|
|
554
|
+
}
|
|
555
|
+
if (backupServers.length === 0) {
|
|
556
|
+
return primarySucceeded;
|
|
557
|
+
}
|
|
558
|
+
try {
|
|
559
|
+
syncWithServers(
|
|
560
|
+
backupServers,
|
|
561
|
+
(server, requestConfig, requestState, signal) => noloWriteRequest(server, requestConfig, requestState, signal, {
|
|
562
|
+
failureLogLevel: "info"
|
|
563
|
+
}).then(
|
|
564
|
+
(ok) => {
|
|
565
|
+
settleTargetFor(server, ok);
|
|
566
|
+
return ok;
|
|
567
|
+
},
|
|
568
|
+
(error) => {
|
|
569
|
+
settleTargetFor(server, false);
|
|
570
|
+
throw error;
|
|
571
|
+
}
|
|
572
|
+
),
|
|
573
|
+
`Backup write sync failed for ${request.customKey} on`,
|
|
574
|
+
request,
|
|
575
|
+
state
|
|
576
|
+
);
|
|
577
|
+
} catch (error) {
|
|
578
|
+
for (const server of backupServers) settleTargetFor(server, false);
|
|
579
|
+
throw error;
|
|
580
|
+
}
|
|
581
|
+
return primarySucceeded;
|
|
582
|
+
});
|
|
583
|
+
return { servers: [...servers], primary: primaryAck, targets };
|
|
584
|
+
};
|
|
585
|
+
var resolveTenantReplicationServers = ({
|
|
586
|
+
currentServer,
|
|
587
|
+
syncServers,
|
|
588
|
+
tenantId
|
|
589
|
+
}) => {
|
|
590
|
+
const allServers = resolveReplicationServers(currentServer, syncServers);
|
|
591
|
+
if (allServers.length === 0) {
|
|
592
|
+
return [];
|
|
593
|
+
}
|
|
594
|
+
return planServersForTenant(allServers, currentServer, tenantId);
|
|
595
|
+
};
|
|
596
|
+
var resolveUploadReplicationServers = ({
|
|
597
|
+
currentServer,
|
|
598
|
+
syncServers,
|
|
599
|
+
tenantId,
|
|
600
|
+
uploadConfig,
|
|
601
|
+
state
|
|
602
|
+
}) => {
|
|
603
|
+
const allServers = resolveReplicationServers(currentServer, syncServers);
|
|
604
|
+
const authority = resolveRecordAuthority({
|
|
605
|
+
dbKey: uploadConfig.customKey,
|
|
606
|
+
record: uploadConfig.metadata,
|
|
607
|
+
currentUserId: selectIdentityUserId(state),
|
|
608
|
+
currentServer,
|
|
609
|
+
userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? selectIdentityUser(state)?.authorityRegistry
|
|
610
|
+
});
|
|
611
|
+
if (authority.ownerUserId || authority.authorityServer) {
|
|
612
|
+
return planAuthorityReadServers({
|
|
613
|
+
allServers,
|
|
614
|
+
authorityServer: authority.authorityServer,
|
|
615
|
+
serverOrigin: authority.serverOrigin
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
return resolveTenantReplicationServers({
|
|
619
|
+
currentServer,
|
|
620
|
+
syncServers,
|
|
621
|
+
tenantId
|
|
622
|
+
});
|
|
623
|
+
};
|
|
624
|
+
var scheduleExistingRecordReplication = ({
|
|
625
|
+
currentServer,
|
|
626
|
+
syncServers,
|
|
627
|
+
preferredServerOrigin,
|
|
628
|
+
dbKey,
|
|
629
|
+
localData,
|
|
630
|
+
state
|
|
631
|
+
}) => {
|
|
632
|
+
if (isReadonlyPublicRecordKey(dbKey)) {
|
|
633
|
+
return [];
|
|
634
|
+
}
|
|
635
|
+
const currentUserId = normalizeCurrentUserId(state);
|
|
636
|
+
const authority = resolveRecordAuthority({
|
|
637
|
+
dbKey,
|
|
638
|
+
record: localData,
|
|
639
|
+
currentUserId,
|
|
640
|
+
currentServer,
|
|
641
|
+
userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? selectIdentityUser(state)?.authorityRegistry
|
|
642
|
+
});
|
|
643
|
+
if (authority.ownerUserId && currentUserId && authority.ownerUserId !== currentUserId) {
|
|
644
|
+
return [];
|
|
645
|
+
}
|
|
646
|
+
const servers = resolveAuthorityReplicationServers({
|
|
647
|
+
currentServer,
|
|
648
|
+
syncServers,
|
|
649
|
+
preferredServerOrigin,
|
|
650
|
+
dbKey,
|
|
651
|
+
record: localData,
|
|
652
|
+
state
|
|
653
|
+
});
|
|
654
|
+
if (servers.length === 0) {
|
|
655
|
+
return [];
|
|
656
|
+
}
|
|
657
|
+
scheduleWriteReplication(
|
|
658
|
+
servers,
|
|
659
|
+
{
|
|
660
|
+
data: localData,
|
|
661
|
+
customKey: dbKey,
|
|
662
|
+
userId: typeof localData?.userId === "string" ? localData.userId : selectIdentityUserId(state)
|
|
663
|
+
},
|
|
664
|
+
state
|
|
665
|
+
);
|
|
666
|
+
return servers;
|
|
667
|
+
};
|
|
668
|
+
var schedulePatchReplication = ({
|
|
669
|
+
servers,
|
|
670
|
+
dbKey,
|
|
671
|
+
changes,
|
|
672
|
+
state,
|
|
673
|
+
preferredServerOrigin
|
|
674
|
+
}) => {
|
|
675
|
+
if (servers.length === 0) return;
|
|
676
|
+
Promise.resolve().then(async () => {
|
|
677
|
+
const primaryServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : servers[0];
|
|
678
|
+
const backupServers = servers.filter(
|
|
679
|
+
(server) => normalizeServerOrigin(server) !== primaryServer
|
|
680
|
+
);
|
|
681
|
+
const primarySucceeded = await noloPatchRequest(primaryServer, dbKey, changes, state, void 0, {
|
|
682
|
+
failureLogLevel: "warn"
|
|
683
|
+
});
|
|
684
|
+
if (!primarySucceeded) {
|
|
685
|
+
console.warn(`Primary patch sync failed for ${dbKey} on ${primaryServer}`);
|
|
686
|
+
}
|
|
687
|
+
if (backupServers.length > 0) {
|
|
688
|
+
syncWithServers(
|
|
689
|
+
backupServers,
|
|
690
|
+
(server, targetDbKey, nextChanges, requestState, signal) => noloPatchRequest(server, targetDbKey, nextChanges, requestState, signal, {
|
|
691
|
+
failureLogLevel: "info"
|
|
692
|
+
}),
|
|
693
|
+
`Backup patch sync failed for ${dbKey} on`,
|
|
694
|
+
dbKey,
|
|
695
|
+
changes,
|
|
696
|
+
state
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
};
|
|
701
|
+
var scheduleConfiguredPatchReplication = ({
|
|
702
|
+
currentServer,
|
|
703
|
+
syncServers,
|
|
704
|
+
preferredServerOrigin,
|
|
705
|
+
dbKey,
|
|
706
|
+
changes,
|
|
707
|
+
state
|
|
708
|
+
}) => {
|
|
709
|
+
const servers = resolveAuthorityReplicationServers({
|
|
710
|
+
currentServer,
|
|
711
|
+
syncServers,
|
|
712
|
+
preferredServerOrigin,
|
|
713
|
+
dbKey,
|
|
714
|
+
record: changes,
|
|
715
|
+
state
|
|
716
|
+
});
|
|
717
|
+
if (servers.length === 0) {
|
|
718
|
+
return [];
|
|
719
|
+
}
|
|
720
|
+
schedulePatchReplication({
|
|
721
|
+
servers,
|
|
722
|
+
dbKey,
|
|
723
|
+
changes,
|
|
724
|
+
state,
|
|
725
|
+
preferredServerOrigin
|
|
726
|
+
});
|
|
727
|
+
return servers;
|
|
728
|
+
};
|
|
729
|
+
var scheduleUploadReplication = ({
|
|
730
|
+
currentServer,
|
|
731
|
+
syncServers,
|
|
732
|
+
tenantId,
|
|
733
|
+
uploadConfig,
|
|
734
|
+
state,
|
|
735
|
+
excludeServers = []
|
|
736
|
+
}) => {
|
|
737
|
+
const servers = resolveUploadReplicationServers({
|
|
738
|
+
currentServer,
|
|
739
|
+
syncServers,
|
|
740
|
+
tenantId,
|
|
741
|
+
uploadConfig,
|
|
742
|
+
state
|
|
743
|
+
});
|
|
744
|
+
const excluded = new Set(
|
|
745
|
+
excludeServers.filter((server) => typeof server === "string").map((server) => normalizeServerOrigin(server))
|
|
746
|
+
);
|
|
747
|
+
const remainingServers = servers.filter(
|
|
748
|
+
(server) => !excluded.has(normalizeServerOrigin(server))
|
|
749
|
+
);
|
|
750
|
+
if (remainingServers.length === 0) {
|
|
751
|
+
return [];
|
|
752
|
+
}
|
|
753
|
+
Promise.resolve().then(() => {
|
|
754
|
+
syncWithServers(
|
|
755
|
+
remainingServers,
|
|
756
|
+
noloUploadRequest,
|
|
757
|
+
`Upload sync failed for ${uploadConfig.customKey} on`,
|
|
758
|
+
uploadConfig,
|
|
759
|
+
state
|
|
760
|
+
);
|
|
761
|
+
});
|
|
762
|
+
return remainingServers;
|
|
763
|
+
};
|
|
764
|
+
var uploadToCurrentServer = async ({
|
|
765
|
+
currentServer,
|
|
766
|
+
uploadConfig,
|
|
767
|
+
state
|
|
768
|
+
}) => {
|
|
769
|
+
if (!currentServer) {
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
return noloUploadRequest(currentServer, uploadConfig, state);
|
|
773
|
+
};
|
|
774
|
+
var deleteFromReplicationServers = async ({
|
|
775
|
+
servers,
|
|
776
|
+
dbKey,
|
|
777
|
+
deleteOptions = { type: "single" },
|
|
778
|
+
state,
|
|
779
|
+
preferredServerOrigin
|
|
780
|
+
}) => {
|
|
781
|
+
if (!servers.length) {
|
|
782
|
+
return { succeeded: [], failed: [] };
|
|
783
|
+
}
|
|
784
|
+
const preferredServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : null;
|
|
785
|
+
const remainingServers = preferredServer ? servers.filter((server) => normalizeServerOrigin(server) !== preferredServer) : servers;
|
|
786
|
+
const succeeded = [];
|
|
787
|
+
const failed = [];
|
|
788
|
+
if (preferredServer) {
|
|
789
|
+
const ok = await noloDeleteRequest(preferredServer, dbKey, deleteOptions, state);
|
|
790
|
+
if (ok) {
|
|
791
|
+
succeeded.push(preferredServer);
|
|
792
|
+
} else {
|
|
793
|
+
failed.push(preferredServer);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (remainingServers.length > 0) {
|
|
797
|
+
const results = await Promise.all(
|
|
798
|
+
remainingServers.map(async (server) => ({
|
|
799
|
+
server,
|
|
800
|
+
ok: await noloDeleteRequest(server, dbKey, deleteOptions, state)
|
|
801
|
+
}))
|
|
802
|
+
);
|
|
803
|
+
results.forEach(({ server, ok }) => {
|
|
804
|
+
if (ok) succeeded.push(server);
|
|
805
|
+
else failed.push(server);
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
return { succeeded, failed };
|
|
809
|
+
};
|
|
810
|
+
var scheduleDeleteReplication = ({
|
|
811
|
+
currentServer,
|
|
812
|
+
syncServers,
|
|
813
|
+
preferredServerOrigin,
|
|
814
|
+
dbKey,
|
|
815
|
+
deleteOptions,
|
|
816
|
+
state,
|
|
817
|
+
onResult,
|
|
818
|
+
onError
|
|
819
|
+
}) => {
|
|
820
|
+
const servers = resolveAuthorityReplicationServers({
|
|
821
|
+
currentServer,
|
|
822
|
+
syncServers,
|
|
823
|
+
preferredServerOrigin,
|
|
824
|
+
dbKey,
|
|
825
|
+
state
|
|
826
|
+
});
|
|
827
|
+
if (servers.length === 0) {
|
|
828
|
+
return [];
|
|
829
|
+
}
|
|
830
|
+
void Promise.resolve().then(
|
|
831
|
+
() => deleteFromReplicationServers({
|
|
832
|
+
servers,
|
|
833
|
+
dbKey,
|
|
834
|
+
deleteOptions,
|
|
835
|
+
state,
|
|
836
|
+
preferredServerOrigin
|
|
837
|
+
})
|
|
838
|
+
).then((result) => {
|
|
839
|
+
onResult?.(result);
|
|
840
|
+
}).catch((error) => {
|
|
841
|
+
onError?.(error);
|
|
842
|
+
});
|
|
843
|
+
return servers;
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
export {
|
|
847
|
+
selectRuntimeSnapshot,
|
|
848
|
+
selectRuntimeCurrentServer,
|
|
849
|
+
getRuntimeServerContext,
|
|
850
|
+
fnv1a32Hex,
|
|
851
|
+
parseOwnerUserIdFromDbKey,
|
|
852
|
+
DEVICE_LOCAL_OWNER_ID,
|
|
853
|
+
isDeviceLocalOwnerId,
|
|
854
|
+
resolveEffectiveSpaceActorId,
|
|
855
|
+
isDeviceLocalSpaceMembership,
|
|
856
|
+
isDeviceLocalSpaceBody,
|
|
857
|
+
resolveRecordOwnerUserId,
|
|
858
|
+
resolveRecordAuthority,
|
|
859
|
+
beginWriteAck,
|
|
860
|
+
partitionReadServers,
|
|
861
|
+
compareRemoteRecordsByComparableTime,
|
|
862
|
+
pickBestSettledRemoteRecord,
|
|
863
|
+
shouldReplaceLocalWithRemoteRecord,
|
|
864
|
+
shouldReplicateLocalRecord,
|
|
865
|
+
planAuthorityReadServers,
|
|
866
|
+
resolveReplicationServers,
|
|
867
|
+
resolveAuthorityReplicationServers,
|
|
868
|
+
scheduleWriteReplication,
|
|
869
|
+
resolveUploadReplicationServers,
|
|
870
|
+
scheduleExistingRecordReplication,
|
|
871
|
+
scheduleConfiguredPatchReplication,
|
|
872
|
+
scheduleUploadReplication,
|
|
873
|
+
uploadToCurrentServer,
|
|
874
|
+
scheduleDeleteReplication
|
|
875
|
+
};
|