@edge-base/server 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/admin-build/.gitkeep +0 -0
  2. package/admin-build/_app/env.js +1 -0
  3. package/admin-build/_app/immutable/assets/0.Bm6cF078.css +1 -0
  4. package/admin-build/_app/immutable/assets/1.BfW3pUNa.css +1 -0
  5. package/admin-build/_app/immutable/assets/11.CVmQOewb.css +1 -0
  6. package/admin-build/_app/immutable/assets/12.B1EhbRZT.css +1 -0
  7. package/admin-build/_app/immutable/assets/13.BvwYeuwE.css +1 -0
  8. package/admin-build/_app/immutable/assets/14.CdVfcO0R.css +1 -0
  9. package/admin-build/_app/immutable/assets/15.2yeZ66b-.css +1 -0
  10. package/admin-build/_app/immutable/assets/17.BVg0JEVu.css +1 -0
  11. package/admin-build/_app/immutable/assets/18.Rwnl3x_i.css +1 -0
  12. package/admin-build/_app/immutable/assets/20.DsPWA9AV.css +1 -0
  13. package/admin-build/_app/immutable/assets/21.Dz2RJ56c.css +1 -0
  14. package/admin-build/_app/immutable/assets/22.DwNLk5Ai.css +1 -0
  15. package/admin-build/_app/immutable/assets/23.CFpu0gOO.css +1 -0
  16. package/admin-build/_app/immutable/assets/24.Cy5LBeoJ.css +1 -0
  17. package/admin-build/_app/immutable/assets/25.pUyLVf-h.css +1 -0
  18. package/admin-build/_app/immutable/assets/26.DBcGrlXa.css +1 -0
  19. package/admin-build/_app/immutable/assets/27.BswYyAJD.css +1 -0
  20. package/admin-build/_app/immutable/assets/28.B4ueB1Kf.css +1 -0
  21. package/admin-build/_app/immutable/assets/29.B-qU6PdF.css +1 -0
  22. package/admin-build/_app/immutable/assets/3.Dg81Pgmd.css +1 -0
  23. package/admin-build/_app/immutable/assets/30.CsdWum94.css +1 -0
  24. package/admin-build/_app/immutable/assets/31.U6OwIp50.css +1 -0
  25. package/admin-build/_app/immutable/assets/4.CyawCCux.css +1 -0
  26. package/admin-build/_app/immutable/assets/5.C0YO2HTk.css +1 -0
  27. package/admin-build/_app/immutable/assets/8.Br5jd6kD.css +1 -0
  28. package/admin-build/_app/immutable/assets/Badge.EMYLHBxE.css +1 -0
  29. package/admin-build/_app/immutable/assets/Button.DpzMRTjK.css +1 -0
  30. package/admin-build/_app/immutable/assets/ConfirmDialog.DAnaWRRk.css +1 -0
  31. package/admin-build/_app/immutable/assets/EmptyState.CwKsu57Y.css +1 -0
  32. package/admin-build/_app/immutable/assets/Input.BDUSenmU.css +1 -0
  33. package/admin-build/_app/immutable/assets/Modal.Dm5B0Xie.css +1 -0
  34. package/admin-build/_app/immutable/assets/PageShell.CmU-Xh-b.css +1 -0
  35. package/admin-build/_app/immutable/assets/SchemaFieldEditor.g4NsCdno.css +1 -0
  36. package/admin-build/_app/immutable/assets/Select.BW4Keufm.css +1 -0
  37. package/admin-build/_app/immutable/assets/Skeleton.KWUulTKJ.css +1 -0
  38. package/admin-build/_app/immutable/assets/Tabs.CniGYb67.css +1 -0
  39. package/admin-build/_app/immutable/assets/TimeChart.BTCDAvmT.css +1 -0
  40. package/admin-build/_app/immutable/assets/Toggle.Cy_K12OM.css +1 -0
  41. package/admin-build/_app/immutable/assets/TopList.ClFzmPlA.css +1 -0
  42. package/admin-build/_app/immutable/chunks/7B47DvSx.js +1 -0
  43. package/admin-build/_app/immutable/chunks/7f08Id8e.js +1 -0
  44. package/admin-build/_app/immutable/chunks/8wJeQ7LN.js +1 -0
  45. package/admin-build/_app/immutable/chunks/B-h2afW5.js +1 -0
  46. package/admin-build/_app/immutable/chunks/B8vJP3wz.js +1 -0
  47. package/admin-build/_app/immutable/chunks/BR_fL5Yv.js +1 -0
  48. package/admin-build/_app/immutable/chunks/BY92tFS2.js +1 -0
  49. package/admin-build/_app/immutable/chunks/BcR-Rdj9.js +1 -0
  50. package/admin-build/_app/immutable/chunks/BdrwyZv8.js +1 -0
  51. package/admin-build/_app/immutable/chunks/Bh56EfQ_.js +1 -0
  52. package/admin-build/_app/immutable/chunks/BkrCkgYp.js +1 -0
  53. package/admin-build/_app/immutable/chunks/BmRjiP5k.js +1 -0
  54. package/admin-build/_app/immutable/chunks/BsokvhWC.js +1 -0
  55. package/admin-build/_app/immutable/chunks/C4D51vTW.js +1 -0
  56. package/admin-build/_app/immutable/chunks/C6puvcoR.js +2 -0
  57. package/admin-build/_app/immutable/chunks/CCKNu7m7.js +1 -0
  58. package/admin-build/_app/immutable/chunks/CWj6FrbW.js +1 -0
  59. package/admin-build/_app/immutable/chunks/Ce-ngf4p.js +5 -0
  60. package/admin-build/_app/immutable/chunks/Cs0GwzJA.js +1 -0
  61. package/admin-build/_app/immutable/chunks/CwROoZK0.js +1 -0
  62. package/admin-build/_app/immutable/chunks/CxCPv_Ut.js +1 -0
  63. package/admin-build/_app/immutable/chunks/CxbRue-5.js +1 -0
  64. package/admin-build/_app/immutable/chunks/CyqB6g-D.js +1 -0
  65. package/admin-build/_app/immutable/chunks/D5h5A1cc.js +2 -0
  66. package/admin-build/_app/immutable/chunks/DnyL7Zq-.js +1 -0
  67. package/admin-build/_app/immutable/chunks/DoPXzH7F.js +1 -0
  68. package/admin-build/_app/immutable/chunks/DrQSgw-f.js +1 -0
  69. package/admin-build/_app/immutable/chunks/DttM2zNO.js +1 -0
  70. package/admin-build/_app/immutable/chunks/DuXuUBWN.js +1 -0
  71. package/admin-build/_app/immutable/chunks/MdeqaOQx.js +10 -0
  72. package/admin-build/_app/immutable/chunks/NuUjtcO2.js +1 -0
  73. package/admin-build/_app/immutable/chunks/Q2nPFxS6.js +1 -0
  74. package/admin-build/_app/immutable/chunks/R6arueIl.js +1 -0
  75. package/admin-build/_app/immutable/chunks/UUazaC_N.js +1 -0
  76. package/admin-build/_app/immutable/chunks/cOYbrQxx.js +1 -0
  77. package/admin-build/_app/immutable/chunks/eFQHTGwA.js +1 -0
  78. package/admin-build/_app/immutable/chunks/ehbppgYb.js +1 -0
  79. package/admin-build/_app/immutable/chunks/glwixJlP.js +1 -0
  80. package/admin-build/_app/immutable/chunks/vApWTCBs.js +1 -0
  81. package/admin-build/_app/immutable/chunks/w89G9Xpi.js +1 -0
  82. package/admin-build/_app/immutable/chunks/wJsUhbfZ.js +1 -0
  83. package/admin-build/_app/immutable/chunks/zfauFM8P.js +1 -0
  84. package/admin-build/_app/immutable/entry/app.CcO-Uos3.js +2 -0
  85. package/admin-build/_app/immutable/entry/start.COebYq3I.js +1 -0
  86. package/admin-build/_app/immutable/nodes/0.CjtHKU-6.js +1 -0
  87. package/admin-build/_app/immutable/nodes/1.DEisjlM0.js +1 -0
  88. package/admin-build/_app/immutable/nodes/10.CvhdyWVB.js +1 -0
  89. package/admin-build/_app/immutable/nodes/11.DjHqcOvy.js +1 -0
  90. package/admin-build/_app/immutable/nodes/12.mQLz4Mj_.js +1 -0
  91. package/admin-build/_app/immutable/nodes/13.CBonZZyP.js +110 -0
  92. package/admin-build/_app/immutable/nodes/14.d-oiZL0j.js +3 -0
  93. package/admin-build/_app/immutable/nodes/15.CKPQsUYF.js +1 -0
  94. package/admin-build/_app/immutable/nodes/16.wPzAPQGx.js +1 -0
  95. package/admin-build/_app/immutable/nodes/17.DayhKyEZ.js +1 -0
  96. package/admin-build/_app/immutable/nodes/18.DKwS0Ir0.js +1 -0
  97. package/admin-build/_app/immutable/nodes/19.wPzAPQGx.js +1 -0
  98. package/admin-build/_app/immutable/nodes/2.BKoKrw1i.js +1 -0
  99. package/admin-build/_app/immutable/nodes/20.BvIkkkrW.js +1 -0
  100. package/admin-build/_app/immutable/nodes/21.DMaFhdHk.js +128 -0
  101. package/admin-build/_app/immutable/nodes/22.3xdgwuK1.js +1 -0
  102. package/admin-build/_app/immutable/nodes/23.8Bvgjbsl.js +112 -0
  103. package/admin-build/_app/immutable/nodes/24.DzSSzRhG.js +2 -0
  104. package/admin-build/_app/immutable/nodes/25.9KKYBnAE.js +2 -0
  105. package/admin-build/_app/immutable/nodes/26.Bhn9dfhY.js +1 -0
  106. package/admin-build/_app/immutable/nodes/27.kRLiC24G.js +1 -0
  107. package/admin-build/_app/immutable/nodes/28.BVIN1-7N.js +1 -0
  108. package/admin-build/_app/immutable/nodes/29.3yabZWj4.js +1 -0
  109. package/admin-build/_app/immutable/nodes/3.BFtSOkX7.js +2 -0
  110. package/admin-build/_app/immutable/nodes/30.CyCQlwaP.js +1 -0
  111. package/admin-build/_app/immutable/nodes/31.C4LDXjES.js +1 -0
  112. package/admin-build/_app/immutable/nodes/4.CvbiMlCa.js +1 -0
  113. package/admin-build/_app/immutable/nodes/5.C6BLv2eM.js +1 -0
  114. package/admin-build/_app/immutable/nodes/6.BcXvfl2P.js +1 -0
  115. package/admin-build/_app/immutable/nodes/7.CIuqhPiK.js +1 -0
  116. package/admin-build/_app/immutable/nodes/8.BQOR_JfO.js +1 -0
  117. package/admin-build/_app/immutable/nodes/9.NZqXQxPy.js +1 -0
  118. package/admin-build/_app/version.json +1 -0
  119. package/admin-build/favicon.svg +26 -0
  120. package/admin-build/index.html +45 -0
  121. package/openapi.json +19543 -0
  122. package/package.json +66 -0
  123. package/src/__tests__/admin-assets.test.ts +55 -0
  124. package/src/__tests__/admin-data-routes.test.ts +488 -0
  125. package/src/__tests__/admin-db-target.test.ts +103 -0
  126. package/src/__tests__/admin-routing.test.ts +31 -0
  127. package/src/__tests__/admin-user-management.test.ts +311 -0
  128. package/src/__tests__/analytics-query.test.ts +75 -0
  129. package/src/__tests__/auth-d1.test.ts +749 -0
  130. package/src/__tests__/auth-db-adapter.test.ts +73 -0
  131. package/src/__tests__/auth-jwt.test.ts +440 -0
  132. package/src/__tests__/auth-oauth.test.ts +389 -0
  133. package/src/__tests__/auth-password.test.ts +367 -0
  134. package/src/__tests__/auth-redirect.test.ts +87 -0
  135. package/src/__tests__/backup-restore.test.ts +711 -0
  136. package/src/__tests__/broadcast.test.ts +128 -0
  137. package/src/__tests__/cli.test.ts +178 -0
  138. package/src/__tests__/cloudflare-realtime.test.ts +113 -0
  139. package/src/__tests__/config.test.ts +469 -0
  140. package/src/__tests__/cors.test.ts +154 -0
  141. package/src/__tests__/cron.test.ts +302 -0
  142. package/src/__tests__/d1-handler.test.ts +402 -0
  143. package/src/__tests__/d1-sql.test.ts +120 -0
  144. package/src/__tests__/database-live-config.test.ts +42 -0
  145. package/src/__tests__/database-live-emitter.test.ts +56 -0
  146. package/src/__tests__/database-live-filters.test.ts +63 -0
  147. package/src/__tests__/database-live-route.test.ts +113 -0
  148. package/src/__tests__/db-sql.test.ts +163 -0
  149. package/src/__tests__/do-lifecycle.test.ts +263 -0
  150. package/src/__tests__/do-router.test.ts +729 -0
  151. package/src/__tests__/email-provider.test.ts +128 -0
  152. package/src/__tests__/email-templates.test.ts +528 -0
  153. package/src/__tests__/error-format.test.ts +250 -0
  154. package/src/__tests__/field-ops.test.ts +242 -0
  155. package/src/__tests__/functions-context.test.ts +334 -0
  156. package/src/__tests__/functions-d1-proxy.test.ts +229 -0
  157. package/src/__tests__/functions-registry-runtime-config.test.ts +17 -0
  158. package/src/__tests__/functions-route.test.ts +139 -0
  159. package/src/__tests__/internal-request.test.ts +77 -0
  160. package/src/__tests__/log-writer.test.ts +44 -0
  161. package/src/__tests__/logger.test.ts +58 -0
  162. package/src/__tests__/meta-admin-proxy.test.ts +48 -0
  163. package/src/__tests__/meta-export-coverage.test.ts +191 -0
  164. package/src/__tests__/meta-route-registration.test.ts +47 -0
  165. package/src/__tests__/namespace-dump.test.ts +28 -0
  166. package/src/__tests__/oauth-providers.test.ts +337 -0
  167. package/src/__tests__/openapi-coverage.test.ts +144 -0
  168. package/src/__tests__/pagination.test.ts +59 -0
  169. package/src/__tests__/password-policy.test.ts +191 -0
  170. package/src/__tests__/plugin-migrations.test.ts +379 -0
  171. package/src/__tests__/postgres-batch-compat.test.ts +133 -0
  172. package/src/__tests__/postgres-dialect.test.ts +328 -0
  173. package/src/__tests__/postgres-executor.test.ts +79 -0
  174. package/src/__tests__/postgres-field-ops-compat.test.ts +222 -0
  175. package/src/__tests__/postgres-schema-init.test.ts +105 -0
  176. package/src/__tests__/postgres-table-utils.test.ts +107 -0
  177. package/src/__tests__/presence.test.ts +199 -0
  178. package/src/__tests__/provider.test.ts +550 -0
  179. package/src/__tests__/public-user-profile.test.ts +339 -0
  180. package/src/__tests__/push-handlers.test.ts +179 -0
  181. package/src/__tests__/push-provider.test.ts +80 -0
  182. package/src/__tests__/push-token.test.ts +418 -0
  183. package/src/__tests__/query.test.ts +771 -0
  184. package/src/__tests__/rate-limit.test.ts +260 -0
  185. package/src/__tests__/room-access-policy.test.ts +101 -0
  186. package/src/__tests__/room-handler-context.test.ts +130 -0
  187. package/src/__tests__/room-monitoring.test.ts +138 -0
  188. package/src/__tests__/room-runtime-routing.test.ts +222 -0
  189. package/src/__tests__/room.test.ts +254 -0
  190. package/src/__tests__/route-parser.test.ts +490 -0
  191. package/src/__tests__/rules.test.ts +234 -0
  192. package/src/__tests__/runtime-surface-accounting.test.ts +120 -0
  193. package/src/__tests__/scheduled.test.ts +80 -0
  194. package/src/__tests__/schema.test.ts +1273 -0
  195. package/src/__tests__/security-hardening.test.ts +312 -0
  196. package/src/__tests__/server.unit.test.ts +333 -0
  197. package/src/__tests__/service-key-db-proxy.test.ts +650 -0
  198. package/src/__tests__/service-key-provider-bypass.test.ts +138 -0
  199. package/src/__tests__/service-key.test.ts +757 -0
  200. package/src/__tests__/smoke-skip-report.test.ts +72 -0
  201. package/src/__tests__/sms-provider.test.ts +39 -0
  202. package/src/__tests__/sql-route.test.ts +218 -0
  203. package/src/__tests__/storage-hook-context.test.ts +115 -0
  204. package/src/__tests__/totp.test.ts +200 -0
  205. package/src/__tests__/uuid.test.ts +144 -0
  206. package/src/__tests__/validation.test.ts +773 -0
  207. package/src/__tests__/websocket-pending.test.ts +163 -0
  208. package/src/_functions-registry.ts +51 -0
  209. package/src/bench-entry.ts +9 -0
  210. package/src/cloudflare-test.d.ts +1 -0
  211. package/src/durable-objects/auth-do.ts +49 -0
  212. package/src/durable-objects/database-do.ts +2240 -0
  213. package/src/durable-objects/database-live-do.ts +949 -0
  214. package/src/durable-objects/logs-do.ts +1200 -0
  215. package/src/durable-objects/room-runtime-base.ts +1604 -0
  216. package/src/durable-objects/rooms-do.ts +2191 -0
  217. package/src/generated-config.ts +6 -0
  218. package/src/index.ts +382 -0
  219. package/src/lib/admin-assets.ts +54 -0
  220. package/src/lib/admin-db-target.ts +301 -0
  221. package/src/lib/admin-routing.ts +35 -0
  222. package/src/lib/admin-user-management.ts +464 -0
  223. package/src/lib/analytics-adapter.ts +103 -0
  224. package/src/lib/analytics-query.ts +579 -0
  225. package/src/lib/auth-d1-service.ts +1193 -0
  226. package/src/lib/auth-d1.ts +1056 -0
  227. package/src/lib/auth-db-adapter.ts +289 -0
  228. package/src/lib/auth-redirect.ts +116 -0
  229. package/src/lib/cidr.ts +115 -0
  230. package/src/lib/client-ip.ts +51 -0
  231. package/src/lib/cloudflare-realtime.ts +251 -0
  232. package/src/lib/control-db.ts +36 -0
  233. package/src/lib/cron.ts +163 -0
  234. package/src/lib/d1-handler.ts +1425 -0
  235. package/src/lib/d1-schema-init.ts +255 -0
  236. package/src/lib/d1-sql.ts +33 -0
  237. package/src/lib/database-live-config.ts +24 -0
  238. package/src/lib/database-live-emitter.ts +111 -0
  239. package/src/lib/db-sql.ts +66 -0
  240. package/src/lib/do-retry.ts +36 -0
  241. package/src/lib/do-router.ts +270 -0
  242. package/src/lib/do-sql.ts +73 -0
  243. package/src/lib/email-provider.ts +379 -0
  244. package/src/lib/email-templates.ts +285 -0
  245. package/src/lib/email-translations.ts +422 -0
  246. package/src/lib/errors.ts +151 -0
  247. package/src/lib/functions.ts +2091 -0
  248. package/src/lib/hono.ts +56 -0
  249. package/src/lib/internal-request.ts +56 -0
  250. package/src/lib/jwt.ts +354 -0
  251. package/src/lib/log-writer.ts +272 -0
  252. package/src/lib/namespace-dump.ts +125 -0
  253. package/src/lib/oauth-providers.ts +1225 -0
  254. package/src/lib/op-parser.ts +99 -0
  255. package/src/lib/openapi.ts +146 -0
  256. package/src/lib/pagination.ts +19 -0
  257. package/src/lib/password-policy.ts +102 -0
  258. package/src/lib/password.ts +145 -0
  259. package/src/lib/plugin-migrations.ts +612 -0
  260. package/src/lib/postgres-executor.ts +203 -0
  261. package/src/lib/postgres-handler.ts +1102 -0
  262. package/src/lib/postgres-schema-init.ts +341 -0
  263. package/src/lib/postgres-table-utils.ts +87 -0
  264. package/src/lib/public-user-profile.ts +187 -0
  265. package/src/lib/push-provider.ts +409 -0
  266. package/src/lib/push-token.ts +294 -0
  267. package/src/lib/query-engine.ts +768 -0
  268. package/src/lib/room-monitoring.ts +97 -0
  269. package/src/lib/room-runtime.ts +14 -0
  270. package/src/lib/route-parser.ts +434 -0
  271. package/src/lib/schema.ts +538 -0
  272. package/src/lib/schemas.ts +152 -0
  273. package/src/lib/service-key.ts +419 -0
  274. package/src/lib/sms-provider.ts +230 -0
  275. package/src/lib/startup-config.ts +99 -0
  276. package/src/lib/totp.ts +242 -0
  277. package/src/lib/uuid.ts +87 -0
  278. package/src/lib/validation.ts +205 -0
  279. package/src/lib/version.ts +2 -0
  280. package/src/lib/websocket-pending.ts +40 -0
  281. package/src/middleware/auth.ts +169 -0
  282. package/src/middleware/captcha-verify.ts +217 -0
  283. package/src/middleware/cors.ts +159 -0
  284. package/src/middleware/error-handler.ts +54 -0
  285. package/src/middleware/internal-guard.ts +26 -0
  286. package/src/middleware/logger.ts +126 -0
  287. package/src/middleware/rate-limit.ts +283 -0
  288. package/src/middleware/rules.ts +475 -0
  289. package/src/routes/admin-auth.ts +447 -0
  290. package/src/routes/admin.ts +3501 -0
  291. package/src/routes/analytics-api.ts +290 -0
  292. package/src/routes/auth.ts +4222 -0
  293. package/src/routes/backup.ts +1466 -0
  294. package/src/routes/config.ts +53 -0
  295. package/src/routes/d1.ts +109 -0
  296. package/src/routes/database-live.ts +281 -0
  297. package/src/routes/functions.ts +155 -0
  298. package/src/routes/health.ts +32 -0
  299. package/src/routes/kv.ts +167 -0
  300. package/src/routes/oauth.ts +1055 -0
  301. package/src/routes/push.ts +1465 -0
  302. package/src/routes/room.ts +639 -0
  303. package/src/routes/schema-endpoint.ts +76 -0
  304. package/src/routes/sql.ts +176 -0
  305. package/src/routes/storage.ts +1674 -0
  306. package/src/routes/tables.ts +699 -0
  307. package/src/routes/users.ts +21 -0
  308. package/src/routes/vectorize.ts +372 -0
  309. package/src/types.ts +99 -0
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@edge-base/server",
3
+ "version": "0.1.1",
4
+ "description": "EdgeBase runtime assets consumed by the EdgeBase CLI",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/edge-base/edgebase.git",
9
+ "directory": "packages/server"
10
+ },
11
+ "homepage": "https://edgebase.fun",
12
+ "bugs": "https://github.com/edge-base/edgebase/issues",
13
+ "keywords": [
14
+ "edgebase",
15
+ "runtime",
16
+ "server",
17
+ "cloudflare-workers"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "type": "module",
23
+ "main": "./src/index.ts",
24
+ "files": [
25
+ "src",
26
+ "admin-build",
27
+ "openapi.json"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc --noEmit",
31
+ "lint": "eslint src/ --max-warnings 0",
32
+ "test": "vitest run --config vitest.unit.config.ts",
33
+ "test:integration": "./scripts/run-integration-shards.sh",
34
+ "bench": "vitest run --config vitest.bench.config.ts",
35
+ "dev": "./scripts/dev.sh",
36
+ "dev:raw": "wrangler dev",
37
+ "test:e2e": "vitest run --config vitest.e2e.config.ts",
38
+ "prepack": "pnpm --dir ../admin build && pnpm run build && node ./scripts/copy-admin-build.mjs"
39
+ },
40
+ "dependencies": {
41
+ "@edge-base/shared": "workspace:*",
42
+ "@hono/zod-openapi": "^1.2.2",
43
+ "@simplewebauthn/server": "^10",
44
+ "bcryptjs": "^3.0.3",
45
+ "hono": "^4.12.5",
46
+ "jose": "^6.0.0",
47
+ "pg": "^8.16.3",
48
+ "zod": "^4.3.6"
49
+ },
50
+ "devDependencies": {
51
+ "@cloudflare/vitest-pool-workers": "^0.8.71",
52
+ "@cloudflare/workers-types": "^4.20260305.1",
53
+ "@stryker-mutator/core": "^8.7.0",
54
+ "@stryker-mutator/typescript-checker": "^8.7.0",
55
+ "@stryker-mutator/vitest-runner": "^8.7.0",
56
+ "@types/bcryptjs": "^3.0.0",
57
+ "@types/pg": "^8.11.0",
58
+ "@types/ws": "^8.18.1",
59
+ "@vitest/coverage-v8": "^3.2.4",
60
+ "fast-check": "^4.5.3",
61
+ "typescript": "^5.7.0",
62
+ "vitest": "^3.0.0",
63
+ "wrangler": "^4.70.0",
64
+ "ws": "^8.19.0"
65
+ }
66
+ }
@@ -0,0 +1,55 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ createAdminAssetRequest,
4
+ createHarnessAssetRequest,
5
+ resolveAdminAssetPath,
6
+ resolveHarnessAssetPath,
7
+ } from '../lib/admin-assets.js';
8
+
9
+ describe('admin asset path resolution', () => {
10
+ it('serves index for the admin root', () => {
11
+ expect(resolveAdminAssetPath('/admin')).toBe('/');
12
+ expect(resolveAdminAssetPath('/admin/')).toBe('/');
13
+ });
14
+
15
+ it('strips the /admin prefix for built assets', () => {
16
+ expect(resolveAdminAssetPath('/admin/_app/version.json')).toBe('/_app/version.json');
17
+ expect(resolveAdminAssetPath('/admin/favicon.png')).toBe('/favicon.png');
18
+ });
19
+
20
+ it('falls back to index for client-side admin routes', () => {
21
+ expect(resolveAdminAssetPath('/admin/login')).toBe('/');
22
+ expect(resolveAdminAssetPath('/admin/database/tables')).toBe('/');
23
+ });
24
+
25
+ it('rewrites requests without dropping the query string', () => {
26
+ const request = new Request('http://localhost:8787/admin/login?next=%2Fadmin%2Fdatabase');
27
+ const rewritten = createAdminAssetRequest(request);
28
+ const url = new URL(rewritten.url);
29
+
30
+ expect(url.pathname).toBe('/');
31
+ expect(url.search).toBe('?next=%2Fadmin%2Fdatabase');
32
+ });
33
+ });
34
+
35
+ describe('harness asset path resolution', () => {
36
+ it('serves index for the harness root and client-side routes', () => {
37
+ expect(resolveHarnessAssetPath('/harness')).toBe('/harness.html');
38
+ expect(resolveHarnessAssetPath('/harness/')).toBe('/harness.html');
39
+ expect(resolveHarnessAssetPath('/harness/scenarios/registered')).toBe('/harness.html');
40
+ });
41
+
42
+ it('preserves explicit asset paths under /harness', () => {
43
+ expect(resolveHarnessAssetPath('/harness/assets/main.js')).toBe('/harness/assets/main.js');
44
+ expect(resolveHarnessAssetPath('/harness/favicon.svg')).toBe('/harness/favicon.svg');
45
+ });
46
+
47
+ it('rewrites harness requests without dropping the query string', () => {
48
+ const request = new Request('http://localhost:8787/harness/scenarios?mode=golden');
49
+ const rewritten = createHarnessAssetRequest(request);
50
+ const url = new URL(rewritten.url);
51
+
52
+ expect(url.pathname).toBe('/harness.html');
53
+ expect(url.search).toBe('?mode=golden');
54
+ });
55
+ });
@@ -0,0 +1,488 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import { OpenAPIHono, type HonoEnv } from '../lib/hono.js';
3
+ import { adminRoute } from '../routes/admin.js';
4
+ import { setConfig } from '../lib/do-router.js';
5
+ import { defineConfig } from '@edge-base/shared';
6
+ import type { Env } from '../types.js';
7
+
8
+ function createApp() {
9
+ const app = new OpenAPIHono<HonoEnv>();
10
+ app.route('/admin/api', adminRoute);
11
+ return app;
12
+ }
13
+
14
+ function createConfig(databases: NonNullable<ReturnType<typeof defineConfig>['databases']>) {
15
+ return defineConfig({
16
+ databases,
17
+ serviceKeys: {
18
+ keys: [
19
+ {
20
+ kid: 'root',
21
+ tier: 'root',
22
+ scopes: ['*'],
23
+ secretSource: 'inline',
24
+ inlineSecret: 'sk-root',
25
+ },
26
+ ],
27
+ },
28
+ });
29
+ }
30
+
31
+ describe('admin data routes', () => {
32
+ afterEach(() => {
33
+ setConfig({});
34
+ });
35
+
36
+ it('reports effective providers and dynamic metadata in admin schema', async () => {
37
+ setConfig(
38
+ createConfig({
39
+ shared: {
40
+ tables: {
41
+ posts: { schema: { title: { type: 'string' } } },
42
+ },
43
+ },
44
+ workspace: {
45
+ instance: true,
46
+ admin: {
47
+ instances: {
48
+ source: 'manual',
49
+ targetLabel: 'Workspace',
50
+ helperText: 'Enter a workspace ID.',
51
+ },
52
+ },
53
+ tables: {
54
+ tasks: { schema: { done: { type: 'boolean' } } },
55
+ },
56
+ },
57
+ analytics: {
58
+ provider: 'postgres',
59
+ tables: {
60
+ events: { schema: { name: { type: 'string' } } },
61
+ },
62
+ },
63
+ reporting: {
64
+ provider: 'neon',
65
+ tables: {
66
+ snapshots: { schema: { label: { type: 'string' } } },
67
+ },
68
+ },
69
+ }),
70
+ );
71
+
72
+ const app = createApp();
73
+ const response = await app.request(
74
+ '/admin/api/data/schema',
75
+ {
76
+ headers: {
77
+ 'X-EdgeBase-Service-Key': 'sk-root',
78
+ },
79
+ },
80
+ {} as Env,
81
+ );
82
+
83
+ expect(response.status).toBe(200);
84
+ await expect(response.json()).resolves.toMatchObject({
85
+ namespaces: {
86
+ shared: {
87
+ provider: 'd1',
88
+ dynamic: false,
89
+ },
90
+ workspace: {
91
+ provider: 'do',
92
+ dynamic: true,
93
+ instanceDiscovery: {
94
+ source: 'manual',
95
+ targetLabel: 'Workspace',
96
+ helperText: 'Enter a workspace ID.',
97
+ },
98
+ },
99
+ analytics: {
100
+ provider: 'postgres',
101
+ dynamic: false,
102
+ },
103
+ reporting: {
104
+ provider: 'neon',
105
+ dynamic: false,
106
+ },
107
+ },
108
+ schema: {
109
+ posts: {
110
+ namespace: 'shared',
111
+ provider: 'd1',
112
+ dynamic: false,
113
+ },
114
+ tasks: {
115
+ namespace: 'workspace',
116
+ provider: 'do',
117
+ dynamic: true,
118
+ instanceDiscovery: {
119
+ source: 'manual',
120
+ targetLabel: 'Workspace',
121
+ helperText: 'Enter a workspace ID.',
122
+ },
123
+ },
124
+ events: {
125
+ namespace: 'analytics',
126
+ provider: 'postgres',
127
+ dynamic: false,
128
+ },
129
+ snapshots: {
130
+ namespace: 'reporting',
131
+ provider: 'neon',
132
+ dynamic: false,
133
+ },
134
+ },
135
+ });
136
+ });
137
+
138
+ it('rejects dynamic record browsing without an instanceId', async () => {
139
+ setConfig(
140
+ createConfig({
141
+ workspace: {
142
+ instance: true,
143
+ tables: {
144
+ members: { schema: { userId: { type: 'string' } } },
145
+ },
146
+ },
147
+ }),
148
+ );
149
+
150
+ const app = createApp();
151
+ const response = await app.request(
152
+ '/admin/api/data/tables/members/records',
153
+ {
154
+ headers: {
155
+ 'X-EdgeBase-Service-Key': 'sk-root',
156
+ },
157
+ },
158
+ {} as Env,
159
+ );
160
+
161
+ expect(response.status).toBe(400);
162
+ await expect(response.json()).resolves.toMatchObject({
163
+ code: 400,
164
+ message: "instanceId is required for dynamic namespace 'workspace'",
165
+ });
166
+ });
167
+
168
+ it('routes dynamic record browsing to the scoped DO when instanceId is provided', async () => {
169
+ setConfig(
170
+ createConfig({
171
+ workspace: {
172
+ instance: true,
173
+ tables: {
174
+ members: { schema: { userId: { type: 'string' } } },
175
+ },
176
+ },
177
+ }),
178
+ );
179
+
180
+ const stub = {
181
+ fetch: vi.fn().mockResolvedValue(
182
+ new Response(JSON.stringify({ rows: [{ id: '1' }], total: 1 }), {
183
+ status: 200,
184
+ headers: { 'Content-Type': 'application/json' },
185
+ }),
186
+ ),
187
+ };
188
+ const env = {
189
+ DATABASE: {
190
+ idFromName: vi.fn().mockReturnValue('do-id'),
191
+ get: vi.fn().mockReturnValue(stub),
192
+ },
193
+ } as unknown as Env;
194
+
195
+ const app = createApp();
196
+ const response = await app.request(
197
+ '/admin/api/data/tables/members/records?instanceId=ws-1&limit=1',
198
+ {
199
+ headers: {
200
+ 'X-EdgeBase-Service-Key': 'sk-root',
201
+ },
202
+ },
203
+ env,
204
+ );
205
+
206
+ expect(response.status).toBe(200);
207
+ await expect(response.json()).resolves.toMatchObject({
208
+ rows: [{ id: '1' }],
209
+ total: 1,
210
+ });
211
+
212
+ expect(stub.fetch).toHaveBeenCalledTimes(1);
213
+ const forwardedInit = stub.fetch.mock.calls[0]?.[1] as RequestInit;
214
+ const headers = new Headers(forwardedInit.headers);
215
+ expect(headers.get('X-DO-Name')).toBe('workspace:ws-1');
216
+ });
217
+
218
+ it('uses D1 run() for admin SQL mutations so table rename actually executes', async () => {
219
+ setConfig(
220
+ createConfig({
221
+ shared: {
222
+ tables: {
223
+ posts: { schema: { title: { type: 'string' } } },
224
+ },
225
+ },
226
+ }),
227
+ );
228
+
229
+ const stmt: {
230
+ bind: ReturnType<typeof vi.fn>;
231
+ all: ReturnType<typeof vi.fn>;
232
+ run: ReturnType<typeof vi.fn>;
233
+ } = {
234
+ bind: vi.fn(() => stmt),
235
+ all: vi.fn().mockResolvedValue({ results: [] }),
236
+ run: vi.fn().mockResolvedValue({ meta: { changes: 0 } }),
237
+ };
238
+ const env = {
239
+ DB_D1_SHARED: {
240
+ prepare: vi.fn(() => stmt),
241
+ },
242
+ } as unknown as Env;
243
+
244
+ const app = createApp();
245
+ const response = await app.request(
246
+ '/admin/api/data/sql',
247
+ {
248
+ method: 'POST',
249
+ headers: {
250
+ 'Content-Type': 'application/json',
251
+ 'X-EdgeBase-Service-Key': 'sk-root',
252
+ },
253
+ body: JSON.stringify({
254
+ namespace: 'shared',
255
+ sql: 'ALTER TABLE "posts" RENAME TO "articles"',
256
+ }),
257
+ },
258
+ env,
259
+ );
260
+
261
+ expect(response.status).toBe(200);
262
+ expect((env as unknown as { DB_D1_SHARED: { prepare: ReturnType<typeof vi.fn> } }).DB_D1_SHARED.prepare).toHaveBeenCalledWith(
263
+ 'ALTER TABLE "posts" RENAME TO "articles"',
264
+ );
265
+ expect(stmt.run).toHaveBeenCalledTimes(1);
266
+ expect(stmt.all).not.toHaveBeenCalled();
267
+ });
268
+
269
+ it('proxies namespace dump and restore through admin backup routes for D1-backed blocks', async () => {
270
+ setConfig(
271
+ createConfig({
272
+ shared: {
273
+ tables: {
274
+ posts: { schema: { title: { type: 'string' } } },
275
+ },
276
+ },
277
+ }),
278
+ );
279
+
280
+ const selectAll = vi.fn()
281
+ .mockResolvedValueOnce({ results: [{ id: '1', title: 'Hello' }] })
282
+ .mockResolvedValueOnce({ results: [{ key: 'schemaHash:posts', value: 'abc' }] });
283
+ const selectFirst = vi.fn().mockResolvedValue(null);
284
+ const run = vi.fn().mockResolvedValue({ meta: { changes: 0 } });
285
+
286
+ const prepare = vi.fn((sql: string) => {
287
+ const stmt = {
288
+ bind: vi.fn(() => stmt),
289
+ all: vi.fn(() => {
290
+ if (sql.startsWith('SELECT * FROM')) {
291
+ return selectAll();
292
+ }
293
+ return Promise.resolve({ results: [] });
294
+ }),
295
+ first: vi.fn(() => selectFirst()),
296
+ run: vi.fn(() => run()),
297
+ };
298
+ return stmt;
299
+ });
300
+
301
+ const env = {
302
+ DB_D1_SHARED: {
303
+ prepare,
304
+ batch: vi.fn().mockResolvedValue([]),
305
+ },
306
+ } as unknown as Env;
307
+
308
+ const app = createApp();
309
+
310
+ const dumpResponse = await app.request(
311
+ '/admin/api/data/backup/dump-data',
312
+ {
313
+ method: 'POST',
314
+ headers: {
315
+ 'Content-Type': 'application/json',
316
+ 'X-EdgeBase-Service-Key': 'sk-root',
317
+ },
318
+ body: JSON.stringify({ namespace: 'shared' }),
319
+ },
320
+ env,
321
+ );
322
+
323
+ expect(dumpResponse.status).toBe(200);
324
+ await expect(dumpResponse.json()).resolves.toMatchObject({
325
+ namespace: 'shared',
326
+ tables: {
327
+ posts: [{ id: '1', title: 'Hello' }],
328
+ _meta: [{ key: 'schemaHash:posts', value: 'abc' }],
329
+ },
330
+ });
331
+
332
+ const restoreResponse = await app.request(
333
+ '/admin/api/data/backup/restore-data',
334
+ {
335
+ method: 'POST',
336
+ headers: {
337
+ 'Content-Type': 'application/json',
338
+ 'X-EdgeBase-Service-Key': 'sk-root',
339
+ },
340
+ body: JSON.stringify({
341
+ namespace: 'shared',
342
+ tables: {
343
+ posts: [{ id: '1', title: 'Hello' }],
344
+ _meta: [{ key: 'schemaHash:posts', value: 'abc' }],
345
+ },
346
+ }),
347
+ },
348
+ env,
349
+ );
350
+
351
+ expect(restoreResponse.status).toBe(200);
352
+ await expect(restoreResponse.json()).resolves.toMatchObject({
353
+ ok: true,
354
+ namespace: 'shared',
355
+ restored: 2,
356
+ });
357
+
358
+ expect((env as unknown as { DB_D1_SHARED: { batch: ReturnType<typeof vi.fn> } }).DB_D1_SHARED.batch).toHaveBeenCalled();
359
+ });
360
+
361
+ it('lists table-backed instance suggestions for dynamic namespaces', async () => {
362
+ setConfig(
363
+ createConfig({
364
+ shared: {
365
+ tables: {
366
+ workspaces: {
367
+ schema: {
368
+ name: { type: 'string' },
369
+ slug: { type: 'string' },
370
+ },
371
+ },
372
+ },
373
+ },
374
+ workspace: {
375
+ instance: true,
376
+ admin: {
377
+ instances: {
378
+ source: 'table',
379
+ targetLabel: 'Workspace',
380
+ namespace: 'shared',
381
+ table: 'workspaces',
382
+ labelField: 'name',
383
+ searchFields: ['name', 'slug'],
384
+ helperText: 'Pick a workspace.',
385
+ },
386
+ },
387
+ tables: {
388
+ members: { schema: { userId: { type: 'string' } } },
389
+ },
390
+ },
391
+ }),
392
+ );
393
+
394
+ const stmt: {
395
+ bind: ReturnType<typeof vi.fn>;
396
+ all: ReturnType<typeof vi.fn>;
397
+ } = {
398
+ bind: vi.fn(() => stmt),
399
+ all: vi.fn().mockResolvedValue({
400
+ results: [
401
+ { __edgebase_id: 'ws_1', __edgebase_label: 'Acme' },
402
+ { __edgebase_id: 'ws_2', __edgebase_label: 'Beta' },
403
+ ],
404
+ }),
405
+ };
406
+ const env = {
407
+ DB_D1_SHARED: {
408
+ prepare: vi.fn(() => stmt),
409
+ },
410
+ } as unknown as Env;
411
+
412
+ const app = createApp();
413
+ const response = await app.request(
414
+ '/admin/api/data/namespaces/workspace/instances?q=ac&limit=5',
415
+ {
416
+ headers: {
417
+ 'X-EdgeBase-Service-Key': 'sk-root',
418
+ },
419
+ },
420
+ env,
421
+ );
422
+
423
+ expect(response.status).toBe(200);
424
+ await expect(response.json()).resolves.toMatchObject({
425
+ discovery: {
426
+ source: 'table',
427
+ targetLabel: 'Workspace',
428
+ helperText: 'Pick a workspace.',
429
+ },
430
+ items: [
431
+ { id: 'ws_1', label: 'Acme' },
432
+ { id: 'ws_2', label: 'Beta' },
433
+ ],
434
+ });
435
+
436
+ expect((env as unknown as { DB_D1_SHARED: { prepare: ReturnType<typeof vi.fn> } }).DB_D1_SHARED.prepare).toHaveBeenCalledWith(
437
+ expect.stringContaining('FROM "workspaces"'),
438
+ );
439
+ });
440
+
441
+ it('lists function-backed instance suggestions for dynamic namespaces', async () => {
442
+ setConfig(
443
+ createConfig({
444
+ workspace: {
445
+ instance: true,
446
+ admin: {
447
+ instances: {
448
+ source: 'function',
449
+ targetLabel: 'Workspace',
450
+ helperText: 'Recent workspaces',
451
+ resolve: ({ query, limit }) => [
452
+ { id: 'ws_recent', label: `Recent ${query}` },
453
+ { id: 'ws_recent', label: 'Duplicate should be dropped' },
454
+ { id: 'bad:id', label: 'Invalid' },
455
+ ].slice(0, limit),
456
+ },
457
+ },
458
+ tables: {
459
+ members: { schema: { userId: { type: 'string' } } },
460
+ },
461
+ },
462
+ }),
463
+ );
464
+
465
+ const app = createApp();
466
+ const response = await app.request(
467
+ '/admin/api/data/namespaces/workspace/instances?q=team&limit=3',
468
+ {
469
+ headers: {
470
+ 'X-EdgeBase-Service-Key': 'sk-root',
471
+ },
472
+ },
473
+ {} as Env,
474
+ );
475
+
476
+ expect(response.status).toBe(200);
477
+ await expect(response.json()).resolves.toMatchObject({
478
+ discovery: {
479
+ source: 'function',
480
+ targetLabel: 'Workspace',
481
+ helperText: 'Recent workspaces',
482
+ },
483
+ items: [
484
+ { id: 'ws_recent', label: 'Recent team' },
485
+ ],
486
+ });
487
+ });
488
+ });
@@ -0,0 +1,103 @@
1
+ import { defineConfig } from '@edge-base/shared';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+ import {
4
+ executeAdminDbQuery,
5
+ resolveAdminInstanceOptions,
6
+ serializeAdminInstanceDiscovery,
7
+ } from '../lib/admin-db-target.js';
8
+
9
+ describe('admin db target helpers', () => {
10
+ it('serializes manual discovery metadata with fallback defaults', () => {
11
+ expect(
12
+ serializeAdminInstanceDiscovery(undefined, { fallbackManual: true }),
13
+ ).toEqual({
14
+ source: 'manual',
15
+ targetLabel: 'Target',
16
+ placeholder: 'Target ID',
17
+ helperText: 'Enter a target ID to browse records and run queries for this table.',
18
+ });
19
+
20
+ expect(serializeAdminInstanceDiscovery({
21
+ source: 'manual',
22
+ targetLabel: 'Workspace',
23
+ placeholder: 'Workspace ID',
24
+ helperText: 'Pick a workspace.',
25
+ })).toEqual({
26
+ source: 'manual',
27
+ targetLabel: 'Workspace',
28
+ placeholder: 'Workspace ID',
29
+ helperText: 'Pick a workspace.',
30
+ });
31
+ });
32
+
33
+ it('executes admin SQL against D1-backed static namespaces', async () => {
34
+ const all = vi.fn().mockResolvedValue({
35
+ results: [{ id: 'row-1', label: 'Acme' }],
36
+ });
37
+ const prepare = vi.fn(() => ({ all }));
38
+
39
+ const result = await executeAdminDbQuery({
40
+ env: {
41
+ DB_D1_SHARED: {
42
+ prepare,
43
+ },
44
+ } as any,
45
+ config: defineConfig({
46
+ databases: {
47
+ shared: {
48
+ provider: 'd1',
49
+ tables: {
50
+ posts: {},
51
+ },
52
+ },
53
+ },
54
+ }),
55
+ namespace: 'shared',
56
+ sql: 'SELECT id, label FROM posts',
57
+ });
58
+
59
+ expect(prepare).toHaveBeenCalledWith('SELECT id, label FROM posts');
60
+ expect(result).toEqual({
61
+ columns: ['id', 'label'],
62
+ rows: [{ id: 'row-1', label: 'Acme' }],
63
+ rowCount: 1,
64
+ });
65
+ });
66
+
67
+ it('returns empty suggestions for manual dynamic instance discovery', async () => {
68
+ const result = await resolveAdminInstanceOptions({
69
+ env: {} as any,
70
+ config: defineConfig({
71
+ databases: {
72
+ workspace: {
73
+ instance: true,
74
+ admin: {
75
+ instances: {
76
+ source: 'manual',
77
+ targetLabel: 'Workspace',
78
+ placeholder: 'Workspace ID',
79
+ helperText: 'Enter a workspace ID.',
80
+ },
81
+ },
82
+ tables: {
83
+ members: {},
84
+ },
85
+ },
86
+ },
87
+ }),
88
+ namespace: 'workspace',
89
+ query: 'acme',
90
+ limit: 20,
91
+ });
92
+
93
+ expect(result).toEqual({
94
+ discovery: {
95
+ source: 'manual',
96
+ targetLabel: 'Workspace',
97
+ placeholder: 'Workspace ID',
98
+ helperText: 'Enter a workspace ID.',
99
+ },
100
+ items: [],
101
+ });
102
+ });
103
+ });