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.
Files changed (323) hide show
  1. package/app/SomaPageClient.tsx +12 -49
  2. package/app/[...path]/page.tsx +21 -0
  3. package/app/api/[...path]/route.ts +86 -77
  4. package/app/components/SomaHostPage.tsx +133 -0
  5. package/app/components/SomaHydrationShell.tsx +1 -1
  6. package/app/layout.tsx +22 -18
  7. package/app/page.tsx +7 -18
  8. package/app/soma/[...path]/route.ts +9 -0
  9. package/app/{api/soma-manifest → soma/manifest}/route.ts +3 -3
  10. package/app/soma/page/route.ts +29 -0
  11. package/app/soma/page-object/route.ts +159 -0
  12. package/app/soma/route.ts +9 -0
  13. package/bin/soma-lsp.cjs +5 -5
  14. package/bin/soma-mock.mjs +38 -0
  15. package/bin/soma-sync.cjs +1 -1
  16. package/core/{compiler → build/compiler}/full-manifest-builder.ts +84 -69
  17. package/core/build/compiler/host-config-sync.cjs +64 -0
  18. package/core/{compiler → build/compiler}/precompiled-manifest-loader.ts +1 -1
  19. package/core/{compiler → build/compiler}/rollup-plugin-soma.ts +1 -1
  20. package/core/{compiler → build/compiler}/route-builder.ts +31 -31
  21. package/core/{compiler → build/compiler}/soma-manifest-webpack-plugin.js +41 -7
  22. package/core/{compiler → build/compiler}/soma-precompile.js +8 -8
  23. package/core/{compiler → build/compiler}/soma-precompile.ts +94 -94
  24. package/core/{compiler → build/compiler}/soma-webpack-loader.js +41 -41
  25. package/core/{compiler → build/compiler}/vite-plugin-soma.ts +83 -83
  26. package/core/{base → client/base}/SomaApi.ts +14 -14
  27. package/core/{base → client/base}/SomaDict.ts +168 -168
  28. package/core/{base → client/base}/SomaHttpClient.ts +128 -126
  29. package/core/{base → client/base}/SomaPageRootBase.ts +71 -71
  30. package/core/{base → client/base}/SomaValidator.ts +147 -147
  31. package/core/{compiler → client/compiler}/manifest-compiler.ts +238 -238
  32. package/core/{engine → client/engine}/asset-resolver.ts +102 -102
  33. package/core/{engine → client/engine}/dom-renderer.ts +341 -341
  34. package/core/{engine → client/engine}/event-engine.ts +356 -356
  35. package/core/{engine → client/engine}/lis.ts +60 -60
  36. package/core/{engine → client/engine}/on-change-engine.ts +3 -3
  37. package/core/{engine → client/engine}/property-watcher.ts +2 -2
  38. package/core/{engine → client/engine}/reactive-proxy.ts +231 -231
  39. package/core/{engine → client/engine}/render-engine.ts +350 -350
  40. package/core/{engine → client/engine}/runtime-builder.ts +177 -177
  41. package/core/{engine → client/engine}/scope-resolver.ts +308 -308
  42. package/core/{engine → client/engine}/soma-bootstrap.ts +8 -8
  43. package/core/{engine → client/engine}/style-binder.ts +423 -423
  44. package/core/{engine → client/engine}/theme-variables.ts +1 -1
  45. package/core/{engine → client/engine}/timer-engine.ts +3 -3
  46. package/core/{engine → client/engine}/trigger-engine.ts +2 -2
  47. package/core/client/host-bridge/index.ts +27 -0
  48. package/core/client/host-bridge/load-host-domain-class.ts +87 -0
  49. package/core/client/host-bridge/soma-domain-loaders.stub.ts +6 -0
  50. package/core/client/host-bridge/soma-domain-loaders.ts +69 -0
  51. package/core/{infra → client/infra}/http/SomaHttpService.ts +208 -199
  52. package/core/{parser → client/parser}/annotation-extractor.ts +2 -2
  53. package/core/{parser → client/parser}/pipeline-parser.ts +3 -3
  54. package/core/{parser → client/parser}/style-config-parser.ts +340 -340
  55. package/core/{parser → client/parser}/timer-parser.ts +3 -3
  56. package/core/{parser → client/parser}/trigger-parser.ts +3 -3
  57. package/core/{parser → client/parser}/ui-config-parser.ts +408 -408
  58. package/core/{parser → client/parser}/yaml-loader.ts +36 -36
  59. package/core/{runtime → client/runtime}/SomaRuntimeServices.ts +5 -1
  60. package/core/client/runtime/serialize-page-state.ts +152 -0
  61. package/core/{scheduler → client/scheduler}/SomaScheduler.ts +190 -190
  62. package/core/{validation → client/validation}/contract-validator.ts +2 -2
  63. package/core/index.ts +55 -32
  64. package/core/{api → server/api}/IService.ts +29 -29
  65. package/core/server/headless/soma-headless-page.ts +103 -0
  66. package/core/server/host/app-config-composer.ts +90 -0
  67. package/core/server/host/host-config-paths.cjs +100 -0
  68. package/core/server/host/host-config-paths.ts +132 -0
  69. package/core/server/host/invoke-host-request-hook.ts +37 -0
  70. package/core/server/host/page-response-mode.cjs +96 -0
  71. package/core/server/host/page-response-request.ts +35 -0
  72. package/core/server/host/request-origin.ts +18 -0
  73. package/core/server/host/resolve-host-request-hook.ts +29 -0
  74. package/core/server/host/server-page-assets.ts +193 -0
  75. package/core/server/host/soma-request-hook-host.stub.ts +4 -0
  76. package/core/{host → server/host}/source-packages.ts +46 -5
  77. package/core/server/index.ts +41 -0
  78. package/core/{infra → server/infra}/cache/ServerFileCache.ts +123 -123
  79. package/core/server/infra/db/soma-db.ts +70 -0
  80. package/core/server/infra/http/soma-server-request-context.ts +126 -0
  81. package/core/server/mock/node/catch-all.mjs +35 -0
  82. package/core/server/mock/node/cli.d.mts +58 -0
  83. package/core/server/mock/node/cli.mjs +243 -0
  84. package/core/server/mock/node/context.mjs +167 -0
  85. package/core/server/mock/node/environment-policy.mjs +52 -0
  86. package/core/server/mock/node/plugin-loader.mjs +212 -0
  87. package/core/server/mock/node/preload.mjs +91 -0
  88. package/core/server/mock/node/process-lifecycle.mjs +236 -0
  89. package/core/server/mock/node/public.d.mts +110 -0
  90. package/core/server/mock/node/public.mjs +4 -0
  91. package/core/server/mock/node/registry.mjs +336 -0
  92. package/core/server/mock/node/schema-generator.mjs +1310 -0
  93. package/core/server/mock/testing/host-harness.d.mts +66 -0
  94. package/core/server/mock/testing/host-harness.mjs +276 -0
  95. package/core/server/mock/testing/host-runtime.mjs +48 -0
  96. package/core/server/server-only.d.ts +1 -0
  97. package/core/{types → shared/types}/domain.types.ts +91 -91
  98. package/dist/cli/soma.js +374 -3
  99. package/dist/core/index.cjs +2933 -2460
  100. package/dist/diagnostics/telemetry.cjs +1 -1
  101. package/dist/tsconfig.types.tsbuildinfo +1 -1
  102. package/dist/types/{compiler → build/compiler}/full-manifest-builder.d.ts +7 -5
  103. package/dist/types/{compiler → build/compiler}/precompiled-manifest-loader.d.ts +1 -1
  104. package/dist/types/{compiler → build/compiler}/soma-precompile.d.ts +5 -5
  105. package/dist/types/{compiler → build/compiler}/vite-plugin-soma.d.ts +1 -1
  106. package/dist/types/{base → client/base}/SomaHttpClient.d.ts +2 -0
  107. package/dist/types/{base → client/base}/SomaPageRootBase.d.ts +1 -1
  108. package/dist/types/{base → client/base}/SomaValidator.d.ts +1 -1
  109. package/dist/types/{compiler → client/compiler}/manifest-compiler.d.ts +3 -3
  110. package/dist/types/{engine → client/engine}/dom-renderer.d.ts +2 -2
  111. package/dist/types/{engine → client/engine}/event-engine.d.ts +1 -1
  112. package/dist/types/{engine → client/engine}/on-change-engine.d.ts +1 -1
  113. package/dist/types/{engine → client/engine}/property-watcher.d.ts +1 -1
  114. package/dist/types/{engine → client/engine}/render-engine.d.ts +3 -3
  115. package/dist/types/{engine → client/engine}/runtime-builder.d.ts +5 -5
  116. package/dist/types/{engine → client/engine}/scope-resolver.d.ts +1 -1
  117. package/dist/types/{engine → client/engine}/soma-bootstrap.d.ts +7 -7
  118. package/dist/types/{engine → client/engine}/style-binder.d.ts +1 -1
  119. package/dist/types/{engine → client/engine}/theme-variables.d.ts +1 -1
  120. package/dist/types/{engine → client/engine}/timer-engine.d.ts +1 -1
  121. package/dist/types/{engine → client/engine}/trigger-engine.d.ts +1 -1
  122. package/dist/types/client/host-bridge/index.d.ts +9 -0
  123. package/dist/types/client/host-bridge/load-host-domain-class.d.ts +12 -0
  124. package/dist/types/client/host-bridge/soma-domain-loaders.d.ts +19 -0
  125. package/dist/types/client/host-bridge/soma-domain-loaders.stub.d.ts +4 -0
  126. package/dist/types/{infra → client/infra}/http/SomaHttpService.d.ts +3 -1
  127. package/dist/types/{parser → client/parser}/annotation-extractor.d.ts +2 -2
  128. package/dist/types/{parser → client/parser}/pipeline-parser.d.ts +1 -1
  129. package/dist/types/{parser → client/parser}/style-config-parser.d.ts +1 -1
  130. package/dist/types/{parser → client/parser}/timer-parser.d.ts +2 -2
  131. package/dist/types/{parser → client/parser}/trigger-parser.d.ts +2 -2
  132. package/dist/types/{parser → client/parser}/ui-config-parser.d.ts +1 -1
  133. package/dist/types/client/runtime/serialize-page-state.d.ts +10 -0
  134. package/dist/types/{scheduler → client/scheduler}/SomaScheduler.d.ts +1 -1
  135. package/dist/types/{validation → client/validation}/contract-validator.d.ts +2 -2
  136. package/dist/types/index.d.ts +35 -32
  137. package/dist/types/{api → server/api}/IService.d.ts +1 -1
  138. package/dist/types/server/headless/soma-headless-page.d.ts +12 -0
  139. package/dist/types/server/host/app-config-composer.d.ts +6 -0
  140. package/dist/types/server/host/host-config-paths.d.ts +23 -0
  141. package/dist/types/server/host/invoke-host-request-hook.d.ts +8 -0
  142. package/dist/types/server/host/page-response-request.d.ts +9 -0
  143. package/dist/types/server/host/request-origin.d.ts +1 -0
  144. package/dist/types/server/host/resolve-host-request-hook.d.ts +16 -0
  145. package/dist/types/server/host/server-page-assets.d.ts +29 -0
  146. package/dist/types/server/host/soma-request-hook-host.stub.d.ts +2 -0
  147. package/dist/types/server/host/source-packages.d.ts +12 -0
  148. package/dist/types/server/index.d.ts +19 -0
  149. package/dist/types/server/infra/db/soma-db.d.ts +31 -0
  150. package/dist/types/server/infra/http/soma-server-request-context.d.ts +5 -0
  151. package/dist/types/{types → shared/types}/domain.types.d.ts +1 -1
  152. 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
  153. 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
  154. 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
  155. package/global.d.ts +67 -26
  156. package/middleware.ts +33 -0
  157. package/next.config.js +116 -30
  158. package/package.json +59 -21
  159. package/tailwind.config.ts +24 -24
  160. package/tsconfig.json +1 -5
  161. package/app/api/page/route.ts +0 -119
  162. package/app/loading.tsx +0 -5
  163. package/core/compiler/host-config-sync.cjs +0 -38
  164. package/dist/types/host/source-packages.d.ts +0 -8
  165. /package/core/{compiler → build/compiler}/page-base-resolver.ts +0 -0
  166. /package/core/{compiler → build/compiler}/rspack-plugin-soma.js +0 -0
  167. /package/core/{compiler → build/compiler}/soma-rspack-yaml-loader.js +0 -0
  168. /package/core/{lsp → build/lsp}/cross-file-diagnostics.cjs +0 -0
  169. /package/core/{lsp → build/lsp}/event-yaml-completion.cjs +0 -0
  170. /package/core/{lsp → build/lsp}/extra-completion.cjs +0 -0
  171. /package/core/{lsp → build/lsp}/lsp-navigation.cjs +0 -0
  172. /package/core/{lsp → build/lsp}/ui-yaml-completion.cjs +0 -0
  173. /package/core/{base → client/base}/SomaEntity.ts +0 -0
  174. /package/core/{base → client/base}/SomaLocaleOnlyPageRoot.ts +0 -0
  175. /package/core/{base → client/base}/decorators/Event.ts +0 -0
  176. /package/core/{base → client/base}/decorators/Locale.ts +0 -0
  177. /package/core/{base → client/base}/decorators/Page.ts +0 -0
  178. /package/core/{base → client/base}/decorators/Show.ts +0 -0
  179. /package/core/{base → client/base}/decorators/ShowList.ts +0 -0
  180. /package/core/{base → client/base}/decorators/index.ts +0 -0
  181. /package/core/{base → client/base}/index.ts +0 -0
  182. /package/core/{base → client/base}/runAsync.ts +0 -0
  183. /package/core/{container → client/container}/IContainerAdapter.ts +0 -0
  184. /package/core/{container → client/container}/MiniProgramContainerAdapter.ts +0 -0
  185. /package/core/{container → client/container}/ReactNativeContainerAdapter.ts +0 -0
  186. /package/core/{container → client/container}/SomaContainerAdapter.ts +0 -0
  187. /package/core/{diagnostics → client/diagnostics}/SomaDiagnostics.ts +0 -0
  188. /package/core/{diagnostics → client/diagnostics}/SomaTelemetry.ts +0 -0
  189. /package/core/{diagnostics → client/diagnostics}/telemetry-context.ts +0 -0
  190. /package/core/{host → client/host-bridge}/resolve-host-bootstrap.ts +0 -0
  191. /package/core/{host → client/host-bridge}/soma-bootstrap-host.stub.ts +0 -0
  192. /package/core/{infra → client/infra}/auth/IAuthService.ts +0 -0
  193. /package/core/{infra → client/infra}/auth/TokenAuthService.ts +0 -0
  194. /package/core/{infra → client/infra}/cache/ICache.ts +0 -0
  195. /package/core/{infra → client/infra}/cache/MemoryCache.ts +0 -0
  196. /package/core/{infra → client/infra}/config/IConfig.ts +0 -0
  197. /package/core/{infra → client/infra}/config/SomaConfig.ts +0 -0
  198. /package/core/{infra → client/infra}/event-bus/IEventBus.ts +0 -0
  199. /package/core/{infra → client/infra}/event-bus/SomaEventBus.ts +0 -0
  200. /package/core/{infra → client/infra}/http/IHttpClient.ts +0 -0
  201. /package/core/{infra → client/infra}/i18n/DefaultI18n.ts +0 -0
  202. /package/core/{infra → client/infra}/i18n/II18n.ts +0 -0
  203. /package/core/{infra → client/infra}/logger/ConsoleLogger.ts +0 -0
  204. /package/core/{infra → client/infra}/logger/ILogger.ts +0 -0
  205. /package/core/{infra → client/infra}/notify/DefaultNotifyService.ts +0 -0
  206. /package/core/{infra → client/infra}/notify/DomNotifyService.ts +0 -0
  207. /package/core/{infra → client/infra}/notify/INotifyService.ts +0 -0
  208. /package/core/{infra → client/infra}/notify/INotifyTheme.ts +0 -0
  209. /package/core/{infra → client/infra}/permission/IPermission.ts +0 -0
  210. /package/core/{infra → client/infra}/permission/SomaPermission.ts +0 -0
  211. /package/core/{infra → client/infra}/realtime/IRealtimeService.ts +0 -0
  212. /package/core/{infra → client/infra}/realtime/IRealtimeTransport.ts +0 -0
  213. /package/core/{infra → client/infra}/realtime/SomaRealtimeService.ts +0 -0
  214. /package/core/{infra → client/infra}/realtime/SseRealtimeTransport.ts +0 -0
  215. /package/core/{infra → client/infra}/realtime/WebSocketRealtimeTransport.ts +0 -0
  216. /package/core/{infra → client/infra}/router/IRouter.ts +0 -0
  217. /package/core/{infra → client/infra}/router/SomaRouter.ts +0 -0
  218. /package/core/{infra → client/infra}/router/router-path.ts +0 -0
  219. /package/core/{infra → client/infra}/storage/IStorageService.ts +0 -0
  220. /package/core/{infra → client/infra}/storage/MemoryStorageService.ts +0 -0
  221. /package/core/{infra → client/infra}/storage/SessionStorageService.ts +0 -0
  222. /package/core/{infra → client/infra}/timer/ITimer.ts +0 -0
  223. /package/core/{infra → client/infra}/timer/SomaTimer.ts +0 -0
  224. /package/core/{middleware → client/middleware}/SomaMiddlewareChain.ts +0 -0
  225. /package/core/{middleware → client/middleware}/createPermissionMiddleware.ts +0 -0
  226. /package/core/{quality → client/quality}/SomaQualityRegistry.ts +0 -0
  227. /package/core/{runtime → client/runtime}/SomaSnapshotStore.ts +0 -0
  228. /package/core/{api → server/api}/load-host-service.ts +0 -0
  229. /package/core/{api → server/api}/service-path.ts +0 -0
  230. /package/core/{host → server/host}/app-config.stub.ts +0 -0
  231. /package/core/{host → server/host}/locale.stub.ts +0 -0
  232. /package/core/{manifest → shared/manifest}/manifest-contract.ts +0 -0
  233. /package/core/{types → shared/types}/engine.types.ts +0 -0
  234. /package/core/{types → shared/types}/event.types.ts +0 -0
  235. /package/core/{types → shared/types}/keyboard.types.ts +0 -0
  236. /package/core/{types → shared/types}/manifest.types.ts +0 -0
  237. /package/core/{types → shared/types}/scheduler.types.ts +0 -0
  238. /package/core/{types → shared/types}/style-config.types.ts +0 -0
  239. /package/core/{types → shared/types}/timer.types.ts +0 -0
  240. /package/core/{types → shared/types}/trigger.types.ts +0 -0
  241. /package/core/{types → shared/types}/ui-config.types.ts +0 -0
  242. /package/core/{types → shared/types}/watcher.types.ts +0 -0
  243. /package/dist/types/{compiler → build/compiler}/page-base-resolver.d.ts +0 -0
  244. /package/dist/types/{compiler → build/compiler}/rollup-plugin-soma.d.ts +0 -0
  245. /package/dist/types/{compiler → build/compiler}/route-builder.d.ts +0 -0
  246. /package/dist/types/{base → client/base}/SomaApi.d.ts +0 -0
  247. /package/dist/types/{base → client/base}/SomaDict.d.ts +0 -0
  248. /package/dist/types/{base → client/base}/SomaEntity.d.ts +0 -0
  249. /package/dist/types/{base → client/base}/SomaLocaleOnlyPageRoot.d.ts +0 -0
  250. /package/dist/types/{base → client/base}/decorators/Event.d.ts +0 -0
  251. /package/dist/types/{base → client/base}/decorators/Locale.d.ts +0 -0
  252. /package/dist/types/{base → client/base}/decorators/Page.d.ts +0 -0
  253. /package/dist/types/{base → client/base}/decorators/Show.d.ts +0 -0
  254. /package/dist/types/{base → client/base}/decorators/ShowList.d.ts +0 -0
  255. /package/dist/types/{base → client/base}/decorators/index.d.ts +0 -0
  256. /package/dist/types/{base → client/base}/index.d.ts +0 -0
  257. /package/dist/types/{base → client/base}/runAsync.d.ts +0 -0
  258. /package/dist/types/{container → client/container}/IContainerAdapter.d.ts +0 -0
  259. /package/dist/types/{container → client/container}/MiniProgramContainerAdapter.d.ts +0 -0
  260. /package/dist/types/{container → client/container}/ReactNativeContainerAdapter.d.ts +0 -0
  261. /package/dist/types/{container → client/container}/SomaContainerAdapter.d.ts +0 -0
  262. /package/dist/types/{diagnostics → client/diagnostics}/SomaDiagnostics.d.ts +0 -0
  263. /package/dist/types/{diagnostics → client/diagnostics}/SomaTelemetry.d.ts +0 -0
  264. /package/dist/types/{diagnostics → client/diagnostics}/telemetry-context.d.ts +0 -0
  265. /package/dist/types/{engine → client/engine}/asset-resolver.d.ts +0 -0
  266. /package/dist/types/{engine → client/engine}/lis.d.ts +0 -0
  267. /package/dist/types/{engine → client/engine}/reactive-proxy.d.ts +0 -0
  268. /package/dist/types/{host → client/host-bridge}/resolve-host-bootstrap.d.ts +0 -0
  269. /package/dist/types/{host → client/host-bridge}/soma-bootstrap-host.stub.d.ts +0 -0
  270. /package/dist/types/{infra → client/infra}/auth/IAuthService.d.ts +0 -0
  271. /package/dist/types/{infra → client/infra}/auth/TokenAuthService.d.ts +0 -0
  272. /package/dist/types/{infra → client/infra}/cache/ICache.d.ts +0 -0
  273. /package/dist/types/{infra → client/infra}/cache/MemoryCache.d.ts +0 -0
  274. /package/dist/types/{infra → client/infra}/config/IConfig.d.ts +0 -0
  275. /package/dist/types/{infra → client/infra}/config/SomaConfig.d.ts +0 -0
  276. /package/dist/types/{infra → client/infra}/event-bus/IEventBus.d.ts +0 -0
  277. /package/dist/types/{infra → client/infra}/event-bus/SomaEventBus.d.ts +0 -0
  278. /package/dist/types/{infra → client/infra}/http/IHttpClient.d.ts +0 -0
  279. /package/dist/types/{infra → client/infra}/i18n/DefaultI18n.d.ts +0 -0
  280. /package/dist/types/{infra → client/infra}/i18n/II18n.d.ts +0 -0
  281. /package/dist/types/{infra → client/infra}/logger/ConsoleLogger.d.ts +0 -0
  282. /package/dist/types/{infra → client/infra}/logger/ILogger.d.ts +0 -0
  283. /package/dist/types/{infra → client/infra}/notify/DefaultNotifyService.d.ts +0 -0
  284. /package/dist/types/{infra → client/infra}/notify/DomNotifyService.d.ts +0 -0
  285. /package/dist/types/{infra → client/infra}/notify/INotifyService.d.ts +0 -0
  286. /package/dist/types/{infra → client/infra}/notify/INotifyTheme.d.ts +0 -0
  287. /package/dist/types/{infra → client/infra}/permission/IPermission.d.ts +0 -0
  288. /package/dist/types/{infra → client/infra}/permission/SomaPermission.d.ts +0 -0
  289. /package/dist/types/{infra → client/infra}/realtime/IRealtimeService.d.ts +0 -0
  290. /package/dist/types/{infra → client/infra}/realtime/IRealtimeTransport.d.ts +0 -0
  291. /package/dist/types/{infra → client/infra}/realtime/SomaRealtimeService.d.ts +0 -0
  292. /package/dist/types/{infra → client/infra}/realtime/SseRealtimeTransport.d.ts +0 -0
  293. /package/dist/types/{infra → client/infra}/realtime/WebSocketRealtimeTransport.d.ts +0 -0
  294. /package/dist/types/{infra → client/infra}/router/IRouter.d.ts +0 -0
  295. /package/dist/types/{infra → client/infra}/router/SomaRouter.d.ts +0 -0
  296. /package/dist/types/{infra → client/infra}/router/router-path.d.ts +0 -0
  297. /package/dist/types/{infra → client/infra}/storage/IStorageService.d.ts +0 -0
  298. /package/dist/types/{infra → client/infra}/storage/MemoryStorageService.d.ts +0 -0
  299. /package/dist/types/{infra → client/infra}/storage/SessionStorageService.d.ts +0 -0
  300. /package/dist/types/{infra → client/infra}/timer/ITimer.d.ts +0 -0
  301. /package/dist/types/{infra → client/infra}/timer/SomaTimer.d.ts +0 -0
  302. /package/dist/types/{middleware → client/middleware}/SomaMiddlewareChain.d.ts +0 -0
  303. /package/dist/types/{middleware → client/middleware}/createPermissionMiddleware.d.ts +0 -0
  304. /package/dist/types/{parser → client/parser}/yaml-loader.d.ts +0 -0
  305. /package/dist/types/{quality → client/quality}/SomaQualityRegistry.d.ts +0 -0
  306. /package/dist/types/{runtime → client/runtime}/SomaRuntimeServices.d.ts +0 -0
  307. /package/dist/types/{runtime → client/runtime}/SomaSnapshotStore.d.ts +0 -0
  308. /package/dist/types/{api → server/api}/load-host-service.d.ts +0 -0
  309. /package/dist/types/{api → server/api}/service-path.d.ts +0 -0
  310. /package/dist/types/{host → server/host}/app-config.stub.d.ts +0 -0
  311. /package/dist/types/{host → server/host}/locale.stub.d.ts +0 -0
  312. /package/dist/types/{infra → server/infra}/cache/ServerFileCache.d.ts +0 -0
  313. /package/dist/types/{manifest → shared/manifest}/manifest-contract.d.ts +0 -0
  314. /package/dist/types/{types → shared/types}/engine.types.d.ts +0 -0
  315. /package/dist/types/{types → shared/types}/event.types.d.ts +0 -0
  316. /package/dist/types/{types → shared/types}/keyboard.types.d.ts +0 -0
  317. /package/dist/types/{types → shared/types}/manifest.types.d.ts +0 -0
  318. /package/dist/types/{types → shared/types}/scheduler.types.d.ts +0 -0
  319. /package/dist/types/{types → shared/types}/style-config.types.d.ts +0 -0
  320. /package/dist/types/{types → shared/types}/timer.types.d.ts +0 -0
  321. /package/dist/types/{types → shared/types}/trigger.types.d.ts +0 -0
  322. /package/dist/types/{types → shared/types}/ui-config.types.d.ts +0 -0
  323. /package/dist/types/{types → shared/types}/watcher.types.d.ts +0 -0
@@ -0,0 +1,1310 @@
1
+ import Ajv2020 from 'ajv/dist/2020.js';
2
+ import { isIP } from 'node:net';
3
+
4
+ const DEFAULT_ARRAY_LENGTH = 2;
5
+ const MAX_GENERATED_COLLECTION_SIZE = 100;
6
+ const MAX_SCHEMA_DEPTH = 32;
7
+ const JSON_SCHEMA_2020_12_URI = 'https://json-schema.org/draft/2020-12/schema';
8
+ const SUPPORTED_STRING_FORMATS = new Set([
9
+ 'date',
10
+ 'date-time',
11
+ 'email',
12
+ 'hostname',
13
+ 'ipv4',
14
+ 'ipv6',
15
+ 'time',
16
+ 'uri',
17
+ 'uri-reference',
18
+ 'url',
19
+ 'uuid',
20
+ ]);
21
+ const SINGLE_SCHEMA_KEYWORDS = new Set([
22
+ 'additionalProperties',
23
+ 'contains',
24
+ 'contentSchema',
25
+ 'else',
26
+ 'if',
27
+ 'items',
28
+ 'not',
29
+ 'propertyNames',
30
+ 'then',
31
+ 'unevaluatedItems',
32
+ 'unevaluatedProperties',
33
+ ]);
34
+ const SCHEMA_ARRAY_KEYWORDS = new Set(['allOf', 'anyOf', 'oneOf', 'prefixItems']);
35
+ const SCHEMA_MAP_KEYWORDS = new Set([
36
+ '$defs',
37
+ 'dependentSchemas',
38
+ 'patternProperties',
39
+ 'properties',
40
+ ]);
41
+ const ANNOTATION_ONLY_KEYWORDS = new Set([
42
+ '$comment',
43
+ '$defs',
44
+ '$id',
45
+ '$schema',
46
+ 'deprecated',
47
+ 'description',
48
+ 'readOnly',
49
+ 'title',
50
+ 'writeOnly',
51
+ ]);
52
+ const UNSUPPORTED_CONSTRAINT_KEYWORDS = new Set([
53
+ '$dynamicRef',
54
+ '$recursiveRef',
55
+ 'additionalItems',
56
+ 'contains',
57
+ 'contentEncoding',
58
+ 'contentMediaType',
59
+ 'contentSchema',
60
+ 'dependentRequired',
61
+ 'dependentSchemas',
62
+ 'dependencies',
63
+ 'definitions',
64
+ 'if',
65
+ 'maxContains',
66
+ 'minContains',
67
+ 'not',
68
+ 'pattern',
69
+ 'patternProperties',
70
+ 'propertyNames',
71
+ 'then',
72
+ 'else',
73
+ 'unevaluatedItems',
74
+ 'unevaluatedProperties',
75
+ 'uniqueItems',
76
+ ]);
77
+
78
+ const schemaMetaValidator = new Ajv2020({
79
+ allErrors: true,
80
+ strict: false,
81
+ validateFormats: false,
82
+ });
83
+ function schemaTypeError(code, message, options) {
84
+ const error = new TypeError(message, options);
85
+ error.code = code;
86
+ return error;
87
+ }
88
+
89
+ function cloneJsonValue(value) {
90
+ if (value === undefined) return undefined;
91
+ return structuredClone(value);
92
+ }
93
+
94
+ export function stableSerialize(value) {
95
+ const seen = new WeakSet();
96
+
97
+ function serialize(current) {
98
+ if (current === null) return 'null';
99
+ if (current === undefined) return 'undefined';
100
+ if (typeof current === 'number' && !Number.isFinite(current)) return JSON.stringify(String(current));
101
+ if (typeof current !== 'object') return JSON.stringify(current);
102
+ if (seen.has(current)) throw new TypeError('Cannot create a deterministic seed from a circular value');
103
+
104
+ seen.add(current);
105
+ const result = Array.isArray(current)
106
+ ? `[${current.map((item) => serialize(item)).join(',')}]`
107
+ : `{${Object.keys(current).sort().map((key) => `${JSON.stringify(key)}:${serialize(current[key])}`).join(',')}}`;
108
+ seen.delete(current);
109
+ return result;
110
+ }
111
+
112
+ return serialize(value);
113
+ }
114
+
115
+ export function hashSeed(value) {
116
+ const input = String(value);
117
+ let hash = 0x811c9dc5;
118
+ for (let index = 0; index < input.length; index += 1) {
119
+ hash ^= input.charCodeAt(index);
120
+ hash = Math.imul(hash, 0x01000193);
121
+ }
122
+ return hash >>> 0;
123
+ }
124
+
125
+ function randomUnit(seed, pathValue) {
126
+ return hashSeed(`${seed}\u0000${pathValue}`) / 0x100000000;
127
+ }
128
+
129
+ function choose(values, seed, pathValue) {
130
+ if (!Array.isArray(values) || values.length === 0) return undefined;
131
+ return values[Math.floor(randomUnit(seed, pathValue) * values.length) % values.length];
132
+ }
133
+
134
+ function decodePointerPart(part) {
135
+ return part.replace(/~1/g, '/').replace(/~0/g, '~');
136
+ }
137
+
138
+ function resolveLocalReference(rootSchema, reference) {
139
+ if (reference === '#') return rootSchema;
140
+ if (!reference.startsWith('#/')) {
141
+ throw schemaTypeError(
142
+ 'SCHEMA_REFERENCE_INVALID',
143
+ `Only local JSON Schema references are supported: ${reference}`,
144
+ );
145
+ }
146
+ let current = rootSchema;
147
+ for (const rawPart of reference.slice(2).split('/')) {
148
+ const part = decodePointerPart(rawPart);
149
+ if (
150
+ !current
151
+ || typeof current !== 'object'
152
+ || !Object.prototype.hasOwnProperty.call(current, part)
153
+ ) {
154
+ throw schemaTypeError(
155
+ 'SCHEMA_REFERENCE_INVALID',
156
+ `JSON Schema reference does not exist: ${reference}`,
157
+ );
158
+ }
159
+ current = current[part];
160
+ }
161
+ return current;
162
+ }
163
+
164
+ function assertSupportedSchemaKeywords(schema, pathValue) {
165
+ if (
166
+ Object.prototype.hasOwnProperty.call(schema, '$schema')
167
+ && typeof schema.$schema !== 'string'
168
+ ) {
169
+ throw schemaTypeError(
170
+ 'SCHEMA_INVALID',
171
+ `JSON Schema $schema must be a string at ${pathValue}`,
172
+ );
173
+ }
174
+ if (
175
+ Object.prototype.hasOwnProperty.call(schema, '$schema')
176
+ && !/^https:\/\/json-schema\.org\/draft\/2020-12\/schema#?$/u.test(schema.$schema)
177
+ ) {
178
+ const error = new TypeError(`Unsupported JSON Schema dialect ${JSON.stringify(schema.$schema)} at ${pathValue}`);
179
+ error.code = 'SCHEMA_DIALECT_UNSUPPORTED';
180
+ throw error;
181
+ }
182
+ if (Array.isArray(schema.items)) {
183
+ const error = new TypeError(`Unsupported JSON Schema keyword "items" (array form) at ${pathValue}`);
184
+ error.code = 'SCHEMA_KEYWORD_UNSUPPORTED';
185
+ throw error;
186
+ }
187
+ for (const keyword of UNSUPPORTED_CONSTRAINT_KEYWORDS) {
188
+ if (!Object.prototype.hasOwnProperty.call(schema, keyword)) continue;
189
+ if (keyword === 'uniqueItems' && schema[keyword] === false) continue;
190
+ const error = new TypeError(`Unsupported JSON Schema keyword ${JSON.stringify(keyword)} at ${pathValue}`);
191
+ error.code = 'SCHEMA_KEYWORD_UNSUPPORTED';
192
+ throw error;
193
+ }
194
+ }
195
+
196
+ function metaValidationMessage(errors) {
197
+ if (!Array.isArray(errors) || errors.length === 0) return 'unknown meta-schema violation';
198
+ return errors.map((entry) => {
199
+ const location = entry.instancePath ? `$${entry.instancePath}` : '$';
200
+ return `${location} ${entry.message || `failed ${entry.keyword}`}`;
201
+ }).join('; ');
202
+ }
203
+
204
+ function assertSchemaTreeSupported(schema, pathValue, visited = new WeakSet()) {
205
+ if (typeof schema === 'boolean') return;
206
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema)) {
207
+ throw schemaTypeError(
208
+ 'SCHEMA_INVALID',
209
+ `JSON Schema subschema must be an object or boolean at ${pathValue}`,
210
+ );
211
+ }
212
+ if (visited.has(schema)) return;
213
+ visited.add(schema);
214
+
215
+ assertSupportedSchemaKeywords(schema, pathValue);
216
+ if (schema.format !== undefined && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
217
+ throw schemaTypeError(
218
+ 'SCHEMA_FORMAT_UNSUPPORTED',
219
+ `Unsupported JSON Schema format ${JSON.stringify(schema.format)} at ${pathValue}`,
220
+ );
221
+ }
222
+
223
+ for (const [keyword, value] of Object.entries(schema)) {
224
+ if (SINGLE_SCHEMA_KEYWORDS.has(keyword)) {
225
+ assertSchemaTreeSupported(value, `${pathValue}.${keyword}`, visited);
226
+ continue;
227
+ }
228
+ if (SCHEMA_ARRAY_KEYWORDS.has(keyword)) {
229
+ for (let index = 0; index < value.length; index += 1) {
230
+ assertSchemaTreeSupported(value[index], `${pathValue}.${keyword}[${index}]`, visited);
231
+ }
232
+ continue;
233
+ }
234
+ if (SCHEMA_MAP_KEYWORDS.has(keyword)) {
235
+ for (const [name, childSchema] of Object.entries(value)) {
236
+ assertSchemaTreeSupported(childSchema, `${pathValue}.${keyword}.${name}`, visited);
237
+ }
238
+ }
239
+ }
240
+ }
241
+
242
+ function assertValidSchemaDocument(schema, pathValue) {
243
+ if (typeof schema !== 'boolean' && (!schema || typeof schema !== 'object' || Array.isArray(schema))) {
244
+ throw schemaTypeError(
245
+ 'SCHEMA_INVALID',
246
+ `JSON Schema must be an object or boolean at ${pathValue}`,
247
+ );
248
+ }
249
+
250
+ // Preserve the existing, more specific dialect error before asking Ajv to
251
+ // select a meta-schema.
252
+ if (schema && typeof schema === 'object') assertSupportedSchemaKeywords(schema, pathValue);
253
+
254
+ let valid;
255
+ try {
256
+ valid = schemaMetaValidator.validateSchema(schema);
257
+ } catch (cause) {
258
+ throw schemaTypeError(
259
+ 'SCHEMA_INVALID',
260
+ `Invalid JSON Schema 2020-12 at ${pathValue}: ${cause instanceof Error ? cause.message : String(cause)}`,
261
+ { cause },
262
+ );
263
+ }
264
+ if (!valid) {
265
+ throw schemaTypeError(
266
+ 'SCHEMA_INVALID',
267
+ `Invalid JSON Schema 2020-12 at ${pathValue}: ${metaValidationMessage(schemaMetaValidator.errors)}`,
268
+ );
269
+ }
270
+ assertSchemaTreeSupported(schema, pathValue);
271
+ }
272
+
273
+ function valueMatchesType(value, type) {
274
+ switch (type) {
275
+ case 'null': return value === null;
276
+ case 'boolean': return typeof value === 'boolean';
277
+ case 'integer': return typeof value === 'number' && Number.isInteger(value);
278
+ case 'number': return typeof value === 'number' && Number.isFinite(value);
279
+ case 'string': return typeof value === 'string';
280
+ case 'array': return Array.isArray(value);
281
+ case 'object': return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
282
+ default: return false;
283
+ }
284
+ }
285
+
286
+ function valueMatchesFormat(value, format) {
287
+ if (typeof value !== 'string' || !format) return true;
288
+ const validDate = (dateValue) => {
289
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/u.exec(dateValue);
290
+ if (!match) return false;
291
+ const year = Number(match[1]);
292
+ const month = Number(match[2]);
293
+ const day = Number(match[3]);
294
+ const date = new Date(0);
295
+ date.setUTCHours(0, 0, 0, 0);
296
+ date.setUTCFullYear(year, month - 1, day);
297
+ return date.getUTCFullYear() === year
298
+ && date.getUTCMonth() === month - 1
299
+ && date.getUTCDate() === day;
300
+ };
301
+ switch (format) {
302
+ case 'uuid':
303
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(value);
304
+ case 'date':
305
+ return validDate(value);
306
+ case 'date-time': {
307
+ const match = /^(\d{4}-\d{2}-\d{2})[Tt](?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:[Zz]|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/u.exec(value);
308
+ return Boolean(match && validDate(match[1]));
309
+ }
310
+ case 'time':
311
+ return /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:[Zz]|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/u.test(value);
312
+ case 'email':
313
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/u.test(value);
314
+ case 'uri':
315
+ case 'url':
316
+ case 'uri-reference':
317
+ try {
318
+ return Boolean(new URL(value));
319
+ } catch {
320
+ return false;
321
+ }
322
+ case 'hostname':
323
+ return value.length <= 253 && /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?))*$/iu.test(value);
324
+ case 'ipv4': {
325
+ return isIP(value) === 4;
326
+ }
327
+ case 'ipv6':
328
+ return isIP(value) === 6;
329
+ default:
330
+ return true;
331
+ }
332
+ }
333
+
334
+ function valueMatchesSchema(value, schema, rootSchema, referenceStack = new Set(), pathValue = '$') {
335
+ if (schema === true || schema === undefined) return true;
336
+ if (schema === false || !schema || typeof schema !== 'object' || Array.isArray(schema)) return false;
337
+ assertSupportedSchemaKeywords(schema, pathValue);
338
+
339
+ if (typeof schema.$ref === 'string') {
340
+ if (referenceStack.has(schema.$ref)) return true;
341
+ const target = resolveLocalReference(rootSchema, schema.$ref);
342
+ const siblings = { ...schema };
343
+ delete siblings.$ref;
344
+ const nextStack = new Set(referenceStack).add(schema.$ref);
345
+ if (!valueMatchesSchema(value, target, rootSchema, nextStack, `${pathValue}:ref`)) return false;
346
+ if (!valueMatchesSchema(value, siblings, rootSchema, nextStack, pathValue)) return false;
347
+ }
348
+
349
+ if (Object.prototype.hasOwnProperty.call(schema, 'const') && stableSerialize(value) !== stableSerialize(schema.const)) {
350
+ return false;
351
+ }
352
+ if (Array.isArray(schema.enum) && !schema.enum.some((candidate) => stableSerialize(value) === stableSerialize(candidate))) {
353
+ return false;
354
+ }
355
+ if (schema.type !== undefined) {
356
+ const allowedTypes = Array.isArray(schema.type) ? schema.type : [schema.type];
357
+ if (!allowedTypes.some((type) => valueMatchesType(value, type))) return false;
358
+ }
359
+
360
+ if (Array.isArray(schema.allOf) && !schema.allOf.every((part, index) =>
361
+ valueMatchesSchema(value, part, rootSchema, referenceStack, `${pathValue}:allOf[${index}]`))) {
362
+ return false;
363
+ }
364
+ if (Array.isArray(schema.anyOf) && !schema.anyOf.some((part, index) =>
365
+ valueMatchesSchema(value, part, rootSchema, referenceStack, `${pathValue}:anyOf[${index}]`))) {
366
+ return false;
367
+ }
368
+ if (Array.isArray(schema.oneOf)) {
369
+ const matches = schema.oneOf.filter((part, index) =>
370
+ valueMatchesSchema(value, part, rootSchema, referenceStack, `${pathValue}:oneOf[${index}]`));
371
+ if (matches.length !== 1) return false;
372
+ }
373
+
374
+ if (typeof value === 'number' && Number.isFinite(value)) {
375
+ if (Number.isFinite(schema.minimum) && value < Number(schema.minimum)) return false;
376
+ if (Number.isFinite(schema.maximum) && value > Number(schema.maximum)) return false;
377
+ if (Number.isFinite(schema.exclusiveMinimum) && value <= Number(schema.exclusiveMinimum)) return false;
378
+ if (Number.isFinite(schema.exclusiveMaximum) && value >= Number(schema.exclusiveMaximum)) return false;
379
+ if (Number.isFinite(schema.multipleOf) && schema.multipleOf > 0) {
380
+ const quotient = value / Number(schema.multipleOf);
381
+ if (Math.abs(quotient - Math.round(quotient)) > Number.EPSILON * Math.max(1, Math.abs(quotient))) return false;
382
+ }
383
+ }
384
+
385
+ if (typeof value === 'string') {
386
+ if (Number.isInteger(schema.minLength) && value.length < schema.minLength) return false;
387
+ if (Number.isInteger(schema.maxLength) && value.length > schema.maxLength) return false;
388
+ if (!valueMatchesFormat(value, schema.format)) return false;
389
+ }
390
+
391
+ if (Array.isArray(value)) {
392
+ if (Number.isInteger(schema.minItems) && value.length < schema.minItems) return false;
393
+ if (Number.isInteger(schema.maxItems) && value.length > schema.maxItems) return false;
394
+ const prefixItems = Array.isArray(schema.prefixItems) ? schema.prefixItems : [];
395
+ for (let index = 0; index < value.length; index += 1) {
396
+ const itemSchema = prefixItems[index] ?? schema.items ?? true;
397
+ if (!valueMatchesSchema(value[index], itemSchema, rootSchema, referenceStack, `${pathValue}[${index}]`)) return false;
398
+ }
399
+ }
400
+
401
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
402
+ const keys = Object.keys(value);
403
+ if (Number.isInteger(schema.minProperties) && keys.length < schema.minProperties) return false;
404
+ if (Number.isInteger(schema.maxProperties) && keys.length > schema.maxProperties) return false;
405
+ const required = Array.isArray(schema.required) ? schema.required : [];
406
+ if (required.some((key) => !Object.prototype.hasOwnProperty.call(value, key))) return false;
407
+ const properties = schema.properties && typeof schema.properties === 'object' && !Array.isArray(schema.properties)
408
+ ? schema.properties
409
+ : {};
410
+ for (const key of keys) {
411
+ const propertySchema = Object.prototype.hasOwnProperty.call(properties, key)
412
+ ? properties[key]
413
+ : schema.additionalProperties ?? true;
414
+ if (!valueMatchesSchema(value[key], propertySchema, rootSchema, referenceStack, `${pathValue}.${key}`)) return false;
415
+ }
416
+ }
417
+
418
+ return true;
419
+ }
420
+
421
+ function schemaTypes(schema) {
422
+ if (schema.type === undefined) return null;
423
+ return Array.isArray(schema.type) ? schema.type : [schema.type];
424
+ }
425
+
426
+ function intersectSchemaTypes(leftTypes, rightTypes) {
427
+ const intersection = [];
428
+ for (const left of leftTypes) {
429
+ for (const right of rightTypes) {
430
+ let matched = null;
431
+ if (left === right) matched = left;
432
+ else if (
433
+ (left === 'number' && right === 'integer')
434
+ || (left === 'integer' && right === 'number')
435
+ ) matched = 'integer';
436
+ if (matched && !intersection.includes(matched)) intersection.push(matched);
437
+ }
438
+ }
439
+ return intersection;
440
+ }
441
+
442
+ function decimalPlaces(value) {
443
+ const source = String(value).toLowerCase();
444
+ const [coefficient, exponentSource = '0'] = source.split('e');
445
+ const fractionLength = coefficient.includes('.') ? coefficient.split('.')[1].length : 0;
446
+ return Math.max(0, fractionLength - Number(exponentSource));
447
+ }
448
+
449
+ function greatestCommonDivisor(left, right) {
450
+ let a = Math.abs(left);
451
+ let b = Math.abs(right);
452
+ while (b !== 0) [a, b] = [b, a % b];
453
+ return a;
454
+ }
455
+
456
+ function leastCommonMultipleOfPositiveNumbers(left, right, pathValue) {
457
+ const precision = Math.max(decimalPlaces(left), decimalPlaces(right));
458
+ if (precision > 12) {
459
+ throw new TypeError(`Cannot safely combine high-precision multipleOf constraints at ${pathValue}`);
460
+ }
461
+ const scale = 10 ** precision;
462
+ const leftScaled = Math.round(left * scale);
463
+ const rightScaled = Math.round(right * scale);
464
+ if (
465
+ !Number.isSafeInteger(leftScaled)
466
+ || !Number.isSafeInteger(rightScaled)
467
+ || leftScaled <= 0
468
+ || rightScaled <= 0
469
+ ) {
470
+ throw new TypeError(`Cannot safely combine multipleOf constraints at ${pathValue}`);
471
+ }
472
+ const divisor = greatestCommonDivisor(leftScaled, rightScaled);
473
+ const combinedScaled = (leftScaled / divisor) * rightScaled;
474
+ if (!Number.isSafeInteger(combinedScaled)) {
475
+ throw new TypeError(`Combined multipleOf constraint exceeds safe numeric range at ${pathValue}`);
476
+ }
477
+ return combinedScaled / scale;
478
+ }
479
+
480
+ function mergeNestedSchemas(base, addition, pathValue) {
481
+ if (base === undefined || base === true) return cloneJsonValue(addition);
482
+ if (addition === undefined || addition === true) return cloneJsonValue(base);
483
+ if (base === false || addition === false) return false;
484
+ return mergeSchemaConstraints(base, addition, pathValue);
485
+ }
486
+
487
+ function mergeSchemaConstraints(base, addition, pathValue) {
488
+ if (base === true || base === undefined) return cloneJsonValue(addition);
489
+ if (addition === true || addition === undefined) return cloneJsonValue(base);
490
+ if (base === false || addition === false) return false;
491
+ if (!base || !addition || typeof base !== 'object' || typeof addition !== 'object') {
492
+ throw new TypeError(`Cannot combine JSON Schema constraints at ${pathValue}`);
493
+ }
494
+
495
+ const output = { ...base, ...addition };
496
+ const baseTypes = schemaTypes(base);
497
+ const additionTypes = schemaTypes(addition);
498
+ if (baseTypes && additionTypes) {
499
+ const intersection = intersectSchemaTypes(baseTypes, additionTypes);
500
+ if (intersection.length === 0) throw new TypeError(`JSON Schema type intersection is empty at ${pathValue}`);
501
+ output.type = intersection.length === 1 ? intersection[0] : intersection;
502
+ }
503
+
504
+ for (const key of ['minimum', 'exclusiveMinimum', 'minLength', 'minItems', 'minProperties']) {
505
+ const values = [base[key], addition[key]].filter((value) => Number.isFinite(value));
506
+ if (values.length > 0) output[key] = Math.max(...values);
507
+ }
508
+ for (const key of ['maximum', 'exclusiveMaximum', 'maxLength', 'maxItems', 'maxProperties']) {
509
+ const values = [base[key], addition[key]].filter((value) => Number.isFinite(value));
510
+ if (values.length > 0) output[key] = Math.min(...values);
511
+ }
512
+
513
+ if (base.format && addition.format && base.format !== addition.format) {
514
+ const uriFormats = new Set(['uri', 'url', 'uri-reference']);
515
+ if (uriFormats.has(base.format) && uriFormats.has(addition.format)) output.format = 'uri';
516
+ else throw new TypeError(`JSON Schema formats conflict at ${pathValue}`);
517
+ }
518
+ if (base.multipleOf !== undefined && addition.multipleOf !== undefined && base.multipleOf !== addition.multipleOf) {
519
+ if (
520
+ !Number.isFinite(base.multipleOf)
521
+ || !Number.isFinite(addition.multipleOf)
522
+ || base.multipleOf <= 0
523
+ || addition.multipleOf <= 0
524
+ ) throw new TypeError(`Invalid multipleOf constraint at ${pathValue}`);
525
+ output.multipleOf = leastCommonMultipleOfPositiveNumbers(
526
+ Number(base.multipleOf),
527
+ Number(addition.multipleOf),
528
+ pathValue,
529
+ );
530
+ }
531
+
532
+ if (Object.prototype.hasOwnProperty.call(base, 'const') && Object.prototype.hasOwnProperty.call(addition, 'const')) {
533
+ if (stableSerialize(base.const) !== stableSerialize(addition.const)) {
534
+ throw new TypeError(`JSON Schema const intersection is empty at ${pathValue}`);
535
+ }
536
+ }
537
+ if (Array.isArray(base.enum) && Array.isArray(addition.enum)) {
538
+ output.enum = base.enum.filter((candidate) =>
539
+ addition.enum.some((value) => stableSerialize(candidate) === stableSerialize(value)));
540
+ if (output.enum.length === 0) throw new TypeError(`JSON Schema enum intersection is empty at ${pathValue}`);
541
+ }
542
+
543
+ if (base.properties || addition.properties) {
544
+ const baseProperties = base.properties && typeof base.properties === 'object' ? base.properties : {};
545
+ const additionProperties = addition.properties && typeof addition.properties === 'object' ? addition.properties : {};
546
+ output.properties = {};
547
+ for (const key of new Set([...Object.keys(baseProperties), ...Object.keys(additionProperties)])) {
548
+ const basePropertySchema = Object.prototype.hasOwnProperty.call(baseProperties, key)
549
+ ? baseProperties[key]
550
+ : base.additionalProperties ?? true;
551
+ const additionPropertySchema = Object.prototype.hasOwnProperty.call(additionProperties, key)
552
+ ? additionProperties[key]
553
+ : addition.additionalProperties ?? true;
554
+ output.properties[key] = mergeNestedSchemas(
555
+ basePropertySchema,
556
+ additionPropertySchema,
557
+ `${pathValue}.properties.${key}`,
558
+ );
559
+ }
560
+ }
561
+ if (base.required || addition.required) {
562
+ output.required = [...new Set([...(base.required || []), ...(addition.required || [])])];
563
+ }
564
+ if (base.items !== undefined || addition.items !== undefined) {
565
+ output.items = mergeNestedSchemas(base.items, addition.items, `${pathValue}.items`);
566
+ }
567
+ if (base.additionalProperties !== undefined || addition.additionalProperties !== undefined) {
568
+ output.additionalProperties = mergeNestedSchemas(
569
+ base.additionalProperties,
570
+ addition.additionalProperties,
571
+ `${pathValue}.additionalProperties`,
572
+ );
573
+ }
574
+ if (Array.isArray(base.prefixItems) || Array.isArray(addition.prefixItems)) {
575
+ const length = Math.max(base.prefixItems?.length || 0, addition.prefixItems?.length || 0);
576
+ output.prefixItems = Array.from({ length }, (_, index) => mergeNestedSchemas(
577
+ base.prefixItems?.[index],
578
+ addition.prefixItems?.[index],
579
+ `${pathValue}.prefixItems[${index}]`,
580
+ ));
581
+ }
582
+ if (base.$defs || addition.$defs) output.$defs = { ...(base.$defs || {}), ...(addition.$defs || {}) };
583
+ delete output.$ref;
584
+ delete output.allOf;
585
+ return output;
586
+ }
587
+
588
+ function expandIntersectionSchema(schema, rootSchema, pathValue, referenceStack) {
589
+ if (schema === true || schema === false) return schema;
590
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema)) {
591
+ throw new TypeError(`JSON Schema must be an object or boolean at ${pathValue}`);
592
+ }
593
+ assertSupportedSchemaKeywords(schema, pathValue);
594
+ let expanded = { ...schema };
595
+
596
+ if (typeof expanded.$ref === 'string') {
597
+ if (referenceStack.has(expanded.$ref)) {
598
+ throw new TypeError(`Recursive JSON Schema reference cannot be generated at ${pathValue}: ${expanded.$ref}`);
599
+ }
600
+ const nextStack = new Set(referenceStack).add(expanded.$ref);
601
+ const target = expandIntersectionSchema(
602
+ resolveLocalReference(rootSchema, expanded.$ref),
603
+ rootSchema,
604
+ `${pathValue}:ref`,
605
+ nextStack,
606
+ );
607
+ const siblings = { ...expanded };
608
+ delete siblings.$ref;
609
+ expanded = mergeSchemaConstraints(
610
+ target,
611
+ expandIntersectionSchema(siblings, rootSchema, pathValue, nextStack),
612
+ pathValue,
613
+ );
614
+ }
615
+
616
+ if (Array.isArray(expanded.allOf)) {
617
+ const parts = expanded.allOf;
618
+ const siblings = { ...expanded };
619
+ delete siblings.allOf;
620
+ expanded = expandIntersectionSchema(siblings, rootSchema, pathValue, referenceStack);
621
+ parts.forEach((part, index) => {
622
+ expanded = mergeSchemaConstraints(
623
+ expanded,
624
+ expandIntersectionSchema(part, rootSchema, `${pathValue}:allOf[${index}]`, referenceStack),
625
+ pathValue,
626
+ );
627
+ });
628
+ }
629
+ return expanded;
630
+ }
631
+
632
+ function hasGenerationKeyword(schema) {
633
+ return Object.keys(schema).some((key) => !ANNOTATION_ONLY_KEYWORDS.has(key));
634
+ }
635
+
636
+ function inferType(schema) {
637
+ const declared = Array.isArray(schema.type)
638
+ ? schema.type.find((typeValue) => typeValue !== 'null') || 'null'
639
+ : schema.type;
640
+ if (declared) return declared;
641
+ if (schema.properties || schema.additionalProperties) return 'object';
642
+ if (schema.items || schema.prefixItems) return 'array';
643
+ if (Array.isArray(schema.enum) && schema.enum.length > 0) {
644
+ const sample = schema.enum[0];
645
+ if (sample === null) return 'null';
646
+ if (Array.isArray(sample)) return 'array';
647
+ return typeof sample;
648
+ }
649
+ return 'string';
650
+ }
651
+
652
+ function tokenFor(seed, pathValue, length = 10) {
653
+ let token = '';
654
+ let round = 0;
655
+ while (token.length < length) {
656
+ token += hashSeed(`${seed}:${pathValue}:${round}`).toString(16).padStart(8, '0');
657
+ round += 1;
658
+ }
659
+ return token.slice(0, length);
660
+ }
661
+
662
+ function resolveStringBounds(schema, pathValue) {
663
+ const minLength = Number.isInteger(schema.minLength) && schema.minLength >= 0 ? schema.minLength : 0;
664
+ const maxLength = Number.isInteger(schema.maxLength) && schema.maxLength >= 0
665
+ ? schema.maxLength
666
+ : Number.POSITIVE_INFINITY;
667
+ if (maxLength < minLength) throw new TypeError(`Invalid string bounds at ${pathValue}`);
668
+ return { minLength, maxLength };
669
+ }
670
+
671
+ function fitStringLength(value, schema, seed, pathValue) {
672
+ const { minLength, maxLength } = resolveStringBounds(schema, pathValue);
673
+ let output = String(value);
674
+ while (output.length < minLength) output += tokenFor(seed, `${pathValue}:padding`, minLength - output.length);
675
+ return output.slice(0, maxLength);
676
+ }
677
+
678
+ function fitFormattedString(value, schema, context, pathValue) {
679
+ const { minLength, maxLength } = resolveStringBounds(schema, pathValue);
680
+ if (
681
+ value.length >= minLength
682
+ && value.length <= maxLength
683
+ && valueMatchesFormat(value, schema.format)
684
+ ) return value;
685
+
686
+ const candidates = [];
687
+ if (schema.format === 'email') {
688
+ const targetLength = Math.max(minLength, 5);
689
+ if (targetLength <= maxLength) {
690
+ const localLength = targetLength - 4;
691
+ candidates.push(`${tokenFor(context.seed, `${pathValue}:compact-email`, localLength)}@b.c`);
692
+ }
693
+ }
694
+
695
+ if (['uri', 'url', 'uri-reference'].includes(schema.format)) {
696
+ const targetLength = Math.max(minLength, 3);
697
+ if (targetLength <= maxLength) {
698
+ candidates.push(`x:${tokenFor(context.seed, `${pathValue}:compact-uri`, targetLength - 2)}`);
699
+ }
700
+ }
701
+
702
+ if (schema.format === 'hostname') {
703
+ const targetLength = Math.max(minLength, 1);
704
+ if (targetLength <= Math.min(maxLength, 253)) {
705
+ const labelCount = Math.max(1, Math.ceil((targetLength + 1) / 64));
706
+ const characterCount = targetLength - (labelCount - 1);
707
+ if (characterCount >= labelCount && characterCount <= labelCount * 63) {
708
+ const lengths = Array(labelCount).fill(1);
709
+ let remaining = characterCount - labelCount;
710
+ for (let index = 0; index < lengths.length && remaining > 0; index += 1) {
711
+ const addition = Math.min(62, remaining);
712
+ lengths[index] += addition;
713
+ remaining -= addition;
714
+ }
715
+ candidates.push(lengths.map((length, index) =>
716
+ tokenFor(context.seed, `${pathValue}:hostname:${index}`, length)).join('.'));
717
+ }
718
+ }
719
+ }
720
+
721
+ if (schema.format === 'ipv4') {
722
+ const targetLength = Math.max(minLength, 7);
723
+ if (targetLength <= Math.min(maxLength, 15)) {
724
+ const lengths = [1, 1, 1, 1];
725
+ let remaining = targetLength - 7;
726
+ for (let index = 0; index < lengths.length && remaining > 0; index += 1) {
727
+ const addition = Math.min(2, remaining);
728
+ lengths[index] += addition;
729
+ remaining -= addition;
730
+ }
731
+ candidates.push(lengths.map((length) => '1'.repeat(length)).join('.'));
732
+ }
733
+ }
734
+
735
+ if (schema.format === 'ipv6') candidates.push('::');
736
+ if (schema.format === 'date') candidates.push('2020-01-01');
737
+ if (schema.format === 'date-time') {
738
+ candidates.push('2020-01-01T00:00:00Z');
739
+ for (let digits = 1; digits <= 32; digits += 1) {
740
+ candidates.push(`2020-01-01T00:00:00.${'0'.repeat(digits)}Z`);
741
+ }
742
+ }
743
+ if (schema.format === 'time') {
744
+ candidates.push('00:00:00Z');
745
+ for (let digits = 1; digits <= 32; digits += 1) {
746
+ candidates.push(`00:00:00.${'0'.repeat(digits)}Z`);
747
+ }
748
+ }
749
+
750
+ for (const candidate of candidates) {
751
+ if (
752
+ candidate.length >= minLength
753
+ && candidate.length <= maxLength
754
+ && valueMatchesFormat(candidate, schema.format)
755
+ ) return candidate;
756
+ }
757
+
758
+ const fitted = fitStringLength(value, schema, context.seed, pathValue);
759
+ if (valueMatchesFormat(fitted, schema.format)) return fitted;
760
+ throw new TypeError(`Cannot satisfy string format and length constraints at ${pathValue}`);
761
+ }
762
+
763
+ function generateString(schema, context, pathValue) {
764
+ const token = tokenFor(context.seed, pathValue, 16);
765
+ const fieldName = pathValue.split('.').at(-1)?.replace(/\[\d+\]$/, '').toLowerCase() || 'value';
766
+ let value;
767
+
768
+ switch (schema.format) {
769
+ case 'uuid': {
770
+ const hex = tokenFor(context.seed, `${pathValue}:uuid`, 32);
771
+ value = `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-a${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
772
+ break;
773
+ }
774
+ case 'date': {
775
+ const dayOffset = hashSeed(`${context.seed}:${pathValue}:date`) % 3650;
776
+ value = new Date(Date.UTC(2020, 0, 1 + dayOffset)).toISOString().slice(0, 10);
777
+ break;
778
+ }
779
+ case 'date-time': {
780
+ const secondOffset = hashSeed(`${context.seed}:${pathValue}:date-time`) % (3650 * 24 * 60 * 60);
781
+ value = new Date(Date.UTC(2020, 0, 1) + secondOffset * 1000).toISOString();
782
+ break;
783
+ }
784
+ case 'time': {
785
+ const seconds = hashSeed(`${context.seed}:${pathValue}:time`) % 86400;
786
+ value = `${String(Math.floor(seconds / 3600)).padStart(2, '0')}:${String(Math.floor((seconds % 3600) / 60)).padStart(2, '0')}:${String(seconds % 60).padStart(2, '0')}Z`;
787
+ break;
788
+ }
789
+ case 'email':
790
+ value = `mock-${token.slice(0, 8)}@example.test`;
791
+ break;
792
+ case 'uri':
793
+ case 'url':
794
+ case 'uri-reference':
795
+ value = `https://mock.example.test/${token.slice(0, 10)}`;
796
+ break;
797
+ case 'hostname':
798
+ value = `mock-${token.slice(0, 8)}.example.test`;
799
+ break;
800
+ case 'ipv4':
801
+ value = `192.0.2.${1 + (hashSeed(`${context.seed}:${pathValue}:ipv4`) % 254)}`;
802
+ break;
803
+ case 'ipv6':
804
+ value = `2001:db8::${token.slice(0, 4)}`;
805
+ break;
806
+ default:
807
+ if (fieldName === 'id' || fieldName.endsWith('id')) value = `mock-${token.slice(0, 12)}`;
808
+ else if (fieldName.includes('email')) value = `mock-${token.slice(0, 8)}@example.test`;
809
+ else if (fieldName.includes('url') || fieldName.includes('uri')) value = `https://mock.example.test/${token.slice(0, 10)}`;
810
+ else if (fieldName.includes('status')) value = 'MOCKED';
811
+ else if (fieldName.includes('code')) value = `MOCK_${token.slice(0, 8).toUpperCase()}`;
812
+ else if (fieldName.includes('name')) value = `Mock ${token.slice(0, 8)}`;
813
+ else if (fieldName.includes('message') || fieldName.includes('description')) value = `Mock data ${token.slice(0, 8)}`;
814
+ else value = `mock-${token.slice(0, 12)}`;
815
+ }
816
+
817
+ return schema.format
818
+ ? fitFormattedString(value, schema, context, pathValue)
819
+ : fitStringLength(value, schema, context.seed, pathValue);
820
+ }
821
+
822
+ function nextRepresentableNumber(value, direction) {
823
+ if (!Number.isFinite(value)) return value;
824
+ if (value === 0) return direction > 0 ? Number.MIN_VALUE : -Number.MIN_VALUE;
825
+ const buffer = new ArrayBuffer(8);
826
+ const view = new DataView(buffer);
827
+ view.setFloat64(0, value, false);
828
+ let bits = view.getBigUint64(0, false);
829
+ if ((value > 0) === (direction > 0)) bits += 1n;
830
+ else bits -= 1n;
831
+ view.setBigUint64(0, bits, false);
832
+ return view.getFloat64(0, false);
833
+ }
834
+
835
+ function generateNumber(schema, context, pathValue, integer) {
836
+ let minimum = null;
837
+ let minimumExclusive = false;
838
+ if (Number.isFinite(schema.minimum)) minimum = Number(schema.minimum);
839
+ if (Number.isFinite(schema.exclusiveMinimum)) {
840
+ const candidate = Number(schema.exclusiveMinimum);
841
+ if (minimum === null || candidate > minimum || candidate === minimum) {
842
+ minimum = candidate;
843
+ minimumExclusive = true;
844
+ }
845
+ }
846
+ let maximum = null;
847
+ let maximumExclusive = false;
848
+ if (Number.isFinite(schema.maximum)) maximum = Number(schema.maximum);
849
+ if (Number.isFinite(schema.exclusiveMaximum)) {
850
+ const candidate = Number(schema.exclusiveMaximum);
851
+ if (maximum === null || candidate < maximum || candidate === maximum) {
852
+ maximum = candidate;
853
+ maximumExclusive = true;
854
+ }
855
+ }
856
+ if (minimum === null && maximum === null) {
857
+ minimum = 0;
858
+ maximum = 1000;
859
+ } else if (minimum === null) {
860
+ const candidate = maximum - 1000;
861
+ minimum = Number.isFinite(candidate) && candidate < maximum
862
+ ? candidate
863
+ : (maximumExclusive ? nextRepresentableNumber(maximum, -1) : maximum);
864
+ } else if (maximum === null) {
865
+ const candidate = minimum + 1000;
866
+ maximum = Number.isFinite(candidate) && candidate > minimum
867
+ ? candidate
868
+ : (minimumExclusive ? nextRepresentableNumber(minimum, 1) : minimum);
869
+ }
870
+
871
+ if (integer) {
872
+ minimum = minimumExclusive ? Math.floor(minimum) + 1 : Math.ceil(minimum);
873
+ maximum = maximumExclusive ? Math.ceil(maximum) - 1 : Math.floor(maximum);
874
+ minimumExclusive = false;
875
+ maximumExclusive = false;
876
+ }
877
+ if (maximum < minimum || (maximum === minimum && (minimumExclusive || maximumExclusive))) {
878
+ throw new TypeError(`Invalid numeric bounds at ${pathValue}`);
879
+ }
880
+
881
+ if (Number.isFinite(schema.multipleOf) && schema.multipleOf > 0) {
882
+ const multiple = Number(schema.multipleOf);
883
+ if (integer) {
884
+ const count = maximum - minimum + 1;
885
+ const start = Math.floor(randomUnit(context.seed, pathValue) * count);
886
+ for (let offset = 0; offset < Math.min(count, 10000); offset += 1) {
887
+ const candidate = minimum + ((start + offset) % count);
888
+ const quotient = candidate / multiple;
889
+ if (Math.abs(quotient - Math.round(quotient)) <= Number.EPSILON * Math.max(1, Math.abs(quotient))) {
890
+ return candidate;
891
+ }
892
+ }
893
+ throw new TypeError(`No integer multipleOf value satisfies bounds at ${pathValue}`);
894
+ }
895
+ const firstFactor = minimumExclusive
896
+ ? Math.floor(minimum / multiple) + 1
897
+ : Math.ceil(minimum / multiple);
898
+ const lastFactor = maximumExclusive
899
+ ? Math.ceil(maximum / multiple) - 1
900
+ : Math.floor(maximum / multiple);
901
+ if (lastFactor < firstFactor) {
902
+ throw new TypeError(`No multipleOf value satisfies bounds at ${pathValue}`);
903
+ }
904
+ const factorCount = lastFactor - firstFactor + 1;
905
+ const factor = firstFactor + Math.floor(randomUnit(context.seed, pathValue) * factorCount);
906
+ return factor * multiple;
907
+ }
908
+
909
+ if (integer) {
910
+ return minimum + Math.floor(randomUnit(context.seed, pathValue) * (maximum - minimum + 1));
911
+ }
912
+ let value = minimum + randomUnit(context.seed, pathValue) * (maximum - minimum);
913
+ if (minimumExclusive && value <= minimum) value = nextRepresentableNumber(minimum, 1);
914
+ if (maximumExclusive && value >= maximum) value = nextRepresentableNumber(maximum, -1);
915
+ if (value < minimum || value > maximum || (minimumExclusive && value === minimum) || (maximumExclusive && value === maximum)) {
916
+ throw new TypeError(`No representable number satisfies bounds at ${pathValue}`);
917
+ }
918
+ return value;
919
+ }
920
+
921
+ function collectionBounds(schema, minimumKey, maximumKey) {
922
+ const minimum = Number.isInteger(schema[minimumKey]) && schema[minimumKey] >= 0 ? schema[minimumKey] : 0;
923
+ const maximum = Number.isInteger(schema[maximumKey]) && schema[maximumKey] >= 0
924
+ ? schema[maximumKey]
925
+ : MAX_GENERATED_COLLECTION_SIZE;
926
+ if (minimum > MAX_GENERATED_COLLECTION_SIZE) {
927
+ throw new TypeError(`${minimumKey} exceeds safe generation limit ${MAX_GENERATED_COLLECTION_SIZE}`);
928
+ }
929
+ if (maximum < minimum) throw new TypeError(`Invalid collection bounds: ${minimumKey}/${maximumKey}`);
930
+ return {
931
+ minimum,
932
+ maximum: Math.min(maximum, MAX_GENERATED_COLLECTION_SIZE),
933
+ };
934
+ }
935
+
936
+ function boundedCollectionSize(schema, minimumKey, maximumKey, fallback) {
937
+ const bounds = collectionBounds(schema, minimumKey, maximumKey);
938
+ return Math.min(bounds.maximum, Math.max(bounds.minimum, fallback));
939
+ }
940
+
941
+ function requiredPropertyNames(schema, pathValue) {
942
+ if (schema.required === undefined) return [];
943
+ if (!Array.isArray(schema.required) || schema.required.some((value) => typeof value !== 'string')) {
944
+ throw new TypeError(`JSON Schema required must be an array of strings at ${pathValue}`);
945
+ }
946
+ return [...new Set(schema.required)];
947
+ }
948
+
949
+ function setGeneratedProperty(output, key, value) {
950
+ Object.defineProperty(output, key, {
951
+ configurable: true,
952
+ enumerable: true,
953
+ value,
954
+ writable: true,
955
+ });
956
+ }
957
+
958
+ const NO_SCHEMA_MISMATCH = Symbol('NO_SCHEMA_MISMATCH');
959
+
960
+ function createSchemaMismatchValue(schema, context, pathValue, referenceStack) {
961
+ const candidates = [
962
+ null,
963
+ false,
964
+ true,
965
+ 0,
966
+ 1,
967
+ '',
968
+ `mismatch-${tokenFor(context.seed, pathValue, 8)}`,
969
+ [],
970
+ {},
971
+ ];
972
+ for (const candidate of candidates) {
973
+ if (!valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue)) {
974
+ return cloneJsonValue(candidate);
975
+ }
976
+ }
977
+ return NO_SCHEMA_MISMATCH;
978
+ }
979
+
980
+ function createCompositionEdgeCandidates(schema, context, pathValue, referenceStack, depth) {
981
+ let expanded;
982
+ try {
983
+ expanded = expandIntersectionSchema(schema, context.rootSchema, pathValue, referenceStack);
984
+ } catch (error) {
985
+ if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
986
+ return [];
987
+ }
988
+ if (!expanded || typeof expanded !== 'object' || Array.isArray(expanded)) return [];
989
+ if (Object.prototype.hasOwnProperty.call(expanded, 'const')) return [cloneJsonValue(expanded.const)];
990
+ if (Array.isArray(expanded.enum)) return expanded.enum.map((value) => cloneJsonValue(value));
991
+
992
+ const type = inferType(expanded);
993
+ if (type === 'array') {
994
+ const lengths = new Set([
995
+ Number.isInteger(expanded.minItems) && expanded.minItems >= 0 ? expanded.minItems : 0,
996
+ ]);
997
+ if (Number.isInteger(expanded.maxItems) && expanded.maxItems >= 0) lengths.add(expanded.maxItems);
998
+ const candidates = [];
999
+ for (const length of lengths) {
1000
+ try {
1001
+ candidates.push(generateInternal(
1002
+ { ...expanded, minItems: length, maxItems: length },
1003
+ context,
1004
+ `${pathValue}:length-${length}`,
1005
+ depth + 1,
1006
+ referenceStack,
1007
+ ));
1008
+ } catch (error) {
1009
+ if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
1010
+ }
1011
+ }
1012
+ return candidates;
1013
+ }
1014
+ if (type === 'string') {
1015
+ const lengths = new Set();
1016
+ if (Number.isInteger(expanded.minLength) && expanded.minLength >= 0) lengths.add(expanded.minLength);
1017
+ if (Number.isInteger(expanded.maxLength) && expanded.maxLength >= 0) lengths.add(expanded.maxLength);
1018
+ const candidates = [];
1019
+ for (const length of lengths) {
1020
+ try {
1021
+ candidates.push(generateInternal(
1022
+ { ...expanded, minLength: length, maxLength: length },
1023
+ context,
1024
+ `${pathValue}:length-${length}`,
1025
+ depth + 1,
1026
+ referenceStack,
1027
+ ));
1028
+ } catch (error) {
1029
+ if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
1030
+ }
1031
+ }
1032
+ return candidates;
1033
+ }
1034
+ if (type !== 'integer' && type !== 'number') return [];
1035
+ const integer = type === 'integer';
1036
+ const candidates = [];
1037
+ if (Number.isFinite(expanded.minimum)) {
1038
+ candidates.push(integer ? Math.ceil(expanded.minimum) : Number(expanded.minimum));
1039
+ }
1040
+ if (Number.isFinite(expanded.exclusiveMinimum)) {
1041
+ candidates.push(integer
1042
+ ? Math.floor(expanded.exclusiveMinimum) + 1
1043
+ : nextRepresentableNumber(Number(expanded.exclusiveMinimum), 1));
1044
+ }
1045
+ if (Number.isFinite(expanded.maximum)) {
1046
+ candidates.push(integer ? Math.floor(expanded.maximum) : Number(expanded.maximum));
1047
+ }
1048
+ if (Number.isFinite(expanded.exclusiveMaximum)) {
1049
+ candidates.push(integer
1050
+ ? Math.ceil(expanded.exclusiveMaximum) - 1
1051
+ : nextRepresentableNumber(Number(expanded.exclusiveMaximum), -1));
1052
+ }
1053
+ return candidates.filter((candidate) =>
1054
+ valueMatchesSchema(candidate, expanded, context.rootSchema, referenceStack, pathValue));
1055
+ }
1056
+
1057
+ function generateInternal(schema, context, pathValue, depth, referenceStack) {
1058
+ if (schema === true || schema === undefined) return generateString({}, context, pathValue);
1059
+ if (schema === false) throw new TypeError(`Cannot generate data from a false JSON Schema at ${pathValue}`);
1060
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema)) {
1061
+ throw new TypeError(`JSON Schema must be an object or boolean at ${pathValue}`);
1062
+ }
1063
+ if (depth > MAX_SCHEMA_DEPTH) throw new TypeError(`JSON Schema exceeds maximum depth at ${pathValue}`);
1064
+ assertSupportedSchemaKeywords(schema, pathValue);
1065
+
1066
+ if (typeof schema.$ref === 'string' || Array.isArray(schema.allOf)) {
1067
+ const expanded = expandIntersectionSchema(schema, context.rootSchema, pathValue, referenceStack);
1068
+ const nextReferenceStack = typeof schema.$ref === 'string'
1069
+ ? new Set(referenceStack).add(schema.$ref)
1070
+ : referenceStack;
1071
+ return generateInternal(expanded, context, pathValue, depth + 1, nextReferenceStack);
1072
+ }
1073
+
1074
+ if (Object.prototype.hasOwnProperty.call(schema, 'const')) {
1075
+ const candidate = cloneJsonValue(schema.const);
1076
+ if (!valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue)) {
1077
+ throw new TypeError(`JSON Schema const cannot satisfy sibling constraints at ${pathValue}`);
1078
+ }
1079
+ return candidate;
1080
+ }
1081
+ if (Object.prototype.hasOwnProperty.call(schema, 'default')) {
1082
+ const candidate = cloneJsonValue(schema.default);
1083
+ if (valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue)) return candidate;
1084
+ }
1085
+ if (Object.prototype.hasOwnProperty.call(schema, 'example')) {
1086
+ const candidate = cloneJsonValue(schema.example);
1087
+ if (valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue)) return candidate;
1088
+ }
1089
+ if (Array.isArray(schema.examples) && schema.examples.length > 0) {
1090
+ const candidates = schema.examples.filter((candidate) =>
1091
+ valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue));
1092
+ if (candidates.length > 0) {
1093
+ return cloneJsonValue(choose(candidates, context.seed, `${pathValue}:examples`));
1094
+ }
1095
+ }
1096
+ if (Array.isArray(schema.enum) && schema.enum.length > 0) {
1097
+ const candidates = schema.enum.filter((candidate) =>
1098
+ valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue));
1099
+ if (candidates.length === 0) throw new TypeError(`JSON Schema enum cannot satisfy sibling constraints at ${pathValue}`);
1100
+ return cloneJsonValue(choose(candidates, context.seed, `${pathValue}:enum`));
1101
+ }
1102
+
1103
+ for (const keyword of ['oneOf', 'anyOf']) {
1104
+ if (Array.isArray(schema[keyword]) && schema[keyword].length > 0) {
1105
+ const siblings = { ...schema };
1106
+ delete siblings[keyword];
1107
+ const generatedCandidates = [];
1108
+ const branchCandidates = [];
1109
+ for (let index = 0; index < schema[keyword].length; index += 1) {
1110
+ const branch = schema[keyword][index];
1111
+ try {
1112
+ const candidateSchema = hasGenerationKeyword(siblings)
1113
+ ? { allOf: [siblings, branch] }
1114
+ : branch;
1115
+ const candidate = generateInternal(
1116
+ candidateSchema,
1117
+ context,
1118
+ `${pathValue}:${keyword}[${index}]`,
1119
+ depth + 1,
1120
+ referenceStack,
1121
+ );
1122
+ const edgeCandidates = createCompositionEdgeCandidates(
1123
+ candidateSchema,
1124
+ context,
1125
+ `${pathValue}:${keyword}[${index}]:edges`,
1126
+ referenceStack,
1127
+ depth,
1128
+ );
1129
+ const currentBranchCandidates = [candidate, ...edgeCandidates];
1130
+ branchCandidates.push(...currentBranchCandidates);
1131
+ for (const branchCandidate of currentBranchCandidates) {
1132
+ if (valueMatchesSchema(branchCandidate, schema, context.rootSchema, referenceStack, pathValue)) {
1133
+ generatedCandidates.push(branchCandidate);
1134
+ }
1135
+ }
1136
+ } catch (error) {
1137
+ if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
1138
+ }
1139
+ }
1140
+ if (keyword === 'oneOf' && generatedCandidates.length === 0) {
1141
+ for (const candidate of branchCandidates) {
1142
+ if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) continue;
1143
+ for (let index = 0; index < schema.oneOf.length; index += 1) {
1144
+ let expandedBranch;
1145
+ try {
1146
+ expandedBranch = expandIntersectionSchema(
1147
+ schema.oneOf[index],
1148
+ context.rootSchema,
1149
+ `${pathValue}:oneOf[${index}]`,
1150
+ referenceStack,
1151
+ );
1152
+ } catch (error) {
1153
+ if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
1154
+ continue;
1155
+ }
1156
+ const properties = expandedBranch?.properties;
1157
+ if (!properties || typeof properties !== 'object' || Array.isArray(properties)) continue;
1158
+ for (const [key, propertySchema] of Object.entries(properties)) {
1159
+ const mismatch = createSchemaMismatchValue(
1160
+ propertySchema,
1161
+ context,
1162
+ `${pathValue}:oneOf-mismatch.${key}`,
1163
+ referenceStack,
1164
+ );
1165
+ if (mismatch === NO_SCHEMA_MISMATCH) continue;
1166
+ const variant = cloneJsonValue(candidate);
1167
+ setGeneratedProperty(variant, key, mismatch);
1168
+ if (valueMatchesSchema(variant, schema, context.rootSchema, referenceStack, pathValue)) {
1169
+ generatedCandidates.push(variant);
1170
+ }
1171
+ }
1172
+ }
1173
+ }
1174
+ }
1175
+ if (generatedCandidates.length === 0) {
1176
+ throw new TypeError(`No ${keyword} branch can satisfy sibling constraints at ${pathValue}`);
1177
+ }
1178
+ return cloneJsonValue(choose(generatedCandidates, context.seed, `${pathValue}:${keyword}`));
1179
+ }
1180
+ }
1181
+
1182
+ const type = inferType(schema);
1183
+ switch (type) {
1184
+ case 'null':
1185
+ return null;
1186
+ case 'boolean':
1187
+ return randomUnit(context.seed, pathValue) >= 0.5;
1188
+ case 'integer':
1189
+ return generateNumber(schema, context, pathValue, true);
1190
+ case 'number':
1191
+ return generateNumber(schema, context, pathValue, false);
1192
+ case 'array': {
1193
+ const prefixItems = Array.isArray(schema.prefixItems) ? schema.prefixItems : [];
1194
+ const itemSchema = schema.items === false ? null : (schema.items || {});
1195
+ const falsePrefixIndex = prefixItems.findIndex((entry) => entry === false);
1196
+ const maximumGeneratableLength = falsePrefixIndex >= 0
1197
+ ? falsePrefixIndex
1198
+ : (itemSchema ? MAX_GENERATED_COLLECTION_SIZE : prefixItems.length);
1199
+ const fallbackLength = itemSchema
1200
+ ? Math.min(DEFAULT_ARRAY_LENGTH, maximumGeneratableLength)
1201
+ : Math.min(DEFAULT_ARRAY_LENGTH, prefixItems.length);
1202
+ const length = boundedCollectionSize(schema, 'minItems', 'maxItems', fallbackLength);
1203
+ if (!itemSchema && length > prefixItems.length) {
1204
+ throw new TypeError(`Cannot satisfy minItems with items=false at ${pathValue}`);
1205
+ }
1206
+ if (length > maximumGeneratableLength) {
1207
+ throw new TypeError(`Cannot satisfy minItems with a false prefixItems schema at ${pathValue}`);
1208
+ }
1209
+ const output = [];
1210
+ for (let index = 0; index < length; index += 1) {
1211
+ const currentSchema = prefixItems[index] === undefined ? itemSchema : prefixItems[index];
1212
+ if (currentSchema === null) break;
1213
+ output.push(generateInternal(currentSchema, context, `${pathValue}[${index}]`, depth + 1, referenceStack));
1214
+ }
1215
+ return output;
1216
+ }
1217
+ case 'object': {
1218
+ const output = {};
1219
+ const properties = schema.properties && typeof schema.properties === 'object' && !Array.isArray(schema.properties)
1220
+ ? schema.properties
1221
+ : {};
1222
+ const propertyNames = Object.keys(properties).sort();
1223
+ const generatablePropertyNames = propertyNames.filter((key) => properties[key] !== false);
1224
+ const requiredNames = requiredPropertyNames(schema, pathValue);
1225
+ const bounds = collectionBounds(schema, 'minProperties', 'maxProperties');
1226
+ if (requiredNames.length > bounds.maximum) {
1227
+ throw new TypeError(`Required properties exceed maxProperties at ${pathValue}`);
1228
+ }
1229
+
1230
+ const additionalAllowed = schema.additionalProperties !== false;
1231
+ const additionalSchema = schema.additionalProperties && typeof schema.additionalProperties === 'object'
1232
+ ? schema.additionalProperties
1233
+ : { type: 'string' };
1234
+ const targetSize = Math.min(
1235
+ bounds.maximum,
1236
+ Math.max(bounds.minimum, new Set([...generatablePropertyNames, ...requiredNames]).size),
1237
+ );
1238
+
1239
+ for (const key of requiredNames) {
1240
+ const declared = Object.prototype.hasOwnProperty.call(properties, key);
1241
+ if (declared && properties[key] === false) {
1242
+ throw new TypeError(`Required property ${JSON.stringify(key)} has a false schema at ${pathValue}`);
1243
+ }
1244
+ const propertySchema = declared ? properties[key] : additionalAllowed ? additionalSchema : null;
1245
+ if (propertySchema === null) {
1246
+ throw new TypeError(`Required property ${JSON.stringify(key)} is not allowed at ${pathValue}`);
1247
+ }
1248
+ setGeneratedProperty(
1249
+ output,
1250
+ key,
1251
+ generateInternal(propertySchema, context, `${pathValue}.${key}`, depth + 1, referenceStack),
1252
+ );
1253
+ }
1254
+
1255
+ for (const key of generatablePropertyNames) {
1256
+ if (Object.keys(output).length >= targetSize) break;
1257
+ if (Object.prototype.hasOwnProperty.call(output, key)) continue;
1258
+ setGeneratedProperty(
1259
+ output,
1260
+ key,
1261
+ generateInternal(properties[key], context, `${pathValue}.${key}`, depth + 1, referenceStack),
1262
+ );
1263
+ }
1264
+
1265
+ if (Object.keys(output).length < bounds.minimum && !additionalAllowed) {
1266
+ throw new TypeError(`Cannot satisfy minProperties with additionalProperties=false at ${pathValue}`);
1267
+ }
1268
+ let additionalIndex = 1;
1269
+ while (Object.keys(output).length < bounds.minimum) {
1270
+ let key = `additionalField${additionalIndex}`;
1271
+ additionalIndex += 1;
1272
+ while (Object.prototype.hasOwnProperty.call(output, key) || Object.prototype.hasOwnProperty.call(properties, key)) {
1273
+ key = `additionalField${additionalIndex}`;
1274
+ additionalIndex += 1;
1275
+ }
1276
+ setGeneratedProperty(
1277
+ output,
1278
+ key,
1279
+ generateInternal(additionalSchema, context, `${pathValue}.${key}`, depth + 1, referenceStack),
1280
+ );
1281
+ }
1282
+ return output;
1283
+ }
1284
+ case 'string':
1285
+ return generateString(schema, context, pathValue);
1286
+ default:
1287
+ throw new TypeError(`Unsupported JSON Schema type "${type}" at ${pathValue}`);
1288
+ }
1289
+ }
1290
+
1291
+ /**
1292
+ * Generate JSON-compatible mock data from a JSON Schema. The same schema, seed
1293
+ * and path always produce byte-for-byte equivalent data.
1294
+ */
1295
+ export function generateFromSchema(schema, options = {}) {
1296
+ const seed = String(options.seed ?? 'soma-mock');
1297
+ const pathValue = String(options.path ?? '$');
1298
+ assertValidSchemaDocument(schema, pathValue);
1299
+ const value = generateInternal(
1300
+ schema,
1301
+ { seed, rootSchema: schema },
1302
+ pathValue,
1303
+ 0,
1304
+ new Set(),
1305
+ );
1306
+ if (!valueMatchesSchema(value, schema, schema)) {
1307
+ throw new TypeError('Generated value does not satisfy the supported JSON Schema constraints at $');
1308
+ }
1309
+ return value;
1310
+ }