@fuzdev/fuz_app 0.1.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 (457) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -0
  3. package/dist/actions/action_bridge.d.ts +65 -0
  4. package/dist/actions/action_bridge.d.ts.map +1 -0
  5. package/dist/actions/action_bridge.js +76 -0
  6. package/dist/actions/action_codegen.d.ts +97 -0
  7. package/dist/actions/action_codegen.d.ts.map +1 -0
  8. package/dist/actions/action_codegen.js +280 -0
  9. package/dist/actions/action_registry.d.ts +35 -0
  10. package/dist/actions/action_registry.d.ts.map +1 -0
  11. package/dist/actions/action_registry.js +83 -0
  12. package/dist/actions/action_spec.d.ts +169 -0
  13. package/dist/actions/action_spec.d.ts.map +1 -0
  14. package/dist/actions/action_spec.js +76 -0
  15. package/dist/auth/account_queries.d.ts +96 -0
  16. package/dist/auth/account_queries.d.ts.map +1 -0
  17. package/dist/auth/account_queries.js +172 -0
  18. package/dist/auth/account_routes.d.ts +86 -0
  19. package/dist/auth/account_routes.d.ts.map +1 -0
  20. package/dist/auth/account_routes.js +406 -0
  21. package/dist/auth/account_schema.d.ts +192 -0
  22. package/dist/auth/account_schema.d.ts.map +1 -0
  23. package/dist/auth/account_schema.js +105 -0
  24. package/dist/auth/admin_routes.d.ts +29 -0
  25. package/dist/auth/admin_routes.d.ts.map +1 -0
  26. package/dist/auth/admin_routes.js +193 -0
  27. package/dist/auth/api_token.d.ts +33 -0
  28. package/dist/auth/api_token.d.ts.map +1 -0
  29. package/dist/auth/api_token.js +36 -0
  30. package/dist/auth/api_token_queries.d.ts +80 -0
  31. package/dist/auth/api_token_queries.d.ts.map +1 -0
  32. package/dist/auth/api_token_queries.js +116 -0
  33. package/dist/auth/app_settings_queries.d.ts +33 -0
  34. package/dist/auth/app_settings_queries.d.ts.map +1 -0
  35. package/dist/auth/app_settings_queries.js +51 -0
  36. package/dist/auth/app_settings_routes.d.ts +27 -0
  37. package/dist/auth/app_settings_routes.d.ts.map +1 -0
  38. package/dist/auth/app_settings_routes.js +66 -0
  39. package/dist/auth/app_settings_schema.d.ts +35 -0
  40. package/dist/auth/app_settings_schema.d.ts.map +1 -0
  41. package/dist/auth/app_settings_schema.js +22 -0
  42. package/dist/auth/audit_log_queries.d.ts +90 -0
  43. package/dist/auth/audit_log_queries.d.ts.map +1 -0
  44. package/dist/auth/audit_log_queries.js +205 -0
  45. package/dist/auth/audit_log_routes.d.ts +33 -0
  46. package/dist/auth/audit_log_routes.d.ts.map +1 -0
  47. package/dist/auth/audit_log_routes.js +106 -0
  48. package/dist/auth/audit_log_schema.d.ts +259 -0
  49. package/dist/auth/audit_log_schema.d.ts.map +1 -0
  50. package/dist/auth/audit_log_schema.js +123 -0
  51. package/dist/auth/bearer_auth.d.ts +32 -0
  52. package/dist/auth/bearer_auth.d.ts.map +1 -0
  53. package/dist/auth/bearer_auth.js +90 -0
  54. package/dist/auth/bootstrap_account.d.ts +82 -0
  55. package/dist/auth/bootstrap_account.d.ts.map +1 -0
  56. package/dist/auth/bootstrap_account.js +97 -0
  57. package/dist/auth/bootstrap_routes.d.ts +74 -0
  58. package/dist/auth/bootstrap_routes.d.ts.map +1 -0
  59. package/dist/auth/bootstrap_routes.js +154 -0
  60. package/dist/auth/daemon_token.d.ts +49 -0
  61. package/dist/auth/daemon_token.d.ts.map +1 -0
  62. package/dist/auth/daemon_token.js +49 -0
  63. package/dist/auth/daemon_token_middleware.d.ts +93 -0
  64. package/dist/auth/daemon_token_middleware.d.ts.map +1 -0
  65. package/dist/auth/daemon_token_middleware.js +167 -0
  66. package/dist/auth/ddl.d.ts +27 -0
  67. package/dist/auth/ddl.d.ts.map +1 -0
  68. package/dist/auth/ddl.js +111 -0
  69. package/dist/auth/deps.d.ts +52 -0
  70. package/dist/auth/deps.d.ts.map +1 -0
  71. package/dist/auth/deps.js +10 -0
  72. package/dist/auth/invite_queries.d.ts +68 -0
  73. package/dist/auth/invite_queries.d.ts.map +1 -0
  74. package/dist/auth/invite_queries.js +105 -0
  75. package/dist/auth/invite_routes.d.ts +18 -0
  76. package/dist/auth/invite_routes.d.ts.map +1 -0
  77. package/dist/auth/invite_routes.js +129 -0
  78. package/dist/auth/invite_schema.d.ts +51 -0
  79. package/dist/auth/invite_schema.d.ts.map +1 -0
  80. package/dist/auth/invite_schema.js +25 -0
  81. package/dist/auth/keyring.d.ts +87 -0
  82. package/dist/auth/keyring.d.ts.map +1 -0
  83. package/dist/auth/keyring.js +142 -0
  84. package/dist/auth/middleware.d.ts +40 -0
  85. package/dist/auth/middleware.d.ts.map +1 -0
  86. package/dist/auth/middleware.js +64 -0
  87. package/dist/auth/migrations.d.ts +42 -0
  88. package/dist/auth/migrations.d.ts.map +1 -0
  89. package/dist/auth/migrations.js +79 -0
  90. package/dist/auth/password.d.ts +39 -0
  91. package/dist/auth/password.d.ts.map +1 -0
  92. package/dist/auth/password.js +25 -0
  93. package/dist/auth/password_argon2.d.ts +43 -0
  94. package/dist/auth/password_argon2.d.ts.map +1 -0
  95. package/dist/auth/password_argon2.js +76 -0
  96. package/dist/auth/permit_queries.d.ts +72 -0
  97. package/dist/auth/permit_queries.d.ts.map +1 -0
  98. package/dist/auth/permit_queries.js +116 -0
  99. package/dist/auth/request_context.d.ts +114 -0
  100. package/dist/auth/request_context.d.ts.map +1 -0
  101. package/dist/auth/request_context.js +176 -0
  102. package/dist/auth/require_keeper.d.ts +20 -0
  103. package/dist/auth/require_keeper.d.ts.map +1 -0
  104. package/dist/auth/require_keeper.js +35 -0
  105. package/dist/auth/role_schema.d.ts +69 -0
  106. package/dist/auth/role_schema.d.ts.map +1 -0
  107. package/dist/auth/role_schema.js +70 -0
  108. package/dist/auth/route_guards.d.ts +21 -0
  109. package/dist/auth/route_guards.d.ts.map +1 -0
  110. package/dist/auth/route_guards.js +32 -0
  111. package/dist/auth/session_cookie.d.ts +158 -0
  112. package/dist/auth/session_cookie.d.ts.map +1 -0
  113. package/dist/auth/session_cookie.js +135 -0
  114. package/dist/auth/session_lifecycle.d.ts +35 -0
  115. package/dist/auth/session_lifecycle.d.ts.map +1 -0
  116. package/dist/auth/session_lifecycle.js +27 -0
  117. package/dist/auth/session_middleware.d.ts +33 -0
  118. package/dist/auth/session_middleware.d.ts.map +1 -0
  119. package/dist/auth/session_middleware.js +62 -0
  120. package/dist/auth/session_queries.d.ts +135 -0
  121. package/dist/auth/session_queries.d.ts.map +1 -0
  122. package/dist/auth/session_queries.js +186 -0
  123. package/dist/auth/signup_routes.d.ts +32 -0
  124. package/dist/auth/signup_routes.d.ts.map +1 -0
  125. package/dist/auth/signup_routes.js +150 -0
  126. package/dist/cli/args.d.ts +48 -0
  127. package/dist/cli/args.d.ts.map +1 -0
  128. package/dist/cli/args.js +76 -0
  129. package/dist/cli/config.d.ts +48 -0
  130. package/dist/cli/config.d.ts.map +1 -0
  131. package/dist/cli/config.js +77 -0
  132. package/dist/cli/daemon.d.ts +82 -0
  133. package/dist/cli/daemon.d.ts.map +1 -0
  134. package/dist/cli/daemon.js +149 -0
  135. package/dist/cli/help.d.ts +85 -0
  136. package/dist/cli/help.d.ts.map +1 -0
  137. package/dist/cli/help.js +138 -0
  138. package/dist/cli/logger.d.ts +46 -0
  139. package/dist/cli/logger.d.ts.map +1 -0
  140. package/dist/cli/logger.js +48 -0
  141. package/dist/cli/util.d.ts +36 -0
  142. package/dist/cli/util.d.ts.map +1 -0
  143. package/dist/cli/util.js +50 -0
  144. package/dist/crypto.d.ts +13 -0
  145. package/dist/crypto.d.ts.map +1 -0
  146. package/dist/crypto.js +19 -0
  147. package/dist/db/assert_row.d.ts +18 -0
  148. package/dist/db/assert_row.d.ts.map +1 -0
  149. package/dist/db/assert_row.js +24 -0
  150. package/dist/db/create_db.d.ts +38 -0
  151. package/dist/db/create_db.d.ts.map +1 -0
  152. package/dist/db/create_db.js +57 -0
  153. package/dist/db/db.d.ts +97 -0
  154. package/dist/db/db.d.ts.map +1 -0
  155. package/dist/db/db.js +76 -0
  156. package/dist/db/db_pg.d.ts +21 -0
  157. package/dist/db/db_pg.d.ts.map +1 -0
  158. package/dist/db/db_pg.js +45 -0
  159. package/dist/db/db_pglite.d.ts +21 -0
  160. package/dist/db/db_pglite.d.ts.map +1 -0
  161. package/dist/db/db_pglite.js +28 -0
  162. package/dist/db/migrate.d.ts +67 -0
  163. package/dist/db/migrate.d.ts.map +1 -0
  164. package/dist/db/migrate.js +118 -0
  165. package/dist/db/pg_error.d.ts +16 -0
  166. package/dist/db/pg_error.d.ts.map +1 -0
  167. package/dist/db/pg_error.js +15 -0
  168. package/dist/db/query_deps.d.ts +14 -0
  169. package/dist/db/query_deps.d.ts.map +1 -0
  170. package/dist/db/query_deps.js +9 -0
  171. package/dist/db/sql_identifier.d.ts +27 -0
  172. package/dist/db/sql_identifier.d.ts.map +1 -0
  173. package/dist/db/sql_identifier.js +31 -0
  174. package/dist/db/status.d.ts +62 -0
  175. package/dist/db/status.d.ts.map +1 -0
  176. package/dist/db/status.js +116 -0
  177. package/dist/dev/setup.d.ts +159 -0
  178. package/dist/dev/setup.d.ts.map +1 -0
  179. package/dist/dev/setup.js +265 -0
  180. package/dist/env/dotenv.d.ts +25 -0
  181. package/dist/env/dotenv.d.ts.map +1 -0
  182. package/dist/env/dotenv.js +52 -0
  183. package/dist/env/load.d.ts +52 -0
  184. package/dist/env/load.d.ts.map +1 -0
  185. package/dist/env/load.js +79 -0
  186. package/dist/env/mask.d.ts +19 -0
  187. package/dist/env/mask.d.ts.map +1 -0
  188. package/dist/env/mask.js +26 -0
  189. package/dist/env/resolve.d.ts +126 -0
  190. package/dist/env/resolve.d.ts.map +1 -0
  191. package/dist/env/resolve.js +200 -0
  192. package/dist/hono_context.d.ts +48 -0
  193. package/dist/hono_context.d.ts.map +1 -0
  194. package/dist/hono_context.js +22 -0
  195. package/dist/http/common_routes.d.ts +52 -0
  196. package/dist/http/common_routes.d.ts.map +1 -0
  197. package/dist/http/common_routes.js +65 -0
  198. package/dist/http/db_routes.d.ts +57 -0
  199. package/dist/http/db_routes.d.ts.map +1 -0
  200. package/dist/http/db_routes.js +176 -0
  201. package/dist/http/error_schemas.d.ts +169 -0
  202. package/dist/http/error_schemas.d.ts.map +1 -0
  203. package/dist/http/error_schemas.js +178 -0
  204. package/dist/http/middleware_spec.d.ts +19 -0
  205. package/dist/http/middleware_spec.d.ts.map +1 -0
  206. package/dist/http/middleware_spec.js +9 -0
  207. package/dist/http/origin.d.ts +57 -0
  208. package/dist/http/origin.d.ts.map +1 -0
  209. package/dist/http/origin.js +207 -0
  210. package/dist/http/proxy.d.ts +112 -0
  211. package/dist/http/proxy.d.ts.map +1 -0
  212. package/dist/http/proxy.js +240 -0
  213. package/dist/http/route_spec.d.ts +197 -0
  214. package/dist/http/route_spec.d.ts.map +1 -0
  215. package/dist/http/route_spec.js +243 -0
  216. package/dist/http/schema_helpers.d.ts +64 -0
  217. package/dist/http/schema_helpers.d.ts.map +1 -0
  218. package/dist/http/schema_helpers.js +90 -0
  219. package/dist/http/surface.d.ts +132 -0
  220. package/dist/http/surface.d.ts.map +1 -0
  221. package/dist/http/surface.js +156 -0
  222. package/dist/http/surface_query.d.ts +77 -0
  223. package/dist/http/surface_query.d.ts.map +1 -0
  224. package/dist/http/surface_query.js +86 -0
  225. package/dist/rate_limiter.d.ts +94 -0
  226. package/dist/rate_limiter.d.ts.map +1 -0
  227. package/dist/rate_limiter.js +156 -0
  228. package/dist/realtime/sse.d.ts +80 -0
  229. package/dist/realtime/sse.d.ts.map +1 -0
  230. package/dist/realtime/sse.js +109 -0
  231. package/dist/realtime/sse_auth_guard.d.ts +93 -0
  232. package/dist/realtime/sse_auth_guard.d.ts.map +1 -0
  233. package/dist/realtime/sse_auth_guard.js +111 -0
  234. package/dist/realtime/subscriber_registry.d.ts +85 -0
  235. package/dist/realtime/subscriber_registry.d.ts.map +1 -0
  236. package/dist/realtime/subscriber_registry.js +108 -0
  237. package/dist/runtime/deno.d.ts +21 -0
  238. package/dist/runtime/deno.d.ts.map +1 -0
  239. package/dist/runtime/deno.js +83 -0
  240. package/dist/runtime/deps.d.ts +113 -0
  241. package/dist/runtime/deps.d.ts.map +1 -0
  242. package/dist/runtime/deps.js +10 -0
  243. package/dist/runtime/fs.d.ts +15 -0
  244. package/dist/runtime/fs.d.ts.map +1 -0
  245. package/dist/runtime/fs.js +17 -0
  246. package/dist/runtime/mock.d.ts +81 -0
  247. package/dist/runtime/mock.d.ts.map +1 -0
  248. package/dist/runtime/mock.js +195 -0
  249. package/dist/runtime/node.d.ts +17 -0
  250. package/dist/runtime/node.d.ts.map +1 -0
  251. package/dist/runtime/node.js +117 -0
  252. package/dist/schema_meta.d.ts +16 -0
  253. package/dist/schema_meta.d.ts.map +1 -0
  254. package/dist/schema_meta.js +9 -0
  255. package/dist/sensitivity.d.ts +15 -0
  256. package/dist/sensitivity.d.ts.map +1 -0
  257. package/dist/sensitivity.js +9 -0
  258. package/dist/server/app_backend.d.ts +74 -0
  259. package/dist/server/app_backend.d.ts.map +1 -0
  260. package/dist/server/app_backend.js +39 -0
  261. package/dist/server/app_server.d.ts +201 -0
  262. package/dist/server/app_server.d.ts.map +1 -0
  263. package/dist/server/app_server.js +266 -0
  264. package/dist/server/env.d.ts +68 -0
  265. package/dist/server/env.d.ts.map +1 -0
  266. package/dist/server/env.js +95 -0
  267. package/dist/server/startup.d.ts +22 -0
  268. package/dist/server/startup.d.ts.map +1 -0
  269. package/dist/server/startup.js +48 -0
  270. package/dist/server/static.d.ts +39 -0
  271. package/dist/server/static.d.ts.map +1 -0
  272. package/dist/server/static.js +38 -0
  273. package/dist/server/validate_nginx.d.ts +34 -0
  274. package/dist/server/validate_nginx.d.ts.map +1 -0
  275. package/dist/server/validate_nginx.js +118 -0
  276. package/dist/testing/CLAUDE.md +3 -0
  277. package/dist/testing/admin_integration.d.ts +45 -0
  278. package/dist/testing/admin_integration.d.ts.map +1 -0
  279. package/dist/testing/admin_integration.js +840 -0
  280. package/dist/testing/adversarial_404.d.ts +15 -0
  281. package/dist/testing/adversarial_404.d.ts.map +1 -0
  282. package/dist/testing/adversarial_404.js +118 -0
  283. package/dist/testing/adversarial_headers.d.ts +36 -0
  284. package/dist/testing/adversarial_headers.d.ts.map +1 -0
  285. package/dist/testing/adversarial_headers.js +128 -0
  286. package/dist/testing/adversarial_input.d.ts +56 -0
  287. package/dist/testing/adversarial_input.d.ts.map +1 -0
  288. package/dist/testing/adversarial_input.js +494 -0
  289. package/dist/testing/app_server.d.ts +169 -0
  290. package/dist/testing/app_server.d.ts.map +1 -0
  291. package/dist/testing/app_server.js +240 -0
  292. package/dist/testing/assert_dev_env.d.ts +10 -0
  293. package/dist/testing/assert_dev_env.d.ts.map +1 -0
  294. package/dist/testing/assert_dev_env.js +13 -0
  295. package/dist/testing/assertions.d.ts +61 -0
  296. package/dist/testing/assertions.d.ts.map +1 -0
  297. package/dist/testing/assertions.js +96 -0
  298. package/dist/testing/attack_surface.d.ts +63 -0
  299. package/dist/testing/attack_surface.d.ts.map +1 -0
  300. package/dist/testing/attack_surface.js +224 -0
  301. package/dist/testing/audit_completeness.d.ts +29 -0
  302. package/dist/testing/audit_completeness.d.ts.map +1 -0
  303. package/dist/testing/audit_completeness.js +410 -0
  304. package/dist/testing/auth_apps.d.ts +55 -0
  305. package/dist/testing/auth_apps.d.ts.map +1 -0
  306. package/dist/testing/auth_apps.js +122 -0
  307. package/dist/testing/data_exposure.d.ts +62 -0
  308. package/dist/testing/data_exposure.d.ts.map +1 -0
  309. package/dist/testing/data_exposure.js +297 -0
  310. package/dist/testing/db.d.ts +111 -0
  311. package/dist/testing/db.d.ts.map +1 -0
  312. package/dist/testing/db.js +258 -0
  313. package/dist/testing/entities.d.ts +21 -0
  314. package/dist/testing/entities.d.ts.map +1 -0
  315. package/dist/testing/entities.js +42 -0
  316. package/dist/testing/error_coverage.d.ts +78 -0
  317. package/dist/testing/error_coverage.d.ts.map +1 -0
  318. package/dist/testing/error_coverage.js +135 -0
  319. package/dist/testing/integration.d.ts +37 -0
  320. package/dist/testing/integration.d.ts.map +1 -0
  321. package/dist/testing/integration.js +1139 -0
  322. package/dist/testing/integration_helpers.d.ts +107 -0
  323. package/dist/testing/integration_helpers.d.ts.map +1 -0
  324. package/dist/testing/integration_helpers.js +246 -0
  325. package/dist/testing/middleware.d.ts +125 -0
  326. package/dist/testing/middleware.d.ts.map +1 -0
  327. package/dist/testing/middleware.js +210 -0
  328. package/dist/testing/rate_limiting.d.ts +43 -0
  329. package/dist/testing/rate_limiting.d.ts.map +1 -0
  330. package/dist/testing/rate_limiting.js +216 -0
  331. package/dist/testing/round_trip.d.ts +37 -0
  332. package/dist/testing/round_trip.d.ts.map +1 -0
  333. package/dist/testing/round_trip.js +128 -0
  334. package/dist/testing/schema_generators.d.ts +33 -0
  335. package/dist/testing/schema_generators.d.ts.map +1 -0
  336. package/dist/testing/schema_generators.js +137 -0
  337. package/dist/testing/standard.d.ts +49 -0
  338. package/dist/testing/standard.d.ts.map +1 -0
  339. package/dist/testing/standard.js +16 -0
  340. package/dist/testing/stubs.d.ts +96 -0
  341. package/dist/testing/stubs.d.ts.map +1 -0
  342. package/dist/testing/stubs.js +192 -0
  343. package/dist/testing/surface_invariants.d.ts +189 -0
  344. package/dist/testing/surface_invariants.d.ts.map +1 -0
  345. package/dist/testing/surface_invariants.js +450 -0
  346. package/dist/ui/AccountSessions.svelte +75 -0
  347. package/dist/ui/AccountSessions.svelte.d.ts +19 -0
  348. package/dist/ui/AccountSessions.svelte.d.ts.map +1 -0
  349. package/dist/ui/AdminAccounts.svelte +107 -0
  350. package/dist/ui/AdminAccounts.svelte.d.ts +19 -0
  351. package/dist/ui/AdminAccounts.svelte.d.ts.map +1 -0
  352. package/dist/ui/AdminAuditLog.svelte +144 -0
  353. package/dist/ui/AdminAuditLog.svelte.d.ts +4 -0
  354. package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -0
  355. package/dist/ui/AdminInvites.svelte +142 -0
  356. package/dist/ui/AdminInvites.svelte.d.ts +4 -0
  357. package/dist/ui/AdminInvites.svelte.d.ts.map +1 -0
  358. package/dist/ui/AdminOverview.svelte +337 -0
  359. package/dist/ui/AdminOverview.svelte.d.ts +4 -0
  360. package/dist/ui/AdminOverview.svelte.d.ts.map +1 -0
  361. package/dist/ui/AdminPermitHistory.svelte +61 -0
  362. package/dist/ui/AdminPermitHistory.svelte.d.ts +19 -0
  363. package/dist/ui/AdminPermitHistory.svelte.d.ts.map +1 -0
  364. package/dist/ui/AdminSessions.svelte +85 -0
  365. package/dist/ui/AdminSessions.svelte.d.ts +19 -0
  366. package/dist/ui/AdminSessions.svelte.d.ts.map +1 -0
  367. package/dist/ui/AdminSettings.svelte +32 -0
  368. package/dist/ui/AdminSettings.svelte.d.ts +19 -0
  369. package/dist/ui/AdminSettings.svelte.d.ts.map +1 -0
  370. package/dist/ui/AdminSurface.svelte +42 -0
  371. package/dist/ui/AdminSurface.svelte.d.ts +4 -0
  372. package/dist/ui/AdminSurface.svelte.d.ts.map +1 -0
  373. package/dist/ui/AppShell.svelte +93 -0
  374. package/dist/ui/AppShell.svelte.d.ts +20 -0
  375. package/dist/ui/AppShell.svelte.d.ts.map +1 -0
  376. package/dist/ui/BootstrapForm.svelte +105 -0
  377. package/dist/ui/BootstrapForm.svelte.d.ts +4 -0
  378. package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -0
  379. package/dist/ui/ColumnLayout.svelte +46 -0
  380. package/dist/ui/ColumnLayout.svelte.d.ts +11 -0
  381. package/dist/ui/ColumnLayout.svelte.d.ts.map +1 -0
  382. package/dist/ui/ConfirmButton.svelte +125 -0
  383. package/dist/ui/ConfirmButton.svelte.d.ts +54 -0
  384. package/dist/ui/ConfirmButton.svelte.d.ts.map +1 -0
  385. package/dist/ui/Datatable.svelte +185 -0
  386. package/dist/ui/Datatable.svelte.d.ts +35 -0
  387. package/dist/ui/Datatable.svelte.d.ts.map +1 -0
  388. package/dist/ui/LoginForm.svelte +82 -0
  389. package/dist/ui/LoginForm.svelte.d.ts +8 -0
  390. package/dist/ui/LoginForm.svelte.d.ts.map +1 -0
  391. package/dist/ui/LogoutButton.svelte +36 -0
  392. package/dist/ui/LogoutButton.svelte.d.ts +10 -0
  393. package/dist/ui/LogoutButton.svelte.d.ts.map +1 -0
  394. package/dist/ui/MenuLink.svelte +35 -0
  395. package/dist/ui/MenuLink.svelte.d.ts +12 -0
  396. package/dist/ui/MenuLink.svelte.d.ts.map +1 -0
  397. package/dist/ui/OpenSignupToggle.svelte +36 -0
  398. package/dist/ui/OpenSignupToggle.svelte.d.ts +19 -0
  399. package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -0
  400. package/dist/ui/PopoverButton.svelte +136 -0
  401. package/dist/ui/PopoverButton.svelte.d.ts +63 -0
  402. package/dist/ui/PopoverButton.svelte.d.ts.map +1 -0
  403. package/dist/ui/SignupForm.svelte +117 -0
  404. package/dist/ui/SignupForm.svelte.d.ts +7 -0
  405. package/dist/ui/SignupForm.svelte.d.ts.map +1 -0
  406. package/dist/ui/SurfaceExplorer.svelte +287 -0
  407. package/dist/ui/SurfaceExplorer.svelte.d.ts +8 -0
  408. package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -0
  409. package/dist/ui/account_sessions_state.svelte.d.ts +15 -0
  410. package/dist/ui/account_sessions_state.svelte.d.ts.map +1 -0
  411. package/dist/ui/account_sessions_state.svelte.js +45 -0
  412. package/dist/ui/admin_accounts_state.svelte.d.ts +19 -0
  413. package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -0
  414. package/dist/ui/admin_accounts_state.svelte.js +65 -0
  415. package/dist/ui/admin_invites_state.svelte.d.ts +19 -0
  416. package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -0
  417. package/dist/ui/admin_invites_state.svelte.js +71 -0
  418. package/dist/ui/admin_sessions_state.svelte.d.ts +18 -0
  419. package/dist/ui/admin_sessions_state.svelte.d.ts.map +1 -0
  420. package/dist/ui/admin_sessions_state.svelte.js +62 -0
  421. package/dist/ui/app_settings_state.svelte.d.ts +14 -0
  422. package/dist/ui/app_settings_state.svelte.d.ts.map +1 -0
  423. package/dist/ui/app_settings_state.svelte.js +44 -0
  424. package/dist/ui/audit_log_state.svelte.d.ts +40 -0
  425. package/dist/ui/audit_log_state.svelte.d.ts.map +1 -0
  426. package/dist/ui/audit_log_state.svelte.js +153 -0
  427. package/dist/ui/auth_state.svelte.d.ts +85 -0
  428. package/dist/ui/auth_state.svelte.d.ts.map +1 -0
  429. package/dist/ui/auth_state.svelte.js +238 -0
  430. package/dist/ui/datatable.d.ts +25 -0
  431. package/dist/ui/datatable.d.ts.map +1 -0
  432. package/dist/ui/datatable.js +9 -0
  433. package/dist/ui/enter_advance.d.ts +13 -0
  434. package/dist/ui/enter_advance.d.ts.map +1 -0
  435. package/dist/ui/enter_advance.js +30 -0
  436. package/dist/ui/loadable.svelte.d.ts +55 -0
  437. package/dist/ui/loadable.svelte.d.ts.map +1 -0
  438. package/dist/ui/loadable.svelte.js +75 -0
  439. package/dist/ui/popover.svelte.d.ts +137 -0
  440. package/dist/ui/popover.svelte.d.ts.map +1 -0
  441. package/dist/ui/popover.svelte.js +288 -0
  442. package/dist/ui/position_helpers.d.ts +27 -0
  443. package/dist/ui/position_helpers.d.ts.map +1 -0
  444. package/dist/ui/position_helpers.js +81 -0
  445. package/dist/ui/sidebar_state.svelte.d.ts +30 -0
  446. package/dist/ui/sidebar_state.svelte.d.ts.map +1 -0
  447. package/dist/ui/sidebar_state.svelte.js +39 -0
  448. package/dist/ui/table_state.svelte.d.ts +63 -0
  449. package/dist/ui/table_state.svelte.d.ts.map +1 -0
  450. package/dist/ui/table_state.svelte.js +117 -0
  451. package/dist/ui/ui_fetch.d.ts +29 -0
  452. package/dist/ui/ui_fetch.d.ts.map +1 -0
  453. package/dist/ui/ui_fetch.js +37 -0
  454. package/dist/ui/ui_format.d.ts +63 -0
  455. package/dist/ui/ui_format.d.ts.map +1 -0
  456. package/dist/ui/ui_format.js +196 -0
  457. package/package.json +121 -0
package/dist/crypto.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Shared cryptographic utilities.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Generate a cryptographically random base64url string.
8
+ *
9
+ * @param byte_length - number of random bytes (default 32 = 256 bits)
10
+ * @returns base64url-encoded string without padding
11
+ */
12
+ export const generate_random_base64url = (byte_length = 32) => {
13
+ const bytes = new Uint8Array(byte_length);
14
+ crypto.getRandomValues(bytes);
15
+ return btoa(String.fromCharCode(...bytes))
16
+ .replace(/\+/g, '-')
17
+ .replace(/\//g, '_')
18
+ .replace(/=+$/, '');
19
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Assertion helper for INSERT RETURNING results.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Assert that a row is present, throwing a descriptive error if missing.
8
+ *
9
+ * Use after `INSERT ... RETURNING` queries where the database guarantees
10
+ * a row is returned on success. Replaces bare `row!` non-null assertions
11
+ * with an explicit runtime check.
12
+ *
13
+ * @param row - the row from `query_one` (`T | undefined`) or `rows[0]` (`T | undefined`)
14
+ * @param context - optional context for the error message (e.g. table or operation name)
15
+ * @returns the row, guaranteed non-undefined
16
+ */
17
+ export declare const assert_row: <T>(row: T | undefined, context?: string) => T;
18
+ //# sourceMappingURL=assert_row.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_row.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/assert_row.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,KAAK,CAAC,GAAG,SAAS,EAAE,UAAU,MAAM,KAAG,CASpE,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Assertion helper for INSERT RETURNING results.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Assert that a row is present, throwing a descriptive error if missing.
8
+ *
9
+ * Use after `INSERT ... RETURNING` queries where the database guarantees
10
+ * a row is returned on success. Replaces bare `row!` non-null assertions
11
+ * with an explicit runtime check.
12
+ *
13
+ * @param row - the row from `query_one` (`T | undefined`) or `rows[0]` (`T | undefined`)
14
+ * @param context - optional context for the error message (e.g. table or operation name)
15
+ * @returns the row, guaranteed non-undefined
16
+ */
17
+ export const assert_row = (row, context) => {
18
+ if (row === undefined) {
19
+ throw new Error(context
20
+ ? `Expected row from ${context}, but got undefined`
21
+ : 'Expected INSERT RETURNING to produce a row, but got undefined');
22
+ }
23
+ return row;
24
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Database initialization with driver auto-detection.
3
+ *
4
+ * Selects the appropriate database driver based on `database_url`:
5
+ * - `postgres://` or `postgresql://` — uses `pg` (PostgreSQL)
6
+ * - `file://` — uses `@electric-sql/pglite` (file-based)
7
+ * - `memory://` — uses `@electric-sql/pglite` (in-memory)
8
+ *
9
+ * Both `pg` and `@electric-sql/pglite` are optional peer dependencies,
10
+ * dynamically imported only when needed. For direct driver construction
11
+ * without auto-detection, use `db_pg.ts` or `db_pglite.ts`.
12
+ *
13
+ * @module
14
+ */
15
+ import type { Db, DbType } from './db.js';
16
+ /** Result of database initialization. */
17
+ export interface CreateDbResult {
18
+ db: Db;
19
+ /** Close the database connection. Bound to the actual driver at construction. */
20
+ close: () => Promise<void>;
21
+ db_type: DbType;
22
+ db_name: string;
23
+ }
24
+ /**
25
+ * Create a database connection based on a URL.
26
+ *
27
+ * Returns the `Db` instance, a typed `close` callback, driver type, and display name.
28
+ * The `close` callback is bound to the actual driver — callers never need to
29
+ * know which driver is in use.
30
+ *
31
+ * For direct driver construction without URL routing, import
32
+ * `create_pg_db` from `db_pg.ts` or `create_pglite_db` from `db_pglite.ts`.
33
+ *
34
+ * @param database_url - connection URL (`postgres://`, `postgresql://`, `file://`, or `memory://`)
35
+ * @returns database instance, close callback, type, and display name
36
+ */
37
+ export declare const create_db: (database_url: string) => Promise<CreateDbResult>;
38
+ //# sourceMappingURL=create_db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_db.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/create_db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAC,EAAE,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAIxC,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,EAAE,CAAC;IACP,iFAAiF;IACjF,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,GAAU,cAAc,MAAM,KAAG,OAAO,CAAC,cAAc,CAgC5E,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Database initialization with driver auto-detection.
3
+ *
4
+ * Selects the appropriate database driver based on `database_url`:
5
+ * - `postgres://` or `postgresql://` — uses `pg` (PostgreSQL)
6
+ * - `file://` — uses `@electric-sql/pglite` (file-based)
7
+ * - `memory://` — uses `@electric-sql/pglite` (in-memory)
8
+ *
9
+ * Both `pg` and `@electric-sql/pglite` are optional peer dependencies,
10
+ * dynamically imported only when needed. For direct driver construction
11
+ * without auto-detection, use `db_pg.ts` or `db_pglite.ts`.
12
+ *
13
+ * @module
14
+ */
15
+ import { create_pg_db } from './db_pg.js';
16
+ import { create_pglite_db } from './db_pglite.js';
17
+ /**
18
+ * Create a database connection based on a URL.
19
+ *
20
+ * Returns the `Db` instance, a typed `close` callback, driver type, and display name.
21
+ * The `close` callback is bound to the actual driver — callers never need to
22
+ * know which driver is in use.
23
+ *
24
+ * For direct driver construction without URL routing, import
25
+ * `create_pg_db` from `db_pg.ts` or `create_pglite_db` from `db_pglite.ts`.
26
+ *
27
+ * @param database_url - connection URL (`postgres://`, `postgresql://`, `file://`, or `memory://`)
28
+ * @returns database instance, close callback, type, and display name
29
+ */
30
+ export const create_db = async (database_url) => {
31
+ if (database_url.startsWith('postgres://') || database_url.startsWith('postgresql://')) {
32
+ const { default: pg } = await import('pg');
33
+ const pool = new pg.Pool({ connectionString: database_url });
34
+ const { db, close } = create_pg_db(pool);
35
+ return {
36
+ db,
37
+ close,
38
+ db_type: 'postgres',
39
+ db_name: new URL(database_url).pathname.slice(1) || 'postgres',
40
+ };
41
+ }
42
+ if (database_url.startsWith('memory://')) {
43
+ const { PGlite } = await import('@electric-sql/pglite');
44
+ const pglite = new PGlite(database_url);
45
+ const { db, close } = create_pglite_db(pglite);
46
+ return { db, close, db_type: 'pglite-memory', db_name: '(memory)' };
47
+ }
48
+ if (database_url.startsWith('file://')) {
49
+ const path = new URL(database_url).pathname;
50
+ const { PGlite } = await import('@electric-sql/pglite');
51
+ const pglite = new PGlite(path);
52
+ const { db, close } = create_pglite_db(pglite);
53
+ return { db, close, db_type: 'pglite-file', db_name: path };
54
+ }
55
+ const scheme = database_url.split('://')[0] ?? database_url;
56
+ throw new Error(`Unsupported database URL scheme: ${scheme}://. Expected postgres://, postgresql://, file://, or memory://`);
57
+ };
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Database wrapper with duck-typed interface.
3
+ *
4
+ * Accepts any client with a query(text, values) method.
5
+ * Both `pg.Pool` and `@electric-sql/pglite` satisfy this interface.
6
+ *
7
+ * Transaction safety is provided by an injected `transaction` callback —
8
+ * the driver adapters (`db_pg.ts`, `db_pglite.ts`) supply the driver-appropriate
9
+ * implementation. Close is handled externally (returned alongside the Db
10
+ * as `DbDriverResult`), not as a method on this class.
11
+ *
12
+ * @module
13
+ */
14
+ /**
15
+ * Minimal interface that both pg and pglite satisfy.
16
+ */
17
+ export interface DbClient {
18
+ query: <T = unknown>(text: string, values?: Array<unknown>) => Promise<{
19
+ rows: Array<T>;
20
+ }>;
21
+ }
22
+ /**
23
+ * Configuration for constructing a `Db` with transaction support.
24
+ *
25
+ * `transaction` is injected by `create_db` which knows the driver.
26
+ * For pg: acquires a dedicated pool client per transaction.
27
+ * For PGlite: delegates to `pglite.transaction()`.
28
+ */
29
+ export interface DbDeps {
30
+ client: DbClient;
31
+ transaction: <T>(fn: (tx_db: Db) => Promise<T>) => Promise<T>;
32
+ }
33
+ /**
34
+ * Result of constructing a driver-specific `Db`.
35
+ *
36
+ * Returned by `create_pg_db()` and `create_pglite_db()`.
37
+ * The `close` callback is bound to the actual driver — callers
38
+ * never need to know which driver is in use.
39
+ */
40
+ export interface DbDriverResult {
41
+ db: Db;
42
+ /** Close the database connection. Bound to the actual driver at construction. */
43
+ close: () => Promise<void>;
44
+ }
45
+ /** Database driver type. */
46
+ export type DbType = 'postgres' | 'pglite-file' | 'pglite-memory';
47
+ /**
48
+ * Sentinel transaction function for transaction-scoped `Db` instances.
49
+ *
50
+ * Throws immediately — nested transactions are not supported.
51
+ * Used by driver adapters when constructing the inner `Db` passed
52
+ * to transaction callbacks.
53
+ */
54
+ export declare const no_nested_transaction: DbDeps['transaction'];
55
+ /**
56
+ * Database wrapper providing a consistent query and transaction interface.
57
+ *
58
+ * Construct via `create_pg_db()` from `db_pg.ts` or `create_pglite_db()` from
59
+ * `db_pglite.ts` for proper transaction support, or via `create_db()` for
60
+ * URL-based auto-detection.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const {db, close} = await create_db('postgres://...');
65
+ * const users = await db.query<User>('SELECT * FROM users WHERE active = $1', [true]);
66
+ * await db.transaction(async (tx) => {
67
+ * await tx.query('INSERT INTO users ...');
68
+ * await tx.query('INSERT INTO audit_log ...');
69
+ * });
70
+ * await close();
71
+ * ```
72
+ */
73
+ export declare class Db {
74
+ #private;
75
+ readonly client: DbClient;
76
+ constructor(options: DbDeps);
77
+ /**
78
+ * Execute a query and return all rows.
79
+ */
80
+ query<T>(text: string, values?: Array<unknown>): Promise<Array<T>>;
81
+ /**
82
+ * Execute a query and return the first row, or undefined if no rows.
83
+ */
84
+ query_one<T>(text: string, values?: Array<unknown>): Promise<T | undefined>;
85
+ /**
86
+ * Run a function inside a database transaction.
87
+ *
88
+ * The callback receives a transaction-scoped `Db`. Queries inside the callback
89
+ * go through the transaction connection; queries outside use the pool normally.
90
+ * Commits on success, rolls back on error.
91
+ *
92
+ * @param fn - async function receiving a transaction-scoped `Db`
93
+ * @returns the value returned by `fn`
94
+ */
95
+ transaction<T>(fn: (tx_db: Db) => Promise<T>): Promise<T>;
96
+ }
97
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,KAAK,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC;QAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;KAAC,CAAC,CAAC;CACzF;AAED;;;;;;GAMG;AACH,MAAM,WAAW,MAAM;IACtB,MAAM,EAAE,QAAQ,CAAC;IACjB,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9D;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,EAAE,CAAC;IACP,iFAAiF;IACjF,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,4BAA4B;AAC5B,MAAM,MAAM,MAAM,GAAG,UAAU,GAAG,aAAa,GAAG,eAAe,CAAC;AAElE;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,aAAa,CAEvD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,EAAE;;IACd,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;gBAId,OAAO,EAAE,MAAM;IAK3B;;OAEG;IACG,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAKxE;;OAEG;IACG,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKjF;;;;;;;;;OASG;IACG,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAG/D"}
package/dist/db/db.js ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Database wrapper with duck-typed interface.
3
+ *
4
+ * Accepts any client with a query(text, values) method.
5
+ * Both `pg.Pool` and `@electric-sql/pglite` satisfy this interface.
6
+ *
7
+ * Transaction safety is provided by an injected `transaction` callback —
8
+ * the driver adapters (`db_pg.ts`, `db_pglite.ts`) supply the driver-appropriate
9
+ * implementation. Close is handled externally (returned alongside the Db
10
+ * as `DbDriverResult`), not as a method on this class.
11
+ *
12
+ * @module
13
+ */
14
+ /**
15
+ * Sentinel transaction function for transaction-scoped `Db` instances.
16
+ *
17
+ * Throws immediately — nested transactions are not supported.
18
+ * Used by driver adapters when constructing the inner `Db` passed
19
+ * to transaction callbacks.
20
+ */
21
+ export const no_nested_transaction = () => {
22
+ throw new Error('Nested transactions are not supported');
23
+ };
24
+ /**
25
+ * Database wrapper providing a consistent query and transaction interface.
26
+ *
27
+ * Construct via `create_pg_db()` from `db_pg.ts` or `create_pglite_db()` from
28
+ * `db_pglite.ts` for proper transaction support, or via `create_db()` for
29
+ * URL-based auto-detection.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const {db, close} = await create_db('postgres://...');
34
+ * const users = await db.query<User>('SELECT * FROM users WHERE active = $1', [true]);
35
+ * await db.transaction(async (tx) => {
36
+ * await tx.query('INSERT INTO users ...');
37
+ * await tx.query('INSERT INTO audit_log ...');
38
+ * });
39
+ * await close();
40
+ * ```
41
+ */
42
+ export class Db {
43
+ client;
44
+ #transaction;
45
+ constructor(options) {
46
+ this.client = options.client;
47
+ this.#transaction = options.transaction;
48
+ }
49
+ /**
50
+ * Execute a query and return all rows.
51
+ */
52
+ async query(text, values) {
53
+ const result = await this.client.query(text, values);
54
+ return result.rows;
55
+ }
56
+ /**
57
+ * Execute a query and return the first row, or undefined if no rows.
58
+ */
59
+ async query_one(text, values) {
60
+ const rows = await this.query(text, values);
61
+ return rows[0];
62
+ }
63
+ /**
64
+ * Run a function inside a database transaction.
65
+ *
66
+ * The callback receives a transaction-scoped `Db`. Queries inside the callback
67
+ * go through the transaction connection; queries outside use the pool normally.
68
+ * Commits on success, rolls back on error.
69
+ *
70
+ * @param fn - async function receiving a transaction-scoped `Db`
71
+ * @returns the value returned by `fn`
72
+ */
73
+ async transaction(fn) {
74
+ return this.#transaction(fn);
75
+ }
76
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * PostgreSQL driver adapter for `Db`.
3
+ *
4
+ * Provides `create_pg_db()` to construct a `Db` backed by a `pg.Pool`.
5
+ * Only imports `pg` types — the actual `pg` package is dynamically imported
6
+ * by callers (e.g., `create_db`) that construct the `Pool`.
7
+ *
8
+ * @module
9
+ */
10
+ import type { Pool } from 'pg';
11
+ import { type DbDriverResult } from './db.js';
12
+ /**
13
+ * Create a `Db` backed by a pg `Pool`.
14
+ *
15
+ * Owns the transaction implementation (acquires a dedicated pool client
16
+ * per transaction) and returns a `close` callback bound to `pool.end()`.
17
+ *
18
+ * @param pool - an already-constructed `pg.Pool`
19
+ */
20
+ export declare const create_pg_db: (pool: Pool) => DbDriverResult;
21
+ //# sourceMappingURL=db_pg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db_pg.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/db_pg.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,IAAI,CAAC;AAE7B,OAAO,EAA4B,KAAK,cAAc,EAAC,MAAM,SAAS,CAAC;AA0BvE;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,IAAI,KAAG,cAGxC,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * PostgreSQL driver adapter for `Db`.
3
+ *
4
+ * Provides `create_pg_db()` to construct a `Db` backed by a `pg.Pool`.
5
+ * Only imports `pg` types — the actual `pg` package is dynamically imported
6
+ * by callers (e.g., `create_db`) that construct the `Pool`.
7
+ *
8
+ * @module
9
+ */
10
+ import { Db, no_nested_transaction } from './db.js';
11
+ /**
12
+ * Create a transaction implementation for a pg Pool.
13
+ *
14
+ * Acquires a dedicated client from the pool for each transaction,
15
+ * ensuring BEGIN/COMMIT/ROLLBACK all hit the same connection.
16
+ */
17
+ const create_pg_transaction = (pool) => async (fn) => {
18
+ const client = await pool.connect();
19
+ try {
20
+ await client.query('BEGIN');
21
+ const tx_db = new Db({ client, transaction: no_nested_transaction });
22
+ const result = await fn(tx_db);
23
+ await client.query('COMMIT');
24
+ return result;
25
+ }
26
+ catch (err) {
27
+ await client.query('ROLLBACK');
28
+ throw err;
29
+ }
30
+ finally {
31
+ client.release();
32
+ }
33
+ };
34
+ /**
35
+ * Create a `Db` backed by a pg `Pool`.
36
+ *
37
+ * Owns the transaction implementation (acquires a dedicated pool client
38
+ * per transaction) and returns a `close` callback bound to `pool.end()`.
39
+ *
40
+ * @param pool - an already-constructed `pg.Pool`
41
+ */
42
+ export const create_pg_db = (pool) => ({
43
+ db: new Db({ client: pool, transaction: create_pg_transaction(pool) }),
44
+ close: () => pool.end(),
45
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * PGlite driver adapter for `Db`.
3
+ *
4
+ * Provides `create_pglite_db()` to construct a `Db` backed by `@electric-sql/pglite`.
5
+ * Only imports PGlite types — the actual package is dynamically imported
6
+ * by callers (e.g., `create_db`) that construct the `PGlite` instance.
7
+ *
8
+ * @module
9
+ */
10
+ import type { PGlite } from '@electric-sql/pglite';
11
+ import { type DbDriverResult } from './db.js';
12
+ /**
13
+ * Create a `Db` backed by a PGlite instance.
14
+ *
15
+ * Delegates transactions to PGlite's native `transaction()` method
16
+ * and returns a `close` callback bound to `pglite.close()`.
17
+ *
18
+ * @param pglite - an already-constructed PGlite instance
19
+ */
20
+ export declare const create_pglite_db: (pglite: PGlite) => DbDriverResult;
21
+ //# sourceMappingURL=db_pglite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db_pglite.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/db_pglite.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAA4B,KAAK,cAAc,EAAC,MAAM,SAAS,CAAC;AAYvE;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,cAGhD,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * PGlite driver adapter for `Db`.
3
+ *
4
+ * Provides `create_pglite_db()` to construct a `Db` backed by `@electric-sql/pglite`.
5
+ * Only imports PGlite types — the actual package is dynamically imported
6
+ * by callers (e.g., `create_db`) that construct the `PGlite` instance.
7
+ *
8
+ * @module
9
+ */
10
+ import { Db, no_nested_transaction } from './db.js';
11
+ /**
12
+ * Create a transaction implementation for PGlite.
13
+ *
14
+ * Delegates to PGlite's native `transaction()` method.
15
+ */
16
+ const create_pglite_transaction = (pglite) => async (fn) => pglite.transaction(async (tx) => fn(new Db({ client: tx, transaction: no_nested_transaction })));
17
+ /**
18
+ * Create a `Db` backed by a PGlite instance.
19
+ *
20
+ * Delegates transactions to PGlite's native `transaction()` method
21
+ * and returns a `close` callback bound to `pglite.close()`.
22
+ *
23
+ * @param pglite - an already-constructed PGlite instance
24
+ */
25
+ export const create_pglite_db = (pglite) => ({
26
+ db: new Db({ client: pglite, transaction: create_pglite_transaction(pglite) }),
27
+ close: () => pglite.close(),
28
+ });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Version-gated database migration runner.
3
+ *
4
+ * Migrations are functions in ordered arrays, grouped by namespace.
5
+ * A `schema_version` table tracks progress per namespace.
6
+ * Each migration runs in its own transaction.
7
+ *
8
+ * **Forward-only**: No down-migrations. Schema changes are additive.
9
+ * For pre-release development, collapse migrations into a single v0.
10
+ *
11
+ * **Named migrations**: Migrations can be bare functions or `{name, up}` objects.
12
+ * Names appear in error messages for debuggability.
13
+ *
14
+ * **Advisory locking**: Per-namespace PostgreSQL advisory locks serialize
15
+ * concurrent migration runs, preventing double-application in multi-instance deployments.
16
+ *
17
+ * @module
18
+ */
19
+ import type { Db } from './db.js';
20
+ /**
21
+ * A single migration function that receives a `Db` and applies DDL/DML.
22
+ *
23
+ * Runs inside a transaction — throw to rollback.
24
+ */
25
+ export type MigrationFn = (db: Db) => Promise<void>;
26
+ /**
27
+ * A migration: either a bare function or a named object with an `up` function.
28
+ *
29
+ * Named migrations include their name in error messages for debuggability.
30
+ */
31
+ export type Migration = MigrationFn | {
32
+ name: string;
33
+ up: MigrationFn;
34
+ };
35
+ /**
36
+ * A named group of ordered migrations.
37
+ *
38
+ * Array index = version number: `migrations[0]` is version 0, etc.
39
+ */
40
+ export interface MigrationNamespace {
41
+ namespace: string;
42
+ migrations: Array<Migration>;
43
+ }
44
+ /** Result of running migrations for a single namespace. */
45
+ export interface MigrationResult {
46
+ namespace: string;
47
+ from_version: number;
48
+ to_version: number;
49
+ migrations_applied: number;
50
+ }
51
+ /**
52
+ * Run pending migrations for each namespace.
53
+ *
54
+ * Creates the `schema_version` tracking table if it does not exist,
55
+ * then for each namespace: acquires an advisory lock, reads the current
56
+ * version, runs pending migrations in order (each in its own transaction),
57
+ * updates the stored version, and releases the lock.
58
+ *
59
+ * **Concurrency**: Uses PostgreSQL advisory locks to serialize concurrent
60
+ * callers on the same namespace. Safe for multi-instance deployments.
61
+ *
62
+ * @param db - the database instance
63
+ * @param namespaces - migration namespaces to process in order
64
+ * @returns results per namespace (only includes namespaces that had work to do)
65
+ */
66
+ export declare const run_migrations: (db: Db, namespaces: Array<MigrationNamespace>) => Promise<Array<MigrationResult>>;
67
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAC,EAAE,EAAC,MAAM,SAAS,CAAC;AAEhC;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,WAAW,CAAA;CAAC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CAC7B;AAED,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;CAC3B;AA8BD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,GAC1B,IAAI,EAAE,EACN,YAAY,KAAK,CAAC,kBAAkB,CAAC,KACnC,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CA2EhC,CAAC"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Version-gated database migration runner.
3
+ *
4
+ * Migrations are functions in ordered arrays, grouped by namespace.
5
+ * A `schema_version` table tracks progress per namespace.
6
+ * Each migration runs in its own transaction.
7
+ *
8
+ * **Forward-only**: No down-migrations. Schema changes are additive.
9
+ * For pre-release development, collapse migrations into a single v0.
10
+ *
11
+ * **Named migrations**: Migrations can be bare functions or `{name, up}` objects.
12
+ * Names appear in error messages for debuggability.
13
+ *
14
+ * **Advisory locking**: Per-namespace PostgreSQL advisory locks serialize
15
+ * concurrent migration runs, preventing double-application in multi-instance deployments.
16
+ *
17
+ * @module
18
+ */
19
+ const SCHEMA_VERSION_DDL = `
20
+ CREATE TABLE IF NOT EXISTS schema_version (
21
+ namespace TEXT PRIMARY KEY,
22
+ version INTEGER NOT NULL DEFAULT 0,
23
+ applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
24
+ )`;
25
+ /** Normalize a migration to its function and optional name. */
26
+ const resolve_migration = (m) => {
27
+ if (typeof m === 'function') {
28
+ return { fn: m, name: null };
29
+ }
30
+ return { fn: m.up, name: m.name };
31
+ };
32
+ /**
33
+ * Compute a stable int32 advisory lock key from a namespace string.
34
+ *
35
+ * Uses djb2 hash, masked to int32 range for `pg_advisory_lock`.
36
+ */
37
+ const namespace_lock_key = (namespace) => {
38
+ let hash = 5381;
39
+ for (let i = 0; i < namespace.length; i++) {
40
+ hash = ((hash << 5) + hash + namespace.charCodeAt(i)) | 0;
41
+ }
42
+ return hash;
43
+ };
44
+ /**
45
+ * Run pending migrations for each namespace.
46
+ *
47
+ * Creates the `schema_version` tracking table if it does not exist,
48
+ * then for each namespace: acquires an advisory lock, reads the current
49
+ * version, runs pending migrations in order (each in its own transaction),
50
+ * updates the stored version, and releases the lock.
51
+ *
52
+ * **Concurrency**: Uses PostgreSQL advisory locks to serialize concurrent
53
+ * callers on the same namespace. Safe for multi-instance deployments.
54
+ *
55
+ * @param db - the database instance
56
+ * @param namespaces - migration namespaces to process in order
57
+ * @returns results per namespace (only includes namespaces that had work to do)
58
+ */
59
+ export const run_migrations = async (db, namespaces) => {
60
+ await db.query(SCHEMA_VERSION_DDL);
61
+ const results = [];
62
+ /* eslint-disable no-await-in-loop */
63
+ for (const { namespace, migrations } of namespaces) {
64
+ const lock_key = namespace_lock_key(namespace);
65
+ // Acquire advisory lock — serializes concurrent migration runs
66
+ try {
67
+ await db.query('SELECT pg_advisory_lock($1)', [lock_key]);
68
+ }
69
+ catch {
70
+ // Advisory lock not supported (e.g. some PGlite versions) — proceed without
71
+ }
72
+ try {
73
+ const row = await db.query_one('SELECT version FROM schema_version WHERE namespace = $1', [namespace]);
74
+ const current_version = row?.version ?? 0;
75
+ if (current_version > migrations.length) {
76
+ throw new Error(`schema_version for "${namespace}" is ${current_version} but only ${migrations.length} migrations exist — was a migration removed?`);
77
+ }
78
+ if (current_version === migrations.length) {
79
+ continue; // up to date
80
+ }
81
+ // run pending migrations, each in its own transaction with version upsert
82
+ for (let i = current_version; i < migrations.length; i++) {
83
+ const { fn, name } = resolve_migration(migrations[i]);
84
+ const label = name != null ? `"${name}"` : '';
85
+ try {
86
+ await db.transaction(async (tx) => {
87
+ await fn(tx);
88
+ await tx.query(`INSERT INTO schema_version (namespace, version, applied_at)
89
+ VALUES ($1, $2, NOW())
90
+ ON CONFLICT (namespace)
91
+ DO UPDATE SET version = $2, applied_at = NOW()`, [namespace, i + 1]);
92
+ });
93
+ }
94
+ catch (err) {
95
+ const name_part = label ? ` ${label}` : '';
96
+ throw new Error(`Migration ${namespace}[${i}]${name_part} failed: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
97
+ }
98
+ }
99
+ results.push({
100
+ namespace,
101
+ from_version: current_version,
102
+ to_version: migrations.length,
103
+ migrations_applied: migrations.length - current_version,
104
+ });
105
+ }
106
+ finally {
107
+ // Release advisory lock
108
+ try {
109
+ await db.query('SELECT pg_advisory_unlock($1)', [lock_key]);
110
+ }
111
+ catch {
112
+ // Advisory lock not supported — nothing to release
113
+ }
114
+ }
115
+ }
116
+ /* eslint-enable no-await-in-loop */
117
+ return results;
118
+ };