soma-core 1.1.0 → 1.2.0
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 +5 -5
- package/app/api/[...path]/route.ts +3 -3
- package/app/components/SomaHostPage.tsx +1 -1
- package/app/layout.tsx +13 -13
- package/app/soma/manifest/route.ts +1 -1
- package/app/soma/page/route.ts +1 -1
- package/app/soma/page-object/route.ts +9 -8
- package/bin/soma-db.cjs +13 -0
- package/bin/soma-lsp.cjs +5 -5
- package/bin/soma-mock.mjs +1 -1
- package/bin/soma-sync.cjs +1 -1
- package/core/{compiler → build/compiler}/full-manifest-builder.ts +10 -10
- package/core/{compiler → build/compiler}/host-config-sync.cjs +1 -1
- 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 +1 -1
- 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/build/db/cli.ts +10 -0
- package/core/build/db/emit-entities.ts +45 -0
- package/core/build/db/emit-mappers.ts +175 -0
- package/core/build/db/emit-prisma-schema.ts +92 -0
- package/core/build/db/generate.ts +166 -0
- package/core/build/db/ir.ts +75 -0
- package/core/build/db/load-db-yaml.ts +241 -0
- 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 +123 -123
- 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/{host → client/host-bridge}/load-host-domain-class.ts +1 -1
- package/core/{infra → client/infra}/http/SomaHttpService.ts +185 -185
- 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/{scheduler → client/scheduler}/SomaScheduler.ts +190 -190
- package/core/{validation → client/validation}/contract-validator.ts +2 -2
- package/core/index.ts +40 -39
- package/core/{api → server/api}/IService.ts +29 -29
- package/core/{engine → server/headless}/soma-headless-page.ts +26 -9
- package/core/{host → server/host}/server-page-assets.ts +1 -1
- package/core/server/index.ts +56 -0
- package/core/{infra → server/infra}/cache/ServerFileCache.ts +123 -123
- package/core/server/infra/db/errors.ts +11 -0
- package/core/server/infra/db/mapper/PrismaSomaMapper.ts +313 -0
- package/core/server/infra/db/mapper/SomaBaseMapper.ts +23 -0
- package/core/server/infra/db/mapper/SomaMapperHooks.ts +13 -0
- package/core/server/infra/db/query/SomaQuery.ts +149 -0
- package/core/server/infra/db/service/SomaDbService.ts +64 -0
- package/core/server/infra/db/soma-db.ts +120 -0
- package/core/server/infra/db/types.ts +21 -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 +5 -1
- package/dist/core/index.cjs +73 -73
- 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 +5 -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/build/db/cli.d.ts +2 -0
- package/dist/types/build/db/emit-entities.d.ts +5 -0
- package/dist/types/build/db/emit-mappers.d.ts +15 -0
- package/dist/types/build/db/emit-prisma-schema.d.ts +2 -0
- package/dist/types/build/db/generate.d.ts +7 -0
- package/dist/types/build/db/ir.d.ts +58 -0
- package/dist/types/build/db/load-db-yaml.d.ts +14 -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/{host → client/host-bridge}/load-host-domain-class.d.ts +1 -1
- package/dist/types/{infra → client/infra}/http/SomaHttpService.d.ts +1 -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/{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 -35
- package/dist/types/{api → server/api}/IService.d.ts +1 -1
- package/dist/types/{engine → server/headless}/soma-headless-page.d.ts +4 -2
- package/dist/types/server/index.d.ts +26 -0
- package/dist/types/server/infra/db/errors.d.ts +5 -0
- package/dist/types/server/infra/db/mapper/PrismaSomaMapper.d.ts +77 -0
- package/dist/types/server/infra/db/mapper/SomaBaseMapper.d.ts +20 -0
- package/dist/types/server/infra/db/mapper/SomaMapperHooks.d.ts +12 -0
- package/dist/types/server/infra/db/query/SomaQuery.d.ts +42 -0
- package/dist/types/server/infra/db/service/SomaDbService.d.ts +24 -0
- package/dist/types/server/infra/db/soma-db.d.ts +45 -0
- package/dist/types/server/infra/db/types.d.ts +18 -0
- package/dist/types/{types → shared/types}/domain.types.d.ts +1 -1
- package/global.d.ts +8 -8
- package/middleware.ts +1 -1
- package/next.config.js +11 -11
- package/package.json +34 -26
- package/tailwind.config.ts +24 -24
- 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 +0 -141
- /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/{host → client/host-bridge}/soma-domain-loaders.stub.ts +0 -0
- /package/core/{host → client/host-bridge}/soma-domain-loaders.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}/SomaRuntimeServices.ts +0 -0
- /package/core/{runtime → client/runtime}/SomaSnapshotStore.ts +0 -0
- /package/core/{runtime → client/runtime}/serialize-page-state.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-composer.ts +0 -0
- /package/core/{host → server/host}/app-config.stub.ts +0 -0
- /package/core/{host → server/host}/host-config-paths.cjs +0 -0
- /package/core/{host → server/host}/host-config-paths.ts +0 -0
- /package/core/{host → server/host}/invoke-host-request-hook.ts +0 -0
- /package/core/{host → server/host}/locale.stub.ts +0 -0
- /package/core/{host → server/host}/page-response-mode.cjs +0 -0
- /package/core/{host → server/host}/page-response-request.ts +0 -0
- /package/core/{host → server/host}/request-origin.ts +0 -0
- /package/core/{host → server/host}/resolve-host-request-hook.ts +0 -0
- /package/core/{host → server/host}/soma-request-hook-host.stub.ts +0 -0
- /package/core/{host → server/host}/source-packages.ts +0 -0
- /package/core/{infra → server/infra}/http/soma-server-request-context.ts +0 -0
- /package/core/{mock → server/mock}/node/catch-all.mjs +0 -0
- /package/core/{mock → server/mock}/node/cli.d.mts +0 -0
- /package/core/{mock → server/mock}/node/cli.mjs +0 -0
- /package/core/{mock → server/mock}/node/context.mjs +0 -0
- /package/core/{mock → server/mock}/node/environment-policy.mjs +0 -0
- /package/core/{mock → server/mock}/node/plugin-loader.mjs +0 -0
- /package/core/{mock → server/mock}/node/preload.mjs +0 -0
- /package/core/{mock → server/mock}/node/process-lifecycle.mjs +0 -0
- /package/core/{mock → server/mock}/node/public.d.mts +0 -0
- /package/core/{mock → server/mock}/node/public.mjs +0 -0
- /package/core/{mock → server/mock}/node/registry.mjs +0 -0
- /package/core/{mock → server/mock}/node/schema-generator.mjs +0 -0
- /package/core/{mock → server/mock}/testing/host-harness.d.mts +0 -0
- /package/core/{mock → server/mock}/testing/host-harness.mjs +0 -0
- /package/core/{mock → server/mock}/testing/host-runtime.mjs +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}/SomaHttpClient.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/{host → client/host-bridge}/soma-domain-loaders.d.ts +0 -0
- /package/dist/types/{host → client/host-bridge}/soma-domain-loaders.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/{runtime → client/runtime}/serialize-page-state.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-composer.d.ts +0 -0
- /package/dist/types/{host → server/host}/app-config.stub.d.ts +0 -0
- /package/dist/types/{host → server/host}/host-config-paths.d.ts +0 -0
- /package/dist/types/{host → server/host}/invoke-host-request-hook.d.ts +0 -0
- /package/dist/types/{host → server/host}/locale.stub.d.ts +0 -0
- /package/dist/types/{host → server/host}/page-response-request.d.ts +0 -0
- /package/dist/types/{host → server/host}/request-origin.d.ts +0 -0
- /package/dist/types/{host → server/host}/resolve-host-request-hook.d.ts +0 -0
- /package/dist/types/{host → server/host}/server-page-assets.d.ts +0 -0
- /package/dist/types/{host → server/host}/soma-request-hook-host.stub.d.ts +0 -0
- /package/dist/types/{host → server/host}/source-packages.d.ts +0 -0
- /package/dist/types/{infra → server/infra}/cache/ServerFileCache.d.ts +0 -0
- /package/dist/types/{infra → server/infra}/http/soma-server-request-context.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
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { emitEntities } from './emit-entities';
|
|
5
|
+
import {
|
|
6
|
+
emitApiServices,
|
|
7
|
+
emitMappers,
|
|
8
|
+
emitRepositoryIndex,
|
|
9
|
+
emitServices,
|
|
10
|
+
} from './emit-mappers';
|
|
11
|
+
import { emitPrismaSchema } from './emit-prisma-schema';
|
|
12
|
+
import type { DbGenerateOptions, DbSchemaIr } from './ir';
|
|
13
|
+
import { loadDbSchemaIr, resolveDefaultDbYamlPath } from './load-db-yaml';
|
|
14
|
+
import { resolveHostAppConfigPath } from '../../server/host/host-config-paths';
|
|
15
|
+
|
|
16
|
+
function writeFile(filePath: string, content: string): void {
|
|
17
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
18
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function scaffoldLibDb(hostDir: string): string | null {
|
|
22
|
+
const target = path.join(hostDir, 'lib', 'db.ts');
|
|
23
|
+
if (fs.existsSync(target)) return null;
|
|
24
|
+
const content = [
|
|
25
|
+
"import { PrismaClient } from '@prisma/client';",
|
|
26
|
+
"import { createSomaDbSingleton, registerSomaDbProvider } from 'soma-core/server';",
|
|
27
|
+
'',
|
|
28
|
+
'/** Register Prisma client for repository mappers (server-only). */',
|
|
29
|
+
'const prisma = createSomaDbSingleton(() => new PrismaClient());',
|
|
30
|
+
'registerSomaDbProvider({',
|
|
31
|
+
' getClient: () => prisma,',
|
|
32
|
+
' disconnect: () => prisma.$disconnect(),',
|
|
33
|
+
'});',
|
|
34
|
+
'export const db = prisma;',
|
|
35
|
+
'',
|
|
36
|
+
].join('\n');
|
|
37
|
+
writeFile(target, content);
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DbGenerateResult {
|
|
42
|
+
schema: DbSchemaIr;
|
|
43
|
+
written: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function generateSomaDb(options: DbGenerateOptions): DbGenerateResult {
|
|
47
|
+
const hostDir = path.resolve(options.hostDir);
|
|
48
|
+
const dbYamlPath = options.dbYamlPath ?? resolveDefaultDbYamlPath(hostDir);
|
|
49
|
+
const appConfigPath =
|
|
50
|
+
options.appConfigPath
|
|
51
|
+
?? resolveHostAppConfigPath(hostDir)
|
|
52
|
+
?? (fs.existsSync(path.join(hostDir, 'config', 'app.config.yaml'))
|
|
53
|
+
? path.join(hostDir, 'config', 'app.config.yaml')
|
|
54
|
+
: null);
|
|
55
|
+
|
|
56
|
+
const schema = loadDbSchemaIr({ dbYamlPath, appConfigPath });
|
|
57
|
+
if (options.generateApiService !== undefined) {
|
|
58
|
+
schema.generateApiService = options.generateApiService;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const repositoryDir = options.repositoryDir ?? path.join(hostDir, 'repository');
|
|
62
|
+
const prismaSchemaPath =
|
|
63
|
+
options.prismaSchemaPath ?? path.join(hostDir, 'prisma', 'schema.prisma');
|
|
64
|
+
|
|
65
|
+
const written: string[] = [];
|
|
66
|
+
|
|
67
|
+
writeFile(prismaSchemaPath, emitPrismaSchema(schema));
|
|
68
|
+
written.push(prismaSchemaPath);
|
|
69
|
+
|
|
70
|
+
for (const file of emitEntities(schema)) {
|
|
71
|
+
const target = path.join(repositoryDir, 'entity', file.fileName);
|
|
72
|
+
writeFile(target, file.content);
|
|
73
|
+
written.push(target);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (const file of emitMappers(schema)) {
|
|
77
|
+
const target = path.join(repositoryDir, 'mapper', file.fileName);
|
|
78
|
+
writeFile(target, file.content);
|
|
79
|
+
written.push(target);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (const file of emitServices(schema)) {
|
|
83
|
+
const target = path.join(repositoryDir, 'service', file.fileName);
|
|
84
|
+
writeFile(target, file.content);
|
|
85
|
+
written.push(target);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const indexPath = path.join(repositoryDir, 'index.ts');
|
|
89
|
+
writeFile(indexPath, emitRepositoryIndex(schema));
|
|
90
|
+
written.push(indexPath);
|
|
91
|
+
|
|
92
|
+
if (schema.generateApiService) {
|
|
93
|
+
for (const file of emitApiServices(schema)) {
|
|
94
|
+
const target = path.join(hostDir, 'api', 'service', 'db', file.fileName);
|
|
95
|
+
writeFile(target, file.content);
|
|
96
|
+
written.push(target);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (options.scaffoldLibDb !== false) {
|
|
101
|
+
const libDb = scaffoldLibDb(hostDir);
|
|
102
|
+
if (libDb) written.push(libDb);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { schema, written };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function runPrisma(hostDir: string, prismaArgs: string[]): number {
|
|
109
|
+
const child = spawnSync('npx', ['prisma', ...prismaArgs], {
|
|
110
|
+
cwd: hostDir,
|
|
111
|
+
stdio: 'inherit',
|
|
112
|
+
shell: process.platform === 'win32',
|
|
113
|
+
env: process.env,
|
|
114
|
+
});
|
|
115
|
+
return child.status === null ? 1 : child.status;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function runSomaDbCli(argv: string[], hostDir = process.cwd()): number {
|
|
119
|
+
const [command, ...rest] = argv;
|
|
120
|
+
|
|
121
|
+
if (command === 'generate') {
|
|
122
|
+
const withApi = rest.includes('--with-api');
|
|
123
|
+
try {
|
|
124
|
+
const result = generateSomaDb({
|
|
125
|
+
hostDir,
|
|
126
|
+
generateApiService: withApi ? true : undefined,
|
|
127
|
+
});
|
|
128
|
+
console.log(`[soma db] generated ${result.schema.models.length} model(s):`);
|
|
129
|
+
for (const file of result.written) {
|
|
130
|
+
console.log(` - ${path.relative(hostDir, file)}`);
|
|
131
|
+
}
|
|
132
|
+
console.log('[soma db] next: npm i @prisma/client prisma && npx soma db prisma generate');
|
|
133
|
+
return 0;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (command === 'migrate') {
|
|
141
|
+
const nameIdx = rest.indexOf('--name');
|
|
142
|
+
const name = nameIdx >= 0 ? rest[nameIdx + 1] : 'init';
|
|
143
|
+
console.log('[soma db] running prisma migrate dev...');
|
|
144
|
+
return runPrisma(hostDir, ['migrate', 'dev', '--name', name || 'init']);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (command === 'prisma') {
|
|
148
|
+
if (rest.length === 0) {
|
|
149
|
+
console.error('Usage: soma db prisma <prisma-args...>');
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
return runPrisma(hostDir, rest);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (command === 'pull') {
|
|
156
|
+
console.log('[soma db] running prisma db pull (introspection)...');
|
|
157
|
+
return runPrisma(hostDir, ['db', 'pull']);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
console.error('Usage: soma db <generate|migrate|pull|prisma> [...args]');
|
|
161
|
+
console.error(' soma db generate [--with-api]');
|
|
162
|
+
console.error(' soma db migrate [--name <migration>]');
|
|
163
|
+
console.error(' soma db pull');
|
|
164
|
+
console.error(' soma db prisma generate|migrate|...');
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema IR for Host config/db.yaml → Prisma + repository codegen.
|
|
3
|
+
* MySQL only.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type DbFieldType =
|
|
7
|
+
| 'string'
|
|
8
|
+
| 'int'
|
|
9
|
+
| 'bigint'
|
|
10
|
+
| 'float'
|
|
11
|
+
| 'decimal'
|
|
12
|
+
| 'boolean'
|
|
13
|
+
| 'datetime'
|
|
14
|
+
| 'json'
|
|
15
|
+
| 'text';
|
|
16
|
+
|
|
17
|
+
export type DbFieldDefault = 'cuid' | 'uuid' | 'now' | 'autoincrement' | string | number | boolean;
|
|
18
|
+
|
|
19
|
+
export interface DbFieldIr {
|
|
20
|
+
name: string;
|
|
21
|
+
type: DbFieldType;
|
|
22
|
+
id?: boolean;
|
|
23
|
+
optional?: boolean;
|
|
24
|
+
unique?: boolean;
|
|
25
|
+
default?: DbFieldDefault;
|
|
26
|
+
precision?: number;
|
|
27
|
+
scale?: number;
|
|
28
|
+
/** Soft-delete column (TableLogic) */
|
|
29
|
+
logicDelete?: boolean;
|
|
30
|
+
/** Auto-fill on insert */
|
|
31
|
+
fillOnInsert?: boolean;
|
|
32
|
+
/** Auto-fill on update (and insert if also fillOnInsert or createdAt pattern) */
|
|
33
|
+
fillOnUpdate?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type DbRelationKind = 'hasMany' | 'belongsTo';
|
|
37
|
+
|
|
38
|
+
export interface DbRelationIr {
|
|
39
|
+
name: string;
|
|
40
|
+
kind: DbRelationKind;
|
|
41
|
+
model: string;
|
|
42
|
+
fields?: string[];
|
|
43
|
+
references?: string[];
|
|
44
|
+
optional?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface DbModelIr {
|
|
48
|
+
name: string;
|
|
49
|
+
table: string;
|
|
50
|
+
idField: string;
|
|
51
|
+
fields: DbFieldIr[];
|
|
52
|
+
relations: DbRelationIr[];
|
|
53
|
+
logicDeleteField?: string;
|
|
54
|
+
createdAtField?: string;
|
|
55
|
+
updatedAtField?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface DbSchemaIr {
|
|
59
|
+
provider: 'mysql';
|
|
60
|
+
datasourceUrlEnv: string;
|
|
61
|
+
models: DbModelIr[];
|
|
62
|
+
/** When true, also emit api/service/db/* CRUD scaffolds */
|
|
63
|
+
generateApiService: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface DbGenerateOptions {
|
|
67
|
+
hostDir: string;
|
|
68
|
+
dbYamlPath?: string;
|
|
69
|
+
appConfigPath?: string;
|
|
70
|
+
repositoryDir?: string;
|
|
71
|
+
prismaSchemaPath?: string;
|
|
72
|
+
scaffoldLibDb?: boolean;
|
|
73
|
+
/** Override yaml generateApiService */
|
|
74
|
+
generateApiService?: boolean;
|
|
75
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
import type {
|
|
5
|
+
DbFieldDefault,
|
|
6
|
+
DbFieldIr,
|
|
7
|
+
DbFieldType,
|
|
8
|
+
DbModelIr,
|
|
9
|
+
DbRelationIr,
|
|
10
|
+
DbSchemaIr,
|
|
11
|
+
} from './ir';
|
|
12
|
+
|
|
13
|
+
const FIELD_TYPES = new Set<DbFieldType>([
|
|
14
|
+
'string',
|
|
15
|
+
'int',
|
|
16
|
+
'bigint',
|
|
17
|
+
'float',
|
|
18
|
+
'decimal',
|
|
19
|
+
'boolean',
|
|
20
|
+
'datetime',
|
|
21
|
+
'json',
|
|
22
|
+
'text',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
26
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function asString(value: unknown, label: string): string {
|
|
30
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
31
|
+
throw new Error(`[soma db] ${label} must be a non-empty string`);
|
|
32
|
+
}
|
|
33
|
+
return value.trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function parseField(name: string, raw: unknown): DbFieldIr | DbRelationIr {
|
|
37
|
+
if (!isRecord(raw)) {
|
|
38
|
+
throw new Error(`[soma db] field "${name}" must be an object`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const type = asString(raw.type, `fields.${name}.type`);
|
|
42
|
+
if (type === 'hasMany' || type === 'belongsTo') {
|
|
43
|
+
const relation: DbRelationIr = {
|
|
44
|
+
name,
|
|
45
|
+
kind: type,
|
|
46
|
+
model: asString(raw.model, `fields.${name}.model`),
|
|
47
|
+
optional: raw.optional === true,
|
|
48
|
+
};
|
|
49
|
+
if (Array.isArray(raw.fields)) {
|
|
50
|
+
relation.fields = raw.fields.map((item, index) =>
|
|
51
|
+
asString(item, `fields.${name}.fields[${index}]`),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(raw.references)) {
|
|
55
|
+
relation.references = raw.references.map((item, index) =>
|
|
56
|
+
asString(item, `fields.${name}.references[${index}]`),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
if (type === 'belongsTo' && (!relation.fields?.length || !relation.references?.length)) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`[soma db] belongsTo "${name}" requires fields and references arrays`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return relation;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!FIELD_TYPES.has(type as DbFieldType)) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`[soma db] unsupported field type "${type}" on "${name}" (MySQL scalar or hasMany/belongsTo)`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const field: DbFieldIr = {
|
|
74
|
+
name,
|
|
75
|
+
type: type as DbFieldType,
|
|
76
|
+
id: raw.id === true,
|
|
77
|
+
optional: raw.optional === true || raw.logicDelete === true,
|
|
78
|
+
unique: raw.unique === true,
|
|
79
|
+
logicDelete: raw.logicDelete === true,
|
|
80
|
+
fillOnInsert: raw.fillOnInsert === true,
|
|
81
|
+
fillOnUpdate: raw.fillOnUpdate === true,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
if (raw.default !== undefined) {
|
|
85
|
+
field.default = raw.default as DbFieldDefault;
|
|
86
|
+
}
|
|
87
|
+
if (typeof raw.precision === 'number') field.precision = raw.precision;
|
|
88
|
+
if (typeof raw.scale === 'number') field.scale = raw.scale;
|
|
89
|
+
|
|
90
|
+
return field;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function parseModel(name: string, raw: unknown): DbModelIr {
|
|
94
|
+
if (!isRecord(raw)) {
|
|
95
|
+
throw new Error(`[soma db] model "${name}" must be an object`);
|
|
96
|
+
}
|
|
97
|
+
if (!isRecord(raw.fields)) {
|
|
98
|
+
throw new Error(`[soma db] model "${name}" requires fields object`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const fields: DbFieldIr[] = [];
|
|
102
|
+
const relations: DbRelationIr[] = [];
|
|
103
|
+
for (const [fieldName, fieldRaw] of Object.entries(raw.fields)) {
|
|
104
|
+
const parsed = parseField(fieldName, fieldRaw);
|
|
105
|
+
if ('kind' in parsed) {
|
|
106
|
+
relations.push(parsed);
|
|
107
|
+
} else {
|
|
108
|
+
fields.push(parsed);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (fields.length === 0) {
|
|
113
|
+
throw new Error(`[soma db] model "${name}" has no scalar fields`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const idField =
|
|
117
|
+
typeof raw.idField === 'string' && raw.idField.trim()
|
|
118
|
+
? raw.idField.trim()
|
|
119
|
+
: fields.find((field) => field.id)?.name;
|
|
120
|
+
if (!idField) {
|
|
121
|
+
throw new Error(`[soma db] model "${name}" needs an id field (id: true) or idField`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const logicDeleteField =
|
|
125
|
+
typeof raw.logicDelete === 'string' && raw.logicDelete.trim()
|
|
126
|
+
? raw.logicDelete.trim()
|
|
127
|
+
: fields.find((field) => field.logicDelete)?.name;
|
|
128
|
+
|
|
129
|
+
const createdAtField =
|
|
130
|
+
typeof raw.createdAt === 'string' && raw.createdAt.trim()
|
|
131
|
+
? raw.createdAt.trim()
|
|
132
|
+
: fields.find((field) => field.fillOnInsert && !field.fillOnUpdate)?.name
|
|
133
|
+
?? fields.find((field) => field.name === 'createdAt')?.name;
|
|
134
|
+
|
|
135
|
+
const updatedAtField =
|
|
136
|
+
typeof raw.updatedAt === 'string' && raw.updatedAt.trim()
|
|
137
|
+
? raw.updatedAt.trim()
|
|
138
|
+
: fields.find((field) => field.fillOnUpdate)?.name
|
|
139
|
+
?? fields.find((field) => field.name === 'updatedAt')?.name;
|
|
140
|
+
|
|
141
|
+
// Ensure fill flags for conventional timestamp fields used by mapper options
|
|
142
|
+
for (const field of fields) {
|
|
143
|
+
if (field.name === createdAtField) field.fillOnInsert = true;
|
|
144
|
+
if (field.name === updatedAtField) {
|
|
145
|
+
field.fillOnInsert = true;
|
|
146
|
+
field.fillOnUpdate = true;
|
|
147
|
+
}
|
|
148
|
+
if (field.name === logicDeleteField) {
|
|
149
|
+
field.logicDelete = true;
|
|
150
|
+
field.optional = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
name,
|
|
156
|
+
table:
|
|
157
|
+
typeof raw.table === 'string' && raw.table.trim()
|
|
158
|
+
? raw.table.trim()
|
|
159
|
+
: toTableName(name),
|
|
160
|
+
idField,
|
|
161
|
+
fields,
|
|
162
|
+
relations,
|
|
163
|
+
logicDeleteField,
|
|
164
|
+
createdAtField,
|
|
165
|
+
updatedAtField,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function toTableName(modelName: string): string {
|
|
170
|
+
return modelName
|
|
171
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
172
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
173
|
+
.toLowerCase() + 's';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function parseDbYaml(source: string): {
|
|
177
|
+
models: DbModelIr[];
|
|
178
|
+
generateApiService: boolean;
|
|
179
|
+
} {
|
|
180
|
+
const loaded = source.trim() ? yaml.load(source) : {};
|
|
181
|
+
if (!isRecord(loaded)) {
|
|
182
|
+
throw new Error('[soma db] config/db.yaml must be a mapping');
|
|
183
|
+
}
|
|
184
|
+
if (!isRecord(loaded.models)) {
|
|
185
|
+
throw new Error('[soma db] config/db.yaml requires models: { ... }');
|
|
186
|
+
}
|
|
187
|
+
const models = Object.entries(loaded.models).map(([name, raw]) => parseModel(name, raw));
|
|
188
|
+
const generateApiService = loaded.generateApiService === true
|
|
189
|
+
|| (isRecord(loaded.generate) && loaded.generate.apiService === true);
|
|
190
|
+
return { models, generateApiService };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function readDatasourceFromAppConfig(appConfigYaml: string): {
|
|
194
|
+
provider: 'mysql';
|
|
195
|
+
datasourceUrlEnv: string;
|
|
196
|
+
} {
|
|
197
|
+
const loaded = appConfigYaml.trim() ? yaml.load(appConfigYaml) : {};
|
|
198
|
+
const soma = isRecord(loaded) && isRecord(loaded.soma) ? loaded.soma : {};
|
|
199
|
+
const db = isRecord(soma.db) ? soma.db : {};
|
|
200
|
+
|
|
201
|
+
const providerRaw = typeof db.provider === 'string' ? db.provider.trim().toLowerCase() : 'mysql';
|
|
202
|
+
if (providerRaw && providerRaw !== 'mysql') {
|
|
203
|
+
throw new Error(`[soma db] only mysql is supported, got provider="${providerRaw}"`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let datasourceUrlEnv = 'DATABASE_URL';
|
|
207
|
+
if (typeof db.urlEnv === 'string' && db.urlEnv.trim()) {
|
|
208
|
+
datasourceUrlEnv = db.urlEnv.trim();
|
|
209
|
+
} else if (typeof db.url === 'string' && db.url.trim()) {
|
|
210
|
+
datasourceUrlEnv = 'DATABASE_URL';
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return { provider: 'mysql', datasourceUrlEnv };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function loadDbSchemaIr(options: {
|
|
217
|
+
dbYamlPath: string;
|
|
218
|
+
appConfigPath: string | null;
|
|
219
|
+
}): DbSchemaIr {
|
|
220
|
+
if (!fs.existsSync(options.dbYamlPath)) {
|
|
221
|
+
throw new Error(`[soma db] missing table config: ${options.dbYamlPath}`);
|
|
222
|
+
}
|
|
223
|
+
const dbYaml = fs.readFileSync(options.dbYamlPath, 'utf8');
|
|
224
|
+
const { models, generateApiService } = parseDbYaml(dbYaml);
|
|
225
|
+
|
|
226
|
+
let datasource = { provider: 'mysql' as const, datasourceUrlEnv: 'DATABASE_URL' };
|
|
227
|
+
if (options.appConfigPath && fs.existsSync(options.appConfigPath)) {
|
|
228
|
+
datasource = readDatasourceFromAppConfig(fs.readFileSync(options.appConfigPath, 'utf8'));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
provider: datasource.provider,
|
|
233
|
+
datasourceUrlEnv: datasource.datasourceUrlEnv,
|
|
234
|
+
models,
|
|
235
|
+
generateApiService,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function resolveDefaultDbYamlPath(hostDir: string): string {
|
|
240
|
+
return path.join(hostDir, 'config', 'db.yaml');
|
|
241
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// soma-core/core/base/SomaApi.ts
|
|
2
|
-
// 业务 API 处理类基类,用户继承此类实现具体接口
|
|
3
|
-
|
|
4
|
-
export abstract class SomaApi {
|
|
5
|
-
abstract handle(req: Request): Promise<Response>;
|
|
6
|
-
|
|
7
|
-
protected json(data: unknown, status = 200): Response {
|
|
8
|
-
return Response.json(data, { status });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
protected error(message: string, status = 400): Response {
|
|
12
|
-
return Response.json({ error: message }, { status });
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
// soma-core/core/client/base/SomaApi.ts
|
|
2
|
+
// 业务 API 处理类基类,用户继承此类实现具体接口
|
|
3
|
+
|
|
4
|
+
export abstract class SomaApi {
|
|
5
|
+
abstract handle(req: Request): Promise<Response>;
|
|
6
|
+
|
|
7
|
+
protected json(data: unknown, status = 200): Response {
|
|
8
|
+
return Response.json(data, { status });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
protected error(message: string, status = 400): Response {
|
|
12
|
+
return Response.json({ error: message }, { status });
|
|
13
|
+
}
|
|
14
|
+
}
|