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
|
@@ -116,8 +116,9 @@ export function pageSuccessResponse(
|
|
|
116
116
|
cacheKey?: string,
|
|
117
117
|
): Response {
|
|
118
118
|
const jsonType = 'application/json; charset=utf-8';
|
|
119
|
+
const isPrefix = (page as { binding?: { kind?: string } }).binding?.kind === 'prefix';
|
|
119
120
|
|
|
120
|
-
if (!page.cacheable || page.purpose === 'preview') {
|
|
121
|
+
if (!page.cacheable || page.purpose === 'preview' || isPrefix) {
|
|
121
122
|
const text = typeof body === 'string' ? body : JSON.stringify(body);
|
|
122
123
|
return new Response(text, {
|
|
123
124
|
status: 200,
|
|
@@ -215,9 +216,8 @@ export function pageErrorResponse(
|
|
|
215
216
|
{ status: error.status, headers },
|
|
216
217
|
);
|
|
217
218
|
}
|
|
218
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
219
219
|
return Response.json(
|
|
220
|
-
{ error:
|
|
220
|
+
{ error: 'Internal server error', code: 'SOMA_PAGE_ASSET_UNKNOWN' },
|
|
221
221
|
{ status: 500, headers },
|
|
222
222
|
);
|
|
223
223
|
}
|
|
@@ -118,7 +118,6 @@ function readAllSomaPublicAliases(hostDir, repoRoot, extraRoots = []) {
|
|
|
118
118
|
path.join(repoRoot, 'soma-core'),
|
|
119
119
|
path.join(repoRoot, 'soma-foundation'),
|
|
120
120
|
path.join(repoRoot, 'soma-ui'),
|
|
121
|
-
path.join(repoRoot, 'soma-lite'),
|
|
122
121
|
path.join(repoRoot, 'soma-kit'),
|
|
123
122
|
path.join(repoRoot, 'soma-ai'),
|
|
124
123
|
];
|
|
@@ -17,11 +17,17 @@ function createHandler(method: HttpMethod) {
|
|
|
17
17
|
const segments = resolvedParams.path || [];
|
|
18
18
|
const url = new URL(req.url, 'http://soma.local');
|
|
19
19
|
const pathname = req.nextUrl?.pathname || url.pathname;
|
|
20
|
+
const hostDir = req.hostDir ?? process.env.SOMA_HOST_DIR;
|
|
20
21
|
|
|
21
|
-
const rejected = await invokeHostRequestHook(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const rejected = await invokeHostRequestHook(
|
|
23
|
+
req,
|
|
24
|
+
{
|
|
25
|
+
kind: 'api',
|
|
26
|
+
path: pathname,
|
|
27
|
+
},
|
|
28
|
+
undefined,
|
|
29
|
+
{ hostDir },
|
|
30
|
+
);
|
|
25
31
|
if (rejected) {
|
|
26
32
|
return rejected;
|
|
27
33
|
}
|
|
@@ -63,10 +69,11 @@ function createHandler(method: HttpMethod) {
|
|
|
63
69
|
): Promise<Response> {
|
|
64
70
|
const url = new URL(req.url, 'http://soma.local');
|
|
65
71
|
const pathname = req.nextUrl?.pathname || url.pathname;
|
|
72
|
+
const hostDir = req.hostDir ?? process.env.SOMA_HOST_DIR;
|
|
66
73
|
return withHostResponseHeaders(await dispatch(req, context), {
|
|
67
74
|
method: req.method || method,
|
|
68
75
|
pathname,
|
|
69
|
-
});
|
|
76
|
+
}, hostDir);
|
|
70
77
|
};
|
|
71
78
|
}
|
|
72
79
|
|
|
@@ -2,43 +2,79 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
4
|
import zlib from 'node:zlib';
|
|
5
|
+
import { Readable } from 'node:stream';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
5
7
|
import { resolveSomaRuntimeLayout } from '../../core/server/runtime-space/root';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
9
|
+
// esbuild format:'cjs' 产物里 import.meta.url 为 undefined,此时回落到原生 require。
|
|
10
|
+
const mimeTypes = (typeof import.meta.url === 'string'
|
|
11
|
+
? createRequire(import.meta.url)('mime-types')
|
|
12
|
+
: require('mime-types')) as { lookup(extension: string): string | false };
|
|
13
|
+
|
|
14
|
+
/** 仅构建输出目录中的内容寻址产物可 immutable(esbuild `[hash]` 为 8 位大写字母数字,区分大小写);public 与可配置 runtime 目录一律保守缓存。 */
|
|
15
|
+
const HASHED_NAME = /-[A-Z0-9]{8}\.(?:js|css)(?:\.map)?$/;
|
|
16
|
+
|
|
17
|
+
const EXECUTABLE_DOC_EXTENSIONS: ReadonlySet<string> = new Set([
|
|
18
|
+
'.html', '.htm', '.xhtml', '.xht', '.shtml', '.mht', '.mhtml',
|
|
19
|
+
]);
|
|
20
|
+
const TYPESCRIPT_EXTENSIONS: ReadonlySet<string> = new Set(['.ts', '.tsx', '.mts', '.cts']);
|
|
21
|
+
|
|
22
|
+
export function contentTypeForExtension(extension: string): string {
|
|
23
|
+
// public/ 只承诺图片与字体等静态素材;避免把 HTML 从下载型变成可执行文档。
|
|
24
|
+
if (EXECUTABLE_DOC_EXTENSIONS.has(extension)) return 'application/octet-stream';
|
|
25
|
+
// mime-types 会把 .ts 当成视频(MPEG-TS),源码文件固定为纯文本。
|
|
26
|
+
if (TYPESCRIPT_EXTENSIONS.has(extension)) return 'text/plain; charset=utf-8';
|
|
27
|
+
const lookedUp = mimeTypes.lookup(extension);
|
|
28
|
+
if (!lookedUp) return 'application/octet-stream';
|
|
29
|
+
const normalized = extension === '.ico'
|
|
30
|
+
? 'image/x-icon'
|
|
31
|
+
: lookedUp === 'application/javascript'
|
|
32
|
+
? 'text/javascript'
|
|
33
|
+
: lookedUp;
|
|
34
|
+
return normalized.startsWith('text/') || normalized === 'application/json' || normalized === 'text/javascript'
|
|
35
|
+
? `${normalized}; charset=utf-8`
|
|
36
|
+
: normalized;
|
|
37
|
+
}
|
|
26
38
|
|
|
27
39
|
export type StaticResolution =
|
|
28
40
|
| { readonly ok: true; readonly file: string; readonly size: number; readonly mtimeMs: number }
|
|
29
41
|
| { readonly ok: false };
|
|
30
42
|
|
|
31
43
|
export function isSafeSegments(segments: readonly string[]): boolean {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
if (segments.length === 0) return false;
|
|
45
|
+
return segments.every((segment) => {
|
|
46
|
+
if (
|
|
47
|
+
segment === '' ||
|
|
48
|
+
segment.startsWith('.') ||
|
|
49
|
+
/[\\/]/.test(segment) ||
|
|
50
|
+
/[\x00-\x1f]/.test(segment)
|
|
51
|
+
) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const decoded = decodeURIComponent(segment);
|
|
56
|
+
if (
|
|
57
|
+
decoded === '' ||
|
|
58
|
+
decoded.startsWith('.') ||
|
|
59
|
+
/[\\/]/.test(decoded) ||
|
|
60
|
+
/[\x00-\x1f]/.test(decoded)
|
|
61
|
+
) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
35
69
|
}
|
|
36
70
|
|
|
37
71
|
export function resolveStaticFile(staticRoot: string, segments: readonly string[]): StaticResolution {
|
|
38
72
|
if (!isSafeSegments(segments)) return { ok: false };
|
|
39
73
|
try {
|
|
40
74
|
const rootReal = fs.realpathSync(staticRoot);
|
|
41
|
-
const candidate = path.join(rootReal, ...segments)
|
|
75
|
+
const candidate = path.join(rootReal, ...segments.map((s) => {
|
|
76
|
+
try { return decodeURIComponent(s); } catch { return s; }
|
|
77
|
+
}));
|
|
42
78
|
const real = fs.realpathSync(candidate);
|
|
43
79
|
if (real !== rootReal && !real.startsWith(rootReal + path.sep)) return { ok: false };
|
|
44
80
|
const stat = fs.statSync(real);
|
|
@@ -69,6 +105,11 @@ export function clearStaticBufferCache(): void {
|
|
|
69
105
|
currentStaticCacheBytes = 0;
|
|
70
106
|
}
|
|
71
107
|
|
|
108
|
+
/** 该大小的静态文件是否存在 gzip 表示:只看大小(≤单文件缓存上限且 ≥1KB),不读文件;缓存函数与响应头(Vary)共用这一组条件 */
|
|
109
|
+
function hasGzipRepresentation(size: number): boolean {
|
|
110
|
+
return size <= MAX_SINGLE_FILE_BYTES && size >= 1024;
|
|
111
|
+
}
|
|
112
|
+
|
|
72
113
|
function getOrCacheStaticFile(filePath: string, size: number, mtimeMs: number): CachedStaticPayload | null {
|
|
73
114
|
if (size > MAX_SINGLE_FILE_BYTES) return null;
|
|
74
115
|
const key = `${filePath}:${size}:${mtimeMs}`;
|
|
@@ -84,7 +125,7 @@ function getOrCacheStaticFile(filePath: string, size: number, mtimeMs: number):
|
|
|
84
125
|
const buffer = fs.readFileSync(filePath);
|
|
85
126
|
const raw = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
86
127
|
let gzip: Uint8Array | null = null;
|
|
87
|
-
if (raw.byteLength
|
|
128
|
+
if (hasGzipRepresentation(raw.byteLength)) {
|
|
88
129
|
try {
|
|
89
130
|
gzip = zlib.gzipSync(raw);
|
|
90
131
|
} catch {
|
|
@@ -111,58 +152,141 @@ function getOrCacheStaticFile(filePath: string, size: number, mtimeMs: number):
|
|
|
111
152
|
}
|
|
112
153
|
}
|
|
113
154
|
|
|
114
|
-
|
|
155
|
+
/** 按逗号拆分并解析 q 值:gzip(或 `*`)且 q>0 才算接受;q=0 明确拒绝,显式 gzip 优先于 `*`。 */
|
|
156
|
+
export function acceptsGzip(header: string | null | undefined): boolean {
|
|
115
157
|
if (!header) return false;
|
|
116
|
-
|
|
158
|
+
let gzip: number | null = null;
|
|
159
|
+
let star: number | null = null;
|
|
160
|
+
for (const part of header.split(',')) {
|
|
161
|
+
const [rawName, ...params] = part.split(';');
|
|
162
|
+
const name = rawName.trim().toLowerCase();
|
|
163
|
+
if (name !== 'gzip' && name !== 'x-gzip' && name !== '*') continue;
|
|
164
|
+
let q = 1;
|
|
165
|
+
for (const param of params) {
|
|
166
|
+
const m = /^\s*q\s*=\s*([0-9.]+)\s*$/i.exec(param);
|
|
167
|
+
if (m) {
|
|
168
|
+
const parsed = Number(m[1]);
|
|
169
|
+
q = Number.isFinite(parsed) ? parsed : 0;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (name === '*') star = q;
|
|
173
|
+
else gzip = q;
|
|
174
|
+
}
|
|
175
|
+
return (gzip ?? star ?? 0) > 0;
|
|
117
176
|
}
|
|
118
177
|
|
|
119
|
-
|
|
178
|
+
/** 解析单区间 Range:合法返回闭区间;越界 'unsatisfiable';多区间 / 非法语法返回 null(忽略 Range)。 */
|
|
179
|
+
function parseSingleRange(
|
|
180
|
+
header: string,
|
|
181
|
+
size: number,
|
|
182
|
+
): { start: number; end: number } | 'unsatisfiable' | null {
|
|
183
|
+
const m = /^\s*bytes\s*=\s*(\d*)\s*-\s*(\d*)\s*$/i.exec(header);
|
|
184
|
+
if (!m || (m[1] === '' && m[2] === '')) return null;
|
|
185
|
+
let start: number;
|
|
186
|
+
let end: number;
|
|
187
|
+
if (m[1] === '') {
|
|
188
|
+
const suffix = Number(m[2]);
|
|
189
|
+
if (!Number.isSafeInteger(suffix)) return null;
|
|
190
|
+
if (suffix === 0 || size === 0) return 'unsatisfiable';
|
|
191
|
+
start = Math.max(0, size - suffix);
|
|
192
|
+
end = size - 1;
|
|
193
|
+
} else {
|
|
194
|
+
start = Number(m[1]);
|
|
195
|
+
if (!Number.isSafeInteger(start)) return null;
|
|
196
|
+
if (m[2] === '') {
|
|
197
|
+
end = size - 1;
|
|
198
|
+
} else {
|
|
199
|
+
end = Number(m[2]);
|
|
200
|
+
if (!Number.isSafeInteger(end) || end < start) return null;
|
|
201
|
+
}
|
|
202
|
+
if (start >= size) return 'unsatisfiable';
|
|
203
|
+
end = Math.min(end, size - 1);
|
|
204
|
+
}
|
|
205
|
+
return { start, end };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function serveStaticFromRoot(
|
|
209
|
+
root: string,
|
|
120
210
|
segments: readonly string[],
|
|
121
211
|
request: { readonly method: string; readonly headers: { get(name: string): string | null } },
|
|
122
|
-
|
|
123
|
-
): Response {
|
|
124
|
-
|
|
125
|
-
const hostDir = env.SOMA_HOST_DIR;
|
|
126
|
-
if (!hostDir) return notFound();
|
|
127
|
-
let root: string;
|
|
128
|
-
try {
|
|
129
|
-
root = staticRootOf(hostDir, env);
|
|
130
|
-
} catch {
|
|
131
|
-
return notFound();
|
|
132
|
-
}
|
|
212
|
+
allowImmutableContentAddressing = false,
|
|
213
|
+
): Response | null {
|
|
214
|
+
if (!isSafeSegments(segments)) return null;
|
|
133
215
|
const resolved = resolveStaticFile(root, segments);
|
|
134
|
-
if (!resolved.ok) return
|
|
216
|
+
if (!resolved.ok) return null;
|
|
135
217
|
|
|
218
|
+
const ext = path.extname(resolved.file).toLowerCase();
|
|
136
219
|
const etag = `W/"${createHash('sha1').update(`${resolved.size}:${resolved.mtimeMs}`).digest('hex').slice(0, 20)}"`;
|
|
137
|
-
const hashed = HASHED_NAME.test(path.basename(resolved.file));
|
|
220
|
+
const hashed = allowImmutableContentAddressing && HASHED_NAME.test(path.basename(resolved.file));
|
|
138
221
|
const headers: Record<string, string> = {
|
|
139
|
-
'content-type':
|
|
222
|
+
'content-type': contentTypeForExtension(ext),
|
|
140
223
|
'cache-control': hashed ? 'public, max-age=31536000, immutable' : 'public, max-age=300, must-revalidate',
|
|
141
224
|
etag,
|
|
142
225
|
'x-content-type-options': 'nosniff',
|
|
143
226
|
};
|
|
144
227
|
|
|
228
|
+
if (ext === '.svg') {
|
|
229
|
+
headers['content-security-policy'] = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 是否存在 gzip 表示只看大小(不读文件):存在则 200 / 304 / 206 一律带 Vary: Accept-Encoding;304 / 206 / 416 不取缓存
|
|
233
|
+
if (hasGzipRepresentation(resolved.size)) headers['vary'] = 'Accept-Encoding';
|
|
234
|
+
|
|
145
235
|
if (request.headers.get('if-none-match')?.split(',').some((value) => value.trim() === etag)) {
|
|
146
236
|
return new Response(null, { status: 304, headers });
|
|
147
237
|
}
|
|
148
238
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
239
|
+
const isHead = request.method.toUpperCase() === 'HEAD';
|
|
240
|
+
|
|
241
|
+
// 单区间 Range:独占身份编码(不 gzip),流式只读该区间;多区间 / 非法语法忽略 Range 走完整 200。
|
|
242
|
+
const rangeHeader = request.headers.get('range');
|
|
243
|
+
const ifRange = request.headers.get('if-range');
|
|
244
|
+
// If-Range 要求强比较:本服务只产弱 ETag,ETag 形式一律忽略 Range;响应不带 Last-Modified,日期形式同样忽略。
|
|
245
|
+
if (rangeHeader && ifRange === null) {
|
|
246
|
+
const range = parseSingleRange(rangeHeader, resolved.size);
|
|
247
|
+
if (range === 'unsatisfiable') {
|
|
248
|
+
const { etag: _etag, ...rest } = headers;
|
|
249
|
+
return new Response(null, {
|
|
250
|
+
status: 416,
|
|
251
|
+
headers: { ...rest, 'cache-control': 'no-store', 'content-range': `bytes */${resolved.size}` },
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (range) {
|
|
255
|
+
const length = range.end - range.start + 1;
|
|
256
|
+
const rangeHeaders = {
|
|
257
|
+
...headers,
|
|
258
|
+
'accept-ranges': 'bytes',
|
|
259
|
+
'content-range': `bytes ${range.start}-${range.end}/${resolved.size}`,
|
|
260
|
+
'content-length': String(length),
|
|
261
|
+
};
|
|
262
|
+
if (isHead) return new Response(null, { status: 206, headers: rangeHeaders });
|
|
263
|
+
const fileStream = fs.createReadStream(resolved.file, { start: range.start, end: range.end });
|
|
264
|
+
// 文件在 stat 之后被删 / 无权限 / IO 错误:先挂监听留下现场,再交给 Web 流(流随即以该错误终止响应体)
|
|
265
|
+
fileStream.on('error', (error: NodeJS.ErrnoException) => {
|
|
266
|
+
console.error(
|
|
267
|
+
`[soma-core][静态文件] 区间读取失败:文件=${resolved.file} 区间=${range.start}-${range.end} 错误码=${error.code ?? 'UNKNOWN'}`,
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
const stream = Readable.toWeb(fileStream);
|
|
271
|
+
return new Response(stream as unknown as BodyInit, { status: 206, headers: rangeHeaders });
|
|
272
|
+
}
|
|
152
273
|
}
|
|
153
274
|
|
|
275
|
+
// 200:GET 与 HEAD 共用同一段「决定表示与响应头」,HEAD 只是不带响应体;只有这里才需要表示内容,才取缓存
|
|
154
276
|
const cached = getOrCacheStaticFile(resolved.file, resolved.size, resolved.mtimeMs);
|
|
155
|
-
const
|
|
277
|
+
const useGzip = !!cached?.gzip && acceptsGzip(request.headers.get('accept-encoding'));
|
|
278
|
+
if (useGzip && cached?.gzip) {
|
|
279
|
+
headers['content-encoding'] = 'gzip';
|
|
280
|
+
headers['content-length'] = String(cached.gzip.byteLength);
|
|
281
|
+
} else {
|
|
282
|
+
headers['accept-ranges'] = 'bytes';
|
|
283
|
+
headers['content-length'] = String(cached ? cached.raw.byteLength : resolved.size);
|
|
284
|
+
}
|
|
285
|
+
if (isHead) return new Response(null, { status: 200, headers });
|
|
156
286
|
|
|
157
287
|
if (cached) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
headers['vary'] = 'Accept-Encoding';
|
|
161
|
-
headers['content-length'] = String(cached.gzip.byteLength);
|
|
162
|
-
return new Response(cached.gzip as unknown as BodyInit, { status: 200, headers });
|
|
163
|
-
}
|
|
164
|
-
headers['content-length'] = String(cached.raw.byteLength);
|
|
165
|
-
return new Response(cached.raw as unknown as BodyInit, { status: 200, headers });
|
|
288
|
+
const body = useGzip && cached.gzip ? cached.gzip : cached.raw;
|
|
289
|
+
return new Response(body as unknown as BodyInit, { status: 200, headers });
|
|
166
290
|
}
|
|
167
291
|
|
|
168
292
|
// 大于 4MB 的文件回退到直接读取
|
|
@@ -170,3 +294,29 @@ export function staticResponse(
|
|
|
170
294
|
headers['content-length'] = String(buf.length);
|
|
171
295
|
return new Response(buf, { status: 200, headers });
|
|
172
296
|
}
|
|
297
|
+
|
|
298
|
+
export function staticResponse(
|
|
299
|
+
segments: readonly string[],
|
|
300
|
+
request: { readonly method: string; readonly headers: { get(name: string): string | null } },
|
|
301
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
302
|
+
): Response {
|
|
303
|
+
const notFound = () =>
|
|
304
|
+
new Response('Not found', {
|
|
305
|
+
status: 404,
|
|
306
|
+
headers: {
|
|
307
|
+
'cache-control': 'no-store',
|
|
308
|
+
'content-type': 'text/plain; charset=utf-8',
|
|
309
|
+
'x-content-type-options': 'nosniff',
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
const hostDir = env.SOMA_HOST_DIR;
|
|
313
|
+
if (!hostDir) return notFound();
|
|
314
|
+
let root: string;
|
|
315
|
+
try {
|
|
316
|
+
root = staticRootOf(hostDir, env);
|
|
317
|
+
} catch {
|
|
318
|
+
return notFound();
|
|
319
|
+
}
|
|
320
|
+
const res = serveStaticFromRoot(root, segments, request);
|
|
321
|
+
return res ?? notFound();
|
|
322
|
+
}
|
|
@@ -34,39 +34,41 @@ select {
|
|
|
34
34
|
font: inherit;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/* 托管组件由角色类和布局工具决定外观,不能叠加浏览器默认标题边距、按钮底色或 outset
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
/* 托管组件由角色类和布局工具决定外观,不能叠加浏览器默认标题边距、按钮底色或 outset 边框;置于最底层 @layer base,确保不压过组件/主题 @layer 规则。 */
|
|
38
|
+
@layer base {
|
|
39
|
+
:where([data-soma-host], [data-soma-host] *, [data-soma-host] *::before, [data-soma-host] *::after) {
|
|
40
|
+
border-width: 0;
|
|
41
|
+
border-style: solid;
|
|
42
|
+
}
|
|
42
43
|
|
|
43
|
-
:where([data-soma-host]) :where(h1, h2, h3, h4, h5, h6, p, blockquote, figure, dl, dd) {
|
|
44
|
-
|
|
45
|
-
}
|
|
44
|
+
:where([data-soma-host]) :where(h1, h2, h3, h4, h5, h6, p, blockquote, figure, dl, dd) {
|
|
45
|
+
margin: 0;
|
|
46
|
+
}
|
|
46
47
|
|
|
47
|
-
:where([data-soma-host], [data-soma-overlay-root]) :where(button, input, optgroup, select, textarea) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
48
|
+
:where([data-soma-host], [data-soma-overlay-root]) :where(button, input, optgroup, select, textarea) {
|
|
49
|
+
color: inherit;
|
|
50
|
+
font: inherit;
|
|
51
|
+
background-color: transparent;
|
|
52
|
+
border-radius: 0;
|
|
53
|
+
border-width: 0;
|
|
54
|
+
border-style: solid;
|
|
55
|
+
}
|
|
55
56
|
|
|
56
|
-
:where([data-soma-host]) :where(ol, ul, menu) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
57
|
+
:where([data-soma-host]) :where(ol, ul, menu) {
|
|
58
|
+
list-style: none;
|
|
59
|
+
margin: 0;
|
|
60
|
+
padding: 0;
|
|
61
|
+
}
|
|
61
62
|
|
|
62
|
-
:where([data-soma-host]) table {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
63
|
+
:where([data-soma-host]) table {
|
|
64
|
+
border-collapse: collapse;
|
|
65
|
+
text-indent: 0;
|
|
66
|
+
}
|
|
66
67
|
|
|
67
|
-
:where([data-soma-host]) a {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
:where([data-soma-host]) a {
|
|
69
|
+
color: inherit;
|
|
70
|
+
text-decoration: inherit;
|
|
71
|
+
}
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
.soma-hidden {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soma-core",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7",
|
|
4
4
|
"description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime with no UI framework dependency; native host shell ships in host-native/.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"soma",
|
|
@@ -175,6 +175,11 @@
|
|
|
175
175
|
"import": "./core/server/index.ts",
|
|
176
176
|
"default": "./core/server/index.ts"
|
|
177
177
|
},
|
|
178
|
+
"./server/paged-list": {
|
|
179
|
+
"types": "./dist/types/server/api/paged-list.d.ts",
|
|
180
|
+
"import": "./core/server/api/paged-list.ts",
|
|
181
|
+
"default": "./core/server/api/paged-list.ts"
|
|
182
|
+
},
|
|
178
183
|
"./server/runtime": {
|
|
179
184
|
"types": "./dist/types/server/runtime-space/index.d.ts",
|
|
180
185
|
"import": "./core/server/runtime-space/index.ts",
|
|
@@ -190,6 +195,12 @@
|
|
|
190
195
|
"import": "./core/server/node.ts",
|
|
191
196
|
"default": "./core/server/node.ts"
|
|
192
197
|
},
|
|
198
|
+
"./server/source-aliases": {
|
|
199
|
+
"types": "./dist/types/server/host/source-aliases.d.ts",
|
|
200
|
+
"require": "./core/server/host/source-aliases.cjs",
|
|
201
|
+
"import": "./core/server/host/source-aliases.cjs",
|
|
202
|
+
"default": "./core/server/host/source-aliases.cjs"
|
|
203
|
+
},
|
|
193
204
|
"./server/registry": {
|
|
194
205
|
"types": "./dist/types/server/registry/index.d.ts",
|
|
195
206
|
"import": "./core/server/registry/index.ts",
|
|
@@ -317,10 +328,11 @@
|
|
|
317
328
|
"esbuild": "0.25.12",
|
|
318
329
|
"jiti": "1.21.7",
|
|
319
330
|
"js-yaml": "4.3.2",
|
|
331
|
+
"mime-types": "2.1.35",
|
|
320
332
|
"parse5": "7.3.0",
|
|
321
333
|
"qrcode-generator": "2.0.4",
|
|
322
334
|
"server-only": "0.0.1",
|
|
323
|
-
"soma-foundation": "^0.1.
|
|
335
|
+
"soma-foundation": "^0.1.4",
|
|
324
336
|
"temporal-polyfill": "0.3.2"
|
|
325
337
|
},
|
|
326
338
|
"peerDependencies": {
|