@powerhousedao/connect 6.2.3-dev.6 → 6.2.3-dev.60
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/{AddDriveModal-xAw48kdl.js → AddDriveModal-C5odBO8y.js} +6 -6
- package/dist/AddDriveModal-C5odBO8y.js.map +1 -0
- package/dist/{ClearStorageModal-B9bF7a7q.js → ClearStorageModal-DE2TKUfn.js} +6 -6
- package/dist/{ClearStorageModal-B9bF7a7q.js.map → ClearStorageModal-DE2TKUfn.js.map} +1 -1
- package/dist/{ConfirmDocumentUpgradeModal-FUOhZsk7.js → ConfirmDocumentUpgradeModal-k79v2wM6.js} +7 -6
- package/dist/{ConfirmDocumentUpgradeModal-FUOhZsk7.js.map → ConfirmDocumentUpgradeModal-k79v2wM6.js.map} +1 -1
- package/dist/{CookiesPolicyModal-BpyPPyxS.js → CookiesPolicyModal-BLw4pnhn.js} +4 -4
- package/dist/{CookiesPolicyModal-BpyPPyxS.js.map → CookiesPolicyModal-BLw4pnhn.js.map} +1 -1
- package/dist/{CreateDocumentModal-C45W8J0V.js → CreateDocumentModal-Bmv0V-kY.js} +6 -5
- package/dist/{CreateDocumentModal-C45W8J0V.js.map → CreateDocumentModal-Bmv0V-kY.js.map} +1 -1
- package/dist/{DebugSettingsModal-C6kwYM5N.js → DebugSettingsModal-BYrr41NU.js} +7 -7
- package/dist/{DebugSettingsModal-C6kwYM5N.js.map → DebugSettingsModal-BYrr41NU.js.map} +1 -1
- package/dist/{DeleteDriveModal-Dug84t1j.js → DeleteDriveModal-CjGnG0ht.js} +5 -5
- package/dist/{DeleteDriveModal-Dug84t1j.js.map → DeleteDriveModal-CjGnG0ht.js.map} +1 -1
- package/dist/{DeleteItemModal-mMzy3V8o.js → DeleteItemModal-BbY_4_xT.js} +5 -5
- package/dist/{DeleteItemModal-mMzy3V8o.js.map → DeleteItemModal-BbY_4_xT.js.map} +1 -1
- package/dist/{DisclaimerModal-DvpD5dPM.js → DisclaimerModal-DuglmEwL.js} +4 -4
- package/dist/{DisclaimerModal-DvpD5dPM.js.map → DisclaimerModal-DuglmEwL.js.map} +1 -1
- package/dist/{DocumentVersionUnsupportedModal-C3Q0V75l.js → DocumentVersionUnsupportedModal-C4fy7fZ6.js} +4 -4
- package/dist/{DocumentVersionUnsupportedModal-C3Q0V75l.js.map → DocumentVersionUnsupportedModal-C4fy7fZ6.js.map} +1 -1
- package/dist/{DownloadDocumentWithErrorsModal-IKl0ljQb.js → DownloadDocumentWithErrorsModal-BsPQ5qgy.js} +6 -5
- package/dist/{DownloadDocumentWithErrorsModal-IKl0ljQb.js.map → DownloadDocumentWithErrorsModal-BsPQ5qgy.js.map} +1 -1
- package/dist/{DriveAuthRequiredModal-DVK7ZQzO.js → DriveAuthRequiredModal-CtsB0kwH.js} +5 -5
- package/dist/{DriveAuthRequiredModal-DVK7ZQzO.js.map → DriveAuthRequiredModal-CtsB0kwH.js.map} +1 -1
- package/dist/{DriveSettingsModal-C6-mRQiv.js → DriveSettingsModal-d1L0eYof.js} +4 -4
- package/dist/{DriveSettingsModal-C6-mRQiv.js.map → DriveSettingsModal-d1L0eYof.js.map} +1 -1
- package/dist/{InspectorModal-BDLUQ91R.js → InspectorModal-CpqAS_PY.js} +62 -22
- package/dist/InspectorModal-CpqAS_PY.js.map +1 -0
- package/dist/{LoginModal-CybbOm3N.js → LoginModal-CI0ogC2-.js} +5 -5
- package/dist/{LoginModal-CybbOm3N.js.map → LoginModal-CI0ogC2-.js.map} +1 -1
- package/dist/{MissingPackageModal-nBnExqO0.js → MissingPackageModal-DS3dgJ1K.js} +5 -5
- package/dist/{MissingPackageModal-nBnExqO0.js.map → MissingPackageModal-DS3dgJ1K.js.map} +1 -1
- package/dist/{OpenFileDocumentsModal-OPmSKJ4w.js → OpenFileDocumentsModal-C9vyTb6I.js} +8 -7
- package/dist/{OpenFileDocumentsModal-OPmSKJ4w.js.map → OpenFileDocumentsModal-C9vyTb6I.js.map} +1 -1
- package/dist/{SettingsModal-BY2USww8.js → SettingsModal-_hk8S-ey.js} +19 -15
- package/dist/{SettingsModal-BY2USww8.js.map → SettingsModal-_hk8S-ey.js.map} +1 -1
- package/dist/{UpgradeDriveModal-_8t9slxQ.js → UpgradeDriveModal-CXX6D5Au.js} +4 -4
- package/dist/{UpgradeDriveModal-_8t9slxQ.js.map → UpgradeDriveModal-CXX6D5Au.js.map} +1 -1
- package/dist/{app-loader-CgBHl_w5.js → app-loader-C_y2O5-k.js} +1257 -1122
- package/dist/app-loader-C_y2O5-k.js.map +1 -0
- package/dist/app-loader-DthM3kLU.js +4 -0
- package/dist/app-skeleton--Me5zlSz.js +112 -0
- package/dist/app-skeleton--Me5zlSz.js.map +1 -0
- package/dist/app-skeleton-CBN4tenZ.js +4 -0
- package/dist/boot-CNW7ypcB.js +210 -0
- package/dist/boot-CNW7ypcB.js.map +1 -0
- package/dist/buffer-DNTcuap_.js +66 -0
- package/dist/buffer-DNTcuap_.js.map +1 -0
- package/dist/{build-info-DKQqI_sg.js → build-info-CRwnXFRI.js} +10 -6
- package/dist/build-info-CRwnXFRI.js.map +1 -0
- package/dist/components-DVQlpeR0.js +5 -0
- package/dist/{connect.config-DaHDEUrw.js → connect.config-CB78ZsFz.js} +26 -14
- package/dist/connect.config-CB78ZsFz.js.map +1 -0
- package/dist/{connection-state-3w4liC1X.js → connection-state-BDikOGKo.js} +20 -9
- package/dist/{connection-state-3w4liC1X.js.map → connection-state-BDikOGKo.js.map} +1 -1
- package/dist/{cookie-banner-BH6bIq24.js → cookie-banner-D05DZRqY.js} +6 -6
- package/dist/{cookie-banner-BH6bIq24.js.map → cookie-banner-D05DZRqY.js.map} +1 -1
- package/dist/{i18n-CWO0vYVd.js → i18n-CTgT1HG-.js} +3 -3
- package/dist/{i18n-CWO0vYVd.js.map → i18n-CTgT1HG-.js.map} +1 -1
- package/dist/{load-VdwMO26x.js → load-BO0qVu72.js} +14 -12
- package/dist/{load-VdwMO26x.js.map → load-BO0qVu72.js.map} +1 -1
- package/dist/main.d.ts +2 -1
- package/dist/main.js +8 -8
- package/dist/main.js.map +1 -1
- package/dist/multi-reactor-BG-DqUcm.js +217 -0
- package/dist/multi-reactor-BG-DqUcm.js.map +1 -0
- package/dist/package-manager-BPVMRBoV.js +488 -0
- package/dist/package-manager-BPVMRBoV.js.map +1 -0
- package/dist/{pglite-major-B39aOEiE.js → pglite-major-p4_YefAE.js} +23 -5
- package/dist/pglite-major-p4_YefAE.js.map +1 -0
- package/dist/{pglite-migrate-core-Boxqqx-c.js → pglite-migrate-core-BcXcImng.js} +8 -6
- package/dist/{pglite-migrate-core-Boxqqx-c.js.map → pglite-migrate-core-BcXcImng.js.map} +1 -1
- package/dist/{pglite-seed-BqAUvNFw.js → pglite-seed-CQJ97bEt.js} +4 -4
- package/dist/{pglite-seed-BqAUvNFw.js.map → pglite-seed-CQJ97bEt.js.map} +1 -1
- package/dist/pglite.worker.d.ts +2 -1
- package/dist/pglite.worker.js +4 -3
- package/dist/pglite.worker.js.map +1 -1
- package/dist/pglite.worker.legacy.d.ts +2 -1
- package/dist/pglite.worker.legacy.js +4 -3
- package/dist/pglite.worker.legacy.js.map +1 -1
- package/dist/plugin-host--lBWChr9.js +254 -0
- package/dist/plugin-host--lBWChr9.js.map +1 -0
- package/dist/{preferences-store-_5Cw4_YV.js → preferences-store-Cm0BoiHA.js} +6 -25
- package/dist/preferences-store-Cm0BoiHA.js.map +1 -0
- package/dist/{pwa-manifest-link-DIgOSo2Q.js → pwa-manifest-link-DQRJpF0r.js} +3 -3
- package/dist/{pwa-manifest-link-DIgOSo2Q.js.map → pwa-manifest-link-DQRJpF0r.js.map} +1 -1
- package/dist/{reactor-D3o30osB.js → reactor-B8Sh7Et8.js} +611 -532
- package/dist/reactor-B8Sh7Et8.js.map +1 -0
- package/dist/reactor.worker.d.ts +2 -1
- package/dist/reactor.worker.js +413 -149
- package/dist/reactor.worker.js.map +1 -1
- package/dist/{registerServiceWorker-BSzbNfvz.js → registerServiceWorker-DT6t8wjg.js} +5 -5
- package/dist/{registerServiceWorker-BSzbNfvz.js.map → registerServiceWorker-DT6t8wjg.js.map} +1 -1
- package/dist/{runtime-config-DL3QjcfM.js → runtime-config-DI5OfIC6.js} +17 -4
- package/dist/runtime-config-DI5OfIC6.js.map +1 -0
- package/dist/runtime-flag-B8IYhkz-.js +4 -0
- package/dist/runtime-flag-CT5OKujT.js +45 -0
- package/dist/runtime-flag-CT5OKujT.js.map +1 -0
- package/dist/{sentry-QXKgQmr2.js → sentry-jfDyrxdX.js} +3 -3
- package/dist/{sentry-QXKgQmr2.js.map → sentry-jfDyrxdX.js.map} +1 -1
- package/dist/start-connect.d.ts +4 -5
- package/dist/start-connect.d.ts.map +1 -1
- package/dist/start-connect.js +6 -8
- package/dist/start-connect.js.map +1 -1
- package/dist/store-lock-Bi3B9VJD.js +159 -0
- package/dist/store-lock-Bi3B9VJD.js.map +1 -0
- package/dist/style.css +3288 -1
- package/dist/{toast-BXIGd4Eb.js → toast-C6WW-_O-.js} +3 -3
- package/dist/{toast-BXIGd4Eb.js.map → toast-C6WW-_O-.js.map} +1 -1
- package/dist/{use-renown-login-Cf3va6u_.js → use-renown-login-BzOSQETV.js} +3 -3
- package/dist/{use-renown-login-Cf3va6u_.js.map → use-renown-login-BzOSQETV.js.map} +1 -1
- package/dist/useIsEmbedded-BWJ0qb7w.js +26 -0
- package/dist/useIsEmbedded-BWJ0qb7w.js.map +1 -0
- package/dist/{useRegistryPackages-BnUcL_nZ.js → useRegistryPackages-3EcR3GOh.js} +75 -13
- package/dist/useRegistryPackages-3EcR3GOh.js.map +1 -0
- package/package.json +21 -19
- package/style.css +7 -5
- package/dist/AddDriveModal-xAw48kdl.js.map +0 -1
- package/dist/InspectorModal-BDLUQ91R.js.map +0 -1
- package/dist/app-loader-CgBHl_w5.js.map +0 -1
- package/dist/app-loader-CxVV3sev.js +0 -4
- package/dist/build-info-DKQqI_sg.js.map +0 -1
- package/dist/components-DIrmDBOB.js +0 -4
- package/dist/connect.config-DaHDEUrw.js.map +0 -1
- package/dist/pglite-major-B39aOEiE.js.map +0 -1
- package/dist/preferences-store-_5Cw4_YV.js.map +0 -1
- package/dist/reactor-D3o30osB.js.map +0 -1
- package/dist/runtime-config-DL3QjcfM.js.map +0 -1
- package/dist/useRegistryPackages-BnUcL_nZ.js.map +0 -1
|
@@ -1,110 +1,103 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import { n as getRuntimeConfig } from "./runtime-config-
|
|
4
|
-
import { a as
|
|
5
|
-
import {
|
|
6
|
-
import { n as buildPHGlobalConfig, o as phGlobalConfig } from "./connect.config-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="25f5b030-997d-5eef-b64b-536c6e8d0f21")}catch(e){}}();
|
|
3
|
+
import { n as getRuntimeConfig } from "./runtime-config-DI5OfIC6.js";
|
|
4
|
+
import { a as closeWithin, n as watchStoreLockWait, o as configureConnectChannelScheme, s as createConnectSignerConfig } from "./store-lock-Bi3B9VJD.js";
|
|
5
|
+
import { a as resolvePgMajorForRuntime, f as toStoredDocumentsRefused, r as loadPGliteModule } from "./pglite-major-p4_YefAE.js";
|
|
6
|
+
import { n as buildPHGlobalConfig, o as phGlobalConfig, r as connectConfig } from "./connect.config-CB78ZsFz.js";
|
|
7
|
+
import { r as toast } from "./toast-C6WW-_O-.js";
|
|
8
|
+
import { r as getSharedDeps, t as BrowserPackageManager } from "./package-manager-BPVMRBoV.js";
|
|
9
|
+
import { a as isPackagedConnectDist, i as getVersion, n as getGitSha } from "./build-info-CRwnXFRI.js";
|
|
10
|
+
import { g as RELATIONAL_PGLITE_NAME, h as REACTOR_PGLITE_NAME, m as REACTOR_INSTANCE_NAMESPACE, n as getWorkerConnectionStatus, o as detectReactorPgMajor, r as setWorkerConnectionStatus, s as detectRelationalPgMajor, t as clearStorageHeld } from "./connection-state-BDikOGKo.js";
|
|
11
|
+
import { t as isRuntimeFlagEnabled } from "./runtime-flag-CT5OKujT.js";
|
|
11
12
|
import { createRelationalDb } from "@powerhousedao/shared/processors";
|
|
12
|
-
import { DocumentModelRegistry, DocumentModelResolver, ReactorEventTypes, createReactorHostModuleBase } from "@powerhousedao/reactor";
|
|
13
|
-
import { MessageRouter, RPC_PROTOCOL_VERSION, SyncManagerProxy, connectReactorClient, createInspectorProxy, createPortTransport, createReactorEventBusProxy, createRelationalPgliteProxy, createWorkerAdminClient, postReactorIdentity } from "@powerhousedao/reactor-browser/rpc";
|
|
13
|
+
import { DocumentModelRegistry, DocumentModelResolver, HardenedPGliteDialect, LocalChannelFactory, LocalChannelPortRegistry, PGLITE_IDB_STORAGE_FACTS, ReactorEventTypes, createReactorHostModuleBase } from "@powerhousedao/reactor";
|
|
14
|
+
import { MessageRouter, RPC_PROTOCOL_VERSION, SyncManagerProxy, connectReactorClient, createInspectorProxy, createPortTransport, createReactorEventBusProxy, createRelationalPgliteProxy, createWorkerAdminClient, isFingerprintMismatchReload, postReactorIdentity } from "@powerhousedao/reactor-browser/rpc";
|
|
15
|
+
import { ConsoleLogger, logger, setLogLevel } from "document-model";
|
|
14
16
|
import { Kysely } from "kysely";
|
|
15
|
-
import {
|
|
16
|
-
import { BrowserLocalStorage, ChannelScheme as ChannelScheme$1, DRIVE_DOCUMENT_TYPES, DocumentCache, DocumentChangeType, ReactorBuilder as ReactorBuilder$1, ReactorClientBuilder as ReactorClientBuilder$1, RegistryClient, addDrive, addPHEventHandlers, addRemoteDrive, createAnalyticsStore, extractDriveSlugFromPath, extractNodeSlugFromPath, getDrives, isDriveAuthError, login, refreshReactorDataClient, setAttachmentService, setDefaultPHGlobalConfig, setDocumentCache, setDriveMetadata, setDrives, setFeatures, setPGliteDB, setPHToast, setPackageDiscoveryService, setReactorClient, setReactorClientModule, setRenown, setSelectedDrive, setSelectedNode, setVetraPackageManager, waitForDocumentReady } from "@powerhousedao/reactor-browser";
|
|
17
|
-
import { ConsoleLogger, logger, setLogLevel as setLogLevel$1 } from "document-model";
|
|
18
|
-
import { BrowserKeyStorage, RenownBuilder, RenownCryptoBuilder, createSignatureVerifier } from "@renown/sdk";
|
|
19
|
-
import { PwaConfigSchema } from "@powerhousedao/shared/document-model";
|
|
17
|
+
import { BrowserLocalStorage, DRIVE_DOCUMENT_TYPES, DocumentCache, DocumentChangeType, ReactorBuilder as ReactorBuilder$1, ReactorClientBuilder as ReactorClientBuilder$1, RegistryClient, addDrive, addPHEventHandlers, addRemoteDrive, createAnalyticsStore, extractDriveSlugFromPath, extractNodeSlugFromPath, getDrives, getFullReactorClient, isDriveAuthError, login, refreshReactorDataClient, setAttachmentService, setDefaultPHGlobalConfig, setDocumentCache, setDriveMetadata, setDrives, setFeatures, setFullReactorClient, setPGliteDB, setPHToast, setPackageDiscoveryService, setReactorClient, setReactorClientModule, setRenown, setSelectedDrive, setSelectedNode, setVetraPackageManager, waitForDocumentReady } from "@powerhousedao/reactor-browser";
|
|
20
18
|
import { createAttachmentClient, createRemoteAttachmentService, createXhrUploadTransport } from "@powerhousedao/reactor-attachments/client";
|
|
19
|
+
import { BrowserKeyStorage, RenownBuilder, RenownCryptoBuilder } from "@renown/sdk";
|
|
21
20
|
import { OpenFeature } from "@openfeature/web-sdk";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("ph-pwa open failed"));
|
|
34
|
-
req.onblocked = () => reject(/* @__PURE__ */ new Error("ph-pwa open blocked"));
|
|
35
|
-
req.onsuccess = () => resolve(req.result);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/** Write (replace) the single merged fragment record. Best-effort: a failure to
|
|
39
|
-
* mirror the manifest must never break package installation, so callers ignore
|
|
40
|
-
* rejections. No-op when IndexedDB is unavailable (SSR/tests). */
|
|
41
|
-
async function writeMergedPwaFragment(fragment) {
|
|
42
|
-
if (typeof indexedDB === "undefined") return;
|
|
43
|
-
const db = await openPwaIdb();
|
|
21
|
+
//#region src/utils/poisoned-store-budget.ts
|
|
22
|
+
const BUDGET_LIMIT = 2;
|
|
23
|
+
const POISONED_STORE = {
|
|
24
|
+
key: "ph-connect:poisoned-store-reloads",
|
|
25
|
+
quietMs: 6e5
|
|
26
|
+
};
|
|
27
|
+
const MISMATCH = {
|
|
28
|
+
key: "ph-connect:mismatch-reloads",
|
|
29
|
+
quietMs: 6e4
|
|
30
|
+
};
|
|
31
|
+
function sessionStore() {
|
|
44
32
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
tx.onerror = () => reject(tx.error ?? /* @__PURE__ */ new Error("PWA fragment write failed"));
|
|
49
|
-
tx.objectStore(PWA_IDB_STORE).put({
|
|
50
|
-
version: 1,
|
|
51
|
-
fragment,
|
|
52
|
-
updatedAt: Date.now()
|
|
53
|
-
}, PWA_IDB_KEY);
|
|
54
|
-
});
|
|
55
|
-
} finally {
|
|
56
|
-
db.close();
|
|
33
|
+
return globalThis.sessionStorage;
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
57
36
|
}
|
|
58
37
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
function readRecord(raw) {
|
|
39
|
+
const record = raw ? JSON.parse(raw) : null;
|
|
40
|
+
return typeof record?.count === "number" && typeof record.lastAt === "number" ? {
|
|
41
|
+
count: record.count,
|
|
42
|
+
lastAt: record.lastAt
|
|
43
|
+
} : {
|
|
44
|
+
count: 0,
|
|
45
|
+
lastAt: 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function claimReload(budget, storage, now) {
|
|
49
|
+
if (storage === void 0) return false;
|
|
65
50
|
try {
|
|
66
|
-
const
|
|
67
|
-
|
|
51
|
+
const previous = readRecord(storage.getItem(budget.key));
|
|
52
|
+
const count = now - previous.lastAt >= budget.quietMs ? 0 : previous.count;
|
|
53
|
+
const allowed = count < BUDGET_LIMIT;
|
|
54
|
+
storage.setItem(budget.key, JSON.stringify({
|
|
55
|
+
count: allowed ? count + 1 : count,
|
|
56
|
+
lastAt: now
|
|
57
|
+
}));
|
|
58
|
+
return allowed;
|
|
68
59
|
} catch {
|
|
69
|
-
return
|
|
60
|
+
return false;
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
/** One page reload answers every budgeted reload the page hears, of either budget. */
|
|
64
|
+
let reloadRequested = false;
|
|
65
|
+
function reloadWithinBudget(budget, reload, pastBudget, storage = sessionStore(), now = Date.now()) {
|
|
66
|
+
if (reloadRequested) return;
|
|
67
|
+
if (claimReload(budget, storage, now)) {
|
|
68
|
+
reloadRequested = true;
|
|
69
|
+
reload();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
setWorkerConnectionStatus(pastBudget);
|
|
77
73
|
}
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}))
|
|
98
|
-
}
|
|
99
|
-
};
|
|
74
|
+
/** Past the budget a poisoned store stops reloading and shows storage-unusable, so clear storage stays reachable. */
|
|
75
|
+
function reloadForPoisonedStore(reload, storage, now) {
|
|
76
|
+
reloadWithinBudget(POISONED_STORE, reload, "storage-unusable", storage, now);
|
|
77
|
+
}
|
|
78
|
+
/** onPoisoned for an in-tab store: the page reload reopens it, within the poisoned-store budget. */
|
|
79
|
+
function reloadPageForPoisonedStore(cause, reload = () => window.location.reload()) {
|
|
80
|
+
console.error("[connect] PGlite session poisoned:", cause);
|
|
81
|
+
reloadForPoisonedStore(reload);
|
|
82
|
+
}
|
|
83
|
+
function reloadForWorker(reason, reload, storage, now) {
|
|
84
|
+
if (reason === "storage session poisoned") {
|
|
85
|
+
reloadForPoisonedStore(reload, storage, now);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (isFingerprintMismatchReload(reason)) {
|
|
89
|
+
reloadWithinBudget(MISMATCH, reload, "version-conflict", storage, now);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
reload();
|
|
100
93
|
}
|
|
101
94
|
//#endregion
|
|
102
95
|
//#region src/pglite.db.ts
|
|
103
|
-
async function createMainThreadPGlite(major, dbName) {
|
|
96
|
+
async function createMainThreadPGlite(major, dbName, relaxedDurability) {
|
|
104
97
|
const { PGlite } = await loadPGliteModule(major);
|
|
105
98
|
const { live } = major === 16 ? await import("pglite-legacy-02/live") : await import("@electric-sql/pglite/live");
|
|
106
99
|
return new PGlite(`idb://${dbName}`, {
|
|
107
|
-
relaxedDurability
|
|
100
|
+
relaxedDurability,
|
|
108
101
|
extensions: { live }
|
|
109
102
|
});
|
|
110
103
|
}
|
|
@@ -114,37 +107,72 @@ function chainedCreate(create) {
|
|
|
114
107
|
bootChain = pending.catch(() => void 0);
|
|
115
108
|
return pending;
|
|
116
109
|
}
|
|
110
|
+
const CLOSE_TIMEOUT_MS = 3e4;
|
|
117
111
|
function pgliteSingleton(opts) {
|
|
118
112
|
let cached;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
113
|
+
let unusable;
|
|
114
|
+
return {
|
|
115
|
+
get() {
|
|
116
|
+
if (cached) return cached;
|
|
117
|
+
const pending = chainedCreate(async () => {
|
|
118
|
+
if (unusable) throw unusable;
|
|
119
|
+
const major = resolvePgMajorForRuntime(await opts.detectMajor());
|
|
120
|
+
if (major !== 17) console.warn(`[${opts.label}] Opening legacy Postgres ${major} data dir. Migrate to PG17 from the banner or the Inspector → Debug tab.`);
|
|
121
|
+
return createMainThreadPGlite(major, opts.dbName, opts.relaxedDurability);
|
|
122
|
+
});
|
|
123
|
+
cached = pending;
|
|
124
|
+
pending.catch(() => {
|
|
125
|
+
if (cached === pending) cached = void 0;
|
|
126
|
+
});
|
|
127
|
+
return pending;
|
|
128
|
+
},
|
|
129
|
+
async discard() {
|
|
130
|
+
const pending = cached;
|
|
131
|
+
if (!pending) return;
|
|
132
|
+
cached = void 0;
|
|
133
|
+
const closing = bootChain.then(async () => {
|
|
134
|
+
const pg = await pending;
|
|
135
|
+
let timer;
|
|
136
|
+
try {
|
|
137
|
+
await Promise.race([pg.close(), new Promise((resolve) => {
|
|
138
|
+
timer = setTimeout(() => {
|
|
139
|
+
unusable = /* @__PURE__ */ new Error(`[${opts.label}] PGlite did not close within ${CLOSE_TIMEOUT_MS}ms; reload the page to reopen its store`);
|
|
140
|
+
console.warn(unusable.message);
|
|
141
|
+
resolve();
|
|
142
|
+
}, CLOSE_TIMEOUT_MS);
|
|
143
|
+
})]);
|
|
144
|
+
} finally {
|
|
145
|
+
clearTimeout(timer);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
bootChain = closing.catch(() => void 0);
|
|
149
|
+
try {
|
|
150
|
+
await closing;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error(`[${opts.label}] closing PGlite failed:`, error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
131
155
|
};
|
|
132
156
|
}
|
|
133
|
-
const
|
|
157
|
+
const reactorPGlite = pgliteSingleton({
|
|
134
158
|
dbName: REACTOR_PGLITE_NAME,
|
|
135
159
|
detectMajor: detectReactorPgMajor,
|
|
136
|
-
label: "reactor"
|
|
160
|
+
label: "reactor",
|
|
161
|
+
relaxedDurability: false
|
|
137
162
|
});
|
|
163
|
+
const getReactorPGlite = reactorPGlite.get;
|
|
164
|
+
const discardReactorPGlite = reactorPGlite.discard;
|
|
138
165
|
const getRelationalPGlite = pgliteSingleton({
|
|
139
166
|
dbName: RELATIONAL_PGLITE_NAME,
|
|
140
167
|
detectMajor: detectRelationalPgMajor,
|
|
141
|
-
label: "relational"
|
|
142
|
-
|
|
168
|
+
label: "relational",
|
|
169
|
+
relaxedDurability: true
|
|
170
|
+
}).get;
|
|
143
171
|
async function getDb() {
|
|
144
172
|
const pgLite = await getRelationalPGlite();
|
|
145
173
|
return {
|
|
146
174
|
pgLite,
|
|
147
|
-
relationalDb: createRelationalDb(new Kysely({ dialect: new
|
|
175
|
+
relationalDb: createRelationalDb(new Kysely({ dialect: new HardenedPGliteDialect(pgLite, { onPoisoned: reloadPageForPoisonedStore }) }))
|
|
148
176
|
};
|
|
149
177
|
}
|
|
150
178
|
//#endregion
|
|
@@ -153,20 +181,34 @@ async function getDb() {
|
|
|
153
181
|
* Creates a Reactor that plugs into legacy storage but syncs through the new
|
|
154
182
|
* Reactor GQL API.
|
|
155
183
|
*/
|
|
156
|
-
async function createBrowserReactor(documentModelModules, upgradeManifests, renown, featureFlags, documentModelLoader) {
|
|
157
|
-
const signerConfig =
|
|
158
|
-
signer: renown.signer,
|
|
159
|
-
verifier: createSignatureVerifier()
|
|
160
|
-
};
|
|
184
|
+
async function createBrowserReactor(documentModelModules, upgradeManifests, renown, featureFlags, documentModelLoader, createSignaturePolicy, renownEndpoints = {}, unsupportedStoredDocuments, multiReactor = false) {
|
|
185
|
+
const signerConfig = await createConnectSignerConfig(renown.signer, featureFlags, renownEndpoints);
|
|
161
186
|
const jwtHandler = async (_url) => {
|
|
162
187
|
if (!renown.user) return;
|
|
163
188
|
return renown.getBearerToken({ expiresIn: 10 });
|
|
164
189
|
};
|
|
165
190
|
const pg = await getReactorPGlite();
|
|
166
191
|
const logger = new ConsoleLogger(["reactor-client"]);
|
|
167
|
-
const
|
|
192
|
+
const reactorBuilder = new ReactorBuilder$1().withDocumentModelSources(documentModelModules).withUpgradeManifests(upgradeManifests).withExecutorConfig({ featureFlags }).withJwtHandler(jwtHandler).withGroupCommitPGlite({
|
|
193
|
+
pg,
|
|
194
|
+
onUnrecoverable: reloadPageForPoisonedStore,
|
|
195
|
+
onDiagnostic: (message, error) => console.error(`[reactor] pglite: ${message}`, error)
|
|
196
|
+
}).withStorageFacts(PGLITE_IDB_STORAGE_FACTS);
|
|
197
|
+
configureConnectChannelScheme(reactorBuilder, {
|
|
198
|
+
multiReactor,
|
|
199
|
+
createLocalChannelFactory: () => new LocalChannelFactory(logger, new LocalChannelPortRegistry({ logger }).provider)
|
|
200
|
+
});
|
|
201
|
+
const builder = new ReactorClientBuilder$1().withLogger(logger).withSigner(signerConfig).withReactorBuilder(reactorBuilder);
|
|
168
202
|
if (documentModelLoader) builder.withDocumentModelLoader(documentModelLoader);
|
|
169
|
-
|
|
203
|
+
if (createSignaturePolicy) builder.withCreateSignaturePolicy(createSignaturePolicy);
|
|
204
|
+
if (unsupportedStoredDocuments) reactorBuilder.withUnsupportedStoredDocuments(unsupportedStoredDocuments);
|
|
205
|
+
let module;
|
|
206
|
+
try {
|
|
207
|
+
module = await builder.buildModule();
|
|
208
|
+
} catch (error) {
|
|
209
|
+
await discardReactorPGlite();
|
|
210
|
+
throw toStoredDocumentsRefused(error);
|
|
211
|
+
}
|
|
170
212
|
return {
|
|
171
213
|
...module,
|
|
172
214
|
kind: "browser",
|
|
@@ -213,7 +255,7 @@ async function addRemoteDefaultDrive(drive) {
|
|
|
213
255
|
}
|
|
214
256
|
}
|
|
215
257
|
if (driveId && (drive.name || drive.icon)) try {
|
|
216
|
-
const reactorClient =
|
|
258
|
+
const reactorClient = getFullReactorClient();
|
|
217
259
|
if (reactorClient) await waitForDocumentReady(reactorClient, driveId, { timeoutMs: 15e3 });
|
|
218
260
|
await setDriveMetadata(driveId, {
|
|
219
261
|
name: drive.name,
|
|
@@ -237,7 +279,7 @@ async function addLocalDefaultDrive(drive) {
|
|
|
237
279
|
return;
|
|
238
280
|
}
|
|
239
281
|
try {
|
|
240
|
-
const reactorClient =
|
|
282
|
+
const reactorClient = getFullReactorClient();
|
|
241
283
|
if (reactorClient) {
|
|
242
284
|
if (await reactorClient.isDocumentIdTaken(drive.id)) return;
|
|
243
285
|
}
|
|
@@ -357,7 +399,7 @@ async function initFeatureFlags(searchParams) {
|
|
|
357
399
|
"error"
|
|
358
400
|
];
|
|
359
401
|
if (validLogLevels.includes(logLevelParam.toLowerCase())) {
|
|
360
|
-
setLogLevel
|
|
402
|
+
setLogLevel(logLevelParam.toLowerCase());
|
|
361
403
|
logger.info("Log level set to @level via query param", logLevelParam.toLowerCase());
|
|
362
404
|
} else logger.warn("Invalid LOG_LEVEL query param: @param. Valid values: @validLevels", logLevelParam, validLogLevels.join(", "));
|
|
363
405
|
}
|
|
@@ -683,341 +725,33 @@ var PackageDiscoveryService = class {
|
|
|
683
725
|
}
|
|
684
726
|
};
|
|
685
727
|
//#endregion
|
|
686
|
-
//#region src/
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
* package name. Mirrors `parsePackageSpec` on the UI side.
|
|
690
|
-
*/
|
|
691
|
-
function parseBareName(spec) {
|
|
692
|
-
const trimmed = spec.trim();
|
|
693
|
-
const at = trimmed.startsWith("@") ? trimmed.lastIndexOf("@") : trimmed.indexOf("@");
|
|
694
|
-
return at > 0 ? trimmed.slice(0, at) : trimmed;
|
|
695
|
-
}
|
|
696
|
-
async function fetchPackageJsonVersion(baseUrl) {
|
|
728
|
+
//#region src/reactor-worker-name.ts
|
|
729
|
+
const GEN_KEY_PREFIX = "ph-reactor-gen:";
|
|
730
|
+
function genStore() {
|
|
697
731
|
try {
|
|
698
|
-
|
|
699
|
-
if (!res.ok) return void 0;
|
|
700
|
-
const pkg = await res.json();
|
|
701
|
-
return typeof pkg.version === "string" ? pkg.version : void 0;
|
|
732
|
+
return globalThis.localStorage;
|
|
702
733
|
} catch {
|
|
703
734
|
return;
|
|
704
735
|
}
|
|
705
736
|
}
|
|
706
|
-
|
|
707
|
-
var BrowserPackageManager = class {
|
|
708
|
-
registryUrl;
|
|
709
|
-
#storage;
|
|
710
|
-
#packages = /* @__PURE__ */ new Map();
|
|
711
|
-
#subscribers = /* @__PURE__ */ new Set();
|
|
712
|
-
#packagesMemo = [];
|
|
713
|
-
#stylesheets = /* @__PURE__ */ new Map();
|
|
714
|
-
#localPackage;
|
|
715
|
-
#cdnUrl;
|
|
716
|
-
#localPackageVersion;
|
|
717
|
-
#localPackageNames = new Set([LOCAL_PACKAGE_NAME]);
|
|
718
|
-
#pwaSyncTimer;
|
|
719
|
-
/** Serialized last-mirrored PWA fragment; lets a sync skip the IndexedDB
|
|
720
|
-
* write + manifest re-attach when nothing PWA-relevant changed. */
|
|
721
|
-
#lastSyncedFragmentJson;
|
|
722
|
-
constructor(namespace, registryUrl) {
|
|
723
|
-
this.#storage = new BrowserLocalStorage(namespace + ":PH_PACKAGES");
|
|
724
|
-
this.registryUrl = registryUrl;
|
|
725
|
-
this.#cdnUrl = registryUrl !== null ? toCdnUrl(registryUrl) : null;
|
|
726
|
-
}
|
|
727
|
-
async init(localPackage, localPackageVersion, studioMode) {
|
|
728
|
-
this.addLocalPackage(common.manifest.name, common, commonPkg.version);
|
|
729
|
-
if (studioMode) {
|
|
730
|
-
const vetra = await import("@powerhousedao/vetra");
|
|
731
|
-
this.addLocalPackage(vetra.manifest.name, vetra, vetraPkg.version);
|
|
732
|
-
}
|
|
733
|
-
if (localPackage) this.updateLocalPackage(localPackage, localPackageVersion);
|
|
734
|
-
for (const packageName of this.#storage.keys()) {
|
|
735
|
-
const specForReload = this.#storage.get(packageName)?.spec ?? packageName;
|
|
736
|
-
console.debug(`[Connect][PackageManager] Rehydrating "${packageName}" via spec "${specForReload}"`);
|
|
737
|
-
if ((await this.addPackage(specForReload)).type === "error") this.#storage.delete(packageName);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
addLocalPackage(name, loadedPackage, version) {
|
|
741
|
-
this.#localPackageNames.add(name);
|
|
742
|
-
this.#registerPackage({
|
|
743
|
-
name,
|
|
744
|
-
importUrl: null,
|
|
745
|
-
stylesheetUrl: null,
|
|
746
|
-
loadedPackage,
|
|
747
|
-
version
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
updateLocalPackage(pkg, version) {
|
|
751
|
-
console.debug("Updating local package:", pkg);
|
|
752
|
-
this.#localPackage = pkg;
|
|
753
|
-
this.#registerPackage({
|
|
754
|
-
name: LOCAL_PACKAGE_NAME,
|
|
755
|
-
stylesheetUrl: null,
|
|
756
|
-
importUrl: null,
|
|
757
|
-
loadedPackage: pkg
|
|
758
|
-
});
|
|
759
|
-
if (version) {
|
|
760
|
-
this.#localPackageVersion = version;
|
|
761
|
-
this.#notifyPackagesChanged();
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
fetchPackageJsonVersion("/package.json").then((fetchedVersion) => {
|
|
765
|
-
this.#localPackageVersion = fetchedVersion;
|
|
766
|
-
if (fetchedVersion) this.#notifyPackagesChanged();
|
|
767
|
-
}).catch(() => {});
|
|
768
|
-
}
|
|
769
|
-
get packages() {
|
|
770
|
-
return this.#packagesMemo;
|
|
771
|
-
}
|
|
772
|
-
get cdnUrl() {
|
|
773
|
-
return this.#cdnUrl;
|
|
774
|
-
}
|
|
775
|
-
getPackageSource(packageName) {
|
|
776
|
-
if (this.#localPackageNames.has(packageName)) return "common";
|
|
777
|
-
if (packageName === this.#localPackage?.manifest.name) return "project";
|
|
778
|
-
const packageMeta = this.#storage.get(packageName);
|
|
779
|
-
if (!packageMeta) return null;
|
|
780
|
-
if (packageMeta.importUrl === `/node_modules/${packageName}`) return "local-install";
|
|
781
|
-
return "registry-install";
|
|
782
|
-
}
|
|
783
|
-
/**
|
|
784
|
-
* Return the registry-installed packages keyed by their storage name (which
|
|
785
|
-
* is the registry spec, e.g. "@powerhousedao/clint-common"), with the
|
|
786
|
-
* installed version when known. Excludes bundled (common) packages, the
|
|
787
|
-
* local project package, and packages resolved out of `/node_modules/`.
|
|
788
|
-
*/
|
|
789
|
-
getRegistryPackages() {
|
|
790
|
-
const out = [];
|
|
791
|
-
for (const [name, meta] of this.#storage) {
|
|
792
|
-
if (this.#localPackageNames.has(name)) continue;
|
|
793
|
-
if (name === LOCAL_PACKAGE_NAME) continue;
|
|
794
|
-
if (meta.importUrl === `/node_modules/${name}`) continue;
|
|
795
|
-
out.push({
|
|
796
|
-
name,
|
|
797
|
-
version: meta.version
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
return out;
|
|
801
|
-
}
|
|
802
|
-
getPackageVersion(packageName) {
|
|
803
|
-
if (packageName === this.#localPackage?.manifest.name) return this.#localPackageVersion;
|
|
804
|
-
return this.#storage.get(packageName)?.version;
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* The spec the user requested when this package was installed (e.g.
|
|
808
|
-
* `name@dev` or `name@6.2.1`). Undefined for bare-name installs, legacy
|
|
809
|
-
* entries, and local packages — the Package Manager treats that as the
|
|
810
|
-
* `latest` stream when picking update targets.
|
|
811
|
-
*/
|
|
812
|
-
getPackageSpec(packageName) {
|
|
813
|
-
return this.#storage.get(packageName)?.spec;
|
|
814
|
-
}
|
|
815
|
-
async addPackage(packageSpec) {
|
|
816
|
-
const bareName = parseBareName(packageSpec);
|
|
817
|
-
const hasTagOrVersion = bareName !== packageSpec;
|
|
818
|
-
console.debug(`[Connect][PackageManager] addPackage spec="${packageSpec}" bareName="${bareName}"`);
|
|
819
|
-
const existingPackage = this.#packages.get(bareName);
|
|
820
|
-
if (existingPackage) {
|
|
821
|
-
const requestedVersion = hasTagOrVersion ? packageSpec.slice(bareName.length + 1) : void 0;
|
|
822
|
-
const currentVersion = this.#storage.get(bareName)?.version;
|
|
823
|
-
if (this.#localPackageNames.has(bareName) || !requestedVersion || !currentVersion || requestedVersion === currentVersion) {
|
|
824
|
-
console.debug(`[Connect][PackageManager] "${bareName}" already loaded; skipping re-fetch`);
|
|
825
|
-
return {
|
|
826
|
-
type: "success",
|
|
827
|
-
package: existingPackage
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
console.debug(`[Connect][PackageManager] "${bareName}" version bump ${currentVersion} → ${requestedVersion}; refetching`);
|
|
831
|
-
}
|
|
832
|
-
try {
|
|
833
|
-
const packageWithMeta = await this.#loadPackage(packageSpec);
|
|
834
|
-
packageWithMeta.name = bareName;
|
|
835
|
-
if (hasTagOrVersion) packageWithMeta.spec = packageSpec;
|
|
836
|
-
if (existingPackage) this.#unmountStylesheet(bareName);
|
|
837
|
-
this.#registerPackage(packageWithMeta);
|
|
838
|
-
return {
|
|
839
|
-
type: "success",
|
|
840
|
-
package: packageWithMeta.loadedPackage
|
|
841
|
-
};
|
|
842
|
-
} catch (error) {
|
|
843
|
-
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
844
|
-
console.error(`[Connect][PackageManager] Failed to install package "${packageSpec}": ${normalized.message}`, normalized);
|
|
845
|
-
return {
|
|
846
|
-
type: "error",
|
|
847
|
-
error: normalized
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
async addPackages(packageNames) {
|
|
852
|
-
const results = [];
|
|
853
|
-
for (const packageName of packageNames) {
|
|
854
|
-
const result = await this.addPackage(packageName);
|
|
855
|
-
results.push(result);
|
|
856
|
-
}
|
|
857
|
-
return results;
|
|
858
|
-
}
|
|
859
|
-
removePackage(name) {
|
|
860
|
-
this.#packages.delete(name);
|
|
861
|
-
this.#storage.delete(name);
|
|
862
|
-
this.#unmountStylesheet(name);
|
|
863
|
-
this.#notifyPackagesChanged();
|
|
864
|
-
}
|
|
865
|
-
subscribe(handler) {
|
|
866
|
-
this.#subscribers.add(handler);
|
|
867
|
-
return () => {
|
|
868
|
-
this.#subscribers.delete(handler);
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
load(documentType) {
|
|
872
|
-
const documentModelModule = Array.from(this.#packages.values().flatMap((p) => p.documentModels)).find((m) => m.documentModel.global.id === documentType);
|
|
873
|
-
if (documentModelModule) return Promise.resolve(documentModelModule);
|
|
874
|
-
return Promise.reject(/* @__PURE__ */ new Error("Model not available"));
|
|
875
|
-
}
|
|
876
|
-
async #loadPackageFromNodeModules(name) {
|
|
877
|
-
const importUrl = `/node_modules/${name}/browser/index.js`;
|
|
878
|
-
const stylesheetUrl = `/node_modules/${name}/style.css`;
|
|
879
|
-
const packageWithMeta = await this.#importPackage({
|
|
880
|
-
name,
|
|
881
|
-
importUrl,
|
|
882
|
-
stylesheetUrl
|
|
883
|
-
});
|
|
884
|
-
packageWithMeta.version = await fetchPackageJsonVersion(`/node_modules/${name}/package.json`);
|
|
885
|
-
return packageWithMeta;
|
|
886
|
-
}
|
|
887
|
-
async #loadPackageFromRegistry(name) {
|
|
888
|
-
const importUrl = `${this.#cdnUrl}/${name}/browser/index.js`;
|
|
889
|
-
const stylesheetUrl = `${this.#cdnUrl}/${name}/style.css`;
|
|
890
|
-
const packageWithMeta = await this.#importPackage({
|
|
891
|
-
name,
|
|
892
|
-
importUrl,
|
|
893
|
-
stylesheetUrl
|
|
894
|
-
});
|
|
895
|
-
packageWithMeta.version = await fetchPackageJsonVersion(`${this.#cdnUrl}/${name}/package.json`);
|
|
896
|
-
return packageWithMeta;
|
|
897
|
-
}
|
|
898
|
-
async #importPackage(packageMeta) {
|
|
899
|
-
const { name, importUrl, stylesheetUrl } = packageMeta;
|
|
900
|
-
if (!importUrl) throw new Error(`Import url not defined for package "${name}".`);
|
|
901
|
-
return {
|
|
902
|
-
name,
|
|
903
|
-
loadedPackage: await import(
|
|
904
|
-
/* @vite-ignore */
|
|
905
|
-
importUrl
|
|
906
|
-
),
|
|
907
|
-
importUrl,
|
|
908
|
-
stylesheetUrl
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
async #loadPackage(packageName) {
|
|
912
|
-
if (this.#localPackageNames.has(packageName)) throw new Error(`Package "${packageName}" is a local package and cannot be loaded dynamically.`);
|
|
913
|
-
if (!import.meta.env.PROD) try {
|
|
914
|
-
return await this.#loadPackageFromNodeModules(packageName);
|
|
915
|
-
} catch (error) {
|
|
916
|
-
console.warn(`Failed to load package "${packageName}" from node_modules:`, error);
|
|
917
|
-
}
|
|
918
|
-
if (!this.registryUrl) throw new Error("Registry url not defined.");
|
|
919
|
-
return await this.#loadPackageFromRegistry(packageName);
|
|
920
|
-
}
|
|
921
|
-
#registerPackage(packageWithMeta) {
|
|
922
|
-
const { name, loadedPackage, importUrl, stylesheetUrl, version, spec } = packageWithMeta;
|
|
923
|
-
if (stylesheetUrl !== null) this.#mountStylesheet(name, stylesheetUrl);
|
|
924
|
-
this.#packages.set(name, loadedPackage);
|
|
925
|
-
this.#storage.set(name, {
|
|
926
|
-
name,
|
|
927
|
-
importUrl,
|
|
928
|
-
stylesheetUrl,
|
|
929
|
-
version,
|
|
930
|
-
...spec ? { spec } : {}
|
|
931
|
-
});
|
|
932
|
-
console.debug(`[Connect][PackageManager] Registered "${name}" (version=${version ?? "?"}, spec=${spec ?? "—"})`);
|
|
933
|
-
this.#notifyPackagesChanged();
|
|
934
|
-
}
|
|
935
|
-
#mountStylesheet(name, href) {
|
|
936
|
-
const existing = this.#stylesheets.get(name);
|
|
937
|
-
if (existing) return existing;
|
|
938
|
-
const style = document.createElement("style");
|
|
939
|
-
style.textContent = `@import url("${href}") layer(external-packages);`;
|
|
940
|
-
document.head.appendChild(style);
|
|
941
|
-
this.#stylesheets.set(name, style);
|
|
942
|
-
}
|
|
943
|
-
#unmountStylesheet(name) {
|
|
944
|
-
const style = this.#stylesheets.get(name);
|
|
945
|
-
if (!style) return;
|
|
946
|
-
style.remove();
|
|
947
|
-
this.#stylesheets.delete(name);
|
|
948
|
-
}
|
|
949
|
-
#notifyPackagesChanged() {
|
|
950
|
-
this.#packagesMemo = Array.from(this.#packages.values());
|
|
951
|
-
const packages = this.packages;
|
|
952
|
-
this.#subscribers.forEach((handler) => {
|
|
953
|
-
handler({ packages });
|
|
954
|
-
});
|
|
955
|
-
this.#schedulePwaSync();
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Debounced mirror of every loaded package's PWA fragment into IndexedDB, so
|
|
959
|
-
* the service worker can serve a web-app manifest that reflects packages
|
|
960
|
-
* installed AT RUNTIME (a SW can't read localStorage, where the package list
|
|
961
|
-
* lives). Debounced because `init()` rehydrates many packages in a burst;
|
|
962
|
-
* coalescing collapses that into a single write.
|
|
963
|
-
*/
|
|
964
|
-
#schedulePwaSync() {
|
|
965
|
-
if (typeof indexedDB === "undefined") return;
|
|
966
|
-
clearTimeout(this.#pwaSyncTimer);
|
|
967
|
-
this.#pwaSyncTimer = setTimeout(() => {
|
|
968
|
-
this.#syncPwaFragments();
|
|
969
|
-
}, 50);
|
|
970
|
-
}
|
|
971
|
-
async #syncPwaFragments() {
|
|
972
|
-
const contributions = [];
|
|
973
|
-
for (const [name, loadedPackage] of this.#packages) {
|
|
974
|
-
const manifest = loadedPackage.manifest;
|
|
975
|
-
let config = {};
|
|
976
|
-
if (manifest.pwa) {
|
|
977
|
-
const parsed = PwaConfigSchema.safeParse(manifest.pwa);
|
|
978
|
-
if (parsed.success) {
|
|
979
|
-
const importUrl = this.#storage.get(name)?.importUrl ?? null;
|
|
980
|
-
const baseUrl = importUrl ? importUrl.replace(/browser\/index\.js$/, "") : null;
|
|
981
|
-
config = resolveFragmentAssetUrls(parsed.data, baseUrl);
|
|
982
|
-
} else console.warn(`[Connect][PWA] "${name}" ships an invalid pwa fragment; skipped.`, parsed.error);
|
|
983
|
-
}
|
|
984
|
-
config = withInferredCategory(config, manifest.category);
|
|
985
|
-
if (Object.keys(config).length === 0) continue;
|
|
986
|
-
contributions.push({
|
|
987
|
-
source: name,
|
|
988
|
-
config
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
const merged = mergePwaConfig(contributions);
|
|
992
|
-
const mergedJson = JSON.stringify(merged);
|
|
993
|
-
if (mergedJson === this.#lastSyncedFragmentJson) return;
|
|
994
|
-
try {
|
|
995
|
-
await writeMergedPwaFragment(merged);
|
|
996
|
-
} catch (error) {
|
|
997
|
-
console.debug("[Connect][PWA] fragment mirror to IndexedDB failed:", error);
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
|
-
this.#lastSyncedFragmentJson = mergedJson;
|
|
1001
|
-
refreshPwaManifestLink();
|
|
1002
|
-
}
|
|
1003
|
-
};
|
|
1004
|
-
//#endregion
|
|
1005
|
-
//#region src/reactor-worker-name.ts
|
|
1006
|
-
const GEN_KEY_PREFIX = "ph-reactor-gen:";
|
|
1007
|
-
function reactorWorkerName(namespace) {
|
|
1008
|
-
const gen = readWorkerGen(namespace);
|
|
737
|
+
function workerNameForGen(namespace, gen) {
|
|
1009
738
|
return gen ? `ph-reactor:${namespace}#${gen}` : `ph-reactor:${namespace}`;
|
|
1010
739
|
}
|
|
1011
|
-
function readWorkerGen(namespace) {
|
|
740
|
+
function readWorkerGen(namespace, storage = genStore()) {
|
|
1012
741
|
try {
|
|
1013
|
-
return
|
|
742
|
+
return storage?.getItem(GEN_KEY_PREFIX + namespace) ?? null;
|
|
1014
743
|
} catch {
|
|
1015
744
|
return null;
|
|
1016
745
|
}
|
|
1017
746
|
}
|
|
1018
|
-
|
|
747
|
+
/**
|
|
748
|
+
* Gens are unordered tokens, so a reload moves the gen on only from the one
|
|
749
|
+
* this tab's worker runs as; a stale worker's reload never undoes a newer one.
|
|
750
|
+
*/
|
|
751
|
+
function adoptWorkerGen(namespace, from, to, storage = genStore()) {
|
|
1019
752
|
try {
|
|
1020
|
-
|
|
753
|
+
if (storage?.getItem(GEN_KEY_PREFIX + namespace) !== from) return;
|
|
754
|
+
storage.setItem(GEN_KEY_PREFIX + namespace, to);
|
|
1021
755
|
} catch {}
|
|
1022
756
|
}
|
|
1023
757
|
//#endregion
|
|
@@ -1026,8 +760,44 @@ const PING_INTERVAL_MS = 2e3;
|
|
|
1026
760
|
const PING_DEADLINE_MS = 3e3;
|
|
1027
761
|
const MAX_MISSED_PINGS = 2;
|
|
1028
762
|
/** Sorted so the same set always produces the same fingerprint. */
|
|
1029
|
-
function enabledFlagList(flags) {
|
|
1030
|
-
return Object.entries(
|
|
763
|
+
function enabledFlagList(flags, multiReactor) {
|
|
764
|
+
return Object.entries({
|
|
765
|
+
...flags,
|
|
766
|
+
multiReactor
|
|
767
|
+
}).filter(([, enabled]) => enabled).map(([name]) => name).sort().join(",");
|
|
768
|
+
}
|
|
769
|
+
/** The hello fingerprint; a running worker with a different one retires. */
|
|
770
|
+
function buildWorkerVersion(args) {
|
|
771
|
+
const gitSha = getGitSha();
|
|
772
|
+
const buildId = gitSha !== "unknown" ? gitSha : getVersion();
|
|
773
|
+
return {
|
|
774
|
+
appBuildId: args.workerDigest ? `${buildId}+w.${args.workerDigest}` : buildId,
|
|
775
|
+
rpcProtocolVersion: RPC_PROTOCOL_VERSION,
|
|
776
|
+
models: args.documentModelModules.map((m) => ({
|
|
777
|
+
id: m.documentModel.global.id,
|
|
778
|
+
version: m.version ?? 1
|
|
779
|
+
})),
|
|
780
|
+
featureFlags: enabledFlagList(args.featureFlags, args.multiReactor)
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
/** What the worker's build reads; flags arrive here because it has no config. */
|
|
784
|
+
function buildWorkerConstruct(args) {
|
|
785
|
+
return {
|
|
786
|
+
namespace: args.namespace,
|
|
787
|
+
relationalNamespace: args.relationalNamespace,
|
|
788
|
+
cdnUrl: args.cdnUrl,
|
|
789
|
+
packageSpecs: args.packageSpecs,
|
|
790
|
+
sharedImports: args.sharedImports,
|
|
791
|
+
studioMode: args.studioMode,
|
|
792
|
+
workflowsEnabled: args.workflowsEnabled,
|
|
793
|
+
renownChainId: args.renownChainId,
|
|
794
|
+
featureFlags: args.featureFlags,
|
|
795
|
+
multiReactor: args.multiReactor,
|
|
796
|
+
createSignaturePolicy: args.createSignaturePolicy,
|
|
797
|
+
unsupportedStoredDocuments: args.unsupportedStoredDocuments,
|
|
798
|
+
renownEndpoints: args.renownEndpoints,
|
|
799
|
+
packageSources: args.packageSources
|
|
800
|
+
};
|
|
1031
801
|
}
|
|
1032
802
|
function toReactorIdentity(user) {
|
|
1033
803
|
if (!user) return null;
|
|
@@ -1038,14 +808,17 @@ function toReactorIdentity(user) {
|
|
|
1038
808
|
};
|
|
1039
809
|
}
|
|
1040
810
|
function createWorkerReactorClientModule(args) {
|
|
1041
|
-
const workerUrl = new URL("./reactor.worker.js", import.meta.url);
|
|
1042
|
-
|
|
811
|
+
const workerUrl = args.workerUrl ? new URL(args.workerUrl) : new URL("./reactor.worker.js", import.meta.url);
|
|
812
|
+
const workerGen = readWorkerGen(args.namespace);
|
|
813
|
+
const workerName = workerNameForGen(args.namespace, workerGen);
|
|
814
|
+
console.info(`[reactor-worker] constructing SharedWorker ${workerName} from ${workerUrl.href}`);
|
|
1043
815
|
const worker = new SharedWorker(workerUrl, {
|
|
1044
|
-
name:
|
|
816
|
+
name: workerName,
|
|
1045
817
|
type: "module"
|
|
1046
818
|
});
|
|
1047
819
|
worker.addEventListener("error", (event) => {
|
|
1048
820
|
console.error(`[reactor-worker] SharedWorker failed to load from ${workerUrl.href}`, event.message || event);
|
|
821
|
+
setWorkerConnectionStatus("failed");
|
|
1049
822
|
});
|
|
1050
823
|
worker.port.onmessageerror = (event) => {
|
|
1051
824
|
console.error("[reactor-worker] port message could not be deserialized", event);
|
|
@@ -1056,28 +829,14 @@ function createWorkerReactorClientModule(args) {
|
|
|
1056
829
|
const documentModelRegistry = new DocumentModelRegistry();
|
|
1057
830
|
documentModelRegistry.registerModules(...args.documentModelModules);
|
|
1058
831
|
documentModelRegistry.registerUpgradeManifests(...args.upgradeManifests);
|
|
1059
|
-
const gitSha = getGitSha();
|
|
1060
832
|
const clientProxy = connectReactorClient(router, {
|
|
1061
|
-
version:
|
|
1062
|
-
|
|
1063
|
-
rpcProtocolVersion: RPC_PROTOCOL_VERSION,
|
|
1064
|
-
models: args.documentModelModules.map((m) => ({
|
|
1065
|
-
id: m.documentModel.global.id,
|
|
1066
|
-
version: m.version ?? 1
|
|
1067
|
-
})),
|
|
1068
|
-
featureFlags: enabledFlagList(args.featureFlags)
|
|
1069
|
-
},
|
|
1070
|
-
construct: {
|
|
1071
|
-
namespace: args.namespace,
|
|
1072
|
-
relationalNamespace: args.relationalNamespace,
|
|
1073
|
-
cdnUrl: args.cdnUrl,
|
|
1074
|
-
packageSpecs: args.packageSpecs,
|
|
1075
|
-
studioMode: args.studioMode,
|
|
1076
|
-
renownChainId: args.renownChainId,
|
|
1077
|
-
featureFlags: args.featureFlags
|
|
1078
|
-
},
|
|
833
|
+
version: buildWorkerVersion(args),
|
|
834
|
+
construct: buildWorkerConstruct(args),
|
|
1079
835
|
packages: args.packageSpecs
|
|
1080
|
-
},
|
|
836
|
+
}, (reason, nextGen) => {
|
|
837
|
+
if (nextGen) adoptWorkerGen(args.namespace, workerGen, nextGen);
|
|
838
|
+
args.onReload(reason);
|
|
839
|
+
}, documentModelRegistry);
|
|
1081
840
|
const busProxy = createReactorEventBusProxy(router);
|
|
1082
841
|
const syncManagerProxy = new SyncManagerProxy(router, busProxy);
|
|
1083
842
|
const modelResolver = new DocumentModelResolver(documentModelRegistry, args.documentModelLoader);
|
|
@@ -1099,6 +858,14 @@ function createWorkerReactorClientModule(args) {
|
|
|
1099
858
|
client: clientProxy,
|
|
1100
859
|
adminClient: createWorkerAdminClient(router),
|
|
1101
860
|
inspector: createInspectorProxy(router),
|
|
861
|
+
registerPackages: async (sources) => {
|
|
862
|
+
await router.request((id) => ({
|
|
863
|
+
k: "register-packages",
|
|
864
|
+
id,
|
|
865
|
+
specs: [],
|
|
866
|
+
sources
|
|
867
|
+
}));
|
|
868
|
+
},
|
|
1102
869
|
reactorModule: {
|
|
1103
870
|
documentModelRegistry,
|
|
1104
871
|
syncModule: { syncManager: syncManagerProxy },
|
|
@@ -1121,7 +888,7 @@ function createWorkerReactorClientModule(args) {
|
|
|
1121
888
|
const timer = setTimeout(() => {
|
|
1122
889
|
pingDeadlines.delete(id);
|
|
1123
890
|
missedPings += 1;
|
|
1124
|
-
if (missedPings >= MAX_MISSED_PINGS) setWorkerConnectionStatus("lost");
|
|
891
|
+
if (missedPings >= MAX_MISSED_PINGS && getWorkerConnectionStatus() !== "failed") setWorkerConnectionStatus("lost");
|
|
1125
892
|
}, PING_DEADLINE_MS);
|
|
1126
893
|
pingDeadlines.set(id, timer);
|
|
1127
894
|
router.post({
|
|
@@ -1141,33 +908,289 @@ function createWorkerReactorClientModule(args) {
|
|
|
1141
908
|
};
|
|
1142
909
|
}
|
|
1143
910
|
//#endregion
|
|
911
|
+
//#region src/utils/deleted-selection.ts
|
|
912
|
+
/** Closes the drive or document a Deleted event removed, saying why. */
|
|
913
|
+
function closeDeletedSelection(event, host) {
|
|
914
|
+
if (event.type !== DocumentChangeType.Deleted) return;
|
|
915
|
+
const deletedId = event.context?.childId;
|
|
916
|
+
if (!deletedId) return;
|
|
917
|
+
const gone = event.context?.purged ? "has been erased" : "has been deleted";
|
|
918
|
+
if (host.selectedDriveId && deletedId === host.selectedDriveId) {
|
|
919
|
+
host.closeDrive();
|
|
920
|
+
host.notify(`The drive you were viewing ${gone}`);
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
if (host.selectedNodeId && deletedId === host.selectedNodeId) {
|
|
924
|
+
host.closeNode();
|
|
925
|
+
host.notify(`The document you were editing ${gone}`);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
//#endregion
|
|
929
|
+
//#region src/utils/worker-startup.ts
|
|
930
|
+
/** Runs the worker's startup seed, showing storage-held while its stores are locked elsewhere. */
|
|
931
|
+
async function startupOwningStores(startup, namespaces, watchOptions) {
|
|
932
|
+
const stopWatching = watchStoreLockWait(namespaces, (waiting) => waiting ? setWorkerConnectionStatus("storage-held") : clearStorageHeld(), watchOptions);
|
|
933
|
+
try {
|
|
934
|
+
await startup({ isWaiting: () => getWorkerConnectionStatus() === "storage-held" });
|
|
935
|
+
clearStorageHeld();
|
|
936
|
+
} finally {
|
|
937
|
+
stopWatching();
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
//#endregion
|
|
1144
941
|
//#region src/utils/reactor-worker-flag.ts
|
|
1145
942
|
const REACTOR_WORKER_QUERY_KEY = "reactorWorker";
|
|
1146
943
|
const REACTOR_WORKER_STORAGE_KEY = "ph:reactorWorker";
|
|
1147
|
-
function resolveReactorWorkerEnabled(input) {
|
|
1148
|
-
const fromQuery = parseFlag(input.queryParam);
|
|
1149
|
-
if (fromQuery !== void 0) return fromQuery;
|
|
1150
|
-
const fromStore = parseFlag(input.storedValue);
|
|
1151
|
-
if (fromStore !== void 0) return fromStore;
|
|
1152
|
-
return input.configFlag;
|
|
1153
|
-
}
|
|
1154
944
|
function isReactorWorkerEnabled() {
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
945
|
+
return isRuntimeFlagEnabled({
|
|
946
|
+
queryKey: REACTOR_WORKER_QUERY_KEY,
|
|
947
|
+
storageKey: REACTOR_WORKER_STORAGE_KEY,
|
|
948
|
+
readConfigFlag: () => getRuntimeConfig().connect.instance?.reactorWorker ?? false
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
//#endregion
|
|
952
|
+
//#region src/utils/multi-reactor-flag.ts
|
|
953
|
+
function isMultiReactorEnabled() {
|
|
954
|
+
return getRuntimeConfig().connect.instance?.multiReactor ?? false;
|
|
955
|
+
}
|
|
956
|
+
//#endregion
|
|
957
|
+
//#region src/store/reactor-client-mode.ts
|
|
958
|
+
const MODES = /* @__PURE__ */ new Set([
|
|
959
|
+
"in-process",
|
|
960
|
+
"worker",
|
|
961
|
+
"remote",
|
|
962
|
+
"router"
|
|
963
|
+
]);
|
|
964
|
+
function fromQuery() {
|
|
965
|
+
if (typeof window === "undefined") return void 0;
|
|
966
|
+
try {
|
|
967
|
+
const value = new URLSearchParams(window.location.search).get("reactorClient");
|
|
968
|
+
return value && MODES.has(value) ? value : void 0;
|
|
969
|
+
} catch {
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
function resolveReactorClientMode() {
|
|
974
|
+
const override = fromQuery();
|
|
975
|
+
if (override) return override;
|
|
976
|
+
const configured = getRuntimeConfig().connect.instance?.reactorClient;
|
|
977
|
+
if (configured && MODES.has(configured)) return configured;
|
|
978
|
+
if (isMultiReactorEnabled()) return "router";
|
|
979
|
+
if (isReactorWorkerEnabled()) return "worker";
|
|
980
|
+
return "in-process";
|
|
981
|
+
}
|
|
982
|
+
//#endregion
|
|
983
|
+
//#region src/utils/reactor-worker-url.ts
|
|
984
|
+
/**
|
|
985
|
+
* Stable path of the prebuilt reactor SharedWorker bundle, relative to the
|
|
986
|
+
* deploy base. `ph connect build` emits it next to `__vendor__/`; the dev
|
|
987
|
+
* server serves it from the same path, building lazily on first request.
|
|
988
|
+
*/
|
|
989
|
+
const REACTOR_WORKER_BUNDLE_PATH = "__reactor_worker__/reactor.worker.js";
|
|
990
|
+
/** Written beside the bundle by the prebuild; carries its `sourceDigest`. */
|
|
991
|
+
const REACTOR_WORKER_META_PATH = "__reactor_worker__/worker-meta.json";
|
|
992
|
+
/** `path` under the deploy base, absolute against `origin`. */
|
|
993
|
+
function joinBase(baseUrl, path, origin) {
|
|
994
|
+
return new URL(`${baseUrl}/${path}`.replace(/\/{2,}/g, "/"), origin);
|
|
995
|
+
}
|
|
996
|
+
/** The bundle's URL under the deploy base, absolute against the page origin. */
|
|
997
|
+
function packagedReactorWorkerUrl(baseUrl, origin) {
|
|
998
|
+
return joinBase(baseUrl, REACTOR_WORKER_BUNDLE_PATH, origin);
|
|
999
|
+
}
|
|
1000
|
+
function isWorkerBundleResponse(probe) {
|
|
1001
|
+
return probe.ok && (probe.contentType ?? "").includes("javascript");
|
|
1002
|
+
}
|
|
1003
|
+
/** Null when the deployment serves no bundle metadata (SPA HTML, error status, bad JSON). */
|
|
1004
|
+
async function resolvePackagedReactorWorker(baseUrl) {
|
|
1005
|
+
const origin = window.location.origin;
|
|
1006
|
+
try {
|
|
1007
|
+
const res = await fetch(joinBase(baseUrl, REACTOR_WORKER_META_PATH, origin), { cache: "no-cache" });
|
|
1008
|
+
if (!res.ok || !(res.headers.get("content-type") ?? "").includes("json")) return null;
|
|
1009
|
+
const meta = await res.json();
|
|
1010
|
+
if (typeof meta?.sourceDigest !== "string") return null;
|
|
1011
|
+
return {
|
|
1012
|
+
url: packagedReactorWorkerUrl(baseUrl, origin).href,
|
|
1013
|
+
sourceDigest: meta.sourceDigest
|
|
1014
|
+
};
|
|
1015
|
+
} catch {
|
|
1016
|
+
return null;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
function selectReactorWorkerSource({ packaged, bundle }) {
|
|
1020
|
+
if (bundle) return {
|
|
1021
|
+
kind: "bundle",
|
|
1022
|
+
url: bundle.url,
|
|
1023
|
+
digest: bundle.sourceDigest
|
|
1024
|
+
};
|
|
1025
|
+
return packaged ? { kind: "unavailable" } : { kind: "source" };
|
|
1026
|
+
}
|
|
1027
|
+
//#endregion
|
|
1028
|
+
//#region src/utils/worker-package-sources.ts
|
|
1029
|
+
/**
|
|
1030
|
+
* Where `ph connect build` publishes the prebuilt local-package model bundles
|
|
1031
|
+
* and the manifest naming them, next to the worker bundle itself.
|
|
1032
|
+
*/
|
|
1033
|
+
const WORKER_PACKAGES_DIR = "__reactor_worker__/packages/";
|
|
1034
|
+
const WORKER_PACKAGES_MANIFEST = `${WORKER_PACKAGES_DIR}manifest.json`;
|
|
1035
|
+
/**
|
|
1036
|
+
* The project's own models entry as the dev server serves it. Vite's
|
|
1037
|
+
* transform pipeline absolutizes its chunk imports and rewrites bare
|
|
1038
|
+
* specifiers to /node_modules/.vite/deps/ URLs, so the result is directly
|
|
1039
|
+
* importable from a worker - the dev server is the bundler.
|
|
1040
|
+
*/
|
|
1041
|
+
const DEV_PROJECT_MODELS_PATH = "dist/browser/document-models/index.js";
|
|
1042
|
+
/** Source name for the project's own package (vetra's local package). */
|
|
1043
|
+
const PROJECT_PACKAGE_SOURCE_NAME = "ph:project-package";
|
|
1044
|
+
async function probeJavaScript(url) {
|
|
1045
|
+
try {
|
|
1046
|
+
const res = await fetch(url, { method: "HEAD" });
|
|
1047
|
+
return isWorkerBundleResponse({
|
|
1048
|
+
ok: res.ok,
|
|
1049
|
+
contentType: res.headers.get("content-type")
|
|
1050
|
+
});
|
|
1051
|
+
} catch {
|
|
1052
|
+
return false;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
async function fetchManifest(baseUrl) {
|
|
1056
|
+
try {
|
|
1057
|
+
const res = await fetch(joinBase(baseUrl, WORKER_PACKAGES_MANIFEST, window.location.origin));
|
|
1058
|
+
if (!res.ok) return [];
|
|
1059
|
+
const parsed = await res.json();
|
|
1060
|
+
if (!Array.isArray(parsed)) return [];
|
|
1061
|
+
return parsed.filter((entry) => typeof entry === "object" && entry !== null && typeof entry.name === "string" && typeof entry.file === "string");
|
|
1062
|
+
} catch {
|
|
1063
|
+
return [];
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* The project's models source as served right now, with a cache-busting query
|
|
1068
|
+
* so a watch rebuild's re-registration imports the fresh file rather than the
|
|
1069
|
+
* worker's cached module. Null when the dev server does not serve one.
|
|
1070
|
+
*/
|
|
1071
|
+
async function resolveDevProjectSource(baseUrl) {
|
|
1072
|
+
const url = joinBase(baseUrl, DEV_PROJECT_MODELS_PATH, window.location.origin);
|
|
1073
|
+
if (!await probeJavaScript(url)) return null;
|
|
1074
|
+
url.searchParams.set("t", String(Date.now()));
|
|
1075
|
+
return {
|
|
1076
|
+
name: PROJECT_PACKAGE_SOURCE_NAME,
|
|
1077
|
+
url: url.href
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* URL-addressed packages the worker should load: the production manifest's
|
|
1082
|
+
* prebuilt bundles when deployed, plus the dev server's live project models
|
|
1083
|
+
* when present. Either list may be empty; both empty means this deployment
|
|
1084
|
+
* has no local packages (or predates the feature).
|
|
1085
|
+
*/
|
|
1086
|
+
async function resolveLocalPackageSources(baseUrl) {
|
|
1087
|
+
const [manifest, devProject] = await Promise.all([fetchManifest(baseUrl), resolveDevProjectSource(baseUrl)]);
|
|
1088
|
+
const sources = manifest.map((entry) => ({
|
|
1089
|
+
name: entry.name,
|
|
1090
|
+
version: entry.version,
|
|
1091
|
+
url: joinBase(baseUrl, `${WORKER_PACKAGES_DIR}${entry.file}`, window.location.origin).href
|
|
1092
|
+
}));
|
|
1093
|
+
if (devProject) sources.push(devProject);
|
|
1094
|
+
return sources;
|
|
1095
|
+
}
|
|
1096
|
+
/** Calls `onChange` only when the local package is replaced (an HMR rebuild), not on every package notification. */
|
|
1097
|
+
function subscribeLocalPackageChanges(manager, onChange) {
|
|
1098
|
+
let last = manager.localPackage;
|
|
1099
|
+
return manager.subscribe(() => {
|
|
1100
|
+
const current = manager.localPackage;
|
|
1101
|
+
if (current === last) return;
|
|
1102
|
+
last = current;
|
|
1103
|
+
onChange();
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
//#endregion
|
|
1107
|
+
//#region src/store/app-reactor-client.ts
|
|
1108
|
+
const loadMultiReactor = () => import("./multi-reactor-BG-DqUcm.js");
|
|
1109
|
+
/**
|
|
1110
|
+
* Pick the client for the resolved mode:
|
|
1111
|
+
* - `in-process` / `worker`: the local client, router module never loaded.
|
|
1112
|
+
* - `router`: the local reactor plus remote backends.
|
|
1113
|
+
* - `remote`: a remote-only router — a full IReactorClient that proxies to
|
|
1114
|
+
* the Switchboard over GraphQL with NO local reactor (no PGlite).
|
|
1115
|
+
*/
|
|
1116
|
+
async function selectAppReactorClient(params) {
|
|
1117
|
+
if (params.mode === "remote") {
|
|
1118
|
+
setFullReactorClient(void 0);
|
|
1119
|
+
const remote = await buildRemoteOnly(params);
|
|
1120
|
+
setFullReactorClient(remote);
|
|
1121
|
+
return remote;
|
|
1122
|
+
}
|
|
1123
|
+
if (params.mode !== "router") {
|
|
1124
|
+
if (window.ph?.fullReactorClient) setFullReactorClient(void 0);
|
|
1125
|
+
return requireModule(params).client;
|
|
1126
|
+
}
|
|
1127
|
+
setFullReactorClient(void 0);
|
|
1128
|
+
const routed = await buildRouter(params);
|
|
1129
|
+
setFullReactorClient(routed);
|
|
1130
|
+
return routed ?? requireModule(params).client;
|
|
1131
|
+
}
|
|
1132
|
+
function requireModule(params) {
|
|
1133
|
+
if (!params.module) throw new Error(`reactorClient mode "${params.mode}" needs a local reactor, but none was built`);
|
|
1134
|
+
return params.module;
|
|
1135
|
+
}
|
|
1136
|
+
/** A Switchboard that cannot answer must not fail boot: list the tab's drives. */
|
|
1137
|
+
async function getAppDrives(client, local) {
|
|
1138
|
+
if (client === local) return getDrives(local);
|
|
1139
|
+
try {
|
|
1140
|
+
return await getDrives(client);
|
|
1141
|
+
} catch (error) {
|
|
1142
|
+
logger.warn("Could not list drives through the router; listing the local reactor's: @error", error);
|
|
1143
|
+
return getDrives(local);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
async function refreshAppDrives(client, local) {
|
|
1147
|
+
if (client === local) return refreshReactorDataClient(client);
|
|
1148
|
+
setDrives(await getAppDrives(client, local));
|
|
1149
|
+
}
|
|
1150
|
+
async function buildRouter(params) {
|
|
1151
|
+
if (!params.remoteDriveUrl) {
|
|
1152
|
+
logger.warn("multiReactor is on but no remote drive URL is configured; using the local reactor only");
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
let multiReactor;
|
|
1156
|
+
try {
|
|
1157
|
+
multiReactor = await (params.loadRouter ?? loadMultiReactor)();
|
|
1158
|
+
} catch (error) {
|
|
1159
|
+
logger.error("Could not load the multi-reactor router: @error", error);
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
const remoteGraphqlUrl = multiReactor.deriveSwitchboardGraphqlUrl(params.remoteDriveUrl);
|
|
1163
|
+
if (!remoteGraphqlUrl) {
|
|
1164
|
+
logger.warn("multiReactor is on but the remote drive URL @url does not parse; using the local reactor only", params.remoteDriveUrl);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
logger.info("Multi-reactor routing to @url", remoteGraphqlUrl);
|
|
1168
|
+
return multiReactor.buildMultiReactorClient({
|
|
1169
|
+
module: requireModule(params),
|
|
1170
|
+
remoteGraphqlUrl,
|
|
1171
|
+
signer: params.signer,
|
|
1172
|
+
documentModelModules: params.documentModelModules
|
|
1162
1173
|
});
|
|
1163
|
-
if (parseFlag(queryParam) !== void 0) window.localStorage.setItem(REACTOR_WORKER_STORAGE_KEY, enabled ? "true" : "false");
|
|
1164
|
-
return enabled;
|
|
1165
1174
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1175
|
+
/**
|
|
1176
|
+
* The `remote` mode: a remote-only router — a full IReactorClient that proxies
|
|
1177
|
+
* to the Switchboard over GraphQL with NO local backend, so no local reactor
|
|
1178
|
+
* and no PGlite are ever built. A missing/unparseable remote URL is a hard
|
|
1179
|
+
* config error here (unlike `router`, there is no local reactor to fall back
|
|
1180
|
+
* to).
|
|
1181
|
+
*/
|
|
1182
|
+
async function buildRemoteOnly(params) {
|
|
1183
|
+
if (!params.remoteDriveUrl) throw new Error("reactorClient \"remote\" needs a remote drive URL — declare a remote backend / default drive the client can proxy to");
|
|
1184
|
+
const multiReactor = await (params.loadRouter ?? loadMultiReactor)();
|
|
1185
|
+
const remoteGraphqlUrl = multiReactor.deriveSwitchboardGraphqlUrl(params.remoteDriveUrl);
|
|
1186
|
+
if (!remoteGraphqlUrl) throw new Error(`reactorClient "remote": the remote drive URL "${params.remoteDriveUrl}" does not resolve to a Switchboard GraphQL endpoint`);
|
|
1187
|
+
logger.info("Remote reactor client → @url", remoteGraphqlUrl);
|
|
1188
|
+
return multiReactor.buildMultiReactorClient({
|
|
1189
|
+
module: void 0,
|
|
1190
|
+
remoteGraphqlUrl,
|
|
1191
|
+
signer: params.signer,
|
|
1192
|
+
documentModelModules: params.documentModelModules
|
|
1193
|
+
});
|
|
1171
1194
|
}
|
|
1172
1195
|
//#endregion
|
|
1173
1196
|
//#region src/store/processor-host-module.ts
|
|
@@ -1276,7 +1299,10 @@ async function clearReactorStorage() {
|
|
|
1276
1299
|
await module.adminClient.clearStorage();
|
|
1277
1300
|
return;
|
|
1278
1301
|
}
|
|
1279
|
-
if (module?.kind === "browser")
|
|
1302
|
+
if (module?.kind === "browser") {
|
|
1303
|
+
const reactorModule = module.reactorModule;
|
|
1304
|
+
await closeWithin(reactorModule?.groupCommitStorage ?? reactorModule?.pg);
|
|
1305
|
+
}
|
|
1280
1306
|
const targets = (await indexedDB.databases()).map((d) => d.name).filter((n) => !!n && !n.startsWith("ph-pglite-backup::") && /pglite|reactor/i.test(n));
|
|
1281
1307
|
await Promise.all(targets.map((name) => new Promise((resolve) => {
|
|
1282
1308
|
const req = indexedDB.deleteDatabase(name);
|
|
@@ -1305,9 +1331,12 @@ async function createReactor(localPackage) {
|
|
|
1305
1331
|
const runtimeConfig = getRuntimeConfig();
|
|
1306
1332
|
const packageManager = new BrowserPackageManager(phGlobalConfig.routerBasename ?? "", runtimeConfig.packageRegistryUrl ?? null);
|
|
1307
1333
|
setVetraPackageManager(packageManager);
|
|
1308
|
-
await packageManager.init(localPackage, runtimeConfig.localPackage?.version, phGlobalConfig.studioMode);
|
|
1334
|
+
await packageManager.init(localPackage, runtimeConfig.localPackage?.version, phGlobalConfig.studioMode, connectConfig.workflowsEnabled);
|
|
1309
1335
|
try {
|
|
1310
|
-
const { default: registerBundledPackages } = await import(
|
|
1336
|
+
const { default: registerBundledPackages } = await import(
|
|
1337
|
+
/* @vite-ignore */
|
|
1338
|
+
"ph-bundled-packages-virtual"
|
|
1339
|
+
);
|
|
1311
1340
|
registerBundledPackages(packageManager);
|
|
1312
1341
|
} catch {}
|
|
1313
1342
|
const remotePackages = runtimeConfig.packages.filter((p) => p.provider !== "local").map((p) => p.version ? `${p.packageName}@${p.version}` : p.packageName);
|
|
@@ -1325,55 +1354,110 @@ async function createReactor(localPackage) {
|
|
|
1325
1354
|
const reactorFeatureFlags = runtimeConfig.connect?.reactor?.featureFlags ?? {};
|
|
1326
1355
|
const enabledReactorFlags = Object.entries(reactorFeatureFlags).filter(([, enabled]) => enabled).map(([name]) => name);
|
|
1327
1356
|
if (enabledReactorFlags.length > 0) logger.info(`Reactor feature flags: ${enabledReactorFlags.join(", ")}`);
|
|
1357
|
+
const createSignaturePolicy = runtimeConfig.connect?.reactor?.createSignaturePolicy;
|
|
1358
|
+
const unsupportedStoredDocuments = runtimeConfig.connect?.reactor?.unsupportedStoredDocuments;
|
|
1359
|
+
const renownEndpoints = {
|
|
1360
|
+
renownUrl: phGlobalConfig.renownUrl,
|
|
1361
|
+
switchboardUrl: phGlobalConfig.switchboardUrl
|
|
1362
|
+
};
|
|
1363
|
+
const mode = resolveReactorClientMode();
|
|
1364
|
+
const multiReactor = mode === "router";
|
|
1365
|
+
const needsLocalReactor = mode !== "remote";
|
|
1366
|
+
const localAsWorker = needsLocalReactor && (mode === "worker" || mode === "router" && isReactorWorkerEnabled());
|
|
1328
1367
|
let reactorClientModule;
|
|
1329
|
-
if (
|
|
1368
|
+
if (localAsWorker) {
|
|
1330
1369
|
const packageSpecs = packageManager.getRegistryPackages().map((p) => p.version ? `${p.name}@${p.version}` : p.name);
|
|
1331
1370
|
const registryClient = new RegistryClient(packageManager.cdnUrl ?? "");
|
|
1371
|
+
const documentModelLoader = { async load(documentType) {
|
|
1372
|
+
const names = packageManager.cdnUrl ? await registryClient.getPackagesByDocumentType(documentType) : [];
|
|
1373
|
+
for (const name of names) {
|
|
1374
|
+
const result = await packageManager.addPackage(name);
|
|
1375
|
+
if (result.type === "error") throw new Error(`Failed to install package "${name}" for document model: ${documentType}`, { cause: result.error });
|
|
1376
|
+
}
|
|
1377
|
+
const module = packageManager.packages.flatMap((p) => p.documentModels).find((m) => m.documentModel.global.id === documentType);
|
|
1378
|
+
if (!module) throw new Error(names.length > 0 ? `Installed [${names.join(", ")}] but document model not available: ${documentType}` : `No package found for document model: ${documentType} (cdnUrl: ${packageManager.cdnUrl ?? "none"})`);
|
|
1379
|
+
return module;
|
|
1380
|
+
} };
|
|
1381
|
+
const [sharedDeps, packagedWorker, packageSources] = await Promise.all([
|
|
1382
|
+
getSharedDeps(),
|
|
1383
|
+
resolvePackagedReactorWorker(import.meta.env.BASE_URL),
|
|
1384
|
+
resolveLocalPackageSources(import.meta.env.BASE_URL)
|
|
1385
|
+
]);
|
|
1386
|
+
const workerSource = selectReactorWorkerSource({
|
|
1387
|
+
packaged: isPackagedConnectDist(),
|
|
1388
|
+
bundle: packagedWorker
|
|
1389
|
+
});
|
|
1390
|
+
if (workerSource.kind === "unavailable") {
|
|
1391
|
+
window.ph.loading = false;
|
|
1392
|
+
throw new Error("reactorWorker is enabled but this deployment serves no reactor worker bundle (__reactor_worker__/); rebuild with ph connect build or open with ?reactorWorker=false");
|
|
1393
|
+
}
|
|
1332
1394
|
const workerClient = createWorkerReactorClientModule({
|
|
1395
|
+
workerUrl: workerSource.kind === "bundle" ? workerSource.url : void 0,
|
|
1396
|
+
workerDigest: workerSource.kind === "bundle" ? workerSource.digest : void 0,
|
|
1397
|
+
packageSources,
|
|
1333
1398
|
namespace: REACTOR_INSTANCE_NAMESPACE,
|
|
1334
1399
|
relationalNamespace: RELATIONAL_PGLITE_NAME,
|
|
1335
1400
|
cdnUrl: packageManager.cdnUrl ?? "",
|
|
1336
1401
|
packageSpecs,
|
|
1402
|
+
sharedImports: sharedDeps?.imports,
|
|
1337
1403
|
studioMode: phGlobalConfig.studioMode,
|
|
1404
|
+
workflowsEnabled: connectConfig.workflowsEnabled,
|
|
1338
1405
|
renownChainId,
|
|
1339
1406
|
featureFlags: reactorFeatureFlags,
|
|
1407
|
+
multiReactor,
|
|
1408
|
+
createSignaturePolicy,
|
|
1409
|
+
unsupportedStoredDocuments,
|
|
1410
|
+
renownEndpoints,
|
|
1340
1411
|
documentModelModules,
|
|
1341
1412
|
upgradeManifests,
|
|
1342
|
-
documentModelLoader
|
|
1343
|
-
const names = packageManager.cdnUrl ? await registryClient.getPackagesByDocumentType(documentType) : [];
|
|
1344
|
-
for (const name of names) {
|
|
1345
|
-
const result = await packageManager.addPackage(name);
|
|
1346
|
-
if (result.type === "error") throw new Error(`Failed to install package "${name}" for document model: ${documentType}`, { cause: result.error });
|
|
1347
|
-
}
|
|
1348
|
-
const module = packageManager.packages.flatMap((p) => p.documentModels).find((m) => m.documentModel.global.id === documentType);
|
|
1349
|
-
if (!module) throw new Error(names.length > 0 ? `Installed [${names.join(", ")}] but document model not available: ${documentType}` : `No package found for document model: ${documentType} (cdnUrl: ${packageManager.cdnUrl ?? "none"})`);
|
|
1350
|
-
return module;
|
|
1351
|
-
} },
|
|
1413
|
+
documentModelLoader,
|
|
1352
1414
|
renown,
|
|
1353
|
-
onReload: (reason
|
|
1415
|
+
onReload: (reason) => {
|
|
1354
1416
|
logger.warn("Reactor worker requested reload: @reason", reason);
|
|
1355
|
-
|
|
1356
|
-
window.location.reload();
|
|
1417
|
+
reloadForWorker(reason, () => window.location.reload());
|
|
1357
1418
|
}
|
|
1358
1419
|
});
|
|
1359
1420
|
reactorClientModule = workerClient.reactorClientModule;
|
|
1421
|
+
const { registerPackages } = workerClient.reactorClientModule;
|
|
1422
|
+
subscribeLocalPackageChanges(packageManager, () => {
|
|
1423
|
+
(async () => {
|
|
1424
|
+
const source = await resolveDevProjectSource(import.meta.env.BASE_URL);
|
|
1425
|
+
if (!source) return;
|
|
1426
|
+
try {
|
|
1427
|
+
await registerPackages([source]);
|
|
1428
|
+
} catch (error) {
|
|
1429
|
+
logger.error("Failed to re-register project models in the reactor worker: @error", error);
|
|
1430
|
+
}
|
|
1431
|
+
})();
|
|
1432
|
+
});
|
|
1360
1433
|
try {
|
|
1361
|
-
await workerClient.syncManagerProxy.startup();
|
|
1434
|
+
await startupOwningStores((options) => workerClient.syncManagerProxy.startup(options), [REACTOR_INSTANCE_NAMESPACE, RELATIONAL_PGLITE_NAME]);
|
|
1362
1435
|
} catch (error) {
|
|
1363
1436
|
window.ph.loading = false;
|
|
1364
1437
|
logger.error("Reactor worker failed to start: @error", error);
|
|
1365
1438
|
throw error;
|
|
1366
1439
|
}
|
|
1367
|
-
} else reactorClientModule = await createBrowserReactor(documentModelModules, upgradeManifests, renown, reactorFeatureFlags, discoveryService);
|
|
1368
|
-
const
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1440
|
+
} else if (needsLocalReactor) reactorClientModule = await createBrowserReactor(documentModelModules, upgradeManifests, renown, reactorFeatureFlags, discoveryService, createSignaturePolicy, renownEndpoints, unsupportedStoredDocuments, multiReactor);
|
|
1441
|
+
const appReactorClient = await selectAppReactorClient({
|
|
1442
|
+
mode,
|
|
1443
|
+
module: reactorClientModule,
|
|
1444
|
+
remoteDriveUrl: phGlobalConfig.defaultDrivesUrl,
|
|
1445
|
+
signer: renown.signer,
|
|
1446
|
+
documentModelModules
|
|
1447
|
+
});
|
|
1448
|
+
const drives = await getAppDrives(appReactorClient, reactorClientModule?.client ?? appReactorClient);
|
|
1449
|
+
const didFromUrl = getDidFromUrl();
|
|
1450
|
+
await login(didFromUrl, renown);
|
|
1451
|
+
const documentCache = new DocumentCache(appReactorClient);
|
|
1452
|
+
const basePath = phGlobalConfig.basePath ?? "/";
|
|
1453
|
+
const routerBasename = phGlobalConfig.routerBasename ?? "/";
|
|
1454
|
+
const mergedGlobalConfig = buildPHGlobalConfig(basePath, routerBasename, runtimeConfig.connect ?? {});
|
|
1455
|
+
setDefaultPHGlobalConfig(mergedGlobalConfig);
|
|
1372
1456
|
const path = window.location.pathname;
|
|
1373
1457
|
const driveSlug = extractDriveSlugFromPath(path);
|
|
1374
1458
|
const nodeSlug = extractNodeSlugFromPath(path);
|
|
1375
1459
|
setReactorClientModule(reactorClientModule);
|
|
1376
|
-
setReactorClient(
|
|
1460
|
+
setReactorClient(appReactorClient);
|
|
1377
1461
|
const _defaultDrivesUrl = phGlobalConfig.defaultDrivesUrl;
|
|
1378
1462
|
if (_defaultDrivesUrl) {
|
|
1379
1463
|
let switchboardOrigin;
|
|
@@ -1385,11 +1469,12 @@ async function createReactor(localPackage) {
|
|
|
1385
1469
|
if (!renown.user) return void 0;
|
|
1386
1470
|
return renown.getBearerToken({ expiresIn: 10 });
|
|
1387
1471
|
};
|
|
1388
|
-
|
|
1472
|
+
const attachmentService = createRemoteAttachmentService({
|
|
1389
1473
|
remoteUrl: switchboardOrigin,
|
|
1390
1474
|
jwtHandler: attachmentJwtHandler,
|
|
1391
1475
|
uploadTransport: createXhrUploadTransport()
|
|
1392
|
-
})
|
|
1476
|
+
});
|
|
1477
|
+
setAttachmentService(attachmentService);
|
|
1393
1478
|
}
|
|
1394
1479
|
}
|
|
1395
1480
|
setDocumentCache(documentCache);
|
|
@@ -1402,32 +1487,26 @@ async function createReactor(localPackage) {
|
|
|
1402
1487
|
if (remoteUrl) addRemoteDrive(remoteUrl, void 0).catch((error) => console.error(`Failed to add remote drive from ${remoteUrl}:`, error));
|
|
1403
1488
|
setSelectedDrive(driveSlug);
|
|
1404
1489
|
setSelectedNode(nodeSlug);
|
|
1405
|
-
const reactorClient =
|
|
1490
|
+
const reactorClient = appReactorClient;
|
|
1406
1491
|
for (const driveType of DRIVE_DOCUMENT_TYPES) reactorClient.subscribe({ type: driveType }, (event) => {
|
|
1407
1492
|
logger.verbose("ReactorClient subscription event: @event", event);
|
|
1408
|
-
refreshReactorDataClient(
|
|
1493
|
+
refreshReactorDataClient(appReactorClient).catch((e) => logger.error("@error", e));
|
|
1409
1494
|
});
|
|
1410
1495
|
reactorClient.subscribe({}, (event) => {
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
toast("The drive you were viewing has been deleted");
|
|
1419
|
-
return;
|
|
1420
|
-
}
|
|
1421
|
-
if (selectedNodeId && deletedId === selectedNodeId) {
|
|
1422
|
-
setSelectedNode(void 0);
|
|
1423
|
-
toast("The document you were editing has been deleted");
|
|
1424
|
-
}
|
|
1496
|
+
closeDeletedSelection(event, {
|
|
1497
|
+
selectedDriveId: window.ph?.selectedDriveId,
|
|
1498
|
+
selectedNodeId: window.ph?.selectedNodeId,
|
|
1499
|
+
closeDrive: () => setSelectedDrive(void 0),
|
|
1500
|
+
closeNode: () => setSelectedNode(void 0),
|
|
1501
|
+
notify: (message) => toast(message)
|
|
1502
|
+
});
|
|
1425
1503
|
});
|
|
1426
|
-
await
|
|
1504
|
+
await refreshAppDrives(appReactorClient, reactorClientModule?.client ?? appReactorClient);
|
|
1427
1505
|
const packagesWithProcessorFactories = packageManager.packages.filter((pkg) => pkg.processorFactory !== void 0);
|
|
1428
|
-
const reactorModule = reactorClientModule
|
|
1429
|
-
if (packagesWithProcessorFactories.length > 0 && !
|
|
1430
|
-
else if (packagesWithProcessorFactories.length > 0 && reactorModule)
|
|
1506
|
+
const reactorModule = reactorClientModule?.kind === "browser" ? reactorClientModule.reactorModule : void 0;
|
|
1507
|
+
if (packagesWithProcessorFactories.length > 0 && !reactorClientModule) logger.info("Remote reactor client: @count processor factory/ies run on the Switchboard, not in the tab", packagesWithProcessorFactories.length);
|
|
1508
|
+
else if (packagesWithProcessorFactories.length > 0 && !reactorModule) for (const pkg of packagesWithProcessorFactories) logger.warn("Skipping processor factory @name: processors are not supported on the worker reactor path yet", pkg.manifest.name);
|
|
1509
|
+
else if (packagesWithProcessorFactories.length > 0 && reactorModule && reactorClientModule) {
|
|
1431
1510
|
const readModels = reactorModule.readModelCoordinator.readModels;
|
|
1432
1511
|
const processorHostModule = await createProcessorHostModule(reactorClientModule.client, readModels, window.ph?.attachmentService);
|
|
1433
1512
|
if (processorHostModule !== void 0) await Promise.all(packagesWithProcessorFactories.map(async (pkg) => {
|
|
@@ -1460,5 +1539,5 @@ function getDriveUrl() {
|
|
|
1460
1539
|
//#endregion
|
|
1461
1540
|
export { createReactor as n, clearReactorStorage as t };
|
|
1462
1541
|
|
|
1463
|
-
//# sourceMappingURL=reactor-
|
|
1464
|
-
//# debugId=
|
|
1542
|
+
//# sourceMappingURL=reactor-B8Sh7Et8.js.map
|
|
1543
|
+
//# debugId=25f5b030-997d-5eef-b64b-536c6e8d0f21
|