@plures/praxis 0.2.1 → 1.0.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 (486) hide show
  1. package/README.md +191 -64
  2. package/core/codegen/docs-generator.ts +808 -0
  3. package/core/codegen/index.ts +27 -0
  4. package/core/codegen/ts-generator.ts +15 -0
  5. package/core/db-adapter/index.ts +52 -0
  6. package/core/db-adapter/sync-engine.ts +450 -0
  7. package/core/logic-engine/engine.ts +12 -0
  8. package/core/logic-engine/index.ts +16 -0
  9. package/core/logic-engine/protocol.ts +16 -0
  10. package/core/logic-engine/psf-adapter.ts +269 -0
  11. package/core/logic-engine/rules.ts +16 -0
  12. package/core/schema-engine/compiler.ts +431 -0
  13. package/core/schema-engine/generator.ts +635 -0
  14. package/core/schema-engine/index.ts +18 -0
  15. package/core/schema-engine/psf.ts +664 -0
  16. package/core/schema-engine/types.ts +63 -0
  17. package/core/schema-engine/validator.ts +541 -0
  18. package/dist/core/codegen/docs-generator.d.ts +123 -0
  19. package/dist/core/codegen/docs-generator.d.ts.map +1 -0
  20. package/dist/core/codegen/docs-generator.js +674 -0
  21. package/dist/core/codegen/docs-generator.js.map +1 -0
  22. package/dist/core/codegen/index.d.ts +11 -0
  23. package/dist/core/codegen/index.d.ts.map +1 -0
  24. package/dist/core/codegen/index.js +13 -0
  25. package/dist/core/codegen/index.js.map +1 -0
  26. package/dist/core/codegen/ts-generator.d.ts +8 -0
  27. package/dist/core/codegen/ts-generator.d.ts.map +1 -0
  28. package/dist/core/codegen/ts-generator.js +8 -0
  29. package/dist/core/codegen/ts-generator.js.map +1 -0
  30. package/dist/core/db-adapter/index.d.ts +18 -0
  31. package/dist/core/db-adapter/index.d.ts.map +1 -0
  32. package/dist/core/db-adapter/index.js +23 -0
  33. package/dist/core/db-adapter/index.js.map +1 -0
  34. package/dist/core/db-adapter/sync-engine.d.ts +180 -0
  35. package/dist/core/db-adapter/sync-engine.d.ts.map +1 -0
  36. package/dist/core/db-adapter/sync-engine.js +342 -0
  37. package/dist/core/db-adapter/sync-engine.js.map +1 -0
  38. package/dist/core/logic-engine/engine.d.ts +8 -0
  39. package/dist/core/logic-engine/engine.d.ts.map +1 -0
  40. package/dist/core/logic-engine/engine.js +8 -0
  41. package/dist/core/logic-engine/engine.js.map +1 -0
  42. package/dist/core/logic-engine/index.d.ts +16 -0
  43. package/dist/core/logic-engine/index.d.ts.map +1 -0
  44. package/dist/core/logic-engine/index.js +16 -0
  45. package/dist/core/logic-engine/index.js.map +1 -0
  46. package/dist/core/logic-engine/protocol.d.ts +7 -0
  47. package/dist/core/logic-engine/protocol.d.ts.map +1 -0
  48. package/dist/core/logic-engine/protocol.js +7 -0
  49. package/dist/core/logic-engine/protocol.js.map +1 -0
  50. package/dist/core/logic-engine/psf-adapter.d.ts +88 -0
  51. package/dist/core/logic-engine/psf-adapter.d.ts.map +1 -0
  52. package/dist/core/logic-engine/psf-adapter.js +207 -0
  53. package/dist/core/logic-engine/psf-adapter.js.map +1 -0
  54. package/dist/core/logic-engine/rules.d.ts +7 -0
  55. package/dist/core/logic-engine/rules.d.ts.map +1 -0
  56. package/dist/core/logic-engine/rules.js +7 -0
  57. package/dist/core/logic-engine/rules.js.map +1 -0
  58. package/dist/core/schema-engine/compiler.d.ts +198 -0
  59. package/dist/core/schema-engine/compiler.d.ts.map +1 -0
  60. package/dist/core/schema-engine/compiler.js +262 -0
  61. package/dist/core/schema-engine/compiler.js.map +1 -0
  62. package/dist/core/schema-engine/generator.d.ts +115 -0
  63. package/dist/core/schema-engine/generator.d.ts.map +1 -0
  64. package/dist/core/schema-engine/generator.js +506 -0
  65. package/dist/core/schema-engine/generator.js.map +1 -0
  66. package/dist/core/schema-engine/index.d.ts +18 -0
  67. package/dist/core/schema-engine/index.d.ts.map +1 -0
  68. package/dist/core/schema-engine/index.js +18 -0
  69. package/dist/core/schema-engine/index.js.map +1 -0
  70. package/dist/core/schema-engine/psf.d.ts +612 -0
  71. package/dist/core/schema-engine/psf.d.ts.map +1 -0
  72. package/dist/core/schema-engine/psf.js +45 -0
  73. package/dist/core/schema-engine/psf.js.map +1 -0
  74. package/dist/core/schema-engine/types.d.ts +10 -0
  75. package/dist/core/schema-engine/types.d.ts.map +1 -0
  76. package/dist/core/schema-engine/types.js +7 -0
  77. package/dist/core/schema-engine/types.js.map +1 -0
  78. package/dist/core/schema-engine/validator.d.ts +140 -0
  79. package/dist/core/schema-engine/validator.d.ts.map +1 -0
  80. package/dist/core/schema-engine/validator.js +407 -0
  81. package/dist/core/schema-engine/validator.js.map +1 -0
  82. package/dist/src/adapters/cli.d.ts.map +1 -0
  83. package/dist/src/adapters/cli.js.map +1 -0
  84. package/dist/src/cli/commands/auth.d.ts.map +1 -0
  85. package/dist/src/cli/commands/auth.js.map +1 -0
  86. package/dist/src/cli/commands/build.d.ts +23 -0
  87. package/dist/src/cli/commands/build.d.ts.map +1 -0
  88. package/dist/src/cli/commands/build.js +162 -0
  89. package/dist/src/cli/commands/build.js.map +1 -0
  90. package/dist/src/cli/commands/canvas.d.ts +23 -0
  91. package/dist/src/cli/commands/canvas.d.ts.map +1 -0
  92. package/dist/src/cli/commands/canvas.js +215 -0
  93. package/dist/src/cli/commands/canvas.js.map +1 -0
  94. package/dist/src/cli/commands/cloud.d.ts.map +1 -0
  95. package/dist/src/cli/commands/cloud.js.map +1 -0
  96. package/dist/src/cli/commands/create.d.ts +21 -0
  97. package/dist/src/cli/commands/create.d.ts.map +1 -0
  98. package/dist/src/cli/commands/create.js +621 -0
  99. package/dist/src/cli/commands/create.js.map +1 -0
  100. package/dist/src/cli/commands/dev.d.ts +21 -0
  101. package/dist/src/cli/commands/dev.d.ts.map +1 -0
  102. package/dist/src/cli/commands/dev.js +71 -0
  103. package/dist/src/cli/commands/dev.js.map +1 -0
  104. package/dist/src/cli/commands/generate.d.ts.map +1 -0
  105. package/dist/src/cli/commands/generate.js.map +1 -0
  106. package/dist/src/cli/commands/orchestrate.d.ts +44 -0
  107. package/dist/src/cli/commands/orchestrate.d.ts.map +1 -0
  108. package/dist/src/cli/commands/orchestrate.js +150 -0
  109. package/dist/src/cli/commands/orchestrate.js.map +1 -0
  110. package/dist/{cli → src/cli}/index.d.ts.map +1 -1
  111. package/dist/{cli → src/cli}/index.js +53 -21
  112. package/dist/src/cli/index.js.map +1 -0
  113. package/dist/src/cloud/auth.d.ts.map +1 -0
  114. package/dist/src/cloud/auth.js.map +1 -0
  115. package/dist/src/cloud/billing.d.ts.map +1 -0
  116. package/dist/src/cloud/billing.js.map +1 -0
  117. package/dist/src/cloud/client.d.ts.map +1 -0
  118. package/dist/src/cloud/client.js.map +1 -0
  119. package/dist/src/cloud/index.d.ts.map +1 -0
  120. package/dist/src/cloud/index.js.map +1 -0
  121. package/dist/src/cloud/marketplace.d.ts.map +1 -0
  122. package/dist/src/cloud/marketplace.js.map +1 -0
  123. package/dist/src/cloud/provisioning.d.ts.map +1 -0
  124. package/dist/src/cloud/provisioning.js.map +1 -0
  125. package/dist/src/cloud/relay/endpoints.d.ts.map +1 -0
  126. package/dist/src/cloud/relay/endpoints.js.map +1 -0
  127. package/dist/src/cloud/relay/health/index.d.ts.map +1 -0
  128. package/dist/src/cloud/relay/health/index.js.map +1 -0
  129. package/dist/src/cloud/relay/stats/index.d.ts.map +1 -0
  130. package/dist/src/cloud/relay/stats/index.js.map +1 -0
  131. package/dist/src/cloud/relay/sync/index.d.ts.map +1 -0
  132. package/dist/src/cloud/relay/sync/index.js.map +1 -0
  133. package/dist/src/cloud/relay/usage/index.d.ts.map +1 -0
  134. package/dist/src/cloud/relay/usage/index.js.map +1 -0
  135. package/dist/src/cloud/sponsors.d.ts.map +1 -0
  136. package/dist/src/cloud/sponsors.js.map +1 -0
  137. package/dist/src/cloud/types.d.ts.map +1 -0
  138. package/dist/src/cloud/types.js.map +1 -0
  139. package/dist/src/components/index.d.ts.map +1 -0
  140. package/dist/src/components/index.js.map +1 -0
  141. package/dist/src/core/actors.d.ts.map +1 -0
  142. package/dist/src/core/actors.js.map +1 -0
  143. package/dist/src/core/component/generator.d.ts.map +1 -0
  144. package/dist/{core → src/core}/component/generator.js +45 -3
  145. package/dist/src/core/component/generator.js.map +1 -0
  146. package/dist/src/core/engine.d.ts.map +1 -0
  147. package/dist/src/core/engine.js.map +1 -0
  148. package/dist/src/core/introspection.d.ts.map +1 -0
  149. package/dist/src/core/introspection.js.map +1 -0
  150. package/dist/src/core/logic/generator.d.ts.map +1 -0
  151. package/dist/{core → src/core}/logic/generator.js +35 -4
  152. package/dist/src/core/logic/generator.js.map +1 -0
  153. package/dist/src/core/pluresdb/adapter.d.ts +72 -0
  154. package/dist/src/core/pluresdb/adapter.d.ts.map +1 -0
  155. package/dist/src/core/pluresdb/adapter.js +73 -0
  156. package/dist/src/core/pluresdb/adapter.js.map +1 -0
  157. package/dist/src/core/pluresdb/generator.d.ts.map +1 -0
  158. package/dist/{core → src/core}/pluresdb/generator.js +33 -4
  159. package/dist/src/core/pluresdb/generator.js.map +1 -0
  160. package/dist/src/core/pluresdb/index.d.ts +15 -0
  161. package/dist/src/core/pluresdb/index.d.ts.map +1 -0
  162. package/dist/src/core/pluresdb/index.js +11 -0
  163. package/dist/src/core/pluresdb/index.js.map +1 -0
  164. package/dist/src/core/pluresdb/schema-registry.d.ts +104 -0
  165. package/dist/src/core/pluresdb/schema-registry.d.ts.map +1 -0
  166. package/dist/src/core/pluresdb/schema-registry.js +130 -0
  167. package/dist/src/core/pluresdb/schema-registry.js.map +1 -0
  168. package/dist/src/core/pluresdb/store.d.ts +199 -0
  169. package/dist/src/core/pluresdb/store.d.ts.map +1 -0
  170. package/dist/src/core/pluresdb/store.js +344 -0
  171. package/dist/src/core/pluresdb/store.js.map +1 -0
  172. package/dist/src/core/protocol.d.ts.map +1 -0
  173. package/dist/src/core/protocol.js.map +1 -0
  174. package/dist/src/core/rules.d.ts.map +1 -0
  175. package/dist/src/core/rules.js.map +1 -0
  176. package/dist/src/core/schema/loader.d.ts.map +1 -0
  177. package/dist/src/core/schema/loader.js.map +1 -0
  178. package/dist/src/core/schema/normalize.d.ts.map +1 -0
  179. package/dist/src/core/schema/normalize.js.map +1 -0
  180. package/dist/src/core/schema/types.d.ts.map +1 -0
  181. package/dist/src/core/schema/types.js.map +1 -0
  182. package/dist/src/dsl/index.d.ts.map +1 -0
  183. package/dist/src/dsl/index.js.map +1 -0
  184. package/dist/src/dsl.d.ts.map +1 -0
  185. package/dist/src/dsl.js.map +1 -0
  186. package/dist/src/examples/advanced-todo/index.d.ts.map +1 -0
  187. package/dist/src/examples/advanced-todo/index.js.map +1 -0
  188. package/dist/src/examples/auth-basic/index.d.ts.map +1 -0
  189. package/dist/src/examples/auth-basic/index.js.map +1 -0
  190. package/dist/src/examples/cart/index.d.ts.map +1 -0
  191. package/dist/src/examples/cart/index.js.map +1 -0
  192. package/dist/src/examples/hero-ecommerce/index.d.ts.map +1 -0
  193. package/dist/src/examples/hero-ecommerce/index.js.map +1 -0
  194. package/dist/src/examples/svelte-counter/index.d.ts.map +1 -0
  195. package/dist/src/examples/svelte-counter/index.js.map +1 -0
  196. package/dist/src/flows.d.ts.map +1 -0
  197. package/dist/src/flows.js.map +1 -0
  198. package/dist/{index.d.ts → src/index.d.ts} +12 -2
  199. package/dist/src/index.d.ts.map +1 -0
  200. package/dist/{index.js → src/index.js} +6 -1
  201. package/dist/src/index.js.map +1 -0
  202. package/dist/src/integrations/code-canvas.d.ts +265 -0
  203. package/dist/src/integrations/code-canvas.d.ts.map +1 -0
  204. package/dist/src/integrations/code-canvas.js +451 -0
  205. package/dist/src/integrations/code-canvas.js.map +1 -0
  206. package/dist/src/integrations/pluresdb.d.ts +117 -0
  207. package/dist/src/integrations/pluresdb.d.ts.map +1 -0
  208. package/dist/src/integrations/pluresdb.js +117 -0
  209. package/dist/src/integrations/pluresdb.js.map +1 -0
  210. package/dist/src/integrations/state-docs.d.ts +191 -0
  211. package/dist/src/integrations/state-docs.d.ts.map +1 -0
  212. package/dist/src/integrations/state-docs.js +515 -0
  213. package/dist/src/integrations/state-docs.js.map +1 -0
  214. package/dist/src/integrations/svelte.d.ts.map +1 -0
  215. package/dist/src/integrations/svelte.js.map +1 -0
  216. package/dist/src/integrations/tauri.d.ts +360 -0
  217. package/dist/src/integrations/tauri.d.ts.map +1 -0
  218. package/dist/src/integrations/tauri.js +278 -0
  219. package/dist/src/integrations/tauri.js.map +1 -0
  220. package/dist/src/integrations/unum.d.ts +159 -0
  221. package/dist/src/integrations/unum.d.ts.map +1 -0
  222. package/dist/src/integrations/unum.js +240 -0
  223. package/dist/src/integrations/unum.js.map +1 -0
  224. package/dist/src/registry.d.ts.map +1 -0
  225. package/dist/src/registry.js.map +1 -0
  226. package/dist/{runtime → src/runtime}/terminal-adapter.d.ts +58 -7
  227. package/dist/src/runtime/terminal-adapter.d.ts.map +1 -0
  228. package/dist/src/runtime/terminal-adapter.js +239 -0
  229. package/dist/src/runtime/terminal-adapter.js.map +1 -0
  230. package/dist/src/step.d.ts.map +1 -0
  231. package/dist/src/step.js.map +1 -0
  232. package/dist/src/types.d.ts.map +1 -0
  233. package/dist/{cloud → src}/types.js.map +1 -1
  234. package/dist/tools/cli/commands/index.d.ts +7 -0
  235. package/dist/tools/cli/commands/index.d.ts.map +1 -0
  236. package/dist/tools/cli/commands/index.js +7 -0
  237. package/dist/tools/cli/commands/index.js.map +1 -0
  238. package/dist/tools/cli/index.d.ts +8 -0
  239. package/dist/tools/cli/index.d.ts.map +1 -0
  240. package/dist/tools/cli/index.js +9 -0
  241. package/dist/tools/cli/index.js.map +1 -0
  242. package/dist/tools/watcher/index.d.ts +105 -0
  243. package/dist/tools/watcher/index.d.ts.map +1 -0
  244. package/dist/tools/watcher/index.js +213 -0
  245. package/dist/tools/watcher/index.js.map +1 -0
  246. package/dist/ui/canvas/canvas-projection.d.ts +78 -0
  247. package/dist/ui/canvas/canvas-projection.d.ts.map +1 -0
  248. package/dist/ui/canvas/canvas-projection.js +416 -0
  249. package/dist/ui/canvas/canvas-projection.js.map +1 -0
  250. package/dist/ui/canvas/canvas-state.d.ts +200 -0
  251. package/dist/ui/canvas/canvas-state.d.ts.map +1 -0
  252. package/dist/ui/canvas/canvas-state.js +464 -0
  253. package/dist/ui/canvas/canvas-state.js.map +1 -0
  254. package/dist/ui/canvas/components/index.d.ts +95 -0
  255. package/dist/ui/canvas/components/index.d.ts.map +1 -0
  256. package/dist/ui/canvas/components/index.js +19 -0
  257. package/dist/ui/canvas/components/index.js.map +1 -0
  258. package/dist/ui/canvas/index.d.ts +32 -0
  259. package/dist/ui/canvas/index.d.ts.map +1 -0
  260. package/dist/ui/canvas/index.js +32 -0
  261. package/dist/ui/canvas/index.js.map +1 -0
  262. package/dist/ui/svelte-generator/index.d.ts +9 -0
  263. package/dist/ui/svelte-generator/index.d.ts.map +1 -0
  264. package/dist/ui/svelte-generator/index.js +11 -0
  265. package/dist/ui/svelte-generator/index.js.map +1 -0
  266. package/dist/ui/svelte-generator/psf-generator.d.ts +128 -0
  267. package/dist/ui/svelte-generator/psf-generator.d.ts.map +1 -0
  268. package/dist/ui/svelte-generator/psf-generator.js +506 -0
  269. package/dist/ui/svelte-generator/psf-generator.js.map +1 -0
  270. package/docs/README.md +155 -0
  271. package/docs/core/building-extensions.md +553 -0
  272. package/docs/core/cli-usage.md +498 -0
  273. package/docs/core/code-canvas-sync.md +468 -0
  274. package/docs/core/logic-engine.md +566 -0
  275. package/docs/core/pluresdb-integration.md +646 -0
  276. package/docs/core/schema-model.md +414 -0
  277. package/docs/core/ui-generation.md +580 -0
  278. package/docs/core/what-is-praxis.md +240 -0
  279. package/docs/tutorials/README.md +84 -0
  280. package/docs/tutorials/ecommerce-cart.md +631 -0
  281. package/docs/tutorials/first-app.md +529 -0
  282. package/docs/tutorials/form-builder.md +620 -0
  283. package/docs/tutorials/todo-pluresdb.md +589 -0
  284. package/package.json +16 -16
  285. package/src/__tests__/canvas-components.test.ts +450 -0
  286. package/src/__tests__/cli-create.test.ts +178 -0
  287. package/src/__tests__/code-canvas-integration.test.ts +277 -0
  288. package/src/__tests__/docs-generator.test.ts +181 -0
  289. package/src/__tests__/generators.test.ts +3 -2
  290. package/src/__tests__/pluresdb.test.ts +457 -0
  291. package/src/__tests__/psf-schema-engine.test.ts +450 -0
  292. package/src/__tests__/state-docs-integration.test.ts +297 -0
  293. package/src/__tests__/tauri-integration.test.ts +298 -0
  294. package/src/__tests__/terminal-node.test.ts +1 -1
  295. package/src/__tests__/unum-integration.test.ts +142 -0
  296. package/src/cli/commands/build.ts +203 -0
  297. package/src/cli/commands/canvas.ts +246 -0
  298. package/src/cli/commands/create.ts +666 -0
  299. package/src/cli/commands/dev.ts +95 -0
  300. package/src/cli/commands/orchestrate.ts +212 -0
  301. package/src/cli/index.ts +48 -21
  302. package/src/core/component/generator.ts +45 -3
  303. package/src/core/logic/generator.ts +39 -4
  304. package/src/core/pluresdb/adapter.ts +117 -0
  305. package/src/core/pluresdb/generator.ts +33 -4
  306. package/src/core/pluresdb/index.ts +37 -0
  307. package/src/core/pluresdb/schema-registry.ts +162 -0
  308. package/src/core/pluresdb/store.ts +446 -0
  309. package/src/index.ts +109 -0
  310. package/src/integrations/code-canvas.ts +717 -0
  311. package/src/integrations/pluresdb.ts +140 -29
  312. package/src/integrations/state-docs.ts +710 -0
  313. package/src/integrations/tauri.ts +638 -0
  314. package/src/integrations/unum.ts +395 -0
  315. package/src/runtime/terminal-adapter.ts +184 -23
  316. package/dist/adapters/cli.d.ts.map +0 -1
  317. package/dist/adapters/cli.js.map +0 -1
  318. package/dist/cli/commands/auth.d.ts.map +0 -1
  319. package/dist/cli/commands/auth.js.map +0 -1
  320. package/dist/cli/commands/cloud.d.ts.map +0 -1
  321. package/dist/cli/commands/cloud.js.map +0 -1
  322. package/dist/cli/commands/generate.d.ts.map +0 -1
  323. package/dist/cli/commands/generate.js.map +0 -1
  324. package/dist/cli/index.js.map +0 -1
  325. package/dist/cloud/auth.d.ts.map +0 -1
  326. package/dist/cloud/auth.js.map +0 -1
  327. package/dist/cloud/billing.d.ts.map +0 -1
  328. package/dist/cloud/billing.js.map +0 -1
  329. package/dist/cloud/client.d.ts.map +0 -1
  330. package/dist/cloud/client.js.map +0 -1
  331. package/dist/cloud/index.d.ts.map +0 -1
  332. package/dist/cloud/index.js.map +0 -1
  333. package/dist/cloud/marketplace.d.ts.map +0 -1
  334. package/dist/cloud/marketplace.js.map +0 -1
  335. package/dist/cloud/provisioning.d.ts.map +0 -1
  336. package/dist/cloud/provisioning.js.map +0 -1
  337. package/dist/cloud/relay/endpoints.d.ts.map +0 -1
  338. package/dist/cloud/relay/endpoints.js.map +0 -1
  339. package/dist/cloud/relay/health/index.d.ts.map +0 -1
  340. package/dist/cloud/relay/health/index.js.map +0 -1
  341. package/dist/cloud/relay/stats/index.d.ts.map +0 -1
  342. package/dist/cloud/relay/stats/index.js.map +0 -1
  343. package/dist/cloud/relay/sync/index.d.ts.map +0 -1
  344. package/dist/cloud/relay/sync/index.js.map +0 -1
  345. package/dist/cloud/relay/usage/index.d.ts.map +0 -1
  346. package/dist/cloud/relay/usage/index.js.map +0 -1
  347. package/dist/cloud/sponsors.d.ts.map +0 -1
  348. package/dist/cloud/sponsors.js.map +0 -1
  349. package/dist/cloud/types.d.ts.map +0 -1
  350. package/dist/components/index.d.ts.map +0 -1
  351. package/dist/components/index.js.map +0 -1
  352. package/dist/core/actors.d.ts.map +0 -1
  353. package/dist/core/actors.js.map +0 -1
  354. package/dist/core/component/generator.d.ts.map +0 -1
  355. package/dist/core/component/generator.js.map +0 -1
  356. package/dist/core/engine.d.ts.map +0 -1
  357. package/dist/core/engine.js.map +0 -1
  358. package/dist/core/introspection.d.ts.map +0 -1
  359. package/dist/core/introspection.js.map +0 -1
  360. package/dist/core/logic/generator.d.ts.map +0 -1
  361. package/dist/core/logic/generator.js.map +0 -1
  362. package/dist/core/pluresdb/generator.d.ts.map +0 -1
  363. package/dist/core/pluresdb/generator.js.map +0 -1
  364. package/dist/core/protocol.d.ts.map +0 -1
  365. package/dist/core/protocol.js.map +0 -1
  366. package/dist/core/rules.d.ts.map +0 -1
  367. package/dist/core/rules.js.map +0 -1
  368. package/dist/core/schema/loader.d.ts.map +0 -1
  369. package/dist/core/schema/loader.js.map +0 -1
  370. package/dist/core/schema/normalize.d.ts.map +0 -1
  371. package/dist/core/schema/normalize.js.map +0 -1
  372. package/dist/core/schema/types.d.ts.map +0 -1
  373. package/dist/core/schema/types.js.map +0 -1
  374. package/dist/dsl/index.d.ts.map +0 -1
  375. package/dist/dsl/index.js.map +0 -1
  376. package/dist/dsl.d.ts.map +0 -1
  377. package/dist/dsl.js.map +0 -1
  378. package/dist/examples/advanced-todo/index.d.ts.map +0 -1
  379. package/dist/examples/advanced-todo/index.js.map +0 -1
  380. package/dist/examples/auth-basic/index.d.ts.map +0 -1
  381. package/dist/examples/auth-basic/index.js.map +0 -1
  382. package/dist/examples/cart/index.d.ts.map +0 -1
  383. package/dist/examples/cart/index.js.map +0 -1
  384. package/dist/examples/hero-ecommerce/index.d.ts.map +0 -1
  385. package/dist/examples/hero-ecommerce/index.js.map +0 -1
  386. package/dist/examples/svelte-counter/index.d.ts.map +0 -1
  387. package/dist/examples/svelte-counter/index.js.map +0 -1
  388. package/dist/flows.d.ts.map +0 -1
  389. package/dist/flows.js.map +0 -1
  390. package/dist/index.d.ts.map +0 -1
  391. package/dist/index.js.map +0 -1
  392. package/dist/integrations/pluresdb.d.ts +0 -56
  393. package/dist/integrations/pluresdb.d.ts.map +0 -1
  394. package/dist/integrations/pluresdb.js +0 -46
  395. package/dist/integrations/pluresdb.js.map +0 -1
  396. package/dist/integrations/svelte.d.ts.map +0 -1
  397. package/dist/integrations/svelte.js.map +0 -1
  398. package/dist/registry.d.ts.map +0 -1
  399. package/dist/registry.js.map +0 -1
  400. package/dist/runtime/terminal-adapter.d.ts.map +0 -1
  401. package/dist/runtime/terminal-adapter.js +0 -113
  402. package/dist/runtime/terminal-adapter.js.map +0 -1
  403. package/dist/step.d.ts.map +0 -1
  404. package/dist/step.js.map +0 -1
  405. package/dist/types.d.ts.map +0 -1
  406. package/dist/types.js.map +0 -1
  407. /package/dist/{adapters → src/adapters}/cli.d.ts +0 -0
  408. /package/dist/{adapters → src/adapters}/cli.js +0 -0
  409. /package/dist/{cli → src/cli}/commands/auth.d.ts +0 -0
  410. /package/dist/{cli → src/cli}/commands/auth.js +0 -0
  411. /package/dist/{cli → src/cli}/commands/cloud.d.ts +0 -0
  412. /package/dist/{cli → src/cli}/commands/cloud.js +0 -0
  413. /package/dist/{cli → src/cli}/commands/generate.d.ts +0 -0
  414. /package/dist/{cli → src/cli}/commands/generate.js +0 -0
  415. /package/dist/{cli → src/cli}/index.d.ts +0 -0
  416. /package/dist/{cloud → src/cloud}/auth.d.ts +0 -0
  417. /package/dist/{cloud → src/cloud}/auth.js +0 -0
  418. /package/dist/{cloud → src/cloud}/billing.d.ts +0 -0
  419. /package/dist/{cloud → src/cloud}/billing.js +0 -0
  420. /package/dist/{cloud → src/cloud}/client.d.ts +0 -0
  421. /package/dist/{cloud → src/cloud}/client.js +0 -0
  422. /package/dist/{cloud → src/cloud}/index.d.ts +0 -0
  423. /package/dist/{cloud → src/cloud}/index.js +0 -0
  424. /package/dist/{cloud → src/cloud}/marketplace.d.ts +0 -0
  425. /package/dist/{cloud → src/cloud}/marketplace.js +0 -0
  426. /package/dist/{cloud → src/cloud}/provisioning.d.ts +0 -0
  427. /package/dist/{cloud → src/cloud}/provisioning.js +0 -0
  428. /package/dist/{cloud → src/cloud}/relay/endpoints.d.ts +0 -0
  429. /package/dist/{cloud → src/cloud}/relay/endpoints.js +0 -0
  430. /package/dist/{cloud → src/cloud}/relay/health/index.d.ts +0 -0
  431. /package/dist/{cloud → src/cloud}/relay/health/index.js +0 -0
  432. /package/dist/{cloud → src/cloud}/relay/stats/index.d.ts +0 -0
  433. /package/dist/{cloud → src/cloud}/relay/stats/index.js +0 -0
  434. /package/dist/{cloud → src/cloud}/relay/sync/index.d.ts +0 -0
  435. /package/dist/{cloud → src/cloud}/relay/sync/index.js +0 -0
  436. /package/dist/{cloud → src/cloud}/relay/usage/index.d.ts +0 -0
  437. /package/dist/{cloud → src/cloud}/relay/usage/index.js +0 -0
  438. /package/dist/{cloud → src/cloud}/sponsors.d.ts +0 -0
  439. /package/dist/{cloud → src/cloud}/sponsors.js +0 -0
  440. /package/dist/{cloud → src/cloud}/types.d.ts +0 -0
  441. /package/dist/{cloud → src/cloud}/types.js +0 -0
  442. /package/dist/{components → src/components}/index.d.ts +0 -0
  443. /package/dist/{components → src/components}/index.js +0 -0
  444. /package/dist/{core → src/core}/actors.d.ts +0 -0
  445. /package/dist/{core → src/core}/actors.js +0 -0
  446. /package/dist/{core → src/core}/component/generator.d.ts +0 -0
  447. /package/dist/{core → src/core}/engine.d.ts +0 -0
  448. /package/dist/{core → src/core}/engine.js +0 -0
  449. /package/dist/{core → src/core}/introspection.d.ts +0 -0
  450. /package/dist/{core → src/core}/introspection.js +0 -0
  451. /package/dist/{core → src/core}/logic/generator.d.ts +0 -0
  452. /package/dist/{core → src/core}/pluresdb/generator.d.ts +0 -0
  453. /package/dist/{core → src/core}/protocol.d.ts +0 -0
  454. /package/dist/{core → src/core}/protocol.js +0 -0
  455. /package/dist/{core → src/core}/rules.d.ts +0 -0
  456. /package/dist/{core → src/core}/rules.js +0 -0
  457. /package/dist/{core → src/core}/schema/loader.d.ts +0 -0
  458. /package/dist/{core → src/core}/schema/loader.js +0 -0
  459. /package/dist/{core → src/core}/schema/normalize.d.ts +0 -0
  460. /package/dist/{core → src/core}/schema/normalize.js +0 -0
  461. /package/dist/{core → src/core}/schema/types.d.ts +0 -0
  462. /package/dist/{core → src/core}/schema/types.js +0 -0
  463. /package/dist/{dsl → src/dsl}/index.d.ts +0 -0
  464. /package/dist/{dsl → src/dsl}/index.js +0 -0
  465. /package/dist/{dsl.d.ts → src/dsl.d.ts} +0 -0
  466. /package/dist/{dsl.js → src/dsl.js} +0 -0
  467. /package/dist/{examples → src/examples}/advanced-todo/index.d.ts +0 -0
  468. /package/dist/{examples → src/examples}/advanced-todo/index.js +0 -0
  469. /package/dist/{examples → src/examples}/auth-basic/index.d.ts +0 -0
  470. /package/dist/{examples → src/examples}/auth-basic/index.js +0 -0
  471. /package/dist/{examples → src/examples}/cart/index.d.ts +0 -0
  472. /package/dist/{examples → src/examples}/cart/index.js +0 -0
  473. /package/dist/{examples → src/examples}/hero-ecommerce/index.d.ts +0 -0
  474. /package/dist/{examples → src/examples}/hero-ecommerce/index.js +0 -0
  475. /package/dist/{examples → src/examples}/svelte-counter/index.d.ts +0 -0
  476. /package/dist/{examples → src/examples}/svelte-counter/index.js +0 -0
  477. /package/dist/{flows.d.ts → src/flows.d.ts} +0 -0
  478. /package/dist/{flows.js → src/flows.js} +0 -0
  479. /package/dist/{integrations → src/integrations}/svelte.d.ts +0 -0
  480. /package/dist/{integrations → src/integrations}/svelte.js +0 -0
  481. /package/dist/{registry.d.ts → src/registry.d.ts} +0 -0
  482. /package/dist/{registry.js → src/registry.js} +0 -0
  483. /package/dist/{step.d.ts → src/step.d.ts} +0 -0
  484. /package/dist/{step.js → src/step.js} +0 -0
  485. /package/dist/{types.d.ts → src/types.d.ts} +0 -0
  486. /package/dist/{types.js → src/types.js} +0 -0
@@ -0,0 +1,808 @@
1
+ /**
2
+ * Documentation Generator
3
+ *
4
+ * Generates Markdown documentation from PSF schemas.
5
+ * Produces API docs, architecture diagrams, and user guides.
6
+ */
7
+
8
+ import type {
9
+ PSFSchema,
10
+ PSFFact,
11
+ PSFEvent,
12
+ PSFRule,
13
+ PSFConstraint,
14
+ PSFModel,
15
+ PSFComponent,
16
+ PSFFlow,
17
+ PSFFieldType,
18
+ } from '../schema-engine/psf.js';
19
+
20
+ /**
21
+ * Documentation generator options
22
+ */
23
+ export interface DocsGeneratorOptions {
24
+ /** Output directory */
25
+ outputDir?: string;
26
+ /** Include Mermaid diagrams */
27
+ includeDiagrams?: boolean;
28
+ /** Include code examples */
29
+ includeExamples?: boolean;
30
+ /** Include API reference */
31
+ includeApiReference?: boolean;
32
+ /** Include table of contents */
33
+ includeToc?: boolean;
34
+ /** Document format */
35
+ format?: 'markdown' | 'html';
36
+ }
37
+
38
+ /**
39
+ * Generated documentation file
40
+ */
41
+ export interface GeneratedDoc {
42
+ /** File path */
43
+ path: string;
44
+ /** File content */
45
+ content: string;
46
+ /** Document type */
47
+ type: 'overview' | 'api' | 'model' | 'component' | 'flow' | 'diagram' | 'index';
48
+ }
49
+
50
+ /**
51
+ * Documentation generation result
52
+ */
53
+ export interface DocsGenerationResult {
54
+ success: boolean;
55
+ files: GeneratedDoc[];
56
+ errors: string[];
57
+ }
58
+
59
+ /**
60
+ * Documentation Generator class
61
+ */
62
+ export class DocsGenerator {
63
+ private options: Required<DocsGeneratorOptions>;
64
+
65
+ constructor(options: DocsGeneratorOptions = {}) {
66
+ this.options = {
67
+ outputDir: options.outputDir || './docs',
68
+ includeDiagrams: options.includeDiagrams ?? true,
69
+ includeExamples: options.includeExamples ?? true,
70
+ includeApiReference: options.includeApiReference ?? true,
71
+ includeToc: options.includeToc ?? true,
72
+ format: options.format || 'markdown',
73
+ };
74
+ }
75
+
76
+ /**
77
+ * Generate all documentation from schema
78
+ */
79
+ generate(schema: PSFSchema): DocsGenerationResult {
80
+ const files: GeneratedDoc[] = [];
81
+ const errors: string[] = [];
82
+
83
+ try {
84
+ // Generate overview
85
+ files.push(this.generateOverview(schema));
86
+
87
+ // Generate API reference
88
+ if (this.options.includeApiReference) {
89
+ files.push(this.generateApiReference(schema));
90
+ }
91
+
92
+ // Generate model docs
93
+ if (schema.models.length > 0) {
94
+ files.push(this.generateModelsDoc(schema.models));
95
+ }
96
+
97
+ // Generate component docs
98
+ if (schema.components.length > 0) {
99
+ files.push(this.generateComponentsDoc(schema.components));
100
+ }
101
+
102
+ // Generate flow docs
103
+ if (schema.flows.length > 0) {
104
+ files.push(this.generateFlowsDoc(schema.flows));
105
+ }
106
+
107
+ // Generate diagrams
108
+ if (this.options.includeDiagrams) {
109
+ files.push(this.generateDiagrams(schema));
110
+ }
111
+
112
+ // Generate index
113
+ files.push(this.generateIndex(schema, files));
114
+ } catch (error) {
115
+ errors.push(error instanceof Error ? error.message : 'Unknown error');
116
+ }
117
+
118
+ return {
119
+ success: errors.length === 0,
120
+ files,
121
+ errors,
122
+ };
123
+ }
124
+
125
+ /**
126
+ * Generate overview document
127
+ */
128
+ private generateOverview(schema: PSFSchema): GeneratedDoc {
129
+ const lines: string[] = [];
130
+
131
+ lines.push(`# ${schema.name}`);
132
+ lines.push('');
133
+
134
+ if (schema.description) {
135
+ lines.push(schema.description);
136
+ lines.push('');
137
+ }
138
+
139
+ // Schema info
140
+ lines.push('## Schema Information');
141
+ lines.push('');
142
+ lines.push(`- **Version**: ${schema.$version}`);
143
+ lines.push(`- **ID**: ${schema.id}`);
144
+ if (schema.createdAt) {
145
+ lines.push(`- **Created**: ${new Date(schema.createdAt).toLocaleString()}`);
146
+ }
147
+ if (schema.modifiedAt) {
148
+ lines.push(`- **Last Modified**: ${new Date(schema.modifiedAt).toLocaleString()}`);
149
+ }
150
+ lines.push('');
151
+
152
+ // Quick stats
153
+ lines.push('## Overview');
154
+ lines.push('');
155
+ lines.push(`| Type | Count |`);
156
+ lines.push(`| ---- | ----- |`);
157
+ lines.push(`| Facts | ${schema.facts.length} |`);
158
+ lines.push(`| Events | ${schema.events.length} |`);
159
+ lines.push(`| Rules | ${schema.rules.length} |`);
160
+ lines.push(`| Constraints | ${schema.constraints.length} |`);
161
+ lines.push(`| Models | ${schema.models.length} |`);
162
+ lines.push(`| Components | ${schema.components.length} |`);
163
+ lines.push(`| Flows | ${schema.flows.length} |`);
164
+ lines.push('');
165
+
166
+ // Schema documentation if available
167
+ if (schema.docs) {
168
+ if (schema.docs.overview) {
169
+ lines.push('## About');
170
+ lines.push('');
171
+ lines.push(schema.docs.overview);
172
+ lines.push('');
173
+ }
174
+
175
+ if (schema.docs.gettingStarted) {
176
+ lines.push('## Getting Started');
177
+ lines.push('');
178
+ lines.push(schema.docs.gettingStarted);
179
+ lines.push('');
180
+ }
181
+ }
182
+
183
+ return {
184
+ path: `${this.options.outputDir}/overview.md`,
185
+ content: lines.join('\n'),
186
+ type: 'overview',
187
+ };
188
+ }
189
+
190
+ /**
191
+ * Generate API reference
192
+ */
193
+ private generateApiReference(schema: PSFSchema): GeneratedDoc {
194
+ const lines: string[] = [];
195
+
196
+ lines.push('# API Reference');
197
+ lines.push('');
198
+
199
+ if (this.options.includeToc) {
200
+ lines.push('## Table of Contents');
201
+ lines.push('');
202
+ lines.push('- [Facts](#facts)');
203
+ lines.push('- [Events](#events)');
204
+ lines.push('- [Rules](#rules)');
205
+ lines.push('- [Constraints](#constraints)');
206
+ lines.push('');
207
+ }
208
+
209
+ // Facts
210
+ lines.push('## Facts');
211
+ lines.push('');
212
+ if (schema.facts.length === 0) {
213
+ lines.push('No facts defined.');
214
+ } else {
215
+ for (const fact of schema.facts) {
216
+ lines.push(this.generateFactDoc(fact));
217
+ }
218
+ }
219
+ lines.push('');
220
+
221
+ // Events
222
+ lines.push('## Events');
223
+ lines.push('');
224
+ if (schema.events.length === 0) {
225
+ lines.push('No events defined.');
226
+ } else {
227
+ for (const event of schema.events) {
228
+ lines.push(this.generateEventDoc(event));
229
+ }
230
+ }
231
+ lines.push('');
232
+
233
+ // Rules
234
+ lines.push('## Rules');
235
+ lines.push('');
236
+ if (schema.rules.length === 0) {
237
+ lines.push('No rules defined.');
238
+ } else {
239
+ for (const rule of schema.rules) {
240
+ lines.push(this.generateRuleDoc(rule));
241
+ }
242
+ }
243
+ lines.push('');
244
+
245
+ // Constraints
246
+ lines.push('## Constraints');
247
+ lines.push('');
248
+ if (schema.constraints.length === 0) {
249
+ lines.push('No constraints defined.');
250
+ } else {
251
+ for (const constraint of schema.constraints) {
252
+ lines.push(this.generateConstraintDoc(constraint));
253
+ }
254
+ }
255
+
256
+ return {
257
+ path: `${this.options.outputDir}/api.md`,
258
+ content: lines.join('\n'),
259
+ type: 'api',
260
+ };
261
+ }
262
+
263
+ /**
264
+ * Generate fact documentation
265
+ */
266
+ private generateFactDoc(fact: PSFFact): string {
267
+ const lines: string[] = [];
268
+
269
+ lines.push(`### ${fact.tag}`);
270
+ lines.push('');
271
+
272
+ if (fact.description) {
273
+ lines.push(fact.description);
274
+ lines.push('');
275
+ }
276
+
277
+ if (fact.docs?.summary) {
278
+ lines.push(`> ${fact.docs.summary}`);
279
+ lines.push('');
280
+ }
281
+
282
+ // Payload schema
283
+ if (fact.payload && Object.keys(fact.payload.properties).length > 0) {
284
+ lines.push('**Payload**');
285
+ lines.push('');
286
+ lines.push('| Property | Type | Description |');
287
+ lines.push('| -------- | ---- | ----------- |');
288
+ for (const [name, prop] of Object.entries(fact.payload.properties)) {
289
+ const type = this.formatFieldType(prop.type);
290
+ const desc = prop.description || '-';
291
+ lines.push(`| \`${name}\` | \`${type}\` | ${desc} |`);
292
+ }
293
+ lines.push('');
294
+ }
295
+
296
+ if (this.options.includeExamples) {
297
+ lines.push('**Example**');
298
+ lines.push('');
299
+ lines.push('```typescript');
300
+ lines.push(`const fact = ${fact.tag}.create({`);
301
+ for (const [name, prop] of Object.entries(fact.payload.properties)) {
302
+ const example = this.getExampleValue(prop.type);
303
+ lines.push(` ${name}: ${example},`);
304
+ }
305
+ lines.push('});');
306
+ lines.push('```');
307
+ lines.push('');
308
+ }
309
+
310
+ return lines.join('\n');
311
+ }
312
+
313
+ /**
314
+ * Generate event documentation
315
+ */
316
+ private generateEventDoc(event: PSFEvent): string {
317
+ const lines: string[] = [];
318
+
319
+ lines.push(`### ${event.tag}`);
320
+ lines.push('');
321
+
322
+ if (event.description) {
323
+ lines.push(event.description);
324
+ lines.push('');
325
+ }
326
+
327
+ if (event.docs?.summary) {
328
+ lines.push(`> ${event.docs.summary}`);
329
+ lines.push('');
330
+ }
331
+
332
+ // Payload schema
333
+ if (event.payload && Object.keys(event.payload.properties).length > 0) {
334
+ lines.push('**Payload**');
335
+ lines.push('');
336
+ lines.push('| Property | Type | Description |');
337
+ lines.push('| -------- | ---- | ----------- |');
338
+ for (const [name, prop] of Object.entries(event.payload.properties)) {
339
+ const type = this.formatFieldType(prop.type);
340
+ const desc = prop.description || '-';
341
+ lines.push(`| \`${name}\` | \`${type}\` | ${desc} |`);
342
+ }
343
+ lines.push('');
344
+ }
345
+
346
+ if (this.options.includeExamples) {
347
+ lines.push('**Example**');
348
+ lines.push('');
349
+ lines.push('```typescript');
350
+ lines.push(`const event = ${event.tag}.create({`);
351
+ for (const [name, prop] of Object.entries(event.payload.properties)) {
352
+ const example = this.getExampleValue(prop.type);
353
+ lines.push(` ${name}: ${example},`);
354
+ }
355
+ lines.push('});');
356
+ lines.push('```');
357
+ lines.push('');
358
+ }
359
+
360
+ return lines.join('\n');
361
+ }
362
+
363
+ /**
364
+ * Generate rule documentation
365
+ */
366
+ private generateRuleDoc(rule: PSFRule): string {
367
+ const lines: string[] = [];
368
+
369
+ lines.push(`### ${rule.name || rule.id}`);
370
+ lines.push('');
371
+ lines.push(`**ID**: \`${rule.id}\``);
372
+ lines.push('');
373
+
374
+ if (rule.description) {
375
+ lines.push(rule.description);
376
+ lines.push('');
377
+ }
378
+
379
+ if (rule.triggers && rule.triggers.length > 0) {
380
+ lines.push(`**Triggers**: ${rule.triggers.map((t) => `\`${t}\``).join(', ')}`);
381
+ lines.push('');
382
+ }
383
+
384
+ if (rule.priority !== undefined) {
385
+ lines.push(`**Priority**: ${rule.priority}`);
386
+ lines.push('');
387
+ }
388
+
389
+ return lines.join('\n');
390
+ }
391
+
392
+ /**
393
+ * Generate constraint documentation
394
+ */
395
+ private generateConstraintDoc(constraint: PSFConstraint): string {
396
+ const lines: string[] = [];
397
+
398
+ lines.push(`### ${constraint.name || constraint.id}`);
399
+ lines.push('');
400
+ lines.push(`**ID**: \`${constraint.id}\``);
401
+ lines.push('');
402
+
403
+ if (constraint.description) {
404
+ lines.push(constraint.description);
405
+ lines.push('');
406
+ }
407
+
408
+ if (constraint.severity) {
409
+ lines.push(`**Severity**: ${constraint.severity}`);
410
+ lines.push('');
411
+ }
412
+
413
+ if (constraint.errorMessage) {
414
+ lines.push(`**Error Message**: "${constraint.errorMessage}"`);
415
+ lines.push('');
416
+ }
417
+
418
+ return lines.join('\n');
419
+ }
420
+
421
+ /**
422
+ * Generate models documentation
423
+ */
424
+ private generateModelsDoc(models: PSFModel[]): GeneratedDoc {
425
+ const lines: string[] = [];
426
+
427
+ lines.push('# Data Models');
428
+ lines.push('');
429
+
430
+ for (const model of models) {
431
+ lines.push(`## ${model.name}`);
432
+ lines.push('');
433
+
434
+ if (model.description) {
435
+ lines.push(model.description);
436
+ lines.push('');
437
+ }
438
+
439
+ // Fields table
440
+ lines.push('### Fields');
441
+ lines.push('');
442
+ lines.push('| Field | Type | Optional | Description |');
443
+ lines.push('| ----- | ---- | -------- | ----------- |');
444
+ for (const field of model.fields) {
445
+ const type = this.formatFieldType(field.type);
446
+ const optional = field.optional ? 'Yes' : 'No';
447
+ const desc = field.description || '-';
448
+ lines.push(`| \`${field.name}\` | \`${type}\` | ${optional} | ${desc} |`);
449
+ }
450
+ lines.push('');
451
+
452
+ // Relationships
453
+ if (model.relationships && model.relationships.length > 0) {
454
+ lines.push('### Relationships');
455
+ lines.push('');
456
+ for (const rel of model.relationships) {
457
+ lines.push(`- **${rel.name}** → \`${rel.target}\` (${rel.type})`);
458
+ }
459
+ lines.push('');
460
+ }
461
+
462
+ // Indexes
463
+ if (model.indexes && model.indexes.length > 0) {
464
+ lines.push('### Indexes');
465
+ lines.push('');
466
+ for (const idx of model.indexes) {
467
+ const unique = idx.unique ? ' (unique)' : '';
468
+ lines.push(`- **${idx.name}**: ${idx.fields.join(', ')}${unique}`);
469
+ }
470
+ lines.push('');
471
+ }
472
+ }
473
+
474
+ return {
475
+ path: `${this.options.outputDir}/models.md`,
476
+ content: lines.join('\n'),
477
+ type: 'model',
478
+ };
479
+ }
480
+
481
+ /**
482
+ * Generate components documentation
483
+ */
484
+ private generateComponentsDoc(components: PSFComponent[]): GeneratedDoc {
485
+ const lines: string[] = [];
486
+
487
+ lines.push('# UI Components');
488
+ lines.push('');
489
+
490
+ for (const comp of components) {
491
+ lines.push(`## ${comp.name}`);
492
+ lines.push('');
493
+ lines.push(`**Type**: ${comp.type}`);
494
+ lines.push('');
495
+
496
+ if (comp.description) {
497
+ lines.push(comp.description);
498
+ lines.push('');
499
+ }
500
+
501
+ if (comp.model) {
502
+ lines.push(`**Bound Model**: \`${comp.model}\``);
503
+ lines.push('');
504
+ }
505
+
506
+ // Props
507
+ if (comp.props.length > 0) {
508
+ lines.push('### Props');
509
+ lines.push('');
510
+ lines.push('| Prop | Type | Required | Description |');
511
+ lines.push('| ---- | ---- | -------- | ----------- |');
512
+ for (const prop of comp.props) {
513
+ const required = prop.required ? 'Yes' : 'No';
514
+ const desc = prop.description || '-';
515
+ lines.push(`| \`${prop.name}\` | \`${prop.type}\` | ${required} | ${desc} |`);
516
+ }
517
+ lines.push('');
518
+ }
519
+
520
+ // Events
521
+ if (comp.events.length > 0) {
522
+ lines.push('### Events');
523
+ lines.push('');
524
+ for (const event of comp.events) {
525
+ lines.push(`- **${event.name}**${event.payload ? `: ${event.payload}` : ''}`);
526
+ if (event.description) {
527
+ lines.push(` - ${event.description}`);
528
+ }
529
+ }
530
+ lines.push('');
531
+ }
532
+ }
533
+
534
+ return {
535
+ path: `${this.options.outputDir}/components.md`,
536
+ content: lines.join('\n'),
537
+ type: 'component',
538
+ };
539
+ }
540
+
541
+ /**
542
+ * Generate flows documentation
543
+ */
544
+ private generateFlowsDoc(flows: PSFFlow[]): GeneratedDoc {
545
+ const lines: string[] = [];
546
+
547
+ lines.push('# Flows & Orchestration');
548
+ lines.push('');
549
+
550
+ for (const flow of flows) {
551
+ lines.push(`## ${flow.name}`);
552
+ lines.push('');
553
+ lines.push(`**Type**: ${flow.type}`);
554
+ lines.push('');
555
+
556
+ if (flow.description) {
557
+ lines.push(flow.description);
558
+ lines.push('');
559
+ }
560
+
561
+ if (flow.initial) {
562
+ lines.push(`**Initial Step**: \`${flow.initial}\``);
563
+ lines.push('');
564
+ }
565
+
566
+ // Steps
567
+ if (flow.steps.length > 0) {
568
+ lines.push('### Steps');
569
+ lines.push('');
570
+ for (const step of flow.steps) {
571
+ lines.push(`#### ${step.name || step.id}`);
572
+ lines.push('');
573
+ lines.push(`- **ID**: \`${step.id}\``);
574
+ lines.push(`- **Type**: ${step.type}`);
575
+
576
+ if (step.next) {
577
+ if (typeof step.next === 'string') {
578
+ lines.push(`- **Next**: \`${step.next}\``);
579
+ } else {
580
+ lines.push('- **Next**:');
581
+ for (const [condition, target] of Object.entries(step.next)) {
582
+ lines.push(` - \`${condition}\` → \`${target}\``);
583
+ }
584
+ }
585
+ }
586
+ lines.push('');
587
+ }
588
+ }
589
+ }
590
+
591
+ return {
592
+ path: `${this.options.outputDir}/flows.md`,
593
+ content: lines.join('\n'),
594
+ type: 'flow',
595
+ };
596
+ }
597
+
598
+ /**
599
+ * Generate Mermaid diagrams
600
+ */
601
+ private generateDiagrams(schema: PSFSchema): GeneratedDoc {
602
+ const lines: string[] = [];
603
+
604
+ lines.push('# Architecture Diagrams');
605
+ lines.push('');
606
+
607
+ // Entity Relationship Diagram
608
+ lines.push('## Data Model Diagram');
609
+ lines.push('');
610
+ lines.push('```mermaid');
611
+ lines.push('erDiagram');
612
+ for (const model of schema.models) {
613
+ for (const rel of model.relationships || []) {
614
+ const cardinalityMap: Record<string, string> = {
615
+ 'one-to-one': '||--||',
616
+ 'one-to-many': '||--o{',
617
+ 'many-to-many': '}o--o{',
618
+ };
619
+ const cardinality = cardinalityMap[rel.type] || '||--||';
620
+ lines.push(` ${model.name} ${cardinality} ${rel.target} : "${rel.name}"`);
621
+ }
622
+ }
623
+ for (const model of schema.models) {
624
+ lines.push(` ${model.name} {`);
625
+ for (const field of model.fields) {
626
+ const type = this.formatFieldTypeSimple(field.type);
627
+ lines.push(` ${type} ${field.name}`);
628
+ }
629
+ lines.push(' }');
630
+ }
631
+ lines.push('```');
632
+ lines.push('');
633
+
634
+ // Event Flow Diagram
635
+ if (schema.rules.length > 0) {
636
+ lines.push('## Event Flow Diagram');
637
+ lines.push('');
638
+ lines.push('```mermaid');
639
+ lines.push('flowchart LR');
640
+
641
+ for (const rule of schema.rules) {
642
+ const ruleNode = `rule_${this.sanitizeId(rule.id)}`;
643
+ lines.push(` ${ruleNode}["${rule.name || rule.id}"]`);
644
+
645
+ if (rule.triggers) {
646
+ for (const trigger of rule.triggers) {
647
+ lines.push(` event_${trigger}((${trigger})) --> ${ruleNode}`);
648
+ }
649
+ }
650
+ }
651
+
652
+ lines.push('```');
653
+ lines.push('');
654
+ }
655
+
656
+ // Component Diagram
657
+ if (schema.components.length > 0) {
658
+ lines.push('## Component Diagram');
659
+ lines.push('');
660
+ lines.push('```mermaid');
661
+ lines.push('flowchart TB');
662
+ lines.push(' subgraph UI[UI Layer]');
663
+ for (const comp of schema.components) {
664
+ lines.push(` ${comp.name}[${comp.name}]`);
665
+ }
666
+ lines.push(' end');
667
+ lines.push(' subgraph Data[Data Layer]');
668
+ for (const model of schema.models) {
669
+ lines.push(` ${model.name}[(${model.name})]`);
670
+ }
671
+ lines.push(' end');
672
+
673
+ // Bindings
674
+ for (const comp of schema.components) {
675
+ if (comp.model) {
676
+ lines.push(` ${comp.name} --> ${comp.model}`);
677
+ }
678
+ }
679
+
680
+ lines.push('```');
681
+ lines.push('');
682
+ }
683
+
684
+ return {
685
+ path: `${this.options.outputDir}/diagrams.md`,
686
+ content: lines.join('\n'),
687
+ type: 'diagram',
688
+ };
689
+ }
690
+
691
+ /**
692
+ * Generate index document
693
+ */
694
+ private generateIndex(schema: PSFSchema, files: GeneratedDoc[]): GeneratedDoc {
695
+ const lines: string[] = [];
696
+
697
+ lines.push(`# ${schema.name} Documentation`);
698
+ lines.push('');
699
+
700
+ if (schema.description) {
701
+ lines.push(schema.description);
702
+ lines.push('');
703
+ }
704
+
705
+ lines.push('## Documentation');
706
+ lines.push('');
707
+
708
+ const docLinks: Record<string, { title: string; desc: string }> = {
709
+ overview: { title: 'Overview', desc: 'Project overview and introduction' },
710
+ api: { title: 'API Reference', desc: 'Facts, events, rules, and constraints' },
711
+ model: { title: 'Data Models', desc: 'Entity definitions and relationships' },
712
+ component: { title: 'UI Components', desc: 'Component documentation' },
713
+ flow: { title: 'Flows', desc: 'Orchestration and workflows' },
714
+ diagram: { title: 'Diagrams', desc: 'Architecture and flow diagrams' },
715
+ };
716
+
717
+ for (const file of files) {
718
+ if (file.type === 'index') continue;
719
+ const link = docLinks[file.type];
720
+ if (link) {
721
+ const relativePath = file.path.replace(`${this.options.outputDir}/`, '');
722
+ lines.push(`- [${link.title}](${relativePath}) - ${link.desc}`);
723
+ }
724
+ }
725
+
726
+ lines.push('');
727
+ lines.push('---');
728
+ lines.push('');
729
+ lines.push(`Generated from PSF Schema v${schema.$version}`);
730
+
731
+ return {
732
+ path: `${this.options.outputDir}/README.md`,
733
+ content: lines.join('\n'),
734
+ type: 'index',
735
+ };
736
+ }
737
+
738
+ /**
739
+ * Format field type for display
740
+ */
741
+ private formatFieldType(type: PSFFieldType | string): string {
742
+ if (typeof type === 'string') return type;
743
+ if ('array' in type) return `${this.formatFieldType(type.array)}[]`;
744
+ if ('reference' in type) return type.reference;
745
+ if ('enum' in type) return type.enum.join(' | ');
746
+ if ('union' in type) return type.union.map((t) => this.formatFieldType(t)).join(' | ');
747
+ return 'object';
748
+ }
749
+
750
+ /**
751
+ * Format field type simple (for Mermaid)
752
+ */
753
+ private formatFieldTypeSimple(type: PSFFieldType): string {
754
+ if (typeof type === 'string') return type;
755
+ if ('array' in type) return 'array';
756
+ if ('reference' in type) return 'ref';
757
+ if ('enum' in type) return 'enum';
758
+ return 'object';
759
+ }
760
+
761
+ /**
762
+ * Get example value for type
763
+ */
764
+ private getExampleValue(type: PSFFieldType | string): string {
765
+ if (typeof type === 'string') {
766
+ switch (type) {
767
+ case 'string':
768
+ return '"example"';
769
+ case 'number':
770
+ return '42';
771
+ case 'boolean':
772
+ return 'true';
773
+ case 'date':
774
+ case 'datetime':
775
+ return 'new Date()';
776
+ case 'uuid':
777
+ return '"550e8400-e29b-41d4-a716-446655440000"';
778
+ default:
779
+ return 'null';
780
+ }
781
+ }
782
+ if ('array' in type) return '[]';
783
+ if ('enum' in type && type.enum.length > 0) return `"${type.enum[0]}"`;
784
+ return '{}';
785
+ }
786
+
787
+ /**
788
+ * Sanitize ID for Mermaid
789
+ */
790
+ private sanitizeId(id: string): string {
791
+ return id.replace(/[^a-zA-Z0-9_]/g, '_');
792
+ }
793
+ }
794
+
795
+ /**
796
+ * Create a docs generator
797
+ */
798
+ export function createDocsGenerator(options?: DocsGeneratorOptions): DocsGenerator {
799
+ return new DocsGenerator(options);
800
+ }
801
+
802
+ /**
803
+ * Generate documentation from PSF schema (convenience function)
804
+ */
805
+ export function generateDocs(schema: PSFSchema, options?: DocsGeneratorOptions): DocsGenerationResult {
806
+ const generator = new DocsGenerator(options);
807
+ return generator.generate(schema);
808
+ }