@powerhousedao/connect 6.2.3-dev.5 → 6.2.3-dev.51
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-DzQEnMdV.js → ClearStorageModal-CW-Oc3c1.js} +6 -6
- package/dist/{ClearStorageModal-DzQEnMdV.js.map → ClearStorageModal-CW-Oc3c1.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-BvUOVfoV.js → DebugSettingsModal-QSXiK9ru.js} +7 -7
- package/dist/{DebugSettingsModal-BvUOVfoV.js.map → DebugSettingsModal-QSXiK9ru.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-BOcB85BR.js → InspectorModal-D4JkdFdD.js} +62 -22
- package/dist/InspectorModal-D4JkdFdD.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-CVHwKA6s.js} +5 -5
- package/dist/{MissingPackageModal-nBnExqO0.js.map → MissingPackageModal-CVHwKA6s.js.map} +1 -1
- package/dist/{OpenFileDocumentsModal-BOei0InB.js → OpenFileDocumentsModal-B95nM_Lp.js} +8 -7
- package/dist/{OpenFileDocumentsModal-BOei0InB.js.map → OpenFileDocumentsModal-B95nM_Lp.js.map} +1 -1
- package/dist/{SettingsModal-u5XxyRfg.js → SettingsModal-Ch0z4Z7p.js} +18 -15
- package/dist/{SettingsModal-u5XxyRfg.js.map → SettingsModal-Ch0z4Z7p.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-D4WUh5Ll.js +4 -0
- package/dist/{app-loader-DgRV2H7q.js → app-loader-YuIXiqx0.js} +1215 -1139
- package/dist/app-loader-YuIXiqx0.js.map +1 -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-DPNEOI2A.js +210 -0
- package/dist/boot-DPNEOI2A.js.map +1 -0
- package/dist/buffer-DNTcuap_.js +66 -0
- package/dist/buffer-DNTcuap_.js.map +1 -0
- package/dist/{build-info-DnKFLu09.js → build-info-BHO7aYLV.js} +10 -6
- package/dist/build-info-BHO7aYLV.js.map +1 -0
- package/dist/components-DS7gJO9p.js +5 -0
- package/dist/{connect.config-DaHDEUrw.js → connect.config-m9zdOvO8.js} +26 -14
- package/dist/connect.config-m9zdOvO8.js.map +1 -0
- package/dist/{connection-state-3w4liC1X.js → connection-state-D7RGI_TC.js} +20 -9
- package/dist/{connection-state-3w4liC1X.js.map → connection-state-D7RGI_TC.js.map} +1 -1
- package/dist/{cookie-banner-BH6bIq24.js → cookie-banner-DzeXtywE.js} +6 -6
- package/dist/{cookie-banner-BH6bIq24.js.map → cookie-banner-DzeXtywE.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-Cc97pAGE.js → load-c7z-7RoP.js} +14 -12
- package/dist/{load-Cc97pAGE.js.map → load-c7z-7RoP.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-CcMPtKrf.js +201 -0
- package/dist/multi-reactor-CcMPtKrf.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-BKiOpxGV.js} +4 -4
- package/dist/{pglite-seed-BqAUvNFw.js.map → pglite-seed-BKiOpxGV.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/{preferences-store-_5Cw4_YV.js → preferences-store-CEwlLlXe.js} +6 -25
- package/dist/preferences-store-CEwlLlXe.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-B-m_UkS8.js → reactor-DfTuWWWD.js} +568 -517
- package/dist/reactor-DfTuWWWD.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-D4BhZIyI.js} +5 -5
- package/dist/{registerServiceWorker-BSzbNfvz.js.map → registerServiceWorker-D4BhZIyI.js.map} +1 -1
- package/dist/{runtime-config-DL3QjcfM.js → runtime-config-DtJIUgYw.js} +3 -3
- package/dist/{runtime-config-DL3QjcfM.js.map → runtime-config-DtJIUgYw.js.map} +1 -1
- 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 +3270 -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-DBxOuy3N.js} +75 -13
- package/dist/useRegistryPackages-DBxOuy3N.js.map +1 -0
- package/package.json +20 -19
- package/style.css +7 -5
- package/dist/AddDriveModal-xAw48kdl.js.map +0 -1
- package/dist/InspectorModal-BOcB85BR.js.map +0 -1
- package/dist/app-loader-C8uDnSIq.js +0 -4
- package/dist/app-loader-DgRV2H7q.js.map +0 -1
- package/dist/build-info-DnKFLu09.js.map +0 -1
- package/dist/components-rLsvDQ-4.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-B-m_UkS8.js.map +0 -1
- package/dist/useRegistryPackages-BnUcL_nZ.js.map +0 -1
|
@@ -1,110 +1,102 @@
|
|
|
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]="4f04d9df-7531-5160-a235-8aa9982f7af2")}catch(e){}}();
|
|
3
|
+
import { n as getRuntimeConfig } from "./runtime-config-DtJIUgYw.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-m9zdOvO8.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-BHO7aYLV.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-D7RGI_TC.js";
|
|
11
11
|
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";
|
|
12
|
+
import { DocumentModelRegistry, DocumentModelResolver, HardenedPGliteDialect, LocalChannelFactory, LocalChannelPortRegistry, PGLITE_IDB_STORAGE_FACTS, ReactorEventTypes, createReactorHostModuleBase } from "@powerhousedao/reactor";
|
|
13
|
+
import { MessageRouter, RPC_PROTOCOL_VERSION, SyncManagerProxy, connectReactorClient, createInspectorProxy, createPortTransport, createReactorEventBusProxy, createRelationalPgliteProxy, createWorkerAdminClient, isFingerprintMismatchReload, postReactorIdentity } from "@powerhousedao/reactor-browser/rpc";
|
|
14
|
+
import { ConsoleLogger, logger, setLogLevel } from "document-model";
|
|
14
15
|
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";
|
|
16
|
+
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
17
|
import { createAttachmentClient, createRemoteAttachmentService, createXhrUploadTransport } from "@powerhousedao/reactor-attachments/client";
|
|
18
|
+
import { BrowserKeyStorage, RenownBuilder, RenownCryptoBuilder } from "@renown/sdk";
|
|
21
19
|
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();
|
|
20
|
+
//#region src/utils/poisoned-store-budget.ts
|
|
21
|
+
const BUDGET_LIMIT = 2;
|
|
22
|
+
const POISONED_STORE = {
|
|
23
|
+
key: "ph-connect:poisoned-store-reloads",
|
|
24
|
+
quietMs: 6e5
|
|
25
|
+
};
|
|
26
|
+
const MISMATCH = {
|
|
27
|
+
key: "ph-connect:mismatch-reloads",
|
|
28
|
+
quietMs: 6e4
|
|
29
|
+
};
|
|
30
|
+
function sessionStore() {
|
|
44
31
|
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();
|
|
32
|
+
return globalThis.sessionStorage;
|
|
33
|
+
} catch {
|
|
34
|
+
return;
|
|
57
35
|
}
|
|
58
36
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
37
|
+
function readRecord(raw) {
|
|
38
|
+
const record = raw ? JSON.parse(raw) : null;
|
|
39
|
+
return typeof record?.count === "number" && typeof record.lastAt === "number" ? {
|
|
40
|
+
count: record.count,
|
|
41
|
+
lastAt: record.lastAt
|
|
42
|
+
} : {
|
|
43
|
+
count: 0,
|
|
44
|
+
lastAt: 0
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function claimReload(budget, storage, now) {
|
|
48
|
+
if (storage === void 0) return false;
|
|
65
49
|
try {
|
|
66
|
-
const
|
|
67
|
-
|
|
50
|
+
const previous = readRecord(storage.getItem(budget.key));
|
|
51
|
+
const count = now - previous.lastAt >= budget.quietMs ? 0 : previous.count;
|
|
52
|
+
const allowed = count < BUDGET_LIMIT;
|
|
53
|
+
storage.setItem(budget.key, JSON.stringify({
|
|
54
|
+
count: allowed ? count + 1 : count,
|
|
55
|
+
lastAt: now
|
|
56
|
+
}));
|
|
57
|
+
return allowed;
|
|
68
58
|
} catch {
|
|
69
|
-
return
|
|
59
|
+
return false;
|
|
70
60
|
}
|
|
71
61
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
/** One page reload answers every budgeted reload the page hears, of either budget. */
|
|
63
|
+
let reloadRequested = false;
|
|
64
|
+
function reloadWithinBudget(budget, reload, pastBudget, storage = sessionStore(), now = Date.now()) {
|
|
65
|
+
if (reloadRequested) return;
|
|
66
|
+
if (claimReload(budget, storage, now)) {
|
|
67
|
+
reloadRequested = true;
|
|
68
|
+
reload();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
setWorkerConnectionStatus(pastBudget);
|
|
77
72
|
}
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}))
|
|
98
|
-
}
|
|
99
|
-
};
|
|
73
|
+
/** Past the budget a poisoned store stops reloading and shows storage-unusable, so clear storage stays reachable. */
|
|
74
|
+
function reloadForPoisonedStore(reload, storage, now) {
|
|
75
|
+
reloadWithinBudget(POISONED_STORE, reload, "storage-unusable", storage, now);
|
|
76
|
+
}
|
|
77
|
+
/** onPoisoned for an in-tab store: the page reload reopens it, within the poisoned-store budget. */
|
|
78
|
+
function reloadPageForPoisonedStore(cause, reload = () => window.location.reload()) {
|
|
79
|
+
console.error("[connect] PGlite session poisoned:", cause);
|
|
80
|
+
reloadForPoisonedStore(reload);
|
|
81
|
+
}
|
|
82
|
+
function reloadForWorker(reason, reload, storage, now) {
|
|
83
|
+
if (reason === "storage session poisoned") {
|
|
84
|
+
reloadForPoisonedStore(reload, storage, now);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (isFingerprintMismatchReload(reason)) {
|
|
88
|
+
reloadWithinBudget(MISMATCH, reload, "version-conflict", storage, now);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
reload();
|
|
100
92
|
}
|
|
101
93
|
//#endregion
|
|
102
94
|
//#region src/pglite.db.ts
|
|
103
|
-
async function createMainThreadPGlite(major, dbName) {
|
|
95
|
+
async function createMainThreadPGlite(major, dbName, relaxedDurability) {
|
|
104
96
|
const { PGlite } = await loadPGliteModule(major);
|
|
105
97
|
const { live } = major === 16 ? await import("pglite-legacy-02/live") : await import("@electric-sql/pglite/live");
|
|
106
98
|
return new PGlite(`idb://${dbName}`, {
|
|
107
|
-
relaxedDurability
|
|
99
|
+
relaxedDurability,
|
|
108
100
|
extensions: { live }
|
|
109
101
|
});
|
|
110
102
|
}
|
|
@@ -114,37 +106,72 @@ function chainedCreate(create) {
|
|
|
114
106
|
bootChain = pending.catch(() => void 0);
|
|
115
107
|
return pending;
|
|
116
108
|
}
|
|
109
|
+
const CLOSE_TIMEOUT_MS = 3e4;
|
|
117
110
|
function pgliteSingleton(opts) {
|
|
118
111
|
let cached;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
112
|
+
let unusable;
|
|
113
|
+
return {
|
|
114
|
+
get() {
|
|
115
|
+
if (cached) return cached;
|
|
116
|
+
const pending = chainedCreate(async () => {
|
|
117
|
+
if (unusable) throw unusable;
|
|
118
|
+
const major = resolvePgMajorForRuntime(await opts.detectMajor());
|
|
119
|
+
if (major !== 17) console.warn(`[${opts.label}] Opening legacy Postgres ${major} data dir. Migrate to PG17 from the banner or the Inspector → Debug tab.`);
|
|
120
|
+
return createMainThreadPGlite(major, opts.dbName, opts.relaxedDurability);
|
|
121
|
+
});
|
|
122
|
+
cached = pending;
|
|
123
|
+
pending.catch(() => {
|
|
124
|
+
if (cached === pending) cached = void 0;
|
|
125
|
+
});
|
|
126
|
+
return pending;
|
|
127
|
+
},
|
|
128
|
+
async discard() {
|
|
129
|
+
const pending = cached;
|
|
130
|
+
if (!pending) return;
|
|
131
|
+
cached = void 0;
|
|
132
|
+
const closing = bootChain.then(async () => {
|
|
133
|
+
const pg = await pending;
|
|
134
|
+
let timer;
|
|
135
|
+
try {
|
|
136
|
+
await Promise.race([pg.close(), new Promise((resolve) => {
|
|
137
|
+
timer = setTimeout(() => {
|
|
138
|
+
unusable = /* @__PURE__ */ new Error(`[${opts.label}] PGlite did not close within ${CLOSE_TIMEOUT_MS}ms; reload the page to reopen its store`);
|
|
139
|
+
console.warn(unusable.message);
|
|
140
|
+
resolve();
|
|
141
|
+
}, CLOSE_TIMEOUT_MS);
|
|
142
|
+
})]);
|
|
143
|
+
} finally {
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
bootChain = closing.catch(() => void 0);
|
|
148
|
+
try {
|
|
149
|
+
await closing;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error(`[${opts.label}] closing PGlite failed:`, error);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
131
154
|
};
|
|
132
155
|
}
|
|
133
|
-
const
|
|
156
|
+
const reactorPGlite = pgliteSingleton({
|
|
134
157
|
dbName: REACTOR_PGLITE_NAME,
|
|
135
158
|
detectMajor: detectReactorPgMajor,
|
|
136
|
-
label: "reactor"
|
|
159
|
+
label: "reactor",
|
|
160
|
+
relaxedDurability: false
|
|
137
161
|
});
|
|
162
|
+
const getReactorPGlite = reactorPGlite.get;
|
|
163
|
+
const discardReactorPGlite = reactorPGlite.discard;
|
|
138
164
|
const getRelationalPGlite = pgliteSingleton({
|
|
139
165
|
dbName: RELATIONAL_PGLITE_NAME,
|
|
140
166
|
detectMajor: detectRelationalPgMajor,
|
|
141
|
-
label: "relational"
|
|
142
|
-
|
|
167
|
+
label: "relational",
|
|
168
|
+
relaxedDurability: true
|
|
169
|
+
}).get;
|
|
143
170
|
async function getDb() {
|
|
144
171
|
const pgLite = await getRelationalPGlite();
|
|
145
172
|
return {
|
|
146
173
|
pgLite,
|
|
147
|
-
relationalDb: createRelationalDb(new Kysely({ dialect: new
|
|
174
|
+
relationalDb: createRelationalDb(new Kysely({ dialect: new HardenedPGliteDialect(pgLite, { onPoisoned: reloadPageForPoisonedStore }) }))
|
|
148
175
|
};
|
|
149
176
|
}
|
|
150
177
|
//#endregion
|
|
@@ -153,20 +180,34 @@ async function getDb() {
|
|
|
153
180
|
* Creates a Reactor that plugs into legacy storage but syncs through the new
|
|
154
181
|
* Reactor GQL API.
|
|
155
182
|
*/
|
|
156
|
-
async function createBrowserReactor(documentModelModules, upgradeManifests, renown, featureFlags, documentModelLoader) {
|
|
157
|
-
const signerConfig =
|
|
158
|
-
signer: renown.signer,
|
|
159
|
-
verifier: createSignatureVerifier()
|
|
160
|
-
};
|
|
183
|
+
async function createBrowserReactor(documentModelModules, upgradeManifests, renown, featureFlags, documentModelLoader, createSignaturePolicy, renownEndpoints = {}, unsupportedStoredDocuments, multiReactor = false) {
|
|
184
|
+
const signerConfig = await createConnectSignerConfig(renown.signer, featureFlags, renownEndpoints);
|
|
161
185
|
const jwtHandler = async (_url) => {
|
|
162
186
|
if (!renown.user) return;
|
|
163
187
|
return renown.getBearerToken({ expiresIn: 10 });
|
|
164
188
|
};
|
|
165
189
|
const pg = await getReactorPGlite();
|
|
166
190
|
const logger = new ConsoleLogger(["reactor-client"]);
|
|
167
|
-
const
|
|
191
|
+
const reactorBuilder = new ReactorBuilder$1().withDocumentModelSources(documentModelModules).withUpgradeManifests(upgradeManifests).withExecutorConfig({ featureFlags }).withJwtHandler(jwtHandler).withGroupCommitPGlite({
|
|
192
|
+
pg,
|
|
193
|
+
onUnrecoverable: reloadPageForPoisonedStore,
|
|
194
|
+
onDiagnostic: (message, error) => console.error(`[reactor] pglite: ${message}`, error)
|
|
195
|
+
}).withStorageFacts(PGLITE_IDB_STORAGE_FACTS);
|
|
196
|
+
configureConnectChannelScheme(reactorBuilder, {
|
|
197
|
+
multiReactor,
|
|
198
|
+
createLocalChannelFactory: () => new LocalChannelFactory(logger, new LocalChannelPortRegistry({ logger }).provider)
|
|
199
|
+
});
|
|
200
|
+
const builder = new ReactorClientBuilder$1().withLogger(logger).withSigner(signerConfig).withReactorBuilder(reactorBuilder);
|
|
168
201
|
if (documentModelLoader) builder.withDocumentModelLoader(documentModelLoader);
|
|
169
|
-
|
|
202
|
+
if (createSignaturePolicy) builder.withCreateSignaturePolicy(createSignaturePolicy);
|
|
203
|
+
if (unsupportedStoredDocuments) reactorBuilder.withUnsupportedStoredDocuments(unsupportedStoredDocuments);
|
|
204
|
+
let module;
|
|
205
|
+
try {
|
|
206
|
+
module = await builder.buildModule();
|
|
207
|
+
} catch (error) {
|
|
208
|
+
await discardReactorPGlite();
|
|
209
|
+
throw toStoredDocumentsRefused(error);
|
|
210
|
+
}
|
|
170
211
|
return {
|
|
171
212
|
...module,
|
|
172
213
|
kind: "browser",
|
|
@@ -213,7 +254,7 @@ async function addRemoteDefaultDrive(drive) {
|
|
|
213
254
|
}
|
|
214
255
|
}
|
|
215
256
|
if (driveId && (drive.name || drive.icon)) try {
|
|
216
|
-
const reactorClient =
|
|
257
|
+
const reactorClient = getFullReactorClient();
|
|
217
258
|
if (reactorClient) await waitForDocumentReady(reactorClient, driveId, { timeoutMs: 15e3 });
|
|
218
259
|
await setDriveMetadata(driveId, {
|
|
219
260
|
name: drive.name,
|
|
@@ -237,7 +278,7 @@ async function addLocalDefaultDrive(drive) {
|
|
|
237
278
|
return;
|
|
238
279
|
}
|
|
239
280
|
try {
|
|
240
|
-
const reactorClient =
|
|
281
|
+
const reactorClient = getFullReactorClient();
|
|
241
282
|
if (reactorClient) {
|
|
242
283
|
if (await reactorClient.isDocumentIdTaken(drive.id)) return;
|
|
243
284
|
}
|
|
@@ -357,7 +398,7 @@ async function initFeatureFlags(searchParams) {
|
|
|
357
398
|
"error"
|
|
358
399
|
];
|
|
359
400
|
if (validLogLevels.includes(logLevelParam.toLowerCase())) {
|
|
360
|
-
setLogLevel
|
|
401
|
+
setLogLevel(logLevelParam.toLowerCase());
|
|
361
402
|
logger.info("Log level set to @level via query param", logLevelParam.toLowerCase());
|
|
362
403
|
} else logger.warn("Invalid LOG_LEVEL query param: @param. Valid values: @validLevels", logLevelParam, validLogLevels.join(", "));
|
|
363
404
|
}
|
|
@@ -683,341 +724,33 @@ var PackageDiscoveryService = class {
|
|
|
683
724
|
}
|
|
684
725
|
};
|
|
685
726
|
//#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) {
|
|
727
|
+
//#region src/reactor-worker-name.ts
|
|
728
|
+
const GEN_KEY_PREFIX = "ph-reactor-gen:";
|
|
729
|
+
function genStore() {
|
|
697
730
|
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;
|
|
731
|
+
return globalThis.localStorage;
|
|
702
732
|
} catch {
|
|
703
733
|
return;
|
|
704
734
|
}
|
|
705
735
|
}
|
|
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);
|
|
736
|
+
function workerNameForGen(namespace, gen) {
|
|
1009
737
|
return gen ? `ph-reactor:${namespace}#${gen}` : `ph-reactor:${namespace}`;
|
|
1010
738
|
}
|
|
1011
|
-
function readWorkerGen(namespace) {
|
|
739
|
+
function readWorkerGen(namespace, storage = genStore()) {
|
|
1012
740
|
try {
|
|
1013
|
-
return
|
|
741
|
+
return storage?.getItem(GEN_KEY_PREFIX + namespace) ?? null;
|
|
1014
742
|
} catch {
|
|
1015
743
|
return null;
|
|
1016
744
|
}
|
|
1017
745
|
}
|
|
1018
|
-
|
|
746
|
+
/**
|
|
747
|
+
* Gens are unordered tokens, so a reload moves the gen on only from the one
|
|
748
|
+
* this tab's worker runs as; a stale worker's reload never undoes a newer one.
|
|
749
|
+
*/
|
|
750
|
+
function adoptWorkerGen(namespace, from, to, storage = genStore()) {
|
|
1019
751
|
try {
|
|
1020
|
-
|
|
752
|
+
if (storage?.getItem(GEN_KEY_PREFIX + namespace) !== from) return;
|
|
753
|
+
storage.setItem(GEN_KEY_PREFIX + namespace, to);
|
|
1021
754
|
} catch {}
|
|
1022
755
|
}
|
|
1023
756
|
//#endregion
|
|
@@ -1026,8 +759,44 @@ const PING_INTERVAL_MS = 2e3;
|
|
|
1026
759
|
const PING_DEADLINE_MS = 3e3;
|
|
1027
760
|
const MAX_MISSED_PINGS = 2;
|
|
1028
761
|
/** Sorted so the same set always produces the same fingerprint. */
|
|
1029
|
-
function enabledFlagList(flags) {
|
|
1030
|
-
return Object.entries(
|
|
762
|
+
function enabledFlagList(flags, multiReactor) {
|
|
763
|
+
return Object.entries({
|
|
764
|
+
...flags,
|
|
765
|
+
multiReactor
|
|
766
|
+
}).filter(([, enabled]) => enabled).map(([name]) => name).sort().join(",");
|
|
767
|
+
}
|
|
768
|
+
/** The hello fingerprint; a running worker with a different one retires. */
|
|
769
|
+
function buildWorkerVersion(args) {
|
|
770
|
+
const gitSha = getGitSha();
|
|
771
|
+
const buildId = gitSha !== "unknown" ? gitSha : getVersion();
|
|
772
|
+
return {
|
|
773
|
+
appBuildId: args.workerDigest ? `${buildId}+w.${args.workerDigest}` : buildId,
|
|
774
|
+
rpcProtocolVersion: RPC_PROTOCOL_VERSION,
|
|
775
|
+
models: args.documentModelModules.map((m) => ({
|
|
776
|
+
id: m.documentModel.global.id,
|
|
777
|
+
version: m.version ?? 1
|
|
778
|
+
})),
|
|
779
|
+
featureFlags: enabledFlagList(args.featureFlags, args.multiReactor)
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
/** What the worker's build reads; flags arrive here because it has no config. */
|
|
783
|
+
function buildWorkerConstruct(args) {
|
|
784
|
+
return {
|
|
785
|
+
namespace: args.namespace,
|
|
786
|
+
relationalNamespace: args.relationalNamespace,
|
|
787
|
+
cdnUrl: args.cdnUrl,
|
|
788
|
+
packageSpecs: args.packageSpecs,
|
|
789
|
+
sharedImports: args.sharedImports,
|
|
790
|
+
studioMode: args.studioMode,
|
|
791
|
+
workflowsEnabled: args.workflowsEnabled,
|
|
792
|
+
renownChainId: args.renownChainId,
|
|
793
|
+
featureFlags: args.featureFlags,
|
|
794
|
+
multiReactor: args.multiReactor,
|
|
795
|
+
createSignaturePolicy: args.createSignaturePolicy,
|
|
796
|
+
unsupportedStoredDocuments: args.unsupportedStoredDocuments,
|
|
797
|
+
renownEndpoints: args.renownEndpoints,
|
|
798
|
+
packageSources: args.packageSources
|
|
799
|
+
};
|
|
1031
800
|
}
|
|
1032
801
|
function toReactorIdentity(user) {
|
|
1033
802
|
if (!user) return null;
|
|
@@ -1038,14 +807,17 @@ function toReactorIdentity(user) {
|
|
|
1038
807
|
};
|
|
1039
808
|
}
|
|
1040
809
|
function createWorkerReactorClientModule(args) {
|
|
1041
|
-
const workerUrl = new URL("./reactor.worker.js", import.meta.url);
|
|
1042
|
-
|
|
810
|
+
const workerUrl = args.workerUrl ? new URL(args.workerUrl) : new URL("./reactor.worker.js", import.meta.url);
|
|
811
|
+
const workerGen = readWorkerGen(args.namespace);
|
|
812
|
+
const workerName = workerNameForGen(args.namespace, workerGen);
|
|
813
|
+
console.info(`[reactor-worker] constructing SharedWorker ${workerName} from ${workerUrl.href}`);
|
|
1043
814
|
const worker = new SharedWorker(workerUrl, {
|
|
1044
|
-
name:
|
|
815
|
+
name: workerName,
|
|
1045
816
|
type: "module"
|
|
1046
817
|
});
|
|
1047
818
|
worker.addEventListener("error", (event) => {
|
|
1048
819
|
console.error(`[reactor-worker] SharedWorker failed to load from ${workerUrl.href}`, event.message || event);
|
|
820
|
+
setWorkerConnectionStatus("failed");
|
|
1049
821
|
});
|
|
1050
822
|
worker.port.onmessageerror = (event) => {
|
|
1051
823
|
console.error("[reactor-worker] port message could not be deserialized", event);
|
|
@@ -1056,28 +828,14 @@ function createWorkerReactorClientModule(args) {
|
|
|
1056
828
|
const documentModelRegistry = new DocumentModelRegistry();
|
|
1057
829
|
documentModelRegistry.registerModules(...args.documentModelModules);
|
|
1058
830
|
documentModelRegistry.registerUpgradeManifests(...args.upgradeManifests);
|
|
1059
|
-
const gitSha = getGitSha();
|
|
1060
831
|
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
|
-
},
|
|
832
|
+
version: buildWorkerVersion(args),
|
|
833
|
+
construct: buildWorkerConstruct(args),
|
|
1079
834
|
packages: args.packageSpecs
|
|
1080
|
-
},
|
|
835
|
+
}, (reason, nextGen) => {
|
|
836
|
+
if (nextGen) adoptWorkerGen(args.namespace, workerGen, nextGen);
|
|
837
|
+
args.onReload(reason);
|
|
838
|
+
}, documentModelRegistry);
|
|
1081
839
|
const busProxy = createReactorEventBusProxy(router);
|
|
1082
840
|
const syncManagerProxy = new SyncManagerProxy(router, busProxy);
|
|
1083
841
|
const modelResolver = new DocumentModelResolver(documentModelRegistry, args.documentModelLoader);
|
|
@@ -1099,6 +857,14 @@ function createWorkerReactorClientModule(args) {
|
|
|
1099
857
|
client: clientProxy,
|
|
1100
858
|
adminClient: createWorkerAdminClient(router),
|
|
1101
859
|
inspector: createInspectorProxy(router),
|
|
860
|
+
registerPackages: async (sources) => {
|
|
861
|
+
await router.request((id) => ({
|
|
862
|
+
k: "register-packages",
|
|
863
|
+
id,
|
|
864
|
+
specs: [],
|
|
865
|
+
sources
|
|
866
|
+
}));
|
|
867
|
+
},
|
|
1102
868
|
reactorModule: {
|
|
1103
869
|
documentModelRegistry,
|
|
1104
870
|
syncModule: { syncManager: syncManagerProxy },
|
|
@@ -1121,7 +887,7 @@ function createWorkerReactorClientModule(args) {
|
|
|
1121
887
|
const timer = setTimeout(() => {
|
|
1122
888
|
pingDeadlines.delete(id);
|
|
1123
889
|
missedPings += 1;
|
|
1124
|
-
if (missedPings >= MAX_MISSED_PINGS) setWorkerConnectionStatus("lost");
|
|
890
|
+
if (missedPings >= MAX_MISSED_PINGS && getWorkerConnectionStatus() !== "failed") setWorkerConnectionStatus("lost");
|
|
1125
891
|
}, PING_DEADLINE_MS);
|
|
1126
892
|
pingDeadlines.set(id, timer);
|
|
1127
893
|
router.post({
|
|
@@ -1141,28 +907,73 @@ function createWorkerReactorClientModule(args) {
|
|
|
1141
907
|
};
|
|
1142
908
|
}
|
|
1143
909
|
//#endregion
|
|
1144
|
-
//#region src/utils/
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
910
|
+
//#region src/utils/deleted-selection.ts
|
|
911
|
+
/** Closes the drive or document a Deleted event removed, saying why. */
|
|
912
|
+
function closeDeletedSelection(event, host) {
|
|
913
|
+
if (event.type !== DocumentChangeType.Deleted) return;
|
|
914
|
+
const deletedId = event.context?.childId;
|
|
915
|
+
if (!deletedId) return;
|
|
916
|
+
const gone = event.context?.purged ? "has been erased" : "has been deleted";
|
|
917
|
+
if (host.selectedDriveId && deletedId === host.selectedDriveId) {
|
|
918
|
+
host.closeDrive();
|
|
919
|
+
host.notify(`The drive you were viewing ${gone}`);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (host.selectedNodeId && deletedId === host.selectedNodeId) {
|
|
923
|
+
host.closeNode();
|
|
924
|
+
host.notify(`The document you were editing ${gone}`);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
//#endregion
|
|
928
|
+
//#region src/utils/worker-startup.ts
|
|
929
|
+
/** Runs the worker's startup seed, showing storage-held while its stores are locked elsewhere. */
|
|
930
|
+
async function startupOwningStores(startup, namespaces, watchOptions) {
|
|
931
|
+
const stopWatching = watchStoreLockWait(namespaces, (waiting) => waiting ? setWorkerConnectionStatus("storage-held") : clearStorageHeld(), watchOptions);
|
|
932
|
+
try {
|
|
933
|
+
await startup({ isWaiting: () => getWorkerConnectionStatus() === "storage-held" });
|
|
934
|
+
clearStorageHeld();
|
|
935
|
+
} finally {
|
|
936
|
+
stopWatching();
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
//#endregion
|
|
940
|
+
//#region src/utils/multi-reactor-flag.ts
|
|
941
|
+
function isMultiReactorEnabled() {
|
|
942
|
+
return getRuntimeConfig().connect.instance?.multiReactor ?? false;
|
|
943
|
+
}
|
|
944
|
+
//#endregion
|
|
945
|
+
//#region src/utils/runtime-flag.ts
|
|
946
|
+
function resolveRuntimeFlag(input) {
|
|
1148
947
|
const fromQuery = parseFlag(input.queryParam);
|
|
1149
948
|
if (fromQuery !== void 0) return fromQuery;
|
|
1150
949
|
const fromStore = parseFlag(input.storedValue);
|
|
1151
950
|
if (fromStore !== void 0) return fromStore;
|
|
1152
951
|
return input.configFlag;
|
|
1153
952
|
}
|
|
1154
|
-
function
|
|
1155
|
-
const configFlag =
|
|
953
|
+
function isRuntimeFlagEnabled(keys) {
|
|
954
|
+
const configFlag = keys.readConfigFlag();
|
|
1156
955
|
if (typeof window === "undefined") return configFlag;
|
|
1157
|
-
const queryParam = new URLSearchParams(window.location.search).get(
|
|
1158
|
-
const enabled =
|
|
956
|
+
const queryParam = new URLSearchParams(window.location.search).get(keys.queryKey);
|
|
957
|
+
const enabled = resolveRuntimeFlag({
|
|
1159
958
|
configFlag,
|
|
1160
959
|
queryParam,
|
|
1161
|
-
storedValue:
|
|
960
|
+
storedValue: readStoredValue(keys.storageKey)
|
|
1162
961
|
});
|
|
1163
|
-
if (parseFlag(queryParam) !== void 0)
|
|
962
|
+
if (parseFlag(queryParam) !== void 0) persistStoredValue(keys.storageKey, enabled);
|
|
1164
963
|
return enabled;
|
|
1165
964
|
}
|
|
965
|
+
function readStoredValue(storageKey) {
|
|
966
|
+
try {
|
|
967
|
+
return window.localStorage.getItem(storageKey);
|
|
968
|
+
} catch {
|
|
969
|
+
return null;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
function persistStoredValue(storageKey, enabled) {
|
|
973
|
+
try {
|
|
974
|
+
window.localStorage.setItem(storageKey, enabled ? "true" : "false");
|
|
975
|
+
} catch {}
|
|
976
|
+
}
|
|
1166
977
|
function parseFlag(value) {
|
|
1167
978
|
if (value === null || value === void 0) return;
|
|
1168
979
|
const normalized = value.trim().toLowerCase();
|
|
@@ -1170,6 +981,194 @@ function parseFlag(value) {
|
|
|
1170
981
|
if (normalized === "false" || normalized === "0") return false;
|
|
1171
982
|
}
|
|
1172
983
|
//#endregion
|
|
984
|
+
//#region src/utils/reactor-worker-flag.ts
|
|
985
|
+
const REACTOR_WORKER_QUERY_KEY = "reactorWorker";
|
|
986
|
+
const REACTOR_WORKER_STORAGE_KEY = "ph:reactorWorker";
|
|
987
|
+
function isReactorWorkerEnabled() {
|
|
988
|
+
return isRuntimeFlagEnabled({
|
|
989
|
+
queryKey: REACTOR_WORKER_QUERY_KEY,
|
|
990
|
+
storageKey: REACTOR_WORKER_STORAGE_KEY,
|
|
991
|
+
readConfigFlag: () => getRuntimeConfig().connect.instance?.reactorWorker ?? false
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
//#endregion
|
|
995
|
+
//#region src/utils/reactor-worker-url.ts
|
|
996
|
+
/**
|
|
997
|
+
* Stable path of the prebuilt reactor SharedWorker bundle, relative to the
|
|
998
|
+
* deploy base. `ph connect build` emits it next to `__vendor__/`; the dev
|
|
999
|
+
* server serves it from the same path, building lazily on first request.
|
|
1000
|
+
*/
|
|
1001
|
+
const REACTOR_WORKER_BUNDLE_PATH = "__reactor_worker__/reactor.worker.js";
|
|
1002
|
+
/** Written beside the bundle by the prebuild; carries its `sourceDigest`. */
|
|
1003
|
+
const REACTOR_WORKER_META_PATH = "__reactor_worker__/worker-meta.json";
|
|
1004
|
+
/** `path` under the deploy base, absolute against `origin`. */
|
|
1005
|
+
function joinBase(baseUrl, path, origin) {
|
|
1006
|
+
return new URL(`${baseUrl}/${path}`.replace(/\/{2,}/g, "/"), origin);
|
|
1007
|
+
}
|
|
1008
|
+
/** The bundle's URL under the deploy base, absolute against the page origin. */
|
|
1009
|
+
function packagedReactorWorkerUrl(baseUrl, origin) {
|
|
1010
|
+
return joinBase(baseUrl, REACTOR_WORKER_BUNDLE_PATH, origin);
|
|
1011
|
+
}
|
|
1012
|
+
function isWorkerBundleResponse(probe) {
|
|
1013
|
+
return probe.ok && (probe.contentType ?? "").includes("javascript");
|
|
1014
|
+
}
|
|
1015
|
+
/** Null when the deployment serves no bundle metadata (SPA HTML, error status, bad JSON). */
|
|
1016
|
+
async function resolvePackagedReactorWorker(baseUrl) {
|
|
1017
|
+
const origin = window.location.origin;
|
|
1018
|
+
try {
|
|
1019
|
+
const res = await fetch(joinBase(baseUrl, REACTOR_WORKER_META_PATH, origin), { cache: "no-cache" });
|
|
1020
|
+
if (!res.ok || !(res.headers.get("content-type") ?? "").includes("json")) return null;
|
|
1021
|
+
const meta = await res.json();
|
|
1022
|
+
if (typeof meta?.sourceDigest !== "string") return null;
|
|
1023
|
+
return {
|
|
1024
|
+
url: packagedReactorWorkerUrl(baseUrl, origin).href,
|
|
1025
|
+
sourceDigest: meta.sourceDigest
|
|
1026
|
+
};
|
|
1027
|
+
} catch {
|
|
1028
|
+
return null;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
function selectReactorWorkerSource({ packaged, bundle }) {
|
|
1032
|
+
if (bundle) return {
|
|
1033
|
+
kind: "bundle",
|
|
1034
|
+
url: bundle.url,
|
|
1035
|
+
digest: bundle.sourceDigest
|
|
1036
|
+
};
|
|
1037
|
+
return packaged ? { kind: "unavailable" } : { kind: "source" };
|
|
1038
|
+
}
|
|
1039
|
+
//#endregion
|
|
1040
|
+
//#region src/utils/worker-package-sources.ts
|
|
1041
|
+
/**
|
|
1042
|
+
* Where `ph connect build` publishes the prebuilt local-package model bundles
|
|
1043
|
+
* and the manifest naming them, next to the worker bundle itself.
|
|
1044
|
+
*/
|
|
1045
|
+
const WORKER_PACKAGES_DIR = "__reactor_worker__/packages/";
|
|
1046
|
+
const WORKER_PACKAGES_MANIFEST = `${WORKER_PACKAGES_DIR}manifest.json`;
|
|
1047
|
+
/**
|
|
1048
|
+
* The project's own models entry as the dev server serves it. Vite's
|
|
1049
|
+
* transform pipeline absolutizes its chunk imports and rewrites bare
|
|
1050
|
+
* specifiers to /node_modules/.vite/deps/ URLs, so the result is directly
|
|
1051
|
+
* importable from a worker - the dev server is the bundler.
|
|
1052
|
+
*/
|
|
1053
|
+
const DEV_PROJECT_MODELS_PATH = "dist/browser/document-models/index.js";
|
|
1054
|
+
/** Source name for the project's own package (vetra's local package). */
|
|
1055
|
+
const PROJECT_PACKAGE_SOURCE_NAME = "ph:project-package";
|
|
1056
|
+
async function probeJavaScript(url) {
|
|
1057
|
+
try {
|
|
1058
|
+
const res = await fetch(url, { method: "HEAD" });
|
|
1059
|
+
return isWorkerBundleResponse({
|
|
1060
|
+
ok: res.ok,
|
|
1061
|
+
contentType: res.headers.get("content-type")
|
|
1062
|
+
});
|
|
1063
|
+
} catch {
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
async function fetchManifest(baseUrl) {
|
|
1068
|
+
try {
|
|
1069
|
+
const res = await fetch(joinBase(baseUrl, WORKER_PACKAGES_MANIFEST, window.location.origin));
|
|
1070
|
+
if (!res.ok) return [];
|
|
1071
|
+
const parsed = await res.json();
|
|
1072
|
+
if (!Array.isArray(parsed)) return [];
|
|
1073
|
+
return parsed.filter((entry) => typeof entry === "object" && entry !== null && typeof entry.name === "string" && typeof entry.file === "string");
|
|
1074
|
+
} catch {
|
|
1075
|
+
return [];
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* The project's models source as served right now, with a cache-busting query
|
|
1080
|
+
* so a watch rebuild's re-registration imports the fresh file rather than the
|
|
1081
|
+
* worker's cached module. Null when the dev server does not serve one.
|
|
1082
|
+
*/
|
|
1083
|
+
async function resolveDevProjectSource(baseUrl) {
|
|
1084
|
+
const url = joinBase(baseUrl, DEV_PROJECT_MODELS_PATH, window.location.origin);
|
|
1085
|
+
if (!await probeJavaScript(url)) return null;
|
|
1086
|
+
url.searchParams.set("t", String(Date.now()));
|
|
1087
|
+
return {
|
|
1088
|
+
name: PROJECT_PACKAGE_SOURCE_NAME,
|
|
1089
|
+
url: url.href
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* URL-addressed packages the worker should load: the production manifest's
|
|
1094
|
+
* prebuilt bundles when deployed, plus the dev server's live project models
|
|
1095
|
+
* when present. Either list may be empty; both empty means this deployment
|
|
1096
|
+
* has no local packages (or predates the feature).
|
|
1097
|
+
*/
|
|
1098
|
+
async function resolveLocalPackageSources(baseUrl) {
|
|
1099
|
+
const [manifest, devProject] = await Promise.all([fetchManifest(baseUrl), resolveDevProjectSource(baseUrl)]);
|
|
1100
|
+
const sources = manifest.map((entry) => ({
|
|
1101
|
+
name: entry.name,
|
|
1102
|
+
version: entry.version,
|
|
1103
|
+
url: joinBase(baseUrl, `${WORKER_PACKAGES_DIR}${entry.file}`, window.location.origin).href
|
|
1104
|
+
}));
|
|
1105
|
+
if (devProject) sources.push(devProject);
|
|
1106
|
+
return sources;
|
|
1107
|
+
}
|
|
1108
|
+
/** Calls `onChange` only when the local package is replaced (an HMR rebuild), not on every package notification. */
|
|
1109
|
+
function subscribeLocalPackageChanges(manager, onChange) {
|
|
1110
|
+
let last = manager.localPackage;
|
|
1111
|
+
return manager.subscribe(() => {
|
|
1112
|
+
const current = manager.localPackage;
|
|
1113
|
+
if (current === last) return;
|
|
1114
|
+
last = current;
|
|
1115
|
+
onChange();
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
//#endregion
|
|
1119
|
+
//#region src/store/app-reactor-client.ts
|
|
1120
|
+
const loadMultiReactor = () => import("./multi-reactor-CcMPtKrf.js");
|
|
1121
|
+
/** Flag off: the local client, and the router module is never loaded. */
|
|
1122
|
+
async function selectAppReactorClient(params) {
|
|
1123
|
+
if (!params.multiReactor) {
|
|
1124
|
+
if (window.ph?.fullReactorClient) setFullReactorClient(void 0);
|
|
1125
|
+
return params.module.client;
|
|
1126
|
+
}
|
|
1127
|
+
setFullReactorClient(void 0);
|
|
1128
|
+
const routed = await buildRouter(params);
|
|
1129
|
+
setFullReactorClient(routed);
|
|
1130
|
+
return routed ?? params.module.client;
|
|
1131
|
+
}
|
|
1132
|
+
/** A Switchboard that cannot answer must not fail boot: list the tab's drives. */
|
|
1133
|
+
async function getAppDrives(client, local) {
|
|
1134
|
+
if (client === local) return getDrives(local);
|
|
1135
|
+
try {
|
|
1136
|
+
return await getDrives(client);
|
|
1137
|
+
} catch (error) {
|
|
1138
|
+
logger.warn("Could not list drives through the router; listing the local reactor's: @error", error);
|
|
1139
|
+
return getDrives(local);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
async function refreshAppDrives(client, local) {
|
|
1143
|
+
if (client === local) return refreshReactorDataClient(client);
|
|
1144
|
+
setDrives(await getAppDrives(client, local));
|
|
1145
|
+
}
|
|
1146
|
+
async function buildRouter(params) {
|
|
1147
|
+
if (!params.remoteDriveUrl) {
|
|
1148
|
+
logger.warn("multiReactor is on but no remote drive URL is configured; using the local reactor only");
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
let multiReactor;
|
|
1152
|
+
try {
|
|
1153
|
+
multiReactor = await (params.loadRouter ?? loadMultiReactor)();
|
|
1154
|
+
} catch (error) {
|
|
1155
|
+
logger.error("Could not load the multi-reactor router: @error", error);
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
const remoteGraphqlUrl = multiReactor.deriveSwitchboardGraphqlUrl(params.remoteDriveUrl);
|
|
1159
|
+
if (!remoteGraphqlUrl) {
|
|
1160
|
+
logger.warn("multiReactor is on but the remote drive URL @url does not parse; using the local reactor only", params.remoteDriveUrl);
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
logger.info("Multi-reactor routing to @url", remoteGraphqlUrl);
|
|
1164
|
+
return multiReactor.buildMultiReactorClient({
|
|
1165
|
+
module: params.module,
|
|
1166
|
+
remoteGraphqlUrl,
|
|
1167
|
+
signer: params.signer,
|
|
1168
|
+
documentModelModules: params.documentModelModules
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
//#endregion
|
|
1173
1172
|
//#region src/store/processor-host-module.ts
|
|
1174
1173
|
var NullAttachmentService = class {
|
|
1175
1174
|
reserve() {
|
|
@@ -1276,7 +1275,10 @@ async function clearReactorStorage() {
|
|
|
1276
1275
|
await module.adminClient.clearStorage();
|
|
1277
1276
|
return;
|
|
1278
1277
|
}
|
|
1279
|
-
if (module?.kind === "browser")
|
|
1278
|
+
if (module?.kind === "browser") {
|
|
1279
|
+
const reactorModule = module.reactorModule;
|
|
1280
|
+
await closeWithin(reactorModule?.groupCommitStorage ?? reactorModule?.pg);
|
|
1281
|
+
}
|
|
1280
1282
|
const targets = (await indexedDB.databases()).map((d) => d.name).filter((n) => !!n && !n.startsWith("ph-pglite-backup::") && /pglite|reactor/i.test(n));
|
|
1281
1283
|
await Promise.all(targets.map((name) => new Promise((resolve) => {
|
|
1282
1284
|
const req = indexedDB.deleteDatabase(name);
|
|
@@ -1305,9 +1307,12 @@ async function createReactor(localPackage) {
|
|
|
1305
1307
|
const runtimeConfig = getRuntimeConfig();
|
|
1306
1308
|
const packageManager = new BrowserPackageManager(phGlobalConfig.routerBasename ?? "", runtimeConfig.packageRegistryUrl ?? null);
|
|
1307
1309
|
setVetraPackageManager(packageManager);
|
|
1308
|
-
await packageManager.init(localPackage, runtimeConfig.localPackage?.version, phGlobalConfig.studioMode);
|
|
1310
|
+
await packageManager.init(localPackage, runtimeConfig.localPackage?.version, phGlobalConfig.studioMode, connectConfig.workflowsEnabled);
|
|
1309
1311
|
try {
|
|
1310
|
-
const { default: registerBundledPackages } = await import(
|
|
1312
|
+
const { default: registerBundledPackages } = await import(
|
|
1313
|
+
/* @vite-ignore */
|
|
1314
|
+
"ph-bundled-packages-virtual"
|
|
1315
|
+
);
|
|
1311
1316
|
registerBundledPackages(packageManager);
|
|
1312
1317
|
} catch {}
|
|
1313
1318
|
const remotePackages = runtimeConfig.packages.filter((p) => p.provider !== "local").map((p) => p.version ? `${p.packageName}@${p.version}` : p.packageName);
|
|
@@ -1325,55 +1330,107 @@ async function createReactor(localPackage) {
|
|
|
1325
1330
|
const reactorFeatureFlags = runtimeConfig.connect?.reactor?.featureFlags ?? {};
|
|
1326
1331
|
const enabledReactorFlags = Object.entries(reactorFeatureFlags).filter(([, enabled]) => enabled).map(([name]) => name);
|
|
1327
1332
|
if (enabledReactorFlags.length > 0) logger.info(`Reactor feature flags: ${enabledReactorFlags.join(", ")}`);
|
|
1333
|
+
const createSignaturePolicy = runtimeConfig.connect?.reactor?.createSignaturePolicy;
|
|
1334
|
+
const unsupportedStoredDocuments = runtimeConfig.connect?.reactor?.unsupportedStoredDocuments;
|
|
1335
|
+
const renownEndpoints = {
|
|
1336
|
+
renownUrl: phGlobalConfig.renownUrl,
|
|
1337
|
+
switchboardUrl: phGlobalConfig.switchboardUrl
|
|
1338
|
+
};
|
|
1339
|
+
const multiReactor = isMultiReactorEnabled();
|
|
1328
1340
|
let reactorClientModule;
|
|
1329
1341
|
if (isReactorWorkerEnabled()) {
|
|
1330
1342
|
const packageSpecs = packageManager.getRegistryPackages().map((p) => p.version ? `${p.name}@${p.version}` : p.name);
|
|
1331
1343
|
const registryClient = new RegistryClient(packageManager.cdnUrl ?? "");
|
|
1344
|
+
const documentModelLoader = { async load(documentType) {
|
|
1345
|
+
const names = packageManager.cdnUrl ? await registryClient.getPackagesByDocumentType(documentType) : [];
|
|
1346
|
+
for (const name of names) {
|
|
1347
|
+
const result = await packageManager.addPackage(name);
|
|
1348
|
+
if (result.type === "error") throw new Error(`Failed to install package "${name}" for document model: ${documentType}`, { cause: result.error });
|
|
1349
|
+
}
|
|
1350
|
+
const module = packageManager.packages.flatMap((p) => p.documentModels).find((m) => m.documentModel.global.id === documentType);
|
|
1351
|
+
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"})`);
|
|
1352
|
+
return module;
|
|
1353
|
+
} };
|
|
1354
|
+
const [sharedDeps, packagedWorker, packageSources] = await Promise.all([
|
|
1355
|
+
getSharedDeps(),
|
|
1356
|
+
resolvePackagedReactorWorker(import.meta.env.BASE_URL),
|
|
1357
|
+
resolveLocalPackageSources(import.meta.env.BASE_URL)
|
|
1358
|
+
]);
|
|
1359
|
+
const workerSource = selectReactorWorkerSource({
|
|
1360
|
+
packaged: isPackagedConnectDist(),
|
|
1361
|
+
bundle: packagedWorker
|
|
1362
|
+
});
|
|
1363
|
+
if (workerSource.kind === "unavailable") {
|
|
1364
|
+
window.ph.loading = false;
|
|
1365
|
+
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");
|
|
1366
|
+
}
|
|
1332
1367
|
const workerClient = createWorkerReactorClientModule({
|
|
1368
|
+
workerUrl: workerSource.kind === "bundle" ? workerSource.url : void 0,
|
|
1369
|
+
workerDigest: workerSource.kind === "bundle" ? workerSource.digest : void 0,
|
|
1370
|
+
packageSources,
|
|
1333
1371
|
namespace: REACTOR_INSTANCE_NAMESPACE,
|
|
1334
1372
|
relationalNamespace: RELATIONAL_PGLITE_NAME,
|
|
1335
1373
|
cdnUrl: packageManager.cdnUrl ?? "",
|
|
1336
1374
|
packageSpecs,
|
|
1375
|
+
sharedImports: sharedDeps?.imports,
|
|
1337
1376
|
studioMode: phGlobalConfig.studioMode,
|
|
1377
|
+
workflowsEnabled: connectConfig.workflowsEnabled,
|
|
1338
1378
|
renownChainId,
|
|
1339
1379
|
featureFlags: reactorFeatureFlags,
|
|
1380
|
+
multiReactor,
|
|
1381
|
+
createSignaturePolicy,
|
|
1382
|
+
unsupportedStoredDocuments,
|
|
1383
|
+
renownEndpoints,
|
|
1340
1384
|
documentModelModules,
|
|
1341
1385
|
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
|
-
} },
|
|
1386
|
+
documentModelLoader,
|
|
1352
1387
|
renown,
|
|
1353
|
-
onReload: (reason
|
|
1388
|
+
onReload: (reason) => {
|
|
1354
1389
|
logger.warn("Reactor worker requested reload: @reason", reason);
|
|
1355
|
-
|
|
1356
|
-
window.location.reload();
|
|
1390
|
+
reloadForWorker(reason, () => window.location.reload());
|
|
1357
1391
|
}
|
|
1358
1392
|
});
|
|
1359
1393
|
reactorClientModule = workerClient.reactorClientModule;
|
|
1394
|
+
const { registerPackages } = workerClient.reactorClientModule;
|
|
1395
|
+
subscribeLocalPackageChanges(packageManager, () => {
|
|
1396
|
+
(async () => {
|
|
1397
|
+
const source = await resolveDevProjectSource(import.meta.env.BASE_URL);
|
|
1398
|
+
if (!source) return;
|
|
1399
|
+
try {
|
|
1400
|
+
await registerPackages([source]);
|
|
1401
|
+
} catch (error) {
|
|
1402
|
+
logger.error("Failed to re-register project models in the reactor worker: @error", error);
|
|
1403
|
+
}
|
|
1404
|
+
})();
|
|
1405
|
+
});
|
|
1360
1406
|
try {
|
|
1361
|
-
await workerClient.syncManagerProxy.startup();
|
|
1407
|
+
await startupOwningStores((options) => workerClient.syncManagerProxy.startup(options), [REACTOR_INSTANCE_NAMESPACE, RELATIONAL_PGLITE_NAME]);
|
|
1362
1408
|
} catch (error) {
|
|
1363
1409
|
window.ph.loading = false;
|
|
1364
1410
|
logger.error("Reactor worker failed to start: @error", error);
|
|
1365
1411
|
throw error;
|
|
1366
1412
|
}
|
|
1367
|
-
} else reactorClientModule = await createBrowserReactor(documentModelModules, upgradeManifests, renown, reactorFeatureFlags, discoveryService);
|
|
1368
|
-
const
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1413
|
+
} else reactorClientModule = await createBrowserReactor(documentModelModules, upgradeManifests, renown, reactorFeatureFlags, discoveryService, createSignaturePolicy, renownEndpoints, unsupportedStoredDocuments, multiReactor);
|
|
1414
|
+
const appReactorClient = await selectAppReactorClient({
|
|
1415
|
+
multiReactor,
|
|
1416
|
+
module: reactorClientModule,
|
|
1417
|
+
remoteDriveUrl: phGlobalConfig.defaultDrivesUrl,
|
|
1418
|
+
signer: renown.signer,
|
|
1419
|
+
documentModelModules
|
|
1420
|
+
});
|
|
1421
|
+
const drives = await getAppDrives(appReactorClient, reactorClientModule.client);
|
|
1422
|
+
const didFromUrl = getDidFromUrl();
|
|
1423
|
+
await login(didFromUrl, renown);
|
|
1424
|
+
const documentCache = new DocumentCache(appReactorClient);
|
|
1425
|
+
const basePath = phGlobalConfig.basePath ?? "/";
|
|
1426
|
+
const routerBasename = phGlobalConfig.routerBasename ?? "/";
|
|
1427
|
+
const mergedGlobalConfig = buildPHGlobalConfig(basePath, routerBasename, runtimeConfig.connect ?? {});
|
|
1428
|
+
setDefaultPHGlobalConfig(mergedGlobalConfig);
|
|
1372
1429
|
const path = window.location.pathname;
|
|
1373
1430
|
const driveSlug = extractDriveSlugFromPath(path);
|
|
1374
1431
|
const nodeSlug = extractNodeSlugFromPath(path);
|
|
1375
1432
|
setReactorClientModule(reactorClientModule);
|
|
1376
|
-
setReactorClient(
|
|
1433
|
+
setReactorClient(appReactorClient);
|
|
1377
1434
|
const _defaultDrivesUrl = phGlobalConfig.defaultDrivesUrl;
|
|
1378
1435
|
if (_defaultDrivesUrl) {
|
|
1379
1436
|
let switchboardOrigin;
|
|
@@ -1385,11 +1442,12 @@ async function createReactor(localPackage) {
|
|
|
1385
1442
|
if (!renown.user) return void 0;
|
|
1386
1443
|
return renown.getBearerToken({ expiresIn: 10 });
|
|
1387
1444
|
};
|
|
1388
|
-
|
|
1445
|
+
const attachmentService = createRemoteAttachmentService({
|
|
1389
1446
|
remoteUrl: switchboardOrigin,
|
|
1390
1447
|
jwtHandler: attachmentJwtHandler,
|
|
1391
1448
|
uploadTransport: createXhrUploadTransport()
|
|
1392
|
-
})
|
|
1449
|
+
});
|
|
1450
|
+
setAttachmentService(attachmentService);
|
|
1393
1451
|
}
|
|
1394
1452
|
}
|
|
1395
1453
|
setDocumentCache(documentCache);
|
|
@@ -1402,28 +1460,21 @@ async function createReactor(localPackage) {
|
|
|
1402
1460
|
if (remoteUrl) addRemoteDrive(remoteUrl, void 0).catch((error) => console.error(`Failed to add remote drive from ${remoteUrl}:`, error));
|
|
1403
1461
|
setSelectedDrive(driveSlug);
|
|
1404
1462
|
setSelectedNode(nodeSlug);
|
|
1405
|
-
const reactorClient =
|
|
1463
|
+
const reactorClient = appReactorClient;
|
|
1406
1464
|
for (const driveType of DRIVE_DOCUMENT_TYPES) reactorClient.subscribe({ type: driveType }, (event) => {
|
|
1407
1465
|
logger.verbose("ReactorClient subscription event: @event", event);
|
|
1408
|
-
refreshReactorDataClient(
|
|
1466
|
+
refreshReactorDataClient(appReactorClient).catch((e) => logger.error("@error", e));
|
|
1409
1467
|
});
|
|
1410
1468
|
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
|
-
}
|
|
1469
|
+
closeDeletedSelection(event, {
|
|
1470
|
+
selectedDriveId: window.ph?.selectedDriveId,
|
|
1471
|
+
selectedNodeId: window.ph?.selectedNodeId,
|
|
1472
|
+
closeDrive: () => setSelectedDrive(void 0),
|
|
1473
|
+
closeNode: () => setSelectedNode(void 0),
|
|
1474
|
+
notify: (message) => toast(message)
|
|
1475
|
+
});
|
|
1425
1476
|
});
|
|
1426
|
-
await
|
|
1477
|
+
await refreshAppDrives(appReactorClient, reactorClientModule.client);
|
|
1427
1478
|
const packagesWithProcessorFactories = packageManager.packages.filter((pkg) => pkg.processorFactory !== void 0);
|
|
1428
1479
|
const reactorModule = reactorClientModule.kind === "browser" ? reactorClientModule.reactorModule : void 0;
|
|
1429
1480
|
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);
|
|
@@ -1460,5 +1511,5 @@ function getDriveUrl() {
|
|
|
1460
1511
|
//#endregion
|
|
1461
1512
|
export { createReactor as n, clearReactorStorage as t };
|
|
1462
1513
|
|
|
1463
|
-
//# sourceMappingURL=reactor-
|
|
1464
|
-
//# debugId=
|
|
1514
|
+
//# sourceMappingURL=reactor-DfTuWWWD.js.map
|
|
1515
|
+
//# debugId=4f04d9df-7531-5160-a235-8aa9982f7af2
|