soma-core 2.0.1 → 2.1.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/eject.cjs +5 -5
- package/bin/soma-runtime.cjs +5 -123
- package/bin/soma.cjs +2 -2
- package/bin/soma.ts +8 -20
- package/core/build/compiler/page-declaration-compiler.ts +5 -6
- package/core/build/lsp/soma-declaration.cjs +0 -6
- package/core/client/container/SomaContainerAdapter.ts +1 -1
- package/core/client/data/region-scope-views.ts +1 -1
- package/core/client/engine/event-engine.ts +1 -6
- package/core/client/engine/soma-bootstrap.ts +5 -13
- package/core/client/host-bridge/soma-bootstrap-from-app.ts +2 -2
- package/core/client/infra/i18n/II18n.ts +5 -6
- package/core/client/infra/i18n/locale-catalog.ts +8 -5
- package/core/client/infra/identity/identity-port.ts +1 -1
- package/core/client/keyboard/index.ts +0 -1
- package/core/client/keyboard/wiring.ts +0 -3
- package/core/client/parser/ui-config-parser.ts +6 -9
- package/core/client/registry/declaration-renderer.ts +1 -1
- package/core/client/runtime/SomaRuntimeServices.ts +1 -1
- package/core/inspect/check-runtime.ts +2 -3
- package/core/server/host/content-security-policy.ts +2 -11
- package/core/server/host/host-assembly-entry.ts +10 -2
- package/core/server/host/host-assembly.ts +28 -10
- package/core/server/host/host-caller.ts +52 -0
- package/core/server/host/host-response-headers.ts +49 -0
- package/core/server/host/locale-yaml.ts +7 -5
- package/core/server/host/published-page-assets.ts +1 -1
- package/core/server/host/resolve-host-request-hook.ts +2 -11
- package/core/server/host/resolve-host-tree-context.ts +7 -41
- package/core/server/host/server-page-assets.ts +0 -22
- package/core/server/host/source-packages.cjs +3 -4
- package/core/server/host/virtual-pages.ts +12 -70
- package/core/server/index.ts +1 -3
- package/core/server/node.ts +0 -1
- package/core/server/page-assets.ts +2 -20
- package/core/server/page-declaration.ts +1 -1
- package/core/server/registry/api-registry-store.ts +5 -25
- package/core/server/registry/asset-store.ts +5 -23
- package/core/server/registry/page-registry-repository.ts +9 -13
- package/core/server/registry/page-registry-store.ts +44 -82
- package/core/server/registry/publish-asset-pin.ts +3 -4
- package/core/server/registry/registry-subjects.ts +6 -6
- package/core/server/registry/rollback-plan.ts +5 -8
- package/core/server/registry/source/version-store.ts +8 -30
- package/core/server/registry/standard-product.ts +1 -1
- package/core/server/runtime-space/bindings.ts +1 -4
- package/core/server/runtime-space/gc.ts +2 -3
- package/core/server/runtime-space/inject.ts +4 -5
- package/core/server/runtime-space/resolve.ts +13 -27
- package/core/server/runtime-space/root.cjs +9 -100
- package/core/server/runtime-space/root.ts +3 -23
- package/core/server/runtime-space/types.ts +0 -11
- package/core/shared/artifact-compatibility.ts +6 -16
- package/core/shared/component-tree-artifact.ts +4 -8
- package/core/shared/core-diagnostic-codes.ts +1 -3
- package/core/shared/pipeline-error-codes-view.ts +1 -2
- package/core/shared/published-page-route.ts +1 -6
- package/core/shared/registry-generated/diagnostic-registry-index.ts +0 -2
- package/core/shared/registry-generated/diagnostic-registry.ts +0 -14
- package/core/shared/source-file-suffix.ts +8 -0
- package/core/shared/types/component-tree-artifact.types.ts +2 -15
- package/core/shared/types/host-assembly.types.ts +31 -2
- package/core/shared/types/locale.types.ts +3 -3
- package/core/shared/types/region-scope.types.ts +1 -1
- package/core/shared/types/ui-config.types.ts +2 -7
- package/core/shared/types/write.types.ts +1 -1
- package/dist/browser/soma-runtime.js +20 -36
- package/dist/cli/soma.js +8 -21
- package/dist/core/index.cjs +20 -38
- package/dist/lsp/component-tree.cjs +7 -14
- package/dist/types/client/container/SomaContainerAdapter.d.ts +1 -1
- package/dist/types/client/engine/event-engine.d.ts +0 -2
- package/dist/types/client/engine/soma-bootstrap.d.ts +2 -3
- package/dist/types/client/host-bridge/soma-bootstrap-from-app.d.ts +2 -2
- package/dist/types/client/infra/i18n/II18n.d.ts +5 -6
- package/dist/types/client/infra/i18n/locale-catalog.d.ts +3 -3
- package/dist/types/client/infra/identity/identity-port.d.ts +1 -1
- package/dist/types/client/keyboard/index.d.ts +1 -1
- package/dist/types/client/keyboard/wiring.d.ts +0 -2
- package/dist/types/client/registry/declaration-renderer.d.ts +1 -1
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +1 -1
- package/dist/types/server/host/content-security-policy.d.ts +0 -5
- package/dist/types/server/host/host-assembly-entry.d.ts +5 -2
- package/dist/types/server/host/host-assembly.d.ts +9 -4
- package/dist/types/server/host/host-caller.d.ts +10 -0
- package/dist/types/server/host/host-response-headers.d.ts +16 -0
- package/dist/types/server/host/published-page-assets.d.ts +1 -1
- package/dist/types/server/host/resolve-host-request-hook.d.ts +0 -4
- package/dist/types/server/host/resolve-host-tree-context.d.ts +1 -1
- package/dist/types/server/host/server-page-assets.d.ts +0 -2
- package/dist/types/server/host/virtual-pages.d.ts +4 -14
- package/dist/types/server/index.d.ts +1 -2
- package/dist/types/server/node.d.ts +1 -1
- package/dist/types/server/page-assets.d.ts +1 -4
- package/dist/types/server/page-declaration.d.ts +1 -1
- package/dist/types/server/registry/api-registry-store.d.ts +1 -6
- package/dist/types/server/registry/asset-store.d.ts +2 -11
- package/dist/types/server/registry/page-registry-repository.d.ts +4 -4
- package/dist/types/server/registry/page-registry-store.d.ts +22 -30
- package/dist/types/server/registry/registry-subjects.d.ts +2 -2
- package/dist/types/server/registry/rollback-plan.d.ts +0 -3
- package/dist/types/server/registry/source/version-store.d.ts +1 -9
- package/dist/types/server/registry/standard-product.d.ts +1 -1
- package/dist/types/server/runtime-space/resolve.d.ts +0 -3
- package/dist/types/server/runtime-space/root.d.cts +6 -29
- package/dist/types/server/runtime-space/root.d.ts +2 -7
- package/dist/types/server/runtime-space/types.d.ts +0 -9
- package/dist/types/shared/artifact-compatibility.d.ts +1 -3
- package/dist/types/shared/core-diagnostic-codes.d.ts +1 -1
- package/dist/types/shared/published-page-route.d.ts +1 -3
- package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +0 -12
- package/dist/types/shared/types/component-tree-artifact.types.d.ts +2 -15
- package/dist/types/shared/types/host-assembly.types.d.ts +27 -1
- package/dist/types/shared/types/locale.types.d.ts +1 -1
- package/dist/types/shared/types/region-scope.types.d.ts +1 -1
- package/dist/types/shared/types/ui-config.types.d.ts +2 -7
- package/dist/types/shared/types/write.types.d.ts +1 -1
- package/global.d.ts +0 -9
- package/host-next/app/SomaPageClient.tsx +359 -0
- package/host-next/app/[...path]/page.tsx +22 -0
- package/host-next/app/api/[...path]/route.ts +98 -0
- package/host-next/app/api/soma-registry/[...path]/route.ts +79 -0
- package/host-next/app/components/SomaHostPage.tsx +128 -0
- package/host-next/app/components/SomaHydrationShell.tsx +20 -0
- package/host-next/app/components/SomaPageClientBoundary.tsx +13 -0
- package/host-next/app/components/SomaPageForbidden.tsx +19 -0
- package/host-next/app/favicon.ico/route.ts +13 -0
- package/host-next/app/globals.css +177 -0
- package/host-next/app/layout.tsx +27 -0
- package/host-next/app/page-access.ts +47 -0
- package/host-next/app/page.tsx +9 -0
- package/host-next/app/router-bridge.ts +42 -0
- package/host-next/app/soma/[...path]/route.ts +9 -0
- package/host-next/app/soma/_shared/host-prepare.ts +33 -0
- package/host-next/app/soma/_shared/page-http.ts +86 -0
- package/host-next/app/soma/manifest/route.ts +98 -0
- package/host-next/app/soma/page/route.ts +36 -0
- package/host-next/app/soma/route.ts +9 -0
- package/host-next/app/soma-runtime/[...file]/route.ts +21 -0
- package/host-next/app/soma-runtime/_shared/static-file.ts +89 -0
- package/host-next/bin/host-next.cjs +59 -0
- package/host-next/instrumentation.ts +13 -0
- package/host-next/next-env.d.ts +7 -0
- package/host-next/next.config.js +382 -0
- package/host-next/proxy.ts +43 -0
- package/host-next/src/shell-routes.cjs +51 -0
- package/host-next/src/workspace.ts +543 -0
- package/package.json +29 -4
- package/tsconfig.json +2 -1
- package/core/server/host/page-response-mode.cjs +0 -96
- package/core/server/host/page-response-request.ts +0 -33
- package/core/server/host/request-origin.ts +0 -18
- package/core/server/host/soma-request-hook-host.stub.ts +0 -4
- package/core/server/runtime-space/migrate-sources.ts +0 -124
- package/core/shared/source-compat.ts +0 -9
- package/dist/types/server/host/page-response-request.d.ts +0 -8
- package/dist/types/server/host/request-origin.d.ts +0 -1
- package/dist/types/server/host/soma-request-hook-host.stub.d.ts +0 -2
- package/dist/types/server/runtime-space/migrate-sources.d.ts +0 -19
- /package/dist/types/shared/{source-compat.d.ts → source-file-suffix.d.ts} +0 -0
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// - 审计记的是**认证出来的主体名**;`x-soma-operator` 降级为"人名备注",
|
|
11
11
|
// 只有在主体已认证时才带上,且始终与主体名一起落库(谁的凭据 + 他声称是谁)。
|
|
12
12
|
//
|
|
13
|
-
//
|
|
13
|
+
// 单凭据:`SOMA_REGISTRY_TOKEN` 有效,等价于一条名为 `default`、两种作用域全给的凭据。
|
|
14
14
|
// 演示门(非生产 + SOMA_REGISTRY_OPEN=1)等价于一个名为 `demo` 的全权主体——
|
|
15
15
|
// 这样下游代码只认主体,不必到处再判一次演示态。
|
|
16
16
|
|
|
@@ -26,12 +26,12 @@ export interface RegistrySubject {
|
|
|
26
26
|
/** 可选组织归属;配置格式支持 名字@组织:令牌:作用域。 */
|
|
27
27
|
orgId?: string;
|
|
28
28
|
/** 凭据来源,只用于日志与排障 */
|
|
29
|
-
source: 'token' | '
|
|
29
|
+
source: 'token' | 'single-token' | 'open-door';
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/** 多凭据配置:`名字:令牌:作用域|作用域, 名字:令牌:作用域` */
|
|
33
33
|
export const REGISTRY_TOKENS_ENV = 'SOMA_REGISTRY_TOKENS';
|
|
34
|
-
/** 单凭据配置
|
|
34
|
+
/** 单凭据配置 */
|
|
35
35
|
export const REGISTRY_TOKEN_ENV = 'SOMA_REGISTRY_TOKEN';
|
|
36
36
|
/** 演示门 */
|
|
37
37
|
export const REGISTRY_OPEN_ENV = 'SOMA_REGISTRY_OPEN';
|
|
@@ -142,9 +142,9 @@ export function resolveRegistrySubject(req: SubjectRequestLike): RegistrySubject
|
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
matched ??= { name: 'default', scopes: ALL_SCOPES, source: '
|
|
145
|
+
const single = process.env[REGISTRY_TOKEN_ENV] ?? '';
|
|
146
|
+
if (single !== '' && timingSafeStringEqual(presented, single)) {
|
|
147
|
+
matched ??= { name: 'default', scopes: ALL_SCOPES, source: 'single-token' };
|
|
148
148
|
}
|
|
149
149
|
if (matched) {
|
|
150
150
|
return matched;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// 通用回滚规则(06b 10.10 / D62;06e §2.11 `planRollback`):默认复用存档产物、零编译,仅在存档与当前运行时不兼容时按保存的声明重编。
|
|
2
2
|
//
|
|
3
|
-
// 是什么:回滚 = 把旧版本复制成新的 published
|
|
3
|
+
// 是什么:回滚 = 把旧版本复制成新的 published 版本(只增不删)。复制什么、要不要编译,由本文件裁决,两个分支:
|
|
4
4
|
// · `reuse` 存档产物与当前 core 运行时 + 当前组件供货兼容(`checkArtifactRuntimeCompatibility`,2.16a 两级判据):
|
|
5
5
|
// 新版本的存档产物与目标版本**逐字节相等**,端口调用 0 次;编译身份与当前不等只带漂移提示(第一级,不重编);
|
|
6
6
|
// · `recompile` 不兼容(① 信封格式 / 能力,② 本页引用组件供货摘要改变;缺信封头视 `envelopeRequired`):按目标版本保存的
|
|
7
|
-
// 声明 + 源附件版本钉 + 主题名经端口 `purpose: 'publish'`
|
|
8
|
-
// · `legacy-copy` 无方言源的 legacy 冻结静态快照:零运行期 JS、不经挂载守卫,不适用判据,原样复制,端口调用 0 次。
|
|
7
|
+
// 声明 + 源附件版本钉 + 主题名经端口 `purpose: 'publish'` 严格重编;编不过则回滚拒绝、版本数不变、原样抛编译诊断。
|
|
9
8
|
//
|
|
10
9
|
// 为什么判据与挂载守卫共用一个纯函数:服务端判「兼容」而浏览器守卫抛 `CT-ARTIFACT-*`,会让回滚出一个到不了线上的版本(KI-27)。
|
|
11
10
|
//
|
|
@@ -32,8 +31,7 @@ export type SomaRollbackPlan =
|
|
|
32
31
|
readonly source: PageVersionRecord;
|
|
33
32
|
readonly reason: SomaArtifactIncompatibility;
|
|
34
33
|
readonly supplyDiff: SomaAssetReconciliation;
|
|
35
|
-
}
|
|
36
|
-
| { readonly kind: 'legacy-copy'; readonly source: PageVersionRecord };
|
|
34
|
+
};
|
|
37
35
|
|
|
38
36
|
export interface PlanRollbackOptions {
|
|
39
37
|
/** 缺信封头是否判不兼容(G6 守卫收紧后 true);缺省 false = 存量守卫口径 */
|
|
@@ -58,7 +56,6 @@ export function planRollback(
|
|
|
58
56
|
currentIdentity: string | null,
|
|
59
57
|
options: PlanRollbackOptions = {},
|
|
60
58
|
): SomaRollbackPlan {
|
|
61
|
-
if (target.origin?.format === 'legacy') return { kind: 'legacy-copy', source: target };
|
|
62
59
|
// 存档产物缺席(发布期预编译没成)等同没有可复用的产物:只能按声明重编
|
|
63
60
|
if (target.compiled === undefined || target.compiled === null) {
|
|
64
61
|
return {
|
|
@@ -167,7 +164,7 @@ export function executeRollbackPlan(
|
|
|
167
164
|
});
|
|
168
165
|
return { record, notices: [recompileNotice(target.name, plan.reason, plan.supplyDiff)] };
|
|
169
166
|
}
|
|
170
|
-
// reuse
|
|
167
|
+
// reuse:存档产物逐字节复制,不调端口
|
|
171
168
|
const record = ctx.append({
|
|
172
169
|
...base,
|
|
173
170
|
declaration: target.declaration,
|
|
@@ -179,6 +176,6 @@ export function executeRollbackPlan(
|
|
|
179
176
|
...(target.origin !== undefined ? { origin: target.origin } : {}),
|
|
180
177
|
},
|
|
181
178
|
});
|
|
182
|
-
const notices = plan.
|
|
179
|
+
const notices = plan.drift !== null ? [identityDriftNotice(target.name, plan.drift)] : [];
|
|
183
180
|
return { record, notices };
|
|
184
181
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// 源附件资产的版本存储(AD-8:进页面 Registry 的同一套存储机制;R-3 中性命名,方言源文本不透明)。
|
|
2
|
-
// 落盘文件后缀 `.source.json`、runtime 目录键 `sources`(AD-46 ①,C6-e
|
|
3
|
-
// 按「不存在」处理;已有数据由 `soma runtime migrate` 搬到新名)。
|
|
2
|
+
// 落盘文件后缀 `.source.json`、runtime 目录键 `sources`(AD-46 ①,C6-e 中性命名)。
|
|
4
3
|
//
|
|
5
4
|
// 一个资产 = 一个聚合对象 `{ schemaVersion: 1, name, versions: [...] }`,全部版本在同一个对象里提交,
|
|
6
5
|
// 「检查 → 写入」之间没有跨键竞态。两个后端与页面 Registry 的两种后端一一对应:
|
|
@@ -18,7 +17,7 @@ import path from 'node:path';
|
|
|
18
17
|
import type { ConditionalObjectStore, WriteCondition } from '../conditional-object-store';
|
|
19
18
|
import { PageRegistryError, PageRegistryErrorCodes } from '../page-registry-store';
|
|
20
19
|
import { withRegistryLock, writeFileAtomic } from '../registry-file-lock';
|
|
21
|
-
import { currentRuntimeLayout
|
|
20
|
+
import { currentRuntimeLayout } from '../../runtime-space/root';
|
|
22
21
|
import { assertSourceName, sourceNameOfStorageKey, sourceStorageKey } from './source-name';
|
|
23
22
|
import { assertSourceAppendOnly } from './ledger';
|
|
24
23
|
import type {
|
|
@@ -28,7 +27,7 @@ import type {
|
|
|
28
27
|
SomaSourceVersionStore,
|
|
29
28
|
} from './types';
|
|
30
29
|
import { SOMA_PIPELINE_LIMITS } from '../../../shared/registry-generated/limits';
|
|
31
|
-
import { SOMA_SOURCE_FILE_SUFFIX } from '../../../shared/source-
|
|
30
|
+
import { SOMA_SOURCE_FILE_SUFFIX } from '../../../shared/source-file-suffix';
|
|
32
31
|
|
|
33
32
|
const AGGREGATE_SCHEMA_VERSION = 1;
|
|
34
33
|
const MAX_CAS_ATTEMPTS = SOMA_PIPELINE_LIMITS.retry.casAttempts;
|
|
@@ -157,10 +156,8 @@ function suffixOf(file: string): string | null {
|
|
|
157
156
|
|
|
158
157
|
/** @req F-003.3 R-028 */
|
|
159
158
|
export interface SomaFileSourceVersionStoreOptions {
|
|
160
|
-
/** 持久化目录(每资产一个 `<键>.source.json`);缺省由 runtime
|
|
159
|
+
/** 持久化目录(每资产一个 `<键>.source.json`);缺省由 runtime 根解析(`<root>/registry/sources`,见 `runtime-space/root.cjs`) */
|
|
161
160
|
readonly baseDir?: string;
|
|
162
|
-
/** 旧位置(只读回退):新目录没有该资产文件而旧目录有时读旧文件并报一次 CORE-RUNTIME-LEGACY-DIR;写入永远落新目录 */
|
|
163
|
-
readonly legacyDir?: string;
|
|
164
161
|
}
|
|
165
162
|
|
|
166
163
|
/**
|
|
@@ -169,15 +166,11 @@ export interface SomaFileSourceVersionStoreOptions {
|
|
|
169
166
|
*/
|
|
170
167
|
export class SomaFileSourceVersionStore implements SomaSourceVersionStore {
|
|
171
168
|
private readonly baseDir: string;
|
|
172
|
-
private readonly legacyDir: string | null;
|
|
173
169
|
/** 资产名 → { 全部版本, 落盘指纹 };指纹变了就重读 */
|
|
174
170
|
private readonly cache = new Map<string, { readonly versions: readonly SomaSourceVersion[]; readonly stamp: string }>();
|
|
175
171
|
|
|
176
172
|
constructor(options: SomaFileSourceVersionStoreOptions = {}) {
|
|
177
|
-
|
|
178
|
-
this.baseDir = path.resolve(options.baseDir ?? layout!.dirs.sources);
|
|
179
|
-
const legacy = options.legacyDir ?? (layout === null ? undefined : firstLegacyDirWithData(layout, 'sources') ?? undefined);
|
|
180
|
-
this.legacyDir = legacy ? path.resolve(legacy) : null;
|
|
173
|
+
this.baseDir = path.resolve(options.baseDir ?? currentRuntimeLayout().dirs.sources);
|
|
181
174
|
}
|
|
182
175
|
|
|
183
176
|
readSync(name: string): readonly SomaSourceVersion[] {
|
|
@@ -188,7 +181,7 @@ export class SomaFileSourceVersionStore implements SomaSourceVersionStore {
|
|
|
188
181
|
this.cache.delete(safeName);
|
|
189
182
|
return NO_VERSIONS;
|
|
190
183
|
}
|
|
191
|
-
//
|
|
184
|
+
// 指纹带路径:避免换文件后因 mtime + 大小碰巧相同而命中旧缓存
|
|
192
185
|
const fullStamp = `${filePath}|${stamp}`;
|
|
193
186
|
const cached = this.cache.get(safeName);
|
|
194
187
|
if (cached !== undefined && cached.stamp === fullStamp) return cached.versions;
|
|
@@ -208,7 +201,7 @@ export class SomaFileSourceVersionStore implements SomaSourceVersionStore {
|
|
|
208
201
|
|
|
209
202
|
async names(): Promise<readonly string[]> {
|
|
210
203
|
const files: string[] = [];
|
|
211
|
-
for (const dir of
|
|
204
|
+
for (const dir of [this.baseDir]) {
|
|
212
205
|
try {
|
|
213
206
|
files.push(...fs.readdirSync(dir));
|
|
214
207
|
} catch (error) {
|
|
@@ -236,7 +229,7 @@ export class SomaFileSourceVersionStore implements SomaSourceVersionStore {
|
|
|
236
229
|
if (after !== before) {
|
|
237
230
|
assertSourceAppendOnly(safeName, before, after);
|
|
238
231
|
fs.mkdirSync(this.baseDir, { recursive: true });
|
|
239
|
-
writeFileAtomic(this.
|
|
232
|
+
writeFileAtomic(this.fileOf(safeName), serializeAggregate(safeName, after));
|
|
240
233
|
// 下一次读按新指纹重读并冻结,不把调用方手里的数组放进缓存
|
|
241
234
|
this.cache.delete(safeName);
|
|
242
235
|
}
|
|
@@ -244,22 +237,7 @@ export class SomaFileSourceVersionStore implements SomaSourceVersionStore {
|
|
|
244
237
|
});
|
|
245
238
|
}
|
|
246
239
|
|
|
247
|
-
/**
|
|
248
|
-
* 读路径:新目录 > 旧目录(告警 CORE-RUNTIME-LEGACY-DIR);只认新后缀 `.source.json`。
|
|
249
|
-
* 找不到时返回新目录的路径(写路径与「不存在」判定共用)。
|
|
250
|
-
*/
|
|
251
240
|
private fileOf(name: string): string {
|
|
252
|
-
const key = sourceStorageKey(name);
|
|
253
|
-
const current = path.join(this.baseDir, `${key}${SOMA_SOURCE_FILE_SUFFIX}`);
|
|
254
|
-
if (stampOf(current) !== null) return current;
|
|
255
|
-
if (this.legacyDir === null) return current;
|
|
256
|
-
const legacy = path.join(this.legacyDir, `${key}${SOMA_SOURCE_FILE_SUFFIX}`);
|
|
257
|
-
if (stampOf(legacy) === null) return current;
|
|
258
|
-
warnRuntimeLegacyDirOnce('sources', this.legacyDir);
|
|
259
|
-
return legacy;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
private writeFileOf(name: string): string {
|
|
263
241
|
return path.join(this.baseDir, `${sourceStorageKey(name)}${SOMA_SOURCE_FILE_SUFFIX}`);
|
|
264
242
|
}
|
|
265
243
|
}
|
|
@@ -157,7 +157,7 @@ export interface RegistryStandardProduct {
|
|
|
157
157
|
readonly assets?: PageDeclarationAssets;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
/** 版本记录 → 标准产物;旧方言存档(含方言键)与组件树页返回 null
|
|
160
|
+
/** 版本记录 → 标准产物;旧方言存档(含方言键)与组件树页返回 null(调用方走组件树通道或报无标准产物) */
|
|
161
161
|
export function standardProductOf(record: {
|
|
162
162
|
readonly name: string;
|
|
163
163
|
readonly version: number;
|
|
@@ -110,10 +110,7 @@ export function resetRuntimeSpace(): void {
|
|
|
110
110
|
|
|
111
111
|
// ── 布局与存储 ────────────────────────────────────────────────────────────────
|
|
112
112
|
|
|
113
|
-
const LAYOUT_ENV_KEYS = [
|
|
114
|
-
'SOMA_HOST_DIR', 'SOMA_RUNTIME_DIR', 'SOMA_PAGE_REGISTRY_DIR', 'SOMA_BIZ_REGISTRY_DIR',
|
|
115
|
-
'SOMA_REGISTRY_ASSET_DIR', 'SOMA_API_REGISTRY_DIR',
|
|
116
|
-
] as const;
|
|
113
|
+
const LAYOUT_ENV_KEYS = ['SOMA_HOST_DIR', 'SOMA_RUNTIME_DIR'] as const;
|
|
117
114
|
|
|
118
115
|
/** 当前进程的 runtime 布局(按环境签名记忆,避免每次调用都读盘) */
|
|
119
116
|
export function runtimeLayout(): SomaRuntimeLayout {
|
|
@@ -55,10 +55,9 @@ export function collectRuntimeGarbage(
|
|
|
55
55
|
for (const digest of options.referenced ?? []) if (isRuntimeDigest(digest)) referenced.add(digest);
|
|
56
56
|
collectJsonDigests(dirs.bindings, referenced);
|
|
57
57
|
collectJsonDigests(dirs.prewarm, referenced);
|
|
58
|
-
// Registry
|
|
59
|
-
// 还没迁移的旧目录(`registry/biz`、`data/soma-runtime/*`)里的版本记录同样是引用方:漏扫会把它们引用的产物当垃圾删掉。
|
|
58
|
+
// Registry 版本记录:pages / sources / apis 目录里的版本记录是引用方,漏扫会把它们引用的产物当垃圾删掉。
|
|
60
59
|
if (dirs.sources === undefined) throw new Error('[soma-core][注册中心] runtime GC 缺少源附件目录 dirs.sources');
|
|
61
|
-
for (const dir of new Set([dirs.pages, dirs.sources, dirs.apis
|
|
60
|
+
for (const dir of new Set([dirs.pages, dirs.sources, dirs.apis])) collectJsonDigests(dir, referenced);
|
|
62
61
|
|
|
63
62
|
let scanned = 0;
|
|
64
63
|
let kept = 0;
|
|
@@ -188,14 +188,13 @@ function prepare(address: string, page: SomaStandardPage, options: SomaInjectOpt
|
|
|
188
188
|
const { normalized, kind } = assertAddress(address, ['exact', 'pattern']);
|
|
189
189
|
assertStandardPageShape(page, normalized);
|
|
190
190
|
const probe = probePage(page);
|
|
191
|
-
if (probe.soma !==
|
|
191
|
+
if (probe.soma !== page.format) {
|
|
192
192
|
throw runtimeError('CORE-FORMAT-VERSION-MISMATCH', `注入 ${normalized}`,
|
|
193
|
-
|
|
193
|
+
probe.soma === undefined
|
|
194
|
+
? `载荷 format 是 ${page.format},page 块没有写 soma:`
|
|
195
|
+
: `载荷 format 是 ${page.format},page 块 soma: 是 ${JSON.stringify(probe.soma)}`, '两处必须一致;page 块写 soma: 1');
|
|
194
196
|
}
|
|
195
197
|
const digest = computeStandardPageDigest(page);
|
|
196
|
-
if (probe.soma === undefined) {
|
|
197
|
-
announceOnce(`implicit:${digest}`, `CORE-FORMAT-VERSION-IMPLICIT ${normalized} 的 page 块未写 soma:,兼容期按 1 处理;请补 soma: 1。`);
|
|
198
|
-
}
|
|
199
198
|
// 方言段一律拒收(MV-CORE-a:兼容期与环境变量开关已删):方言在上游编译成标准格式再注入
|
|
200
199
|
if (probe.nonStandardKeys.length > 0) {
|
|
201
200
|
throw runtimeError('CORE-INJECT-NONSTANDARD-KEY', `注入 ${normalized}`,
|
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
loadSomaServerPageAssets,
|
|
25
25
|
resolveSomaPageSource,
|
|
26
26
|
SomaPageAssetError,
|
|
27
|
-
type SomaPageAssetLoadProfile,
|
|
28
27
|
type SomaServerPageAssets,
|
|
29
28
|
} from '../host/server-page-assets';
|
|
30
29
|
import { collectIncludes, getSomaAssetSources } from '../host/source-packages';
|
|
@@ -72,8 +71,6 @@ import type {
|
|
|
72
71
|
export interface SomaLoadPageOptions {
|
|
73
72
|
/** 宿主根(缺省 SOMA_HOST_DIR) */
|
|
74
73
|
readonly hostDir?: string;
|
|
75
|
-
/** `headless` 供无头页面对象路由(不下发 html / 样式) */
|
|
76
|
-
readonly profile?: SomaPageAssetLoadProfile;
|
|
77
74
|
readonly watch?: boolean;
|
|
78
75
|
readonly treeContext?: TreeCompileContext;
|
|
79
76
|
}
|
|
@@ -231,7 +228,6 @@ function compileStandardPage(
|
|
|
231
228
|
page: SomaStandardPage,
|
|
232
229
|
address: string,
|
|
233
230
|
hostDir: string | undefined,
|
|
234
|
-
profile: SomaPageAssetLoadProfile,
|
|
235
231
|
origin: 'inject',
|
|
236
232
|
): { assets: SomaServerPageAssets; degraded: boolean } {
|
|
237
233
|
const host = readHostFiles(hostDir);
|
|
@@ -269,29 +265,22 @@ function compileStandardPage(
|
|
|
269
265
|
appConfigYaml: host.appConfigYaml,
|
|
270
266
|
...extras,
|
|
271
267
|
};
|
|
272
|
-
const assets: SomaServerPageAssets =
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
: {
|
|
280
|
-
...common,
|
|
281
|
-
html: compiled.html,
|
|
282
|
-
ui: compiled.ui,
|
|
283
|
-
event: compiled.event,
|
|
284
|
-
...(compiled.sourceMarkup === 'legacy-html' ? { includes } : {}),
|
|
285
|
-
};
|
|
268
|
+
const assets: SomaServerPageAssets = {
|
|
269
|
+
...common,
|
|
270
|
+
html: compiled.html,
|
|
271
|
+
ui: compiled.ui,
|
|
272
|
+
event: compiled.event,
|
|
273
|
+
...(compiled.sourceMarkup === 'legacy-html' ? { includes } : {}),
|
|
274
|
+
};
|
|
286
275
|
return { assets, degraded: compiled.degradedRegions.length > 0 };
|
|
287
276
|
}
|
|
288
277
|
|
|
289
278
|
/** 编译结果键 = 摘要 + 页面形态 + core 编译版本 + 编译身份(组件供货 / 设计规则 / 主题指纹);读不到身份就不缓存 */
|
|
290
|
-
function compileKey(digest: string
|
|
279
|
+
function compileKey(digest: string): string | null {
|
|
291
280
|
// core 不持有编译器,读不到编译身份(恒为 null)→ 不缓存
|
|
292
281
|
const identity = null as string | null;
|
|
293
282
|
if (identity === null || identity === '') return null;
|
|
294
|
-
return createHash('sha256').update(`${digest}|${
|
|
283
|
+
return createHash('sha256').update(`${digest}|${DECLARATION_COMPILER_VERSION}|${identity}`).digest('hex');
|
|
295
284
|
}
|
|
296
285
|
|
|
297
286
|
function servePage(
|
|
@@ -299,15 +288,14 @@ function servePage(
|
|
|
299
288
|
digest: string,
|
|
300
289
|
binding: SomaRuntimeBinding,
|
|
301
290
|
hostDir: string | undefined,
|
|
302
|
-
profile: SomaPageAssetLoadProfile,
|
|
303
291
|
): SomaServerPageAssets {
|
|
304
292
|
const store = runtimeStore();
|
|
305
|
-
const key = binding.cache === 'store' ? compileKey(digest
|
|
293
|
+
const key = binding.cache === 'store' ? compileKey(digest) : null;
|
|
306
294
|
if (key !== null) {
|
|
307
295
|
const hot = store.compiled.get(key) as SomaServerPageAssets | undefined;
|
|
308
296
|
if (hot !== undefined) return hot;
|
|
309
297
|
}
|
|
310
|
-
const { assets, degraded } = compileStandardPage(page, binding.address, hostDir,
|
|
298
|
+
const { assets, degraded } = compileStandardPage(page, binding.address, hostDir, 'inject');
|
|
311
299
|
// 降级产物与整页失败一律不缓存,沿用存量规则
|
|
312
300
|
if (key !== null && !degraded) {
|
|
313
301
|
store.compiled.set(key, assets);
|
|
@@ -451,7 +439,6 @@ export async function loadPageByAddress(
|
|
|
451
439
|
options: SomaLoadPageOptions = {},
|
|
452
440
|
): Promise<SomaLoadedPage> {
|
|
453
441
|
const hostDir = options.hostDir ?? currentHostDir();
|
|
454
|
-
const profile = options.profile ?? 'render';
|
|
455
442
|
const requestPath = normalizeRequestPath(urlPath);
|
|
456
443
|
const search = searchOf(urlPath, request, requestPath);
|
|
457
444
|
const access: AccessContext = { policy: readAccessPolicy(hostDir), identity: createIdentityResolver(hostDir, request) };
|
|
@@ -483,7 +470,7 @@ export async function loadPageByAddress(
|
|
|
483
470
|
// 先过访问门(未授权的人不该靠 404 / 非 404 的差别探到参数契约),再校验参数、再编译
|
|
484
471
|
await gateAccess(entry.binding, entry.envelope, access.policy, access.identity, requestPath);
|
|
485
472
|
restoreParams(entry, hit.params, entry.binding.address); // 类型不合先 404,不编译
|
|
486
|
-
const assets = servePage(entry.page, entry.binding.digest, entry.binding, hostDir
|
|
473
|
+
const assets = servePage(entry.page, entry.binding.digest, entry.binding, hostDir);
|
|
487
474
|
return finish(assets, entry.binding, { entry, rawParams: hit.params, address: entry.binding.address, ...common });
|
|
488
475
|
}
|
|
489
476
|
}
|
|
@@ -495,7 +482,6 @@ return finish(assets, entry.binding, { entry, rawParams: hit.params, address: en
|
|
|
495
482
|
const assets = loadSomaServerPageAssets({
|
|
496
483
|
hostDir,
|
|
497
484
|
urlPath: requestPath,
|
|
498
|
-
profile,
|
|
499
485
|
...(options.watch !== undefined ? { watch: options.watch } : {}),
|
|
500
486
|
...(options.treeContext !== undefined ? { treeContext: options.treeContext } : {}),
|
|
501
487
|
});
|
|
@@ -528,7 +514,7 @@ return finish(assets, entry.binding, { entry, rawParams: hit.params, address: en
|
|
|
528
514
|
// 解析出的页面自带 access 时再过一遍(前缀授权下限与缺省策略已在上面过过,重复判定无副作用)
|
|
529
515
|
await gateAccess(entry.binding, result.page.envelope ?? null, access.policy, access.identity, requestPath);
|
|
530
516
|
const digest = createHash('sha256').update(`${entry.binding.address}|${requestPath}|${JSON.stringify(result.page)}`).digest('hex');
|
|
531
|
-
const assets = servePage(result.page, digest, entry.binding, hostDir
|
|
517
|
+
const assets = servePage(result.page, digest, entry.binding, hostDir);
|
|
532
518
|
return finish({ ...assets, ...(result.title !== undefined ? { title: result.title } : {}) }, entry.binding, {
|
|
533
519
|
entry, rawParams: hit.params, address: entry.binding.address, envelope: result.page.envelope ?? null, ...common,
|
|
534
520
|
});
|
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
// · 缺省根 `<host>/.soma/runtime`;环境变量 `SOMA_RUNTIME_DIR` 可改,相对路径相对 `<host>`(不相对 cwd),绝对路径原样用;
|
|
6
6
|
// · 越界:根不能是 `<host>` 本身、不能是 `<host>/html|ui|public`(及宿主源码根下同名目录)或其子目录、
|
|
7
7
|
// 不能是 `<host>` 的祖先目录或文件系统根 → 抛 CORE-RUNTIME-ROOT-INVALID(拒绝启动);
|
|
8
|
-
// · Registry
|
|
9
|
-
// ·
|
|
10
|
-
// · 源附件目录的键叫 `sources`(盘上 `registry/sources`)。旧键 `biz` 不再识别;
|
|
11
|
-
// 盘上的旧目录 `registry/biz` 与旧位置 `data/soma-runtime/biz` 作为 `sources` 的只读回退候选,由 `soma runtime migrate` 搬走;
|
|
12
|
-
// · 旧位置(`data/soma-runtime/<kind>`,含 `soma dev` 下 cwd 为 `.soma/next` 的落点)仅作只读回退候选。
|
|
8
|
+
// · Registry 四目录(pages / sources / assets / apis)固定在 `<root>/registry/<kind>`,没有别的位置或环境变量覆盖;
|
|
9
|
+
// · 源附件目录的键叫 `sources`(盘上 `registry/sources`)。
|
|
13
10
|
|
|
14
11
|
const fs = require('node:fs');
|
|
15
12
|
const path = require('node:path');
|
|
@@ -17,12 +14,6 @@ const path = require('node:path');
|
|
|
17
14
|
/** @typedef {Readonly<Record<string, string | undefined>>} SomaEnv */
|
|
18
15
|
|
|
19
16
|
const SOMA_RUNTIME_DIR_ENV = 'SOMA_RUNTIME_DIR';
|
|
20
|
-
const SOMA_RUNTIME_LEGACY_ENV = Object.freeze({
|
|
21
|
-
pages: 'SOMA_PAGE_REGISTRY_DIR',
|
|
22
|
-
sources: 'SOMA_BIZ_REGISTRY_DIR',
|
|
23
|
-
assets: 'SOMA_REGISTRY_ASSET_DIR',
|
|
24
|
-
apis: 'SOMA_API_REGISTRY_DIR',
|
|
25
|
-
});
|
|
26
17
|
const SOMA_RUNTIME_DEFAULT_RELATIVE = path.join('.soma', 'runtime');
|
|
27
18
|
/** 源码目录名:根不能落在这些目录里(防止产物写进作者源码目录) */
|
|
28
19
|
const SOMA_RUNTIME_FORBIDDEN_SOURCE_DIRS = Object.freeze(['html', 'ui', 'public']);
|
|
@@ -103,73 +94,13 @@ function resolveSomaRuntimeRoot(hostDir, env = process.env) {
|
|
|
103
94
|
return assertRuntimeRootValid(host, root);
|
|
104
95
|
}
|
|
105
96
|
|
|
106
|
-
|
|
107
|
-
return path.resolve(left) === path.resolve(right);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 完整布局:根、各子目录、四个 Registry 目录的来源与旧位置候选。
|
|
112
|
-
* cwd 只用于生成旧位置候选(旧缺省相对 cwd),不参与新位置。
|
|
113
|
-
*/
|
|
97
|
+
/** 完整布局:根与各子目录(四个 Registry 目录固定在 `<root>/registry/<kind>`) */
|
|
114
98
|
/** @param {SomaEnv} [env] */
|
|
115
|
-
function resolveSomaRuntimeLayout(hostDir, env = process.env
|
|
99
|
+
function resolveSomaRuntimeLayout(hostDir, env = process.env) {
|
|
116
100
|
const host = path.resolve(hostDir);
|
|
117
101
|
const root = resolveSomaRuntimeRoot(host, env);
|
|
118
102
|
const rootFromEnv = nonEmpty(env[SOMA_RUNTIME_DIR_ENV]) !== null;
|
|
119
|
-
const alias = (kind) => {
|
|
120
|
-
const value = nonEmpty(env[SOMA_RUNTIME_LEGACY_ENV[kind]]);
|
|
121
|
-
return value ? path.resolve(host, value) : null;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
103
|
const registry = path.join(root, 'registry');
|
|
125
|
-
const pagesAlias = alias('pages');
|
|
126
|
-
const sources = {};
|
|
127
|
-
const dirs = {};
|
|
128
|
-
|
|
129
|
-
dirs.pages = pagesAlias ?? path.join(registry, 'pages');
|
|
130
|
-
sources.pages = pagesAlias ? 'alias' : 'root';
|
|
131
|
-
for (const kind of ['sources', 'assets']) {
|
|
132
|
-
const explicit = alias(kind);
|
|
133
|
-
if (explicit) {
|
|
134
|
-
dirs[kind] = explicit;
|
|
135
|
-
sources[kind] = 'alias';
|
|
136
|
-
} else if (pagesAlias) {
|
|
137
|
-
dirs[kind] = path.join(pagesAlias, '..', kind);
|
|
138
|
-
sources[kind] = 'sibling';
|
|
139
|
-
} else {
|
|
140
|
-
dirs[kind] = path.join(registry, kind);
|
|
141
|
-
sources[kind] = 'root';
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
const apisAlias = alias('apis');
|
|
145
|
-
dirs.apis = apisAlias ?? path.join(registry, 'apis');
|
|
146
|
-
sources.apis = apisAlias ? 'alias' : 'root';
|
|
147
|
-
|
|
148
|
-
const legacy = {};
|
|
149
|
-
for (const kind of ['pages', 'sources', 'assets', 'apis']) {
|
|
150
|
-
// 源附件的旧盘上目录名是 biz(旧位置 data/soma-runtime/biz、runtime 根下 registry/biz、页面别名同级的 ../biz)
|
|
151
|
-
const diskName = kind === 'sources' ? 'biz' : kind;
|
|
152
|
-
if (sources[kind] === 'sibling' && kind === 'sources') {
|
|
153
|
-
legacy[kind] = Object.freeze([path.resolve(pagesAlias, '..', diskName)]);
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
if (sources[kind] !== 'root') {
|
|
157
|
-
legacy[kind] = Object.freeze([]);
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
const candidates = [
|
|
161
|
-
...(kind === 'sources' ? [path.join(registry, diskName)] : []),
|
|
162
|
-
path.join(host, '.soma', 'next', 'data', 'soma-runtime', diskName),
|
|
163
|
-
path.join(host, 'data', 'soma-runtime', diskName),
|
|
164
|
-
path.resolve(cwd, 'data', 'soma-runtime', diskName),
|
|
165
|
-
];
|
|
166
|
-
const unique = [];
|
|
167
|
-
for (const candidate of candidates) {
|
|
168
|
-
if (sameDir(candidate, dirs[kind])) continue;
|
|
169
|
-
if (!unique.some((existing) => sameDir(existing, candidate))) unique.push(path.resolve(candidate));
|
|
170
|
-
}
|
|
171
|
-
legacy[kind] = Object.freeze(unique);
|
|
172
|
-
}
|
|
173
104
|
|
|
174
105
|
return Object.freeze({
|
|
175
106
|
hostDir: host,
|
|
@@ -177,10 +108,10 @@ function resolveSomaRuntimeLayout(hostDir, env = process.env, cwd = process.cwd(
|
|
|
177
108
|
rootFromEnv,
|
|
178
109
|
dirs: Object.freeze({
|
|
179
110
|
root,
|
|
180
|
-
pages:
|
|
181
|
-
sources:
|
|
182
|
-
assets:
|
|
183
|
-
apis:
|
|
111
|
+
pages: path.join(registry, 'pages'),
|
|
112
|
+
sources: path.join(registry, 'sources'),
|
|
113
|
+
assets: path.join(registry, 'assets'),
|
|
114
|
+
apis: path.join(registry, 'apis'),
|
|
184
115
|
bindings: path.join(root, 'bindings'),
|
|
185
116
|
artifacts: path.join(root, 'artifacts'),
|
|
186
117
|
prewarm: path.join(root, 'prewarm'),
|
|
@@ -188,28 +119,9 @@ function resolveSomaRuntimeLayout(hostDir, env = process.env, cwd = process.cwd(
|
|
|
188
119
|
config: path.join(root, 'config'),
|
|
189
120
|
journal: path.join(root, 'journal'),
|
|
190
121
|
}),
|
|
191
|
-
sources: Object.freeze(sources),
|
|
192
|
-
legacy: Object.freeze(legacy),
|
|
193
122
|
});
|
|
194
123
|
}
|
|
195
124
|
|
|
196
|
-
/** 目录存在且至少有一个条目(忽略锁文件与临时文件) */
|
|
197
|
-
function dirHasEntries(dir) {
|
|
198
|
-
try {
|
|
199
|
-
return fs.readdirSync(dir).some((name) => !name.endsWith('.lock') && !name.endsWith('.tmp'));
|
|
200
|
-
} catch {
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/** 旧位置候选里第一个有数据的目录;没有返回 null。只用于只读回退 */
|
|
206
|
-
function firstLegacyDirWithData(layout, kind) {
|
|
207
|
-
for (const candidate of layout.legacy[kind]) {
|
|
208
|
-
if (dirHasEntries(candidate)) return candidate;
|
|
209
|
-
}
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
125
|
/**
|
|
214
126
|
* 生产模式且没设 SOMA_RUNTIME_DIR 时的告警文案(AD-39 Q8);不需要告警返回 null。
|
|
215
127
|
* 生产判据沿用 host-config-paths 的环境名口径:SOMA_ENV → APP_ENV → NODE_ENV,归一后为 prod。
|
|
@@ -232,20 +144,17 @@ function runtimeRootProductionWarning(hostDir, env = process.env) {
|
|
|
232
144
|
*/
|
|
233
145
|
/** @param {SomaEnv} [env] */
|
|
234
146
|
function currentRuntimeLayout(env = process.env, cwd = process.cwd()) {
|
|
235
|
-
return resolveSomaRuntimeLayout(resolveSomaHostDir(env, cwd), env
|
|
147
|
+
return resolveSomaRuntimeLayout(resolveSomaHostDir(env, cwd), env);
|
|
236
148
|
}
|
|
237
149
|
|
|
238
150
|
module.exports = {
|
|
239
151
|
currentRuntimeLayout,
|
|
240
152
|
SOMA_RUNTIME_DIR_ENV,
|
|
241
|
-
SOMA_RUNTIME_LEGACY_ENV,
|
|
242
153
|
SOMA_RUNTIME_DEFAULT_RELATIVE,
|
|
243
154
|
SOMA_RUNTIME_FORBIDDEN_SOURCE_DIRS,
|
|
244
155
|
SomaRuntimeRootError,
|
|
245
156
|
resolveSomaHostDir,
|
|
246
157
|
resolveSomaRuntimeRoot,
|
|
247
158
|
resolveSomaRuntimeLayout,
|
|
248
|
-
dirHasEntries,
|
|
249
|
-
firstLegacyDirWithData,
|
|
250
159
|
runtimeRootProductionWarning,
|
|
251
160
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// runtime 根目录解析的 TS 面:实现只有 root.cjs 一份,这里仅补类型再导出,不另写第二份。
|
|
2
2
|
|
|
3
3
|
import * as impl from './root.cjs';
|
|
4
|
-
import type {
|
|
4
|
+
import type { SomaRuntimeLayout } from './types';
|
|
5
5
|
|
|
6
6
|
type Env = Readonly<Record<string, string | undefined>>;
|
|
7
7
|
|
|
@@ -14,33 +14,13 @@ export const SomaRuntimeRootError: new (message: string, details?: Record<string
|
|
|
14
14
|
export const resolveSomaHostDir: (env?: Env, cwd?: string) => string = impl.resolveSomaHostDir;
|
|
15
15
|
/** @testHook 测试直接解析运行根 */
|
|
16
16
|
export const resolveSomaRuntimeRoot: (hostDir: string, env?: Env) => string = impl.resolveSomaRuntimeRoot;
|
|
17
|
-
export const resolveSomaRuntimeLayout: (hostDir: string, env?: Env
|
|
17
|
+
export const resolveSomaRuntimeLayout: (hostDir: string, env?: Env) => SomaRuntimeLayout =
|
|
18
18
|
(impl.resolveSomaRuntimeLayout as never);
|
|
19
|
-
export const firstLegacyDirWithData: (layout: SomaRuntimeLayout, kind: SomaRegistryStoreKind) => string | null =
|
|
20
|
-
impl.firstLegacyDirWithData;
|
|
21
19
|
/** @testHook 测试读取运行根的生产告警 */
|
|
22
20
|
export const runtimeRootProductionWarning: (hostDir: string, env?: Env) => string | null =
|
|
23
21
|
impl.runtimeRootProductionWarning;
|
|
24
22
|
|
|
25
23
|
/** 取当前进程的布局(宿主根取 SOMA_HOST_DIR,缺省 cwd) */
|
|
26
24
|
export function currentRuntimeLayout(env: Env = process.env, cwd: string = process.cwd()): SomaRuntimeLayout {
|
|
27
|
-
return resolveSomaRuntimeLayout(resolveSomaHostDir(env, cwd), env
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const warnedLegacy = new Set<string>();
|
|
31
|
-
|
|
32
|
-
/** 旧目录只读回退时的一次性诊断 CORE-RUNTIME-LEGACY-DIR(每个旧目录每进程一次) */
|
|
33
|
-
export function warnRuntimeLegacyDirOnce(kind: SomaRegistryStoreKind, legacyDir: string): void {
|
|
34
|
-
const key = `${kind}:${legacyDir}`;
|
|
35
|
-
if (warnedLegacy.has(key)) return;
|
|
36
|
-
warnedLegacy.add(key);
|
|
37
|
-
console.warn(
|
|
38
|
-
`[soma-core][注册中心] CORE-RUNTIME-LEGACY-DIR 正在从旧目录只读回退 ${kind}:${legacyDir}。`
|
|
39
|
-
+ '新数据写入 runtime 根;请运行 soma runtime migrate 把旧目录搬入。',
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** 测试复位 */
|
|
44
|
-
export function resetRuntimeLegacyWarnings(): void {
|
|
45
|
-
warnedLegacy.clear();
|
|
25
|
+
return resolveSomaRuntimeLayout(resolveSomaHostDir(env, cwd), env);
|
|
46
26
|
}
|
|
@@ -194,21 +194,12 @@ export interface SomaRuntimeDirs {
|
|
|
194
194
|
readonly journal: string;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
/** 某个 Registry 目录的来源:显式旧环境变量别名 / 跟着页面目录走 / runtime 根缺省 */
|
|
198
|
-
export type SomaRuntimeDirSource = 'alias' | 'sibling' | 'root';
|
|
199
|
-
|
|
200
|
-
/** Registry 存储类别(旧名 `biz` 已改 `sources`,不再识别) */
|
|
201
|
-
export type SomaRegistryStoreKind = 'pages' | 'sources' | 'assets' | 'apis';
|
|
202
|
-
|
|
203
197
|
export interface SomaRuntimeLayout {
|
|
204
198
|
readonly hostDir: string;
|
|
205
199
|
readonly root: string;
|
|
206
200
|
/** `SOMA_RUNTIME_DIR` 是否显式设置 */
|
|
207
201
|
readonly rootFromEnv: boolean;
|
|
208
202
|
readonly dirs: SomaRuntimeDirs;
|
|
209
|
-
readonly sources: Readonly<Record<SomaRegistryStoreKind, SomaRuntimeDirSource>>;
|
|
210
|
-
/** 旧位置候选(只读回退用);来源是 alias / sibling 的类别为空 */
|
|
211
|
-
readonly legacy: Readonly<Record<SomaRegistryStoreKind, readonly string[]>>;
|
|
212
203
|
}
|
|
213
204
|
|
|
214
205
|
export interface SomaRuntimeStoreStats {
|
|
@@ -237,8 +228,6 @@ export interface SomaRuntimeGcOptions {
|
|
|
237
228
|
readonly dryRun?: boolean;
|
|
238
229
|
/** 年龄不足的文件不删(防止与「刚写产物、还没写绑定」竞态),缺省 5 分钟 */
|
|
239
230
|
readonly minAgeMs?: number;
|
|
240
|
-
/** 额外要扫描的 Registry 版本记录目录(未迁移的旧目录:`layout.legacy.*`);缺席的目录按空处理 */
|
|
241
|
-
readonly extraRegistryDirs?: readonly string[];
|
|
242
231
|
/** 调用方(进程内绑定表)额外声明在用的摘要 */
|
|
243
232
|
readonly referenced?: Iterable<string>;
|
|
244
233
|
readonly now?: () => number;
|
|
@@ -69,23 +69,15 @@ const KNOWN_CAPABILITIES: readonly string[] = COMPONENT_TREE_CAPABILITIES;
|
|
|
69
69
|
const REQUIRED_CAPABILITY = 'component-tree:1';
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
* 信封头的格式标识是否被当前 core
|
|
72
|
+
* 信封头的格式标识是否被当前 core 接受:只认 `format`,且在闭集内。
|
|
73
73
|
* 供挂载守卫在「格式」这一步直接引用(与 `checkArtifactRuntimeCompatibility` 同一口径)。
|
|
74
74
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
readonly format?: unknown; readonly schemaVersion?: unknown; readonly grammarVersion?: unknown;
|
|
78
|
-
}): boolean {
|
|
79
|
-
if (head.format !== undefined) return typeof head.format === 'string' && ACCEPTED_FORMATS.includes(head.format);
|
|
80
|
-
return head.schemaVersion === 1 && head.grammarVersion === 1;
|
|
75
|
+
export function isArtifactFormatAccepted(head: { readonly format?: unknown }): boolean {
|
|
76
|
+
return typeof head.format === 'string' && ACCEPTED_FORMATS.includes(head.format);
|
|
81
77
|
}
|
|
82
78
|
|
|
83
79
|
function archivedFormatOf(head: SomaArtifactEnvelopeHead): string | null {
|
|
84
|
-
|
|
85
|
-
if (head.schemaVersion !== undefined || head.grammarVersion !== undefined) {
|
|
86
|
-
return `schemaVersion:${String(head.schemaVersion)}/grammarVersion:${String(head.grammarVersion)}`;
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
80
|
+
return typeof head.format === 'string' ? head.format : null;
|
|
89
81
|
}
|
|
90
82
|
|
|
91
83
|
function incompatible(reason: SomaArtifactIncompatibility, code: 'CT-ARTIFACT-VERSION' | 'CT-ARTIFACT-CAPABILITY'): SomaArtifactCompatibility {
|
|
@@ -108,10 +100,8 @@ export function checkArtifactRuntimeCompatibility(
|
|
|
108
100
|
return required ? incompatible({ rule: 'envelope-missing' }, 'CT-ARTIFACT-VERSION') : { compatible: true, level: 'reuse', reason: null };
|
|
109
101
|
}
|
|
110
102
|
|
|
111
|
-
// ① 格式:sourceMarkup
|
|
112
|
-
|
|
113
|
-
const hasFormatMark = envelope.format !== undefined
|
|
114
|
-
|| envelope.schemaVersion !== undefined || envelope.grammarVersion !== undefined;
|
|
103
|
+
// ① 格式:sourceMarkup 须在闭集;有 format 时须被接受
|
|
104
|
+
const hasFormatMark = envelope.format !== undefined;
|
|
115
105
|
const tree = envelope.sourceMarkup === 'component-tree';
|
|
116
106
|
if (!SOURCE_MARKUPS.includes(envelope.sourceMarkup)) {
|
|
117
107
|
return incompatible({ rule: 'format', archived: String(envelope.sourceMarkup), accepted: ACCEPTED_FORMATS }, 'CT-ARTIFACT-VERSION');
|