soma-core 1.3.4 → 1.3.5
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/soma/page/route.ts +17 -2
- package/core/build/v2/migrate-v1.ts +1 -1
- package/core/client/registry/page-lifecycle.ts +1 -1
- package/core/client/security/attribute-presence.ts +16 -1
- package/core/server/host/published-page-assets.ts +35 -0
- package/core/server/registry/page-registry-store.ts +1 -1
- package/dist/core/index.cjs +6 -1
- package/dist/types/server/host/published-page-assets.d.ts +19 -0
- package/dist/types/server/registry/page-registry-store.d.ts +1 -1
- package/package.json +1 -1
- package/tsconfig.json +20 -7
package/app/soma/page/route.ts
CHANGED
|
@@ -3,17 +3,32 @@ import {
|
|
|
3
3
|
loadSomaServerPageAssets,
|
|
4
4
|
SomaPageAssetError,
|
|
5
5
|
} from '../../../core/server/host/server-page-assets';
|
|
6
|
+
import { loadPublishedRegistryPageAssets } from '../../../core/server/host/published-page-assets';
|
|
7
|
+
|
|
8
|
+
export const runtime = 'nodejs';
|
|
9
|
+
export const dynamic = 'force-dynamic';
|
|
6
10
|
|
|
7
11
|
/** SOMA internal page asset endpoint. Host request hooks must never run here. */
|
|
8
12
|
export async function GET(request: NextRequest) {
|
|
13
|
+
const pagePath = request.nextUrl.searchParams.get('path') || '/';
|
|
9
14
|
try {
|
|
10
15
|
const assets = loadSomaServerPageAssets({
|
|
11
16
|
hostDir: process.env.SOMA_HOST_DIR,
|
|
12
|
-
urlPath:
|
|
17
|
+
urlPath: pagePath,
|
|
13
18
|
profile: 'render',
|
|
14
19
|
});
|
|
15
|
-
return Response.json(assets);
|
|
20
|
+
return Response.json(assets, { headers: { 'cache-control': 'no-store' } });
|
|
16
21
|
} catch (error) {
|
|
22
|
+
if (error instanceof SomaPageAssetError && error.code === 'SOMA_PAGE_NOT_FOUND') {
|
|
23
|
+
try {
|
|
24
|
+
const published = await loadPublishedRegistryPageAssets(pagePath);
|
|
25
|
+
if (published) {
|
|
26
|
+
return Response.json(published, { headers: { 'cache-control': 'no-store' } });
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
// 统一沿用 Host 的 404:匿名页面路径不泄漏 Registry 中的草稿、归档或非法名称细节。
|
|
30
|
+
}
|
|
31
|
+
}
|
|
17
32
|
if (error instanceof SomaPageAssetError) {
|
|
18
33
|
return Response.json(
|
|
19
34
|
{ error: error.message, code: error.code },
|
|
@@ -177,7 +177,7 @@ function migrateEvents(
|
|
|
177
177
|
/**
|
|
178
178
|
* 列表作用域在 v1 事件里是**嵌套**的(外层键 = 列表锚点)。
|
|
179
179
|
* v2 保持同形——曾经把它拍平成 `列表.锚点.事件` 三段,
|
|
180
|
-
* 解析器直接拒收(DOM
|
|
180
|
+
* 解析器直接拒收(DOM 事件白名单只认两段),既有 Host 实迁时当场暴露。
|
|
181
181
|
* 嵌套照搬,只把其中的 emit 抽走。
|
|
182
182
|
*/
|
|
183
183
|
const walk = (node: Record<string, unknown>, target: Record<string, unknown>): void => {
|
|
@@ -55,10 +55,25 @@ const ABSENT_WHEN_EMPTY_ARIA = new Set([
|
|
|
55
55
|
'aria-invalid',
|
|
56
56
|
]);
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* 空值会触发无意义资源请求的 URL 属性。
|
|
60
|
+
*
|
|
61
|
+
* 浏览器把 img/iframe 的 src="" 解释成当前文档 URL,既可能重复请求页面,
|
|
62
|
+
* 也会产生 resource error;srcset/poster 的空值同样不表达任何资源。
|
|
63
|
+
* 它们与 alt="" 这类有明确语义的内容属性不同,空值应等价于属性缺省。
|
|
64
|
+
*/
|
|
65
|
+
const ABSENT_WHEN_EMPTY_RESOURCE = new Set([
|
|
66
|
+
'src',
|
|
67
|
+
'srcset',
|
|
68
|
+
'poster',
|
|
69
|
+
]);
|
|
70
|
+
|
|
58
71
|
/** 空串是否意味着「删除该属性」 */
|
|
59
72
|
export function isAbsentWhenEmpty(attrName: string): boolean {
|
|
60
73
|
const name = attrName.toLowerCase();
|
|
61
|
-
return BOOLEAN_ATTRS.has(name)
|
|
74
|
+
return BOOLEAN_ATTRS.has(name)
|
|
75
|
+
|| ABSENT_WHEN_EMPTY_ARIA.has(name)
|
|
76
|
+
|| ABSENT_WHEN_EMPTY_RESOURCE.has(name);
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
/**
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// 发布页路径接线:Registry canonical 声明 → 服务端内存编译 → Host 运行时资产。
|
|
2
|
+
|
|
3
|
+
import { compilePageDeclaration } from '../../build/compiler/page-declaration-compiler';
|
|
4
|
+
import { getPageRegistryRepository } from '../registry/page-registry-repository';
|
|
5
|
+
|
|
6
|
+
const PUBLISHED_PAGE_PREFIX = '/pages/';
|
|
7
|
+
|
|
8
|
+
/** `/pages/<registry-name>` 是发布声明的稳定浏览路径;更深层路径仍归普通 Host 页面。 */
|
|
9
|
+
export function registryPageNameFromPath(pagePath: string): string | null {
|
|
10
|
+
if (!pagePath.startsWith(PUBLISHED_PAGE_PREFIX)) return null;
|
|
11
|
+
const name = pagePath.slice(PUBLISHED_PAGE_PREFIX.length);
|
|
12
|
+
return name !== '' && !name.includes('/') ? name : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Registry 声明只在服务端编译,浏览器收到的仍是既有运行时资产。 */
|
|
16
|
+
export async function loadPublishedRegistryPageAssets(pagePath: string) {
|
|
17
|
+
const name = registryPageNameFromPath(pagePath);
|
|
18
|
+
if (!name) return null;
|
|
19
|
+
|
|
20
|
+
const record = await getPageRegistryRepository().get(name);
|
|
21
|
+
const compiled = compilePageDeclaration(record.declaration);
|
|
22
|
+
return {
|
|
23
|
+
base: record.name,
|
|
24
|
+
sourceType: 'registry' as const,
|
|
25
|
+
sourcePackage: null,
|
|
26
|
+
html: record.declaration.html,
|
|
27
|
+
ui: compiled.runtimeAssets.uiYaml,
|
|
28
|
+
event: compiled.runtimeAssets.eventYaml,
|
|
29
|
+
styleYaml: '',
|
|
30
|
+
...(compiled.runtimeAssets.dataYaml ? { dataYaml: compiled.runtimeAssets.dataYaml } : {}),
|
|
31
|
+
localeYaml: '',
|
|
32
|
+
appConfigYaml: '',
|
|
33
|
+
registryPage: { name: record.name, version: record.version },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -47,7 +47,7 @@ export const PAGE_APP_PATTERN = /^[a-z0-9-]{1,32}$/;
|
|
|
47
47
|
* notes 塞满一样会撑爆响应。
|
|
48
48
|
*
|
|
49
49
|
* 128KiB 这个数的依据(实测,2026-08-12):
|
|
50
|
-
* -
|
|
50
|
+
* - 历史基线中**最大的真实 Host 声明**是 gallery 页(html 13,826 + ui 4,407 + event 1,805)
|
|
51
51
|
* = 20,038 字节。128KiB / 20,038 ≈ 6.5×,即人手写得最复杂的整站页面还能再翻 6.5 倍。
|
|
52
52
|
* - 声明仓库里 119 份 AI 生成版本的实测分布:中位 1,777 / p90 2,305 / 最大 2,995 字节,
|
|
53
53
|
* 离上限有 43 倍余量——正常生成永远撞不到这条线。
|
package/dist/core/index.cjs
CHANGED
|
@@ -758,9 +758,14 @@ var ABSENT_WHEN_EMPTY_ARIA = /* @__PURE__ */ new Set([
|
|
|
758
758
|
// 表单控件在非错误态下写空串等于凭空宣告"这个字段填错了"。
|
|
759
759
|
"aria-invalid"
|
|
760
760
|
]);
|
|
761
|
+
var ABSENT_WHEN_EMPTY_RESOURCE = /* @__PURE__ */ new Set([
|
|
762
|
+
"src",
|
|
763
|
+
"srcset",
|
|
764
|
+
"poster"
|
|
765
|
+
]);
|
|
761
766
|
function isAbsentWhenEmpty(attrName) {
|
|
762
767
|
const name = attrName.toLowerCase();
|
|
763
|
-
return BOOLEAN_ATTRS.has(name) || ABSENT_WHEN_EMPTY_ARIA.has(name);
|
|
768
|
+
return BOOLEAN_ATTRS.has(name) || ABSENT_WHEN_EMPTY_ARIA.has(name) || ABSENT_WHEN_EMPTY_RESOURCE.has(name);
|
|
764
769
|
}
|
|
765
770
|
function shouldRemoveAttribute(attrName, value) {
|
|
766
771
|
return value === "" && isAbsentWhenEmpty(attrName);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** `/pages/<registry-name>` 是发布声明的稳定浏览路径;更深层路径仍归普通 Host 页面。 */
|
|
2
|
+
export declare function registryPageNameFromPath(pagePath: string): string | null;
|
|
3
|
+
/** Registry 声明只在服务端编译,浏览器收到的仍是既有运行时资产。 */
|
|
4
|
+
export declare function loadPublishedRegistryPageAssets(pagePath: string): Promise<{
|
|
5
|
+
localeYaml: string;
|
|
6
|
+
appConfigYaml: string;
|
|
7
|
+
registryPage: {
|
|
8
|
+
name: string;
|
|
9
|
+
version: number;
|
|
10
|
+
};
|
|
11
|
+
dataYaml?: string | undefined;
|
|
12
|
+
base: string;
|
|
13
|
+
sourceType: "registry";
|
|
14
|
+
sourcePackage: null;
|
|
15
|
+
html: string;
|
|
16
|
+
ui: string;
|
|
17
|
+
event: string;
|
|
18
|
+
styleYaml: string;
|
|
19
|
+
} | null>;
|
|
@@ -17,7 +17,7 @@ export declare const PAGE_APP_PATTERN: RegExp;
|
|
|
17
17
|
* notes 塞满一样会撑爆响应。
|
|
18
18
|
*
|
|
19
19
|
* 128KiB 这个数的依据(实测,2026-08-12):
|
|
20
|
-
* -
|
|
20
|
+
* - 历史基线中**最大的真实 Host 声明**是 gallery 页(html 13,826 + ui 4,407 + event 1,805)
|
|
21
21
|
* = 20,038 字节。128KiB / 20,038 ≈ 6.5×,即人手写得最复杂的整站页面还能再翻 6.5 倍。
|
|
22
22
|
* - 声明仓库里 119 份 AI 生成版本的实测分布:中位 1,777 / p90 2,305 / 最大 2,995 字节,
|
|
23
23
|
* 离上限有 43 倍余量——正常生成永远撞不到这条线。
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2017",
|
|
4
|
-
"lib": [
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
5
9
|
"allowJs": true,
|
|
6
10
|
"skipLibCheck": true,
|
|
7
11
|
"strict": true,
|
|
@@ -11,16 +15,22 @@
|
|
|
11
15
|
"moduleResolution": "bundler",
|
|
12
16
|
"resolveJsonModule": true,
|
|
13
17
|
"isolatedModules": true,
|
|
14
|
-
"jsx": "
|
|
18
|
+
"jsx": "react-jsx",
|
|
15
19
|
"incremental": true,
|
|
16
20
|
"experimentalDecorators": true,
|
|
17
21
|
"emitDecoratorMetadata": true,
|
|
18
22
|
"plugins": [
|
|
19
|
-
{
|
|
23
|
+
{
|
|
24
|
+
"name": "next"
|
|
25
|
+
}
|
|
20
26
|
],
|
|
21
27
|
"paths": {
|
|
22
|
-
"@core/*": [
|
|
23
|
-
|
|
28
|
+
"@core/*": [
|
|
29
|
+
"./core/*"
|
|
30
|
+
],
|
|
31
|
+
"@/*": [
|
|
32
|
+
"./*"
|
|
33
|
+
]
|
|
24
34
|
},
|
|
25
35
|
"baseUrl": "."
|
|
26
36
|
},
|
|
@@ -29,7 +39,10 @@
|
|
|
29
39
|
"global.d.ts",
|
|
30
40
|
"**/*.ts",
|
|
31
41
|
"**/*.tsx",
|
|
32
|
-
".next/types/**/*.ts"
|
|
42
|
+
".next/types/**/*.ts",
|
|
43
|
+
".next/dev/types/**/*.ts"
|
|
33
44
|
],
|
|
34
|
-
"exclude": [
|
|
45
|
+
"exclude": [
|
|
46
|
+
"node_modules"
|
|
47
|
+
]
|
|
35
48
|
}
|