@powerhousedao/connect 6.2.3-dev.9 → 6.2.3-dev.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/{AddDriveModal-xAw48kdl.js → AddDriveModal-zMepHdWt.js} +44 -18
- package/dist/AddDriveModal-zMepHdWt.js.map +1 -0
- package/dist/{ClearStorageModal-C1BXHTq3.js → ClearStorageModal-CDXvQxfJ.js} +11 -13
- package/dist/ClearStorageModal-CDXvQxfJ.js.map +1 -0
- package/dist/{ConfirmDocumentUpgradeModal-FUOhZsk7.js → ConfirmDocumentUpgradeModal-CoixS60F.js} +9 -8
- package/dist/ConfirmDocumentUpgradeModal-CoixS60F.js.map +1 -0
- package/dist/{CookiesPolicyModal-BpyPPyxS.js → CookiesPolicyModal-BpFjYc7T.js} +5 -5
- package/dist/{CookiesPolicyModal-BpyPPyxS.js.map → CookiesPolicyModal-BpFjYc7T.js.map} +1 -1
- package/dist/CreateDocumentModal-CiIW3pzx.js +45 -0
- package/dist/CreateDocumentModal-CiIW3pzx.js.map +1 -0
- package/dist/{DebugSettingsModal-ClqHzcxM.js → DebugSettingsModal-B02UGneJ.js} +11 -11
- package/dist/DebugSettingsModal-B02UGneJ.js.map +1 -0
- package/dist/{DeleteDriveModal-Dug84t1j.js → DeleteDriveModal-1pAIayG_.js} +7 -7
- package/dist/DeleteDriveModal-1pAIayG_.js.map +1 -0
- package/dist/{DeleteItemModal-mMzy3V8o.js → DeleteItemModal-BUpqmFxS.js} +8 -8
- package/dist/DeleteItemModal-BUpqmFxS.js.map +1 -0
- package/dist/{DisclaimerModal-DvpD5dPM.js → DisclaimerModal-TIJXRYLF.js} +7 -7
- package/dist/DisclaimerModal-TIJXRYLF.js.map +1 -0
- package/dist/{DocumentVersionUnsupportedModal-C3Q0V75l.js → DocumentVersionUnsupportedModal-DH9Zzsyw.js} +6 -6
- package/dist/DocumentVersionUnsupportedModal-DH9Zzsyw.js.map +1 -0
- package/dist/{DownloadDocumentWithErrorsModal-IKl0ljQb.js → DownloadDocumentWithErrorsModal-Beh-xw8B.js} +8 -7
- package/dist/DownloadDocumentWithErrorsModal-Beh-xw8B.js.map +1 -0
- package/dist/{DriveAuthRequiredModal-DVK7ZQzO.js → DriveAuthRequiredModal-XTcoJKvj.js} +7 -7
- package/dist/DriveAuthRequiredModal-XTcoJKvj.js.map +1 -0
- package/dist/DriveSettingsModal-CGZQhzBa.js +127 -0
- package/dist/DriveSettingsModal-CGZQhzBa.js.map +1 -0
- package/dist/FloatingTanStackRouterDevtools-CqogiFob-dxj8lrTP.js +2565 -0
- package/dist/FloatingTanStackRouterDevtools-CqogiFob-dxj8lrTP.js.map +1 -0
- package/dist/{InspectorModal-7FQBTEzt.js → InspectorModal-BECRjBej.js} +71 -31
- package/dist/InspectorModal-BECRjBej.js.map +1 -0
- package/dist/{LoginModal-CybbOm3N.js → LoginModal-O06ZvWFI.js} +8 -8
- package/dist/LoginModal-O06ZvWFI.js.map +1 -0
- package/dist/{OpenFileDocumentsModal-DGaYJpXW.js → OpenFileDocumentsModal-DJsC1oR1.js} +22 -16
- package/dist/OpenFileDocumentsModal-DJsC1oR1.js.map +1 -0
- package/dist/{UpgradeDriveModal-_8t9slxQ.js → UpgradeDriveModal-CCWKp5yn.js} +7 -7
- package/dist/UpgradeDriveModal-CCWKp5yn.js.map +1 -0
- package/dist/ai-tools-CSRAzPuU.js +41 -0
- package/dist/ai-tools-CSRAzPuU.js.map +1 -0
- package/dist/ai-tools-FwcvsTEc.js +4 -0
- package/dist/app-loader-B43UTqh-.js +4 -0
- package/dist/app-loader-DSYNwqKv.js +1254 -0
- package/dist/app-loader-DSYNwqKv.js.map +1 -0
- package/dist/app-skeleton-CMUP2zaz.js +132 -0
- package/dist/app-skeleton-CMUP2zaz.js.map +1 -0
- package/dist/app-skeleton-CdD1m8G3.js +4 -0
- package/dist/boot-JeVIsfm1.js +233 -0
- package/dist/boot-JeVIsfm1.js.map +1 -0
- package/dist/buffer-DNTcuap_.js +66 -0
- package/dist/buffer-DNTcuap_.js.map +1 -0
- package/dist/{build-info-D9_h0032.js → build-info-D0xL66Ow.js} +10 -6
- package/dist/build-info-D0xL66Ow.js.map +1 -0
- package/dist/components-DodkBJEK.js +121 -0
- package/dist/components-DodkBJEK.js.map +1 -0
- package/dist/{connect.config-DaHDEUrw.js → connect.config-DL9nKtlW.js} +28 -15
- package/dist/connect.config-DL9nKtlW.js.map +1 -0
- package/dist/{connection-state-3w4liC1X.js → connection-state-B6YMctkg.js} +20 -9
- package/dist/connection-state-B6YMctkg.js.map +1 -0
- package/dist/context-De2EB1AA-Ni0d829Q.js +1759 -0
- package/dist/context-De2EB1AA-Ni0d829Q.js.map +1 -0
- package/dist/{cookie-banner-BH6bIq24.js → cookie-banner-NclLYtB0.js} +7 -7
- package/dist/{cookie-banner-BH6bIq24.js.map → cookie-banner-NclLYtB0.js.map} +1 -1
- package/dist/document-editor-container-BuUPe031.js +4 -0
- package/dist/document-editor-container-C0lE2N2j.js +310 -0
- package/dist/document-editor-container-C0lE2N2j.js.map +1 -0
- package/dist/drive-icon-BIpd8edR.js +49 -0
- package/dist/drive-icon-BIpd8edR.js.map +1 -0
- package/dist/drive-placements-DjeVpTTm.js +38 -0
- package/dist/drive-placements-DjeVpTTm.js.map +1 -0
- package/dist/error-boundary-BsUBww61.js +155 -0
- package/dist/error-boundary-BsUBww61.js.map +1 -0
- package/dist/esm-BDACZntJ.js +148 -0
- package/dist/esm-BDACZntJ.js.map +1 -0
- package/dist/generic.d.ts +140 -0
- package/dist/generic.d.ts.map +1 -0
- package/dist/generic.js +31 -0
- package/dist/generic.js.map +1 -0
- package/dist/{i18n-CWO0vYVd.js → i18n-D9WYPgk9.js} +4 -4
- package/dist/{i18n-CWO0vYVd.js.map → i18n-D9WYPgk9.js.map} +1 -1
- package/dist/index-D7c2WAbn.d.ts +4 -0
- package/dist/layout-Dj3_KscE.js +5 -0
- package/dist/layout.d.ts +3 -0
- package/dist/layout.js +4 -0
- package/dist/{load-Cu7S9GPc.js → load-DWVtW2FC.js} +48 -46
- package/dist/load-DWVtW2FC.js.map +1 -0
- package/dist/load-runtime-config-sUkpYMDx.js +14 -0
- package/dist/load-runtime-config-sUkpYMDx.js.map +1 -0
- package/dist/main.d.ts +2 -1
- package/dist/main.js +8 -8
- package/dist/main.js.map +1 -1
- package/dist/open-file-uploads-B5pr1sA2.js +183 -0
- package/dist/open-file-uploads-B5pr1sA2.js.map +1 -0
- package/dist/package-manager-DWRRy1lv.js +543 -0
- package/dist/package-manager-DWRRy1lv.js.map +1 -0
- package/dist/{pglite-major-B39aOEiE.js → pglite-major-pao-ozRo.js} +23 -5
- package/dist/pglite-major-pao-ozRo.js.map +1 -0
- package/dist/{pglite-migrate-core-Boxqqx-c.js → pglite-migrate-core-B6FqmhH8.js} +9 -7
- package/dist/pglite-migrate-core-B6FqmhH8.js.map +1 -0
- package/dist/{pglite-seed-BqAUvNFw.js → pglite-seed-Ben-06-w.js} +4 -4
- package/dist/{pglite-seed-BqAUvNFw.js.map → pglite-seed-Ben-06-w.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-configs.d.ts +242 -0
- package/dist/plugin-configs.d.ts.map +1 -0
- package/dist/plugin-configs.js +26 -0
- package/dist/plugin-configs.js.map +1 -0
- package/dist/plugins-BXcwZXcP.js +264 -0
- package/dist/plugins-BXcwZXcP.js.map +1 -0
- package/dist/{preferences-store-_5Cw4_YV.js → preferences-store-DxYAnGCc.js} +6 -25
- package/dist/preferences-store-DxYAnGCc.js.map +1 -0
- package/dist/prerender.d.ts +38 -0
- package/dist/prerender.d.ts.map +1 -0
- package/dist/prerender.js +195 -0
- package/dist/prerender.js.map +1 -0
- package/dist/prerendered-shell-peKE7AqI.js +51 -0
- package/dist/prerendered-shell-peKE7AqI.js.map +1 -0
- package/dist/{pwa-manifest-link-DIgOSo2Q.js → pwa-manifest-link-DNwWvnLV.js} +5 -5
- package/dist/{pwa-manifest-link-DIgOSo2Q.js.map → pwa-manifest-link-DNwWvnLV.js.map} +1 -1
- package/dist/reactor-chat-B0IFAanh.js +15 -0
- package/dist/reactor-chat-B0IFAanh.js.map +1 -0
- package/dist/reactor-wOiLUmuW.js +1639 -0
- package/dist/reactor-wOiLUmuW.js.map +1 -0
- package/dist/reactor.worker.d.ts +2 -1
- package/dist/reactor.worker.js +478 -158
- package/dist/reactor.worker.js.map +1 -1
- package/dist/{registerServiceWorker-BSzbNfvz.js → registerServiceWorker-OR8nokAn.js} +5 -5
- package/dist/{registerServiceWorker-BSzbNfvz.js.map → registerServiceWorker-OR8nokAn.js.map} +1 -1
- package/dist/root-v9fj27sn.js +27 -0
- package/dist/root-v9fj27sn.js.map +1 -0
- package/dist/route-tree.d.ts +2220 -0
- package/dist/route-tree.d.ts.map +1 -0
- package/dist/route-tree.js +135 -0
- package/dist/route-tree.js.map +1 -0
- package/dist/route-views-BovMNHyn.js +60 -0
- package/dist/route-views-BovMNHyn.js.map +1 -0
- package/dist/route-views-C-H3ofJW.js +4 -0
- package/dist/route-views-DzgRMAx8.js +55 -0
- package/dist/route-views-DzgRMAx8.js.map +1 -0
- package/dist/route-views.d.ts +7 -0
- package/dist/route-views.d.ts.map +1 -0
- package/dist/route-views.js +4 -0
- package/dist/router-CWIsjETx.js +54 -0
- package/dist/router-CWIsjETx.js.map +1 -0
- package/dist/router-CnWkTEey.js +4 -0
- package/dist/router.d.ts +2 -0
- package/dist/router.js +3 -0
- package/dist/sentry-Cuc_Nbba.js +22 -0
- package/dist/sentry-Cuc_Nbba.js.map +1 -0
- package/dist/settings-CkNLybyI.js +1089 -0
- package/dist/settings-CkNLybyI.js.map +1 -0
- package/dist/settings-tabs-C0yGKzgj.js +424 -0
- package/dist/settings-tabs-C0yGKzgj.js.map +1 -0
- package/dist/shell-core-head.html +2 -0
- package/dist/shell-core.html +1 -0
- package/dist/shell-head.html +2 -0
- package/dist/shell-plugins.json +1 -0
- package/dist/shell.html +1 -0
- package/dist/start-connect.d.ts +7 -9
- package/dist/start-connect.d.ts.map +1 -1
- package/dist/start-connect.js +9 -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 +3482 -733
- 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/ui-C1-l-Eyh.js +170 -0
- package/dist/ui-C1-l-Eyh.js.map +1 -0
- package/dist/ui-DQrlNYAB.js +66 -0
- package/dist/ui-DQrlNYAB.js.map +1 -0
- package/dist/{use-renown-login-Cf3va6u_.js → use-renown-login-dPpDOYq5.js} +4 -4
- package/dist/use-renown-login-dPpDOYq5.js.map +1 -0
- package/dist/workflows-C3qEvx1R.js +63 -0
- package/dist/workflows-C3qEvx1R.js.map +1 -0
- package/fonts.css +177 -0
- package/generic-routes.json +9 -0
- package/package.json +87 -26
- package/scripts/assert-plugin-configs.mjs +47 -0
- package/scripts/prerender-shell.ts +51 -0
- package/skills/customize-connect/SKILL.md +80 -0
- package/skills/customize-connect/references/data-and-navigation.md +315 -0
- package/skills/customize-connect/references/drive-apps.md +44 -0
- package/skills/customize-connect/references/hosts-and-plugins.md +88 -0
- package/skills/customize-connect/references/layout.md +162 -0
- package/skills/customize-connect/references/modals.md +99 -0
- package/skills/customize-connect/references/overrides.md +177 -0
- package/skills/customize-connect/references/packages.md +41 -0
- package/skills/customize-connect/references/pages.md +141 -0
- package/skills/customize-connect/references/runtime-config.md +403 -0
- package/skills/customize-connect/references/styles-and-branding.md +76 -0
- package/skills/customize-connect/references/types-and-troubleshooting.md +64 -0
- package/src/route-tree.ts +3 -0
- package/src/routeTree.gen.ts +235 -0
- package/src/router/index.ts +2 -0
- package/src/router/register.ts +9 -0
- package/src/routes/__root.tsx +12 -0
- package/src/routes/_app/$.tsx +13 -0
- package/src/routes/_app/d/$driveSlug/{-$nodeSlug}.tsx +13 -0
- package/src/routes/_app/d/$driveSlug.tsx +13 -0
- package/src/routes/_app/index.tsx +13 -0
- package/src/routes/_app/settings/appearance.tsx +13 -0
- package/src/routes/_app/settings/packages.tsx +13 -0
- package/src/routes/_app/settings.tsx +13 -0
- package/src/routes/_app.tsx +13 -0
- package/style.css +8 -23
- package/tailwind.css +12 -0
- package/theme.css +5 -0
- package/dist/AddDriveModal-xAw48kdl.js.map +0 -1
- package/dist/ClearStorageModal-C1BXHTq3.js.map +0 -1
- package/dist/ConfirmDocumentUpgradeModal-FUOhZsk7.js.map +0 -1
- package/dist/CreateDocumentModal-C45W8J0V.js +0 -35
- package/dist/CreateDocumentModal-C45W8J0V.js.map +0 -1
- package/dist/DebugSettingsModal-ClqHzcxM.js.map +0 -1
- package/dist/DeleteDriveModal-Dug84t1j.js.map +0 -1
- package/dist/DeleteItemModal-mMzy3V8o.js.map +0 -1
- package/dist/DisclaimerModal-DvpD5dPM.js.map +0 -1
- package/dist/DocumentVersionUnsupportedModal-C3Q0V75l.js.map +0 -1
- package/dist/DownloadDocumentWithErrorsModal-IKl0ljQb.js.map +0 -1
- package/dist/DriveAuthRequiredModal-DVK7ZQzO.js.map +0 -1
- package/dist/DriveSettingsModal-C6-mRQiv.js +0 -57
- package/dist/DriveSettingsModal-C6-mRQiv.js.map +0 -1
- package/dist/InspectorModal-7FQBTEzt.js.map +0 -1
- package/dist/LoginModal-CybbOm3N.js.map +0 -1
- package/dist/MissingPackageModal-nBnExqO0.js +0 -49
- package/dist/MissingPackageModal-nBnExqO0.js.map +0 -1
- package/dist/OpenFileDocumentsModal-DGaYJpXW.js.map +0 -1
- package/dist/SettingsModal-CPv3_jmp.js +0 -569
- package/dist/SettingsModal-CPv3_jmp.js.map +0 -1
- package/dist/UpgradeDriveModal-_8t9slxQ.js.map +0 -1
- package/dist/app-loader-C4pFYc82.js +0 -4
- package/dist/app-loader-DyGcBhGV.js +0 -2244
- package/dist/app-loader-DyGcBhGV.js.map +0 -1
- package/dist/build-info-D9_h0032.js.map +0 -1
- package/dist/components-MEmS6hgr.js +0 -4
- package/dist/connect.config-DaHDEUrw.js.map +0 -1
- package/dist/connection-state-3w4liC1X.js.map +0 -1
- package/dist/load-Cu7S9GPc.js.map +0 -1
- package/dist/pglite-major-B39aOEiE.js.map +0 -1
- package/dist/pglite-migrate-core-Boxqqx-c.js.map +0 -1
- package/dist/preferences-store-_5Cw4_YV.js.map +0 -1
- package/dist/reactor-yC8BveHb.js +0 -1464
- package/dist/reactor-yC8BveHb.js.map +0 -1
- package/dist/runtime-config-DL3QjcfM.js +0 -24
- package/dist/runtime-config-DL3QjcfM.js.map +0 -1
- package/dist/sentry-QXKgQmr2.js +0 -15
- package/dist/sentry-QXKgQmr2.js.map +0 -1
- package/dist/use-renown-login-Cf3va6u_.js.map +0 -1
- package/dist/useRegistryPackages-BnUcL_nZ.js +0 -390
- package/dist/useRegistryPackages-BnUcL_nZ.js.map +0 -1
package/dist/reactor-yC8BveHb.js
DELETED
|
@@ -1,1464 +0,0 @@
|
|
|
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]="f8f2f6b8-9d33-50e7-af3e-fcd10c6d78da")}catch(e){}}();
|
|
3
|
-
import { n as getRuntimeConfig } from "./runtime-config-DL3QjcfM.js";
|
|
4
|
-
import { a as resolvePgMajorForRuntime, r as loadPGliteModule } from "./pglite-major-B39aOEiE.js";
|
|
5
|
-
import { i as getVersion, n as getGitSha } from "./build-info-D9_h0032.js";
|
|
6
|
-
import { n as buildPHGlobalConfig, o as phGlobalConfig } from "./connect.config-DaHDEUrw.js";
|
|
7
|
-
import { t as refreshPwaManifestLink } from "./pwa-manifest-link-DIgOSo2Q.js";
|
|
8
|
-
import { a as detectReactorPgMajor, h as RELATIONAL_PGLITE_NAME, m as REACTOR_PGLITE_NAME, n as setWorkerConnectionStatus, o as detectRelationalPgMajor, p as REACTOR_INSTANCE_NAMESPACE } from "./connection-state-3w4liC1X.js";
|
|
9
|
-
import { r as toast } from "./toast-BXIGd4Eb.js";
|
|
10
|
-
import { PWA_IDB_KEY, PWA_IDB_NAME, PWA_IDB_STORE, PWA_IDB_VERSION, mergePwaConfig, withInferredCategory } from "@powerhousedao/shared/connect";
|
|
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";
|
|
14
|
-
import { Kysely } from "kysely";
|
|
15
|
-
import { PGliteDialect } from "kysely-pglite-dialect";
|
|
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";
|
|
20
|
-
import { createAttachmentClient, createRemoteAttachmentService, createXhrUploadTransport } from "@powerhousedao/reactor-attachments/client";
|
|
21
|
-
import { OpenFeature } from "@openfeature/web-sdk";
|
|
22
|
-
import * as common from "@powerhousedao/powerhouse-vetra-packages";
|
|
23
|
-
import commonPkg from "@powerhousedao/powerhouse-vetra-packages/package.json" with { type: "json" };
|
|
24
|
-
import { toCdnUrl } from "@powerhousedao/shared/registry/urls";
|
|
25
|
-
import vetraPkg from "@powerhousedao/vetra/package.json" with { type: "json" };
|
|
26
|
-
//#region src/utils/pwa-idb.ts
|
|
27
|
-
function openPwaIdb() {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
const req = indexedDB.open(PWA_IDB_NAME, PWA_IDB_VERSION);
|
|
30
|
-
req.onupgradeneeded = () => {
|
|
31
|
-
if (!req.result.objectStoreNames.contains(PWA_IDB_STORE)) req.result.createObjectStore(PWA_IDB_STORE);
|
|
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();
|
|
44
|
-
try {
|
|
45
|
-
await new Promise((resolve, reject) => {
|
|
46
|
-
const tx = db.transaction(PWA_IDB_STORE, "readwrite");
|
|
47
|
-
tx.oncomplete = () => resolve();
|
|
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();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/** Resolve `src` against the package `baseUrl`, absolute srcs passing through.
|
|
60
|
-
* `baseUrl` may itself be relative (e.g. a same-origin-proxied registry, or the
|
|
61
|
-
* dev `/node_modules/…` path), so it is first made absolute against the app
|
|
62
|
-
* origin — `new URL(src, relativeBase)` would otherwise throw and silently
|
|
63
|
-
* leave the src unresolved. A malformed src is left untouched. */
|
|
64
|
-
function toAbsoluteAssetUrl(src, baseUrl) {
|
|
65
|
-
try {
|
|
66
|
-
const origin = typeof location !== "undefined" ? location.href : "http://localhost/";
|
|
67
|
-
return new URL(src, new URL(baseUrl, origin)).toString();
|
|
68
|
-
} catch {
|
|
69
|
-
return src;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function resolveIconSrc(icon, baseUrl) {
|
|
73
|
-
return {
|
|
74
|
-
...icon,
|
|
75
|
-
src: toAbsoluteAssetUrl(icon.src, baseUrl)
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Rewrite a package fragment's relative asset srcs (manifest icons and
|
|
80
|
-
* file-handler icons) to absolute URLs against the package's base — a runtime
|
|
81
|
-
* package's assets live on the registry CDN, not the app origin, so the served
|
|
82
|
-
* manifest must point there. `baseUrl` null (a local/bundled package whose
|
|
83
|
-
* assets are app-origin-relative) leaves srcs untouched.
|
|
84
|
-
*/
|
|
85
|
-
function resolveFragmentAssetUrls(config, baseUrl) {
|
|
86
|
-
if (!baseUrl || !config.manifest) return config;
|
|
87
|
-
const m = config.manifest;
|
|
88
|
-
const resolveIcons = (icons) => icons?.map((icon) => resolveIconSrc(icon, baseUrl));
|
|
89
|
-
return {
|
|
90
|
-
...config,
|
|
91
|
-
manifest: {
|
|
92
|
-
...m,
|
|
93
|
-
icons: resolveIcons(m.icons),
|
|
94
|
-
file_handlers: m.file_handlers?.map((handler) => ({
|
|
95
|
-
...handler,
|
|
96
|
-
icons: resolveIcons(handler.icons)
|
|
97
|
-
}))
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/pglite.db.ts
|
|
103
|
-
async function createMainThreadPGlite(major, dbName) {
|
|
104
|
-
const { PGlite } = await loadPGliteModule(major);
|
|
105
|
-
const { live } = major === 16 ? await import("pglite-legacy-02/live") : await import("@electric-sql/pglite/live");
|
|
106
|
-
return new PGlite(`idb://${dbName}`, {
|
|
107
|
-
relaxedDurability: true,
|
|
108
|
-
extensions: { live }
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
let bootChain = Promise.resolve();
|
|
112
|
-
function chainedCreate(create) {
|
|
113
|
-
const pending = bootChain.then(create, create);
|
|
114
|
-
bootChain = pending.catch(() => void 0);
|
|
115
|
-
return pending;
|
|
116
|
-
}
|
|
117
|
-
function pgliteSingleton(opts) {
|
|
118
|
-
let cached;
|
|
119
|
-
return function getPGlite() {
|
|
120
|
-
if (cached) return cached;
|
|
121
|
-
const pending = chainedCreate(async () => {
|
|
122
|
-
const major = resolvePgMajorForRuntime(await opts.detectMajor());
|
|
123
|
-
if (major !== 17) console.warn(`[${opts.label}] Opening legacy Postgres ${major} data dir. Migrate to PG17 from the banner or the Inspector → Debug tab.`);
|
|
124
|
-
return createMainThreadPGlite(major, opts.dbName);
|
|
125
|
-
});
|
|
126
|
-
cached = pending;
|
|
127
|
-
pending.catch(() => {
|
|
128
|
-
if (cached === pending) cached = void 0;
|
|
129
|
-
});
|
|
130
|
-
return pending;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
const getReactorPGlite = pgliteSingleton({
|
|
134
|
-
dbName: REACTOR_PGLITE_NAME,
|
|
135
|
-
detectMajor: detectReactorPgMajor,
|
|
136
|
-
label: "reactor"
|
|
137
|
-
});
|
|
138
|
-
const getRelationalPGlite = pgliteSingleton({
|
|
139
|
-
dbName: RELATIONAL_PGLITE_NAME,
|
|
140
|
-
detectMajor: detectRelationalPgMajor,
|
|
141
|
-
label: "relational"
|
|
142
|
-
});
|
|
143
|
-
async function getDb() {
|
|
144
|
-
const pgLite = await getRelationalPGlite();
|
|
145
|
-
return {
|
|
146
|
-
pgLite,
|
|
147
|
-
relationalDb: createRelationalDb(new Kysely({ dialect: new PGliteDialect(pgLite) }))
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
//#endregion
|
|
151
|
-
//#region src/utils/reactor.ts
|
|
152
|
-
/**
|
|
153
|
-
* Creates a Reactor that plugs into legacy storage but syncs through the new
|
|
154
|
-
* Reactor GQL API.
|
|
155
|
-
*/
|
|
156
|
-
async function createBrowserReactor(documentModelModules, upgradeManifests, renown, featureFlags, documentModelLoader) {
|
|
157
|
-
const signerConfig = {
|
|
158
|
-
signer: renown.signer,
|
|
159
|
-
verifier: createSignatureVerifier()
|
|
160
|
-
};
|
|
161
|
-
const jwtHandler = async (_url) => {
|
|
162
|
-
if (!renown.user) return;
|
|
163
|
-
return renown.getBearerToken({ expiresIn: 10 });
|
|
164
|
-
};
|
|
165
|
-
const pg = await getReactorPGlite();
|
|
166
|
-
const logger = new ConsoleLogger(["reactor-client"]);
|
|
167
|
-
const builder = new ReactorClientBuilder$1().withLogger(logger).withSigner(signerConfig).withReactorBuilder(new ReactorBuilder$1().withDocumentModelSources(documentModelModules).withUpgradeManifests(upgradeManifests).withChannelScheme(ChannelScheme$1.CONNECT).withExecutorConfig({ featureFlags }).withJwtHandler(jwtHandler).withKysely(new Kysely({ dialect: new PGliteDialect(pg) })));
|
|
168
|
-
if (documentModelLoader) builder.withDocumentModelLoader(documentModelLoader);
|
|
169
|
-
const module = await builder.buildModule();
|
|
170
|
-
return {
|
|
171
|
-
...module,
|
|
172
|
-
kind: "browser",
|
|
173
|
-
reactorModule: module.reactorModule ? {
|
|
174
|
-
...module.reactorModule,
|
|
175
|
-
pg
|
|
176
|
-
} : void 0
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function getDefaultDrives(runtimeConfig) {
|
|
180
|
-
return runtimeConfig.connect.drives?.defaultDrives ?? [];
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Add default drives for the new reactor via sync manager.
|
|
184
|
-
*
|
|
185
|
-
* Drives register concurrently so a slow or unreachable drive can't delay the
|
|
186
|
-
* others — in particular the one the URL slug resolves to. Remote drives
|
|
187
|
-
* retry with linear backoff to handle the common race where Connect's dev
|
|
188
|
-
* server is ready before the switchboard has finished binding its port.
|
|
189
|
-
*
|
|
190
|
-
* Each entry is either a remote drive (a URL registered with the sync
|
|
191
|
-
* manager, waited on for initial backfill) or a local drive (created once in
|
|
192
|
-
* this browser's local reactor; its fixed id makes later boots skip it).
|
|
193
|
-
*
|
|
194
|
-
* @param drives - Array of default-drive entries
|
|
195
|
-
*/
|
|
196
|
-
async function addDefaultDrivesForNewReactor(drives) {
|
|
197
|
-
await Promise.all(drives.map((drive) => "url" in drive ? addRemoteDefaultDrive(drive) : addLocalDefaultDrive(drive)));
|
|
198
|
-
}
|
|
199
|
-
async function addRemoteDefaultDrive(drive) {
|
|
200
|
-
const MAX_ATTEMPTS = 3;
|
|
201
|
-
const BACKOFF_MS = 2e3;
|
|
202
|
-
let driveId;
|
|
203
|
-
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) try {
|
|
204
|
-
driveId = await addRemoteDrive(drive.url);
|
|
205
|
-
break;
|
|
206
|
-
} catch (error) {
|
|
207
|
-
if (isDriveAuthError(error)) break;
|
|
208
|
-
if (attempt === MAX_ATTEMPTS) console.error(`Failed to add default drive ${drive.url} after ${MAX_ATTEMPTS} attempts:`, error);
|
|
209
|
-
else {
|
|
210
|
-
const delay = BACKOFF_MS * attempt;
|
|
211
|
-
console.warn(`Default drive ${drive.url} not reachable (attempt ${attempt}/${MAX_ATTEMPTS}), retrying in ${delay}ms...`);
|
|
212
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (driveId && (drive.name || drive.icon)) try {
|
|
216
|
-
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
217
|
-
if (reactorClient) await waitForDocumentReady(reactorClient, driveId, { timeoutMs: 15e3 });
|
|
218
|
-
await setDriveMetadata(driveId, {
|
|
219
|
-
name: drive.name,
|
|
220
|
-
icon: drive.icon
|
|
221
|
-
});
|
|
222
|
-
} catch (error) {
|
|
223
|
-
console.warn(`Default drive ${drive.url} was added but metadata update failed:`, error);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Create a configured local default drive in this browser's local reactor.
|
|
228
|
-
* The drive is only created when the configured id is not already taken, so
|
|
229
|
-
* repeated boots are idempotent and a drive the user deleted stays deleted.
|
|
230
|
-
* Name and icon are written straight into the created document's global state
|
|
231
|
-
* (no setDriveMetadata round-trip), and `app` maps to the drive's preferred
|
|
232
|
-
* editor.
|
|
233
|
-
*/
|
|
234
|
-
async function addLocalDefaultDrive(drive) {
|
|
235
|
-
if (!drive.id) {
|
|
236
|
-
console.error("Ignoring local default drive with no id:", JSON.stringify(drive));
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
241
|
-
if (reactorClient) {
|
|
242
|
-
if (await reactorClient.isDocumentIdTaken(drive.id)) return;
|
|
243
|
-
}
|
|
244
|
-
await addDrive({
|
|
245
|
-
id: drive.id,
|
|
246
|
-
global: {
|
|
247
|
-
name: drive.name ?? "",
|
|
248
|
-
icon: drive.icon ?? null
|
|
249
|
-
}
|
|
250
|
-
}, drive.app);
|
|
251
|
-
} catch (error) {
|
|
252
|
-
console.error(`Failed to create local default drive ${drive.id}:`, error);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region src/feature-flags.ts
|
|
257
|
-
/**
|
|
258
|
-
* QueryParamProvider reads feature flags from URL query parameters.
|
|
259
|
-
*
|
|
260
|
-
* Usage:
|
|
261
|
-
* const params = new URLSearchParams(window.location.search);
|
|
262
|
-
* const provider = new QueryParamProvider(params);
|
|
263
|
-
* await OpenFeature.setProviderAndWait(provider);
|
|
264
|
-
*
|
|
265
|
-
* Query parameter format:
|
|
266
|
-
* ?FEATURE_DUAL_ACTION_CREATE_ENABLED=true&FEATURE_FOO=false
|
|
267
|
-
*/
|
|
268
|
-
var QueryParamProvider = class {
|
|
269
|
-
runsOn = "client";
|
|
270
|
-
metadata = { name: "QueryParamProvider" };
|
|
271
|
-
flags;
|
|
272
|
-
constructor(searchParams) {
|
|
273
|
-
this.flags = /* @__PURE__ */ new Map();
|
|
274
|
-
for (const [key, value] of searchParams.entries()) this.flags.set(key, value);
|
|
275
|
-
}
|
|
276
|
-
resolveBooleanEvaluation(flagKey, defaultValue) {
|
|
277
|
-
const value = this.flags.get(flagKey);
|
|
278
|
-
if (value === void 0) return {
|
|
279
|
-
value: defaultValue,
|
|
280
|
-
reason: "DEFAULT"
|
|
281
|
-
};
|
|
282
|
-
return {
|
|
283
|
-
value: value.toLowerCase() === "true" || value === "1",
|
|
284
|
-
reason: "STATIC",
|
|
285
|
-
variant: value
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
resolveStringEvaluation(flagKey, defaultValue) {
|
|
289
|
-
const value = this.flags.get(flagKey);
|
|
290
|
-
if (value === void 0) return {
|
|
291
|
-
value: defaultValue,
|
|
292
|
-
reason: "DEFAULT"
|
|
293
|
-
};
|
|
294
|
-
return {
|
|
295
|
-
value,
|
|
296
|
-
reason: "STATIC",
|
|
297
|
-
variant: value
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
resolveNumberEvaluation(flagKey, defaultValue) {
|
|
301
|
-
const value = this.flags.get(flagKey);
|
|
302
|
-
if (value === void 0) return {
|
|
303
|
-
value: defaultValue,
|
|
304
|
-
reason: "DEFAULT"
|
|
305
|
-
};
|
|
306
|
-
const numValue = Number(value);
|
|
307
|
-
if (isNaN(numValue)) return {
|
|
308
|
-
value: defaultValue,
|
|
309
|
-
reason: "ERROR",
|
|
310
|
-
errorCode: "PARSE_ERROR",
|
|
311
|
-
errorMessage: `Failed to parse "${value}" as a number`
|
|
312
|
-
};
|
|
313
|
-
return {
|
|
314
|
-
value: numValue,
|
|
315
|
-
reason: "STATIC",
|
|
316
|
-
variant: value
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
resolveObjectEvaluation(flagKey, defaultValue) {
|
|
320
|
-
const value = this.flags.get(flagKey);
|
|
321
|
-
if (value === void 0) return {
|
|
322
|
-
value: defaultValue,
|
|
323
|
-
reason: "DEFAULT"
|
|
324
|
-
};
|
|
325
|
-
try {
|
|
326
|
-
return {
|
|
327
|
-
value: JSON.parse(value),
|
|
328
|
-
reason: "STATIC",
|
|
329
|
-
variant: value
|
|
330
|
-
};
|
|
331
|
-
} catch (error) {
|
|
332
|
-
return {
|
|
333
|
-
value: defaultValue,
|
|
334
|
-
reason: "ERROR",
|
|
335
|
-
errorCode: "PARSE_ERROR",
|
|
336
|
-
errorMessage: `Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
/**
|
|
342
|
-
* Initialize OpenFeature with the QueryParamProvider.
|
|
343
|
-
* Reads feature flags from query parameters.
|
|
344
|
-
*/
|
|
345
|
-
async function initFeatureFlags(searchParams) {
|
|
346
|
-
const params = searchParams ?? (typeof window !== "undefined" ? new URLSearchParams(window.location.search) : new URLSearchParams());
|
|
347
|
-
const provider = new QueryParamProvider(params);
|
|
348
|
-
await OpenFeature.setProviderAndWait(provider);
|
|
349
|
-
const features = /* @__PURE__ */ new Map();
|
|
350
|
-
const logLevelParam = params.get("LOG_LEVEL");
|
|
351
|
-
if (logLevelParam) {
|
|
352
|
-
const validLogLevels = [
|
|
353
|
-
"verbose",
|
|
354
|
-
"debug",
|
|
355
|
-
"info",
|
|
356
|
-
"warn",
|
|
357
|
-
"error"
|
|
358
|
-
];
|
|
359
|
-
if (validLogLevels.includes(logLevelParam.toLowerCase())) {
|
|
360
|
-
setLogLevel$1(logLevelParam.toLowerCase());
|
|
361
|
-
logger.info("Log level set to @level via query param", logLevelParam.toLowerCase());
|
|
362
|
-
} else logger.warn("Invalid LOG_LEVEL query param: @param. Valid values: @validLevels", logLevelParam, validLogLevels.join(", "));
|
|
363
|
-
}
|
|
364
|
-
return features;
|
|
365
|
-
}
|
|
366
|
-
//#endregion
|
|
367
|
-
//#region src/no-registry-discovery.ts
|
|
368
|
-
/**
|
|
369
|
-
* Discovery service used when no package registry is configured. Every load
|
|
370
|
-
* for an unknown document type is recorded as a failure with reason
|
|
371
|
-
* "no-registry" so the UI can surface the issue; the modal install flow is a
|
|
372
|
-
* no-op because there is no registry to query.
|
|
373
|
-
*/
|
|
374
|
-
var NoRegistryDiscoveryService = class {
|
|
375
|
-
#packageManager;
|
|
376
|
-
#failed = /* @__PURE__ */ new Map();
|
|
377
|
-
#failedMemo = [];
|
|
378
|
-
#failedSubscribers = /* @__PURE__ */ new Set();
|
|
379
|
-
#eventSubscribers = /* @__PURE__ */ new Set();
|
|
380
|
-
constructor(packageManager) {
|
|
381
|
-
this.#packageManager = packageManager;
|
|
382
|
-
}
|
|
383
|
-
load(documentType) {
|
|
384
|
-
const existing = this.#findModuleInLoadedPackages(documentType);
|
|
385
|
-
if (existing) {
|
|
386
|
-
this.#clearFailed(documentType);
|
|
387
|
-
return Promise.resolve(existing);
|
|
388
|
-
}
|
|
389
|
-
this.#recordFailure(documentType);
|
|
390
|
-
return Promise.reject(/* @__PURE__ */ new Error(`No package registry configured; cannot resolve "${documentType}"`));
|
|
391
|
-
}
|
|
392
|
-
promptInstallation() {}
|
|
393
|
-
approveInstallation() {
|
|
394
|
-
return Promise.resolve();
|
|
395
|
-
}
|
|
396
|
-
dismissInstallation() {}
|
|
397
|
-
getPendingInstallations() {
|
|
398
|
-
return [];
|
|
399
|
-
}
|
|
400
|
-
subscribePending() {
|
|
401
|
-
return () => {};
|
|
402
|
-
}
|
|
403
|
-
getFailedInstallations() {
|
|
404
|
-
return this.#failedMemo;
|
|
405
|
-
}
|
|
406
|
-
subscribeFailed(listener) {
|
|
407
|
-
this.#failedSubscribers.add(listener);
|
|
408
|
-
return () => {
|
|
409
|
-
this.#failedSubscribers.delete(listener);
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
subscribeEvents(listener) {
|
|
413
|
-
this.#eventSubscribers.add(listener);
|
|
414
|
-
return () => {
|
|
415
|
-
this.#eventSubscribers.delete(listener);
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
retryInstallation(documentType) {
|
|
419
|
-
this.#recordFailure(documentType);
|
|
420
|
-
return Promise.resolve();
|
|
421
|
-
}
|
|
422
|
-
#findModuleInLoadedPackages(documentType) {
|
|
423
|
-
return this.#packageManager.packages.flatMap((p) => p.documentModels).find((m) => m.documentModel.global.id === documentType);
|
|
424
|
-
}
|
|
425
|
-
#recordFailure(documentType) {
|
|
426
|
-
this.#failed.set(documentType, {
|
|
427
|
-
documentType,
|
|
428
|
-
reason: "no-registry",
|
|
429
|
-
packageNames: [],
|
|
430
|
-
error: null
|
|
431
|
-
});
|
|
432
|
-
this.#emitEvent({
|
|
433
|
-
type: "load-failed",
|
|
434
|
-
documentType,
|
|
435
|
-
reason: "no-registry"
|
|
436
|
-
});
|
|
437
|
-
this.#notifyFailedChanged();
|
|
438
|
-
}
|
|
439
|
-
#clearFailed(documentType) {
|
|
440
|
-
if (this.#failed.delete(documentType)) this.#notifyFailedChanged();
|
|
441
|
-
}
|
|
442
|
-
#notifyFailedChanged() {
|
|
443
|
-
this.#failedMemo = Array.from(this.#failed.values());
|
|
444
|
-
for (const listener of this.#failedSubscribers) listener();
|
|
445
|
-
}
|
|
446
|
-
#emitEvent(event) {
|
|
447
|
-
for (const listener of this.#eventSubscribers) listener(event);
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
//#endregion
|
|
451
|
-
//#region src/package-discovery.ts
|
|
452
|
-
var PackageDiscoveryService = class {
|
|
453
|
-
#packageManager;
|
|
454
|
-
#registryClient;
|
|
455
|
-
#mode;
|
|
456
|
-
#deferred = /* @__PURE__ */ new Map();
|
|
457
|
-
#pending = /* @__PURE__ */ new Map();
|
|
458
|
-
#pendingMemo = [];
|
|
459
|
-
#pendingSubscribers = /* @__PURE__ */ new Set();
|
|
460
|
-
#failed = /* @__PURE__ */ new Map();
|
|
461
|
-
#failedMemo = [];
|
|
462
|
-
#failedSubscribers = /* @__PURE__ */ new Set();
|
|
463
|
-
#eventSubscribers = /* @__PURE__ */ new Set();
|
|
464
|
-
#dismissedStorage;
|
|
465
|
-
#discoveredTypes = /* @__PURE__ */ new Map();
|
|
466
|
-
constructor(packageManager, registryClient, options) {
|
|
467
|
-
this.#packageManager = packageManager;
|
|
468
|
-
this.#registryClient = registryClient;
|
|
469
|
-
this.#mode = options.mode;
|
|
470
|
-
this.#dismissedStorage = new BrowserLocalStorage(options.storageKey + ":PH_DISMISSED_TYPES");
|
|
471
|
-
}
|
|
472
|
-
load(documentType) {
|
|
473
|
-
const existing = this.#findModuleInLoadedPackages(documentType);
|
|
474
|
-
if (existing) {
|
|
475
|
-
this.#clearFailed(documentType);
|
|
476
|
-
return Promise.resolve(existing);
|
|
477
|
-
}
|
|
478
|
-
if (this.#dismissedStorage.has(documentType)) {
|
|
479
|
-
this.#recordFailure(documentType, "dismissed", [], null);
|
|
480
|
-
return Promise.reject(/* @__PURE__ */ new Error(`Document type "${documentType}" was dismissed`));
|
|
481
|
-
}
|
|
482
|
-
const tracked = this.#deferred.get(documentType);
|
|
483
|
-
if (tracked) return tracked.promise;
|
|
484
|
-
return this.#discover(documentType);
|
|
485
|
-
}
|
|
486
|
-
promptInstallation(documentType) {
|
|
487
|
-
const packageNames = this.#discoveredTypes.get(documentType);
|
|
488
|
-
if (!packageNames) return;
|
|
489
|
-
if (this.#pending.has(documentType)) return;
|
|
490
|
-
this.#discoveredTypes.delete(documentType);
|
|
491
|
-
this.#addToPending(documentType, packageNames);
|
|
492
|
-
}
|
|
493
|
-
async approveInstallation(packageName) {
|
|
494
|
-
const affectedTypes = this.#findTypesByPackage(packageName);
|
|
495
|
-
if (affectedTypes.length === 0) return;
|
|
496
|
-
const result = await this.#packageManager.addPackage(packageName);
|
|
497
|
-
if (result.type === "error") {
|
|
498
|
-
this.#emitEvent({
|
|
499
|
-
type: "installation-failed",
|
|
500
|
-
packageName,
|
|
501
|
-
error: result.error
|
|
502
|
-
});
|
|
503
|
-
for (const documentType of affectedTypes) {
|
|
504
|
-
const entry = this.#deferred.get(documentType);
|
|
505
|
-
if (entry) {
|
|
506
|
-
entry.reject(result.error);
|
|
507
|
-
this.#deferred.delete(documentType);
|
|
508
|
-
this.#pending.delete(documentType);
|
|
509
|
-
}
|
|
510
|
-
this.#recordFailure(documentType, "install-failed", [packageName], result.error);
|
|
511
|
-
}
|
|
512
|
-
this.#notifyPendingChanged();
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
this.#emitEvent({
|
|
516
|
-
type: "installation-approved",
|
|
517
|
-
packageName,
|
|
518
|
-
documentTypes: affectedTypes
|
|
519
|
-
});
|
|
520
|
-
for (const documentType of affectedTypes) {
|
|
521
|
-
const entry = this.#deferred.get(documentType);
|
|
522
|
-
if (!entry) continue;
|
|
523
|
-
const module = this.#findModuleInLoadedPackages(documentType);
|
|
524
|
-
if (module) {
|
|
525
|
-
entry.resolve(module);
|
|
526
|
-
this.#clearFailed(documentType);
|
|
527
|
-
} else {
|
|
528
|
-
const error = /* @__PURE__ */ new Error(`Package "${packageName}" installed but module for "${documentType}" not found`);
|
|
529
|
-
entry.reject(error);
|
|
530
|
-
this.#recordFailure(documentType, "install-failed", [packageName], error);
|
|
531
|
-
}
|
|
532
|
-
this.#deferred.delete(documentType);
|
|
533
|
-
this.#pending.delete(documentType);
|
|
534
|
-
}
|
|
535
|
-
this.#notifyPendingChanged();
|
|
536
|
-
}
|
|
537
|
-
dismissInstallation(packageName) {
|
|
538
|
-
const affectedTypes = this.#findTypesByPackage(packageName);
|
|
539
|
-
if (affectedTypes.length === 0) return;
|
|
540
|
-
for (const documentType of affectedTypes) {
|
|
541
|
-
this.#dismissedStorage.set(documentType, true);
|
|
542
|
-
const entry = this.#deferred.get(documentType);
|
|
543
|
-
if (entry) entry.reject(/* @__PURE__ */ new Error(`Document type "${documentType}" was dismissed`));
|
|
544
|
-
this.#deferred.delete(documentType);
|
|
545
|
-
this.#pending.delete(documentType);
|
|
546
|
-
this.#discoveredTypes.delete(documentType);
|
|
547
|
-
this.#recordFailure(documentType, "dismissed", [packageName], null);
|
|
548
|
-
}
|
|
549
|
-
this.#emitEvent({
|
|
550
|
-
type: "installation-dismissed",
|
|
551
|
-
packageName,
|
|
552
|
-
documentTypes: affectedTypes
|
|
553
|
-
});
|
|
554
|
-
this.#notifyPendingChanged();
|
|
555
|
-
}
|
|
556
|
-
getPendingInstallations() {
|
|
557
|
-
return this.#pendingMemo;
|
|
558
|
-
}
|
|
559
|
-
subscribePending(listener) {
|
|
560
|
-
this.#pendingSubscribers.add(listener);
|
|
561
|
-
return () => {
|
|
562
|
-
this.#pendingSubscribers.delete(listener);
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
getFailedInstallations() {
|
|
566
|
-
return this.#failedMemo;
|
|
567
|
-
}
|
|
568
|
-
subscribeFailed(listener) {
|
|
569
|
-
this.#failedSubscribers.add(listener);
|
|
570
|
-
return () => {
|
|
571
|
-
this.#failedSubscribers.delete(listener);
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
subscribeEvents(listener) {
|
|
575
|
-
this.#eventSubscribers.add(listener);
|
|
576
|
-
return () => {
|
|
577
|
-
this.#eventSubscribers.delete(listener);
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
async retryInstallation(documentType) {
|
|
581
|
-
this.#dismissedStorage.delete(documentType);
|
|
582
|
-
this.#clearFailed(documentType);
|
|
583
|
-
try {
|
|
584
|
-
await this.#discover(documentType);
|
|
585
|
-
} catch {}
|
|
586
|
-
}
|
|
587
|
-
async #discover(documentType) {
|
|
588
|
-
if (typeof navigator !== "undefined" && navigator.onLine === false) {
|
|
589
|
-
this.#recordFailure(documentType, "offline", [], null);
|
|
590
|
-
return Promise.reject(/* @__PURE__ */ new Error(`Offline: cannot discover document type "${documentType}"`));
|
|
591
|
-
}
|
|
592
|
-
let packageNames;
|
|
593
|
-
try {
|
|
594
|
-
packageNames = await this.#registryClient.getPackagesByDocumentType(documentType);
|
|
595
|
-
} catch (error) {
|
|
596
|
-
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
597
|
-
this.#emitEvent({
|
|
598
|
-
type: "registry-query-failed",
|
|
599
|
-
documentType,
|
|
600
|
-
error: normalized
|
|
601
|
-
});
|
|
602
|
-
this.#recordFailure(documentType, "registry-error", [], normalized);
|
|
603
|
-
return Promise.reject(normalized);
|
|
604
|
-
}
|
|
605
|
-
if (packageNames.length === 0) {
|
|
606
|
-
this.#recordFailure(documentType, "not-in-registry", [], null);
|
|
607
|
-
return Promise.reject(/* @__PURE__ */ new Error(`No packages found for document type "${documentType}"`));
|
|
608
|
-
}
|
|
609
|
-
const entry = this.#createDeferredEntry(documentType, packageNames);
|
|
610
|
-
this.#emitEvent({
|
|
611
|
-
type: "type-discovered",
|
|
612
|
-
documentType,
|
|
613
|
-
packageNames
|
|
614
|
-
});
|
|
615
|
-
if (this.#mode === "immediate") this.#addToPending(documentType, packageNames);
|
|
616
|
-
else this.#discoveredTypes.set(documentType, packageNames);
|
|
617
|
-
return entry.promise;
|
|
618
|
-
}
|
|
619
|
-
#createDeferredEntry(documentType, packageNames) {
|
|
620
|
-
let resolve;
|
|
621
|
-
let reject;
|
|
622
|
-
const promise = new Promise((res, rej) => {
|
|
623
|
-
resolve = res;
|
|
624
|
-
reject = rej;
|
|
625
|
-
});
|
|
626
|
-
const entry = {
|
|
627
|
-
packageNames,
|
|
628
|
-
resolve,
|
|
629
|
-
reject,
|
|
630
|
-
promise
|
|
631
|
-
};
|
|
632
|
-
this.#deferred.set(documentType, entry);
|
|
633
|
-
return entry;
|
|
634
|
-
}
|
|
635
|
-
#addToPending(documentType, packageNames) {
|
|
636
|
-
const installation = {
|
|
637
|
-
documentType,
|
|
638
|
-
packageNames
|
|
639
|
-
};
|
|
640
|
-
this.#pending.set(documentType, installation);
|
|
641
|
-
this.#emitEvent({
|
|
642
|
-
type: "installation-prompted",
|
|
643
|
-
documentType,
|
|
644
|
-
packageNames
|
|
645
|
-
});
|
|
646
|
-
this.#notifyPendingChanged();
|
|
647
|
-
}
|
|
648
|
-
#findModuleInLoadedPackages(documentType) {
|
|
649
|
-
return this.#packageManager.packages.flatMap((p) => p.documentModels).find((m) => m.documentModel.global.id === documentType);
|
|
650
|
-
}
|
|
651
|
-
#findTypesByPackage(packageName) {
|
|
652
|
-
const types = [];
|
|
653
|
-
for (const [documentType, entry] of this.#deferred) if (entry.packageNames.includes(packageName)) types.push(documentType);
|
|
654
|
-
return types;
|
|
655
|
-
}
|
|
656
|
-
#notifyPendingChanged() {
|
|
657
|
-
this.#pendingMemo = Array.from(this.#pending.values());
|
|
658
|
-
for (const listener of this.#pendingSubscribers) listener();
|
|
659
|
-
}
|
|
660
|
-
#notifyFailedChanged() {
|
|
661
|
-
this.#failedMemo = Array.from(this.#failed.values());
|
|
662
|
-
for (const listener of this.#failedSubscribers) listener();
|
|
663
|
-
}
|
|
664
|
-
#recordFailure(documentType, reason, packageNames, error) {
|
|
665
|
-
this.#failed.set(documentType, {
|
|
666
|
-
documentType,
|
|
667
|
-
reason,
|
|
668
|
-
packageNames,
|
|
669
|
-
error
|
|
670
|
-
});
|
|
671
|
-
this.#emitEvent({
|
|
672
|
-
type: "load-failed",
|
|
673
|
-
documentType,
|
|
674
|
-
reason
|
|
675
|
-
});
|
|
676
|
-
this.#notifyFailedChanged();
|
|
677
|
-
}
|
|
678
|
-
#clearFailed(documentType) {
|
|
679
|
-
if (this.#failed.delete(documentType)) this.#notifyFailedChanged();
|
|
680
|
-
}
|
|
681
|
-
#emitEvent(event) {
|
|
682
|
-
for (const listener of this.#eventSubscribers) listener(event);
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
//#endregion
|
|
686
|
-
//#region src/package-manager.ts
|
|
687
|
-
/**
|
|
688
|
-
* Strip any `@tag` / `@version` suffix from a package spec, returning the bare
|
|
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) {
|
|
697
|
-
try {
|
|
698
|
-
const res = await fetch(baseUrl);
|
|
699
|
-
if (!res.ok) return void 0;
|
|
700
|
-
const pkg = await res.json();
|
|
701
|
-
return typeof pkg.version === "string" ? pkg.version : void 0;
|
|
702
|
-
} catch {
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
const LOCAL_PACKAGE_NAME = "Local";
|
|
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);
|
|
1009
|
-
return gen ? `ph-reactor:${namespace}#${gen}` : `ph-reactor:${namespace}`;
|
|
1010
|
-
}
|
|
1011
|
-
function readWorkerGen(namespace) {
|
|
1012
|
-
try {
|
|
1013
|
-
return localStorage.getItem(GEN_KEY_PREFIX + namespace);
|
|
1014
|
-
} catch {
|
|
1015
|
-
return null;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
function bumpWorkerGen(namespace, gen) {
|
|
1019
|
-
try {
|
|
1020
|
-
localStorage.setItem(GEN_KEY_PREFIX + namespace, gen);
|
|
1021
|
-
} catch {}
|
|
1022
|
-
}
|
|
1023
|
-
//#endregion
|
|
1024
|
-
//#region src/reactor-worker-client.ts
|
|
1025
|
-
const PING_INTERVAL_MS = 2e3;
|
|
1026
|
-
const PING_DEADLINE_MS = 3e3;
|
|
1027
|
-
const MAX_MISSED_PINGS = 2;
|
|
1028
|
-
/** Sorted so the same set always produces the same fingerprint. */
|
|
1029
|
-
function enabledFlagList(flags) {
|
|
1030
|
-
return Object.entries(flags).filter(([, enabled]) => enabled).map(([name]) => name).sort().join(",");
|
|
1031
|
-
}
|
|
1032
|
-
function toReactorIdentity(user) {
|
|
1033
|
-
if (!user) return null;
|
|
1034
|
-
return {
|
|
1035
|
-
address: user.address,
|
|
1036
|
-
chainId: user.chainId,
|
|
1037
|
-
networkId: user.networkId
|
|
1038
|
-
};
|
|
1039
|
-
}
|
|
1040
|
-
function createWorkerReactorClientModule(args) {
|
|
1041
|
-
const workerUrl = new URL("./reactor.worker.js", import.meta.url);
|
|
1042
|
-
console.info(`[reactor-worker] constructing SharedWorker ${reactorWorkerName(args.namespace)} from ${workerUrl.href}`);
|
|
1043
|
-
const worker = new SharedWorker(workerUrl, {
|
|
1044
|
-
name: reactorWorkerName(args.namespace),
|
|
1045
|
-
type: "module"
|
|
1046
|
-
});
|
|
1047
|
-
worker.addEventListener("error", (event) => {
|
|
1048
|
-
console.error(`[reactor-worker] SharedWorker failed to load from ${workerUrl.href}`, event.message || event);
|
|
1049
|
-
});
|
|
1050
|
-
worker.port.onmessageerror = (event) => {
|
|
1051
|
-
console.error("[reactor-worker] port message could not be deserialized", event);
|
|
1052
|
-
};
|
|
1053
|
-
const transport = createPortTransport(worker.port);
|
|
1054
|
-
const router = new MessageRouter();
|
|
1055
|
-
router.attach(transport);
|
|
1056
|
-
const documentModelRegistry = new DocumentModelRegistry();
|
|
1057
|
-
documentModelRegistry.registerModules(...args.documentModelModules);
|
|
1058
|
-
documentModelRegistry.registerUpgradeManifests(...args.upgradeManifests);
|
|
1059
|
-
const gitSha = getGitSha();
|
|
1060
|
-
const clientProxy = connectReactorClient(router, {
|
|
1061
|
-
version: {
|
|
1062
|
-
appBuildId: gitSha !== "unknown" ? gitSha : getVersion(),
|
|
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
|
-
},
|
|
1079
|
-
packages: args.packageSpecs
|
|
1080
|
-
}, args.onReload, documentModelRegistry);
|
|
1081
|
-
const busProxy = createReactorEventBusProxy(router);
|
|
1082
|
-
const syncManagerProxy = new SyncManagerProxy(router, busProxy);
|
|
1083
|
-
const modelResolver = new DocumentModelResolver(documentModelRegistry, args.documentModelLoader);
|
|
1084
|
-
busProxy.subscribe(ReactorEventTypes.MODEL_LOADED, (_type, event) => {
|
|
1085
|
-
const { documentType } = event;
|
|
1086
|
-
modelResolver.ensureModelLoaded(documentType).catch((error) => {
|
|
1087
|
-
console.error(`Failed to load model "${documentType}" into tab registry`, error);
|
|
1088
|
-
});
|
|
1089
|
-
});
|
|
1090
|
-
setPGliteDB({
|
|
1091
|
-
db: createRelationalPgliteProxy(router),
|
|
1092
|
-
isLoading: false,
|
|
1093
|
-
error: null
|
|
1094
|
-
});
|
|
1095
|
-
postReactorIdentity(router, toReactorIdentity(args.renown.user));
|
|
1096
|
-
args.renown.on("user", (user) => postReactorIdentity(router, toReactorIdentity(user)));
|
|
1097
|
-
const reactorClientModule = {
|
|
1098
|
-
kind: "worker",
|
|
1099
|
-
client: clientProxy,
|
|
1100
|
-
adminClient: createWorkerAdminClient(router),
|
|
1101
|
-
inspector: createInspectorProxy(router),
|
|
1102
|
-
reactorModule: {
|
|
1103
|
-
documentModelRegistry,
|
|
1104
|
-
syncModule: { syncManager: syncManagerProxy },
|
|
1105
|
-
eventBus: busProxy
|
|
1106
|
-
}
|
|
1107
|
-
};
|
|
1108
|
-
let pingCounter = 0;
|
|
1109
|
-
let missedPings = 0;
|
|
1110
|
-
const pingDeadlines = /* @__PURE__ */ new Map();
|
|
1111
|
-
router.on("pong", (msg) => {
|
|
1112
|
-
const timer = pingDeadlines.get(msg.id);
|
|
1113
|
-
if (timer === void 0) return;
|
|
1114
|
-
clearTimeout(timer);
|
|
1115
|
-
pingDeadlines.delete(msg.id);
|
|
1116
|
-
missedPings = 0;
|
|
1117
|
-
setWorkerConnectionStatus("connected");
|
|
1118
|
-
});
|
|
1119
|
-
const pingInterval = setInterval(() => {
|
|
1120
|
-
const id = `ping${++pingCounter}`;
|
|
1121
|
-
const timer = setTimeout(() => {
|
|
1122
|
-
pingDeadlines.delete(id);
|
|
1123
|
-
missedPings += 1;
|
|
1124
|
-
if (missedPings >= MAX_MISSED_PINGS) setWorkerConnectionStatus("lost");
|
|
1125
|
-
}, PING_DEADLINE_MS);
|
|
1126
|
-
pingDeadlines.set(id, timer);
|
|
1127
|
-
router.post({
|
|
1128
|
-
k: "ping",
|
|
1129
|
-
id
|
|
1130
|
-
});
|
|
1131
|
-
}, PING_INTERVAL_MS);
|
|
1132
|
-
const dispose = () => {
|
|
1133
|
-
clearInterval(pingInterval);
|
|
1134
|
-
for (const timer of pingDeadlines.values()) clearTimeout(timer);
|
|
1135
|
-
pingDeadlines.clear();
|
|
1136
|
-
};
|
|
1137
|
-
return {
|
|
1138
|
-
reactorClientModule,
|
|
1139
|
-
syncManagerProxy,
|
|
1140
|
-
dispose
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
|
-
//#endregion
|
|
1144
|
-
//#region src/utils/reactor-worker-flag.ts
|
|
1145
|
-
const REACTOR_WORKER_QUERY_KEY = "reactorWorker";
|
|
1146
|
-
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
|
-
function isReactorWorkerEnabled() {
|
|
1155
|
-
const configFlag = getRuntimeConfig().connect.instance?.reactorWorker ?? false;
|
|
1156
|
-
if (typeof window === "undefined") return configFlag;
|
|
1157
|
-
const queryParam = new URLSearchParams(window.location.search).get(REACTOR_WORKER_QUERY_KEY);
|
|
1158
|
-
const enabled = resolveReactorWorkerEnabled({
|
|
1159
|
-
configFlag,
|
|
1160
|
-
queryParam,
|
|
1161
|
-
storedValue: window.localStorage.getItem(REACTOR_WORKER_STORAGE_KEY)
|
|
1162
|
-
});
|
|
1163
|
-
if (parseFlag(queryParam) !== void 0) window.localStorage.setItem(REACTOR_WORKER_STORAGE_KEY, enabled ? "true" : "false");
|
|
1164
|
-
return enabled;
|
|
1165
|
-
}
|
|
1166
|
-
function parseFlag(value) {
|
|
1167
|
-
if (value === null || value === void 0) return;
|
|
1168
|
-
const normalized = value.trim().toLowerCase();
|
|
1169
|
-
if (normalized === "true" || normalized === "1") return true;
|
|
1170
|
-
if (normalized === "false" || normalized === "0") return false;
|
|
1171
|
-
}
|
|
1172
|
-
//#endregion
|
|
1173
|
-
//#region src/store/processor-host-module.ts
|
|
1174
|
-
var NullAttachmentService = class {
|
|
1175
|
-
reserve() {
|
|
1176
|
-
return Promise.reject(/* @__PURE__ */ new Error("NullAttachmentService: no attachment service configured"));
|
|
1177
|
-
}
|
|
1178
|
-
stat() {
|
|
1179
|
-
return Promise.reject(/* @__PURE__ */ new Error("NullAttachmentService: no attachment service configured"));
|
|
1180
|
-
}
|
|
1181
|
-
get() {
|
|
1182
|
-
return Promise.reject(/* @__PURE__ */ new Error("NullAttachmentService: no attachment service configured"));
|
|
1183
|
-
}
|
|
1184
|
-
getDownloadTarget() {
|
|
1185
|
-
return Promise.reject(/* @__PURE__ */ new Error("NullAttachmentService: no attachment service configured"));
|
|
1186
|
-
}
|
|
1187
|
-
};
|
|
1188
|
-
async function createProcessorHostModule(reactorClient, readModels, attachmentService) {
|
|
1189
|
-
try {
|
|
1190
|
-
const { pgLite, relationalDb } = await getDb();
|
|
1191
|
-
const { store: analyticsStore } = await createAnalyticsStore({ pgLite });
|
|
1192
|
-
return {
|
|
1193
|
-
...createReactorHostModuleBase({
|
|
1194
|
-
client: reactorClient,
|
|
1195
|
-
readModels,
|
|
1196
|
-
relationalDb,
|
|
1197
|
-
analyticsStore,
|
|
1198
|
-
processorApp: "connect"
|
|
1199
|
-
}),
|
|
1200
|
-
attachments: createAttachmentClient(attachmentService ?? new NullAttachmentService())
|
|
1201
|
-
};
|
|
1202
|
-
} catch (error) {
|
|
1203
|
-
console.error(`Failed to initialize processor host module:`);
|
|
1204
|
-
console.error(error);
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
//#endregion
|
|
1208
|
-
//#region src/store/reactor.ts
|
|
1209
|
-
/**
|
|
1210
|
-
* Subscribe to ph-clint's `/__packages` SSE channel; each `packages-changed`
|
|
1211
|
-
* event sends the full live list, which we diff to add/remove packages.
|
|
1212
|
-
* Best-effort: no-ops when the endpoint is absent (e.g. vite dev).
|
|
1213
|
-
*/
|
|
1214
|
-
function subscribeToPackagesChannel(packageManager) {
|
|
1215
|
-
if (typeof window === "undefined" || typeof EventSource === "undefined") return;
|
|
1216
|
-
let source;
|
|
1217
|
-
try {
|
|
1218
|
-
source = new EventSource("/__packages");
|
|
1219
|
-
} catch (err) {
|
|
1220
|
-
console.debug("[Connect] /__packages subscribe failed:", err);
|
|
1221
|
-
return;
|
|
1222
|
-
}
|
|
1223
|
-
let firstEvent = true;
|
|
1224
|
-
source.addEventListener("packages-changed", (event) => {
|
|
1225
|
-
try {
|
|
1226
|
-
const payload = JSON.parse(event.data);
|
|
1227
|
-
if (!Array.isArray(payload.packages)) return;
|
|
1228
|
-
const next = payload.packages.filter((p) => typeof p === "string");
|
|
1229
|
-
const parseBare = (spec) => {
|
|
1230
|
-
const at = spec.startsWith("@") ? spec.lastIndexOf("@") : spec.indexOf("@");
|
|
1231
|
-
if (at > 0) return {
|
|
1232
|
-
bareName: spec.slice(0, at),
|
|
1233
|
-
version: spec.slice(at + 1)
|
|
1234
|
-
};
|
|
1235
|
-
return { bareName: spec };
|
|
1236
|
-
};
|
|
1237
|
-
const currentByName = new Map(packageManager.getRegistryPackages().map(({ name, version }) => [name, version]));
|
|
1238
|
-
const nextByName = /* @__PURE__ */ new Map();
|
|
1239
|
-
for (const spec of next) {
|
|
1240
|
-
const { bareName, version } = parseBare(spec);
|
|
1241
|
-
nextByName.set(bareName, version);
|
|
1242
|
-
}
|
|
1243
|
-
const isFirst = firstEvent;
|
|
1244
|
-
firstEvent = false;
|
|
1245
|
-
for (const name of currentByName.keys()) if (!nextByName.has(name)) {
|
|
1246
|
-
packageManager.removePackage(name);
|
|
1247
|
-
if (!isFirst) toast(`Removed package ${name}`, { type: "connect-deleted" });
|
|
1248
|
-
}
|
|
1249
|
-
for (const spec of next) {
|
|
1250
|
-
const { bareName, version } = parseBare(spec);
|
|
1251
|
-
const currentVersion = currentByName.get(bareName);
|
|
1252
|
-
const isKnown = currentByName.has(bareName);
|
|
1253
|
-
if (isKnown && (!version || !currentVersion || version === currentVersion)) continue;
|
|
1254
|
-
const isUpdate = isKnown;
|
|
1255
|
-
Promise.resolve(packageManager.addPackage(spec)).then((result) => {
|
|
1256
|
-
if (result.type === "error") {
|
|
1257
|
-
console.error(`[Connect] /__packages addPackage(${spec}) failed:`, result.error);
|
|
1258
|
-
return;
|
|
1259
|
-
}
|
|
1260
|
-
if (isFirst) return;
|
|
1261
|
-
const name = result.package.manifest.name;
|
|
1262
|
-
toast(isUpdate ? `Updated package ${name}` : `Installed package ${name}`, { type: "connect-success" });
|
|
1263
|
-
}, (err) => {
|
|
1264
|
-
console.error(`[Connect] /__packages addPackage(${spec}) threw:`, err);
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
} catch (err) {
|
|
1268
|
-
console.error("[Connect] /__packages event parse failed:", err);
|
|
1269
|
-
}
|
|
1270
|
-
});
|
|
1271
|
-
source.addEventListener("error", () => {});
|
|
1272
|
-
}
|
|
1273
|
-
async function clearReactorStorage() {
|
|
1274
|
-
const module = window.ph?.reactorClientModule;
|
|
1275
|
-
if (module?.kind === "worker") {
|
|
1276
|
-
await module.adminClient.clearStorage();
|
|
1277
|
-
return;
|
|
1278
|
-
}
|
|
1279
|
-
if (module?.kind === "browser") await module.reactorModule?.pg?.close();
|
|
1280
|
-
const targets = (await indexedDB.databases()).map((d) => d.name).filter((n) => !!n && !n.startsWith("ph-pglite-backup::") && /pglite|reactor/i.test(n));
|
|
1281
|
-
await Promise.all(targets.map((name) => new Promise((resolve) => {
|
|
1282
|
-
const req = indexedDB.deleteDatabase(name);
|
|
1283
|
-
req.onsuccess = req.onerror = req.onblocked = () => resolve();
|
|
1284
|
-
})));
|
|
1285
|
-
}
|
|
1286
|
-
async function createReactor(localPackage) {
|
|
1287
|
-
if (!window.ph) window.ph = {};
|
|
1288
|
-
if (window.ph.loading) return;
|
|
1289
|
-
window.ph.loading = true;
|
|
1290
|
-
addPHEventHandlers();
|
|
1291
|
-
setPHToast(toast);
|
|
1292
|
-
const features = await initFeatureFlags();
|
|
1293
|
-
logger.info("Features: @features", JSON.stringify(Object.fromEntries(features), null, 2));
|
|
1294
|
-
const renownChainId = getRuntimeConfig().connect.renown?.chainId;
|
|
1295
|
-
const keyPairStorage = await BrowserKeyStorage.create();
|
|
1296
|
-
const cryptoBuilder = new RenownCryptoBuilder().withKeyPairStorage(keyPairStorage);
|
|
1297
|
-
if (renownChainId !== void 0) cryptoBuilder.withChainId(renownChainId);
|
|
1298
|
-
const renownCrypto = await cryptoBuilder.build();
|
|
1299
|
-
const renown = await new RenownBuilder("connect", {
|
|
1300
|
-
basename: getRuntimeConfig().connect.renown?.namespace ?? phGlobalConfig.routerBasename,
|
|
1301
|
-
baseUrl: phGlobalConfig.renownUrl,
|
|
1302
|
-
switchboardUrl: phGlobalConfig.switchboardUrl,
|
|
1303
|
-
chainId: renownChainId
|
|
1304
|
-
}).withCrypto(renownCrypto).build();
|
|
1305
|
-
const runtimeConfig = getRuntimeConfig();
|
|
1306
|
-
const packageManager = new BrowserPackageManager(phGlobalConfig.routerBasename ?? "", runtimeConfig.packageRegistryUrl ?? null);
|
|
1307
|
-
setVetraPackageManager(packageManager);
|
|
1308
|
-
await packageManager.init(localPackage, runtimeConfig.localPackage?.version, phGlobalConfig.studioMode);
|
|
1309
|
-
try {
|
|
1310
|
-
const { default: registerBundledPackages } = await import("ph-bundled-packages-virtual");
|
|
1311
|
-
registerBundledPackages(packageManager);
|
|
1312
|
-
} catch {}
|
|
1313
|
-
const remotePackages = runtimeConfig.packages.filter((p) => p.provider !== "local").map((p) => p.version ? `${p.packageName}@${p.version}` : p.packageName);
|
|
1314
|
-
(await packageManager.addPackages(remotePackages)).map((r) => {
|
|
1315
|
-
if (r.type === "error") console.error(r.error);
|
|
1316
|
-
});
|
|
1317
|
-
if (runtimeConfig.connect?.packages?.liveReload) subscribeToPackagesChannel(packageManager);
|
|
1318
|
-
const documentModelModules = packageManager.packages.flatMap((pkg) => pkg.documentModels).filter((module, index, modules) => modules.findIndex((m) => m.documentModel.global.id === module.documentModel.global.id && m.version === module.version) === index);
|
|
1319
|
-
const upgradeManifests = packageManager.packages.flatMap((pkg) => pkg.upgradeManifests).filter((manifest, index, manifests) => manifest !== void 0 && manifests.findIndex((m) => m && m.documentType === manifest.documentType) === index);
|
|
1320
|
-
const discoveryService = packageManager.cdnUrl !== null ? new PackageDiscoveryService(packageManager, new RegistryClient(packageManager.cdnUrl), {
|
|
1321
|
-
mode: "immediate",
|
|
1322
|
-
storageKey: phGlobalConfig.routerBasename ?? ""
|
|
1323
|
-
}) : new NoRegistryDiscoveryService(packageManager);
|
|
1324
|
-
setPackageDiscoveryService(discoveryService);
|
|
1325
|
-
const reactorFeatureFlags = runtimeConfig.connect?.reactor?.featureFlags ?? {};
|
|
1326
|
-
const enabledReactorFlags = Object.entries(reactorFeatureFlags).filter(([, enabled]) => enabled).map(([name]) => name);
|
|
1327
|
-
if (enabledReactorFlags.length > 0) logger.info(`Reactor feature flags: ${enabledReactorFlags.join(", ")}`);
|
|
1328
|
-
let reactorClientModule;
|
|
1329
|
-
if (isReactorWorkerEnabled()) {
|
|
1330
|
-
const packageSpecs = packageManager.getRegistryPackages().map((p) => p.version ? `${p.name}@${p.version}` : p.name);
|
|
1331
|
-
const registryClient = new RegistryClient(packageManager.cdnUrl ?? "");
|
|
1332
|
-
const workerClient = createWorkerReactorClientModule({
|
|
1333
|
-
namespace: REACTOR_INSTANCE_NAMESPACE,
|
|
1334
|
-
relationalNamespace: RELATIONAL_PGLITE_NAME,
|
|
1335
|
-
cdnUrl: packageManager.cdnUrl ?? "",
|
|
1336
|
-
packageSpecs,
|
|
1337
|
-
studioMode: phGlobalConfig.studioMode,
|
|
1338
|
-
renownChainId,
|
|
1339
|
-
featureFlags: reactorFeatureFlags,
|
|
1340
|
-
documentModelModules,
|
|
1341
|
-
upgradeManifests,
|
|
1342
|
-
documentModelLoader: { async load(documentType) {
|
|
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
|
-
} },
|
|
1352
|
-
renown,
|
|
1353
|
-
onReload: (reason, workerGen) => {
|
|
1354
|
-
logger.warn("Reactor worker requested reload: @reason", reason);
|
|
1355
|
-
if (workerGen) bumpWorkerGen(REACTOR_INSTANCE_NAMESPACE, workerGen);
|
|
1356
|
-
window.location.reload();
|
|
1357
|
-
}
|
|
1358
|
-
});
|
|
1359
|
-
reactorClientModule = workerClient.reactorClientModule;
|
|
1360
|
-
try {
|
|
1361
|
-
await workerClient.syncManagerProxy.startup();
|
|
1362
|
-
} catch (error) {
|
|
1363
|
-
window.ph.loading = false;
|
|
1364
|
-
logger.error("Reactor worker failed to start: @error", error);
|
|
1365
|
-
throw error;
|
|
1366
|
-
}
|
|
1367
|
-
} else reactorClientModule = await createBrowserReactor(documentModelModules, upgradeManifests, renown, reactorFeatureFlags, discoveryService);
|
|
1368
|
-
const drives = await getDrives(reactorClientModule.client);
|
|
1369
|
-
await login(getDidFromUrl(), renown);
|
|
1370
|
-
const documentCache = new DocumentCache(reactorClientModule.client);
|
|
1371
|
-
setDefaultPHGlobalConfig(buildPHGlobalConfig(phGlobalConfig.basePath ?? "/", phGlobalConfig.routerBasename ?? "/", runtimeConfig.connect ?? {}));
|
|
1372
|
-
const path = window.location.pathname;
|
|
1373
|
-
const driveSlug = extractDriveSlugFromPath(path);
|
|
1374
|
-
const nodeSlug = extractNodeSlugFromPath(path);
|
|
1375
|
-
setReactorClientModule(reactorClientModule);
|
|
1376
|
-
setReactorClient(reactorClientModule.client);
|
|
1377
|
-
const _defaultDrivesUrl = phGlobalConfig.defaultDrivesUrl;
|
|
1378
|
-
if (_defaultDrivesUrl) {
|
|
1379
|
-
let switchboardOrigin;
|
|
1380
|
-
try {
|
|
1381
|
-
switchboardOrigin = new URL(_defaultDrivesUrl).origin;
|
|
1382
|
-
} catch {}
|
|
1383
|
-
if (switchboardOrigin) {
|
|
1384
|
-
const attachmentJwtHandler = async (_url) => {
|
|
1385
|
-
if (!renown.user) return void 0;
|
|
1386
|
-
return renown.getBearerToken({ expiresIn: 10 });
|
|
1387
|
-
};
|
|
1388
|
-
setAttachmentService(createRemoteAttachmentService({
|
|
1389
|
-
remoteUrl: switchboardOrigin,
|
|
1390
|
-
jwtHandler: attachmentJwtHandler,
|
|
1391
|
-
uploadTransport: createXhrUploadTransport()
|
|
1392
|
-
}));
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
setDocumentCache(documentCache);
|
|
1396
|
-
setRenown(renown);
|
|
1397
|
-
setDrives(drives);
|
|
1398
|
-
setFeatures(features);
|
|
1399
|
-
const defaultDrivesConfig = getDefaultDrives(runtimeConfig);
|
|
1400
|
-
if (defaultDrivesConfig.length > 0) addDefaultDrivesForNewReactor(defaultDrivesConfig).catch((error) => console.error("Failed to add default drives:", error));
|
|
1401
|
-
const remoteUrl = getDriveUrl();
|
|
1402
|
-
if (remoteUrl) addRemoteDrive(remoteUrl, void 0).catch((error) => console.error(`Failed to add remote drive from ${remoteUrl}:`, error));
|
|
1403
|
-
setSelectedDrive(driveSlug);
|
|
1404
|
-
setSelectedNode(nodeSlug);
|
|
1405
|
-
const reactorClient = reactorClientModule.client;
|
|
1406
|
-
for (const driveType of DRIVE_DOCUMENT_TYPES) reactorClient.subscribe({ type: driveType }, (event) => {
|
|
1407
|
-
logger.verbose("ReactorClient subscription event: @event", event);
|
|
1408
|
-
refreshReactorDataClient(reactorClientModule.client).catch((e) => logger.error("@error", e));
|
|
1409
|
-
});
|
|
1410
|
-
reactorClient.subscribe({}, (event) => {
|
|
1411
|
-
if (event.type !== DocumentChangeType.Deleted) return;
|
|
1412
|
-
const deletedId = event.context?.childId;
|
|
1413
|
-
if (!deletedId) return;
|
|
1414
|
-
const selectedDriveId = window.ph?.selectedDriveId;
|
|
1415
|
-
const selectedNodeId = window.ph?.selectedNodeId;
|
|
1416
|
-
if (selectedDriveId && deletedId === selectedDriveId) {
|
|
1417
|
-
setSelectedDrive(void 0);
|
|
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
|
-
}
|
|
1425
|
-
});
|
|
1426
|
-
await refreshReactorDataClient(reactorClientModule.client);
|
|
1427
|
-
const packagesWithProcessorFactories = packageManager.packages.filter((pkg) => pkg.processorFactory !== void 0);
|
|
1428
|
-
const reactorModule = reactorClientModule.kind === "browser" ? reactorClientModule.reactorModule : void 0;
|
|
1429
|
-
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);
|
|
1430
|
-
else if (packagesWithProcessorFactories.length > 0 && reactorModule) {
|
|
1431
|
-
const readModels = reactorModule.readModelCoordinator.readModels;
|
|
1432
|
-
const processorHostModule = await createProcessorHostModule(reactorClientModule.client, readModels, window.ph?.attachmentService);
|
|
1433
|
-
if (processorHostModule !== void 0) await Promise.all(packagesWithProcessorFactories.map(async (pkg) => {
|
|
1434
|
-
const { manifest, processorFactory } = pkg;
|
|
1435
|
-
const name = manifest.name;
|
|
1436
|
-
const id = manifest.name;
|
|
1437
|
-
const version = packageManager.getPackageVersion(name);
|
|
1438
|
-
const label = version ? `${name}@${version}` : name;
|
|
1439
|
-
logger.info("Loading processor factory: @label", label);
|
|
1440
|
-
try {
|
|
1441
|
-
const factory = await processorFactory?.(processorHostModule);
|
|
1442
|
-
if (!factory) return;
|
|
1443
|
-
await reactorModule.processorManager.registerFactory(id, factory);
|
|
1444
|
-
} catch (error) {
|
|
1445
|
-
logger.error(`Error registering processor: @label`, label);
|
|
1446
|
-
logger.error("@error", error);
|
|
1447
|
-
}
|
|
1448
|
-
}));
|
|
1449
|
-
}
|
|
1450
|
-
window.ph.loading = false;
|
|
1451
|
-
}
|
|
1452
|
-
function getDidFromUrl() {
|
|
1453
|
-
const didComponent = new URLSearchParams(window.location.search).get("user");
|
|
1454
|
-
return didComponent ? decodeURIComponent(didComponent) : void 0;
|
|
1455
|
-
}
|
|
1456
|
-
function getDriveUrl() {
|
|
1457
|
-
const driveUrl = new URLSearchParams(window.location.search).get("driveUrl");
|
|
1458
|
-
return driveUrl ? decodeURIComponent(driveUrl) : void 0;
|
|
1459
|
-
}
|
|
1460
|
-
//#endregion
|
|
1461
|
-
export { createReactor as n, clearReactorStorage as t };
|
|
1462
|
-
|
|
1463
|
-
//# sourceMappingURL=reactor-yC8BveHb.js.map
|
|
1464
|
-
//# debugId=f8f2f6b8-9d33-50e7-af3e-fcd10c6d78da
|