soma-core 1.0.1 → 1.0.3
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/app/SomaPageClient.tsx +364 -0
- package/app/api/[...path]/route.ts +9 -85
- package/app/api/page/route.ts +57 -35
- package/app/api/soma-manifest/route.ts +39 -0
- package/app/components/SomaHydrationShell.tsx +23 -0
- package/app/favicon.ico/route.ts +13 -0
- package/app/layout.tsx +2 -2
- package/app/loading.tsx +5 -0
- package/app/page.tsx +19 -128
- package/bin/soma-lsp.cjs +195 -0
- package/bin/soma-sync.cjs +3 -0
- package/bin/soma.cjs +13 -1
- package/core/api/IService.ts +6 -10
- package/core/api/load-host-service.ts +75 -0
- package/core/api/service-path.ts +39 -0
- package/core/base/SomaEntity.ts +3 -10
- package/core/base/SomaLocaleOnlyPageRoot.ts +3 -4
- package/core/base/SomaPageRootBase.ts +20 -3
- package/core/base/decorators/Event.ts +23 -0
- package/core/base/decorators/Locale.ts +35 -0
- package/core/base/decorators/Page.ts +16 -0
- package/core/base/decorators/Show.ts +20 -0
- package/core/base/decorators/ShowList.ts +34 -0
- package/core/base/decorators/index.ts +5 -0
- package/core/base/index.ts +2 -0
- package/core/base/runAsync.ts +32 -0
- package/core/compiler/full-manifest-builder.ts +33 -7
- package/core/compiler/host-config-sync.cjs +38 -0
- package/core/compiler/manifest-compiler.ts +3 -2
- package/core/compiler/page-base-resolver.ts +26 -0
- package/core/compiler/precompiled-manifest-loader.ts +34 -0
- package/core/compiler/rollup-plugin-soma.ts +45 -0
- package/core/compiler/rspack-plugin-soma.js +33 -0
- package/core/compiler/soma-manifest-webpack-plugin.js +188 -0
- package/core/compiler/soma-precompile.js +3513 -0
- package/core/compiler/soma-precompile.ts +52 -6
- package/core/compiler/soma-rspack-yaml-loader.js +22 -0
- package/core/compiler/soma-webpack-loader.js +7 -1
- package/core/compiler/vite-plugin-soma.ts +11 -1
- package/core/container/IContainerAdapter.ts +36 -0
- package/core/container/MiniProgramContainerAdapter.ts +190 -0
- package/core/container/ReactNativeContainerAdapter.ts +189 -0
- package/core/container/SomaContainerAdapter.ts +17 -6
- package/core/diagnostics/SomaDiagnostics.ts +1 -1
- package/core/diagnostics/SomaTelemetry.ts +100 -0
- package/core/diagnostics/telemetry-context.ts +15 -0
- package/core/engine/asset-resolver.ts +39 -4
- package/core/engine/dom-renderer.ts +169 -35
- package/core/engine/event-engine.ts +110 -41
- package/core/engine/on-change-engine.ts +71 -0
- package/core/engine/property-watcher.ts +117 -0
- package/core/engine/reactive-proxy.ts +11 -5
- package/core/engine/render-engine.ts +97 -11
- package/core/engine/runtime-builder.ts +88 -11
- package/core/engine/scope-resolver.ts +65 -9
- package/core/engine/soma-bootstrap.ts +448 -244
- package/core/engine/style-binder.ts +423 -0
- package/core/engine/theme-variables.ts +37 -0
- package/core/engine/timer-engine.ts +92 -0
- package/core/engine/trigger-engine.ts +55 -0
- package/core/host/app-config.stub.ts +2 -0
- package/core/host/locale.stub.ts +2 -0
- package/core/host/resolve-host-bootstrap.ts +28 -0
- package/core/host/soma-bootstrap-host.stub.ts +4 -0
- package/core/host/source-packages.ts +112 -0
- package/core/index.ts +33 -2
- package/core/infra/auth/TokenAuthService.ts +17 -3
- package/core/infra/http/IHttpClient.ts +11 -1
- package/core/infra/http/SomaHttpService.ts +89 -31
- package/core/infra/i18n/DefaultI18n.ts +6 -18
- package/core/infra/i18n/II18n.ts +2 -3
- package/core/infra/notify/DomNotifyService.ts +98 -0
- package/core/infra/notify/INotifyTheme.ts +22 -0
- package/core/infra/realtime/IRealtimeService.ts +23 -0
- package/core/infra/realtime/IRealtimeTransport.ts +9 -0
- package/core/infra/realtime/SomaRealtimeService.ts +95 -0
- package/core/infra/realtime/SseRealtimeTransport.ts +36 -0
- package/core/infra/realtime/WebSocketRealtimeTransport.ts +102 -0
- package/core/infra/router/router-path.ts +28 -0
- package/core/infra/storage/SessionStorageService.ts +59 -0
- package/core/lsp/cross-file-diagnostics.cjs +160 -0
- package/core/lsp/event-yaml-completion.cjs +106 -0
- package/core/lsp/extra-completion.cjs +64 -0
- package/core/lsp/lsp-navigation.cjs +191 -0
- package/core/lsp/ui-yaml-completion.cjs +170 -0
- package/core/manifest/manifest-contract.ts +12 -0
- package/core/middleware/createPermissionMiddleware.ts +37 -0
- package/core/parser/annotation-extractor.ts +113 -0
- package/core/parser/pipeline-parser.ts +344 -276
- package/core/parser/style-config-parser.ts +340 -0
- package/core/parser/timer-parser.ts +70 -0
- package/core/parser/trigger-parser.ts +90 -0
- package/core/parser/ui-config-parser.ts +73 -1
- package/core/quality/SomaQualityRegistry.ts +68 -0
- package/core/runtime/SomaRuntimeServices.ts +100 -0
- package/core/runtime/SomaSnapshotStore.ts +5 -3
- package/core/types/domain.types.ts +5 -2
- package/core/types/event.types.ts +82 -57
- package/core/types/manifest.types.ts +2 -0
- package/core/types/style-config.types.ts +76 -0
- package/core/types/timer.types.ts +23 -0
- package/core/types/trigger.types.ts +14 -0
- package/core/types/ui-config.types.ts +9 -0
- package/core/types/watcher.types.ts +29 -0
- package/dist/cli/soma.js +23 -23
- package/dist/core/index.cjs +9065 -0
- package/dist/diagnostics/telemetry.cjs +105 -0
- package/dist/preview-export.cjs +3401 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/api/IService.d.ts +28 -0
- package/dist/types/api/load-host-service.d.ts +5 -0
- package/dist/types/api/service-path.d.ts +13 -0
- package/dist/types/base/SomaApi.d.ts +5 -0
- package/dist/types/base/SomaDict.d.ts +89 -0
- package/dist/types/base/SomaEntity.d.ts +15 -0
- package/dist/types/base/SomaHttpClient.d.ts +66 -0
- package/dist/types/base/SomaLocaleOnlyPageRoot.d.ts +3 -0
- package/dist/types/base/SomaPageRootBase.d.ts +49 -0
- package/dist/types/base/SomaValidator.d.ts +55 -0
- package/dist/types/base/decorators/Event.d.ts +10 -0
- package/dist/types/base/decorators/Locale.d.ts +9 -0
- package/dist/types/base/decorators/Page.d.ts +4 -0
- package/dist/types/base/decorators/Show.d.ts +7 -0
- package/dist/types/base/decorators/ShowList.d.ts +12 -0
- package/dist/types/base/decorators/index.d.ts +5 -0
- package/dist/types/base/index.d.ts +9 -0
- package/dist/types/base/runAsync.d.ts +12 -0
- package/dist/types/compiler/full-manifest-builder.d.ts +35 -0
- package/dist/types/compiler/manifest-compiler.d.ts +29 -0
- package/dist/types/compiler/page-base-resolver.d.ts +6 -0
- package/dist/types/compiler/precompiled-manifest-loader.d.ts +5 -0
- package/dist/types/compiler/rollup-plugin-soma.d.ts +14 -0
- package/dist/types/compiler/route-builder.d.ts +12 -0
- package/dist/types/compiler/soma-precompile.d.ts +40 -0
- package/dist/types/compiler/vite-plugin-soma.d.ts +34 -0
- package/dist/types/container/IContainerAdapter.d.ts +30 -0
- package/dist/types/container/MiniProgramContainerAdapter.d.ts +52 -0
- package/dist/types/container/ReactNativeContainerAdapter.d.ts +47 -0
- package/dist/types/container/SomaContainerAdapter.d.ts +30 -0
- package/dist/types/diagnostics/SomaDiagnostics.d.ts +64 -0
- package/dist/types/diagnostics/SomaTelemetry.d.ts +32 -0
- package/dist/types/diagnostics/telemetry-context.d.ts +4 -0
- package/dist/types/engine/asset-resolver.d.ts +17 -0
- package/dist/types/engine/dom-renderer.d.ts +41 -0
- package/dist/types/engine/event-engine.d.ts +64 -0
- package/dist/types/engine/lis.d.ts +10 -0
- package/dist/types/engine/on-change-engine.d.ts +16 -0
- package/dist/types/engine/property-watcher.d.ts +18 -0
- package/dist/types/engine/reactive-proxy.d.ts +58 -0
- package/dist/types/engine/render-engine.d.ts +73 -0
- package/dist/types/engine/runtime-builder.d.ts +58 -0
- package/dist/types/engine/scope-resolver.d.ts +90 -0
- package/dist/types/engine/soma-bootstrap.d.ts +112 -0
- package/dist/types/engine/style-binder.d.ts +81 -0
- package/dist/types/engine/theme-variables.d.ts +3 -0
- package/dist/types/engine/timer-engine.d.ts +19 -0
- package/dist/types/engine/trigger-engine.d.ts +16 -0
- package/dist/types/host/app-config.stub.d.ts +3 -0
- package/dist/types/host/locale.stub.d.ts +3 -0
- package/dist/types/host/resolve-host-bootstrap.d.ts +11 -0
- package/dist/types/host/soma-bootstrap-host.stub.d.ts +3 -0
- package/dist/types/host/source-packages.d.ts +8 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/infra/auth/IAuthService.d.ts +12 -0
- package/dist/types/infra/auth/TokenAuthService.d.ts +26 -0
- package/dist/types/infra/cache/ICache.d.ts +12 -0
- package/dist/types/infra/cache/MemoryCache.d.ts +14 -0
- package/dist/types/infra/cache/ServerFileCache.d.ts +37 -0
- package/dist/types/infra/config/IConfig.d.ts +9 -0
- package/dist/types/infra/config/SomaConfig.d.ts +21 -0
- package/dist/types/infra/event-bus/IEventBus.d.ts +8 -0
- package/dist/types/infra/event-bus/SomaEventBus.d.ts +9 -0
- package/dist/types/infra/http/IHttpClient.d.ts +28 -0
- package/dist/types/infra/http/SomaHttpService.d.ts +27 -0
- package/dist/types/infra/i18n/DefaultI18n.d.ts +7 -0
- package/dist/types/infra/i18n/II18n.d.ts +6 -0
- package/dist/types/infra/logger/ConsoleLogger.d.ts +14 -0
- package/dist/types/infra/logger/ILogger.d.ts +17 -0
- package/dist/types/infra/notify/DefaultNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/DomNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/INotifyService.d.ts +12 -0
- package/dist/types/infra/notify/INotifyTheme.d.ts +12 -0
- package/dist/types/infra/permission/IPermission.d.ts +10 -0
- package/dist/types/infra/permission/SomaPermission.d.ts +19 -0
- package/dist/types/infra/realtime/IRealtimeService.d.ts +13 -0
- package/dist/types/infra/realtime/IRealtimeTransport.d.ts +8 -0
- package/dist/types/infra/realtime/SomaRealtimeService.d.ts +20 -0
- package/dist/types/infra/realtime/SseRealtimeTransport.d.ts +11 -0
- package/dist/types/infra/realtime/WebSocketRealtimeTransport.d.ts +30 -0
- package/dist/types/infra/router/IRouter.d.ts +16 -0
- package/dist/types/infra/router/SomaRouter.d.ts +18 -0
- package/dist/types/infra/router/router-path.d.ts +6 -0
- package/dist/types/infra/storage/IStorageService.d.ts +7 -0
- package/dist/types/infra/storage/MemoryStorageService.d.ts +15 -0
- package/dist/types/infra/storage/SessionStorageService.d.ts +14 -0
- package/dist/types/infra/timer/ITimer.d.ts +13 -0
- package/dist/types/infra/timer/SomaTimer.d.ts +21 -0
- package/dist/types/manifest/manifest-contract.d.ts +4 -0
- package/dist/types/middleware/SomaMiddlewareChain.d.ts +6 -0
- package/dist/types/middleware/createPermissionMiddleware.d.ts +14 -0
- package/dist/types/parser/annotation-extractor.d.ts +12 -0
- package/dist/types/parser/pipeline-parser.d.ts +62 -0
- package/dist/types/parser/style-config-parser.d.ts +20 -0
- package/dist/types/parser/timer-parser.d.ts +6 -0
- package/dist/types/parser/trigger-parser.d.ts +13 -0
- package/dist/types/parser/ui-config-parser.d.ts +34 -0
- package/dist/types/parser/yaml-loader.d.ts +21 -0
- package/dist/types/quality/SomaQualityRegistry.d.ts +31 -0
- package/dist/types/runtime/SomaRuntimeServices.d.ts +35 -0
- package/dist/types/runtime/SomaSnapshotStore.d.ts +13 -0
- package/dist/types/scheduler/SomaScheduler.d.ts +25 -0
- package/dist/types/types/domain.types.d.ts +82 -0
- package/dist/types/types/engine.types.d.ts +22 -0
- package/dist/types/types/event.types.d.ts +61 -0
- package/dist/types/types/keyboard.types.d.ts +4 -0
- package/dist/types/types/manifest.types.d.ts +29 -0
- package/dist/types/types/scheduler.types.d.ts +8 -0
- package/dist/types/types/style-config.types.d.ts +62 -0
- package/dist/types/types/timer.types.d.ts +19 -0
- package/dist/types/types/trigger.types.d.ts +12 -0
- package/dist/types/types/ui-config.types.d.ts +85 -0
- package/dist/types/types/watcher.types.d.ts +24 -0
- package/dist/types/validation/contract-validator.d.ts +40 -0
- package/editor/vscode/extension.js +39 -0
- package/editor/vscode/language-configuration.json +17 -0
- package/editor/vscode/package.json +98 -0
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +30 -0
- package/editor/vscode/syntaxes/soma-ui-yaml.tmLanguage.json +42 -0
- package/global.d.ts +22 -3
- package/next.config.js +73 -4
- package/package.json +58 -17
- package/tailwind.config.ts +36 -13
- package/tsconfig.json +6 -2
- package/core/router/RouteHandler.ts +0 -93
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
5
|
+
import { SomaHydrationShell } from './components/SomaHydrationShell';
|
|
6
|
+
import type { SomaBootstrap as SomaBootstrapType, SomaPageAssets } from '../core/engine/soma-bootstrap';
|
|
7
|
+
|
|
8
|
+
const isDev = process.env.NODE_ENV !== 'production';
|
|
9
|
+
|
|
10
|
+
export default function SomaEntry() {
|
|
11
|
+
const pathname = usePathname();
|
|
12
|
+
const searchParams = useSearchParams();
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
const navigate = useCallback((url: string) => {
|
|
15
|
+
router.push(url);
|
|
16
|
+
}, [router]);
|
|
17
|
+
const routerPath = searchParams.toString()
|
|
18
|
+
? `${pathname}?${searchParams.toString()}`
|
|
19
|
+
: pathname;
|
|
20
|
+
return (
|
|
21
|
+
<SomaPageRenderer
|
|
22
|
+
pagePath={pathname}
|
|
23
|
+
routerPath={routerPath}
|
|
24
|
+
onNavigate={navigate}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function urlPathToPageBase(urlPath: string): string {
|
|
30
|
+
const clean = urlPath.replace(/^\//, '').replace(/\.html$/i, '');
|
|
31
|
+
return clean || 'index';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type DomainModule = { default?: unknown; [key: string]: unknown };
|
|
35
|
+
|
|
36
|
+
const webAdminShellDomainLoaders: Record<string, () => Promise<DomainModule>> = {
|
|
37
|
+
index: () => import('web-admin-shell/domain/ui/indexClass') as Promise<DomainModule>,
|
|
38
|
+
'auth-manage/route': () => import('web-admin-shell/domain/ui/auth-manage/routeClass') as Promise<DomainModule>,
|
|
39
|
+
'auth-manage/menu': () => import('web-admin-shell/domain/ui/auth-manage/menuClass') as Promise<DomainModule>,
|
|
40
|
+
'auth-manage/role': () => import('web-admin-shell/domain/ui/auth-manage/roleClass') as Promise<DomainModule>,
|
|
41
|
+
'auth-manage/role-auth': () => import('web-admin-shell/domain/ui/auth-manage/role-authClass') as Promise<DomainModule>,
|
|
42
|
+
'auth-manage/user-role': () => import('web-admin-shell/domain/ui/auth-manage/user-roleClass') as Promise<DomainModule>,
|
|
43
|
+
'auth-manage/action-log': () => import('web-admin-shell/domain/ui/auth-manage/action-logClass') as Promise<DomainModule>,
|
|
44
|
+
'auth-manage/dictionary': () => import('web-admin-shell/domain/ui/auth-manage/dictionaryClass') as Promise<DomainModule>,
|
|
45
|
+
'auth-manage/auth-app': () => import('web-admin-shell/domain/ui/auth-manage/auth-appClass') as Promise<DomainModule>,
|
|
46
|
+
'auth-manage/system': () => import('web-admin-shell/domain/ui/auth-manage/systemClass') as Promise<DomainModule>,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
async function loadDomainClass(base: string, sourcePackage?: string | null): Promise<new () => any> {
|
|
50
|
+
try {
|
|
51
|
+
if (sourcePackage === 'web-admin-shell') {
|
|
52
|
+
const load = webAdminShellDomainLoaders[base];
|
|
53
|
+
if (!load) throw new Error(`domain class missing: ${sourcePackage}:${base}Class`);
|
|
54
|
+
const mod = await load();
|
|
55
|
+
if (typeof mod.default === 'function') return mod.default as new () => any;
|
|
56
|
+
const ctor = Object.values(mod).find((v): v is new () => any => typeof v === 'function');
|
|
57
|
+
if (ctor) return ctor as new () => any;
|
|
58
|
+
throw new Error(`domain class missing: ${sourcePackage}:${base}Class`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const mod = await import(
|
|
62
|
+
/* webpackInclude: /\/domain\/ui\/.*Class\.ts$/ */
|
|
63
|
+
`@soma-host/domain/ui/${base}Class`
|
|
64
|
+
);
|
|
65
|
+
if (typeof mod.default === 'function') return mod.default;
|
|
66
|
+
const ctor = Object.values(mod).find((v) => typeof v === 'function');
|
|
67
|
+
if (ctor) return ctor as new () => any;
|
|
68
|
+
throw new Error(`domain class missing: ${base}Class`);
|
|
69
|
+
} catch {
|
|
70
|
+
const { SomaLocaleOnlyPageRoot } = await import('../core/base/SomaLocaleOnlyPageRoot');
|
|
71
|
+
return SomaLocaleOnlyPageRoot;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type PagePayload = {
|
|
76
|
+
base: string;
|
|
77
|
+
sourcePackage?: string | null;
|
|
78
|
+
html: string;
|
|
79
|
+
ui: string;
|
|
80
|
+
event: string;
|
|
81
|
+
styleYaml?: string;
|
|
82
|
+
includes?: Record<string, string>;
|
|
83
|
+
localeYaml: string;
|
|
84
|
+
appConfigYaml: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type PrecompiledAssets = Pick<
|
|
88
|
+
SomaPageAssets,
|
|
89
|
+
'uiConfig' | 'eventConfig' | 'triggerConfig' | 'timerConfig' | 'styleConfig' | 'locale' | 'appConfig'
|
|
90
|
+
>;
|
|
91
|
+
|
|
92
|
+
function normalizeEventBundle(raw: unknown): {
|
|
93
|
+
events: PrecompiledAssets['eventConfig'];
|
|
94
|
+
triggers: NonNullable<PrecompiledAssets['triggerConfig']>;
|
|
95
|
+
timers: NonNullable<PrecompiledAssets['timerConfig']>;
|
|
96
|
+
} {
|
|
97
|
+
if (Array.isArray(raw)) {
|
|
98
|
+
return { events: raw, triggers: [], timers: [] };
|
|
99
|
+
}
|
|
100
|
+
if (raw && typeof raw === 'object' && 'events' in raw) {
|
|
101
|
+
const bundle = raw as { events?: unknown; triggers?: unknown; timers?: unknown };
|
|
102
|
+
return {
|
|
103
|
+
events: (bundle.events ?? []) as NonNullable<PrecompiledAssets['eventConfig']>,
|
|
104
|
+
triggers: (bundle.triggers ?? []) as NonNullable<PrecompiledAssets['triggerConfig']>,
|
|
105
|
+
timers: (bundle.timers ?? []) as NonNullable<PrecompiledAssets['timerConfig']>,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return { events: [], triggers: [], timers: [] };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const pageAssetCache = new Map<string, PagePayload>();
|
|
112
|
+
|
|
113
|
+
async function loadPrecompiledFromManifest(base: string, path: string): Promise<PrecompiledAssets | null> {
|
|
114
|
+
try {
|
|
115
|
+
const res = await fetch(`/api/soma-manifest?path=${encodeURIComponent(path)}`);
|
|
116
|
+
if (!res.ok) return null;
|
|
117
|
+
const data = await res.json();
|
|
118
|
+
return {
|
|
119
|
+
uiConfig: data.uiConfig,
|
|
120
|
+
eventConfig: data.eventConfig,
|
|
121
|
+
triggerConfig: data.triggers ?? [],
|
|
122
|
+
timerConfig: data.timers ?? [],
|
|
123
|
+
styleConfig: data.styleConfig,
|
|
124
|
+
locale: data.locale ?? {},
|
|
125
|
+
appConfig: data.appConfig ?? null,
|
|
126
|
+
};
|
|
127
|
+
} catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function loadPrecompiledAssets(base: string, urlPath = `/${base}`): Promise<PrecompiledAssets | null> {
|
|
133
|
+
try {
|
|
134
|
+
const [uiMod, eventMod, styleMod, localeMod, configMod] = await Promise.all([
|
|
135
|
+
import(
|
|
136
|
+
/* webpackInclude: /\/ui\/.*_ui\.yaml$/ */
|
|
137
|
+
`@soma-host/ui/${base}_ui.yaml`
|
|
138
|
+
).catch(() => null),
|
|
139
|
+
import(
|
|
140
|
+
/* webpackInclude: /\/event\/.*_event\.yaml$/ */
|
|
141
|
+
`@soma-host/event/${base}_event.yaml`
|
|
142
|
+
).catch(() => null),
|
|
143
|
+
import(
|
|
144
|
+
/* webpackInclude: /\/ui\/.*_style\.yaml$/ */
|
|
145
|
+
`@soma-host/ui/${base}_style.yaml`
|
|
146
|
+
).catch(() => null),
|
|
147
|
+
import(
|
|
148
|
+
/* webpackInclude: /\/config\/locale\.yaml$/ */
|
|
149
|
+
'@soma-host/config/locale.yaml'
|
|
150
|
+
).catch(() => null),
|
|
151
|
+
import(
|
|
152
|
+
/* webpackInclude: /\/config\/app\.config\.yaml$/ */
|
|
153
|
+
'@soma-host/config/app.config.yaml'
|
|
154
|
+
).catch(() => null),
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
if (!uiMod?.default || !eventMod?.default) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const eventBundle = normalizeEventBundle(eventMod.default);
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
uiConfig: uiMod.default,
|
|
165
|
+
eventConfig: eventBundle.events,
|
|
166
|
+
triggerConfig: eventBundle.triggers,
|
|
167
|
+
timerConfig: eventBundle.timers,
|
|
168
|
+
styleConfig: styleMod?.default ?? undefined,
|
|
169
|
+
locale: (localeMod?.default ?? {}) as Record<string, unknown>,
|
|
170
|
+
appConfig: configMod?.default ?? null,
|
|
171
|
+
};
|
|
172
|
+
} catch {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function SomaPageRenderer({
|
|
178
|
+
pagePath,
|
|
179
|
+
routerPath,
|
|
180
|
+
onNavigate,
|
|
181
|
+
}: {
|
|
182
|
+
pagePath: string;
|
|
183
|
+
routerPath: string;
|
|
184
|
+
onNavigate: (url: string) => void;
|
|
185
|
+
}) {
|
|
186
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
187
|
+
const bootstrapRef = useRef<SomaBootstrapType | null>(null);
|
|
188
|
+
const routerBridgeRef = useRef<(() => void) | null>(null);
|
|
189
|
+
const [error, setError] = useState<string | null>(null);
|
|
190
|
+
const [mounting, setMounting] = useState(true);
|
|
191
|
+
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (!containerRef.current) return;
|
|
194
|
+
|
|
195
|
+
let cancelled = false;
|
|
196
|
+
|
|
197
|
+
const mountInto = async (
|
|
198
|
+
DomainClass: new () => any,
|
|
199
|
+
SomaBootstrapCtor: new (...args: any[]) => SomaBootstrapType,
|
|
200
|
+
assets: Omit<SomaPageAssets, 'html' | 'includes' | 'DomainClass'>,
|
|
201
|
+
html: string,
|
|
202
|
+
includes?: Record<string, string>,
|
|
203
|
+
) => {
|
|
204
|
+
await bootstrapRef.current?.unmount();
|
|
205
|
+
|
|
206
|
+
const getServices = () =>
|
|
207
|
+
bootstrapRef.current?.getDomainInstance()?._services as import('../core/runtime/SomaRuntimeServices').SomaRuntimeServices | undefined;
|
|
208
|
+
|
|
209
|
+
const { resolveHostBootstrapOptions } = await import('../core/host/resolve-host-bootstrap');
|
|
210
|
+
const hostBootstrapOptions = await resolveHostBootstrapOptions(getServices);
|
|
211
|
+
|
|
212
|
+
const bs = new SomaBootstrapCtor(hostBootstrapOptions);
|
|
213
|
+
bootstrapRef.current = bs;
|
|
214
|
+
|
|
215
|
+
await bs.mount(containerRef.current!, {
|
|
216
|
+
html,
|
|
217
|
+
includes,
|
|
218
|
+
DomainClass,
|
|
219
|
+
...assets,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
routerBridgeRef.current?.();
|
|
223
|
+
const domain = bs.getDomainInstance() as {
|
|
224
|
+
_services?: {
|
|
225
|
+
router: {
|
|
226
|
+
getCurrentPath: () => string;
|
|
227
|
+
onNavigate: (cb: (p: string) => void) => () => void;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
} | null;
|
|
231
|
+
if (domain?._services?.router) {
|
|
232
|
+
const somaRouter = domain._services.router;
|
|
233
|
+
routerBridgeRef.current = somaRouter.onNavigate((nextPath) => {
|
|
234
|
+
if (nextPath !== routerPath) {
|
|
235
|
+
onNavigate(nextPath);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
// onMount 里触发的 navigate 发生在桥接注册之前,此处补同步到 Next 路由
|
|
239
|
+
const pending = somaRouter.getCurrentPath();
|
|
240
|
+
if (pending !== routerPath) {
|
|
241
|
+
onNavigate(pending);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (isDev && typeof window !== 'undefined') {
|
|
246
|
+
window.__SOMA__ = {
|
|
247
|
+
getDiagnosticsSnapshot: () => bs.getDiagnosticsSnapshot(),
|
|
248
|
+
getTelemetrySnapshot: () => bs.getTelemetrySnapshot(),
|
|
249
|
+
getAvailableThemes: () => bs.getAvailableThemes(),
|
|
250
|
+
getDomainInstance: () => bs.getDomainInstance(),
|
|
251
|
+
captureSnapshot: () => bs.captureSnapshot(),
|
|
252
|
+
restoreSnapshot: (id: number) => bs.restoreSnapshot(id),
|
|
253
|
+
switchTheme: (name: string | null) => bs.switchTheme(name),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const run = async () => {
|
|
259
|
+
try {
|
|
260
|
+
setError(null);
|
|
261
|
+
setMounting(true);
|
|
262
|
+
|
|
263
|
+
const { SomaBootstrap } = await import('../core/engine/soma-bootstrap');
|
|
264
|
+
|
|
265
|
+
const res = await fetch(`/api/page?path=${encodeURIComponent(pagePath)}`);
|
|
266
|
+
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
267
|
+
const data = await res.json();
|
|
268
|
+
if (cancelled) return;
|
|
269
|
+
|
|
270
|
+
const base = (data.base as string) || urlPathToPageBase(pagePath);
|
|
271
|
+
const sourcePackage = typeof data.sourcePackage === 'string' ? data.sourcePackage : null;
|
|
272
|
+
const DomainClass = await loadDomainClass(base, sourcePackage);
|
|
273
|
+
const routeAssets = { routerPath };
|
|
274
|
+
|
|
275
|
+
if (!isDev) {
|
|
276
|
+
const fromManifest = await loadPrecompiledFromManifest(base, pagePath);
|
|
277
|
+
const precompiled = fromManifest ?? await loadPrecompiledAssets(base, pagePath);
|
|
278
|
+
if (precompiled) {
|
|
279
|
+
await mountInto(
|
|
280
|
+
DomainClass,
|
|
281
|
+
SomaBootstrap,
|
|
282
|
+
{ ...precompiled, ...routeAssets },
|
|
283
|
+
data.html,
|
|
284
|
+
data.includes,
|
|
285
|
+
);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const cached = pageAssetCache.get(routerPath);
|
|
290
|
+
if (cached) {
|
|
291
|
+
const CachedClass = await loadDomainClass(cached.base, cached.sourcePackage);
|
|
292
|
+
await mountInto(CachedClass, SomaBootstrap, {
|
|
293
|
+
uiYaml: cached.ui,
|
|
294
|
+
eventYaml: cached.event,
|
|
295
|
+
styleYaml: cached.styleYaml,
|
|
296
|
+
localeYaml: cached.localeYaml ?? '',
|
|
297
|
+
appConfigYaml: cached.appConfigYaml ?? '',
|
|
298
|
+
...routeAssets,
|
|
299
|
+
}, cached.html, cached.includes);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const payload: PagePayload = {
|
|
305
|
+
base,
|
|
306
|
+
sourcePackage,
|
|
307
|
+
html: data.html,
|
|
308
|
+
ui: data.ui,
|
|
309
|
+
event: data.event,
|
|
310
|
+
styleYaml: data.styleYaml ?? '',
|
|
311
|
+
includes: data.includes,
|
|
312
|
+
localeYaml: data.localeYaml ?? '',
|
|
313
|
+
appConfigYaml: data.appConfigYaml ?? '',
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
if (!isDev) {
|
|
317
|
+
pageAssetCache.set(routerPath, payload);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
await mountInto(DomainClass, SomaBootstrap, {
|
|
321
|
+
uiYaml: payload.ui,
|
|
322
|
+
eventYaml: payload.event,
|
|
323
|
+
styleYaml: payload.styleYaml,
|
|
324
|
+
localeYaml: payload.localeYaml ?? '',
|
|
325
|
+
appConfigYaml: payload.appConfigYaml ?? '',
|
|
326
|
+
...routeAssets,
|
|
327
|
+
}, payload.html, payload.includes);
|
|
328
|
+
} catch (err: any) {
|
|
329
|
+
if (!cancelled) setError(err?.message ?? String(err));
|
|
330
|
+
} finally {
|
|
331
|
+
if (!cancelled) setMounting(false);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
void run();
|
|
336
|
+
|
|
337
|
+
return () => {
|
|
338
|
+
cancelled = true;
|
|
339
|
+
routerBridgeRef.current?.();
|
|
340
|
+
routerBridgeRef.current = null;
|
|
341
|
+
if (typeof window !== 'undefined') {
|
|
342
|
+
delete window.__SOMA__;
|
|
343
|
+
}
|
|
344
|
+
void bootstrapRef.current?.unmount();
|
|
345
|
+
bootstrapRef.current = null;
|
|
346
|
+
};
|
|
347
|
+
}, [pagePath, routerPath, onNavigate]);
|
|
348
|
+
|
|
349
|
+
if (error) {
|
|
350
|
+
return (
|
|
351
|
+
<div className="p-8 text-red-600">
|
|
352
|
+
<p className="font-bold">Page failed to load</p>
|
|
353
|
+
<p className="text-sm mt-1">{error}</p>
|
|
354
|
+
</div>
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return (
|
|
359
|
+
<>
|
|
360
|
+
{mounting && !error ? <SomaHydrationShell /> : null}
|
|
361
|
+
<div ref={containerRef} className={mounting && !error ? 'hidden' : undefined} />
|
|
362
|
+
</>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
@@ -1,83 +1,6 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
import type { IService } from '@/core/api/IService';
|
|
3
|
-
|
|
4
|
-
// ─── 工具函数 ──────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 将 kebab-case / snake_case 转为 PascalCase
|
|
8
|
-
* @example "user-profile" → "UserProfile", "oauth_token" → "OauthToken"
|
|
9
|
-
*/
|
|
10
|
-
function toPascalCase(str: string): string {
|
|
11
|
-
return str
|
|
12
|
-
.split(/[-_]/)
|
|
13
|
-
.map(s => s.charAt(0).toUpperCase() + s.slice(1))
|
|
14
|
-
.join('');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 从 path 片段构造服务文件路径并动态加载
|
|
19
|
-
* @example ["login"] → @soma-host/api/service/Login
|
|
20
|
-
* @example ["user", "profile"] → @soma-host/api/service/user/Profile
|
|
21
|
-
*/
|
|
22
|
-
function buildImportPath(segments: string[]): string {
|
|
23
|
-
const fileName = toPascalCase(segments[segments.length - 1]);
|
|
24
|
-
const dirs = segments.slice(0, -1);
|
|
25
|
-
const dirPrefix = dirs.length > 0 ? `${dirs.join('/')}/` : '';
|
|
26
|
-
return `@soma-host/api/service/${dirPrefix}${fileName}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 检查对象是否为合法的 IService 实例
|
|
31
|
-
*/
|
|
32
|
-
function isService(obj: any): obj is IService {
|
|
33
|
-
if (!obj || typeof obj !== 'object') return false;
|
|
34
|
-
const methods = ['get', 'post', 'put', 'patch', 'delete'];
|
|
35
|
-
return methods.some(m => typeof obj[m] === 'function');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ─── 模块缓存(dev 模式下不缓存,确保热更新) ────────────────
|
|
39
|
-
|
|
40
|
-
const isDev = process.env.NODE_ENV !== 'production';
|
|
41
|
-
const moduleCache = new Map<string, { mod: any; mtime: number }>();
|
|
42
|
-
|
|
43
|
-
async function loadService(segments: string[]): Promise<IService | null> {
|
|
44
|
-
const importPath = buildImportPath(segments);
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
// 动态导入服务模块(webpack 通过 @soma-host 别名解析到 app-demo)
|
|
48
|
-
const mod = await import(
|
|
49
|
-
/* webpackChunkName: "api-service" */
|
|
50
|
-
/* webpackMode: "lazy" */
|
|
51
|
-
/* webpackInclude: /api\/service\/.*\.ts$/ */
|
|
52
|
-
importPath
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
// 清除缓存以支持热更新(dev 模式)
|
|
56
|
-
if (isDev && moduleCache.has(importPath)) {
|
|
57
|
-
moduleCache.delete(importPath);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const ServiceClass = mod.default;
|
|
61
|
-
if (!ServiceClass || typeof ServiceClass !== 'function') {
|
|
62
|
-
console.warn(`[soma-api] ${importPath} 缺少 default export`);
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const instance = new ServiceClass();
|
|
67
|
-
if (!isService(instance)) {
|
|
68
|
-
console.warn(`[soma-api] ${importPath} 未实现 IService 接口`);
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return instance;
|
|
73
|
-
} catch (e: any) {
|
|
74
|
-
if (e.code === 'MODULE_NOT_FOUND' || e.code === 'ERR_MODULE_NOT_FOUND') {
|
|
75
|
-
return null; // 服务文件不存在
|
|
76
|
-
}
|
|
77
|
-
console.error(`[soma-api] 加载 ${importPath} 失败:`, e.message);
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
3
|
+
import { loadHostService } from '@/core/api/load-host-service';
|
|
81
4
|
|
|
82
5
|
// ─── HTTP 方法分发工厂 ─────────────────────────────────────
|
|
83
6
|
|
|
@@ -94,16 +17,16 @@ function createHandler(method: HttpMethod) {
|
|
|
94
17
|
|
|
95
18
|
if (segments.length === 0) {
|
|
96
19
|
return Response.json(
|
|
97
|
-
{ error: '
|
|
20
|
+
{ error: 'Missing API path. Expected: /api/{module}/{action}' },
|
|
98
21
|
{ status: 400 },
|
|
99
22
|
);
|
|
100
23
|
}
|
|
101
24
|
|
|
102
|
-
const service =
|
|
25
|
+
const service = loadHostService(segments);
|
|
103
26
|
|
|
104
27
|
if (!service) {
|
|
105
28
|
return Response.json(
|
|
106
|
-
{ error: `API
|
|
29
|
+
{ error: `API not found: /api/${segments.join('/')}` },
|
|
107
30
|
{ status: 404 },
|
|
108
31
|
);
|
|
109
32
|
}
|
|
@@ -112,7 +35,7 @@ function createHandler(method: HttpMethod) {
|
|
|
112
35
|
if (typeof handlerFn !== 'function') {
|
|
113
36
|
return Response.json(
|
|
114
37
|
{
|
|
115
|
-
error:
|
|
38
|
+
error: `Method ${method} not allowed: /api/${segments.join('/')}`,
|
|
116
39
|
},
|
|
117
40
|
{
|
|
118
41
|
status: 405,
|
|
@@ -123,10 +46,11 @@ function createHandler(method: HttpMethod) {
|
|
|
123
46
|
|
|
124
47
|
try {
|
|
125
48
|
return await handlerFn.call(service, req);
|
|
126
|
-
} catch (e:
|
|
127
|
-
|
|
49
|
+
} catch (e: unknown) {
|
|
50
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
51
|
+
console.error(`[soma-api] ${method} /api/${segments.join('/')}:`, message);
|
|
128
52
|
return Response.json(
|
|
129
|
-
{ error:
|
|
53
|
+
{ error: message || 'Internal server error' },
|
|
130
54
|
{ status: 500 },
|
|
131
55
|
);
|
|
132
56
|
}
|
package/app/api/page/route.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
// 规则:/ → index.html,其他 /xxx → xxx.html,/xxx/yyy → xxx/yyy.html
|
|
1
|
+
// URL → html/ui/event files: / → index.html, /a/b → a/b.html; */index.html also maps to short path /a
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { join, resolve } from 'path';
|
|
5
5
|
import { NextRequest } from 'next/server';
|
|
6
|
+
import { isSafePageBase, urlPathToCandidates } from '../../../core/compiler/page-base-resolver';
|
|
7
|
+
import { getSomaAssetSources, type SomaAssetSource } from '../../../core/host/source-packages';
|
|
6
8
|
import { ServerFileCache } from '../../../core/infra/cache/ServerFileCache';
|
|
7
9
|
|
|
8
10
|
const cache = ServerFileCache.getInstance();
|
|
@@ -11,34 +13,43 @@ function getHostDir(): string | undefined {
|
|
|
11
13
|
return process.env.SOMA_HOST_DIR || undefined;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
const watchedRoots = new Set<string>();
|
|
15
17
|
|
|
16
18
|
function ensureWatch(root: string) {
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
+
if (watchedRoots.has(root)) return;
|
|
20
|
+
watchedRoots.add(root);
|
|
19
21
|
cache.watchAndInvalidate(root);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
function
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
function resolvePageSource(sources: SomaAssetSource[], urlPath: string): { source: SomaAssetSource; base: string } | null {
|
|
25
|
+
for (const candidate of urlPathToCandidates(urlPath)) {
|
|
26
|
+
if (!isSafePageBase(candidate)) continue;
|
|
27
|
+
for (const source of sources) {
|
|
28
|
+
const htmlPath = join(source.assetRoot, 'html', `${candidate}.html`);
|
|
29
|
+
if (existsSync(htmlPath)) {
|
|
30
|
+
return { source, base: candidate };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
function collectIncludes(
|
|
37
|
+
function collectIncludes(sources: SomaAssetSource[]): Record<string, string> {
|
|
33
38
|
const includes: Record<string, string> = {};
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const ordered = [
|
|
40
|
+
...sources.filter((source) => source.type === 'package'),
|
|
41
|
+
...sources.filter((source) => source.type === 'host'),
|
|
42
|
+
];
|
|
43
|
+
for (const source of ordered) {
|
|
44
|
+
const sharedDir = join(source.assetRoot, 'html', 'shared');
|
|
45
|
+
try {
|
|
46
|
+
const files = cache.readDirFiles(sharedDir, '.html');
|
|
47
|
+
const names = cache.readDirNames(sharedDir, '.html');
|
|
48
|
+
for (let i = 0; i < names.length; i++) {
|
|
49
|
+
includes[`shared/${names[i]}`] = files[i];
|
|
50
|
+
}
|
|
51
|
+
} catch {}
|
|
52
|
+
}
|
|
42
53
|
return includes;
|
|
43
54
|
}
|
|
44
55
|
|
|
@@ -46,47 +57,58 @@ export async function GET(req: NextRequest) {
|
|
|
46
57
|
const hostDir = getHostDir();
|
|
47
58
|
if (!hostDir) {
|
|
48
59
|
return Response.json(
|
|
49
|
-
{ error: 'SOMA_HOST_DIR
|
|
60
|
+
{ error: 'SOMA_HOST_DIR is not set. Run: npx soma dev from your app root.' },
|
|
50
61
|
{ status: 503 },
|
|
51
62
|
);
|
|
52
63
|
}
|
|
53
64
|
|
|
54
|
-
|
|
65
|
+
const sources = getSomaAssetSources(hostDir);
|
|
66
|
+
sources.forEach((source) => ensureWatch(source.assetRoot));
|
|
67
|
+
sources.forEach((source) => {
|
|
68
|
+
if (source.codeRoot !== source.assetRoot) {
|
|
69
|
+
ensureWatch(source.codeRoot);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
55
72
|
|
|
56
73
|
const urlPath = req.nextUrl.searchParams.get('path') || '/';
|
|
57
|
-
const
|
|
74
|
+
const resolvedPage = resolvePageSource(sources, urlPath);
|
|
58
75
|
|
|
59
|
-
if (!
|
|
60
|
-
return Response.json({ error:
|
|
76
|
+
if (!resolvedPage) {
|
|
77
|
+
return Response.json({ error: `Page not found: ${urlPath}` }, { status: 404 });
|
|
61
78
|
}
|
|
62
79
|
|
|
63
|
-
const
|
|
80
|
+
const { source, base } = resolvedPage;
|
|
81
|
+
const htmlPath = join(source.assetRoot, 'html', `${base}.html`);
|
|
64
82
|
const resolvedHtml = resolve(htmlPath);
|
|
65
|
-
const
|
|
66
|
-
if (!resolvedHtml.startsWith(
|
|
83
|
+
const resolvedSourceHtml = resolve(source.assetRoot, 'html');
|
|
84
|
+
if (!resolvedHtml.startsWith(resolvedSourceHtml)) {
|
|
67
85
|
return Response.json({ error: 'Invalid path' }, { status: 400 });
|
|
68
86
|
}
|
|
69
87
|
|
|
70
88
|
try {
|
|
71
89
|
const html = cache.readFile(htmlPath);
|
|
72
90
|
|
|
73
|
-
let ui: string, event: string, localeYaml: string, appConfigYaml: string;
|
|
91
|
+
let ui: string, event: string, style: string, localeYaml: string, appConfigYaml: string;
|
|
74
92
|
try {
|
|
75
|
-
ui = cache.tryReadFile(join(
|
|
76
|
-
event = cache.tryReadFile(join(
|
|
93
|
+
ui = cache.tryReadFile(join(source.assetRoot, 'ui', `${base}_ui.yaml`));
|
|
94
|
+
event = cache.tryReadFile(join(source.assetRoot, 'event', `${base}_event.yaml`));
|
|
95
|
+
style = cache.tryReadFile(join(source.assetRoot, 'ui', `${base}_style.yaml`));
|
|
77
96
|
localeYaml = cache.tryReadFile(join(hostDir, 'config', 'locale.yaml'));
|
|
78
97
|
appConfigYaml = cache.tryReadFile(join(hostDir, 'config', 'app.config.yaml'));
|
|
79
98
|
} catch (e: any) {
|
|
80
99
|
return Response.json({ error: `Asset read error: ${e.message}` }, { status: 500 });
|
|
81
100
|
}
|
|
82
101
|
|
|
83
|
-
const includes = collectIncludes(
|
|
102
|
+
const includes = collectIncludes(sources);
|
|
84
103
|
|
|
85
104
|
return Response.json({
|
|
86
105
|
base,
|
|
106
|
+
sourceType: source.type,
|
|
107
|
+
sourcePackage: source.packageName ?? null,
|
|
87
108
|
html,
|
|
88
109
|
ui,
|
|
89
110
|
event,
|
|
111
|
+
styleYaml: style,
|
|
90
112
|
localeYaml,
|
|
91
113
|
appConfigYaml,
|
|
92
114
|
includes,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { loadPrecompiledManifest, findPrecompiledPage } from '@/core/compiler/precompiled-manifest-loader';
|
|
4
|
+
|
|
5
|
+
/** GET /api/soma-manifest?path=/items — returns precompiled page config */
|
|
6
|
+
export async function GET(request: Request): Promise<Response> {
|
|
7
|
+
const hostDir = process.env.SOMA_HOST_DIR;
|
|
8
|
+
if (!hostDir) {
|
|
9
|
+
return Response.json({ error: 'SOMA_HOST_DIR not set' }, { status: 500 });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const url = new URL(request.url);
|
|
13
|
+
const pagePath = url.searchParams.get('path') ?? '/';
|
|
14
|
+
|
|
15
|
+
const manifest = loadPrecompiledManifest(hostDir);
|
|
16
|
+
if (!manifest) {
|
|
17
|
+
return Response.json({ error: 'manifest not found' }, { status: 404 });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const page = findPrecompiledPage(manifest, pagePath);
|
|
21
|
+
if (!page) {
|
|
22
|
+
return Response.json({ error: `page not in manifest: ${pagePath}` }, { status: 404 });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return Response.json({
|
|
26
|
+
path: page.path,
|
|
27
|
+
uiConfig: page.uiConfig,
|
|
28
|
+
eventConfig: page.eventConfig,
|
|
29
|
+
triggers: page.triggers,
|
|
30
|
+
timers: page.timers ?? [],
|
|
31
|
+
styleConfig: page.styleConfig,
|
|
32
|
+
locale: manifest.locale,
|
|
33
|
+
appConfig: manifest.appConfig,
|
|
34
|
+
manifestVersion: '1.0.0',
|
|
35
|
+
generatedAt: fs.existsSync(path.join(hostDir, '.soma', 'manifest.json'))
|
|
36
|
+
? fs.statSync(path.join(hostDir, '.soma', 'manifest.json')).mtime.toISOString()
|
|
37
|
+
: null,
|
|
38
|
+
});
|
|
39
|
+
}
|