soma-core 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/SomaPageClient.tsx +364 -0
- package/app/api/[...path]/route.ts +9 -85
- package/app/api/page/route.ts +57 -35
- package/app/api/soma-manifest/route.ts +39 -0
- package/app/components/SomaHydrationShell.tsx +23 -0
- package/app/favicon.ico/route.ts +13 -0
- package/app/layout.tsx +2 -2
- package/app/loading.tsx +5 -0
- package/app/page.tsx +19 -128
- package/bin/soma-lsp.cjs +195 -0
- package/bin/soma-sync.cjs +3 -0
- package/bin/soma.cjs +13 -1
- package/core/api/IService.ts +6 -10
- package/core/api/load-host-service.ts +75 -0
- package/core/api/service-path.ts +39 -0
- package/core/base/SomaEntity.ts +3 -10
- package/core/base/SomaLocaleOnlyPageRoot.ts +3 -4
- package/core/base/SomaPageRootBase.ts +20 -3
- package/core/base/decorators/Event.ts +23 -0
- package/core/base/decorators/Locale.ts +35 -0
- package/core/base/decorators/Page.ts +16 -0
- package/core/base/decorators/Show.ts +20 -0
- package/core/base/decorators/ShowList.ts +34 -0
- package/core/base/decorators/index.ts +5 -0
- package/core/base/index.ts +2 -0
- package/core/base/runAsync.ts +32 -0
- package/core/compiler/full-manifest-builder.ts +33 -7
- package/core/compiler/host-config-sync.cjs +38 -0
- package/core/compiler/manifest-compiler.ts +3 -2
- package/core/compiler/page-base-resolver.ts +26 -0
- package/core/compiler/precompiled-manifest-loader.ts +34 -0
- package/core/compiler/rollup-plugin-soma.ts +45 -0
- package/core/compiler/rspack-plugin-soma.js +33 -0
- package/core/compiler/soma-manifest-webpack-plugin.js +188 -0
- package/core/compiler/soma-precompile.js +3513 -0
- package/core/compiler/soma-precompile.ts +52 -6
- package/core/compiler/soma-rspack-yaml-loader.js +22 -0
- package/core/compiler/soma-webpack-loader.js +7 -1
- package/core/compiler/vite-plugin-soma.ts +11 -1
- package/core/container/IContainerAdapter.ts +36 -0
- package/core/container/MiniProgramContainerAdapter.ts +190 -0
- package/core/container/ReactNativeContainerAdapter.ts +189 -0
- package/core/container/SomaContainerAdapter.ts +17 -6
- package/core/diagnostics/SomaDiagnostics.ts +1 -1
- package/core/diagnostics/SomaTelemetry.ts +100 -0
- package/core/diagnostics/telemetry-context.ts +15 -0
- package/core/engine/asset-resolver.ts +39 -4
- package/core/engine/dom-renderer.ts +169 -35
- package/core/engine/event-engine.ts +110 -41
- package/core/engine/on-change-engine.ts +71 -0
- package/core/engine/property-watcher.ts +117 -0
- package/core/engine/reactive-proxy.ts +11 -5
- package/core/engine/render-engine.ts +97 -11
- package/core/engine/runtime-builder.ts +88 -11
- package/core/engine/scope-resolver.ts +65 -9
- package/core/engine/soma-bootstrap.ts +448 -244
- package/core/engine/style-binder.ts +423 -0
- package/core/engine/theme-variables.ts +37 -0
- package/core/engine/timer-engine.ts +92 -0
- package/core/engine/trigger-engine.ts +55 -0
- package/core/host/app-config.stub.ts +2 -0
- package/core/host/locale.stub.ts +2 -0
- package/core/host/resolve-host-bootstrap.ts +28 -0
- package/core/host/soma-bootstrap-host.stub.ts +4 -0
- package/core/host/source-packages.ts +112 -0
- package/core/index.ts +33 -2
- package/core/infra/auth/TokenAuthService.ts +17 -3
- package/core/infra/http/IHttpClient.ts +11 -1
- package/core/infra/http/SomaHttpService.ts +89 -31
- package/core/infra/i18n/DefaultI18n.ts +6 -18
- package/core/infra/i18n/II18n.ts +2 -3
- package/core/infra/notify/DomNotifyService.ts +98 -0
- package/core/infra/notify/INotifyTheme.ts +22 -0
- package/core/infra/realtime/IRealtimeService.ts +23 -0
- package/core/infra/realtime/IRealtimeTransport.ts +9 -0
- package/core/infra/realtime/SomaRealtimeService.ts +95 -0
- package/core/infra/realtime/SseRealtimeTransport.ts +36 -0
- package/core/infra/realtime/WebSocketRealtimeTransport.ts +102 -0
- package/core/infra/router/router-path.ts +28 -0
- package/core/infra/storage/SessionStorageService.ts +59 -0
- package/core/lsp/cross-file-diagnostics.cjs +160 -0
- package/core/lsp/event-yaml-completion.cjs +106 -0
- package/core/lsp/extra-completion.cjs +64 -0
- package/core/lsp/lsp-navigation.cjs +191 -0
- package/core/lsp/ui-yaml-completion.cjs +170 -0
- package/core/manifest/manifest-contract.ts +12 -0
- package/core/middleware/createPermissionMiddleware.ts +37 -0
- package/core/parser/annotation-extractor.ts +113 -0
- package/core/parser/pipeline-parser.ts +344 -276
- package/core/parser/style-config-parser.ts +340 -0
- package/core/parser/timer-parser.ts +70 -0
- package/core/parser/trigger-parser.ts +90 -0
- package/core/parser/ui-config-parser.ts +73 -1
- package/core/quality/SomaQualityRegistry.ts +68 -0
- package/core/runtime/SomaRuntimeServices.ts +100 -0
- package/core/runtime/SomaSnapshotStore.ts +5 -3
- package/core/types/domain.types.ts +5 -2
- package/core/types/event.types.ts +82 -57
- package/core/types/manifest.types.ts +2 -0
- package/core/types/style-config.types.ts +76 -0
- package/core/types/timer.types.ts +23 -0
- package/core/types/trigger.types.ts +14 -0
- package/core/types/ui-config.types.ts +9 -0
- package/core/types/watcher.types.ts +29 -0
- package/dist/cli/soma.js +23 -23
- package/dist/core/index.cjs +9065 -0
- package/dist/diagnostics/telemetry.cjs +105 -0
- package/dist/preview-export.cjs +3401 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/api/IService.d.ts +28 -0
- package/dist/types/api/load-host-service.d.ts +5 -0
- package/dist/types/api/service-path.d.ts +13 -0
- package/dist/types/base/SomaApi.d.ts +5 -0
- package/dist/types/base/SomaDict.d.ts +89 -0
- package/dist/types/base/SomaEntity.d.ts +15 -0
- package/dist/types/base/SomaHttpClient.d.ts +66 -0
- package/dist/types/base/SomaLocaleOnlyPageRoot.d.ts +3 -0
- package/dist/types/base/SomaPageRootBase.d.ts +49 -0
- package/dist/types/base/SomaValidator.d.ts +55 -0
- package/dist/types/base/decorators/Event.d.ts +10 -0
- package/dist/types/base/decorators/Locale.d.ts +9 -0
- package/dist/types/base/decorators/Page.d.ts +4 -0
- package/dist/types/base/decorators/Show.d.ts +7 -0
- package/dist/types/base/decorators/ShowList.d.ts +12 -0
- package/dist/types/base/decorators/index.d.ts +5 -0
- package/dist/types/base/index.d.ts +9 -0
- package/dist/types/base/runAsync.d.ts +12 -0
- package/dist/types/compiler/full-manifest-builder.d.ts +35 -0
- package/dist/types/compiler/manifest-compiler.d.ts +29 -0
- package/dist/types/compiler/page-base-resolver.d.ts +6 -0
- package/dist/types/compiler/precompiled-manifest-loader.d.ts +5 -0
- package/dist/types/compiler/rollup-plugin-soma.d.ts +14 -0
- package/dist/types/compiler/route-builder.d.ts +12 -0
- package/dist/types/compiler/soma-precompile.d.ts +40 -0
- package/dist/types/compiler/vite-plugin-soma.d.ts +34 -0
- package/dist/types/container/IContainerAdapter.d.ts +30 -0
- package/dist/types/container/MiniProgramContainerAdapter.d.ts +52 -0
- package/dist/types/container/ReactNativeContainerAdapter.d.ts +47 -0
- package/dist/types/container/SomaContainerAdapter.d.ts +30 -0
- package/dist/types/diagnostics/SomaDiagnostics.d.ts +64 -0
- package/dist/types/diagnostics/SomaTelemetry.d.ts +32 -0
- package/dist/types/diagnostics/telemetry-context.d.ts +4 -0
- package/dist/types/engine/asset-resolver.d.ts +17 -0
- package/dist/types/engine/dom-renderer.d.ts +41 -0
- package/dist/types/engine/event-engine.d.ts +64 -0
- package/dist/types/engine/lis.d.ts +10 -0
- package/dist/types/engine/on-change-engine.d.ts +16 -0
- package/dist/types/engine/property-watcher.d.ts +18 -0
- package/dist/types/engine/reactive-proxy.d.ts +58 -0
- package/dist/types/engine/render-engine.d.ts +73 -0
- package/dist/types/engine/runtime-builder.d.ts +58 -0
- package/dist/types/engine/scope-resolver.d.ts +90 -0
- package/dist/types/engine/soma-bootstrap.d.ts +112 -0
- package/dist/types/engine/style-binder.d.ts +81 -0
- package/dist/types/engine/theme-variables.d.ts +3 -0
- package/dist/types/engine/timer-engine.d.ts +19 -0
- package/dist/types/engine/trigger-engine.d.ts +16 -0
- package/dist/types/host/app-config.stub.d.ts +3 -0
- package/dist/types/host/locale.stub.d.ts +3 -0
- package/dist/types/host/resolve-host-bootstrap.d.ts +11 -0
- package/dist/types/host/soma-bootstrap-host.stub.d.ts +3 -0
- package/dist/types/host/source-packages.d.ts +8 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/infra/auth/IAuthService.d.ts +12 -0
- package/dist/types/infra/auth/TokenAuthService.d.ts +26 -0
- package/dist/types/infra/cache/ICache.d.ts +12 -0
- package/dist/types/infra/cache/MemoryCache.d.ts +14 -0
- package/dist/types/infra/cache/ServerFileCache.d.ts +37 -0
- package/dist/types/infra/config/IConfig.d.ts +9 -0
- package/dist/types/infra/config/SomaConfig.d.ts +21 -0
- package/dist/types/infra/event-bus/IEventBus.d.ts +8 -0
- package/dist/types/infra/event-bus/SomaEventBus.d.ts +9 -0
- package/dist/types/infra/http/IHttpClient.d.ts +28 -0
- package/dist/types/infra/http/SomaHttpService.d.ts +27 -0
- package/dist/types/infra/i18n/DefaultI18n.d.ts +7 -0
- package/dist/types/infra/i18n/II18n.d.ts +6 -0
- package/dist/types/infra/logger/ConsoleLogger.d.ts +14 -0
- package/dist/types/infra/logger/ILogger.d.ts +17 -0
- package/dist/types/infra/notify/DefaultNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/DomNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/INotifyService.d.ts +12 -0
- package/dist/types/infra/notify/INotifyTheme.d.ts +12 -0
- package/dist/types/infra/permission/IPermission.d.ts +10 -0
- package/dist/types/infra/permission/SomaPermission.d.ts +19 -0
- package/dist/types/infra/realtime/IRealtimeService.d.ts +13 -0
- package/dist/types/infra/realtime/IRealtimeTransport.d.ts +8 -0
- package/dist/types/infra/realtime/SomaRealtimeService.d.ts +20 -0
- package/dist/types/infra/realtime/SseRealtimeTransport.d.ts +11 -0
- package/dist/types/infra/realtime/WebSocketRealtimeTransport.d.ts +30 -0
- package/dist/types/infra/router/IRouter.d.ts +16 -0
- package/dist/types/infra/router/SomaRouter.d.ts +18 -0
- package/dist/types/infra/router/router-path.d.ts +6 -0
- package/dist/types/infra/storage/IStorageService.d.ts +7 -0
- package/dist/types/infra/storage/MemoryStorageService.d.ts +15 -0
- package/dist/types/infra/storage/SessionStorageService.d.ts +14 -0
- package/dist/types/infra/timer/ITimer.d.ts +13 -0
- package/dist/types/infra/timer/SomaTimer.d.ts +21 -0
- package/dist/types/manifest/manifest-contract.d.ts +4 -0
- package/dist/types/middleware/SomaMiddlewareChain.d.ts +6 -0
- package/dist/types/middleware/createPermissionMiddleware.d.ts +14 -0
- package/dist/types/parser/annotation-extractor.d.ts +12 -0
- package/dist/types/parser/pipeline-parser.d.ts +62 -0
- package/dist/types/parser/style-config-parser.d.ts +20 -0
- package/dist/types/parser/timer-parser.d.ts +6 -0
- package/dist/types/parser/trigger-parser.d.ts +13 -0
- package/dist/types/parser/ui-config-parser.d.ts +34 -0
- package/dist/types/parser/yaml-loader.d.ts +21 -0
- package/dist/types/quality/SomaQualityRegistry.d.ts +31 -0
- package/dist/types/runtime/SomaRuntimeServices.d.ts +35 -0
- package/dist/types/runtime/SomaSnapshotStore.d.ts +13 -0
- package/dist/types/scheduler/SomaScheduler.d.ts +25 -0
- package/dist/types/types/domain.types.d.ts +82 -0
- package/dist/types/types/engine.types.d.ts +22 -0
- package/dist/types/types/event.types.d.ts +61 -0
- package/dist/types/types/keyboard.types.d.ts +4 -0
- package/dist/types/types/manifest.types.d.ts +29 -0
- package/dist/types/types/scheduler.types.d.ts +8 -0
- package/dist/types/types/style-config.types.d.ts +62 -0
- package/dist/types/types/timer.types.d.ts +19 -0
- package/dist/types/types/trigger.types.d.ts +12 -0
- package/dist/types/types/ui-config.types.d.ts +85 -0
- package/dist/types/types/watcher.types.d.ts +24 -0
- package/dist/types/validation/contract-validator.d.ts +40 -0
- package/editor/vscode/extension.js +39 -0
- package/editor/vscode/language-configuration.json +17 -0
- package/editor/vscode/package.json +98 -0
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +30 -0
- package/editor/vscode/syntaxes/soma-ui-yaml.tmLanguage.json +42 -0
- package/global.d.ts +22 -3
- package/next.config.js +73 -4
- package/package.json +58 -17
- package/tailwind.config.ts +36 -13
- package/tsconfig.json +6 -2
- package/core/router/RouteHandler.ts +0 -93
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const LOCALE_REGISTRY = new WeakMap<Function, LocaleEntry[]>();
|
|
2
|
+
|
|
3
|
+
interface LocaleEntry {
|
|
4
|
+
propertyKey: string;
|
|
5
|
+
localeKey: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Bind a locale.yaml key to a domain property (injected after _locale load) */
|
|
9
|
+
export function Locale(key: string): PropertyDecorator {
|
|
10
|
+
return (target: object, propertyKey: string | symbol) => {
|
|
11
|
+
const ctor = (target as { constructor: Function }).constructor;
|
|
12
|
+
const existing = LOCALE_REGISTRY.get(ctor) ?? [];
|
|
13
|
+
existing.push({ propertyKey: String(propertyKey), localeKey: key });
|
|
14
|
+
LOCALE_REGISTRY.set(ctor, existing);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function applyLocaleMetadata(instance: object): void {
|
|
19
|
+
const locale = (instance as { _locale?: Record<string, string> })._locale;
|
|
20
|
+
if (!locale) return;
|
|
21
|
+
|
|
22
|
+
const entries = LOCALE_REGISTRY.get(instance.constructor as Function) ?? [];
|
|
23
|
+
|
|
24
|
+
for (const { propertyKey, localeKey } of entries) {
|
|
25
|
+
if (localeKey in locale) {
|
|
26
|
+
(instance as Record<string, unknown>)[propertyKey] = locale[localeKey];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getLocaleMetadata(
|
|
32
|
+
ctor: new (...args: unknown[]) => object,
|
|
33
|
+
): LocaleEntry[] {
|
|
34
|
+
return LOCALE_REGISTRY.get(ctor) ?? [];
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const PAGE_REGISTRY = new WeakMap<Function, string>();
|
|
2
|
+
|
|
3
|
+
/** @Page(id) — 标记 Class 绑定的 data-soma-host 标识 */
|
|
4
|
+
export function Page(id: string): ClassDecorator {
|
|
5
|
+
return (target) => {
|
|
6
|
+
PAGE_REGISTRY.set(target as Function, id);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getPageId(ctor: Function): string | undefined {
|
|
11
|
+
return PAGE_REGISTRY.get(ctor);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function hasPageMetadata(ctor: Function): boolean {
|
|
15
|
+
return PAGE_REGISTRY.has(ctor);
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ShowEntry {
|
|
2
|
+
propertyKey: string;
|
|
3
|
+
somaId: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const SHOW_REGISTRY = new WeakMap<Function, ShowEntry[]>();
|
|
7
|
+
|
|
8
|
+
/** @Show(somaId) — 单向绑定属性到 DOM 节点 */
|
|
9
|
+
export function Show(somaId: string): PropertyDecorator {
|
|
10
|
+
return (target: object, propertyKey: string | symbol) => {
|
|
11
|
+
const ctor = (target as { constructor: Function }).constructor;
|
|
12
|
+
const existing = SHOW_REGISTRY.get(ctor) ?? [];
|
|
13
|
+
existing.push({ propertyKey: String(propertyKey), somaId });
|
|
14
|
+
SHOW_REGISTRY.set(ctor, existing);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getShowMetadata(ctor: Function): ShowEntry[] {
|
|
19
|
+
return SHOW_REGISTRY.get(ctor) ?? [];
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface ShowListEntry {
|
|
2
|
+
propertyKey: string;
|
|
3
|
+
somaId: string;
|
|
4
|
+
entityClass: new (...args: unknown[]) => object;
|
|
5
|
+
itemVar?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const SHOW_LIST_REGISTRY = new WeakMap<Function, ShowListEntry[]>();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @ShowList(somaId, EntityClass, itemVar?) — 列表绑定,声明子实体类型
|
|
12
|
+
* itemVar 默认取属性名首字母(如 sensors → s)
|
|
13
|
+
*/
|
|
14
|
+
export function ShowList(
|
|
15
|
+
somaId: string,
|
|
16
|
+
entityClass: new (...args: unknown[]) => object,
|
|
17
|
+
itemVar?: string,
|
|
18
|
+
): PropertyDecorator {
|
|
19
|
+
return (target: object, propertyKey: string | symbol) => {
|
|
20
|
+
const ctor = (target as { constructor: Function }).constructor;
|
|
21
|
+
const existing = SHOW_LIST_REGISTRY.get(ctor) ?? [];
|
|
22
|
+
existing.push({
|
|
23
|
+
propertyKey: String(propertyKey),
|
|
24
|
+
somaId,
|
|
25
|
+
entityClass,
|
|
26
|
+
itemVar,
|
|
27
|
+
});
|
|
28
|
+
SHOW_LIST_REGISTRY.set(ctor, existing);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getShowListMetadata(ctor: Function): ShowListEntry[] {
|
|
33
|
+
return SHOW_LIST_REGISTRY.get(ctor) ?? [];
|
|
34
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Locale, applyLocaleMetadata, getLocaleMetadata } from './Locale';
|
|
2
|
+
export { Page, getPageId, hasPageMetadata } from './Page';
|
|
3
|
+
export { Show, getShowMetadata, type ShowEntry } from './Show';
|
|
4
|
+
export { ShowList, getShowListMetadata, type ShowListEntry } from './ShowList';
|
|
5
|
+
export { Event, getEventMetadata, type EventEntry } from './Event';
|
package/core/base/index.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** 支持 runAsync 的状态宿主(SomaEntity / SomaPageRootBase 均满足) */
|
|
2
|
+
export interface AsyncStateHost {
|
|
3
|
+
loading?: boolean;
|
|
4
|
+
error?: string | null;
|
|
5
|
+
pageLoading?: boolean;
|
|
6
|
+
pageError?: string | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 独立 runAsync 工具 — 自动管理 loading / error 状态
|
|
11
|
+
* SomaEntity 与 SomaPageRootBase 内部均委托此方法
|
|
12
|
+
*/
|
|
13
|
+
export async function runAsync<R>(
|
|
14
|
+
host: AsyncStateHost,
|
|
15
|
+
fn: () => Promise<R>,
|
|
16
|
+
): Promise<R | null> {
|
|
17
|
+
const loadingKey = 'pageLoading' in host ? 'pageLoading' : 'loading';
|
|
18
|
+
const errorKey = 'pageError' in host ? 'pageError' : 'error';
|
|
19
|
+
|
|
20
|
+
(host as Record<string, unknown>)[loadingKey] = true;
|
|
21
|
+
(host as Record<string, unknown>)[errorKey] = null;
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
return await fn();
|
|
25
|
+
} catch (e) {
|
|
26
|
+
(host as Record<string, unknown>)[errorKey] =
|
|
27
|
+
e instanceof Error ? e.message : String(e);
|
|
28
|
+
return null;
|
|
29
|
+
} finally {
|
|
30
|
+
(host as Record<string, unknown>)[loadingKey] = false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -3,14 +3,34 @@
|
|
|
3
3
|
|
|
4
4
|
import type { UiConfig } from '../types/ui-config.types';
|
|
5
5
|
import type { ParsedEvent } from '../types/event.types';
|
|
6
|
-
import {
|
|
6
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
7
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
8
|
+
import type { StyleConfig } from '../types/style-config.types';
|
|
9
|
+
import { compileUiConfig, compileStyleConfig, precompileYaml } from '@core/compiler/soma-precompile';
|
|
10
|
+
import { parseEventConfig } from '../parser/pipeline-parser';
|
|
11
|
+
import { splitEventConfigRaw } from '../parser/trigger-parser';
|
|
7
12
|
import { buildRouteTable, type SomaRouteEntry } from './route-builder';
|
|
8
13
|
import yaml from 'js-yaml';
|
|
9
14
|
|
|
15
|
+
function compileEventBundle(eventYaml: string) {
|
|
16
|
+
if (!eventYaml.trim()) {
|
|
17
|
+
return { events: [], triggers: [] as PropertyTrigger[], timers: [] as ParsedTimer[] };
|
|
18
|
+
}
|
|
19
|
+
const { eventsRaw, triggers, timers } = splitEventConfigRaw(yaml.load(eventYaml));
|
|
20
|
+
return {
|
|
21
|
+
events: parseEventConfig(eventsRaw as any),
|
|
22
|
+
triggers,
|
|
23
|
+
timers,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
10
27
|
export interface SomaPrecompiledPage {
|
|
11
28
|
path: string;
|
|
12
29
|
uiConfig: UiConfig;
|
|
13
30
|
eventConfig: ParsedEvent[];
|
|
31
|
+
triggers: PropertyTrigger[];
|
|
32
|
+
timers: ParsedTimer[];
|
|
33
|
+
styleConfig?: StyleConfig;
|
|
14
34
|
}
|
|
15
35
|
|
|
16
36
|
export interface SomaPrecompiledManifest {
|
|
@@ -28,16 +48,22 @@ export function precompileAll(inputs: {
|
|
|
28
48
|
htmlFiles: string[];
|
|
29
49
|
localeYaml: string;
|
|
30
50
|
appConfigYaml: string;
|
|
31
|
-
pages: Array<{ path: string; uiYaml: string; eventYaml: string }>;
|
|
51
|
+
pages: Array<{ path: string; uiYaml: string; eventYaml: string; styleYaml?: string }>;
|
|
32
52
|
}): SomaPrecompiledManifest {
|
|
33
53
|
return {
|
|
34
54
|
routes: buildRouteTable(inputs.htmlFiles),
|
|
35
55
|
locale: (yaml.load(inputs.localeYaml) as Record<string, unknown>) || {},
|
|
36
56
|
appConfig: yaml.load(inputs.appConfigYaml) ?? {},
|
|
37
|
-
pages: inputs.pages.map(p =>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
57
|
+
pages: inputs.pages.map(p => {
|
|
58
|
+
const eventBundle = compileEventBundle(p.eventYaml);
|
|
59
|
+
return {
|
|
60
|
+
path: p.path,
|
|
61
|
+
uiConfig: compileUiConfig(p.uiYaml),
|
|
62
|
+
eventConfig: eventBundle.events,
|
|
63
|
+
triggers: eventBundle.triggers,
|
|
64
|
+
timers: eventBundle.timers,
|
|
65
|
+
styleConfig: p.styleYaml ? compileStyleConfig(p.styleYaml) : undefined,
|
|
66
|
+
};
|
|
67
|
+
}),
|
|
42
68
|
};
|
|
43
69
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** HOST 配置同步 — 供 bin/soma-sync.cjs 使用 */
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
const SYNC_FILES = [
|
|
6
|
+
'config/locale.yaml',
|
|
7
|
+
'config/app.config.yaml',
|
|
8
|
+
'tailwind.config.js',
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
function syncHostConfig(hostDir, outputDir) {
|
|
12
|
+
const target = outputDir ?? path.join(hostDir, '.soma-sync');
|
|
13
|
+
const copied = [];
|
|
14
|
+
const skipped = [];
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(target)) fs.mkdirSync(target, { recursive: true });
|
|
17
|
+
|
|
18
|
+
for (const rel of SYNC_FILES) {
|
|
19
|
+
const src = path.join(hostDir, rel);
|
|
20
|
+
const dest = path.join(target, rel);
|
|
21
|
+
if (!fs.existsSync(src)) {
|
|
22
|
+
skipped.push(rel);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
26
|
+
fs.copyFileSync(src, dest);
|
|
27
|
+
copied.push(rel);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fs.writeFileSync(
|
|
31
|
+
path.join(target, 'sync-manifest.json'),
|
|
32
|
+
JSON.stringify({ syncedAt: new Date().toISOString(), hostDir, files: copied }, null, 2),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return { copied, skipped, target };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { syncHostConfig, SYNC_FILES };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
2
|
import type { SomaScopeResolver } from '../engine/scope-resolver';
|
|
3
3
|
import type { BindingType } from '../types/engine.types';
|
|
4
4
|
import type {
|
|
@@ -16,7 +16,7 @@ import type { ParsedEvent } from '../types/event.types';
|
|
|
16
16
|
|
|
17
17
|
export interface SomaManifestCompilerInput {
|
|
18
18
|
container: HTMLElement;
|
|
19
|
-
adapter:
|
|
19
|
+
adapter: IContainerAdapter;
|
|
20
20
|
uiConfig: UiConfig;
|
|
21
21
|
eventConfig: ParsedEvent[];
|
|
22
22
|
resolver: SomaScopeResolver;
|
|
@@ -64,6 +64,7 @@ export class SomaManifestCompiler {
|
|
|
64
64
|
bindingIndex,
|
|
65
65
|
events: eventResult.events,
|
|
66
66
|
eventIndex: eventResult.eventIndex,
|
|
67
|
+
initProps: input.uiConfig.initProps,
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve URL path to html/ui/event base name (without .html).
|
|
3
|
+
* Tries exact path first, then foo/index short form (/items → items/index).
|
|
4
|
+
*/
|
|
5
|
+
export function urlPathToCandidates(urlPath: string): string[] {
|
|
6
|
+
const withoutQuery = urlPath.split('?')[0]?.split('#')[0] ?? urlPath;
|
|
7
|
+
const clean = withoutQuery.replace(/^\//, '').replace(/\.html$/i, '');
|
|
8
|
+
const base = clean || 'index';
|
|
9
|
+
const candidates = [base];
|
|
10
|
+
if (base.endsWith('/index')) {
|
|
11
|
+
candidates.push(base.slice(0, -'/index'.length));
|
|
12
|
+
}
|
|
13
|
+
if (!base.includes('/') && base !== 'index') {
|
|
14
|
+
candidates.push(`${base}/index`);
|
|
15
|
+
}
|
|
16
|
+
return candidates;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isSafePageBase(base: string): boolean {
|
|
20
|
+
const normalized = base.replace(/\\/g, '/');
|
|
21
|
+
return (
|
|
22
|
+
!normalized.startsWith('..')
|
|
23
|
+
&& !normalized.includes('\0')
|
|
24
|
+
&& !/^[a-zA-Z]:/.test(normalized)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import type { SomaPrecompiledManifest, SomaPrecompiledPage } from '../compiler/full-manifest-builder';
|
|
4
|
+
import { urlPathToCandidates } from './page-base-resolver';
|
|
5
|
+
|
|
6
|
+
/** Load full precompiled manifest from HOST .soma/manifest.json */
|
|
7
|
+
export function loadPrecompiledManifest(hostDir: string): SomaPrecompiledManifest | null {
|
|
8
|
+
const manifestPath = path.join(hostDir, '.soma', 'manifest.json');
|
|
9
|
+
if (!fs.existsSync(manifestPath)) return null;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const raw = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as SomaPrecompiledManifest;
|
|
13
|
+
if (!raw?.pages || !Array.isArray(raw.pages)) return null;
|
|
14
|
+
return raw;
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Find precompiled page by route (supports /items → items/index short path) */
|
|
21
|
+
export function findPrecompiledPage(
|
|
22
|
+
manifest: SomaPrecompiledManifest,
|
|
23
|
+
urlPath: string,
|
|
24
|
+
): SomaPrecompiledPage | null {
|
|
25
|
+
for (const base of urlPathToCandidates(urlPath)) {
|
|
26
|
+
const route = base === 'index' ? '/' : `/${base}`;
|
|
27
|
+
const page = manifest.pages.find((p) => {
|
|
28
|
+
const pageBase = p.path.replace(/^\//, '').replace(/\.html$/i, '');
|
|
29
|
+
return p.path === route || pageBase === base;
|
|
30
|
+
});
|
|
31
|
+
if (page) return page;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// core/compiler/rollup-plugin-soma.ts
|
|
2
|
+
// Rollup 预编译插件:构建阶段将 YAML 编译为 JS 模块(与 vite-plugin-soma 对齐)
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
precompileUiYaml,
|
|
6
|
+
precompileEventYaml,
|
|
7
|
+
precompileStyleYaml,
|
|
8
|
+
precompileYaml,
|
|
9
|
+
} from './soma-precompile';
|
|
10
|
+
|
|
11
|
+
export interface SomaRollupPluginOptions {
|
|
12
|
+
uiSuffix?: string;
|
|
13
|
+
eventSuffix?: string;
|
|
14
|
+
styleSuffix?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function somaRollupPlugin(options: SomaRollupPluginOptions = {}) {
|
|
18
|
+
const uiSuffix = options.uiSuffix ?? '_ui.yaml';
|
|
19
|
+
const eventSuffix = options.eventSuffix ?? '_event.yaml';
|
|
20
|
+
const styleSuffix = options.styleSuffix ?? '_style.yaml';
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
name: 'rollup-plugin-soma',
|
|
24
|
+
transform(code: string, id: string) {
|
|
25
|
+
if (!id.endsWith('.yaml') && !id.endsWith('.yml')) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
if (id.endsWith(uiSuffix)) {
|
|
31
|
+
return { code: `export default ${precompileUiYaml(code)};`, map: { mappings: '' } };
|
|
32
|
+
}
|
|
33
|
+
if (id.endsWith(eventSuffix)) {
|
|
34
|
+
return { code: `export default ${precompileEventYaml(code)};`, map: { mappings: '' } };
|
|
35
|
+
}
|
|
36
|
+
if (id.endsWith(styleSuffix)) {
|
|
37
|
+
return { code: `export default ${precompileStyleYaml(code)};`, map: { mappings: '' } };
|
|
38
|
+
}
|
|
39
|
+
return { code: `export default ${precompileYaml(code)};`, map: { mappings: '' } };
|
|
40
|
+
} catch (err) {
|
|
41
|
+
throw new Error(`[rollup-plugin-soma] Failed to compile ${id}: ${err}`);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const {
|
|
2
|
+
precompileUiYaml,
|
|
3
|
+
precompileEventYaml,
|
|
4
|
+
precompileStyleYaml,
|
|
5
|
+
precompileYaml,
|
|
6
|
+
} = require('./soma-precompile');
|
|
7
|
+
|
|
8
|
+
function somaRspackPlugin(options = {}) {
|
|
9
|
+
const uiSuffix = options.uiSuffix ?? '_ui.yaml';
|
|
10
|
+
const eventSuffix = options.eventSuffix ?? '_event.yaml';
|
|
11
|
+
const styleSuffix = options.styleSuffix ?? '_style.yaml';
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
name: 'rspack-plugin-soma',
|
|
15
|
+
enforce: 'pre',
|
|
16
|
+
module: {
|
|
17
|
+
rules: [
|
|
18
|
+
{
|
|
19
|
+
test: /\.ya?ml$/,
|
|
20
|
+
type: 'javascript/auto',
|
|
21
|
+
use: [
|
|
22
|
+
{
|
|
23
|
+
loader: require.resolve('./soma-rspack-yaml-loader.js'),
|
|
24
|
+
options: { uiSuffix, eventSuffix, styleSuffix },
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = { somaRspackPlugin };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webpack 插件:构建期全量预编译 manifest → .soma/manifest.json
|
|
3
|
+
*/
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const createJiti = require('jiti');
|
|
7
|
+
|
|
8
|
+
function collectHtmlFiles(dir, prefix = '', acc = []) {
|
|
9
|
+
if (!fs.existsSync(dir)) return acc;
|
|
10
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
11
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
12
|
+
const full = path.join(dir, entry.name);
|
|
13
|
+
if (entry.isDirectory()) collectHtmlFiles(full, rel, acc);
|
|
14
|
+
else if (entry.name.endsWith('.html')) acc.push(rel);
|
|
15
|
+
}
|
|
16
|
+
return acc;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readJson(filePath) {
|
|
20
|
+
try {
|
|
21
|
+
if (!fs.existsSync(filePath)) return null;
|
|
22
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function packagePathInNodeModules(hostDir, packageName) {
|
|
29
|
+
return path.join(hostDir, 'node_modules', ...packageName.split('/'));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolvePackageRoot(hostDir, packageName, version) {
|
|
33
|
+
const nodeModulesPath = packagePathInNodeModules(hostDir, packageName);
|
|
34
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
35
|
+
return nodeModulesPath;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (typeof version === 'string' && version.startsWith('file:')) {
|
|
39
|
+
const fileRoot = path.resolve(hostDir, version.slice('file:'.length));
|
|
40
|
+
if (fs.existsSync(fileRoot)) {
|
|
41
|
+
return fileRoot;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readExplicitSourcePackages() {
|
|
49
|
+
return String(process.env.SOMA_SOURCE_PACKAGES ?? '')
|
|
50
|
+
.split(',')
|
|
51
|
+
.map((item) => item.trim())
|
|
52
|
+
.filter(Boolean);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function readHostDependencies(hostDir) {
|
|
56
|
+
const packageJson = readJson(path.join(hostDir, 'package.json'));
|
|
57
|
+
return {
|
|
58
|
+
...(packageJson?.dependencies ?? {}),
|
|
59
|
+
...(packageJson?.devDependencies ?? {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function isSomaSourcePackage(packageRoot, explicit) {
|
|
64
|
+
if (explicit) return true;
|
|
65
|
+
const packageJson = readJson(path.join(packageRoot, 'package.json'));
|
|
66
|
+
return packageJson?.soma?.source === true || fs.existsSync(path.join(packageRoot, 'shell', 'html'));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function toPackageSource(packageName, packageRoot) {
|
|
70
|
+
const shellRoot = path.join(packageRoot, 'shell');
|
|
71
|
+
return {
|
|
72
|
+
type: 'package',
|
|
73
|
+
name: packageName,
|
|
74
|
+
packageName,
|
|
75
|
+
assetRoot: fs.existsSync(path.join(shellRoot, 'html')) ? shellRoot : packageRoot,
|
|
76
|
+
codeRoot: packageRoot,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getSomaAssetSources(hostDir) {
|
|
81
|
+
const normalizedHostDir = path.resolve(hostDir);
|
|
82
|
+
const dependencies = readHostDependencies(normalizedHostDir);
|
|
83
|
+
const explicitPackages = new Set(readExplicitSourcePackages());
|
|
84
|
+
const packageNames = new Set([
|
|
85
|
+
...Object.keys(dependencies),
|
|
86
|
+
...explicitPackages,
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
const sources = [
|
|
90
|
+
{
|
|
91
|
+
type: 'host',
|
|
92
|
+
name: 'host',
|
|
93
|
+
assetRoot: normalizedHostDir,
|
|
94
|
+
codeRoot: normalizedHostDir,
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
for (const packageName of packageNames) {
|
|
99
|
+
const packageRoot = resolvePackageRoot(normalizedHostDir, packageName, dependencies[packageName]);
|
|
100
|
+
if (!packageRoot || !isSomaSourcePackage(packageRoot, explicitPackages.has(packageName))) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
sources.push(toPackageSource(packageName, packageRoot));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return sources;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function collectPageEntries(sources) {
|
|
110
|
+
const byHtmlFile = new Map();
|
|
111
|
+
const orderedSources = [
|
|
112
|
+
...sources.filter((source) => source.type === 'package'),
|
|
113
|
+
...sources.filter((source) => source.type === 'host'),
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
for (const source of orderedSources) {
|
|
117
|
+
const htmlRoot = path.join(source.assetRoot, 'html');
|
|
118
|
+
for (const htmlFile of collectHtmlFiles(htmlRoot).sort()) {
|
|
119
|
+
byHtmlFile.set(htmlFile, { source, htmlFile });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return [...byHtmlFile.values()].sort((a, b) => a.htmlFile.localeCompare(b.htmlFile));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
class SomaManifestWebpackPlugin {
|
|
127
|
+
constructor(options = {}) {
|
|
128
|
+
this.hostDir = options.hostDir;
|
|
129
|
+
this.outputDir = options.outputDir ?? '.soma';
|
|
130
|
+
this.jiti = createJiti(__filename, {
|
|
131
|
+
interopDefault: true,
|
|
132
|
+
alias: {
|
|
133
|
+
'@core': path.resolve(__dirname, '..'),
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
apply(compiler) {
|
|
139
|
+
compiler.hooks.beforeCompile.tapAsync('SomaManifestWebpackPlugin', (_params, callback) => {
|
|
140
|
+
const hostDir = this.hostDir ?? process.env.SOMA_HOST_DIR;
|
|
141
|
+
if (!hostDir) {
|
|
142
|
+
callback();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const { precompileAll } = this.jiti('./full-manifest-builder.ts');
|
|
148
|
+
const sources = getSomaAssetSources(hostDir);
|
|
149
|
+
const pageEntries = collectPageEntries(sources);
|
|
150
|
+
const htmlFiles = pageEntries.map((entry) => entry.htmlFile);
|
|
151
|
+
const readYaml = (filePath) =>
|
|
152
|
+
fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';
|
|
153
|
+
|
|
154
|
+
const pages = pageEntries
|
|
155
|
+
.filter(({ htmlFile }) => !htmlFile.startsWith('shared/') && !htmlFile.startsWith('system/'))
|
|
156
|
+
.map(({ source, htmlFile }) => {
|
|
157
|
+
const base = htmlFile.replace(/\.html$/, '');
|
|
158
|
+
return {
|
|
159
|
+
path: `/${base}`,
|
|
160
|
+
uiYaml: readYaml(path.join(source.assetRoot, 'ui', `${base}_ui.yaml`)),
|
|
161
|
+
eventYaml: readYaml(path.join(source.assetRoot, 'event', `${base}_event.yaml`)),
|
|
162
|
+
styleYaml: readYaml(path.join(source.assetRoot, 'ui', `${base}_style.yaml`)) || undefined,
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const localeYaml = readYaml(path.join(hostDir, 'config/locale.yaml'));
|
|
167
|
+
const appConfigYaml = readYaml(path.join(hostDir, 'config/app.config.yaml'));
|
|
168
|
+
const manifest = precompileAll({ htmlFiles, localeYaml, appConfigYaml, pages });
|
|
169
|
+
|
|
170
|
+
const outDir = path.join(hostDir, this.outputDir);
|
|
171
|
+
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
|
172
|
+
fs.writeFileSync(
|
|
173
|
+
path.join(outDir, 'manifest.json'),
|
|
174
|
+
JSON.stringify(manifest, null, 2),
|
|
175
|
+
);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
compiler.hooks.infrastructureLog?.call(
|
|
178
|
+
'SomaManifestWebpackPlugin',
|
|
179
|
+
`[soma-manifest] 预编译跳过: ${e.message}`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
callback();
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = { SomaManifestWebpackPlugin };
|