soma-core 2.2.5 → 2.2.7
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 +5 -6
- package/bin/soma.cjs +2 -2
- package/core/build/compiler/flat-page.ts +16 -0
- package/core/build/compiler/full-manifest-builder.ts +0 -3
- package/core/build/compiler/page-assets.ts +0 -1
- package/core/build/compiler/page-closure.ts +245 -0
- package/core/build/compiler/page-declaration-compiler.ts +2 -5
- package/core/build/compiler/soma-precompile.js +1972 -3312
- package/core/build/compiler/soma-precompile.ts +4 -7
- package/core/build/component-tree/artifact-codec.ts +4 -8
- package/core/build/lsp/soma-declaration.cjs +1 -1
- package/core/build/lsp/std-completion.generated.json +3 -3
- package/core/client/a11y/a11y-config.ts +2 -1
- package/core/client/a11y/dom-id.ts +1 -1
- package/core/client/base/SomaHttpClient.ts +11 -3
- package/core/client/base/SomaPageRootBase.ts +6 -0
- package/core/client/base/defineSomaView.ts +178 -0
- package/core/client/base/index.ts +13 -0
- package/core/client/base/view-context.ts +328 -0
- package/core/client/behavior/adapter-collection.ts +2 -2
- package/core/client/compiler/manifest-compiler.ts +5 -36
- package/core/client/component/component-definition.types.ts +2 -1
- package/core/client/component/component-manager.ts +110 -20
- package/core/client/component/structure-adapter.ts +3 -7
- package/core/client/container/IContainerAdapter.ts +4 -0
- package/core/client/container/SomaContainerAdapter.ts +52 -3
- package/core/client/data/data-object-resolver.ts +523 -184
- package/core/client/data/data-write-actions.ts +79 -15
- package/core/client/data/format-config.ts +3 -1
- package/core/client/data/region-scope-port.ts +11 -0
- package/core/client/engine/asset-resolver.ts +2 -5
- package/core/client/engine/dom-renderer.ts +7 -40
- package/core/client/engine/event-engine.ts +29 -108
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +78 -17
- package/core/client/engine/runtime-builder.ts +0 -14
- package/core/client/engine/scope-resolver.ts +18 -0
- package/core/client/engine/soma-bootstrap.ts +387 -99
- package/core/client/engine/style-binder.ts +49 -106
- package/core/client/engine/timer-engine.ts +11 -1
- package/core/client/host-bridge/load-host-domain-class.ts +2 -1
- package/core/client/infra/http/SomaHttpService.ts +15 -4
- package/core/client/infra/i18n/pack-locales.ts +2 -2
- package/core/client/infra/notify/DefaultNotifyService.ts +2 -2
- package/core/client/mount/domain-rule.ts +7 -3
- package/core/client/mount/mount-page.ts +38 -5
- package/core/client/mount/types.ts +2 -0
- package/core/client/parser/confirm-spec.ts +100 -7
- package/core/client/parser/data-config-parser.ts +28 -211
- package/core/client/parser/pipeline-parser.ts +16 -60
- package/core/client/parser/style-config-parser.ts +101 -95
- package/core/client/parser/timer-parser.ts +21 -0
- package/core/client/parser/ui-config-parser.ts +64 -12
- package/core/client/registry/declaration-renderer.ts +1 -1
- package/core/client/render-ports/hide-transition.ts +9 -0
- package/core/client/render-ports/index.ts +4 -0
- package/core/client/render-ports/notify-renderer.ts +2 -1
- package/core/client/runtime/SomaRuntimeServices.ts +2 -1
- package/core/client/runtime/SomaSnapshotStore.ts +5 -0
- package/core/client/security/url-guard.ts +71 -11
- package/core/client/validation/async-check-registry.ts +2 -1
- package/core/client/validation/contract-validator.ts +2 -6
- package/core/client/validation/field-rules.ts +3 -13
- package/core/client/validation/object-rules.ts +2 -10
- package/core/index.ts +17 -39
- package/core/inspect/check-product.ts +5 -5
- package/core/inspect/runtime.ts +2 -1
- package/core/server/api/dispatch-service-api.ts +35 -36
- package/core/server/api/load-host-service.ts +8 -4
- package/core/server/api/paged-list.ts +259 -0
- package/core/server/compile-port.ts +1 -1
- package/core/server/host/app-config-composer.ts +2 -1
- package/core/server/host/empty-host-bootstrap.mjs +3 -0
- package/core/server/host/host-assembly-entry.ts +1 -0
- package/core/server/host/host-assembly.ts +50 -3
- package/core/server/host/host-caller.ts +2 -1
- package/core/server/host/host-dir.ts +9 -0
- package/core/server/host/host-response-headers.ts +2 -1
- package/core/server/host/invoke-host-request-hook.ts +28 -4
- package/core/server/host/published-page-assets.ts +2 -1
- package/core/server/host/resolve-host-request-hook.ts +25 -7
- package/core/server/host/server-page-assets.ts +4 -4
- package/core/server/host/source-aliases.cjs +345 -0
- package/core/server/host/source-aliases.ts +32 -0
- package/core/server/host/source-packages.cjs +1 -0
- package/core/server/host/virtual-pages.ts +3 -2
- package/core/server/infra/cache/ServerFileCache.ts +83 -10
- package/core/server/node.ts +10 -0
- package/core/server/registry/api-registry-store.ts +3 -1
- package/core/server/registry/declaration-precompiler.ts +0 -2
- package/core/server/registry/page-registry-repository.ts +2 -1
- package/core/server/registry/page-registry-store.ts +2 -1
- package/core/server/registry/registry-error.ts +6 -1
- package/core/server/registry/registry-file-lock.ts +296 -23
- package/core/server/registry/request-body-limit.ts +3 -2
- package/core/server/registry/validation/declaration-safety-scan.ts +151 -27
- package/core/server/runtime-space/access-gate.ts +21 -7
- package/core/server/runtime-space/bindings.ts +3 -6
- package/core/server/runtime-space/dynamic-pages.ts +181 -49
- package/core/server/runtime-space/errors.ts +3 -0
- package/core/server/runtime-space/inject.ts +78 -16
- package/core/server/runtime-space/page-grants.ts +7 -1
- package/core/server/runtime-space/resolve.ts +66 -19
- package/core/server/runtime-space/store.ts +32 -3
- package/core/server/runtime-space/submit-steps.ts +2 -1
- package/core/server/runtime-space/types.ts +3 -1
- package/core/shared/component-tree-errors.ts +2 -1
- package/core/shared/contract-a11y.ts +1 -1
- package/core/shared/contract-sections.ts +2 -2
- package/core/shared/core-diagnostic-codes.ts +14 -0
- package/core/shared/data-declaration-checks.ts +29 -3
- package/core/shared/declaration-keys.ts +1 -1
- package/core/shared/engines/engine-error.ts +2 -1
- package/core/shared/generation-error.ts +2 -1
- package/core/shared/page-envelope.ts +1 -1
- package/core/shared/pure-binding.ts +88 -0
- package/core/shared/registry-generated/diagnostic-registry-index.ts +21 -19
- package/core/shared/registry-generated/diagnostic-registry.ts +170 -177
- package/core/shared/registry-generated/limits.ts +65 -13
- package/core/shared/registry-generated/std-grammar-completion.ts +0 -4
- package/core/shared/registry-generated/std-grammar-views.ts +40 -10
- package/core/shared/registry-generated/std-grammar.ts +43 -21
- package/core/shared/soma-error.ts +36 -0
- package/core/shared/types/compile-port.types.ts +1 -1
- package/core/shared/types/data-config.types.ts +20 -18
- package/core/shared/types/engine.types.ts +0 -3
- package/core/shared/types/event.types.ts +10 -11
- package/core/shared/types/generation-error.types.ts +5 -1
- package/core/shared/types/host-assembly.types.ts +7 -1
- package/core/shared/types/manifest.types.ts +0 -3
- package/core/shared/types/region-scope.types.ts +5 -1
- package/core/shared/types/scope-manifest.types.ts +0 -2
- package/core/shared/types/style-config.types.ts +21 -21
- package/core/shared/types/ui-config.types.ts +4 -5
- package/core/shared/types/watcher.types.ts +1 -1
- package/dist/browser/runtime-bundle.manifest.json +11 -13
- package/dist/browser/soma-runtime.js +2733 -2712
- package/dist/core/index.cjs +5665 -5534
- package/dist/host-native/aot-builder.cjs +330 -1
- package/dist/host-native/native-server.cjs +5434 -4726
- package/dist/lsp/component-tree.cjs +5868 -7040
- package/dist/types/build/compiler/full-manifest-builder.d.ts +0 -2
- package/dist/types/build/compiler/page-closure.d.ts +21 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -4
- package/dist/types/build/compiler/soma-precompile.d.ts +1 -3
- package/dist/types/build/component-tree/artifact-codec.d.ts +0 -2
- package/dist/types/client/a11y/a11y-config.d.ts +2 -1
- package/dist/types/client/base/SomaHttpClient.d.ts +1 -1
- package/dist/types/client/base/SomaPageRootBase.d.ts +5 -0
- package/dist/types/client/base/defineSomaView.d.ts +46 -0
- package/dist/types/client/base/index.d.ts +2 -0
- package/dist/types/client/base/view-context.d.ts +136 -0
- package/dist/types/client/behavior/adapter-collection.d.ts +1 -1
- package/dist/types/client/compiler/manifest-compiler.d.ts +0 -3
- package/dist/types/client/component/component-definition.types.d.ts +2 -1
- package/dist/types/client/component/component-manager.d.ts +29 -0
- package/dist/types/client/container/IContainerAdapter.d.ts +3 -0
- package/dist/types/client/container/SomaContainerAdapter.d.ts +5 -0
- package/dist/types/client/data/data-object-resolver.d.ts +93 -31
- package/dist/types/client/data/format-config.d.ts +2 -1
- package/dist/types/client/engine/dom-renderer.d.ts +1 -2
- package/dist/types/client/engine/event-engine.d.ts +0 -7
- package/dist/types/client/engine/reactive-proxy.d.ts +11 -4
- package/dist/types/client/engine/runtime-builder.d.ts +0 -4
- package/dist/types/client/engine/soma-bootstrap.d.ts +44 -6
- package/dist/types/client/engine/style-binder.d.ts +8 -4
- package/dist/types/client/host-bridge/load-host-domain-class.d.ts +2 -1
- package/dist/types/client/mount/domain-rule.d.ts +2 -0
- package/dist/types/client/mount/mount-page.d.ts +2 -1
- package/dist/types/client/mount/types.d.ts +2 -0
- package/dist/types/client/parser/confirm-spec.d.ts +27 -3
- package/dist/types/client/parser/data-config-parser.d.ts +6 -5
- package/dist/types/client/parser/style-config-parser.d.ts +7 -3
- package/dist/types/client/parser/timer-parser.d.ts +5 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +6 -2
- package/dist/types/client/render-ports/hide-transition.d.ts +9 -0
- package/dist/types/client/render-ports/index.d.ts +4 -0
- package/dist/types/client/render-ports/notify-renderer.d.ts +2 -1
- package/dist/types/client/runtime/SomaSnapshotStore.d.ts +2 -0
- package/dist/types/client/security/url-guard.d.ts +14 -0
- package/dist/types/client/validation/async-check-registry.d.ts +2 -1
- package/dist/types/client/validation/object-rules.d.ts +0 -5
- package/dist/types/index.d.ts +6 -11
- package/dist/types/inspect/runtime.d.ts +2 -1
- package/dist/types/server/api/dispatch-service-api.d.ts +5 -0
- package/dist/types/server/api/load-host-service.d.ts +1 -1
- package/dist/types/server/api/paged-list.d.ts +101 -0
- package/dist/types/server/compile-port.d.ts +1 -1
- package/dist/types/server/host/host-assembly-entry.d.ts +1 -1
- package/dist/types/server/host/host-assembly.d.ts +2 -0
- package/dist/types/server/host/host-dir.d.ts +2 -0
- package/dist/types/server/host/invoke-host-request-hook.d.ts +10 -3
- package/dist/types/server/host/published-page-assets.d.ts +2 -1
- package/dist/types/server/host/resolve-host-request-hook.d.ts +18 -5
- package/dist/types/server/host/server-page-assets.d.ts +2 -1
- package/dist/types/server/host/source-aliases.d.cts +53 -0
- package/dist/types/server/host/source-aliases.d.ts +30 -0
- package/dist/types/server/host/source-packages.d.cts +2 -0
- package/dist/types/server/infra/cache/ServerFileCache.d.ts +8 -0
- package/dist/types/server/node.d.ts +1 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +0 -1
- package/dist/types/server/registry/registry-error.d.ts +5 -1
- package/dist/types/server/registry/registry-file-lock.d.ts +30 -0
- package/dist/types/server/registry/request-body-limit.d.ts +3 -2
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +3 -0
- package/dist/types/server/runtime-space/access-gate.d.ts +7 -0
- package/dist/types/server/runtime-space/bindings.d.ts +3 -2
- package/dist/types/server/runtime-space/dynamic-pages.d.ts +6 -1
- package/dist/types/server/runtime-space/errors.d.ts +1 -1
- package/dist/types/server/runtime-space/resolve.d.ts +2 -0
- package/dist/types/server/runtime-space/store.d.ts +8 -1
- package/dist/types/server/runtime-space/submit-steps.d.ts +2 -1
- package/dist/types/server/runtime-space/types.d.ts +3 -1
- package/dist/types/shared/component-tree-errors.d.ts +2 -1
- package/dist/types/shared/core-diagnostic-codes.d.ts +1 -1
- package/dist/types/shared/declaration-keys.d.ts +1 -1
- package/dist/types/shared/engines/engine-error.d.ts +2 -1
- package/dist/types/shared/generation-error.d.ts +2 -1
- package/dist/types/shared/pure-binding.d.ts +48 -0
- package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +149 -158
- package/dist/types/shared/registry-generated/limits.d.ts +54 -10
- package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +0 -30
- package/dist/types/shared/registry-generated/std-grammar-views.d.ts +97 -23
- package/dist/types/shared/registry-generated/std-grammar.d.ts +110 -242
- package/dist/types/shared/soma-error.d.ts +15 -0
- package/dist/types/shared/types/data-config.types.d.ts +17 -17
- package/dist/types/shared/types/engine.types.d.ts +0 -3
- package/dist/types/shared/types/event.types.d.ts +9 -7
- package/dist/types/shared/types/generation-error.types.d.ts +1 -1
- package/dist/types/shared/types/host-assembly.types.d.ts +2 -0
- package/dist/types/shared/types/manifest.types.d.ts +0 -3
- package/dist/types/shared/types/region-scope.types.d.ts +4 -1
- package/dist/types/shared/types/scope-manifest.types.d.ts +0 -2
- package/dist/types/shared/types/style-config.types.d.ts +17 -19
- package/dist/types/shared/types/ui-config.types.d.ts +4 -5
- package/host-native/bin/host-native.cjs +22 -1
- package/host-native/client/browser-entry.ts +21 -172
- package/host-native/src/aot-builder.ts +75 -0
- package/host-native/src/host-prepare.ts +39 -5
- package/host-native/src/manifest-http.ts +2 -3
- package/host-native/src/native-server.ts +812 -174
- package/host-native/src/page-http.ts +3 -3
- package/host-native/src/public-packages.cjs +0 -1
- package/host-native/src/registry-handler.ts +12 -5
- package/host-native/src/static-file.ts +203 -53
- package/host-native/styles/globals.css +30 -28
- package/package.json +14 -2
- package/core/client/engine/step-runner.ts +0 -212
- package/core/client/engine/trigger-engine.ts +0 -55
- package/core/client/format/zoned.ts +0 -10
- package/core/client/parser/step-parser.ts +0 -359
- package/core/client/parser/trigger-parser.ts +0 -90
- package/core/client/parser/value-lang.ts +0 -340
- package/core/client/time/instant.ts +0 -2
- package/core/shared/calc/coerce.ts +0 -2
- package/core/shared/calc/errors.ts +0 -40
- package/core/shared/calc/evaluator.ts +0 -113
- package/core/shared/calc/index.ts +0 -11
- package/core/shared/calc/lexer.ts +0 -189
- package/core/shared/calc/parser.ts +0 -193
- package/core/shared/calc/typer.ts +0 -171
- package/core/shared/date-parts.ts +0 -2
- package/core/shared/show-when.ts +0 -77
- package/core/shared/types/step.types.ts +0 -91
- package/core/shared/types/trigger.types.ts +0 -14
- package/dist/types/client/engine/step-runner.d.ts +0 -42
- package/dist/types/client/engine/trigger-engine.d.ts +0 -16
- package/dist/types/client/format/zoned.d.ts +0 -1
- package/dist/types/client/parser/step-parser.d.ts +0 -23
- package/dist/types/client/parser/trigger-parser.d.ts +0 -13
- package/dist/types/client/parser/value-lang.d.ts +0 -63
- package/dist/types/client/time/instant.d.ts +0 -1
- package/dist/types/shared/calc/coerce.d.ts +0 -1
- package/dist/types/shared/calc/errors.d.ts +0 -14
- package/dist/types/shared/calc/evaluator.d.ts +0 -2
- package/dist/types/shared/calc/index.d.ts +0 -6
- package/dist/types/shared/calc/lexer.d.ts +0 -19
- package/dist/types/shared/calc/parser.d.ts +0 -43
- package/dist/types/shared/calc/typer.d.ts +0 -11
- package/dist/types/shared/date-parts.d.ts +0 -1
- package/dist/types/shared/show-when.d.ts +0 -21
- package/dist/types/shared/types/step.types.d.ts +0 -76
- package/dist/types/shared/types/trigger.types.d.ts +0 -12
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// 可诊断性,并在控制台给出可定位的告警。
|
|
12
12
|
|
|
13
13
|
/** 会被浏览器当作 URL 加载/跳转的属性 */
|
|
14
|
-
const
|
|
14
|
+
export const URL_BEARING_ATTR_NAMES = [
|
|
15
15
|
'href',
|
|
16
16
|
'src',
|
|
17
17
|
'srcset',
|
|
@@ -22,25 +22,68 @@ const URL_BEARING_ATTRS = new Set([
|
|
|
22
22
|
'xlink:href',
|
|
23
23
|
'ping',
|
|
24
24
|
'background',
|
|
25
|
-
]
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
export const URL_BEARING_ATTRS: ReadonlySet<string> = new Set(URL_BEARING_ATTR_NAMES);
|
|
26
28
|
|
|
27
29
|
/** 危险伪协议:命中即阻断 */
|
|
28
|
-
const BLOCKED_SCHEMES = ['javascript:', 'vbscript:', 'data:', 'file:', 'blob:'];
|
|
30
|
+
export const BLOCKED_SCHEMES = ['javascript:', 'vbscript:', 'data:', 'file:', 'blob:'] as const;
|
|
31
|
+
|
|
32
|
+
/** 纯位图图片 data URI:在媒体展示属性(src/srcset/poster/background)上安全 */
|
|
33
|
+
const SAFE_RASTER_DATA_URI = /^data:image\/(png|jpe?g|gif|webp|avif);base64,/i;
|
|
29
34
|
|
|
30
|
-
/**
|
|
35
|
+
/** svg+xml data URI:即使是媒体展示也仅限 src/poster/background(不放行 srcset,更绝不在导航/提交属性上放行) */
|
|
36
|
+
const SAFE_SVG_DATA_URI = /^data:image\/svg\+xml;base64,/i;
|
|
37
|
+
|
|
38
|
+
/** data: 的白名单例外——图片类 data URI 全集(用于 resolveSafeUrl 的 allowDataImage) */
|
|
31
39
|
const SAFE_DATA_URI = /^data:image\/(png|jpe?g|gif|webp|avif|svg\+xml);base64,/i;
|
|
32
40
|
|
|
33
41
|
/** 拦截后写入的安全占位值 */
|
|
34
42
|
export const BLOCKED_URL_PLACEHOLDER = 'about:blank';
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
/**
|
|
45
|
+
* 解码基础 HTML 实体(命名实体 : / &tab; / &newline;、十进制 &#...; 与十六进制 &#x...;)
|
|
46
|
+
* 用于防范利用 HTML 实体编码混淆伪协议前缀绕过安全检查。
|
|
47
|
+
*/
|
|
48
|
+
export function decodeHtmlEntities(str: string): string {
|
|
49
|
+
return str
|
|
50
|
+
.replace(/&(?:colon|tab|newline);/gi, (match) => {
|
|
51
|
+
const lower = match.toLowerCase();
|
|
52
|
+
if (lower === ':') return ':';
|
|
53
|
+
if (lower === '&tab;') return '\t';
|
|
54
|
+
if (lower === '&newline;') return '\n';
|
|
55
|
+
return match;
|
|
56
|
+
})
|
|
57
|
+
.replace(/&#x([0-9a-fA-F]+);?/g, (_, hex) => {
|
|
58
|
+
try {
|
|
59
|
+
const cp = parseInt(hex, 16);
|
|
60
|
+
return cp >= 0 && cp <= 0x10ffff ? String.fromCodePoint(cp) : '';
|
|
61
|
+
} catch {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.replace(/&#([0-9]+);?/g, (_, dec) => {
|
|
66
|
+
try {
|
|
67
|
+
const cp = parseInt(dec, 10);
|
|
68
|
+
return cp >= 0 && cp <= 0x10ffff ? String.fromCodePoint(cp) : '';
|
|
69
|
+
} catch {
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 归一化 URL 文本:先解码 HTML 实体,再去除所有空白与控制字符,再小写。
|
|
77
|
+
*/
|
|
78
|
+
export function normalizeUrlValue(value: string): string {
|
|
79
|
+
return decodeHtmlEntities(value)
|
|
80
|
+
.replace(/[\u0000-\u0020\u007f-\u009f\s]/g, '')
|
|
81
|
+
.toLowerCase();
|
|
39
82
|
}
|
|
40
83
|
|
|
41
84
|
/** URL 的协议名(小写、不含冒号);相对地址或无协议返回 null。判定核:hasBlockedScheme 与 resolveSafeUrl 共用 */
|
|
42
85
|
export function urlSchemeOf(value: string): string | null {
|
|
43
|
-
const matched = /^([a-z][a-z0-9+.-]*):/.exec(
|
|
86
|
+
const matched = /^([a-z][a-z0-9+.-]*):/.exec(normalizeUrlValue(value));
|
|
44
87
|
return matched ? matched[1] : null;
|
|
45
88
|
}
|
|
46
89
|
|
|
@@ -49,16 +92,33 @@ export function isEventHandlerAttribute(attrName: string): boolean {
|
|
|
49
92
|
return /^on[a-z]+$/i.test(attrName);
|
|
50
93
|
}
|
|
51
94
|
|
|
95
|
+
/**
|
|
96
|
+
* 判断是否属于受允许的 data: URI 白名单例外:
|
|
97
|
+
* 仅对纯媒体展示属性(src/srcset/poster/background)生效,且对 svg+xml 仅限 src/poster/background;
|
|
98
|
+
* 导航与提交属性(href/action/formaction/xlink:href/data/ping)上绝不放行任何 data: 协议。
|
|
99
|
+
*/
|
|
100
|
+
function isAllowedDataUri(attrLower: string, value: string): boolean {
|
|
101
|
+
const trimmed = value.trim();
|
|
102
|
+
if (['src', 'srcset', 'poster', 'background'].includes(attrLower) && SAFE_RASTER_DATA_URI.test(trimmed)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (['src', 'poster', 'background'].includes(attrLower) && SAFE_SVG_DATA_URI.test(trimmed)) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
52
111
|
/** 该属性值是否含危险 scheme */
|
|
53
112
|
export function hasBlockedScheme(attrName: string, value: string): boolean {
|
|
54
|
-
|
|
113
|
+
const attrLower = attrName.toLowerCase();
|
|
114
|
+
if (!URL_BEARING_ATTRS.has(attrLower)) {
|
|
55
115
|
return false;
|
|
56
116
|
}
|
|
57
|
-
if (
|
|
117
|
+
if (isAllowedDataUri(attrLower, value)) {
|
|
58
118
|
return false;
|
|
59
119
|
}
|
|
60
120
|
const scheme = urlSchemeOf(value);
|
|
61
|
-
return scheme !== null && BLOCKED_SCHEMES.includes(`${scheme}:`);
|
|
121
|
+
return scheme !== null && (BLOCKED_SCHEMES as readonly string[]).includes(`${scheme}:`);
|
|
62
122
|
}
|
|
63
123
|
|
|
64
124
|
/** 任何策略下都不放行的协议 */
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// 检查器签名沿用 `SomaAsyncFieldChecker`(`async-rules.ts`):`(input) => Promise<{ outcome: 'valid' | 'invalid' | 'error', message? }>`。
|
|
15
15
|
// 纯逻辑、无 DOM。
|
|
16
16
|
|
|
17
|
+
import { SomaError } from '../../shared/soma-error';
|
|
17
18
|
import type { SomaAsyncFieldChecker } from './async-rules';
|
|
18
19
|
|
|
19
20
|
/** 登记表:`{ 检查器名: 检查器 }` */
|
|
@@ -31,7 +32,7 @@ export interface SomaValidationService {
|
|
|
31
32
|
|
|
32
33
|
export type SomaAsyncCheckErrorCode = 'CORE-ASYNC-CHECK-TABLE' | 'CORE-ASYNC-CHECK-UNREGISTERED';
|
|
33
34
|
|
|
34
|
-
export class SomaAsyncCheckError extends
|
|
35
|
+
export class SomaAsyncCheckError extends SomaError {
|
|
35
36
|
constructor(readonly code: SomaAsyncCheckErrorCode, message: string, readonly names: readonly string[] = []) {
|
|
36
37
|
super(`[${code}] ${message}`);
|
|
37
38
|
this.name = 'SomaAsyncCheckError';
|
|
@@ -256,7 +256,7 @@ export class SomaContractValidator {
|
|
|
256
256
|
}
|
|
257
257
|
if (value.when) {
|
|
258
258
|
this.validateReadablePath(
|
|
259
|
-
|
|
259
|
+
value.when,
|
|
260
260
|
`${currentPath}.when`,
|
|
261
261
|
resolver,
|
|
262
262
|
rootInstance,
|
|
@@ -344,16 +344,12 @@ export class SomaContractValidator {
|
|
|
344
344
|
rootInstance: object,
|
|
345
345
|
report: SomaContractReport,
|
|
346
346
|
): void {
|
|
347
|
-
|
|
347
|
+
const path = rawPath.trim();
|
|
348
348
|
if (!path) {
|
|
349
349
|
this.addError(report, `${location}: 绑定路径不能为空`);
|
|
350
350
|
return;
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
if (path.startsWith('!')) {
|
|
354
|
-
path = path.slice(1);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
353
|
const segments = path.split('.').filter(Boolean);
|
|
358
354
|
if (segments.length === 0) {
|
|
359
355
|
this.addError(report, `${location}: 绑定路径不能为空`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 字段规则求值核在通用值区 `soma-foundation/values`;页面规则只有 required / 长度 / 范围 / 正则 / 步长 / async,不含条件求值,这里原样转出。
|
|
2
2
|
import {
|
|
3
3
|
checkField as checkFieldBase,
|
|
4
4
|
checkFieldAll as checkFieldAllBase,
|
|
@@ -6,16 +6,6 @@ import {
|
|
|
6
6
|
type FieldRule,
|
|
7
7
|
type RuleFailure,
|
|
8
8
|
} from 'soma-foundation/values';
|
|
9
|
-
import {
|
|
10
|
-
evaluatePredicate,
|
|
11
|
-
type SomaFieldPredicate as CorePredicate,
|
|
12
|
-
type SomaNamedPredicates as CoreNamedPredicates,
|
|
13
|
-
} from '../../shared/predicates';
|
|
14
|
-
|
|
15
|
-
/** core 装好的求值端口:算子名在基础区是泛型 string,这里收窄回 core 的算子闭集 */
|
|
16
|
-
const evaluateWithCore: NonNullable<FieldCheckContext['evaluate']> = (predicate, values, named) =>
|
|
17
|
-
evaluatePredicate(predicate as CorePredicate, values, named as CoreNamedPredicates | undefined);
|
|
18
|
-
|
|
19
9
|
export {
|
|
20
10
|
RULE_MESSAGE_KEYS,
|
|
21
11
|
SOMA_ASYNC_UNAVAILABLE_I18N_KEY,
|
|
@@ -36,7 +26,7 @@ export function checkField(
|
|
|
36
26
|
value: unknown,
|
|
37
27
|
context: FieldCheckContext = {},
|
|
38
28
|
): RuleFailure | null {
|
|
39
|
-
return checkFieldBase(rules, value,
|
|
29
|
+
return checkFieldBase(rules, value, context);
|
|
40
30
|
}
|
|
41
31
|
|
|
42
32
|
/** 单字段校验,返回全部失败(含非 hard 档) */
|
|
@@ -45,5 +35,5 @@ export function checkFieldAll(
|
|
|
45
35
|
value: unknown,
|
|
46
36
|
context: FieldCheckContext = {},
|
|
47
37
|
): RuleFailure[] {
|
|
48
|
-
return checkFieldAllBase(rules, value,
|
|
38
|
+
return checkFieldAllBase(rules, value, context);
|
|
49
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 对象级记录校验(WP3b-A S4 / S8 / S9 的运行期兑现):按数据对象字典一次校验一份表单值。
|
|
2
2
|
//
|
|
3
|
-
// 声明面:字段 `rules
|
|
3
|
+
// 声明面:字段 `rules`、写通道 `validate_on`(校验时机)。
|
|
4
4
|
// 求值核仍是 `checkField`(长度按码点,AD-15)。
|
|
5
5
|
// 日期粒度、时间型值形状、链接策略等领域值协议不在 core:方言装配层经 `protocolCheck` 入参接入
|
|
6
6
|
// (链接策略可直接用 `security/url-guard` 的 `resolveSafeUrl`)。
|
|
@@ -10,7 +10,6 @@ import type {
|
|
|
10
10
|
SomaDataWriteConfig,
|
|
11
11
|
SomaValidateTrigger,
|
|
12
12
|
} from '../../shared/types/data-config.types';
|
|
13
|
-
import type { SomaNamedPredicates } from '../../shared/predicates';
|
|
14
13
|
import { checkFieldAll, isBlank, severityOfFailure, type RuleFailure } from './field-rules';
|
|
15
14
|
|
|
16
15
|
/** 写通道声明的校验时机里有没有这一个:没声明 `validate_on` 恒为真(时机由调用方决定,存量口径) */
|
|
@@ -21,10 +20,6 @@ export function shouldValidateOn(write: Pick<SomaDataWriteConfig, 'validate_on'>
|
|
|
21
20
|
export interface ObjectRecordCheckOptions {
|
|
22
21
|
/** 只校验这些字段(缺省 = 字典里全部字段) */
|
|
23
22
|
readonly keys?: readonly string[];
|
|
24
|
-
/** 对象的具名谓词表(条件规则的 `{ ref }`) */
|
|
25
|
-
readonly named?: SomaNamedPredicates;
|
|
26
|
-
/** 条件规则的求值记录(缺省 = `record` 本身);数据端口传「读态 ∪ 表单值」 */
|
|
27
|
-
readonly context?: Readonly<Record<string, unknown>>;
|
|
28
23
|
/** 方言接入的领域值协议检查(日期粒度、时间型值形状等):非空值逐字段调用,返回失败或 null;缺省不检查 */
|
|
29
24
|
readonly protocolCheck?: (field: SomaDataFieldConfig, value: unknown) => RuleFailure | null;
|
|
30
25
|
}
|
|
@@ -44,10 +39,7 @@ export function validateObjectRecordGraded(
|
|
|
44
39
|
const field = Object.hasOwn(fields, key) ? fields[key] : undefined;
|
|
45
40
|
if (field === undefined) continue;
|
|
46
41
|
const value = record[key];
|
|
47
|
-
const failures = checkFieldAll(field.rules, value
|
|
48
|
-
record: options.context ?? record,
|
|
49
|
-
...(options.named !== undefined ? { named: options.named } : {}),
|
|
50
|
-
});
|
|
42
|
+
const failures = checkFieldAll(field.rules, value);
|
|
51
43
|
if (!isBlank(value)) {
|
|
52
44
|
const protocol = options.protocolCheck?.(field, value) ?? null;
|
|
53
45
|
if (protocol !== null) failures.push(protocol);
|
package/core/index.ts
CHANGED
|
@@ -45,7 +45,6 @@ export {
|
|
|
45
45
|
parseDataConfig,
|
|
46
46
|
parseDataYaml,
|
|
47
47
|
parseDataRef,
|
|
48
|
-
normalizeDataPipeValue,
|
|
49
48
|
SomaDataConfigError,
|
|
50
49
|
// 对象声明的各层键集:AI 提示词词汇、闸门共用同一份,不得本地抄一份——
|
|
51
50
|
// 抄本漂开那天的表现是「能写、不报错、值被静默丢弃」
|
|
@@ -116,12 +115,6 @@ export type {
|
|
|
116
115
|
SomaPredicateValidateOptions,
|
|
117
116
|
} from './shared/predicates';
|
|
118
117
|
|
|
119
|
-
// 动作编排:一个交互按顺序做好几件事。编排图是纯数据——
|
|
120
|
-
// 可画、可 diff、可在编译期判定可终止性。逃生舱是具名动作注册表,不是脚本。
|
|
121
|
-
export { parseSteps } from './client/parser/step-parser';
|
|
122
|
-
export type { StepParseInput, StepParseDeps } from './client/parser/step-parser';
|
|
123
|
-
export { runSteps } from './client/engine/step-runner';
|
|
124
|
-
|
|
125
118
|
// 页面态切片:分享链接与地址栏同步共用一套结构。
|
|
126
119
|
export {
|
|
127
120
|
parsePageState,
|
|
@@ -134,18 +127,6 @@ export type {
|
|
|
134
127
|
SomaPageState,
|
|
135
128
|
SomaPageStateConfig,
|
|
136
129
|
} from './shared/types/page-state.types';
|
|
137
|
-
export type { StepRunContext, StepRunResult } from './client/engine/step-runner';
|
|
138
|
-
export type {
|
|
139
|
-
SomaStep,
|
|
140
|
-
SomaDoStep,
|
|
141
|
-
SomaSwitchStep,
|
|
142
|
-
SomaParallelStep,
|
|
143
|
-
SomaForEachStep,
|
|
144
|
-
SomaStepOnError,
|
|
145
|
-
SomaStepSlot,
|
|
146
|
-
SomaCompiledStep,
|
|
147
|
-
SomaStepGraph,
|
|
148
|
-
} from './shared/types/step.types';
|
|
149
130
|
|
|
150
131
|
// ── 调度原语两件套(F-11 – F-14 / 契约 C7)──
|
|
151
132
|
// 也可经 `soma-core/scheduling` 子路径单独引入:不 attach 即不加载不执行。
|
|
@@ -337,14 +318,26 @@ export type { IRealtimeTransport, RealtimeMessageHandler } from './client/infra/
|
|
|
337
318
|
export type { IRealtimeService, RealtimeSubscribeOptions } from './client/infra/realtime/IRealtimeService';
|
|
338
319
|
export { SseRealtimeTransport } from './client/infra/realtime/SseRealtimeTransport';
|
|
339
320
|
export { WebSocketRealtimeTransport } from './client/infra/realtime/WebSocketRealtimeTransport';
|
|
340
|
-
export type { NotifyEntry, NotifyRenderer, RegionFallbackRenderer, SomaRenderPorts } from './client/render-ports';
|
|
321
|
+
export type { HideTransition, NotifyEntry, NotifyRenderer, RegionFallbackRenderer, SomaRenderPorts } from './client/render-ports';
|
|
341
322
|
export type { SomaEngineAdapters, SomaEngineId } from './client/engines/engine-adapters';
|
|
342
323
|
export type { INotifyService, NotifyOptions, NotifyLevel, NotifyCarrier, NotifyAction } from './client/infra/notify/INotifyService';
|
|
343
324
|
export { DefaultNotifyService, createNotifyService } from './client/infra/notify/DefaultNotifyService';
|
|
344
325
|
// 确认分级(R-23):规格类型、对象 / 段文本判据、确认钮判定与键盘判定(渲染端口共用)
|
|
345
|
-
export type { SomaConfirmSpec, SomaConfirmLevel } from './shared/types/event.types';
|
|
346
|
-
export {
|
|
347
|
-
|
|
326
|
+
export type { SomaConfirmSpec, SomaConfirmLevel, SomaConfirmTone } from './shared/types/event.types';
|
|
327
|
+
export {
|
|
328
|
+
SOMA_CONFIRM_TONES,
|
|
329
|
+
checkConfirmSpec,
|
|
330
|
+
parseConfirmSegment,
|
|
331
|
+
confirmSatisfied,
|
|
332
|
+
confirmKeyAccepts,
|
|
333
|
+
confirmContextOf,
|
|
334
|
+
listConfirmPlaceholders,
|
|
335
|
+
resolveConfirmSpec,
|
|
336
|
+
substituteConfirmText,
|
|
337
|
+
SOMA_CONFIRM_MISSING,
|
|
338
|
+
SOMA_CONFIRM_COUNT_NAME,
|
|
339
|
+
} from './client/parser/confirm-spec';
|
|
340
|
+
export type { SomaConfirmInput, SomaConfirmCheck, SomaConfirmSegment, SomaConfirmContext } from './client/parser/confirm-spec';
|
|
348
341
|
export { SomaRealtimeService } from './client/infra/realtime/SomaRealtimeService';
|
|
349
342
|
export { SomaMiddlewareChain } from './client/middleware/SomaMiddlewareChain';
|
|
350
343
|
export { createPermissionMiddleware } from './client/middleware/createPermissionMiddleware';
|
|
@@ -424,26 +417,11 @@ export {
|
|
|
424
417
|
type PackLocalesIssue,
|
|
425
418
|
} from './client/infra/i18n/pack-locales';
|
|
426
419
|
|
|
427
|
-
// 值语言(REQ-005 F4):算术六词元 + 管道链的唯一值规则。
|
|
428
|
-
// 规格见 soma-core/doc/soma DSL 语法全书.md 值语言一节(纯函数、无依赖)。
|
|
429
|
-
export {
|
|
430
|
-
parseValueSegment,
|
|
431
|
-
evaluateValueNode,
|
|
432
|
-
isArithSegment,
|
|
433
|
-
isPlainPath,
|
|
434
|
-
describeNode,
|
|
435
|
-
SomaValueLangError,
|
|
436
|
-
type ValueNode,
|
|
437
|
-
type PipedValue,
|
|
438
|
-
type ValuePosition,
|
|
439
|
-
type HasVarFn,
|
|
440
|
-
type EvalOptions,
|
|
441
|
-
} from './client/parser/value-lang';
|
|
442
|
-
|
|
443
420
|
// 四件套编译与 HTML 锚点扫描的值函数只在 `soma-core/server/page-declaration`。
|
|
444
421
|
// 根入口保留类型,不能让客户端加载页面编译实现。
|
|
445
422
|
export type { CompiledFlatPage, FlatPageInput, SomaFlatDoc } from './build/compiler/flat-page';
|
|
446
423
|
export { SomaDeclarationError } from './shared/declaration-errors';
|
|
424
|
+
export { SomaError, isSomaError, somaErrorCodeOf } from './shared/soma-error';
|
|
447
425
|
export type { HtmlAnchorIndex, HtmlAnchorInfo } from './build/compiler/html-index';
|
|
448
426
|
// 统一寻址(AD-49):页面 html 与 fragments.regions[].html 共用一个 data-soma-id 空间
|
|
449
427
|
export {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import fs from 'node:fs';
|
|
15
15
|
import path from 'node:path';
|
|
16
16
|
import yaml from 'js-yaml';
|
|
17
|
-
import { compileFlatPage, flatUiNonStandardKeys, type CompiledFlatPage, type SomaFlatDoc } from '../build/compiler/flat-page';
|
|
17
|
+
import { compileFlatPage, flatUiNonStandardKeys, readFlatDoc, type CompiledFlatPage, type SomaFlatDoc } from '../build/compiler/flat-page';
|
|
18
18
|
import { expandSomaHtmlIncludes } from '../build/compiler/html-include-expander';
|
|
19
19
|
import {
|
|
20
20
|
compilePageDeclaration,
|
|
@@ -177,13 +177,14 @@ export function validateCoreProduct(
|
|
|
177
177
|
}
|
|
178
178
|
if (nonStandard.length > 0) return done();
|
|
179
179
|
let compiled: CompiledFlatPage;
|
|
180
|
+
let rawEvent: Record<string, unknown> = {};
|
|
180
181
|
try {
|
|
181
182
|
compiled = compileFlatPage({
|
|
182
183
|
html,
|
|
183
184
|
uiYaml: input.uiYaml,
|
|
184
|
-
...(input.eventYaml !== undefined ? { eventYaml: input.eventYaml } : {}),
|
|
185
185
|
...(input.styleYaml !== undefined ? { styleYaml: input.styleYaml } : {}),
|
|
186
186
|
});
|
|
187
|
+
rawEvent = readFlatDoc(input.eventYaml, 'event');
|
|
187
188
|
} catch (error) {
|
|
188
189
|
report(SOMA_CORE_CHECK_CODES.blocks, 'blocks', '', messageOf(error));
|
|
189
190
|
return done();
|
|
@@ -217,7 +218,7 @@ export function validateCoreProduct(
|
|
|
217
218
|
// ⑤ 事件管道
|
|
218
219
|
let events: readonly ParsedEvent[] = [];
|
|
219
220
|
try {
|
|
220
|
-
events = compileEventConfigFromRaw(
|
|
221
|
+
events = compileEventConfigFromRaw(rawEvent).events;
|
|
221
222
|
} catch (error) {
|
|
222
223
|
report(SOMA_CORE_CHECK_CODES.events, 'events', '', messageOf(error));
|
|
223
224
|
}
|
|
@@ -281,7 +282,7 @@ const sortedKeys = (value: unknown): string[] => (isRecord(value) ? Object.keys(
|
|
|
281
282
|
function dumpField(raw: unknown): SomaDumpField {
|
|
282
283
|
const field = isRecord(raw) ? raw : {};
|
|
283
284
|
const rules = Array.isArray(field.rules)
|
|
284
|
-
? [...new Set(field.rules.flatMap((rule) => (isRecord(rule) ? Object.keys(rule).filter((key) => key !== 'message'
|
|
285
|
+
? [...new Set(field.rules.flatMap((rule) => (isRecord(rule) ? Object.keys(rule).filter((key) => key !== 'message') : [])))].sort()
|
|
285
286
|
: [];
|
|
286
287
|
const options = Array.isArray(field.options)
|
|
287
288
|
? field.options.filter(isRecord).map((option) => ({
|
|
@@ -414,7 +415,6 @@ function eventTarget(event: ParsedEvent): string | undefined {
|
|
|
414
415
|
return `${event.scope.scope}:${event.scope.verb}${tail ? `:${tail}` : ''}`;
|
|
415
416
|
}
|
|
416
417
|
if (event.notify) return `notify:${event.notify.level}`;
|
|
417
|
-
if (event.steps) return 'steps';
|
|
418
418
|
return event.funcPath ?? event.targetUrl ?? (event.targetId !== undefined ? `${event.targetId}:${event.action ?? 'toggle'}` : undefined);
|
|
419
419
|
}
|
|
420
420
|
|
package/core/inspect/runtime.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// 只增不减(M03 / M26 / 目标架构):observe / runtimeBundle / styleKeys / SomaRuntimeExitError / setLocale /
|
|
5
5
|
// evaluatePredicate / 最小数据端口类型。
|
|
6
6
|
|
|
7
|
+
import { SomaError } from '../shared/soma-error';
|
|
7
8
|
import fs from 'node:fs';
|
|
8
9
|
import path from 'node:path';
|
|
9
10
|
import { fileURLToPath } from 'node:url';
|
|
@@ -32,7 +33,7 @@ export { evaluatePredicate } from '../shared/predicates';
|
|
|
32
33
|
export type { SomaDataPort } from '../shared/types/data-config.types';
|
|
33
34
|
|
|
34
35
|
/** 运行出口的可辨认错误(testkit 据 code 报 ERR-VERIFY-EXIT-MODE) */
|
|
35
|
-
export class SomaRuntimeExitError extends
|
|
36
|
+
export class SomaRuntimeExitError extends SomaError {
|
|
36
37
|
readonly code: 'CORE-OBSERVE-OFF';
|
|
37
38
|
constructor(code: 'CORE-OBSERVE-OFF', message: string) {
|
|
38
39
|
super(message);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import type { IService } from "./IService";
|
|
2
3
|
import {
|
|
3
4
|
getAotServiceResolver,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
} from "./load-host-service";
|
|
7
8
|
import { invokeHostRequestHook } from "../host/invoke-host-request-hook";
|
|
8
9
|
import { withHostResponseHeaders } from "../host/host-response-headers";
|
|
10
|
+
import { currentHostDir } from "../host/host-dir";
|
|
9
11
|
|
|
10
12
|
export interface RequestCookie {
|
|
11
13
|
readonly name: string;
|
|
@@ -21,6 +23,11 @@ export interface RequestCookiesAdapter {
|
|
|
21
23
|
export interface DispatchHostServiceApiOptions {
|
|
22
24
|
readonly segments?: readonly string[];
|
|
23
25
|
readonly hostDir?: string;
|
|
26
|
+
/**
|
|
27
|
+
* 内部选项:标记宿主壳是否已经执行过请求钩子。
|
|
28
|
+
* 仅供原生宿主壳(如 native-server)在读请求体前已执行过鉴权钩子时使用,为 true 时避免重复执行钩子。
|
|
29
|
+
*/
|
|
30
|
+
readonly requestHookHandled?: boolean;
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
function parseCookieHeader(headerValue: string | null): RequestCookiesAdapter {
|
|
@@ -116,7 +123,7 @@ export async function dispatchHostServiceApiRequest(
|
|
|
116
123
|
? { segments: segmentsOrOptions }
|
|
117
124
|
: (segmentsOrOptions as DispatchHostServiceApiOptions | undefined);
|
|
118
125
|
|
|
119
|
-
const hostDir = options?.hostDir ??
|
|
126
|
+
const hostDir = options?.hostDir ?? currentHostDir();
|
|
120
127
|
|
|
121
128
|
let segments: string[];
|
|
122
129
|
if (options?.segments && options.segments.length > 0) {
|
|
@@ -132,15 +139,22 @@ export async function dispatchHostServiceApiRequest(
|
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
const pathname = polyfilledReq.nextUrl.pathname;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
if (!options?.requestHookHandled) {
|
|
143
|
+
const rejected = await invokeHostRequestHook(
|
|
144
|
+
polyfilledReq,
|
|
145
|
+
{
|
|
146
|
+
kind: "api",
|
|
147
|
+
path: pathname,
|
|
148
|
+
},
|
|
149
|
+
undefined,
|
|
150
|
+
{ hostDir },
|
|
151
|
+
);
|
|
152
|
+
if (rejected) {
|
|
153
|
+
return withHostResponseHeaders(rejected, {
|
|
154
|
+
method: request.method,
|
|
155
|
+
pathname,
|
|
156
|
+
}, hostDir);
|
|
157
|
+
}
|
|
144
158
|
}
|
|
145
159
|
|
|
146
160
|
if (segments.length === 0) {
|
|
@@ -151,31 +165,16 @@ export async function dispatchHostServiceApiRequest(
|
|
|
151
165
|
return withHostResponseHeaders(res, { method: request.method, pathname }, hostDir);
|
|
152
166
|
}
|
|
153
167
|
|
|
154
|
-
let service: IService | null =
|
|
155
|
-
if (hostDir) {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
if (aotResolver) {
|
|
163
|
-
const routeKey = segments.join("/");
|
|
164
|
-
const resolved = await aotResolver(routeKey, segments);
|
|
165
|
-
if (resolved) {
|
|
166
|
-
service = resolveServiceExport(resolved, `[aot:${routeKey}]`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
} finally {
|
|
171
|
-
if (prevHostDir === undefined) {
|
|
172
|
-
delete process.env.SOMA_HOST_DIR;
|
|
173
|
-
} else {
|
|
174
|
-
process.env.SOMA_HOST_DIR = prevHostDir;
|
|
168
|
+
let service: IService | null = loadHostService(segments, hostDir);
|
|
169
|
+
if (!service && hostDir) {
|
|
170
|
+
const aotResolver = getAotServiceResolver(hostDir);
|
|
171
|
+
if (aotResolver) {
|
|
172
|
+
const routeKey = segments.join("/");
|
|
173
|
+
const resolved = await aotResolver(routeKey, segments);
|
|
174
|
+
if (resolved) {
|
|
175
|
+
service = resolveServiceExport(resolved, `[aot:${routeKey}]`);
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
|
-
} else {
|
|
178
|
-
service = loadHostService(segments);
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
if (!service) {
|
|
@@ -201,10 +200,10 @@ export async function dispatchHostServiceApiRequest(
|
|
|
201
200
|
const response = await handlerFn.call(service, polyfilledReq);
|
|
202
201
|
return withHostResponseHeaders(response, { method: request.method, pathname }, hostDir);
|
|
203
202
|
} catch (e: unknown) {
|
|
204
|
-
const
|
|
205
|
-
console.error(`[soma-core][接口] ${method} /api/${segments.join("/")}:`,
|
|
203
|
+
const eventId = randomUUID();
|
|
204
|
+
console.error(`[soma-core][接口][eventId=${eventId}] ${method} /api/${segments.join("/")}:`, e);
|
|
206
205
|
const res = Response.json(
|
|
207
|
-
{ error:
|
|
206
|
+
{ error: "Internal server error", eventId },
|
|
208
207
|
{ status: 500 },
|
|
209
208
|
);
|
|
210
209
|
return withHostResponseHeaders(res, { method: request.method, pathname }, hostDir);
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
getSomaHostSourceRoot,
|
|
10
10
|
} from "../host/source-packages";
|
|
11
11
|
import { ensureNodeServerOnlyInterop, getJitiFactory } from "../host/host-assembly";
|
|
12
|
+
import { currentHostDir } from "../host/host-dir";
|
|
13
|
+
import { getSomaSourceRootAliases } from "../host/source-aliases";
|
|
12
14
|
|
|
13
15
|
export type AotServiceResolver = (routeKey: string, segments: readonly string[]) => unknown | Promise<unknown>;
|
|
14
16
|
|
|
@@ -120,6 +122,8 @@ function getJitiLoader(
|
|
|
120
122
|
moduleCache: !reload,
|
|
121
123
|
requireCache: !reload,
|
|
122
124
|
alias: {
|
|
125
|
+
// 源码根别名(soma.sourceRoots):jiti 只匹配带斜杠的整段前缀,不劫持裸名;固定别名在后,不可被覆盖
|
|
126
|
+
...getSomaSourceRootAliases(normalizedHostDir),
|
|
123
127
|
"@core": getCoreDir(),
|
|
124
128
|
"@soma-host": normalizedWebRoot,
|
|
125
129
|
"@soma-api": normalizedApiRoot,
|
|
@@ -143,12 +147,12 @@ function getJitiLoader(
|
|
|
143
147
|
/**
|
|
144
148
|
* 按约定从宿主 apiRoot 加载 IService 实例(运行时按需加载,零手动 registry)。
|
|
145
149
|
*/
|
|
146
|
-
export function loadHostService(segments: string[]): IService | null {
|
|
150
|
+
export function loadHostService(segments: string[], hostDir?: string): IService | null {
|
|
147
151
|
if (typeof process !== "undefined" && process.env.NEXT_RUNTIME === "edge") return null;
|
|
148
|
-
const
|
|
149
|
-
if (!
|
|
152
|
+
const resolvedHostDir = hostDir || currentHostDir();
|
|
153
|
+
if (!resolvedHostDir) return null;
|
|
150
154
|
|
|
151
|
-
const normalizedHostDir = path.resolve(
|
|
155
|
+
const normalizedHostDir = path.resolve(resolvedHostDir);
|
|
152
156
|
const routeKey = segments.join("/");
|
|
153
157
|
|
|
154
158
|
// 1. AOT 预编译服务快速命中(零磁盘、零 jiti)
|