soma-core 1.0.0 → 1.0.2

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.
Files changed (228) hide show
  1. package/app/SomaPageClient.tsx +336 -0
  2. package/app/api/[...path]/route.ts +77 -0
  3. package/app/api/page/route.ts +18 -16
  4. package/app/api/soma-manifest/route.ts +39 -0
  5. package/app/components/SomaHydrationShell.tsx +23 -0
  6. package/app/layout.tsx +2 -2
  7. package/app/loading.tsx +5 -0
  8. package/app/page.tsx +19 -128
  9. package/bin/soma-lsp.cjs +195 -0
  10. package/bin/soma-sync.cjs +3 -0
  11. package/bin/soma.cjs +13 -1
  12. package/core/api/IService.ts +29 -0
  13. package/core/api/load-host-service.ts +72 -0
  14. package/core/api/service-path.ts +39 -0
  15. package/core/base/SomaEntity.ts +3 -10
  16. package/core/base/SomaLocaleOnlyPageRoot.ts +3 -4
  17. package/core/base/SomaPageRootBase.ts +20 -3
  18. package/core/base/decorators/Event.ts +23 -0
  19. package/core/base/decorators/Locale.ts +35 -0
  20. package/core/base/decorators/Page.ts +16 -0
  21. package/core/base/decorators/Show.ts +20 -0
  22. package/core/base/decorators/ShowList.ts +34 -0
  23. package/core/base/decorators/index.ts +5 -0
  24. package/core/base/index.ts +2 -0
  25. package/core/base/runAsync.ts +32 -0
  26. package/core/compiler/full-manifest-builder.ts +33 -7
  27. package/core/compiler/host-config-sync.cjs +38 -0
  28. package/core/compiler/manifest-compiler.ts +3 -2
  29. package/core/compiler/page-base-resolver.ts +23 -0
  30. package/core/compiler/precompiled-manifest-loader.ts +34 -0
  31. package/core/compiler/rollup-plugin-soma.ts +45 -0
  32. package/core/compiler/rspack-plugin-soma.js +33 -0
  33. package/core/compiler/soma-manifest-webpack-plugin.js +72 -0
  34. package/core/compiler/soma-precompile.js +3513 -0
  35. package/core/compiler/soma-precompile.ts +52 -6
  36. package/core/compiler/soma-rspack-yaml-loader.js +22 -0
  37. package/core/compiler/soma-webpack-loader.js +7 -1
  38. package/core/compiler/vite-plugin-soma.ts +11 -1
  39. package/core/container/IContainerAdapter.ts +36 -0
  40. package/core/container/MiniProgramContainerAdapter.ts +190 -0
  41. package/core/container/ReactNativeContainerAdapter.ts +189 -0
  42. package/core/container/SomaContainerAdapter.ts +17 -6
  43. package/core/diagnostics/SomaDiagnostics.ts +1 -1
  44. package/core/diagnostics/SomaTelemetry.ts +100 -0
  45. package/core/diagnostics/telemetry-context.ts +15 -0
  46. package/core/engine/asset-resolver.ts +39 -4
  47. package/core/engine/dom-renderer.ts +9 -11
  48. package/core/engine/event-engine.ts +110 -41
  49. package/core/engine/on-change-engine.ts +71 -0
  50. package/core/engine/property-watcher.ts +117 -0
  51. package/core/engine/reactive-proxy.ts +11 -5
  52. package/core/engine/render-engine.ts +97 -11
  53. package/core/engine/runtime-builder.ts +88 -11
  54. package/core/engine/scope-resolver.ts +65 -9
  55. package/core/engine/soma-bootstrap.ts +448 -244
  56. package/core/engine/style-binder.ts +423 -0
  57. package/core/engine/theme-variables.ts +37 -0
  58. package/core/engine/timer-engine.ts +92 -0
  59. package/core/engine/trigger-engine.ts +55 -0
  60. package/core/host/resolve-host-bootstrap.ts +28 -0
  61. package/core/host/soma-bootstrap-host.stub.ts +4 -0
  62. package/core/index.ts +40 -6
  63. package/core/infra/auth/TokenAuthService.ts +17 -3
  64. package/core/infra/http/IHttpClient.ts +11 -1
  65. package/core/infra/http/SomaHttpService.ts +89 -31
  66. package/core/infra/i18n/DefaultI18n.ts +6 -18
  67. package/core/infra/i18n/II18n.ts +2 -3
  68. package/core/infra/notify/DomNotifyService.ts +98 -0
  69. package/core/infra/notify/INotifyTheme.ts +22 -0
  70. package/core/infra/realtime/IRealtimeService.ts +23 -0
  71. package/core/infra/realtime/IRealtimeTransport.ts +9 -0
  72. package/core/infra/realtime/SomaRealtimeService.ts +95 -0
  73. package/core/infra/realtime/SseRealtimeTransport.ts +36 -0
  74. package/core/infra/realtime/WebSocketRealtimeTransport.ts +102 -0
  75. package/core/infra/router/router-path.ts +28 -0
  76. package/core/infra/storage/SessionStorageService.ts +59 -0
  77. package/core/lsp/cross-file-diagnostics.cjs +160 -0
  78. package/core/lsp/event-yaml-completion.cjs +106 -0
  79. package/core/lsp/extra-completion.cjs +64 -0
  80. package/core/lsp/lsp-navigation.cjs +191 -0
  81. package/core/lsp/ui-yaml-completion.cjs +170 -0
  82. package/core/manifest/manifest-contract.ts +12 -0
  83. package/core/middleware/createPermissionMiddleware.ts +37 -0
  84. package/core/parser/annotation-extractor.ts +113 -0
  85. package/core/parser/pipeline-parser.ts +344 -276
  86. package/core/parser/style-config-parser.ts +340 -0
  87. package/core/parser/timer-parser.ts +70 -0
  88. package/core/parser/trigger-parser.ts +90 -0
  89. package/core/parser/ui-config-parser.ts +73 -1
  90. package/core/quality/SomaQualityRegistry.ts +68 -0
  91. package/core/runtime/SomaRuntimeServices.ts +100 -0
  92. package/core/runtime/SomaSnapshotStore.ts +5 -3
  93. package/core/types/domain.types.ts +5 -2
  94. package/core/types/event.types.ts +82 -57
  95. package/core/types/manifest.types.ts +2 -0
  96. package/core/types/style-config.types.ts +76 -0
  97. package/core/types/timer.types.ts +23 -0
  98. package/core/types/trigger.types.ts +14 -0
  99. package/core/types/ui-config.types.ts +9 -0
  100. package/core/types/watcher.types.ts +29 -0
  101. package/core/validation/contract-validator.ts +465 -465
  102. package/dist/cli/soma.js +23 -23
  103. package/dist/core/index.cjs +8968 -0
  104. package/dist/diagnostics/telemetry.cjs +105 -0
  105. package/dist/preview-export.cjs +3401 -0
  106. package/dist/tsconfig.types.tsbuildinfo +1 -0
  107. package/dist/types/api/IService.d.ts +28 -0
  108. package/dist/types/api/load-host-service.d.ts +5 -0
  109. package/dist/types/api/service-path.d.ts +13 -0
  110. package/dist/types/base/SomaApi.d.ts +5 -0
  111. package/dist/types/base/SomaDict.d.ts +89 -0
  112. package/dist/types/base/SomaEntity.d.ts +15 -0
  113. package/dist/types/base/SomaHttpClient.d.ts +66 -0
  114. package/dist/types/base/SomaLocaleOnlyPageRoot.d.ts +3 -0
  115. package/dist/types/base/SomaPageRootBase.d.ts +49 -0
  116. package/dist/types/base/SomaValidator.d.ts +55 -0
  117. package/dist/types/base/decorators/Event.d.ts +10 -0
  118. package/dist/types/base/decorators/Locale.d.ts +9 -0
  119. package/dist/types/base/decorators/Page.d.ts +4 -0
  120. package/dist/types/base/decorators/Show.d.ts +7 -0
  121. package/dist/types/base/decorators/ShowList.d.ts +12 -0
  122. package/dist/types/base/decorators/index.d.ts +5 -0
  123. package/dist/types/base/index.d.ts +9 -0
  124. package/dist/types/base/runAsync.d.ts +12 -0
  125. package/dist/types/compiler/full-manifest-builder.d.ts +35 -0
  126. package/dist/types/compiler/manifest-compiler.d.ts +29 -0
  127. package/dist/types/compiler/page-base-resolver.d.ts +6 -0
  128. package/dist/types/compiler/precompiled-manifest-loader.d.ts +5 -0
  129. package/dist/types/compiler/rollup-plugin-soma.d.ts +14 -0
  130. package/dist/types/compiler/route-builder.d.ts +12 -0
  131. package/dist/types/compiler/soma-precompile.d.ts +40 -0
  132. package/dist/types/compiler/vite-plugin-soma.d.ts +34 -0
  133. package/dist/types/container/IContainerAdapter.d.ts +30 -0
  134. package/dist/types/container/MiniProgramContainerAdapter.d.ts +52 -0
  135. package/dist/types/container/ReactNativeContainerAdapter.d.ts +47 -0
  136. package/dist/types/container/SomaContainerAdapter.d.ts +30 -0
  137. package/dist/types/diagnostics/SomaDiagnostics.d.ts +64 -0
  138. package/dist/types/diagnostics/SomaTelemetry.d.ts +32 -0
  139. package/dist/types/diagnostics/telemetry-context.d.ts +4 -0
  140. package/dist/types/engine/asset-resolver.d.ts +17 -0
  141. package/dist/types/engine/dom-renderer.d.ts +35 -0
  142. package/dist/types/engine/event-engine.d.ts +64 -0
  143. package/dist/types/engine/lis.d.ts +10 -0
  144. package/dist/types/engine/on-change-engine.d.ts +16 -0
  145. package/dist/types/engine/property-watcher.d.ts +18 -0
  146. package/dist/types/engine/reactive-proxy.d.ts +58 -0
  147. package/dist/types/engine/render-engine.d.ts +73 -0
  148. package/dist/types/engine/runtime-builder.d.ts +58 -0
  149. package/dist/types/engine/scope-resolver.d.ts +90 -0
  150. package/dist/types/engine/soma-bootstrap.d.ts +112 -0
  151. package/dist/types/engine/style-binder.d.ts +81 -0
  152. package/dist/types/engine/theme-variables.d.ts +3 -0
  153. package/dist/types/engine/timer-engine.d.ts +19 -0
  154. package/dist/types/engine/trigger-engine.d.ts +16 -0
  155. package/dist/types/host/resolve-host-bootstrap.d.ts +11 -0
  156. package/dist/types/host/soma-bootstrap-host.stub.d.ts +3 -0
  157. package/dist/types/index.d.ts +35 -0
  158. package/dist/types/infra/auth/IAuthService.d.ts +12 -0
  159. package/dist/types/infra/auth/TokenAuthService.d.ts +26 -0
  160. package/dist/types/infra/cache/ICache.d.ts +12 -0
  161. package/dist/types/infra/cache/MemoryCache.d.ts +14 -0
  162. package/dist/types/infra/cache/ServerFileCache.d.ts +37 -0
  163. package/dist/types/infra/config/IConfig.d.ts +9 -0
  164. package/dist/types/infra/config/SomaConfig.d.ts +21 -0
  165. package/dist/types/infra/event-bus/IEventBus.d.ts +8 -0
  166. package/dist/types/infra/event-bus/SomaEventBus.d.ts +9 -0
  167. package/dist/types/infra/http/IHttpClient.d.ts +28 -0
  168. package/dist/types/infra/http/SomaHttpService.d.ts +27 -0
  169. package/dist/types/infra/i18n/DefaultI18n.d.ts +7 -0
  170. package/dist/types/infra/i18n/II18n.d.ts +6 -0
  171. package/dist/types/infra/logger/ConsoleLogger.d.ts +14 -0
  172. package/dist/types/infra/logger/ILogger.d.ts +17 -0
  173. package/dist/types/infra/notify/DefaultNotifyService.d.ts +16 -0
  174. package/dist/types/infra/notify/DomNotifyService.d.ts +16 -0
  175. package/dist/types/infra/notify/INotifyService.d.ts +12 -0
  176. package/dist/types/infra/notify/INotifyTheme.d.ts +12 -0
  177. package/dist/types/infra/permission/IPermission.d.ts +10 -0
  178. package/dist/types/infra/permission/SomaPermission.d.ts +19 -0
  179. package/dist/types/infra/realtime/IRealtimeService.d.ts +13 -0
  180. package/dist/types/infra/realtime/IRealtimeTransport.d.ts +8 -0
  181. package/dist/types/infra/realtime/SomaRealtimeService.d.ts +20 -0
  182. package/dist/types/infra/realtime/SseRealtimeTransport.d.ts +11 -0
  183. package/dist/types/infra/realtime/WebSocketRealtimeTransport.d.ts +30 -0
  184. package/dist/types/infra/router/IRouter.d.ts +16 -0
  185. package/dist/types/infra/router/SomaRouter.d.ts +18 -0
  186. package/dist/types/infra/router/router-path.d.ts +6 -0
  187. package/dist/types/infra/storage/IStorageService.d.ts +7 -0
  188. package/dist/types/infra/storage/MemoryStorageService.d.ts +15 -0
  189. package/dist/types/infra/storage/SessionStorageService.d.ts +14 -0
  190. package/dist/types/infra/timer/ITimer.d.ts +13 -0
  191. package/dist/types/infra/timer/SomaTimer.d.ts +21 -0
  192. package/dist/types/manifest/manifest-contract.d.ts +4 -0
  193. package/dist/types/middleware/SomaMiddlewareChain.d.ts +6 -0
  194. package/dist/types/middleware/createPermissionMiddleware.d.ts +14 -0
  195. package/dist/types/parser/annotation-extractor.d.ts +12 -0
  196. package/dist/types/parser/pipeline-parser.d.ts +62 -0
  197. package/dist/types/parser/style-config-parser.d.ts +20 -0
  198. package/dist/types/parser/timer-parser.d.ts +6 -0
  199. package/dist/types/parser/trigger-parser.d.ts +13 -0
  200. package/dist/types/parser/ui-config-parser.d.ts +34 -0
  201. package/dist/types/parser/yaml-loader.d.ts +21 -0
  202. package/dist/types/quality/SomaQualityRegistry.d.ts +31 -0
  203. package/dist/types/runtime/SomaRuntimeServices.d.ts +35 -0
  204. package/dist/types/runtime/SomaSnapshotStore.d.ts +13 -0
  205. package/dist/types/scheduler/SomaScheduler.d.ts +25 -0
  206. package/dist/types/types/domain.types.d.ts +82 -0
  207. package/dist/types/types/engine.types.d.ts +22 -0
  208. package/dist/types/types/event.types.d.ts +61 -0
  209. package/dist/types/types/keyboard.types.d.ts +4 -0
  210. package/dist/types/types/manifest.types.d.ts +29 -0
  211. package/dist/types/types/scheduler.types.d.ts +8 -0
  212. package/dist/types/types/style-config.types.d.ts +62 -0
  213. package/dist/types/types/timer.types.d.ts +19 -0
  214. package/dist/types/types/trigger.types.d.ts +12 -0
  215. package/dist/types/types/ui-config.types.d.ts +85 -0
  216. package/dist/types/types/watcher.types.d.ts +24 -0
  217. package/dist/types/validation/contract-validator.d.ts +40 -0
  218. package/editor/vscode/extension.js +39 -0
  219. package/editor/vscode/language-configuration.json +17 -0
  220. package/editor/vscode/package.json +98 -0
  221. package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +30 -0
  222. package/editor/vscode/syntaxes/soma-ui-yaml.tmLanguage.json +42 -0
  223. package/global.d.ts +19 -0
  224. package/next.config.js +9 -4
  225. package/package.json +53 -16
  226. package/tailwind.config.ts +26 -7
  227. package/tsconfig.json +6 -2
  228. package/core/router/RouteHandler.ts +0 -93
@@ -0,0 +1,11 @@
1
+ import type { SomaBootstrapOptions } from '../engine/soma-bootstrap';
2
+ import type { SomaRuntimeServices } from '../runtime/SomaRuntimeServices';
3
+ /** Optional host module `@soma-host/bootstrap/soma-bootstrap.ts` */
4
+ export type SomaBootstrapConfigurator = (ctx: {
5
+ getServices: () => SomaRuntimeServices | undefined;
6
+ }) => Partial<SomaBootstrapOptions>;
7
+ /**
8
+ * Load host-provided `configureSomaBootstrap` when present.
9
+ * Keeps soma-core shell free of business middleware; host opts in explicitly.
10
+ */
11
+ export declare function resolveHostBootstrapOptions(getServices: () => SomaRuntimeServices | undefined): Promise<Partial<SomaBootstrapOptions>>;
@@ -0,0 +1,3 @@
1
+ /** Typecheck stub for `resolve-host-bootstrap` dynamic import — runtime resolves real host file. */
2
+ import type { SomaBootstrapConfigurator } from './resolve-host-bootstrap';
3
+ export declare const configureSomaBootstrap: SomaBootstrapConfigurator | undefined;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * soma-core — host apps should import subpaths via package exports.
3
+ */
4
+ export * from './base/index';
5
+ export type { SomaAppConfig, SomaPageRoot } from './types/domain.types';
6
+ export type { IService } from './api/IService';
7
+ export { SomaBootstrap } from './engine/soma-bootstrap';
8
+ export type { SomaPageAssets, SomaBootstrapOptions } from './engine/soma-bootstrap';
9
+ export { createDefaultRuntimeServices } from './runtime/SomaRuntimeServices';
10
+ export type { SomaRuntimeServices } from './runtime/SomaRuntimeServices';
11
+ export { SomaDiagnostics } from './diagnostics/SomaDiagnostics';
12
+ export type { SomaDiagnosticsSnapshot } from './diagnostics/SomaDiagnostics';
13
+ export { matchGlobPath } from './engine/property-watcher';
14
+ export { extractConfigFromDomainClass } from './parser/annotation-extractor';
15
+ export { somaRollupPlugin } from './compiler/rollup-plugin-soma';
16
+ export { Page, Show, ShowList, Event } from './base/decorators';
17
+ export { runAsync } from './base/runAsync';
18
+ export type { AsyncStateHost } from './base/runAsync';
19
+ export { SomaQualityRegistry } from './quality/SomaQualityRegistry';
20
+ export { SomaTelemetry } from './diagnostics/SomaTelemetry';
21
+ export { setActiveTelemetry, recordMetric } from './diagnostics/telemetry-context';
22
+ export type { IContainerAdapter, SomaAnchorStats } from './container/IContainerAdapter';
23
+ export { SomaContainerAdapter } from './container/SomaContainerAdapter';
24
+ export { ReactNativeContainerAdapter } from './container/ReactNativeContainerAdapter';
25
+ export { MiniProgramContainerAdapter } from './container/MiniProgramContainerAdapter';
26
+ export type { IRealtimeTransport, RealtimeMessageHandler } from './infra/realtime/IRealtimeTransport';
27
+ export type { IRealtimeService, RealtimeSubscribeOptions } from './infra/realtime/IRealtimeService';
28
+ export { SseRealtimeTransport } from './infra/realtime/SseRealtimeTransport';
29
+ export { WebSocketRealtimeTransport } from './infra/realtime/WebSocketRealtimeTransport';
30
+ export { SomaRealtimeService } from './infra/realtime/SomaRealtimeService';
31
+ export { SomaMiddlewareChain } from './middleware/SomaMiddlewareChain';
32
+ export { createPermissionMiddleware } from './middleware/createPermissionMiddleware';
33
+ export type { SomaEventMiddlewareContext } from './engine/event-engine';
34
+ export type { SomaBootstrapConfigurator } from './host/resolve-host-bootstrap';
35
+ export { resolveHostBootstrapOptions } from './host/resolve-host-bootstrap';
@@ -0,0 +1,12 @@
1
+ export interface LoginCredentials {
2
+ email: string;
3
+ password: string;
4
+ }
5
+ export interface IAuthService {
6
+ login(credentials: LoginCredentials): Promise<boolean>;
7
+ logout(): Promise<void>;
8
+ getToken(): string | null;
9
+ isAuthenticated(): boolean;
10
+ refreshToken(): Promise<boolean>;
11
+ onAuthStateChange(callback: (isAuth: boolean) => void): () => void;
12
+ }
@@ -0,0 +1,26 @@
1
+ import { IAuthService, LoginCredentials } from './IAuthService';
2
+ import { IHttpClient } from '../http/IHttpClient';
3
+ import { IStorageService } from '../storage/IStorageService';
4
+ /**
5
+ * TokenAuthService — JWT-style token authentication.
6
+ *
7
+ * Dependencies are injected via constructor so the service stays testable
8
+ * and decoupled from concrete HTTP / storage implementations.
9
+ */
10
+ export declare class TokenAuthService implements IAuthService {
11
+ private http;
12
+ private storage;
13
+ private loginUrl;
14
+ private refreshUrl;
15
+ private listeners;
16
+ constructor(http: IHttpClient, storage: IStorageService, loginUrl: string, refreshUrl: string);
17
+ login(credentials: LoginCredentials): Promise<boolean>;
18
+ logout(): Promise<void>;
19
+ getDisplayName(): string | null;
20
+ getToken(): string | null;
21
+ isAuthenticated(): boolean;
22
+ refreshToken(): Promise<boolean>;
23
+ onAuthStateChange(callback: (isAuth: boolean) => void): () => void;
24
+ private storeToken;
25
+ private notify;
26
+ }
@@ -0,0 +1,12 @@
1
+ export interface CacheOptions {
2
+ ttl?: number;
3
+ maxSize?: number;
4
+ }
5
+ export interface ICache<V = any> {
6
+ get(key: string): V | undefined;
7
+ set(key: string, value: V, ttl?: number): void;
8
+ has(key: string): boolean;
9
+ delete(key: string): boolean;
10
+ clear(): void;
11
+ size(): number;
12
+ }
@@ -0,0 +1,14 @@
1
+ import type { CacheOptions, ICache } from './ICache';
2
+ export declare class MemoryCache<V = any> implements ICache<V> {
3
+ private store;
4
+ private readonly defaultTtl;
5
+ private readonly maxSize;
6
+ constructor(options?: CacheOptions);
7
+ get(key: string): V | undefined;
8
+ set(key: string, value: V, ttl?: number): void;
9
+ has(key: string): boolean;
10
+ delete(key: string): boolean;
11
+ clear(): void;
12
+ size(): number;
13
+ private evictLru;
14
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 服务端文件缓存单例
3
+ *
4
+ * 将磁盘文件内容和目录列表缓存到内存中,避免每次请求都执行 I/O。
5
+ * 支持 fs.watch 监听文件变化,自动失效对应缓存条目。
6
+ */
7
+ export declare class ServerFileCache {
8
+ private static instance;
9
+ private fileCache;
10
+ private dirCache;
11
+ private watchers;
12
+ private constructor();
13
+ static getInstance(): ServerFileCache;
14
+ /**
15
+ * 读取文件内容,命中缓存直接返回,未命中则读磁盘并缓存。
16
+ */
17
+ readFile(filePath: string): string;
18
+ /**
19
+ * 尝试读取文件,不存在返回空字符串。
20
+ */
21
+ tryReadFile(filePath: string): string;
22
+ /**
23
+ * 读取目录下指定扩展名的文件内容列表。
24
+ * 缓存目录扫描结果和每个文件的内容。
25
+ */
26
+ readDirFiles(dirPath: string, ext: string): string[];
27
+ readDirNames(dirPath: string, ext: string): string[];
28
+ /**
29
+ * 监听目录变化,自动失效缓存。
30
+ * 使用 fs.watch 递归监听。
31
+ */
32
+ watchAndInvalidate(rootDir: string): void;
33
+ /**
34
+ * 清除所有缓存并关闭 watcher。
35
+ */
36
+ dispose(): void;
37
+ }
@@ -0,0 +1,9 @@
1
+ export interface IConfig {
2
+ get<T>(key: string, defaultValue?: T): T;
3
+ set(key: string, value: any): void;
4
+ has(key: string): boolean;
5
+ getAll(): Record<string, any>;
6
+ load(data: Record<string, any>): void;
7
+ isFeatureEnabled(feature: string): boolean;
8
+ setFeatureFlag(feature: string, enabled: boolean): void;
9
+ }
@@ -0,0 +1,21 @@
1
+ import { IConfig } from './IConfig';
2
+ /**
3
+ * SomaConfig — stores config in a plain object.
4
+ *
5
+ * Supports dot-notation paths for get (e.g., get('api.timeout')).
6
+ * Feature flags are stored separately.
7
+ */
8
+ export declare class SomaConfig implements IConfig {
9
+ private data;
10
+ private featureFlags;
11
+ get<T>(key: string, defaultValue?: T): T;
12
+ set(key: string, value: any): void;
13
+ has(key: string): boolean;
14
+ getAll(): Record<string, any>;
15
+ load(data: Record<string, any>): void;
16
+ isFeatureEnabled(feature: string): boolean;
17
+ setFeatureFlag(feature: string, enabled: boolean): void;
18
+ private getByPath;
19
+ private setByPath;
20
+ private merge;
21
+ }
@@ -0,0 +1,8 @@
1
+ export type EventHandler<T = any> = (payload: T) => void;
2
+ export interface IEventBus {
3
+ on<T>(event: string, handler: EventHandler<T>): () => void;
4
+ once<T>(event: string, handler: EventHandler<T>): () => void;
5
+ emit<T>(event: string, payload?: T): void;
6
+ off(event: string, handler?: EventHandler): void;
7
+ clear(): void;
8
+ }
@@ -0,0 +1,9 @@
1
+ import type { EventHandler, IEventBus } from './IEventBus';
2
+ export declare class SomaEventBus implements IEventBus {
3
+ private handlers;
4
+ on<T>(event: string, handler: EventHandler<T>): () => void;
5
+ once<T>(event: string, handler: EventHandler<T>): () => void;
6
+ emit<T>(event: string, payload?: T): void;
7
+ off(event: string, handler?: EventHandler): void;
8
+ clear(): void;
9
+ }
@@ -0,0 +1,28 @@
1
+ export interface HttpRequestConfig {
2
+ headers?: Record<string, string>;
3
+ params?: Record<string, string>;
4
+ timeout?: number;
5
+ signal?: AbortSignal;
6
+ }
7
+ export interface UploadOptions {
8
+ /** multipart 字段名,默认 file */
9
+ fieldName?: string;
10
+ /** 上传文件名 */
11
+ fileName?: string;
12
+ /** 额外表单字段 */
13
+ fields?: Record<string, string>;
14
+ }
15
+ export interface HttpResponse<T = any> {
16
+ data: T;
17
+ status: number;
18
+ headers: Record<string, string>;
19
+ }
20
+ export interface IHttpClient {
21
+ get<T>(url: string, config?: HttpRequestConfig): Promise<T>;
22
+ post<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<T>;
23
+ put<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<T>;
24
+ patch<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<T>;
25
+ delete<T>(url: string, config?: HttpRequestConfig): Promise<T>;
26
+ upload<T>(url: string, file: Blob, onProgress?: (percent: number) => void, options?: UploadOptions): Promise<T>;
27
+ abortAll(): void;
28
+ }
@@ -0,0 +1,27 @@
1
+ import { SomaHttpClientConfig } from '@/core/base/SomaHttpClient';
2
+ import { IHttpClient, HttpRequestConfig, UploadOptions } from './IHttpClient';
3
+ /**
4
+ * SomaHttpService — wraps the core SomaHttpClient and implements IHttpClient.
5
+ *
6
+ * Adds support for:
7
+ * - per-request headers, query params, timeout, and external AbortSignal
8
+ * - file upload via fetch with Blob body
9
+ */
10
+ export declare class SomaHttpService implements IHttpClient {
11
+ private client;
12
+ private baseURL;
13
+ private abortControllers;
14
+ private onHttpError;
15
+ constructor(config: SomaHttpClientConfig);
16
+ /** 注册 HTTP 错误回调(401/403/422 等统一处理) */
17
+ setErrorHandler(handler: (status: number, message: string) => void): void;
18
+ get<T>(url: string, config?: HttpRequestConfig): Promise<T>;
19
+ post<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<T>;
20
+ put<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<T>;
21
+ patch<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<T>;
22
+ delete<T>(url: string, config?: HttpRequestConfig): Promise<T>;
23
+ upload<T>(url: string, file: Blob, onProgress?: (percent: number) => void, options?: UploadOptions): Promise<T>;
24
+ private uploadWithProgress;
25
+ abortAll(): void;
26
+ private requestWithConfig;
27
+ }
@@ -0,0 +1,7 @@
1
+ import type { II18n } from './II18n';
2
+ export declare class DefaultI18n implements II18n {
3
+ private messages;
4
+ t(key: string, params?: Record<string, string | number>): string;
5
+ loadContent(messages: Record<string, string>): void;
6
+ hasKey(key: string): boolean;
7
+ }
@@ -0,0 +1,6 @@
1
+ /** Lookup for content strings loaded from locale.yaml (single dictionary, no locale switching) */
2
+ export interface II18n {
3
+ t(key: string, params?: Record<string, string | number>): string;
4
+ loadContent(messages: Record<string, string>): void;
5
+ hasKey(key: string): boolean;
6
+ }
@@ -0,0 +1,14 @@
1
+ import type { ILogger, LogEntry, LogLevel } from './ILogger';
2
+ export declare class ConsoleLogger implements ILogger {
3
+ private level;
4
+ private context;
5
+ private entries;
6
+ debug(message: string, data?: any): void;
7
+ info(message: string, data?: any): void;
8
+ warn(message: string, data?: any): void;
9
+ error(message: string, data?: any): void;
10
+ setLevel(level: LogLevel): void;
11
+ setContext(context: string): void;
12
+ getEntries(): LogEntry[];
13
+ private log;
14
+ }
@@ -0,0 +1,17 @@
1
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ export interface LogEntry {
3
+ level: LogLevel;
4
+ message: string;
5
+ context?: string;
6
+ data?: any;
7
+ timestamp: number;
8
+ }
9
+ export interface ILogger {
10
+ debug(message: string, data?: any): void;
11
+ info(message: string, data?: any): void;
12
+ warn(message: string, data?: any): void;
13
+ error(message: string, data?: any): void;
14
+ setLevel(level: LogLevel): void;
15
+ setContext(context: string): void;
16
+ getEntries(): LogEntry[];
17
+ }
@@ -0,0 +1,16 @@
1
+ import { INotifyService, NotifyOptions } from './INotifyService';
2
+ /**
3
+ * DefaultNotifyService — headless / testable notification service.
4
+ *
5
+ * Collects toasts into an in-memory queue. confirm() and alert() resolve
6
+ * immediately so tests and headless environments never block.
7
+ */
8
+ export declare class DefaultNotifyService implements INotifyService {
9
+ /** All toasts received, newest last. */
10
+ readonly notifications: NotifyOptions[];
11
+ /** Default return value for confirm(). Can be changed per-test. */
12
+ confirmResult: boolean;
13
+ toast(options: NotifyOptions): void;
14
+ confirm(_message: string, _title?: string): Promise<boolean>;
15
+ alert(_message: string, _title?: string): Promise<void>;
16
+ }
@@ -0,0 +1,16 @@
1
+ import { DefaultNotifyService } from './DefaultNotifyService';
2
+ import type { NotifyOptions } from './INotifyService';
3
+ import type { ToastTheme } from './INotifyTheme';
4
+ /**
5
+ * 浏览器端通知:样式类名由宿主 app.config.yaml → notify.toast 注入(Tailwind)。
6
+ */
7
+ export declare class DomNotifyService extends DefaultNotifyService {
8
+ private readonly theme;
9
+ private root;
10
+ constructor(theme: ToastTheme);
11
+ toast(options: NotifyOptions): void;
12
+ confirm(message: string, title?: string): Promise<boolean>;
13
+ alert(message: string, title?: string): Promise<void>;
14
+ private ensureRoot;
15
+ private renderToast;
16
+ }
@@ -0,0 +1,12 @@
1
+ export type NotifyLevel = 'info' | 'success' | 'warning' | 'error';
2
+ export interface NotifyOptions {
3
+ message: string;
4
+ level?: NotifyLevel;
5
+ duration?: number;
6
+ title?: string;
7
+ }
8
+ export interface INotifyService {
9
+ toast(options: NotifyOptions): void;
10
+ confirm(message: string, title?: string): Promise<boolean>;
11
+ alert(message: string, title?: string): Promise<void>;
12
+ }
@@ -0,0 +1,12 @@
1
+ import type { NotifyLevel } from './INotifyService';
2
+ /** 宿主在 app.config.yaml 中声明的 Toast Tailwind 类名 */
3
+ export interface ToastTheme {
4
+ root: string;
5
+ item: string;
6
+ visible: string;
7
+ leaving: string;
8
+ title: string;
9
+ message: string;
10
+ levels: Record<NotifyLevel, string>;
11
+ }
12
+ export declare function isToastTheme(value: unknown): value is ToastTheme;
@@ -0,0 +1,10 @@
1
+ export interface IPermission {
2
+ setRoles(roles: string[]): void;
3
+ setPermissions(permissions: string[]): void;
4
+ hasRole(role: string): boolean;
5
+ hasPermission(permission: string): boolean;
6
+ hasAnyRole(roles: string[]): boolean;
7
+ hasAllPermissions(permissions: string[]): boolean;
8
+ check(required: string | string[]): boolean;
9
+ reset(): void;
10
+ }
@@ -0,0 +1,19 @@
1
+ import { IPermission } from './IPermission';
2
+ /**
3
+ * SomaPermission — stores roles and permissions as Sets.
4
+ *
5
+ * check() accepts a single string (single permission required) or
6
+ * an array of strings (all required).
7
+ */
8
+ export declare class SomaPermission implements IPermission {
9
+ private roles;
10
+ private permissions;
11
+ setRoles(roles: string[]): void;
12
+ setPermissions(permissions: string[]): void;
13
+ hasRole(role: string): boolean;
14
+ hasPermission(permission: string): boolean;
15
+ hasAnyRole(roles: string[]): boolean;
16
+ hasAllPermissions(permissions: string[]): boolean;
17
+ check(required: string | string[]): boolean;
18
+ reset(): void;
19
+ }
@@ -0,0 +1,13 @@
1
+ import type { RealtimeMessageHandler } from './IRealtimeTransport';
2
+ export interface RealtimeSubscribeOptions {
3
+ /** Auth token passed as query param */
4
+ token?: string | null;
5
+ /** Extra query params forwarded to the transport URL */
6
+ query?: Record<string, string>;
7
+ }
8
+ /** Realtime push facade for domain code (SSE / WebSocket) */
9
+ export interface IRealtimeService {
10
+ subscribeSse(channel: string, handler: RealtimeMessageHandler, options?: RealtimeSubscribeOptions): () => void;
11
+ subscribeWebSocket(channel: string, handler: RealtimeMessageHandler, options?: RealtimeSubscribeOptions): () => void;
12
+ disconnectAll(): void;
13
+ }
@@ -0,0 +1,8 @@
1
+ export type RealtimeMessageHandler = (data: unknown) => void;
2
+ export interface IRealtimeTransport {
3
+ readonly kind: 'sse' | 'websocket';
4
+ connect(url: string): void;
5
+ disconnect(): void;
6
+ onMessage(handler: RealtimeMessageHandler): () => void;
7
+ isConnected(): boolean;
8
+ }
@@ -0,0 +1,20 @@
1
+ import type { IRealtimeService, RealtimeSubscribeOptions } from './IRealtimeService';
2
+ import type { RealtimeMessageHandler } from './IRealtimeTransport';
3
+ export interface SomaRealtimeServiceOptions {
4
+ sseBasePath?: string;
5
+ wsBaseUrl?: string;
6
+ tokenProvider?: () => string | null;
7
+ }
8
+ export declare class SomaRealtimeService implements IRealtimeService {
9
+ private readonly sseBasePath;
10
+ private readonly wsBaseUrl;
11
+ private readonly tokenProvider?;
12
+ private readonly active;
13
+ private readonly unsubscribers;
14
+ constructor(options?: SomaRealtimeServiceOptions);
15
+ subscribeSse(channel: string, handler: RealtimeMessageHandler, options?: RealtimeSubscribeOptions): () => void;
16
+ private buildSseUrl;
17
+ subscribeWebSocket(channel: string, handler: RealtimeMessageHandler, options?: RealtimeSubscribeOptions): () => void;
18
+ disconnectAll(): void;
19
+ private track;
20
+ }
@@ -0,0 +1,11 @@
1
+ import type { IRealtimeTransport, RealtimeMessageHandler } from './IRealtimeTransport';
2
+ /** 浏览器 SSE 实时传输 */
3
+ export declare class SseRealtimeTransport implements IRealtimeTransport {
4
+ readonly kind: "sse";
5
+ private source;
6
+ private handlers;
7
+ connect(url: string): void;
8
+ disconnect(): void;
9
+ onMessage(handler: RealtimeMessageHandler): () => void;
10
+ isConnected(): boolean;
11
+ }
@@ -0,0 +1,30 @@
1
+ import type { IRealtimeTransport, RealtimeMessageHandler } from './IRealtimeTransport';
2
+ export interface WebSocketRealtimeOptions {
3
+ reconnect?: boolean;
4
+ maxRetries?: number;
5
+ heartbeatMs?: number;
6
+ }
7
+ /** 浏览器 WebSocket 实时传输(支持重连与心跳) */
8
+ export declare class WebSocketRealtimeTransport implements IRealtimeTransport {
9
+ readonly kind: "websocket";
10
+ private socket;
11
+ private handlers;
12
+ private url;
13
+ private closedByUser;
14
+ private retries;
15
+ private heartbeatTimer;
16
+ private reconnectTimer;
17
+ private readonly reconnect;
18
+ private readonly maxRetries;
19
+ private readonly heartbeatMs;
20
+ constructor(options?: WebSocketRealtimeOptions);
21
+ connect(url: string): void;
22
+ disconnect(): void;
23
+ onMessage(handler: RealtimeMessageHandler): () => void;
24
+ isConnected(): boolean;
25
+ send(data: unknown): void;
26
+ private openSocket;
27
+ private startHeartbeat;
28
+ private clearHeartbeat;
29
+ private clearTimers;
30
+ }
@@ -0,0 +1,16 @@
1
+ export interface RouteParams {
2
+ [key: string]: string;
3
+ }
4
+ export interface NavigateOptions {
5
+ replace?: boolean;
6
+ params?: RouteParams;
7
+ query?: Record<string, string>;
8
+ }
9
+ export type RouteGuard = (to: string, from: string) => boolean | Promise<boolean>;
10
+ export interface IRouter {
11
+ navigate(path: string, options?: NavigateOptions): void | Promise<void>;
12
+ getCurrentPath(): string;
13
+ addGuard(guard: RouteGuard): () => void;
14
+ buildUrl(path: string, query?: Record<string, string>): string;
15
+ onNavigate(callback: (path: string) => void): () => void;
16
+ }
@@ -0,0 +1,18 @@
1
+ import { IRouter, NavigateOptions, RouteGuard } from './IRouter';
2
+ /**
3
+ * SomaRouter — in-memory router implementation.
4
+ *
5
+ * Maintains currentPath in memory, supports guards (before-navigate checks),
6
+ * and emits callbacks on navigate. Does NOT use window.location.
7
+ */
8
+ export declare class SomaRouter implements IRouter {
9
+ private currentPath;
10
+ private guards;
11
+ private listeners;
12
+ constructor(initialPath?: string);
13
+ navigate(path: string, options?: NavigateOptions): Promise<void>;
14
+ getCurrentPath(): string;
15
+ addGuard(guard: RouteGuard): () => void;
16
+ buildUrl(path: string, query?: Record<string, string>): string;
17
+ onNavigate(callback: (path: string) => void): () => void;
18
+ }
@@ -0,0 +1,6 @@
1
+ /** Strip query/hash for router utilities */
2
+ export declare function pathOnly(url: string): string;
3
+ /** Browser location pathname + search (includes ?id= etc.) */
4
+ export declare function getBrowserUrlPath(): string;
5
+ /** Read a query parameter from router path or the browser address bar */
6
+ export declare function readQueryParam(key: string, routerPath?: string): string;
@@ -0,0 +1,7 @@
1
+ export interface IStorageService {
2
+ get<T>(key: string): T | null;
3
+ set<T>(key: string, value: T, ttl?: number): void;
4
+ remove(key: string): void;
5
+ clear(): void;
6
+ has(key: string): boolean;
7
+ }
@@ -0,0 +1,15 @@
1
+ import { IStorageService } from './IStorageService';
2
+ /**
3
+ * MemoryStorageService — in-memory implementation of IStorageService.
4
+ *
5
+ * Works in any JS runtime (Node.js, browser, etc.).
6
+ * Supports optional TTL (time-to-live) in milliseconds.
7
+ */
8
+ export declare class MemoryStorageService implements IStorageService {
9
+ private store;
10
+ get<T>(key: string): T | null;
11
+ set<T>(key: string, value: T, ttl?: number): void;
12
+ remove(key: string): void;
13
+ clear(): void;
14
+ has(key: string): boolean;
15
+ }
@@ -0,0 +1,14 @@
1
+ import { IStorageService } from './IStorageService';
2
+ /**
3
+ * 浏览器 sessionStorage 实现 — 同标签页内跨页面导航保持登录态。
4
+ * 非浏览器环境回退到进程内 Map。
5
+ */
6
+ export declare class SessionStorageService implements IStorageService {
7
+ private fallback;
8
+ private get session();
9
+ get<T>(key: string): T | null;
10
+ set<T>(key: string, value: T, ttl?: number): void;
11
+ remove(key: string): void;
12
+ clear(): void;
13
+ has(key: string): boolean;
14
+ }
@@ -0,0 +1,13 @@
1
+ export interface ITimer {
2
+ setTimeout(callback: () => void, ms: number): string;
3
+ setInterval(callback: () => void, ms: number): string;
4
+ clearTimeout(id: string): void;
5
+ clearInterval(id: string): void;
6
+ clearAll(): void;
7
+ debounce<T extends (...args: any[]) => void>(fn: T, ms: number): T & {
8
+ cancel(): void;
9
+ };
10
+ throttle<T extends (...args: any[]) => void>(fn: T, ms: number): T & {
11
+ cancel(): void;
12
+ };
13
+ }
@@ -0,0 +1,21 @@
1
+ import { ITimer } from './ITimer';
2
+ /**
3
+ * SomaTimer — wraps native setTimeout/setInterval with string IDs for tracking.
4
+ *
5
+ * clearAll cancels everything. debounce/throttle return wrapped functions with cancel().
6
+ */
7
+ export declare class SomaTimer implements ITimer {
8
+ private timeouts;
9
+ private intervals;
10
+ setTimeout(callback: () => void, ms: number): string;
11
+ setInterval(callback: () => void, ms: number): string;
12
+ clearTimeout(id: string): void;
13
+ clearInterval(id: string): void;
14
+ clearAll(): void;
15
+ debounce<T extends (...args: any[]) => void>(fn: T, ms: number): T & {
16
+ cancel(): void;
17
+ };
18
+ throttle<T extends (...args: any[]) => void>(fn: T, ms: number): T & {
19
+ cancel(): void;
20
+ };
21
+ }
@@ -0,0 +1,4 @@
1
+ /** SOMA runtime manifest version contract */
2
+ export declare const SOMA_MANIFEST_VERSION: "1.0.0";
3
+ export type SomaManifestVersion = typeof SOMA_MANIFEST_VERSION;
4
+ export declare function assertManifestVersion(version: string): void;
@@ -0,0 +1,6 @@
1
+ export type SomaMiddleware<TContext> = (context: TContext, next: () => Promise<void>) => Promise<void> | void;
2
+ export declare class SomaMiddlewareChain<TContext> {
3
+ private readonly middlewares;
4
+ use(middleware: SomaMiddleware<TContext>): void;
5
+ execute(context: TContext, terminal: (context: TContext) => Promise<void> | void): Promise<void>;
6
+ }