spacefn-docs 0.0.0-stage → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/LICENSE +200 -0
  2. package/README.md +15 -2
  3. package/assets/reader.css +1131 -0
  4. package/assets/reader.js +324 -0
  5. package/content/1-getting-started.md +107 -0
  6. package/content/2-conventions.md +138 -0
  7. package/content/3-best-practices.md +68 -0
  8. package/content/4-folders/1-app/1-entry.md +48 -0
  9. package/content/4-folders/1-app/2-routes.md +92 -0
  10. package/content/4-folders/1-app/3-db.md +81 -0
  11. package/content/4-folders/1-app/4-queues.md +46 -0
  12. package/content/4-folders/1-app/5-crons.md +30 -0
  13. package/content/4-folders/1-app/6-assets.md +53 -0
  14. package/content/4-folders/1-app/7-durable-objects.md +60 -0
  15. package/content/4-folders/1-app/8-workflows.md +46 -0
  16. package/content/4-folders/1-app/index.md +43 -0
  17. package/content/4-folders/2-modules.md +71 -0
  18. package/content/4-folders/3-lib.md +60 -0
  19. package/content/4-folders/4-public.md +24 -0
  20. package/content/4-folders/5-docs.md +23 -0
  21. package/content/4-folders/6-configs.md +57 -0
  22. package/content/4-folders/7-space.md +34 -0
  23. package/content/4-folders/8-env.md +34 -0
  24. package/content/4-folders/9-package-json.md +37 -0
  25. package/content/4-folders/index.md +50 -0
  26. package/content/5-deployment/1-cloudflare.md +56 -0
  27. package/content/5-deployment/2-bun.md +68 -0
  28. package/content/5-deployment/3-infrastructure.md +67 -0
  29. package/content/5-deployment/4-ci-cd.md +131 -0
  30. package/content/5-deployment/index.md +48 -0
  31. package/content/6-guides/1-entry.md +113 -0
  32. package/content/6-guides/2-routes.md +162 -0
  33. package/content/6-guides/3-pages.md +148 -0
  34. package/content/6-guides/4-frontend.md +232 -0
  35. package/content/6-guides/5-database.md +178 -0
  36. package/content/6-guides/6-services.md +125 -0
  37. package/content/6-guides/7-jobs.md +61 -0
  38. package/content/6-guides/8-auth.md +111 -0
  39. package/content/6-guides/9-testing.md +70 -0
  40. package/content/6-guides/index.md +21 -0
  41. package/content/7-reference/1-config.md +67 -0
  42. package/content/7-reference/2-cli.md +27 -0
  43. package/content/7-reference/3-writing-docs.md +206 -0
  44. package/content/7-reference/index.md +15 -0
  45. package/content/index.md +49 -0
  46. package/content/logo.svg +12 -0
  47. package/dist/index.d.mts +72 -0
  48. package/dist/index.mjs +713 -0
  49. package/examples/README.md +18 -0
  50. package/examples/datastar/.env.example +2 -0
  51. package/examples/datastar/README.md +17 -0
  52. package/examples/datastar/app/assets/main.ts +4 -0
  53. package/examples/datastar/app/assets/site.css +3 -0
  54. package/examples/datastar/app/db/main/config.json +5 -0
  55. package/examples/datastar/app/db/main/migrations/0001_votes.sql +8 -0
  56. package/examples/datastar/app/db/main/queries/add-vote.sql +3 -0
  57. package/examples/datastar/app/db/main/queries/tally.sql +1 -0
  58. package/examples/datastar/app/entry.ts +28 -0
  59. package/examples/datastar/app/routes/_middleware.ts +4 -0
  60. package/examples/datastar/app/routes/health.ts +7 -0
  61. package/examples/datastar/app/routes/index.ts +43 -0
  62. package/examples/datastar/configs/env.ts +6 -0
  63. package/examples/datastar/configs/infra.ts +85 -0
  64. package/examples/datastar/configs/tsconfig.json +15 -0
  65. package/examples/datastar/configs/vite.ts +4 -0
  66. package/examples/datastar/configs/vitest.ts +9 -0
  67. package/examples/datastar/lib/types/rocket.d.ts +30 -0
  68. package/examples/datastar/lib/ui/base.css +17 -0
  69. package/examples/datastar/lib/ui/layout.ts +27 -0
  70. package/examples/datastar/modules/poll/client/poll-meter.ts +39 -0
  71. package/examples/datastar/modules/poll/poll.css +13 -0
  72. package/examples/datastar/modules/poll/poll.test.ts +48 -0
  73. package/examples/datastar/modules/poll/poll.ts +62 -0
  74. package/examples/datastar/modules/poll/views.ts +52 -0
  75. package/examples/datastar/package.json +33 -0
  76. package/examples/datastar/tsconfig.json +4 -0
  77. package/examples/lightningcss/.env.example +1 -0
  78. package/examples/lightningcss/README.md +15 -0
  79. package/examples/lightningcss/app/assets/site.css +3 -0
  80. package/examples/lightningcss/app/entry.ts +28 -0
  81. package/examples/lightningcss/app/routes/_middleware.ts +4 -0
  82. package/examples/lightningcss/app/routes/health.ts +7 -0
  83. package/examples/lightningcss/app/routes/index.ts +12 -0
  84. package/examples/lightningcss/configs/Dockerfile +26 -0
  85. package/examples/lightningcss/configs/Dockerfile.dockerignore +9 -0
  86. package/examples/lightningcss/configs/env.ts +4 -0
  87. package/examples/lightningcss/configs/infra.ts +55 -0
  88. package/examples/lightningcss/configs/tsconfig.json +15 -0
  89. package/examples/lightningcss/configs/vite.ts +19 -0
  90. package/examples/lightningcss/configs/vitest.ts +9 -0
  91. package/examples/lightningcss/lib/ui/layout.ts +17 -0
  92. package/examples/lightningcss/lib/ui/tokens.css +23 -0
  93. package/examples/lightningcss/modules/releases/releases.css +20 -0
  94. package/examples/lightningcss/modules/releases/releases.test.ts +18 -0
  95. package/examples/lightningcss/modules/releases/releases.ts +21 -0
  96. package/examples/lightningcss/modules/releases/views.ts +25 -0
  97. package/examples/lightningcss/package.json +33 -0
  98. package/examples/lightningcss/tsconfig.json +4 -0
  99. package/examples/mini-shopify/.env.example +6 -0
  100. package/examples/mini-shopify/README.md +19 -0
  101. package/examples/mini-shopify/app/assets/site.css +2 -0
  102. package/examples/mini-shopify/app/db/platform/config.json +5 -0
  103. package/examples/mini-shopify/app/db/platform/migrations/0001_shops.sql +10 -0
  104. package/examples/mini-shopify/app/db/platform/queries/add-shop.sql +4 -0
  105. package/examples/mini-shopify/app/db/platform/queries/find-shop.sql +3 -0
  106. package/examples/mini-shopify/app/db/platform/queries/list-shops.sql +1 -0
  107. package/examples/mini-shopify/app/db/shop/config.json +6 -0
  108. package/examples/mini-shopify/app/db/shop/migrations/0001_products.sql +11 -0
  109. package/examples/mini-shopify/app/db/shop/queries/add-product.sql +4 -0
  110. package/examples/mini-shopify/app/db/shop/queries/list-products.sql +1 -0
  111. package/examples/mini-shopify/app/db/shop/queries/sell-product.sql +2 -0
  112. package/examples/mini-shopify/app/entry.ts +25 -0
  113. package/examples/mini-shopify/app/routes/_middleware.ts +4 -0
  114. package/examples/mini-shopify/app/routes/health.ts +7 -0
  115. package/examples/mini-shopify/app/routes/index.ts +26 -0
  116. package/examples/mini-shopify/app/routes/s/[shop]/_middleware.ts +6 -0
  117. package/examples/mini-shopify/app/routes/s/[shop]/index.ts +32 -0
  118. package/examples/mini-shopify/configs/Dockerfile +26 -0
  119. package/examples/mini-shopify/configs/Dockerfile.dockerignore +9 -0
  120. package/examples/mini-shopify/configs/env.ts +14 -0
  121. package/examples/mini-shopify/configs/infra.ts +55 -0
  122. package/examples/mini-shopify/configs/tsconfig.json +15 -0
  123. package/examples/mini-shopify/configs/vite.ts +4 -0
  124. package/examples/mini-shopify/configs/vitest.ts +9 -0
  125. package/examples/mini-shopify/lib/ui/base.css +19 -0
  126. package/examples/mini-shopify/lib/ui/layout.ts +17 -0
  127. package/examples/mini-shopify/modules/catalog/catalog.ts +31 -0
  128. package/examples/mini-shopify/modules/catalog/views.ts +39 -0
  129. package/examples/mini-shopify/modules/shops/host.test.ts +38 -0
  130. package/examples/mini-shopify/modules/shops/host.ts +73 -0
  131. package/examples/mini-shopify/modules/shops/shops.test.ts +63 -0
  132. package/examples/mini-shopify/modules/shops/shops.ts +64 -0
  133. package/examples/mini-shopify/modules/shops/views.ts +28 -0
  134. package/examples/mini-shopify/package.json +35 -0
  135. package/examples/mini-shopify/tsconfig.json +4 -0
  136. package/examples/react/.env.example +2 -0
  137. package/examples/react/README.md +18 -0
  138. package/examples/react/app/assets/site.css +3 -0
  139. package/examples/react/app/entry.ts +28 -0
  140. package/examples/react/app/routes/_middleware.ts +4 -0
  141. package/examples/react/app/routes/about.ts +10 -0
  142. package/examples/react/app/routes/health.ts +7 -0
  143. package/examples/react/app/routes/index.ts +12 -0
  144. package/examples/react/configs/Dockerfile +26 -0
  145. package/examples/react/configs/Dockerfile.dockerignore +9 -0
  146. package/examples/react/configs/env.ts +6 -0
  147. package/examples/react/configs/infra.ts +55 -0
  148. package/examples/react/configs/tsconfig.json +16 -0
  149. package/examples/react/configs/vite.ts +7 -0
  150. package/examples/react/configs/vitest.ts +9 -0
  151. package/examples/react/lib/ui/base.css +12 -0
  152. package/examples/react/lib/ui/layout.ts +18 -0
  153. package/examples/react/modules/about/views.ts +8 -0
  154. package/examples/react/modules/shop/products.ts +18 -0
  155. package/examples/react/modules/shop/shop.css +13 -0
  156. package/examples/react/modules/shop/shop.test.ts +28 -0
  157. package/examples/react/modules/shop/shop.ts +13 -0
  158. package/examples/react/modules/shop/ui/Cart.island.tsx +31 -0
  159. package/examples/react/modules/shop/views.ts +16 -0
  160. package/examples/react/package.json +38 -0
  161. package/examples/react/tsconfig.json +4 -0
  162. package/examples/services-bun/README.md +10 -0
  163. package/examples/services-bun/app/assets/main.ts +4 -0
  164. package/examples/services-bun/app/assets/style.css +1 -0
  165. package/examples/services-bun/app/crons/nightly.ts +5 -0
  166. package/examples/services-bun/app/entry.ts +9 -0
  167. package/examples/services-bun/app/queues/jobs.ts +5 -0
  168. package/examples/services-bun/app/routes/index.ts +10 -0
  169. package/examples/services-bun/app/routes/runtime.ts +5 -0
  170. package/examples/services-bun/app/routes/send.ts +8 -0
  171. package/examples/services-bun/app/routes/version.ts +5 -0
  172. package/examples/services-bun/configs/Dockerfile +10 -0
  173. package/examples/services-bun/configs/Dockerfile.dockerignore +4 -0
  174. package/examples/services-bun/configs/infra.ts +28 -0
  175. package/examples/services-bun/configs/tsconfig.json +15 -0
  176. package/examples/services-bun/configs/vite.ts +4 -0
  177. package/examples/services-bun/lib/ui/base.css +3 -0
  178. package/examples/services-bun/lib/ui/layout.ts +13 -0
  179. package/examples/services-bun/modules/status/client/ready.ts +4 -0
  180. package/examples/services-bun/modules/status/status.ts +20 -0
  181. package/examples/services-bun/modules/status/views.ts +4 -0
  182. package/examples/services-bun/package.json +30 -0
  183. package/examples/services-bun/public/robots.txt +1 -0
  184. package/examples/services-bun/tsconfig.json +4 -0
  185. package/examples/services-cloudflare/README.md +9 -0
  186. package/examples/services-cloudflare/app/assets/main.ts +4 -0
  187. package/examples/services-cloudflare/app/crons/nightly.ts +5 -0
  188. package/examples/services-cloudflare/app/db/main/config.json +4 -0
  189. package/examples/services-cloudflare/app/db/main/migrations/0001_notes.sql +2 -0
  190. package/examples/services-cloudflare/app/db/main/queries/add-note.sql +1 -0
  191. package/examples/services-cloudflare/app/db/main/queries/count-notes.sql +3 -0
  192. package/examples/services-cloudflare/app/entry.ts +10 -0
  193. package/examples/services-cloudflare/app/queues/jobs.ts +5 -0
  194. package/examples/services-cloudflare/app/routes/files.ts +5 -0
  195. package/examples/services-cloudflare/app/routes/index.ts +10 -0
  196. package/examples/services-cloudflare/app/routes/limited.ts +7 -0
  197. package/examples/services-cloudflare/app/routes/send.ts +8 -0
  198. package/examples/services-cloudflare/configs/env.ts +3 -0
  199. package/examples/services-cloudflare/configs/infra.ts +85 -0
  200. package/examples/services-cloudflare/configs/tsconfig.json +15 -0
  201. package/examples/services-cloudflare/configs/vite.ts +4 -0
  202. package/examples/services-cloudflare/lib/ui/layout.ts +12 -0
  203. package/examples/services-cloudflare/modules/files/files.ts +9 -0
  204. package/examples/services-cloudflare/modules/status/client/ready.ts +4 -0
  205. package/examples/services-cloudflare/modules/status/status.ts +27 -0
  206. package/examples/services-cloudflare/modules/status/views.ts +8 -0
  207. package/examples/services-cloudflare/package.json +30 -0
  208. package/examples/services-cloudflare/public/robots.txt +1 -0
  209. package/examples/services-cloudflare/tsconfig.json +4 -0
  210. package/examples/solid/.env.example +2 -0
  211. package/examples/solid/README.md +18 -0
  212. package/examples/solid/app/assets/site.css +3 -0
  213. package/examples/solid/app/entry.ts +28 -0
  214. package/examples/solid/app/routes/_middleware.ts +4 -0
  215. package/examples/solid/app/routes/about.ts +10 -0
  216. package/examples/solid/app/routes/health.ts +7 -0
  217. package/examples/solid/app/routes/index.ts +12 -0
  218. package/examples/solid/configs/Dockerfile +26 -0
  219. package/examples/solid/configs/Dockerfile.dockerignore +9 -0
  220. package/examples/solid/configs/env.ts +6 -0
  221. package/examples/solid/configs/infra.ts +55 -0
  222. package/examples/solid/configs/tsconfig.json +17 -0
  223. package/examples/solid/configs/vite.ts +7 -0
  224. package/examples/solid/configs/vitest.ts +12 -0
  225. package/examples/solid/lib/ui/base.css +12 -0
  226. package/examples/solid/lib/ui/layout.ts +18 -0
  227. package/examples/solid/modules/about/views.ts +8 -0
  228. package/examples/solid/modules/shop/products.ts +18 -0
  229. package/examples/solid/modules/shop/shop.css +13 -0
  230. package/examples/solid/modules/shop/shop.test.ts +28 -0
  231. package/examples/solid/modules/shop/shop.ts +13 -0
  232. package/examples/solid/modules/shop/ui/Cart.island.tsx +31 -0
  233. package/examples/solid/modules/shop/views.ts +16 -0
  234. package/examples/solid/package.json +35 -0
  235. package/examples/solid/tsconfig.json +4 -0
  236. package/examples/starter-bun/.env.example +2 -0
  237. package/examples/starter-bun/AGENTS.md +9 -0
  238. package/examples/starter-bun/README.md +47 -0
  239. package/examples/starter-bun/app/assets/site.css +3 -0
  240. package/examples/starter-bun/app/db/main/config.json +5 -0
  241. package/examples/starter-bun/app/db/main/migrations/0001_todos.sql +9 -0
  242. package/examples/starter-bun/app/db/main/queries/add-todo.sql +2 -0
  243. package/examples/starter-bun/app/db/main/queries/list-todos.sql +2 -0
  244. package/examples/starter-bun/app/db/main/queries/toggle-todo.sql +2 -0
  245. package/examples/starter-bun/app/entry.ts +28 -0
  246. package/examples/starter-bun/app/routes/_middleware.ts +4 -0
  247. package/examples/starter-bun/app/routes/health.ts +7 -0
  248. package/examples/starter-bun/app/routes/index.ts +44 -0
  249. package/examples/starter-bun/configs/Dockerfile +26 -0
  250. package/examples/starter-bun/configs/Dockerfile.dockerignore +9 -0
  251. package/examples/starter-bun/configs/env.ts +6 -0
  252. package/examples/starter-bun/configs/infra.ts +55 -0
  253. package/examples/starter-bun/configs/tsconfig.json +15 -0
  254. package/examples/starter-bun/configs/vite.ts +4 -0
  255. package/examples/starter-bun/configs/vitest.ts +9 -0
  256. package/examples/starter-bun/docs/index.md +5 -0
  257. package/examples/starter-bun/lib/ui/base.css +17 -0
  258. package/examples/starter-bun/lib/ui/layout.ts +22 -0
  259. package/examples/starter-bun/modules/todos/todos.css +16 -0
  260. package/examples/starter-bun/modules/todos/todos.test.ts +33 -0
  261. package/examples/starter-bun/modules/todos/todos.ts +31 -0
  262. package/examples/starter-bun/modules/todos/views.ts +38 -0
  263. package/examples/starter-bun/package.json +32 -0
  264. package/examples/starter-bun/public/favicon.svg +1 -0
  265. package/examples/starter-bun/tsconfig.json +4 -0
  266. package/examples/starter-cloudflare/.env.example +2 -0
  267. package/examples/starter-cloudflare/AGENTS.md +9 -0
  268. package/examples/starter-cloudflare/README.md +47 -0
  269. package/examples/starter-cloudflare/app/assets/site.css +3 -0
  270. package/examples/starter-cloudflare/app/db/main/config.json +5 -0
  271. package/examples/starter-cloudflare/app/db/main/migrations/0001_todos.sql +9 -0
  272. package/examples/starter-cloudflare/app/db/main/queries/add-todo.sql +2 -0
  273. package/examples/starter-cloudflare/app/db/main/queries/list-todos.sql +2 -0
  274. package/examples/starter-cloudflare/app/db/main/queries/toggle-todo.sql +2 -0
  275. package/examples/starter-cloudflare/app/entry.ts +28 -0
  276. package/examples/starter-cloudflare/app/routes/_middleware.ts +4 -0
  277. package/examples/starter-cloudflare/app/routes/health.ts +7 -0
  278. package/examples/starter-cloudflare/app/routes/index.ts +44 -0
  279. package/examples/starter-cloudflare/configs/env.ts +6 -0
  280. package/examples/starter-cloudflare/configs/infra.ts +85 -0
  281. package/examples/starter-cloudflare/configs/tsconfig.json +15 -0
  282. package/examples/starter-cloudflare/configs/vite.ts +4 -0
  283. package/examples/starter-cloudflare/configs/vitest.ts +9 -0
  284. package/examples/starter-cloudflare/docs/index.md +5 -0
  285. package/examples/starter-cloudflare/lib/ui/base.css +17 -0
  286. package/examples/starter-cloudflare/lib/ui/layout.ts +22 -0
  287. package/examples/starter-cloudflare/modules/todos/todos.css +16 -0
  288. package/examples/starter-cloudflare/modules/todos/todos.test.ts +33 -0
  289. package/examples/starter-cloudflare/modules/todos/todos.ts +31 -0
  290. package/examples/starter-cloudflare/modules/todos/views.ts +38 -0
  291. package/examples/starter-cloudflare/package.json +32 -0
  292. package/examples/starter-cloudflare/public/favicon.svg +1 -0
  293. package/examples/starter-cloudflare/tsconfig.json +4 -0
  294. package/examples/svelte/.env.example +2 -0
  295. package/examples/svelte/README.md +18 -0
  296. package/examples/svelte/app/assets/site.css +3 -0
  297. package/examples/svelte/app/entry.ts +28 -0
  298. package/examples/svelte/app/routes/_middleware.ts +4 -0
  299. package/examples/svelte/app/routes/about.ts +10 -0
  300. package/examples/svelte/app/routes/health.ts +7 -0
  301. package/examples/svelte/app/routes/index.ts +12 -0
  302. package/examples/svelte/configs/env.ts +6 -0
  303. package/examples/svelte/configs/infra.ts +85 -0
  304. package/examples/svelte/configs/tsconfig.json +15 -0
  305. package/examples/svelte/configs/vite.ts +9 -0
  306. package/examples/svelte/configs/vitest.ts +9 -0
  307. package/examples/svelte/lib/types/svelte.d.ts +8 -0
  308. package/examples/svelte/lib/ui/base.css +12 -0
  309. package/examples/svelte/lib/ui/layout.ts +18 -0
  310. package/examples/svelte/modules/about/views.ts +8 -0
  311. package/examples/svelte/modules/shop/products.ts +18 -0
  312. package/examples/svelte/modules/shop/shop.css +13 -0
  313. package/examples/svelte/modules/shop/shop.test.ts +28 -0
  314. package/examples/svelte/modules/shop/shop.ts +13 -0
  315. package/examples/svelte/modules/shop/ui/Cart.island.svelte +23 -0
  316. package/examples/svelte/modules/shop/views.ts +16 -0
  317. package/examples/svelte/package.json +35 -0
  318. package/examples/svelte/tsconfig.json +4 -0
  319. package/examples/tailwind/.env.example +2 -0
  320. package/examples/tailwind/README.md +16 -0
  321. package/examples/tailwind/app/assets/site.css +2 -0
  322. package/examples/tailwind/app/entry.ts +28 -0
  323. package/examples/tailwind/app/routes/_middleware.ts +4 -0
  324. package/examples/tailwind/app/routes/health.ts +7 -0
  325. package/examples/tailwind/app/routes/index.ts +30 -0
  326. package/examples/tailwind/configs/Dockerfile +26 -0
  327. package/examples/tailwind/configs/Dockerfile.dockerignore +9 -0
  328. package/examples/tailwind/configs/env.ts +6 -0
  329. package/examples/tailwind/configs/infra.ts +55 -0
  330. package/examples/tailwind/configs/tsconfig.json +15 -0
  331. package/examples/tailwind/configs/vite.ts +7 -0
  332. package/examples/tailwind/configs/vitest.ts +9 -0
  333. package/examples/tailwind/lib/ui/components.ts +21 -0
  334. package/examples/tailwind/lib/ui/layout.ts +21 -0
  335. package/examples/tailwind/lib/ui/theme.css +10 -0
  336. package/examples/tailwind/modules/team/team.test.ts +30 -0
  337. package/examples/tailwind/modules/team/team.ts +34 -0
  338. package/examples/tailwind/modules/team/views.ts +45 -0
  339. package/examples/tailwind/package.json +35 -0
  340. package/examples/tailwind/tsconfig.json +4 -0
  341. package/examples/vue/.env.example +2 -0
  342. package/examples/vue/README.md +18 -0
  343. package/examples/vue/app/assets/site.css +3 -0
  344. package/examples/vue/app/entry.ts +28 -0
  345. package/examples/vue/app/routes/_middleware.ts +4 -0
  346. package/examples/vue/app/routes/about.ts +10 -0
  347. package/examples/vue/app/routes/health.ts +7 -0
  348. package/examples/vue/app/routes/index.ts +12 -0
  349. package/examples/vue/configs/env.ts +6 -0
  350. package/examples/vue/configs/infra.ts +85 -0
  351. package/examples/vue/configs/tsconfig.json +15 -0
  352. package/examples/vue/configs/vite.ts +7 -0
  353. package/examples/vue/configs/vitest.ts +9 -0
  354. package/examples/vue/lib/types/vue.d.ts +8 -0
  355. package/examples/vue/lib/ui/base.css +12 -0
  356. package/examples/vue/lib/ui/layout.ts +18 -0
  357. package/examples/vue/modules/about/views.ts +8 -0
  358. package/examples/vue/modules/shop/products.ts +18 -0
  359. package/examples/vue/modules/shop/shop.css +13 -0
  360. package/examples/vue/modules/shop/shop.test.ts +28 -0
  361. package/examples/vue/modules/shop/shop.ts +13 -0
  362. package/examples/vue/modules/shop/ui/Cart.island.vue +27 -0
  363. package/examples/vue/modules/shop/views.ts +16 -0
  364. package/examples/vue/package.json +35 -0
  365. package/examples/vue/tsconfig.json +4 -0
  366. package/package.json +44 -3
@@ -0,0 +1,18 @@
1
+ # Examples
2
+
3
+ Apps that show spacefn's conventions in full: `app/` only wires, the code is in `modules/<feature>/` and `lib/`. Each one is tested in the repo, and ships in `spacefn-docs` (`node_modules/spacefn-docs/examples/`) at the version you have installed.
4
+
5
+ | Example | Target | What it shows |
6
+ | --------------------- | ---------- | ------------------------------------------------------------------------------------ |
7
+ | `starter-cloudflare` | Cloudflare | What `npm create spacefn` makes: todos with D1, a live list with Datastar |
8
+ | `starter-bun` | Bun | The same app on Bun, deployed to Docker |
9
+ | `services-cloudflare` | Cloudflare | Every binding a deploy creates in use: D1, KV, R2, a queue, a cron, the rate limiter |
10
+ | `services-bun` | Bun | KV, a queue, a cron, `public/` and the client build, deployed to Docker |
11
+ | `datastar` | Cloudflare | A live poll: html components with fixed ids, signals under `poll.`, a Rocket element |
12
+ | `tailwind` | Bun | Tailwind v4: design tokens in `@theme`, a UI kit in `lib/ui/`, a live search |
13
+ | `lightningcss` | Bun | Plain CSS through Lightning CSS: nesting, custom media, `light-dark()`, lowered |
14
+ | `react`, `solid` | Bun | A client-only cart island on a server-rendered page, loaded by one page only |
15
+ | `vue`, `svelte` | Cloudflare | The same island with Vue and Svelte single-file components |
16
+ | `mini-shopify` | Bun | A database per shop: created with Turso's Platform API, opened per request |
17
+
18
+ In the repo, `pnpm examples` remakes the starters from the `create-spacefn` template, and `pnpm install` gives every example the workspace's packages. Run one with `cd examples/<name> && pnpm dev`.
@@ -0,0 +1,2 @@
1
+ # Copy to .env for local dev. Deploys read .env.<stage> (e.g. .env.prod) or the environment.
2
+ QUESTION=Tabs or spaces?
@@ -0,0 +1,17 @@
1
+ # datastar
2
+
3
+ A live poll with [Datastar](https://data-star.dev), on Cloudflare: vote in one tab and the results move in every open tab.
4
+
5
+ ```sh
6
+ pnpm dev # alchemy dev
7
+ pnpm test
8
+ ```
9
+
10
+ What it shows:
11
+
12
+ - **Components** are functions from plain props to `html`, in `modules/poll/views.ts`. One that Datastar patches has a fixed `id`, exported beside it (`results.id`), so the page and the live updates can't drift apart.
13
+ - **Signals** live under the feature's name: `data-signals="{poll: {choice: '', voted: ''}}"`, read as `$poll.choice`. Two features on one page don't collide.
14
+ - **Actions**: the ballot's buttons `@post` the signals to the page's `vote` action, which decodes them with a Schema and answers with `Datastar.patchSignals`. The `live` action keeps the results current with `Datastar.watch` over the Bus.
15
+ - **Custom elements** with Rocket, Datastar's web component API: `<poll-meter>` in `modules/poll/client/poll-meter.ts`, registered by the `app/assets/main.ts` entry. Rocket is in beta and comes in the `datastar-rocket.js` bundle, which this example loads from the CDN in place of `datastar.js`; nothing of it is copied into the app. `lib/types/rocket.d.ts` types that import for every component in the app. Check its license before you ship it.
16
+
17
+ `app/` only wires: the page connects `modules/poll/`, and `lib/ui/` has the layout and base styles.
@@ -0,0 +1,4 @@
1
+ // The browser entry, loaded by assets("main"): it registers the custom elements the pages use.
2
+ import { definePollMeter } from "#modules/poll/client/poll-meter.ts";
3
+
4
+ definePollMeter();
@@ -0,0 +1,3 @@
1
+ /* The site's stylesheet, loaded by assets("site"): the shared base, then each feature's. */
2
+ @import "#lib/ui/base.css";
3
+ @import "#modules/poll/poll.css";
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "../../../node_modules/spacefn/schemas/db.json",
3
+ "driver": "d1",
4
+ "migrateOn": "startup"
5
+ }
@@ -0,0 +1,8 @@
1
+ -- up
2
+ CREATE TABLE votes (
3
+ choice TEXT PRIMARY KEY,
4
+ n INTEGER NOT NULL
5
+ );
6
+
7
+ -- down
8
+ DROP TABLE votes;
@@ -0,0 +1,3 @@
1
+ -- @param choice string
2
+ INSERT INTO votes (choice, n) VALUES (:choice, 1)
3
+ ON CONFLICT (choice) DO UPDATE SET n = n + 1;
@@ -0,0 +1 @@
1
+ SELECT choice, n FROM votes;
@@ -0,0 +1,28 @@
1
+ import { app, databases, errorPage, staticFiles, telemetry } from "spacefn";
2
+ import { platform } from "spacefn/platform";
3
+
4
+ import Env from "#configs/env.ts";
5
+ import { manifest } from "#space/manifest.ts";
6
+
7
+ // The app: the file conventions (manifest) and what runs with them. It's yours to change;
8
+ // spacefn only provides the pieces. The same file runs on Cloudflare and on Bun.
9
+ export default app(manifest, {
10
+ // In order: each can use the ones before it, and routes, pages, queues and crons use them all.
11
+ services: [
12
+ // This target's Kv, Blob, Queue, Bus, RateLimiter, HttpClient and database connections.
13
+ platform(manifest),
14
+ // configs/env.ts, read from the environment.
15
+ Env.layer,
16
+ // app/db/*, migrated as each config.json says.
17
+ databases(manifest),
18
+ // Traces, logs and metrics over OTLP, once OTEL_EXPORTER_OTLP_ENDPOINT is set.
19
+ telemetry(manifest.name),
20
+ ],
21
+ // Around every request, before app/routes/_middleware.ts. staticFiles() serves the client
22
+ // build on Bun; Cloudflare serves it as assets before the Worker runs.
23
+ before: [staticFiles()],
24
+ // Effect HttpRouter layers beside the file routes, e.g. an HttpApi.
25
+ routes: [],
26
+ // What a failed request answers: an HTML page for browsers, JSON for the rest.
27
+ onError: errorPage,
28
+ });
@@ -0,0 +1,4 @@
1
+ import { csrf } from "spacefn";
2
+
3
+ // Refuses cross-site form posts and Datastar requests.
4
+ export default csrf();
@@ -0,0 +1,7 @@
1
+ import { Effect } from "effect";
2
+ import { route } from "spacefn";
3
+
4
+ // GET /health answers JSON, for uptime checks.
5
+ export default route({
6
+ GET: Effect.succeed({ ok: true }),
7
+ });
@@ -0,0 +1,43 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { action, Datastar, page } from "spacefn";
3
+
4
+ import { layout } from "#lib/ui/layout.ts";
5
+ import * as Poll from "#modules/poll/poll.ts";
6
+ import { pollPage, results } from "#modules/poll/views.ts";
7
+
8
+ // The poll at /. It only connects the poll module to the web.
9
+
10
+ export default page({
11
+ loader: Effect.all({ question: Poll.question, results: Poll.results }),
12
+ actions: {
13
+ // A Datastar @post: it answers with signals to patch, not a page.
14
+ vote: action({
15
+ input: Poll.Vote,
16
+ handler: ({ poll }) =>
17
+ Effect.andThen(
18
+ Poll.vote(poll.choice),
19
+ Datastar.sse([Datastar.patchSignals({ poll: { voted: poll.choice } })]),
20
+ ),
21
+ }),
22
+ // Datastar opens this when the page loads, and gets the results again after each vote.
23
+ live: action({
24
+ method: "get",
25
+ input: Schema.Struct({}),
26
+ handler: () =>
27
+ Datastar.watch(
28
+ [Poll.TOPIC],
29
+ Effect.map(Poll.results, (all) => results({ results: all })),
30
+ ),
31
+ }),
32
+ },
33
+ render: (ctx) =>
34
+ layout(
35
+ ctx.data.question,
36
+ pollPage({
37
+ question: ctx.data.question,
38
+ vote: ctx.actions.vote.url,
39
+ live: ctx.actions.live.url,
40
+ results: ctx.data.results,
41
+ }),
42
+ ),
43
+ });
@@ -0,0 +1,6 @@
1
+ // Deploys import this file to learn which variables to pass on, so it imports only spacefn and effect.
2
+ import { defineEnv, Env } from "spacefn";
3
+
4
+ export default defineEnv({
5
+ QUESTION: Env.string({ default: "Tabs or spaces?" }),
6
+ });
@@ -0,0 +1,85 @@
1
+ // The app's infrastructure: a plain Alchemy stack. `space deploy` runs `alchemy deploy configs/infra.ts`.
2
+ import * as Cloudflare from "@alchemy.run/cloudflare";
3
+ import * as Alchemy from "alchemy";
4
+ import { Effect } from "effect";
5
+ import { variables } from "spacefn/infra";
6
+
7
+ import env from "#configs/env.ts";
8
+ // What the file conventions ask for (databases, queues, crons, ...), as plain data from app/.
9
+ import { app } from "#space/infra.ts";
10
+
11
+ export default Alchemy.Stack(
12
+ app.name,
13
+ {
14
+ providers: Cloudflare.providers(),
15
+ // Deploy state in your Cloudflare account, so CI and other machines share it. Local under `space dev`.
16
+ state: process.env.ALCHEMY_DEV ? Alchemy.localState() : Cloudflare.state(),
17
+ },
18
+ Effect.gen(function* () {
19
+ const stage = yield* Alchemy.Stage;
20
+ const bindings: Record<string, any> = {
21
+ // Kv and Blob. R2 must be enabled on the account; remove BLOB if the app doesn't use Blob.
22
+ KV: yield* Cloudflare.KV.Namespace("KV"),
23
+ BLOB: yield* Cloudflare.R2.Bucket("BLOB"),
24
+ // The Durable Objects behind Bus and RateLimiter.
25
+ SPACE_BUS: Cloudflare.DurableObject("SpaceBus"),
26
+ SPACE_RATE_LIMITER: Cloudflare.DurableObject("SpaceRateLimiter"),
27
+ // configs/env.ts's variables, from .env.<stage> or the environment; Env.secret ones as secrets.
28
+ ...variables(env),
29
+ ...variables({ OTEL_EXPORTER_OTLP_ENDPOINT: "plain", OTEL_EXPORTER_OTLP_HEADERS: "secret" }),
30
+ };
31
+
32
+ // app/db/<name>/: D1 here; a libSQL database reads DB_<NAME>_URL and DB_<NAME>_AUTH_TOKEN.
33
+ for (const db of app.databases)
34
+ if (db.driver === "d1") bindings[db.binding] = yield* Cloudflare.D1.Database(db.binding);
35
+ else if (db.driver === "libsql")
36
+ Object.assign(
37
+ bindings,
38
+ variables({ [`${db.binding}_URL`]: "plain", [`${db.binding}_AUTH_TOKEN`]: "secret" }),
39
+ );
40
+
41
+ // app/queues/<name>.ts: queue names are unique per account, so they carry the app and stage.
42
+ const prefix = `${app.name}-${stage}-`.toLowerCase();
43
+ bindings.SPACE_QUEUE_PREFIX = prefix;
44
+ const queues: { binding: string; queue: Cloudflare.Queues.Queue }[] = [];
45
+ for (const { name, binding } of app.queues) {
46
+ const queue = yield* Cloudflare.Queues.Queue(binding, { name: prefix + name });
47
+ bindings[binding] = queue;
48
+ queues.push({ binding, queue });
49
+ }
50
+
51
+ // app/durable-objects/ and app/workflows/.
52
+ for (const { className, binding } of app.durableObjects)
53
+ bindings[binding] = Cloudflare.DurableObject(className);
54
+ for (const { className, binding } of app.workflows)
55
+ bindings[binding] = Cloudflare.Workflow(className, { className });
56
+
57
+ const worker = yield* Cloudflare.Website.Vite("Worker", {
58
+ // Vite runs in .space/: its vite.config.ts is configs/vite.ts, and entry.ts runs app/entry.ts.
59
+ rootDir: ".space",
60
+ main: "./entry.ts",
61
+ crons: [...app.crons],
62
+ env: bindings,
63
+ // What a deploy hashes to tell whether to rebuild, from .space/.
64
+ memo: {
65
+ include: [
66
+ "**/*",
67
+ "../app/**",
68
+ "../configs/**",
69
+ "../package.json",
70
+ ...app.folders.map((folder) => `../${folder}/**`),
71
+ ],
72
+ exclude: ["data/**"],
73
+ lockfile: true,
74
+ },
75
+ });
76
+
77
+ for (const { binding, queue } of queues)
78
+ yield* Cloudflare.Queues.Consumer(`${binding}_CONSUMER`, {
79
+ queueId: queue.queueId,
80
+ scriptName: worker.workerName,
81
+ });
82
+
83
+ return { url: worker.url };
84
+ }),
85
+ );
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2022", "ESNext.Disposable", "DOM", "DOM.Iterable"],
5
+ "module": "preserve",
6
+ "moduleResolution": "bundler",
7
+ "allowImportingTsExtensions": true,
8
+ "verbatimModuleSyntax": true,
9
+ "strict": true,
10
+ "noEmit": true,
11
+ "skipLibCheck": true,
12
+ "types": []
13
+ },
14
+ "include": ["../app", "../lib", "../modules", "../configs"]
15
+ }
@@ -0,0 +1,4 @@
1
+ import { space } from "spacefn/vite";
2
+ import { defineConfig } from "vite";
3
+
4
+ export default defineConfig({ plugins: [space({ target: "cloudflare" })] });
@@ -0,0 +1,9 @@
1
+ import { defineConfig, mergeConfig } from "vitest/config";
2
+
3
+ import vite from "./vite.ts";
4
+
5
+ // The app's Vite config, so tests get the spacefn plugin (and spacefn/assets) too.
6
+ export default mergeConfig(
7
+ vite,
8
+ defineConfig({ test: { include: ["{app,lib,modules}/**/*.test.ts"] } }),
9
+ );
@@ -0,0 +1,30 @@
1
+ // The types this example uses of Datastar's Rocket bundle, which it loads from the
2
+ // CDN: Rocket is in beta, and its published types are at
3
+ // https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.5/bundles/datastar-rocket.d.ts.
4
+ declare module "https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.5/bundles/datastar-rocket.js" {
5
+ interface Codec<T> {
6
+ readonly default: (value: T) => Codec<T>;
7
+ }
8
+ interface StringCodec extends Codec<string> {
9
+ readonly trim: StringCodec;
10
+ }
11
+ interface NumberCodec extends Codec<number> {
12
+ readonly clamp: (min: number, max: number) => NumberCodec;
13
+ }
14
+ interface AnyCodec {
15
+ readonly default: (value: never) => unknown;
16
+ }
17
+ type Props<D> = { readonly [K in keyof D]: D[K] extends Codec<infer T> ? T : never };
18
+ export function rocket<D extends Record<string, AnyCodec>>(
19
+ tag: `${string}-${string}`,
20
+ options: {
21
+ readonly mode?: "open" | "closed" | "light";
22
+ readonly props?: (codecs: { string: StringCodec; number: NumberCodec }) => D;
23
+ readonly render?: (context: {
24
+ readonly html: (strings: TemplateStringsArray, ...values: unknown[]) => unknown;
25
+ readonly props: Props<D>;
26
+ readonly host: HTMLElement;
27
+ }) => unknown;
28
+ },
29
+ ): void;
30
+ }
@@ -0,0 +1,17 @@
1
+ /* The design tokens and base styles every page shares. */
2
+ :root {
3
+ --space: 0.5rem;
4
+ --measure: 32rem;
5
+ color-scheme: light dark;
6
+ font-family: system-ui, sans-serif;
7
+ }
8
+ body {
9
+ max-width: var(--measure);
10
+ margin: calc(var(--space) * 6) auto;
11
+ padding: 0 calc(var(--space) * 2);
12
+ line-height: 1.5;
13
+ }
14
+ form {
15
+ display: flex;
16
+ gap: var(--space);
17
+ }
@@ -0,0 +1,27 @@
1
+ import { html, type HtmlValue } from "spacefn";
2
+ import { assets } from "spacefn/assets";
3
+
4
+ /**
5
+ * Datastar with Rocket, from the CDN: the bundle includes Datastar, so it loads
6
+ * in place of datastar.js. app/assets/main.ts imports the same URL for `rocket`,
7
+ * and the browser runs it once.
8
+ */
9
+ const DATASTAR =
10
+ "https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.5/bundles/datastar-rocket.js";
11
+
12
+ /** The HTML around every page: its title, the site's styles, Datastar and the asset entry. */
13
+ export const layout = (title: string, body: HtmlValue) =>
14
+ html`<!doctype html>
15
+ <html lang="en">
16
+ <head>
17
+ <meta charset="utf-8" />
18
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
19
+ <title>${title}</title>
20
+ ${assets("site")}
21
+ <script type="module" src="${DATASTAR}"></script>
22
+ ${assets("main")}
23
+ </head>
24
+ <body>
25
+ ${body}
26
+ </body>
27
+ </html>`;
@@ -0,0 +1,39 @@
1
+ import { rocket } from "https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.5/bundles/datastar-rocket.js";
2
+
3
+ /**
4
+ * `<poll-meter label="Tabs" value="40">`: a labelled bar, `value` in percent.
5
+ * A Rocket custom element (beta): it renders in its own shadow root, and renders
6
+ * again when Datastar morphs new attributes in. Custom element names have a
7
+ * hyphen; start them with the feature's name.
8
+ */
9
+ export const definePollMeter = () =>
10
+ rocket("poll-meter", {
11
+ props: ({ number, string }) => ({
12
+ label: string.trim.default(""),
13
+ value: number.clamp(0, 100).default(0),
14
+ }),
15
+ render: ({ html, props: { label, value } }) => html`
16
+ <style>
17
+ :host {
18
+ display: grid;
19
+ grid-template-columns: 1fr 3rem;
20
+ gap: 0.25rem 0.5rem;
21
+ }
22
+ .bar {
23
+ grid-column: 1 / -1;
24
+ height: 0.5rem;
25
+ border-radius: 0.25rem;
26
+ background: color-mix(in srgb, currentColor 15%, transparent);
27
+ }
28
+ .fill {
29
+ height: 100%;
30
+ border-radius: inherit;
31
+ background: currentColor;
32
+ transition: width 0.3s;
33
+ }
34
+ </style>
35
+ <span>${label}</span>
36
+ <span>${value}%</span>
37
+ <span class="bar"><span class="fill" style="width: ${value}%"></span></span>
38
+ `,
39
+ });
@@ -0,0 +1,13 @@
1
+ /* The poll's own styles. <poll-meter> styles itself, in its shadow root. */
2
+ .ballot {
3
+ display: flex;
4
+ flex-wrap: wrap;
5
+ gap: var(--space);
6
+ }
7
+ .ballot .chosen {
8
+ outline: 2px solid currentColor;
9
+ }
10
+ .results {
11
+ padding: 0;
12
+ list-style: none;
13
+ }
@@ -0,0 +1,48 @@
1
+ import { Layer } from "effect";
2
+ import { memoryServices, testApp, testDb, testEnv } from "spacefn/testing";
3
+ import { describe, expect, it } from "vitest";
4
+
5
+ import Env from "#configs/env.ts";
6
+ import MainDb from "#space/db/main.ts";
7
+ import { manifest } from "#space/manifest.ts";
8
+
9
+ const app = () =>
10
+ testApp(
11
+ manifest,
12
+ Layer.mergeAll(testDb(MainDb), memoryServices, Env.layer.pipe(Layer.provide(testEnv({})))),
13
+ );
14
+
15
+ /** A vote as Datastar's @post sends it: the page's signals, as JSON. */
16
+ const vote = (choice: string) => ({
17
+ method: "POST",
18
+ headers: { "content-type": "application/json", "datastar-request": "true" },
19
+ body: JSON.stringify({ poll: { choice, voted: "" } }),
20
+ });
21
+
22
+ describe("the poll", () => {
23
+ it("shows the question, a button per answer and empty results", async () => {
24
+ await using poll = app();
25
+ const page = await (await poll.fetch("/")).text();
26
+ expect(page).toContain("<h1>Tabs or spaces?</h1>");
27
+ expect(page).toContain(`data-on:click="$poll.choice = 'tabs'; @post('?__action=vote')"`);
28
+ expect(page).toContain('<poll-meter label="Tabs" value="0"></poll-meter>');
29
+ });
30
+
31
+ it("counts a vote, answers with the signal to patch, and shows it in the results", async () => {
32
+ await using poll = app();
33
+ const answer = await poll.fetch("/?__action=vote", vote("tabs"));
34
+ expect(answer.headers.get("content-type")).toBe("text/event-stream");
35
+ expect(await answer.text()).toBe(
36
+ 'event: datastar-patch-signals\ndata: signals {"poll":{"voted":"tabs"}}\n\n',
37
+ );
38
+ await poll.fetch("/?__action=vote", vote("spaces"));
39
+ const page = await (await poll.fetch("/")).text();
40
+ expect(page).toContain('<poll-meter label="Tabs" value="50"></poll-meter>');
41
+ expect(page).toContain("<small>1 vote</small>");
42
+ });
43
+
44
+ it("refuses an answer that isn't one", async () => {
45
+ await using poll = app();
46
+ expect((await poll.fetch("/?__action=vote", vote("emacs"))).status).toBe(422);
47
+ });
48
+ });
@@ -0,0 +1,62 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Bus } from "spacefn";
3
+
4
+ import Env from "#configs/env.ts";
5
+ import MainDb from "#space/db/main.ts";
6
+
7
+ /** The Bus topic each vote is announced on. */
8
+ export const TOPIC = "poll";
9
+
10
+ /** The poll's question, from configs/env.ts. */
11
+ export const question = Effect.gen(function* () {
12
+ return (yield* Env).QUESTION;
13
+ });
14
+
15
+ /** The answers, by the id a vote sends. */
16
+ export const CHOICES = {
17
+ tabs: "Tabs",
18
+ spaces: "Spaces",
19
+ formatter: "Whatever the formatter says",
20
+ } as const;
21
+
22
+ export type Choice = keyof typeof CHOICES;
23
+
24
+ const choiceIds = Object.keys(CHOICES) as [Choice, ...Choice[]];
25
+
26
+ /**
27
+ * What a vote sends: Datastar's `@post` sends the page's signals as JSON, and
28
+ * this page keeps its own under `poll`.
29
+ */
30
+ export const Vote = Schema.Struct({
31
+ poll: Schema.Struct({ choice: Schema.Literals(choiceIds) }),
32
+ });
33
+
34
+ export interface Result {
35
+ readonly id: Choice;
36
+ readonly label: string;
37
+ readonly votes: number;
38
+ /** Of all votes, rounded. */
39
+ readonly percent: number;
40
+ }
41
+
42
+ /** Each answer with its votes, in the order of {@link CHOICES}. */
43
+ export const results: Effect.Effect<readonly Result[], unknown, MainDb> = Effect.map(
44
+ MainDb.tally(),
45
+ (rows) => {
46
+ const votes = new Map(rows.map((row) => [row.choice, row.n]));
47
+ const total = rows.reduce((sum, row) => sum + row.n, 0);
48
+ return choiceIds.map((id) => {
49
+ const n = votes.get(id) ?? 0;
50
+ return {
51
+ id,
52
+ label: CHOICES[id],
53
+ votes: n,
54
+ percent: total === 0 ? 0 : Math.round((n / total) * 100),
55
+ };
56
+ });
57
+ },
58
+ );
59
+
60
+ /** Counts a vote, and tells every open page. */
61
+ export const vote = (choice: Choice) =>
62
+ MainDb.addVote({ choice }).pipe(Effect.andThen(Bus.publish(TOPIC, "voted")));
@@ -0,0 +1,52 @@
1
+ import { html } from "spacefn";
2
+
3
+ import { CHOICES, type Result } from "./poll.ts";
4
+
5
+ // Components are functions from plain props to html. One that Datastar patches
6
+ // keeps a fixed id, exported beside it, and the page's signals live under `poll.`.
7
+
8
+ /** The page's signals: what was picked, and what the server counted. */
9
+ export const signals = `{poll: {choice: '', voted: ''}}`;
10
+
11
+ /** A button per answer. Clicking sets `$poll.choice` and posts the signals to `vote`. */
12
+ export const ballot = (props: { readonly vote: string }) =>
13
+ html`<div id="${ballot.id}" class="ballot">
14
+ ${Object.entries(CHOICES).map(
15
+ ([id, label]) =>
16
+ html`<button
17
+ type="button"
18
+ data-class:chosen="$poll.voted === '${id}'"
19
+ data-on:click="$poll.choice = '${id}'; @post('${props.vote}')"
20
+ >
21
+ ${label}
22
+ </button>`,
23
+ )}
24
+ </div>`;
25
+ ballot.id = "poll-ballot";
26
+
27
+ /** The results, as `<poll-meter>` elements. Datastar swaps the list in by its id after each vote. */
28
+ export const results = (props: { readonly results: readonly Result[] }) =>
29
+ html`<ol id="${results.id}" class="results">
30
+ ${props.results.map(
31
+ (result) =>
32
+ html`<li>
33
+ <poll-meter label="${result.label}" value="${result.percent}"></poll-meter>
34
+ <small>${result.votes} ${result.votes === 1 ? "vote" : "votes"}</small>
35
+ </li>`,
36
+ )}
37
+ </ol>`;
38
+ results.id = "poll-results";
39
+
40
+ /** The page's body: the question, the ballot, and the results, kept current by `live`. */
41
+ export const pollPage = (props: {
42
+ readonly question: string;
43
+ readonly vote: string;
44
+ readonly live: string;
45
+ readonly results: readonly Result[];
46
+ }) =>
47
+ html`<main data-signals="${signals}" data-init="@get('${props.live}')">
48
+ <h1>${props.question}</h1>
49
+ ${ballot({ vote: props.vote })}
50
+ <p data-show="$poll.voted !== ''">Thanks for voting.</p>
51
+ ${results({ results: props.results })}
52
+ </main>`;
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "datastar",
3
+ "private": true,
4
+ "description": "A live poll with Datastar: html components, namespaced signals, live updates over the Bus, and a Rocket custom element.",
5
+ "type": "module",
6
+ "imports": {
7
+ "#configs/*": "./configs/*",
8
+ "#lib/*": "./lib/*",
9
+ "#modules/*": "./modules/*",
10
+ "#space/*": "./.space/*"
11
+ },
12
+ "scripts": {
13
+ "postinstall": "space gen",
14
+ "dev": "space dev",
15
+ "build": "space build",
16
+ "deploy": "space deploy",
17
+ "docs": "space docs",
18
+ "test": "vitest run --config configs/vitest.ts",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "dependencies": {
22
+ "effect": "4.1.4",
23
+ "spacefn": "^0.11.0"
24
+ },
25
+ "devDependencies": {
26
+ "@alchemy.run/cloudflare": "2.0.0-beta.87",
27
+ "alchemy": "2.0.0-beta.87",
28
+ "spacefn-docs": "^0.11.0",
29
+ "typescript": "^7.0.2",
30
+ "vite": "8.3.8",
31
+ "vitest": "5.1.1"
32
+ }
33
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "//": "Editors and tsc look for this file here; the settings are in configs/tsconfig.json.",
3
+ "extends": "./configs/tsconfig.json"
4
+ }
@@ -0,0 +1 @@
1
+ # Copy to .env for local dev. Deploys read .env.<stage> (e.g. .env.prod) or the environment.
@@ -0,0 +1,15 @@
1
+ # lightningcss
2
+
3
+ Plain CSS through [Lightning CSS](https://lightningcss.dev) on a spacefn app (Bun): write today's CSS, and the build lowers it for the browsers you target.
4
+
5
+ ```sh
6
+ pnpm dev
7
+ pnpm test
8
+ pnpm build
9
+ ```
10
+
11
+ What it shows:
12
+
13
+ - **The config** is Vite's own, in `configs/vite.ts`: `css.transformer: "lightningcss"` with `targets`, and `drafts.customMedia`. No PostCSS, no plugin.
14
+ - **Tokens and breakpoints** in `lib/ui/tokens.css`: colors with `light-dark()`, and `@custom-media --narrow`, which every stylesheet can use because Lightning CSS bundles the `@import`s first.
15
+ - **Feature styles** next to the feature, `modules/releases/releases.css`, with nested rules. `app/assets/site.css` is only the entry that imports them, loaded with `assets("site")`.
@@ -0,0 +1,3 @@
1
+ /* The site's stylesheet, loaded by assets("site"): the tokens, then each feature's styles. */
2
+ @import "#lib/ui/tokens.css";
3
+ @import "#modules/releases/releases.css";