@nextclaw/app-runtime 0.9.13 → 0.9.15
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 +2 -2
- package/dist/{main.js → app/main.js} +2 -2
- package/dist/app/main.js.map +1 -0
- package/dist/{commands → controllers}/create.controller.d.ts +2 -2
- package/dist/controllers/create.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/create.controller.js +2 -2
- package/dist/controllers/create.controller.js.map +1 -0
- package/dist/{commands → controllers}/dev.controller.js +1 -1
- package/dist/controllers/dev.controller.js.map +1 -0
- package/dist/{commands → controllers}/grant.controller.d.ts +3 -3
- package/dist/controllers/grant.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/grant.controller.js +2 -2
- package/dist/controllers/grant.controller.js.map +1 -0
- package/dist/{commands → controllers}/info.controller.d.ts +2 -2
- package/dist/controllers/info.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/info.controller.js +2 -2
- package/dist/controllers/info.controller.js.map +1 -0
- package/dist/{commands → controllers}/inspect.controller.js +8 -2
- package/dist/controllers/inspect.controller.js.map +1 -0
- package/dist/{commands → controllers}/install.controller.d.ts +2 -2
- package/dist/controllers/install.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/install.controller.js +2 -2
- package/dist/controllers/install.controller.js.map +1 -0
- package/dist/{commands → controllers}/list.controller.d.ts +2 -2
- package/dist/controllers/list.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/list.controller.js +2 -2
- package/dist/controllers/list.controller.js.map +1 -0
- package/dist/controllers/pack.controller.d.ts +19 -0
- package/dist/controllers/pack.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/pack.controller.js +8 -4
- package/dist/controllers/pack.controller.js.map +1 -0
- package/dist/{commands → controllers}/permissions.controller.d.ts +2 -2
- package/dist/controllers/permissions.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/permissions.controller.js +2 -2
- package/dist/controllers/permissions.controller.js.map +1 -0
- package/dist/{commands → controllers}/publish.controller.d.ts +3 -3
- package/dist/controllers/publish.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/publish.controller.js +2 -2
- package/dist/controllers/publish.controller.js.map +1 -0
- package/dist/{commands → controllers}/registry.controller.d.ts +2 -2
- package/dist/controllers/registry.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/registry.controller.js +2 -2
- package/dist/controllers/registry.controller.js.map +1 -0
- package/dist/{commands → controllers}/revoke.controller.d.ts +2 -2
- package/dist/controllers/revoke.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/revoke.controller.js +2 -2
- package/dist/controllers/revoke.controller.js.map +1 -0
- package/dist/{commands → controllers}/run.controller.js +8 -6
- package/dist/controllers/run.controller.js.map +1 -0
- package/dist/{commands → controllers}/uninstall.controller.d.ts +2 -2
- package/dist/controllers/uninstall.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/uninstall.controller.js +2 -2
- package/dist/controllers/uninstall.controller.js.map +1 -0
- package/dist/{commands → controllers}/update.controller.d.ts +2 -2
- package/dist/controllers/update.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/update.controller.js +2 -2
- package/dist/controllers/update.controller.js.map +1 -0
- package/dist/{commands → controllers}/validate-publish.controller.d.ts +3 -3
- package/dist/controllers/validate-publish.controller.d.ts.map +1 -0
- package/dist/{commands → controllers}/validate-publish.controller.js +9 -5
- package/dist/controllers/validate-publish.controller.js.map +1 -0
- package/dist/index.d.ts +51 -51
- package/dist/index.js +46 -45
- package/dist/package.js +1 -1
- package/dist/{runtime → services}/app-build.service.d.ts +2 -2
- package/dist/services/app-build.service.d.ts.map +1 -0
- package/dist/{runtime → services}/app-build.service.js +4 -2
- package/dist/services/app-build.service.js.map +1 -0
- package/dist/{bundle → services}/app-bundle.service.d.ts +18 -6
- package/dist/services/app-bundle.service.d.ts.map +1 -0
- package/dist/services/app-bundle.service.js +305 -0
- package/dist/services/app-bundle.service.js.map +1 -0
- package/dist/{permissions → services}/app-grant.service.d.ts +4 -4
- package/dist/services/app-grant.service.d.ts.map +1 -0
- package/dist/{permissions → services}/app-grant.service.js +7 -4
- package/dist/services/app-grant.service.js.map +1 -0
- package/dist/{paths → services}/app-home.service.d.ts +2 -1
- package/dist/services/app-home.service.d.ts.map +1 -0
- package/dist/{paths → services}/app-home.service.js +4 -1
- package/dist/services/app-home.service.js.map +1 -0
- package/dist/{host → services}/app-host.service.d.ts +2 -2
- package/dist/services/app-host.service.d.ts.map +1 -0
- package/dist/{host → services}/app-host.service.js +3 -3
- package/dist/services/app-host.service.js.map +1 -0
- package/dist/services/app-install-source.service.js +72 -0
- package/dist/services/app-install-source.service.js.map +1 -0
- package/dist/services/app-installation.service.d.ts +48 -0
- package/dist/services/app-installation.service.d.ts.map +1 -0
- package/dist/services/app-installation.service.js +411 -0
- package/dist/services/app-installation.service.js.map +1 -0
- package/dist/services/app-instance.service.d.ts +34 -0
- package/dist/services/app-instance.service.d.ts.map +1 -0
- package/dist/{host → services}/app-instance.service.js +4 -4
- package/dist/services/app-instance.service.js.map +1 -0
- package/dist/{manifest → services}/app-manifest.service.d.ts +12 -2
- package/dist/services/app-manifest.service.d.ts.map +1 -0
- package/dist/services/app-manifest.service.js +271 -0
- package/dist/services/app-manifest.service.js.map +1 -0
- package/dist/{publish → services}/app-marketplace-client.service.d.ts +2 -2
- package/dist/services/app-marketplace-client.service.d.ts.map +1 -0
- package/dist/{publish → services}/app-marketplace-client.service.js +2 -2
- package/dist/services/app-marketplace-client.service.js.map +1 -0
- package/dist/{publish → services}/app-marketplace-metadata.service.d.ts +7 -3
- package/dist/services/app-marketplace-metadata.service.d.ts.map +1 -0
- package/dist/{publish → services}/app-marketplace-metadata.service.js +45 -3
- package/dist/services/app-marketplace-metadata.service.js.map +1 -0
- package/dist/{permissions → services}/app-permissions.service.d.ts +3 -3
- package/dist/services/app-permissions.service.d.ts.map +1 -0
- package/dist/{permissions → services}/app-permissions.service.js +4 -1
- package/dist/services/app-permissions.service.js.map +1 -0
- package/dist/{publish → services}/app-publish-validation.service.d.ts +9 -7
- package/dist/services/app-publish-validation.service.d.ts.map +1 -0
- package/dist/{publish → services}/app-publish-validation.service.js +14 -10
- package/dist/services/app-publish-validation.service.js.map +1 -0
- package/dist/{publish → services}/app-publish.service.d.ts +5 -5
- package/dist/services/app-publish.service.d.ts.map +1 -0
- package/dist/{publish → services}/app-publish.service.js +10 -7
- package/dist/services/app-publish.service.js.map +1 -0
- package/dist/{registry → services}/app-registry-config.service.d.ts +3 -3
- package/dist/{registry → services}/app-registry-config.service.d.ts.map +1 -1
- package/dist/{registry → services}/app-registry-config.service.js +3 -3
- package/dist/services/app-registry-config.service.js.map +1 -0
- package/dist/{registry → services}/app-registry.service.d.ts +20 -5
- package/dist/services/app-registry.service.d.ts.map +1 -0
- package/dist/services/app-registry.service.js +228 -0
- package/dist/services/app-registry.service.js.map +1 -0
- package/dist/{registry → services}/app-remote-registry-client.service.d.ts +6 -2
- package/dist/services/app-remote-registry-client.service.d.ts.map +1 -0
- package/dist/{registry → services}/app-remote-registry-client.service.js +54 -8
- package/dist/services/app-remote-registry-client.service.js.map +1 -0
- package/dist/{cli → services}/app-runtime-cli.service.d.ts +1 -1
- package/dist/services/app-runtime-cli.service.d.ts.map +1 -0
- package/dist/{cli → services}/app-runtime-cli.service.js +19 -19
- package/dist/services/app-runtime-cli.service.js.map +1 -0
- package/dist/{cli → services}/app-runtime-options.service.d.ts +6 -6
- package/dist/services/app-runtime-options.service.d.ts.map +1 -0
- package/dist/{cli → services}/app-runtime-options.service.js +3 -9
- package/dist/services/app-runtime-options.service.js.map +1 -0
- package/dist/{runtime → services}/app-runtime-toolchain.service.d.ts +1 -1
- package/dist/services/app-runtime-toolchain.service.d.ts.map +1 -0
- package/dist/{runtime → services}/app-runtime-toolchain.service.js +1 -1
- package/dist/services/app-runtime-toolchain.service.js.map +1 -0
- package/dist/{scaffold → services}/app-scaffold.service.d.ts +1 -1
- package/dist/{scaffold → services}/app-scaffold.service.d.ts.map +1 -1
- package/dist/{scaffold → services}/app-scaffold.service.js +1 -1
- package/dist/{scaffold → services}/app-scaffold.service.js.map +1 -1
- package/dist/{scaffold → services}/app-ts-http-lite-scaffold-template.service.d.ts +1 -1
- package/dist/{scaffold → services}/app-ts-http-lite-scaffold-template.service.d.ts.map +1 -1
- package/dist/{scaffold → services}/app-ts-http-lite-scaffold-template.service.js +1 -1
- package/dist/{scaffold → services}/app-ts-http-lite-scaffold-template.service.js.map +1 -1
- package/dist/{scaffold → services}/app-ts-http-scaffold-template.service.d.ts +1 -1
- package/dist/{scaffold → services}/app-ts-http-scaffold-template.service.d.ts.map +1 -1
- package/dist/{scaffold → services}/app-ts-http-scaffold-template.service.js +1 -1
- package/dist/{scaffold → services}/app-ts-http-scaffold-template.service.js.map +1 -1
- package/dist/{bridge → services}/host-bridge.service.d.ts +2 -2
- package/dist/services/host-bridge.service.d.ts.map +1 -0
- package/dist/{bridge → services}/host-bridge.service.js +1 -1
- package/dist/services/host-bridge.service.js.map +1 -0
- package/dist/services/main-runner.service.d.ts +9 -0
- package/dist/services/main-runner.service.d.ts.map +1 -0
- package/dist/services/main-runner.service.js +6 -0
- package/dist/services/main-runner.service.js.map +1 -0
- package/dist/{publish → services}/platform-auth-state.service.d.ts +1 -1
- package/dist/services/platform-auth-state.service.d.ts.map +1 -0
- package/dist/{publish → services}/platform-auth-state.service.js +1 -1
- package/dist/services/platform-auth-state.service.js.map +1 -0
- package/dist/{ui → services}/ui-server.service.d.ts +3 -3
- package/dist/services/ui-server.service.d.ts.map +1 -0
- package/dist/{ui → services}/ui-server.service.js +1 -1
- package/dist/services/ui-server.service.js.map +1 -0
- package/dist/{runtime → services}/wasm-main-runner.service.d.ts +3 -3
- package/dist/services/wasm-main-runner.service.d.ts.map +1 -0
- package/dist/{runtime → services}/wasm-main-runner.service.js +2 -2
- package/dist/services/wasm-main-runner.service.js.map +1 -0
- package/dist/{sidecar → services}/wasm-sidecar-client.service.d.ts +1 -1
- package/dist/services/wasm-sidecar-client.service.d.ts.map +1 -0
- package/dist/{sidecar → services}/wasm-sidecar-client.service.js +1 -1
- package/dist/services/wasm-sidecar-client.service.js.map +1 -0
- package/dist/{runtime → services}/wasmtime-wasi-http-component.service.d.ts +1 -1
- package/dist/services/wasmtime-wasi-http-component.service.d.ts.map +1 -0
- package/dist/{runtime → services}/wasmtime-wasi-http-component.service.js +1 -1
- package/dist/services/wasmtime-wasi-http-component.service.js.map +1 -0
- package/dist/{bundle → types}/app-bundle.types.d.ts +1 -1
- package/dist/types/app-bundle.types.d.ts.map +1 -0
- package/dist/{install → types}/app-installation.types.d.ts +29 -7
- package/dist/types/app-installation.types.d.ts.map +1 -0
- package/dist/types/app-manifest.types.d.ts +119 -0
- package/dist/types/app-manifest.types.d.ts.map +1 -0
- package/dist/types/app-manifest.types.js +11 -0
- package/dist/types/app-manifest.types.js.map +1 -0
- package/dist/{permissions → types}/app-permissions.types.d.ts +2 -2
- package/dist/types/app-permissions.types.d.ts.map +1 -0
- package/dist/{publish → types}/app-publish.types.d.ts +11 -5
- package/dist/types/app-publish.types.d.ts.map +1 -0
- package/dist/{publish → types}/app-publish.types.js +1 -1
- package/dist/types/app-publish.types.js.map +1 -0
- package/dist/{registry → types}/app-registry.types.d.ts +11 -4
- package/dist/types/app-registry.types.d.ts.map +1 -0
- package/dist/{registry → types}/app-remote-registry.types.d.ts +3 -3
- package/dist/types/app-remote-registry.types.d.ts.map +1 -0
- package/dist/{registry → types}/app-remote-registry.types.js +1 -1
- package/dist/types/app-remote-registry.types.js.map +1 -0
- package/dist/{runtime → types}/main-runner.types.d.ts +3 -3
- package/dist/types/main-runner.types.d.ts.map +1 -0
- package/package.json +10 -3
- package/dist/bridge/host-bridge.service.d.ts.map +0 -1
- package/dist/bridge/host-bridge.service.js.map +0 -1
- package/dist/bundle/app-bundle.service.d.ts.map +0 -1
- package/dist/bundle/app-bundle.service.js +0 -196
- package/dist/bundle/app-bundle.service.js.map +0 -1
- package/dist/bundle/app-bundle.types.d.ts.map +0 -1
- package/dist/cli/app-runtime-cli.service.d.ts.map +0 -1
- package/dist/cli/app-runtime-cli.service.js.map +0 -1
- package/dist/cli/app-runtime-options.service.d.ts.map +0 -1
- package/dist/cli/app-runtime-options.service.js.map +0 -1
- package/dist/commands/create.controller.d.ts.map +0 -1
- package/dist/commands/create.controller.js.map +0 -1
- package/dist/commands/dev.controller.js.map +0 -1
- package/dist/commands/grant.controller.d.ts.map +0 -1
- package/dist/commands/grant.controller.js.map +0 -1
- package/dist/commands/info.controller.d.ts.map +0 -1
- package/dist/commands/info.controller.js.map +0 -1
- package/dist/commands/inspect.controller.js.map +0 -1
- package/dist/commands/install.controller.d.ts.map +0 -1
- package/dist/commands/install.controller.js.map +0 -1
- package/dist/commands/list.controller.d.ts.map +0 -1
- package/dist/commands/list.controller.js.map +0 -1
- package/dist/commands/pack.controller.d.ts +0 -17
- package/dist/commands/pack.controller.d.ts.map +0 -1
- package/dist/commands/pack.controller.js.map +0 -1
- package/dist/commands/permissions.controller.d.ts.map +0 -1
- package/dist/commands/permissions.controller.js.map +0 -1
- package/dist/commands/publish.controller.d.ts.map +0 -1
- package/dist/commands/publish.controller.js.map +0 -1
- package/dist/commands/registry.controller.d.ts.map +0 -1
- package/dist/commands/registry.controller.js.map +0 -1
- package/dist/commands/revoke.controller.d.ts.map +0 -1
- package/dist/commands/revoke.controller.js.map +0 -1
- package/dist/commands/run.controller.js.map +0 -1
- package/dist/commands/uninstall.controller.d.ts.map +0 -1
- package/dist/commands/uninstall.controller.js.map +0 -1
- package/dist/commands/update.controller.d.ts.map +0 -1
- package/dist/commands/update.controller.js.map +0 -1
- package/dist/commands/validate-publish.controller.d.ts.map +0 -1
- package/dist/commands/validate-publish.controller.js.map +0 -1
- package/dist/host/app-host.service.d.ts.map +0 -1
- package/dist/host/app-host.service.js.map +0 -1
- package/dist/host/app-instance.service.d.ts +0 -34
- package/dist/host/app-instance.service.d.ts.map +0 -1
- package/dist/host/app-instance.service.js.map +0 -1
- package/dist/install/app-installation.service.d.ts +0 -41
- package/dist/install/app-installation.service.d.ts.map +0 -1
- package/dist/install/app-installation.service.js +0 -276
- package/dist/install/app-installation.service.js.map +0 -1
- package/dist/install/app-installation.types.d.ts.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/manifest/app-manifest.service.d.ts.map +0 -1
- package/dist/manifest/app-manifest.service.js +0 -147
- package/dist/manifest/app-manifest.service.js.map +0 -1
- package/dist/manifest/app-manifest.types.d.ts +0 -68
- package/dist/manifest/app-manifest.types.d.ts.map +0 -1
- package/dist/paths/app-home.service.d.ts.map +0 -1
- package/dist/paths/app-home.service.js.map +0 -1
- package/dist/permissions/app-grant.service.d.ts.map +0 -1
- package/dist/permissions/app-grant.service.js.map +0 -1
- package/dist/permissions/app-permissions.service.d.ts.map +0 -1
- package/dist/permissions/app-permissions.service.js.map +0 -1
- package/dist/permissions/app-permissions.types.d.ts.map +0 -1
- package/dist/publish/app-marketplace-client.service.d.ts.map +0 -1
- package/dist/publish/app-marketplace-client.service.js.map +0 -1
- package/dist/publish/app-marketplace-metadata.service.d.ts.map +0 -1
- package/dist/publish/app-marketplace-metadata.service.js.map +0 -1
- package/dist/publish/app-publish-validation.service.d.ts.map +0 -1
- package/dist/publish/app-publish-validation.service.js.map +0 -1
- package/dist/publish/app-publish.service.d.ts.map +0 -1
- package/dist/publish/app-publish.service.js.map +0 -1
- package/dist/publish/app-publish.types.d.ts.map +0 -1
- package/dist/publish/app-publish.types.js.map +0 -1
- package/dist/publish/platform-auth-state.service.d.ts.map +0 -1
- package/dist/publish/platform-auth-state.service.js.map +0 -1
- package/dist/registry/app-registry-config.service.js.map +0 -1
- package/dist/registry/app-registry.service.d.ts.map +0 -1
- package/dist/registry/app-registry.service.js +0 -118
- package/dist/registry/app-registry.service.js.map +0 -1
- package/dist/registry/app-registry.types.d.ts.map +0 -1
- package/dist/registry/app-remote-registry-client.service.d.ts.map +0 -1
- package/dist/registry/app-remote-registry-client.service.js.map +0 -1
- package/dist/registry/app-remote-registry.types.d.ts.map +0 -1
- package/dist/registry/app-remote-registry.types.js.map +0 -1
- package/dist/runtime/app-build.service.d.ts.map +0 -1
- package/dist/runtime/app-build.service.js.map +0 -1
- package/dist/runtime/app-runtime-toolchain.service.d.ts.map +0 -1
- package/dist/runtime/app-runtime-toolchain.service.js.map +0 -1
- package/dist/runtime/main-runner.service.d.ts +0 -9
- package/dist/runtime/main-runner.service.d.ts.map +0 -1
- package/dist/runtime/main-runner.service.js +0 -6
- package/dist/runtime/main-runner.service.js.map +0 -1
- package/dist/runtime/main-runner.types.d.ts.map +0 -1
- package/dist/runtime/wasm-main-runner.service.d.ts.map +0 -1
- package/dist/runtime/wasm-main-runner.service.js.map +0 -1
- package/dist/runtime/wasmtime-wasi-http-component.service.d.ts.map +0 -1
- package/dist/runtime/wasmtime-wasi-http-component.service.js.map +0 -1
- package/dist/sidecar/wasm-sidecar-client.service.d.ts.map +0 -1
- package/dist/sidecar/wasm-sidecar-client.service.js.map +0 -1
- package/dist/ui/ui-server.service.d.ts.map +0 -1
- package/dist/ui/ui-server.service.js.map +0 -1
- /package/dist/{main.d.ts → app/main.d.ts} +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AppManifestService } from "./app-manifest.service.js";
|
|
2
|
+
import { AppBundleService } from "./app-bundle.service.js";
|
|
3
|
+
import { AppDocumentGrantMap } from "../types/app-permissions.types.js";
|
|
4
|
+
import { AppHomeService } from "./app-home.service.js";
|
|
5
|
+
import { AppRegistryService } from "./app-registry.service.js";
|
|
6
|
+
import { AppBuildService } from "./app-build.service.js";
|
|
7
|
+
import { AppRegistryConfigService } from "./app-registry-config.service.js";
|
|
8
|
+
import { AppRemoteRegistryClientService } from "./app-remote-registry-client.service.js";
|
|
9
|
+
import { AppActivationResult, AppInfoResult, AppInstallProgressHandler, AppInstallResult, AppLaunchResolution, AppRollbackResult, AppUninstallResult, AppUpdateResult, InstalledAppListItem } from "../types/app-installation.types.js";
|
|
10
|
+
|
|
11
|
+
//#region src/services/app-installation.service.d.ts
|
|
12
|
+
declare class AppInstallationService {
|
|
13
|
+
private readonly appHomeService;
|
|
14
|
+
private readonly bundleService;
|
|
15
|
+
private readonly manifestService;
|
|
16
|
+
private readonly buildService;
|
|
17
|
+
private readonly registryService;
|
|
18
|
+
private readonly registryConfigService;
|
|
19
|
+
private readonly remoteRegistryClient;
|
|
20
|
+
private readonly installSourceService;
|
|
21
|
+
constructor(appHomeService?: AppHomeService, bundleService?: AppBundleService, manifestService?: AppManifestService, buildService?: AppBuildService, registryService?: AppRegistryService, registryConfigService?: AppRegistryConfigService, remoteRegistryClient?: AppRemoteRegistryClientService);
|
|
22
|
+
install: (appSource: string, options?: {
|
|
23
|
+
registryUrl?: string;
|
|
24
|
+
onProgress?: AppInstallProgressHandler;
|
|
25
|
+
}) => Promise<AppInstallResult>;
|
|
26
|
+
update: (appId: string, options?: {
|
|
27
|
+
version?: string;
|
|
28
|
+
registryUrl?: string;
|
|
29
|
+
onProgress?: AppInstallProgressHandler;
|
|
30
|
+
}) => Promise<AppUpdateResult>;
|
|
31
|
+
uninstall: (appId: string, purgeData: boolean) => Promise<AppUninstallResult>;
|
|
32
|
+
list: () => Promise<InstalledAppListItem[]>;
|
|
33
|
+
reconcileFilesystem: () => Promise<void>;
|
|
34
|
+
info: (appId: string) => Promise<AppInfoResult>;
|
|
35
|
+
setEnabled: (appId: string, enabled: boolean) => Promise<AppActivationResult>;
|
|
36
|
+
rollback: (appId: string, version: string) => Promise<AppRollbackResult>;
|
|
37
|
+
resolveLaunch: (appReference: string, explicitDocumentGrantMap: AppDocumentGrantMap) => Promise<AppLaunchResolution>;
|
|
38
|
+
persistGrants: (appId: string | undefined, documentGrantMap: AppDocumentGrantMap) => Promise<void>;
|
|
39
|
+
private copyToImmutableInstallDirectory;
|
|
40
|
+
private materializeDistribution;
|
|
41
|
+
private reconcileGeneratedSiblings;
|
|
42
|
+
private readDirectories;
|
|
43
|
+
private pathExists;
|
|
44
|
+
private isMissingFileError;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { AppInstallationService };
|
|
48
|
+
//# sourceMappingURL=app-installation.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-installation.service.d.ts","names":[],"sources":["../../src/services/app-installation.service.ts"],"mappings":";;;;;;;;;;;cA6Ba,sBAAA;EAAA,iBAIQ,cAAA;EAAA,iBACA,aAAA;EAAA,iBACA,eAAA;EAAA,iBACA,YAAA;EAAA,iBACA,eAAA;EAAA,iBACA,qBAAA;EAAA,iBAGA,oBAAA;EAAA,iBAXF,oBAAA;cAGE,cAAA,GAAgB,cAAA,EAChB,aAAA,GAAe,gBAAA,EACf,eAAA,GAAiB,kBAAA,EACjB,YAAA,GAAc,eAAA,EACd,eAAA,GAAiB,kBAAA,EACjB,qBAAA,GAAuB,wBAAA,EAGvB,oBAAA,GAAsB,8BAAA;EAUzC,OAAA,GACE,SAAA,UACA,OAAA;IACE,WAAA;IACA,UAAA,GAAa,yBAAA;EAAA,MAEd,OAAA,CAAQ,gBAAA;EAoIX,MAAA,GACE,KAAA,UACA,OAAA;IACE,OAAA;IACA,WAAA;IACA,UAAA,GAAa,yBAAA;EAAA,MAEd,OAAA,CAAQ,eAAA;EAiFX,SAAA,GACE,KAAA,UACA,SAAA,cACC,OAAA,CAAQ,kBAAA;EAwDX,IAAA,QAAiB,OAAA,CAAQ,oBAAA;EAkBzB,mBAAA,QAAgC,OAAA;EAiBhC,IAAA,GAAc,KAAA,aAAgB,OAAA,CAAQ,aAAA;EAmCtC,UAAA,GAAoB,KAAA,UAAe,OAAA,cAAmB,OAAA,CAAQ,mBAAA;EAS9D,QAAA,GAAkB,KAAA,UAAe,OAAA,aAAkB,OAAA,CAAQ,iBAAA;EAgC3D,aAAA,GACE,YAAA,UACA,wBAAA,EAA0B,mBAAA,KACzB,OAAA,CAAQ,mBAAA;EA2BX,aAAA,GACE,KAAA,sBACA,gBAAA,EAAkB,mBAAA,KACjB,OAAA;EAAA,QAOK,+BAAA;EAAA,QA4BA,uBAAA;EAAA,QAoBA,0BAAA;EAAA,QAyBA,eAAA;EAAA,QAaA,UAAA;EAAA,QASA,kBAAA;AAAA"}
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { AppManifestService } from "./app-manifest.service.js";
|
|
2
|
+
import { isAppComponentManifestBundle, isAppStandaloneManifestBundle } from "../types/app-manifest.types.js";
|
|
3
|
+
import { AppBundleService } from "./app-bundle.service.js";
|
|
4
|
+
import { AppHomeService } from "./app-home.service.js";
|
|
5
|
+
import { AppBuildService } from "./app-build.service.js";
|
|
6
|
+
import { AppRegistryConfigService } from "./app-registry-config.service.js";
|
|
7
|
+
import { AppRemoteRegistryClientService } from "./app-remote-registry-client.service.js";
|
|
8
|
+
import { AppRegistryService } from "./app-registry.service.js";
|
|
9
|
+
import { AppInstallSourceService } from "./app-install-source.service.js";
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
import { access, cp, mkdir, readdir, rename, rm } from "node:fs/promises";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
//#region src/services/app-installation.service.ts
|
|
14
|
+
var AppInstallationService = class {
|
|
15
|
+
installSourceService;
|
|
16
|
+
constructor(appHomeService = new AppHomeService(), bundleService = new AppBundleService(), manifestService = new AppManifestService(), buildService = new AppBuildService(), registryService = new AppRegistryService(appHomeService), registryConfigService = new AppRegistryConfigService(appHomeService), remoteRegistryClient = new AppRemoteRegistryClientService(new AppRegistryConfigService(appHomeService))) {
|
|
17
|
+
this.appHomeService = appHomeService;
|
|
18
|
+
this.bundleService = bundleService;
|
|
19
|
+
this.manifestService = manifestService;
|
|
20
|
+
this.buildService = buildService;
|
|
21
|
+
this.registryService = registryService;
|
|
22
|
+
this.registryConfigService = registryConfigService;
|
|
23
|
+
this.remoteRegistryClient = remoteRegistryClient;
|
|
24
|
+
this.installSourceService = new AppInstallSourceService(this.manifestService, this.remoteRegistryClient);
|
|
25
|
+
}
|
|
26
|
+
install = async (appSource, options) => {
|
|
27
|
+
const { onProgress, registryUrl } = options ?? {};
|
|
28
|
+
await onProgress?.("resolving");
|
|
29
|
+
const source = await this.installSourceService.resolve(appSource, registryUrl);
|
|
30
|
+
const tempDirectory = await this.appHomeService.createTemporaryDirectory("napp-install-");
|
|
31
|
+
try {
|
|
32
|
+
if (source.kind === "registry") await onProgress?.("downloading");
|
|
33
|
+
const bundlePath = source.kind === "directory" ? (await this.bundleService.packAppDirectory({
|
|
34
|
+
appDirectory: source.appDirectory,
|
|
35
|
+
outputPath: path.join(tempDirectory, "app.napp")
|
|
36
|
+
})).bundlePath : source.kind === "bundle" ? source.bundlePath : (await this.remoteRegistryClient.downloadBundle({
|
|
37
|
+
resolution: source.registryResolution,
|
|
38
|
+
targetDirectory: tempDirectory
|
|
39
|
+
})).bundlePath;
|
|
40
|
+
await onProgress?.("verifying");
|
|
41
|
+
const extractedDirectory = path.join(tempDirectory, "bundle");
|
|
42
|
+
const extractedMetadata = await this.bundleService.extractBundle({
|
|
43
|
+
bundlePath,
|
|
44
|
+
targetDirectory: extractedDirectory
|
|
45
|
+
});
|
|
46
|
+
await this.materializeDistribution({
|
|
47
|
+
appDirectory: extractedDirectory,
|
|
48
|
+
distributionMode: extractedMetadata.metadata.distributionMode
|
|
49
|
+
});
|
|
50
|
+
const manifestBundle = await this.manifestService.load(extractedDirectory);
|
|
51
|
+
const installDirectory = this.appHomeService.getInstallDirectory(manifestBundle.manifest.id, manifestBundle.manifest.version);
|
|
52
|
+
if (source.kind === "registry" && manifestBundle.manifest.id !== source.registryResolution.appId) throw new Error(`bundle manifest.appId 与 registry 请求不一致:期望 ${source.registryResolution.appId},实际 ${manifestBundle.manifest.id}`);
|
|
53
|
+
await onProgress?.("installing");
|
|
54
|
+
const dataDirectory = this.appHomeService.getAppDataDirectory(manifestBundle.manifest.id);
|
|
55
|
+
await this.copyToImmutableInstallDirectory({
|
|
56
|
+
appId: manifestBundle.manifest.id,
|
|
57
|
+
appVersion: manifestBundle.manifest.version,
|
|
58
|
+
extractedDirectory,
|
|
59
|
+
installDirectory
|
|
60
|
+
});
|
|
61
|
+
await mkdir(dataDirectory, { recursive: true });
|
|
62
|
+
await onProgress?.("finalizing");
|
|
63
|
+
let registryRecord;
|
|
64
|
+
try {
|
|
65
|
+
registryRecord = await this.registryService.upsertInstallation({
|
|
66
|
+
appId: manifestBundle.manifest.id,
|
|
67
|
+
name: manifestBundle.manifest.name,
|
|
68
|
+
description: manifestBundle.manifest.description,
|
|
69
|
+
version: manifestBundle.manifest.version,
|
|
70
|
+
installDirectory,
|
|
71
|
+
dataDirectory,
|
|
72
|
+
sourceKind: source.kind,
|
|
73
|
+
distributionMode: source.kind === "registry" ? source.registryResolution.distributionMode : extractedMetadata.metadata.distributionMode,
|
|
74
|
+
sourceRef: source.sourceRef,
|
|
75
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
76
|
+
permissions: manifestBundle.manifest.schemaVersion === 1 ? manifestBundle.manifest.permissions ?? {} : {},
|
|
77
|
+
registryUrl: source.kind === "registry" ? source.registryResolution.registryUrl : void 0,
|
|
78
|
+
bundleUrl: source.kind === "registry" ? source.registryResolution.bundleUrl : void 0,
|
|
79
|
+
sha256: source.kind === "registry" ? source.registryResolution.sha256 : void 0,
|
|
80
|
+
publisher: source.kind === "registry" ? source.registryResolution.publisher : void 0,
|
|
81
|
+
manifestSchemaVersion: manifestBundle.manifest.schemaVersion,
|
|
82
|
+
components: isAppComponentManifestBundle(manifestBundle) ? manifestBundle.components.map((component) => ({
|
|
83
|
+
...component,
|
|
84
|
+
componentDirectory: path.join(installDirectory, component.path),
|
|
85
|
+
manifestPath: path.join(installDirectory, component.path, component.kind === "panel" ? "panel-app.json" : "service-app.json")
|
|
86
|
+
})) : void 0,
|
|
87
|
+
primaryPanelId: isAppComponentManifestBundle(manifestBundle) ? manifestBundle.primaryPanelId : void 0
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
await rm(installDirectory, {
|
|
91
|
+
recursive: true,
|
|
92
|
+
force: true
|
|
93
|
+
});
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
const activeVersionRecord = registryRecord.installedVersions[registryRecord.activeVersion];
|
|
97
|
+
return {
|
|
98
|
+
appId: registryRecord.appId,
|
|
99
|
+
name: registryRecord.name,
|
|
100
|
+
version: registryRecord.activeVersion,
|
|
101
|
+
installDirectory,
|
|
102
|
+
dataDirectory,
|
|
103
|
+
sourceKind: source.kind,
|
|
104
|
+
sourceRef: source.sourceRef,
|
|
105
|
+
distributionMode: registryRecord.installedVersions[registryRecord.activeVersion]?.distributionMode,
|
|
106
|
+
permissions: registryRecord.installedVersions[registryRecord.activeVersion]?.permissions ?? {},
|
|
107
|
+
registryUrl: registryRecord.installedVersions[registryRecord.activeVersion]?.registryUrl,
|
|
108
|
+
bundleUrl: registryRecord.installedVersions[registryRecord.activeVersion]?.bundleUrl,
|
|
109
|
+
sha256: registryRecord.installedVersions[registryRecord.activeVersion]?.sha256,
|
|
110
|
+
publisher: registryRecord.installedVersions[registryRecord.activeVersion]?.publisher,
|
|
111
|
+
enabled: registryRecord.enabled,
|
|
112
|
+
manifestSchemaVersion: activeVersionRecord?.manifestSchemaVersion ?? 1,
|
|
113
|
+
components: activeVersionRecord?.components,
|
|
114
|
+
primaryPanelId: activeVersionRecord?.primaryPanelId
|
|
115
|
+
};
|
|
116
|
+
} finally {
|
|
117
|
+
await rm(tempDirectory, {
|
|
118
|
+
recursive: true,
|
|
119
|
+
force: true
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
update = async (appId, options) => {
|
|
124
|
+
const { onProgress, registryUrl: requestedRegistryUrl, version } = options ?? {};
|
|
125
|
+
await onProgress?.("resolving");
|
|
126
|
+
const appRecord = await this.registryService.getApp(appId);
|
|
127
|
+
if (!appRecord) throw new Error(`未找到已安装应用:${appId}`);
|
|
128
|
+
const activeVersionRecord = appRecord.installedVersions[appRecord.activeVersion];
|
|
129
|
+
const registryUrl = requestedRegistryUrl ?? activeVersionRecord?.registryUrl ?? (await this.registryConfigService.getSnapshot()).currentUrl;
|
|
130
|
+
const resolution = await this.remoteRegistryClient.resolve({
|
|
131
|
+
appId,
|
|
132
|
+
version,
|
|
133
|
+
registryUrl
|
|
134
|
+
});
|
|
135
|
+
if (resolution.version === appRecord.activeVersion) {
|
|
136
|
+
if (!activeVersionRecord) throw new Error(`已安装应用缺少激活版本:${appId}`);
|
|
137
|
+
return {
|
|
138
|
+
appId: appRecord.appId,
|
|
139
|
+
name: appRecord.name,
|
|
140
|
+
version: appRecord.activeVersion,
|
|
141
|
+
previousVersion: appRecord.activeVersion,
|
|
142
|
+
installDirectory: activeVersionRecord.installDirectory,
|
|
143
|
+
dataDirectory: appRecord.dataDirectory,
|
|
144
|
+
sourceKind: activeVersionRecord.sourceKind,
|
|
145
|
+
sourceRef: activeVersionRecord.sourceRef,
|
|
146
|
+
permissions: activeVersionRecord.permissions,
|
|
147
|
+
registryUrl: activeVersionRecord.registryUrl,
|
|
148
|
+
bundleUrl: activeVersionRecord.bundleUrl,
|
|
149
|
+
sha256: activeVersionRecord.sha256,
|
|
150
|
+
publisher: activeVersionRecord.publisher,
|
|
151
|
+
enabled: appRecord.enabled,
|
|
152
|
+
manifestSchemaVersion: activeVersionRecord.manifestSchemaVersion,
|
|
153
|
+
components: activeVersionRecord.components,
|
|
154
|
+
primaryPanelId: activeVersionRecord.primaryPanelId,
|
|
155
|
+
updated: false
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const installedTarget = appRecord.installedVersions[resolution.version];
|
|
159
|
+
if (installedTarget) {
|
|
160
|
+
await onProgress?.("verifying");
|
|
161
|
+
await onProgress?.("installing");
|
|
162
|
+
await this.rollback(appId, resolution.version);
|
|
163
|
+
await onProgress?.("finalizing");
|
|
164
|
+
return {
|
|
165
|
+
appId: appRecord.appId,
|
|
166
|
+
name: appRecord.name,
|
|
167
|
+
version: resolution.version,
|
|
168
|
+
previousVersion: appRecord.activeVersion,
|
|
169
|
+
installDirectory: installedTarget.installDirectory,
|
|
170
|
+
dataDirectory: appRecord.dataDirectory,
|
|
171
|
+
sourceKind: installedTarget.sourceKind,
|
|
172
|
+
distributionMode: installedTarget.distributionMode,
|
|
173
|
+
sourceRef: installedTarget.sourceRef,
|
|
174
|
+
permissions: installedTarget.permissions,
|
|
175
|
+
registryUrl: installedTarget.registryUrl,
|
|
176
|
+
bundleUrl: installedTarget.bundleUrl,
|
|
177
|
+
sha256: installedTarget.sha256,
|
|
178
|
+
publisher: installedTarget.publisher,
|
|
179
|
+
enabled: appRecord.enabled,
|
|
180
|
+
manifestSchemaVersion: installedTarget.manifestSchemaVersion,
|
|
181
|
+
components: installedTarget.components,
|
|
182
|
+
primaryPanelId: installedTarget.primaryPanelId,
|
|
183
|
+
updated: true
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
...await this.install(`${appId}@${resolution.version}`, {
|
|
188
|
+
registryUrl,
|
|
189
|
+
onProgress
|
|
190
|
+
}),
|
|
191
|
+
previousVersion: appRecord.activeVersion,
|
|
192
|
+
updated: true
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
uninstall = async (appId, purgeData) => {
|
|
196
|
+
const appRecord = await this.registryService.getApp(appId);
|
|
197
|
+
if (!appRecord) throw new Error(`未找到已安装应用:${appId}`);
|
|
198
|
+
const removedVersions = Object.keys(appRecord.installedVersions).sort((left, right) => left.localeCompare(right));
|
|
199
|
+
const stagedPaths = [];
|
|
200
|
+
const stagePath = async (originalPath) => {
|
|
201
|
+
if (!await this.pathExists(originalPath)) return;
|
|
202
|
+
const stagedPath = `${originalPath}.uninstalling-${randomUUID()}`;
|
|
203
|
+
await rename(originalPath, stagedPath);
|
|
204
|
+
stagedPaths.push({
|
|
205
|
+
originalPath,
|
|
206
|
+
stagedPath
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
const restoreStagedPaths = async () => {
|
|
210
|
+
for (const entry of [...stagedPaths].reverse()) if (await this.pathExists(entry.stagedPath)) await rename(entry.stagedPath, entry.originalPath);
|
|
211
|
+
};
|
|
212
|
+
try {
|
|
213
|
+
for (const versionRecord of Object.values(appRecord.installedVersions)) await stagePath(versionRecord.installDirectory);
|
|
214
|
+
if (purgeData) await stagePath(appRecord.dataDirectory);
|
|
215
|
+
if (!await this.registryService.removeApp(appId)) throw new Error(`卸载过程中应用记录已发生变化:${appId}`);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
try {
|
|
218
|
+
await restoreStagedPaths();
|
|
219
|
+
} catch (restoreError) {
|
|
220
|
+
throw new AggregateError([error, restoreError], `卸载 ${appId} 失败,且无法完全恢复已暂存文件。`);
|
|
221
|
+
}
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
await Promise.all(stagedPaths.map((entry) => rm(entry.stagedPath, {
|
|
225
|
+
recursive: true,
|
|
226
|
+
force: true
|
|
227
|
+
})));
|
|
228
|
+
return {
|
|
229
|
+
appId,
|
|
230
|
+
removedVersions,
|
|
231
|
+
dataRemoved: purgeData
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
list = async () => {
|
|
235
|
+
return (await this.registryService.listApps()).map((appRecord) => ({
|
|
236
|
+
appId: appRecord.appId,
|
|
237
|
+
name: appRecord.name,
|
|
238
|
+
activeVersion: appRecord.activeVersion,
|
|
239
|
+
sourceKind: appRecord.installedVersions[appRecord.activeVersion]?.sourceKind ?? "directory",
|
|
240
|
+
distributionMode: appRecord.installedVersions[appRecord.activeVersion]?.distributionMode,
|
|
241
|
+
enabled: appRecord.enabled,
|
|
242
|
+
manifestSchemaVersion: appRecord.installedVersions[appRecord.activeVersion]?.manifestSchemaVersion ?? 1,
|
|
243
|
+
primaryPanelId: appRecord.installedVersions[appRecord.activeVersion]?.primaryPanelId
|
|
244
|
+
}));
|
|
245
|
+
};
|
|
246
|
+
reconcileFilesystem = async () => {
|
|
247
|
+
await this.appHomeService.ensureBaseDirectories();
|
|
248
|
+
const appRecords = await this.registryService.listApps();
|
|
249
|
+
const referencedInstallPaths = new Set(appRecords.flatMap((record) => Object.values(record.installedVersions).map((version) => path.resolve(version.installDirectory))));
|
|
250
|
+
const referencedDataPaths = new Set(appRecords.map((record) => path.resolve(record.dataDirectory)));
|
|
251
|
+
const packageDirectories = await this.readDirectories(this.appHomeService.getPackagesDirectory());
|
|
252
|
+
for (const appDirectory of packageDirectories) await this.reconcileGeneratedSiblings(appDirectory, referencedInstallPaths);
|
|
253
|
+
await this.reconcileGeneratedSiblings(this.appHomeService.getDataDirectory(), referencedDataPaths);
|
|
254
|
+
};
|
|
255
|
+
info = async (appId) => {
|
|
256
|
+
const appRecord = await this.registryService.getApp(appId);
|
|
257
|
+
if (!appRecord) throw new Error(`未找到已安装应用:${appId}`);
|
|
258
|
+
const installedVersions = Object.values(appRecord.installedVersions).sort((left, right) => left.version.localeCompare(right.version));
|
|
259
|
+
return {
|
|
260
|
+
appId: appRecord.appId,
|
|
261
|
+
name: appRecord.name,
|
|
262
|
+
description: appRecord.description,
|
|
263
|
+
activeVersion: appRecord.activeVersion,
|
|
264
|
+
enabled: appRecord.enabled,
|
|
265
|
+
dataDirectory: appRecord.dataDirectory,
|
|
266
|
+
installedVersions: installedVersions.map((versionRecord) => ({
|
|
267
|
+
version: versionRecord.version,
|
|
268
|
+
installDirectory: versionRecord.installDirectory,
|
|
269
|
+
sourceKind: versionRecord.sourceKind,
|
|
270
|
+
distributionMode: versionRecord.distributionMode,
|
|
271
|
+
sourceRef: versionRecord.sourceRef,
|
|
272
|
+
installedAt: versionRecord.installedAt,
|
|
273
|
+
permissions: versionRecord.permissions,
|
|
274
|
+
registryUrl: versionRecord.registryUrl,
|
|
275
|
+
bundleUrl: versionRecord.bundleUrl,
|
|
276
|
+
sha256: versionRecord.sha256,
|
|
277
|
+
publisher: versionRecord.publisher,
|
|
278
|
+
manifestSchemaVersion: versionRecord.manifestSchemaVersion,
|
|
279
|
+
components: versionRecord.components,
|
|
280
|
+
primaryPanelId: versionRecord.primaryPanelId
|
|
281
|
+
})),
|
|
282
|
+
grants: appRecord.grants
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
setEnabled = async (appId, enabled) => {
|
|
286
|
+
const appRecord = await this.registryService.setEnabled(appId, enabled);
|
|
287
|
+
return {
|
|
288
|
+
appId: appRecord.appId,
|
|
289
|
+
activeVersion: appRecord.activeVersion,
|
|
290
|
+
enabled: appRecord.enabled
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
rollback = async (appId, version) => {
|
|
294
|
+
const currentRecord = await this.registryService.getApp(appId);
|
|
295
|
+
if (!currentRecord) throw new Error(`未找到已安装应用:${appId}`);
|
|
296
|
+
if (currentRecord.activeVersion === version) return {
|
|
297
|
+
appId,
|
|
298
|
+
activeVersion: version,
|
|
299
|
+
previousVersion: version,
|
|
300
|
+
enabled: currentRecord.enabled,
|
|
301
|
+
rolledBack: false
|
|
302
|
+
};
|
|
303
|
+
const targetVersion = currentRecord.installedVersions[version];
|
|
304
|
+
if (!targetVersion) throw new Error(`应用 ${appId} 未安装版本 ${version}。`);
|
|
305
|
+
const targetManifest = await this.manifestService.load(targetVersion.installDirectory);
|
|
306
|
+
if (targetManifest.manifest.id !== appId || targetManifest.manifest.version !== version) throw new Error(`回滚目标 ${appId}@${version} 校验失败。`);
|
|
307
|
+
const appRecord = await this.registryService.activateVersion(appId, version);
|
|
308
|
+
return {
|
|
309
|
+
appId,
|
|
310
|
+
activeVersion: appRecord.activeVersion,
|
|
311
|
+
previousVersion: currentRecord.activeVersion,
|
|
312
|
+
enabled: appRecord.enabled,
|
|
313
|
+
rolledBack: true
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
resolveLaunch = async (appReference, explicitDocumentGrantMap) => {
|
|
317
|
+
const sourceType = await this.installSourceService.detectLocal(appReference, false);
|
|
318
|
+
if (sourceType.kind === "directory") return {
|
|
319
|
+
appDirectory: sourceType.appDirectory,
|
|
320
|
+
documentGrantMap: explicitDocumentGrantMap
|
|
321
|
+
};
|
|
322
|
+
const appRecord = await this.registryService.getApp(appReference);
|
|
323
|
+
if (!appRecord) throw new Error(`未找到应用目录,也未找到已安装应用:${appReference}`);
|
|
324
|
+
const activeVersion = appRecord.installedVersions[appRecord.activeVersion];
|
|
325
|
+
if (!activeVersion) throw new Error(`已安装应用缺少激活版本:${appReference}`);
|
|
326
|
+
return {
|
|
327
|
+
appDirectory: activeVersion.installDirectory,
|
|
328
|
+
appId: appRecord.appId,
|
|
329
|
+
dataDirectory: appRecord.dataDirectory,
|
|
330
|
+
documentGrantMap: {
|
|
331
|
+
...appRecord.grants,
|
|
332
|
+
...explicitDocumentGrantMap
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
persistGrants = async (appId, documentGrantMap) => {
|
|
337
|
+
if (!appId || Object.keys(documentGrantMap).length === 0) return;
|
|
338
|
+
await this.registryService.updateGrants(appId, documentGrantMap);
|
|
339
|
+
};
|
|
340
|
+
copyToImmutableInstallDirectory = async (params) => {
|
|
341
|
+
const { appId, appVersion, extractedDirectory, installDirectory } = params;
|
|
342
|
+
if (await this.pathExists(installDirectory)) throw new Error(`应用版本目录已存在,不能覆盖不可变版本:${appId}@${appVersion}`);
|
|
343
|
+
await mkdir(path.dirname(installDirectory), { recursive: true });
|
|
344
|
+
const stagedInstallDirectory = `${installDirectory}.staging-${randomUUID()}`;
|
|
345
|
+
try {
|
|
346
|
+
await cp(extractedDirectory, stagedInstallDirectory, { recursive: true });
|
|
347
|
+
const stagedManifest = await this.manifestService.load(stagedInstallDirectory);
|
|
348
|
+
if (stagedManifest.manifest.id !== appId || stagedManifest.manifest.version !== appVersion) throw new Error("staging manifest 与已验证 bundle 身份不一致。");
|
|
349
|
+
await rename(stagedInstallDirectory, installDirectory);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
await rm(stagedInstallDirectory, {
|
|
352
|
+
recursive: true,
|
|
353
|
+
force: true
|
|
354
|
+
});
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
materializeDistribution = async (params) => {
|
|
359
|
+
if (params.distributionMode !== "source") return;
|
|
360
|
+
const manifestBundle = await this.manifestService.load(params.appDirectory);
|
|
361
|
+
if (!isAppStandaloneManifestBundle(manifestBundle)) throw new Error("schema v2 组合包不允许运行安装期 build。");
|
|
362
|
+
if (manifestBundle.manifest.main.kind !== "wasi-http-component") return;
|
|
363
|
+
await this.buildService.build({
|
|
364
|
+
appDirectory: params.appDirectory,
|
|
365
|
+
install: true
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
reconcileGeneratedSiblings = async (parentDirectory, referencedPaths) => {
|
|
369
|
+
for (const entry of await this.readDirectories(parentDirectory)) {
|
|
370
|
+
const entryName = path.basename(entry);
|
|
371
|
+
const stagingMarker = ".staging-";
|
|
372
|
+
const uninstallingMarker = ".uninstalling-";
|
|
373
|
+
if (entryName.includes(stagingMarker)) {
|
|
374
|
+
await rm(entry, {
|
|
375
|
+
recursive: true,
|
|
376
|
+
force: true
|
|
377
|
+
});
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const markerIndex = entryName.indexOf(uninstallingMarker);
|
|
381
|
+
if (markerIndex < 0) continue;
|
|
382
|
+
const originalPath = path.join(parentDirectory, entryName.slice(0, markerIndex));
|
|
383
|
+
if (referencedPaths.has(path.resolve(originalPath)) && !await this.pathExists(originalPath)) await rename(entry, originalPath);
|
|
384
|
+
else await rm(entry, {
|
|
385
|
+
recursive: true,
|
|
386
|
+
force: true
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
readDirectories = async (directory) => {
|
|
391
|
+
try {
|
|
392
|
+
return (await readdir(directory, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => path.join(directory, entry.name));
|
|
393
|
+
} catch (error) {
|
|
394
|
+
if (this.isMissingFileError(error)) return [];
|
|
395
|
+
throw error;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
pathExists = async (targetPath) => {
|
|
399
|
+
try {
|
|
400
|
+
await access(targetPath);
|
|
401
|
+
return true;
|
|
402
|
+
} catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
isMissingFileError = (error) => typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
407
|
+
};
|
|
408
|
+
//#endregion
|
|
409
|
+
export { AppInstallationService };
|
|
410
|
+
|
|
411
|
+
//# sourceMappingURL=app-installation.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-installation.service.js","names":[],"sources":["../../src/services/app-installation.service.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { access, cp, mkdir, readdir, rename, rm } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { AppBundleService } from \"#app-runtime/services/app-bundle.service.js\";\nimport { AppManifestService } from \"#app-runtime/services/app-manifest.service.js\";\nimport {\n isAppComponentManifestBundle,\n isAppStandaloneManifestBundle,\n} from \"#app-runtime/types/app-manifest.types.js\";\nimport { AppHomeService } from \"#app-runtime/services/app-home.service.js\";\nimport { AppBuildService } from \"#app-runtime/services/app-build.service.js\";\nimport type { AppDistributionMode } from \"#app-runtime/types/app-bundle.types.js\";\nimport type { AppDocumentGrantMap } from \"#app-runtime/types/app-permissions.types.js\";\nimport { AppRegistryConfigService } from \"#app-runtime/services/app-registry-config.service.js\";\nimport { AppRemoteRegistryClientService } from \"#app-runtime/services/app-remote-registry-client.service.js\";\nimport { AppRegistryService } from \"#app-runtime/services/app-registry.service.js\";\nimport { AppInstallSourceService } from \"#app-runtime/services/app-install-source.service.js\";\nimport type {\n AppInfoResult,\n AppInstallProgressHandler,\n AppActivationResult,\n AppInstallResult,\n AppLaunchResolution,\n AppUpdateResult,\n AppRollbackResult,\n AppUninstallResult,\n InstalledAppListItem,\n} from \"#app-runtime/types/app-installation.types.js\";\n\nexport class AppInstallationService {\n private readonly installSourceService: AppInstallSourceService;\n\n constructor(\n private readonly appHomeService: AppHomeService = new AppHomeService(),\n private readonly bundleService: AppBundleService = new AppBundleService(),\n private readonly manifestService: AppManifestService = new AppManifestService(),\n private readonly buildService: AppBuildService = new AppBuildService(),\n private readonly registryService: AppRegistryService = new AppRegistryService(appHomeService),\n private readonly registryConfigService: AppRegistryConfigService = new AppRegistryConfigService(\n appHomeService,\n ),\n private readonly remoteRegistryClient: AppRemoteRegistryClientService = new AppRemoteRegistryClientService(\n new AppRegistryConfigService(appHomeService),\n ),\n ) {\n this.installSourceService = new AppInstallSourceService(\n this.manifestService,\n this.remoteRegistryClient,\n );\n }\n\n install = async (\n appSource: string,\n options?: {\n registryUrl?: string;\n onProgress?: AppInstallProgressHandler;\n },\n ): Promise<AppInstallResult> => {\n const { onProgress, registryUrl } = options ?? {};\n await onProgress?.(\"resolving\");\n const source = await this.installSourceService.resolve(appSource, registryUrl);\n const tempDirectory = await this.appHomeService.createTemporaryDirectory(\"napp-install-\");\n try {\n if (source.kind === \"registry\") {\n await onProgress?.(\"downloading\");\n }\n const bundlePath =\n source.kind === \"directory\"\n ? (await this.bundleService.packAppDirectory({\n appDirectory: source.appDirectory,\n outputPath: path.join(tempDirectory, \"app.napp\"),\n })).bundlePath\n : source.kind === \"bundle\"\n ? source.bundlePath\n : (\n await this.remoteRegistryClient.downloadBundle({\n resolution: source.registryResolution,\n targetDirectory: tempDirectory,\n })\n ).bundlePath;\n await onProgress?.(\"verifying\");\n const extractedDirectory = path.join(tempDirectory, \"bundle\");\n const extractedMetadata = await this.bundleService.extractBundle({\n bundlePath,\n targetDirectory: extractedDirectory,\n });\n await this.materializeDistribution({\n appDirectory: extractedDirectory,\n distributionMode: extractedMetadata.metadata.distributionMode,\n });\n const manifestBundle = await this.manifestService.load(extractedDirectory);\n const installDirectory = this.appHomeService.getInstallDirectory(\n manifestBundle.manifest.id,\n manifestBundle.manifest.version,\n );\n if (\n source.kind === \"registry\" &&\n manifestBundle.manifest.id !== source.registryResolution.appId\n ) {\n throw new Error(\n `bundle manifest.appId 与 registry 请求不一致:期望 ${source.registryResolution.appId},实际 ${manifestBundle.manifest.id}`,\n );\n }\n await onProgress?.(\"installing\");\n const dataDirectory = this.appHomeService.getAppDataDirectory(manifestBundle.manifest.id);\n await this.copyToImmutableInstallDirectory({\n appId: manifestBundle.manifest.id,\n appVersion: manifestBundle.manifest.version,\n extractedDirectory,\n installDirectory,\n });\n await mkdir(dataDirectory, { recursive: true });\n await onProgress?.(\"finalizing\");\n let registryRecord;\n try {\n registryRecord = await this.registryService.upsertInstallation({\n appId: manifestBundle.manifest.id,\n name: manifestBundle.manifest.name,\n description: manifestBundle.manifest.description,\n version: manifestBundle.manifest.version,\n installDirectory,\n dataDirectory,\n sourceKind: source.kind,\n distributionMode:\n source.kind === \"registry\"\n ? source.registryResolution.distributionMode\n : extractedMetadata.metadata.distributionMode,\n sourceRef: source.sourceRef,\n installedAt: new Date().toISOString(),\n permissions: manifestBundle.manifest.schemaVersion === 1\n ? manifestBundle.manifest.permissions ?? {}\n : {},\n registryUrl:\n source.kind === \"registry\" ? source.registryResolution.registryUrl : undefined,\n bundleUrl:\n source.kind === \"registry\" ? source.registryResolution.bundleUrl : undefined,\n sha256: source.kind === \"registry\" ? source.registryResolution.sha256 : undefined,\n publisher:\n source.kind === \"registry\" ? source.registryResolution.publisher : undefined,\n manifestSchemaVersion: manifestBundle.manifest.schemaVersion,\n components: isAppComponentManifestBundle(manifestBundle)\n ? manifestBundle.components.map((component) => ({\n ...component,\n componentDirectory: path.join(installDirectory, component.path),\n manifestPath: path.join(\n installDirectory,\n component.path,\n component.kind === \"panel\" ? \"panel-app.json\" : \"service-app.json\",\n ),\n }))\n : undefined,\n primaryPanelId: isAppComponentManifestBundle(manifestBundle)\n ? manifestBundle.primaryPanelId\n : undefined,\n });\n } catch (error) {\n await rm(installDirectory, { recursive: true, force: true });\n throw error;\n }\n const activeVersionRecord = registryRecord.installedVersions[registryRecord.activeVersion];\n return {\n appId: registryRecord.appId,\n name: registryRecord.name,\n version: registryRecord.activeVersion,\n installDirectory,\n dataDirectory,\n sourceKind: source.kind,\n sourceRef: source.sourceRef,\n distributionMode:\n registryRecord.installedVersions[registryRecord.activeVersion]?.distributionMode,\n permissions:\n registryRecord.installedVersions[registryRecord.activeVersion]?.permissions ?? {},\n registryUrl:\n registryRecord.installedVersions[registryRecord.activeVersion]?.registryUrl,\n bundleUrl:\n registryRecord.installedVersions[registryRecord.activeVersion]?.bundleUrl,\n sha256: registryRecord.installedVersions[registryRecord.activeVersion]?.sha256,\n publisher:\n registryRecord.installedVersions[registryRecord.activeVersion]?.publisher,\n enabled: registryRecord.enabled,\n manifestSchemaVersion: activeVersionRecord?.manifestSchemaVersion ?? 1,\n components: activeVersionRecord?.components,\n primaryPanelId: activeVersionRecord?.primaryPanelId,\n };\n } finally {\n await rm(tempDirectory, { recursive: true, force: true });\n }\n };\n\n update = async (\n appId: string,\n options?: {\n version?: string;\n registryUrl?: string;\n onProgress?: AppInstallProgressHandler;\n },\n ): Promise<AppUpdateResult> => {\n const { onProgress, registryUrl: requestedRegistryUrl, version } = options ?? {};\n await onProgress?.(\"resolving\");\n const appRecord = await this.registryService.getApp(appId);\n if (!appRecord) {\n throw new Error(`未找到已安装应用:${appId}`);\n }\n const activeVersionRecord = appRecord.installedVersions[appRecord.activeVersion];\n const registryUrl =\n requestedRegistryUrl ??\n activeVersionRecord?.registryUrl ??\n (await this.registryConfigService.getSnapshot()).currentUrl;\n const resolution = await this.remoteRegistryClient.resolve({\n appId,\n version,\n registryUrl,\n });\n if (resolution.version === appRecord.activeVersion) {\n if (!activeVersionRecord) {\n throw new Error(`已安装应用缺少激活版本:${appId}`);\n }\n return {\n appId: appRecord.appId,\n name: appRecord.name,\n version: appRecord.activeVersion,\n previousVersion: appRecord.activeVersion,\n installDirectory: activeVersionRecord.installDirectory,\n dataDirectory: appRecord.dataDirectory,\n sourceKind: activeVersionRecord.sourceKind,\n sourceRef: activeVersionRecord.sourceRef,\n permissions: activeVersionRecord.permissions,\n registryUrl: activeVersionRecord.registryUrl,\n bundleUrl: activeVersionRecord.bundleUrl,\n sha256: activeVersionRecord.sha256,\n publisher: activeVersionRecord.publisher,\n enabled: appRecord.enabled,\n manifestSchemaVersion: activeVersionRecord.manifestSchemaVersion,\n components: activeVersionRecord.components,\n primaryPanelId: activeVersionRecord.primaryPanelId,\n updated: false,\n };\n }\n const installedTarget = appRecord.installedVersions[resolution.version];\n if (installedTarget) {\n await onProgress?.(\"verifying\");\n await onProgress?.(\"installing\");\n await this.rollback(appId, resolution.version);\n await onProgress?.(\"finalizing\");\n return {\n appId: appRecord.appId,\n name: appRecord.name,\n version: resolution.version,\n previousVersion: appRecord.activeVersion,\n installDirectory: installedTarget.installDirectory,\n dataDirectory: appRecord.dataDirectory,\n sourceKind: installedTarget.sourceKind,\n distributionMode: installedTarget.distributionMode,\n sourceRef: installedTarget.sourceRef,\n permissions: installedTarget.permissions,\n registryUrl: installedTarget.registryUrl,\n bundleUrl: installedTarget.bundleUrl,\n sha256: installedTarget.sha256,\n publisher: installedTarget.publisher,\n enabled: appRecord.enabled,\n manifestSchemaVersion: installedTarget.manifestSchemaVersion,\n components: installedTarget.components,\n primaryPanelId: installedTarget.primaryPanelId,\n updated: true,\n };\n }\n const installResult = await this.install(`${appId}@${resolution.version}`, {\n registryUrl,\n onProgress,\n });\n return {\n ...installResult,\n previousVersion: appRecord.activeVersion,\n updated: true,\n };\n };\n\n uninstall = async (\n appId: string,\n purgeData: boolean,\n ): Promise<AppUninstallResult> => {\n const appRecord = await this.registryService.getApp(appId);\n if (!appRecord) {\n throw new Error(`未找到已安装应用:${appId}`);\n }\n const removedVersions = Object.keys(appRecord.installedVersions).sort((left, right) =>\n left.localeCompare(right),\n );\n const stagedPaths: Array<{ originalPath: string; stagedPath: string }> = [];\n const stagePath = async (originalPath: string): Promise<void> => {\n if (!await this.pathExists(originalPath)) {\n return;\n }\n const stagedPath = `${originalPath}.uninstalling-${randomUUID()}`;\n await rename(originalPath, stagedPath);\n stagedPaths.push({ originalPath, stagedPath });\n };\n const restoreStagedPaths = async (): Promise<void> => {\n for (const entry of [...stagedPaths].reverse()) {\n if (await this.pathExists(entry.stagedPath)) {\n await rename(entry.stagedPath, entry.originalPath);\n }\n }\n };\n try {\n for (const versionRecord of Object.values(appRecord.installedVersions)) {\n await stagePath(versionRecord.installDirectory);\n }\n if (purgeData) {\n await stagePath(appRecord.dataDirectory);\n }\n const removedRecord = await this.registryService.removeApp(appId);\n if (!removedRecord) {\n throw new Error(`卸载过程中应用记录已发生变化:${appId}`);\n }\n } catch (error) {\n try {\n await restoreStagedPaths();\n } catch (restoreError) {\n throw new AggregateError(\n [error, restoreError],\n `卸载 ${appId} 失败,且无法完全恢复已暂存文件。`,\n );\n }\n throw error;\n }\n await Promise.all(stagedPaths.map((entry) =>\n rm(entry.stagedPath, { recursive: true, force: true }),\n ));\n return {\n appId,\n removedVersions,\n dataRemoved: purgeData,\n };\n };\n\n list = async (): Promise<InstalledAppListItem[]> => {\n const appRecords = await this.registryService.listApps();\n return appRecords.map((appRecord) => ({\n appId: appRecord.appId,\n name: appRecord.name,\n activeVersion: appRecord.activeVersion,\n sourceKind:\n appRecord.installedVersions[appRecord.activeVersion]?.sourceKind ?? \"directory\",\n distributionMode:\n appRecord.installedVersions[appRecord.activeVersion]?.distributionMode,\n enabled: appRecord.enabled,\n manifestSchemaVersion:\n appRecord.installedVersions[appRecord.activeVersion]?.manifestSchemaVersion ?? 1,\n primaryPanelId:\n appRecord.installedVersions[appRecord.activeVersion]?.primaryPanelId,\n }));\n };\n\n reconcileFilesystem = async (): Promise<void> => {\n await this.appHomeService.ensureBaseDirectories();\n const appRecords = await this.registryService.listApps();\n const referencedInstallPaths = new Set(appRecords.flatMap((record) =>\n Object.values(record.installedVersions).map((version) => path.resolve(version.installDirectory))));\n const referencedDataPaths = new Set(appRecords.map((record) => path.resolve(record.dataDirectory)));\n\n const packageDirectories = await this.readDirectories(this.appHomeService.getPackagesDirectory());\n for (const appDirectory of packageDirectories) {\n await this.reconcileGeneratedSiblings(appDirectory, referencedInstallPaths);\n }\n await this.reconcileGeneratedSiblings(\n this.appHomeService.getDataDirectory(),\n referencedDataPaths,\n );\n };\n\n info = async (appId: string): Promise<AppInfoResult> => {\n const appRecord = await this.registryService.getApp(appId);\n if (!appRecord) {\n throw new Error(`未找到已安装应用:${appId}`);\n }\n const installedVersions = Object.values(appRecord.installedVersions).sort((left, right) =>\n left.version.localeCompare(right.version),\n );\n return {\n appId: appRecord.appId,\n name: appRecord.name,\n description: appRecord.description,\n activeVersion: appRecord.activeVersion,\n enabled: appRecord.enabled,\n dataDirectory: appRecord.dataDirectory,\n installedVersions: installedVersions.map((versionRecord) => ({\n version: versionRecord.version,\n installDirectory: versionRecord.installDirectory,\n sourceKind: versionRecord.sourceKind,\n distributionMode: versionRecord.distributionMode,\n sourceRef: versionRecord.sourceRef,\n installedAt: versionRecord.installedAt,\n permissions: versionRecord.permissions,\n registryUrl: versionRecord.registryUrl,\n bundleUrl: versionRecord.bundleUrl,\n sha256: versionRecord.sha256,\n publisher: versionRecord.publisher,\n manifestSchemaVersion: versionRecord.manifestSchemaVersion,\n components: versionRecord.components,\n primaryPanelId: versionRecord.primaryPanelId,\n })),\n grants: appRecord.grants,\n };\n };\n\n setEnabled = async (appId: string, enabled: boolean): Promise<AppActivationResult> => {\n const appRecord = await this.registryService.setEnabled(appId, enabled);\n return {\n appId: appRecord.appId,\n activeVersion: appRecord.activeVersion,\n enabled: appRecord.enabled,\n };\n };\n\n rollback = async (appId: string, version: string): Promise<AppRollbackResult> => {\n const currentRecord = await this.registryService.getApp(appId);\n if (!currentRecord) {\n throw new Error(`未找到已安装应用:${appId}`);\n }\n if (currentRecord.activeVersion === version) {\n return {\n appId,\n activeVersion: version,\n previousVersion: version,\n enabled: currentRecord.enabled,\n rolledBack: false,\n };\n }\n const targetVersion = currentRecord.installedVersions[version];\n if (!targetVersion) {\n throw new Error(`应用 ${appId} 未安装版本 ${version}。`);\n }\n const targetManifest = await this.manifestService.load(targetVersion.installDirectory);\n if (targetManifest.manifest.id !== appId || targetManifest.manifest.version !== version) {\n throw new Error(`回滚目标 ${appId}@${version} 校验失败。`);\n }\n const appRecord = await this.registryService.activateVersion(appId, version);\n return {\n appId,\n activeVersion: appRecord.activeVersion,\n previousVersion: currentRecord.activeVersion,\n enabled: appRecord.enabled,\n rolledBack: true,\n };\n };\n\n resolveLaunch = async (\n appReference: string,\n explicitDocumentGrantMap: AppDocumentGrantMap,\n ): Promise<AppLaunchResolution> => {\n const sourceType = await this.installSourceService.detectLocal(appReference, false);\n if (sourceType.kind === \"directory\") {\n return {\n appDirectory: sourceType.appDirectory,\n documentGrantMap: explicitDocumentGrantMap,\n };\n }\n const appRecord = await this.registryService.getApp(appReference);\n if (!appRecord) {\n throw new Error(`未找到应用目录,也未找到已安装应用:${appReference}`);\n }\n const activeVersion = appRecord.installedVersions[appRecord.activeVersion];\n if (!activeVersion) {\n throw new Error(`已安装应用缺少激活版本:${appReference}`);\n }\n return {\n appDirectory: activeVersion.installDirectory,\n appId: appRecord.appId,\n dataDirectory: appRecord.dataDirectory,\n documentGrantMap: {\n ...appRecord.grants,\n ...explicitDocumentGrantMap,\n },\n };\n };\n\n persistGrants = async (\n appId: string | undefined,\n documentGrantMap: AppDocumentGrantMap,\n ): Promise<void> => {\n if (!appId || Object.keys(documentGrantMap).length === 0) {\n return;\n }\n await this.registryService.updateGrants(appId, documentGrantMap);\n };\n\n private copyToImmutableInstallDirectory = async (params: {\n appId: string;\n appVersion: string;\n extractedDirectory: string;\n installDirectory: string;\n }): Promise<void> => {\n const { appId, appVersion, extractedDirectory, installDirectory } = params;\n if (await this.pathExists(installDirectory)) {\n throw new Error(`应用版本目录已存在,不能覆盖不可变版本:${appId}@${appVersion}`);\n }\n await mkdir(path.dirname(installDirectory), { recursive: true });\n const stagedInstallDirectory = `${installDirectory}.staging-${randomUUID()}`;\n try {\n await cp(extractedDirectory, stagedInstallDirectory, { recursive: true });\n const stagedManifest = await this.manifestService.load(stagedInstallDirectory);\n if (\n stagedManifest.manifest.id !== appId ||\n stagedManifest.manifest.version !== appVersion\n ) {\n throw new Error(\"staging manifest 与已验证 bundle 身份不一致。\");\n }\n await rename(stagedInstallDirectory, installDirectory);\n } catch (error) {\n await rm(stagedInstallDirectory, { recursive: true, force: true });\n throw error;\n }\n };\n\n private materializeDistribution = async (params: {\n appDirectory: string;\n distributionMode: AppDistributionMode;\n }): Promise<void> => {\n if (params.distributionMode !== \"source\") {\n return;\n }\n const manifestBundle = await this.manifestService.load(params.appDirectory);\n if (!isAppStandaloneManifestBundle(manifestBundle)) {\n throw new Error(\"schema v2 组合包不允许运行安装期 build。\");\n }\n if (manifestBundle.manifest.main.kind !== \"wasi-http-component\") {\n return;\n }\n await this.buildService.build({\n appDirectory: params.appDirectory,\n install: true,\n });\n };\n\n private reconcileGeneratedSiblings = async (\n parentDirectory: string,\n referencedPaths: Set<string>,\n ): Promise<void> => {\n for (const entry of await this.readDirectories(parentDirectory)) {\n const entryName = path.basename(entry);\n const stagingMarker = \".staging-\";\n const uninstallingMarker = \".uninstalling-\";\n if (entryName.includes(stagingMarker)) {\n await rm(entry, { recursive: true, force: true });\n continue;\n }\n const markerIndex = entryName.indexOf(uninstallingMarker);\n if (markerIndex < 0) {\n continue;\n }\n const originalPath = path.join(parentDirectory, entryName.slice(0, markerIndex));\n if (referencedPaths.has(path.resolve(originalPath)) && !await this.pathExists(originalPath)) {\n await rename(entry, originalPath);\n } else {\n await rm(entry, { recursive: true, force: true });\n }\n }\n };\n\n private readDirectories = async (directory: string): Promise<string[]> => {\n try {\n return (await readdir(directory, { withFileTypes: true }))\n .filter((entry) => entry.isDirectory())\n .map((entry) => path.join(directory, entry.name));\n } catch (error) {\n if (this.isMissingFileError(error)) {\n return [];\n }\n throw error;\n }\n };\n\n private pathExists = async (targetPath: string): Promise<boolean> => {\n try {\n await access(targetPath);\n return true;\n } catch {\n return false;\n }\n };\n\n private isMissingFileError = (error: unknown): boolean =>\n typeof error === \"object\" && error !== null &&\n \"code\" in error && (error as { code?: unknown }).code === \"ENOENT\";\n}\n"],"mappings":";;;;;;;;;;;;;AA6BA,IAAa,yBAAb,MAAoC;CAClC;CAEA,YACE,iBAAkD,IAAI,gBAAgB,EACtE,gBAAmD,IAAI,kBAAkB,EACzE,kBAAuD,IAAI,oBAAoB,EAC/E,eAAiD,IAAI,iBAAiB,EACtE,kBAAuD,IAAI,mBAAmB,eAAe,EAC7F,wBAAmE,IAAI,yBACrE,eACD,EACD,uBAAwE,IAAI,+BAC1E,IAAI,yBAAyB,eAAe,CAC7C,EACD;AAXiB,OAAA,iBAAA;AACA,OAAA,gBAAA;AACA,OAAA,kBAAA;AACA,OAAA,eAAA;AACA,OAAA,kBAAA;AACA,OAAA,wBAAA;AAGA,OAAA,uBAAA;AAIjB,OAAK,uBAAuB,IAAI,wBAC9B,KAAK,iBACL,KAAK,qBACN;;CAGH,UAAU,OACR,WACA,YAI8B;EAC9B,MAAM,EAAE,YAAY,gBAAgB,WAAW,EAAE;AACjD,QAAM,aAAa,YAAY;EAC/B,MAAM,SAAS,MAAM,KAAK,qBAAqB,QAAQ,WAAW,YAAY;EAC9E,MAAM,gBAAgB,MAAM,KAAK,eAAe,yBAAyB,gBAAgB;AACzF,MAAI;AACF,OAAI,OAAO,SAAS,WAClB,OAAM,aAAa,cAAc;GAEnC,MAAM,aACJ,OAAO,SAAS,eACX,MAAM,KAAK,cAAc,iBAAiB;IACzC,cAAc,OAAO;IACrB,YAAY,KAAK,KAAK,eAAe,WAAW;IACjD,CAAC,EAAE,aACJ,OAAO,SAAS,WACd,OAAO,cAEL,MAAM,KAAK,qBAAqB,eAAe;IAC7C,YAAY,OAAO;IACnB,iBAAiB;IAClB,CAAC,EACF;AACV,SAAM,aAAa,YAAY;GAC/B,MAAM,qBAAqB,KAAK,KAAK,eAAe,SAAS;GAC7D,MAAM,oBAAoB,MAAM,KAAK,cAAc,cAAc;IAC/D;IACA,iBAAiB;IACl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,OAAO,UAAU,YAAY,UAAU,QACvC,UAAU,SAAU,MAA6B,SAAS"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AppManifestSummary, AppStandaloneManifestBundle } from "../types/app-manifest.types.js";
|
|
2
|
+
import { AppManifestService } from "./app-manifest.service.js";
|
|
3
|
+
import { AppDocumentGrantMap, AppPermissionSummary } from "../types/app-permissions.types.js";
|
|
4
|
+
import { AppPermissionsService } from "./app-permissions.service.js";
|
|
5
|
+
import { MainRunResult, WasmDocumentSummaryInput } from "../types/main-runner.types.js";
|
|
6
|
+
import { WasmMainRunnerService } from "./wasm-main-runner.service.js";
|
|
7
|
+
|
|
8
|
+
//#region src/services/app-instance.service.d.ts
|
|
9
|
+
type AppRunResult = {
|
|
10
|
+
action: string;
|
|
11
|
+
input: WasmDocumentSummaryInput;
|
|
12
|
+
output: MainRunResult;
|
|
13
|
+
observedAt: string;
|
|
14
|
+
};
|
|
15
|
+
declare class AppInstanceService {
|
|
16
|
+
readonly bundle: AppStandaloneManifestBundle;
|
|
17
|
+
private readonly permissionsService;
|
|
18
|
+
private readonly mainRunner;
|
|
19
|
+
private readonly manifestService;
|
|
20
|
+
private permissions?;
|
|
21
|
+
constructor(bundle: AppStandaloneManifestBundle, permissionsService?: AppPermissionsService, mainRunner?: WasmMainRunnerService, manifestService?: AppManifestService);
|
|
22
|
+
initialize: (documentGrantMap: AppDocumentGrantMap, context?: {
|
|
23
|
+
appId?: string;
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
summarizeManifest: () => AppManifestSummary;
|
|
26
|
+
summarizePermissions: () => AppPermissionSummary;
|
|
27
|
+
runAction: (action?: string) => Promise<AppRunResult>;
|
|
28
|
+
private collectDocumentSummaryInput;
|
|
29
|
+
private collectDirectorySummary;
|
|
30
|
+
private getPermissions;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { AppInstanceService, AppRunResult };
|
|
34
|
+
//# sourceMappingURL=app-instance.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-instance.service.d.ts","names":[],"sources":["../../src/services/app-instance.service.ts"],"mappings":";;;;;;;;KAaY,YAAA;EACV,MAAA;EACA,KAAA,EAAO,wBAAA;EACP,MAAA,EAAQ,aAAA;EACR,UAAA;AAAA;AAAA,cAGW,kBAAA;EAAA,SAIA,MAAA,EAAQ,2BAAA;EAAA,iBACA,kBAAA;EAAA,iBACA,UAAA;EAAA,iBACA,eAAA;EAAA,QANX,WAAA;cAGG,MAAA,EAAQ,2BAAA,EACA,kBAAA,GAAoB,qBAAA,EACpB,UAAA,GAAY,qBAAA,EACZ,eAAA,GAAiB,kBAAA;EAGpC,UAAA,GACE,gBAAA,EAAkB,mBAAA,EAClB,OAAA;IACE,KAAA;EAAA,MAED,OAAA;EAQH,iBAAA,QARU,kBAAA;EAYV,oBAAA,QAA2B,oBAAA;EAI3B,SAAA,GAAmB,MAAA,cAAkB,OAAA,CAAQ,YAAA;EAAA,QAuBrC,2BAAA;EAAA,QAiBA,uBAAA;EAAA,QA6BA,cAAA;AAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AppManifestService } from "
|
|
2
|
-
import { AppPermissionsService } from "
|
|
3
|
-
import { WasmMainRunnerService } from "
|
|
1
|
+
import { AppManifestService } from "./app-manifest.service.js";
|
|
2
|
+
import { AppPermissionsService } from "./app-permissions.service.js";
|
|
3
|
+
import { WasmMainRunnerService } from "./wasm-main-runner.service.js";
|
|
4
4
|
import { readFile, readdir } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
//#region src/
|
|
6
|
+
//#region src/services/app-instance.service.ts
|
|
7
7
|
var AppInstanceService = class {
|
|
8
8
|
permissions;
|
|
9
9
|
constructor(bundle, permissionsService = new AppPermissionsService(), mainRunner = new WasmMainRunnerService(), manifestService = new AppManifestService()) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-instance.service.js","names":[],"sources":["../../src/services/app-instance.service.ts"],"sourcesContent":["import { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { AppStandaloneManifestBundle } from \"#app-runtime/types/app-manifest.types.js\";\nimport { AppManifestService } from \"#app-runtime/services/app-manifest.service.js\";\nimport { AppPermissionsService } from \"#app-runtime/services/app-permissions.service.js\";\nimport type {\n AppDocumentGrantMap,\n AppPermissionSummary,\n ResolvedPermissions,\n} from \"#app-runtime/types/app-permissions.types.js\";\nimport { WasmMainRunnerService } from \"#app-runtime/services/wasm-main-runner.service.js\";\nimport type { MainRunResult, WasmDocumentSummaryInput } from \"#app-runtime/types/main-runner.types.js\";\n\nexport type AppRunResult = {\n action: string;\n input: WasmDocumentSummaryInput;\n output: MainRunResult;\n observedAt: string;\n};\n\nexport class AppInstanceService {\n private permissions?: ResolvedPermissions;\n\n constructor(\n readonly bundle: AppStandaloneManifestBundle,\n private readonly permissionsService: AppPermissionsService = new AppPermissionsService(),\n private readonly mainRunner: WasmMainRunnerService = new WasmMainRunnerService(),\n private readonly manifestService: AppManifestService = new AppManifestService(),\n ) {}\n\n initialize = async (\n documentGrantMap: AppDocumentGrantMap,\n context?: {\n appId?: string;\n },\n ): Promise<void> => {\n this.permissions = await this.permissionsService.resolve(\n this.bundle,\n documentGrantMap,\n context,\n );\n };\n\n summarizeManifest = () => {\n return this.manifestService.summarize(this.bundle);\n };\n\n summarizePermissions = (): AppPermissionSummary => {\n return this.permissionsService.summarize(this.bundle, this.getPermissions());\n };\n\n runAction = async (action?: string): Promise<AppRunResult> => {\n if (this.bundle.manifest.main.kind !== \"wasm\") {\n throw new Error(\"当前应用不支持 __napp/run action,请通过 /api/* 调用 WASI HTTP 后端。\");\n }\n const expectedAction = this.bundle.manifest.main.action;\n if (action && action !== expectedAction) {\n throw new Error(`当前应用只支持动作 ${expectedAction}。`);\n }\n\n const input = await this.collectDocumentSummaryInput();\n const output = await this.mainRunner.runDocumentSummary({\n bundle: this.bundle,\n input,\n });\n\n return {\n action: expectedAction,\n input,\n output,\n observedAt: new Date().toISOString(),\n };\n };\n\n private collectDocumentSummaryInput = async (): Promise<WasmDocumentSummaryInput> => {\n const permissions = this.getPermissions();\n let documentCount = 0;\n let textBytes = 0;\n\n for (const grant of permissions.documentAccess) {\n const scopeSummary = await this.collectDirectorySummary(grant.path);\n documentCount += scopeSummary.documentCount;\n textBytes += scopeSummary.textBytes;\n }\n\n return {\n documentCount,\n textBytes,\n };\n };\n\n private collectDirectorySummary = async (\n directoryPath: string,\n ): Promise<WasmDocumentSummaryInput> => {\n const entries = await readdir(directoryPath, { withFileTypes: true });\n let documentCount = 0;\n let textBytes = 0;\n\n for (const entry of entries) {\n const entryPath = path.join(directoryPath, entry.name);\n if (entry.isDirectory()) {\n const childSummary = await this.collectDirectorySummary(entryPath);\n documentCount += childSummary.documentCount;\n textBytes += childSummary.textBytes;\n continue;\n }\n if (!entry.isFile()) {\n continue;\n }\n const content = await readFile(entryPath, \"utf-8\");\n documentCount += 1;\n textBytes += Buffer.byteLength(content, \"utf-8\");\n }\n\n return {\n documentCount,\n textBytes,\n };\n };\n\n private getPermissions = (): ResolvedPermissions => {\n if (!this.permissions) {\n throw new Error(\"应用实例尚未初始化权限。\");\n }\n return this.permissions;\n };\n}\n"],"mappings":";;;;;;AAoBA,IAAa,qBAAb,MAAgC;CAC9B;CAEA,YACE,QACA,qBAA6D,IAAI,uBAAuB,EACxF,aAAqD,IAAI,uBAAuB,EAChF,kBAAuD,IAAI,oBAAoB,EAC/E;AAJS,OAAA,SAAA;AACQ,OAAA,qBAAA;AACA,OAAA,aAAA;AACA,OAAA,kBAAA;;CAGnB,aAAa,OACX,kBACA,YAGkB;AAClB,OAAK,cAAc,MAAM,KAAK,mBAAmB,QAC/C,KAAK,QACL,kBACA,QACD;;CAGH,0BAA0B;AACxB,SAAO,KAAK,gBAAgB,UAAU,KAAK,OAAO;;CAGpD,6BAAmD;AACjD,SAAO,KAAK,mBAAmB,UAAU,KAAK,QAAQ,KAAK,gBAA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EjC,SAAO,KAAK"}
|
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import { AppManifestBundle, AppManifestSummary } from "
|
|
1
|
+
import { AppManifestBundle, AppManifestSummary } from "../types/app-manifest.types.js";
|
|
2
2
|
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/services/app-manifest.service.d.ts
|
|
4
4
|
declare class AppManifestService {
|
|
5
5
|
load: (appDirectory: string) => Promise<AppManifestBundle>;
|
|
6
6
|
summarize: (bundle: AppManifestBundle) => AppManifestSummary;
|
|
7
|
+
private loadStandaloneBundle;
|
|
8
|
+
private loadComponentBundle;
|
|
7
9
|
private parseManifest;
|
|
10
|
+
private parseCommonManifest;
|
|
8
11
|
private parseMain;
|
|
9
12
|
private parseUi;
|
|
13
|
+
private parseComponents;
|
|
14
|
+
private parseEngines;
|
|
15
|
+
private parsePresentation;
|
|
16
|
+
private readComponentId;
|
|
10
17
|
private parsePermissions;
|
|
11
18
|
private parseDocumentAccess;
|
|
12
19
|
private parseStringArray;
|
|
13
20
|
private parseStorage;
|
|
14
21
|
private parseCapabilities;
|
|
15
22
|
private assertResolvedFile;
|
|
23
|
+
private assertResolvedDirectory;
|
|
24
|
+
private resolveInside;
|
|
25
|
+
private normalizeRelativePath;
|
|
16
26
|
private assertObject;
|
|
17
27
|
private readRequiredString;
|
|
18
28
|
private readOptionalString;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-manifest.service.d.ts","names":[],"sources":["../../src/services/app-manifest.service.ts"],"mappings":";;;cAmBa,kBAAA;EACX,IAAA,GAAc,YAAA,aAAuB,OAAA,CAAQ,iBAAA;EAU7C,SAAA,GAAa,MAAA,EAAQ,iBAAA,KAAoB,kBAAA;EAAA,QAoCjC,oBAAA;EAAA,QA8BA,mBAAA;EAAA,QA8DA,aAAA;EAAA,QAyBA,mBAAA;EAAA,QAcA,SAAA;EAAA,QAoBA,OAAA;EAAA,QAKA,eAAA;EAAA,QA+BA,YAAA;EAAA,QAUA,iBAAA;EAAA,QAeA,eAAA;EAAA,QA0BA,gBAAA;EAAA,QAaA,mBAAA;EAAA,QAwBA,gBAAA;EAAA,QAUA,YAAA;EAAA,QAQA,iBAAA;EAAA,QAYA,kBAAA;EAAA,QAaA,uBAAA;EAAA,QAcA,aAAA;EAAA,QAUA,qBAAA;EAAA,QAWA,YAAA;EAAA,QAOA,kBAAA;EAAA,QAOA,kBAAA;EAAA,QAIA,UAAA;EAAA,QAOA,WAAA;AAAA"}
|