soma-core 2.2.8 → 2.2.9
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/core/build/compiler/full-manifest-builder.ts +1 -1
- package/core/build/compiler/host-config-sync.cjs +1 -1
- package/core/build/compiler/soma-manifest-webpack-plugin.js +2 -6
- package/core/build/compiler/soma-precompile.js +80 -4
- package/core/client/a11y/announcer.ts +2 -16
- package/core/client/base/SomaPageRootBase.ts +2 -2
- package/core/client/base/defineSomaView.ts +11 -2
- package/core/client/base/runtime-services.types.ts +57 -0
- package/core/client/data/role-gate.ts +2 -8
- package/core/client/engine/event-engine.ts +1 -0
- package/core/client/engines/diff/adapter-jsdiff.ts +27 -8
- package/core/client/engines/diff/index.ts +81 -6
- package/core/client/engines/diff/items.ts +212 -0
- package/core/client/engines/diff/port.ts +140 -3
- package/core/client/engines/diff/prose.ts +443 -0
- package/core/client/engines/engine-adapters.ts +6 -0
- package/core/client/engines/highlight/adapter-lezer.ts +109 -0
- package/core/client/engines/highlight/index.ts +135 -0
- package/core/client/engines/highlight/port.ts +92 -0
- package/core/client/engines/markdown/adapter-markdown-it.ts +65 -0
- package/core/client/engines/markdown/blocks.ts +335 -0
- package/core/client/engines/markdown/index.ts +51 -0
- package/core/client/engines/markdown/port.ts +94 -0
- package/core/client/engines/markdown/vendor-modules.d.ts +6 -0
- package/core/client/engines/structured/adapter-js-yaml.ts +33 -0
- package/core/client/engines/structured/index.ts +139 -0
- package/core/client/engines/structured/port.ts +59 -0
- package/core/client/infra/http/SomaHttpService.ts +2 -4
- package/core/client/infra/notify/DefaultNotifyService.ts +2 -3
- package/core/client/infra/permission/SomaPermission.ts +1 -1
- package/core/client/render-ports/notify-renderer.ts +2 -46
- package/core/client/runtime/SomaRuntimeServices.ts +16 -45
- package/core/server/host/app-config-composer.ts +6 -52
- package/core/server/host/host-config-paths.cjs +2 -100
- package/core/server/host/precompiled-manifest.ts +69 -0
- package/core/server/infra/host-config-paths.cjs +100 -0
- package/core/server/page-assets.ts +2 -70
- package/core/server/runtime-space/bindings.ts +33 -4
- package/core/server/runtime-space/store.ts +16 -1
- package/core/shared/app-config-merge.ts +59 -0
- package/core/shared/registry-generated/limits.ts +80 -4
- package/core/shared/types/announcer.types.ts +18 -0
- package/core/shared/types/notify.types.ts +26 -0
- package/core/shared/types/role-gate.types.ts +11 -0
- package/dist/browser/runtime-bundle.manifest.json +50 -7
- package/dist/browser/soma-runtime.js +120741 -104799
- package/dist/core/index.cjs +113807 -97854
- package/dist/host-native/aot-builder.cjs +277 -189
- package/dist/host-native/native-server.cjs +196 -72
- package/dist/lsp/component-tree.cjs +80 -4
- package/dist/types/build/compiler/full-manifest-builder.d.ts +1 -1
- package/dist/types/client/a11y/announcer.d.ts +2 -14
- package/dist/types/client/base/SomaPageRootBase.d.ts +2 -2
- package/dist/types/client/base/runtime-services.types.d.ts +50 -0
- package/dist/types/client/data/role-gate.d.ts +2 -8
- package/dist/types/client/engines/diff/index.d.ts +1 -1
- package/dist/types/client/engines/diff/items.d.ts +24 -0
- package/dist/types/client/engines/diff/port.d.ts +124 -2
- package/dist/types/client/engines/diff/prose.d.ts +80 -0
- package/dist/types/client/engines/engine-adapters.d.ts +6 -0
- package/dist/types/client/engines/highlight/adapter-lezer.d.ts +6 -0
- package/dist/types/client/engines/highlight/index.d.ts +15 -0
- package/dist/types/client/engines/highlight/port.d.ts +64 -0
- package/dist/types/client/engines/markdown/adapter-markdown-it.d.ts +6 -0
- package/dist/types/client/engines/markdown/blocks.d.ts +29 -0
- package/dist/types/client/engines/markdown/index.d.ts +9 -0
- package/dist/types/client/engines/markdown/port.d.ts +166 -0
- package/dist/types/client/engines/structured/adapter-js-yaml.d.ts +6 -0
- package/dist/types/client/engines/structured/index.d.ts +29 -0
- package/dist/types/client/engines/structured/port.d.ts +45 -0
- package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
- package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +2 -3
- package/dist/types/client/infra/permission/SomaPermission.d.ts +1 -1
- package/dist/types/client/render-ports/notify-renderer.d.ts +1 -56
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +9 -44
- package/dist/types/server/host/app-config-composer.d.ts +2 -3
- package/dist/types/server/host/host-config-paths.d.cts +2 -7
- package/dist/types/server/host/precompiled-manifest.d.ts +5 -0
- package/dist/types/server/infra/host-config-paths.d.cts +7 -0
- package/dist/types/server/page-assets.d.ts +2 -5
- package/dist/types/server/runtime-space/store.d.ts +4 -0
- package/dist/types/shared/app-config-merge.d.ts +3 -0
- package/dist/types/shared/registry-generated/limits.d.ts +78 -4
- package/dist/types/shared/types/announcer.types.d.ts +14 -0
- package/dist/types/shared/types/notify.types.d.ts +36 -0
- package/dist/types/shared/types/role-gate.types.d.ts +8 -0
- package/host-native/src/aot-builder.ts +12 -5
- package/host-native/src/dev-chunk-gc.ts +104 -0
- package/host-native/src/host-prepare.ts +1 -1
- package/host-native/src/manifest-http.ts +1 -1
- package/host-native/src/page-http.ts +2 -67
- package/host-native/src/page-payload-cache.ts +68 -0
- package/package.json +16 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type AnnouncePoliteness = 'polite' | 'assertive';
|
|
2
|
+
export interface AnnounceOptions {
|
|
3
|
+
readonly politeness?: AnnouncePoliteness;
|
|
4
|
+
}
|
|
5
|
+
export interface Announcer {
|
|
6
|
+
/** 追加一条播报;空消息忽略;politeness 缺省 polite,未知值抛 TypeError */
|
|
7
|
+
announce(message: string, options?: AnnounceOptions): void;
|
|
8
|
+
/** 两个常驻宿主 */
|
|
9
|
+
hosts(): Readonly<Record<AnnouncePoliteness, HTMLElement>>;
|
|
10
|
+
/** 立即移除全部待清理节点 */
|
|
11
|
+
clear(): void;
|
|
12
|
+
/** 清空、取消计时并移除宿主;之后 announce 忽略 */
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}
|
|
@@ -35,3 +35,39 @@ export interface INotifyService {
|
|
|
35
35
|
/** 读屏播报(S7 · `NOTIFY | announce`);可选,缺省实现见 DefaultNotifyService */
|
|
36
36
|
announce?(message: string, politeness?: 'polite' | 'assertive'): void;
|
|
37
37
|
}
|
|
38
|
+
/** 交给渲染器的一条通知;`duration` 只透传调用方给的值,未给则不带字段,由渲染器决定停留 */
|
|
39
|
+
export interface NotifyEntry {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly level: NotifyLevel;
|
|
42
|
+
readonly message: string;
|
|
43
|
+
readonly title?: string;
|
|
44
|
+
readonly duration?: number;
|
|
45
|
+
/** 呈现载体偏好;未给则渲染器按级别与动作自定 */
|
|
46
|
+
readonly carrier?: NotifyCarrier;
|
|
47
|
+
/** 附带动作;未给则无 */
|
|
48
|
+
readonly action?: NotifyAction;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 通知渲染端口(UI 体系注入,经 `SomaBootstrap` 选项 `renderPorts.notify`)。
|
|
52
|
+
* core 不带可见实现:停留、动效、位置、模态呈现全在渲染器里。
|
|
53
|
+
*/
|
|
54
|
+
export interface NotifyRenderer {
|
|
55
|
+
show(entry: NotifyEntry): {
|
|
56
|
+
dismiss(): void;
|
|
57
|
+
};
|
|
58
|
+
confirm(req: {
|
|
59
|
+
message: string;
|
|
60
|
+
title?: string;
|
|
61
|
+
spec?: SomaConfirmSpec;
|
|
62
|
+
}): Promise<boolean>;
|
|
63
|
+
alert(req: {
|
|
64
|
+
message: string;
|
|
65
|
+
title?: string;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
confirmChoice?(spec: SomaChoiceConfirmSpec): Promise<SomaChoiceConfirmOutcome>;
|
|
68
|
+
announce?(req: {
|
|
69
|
+
message: string;
|
|
70
|
+
politeness: 'polite' | 'assertive';
|
|
71
|
+
}): void;
|
|
72
|
+
dispose(): void;
|
|
73
|
+
}
|
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
4
|
import esbuild, { type BuildContext, type Plugin } from 'esbuild';
|
|
5
5
|
import { readAllSomaPublicAliases } from './public-packages.cjs';
|
|
6
|
+
import { collectDevChunks, outputsRelativeTo, releaseDevChunks } from './dev-chunk-gc';
|
|
6
7
|
import { toPascalCase } from '../../core/server/api/service-path';
|
|
7
8
|
import { getSomaHostSourceRoot, getSomaHostApiRoot } from '../../core/server/host/source-packages.cjs';
|
|
8
9
|
import { getSomaSourceRootAliases, matchSomaSourceRoot, somaSourceRootFilter } from '../../core/server/host/source-aliases.cjs';
|
|
@@ -315,9 +316,16 @@ export async function buildBrowserClient(
|
|
|
315
316
|
let ctx: BuildContext | null = null;
|
|
316
317
|
let entryUrl = '/_soma/client/browser-entry.js';
|
|
317
318
|
|
|
319
|
+
// 开发态每次构建后按进程登记回收旧分片(dev-chunk-gc.ts):旧实现从不清理,chunks/ 会无限增长
|
|
320
|
+
const devRebuild = async (): Promise<void> => {
|
|
321
|
+
if (!ctx) return;
|
|
322
|
+
const result = await ctx.rebuild();
|
|
323
|
+
if (result.metafile) collectDevChunks(clientOutDir, outputsRelativeTo(clientOutDir, Object.keys(result.metafile.outputs)));
|
|
324
|
+
};
|
|
325
|
+
|
|
318
326
|
if (options.dev) {
|
|
319
|
-
ctx = await esbuild.context(buildOptions);
|
|
320
|
-
await
|
|
327
|
+
ctx = await esbuild.context({ ...buildOptions, metafile: true });
|
|
328
|
+
await devRebuild();
|
|
321
329
|
entryUrl = '/_soma/client/browser-entry.js';
|
|
322
330
|
} else {
|
|
323
331
|
const result = await esbuild.build({
|
|
@@ -352,13 +360,12 @@ export async function buildBrowserClient(
|
|
|
352
360
|
cssUrl,
|
|
353
361
|
cssText: finalCss,
|
|
354
362
|
rebuild: async () => {
|
|
355
|
-
|
|
356
|
-
await ctx.rebuild();
|
|
357
|
-
}
|
|
363
|
+
await devRebuild();
|
|
358
364
|
},
|
|
359
365
|
dispose: async () => {
|
|
360
366
|
if (ctx) {
|
|
361
367
|
await ctx.dispose();
|
|
368
|
+
releaseDevChunks(clientOutDir);
|
|
362
369
|
}
|
|
363
370
|
},
|
|
364
371
|
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 开发态客户端分片回收(`soma dev`)。
|
|
6
|
+
*
|
|
7
|
+
* 背景:开发态 esbuild 以 `chunks/[name]-[hash]` 命名分片、带内联 sourcemap;每次启动 / 重建内容一变就写一份新的,
|
|
8
|
+
* 旧的从不清理,几个应用累计到数 GB。
|
|
9
|
+
*
|
|
10
|
+
* 做法(按进程登记,不按时间猜):
|
|
11
|
+
* 1. 每个 dev 进程在 `<clientOutDir>/.live/<pid>.json` 登记自己当前这次构建产出的全部文件(相对 clientOutDir 的路径)。
|
|
12
|
+
* 2. 每次构建 / 重建后回收:保留集 = 自己的登记 ∪ 仍存活的其他 dev 进程的登记(`process.kill(pid, 0)` 判活;
|
|
13
|
+
* 已退出进程的登记文件随即删除);`chunks/` 下不在保留集里的文件删除。
|
|
14
|
+
* 3. 进程正常退出(dispose)时删除自己的登记。异常退出留下的登记,在下一个进程回收时因判活失败被清掉。
|
|
15
|
+
* 同一应用目录并发启动:内容相同的分片同名(内容哈希),两边登记里都有,不会误删;内容不同时各自的登记互相保留。
|
|
16
|
+
* 只回收 `chunks/` 目录下的文件;入口 `browser-entry.js` 与 `globals.css` 在开发态是固定名,覆盖写,不涉及回收。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const LIVE_DIR = '.live';
|
|
20
|
+
const CHUNKS_DIR = 'chunks';
|
|
21
|
+
|
|
22
|
+
function isAlive(pid: number): boolean {
|
|
23
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
24
|
+
if (pid === process.pid) return true;
|
|
25
|
+
try {
|
|
26
|
+
process.kill(pid, 0);
|
|
27
|
+
return true;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
// EPERM:进程存在但无权发信号 → 视为存活(保守,不删它的产物)
|
|
30
|
+
return (error as NodeJS.ErrnoException).code === 'EPERM';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readLiveSet(file: string): readonly string[] {
|
|
35
|
+
try {
|
|
36
|
+
const parsed: unknown = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
37
|
+
return Array.isArray(parsed) ? parsed.filter((v): v is string => typeof v === 'string') : [];
|
|
38
|
+
} catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** esbuild metafile 的输出路径(相对 cwd 或绝对)→ 相对 clientOutDir 的 posix 路径 */
|
|
44
|
+
export function outputsRelativeTo(clientOutDir: string, outputs: readonly string[]): string[] {
|
|
45
|
+
const rel: string[] = [];
|
|
46
|
+
for (const out of outputs) {
|
|
47
|
+
const abs = path.resolve(out);
|
|
48
|
+
const r = path.relative(clientOutDir, abs);
|
|
49
|
+
if (r === '' || r.startsWith('..') || path.isAbsolute(r)) continue;
|
|
50
|
+
rel.push(r.split(path.sep).join('/'));
|
|
51
|
+
}
|
|
52
|
+
return rel;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 登记本进程的产物并回收不再被任何存活 dev 进程使用的分片。失败只吞掉(回收是尽力而为,不影响开发服务)。 */
|
|
56
|
+
export function collectDevChunks(clientOutDir: string, ownOutputs: readonly string[]): { readonly removed: number } {
|
|
57
|
+
let removed = 0;
|
|
58
|
+
try {
|
|
59
|
+
const liveDir = path.join(clientOutDir, LIVE_DIR);
|
|
60
|
+
fs.mkdirSync(liveDir, { recursive: true });
|
|
61
|
+
fs.writeFileSync(path.join(liveDir, `${process.pid}.json`), JSON.stringify(ownOutputs), 'utf8');
|
|
62
|
+
|
|
63
|
+
const keep = new Set<string>(ownOutputs);
|
|
64
|
+
for (const name of fs.readdirSync(liveDir)) {
|
|
65
|
+
if (!name.endsWith('.json')) continue;
|
|
66
|
+
const pid = Number(name.slice(0, -'.json'.length));
|
|
67
|
+
const file = path.join(liveDir, name);
|
|
68
|
+
if (pid === process.pid) continue;
|
|
69
|
+
if (!isAlive(pid)) {
|
|
70
|
+
fs.rmSync(file, { force: true });
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
for (const rel of readLiveSet(file)) keep.add(rel);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const chunksDir = path.join(clientOutDir, CHUNKS_DIR);
|
|
77
|
+
if (!fs.existsSync(chunksDir)) return { removed };
|
|
78
|
+
for (const name of fs.readdirSync(chunksDir)) {
|
|
79
|
+
const rel = `${CHUNKS_DIR}/${name}`;
|
|
80
|
+
if (keep.has(rel)) continue;
|
|
81
|
+
const abs = path.join(chunksDir, name);
|
|
82
|
+
try {
|
|
83
|
+
if (fs.statSync(abs).isFile()) {
|
|
84
|
+
fs.rmSync(abs, { force: true });
|
|
85
|
+
removed += 1;
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
// 另一进程刚好删掉了:忽略
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
// 尽力而为
|
|
93
|
+
}
|
|
94
|
+
return { removed };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** dispose 时删除本进程的登记(产物留给下一次启动按登记回收)。 */
|
|
98
|
+
export function releaseDevChunks(clientOutDir: string): void {
|
|
99
|
+
try {
|
|
100
|
+
fs.rmSync(path.join(clientOutDir, LIVE_DIR, `${process.pid}.json`), { force: true });
|
|
101
|
+
} catch {
|
|
102
|
+
// 尽力而为
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { assertReservedRoutesShape, loadHostAssembly, invalidateHostAssembly, registerShellRoutes as registerCoreShellRoutes } from 'soma-core/server/host-assembly';
|
|
4
|
-
import { clearPagePayloadBufferCache } from './page-
|
|
4
|
+
import { clearPagePayloadBufferCache } from './page-payload-cache';
|
|
5
5
|
import { precompileAll, precompilePage } from '../../core/build/compiler/full-manifest-builder';
|
|
6
6
|
import { addressOfPageBase } from '../../core/build/compiler/page-base-resolver';
|
|
7
7
|
import { loadPageMarkupConfig } from '../../core/server/host/page-markup-config';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadPrecompiledManifest, findPrecompiledPage } from '../../core/server/
|
|
1
|
+
import { loadPrecompiledManifest, findPrecompiledPage } from '../../core/server/host/precompiled-manifest';
|
|
2
2
|
import { listBindings } from '../../core/server/runtime-space';
|
|
3
3
|
import { resolveSomaRuntimeLayout } from '../../core/server/runtime-space/root';
|
|
4
4
|
import { SomaRuntimeStore } from '../../core/server/runtime-space/store';
|
|
@@ -3,8 +3,9 @@ import zlib from 'node:zlib';
|
|
|
3
3
|
import { resolveHostLoginPath, SOMA_DEFAULT_LOGIN_PATH } from 'soma-core/server/host-assembly';
|
|
4
4
|
import { isStatusError } from '../../core/server/runtime-space/errors';
|
|
5
5
|
import { SomaPublishedPageError } from '../../core/server/host/published-page-assets';
|
|
6
|
+
import { PagePayloadBufferCache, clearPagePayloadBufferCache } from './page-payload-cache';
|
|
6
7
|
|
|
7
|
-
export { SOMA_DEFAULT_LOGIN_PATH };
|
|
8
|
+
export { SOMA_DEFAULT_LOGIN_PATH, PagePayloadBufferCache, clearPagePayloadBufferCache };
|
|
8
9
|
|
|
9
10
|
export function resolveLoginPath(
|
|
10
11
|
assembly?: { readonly login?: { readonly path?: string } } | null,
|
|
@@ -21,72 +22,6 @@ export interface CacheableLoadedPage {
|
|
|
21
22
|
const VARY_DEFAULT = 'Cookie, Authorization';
|
|
22
23
|
const VARY_ENCODING = 'Cookie, Authorization, Accept-Encoding';
|
|
23
24
|
|
|
24
|
-
interface CachedPagePayload {
|
|
25
|
-
readonly utf8: Uint8Array;
|
|
26
|
-
readonly gzip: Uint8Array | null;
|
|
27
|
-
readonly etag: string;
|
|
28
|
-
readonly size: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const MAX_CACHE_ENTRIES = 256;
|
|
32
|
-
const MAX_CACHE_BYTES = 64 * 1024 * 1024; // 64MB
|
|
33
|
-
|
|
34
|
-
class PagePayloadBufferLRU {
|
|
35
|
-
private cache = new Map<string, CachedPagePayload>();
|
|
36
|
-
private totalBytes = 0;
|
|
37
|
-
|
|
38
|
-
get(key: string): CachedPagePayload | undefined {
|
|
39
|
-
const entry = this.cache.get(key);
|
|
40
|
-
if (!entry) return undefined;
|
|
41
|
-
// LRU refresh: re-insert to end
|
|
42
|
-
this.cache.delete(key);
|
|
43
|
-
this.cache.set(key, entry);
|
|
44
|
-
return entry;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
set(key: string, entry: CachedPagePayload): void {
|
|
48
|
-
if (this.cache.has(key)) {
|
|
49
|
-
const old = this.cache.get(key)!;
|
|
50
|
-
this.totalBytes -= old.size;
|
|
51
|
-
this.cache.delete(key);
|
|
52
|
-
}
|
|
53
|
-
while (
|
|
54
|
-
(this.cache.size >= MAX_CACHE_ENTRIES || this.totalBytes + entry.size > MAX_CACHE_BYTES) &&
|
|
55
|
-
this.cache.size > 0
|
|
56
|
-
) {
|
|
57
|
-
const firstKey = this.cache.keys().next().value;
|
|
58
|
-
if (firstKey !== undefined) {
|
|
59
|
-
const item = this.cache.get(firstKey);
|
|
60
|
-
if (item) this.totalBytes -= item.size;
|
|
61
|
-
this.cache.delete(firstKey);
|
|
62
|
-
} else {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.cache.set(key, entry);
|
|
67
|
-
this.totalBytes += entry.size;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
clear(): void {
|
|
71
|
-
this.cache.clear();
|
|
72
|
-
this.totalBytes = 0;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get size(): number {
|
|
76
|
-
return this.cache.size;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get bytes(): number {
|
|
80
|
-
return this.totalBytes;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const PagePayloadBufferCache = new PagePayloadBufferLRU();
|
|
85
|
-
|
|
86
|
-
export function clearPagePayloadBufferCache(): void {
|
|
87
|
-
PagePayloadBufferCache.clear();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
25
|
function weakEtag(body: string | Uint8Array): string {
|
|
91
26
|
return `W/"${createHash('sha1').update(body).digest('hex').slice(0, 20)}"`;
|
|
92
27
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// 页面响应体预序列化二进制缓冲池(LRU),供 host-prepare.ts 与 page-http.ts 共用。
|
|
2
|
+
// 从契约层 page-http.ts 抽出至应用层,解除 host-prepare.ts -> page-http.ts 的反向依赖。
|
|
3
|
+
|
|
4
|
+
export interface CachedPagePayload {
|
|
5
|
+
readonly utf8: Uint8Array;
|
|
6
|
+
readonly gzip: Uint8Array | null;
|
|
7
|
+
readonly etag: string;
|
|
8
|
+
readonly size: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const MAX_CACHE_ENTRIES = 256;
|
|
12
|
+
const MAX_CACHE_BYTES = 64 * 1024 * 1024; // 64MB
|
|
13
|
+
|
|
14
|
+
class PagePayloadBufferLRU {
|
|
15
|
+
private cache = new Map<string, CachedPagePayload>();
|
|
16
|
+
private totalBytes = 0;
|
|
17
|
+
|
|
18
|
+
get(key: string): CachedPagePayload | undefined {
|
|
19
|
+
const entry = this.cache.get(key);
|
|
20
|
+
if (!entry) return undefined;
|
|
21
|
+
// LRU refresh: re-insert to end
|
|
22
|
+
this.cache.delete(key);
|
|
23
|
+
this.cache.set(key, entry);
|
|
24
|
+
return entry;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set(key: string, entry: CachedPagePayload): void {
|
|
28
|
+
if (this.cache.has(key)) {
|
|
29
|
+
const old = this.cache.get(key)!;
|
|
30
|
+
this.totalBytes -= old.size;
|
|
31
|
+
this.cache.delete(key);
|
|
32
|
+
}
|
|
33
|
+
while (
|
|
34
|
+
(this.cache.size >= MAX_CACHE_ENTRIES || this.totalBytes + entry.size > MAX_CACHE_BYTES) &&
|
|
35
|
+
this.cache.size > 0
|
|
36
|
+
) {
|
|
37
|
+
const firstKey = this.cache.keys().next().value;
|
|
38
|
+
if (firstKey !== undefined) {
|
|
39
|
+
const item = this.cache.get(firstKey);
|
|
40
|
+
if (item) this.totalBytes -= item.size;
|
|
41
|
+
this.cache.delete(firstKey);
|
|
42
|
+
} else {
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
this.cache.set(key, entry);
|
|
47
|
+
this.totalBytes += entry.size;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
clear(): void {
|
|
51
|
+
this.cache.clear();
|
|
52
|
+
this.totalBytes = 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get size(): number {
|
|
56
|
+
return this.cache.size;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get bytes(): number {
|
|
60
|
+
return this.totalBytes;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const PagePayloadBufferCache = new PagePayloadBufferLRU();
|
|
65
|
+
|
|
66
|
+
export function clearPagePayloadBufferCache(): void {
|
|
67
|
+
PagePayloadBufferCache.clear();
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soma-core",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.9",
|
|
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",
|
|
@@ -311,6 +311,17 @@
|
|
|
311
311
|
"dependencies": {
|
|
312
312
|
"@atlaskit/pragmatic-drag-and-drop": "1.8.1",
|
|
313
313
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "1.2.0",
|
|
314
|
+
"@lezer/css": "1.3.9",
|
|
315
|
+
"@lezer/go": "1.0.1",
|
|
316
|
+
"@lezer/highlight": "1.2.5",
|
|
317
|
+
"@lezer/html": "1.3.13",
|
|
318
|
+
"@lezer/java": "1.2.0",
|
|
319
|
+
"@lezer/javascript": "1.5.6",
|
|
320
|
+
"@lezer/json": "1.0.3",
|
|
321
|
+
"@lezer/markdown": "1.8.1",
|
|
322
|
+
"@lezer/python": "1.1.19",
|
|
323
|
+
"@lezer/xml": "1.0.6",
|
|
324
|
+
"@lezer/yaml": "1.0.4",
|
|
314
325
|
"@tanstack/table-core": "8.21.3",
|
|
315
326
|
"@tanstack/virtual-core": "3.19.7",
|
|
316
327
|
"@zag-js/combobox": "1.46.0",
|
|
@@ -328,11 +339,14 @@
|
|
|
328
339
|
"esbuild": "0.25.12",
|
|
329
340
|
"jiti": "1.21.7",
|
|
330
341
|
"js-yaml": "4.3.2",
|
|
342
|
+
"markdown-it": "15.0.3",
|
|
343
|
+
"markdown-it-cjk-friendly": "3.0.0",
|
|
344
|
+
"markdown-it-footnote": "4.0.0",
|
|
331
345
|
"mime-types": "2.1.35",
|
|
332
346
|
"parse5": "7.3.0",
|
|
333
347
|
"qrcode-generator": "2.0.4",
|
|
334
348
|
"server-only": "0.0.1",
|
|
335
|
-
"soma-foundation": "^0.1.
|
|
349
|
+
"soma-foundation": "^0.1.6",
|
|
336
350
|
"temporal-polyfill": "0.3.2"
|
|
337
351
|
},
|
|
338
352
|
"peerDependencies": {
|