soma-core 2.1.5 → 2.2.0
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/bin/soma.cjs +1 -1
- package/bin/soma.ts +64 -15
- package/core/build/compiler/soma-precompile.js +11 -1
- package/core/client/base/SomaHttpClient.ts +85 -12
- package/core/client/data/data-object-resolver.ts +12 -1
- package/core/client/engine/event-engine.ts +3 -3
- package/core/client/engine/soma-bootstrap.ts +30 -30
- package/core/client/host-bridge/load-host-domain-class.ts +74 -20
- package/core/client/host-bridge/resolve-host-bootstrap.ts +125 -23
- package/core/client/infra/http/IHttpClient.ts +3 -1
- package/core/client/infra/http/SomaHttpService.ts +15 -6
- package/core/client/parser/data-config-parser.ts +6 -1
- package/core/server/api/dispatch-service-api.ts +212 -0
- package/core/server/api/load-host-service.ts +230 -56
- package/core/server/api/service-path.ts +78 -14
- package/core/server/engines/style/candidate-guard.ts +57 -0
- package/core/server/engines/style/index.ts +1 -1
- package/core/server/engines/style/tailwind-adapter.ts +83 -16
- package/core/server/host/source-packages.cjs +96 -30
- package/core/server/host/source-packages.ts +12 -5
- package/core/server/index.ts +39 -17
- package/core/server/infra/cache/ServerFileCache.ts +138 -25
- package/core/server/node.ts +32 -8
- package/core/shared/registry-generated/error-codes.ts +5 -0
- package/core/shared/registry-generated/limits.ts +5 -0
- package/core/shared/types/data-config.types.ts +2 -0
- package/dist/browser/soma-runtime.js +197 -49
- package/dist/cli/soma.js +68 -14
- package/dist/core/index.cjs +284 -64
- package/dist/host-native/aot-builder.cjs +850 -0
- package/dist/host-native/native-server.cjs +15338 -0
- package/dist/lsp/component-tree.cjs +11 -1
- package/dist/types/client/base/SomaHttpClient.d.ts +1 -8
- package/dist/types/client/data/data-object-resolver.d.ts +1 -0
- package/dist/types/client/engine/event-engine.d.ts +2 -2
- package/dist/types/client/engine/soma-bootstrap.d.ts +3 -2
- package/dist/types/client/host-bridge/load-host-domain-class.d.ts +1 -0
- package/dist/types/client/host-bridge/resolve-host-bootstrap.d.ts +20 -0
- package/dist/types/client/infra/http/IHttpClient.d.ts +2 -0
- package/dist/types/server/api/dispatch-service-api.d.ts +18 -0
- package/dist/types/server/api/load-host-service.d.ts +7 -2
- package/dist/types/server/api/service-path.d.ts +21 -1
- package/dist/types/server/engines/style/candidate-guard.d.ts +10 -0
- package/dist/types/server/engines/style/index.d.ts +1 -1
- package/dist/types/server/engines/style/tailwind-adapter.d.ts +12 -0
- package/dist/types/server/host/source-packages.d.cts +13 -1
- package/dist/types/server/host/source-packages.d.ts +7 -4
- package/dist/types/server/index.d.ts +18 -17
- package/dist/types/server/infra/cache/ServerFileCache.d.ts +28 -5
- package/dist/types/server/node.d.ts +10 -7
- package/dist/types/shared/registry-generated/error-codes.d.ts +4 -0
- package/dist/types/shared/registry-generated/limits.d.ts +4 -0
- package/dist/types/shared/types/data-config.types.d.ts +2 -0
- package/host-native/bin/host-native.cjs +204 -0
- package/host-native/client/browser-entry.ts +499 -0
- package/{host-next/app → host-native/client}/page-access.ts +12 -0
- package/host-native/client/router-bridge.ts +120 -0
- package/host-native/src/aot-builder.ts +486 -0
- package/host-native/src/csp-headers.ts +75 -0
- package/host-native/src/host-prepare.ts +123 -0
- package/{host-next/app/soma/manifest/route.ts → host-native/src/manifest-http.ts} +10 -10
- package/host-native/src/native-server.ts +691 -0
- package/host-native/src/page-http.ts +223 -0
- package/host-native/src/public-packages.cjs +167 -0
- package/{host-next/app/api/soma-registry/[...path]/route.ts → host-native/src/registry-handler.ts} +17 -19
- package/{host-next → host-native}/src/shell-routes.cjs +23 -13
- package/host-native/src/static-file.ts +172 -0
- package/host-native/src/workspace.ts +185 -0
- package/{host-next/app → host-native/styles}/globals.css +2 -2
- package/package.json +13 -32
- package/tsconfig.json +1 -1
- package/host-next/app/SomaPageClient.tsx +0 -359
- package/host-next/app/[...path]/page.tsx +0 -22
- package/host-next/app/api/[...path]/route.ts +0 -98
- package/host-next/app/components/SomaHostPage.tsx +0 -128
- package/host-next/app/components/SomaHydrationShell.tsx +0 -20
- package/host-next/app/components/SomaPageClientBoundary.tsx +0 -13
- package/host-next/app/components/SomaPageForbidden.tsx +0 -19
- package/host-next/app/favicon.ico/route.ts +0 -13
- package/host-next/app/layout.tsx +0 -27
- package/host-next/app/page.tsx +0 -9
- package/host-next/app/router-bridge.ts +0 -42
- package/host-next/app/soma/[...path]/route.ts +0 -9
- package/host-next/app/soma/_shared/host-prepare.ts +0 -33
- package/host-next/app/soma/_shared/page-http.ts +0 -86
- package/host-next/app/soma/page/route.ts +0 -36
- package/host-next/app/soma/route.ts +0 -9
- package/host-next/app/soma-runtime/[...file]/route.ts +0 -21
- package/host-next/app/soma-runtime/_shared/static-file.ts +0 -89
- package/host-next/bin/host-next.cjs +0 -60
- package/host-next/instrumentation.ts +0 -18
- package/host-next/next-env.d.ts +0 -7
- package/host-next/next.config.js +0 -410
- package/host-next/proxy.ts +0 -43
- package/host-next/src/workspace.ts +0 -543
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { assertReservedRoutesShape, loadHostAssembly, registerShellRoutes as registerCoreShellRoutes } from 'soma-core/server/host-assembly';
|
|
4
|
+
import { precompileAll, precompilePage } from '../../core/build/compiler/full-manifest-builder';
|
|
5
|
+
import { addressOfPageBase } from '../../core/build/compiler/page-base-resolver';
|
|
6
|
+
import { loadPageMarkupConfig } from '../../core/server/host/page-markup-config';
|
|
7
|
+
import { resolveHostTreeCompileContext } from '../../core/server/host/resolve-host-tree-context';
|
|
8
|
+
import { runPrewarm, computePrewarmInputsDigest } from '../../core/server/runtime-space/prewarm';
|
|
9
|
+
import { resolveAppConfigPath, resolveHostAppConfigPath } from '../../core/server/host/host-config-paths.cjs';
|
|
10
|
+
import { getSomaAssetSources, collectPageEntries, collectIncludes } from '../../core/server/host/source-packages';
|
|
11
|
+
|
|
12
|
+
export const SOMA_SHELL_ROUTES_ENV = 'SOMA_SHELL_ROUTES';
|
|
13
|
+
|
|
14
|
+
let lastRaw: string | undefined;
|
|
15
|
+
let lastParsed: readonly string[] = [];
|
|
16
|
+
|
|
17
|
+
export function readShellRoutesFromEnv(env: Readonly<Record<string, string | undefined>> = process.env): readonly string[] {
|
|
18
|
+
const raw = env[SOMA_SHELL_ROUTES_ENV];
|
|
19
|
+
if (!raw) return [];
|
|
20
|
+
if (raw === lastRaw) return lastParsed;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const parsed: unknown = JSON.parse(raw);
|
|
24
|
+
assertReservedRoutesShape(parsed);
|
|
25
|
+
const result = Array.isArray(parsed) ? (parsed as string[]) : [];
|
|
26
|
+
lastRaw = raw;
|
|
27
|
+
lastParsed = result;
|
|
28
|
+
return result;
|
|
29
|
+
} catch {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 登记壳路由(转调 core 登记口);环境里没有时什么也不做。返回登记后 core 已知的壳路由 */
|
|
35
|
+
export function registerShellRoutes(shellRoutes: readonly string[] = readShellRoutesFromEnv()): readonly string[] {
|
|
36
|
+
return shellRoutes.length === 0 ? [] : registerCoreShellRoutes(shellRoutes);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function prepareHostAssembly(hostDir: string | undefined) {
|
|
40
|
+
if (!hostDir) return null;
|
|
41
|
+
const assembly = await loadHostAssembly(hostDir);
|
|
42
|
+
registerShellRoutes();
|
|
43
|
+
return assembly;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function readFileOrEmpty(filePath: string): string {
|
|
47
|
+
return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 构建期 / 开发期全量页面预热:统一处理原生四件套静态页与方言装配 prewarm() 钩子。
|
|
52
|
+
*/
|
|
53
|
+
export async function prewarmHostPages(hostDir: string, env: NodeJS.ProcessEnv = process.env) {
|
|
54
|
+
const resolvedHostDir = path.resolve(hostDir);
|
|
55
|
+
const host = await prepareHostAssembly(resolvedHostDir);
|
|
56
|
+
const sources = getSomaAssetSources(resolvedHostDir, env);
|
|
57
|
+
const pageEntries = collectPageEntries(sources);
|
|
58
|
+
const includes = collectIncludes(sources);
|
|
59
|
+
const htmlFiles = pageEntries.map((entry: { htmlFile: string }) => entry.htmlFile);
|
|
60
|
+
const hostConfigRoot = sources.find((source: { type: string }) => source.type === 'host')?.configRoot ?? resolvedHostDir;
|
|
61
|
+
const hostAppConfigPath = resolveHostAppConfigPath(resolvedHostDir);
|
|
62
|
+
const localeYaml = readFileOrEmpty(path.join(hostConfigRoot, 'locale.yaml'));
|
|
63
|
+
const appConfigYaml = hostAppConfigPath ? readFileOrEmpty(hostAppConfigPath) : '';
|
|
64
|
+
|
|
65
|
+
const shell = precompileAll({ htmlFiles, localeYaml, appConfigYaml, pages: [] });
|
|
66
|
+
const hasIncludes = Object.keys(includes).length > 0;
|
|
67
|
+
|
|
68
|
+
const pages = pageEntries
|
|
69
|
+
.filter(({ htmlFile }: { htmlFile: string }) => !htmlFile.startsWith('shared/') && !htmlFile.startsWith('system/'))
|
|
70
|
+
.map(({ source, htmlFile }: { source: { configRoot: string; assetRoot: string }; htmlFile: string }) => {
|
|
71
|
+
const base = htmlFile.replace(/\.html$/, '');
|
|
72
|
+
const sourceAppConfigPath = resolveAppConfigPath(source.configRoot);
|
|
73
|
+
const uiDir = path.join(source.assetRoot, 'ui');
|
|
74
|
+
const metadata = loadPageMarkupConfig(source.configRoot, base);
|
|
75
|
+
const html = fs.readFileSync(path.join(source.assetRoot, 'html', htmlFile), 'utf8');
|
|
76
|
+
const uiYaml = readFileOrEmpty(path.join(uiDir, `${base}_ui.yaml`));
|
|
77
|
+
const eventYaml = readFileOrEmpty(path.join(source.assetRoot, 'event', `${base}_event.yaml`));
|
|
78
|
+
const styleYaml = readFileOrEmpty(path.join(source.assetRoot, 'style', `${base}_style.yaml`));
|
|
79
|
+
const compileInput = {
|
|
80
|
+
path: `/${base}`,
|
|
81
|
+
html,
|
|
82
|
+
uiYaml,
|
|
83
|
+
...(eventYaml.trim() ? { eventYaml } : {}),
|
|
84
|
+
...(styleYaml.trim() ? { styleYaml } : {}),
|
|
85
|
+
...metadata,
|
|
86
|
+
treeContext: metadata.markup === 'component-tree'
|
|
87
|
+
? resolveHostTreeCompileContext(resolvedHostDir, { pageBase: base })
|
|
88
|
+
: undefined,
|
|
89
|
+
...(hasIncludes ? { includes } : {}),
|
|
90
|
+
appConfigYaml: sourceAppConfigPath
|
|
91
|
+
? readFileOrEmpty(sourceAppConfigPath)
|
|
92
|
+
: (hostAppConfigPath ? readFileOrEmpty(hostAppConfigPath) : ''),
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
address: addressOfPageBase(base),
|
|
96
|
+
page: {
|
|
97
|
+
format: 1 as const,
|
|
98
|
+
html,
|
|
99
|
+
uiYaml,
|
|
100
|
+
...(eventYaml.trim() ? { eventYaml } : {}),
|
|
101
|
+
...(styleYaml.trim() ? { styleYaml } : {}),
|
|
102
|
+
...(localeYaml ? { locale: localeYaml } : {}),
|
|
103
|
+
...(hasIncludes ? { includes } : {}),
|
|
104
|
+
},
|
|
105
|
+
inputsDigest: computePrewarmInputsDigest({
|
|
106
|
+
path: compileInput.path,
|
|
107
|
+
metadata,
|
|
108
|
+
appConfigYaml: compileInput.appConfigYaml,
|
|
109
|
+
hostAppConfigYaml: appConfigYaml,
|
|
110
|
+
treeContext: compileInput.treeContext ?? null,
|
|
111
|
+
compilerIdentity: null,
|
|
112
|
+
}),
|
|
113
|
+
compile: () => precompilePage(compileInput, { hostAppConfig: shell.appConfig }),
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return runPrewarm({
|
|
118
|
+
hostDir: resolvedHostDir,
|
|
119
|
+
pages,
|
|
120
|
+
meta: { routes: shell.routes, locale: shell.locale, appConfig: shell.appConfig },
|
|
121
|
+
...(host && typeof host.prewarm === 'function' ? { hook: () => host.prewarm!() } : {}),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { loadPrecompiledManifest, findPrecompiledPage } from '
|
|
2
|
-
import { listBindings } from '
|
|
3
|
-
import { resolveSomaRuntimeLayout } from '
|
|
4
|
-
import { SomaRuntimeStore } from '
|
|
5
|
-
import { normalizeAddress } from '
|
|
6
|
-
import type { SomaRuntimeBinding } from '
|
|
7
|
-
|
|
8
|
-
export const runtime = 'nodejs';
|
|
9
|
-
export const dynamic = 'force-dynamic';
|
|
1
|
+
import { loadPrecompiledManifest, findPrecompiledPage } from '../../core/server/page-assets';
|
|
2
|
+
import { listBindings } from '../../core/server/runtime-space';
|
|
3
|
+
import { resolveSomaRuntimeLayout } from '../../core/server/runtime-space/root';
|
|
4
|
+
import { SomaRuntimeStore } from '../../core/server/runtime-space/store';
|
|
5
|
+
import { normalizeAddress } from '../../core/shared/runtime-address';
|
|
6
|
+
import type { SomaRuntimeBinding } from '../../core/server/runtime-space/types';
|
|
10
7
|
|
|
11
8
|
/** 绑定的公开视图:只有地址、类别、来源类别、缓存、代次与摘要(不带 caller / source / 到期等产生方信息) */
|
|
12
9
|
function bindingView(binding: SomaRuntimeBinding) {
|
|
@@ -40,7 +37,7 @@ function findExactBinding(bindings: readonly SomaRuntimeBinding[], address: stri
|
|
|
40
37
|
* 客户端走 /soma/page)。命中后产物来自预热(`<root>/prewarm/`)。
|
|
41
38
|
* GET /soma/manifest?index=1 - 绑定清单 + 预热索引(地址 → 摘要)。
|
|
42
39
|
*/
|
|
43
|
-
export async function
|
|
40
|
+
export async function handleManifestGet(request: Request): Promise<Response> {
|
|
44
41
|
const hostDir = process.env.SOMA_HOST_DIR;
|
|
45
42
|
if (!hostDir) {
|
|
46
43
|
return Response.json({ error: 'SOMA_HOST_DIR not set' }, { status: 500 });
|
|
@@ -96,3 +93,6 @@ export async function GET(request: Request): Promise<Response> {
|
|
|
96
93
|
manifestVersion: '1.0.0',
|
|
97
94
|
});
|
|
98
95
|
}
|
|
96
|
+
|
|
97
|
+
// 别名导出,兼容原 route.ts 导出风格
|
|
98
|
+
export { handleManifestGet as GET };
|