soma-core 1.0.3 → 1.1.1
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 +12 -49
- package/app/[...path]/page.tsx +21 -0
- package/app/api/[...path]/route.ts +86 -77
- package/app/components/SomaHostPage.tsx +133 -0
- package/app/components/SomaHydrationShell.tsx +1 -1
- package/app/layout.tsx +22 -18
- package/app/page.tsx +7 -18
- package/app/soma/[...path]/route.ts +9 -0
- package/app/{api/soma-manifest → soma/manifest}/route.ts +3 -3
- package/app/soma/page/route.ts +29 -0
- package/app/soma/page-object/route.ts +159 -0
- package/app/soma/route.ts +9 -0
- package/bin/soma-lsp.cjs +5 -5
- package/bin/soma-mock.mjs +38 -0
- package/bin/soma-sync.cjs +1 -1
- package/core/{compiler → build/compiler}/full-manifest-builder.ts +84 -69
- package/core/build/compiler/host-config-sync.cjs +64 -0
- package/core/{compiler → build/compiler}/precompiled-manifest-loader.ts +1 -1
- package/core/{compiler → build/compiler}/rollup-plugin-soma.ts +1 -1
- package/core/{compiler → build/compiler}/route-builder.ts +31 -31
- package/core/{compiler → build/compiler}/soma-manifest-webpack-plugin.js +41 -7
- package/core/{compiler → build/compiler}/soma-precompile.js +8 -8
- package/core/{compiler → build/compiler}/soma-precompile.ts +94 -94
- package/core/{compiler → build/compiler}/soma-webpack-loader.js +41 -41
- package/core/{compiler → build/compiler}/vite-plugin-soma.ts +83 -83
- package/core/{base → client/base}/SomaApi.ts +14 -14
- package/core/{base → client/base}/SomaDict.ts +168 -168
- package/core/{base → client/base}/SomaHttpClient.ts +128 -126
- package/core/{base → client/base}/SomaPageRootBase.ts +71 -71
- package/core/{base → client/base}/SomaValidator.ts +147 -147
- package/core/{compiler → client/compiler}/manifest-compiler.ts +238 -238
- package/core/{engine → client/engine}/asset-resolver.ts +102 -102
- package/core/{engine → client/engine}/dom-renderer.ts +341 -341
- package/core/{engine → client/engine}/event-engine.ts +356 -356
- package/core/{engine → client/engine}/lis.ts +60 -60
- package/core/{engine → client/engine}/on-change-engine.ts +3 -3
- package/core/{engine → client/engine}/property-watcher.ts +2 -2
- package/core/{engine → client/engine}/reactive-proxy.ts +231 -231
- package/core/{engine → client/engine}/render-engine.ts +350 -350
- package/core/{engine → client/engine}/runtime-builder.ts +177 -177
- package/core/{engine → client/engine}/scope-resolver.ts +308 -308
- package/core/{engine → client/engine}/soma-bootstrap.ts +8 -8
- package/core/{engine → client/engine}/style-binder.ts +423 -423
- package/core/{engine → client/engine}/theme-variables.ts +1 -1
- package/core/{engine → client/engine}/timer-engine.ts +3 -3
- package/core/{engine → client/engine}/trigger-engine.ts +2 -2
- package/core/client/host-bridge/index.ts +27 -0
- package/core/client/host-bridge/load-host-domain-class.ts +87 -0
- package/core/client/host-bridge/soma-domain-loaders.stub.ts +6 -0
- package/core/client/host-bridge/soma-domain-loaders.ts +69 -0
- package/core/{infra → client/infra}/http/SomaHttpService.ts +208 -199
- package/core/{parser → client/parser}/annotation-extractor.ts +2 -2
- package/core/{parser → client/parser}/pipeline-parser.ts +3 -3
- package/core/{parser → client/parser}/style-config-parser.ts +340 -340
- package/core/{parser → client/parser}/timer-parser.ts +3 -3
- package/core/{parser → client/parser}/trigger-parser.ts +3 -3
- package/core/{parser → client/parser}/ui-config-parser.ts +408 -408
- package/core/{parser → client/parser}/yaml-loader.ts +36 -36
- package/core/{runtime → client/runtime}/SomaRuntimeServices.ts +5 -1
- package/core/client/runtime/serialize-page-state.ts +152 -0
- package/core/{scheduler → client/scheduler}/SomaScheduler.ts +190 -190
- package/core/{validation → client/validation}/contract-validator.ts +2 -2
- package/core/index.ts +55 -32
- package/core/{api → server/api}/IService.ts +29 -29
- package/core/server/headless/soma-headless-page.ts +103 -0
- package/core/server/host/app-config-composer.ts +90 -0
- package/core/server/host/host-config-paths.cjs +100 -0
- package/core/server/host/host-config-paths.ts +132 -0
- package/core/server/host/invoke-host-request-hook.ts +37 -0
- package/core/server/host/page-response-mode.cjs +96 -0
- package/core/server/host/page-response-request.ts +35 -0
- package/core/server/host/request-origin.ts +18 -0
- package/core/server/host/resolve-host-request-hook.ts +29 -0
- package/core/server/host/server-page-assets.ts +193 -0
- package/core/server/host/soma-request-hook-host.stub.ts +4 -0
- package/core/{host → server/host}/source-packages.ts +46 -5
- package/core/server/index.ts +41 -0
- package/core/{infra → server/infra}/cache/ServerFileCache.ts +123 -123
- package/core/server/infra/db/soma-db.ts +70 -0
- package/core/server/infra/http/soma-server-request-context.ts +126 -0
- package/core/server/mock/node/catch-all.mjs +35 -0
- package/core/server/mock/node/cli.d.mts +58 -0
- package/core/server/mock/node/cli.mjs +243 -0
- package/core/server/mock/node/context.mjs +167 -0
- package/core/server/mock/node/environment-policy.mjs +52 -0
- package/core/server/mock/node/plugin-loader.mjs +212 -0
- package/core/server/mock/node/preload.mjs +91 -0
- package/core/server/mock/node/process-lifecycle.mjs +236 -0
- package/core/server/mock/node/public.d.mts +110 -0
- package/core/server/mock/node/public.mjs +4 -0
- package/core/server/mock/node/registry.mjs +336 -0
- package/core/server/mock/node/schema-generator.mjs +1310 -0
- package/core/server/mock/testing/host-harness.d.mts +66 -0
- package/core/server/mock/testing/host-harness.mjs +276 -0
- package/core/server/mock/testing/host-runtime.mjs +48 -0
- package/core/server/server-only.d.ts +1 -0
- package/core/{types → shared/types}/domain.types.ts +91 -91
- package/dist/cli/soma.js +374 -3
- package/dist/core/index.cjs +2933 -2460
- package/dist/diagnostics/telemetry.cjs +1 -1
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/{compiler → build/compiler}/full-manifest-builder.d.ts +7 -5
- package/dist/types/{compiler → build/compiler}/precompiled-manifest-loader.d.ts +1 -1
- package/dist/types/{compiler → build/compiler}/soma-precompile.d.ts +5 -5
- package/dist/types/{compiler → build/compiler}/vite-plugin-soma.d.ts +1 -1
- package/dist/types/{base → client/base}/SomaHttpClient.d.ts +2 -0
- package/dist/types/{base → client/base}/SomaPageRootBase.d.ts +1 -1
- package/dist/types/{base → client/base}/SomaValidator.d.ts +1 -1
- package/dist/types/{compiler → client/compiler}/manifest-compiler.d.ts +3 -3
- package/dist/types/{engine → client/engine}/dom-renderer.d.ts +2 -2
- package/dist/types/{engine → client/engine}/event-engine.d.ts +1 -1
- package/dist/types/{engine → client/engine}/on-change-engine.d.ts +1 -1
- package/dist/types/{engine → client/engine}/property-watcher.d.ts +1 -1
- package/dist/types/{engine → client/engine}/render-engine.d.ts +3 -3
- package/dist/types/{engine → client/engine}/runtime-builder.d.ts +5 -5
- package/dist/types/{engine → client/engine}/scope-resolver.d.ts +1 -1
- package/dist/types/{engine → client/engine}/soma-bootstrap.d.ts +7 -7
- package/dist/types/{engine → client/engine}/style-binder.d.ts +1 -1
- package/dist/types/{engine → client/engine}/theme-variables.d.ts +1 -1
- package/dist/types/{engine → client/engine}/timer-engine.d.ts +1 -1
- package/dist/types/{engine → client/engine}/trigger-engine.d.ts +1 -1
- package/dist/types/client/host-bridge/index.d.ts +9 -0
- package/dist/types/client/host-bridge/load-host-domain-class.d.ts +12 -0
- package/dist/types/client/host-bridge/soma-domain-loaders.d.ts +19 -0
- package/dist/types/client/host-bridge/soma-domain-loaders.stub.d.ts +4 -0
- package/dist/types/{infra → client/infra}/http/SomaHttpService.d.ts +3 -1
- package/dist/types/{parser → client/parser}/annotation-extractor.d.ts +2 -2
- package/dist/types/{parser → client/parser}/pipeline-parser.d.ts +1 -1
- package/dist/types/{parser → client/parser}/style-config-parser.d.ts +1 -1
- package/dist/types/{parser → client/parser}/timer-parser.d.ts +2 -2
- package/dist/types/{parser → client/parser}/trigger-parser.d.ts +2 -2
- package/dist/types/{parser → client/parser}/ui-config-parser.d.ts +1 -1
- package/dist/types/client/runtime/serialize-page-state.d.ts +10 -0
- package/dist/types/{scheduler → client/scheduler}/SomaScheduler.d.ts +1 -1
- package/dist/types/{validation → client/validation}/contract-validator.d.ts +2 -2
- package/dist/types/index.d.ts +35 -32
- package/dist/types/{api → server/api}/IService.d.ts +1 -1
- package/dist/types/server/headless/soma-headless-page.d.ts +12 -0
- package/dist/types/server/host/app-config-composer.d.ts +6 -0
- package/dist/types/server/host/host-config-paths.d.ts +23 -0
- package/dist/types/server/host/invoke-host-request-hook.d.ts +8 -0
- package/dist/types/server/host/page-response-request.d.ts +9 -0
- package/dist/types/server/host/request-origin.d.ts +1 -0
- package/dist/types/server/host/resolve-host-request-hook.d.ts +16 -0
- package/dist/types/server/host/server-page-assets.d.ts +29 -0
- package/dist/types/server/host/soma-request-hook-host.stub.d.ts +2 -0
- package/dist/types/server/host/source-packages.d.ts +12 -0
- package/dist/types/server/index.d.ts +19 -0
- package/dist/types/server/infra/db/soma-db.d.ts +31 -0
- package/dist/types/server/infra/http/soma-server-request-context.d.ts +5 -0
- package/dist/types/{types → shared/types}/domain.types.d.ts +1 -1
- package/docs//345/256/242/346/210/267/347/253/257/346/234/215/345/212/241/347/253/257/351/232/224/347/246/273/346/226/271/346/241/210.md +399 -0
- package/docs//351/232/224/347/246/273/346/216/245/345/205/245/345/217/230/346/233/264/346/226/271/346/241/210.md +250 -0
- package/docs//351/241/265/351/235/242JSON/346/250/241/345/274/217/346/216/245/345/205/245/346/214/207/345/215/227.md +141 -0
- package/global.d.ts +67 -26
- package/middleware.ts +33 -0
- package/next.config.js +116 -30
- package/package.json +59 -21
- package/tailwind.config.ts +24 -24
- package/tsconfig.json +1 -5
- package/app/api/page/route.ts +0 -119
- package/app/loading.tsx +0 -5
- package/core/compiler/host-config-sync.cjs +0 -38
- package/dist/types/host/source-packages.d.ts +0 -8
- /package/core/{compiler → build/compiler}/page-base-resolver.ts +0 -0
- /package/core/{compiler → build/compiler}/rspack-plugin-soma.js +0 -0
- /package/core/{compiler → build/compiler}/soma-rspack-yaml-loader.js +0 -0
- /package/core/{lsp → build/lsp}/cross-file-diagnostics.cjs +0 -0
- /package/core/{lsp → build/lsp}/event-yaml-completion.cjs +0 -0
- /package/core/{lsp → build/lsp}/extra-completion.cjs +0 -0
- /package/core/{lsp → build/lsp}/lsp-navigation.cjs +0 -0
- /package/core/{lsp → build/lsp}/ui-yaml-completion.cjs +0 -0
- /package/core/{base → client/base}/SomaEntity.ts +0 -0
- /package/core/{base → client/base}/SomaLocaleOnlyPageRoot.ts +0 -0
- /package/core/{base → client/base}/decorators/Event.ts +0 -0
- /package/core/{base → client/base}/decorators/Locale.ts +0 -0
- /package/core/{base → client/base}/decorators/Page.ts +0 -0
- /package/core/{base → client/base}/decorators/Show.ts +0 -0
- /package/core/{base → client/base}/decorators/ShowList.ts +0 -0
- /package/core/{base → client/base}/decorators/index.ts +0 -0
- /package/core/{base → client/base}/index.ts +0 -0
- /package/core/{base → client/base}/runAsync.ts +0 -0
- /package/core/{container → client/container}/IContainerAdapter.ts +0 -0
- /package/core/{container → client/container}/MiniProgramContainerAdapter.ts +0 -0
- /package/core/{container → client/container}/ReactNativeContainerAdapter.ts +0 -0
- /package/core/{container → client/container}/SomaContainerAdapter.ts +0 -0
- /package/core/{diagnostics → client/diagnostics}/SomaDiagnostics.ts +0 -0
- /package/core/{diagnostics → client/diagnostics}/SomaTelemetry.ts +0 -0
- /package/core/{diagnostics → client/diagnostics}/telemetry-context.ts +0 -0
- /package/core/{host → client/host-bridge}/resolve-host-bootstrap.ts +0 -0
- /package/core/{host → client/host-bridge}/soma-bootstrap-host.stub.ts +0 -0
- /package/core/{infra → client/infra}/auth/IAuthService.ts +0 -0
- /package/core/{infra → client/infra}/auth/TokenAuthService.ts +0 -0
- /package/core/{infra → client/infra}/cache/ICache.ts +0 -0
- /package/core/{infra → client/infra}/cache/MemoryCache.ts +0 -0
- /package/core/{infra → client/infra}/config/IConfig.ts +0 -0
- /package/core/{infra → client/infra}/config/SomaConfig.ts +0 -0
- /package/core/{infra → client/infra}/event-bus/IEventBus.ts +0 -0
- /package/core/{infra → client/infra}/event-bus/SomaEventBus.ts +0 -0
- /package/core/{infra → client/infra}/http/IHttpClient.ts +0 -0
- /package/core/{infra → client/infra}/i18n/DefaultI18n.ts +0 -0
- /package/core/{infra → client/infra}/i18n/II18n.ts +0 -0
- /package/core/{infra → client/infra}/logger/ConsoleLogger.ts +0 -0
- /package/core/{infra → client/infra}/logger/ILogger.ts +0 -0
- /package/core/{infra → client/infra}/notify/DefaultNotifyService.ts +0 -0
- /package/core/{infra → client/infra}/notify/DomNotifyService.ts +0 -0
- /package/core/{infra → client/infra}/notify/INotifyService.ts +0 -0
- /package/core/{infra → client/infra}/notify/INotifyTheme.ts +0 -0
- /package/core/{infra → client/infra}/permission/IPermission.ts +0 -0
- /package/core/{infra → client/infra}/permission/SomaPermission.ts +0 -0
- /package/core/{infra → client/infra}/realtime/IRealtimeService.ts +0 -0
- /package/core/{infra → client/infra}/realtime/IRealtimeTransport.ts +0 -0
- /package/core/{infra → client/infra}/realtime/SomaRealtimeService.ts +0 -0
- /package/core/{infra → client/infra}/realtime/SseRealtimeTransport.ts +0 -0
- /package/core/{infra → client/infra}/realtime/WebSocketRealtimeTransport.ts +0 -0
- /package/core/{infra → client/infra}/router/IRouter.ts +0 -0
- /package/core/{infra → client/infra}/router/SomaRouter.ts +0 -0
- /package/core/{infra → client/infra}/router/router-path.ts +0 -0
- /package/core/{infra → client/infra}/storage/IStorageService.ts +0 -0
- /package/core/{infra → client/infra}/storage/MemoryStorageService.ts +0 -0
- /package/core/{infra → client/infra}/storage/SessionStorageService.ts +0 -0
- /package/core/{infra → client/infra}/timer/ITimer.ts +0 -0
- /package/core/{infra → client/infra}/timer/SomaTimer.ts +0 -0
- /package/core/{middleware → client/middleware}/SomaMiddlewareChain.ts +0 -0
- /package/core/{middleware → client/middleware}/createPermissionMiddleware.ts +0 -0
- /package/core/{quality → client/quality}/SomaQualityRegistry.ts +0 -0
- /package/core/{runtime → client/runtime}/SomaSnapshotStore.ts +0 -0
- /package/core/{api → server/api}/load-host-service.ts +0 -0
- /package/core/{api → server/api}/service-path.ts +0 -0
- /package/core/{host → server/host}/app-config.stub.ts +0 -0
- /package/core/{host → server/host}/locale.stub.ts +0 -0
- /package/core/{manifest → shared/manifest}/manifest-contract.ts +0 -0
- /package/core/{types → shared/types}/engine.types.ts +0 -0
- /package/core/{types → shared/types}/event.types.ts +0 -0
- /package/core/{types → shared/types}/keyboard.types.ts +0 -0
- /package/core/{types → shared/types}/manifest.types.ts +0 -0
- /package/core/{types → shared/types}/scheduler.types.ts +0 -0
- /package/core/{types → shared/types}/style-config.types.ts +0 -0
- /package/core/{types → shared/types}/timer.types.ts +0 -0
- /package/core/{types → shared/types}/trigger.types.ts +0 -0
- /package/core/{types → shared/types}/ui-config.types.ts +0 -0
- /package/core/{types → shared/types}/watcher.types.ts +0 -0
- /package/dist/types/{compiler → build/compiler}/page-base-resolver.d.ts +0 -0
- /package/dist/types/{compiler → build/compiler}/rollup-plugin-soma.d.ts +0 -0
- /package/dist/types/{compiler → build/compiler}/route-builder.d.ts +0 -0
- /package/dist/types/{base → client/base}/SomaApi.d.ts +0 -0
- /package/dist/types/{base → client/base}/SomaDict.d.ts +0 -0
- /package/dist/types/{base → client/base}/SomaEntity.d.ts +0 -0
- /package/dist/types/{base → client/base}/SomaLocaleOnlyPageRoot.d.ts +0 -0
- /package/dist/types/{base → client/base}/decorators/Event.d.ts +0 -0
- /package/dist/types/{base → client/base}/decorators/Locale.d.ts +0 -0
- /package/dist/types/{base → client/base}/decorators/Page.d.ts +0 -0
- /package/dist/types/{base → client/base}/decorators/Show.d.ts +0 -0
- /package/dist/types/{base → client/base}/decorators/ShowList.d.ts +0 -0
- /package/dist/types/{base → client/base}/decorators/index.d.ts +0 -0
- /package/dist/types/{base → client/base}/index.d.ts +0 -0
- /package/dist/types/{base → client/base}/runAsync.d.ts +0 -0
- /package/dist/types/{container → client/container}/IContainerAdapter.d.ts +0 -0
- /package/dist/types/{container → client/container}/MiniProgramContainerAdapter.d.ts +0 -0
- /package/dist/types/{container → client/container}/ReactNativeContainerAdapter.d.ts +0 -0
- /package/dist/types/{container → client/container}/SomaContainerAdapter.d.ts +0 -0
- /package/dist/types/{diagnostics → client/diagnostics}/SomaDiagnostics.d.ts +0 -0
- /package/dist/types/{diagnostics → client/diagnostics}/SomaTelemetry.d.ts +0 -0
- /package/dist/types/{diagnostics → client/diagnostics}/telemetry-context.d.ts +0 -0
- /package/dist/types/{engine → client/engine}/asset-resolver.d.ts +0 -0
- /package/dist/types/{engine → client/engine}/lis.d.ts +0 -0
- /package/dist/types/{engine → client/engine}/reactive-proxy.d.ts +0 -0
- /package/dist/types/{host → client/host-bridge}/resolve-host-bootstrap.d.ts +0 -0
- /package/dist/types/{host → client/host-bridge}/soma-bootstrap-host.stub.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/auth/IAuthService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/auth/TokenAuthService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/cache/ICache.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/cache/MemoryCache.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/config/IConfig.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/config/SomaConfig.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/event-bus/IEventBus.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/event-bus/SomaEventBus.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/http/IHttpClient.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/i18n/DefaultI18n.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/i18n/II18n.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/logger/ConsoleLogger.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/logger/ILogger.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/notify/DefaultNotifyService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/notify/DomNotifyService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/notify/INotifyService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/notify/INotifyTheme.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/permission/IPermission.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/permission/SomaPermission.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/realtime/IRealtimeService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/realtime/IRealtimeTransport.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/realtime/SomaRealtimeService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/realtime/SseRealtimeTransport.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/realtime/WebSocketRealtimeTransport.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/router/IRouter.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/router/SomaRouter.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/router/router-path.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/storage/IStorageService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/storage/MemoryStorageService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/storage/SessionStorageService.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/timer/ITimer.d.ts +0 -0
- /package/dist/types/{infra → client/infra}/timer/SomaTimer.d.ts +0 -0
- /package/dist/types/{middleware → client/middleware}/SomaMiddlewareChain.d.ts +0 -0
- /package/dist/types/{middleware → client/middleware}/createPermissionMiddleware.d.ts +0 -0
- /package/dist/types/{parser → client/parser}/yaml-loader.d.ts +0 -0
- /package/dist/types/{quality → client/quality}/SomaQualityRegistry.d.ts +0 -0
- /package/dist/types/{runtime → client/runtime}/SomaRuntimeServices.d.ts +0 -0
- /package/dist/types/{runtime → client/runtime}/SomaSnapshotStore.d.ts +0 -0
- /package/dist/types/{api → server/api}/load-host-service.d.ts +0 -0
- /package/dist/types/{api → server/api}/service-path.d.ts +0 -0
- /package/dist/types/{host → server/host}/app-config.stub.d.ts +0 -0
- /package/dist/types/{host → server/host}/locale.stub.d.ts +0 -0
- /package/dist/types/{infra → server/infra}/cache/ServerFileCache.d.ts +0 -0
- /package/dist/types/{manifest → shared/manifest}/manifest-contract.d.ts +0 -0
- /package/dist/types/{types → shared/types}/engine.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/event.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/keyboard.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/manifest.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/scheduler.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/style-config.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/timer.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/trigger.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/ui-config.types.d.ts +0 -0
- /package/dist/types/{types → shared/types}/watcher.types.d.ts +0 -0
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
// core/base/SomaDict.ts — 字典基类
|
|
2
|
-
// 封装缓存、去重加载、TTL 机制的字典数据管理
|
|
3
|
-
// 不依赖任何 DOM API,可在 Node.js 环境下独立运行
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 缓存条目
|
|
7
|
-
*/
|
|
8
|
-
interface CacheEntry<T> {
|
|
9
|
-
/** 缓存的数据 */
|
|
10
|
-
data: T;
|
|
11
|
-
/** 缓存写入时的时间戳(ms) */
|
|
12
|
-
timestamp: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* SomaDict — 字典基类
|
|
17
|
-
*
|
|
18
|
-
* 为常量对象/字典数据提供以下能力:
|
|
19
|
-
* - 数据缓存:避免重复请求同一字典
|
|
20
|
-
* - 去重加载:同一 key 在并发请求时只发起一次实际加载
|
|
21
|
-
* - TTL 过期:缓存可配置生存时间,过期后自动重新加载
|
|
22
|
-
*
|
|
23
|
-
* 子类需实现 fetchData() 方法,定义具体的数据加载逻辑。
|
|
24
|
-
*
|
|
25
|
-
* @template T 字典数据类型
|
|
26
|
-
*
|
|
27
|
-
* 使用示例:
|
|
28
|
-
* ```typescript
|
|
29
|
-
* class DeviceTypeDict extends SomaDict<string[]> {
|
|
30
|
-
* protected async fetchData(key: string): Promise<string[]> {
|
|
31
|
-
* const res = await fetch(`/api/dict/${key}`);
|
|
32
|
-
* return res.json();
|
|
33
|
-
* }
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* const dict = new DeviceTypeDict();
|
|
37
|
-
* const types = await dict.get('device_types');
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export abstract class SomaDict<T = any> {
|
|
41
|
-
/** 数据缓存:key -> CacheEntry */
|
|
42
|
-
private cache: Map<string, CacheEntry<T>> = new Map();
|
|
43
|
-
|
|
44
|
-
/** 进行中的请求:key -> Promise(用于去重) */
|
|
45
|
-
private pending: Map<string, Promise<T>> = new Map();
|
|
46
|
-
|
|
47
|
-
/** 缓存生存时间(毫秒),默认 5 分钟。子类可 override */
|
|
48
|
-
protected ttl: number = 5 * 60 * 1000;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 子类必须实现:定义具体的数据加载逻辑
|
|
52
|
-
*
|
|
53
|
-
* @param key 字典键
|
|
54
|
-
* @returns 加载到的数据
|
|
55
|
-
*/
|
|
56
|
-
protected abstract fetchData(key: string): Promise<T>;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 获取字典数据
|
|
60
|
-
* 优先从缓存读取,缓存未命中或已过期时从后端加载
|
|
61
|
-
* 并发请求同一 key 时自动去重,共享同一个 Promise
|
|
62
|
-
*
|
|
63
|
-
* @param key 字典键
|
|
64
|
-
* @param forceRefresh 是否强制刷新(忽略缓存)
|
|
65
|
-
* @returns 字典数据
|
|
66
|
-
*/
|
|
67
|
-
async get(key: string, forceRefresh: boolean = false): Promise<T> {
|
|
68
|
-
// 检查缓存是否有效
|
|
69
|
-
if (!forceRefresh) {
|
|
70
|
-
const cached = this.cache.get(key);
|
|
71
|
-
if (cached && !this.isExpired(cached)) {
|
|
72
|
-
return cached.data;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 检查是否有进行中的相同请求(去重)
|
|
77
|
-
const inflight = this.pending.get(key);
|
|
78
|
-
if (inflight) {
|
|
79
|
-
return inflight;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 发起新的加载请求
|
|
83
|
-
const promise = this.loadAndCache(key);
|
|
84
|
-
this.pending.set(key, promise);
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
return await promise;
|
|
88
|
-
} finally {
|
|
89
|
-
this.pending.delete(key);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 批量获取多个字典数据
|
|
95
|
-
*
|
|
96
|
-
* @param keys 字典键数组
|
|
97
|
-
* @returns key -> data 的映射
|
|
98
|
-
*/
|
|
99
|
-
async getMany(keys: string[]): Promise<Map<string, T>> {
|
|
100
|
-
const results = new Map<string, T>();
|
|
101
|
-
const promises = keys.map(async (key) => {
|
|
102
|
-
const data = await this.get(key);
|
|
103
|
-
results.set(key, data);
|
|
104
|
-
});
|
|
105
|
-
await Promise.all(promises);
|
|
106
|
-
return results;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 手动设置缓存(用于预热或测试)
|
|
111
|
-
*
|
|
112
|
-
* @param key 字典键
|
|
113
|
-
* @param data 数据
|
|
114
|
-
*/
|
|
115
|
-
set(key: string, data: T): void {
|
|
116
|
-
this.cache.set(key, {
|
|
117
|
-
data,
|
|
118
|
-
timestamp: Date.now(),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* 使指定 key 的缓存失效
|
|
124
|
-
*
|
|
125
|
-
* @param key 字典键
|
|
126
|
-
*/
|
|
127
|
-
invalidate(key: string): void {
|
|
128
|
-
this.cache.delete(key);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 清空所有缓存
|
|
133
|
-
*/
|
|
134
|
-
clear(): void {
|
|
135
|
-
this.cache.clear();
|
|
136
|
-
this.pending.clear();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* 检查指定 key 是否已缓存且未过期
|
|
141
|
-
*
|
|
142
|
-
* @param key 字典键
|
|
143
|
-
* @returns 是否有有效缓存
|
|
144
|
-
*/
|
|
145
|
-
has(key: string): boolean {
|
|
146
|
-
const cached = this.cache.get(key);
|
|
147
|
-
return cached != null && !this.isExpired(cached);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* 加载数据并写入缓存
|
|
152
|
-
*/
|
|
153
|
-
private async loadAndCache(key: string): Promise<T> {
|
|
154
|
-
const data = await this.fetchData(key);
|
|
155
|
-
this.cache.set(key, {
|
|
156
|
-
data,
|
|
157
|
-
timestamp: Date.now(),
|
|
158
|
-
});
|
|
159
|
-
return data;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 检查缓存条目是否已过期
|
|
164
|
-
*/
|
|
165
|
-
private isExpired(entry: CacheEntry<T>): boolean {
|
|
166
|
-
return Date.now() - entry.timestamp > this.ttl;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
1
|
+
// core/client/base/SomaDict.ts — 字典基类
|
|
2
|
+
// 封装缓存、去重加载、TTL 机制的字典数据管理
|
|
3
|
+
// 不依赖任何 DOM API,可在 Node.js 环境下独立运行
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 缓存条目
|
|
7
|
+
*/
|
|
8
|
+
interface CacheEntry<T> {
|
|
9
|
+
/** 缓存的数据 */
|
|
10
|
+
data: T;
|
|
11
|
+
/** 缓存写入时的时间戳(ms) */
|
|
12
|
+
timestamp: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* SomaDict — 字典基类
|
|
17
|
+
*
|
|
18
|
+
* 为常量对象/字典数据提供以下能力:
|
|
19
|
+
* - 数据缓存:避免重复请求同一字典
|
|
20
|
+
* - 去重加载:同一 key 在并发请求时只发起一次实际加载
|
|
21
|
+
* - TTL 过期:缓存可配置生存时间,过期后自动重新加载
|
|
22
|
+
*
|
|
23
|
+
* 子类需实现 fetchData() 方法,定义具体的数据加载逻辑。
|
|
24
|
+
*
|
|
25
|
+
* @template T 字典数据类型
|
|
26
|
+
*
|
|
27
|
+
* 使用示例:
|
|
28
|
+
* ```typescript
|
|
29
|
+
* class DeviceTypeDict extends SomaDict<string[]> {
|
|
30
|
+
* protected async fetchData(key: string): Promise<string[]> {
|
|
31
|
+
* const res = await fetch(`/api/dict/${key}`);
|
|
32
|
+
* return res.json();
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* const dict = new DeviceTypeDict();
|
|
37
|
+
* const types = await dict.get('device_types');
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export abstract class SomaDict<T = any> {
|
|
41
|
+
/** 数据缓存:key -> CacheEntry */
|
|
42
|
+
private cache: Map<string, CacheEntry<T>> = new Map();
|
|
43
|
+
|
|
44
|
+
/** 进行中的请求:key -> Promise(用于去重) */
|
|
45
|
+
private pending: Map<string, Promise<T>> = new Map();
|
|
46
|
+
|
|
47
|
+
/** 缓存生存时间(毫秒),默认 5 分钟。子类可 override */
|
|
48
|
+
protected ttl: number = 5 * 60 * 1000;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 子类必须实现:定义具体的数据加载逻辑
|
|
52
|
+
*
|
|
53
|
+
* @param key 字典键
|
|
54
|
+
* @returns 加载到的数据
|
|
55
|
+
*/
|
|
56
|
+
protected abstract fetchData(key: string): Promise<T>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 获取字典数据
|
|
60
|
+
* 优先从缓存读取,缓存未命中或已过期时从后端加载
|
|
61
|
+
* 并发请求同一 key 时自动去重,共享同一个 Promise
|
|
62
|
+
*
|
|
63
|
+
* @param key 字典键
|
|
64
|
+
* @param forceRefresh 是否强制刷新(忽略缓存)
|
|
65
|
+
* @returns 字典数据
|
|
66
|
+
*/
|
|
67
|
+
async get(key: string, forceRefresh: boolean = false): Promise<T> {
|
|
68
|
+
// 检查缓存是否有效
|
|
69
|
+
if (!forceRefresh) {
|
|
70
|
+
const cached = this.cache.get(key);
|
|
71
|
+
if (cached && !this.isExpired(cached)) {
|
|
72
|
+
return cached.data;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 检查是否有进行中的相同请求(去重)
|
|
77
|
+
const inflight = this.pending.get(key);
|
|
78
|
+
if (inflight) {
|
|
79
|
+
return inflight;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 发起新的加载请求
|
|
83
|
+
const promise = this.loadAndCache(key);
|
|
84
|
+
this.pending.set(key, promise);
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
return await promise;
|
|
88
|
+
} finally {
|
|
89
|
+
this.pending.delete(key);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 批量获取多个字典数据
|
|
95
|
+
*
|
|
96
|
+
* @param keys 字典键数组
|
|
97
|
+
* @returns key -> data 的映射
|
|
98
|
+
*/
|
|
99
|
+
async getMany(keys: string[]): Promise<Map<string, T>> {
|
|
100
|
+
const results = new Map<string, T>();
|
|
101
|
+
const promises = keys.map(async (key) => {
|
|
102
|
+
const data = await this.get(key);
|
|
103
|
+
results.set(key, data);
|
|
104
|
+
});
|
|
105
|
+
await Promise.all(promises);
|
|
106
|
+
return results;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 手动设置缓存(用于预热或测试)
|
|
111
|
+
*
|
|
112
|
+
* @param key 字典键
|
|
113
|
+
* @param data 数据
|
|
114
|
+
*/
|
|
115
|
+
set(key: string, data: T): void {
|
|
116
|
+
this.cache.set(key, {
|
|
117
|
+
data,
|
|
118
|
+
timestamp: Date.now(),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 使指定 key 的缓存失效
|
|
124
|
+
*
|
|
125
|
+
* @param key 字典键
|
|
126
|
+
*/
|
|
127
|
+
invalidate(key: string): void {
|
|
128
|
+
this.cache.delete(key);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 清空所有缓存
|
|
133
|
+
*/
|
|
134
|
+
clear(): void {
|
|
135
|
+
this.cache.clear();
|
|
136
|
+
this.pending.clear();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 检查指定 key 是否已缓存且未过期
|
|
141
|
+
*
|
|
142
|
+
* @param key 字典键
|
|
143
|
+
* @returns 是否有有效缓存
|
|
144
|
+
*/
|
|
145
|
+
has(key: string): boolean {
|
|
146
|
+
const cached = this.cache.get(key);
|
|
147
|
+
return cached != null && !this.isExpired(cached);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 加载数据并写入缓存
|
|
152
|
+
*/
|
|
153
|
+
private async loadAndCache(key: string): Promise<T> {
|
|
154
|
+
const data = await this.fetchData(key);
|
|
155
|
+
this.cache.set(key, {
|
|
156
|
+
data,
|
|
157
|
+
timestamp: Date.now(),
|
|
158
|
+
});
|
|
159
|
+
return data;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 检查缓存条目是否已过期
|
|
164
|
+
*/
|
|
165
|
+
private isExpired(entry: CacheEntry<T>): boolean {
|
|
166
|
+
return Date.now() - entry.timestamp > this.ttl;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -1,126 +1,128 @@
|
|
|
1
|
-
// core/base/SomaHttpClient.ts — API 请求封装
|
|
2
|
-
// 统一的 HTTP 客户端,处理 baseURL、超时、错误拦截、请求取消
|
|
3
|
-
// 不依赖任何 DOM API,可在 Node.js 环境下独立运行
|
|
4
|
-
// 使用全局 fetch(Node.js 18+ 原生支持,或通过 polyfill 提供)
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* HTTP 客户端配置
|
|
8
|
-
*/
|
|
9
|
-
export interface SomaHttpClientConfig {
|
|
10
|
-
/** API 基础地址(如 "https://api.example.com") */
|
|
11
|
-
baseURL: string;
|
|
12
|
-
/** 请求超时时间(毫秒),默认 30000 */
|
|
13
|
-
timeout?: number;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* -
|
|
23
|
-
* -
|
|
24
|
-
* -
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
1
|
+
// core/client/base/SomaHttpClient.ts — API 请求封装
|
|
2
|
+
// 统一的 HTTP 客户端,处理 baseURL、超时、错误拦截、请求取消
|
|
3
|
+
// 不依赖任何 DOM API,可在 Node.js 环境下独立运行
|
|
4
|
+
// 使用全局 fetch(Node.js 18+ 原生支持,或通过 polyfill 提供)
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HTTP 客户端配置
|
|
8
|
+
*/
|
|
9
|
+
export interface SomaHttpClientConfig {
|
|
10
|
+
/** API 基础地址(如 "https://api.example.com") */
|
|
11
|
+
baseURL: string;
|
|
12
|
+
/** 请求超时时间(毫秒),默认 30000 */
|
|
13
|
+
timeout?: number;
|
|
14
|
+
/** Generic headers supplied by the host runtime, such as page context. */
|
|
15
|
+
defaultHeaders?: Record<string, string> | (() => Record<string, string>);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* SomaHttpClient — API 请求封装
|
|
20
|
+
*
|
|
21
|
+
* 提供以下能力:
|
|
22
|
+
* - GET / POST / PUT / DELETE 四种 HTTP 方法
|
|
23
|
+
* - baseURL 自动拼接
|
|
24
|
+
* - 超时控制(基于 AbortController)
|
|
25
|
+
* - 请求取消:abortAll() 可一键取消所有进行中的请求
|
|
26
|
+
* - JSON 自动序列化/反序列化
|
|
27
|
+
*
|
|
28
|
+
* 使用示例:
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const http = new SomaHttpClient({ baseURL: 'https://api.example.com' });
|
|
31
|
+
* const data = await http.get<User[]>('/users');
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export class SomaHttpClient {
|
|
35
|
+
private baseURL: string;
|
|
36
|
+
private timeout: number;
|
|
37
|
+
private abortControllers: Set<AbortController> = new Set();
|
|
38
|
+
|
|
39
|
+
constructor(config: SomaHttpClientConfig) {
|
|
40
|
+
this.baseURL = config.baseURL;
|
|
41
|
+
this.timeout = config.timeout ?? 30000;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 发送 GET 请求
|
|
46
|
+
* @param path 请求路径(拼接在 baseURL 后面)
|
|
47
|
+
* @returns 响应 JSON 解析后的数据
|
|
48
|
+
*/
|
|
49
|
+
async get<T>(path: string): Promise<T> {
|
|
50
|
+
return this.request<T>('GET', path);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 发送 POST 请求
|
|
55
|
+
* @param path 请求路径
|
|
56
|
+
* @param body 请求体(将被 JSON.stringify 序列化)
|
|
57
|
+
* @returns 响应 JSON 解析后的数据
|
|
58
|
+
*/
|
|
59
|
+
async post<T>(path: string, body?: any): Promise<T> {
|
|
60
|
+
return this.request<T>('POST', path, body);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 发送 PUT 请求
|
|
65
|
+
* @param path 请求路径
|
|
66
|
+
* @param body 请求体
|
|
67
|
+
* @returns 响应 JSON 解析后的数据
|
|
68
|
+
*/
|
|
69
|
+
async put<T>(path: string, body?: any): Promise<T> {
|
|
70
|
+
return this.request<T>('PUT', path, body);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 发送 DELETE 请求
|
|
75
|
+
* @param path 请求路径
|
|
76
|
+
* @returns 响应 JSON 解析后的数据
|
|
77
|
+
*/
|
|
78
|
+
async delete<T>(path: string): Promise<T> {
|
|
79
|
+
return this.request<T>('DELETE', path);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 取消所有进行中的请求
|
|
84
|
+
* 通常在 onUnmount 生命周期钩子中调用
|
|
85
|
+
*/
|
|
86
|
+
abortAll(): void {
|
|
87
|
+
this.abortControllers.forEach((c) => c.abort());
|
|
88
|
+
this.abortControllers.clear();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 内部统一请求方法
|
|
93
|
+
*/
|
|
94
|
+
private async request<T>(method: string, path: string, body?: any): Promise<T> {
|
|
95
|
+
const controller = new AbortController();
|
|
96
|
+
this.abortControllers.add(controller);
|
|
97
|
+
|
|
98
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const url = `${this.baseURL}${path}`;
|
|
102
|
+
const headers: Record<string, string> = {
|
|
103
|
+
'Content-Type': 'application/json',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const options: RequestInit = {
|
|
107
|
+
method,
|
|
108
|
+
headers,
|
|
109
|
+
signal: controller.signal,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
if (body !== undefined) {
|
|
113
|
+
options.body = JSON.stringify(body);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const res = await fetch(url, options);
|
|
117
|
+
|
|
118
|
+
if (!res.ok) {
|
|
119
|
+
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return (await res.json()) as T;
|
|
123
|
+
} finally {
|
|
124
|
+
clearTimeout(timeoutId);
|
|
125
|
+
this.abortControllers.delete(controller);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|