@guren/server 2.15.0 → 2.16.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 (296) hide show
  1. package/dist/{DocsViewerServiceProvider-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js} +7 -12
  2. package/dist/{Hash-C8aejmi8.js → Hash-D2DFd8xX.js} +7 -57
  3. package/dist/{HttpException-BkS3euNG.js → HttpException-BlQ2yEmT.js} +2 -79
  4. package/dist/{Job-BVT813DO.js → Job-DxQK8h3P.js} +24 -179
  5. package/dist/{McpServiceProvider-BawsYjgN.js → McpServiceProvider-nNcbCIQX.js} +11 -20
  6. package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
  7. package/dist/agent/AgentApprovalRequested.d.ts +11 -39
  8. package/dist/agent/approval.d.ts +76 -187
  9. package/dist/agent/audit-emitter.d.ts +16 -44
  10. package/dist/agent/audit.d.ts +20 -56
  11. package/dist/agent/derive.d.ts +32 -66
  12. package/dist/agent/dispatch.d.ts +38 -90
  13. package/dist/agent/events.d.ts +11 -19
  14. package/dist/agent/meta-tools.d.ts +18 -46
  15. package/dist/agent/public.d.ts +6 -25
  16. package/dist/agent/public.js +1 -1
  17. package/dist/agent/redact.d.ts +16 -38
  18. package/dist/agent/scopes.d.ts +23 -69
  19. package/dist/auth/AuthManager.d.ts +19 -40
  20. package/dist/auth/AuthenticatableModel.d.ts +2 -2
  21. package/dist/auth/SessionGuard.d.ts +0 -1
  22. package/dist/auth/TokenGuard.d.ts +6 -26
  23. package/dist/auth/api-token.d.ts +16 -148
  24. package/dist/auth/context.d.ts +5 -10
  25. package/dist/auth/email-verification.d.ts +29 -127
  26. package/dist/auth/index.js +1 -1
  27. package/dist/auth/oauth/index.d.ts +35 -57
  28. package/dist/auth/password/DefaultHasher.d.ts +5 -14
  29. package/dist/auth/password/PasswordHasher.d.ts +5 -13
  30. package/dist/auth/password/hash-format.d.ts +5 -13
  31. package/dist/auth/password-reset.d.ts +16 -42
  32. package/dist/auth/providers/ModelUserProvider.d.ts +3 -4
  33. package/dist/auth/providers/UserProvider.d.ts +4 -4
  34. package/dist/auth/signed-token.d.ts +18 -0
  35. package/dist/auth/types.d.ts +9 -32
  36. package/dist/auth/utils.d.ts +6 -27
  37. package/dist/{auth-DkYoAPVn.js → auth-CbdPH4Cd.js} +169 -502
  38. package/dist/authorization/Gate.d.ts +9 -145
  39. package/dist/authorization/Policy.d.ts +6 -53
  40. package/dist/authorization/index.js +1 -1
  41. package/dist/authorization/middleware.d.ts +16 -62
  42. package/dist/authorization/types.d.ts +8 -64
  43. package/dist/{authorization-CdfbCj8J.js → authorization-CdEWZZw3.js} +44 -309
  44. package/dist/broadcasting/BroadcastManager.d.ts +29 -149
  45. package/dist/broadcasting/channels/Channel.d.ts +1 -19
  46. package/dist/broadcasting/channels/PresenceChannel.d.ts +1 -55
  47. package/dist/broadcasting/channels/PrivateChannel.d.ts +1 -23
  48. package/dist/broadcasting/drivers/MemoryDriver.d.ts +18 -70
  49. package/dist/broadcasting/drivers/RedisDriver.d.ts +3 -80
  50. package/dist/broadcasting/drivers/index.d.ts +1 -1
  51. package/dist/broadcasting/index.d.ts +1 -1
  52. package/dist/broadcasting/index.js +1 -1
  53. package/dist/broadcasting/types.d.ts +7 -88
  54. package/dist/{broadcasting-BwodCA4q.js → broadcasting-B5RzB0A2.js} +87 -414
  55. package/dist/cache/CacheManager.d.ts +8 -62
  56. package/dist/cache/TaggedCache.d.ts +2 -35
  57. package/dist/cache/index.js +1 -1
  58. package/dist/cache/stores/FileStore.d.ts +2 -36
  59. package/dist/cache/stores/MemoryStore.d.ts +2 -26
  60. package/dist/cache/stores/RedisStore.d.ts +1 -29
  61. package/dist/cache/types.d.ts +21 -128
  62. package/dist/{cache-BYnZf2FR.js → cache-BOOIr324.js} +19 -198
  63. package/dist/client-C4TEr_Dd.js +9 -0
  64. package/dist/console/Command.d.ts +17 -126
  65. package/dist/console/ConsoleKernel.d.ts +2 -74
  66. package/dist/console/Input.d.ts +5 -113
  67. package/dist/console/Output.d.ts +3 -99
  68. package/dist/console/types.d.ts +3 -33
  69. package/dist/container/Container.d.ts +12 -103
  70. package/dist/container/ServiceProvider.d.ts +17 -61
  71. package/dist/container/bindings.d.ts +5 -26
  72. package/dist/container/defineModule.d.ts +16 -54
  73. package/dist/container/definePlugin.d.ts +12 -45
  74. package/dist/container/types.d.ts +2 -34
  75. package/dist/context-CXk_umpT.js +21 -0
  76. package/dist/database/Factory.d.ts +4 -57
  77. package/dist/database/Seeder.d.ts +8 -46
  78. package/dist/database/SeederRunner.d.ts +3 -33
  79. package/dist/database/types.d.ts +3 -24
  80. package/dist/discovery/AutoDiscovery.d.ts +10 -82
  81. package/dist/{dispatch-erOS9epZ.js → dispatch-BAwzftws.js} +32 -79
  82. package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +2 -5
  83. package/dist/docs-viewer/endpoint.d.ts +5 -11
  84. package/dist/encryption/Encrypter.d.ts +5 -71
  85. package/dist/encryption/Hash.d.ts +7 -57
  86. package/dist/encryption/Random.d.ts +6 -99
  87. package/dist/encryption/index.js +3 -3
  88. package/dist/encryption/types.d.ts +10 -72
  89. package/dist/{encryption-D99Vmls3.js → encryption-uwP3Di4D.js} +9 -78
  90. package/dist/{endpoint-D6GIqOpe.js → endpoint-BXipU2Jj.js} +6 -12
  91. package/dist/endpoint-Dsw3Acvq.js +26 -0
  92. package/dist/errors/ExceptionHandler.d.ts +3 -90
  93. package/dist/errors/HttpException.d.ts +2 -79
  94. package/dist/errors/debug-page.d.ts +3 -17
  95. package/dist/errors/error-page.d.ts +1 -0
  96. package/dist/errors/exceptions/AuthenticationException.d.ts +2 -24
  97. package/dist/errors/exceptions/AuthorizationException.d.ts +1 -24
  98. package/dist/errors/exceptions/MethodNotAllowedException.d.ts +1 -23
  99. package/dist/errors/exceptions/NotFoundHttpException.d.ts +1 -27
  100. package/dist/errors/exceptions/ValidationException.d.ts +2 -43
  101. package/dist/errors/types.d.ts +1 -25
  102. package/dist/{errors-BgeOl_DC.js → errors-JpkcCjjn.js} +3 -41
  103. package/dist/events/Event.d.ts +1 -28
  104. package/dist/events/EventManager.d.ts +5 -107
  105. package/dist/events/Listener.d.ts +7 -55
  106. package/dist/events/builtin.d.ts +0 -24
  107. package/dist/events/index.js +1 -1
  108. package/dist/events/types.d.ts +4 -22
  109. package/dist/{events-aIH_bWRx.js → events-DOmAHDeP.js} +11 -191
  110. package/dist/facades/index.d.ts +2 -14
  111. package/dist/health/HealthCheck.d.ts +0 -24
  112. package/dist/health/HealthManager.d.ts +0 -36
  113. package/dist/health/checks/CacheCheck.d.ts +2 -17
  114. package/dist/health/checks/CustomCheck.d.ts +0 -9
  115. package/dist/health/checks/DatabaseCheck.d.ts +2 -17
  116. package/dist/health/checks/MemoryCheck.d.ts +3 -12
  117. package/dist/health/checks/RedisCheck.d.ts +1 -13
  118. package/dist/health/checks/StorageCheck.d.ts +2 -17
  119. package/dist/health/index.js +1 -1
  120. package/dist/health/types.d.ts +4 -24
  121. package/dist/{health-VWdWXRwh.js → health-DQSvUplL.js} +1 -76
  122. package/dist/hot-disposables-B5BXqaIH.js +167 -0
  123. package/dist/hot-reload/hot-disposables.d.ts +22 -74
  124. package/dist/hot-reload/testing.d.ts +4 -9
  125. package/dist/http/Application.d.ts +62 -208
  126. package/dist/http/FormRequest.d.ts +4 -55
  127. package/dist/http/dev-assets.d.ts +13 -31
  128. package/dist/http/dev-banner.d.ts +2 -5
  129. package/dist/http/inertia-assets.d.ts +3 -6
  130. package/dist/http/middleware/capabilities.d.ts +27 -50
  131. package/dist/http/middleware/cors.d.ts +4 -29
  132. package/dist/http/middleware/csp.d.ts +2 -25
  133. package/dist/http/middleware/csrf.d.ts +20 -95
  134. package/dist/http/middleware/detect-locale.d.ts +7 -27
  135. package/dist/http/middleware/force-https.d.ts +6 -24
  136. package/dist/http/middleware/host-authorization.d.ts +2 -12
  137. package/dist/http/middleware/loopback-guard.d.ts +15 -33
  138. package/dist/http/middleware/rate-limit.d.ts +29 -126
  139. package/dist/http/middleware/redirect-safety.d.ts +2 -20
  140. package/dist/http/middleware/request-id.d.ts +1 -14
  141. package/dist/http/middleware/request-logging.d.ts +2 -13
  142. package/dist/http/middleware/response-headers.d.ts +5 -13
  143. package/dist/http/middleware/security-headers.d.ts +2 -16
  144. package/dist/http/middleware/session.d.ts +15 -34
  145. package/dist/http/middleware/validation-errors-cookie.d.ts +7 -18
  146. package/dist/http/middleware/validation.d.ts +8 -63
  147. package/dist/http/public-assets.d.ts +11 -7
  148. package/dist/http/request.d.ts +32 -118
  149. package/dist/http/resources/CursorPaginator.d.ts +5 -64
  150. package/dist/http/resources/Paginator.d.ts +7 -84
  151. package/dist/http/resources/Resource.d.ts +9 -65
  152. package/dist/http/resources/ResourceCollection.d.ts +5 -39
  153. package/dist/http/resources/types.d.ts +10 -30
  154. package/dist/http/static-documents.d.ts +10 -20
  155. package/dist/http/validation/Validator.d.ts +25 -85
  156. package/dist/http/validation/rules.d.ts +48 -147
  157. package/dist/http/validation/types.d.ts +16 -61
  158. package/dist/http/vite-assets.d.ts +5 -28
  159. package/dist/http/vite-dev-server.d.ts +6 -9
  160. package/dist/http/vite-manifest.d.ts +19 -33
  161. package/dist/i18n/I18nManager.d.ts +12 -78
  162. package/dist/i18n/Translator.d.ts +3 -54
  163. package/dist/i18n/index.js +1 -1
  164. package/dist/i18n/loaders/JsonLoader.d.ts +4 -31
  165. package/dist/i18n/loaders/MemoryLoader.d.ts +1 -21
  166. package/dist/i18n/pluralization.d.ts +4 -13
  167. package/dist/i18n/types.d.ts +17 -69
  168. package/dist/{i18n-mcWi7LCd.js → i18n-Cg1aajRP.js} +31 -225
  169. package/dist/index.d.ts +2 -1
  170. package/dist/index.js +714 -3011
  171. package/dist/internal/agent-preflight.d.ts +9 -21
  172. package/dist/internal/request.d.ts +6 -19
  173. package/dist/internal/request.js +1 -1
  174. package/dist/internal/route-path.d.ts +9 -21
  175. package/dist/internal/route-path.js +9 -21
  176. package/dist/internal/zod-compat.d.ts +55 -122
  177. package/dist/internal/zod-compat.js +39 -70
  178. package/dist/internal/zod-json-schema.d.ts +18 -54
  179. package/dist/internal/zod-json-schema.js +46 -123
  180. package/dist/jsx-runtime.d.ts +3 -8
  181. package/dist/lambda/index.d.ts +17 -79
  182. package/dist/lambda/index.js +11 -59
  183. package/dist/logging/LogManager.d.ts +1 -51
  184. package/dist/logging/Logger.d.ts +8 -47
  185. package/dist/logging/channels/ConsoleChannel.d.ts +1 -3
  186. package/dist/logging/channels/DailyFileChannel.d.ts +1 -3
  187. package/dist/logging/channels/FileChannel.d.ts +1 -3
  188. package/dist/logging/daily-file-path.d.ts +7 -16
  189. package/dist/logging/index.js +1 -1
  190. package/dist/logging/types.d.ts +13 -45
  191. package/dist/{logging-B-kngi3q.js → logging-zOY1XCtq.js} +52 -141
  192. package/dist/{loopback-guard-D0Kc7-xc.js → loopback-guard-DT9gHF0F.js} +41 -92
  193. package/dist/mail/Mail.d.ts +10 -106
  194. package/dist/mail/MailManager.d.ts +2 -60
  195. package/dist/mail/index.js +1 -1
  196. package/dist/mail/transports/LogTransport.d.ts +1 -4
  197. package/dist/mail/transports/MemoryTransport.d.ts +1 -63
  198. package/dist/mail/transports/ResendTransport.d.ts +1 -23
  199. package/dist/mail/transports/SmtpTransport.d.ts +1 -31
  200. package/dist/mail/types.d.ts +28 -150
  201. package/dist/{mail-DfEfSQEr.js → mail-76DWy9lj.js} +31 -289
  202. package/dist/mcp/McpServiceProvider.d.ts +4 -10
  203. package/dist/mcp/create-mcp-server.d.ts +25 -57
  204. package/dist/mcp/endpoint.d.ts +12 -36
  205. package/dist/mcp/index.js +1 -1
  206. package/dist/mvc/Controller.d.ts +46 -227
  207. package/dist/mvc/Router.d.ts +50 -129
  208. package/dist/mvc/inertia/InertiaEngine.d.ts +18 -48
  209. package/dist/mvc/inertia/shared.d.ts +6 -19
  210. package/dist/mvc/mount-route.d.ts +2 -6
  211. package/dist/mvc/view.d.ts +1 -2
  212. package/dist/notifications/Notification.d.ts +8 -75
  213. package/dist/notifications/NotificationManager.d.ts +15 -88
  214. package/dist/notifications/channels/DatabaseChannel.d.ts +1 -41
  215. package/dist/notifications/channels/MailChannel.d.ts +2 -31
  216. package/dist/notifications/channels/MemoryChannel.d.ts +2 -62
  217. package/dist/notifications/channels/SlackChannel.d.ts +3 -48
  218. package/dist/notifications/index.js +1 -1
  219. package/dist/notifications/notifiable-type.d.ts +3 -6
  220. package/dist/notifications/registry.d.ts +8 -27
  221. package/dist/notifications/types.d.ts +16 -53
  222. package/dist/{notifications-BGqmUNZ8.js → notifications-okWFs9ly.js} +37 -335
  223. package/dist/providers/AuthServiceProvider.d.ts +1 -3
  224. package/dist/providers/AuthorizationServiceProvider.d.ts +2 -3
  225. package/dist/providers/BroadcastServiceProvider.d.ts +1 -3
  226. package/dist/providers/CacheServiceProvider.d.ts +1 -3
  227. package/dist/providers/EncryptionServiceProvider.d.ts +1 -3
  228. package/dist/providers/ErrorServiceProvider.d.ts +1 -4
  229. package/dist/providers/EventServiceProvider.d.ts +1 -3
  230. package/dist/providers/HealthServiceProvider.d.ts +1 -3
  231. package/dist/providers/I18nServiceProvider.d.ts +6 -10
  232. package/dist/providers/InertiaServiceProvider.d.ts +1 -4
  233. package/dist/providers/LogServiceProvider.d.ts +1 -3
  234. package/dist/providers/MailServiceProvider.d.ts +1 -3
  235. package/dist/providers/NotificationServiceProvider.d.ts +1 -3
  236. package/dist/providers/OAuthServiceProvider.d.ts +1 -3
  237. package/dist/providers/QueueServiceProvider.d.ts +1 -3
  238. package/dist/providers/SchedulingServiceProvider.d.ts +1 -3
  239. package/dist/providers/StorageServiceProvider.d.ts +1 -3
  240. package/dist/queue/FailedJobReporter.d.ts +1 -24
  241. package/dist/queue/Job.d.ts +12 -99
  242. package/dist/queue/QueueManager.d.ts +6 -57
  243. package/dist/queue/Worker.d.ts +4 -65
  244. package/dist/queue/drivers/MemoryDriver.d.ts +3 -44
  245. package/dist/queue/drivers/RedisDriver.d.ts +7 -65
  246. package/dist/queue/drivers/SqsDriver.d.ts +6 -57
  247. package/dist/queue/drivers/SyncDriver.d.ts +10 -13
  248. package/dist/queue/index.js +2 -2
  249. package/dist/queue/types.d.ts +10 -92
  250. package/dist/{queue-CXrRK85G.js → queue-CcXCjuJI.js} +32 -260
  251. package/dist/redis/RedisApiTokenStore.d.ts +4 -56
  252. package/dist/redis/RedisEmailVerificationStore.d.ts +4 -37
  253. package/dist/redis/RedisOAuthStateStore.d.ts +2 -10
  254. package/dist/redis/RedisPasswordResetStore.d.ts +4 -37
  255. package/dist/redis/RedisRateLimitStore.d.ts +16 -49
  256. package/dist/redis/RedisSessionStore.d.ts +3 -44
  257. package/dist/redis/client.d.ts +2 -32
  258. package/dist/redis/index.js +47 -232
  259. package/dist/redis/redis-values.d.ts +6 -12
  260. package/dist/redis/scan-keys.d.ts +1 -4
  261. package/dist/request-CLOYytGP.js +68 -0
  262. package/dist/runtime/index.d.ts +2 -0
  263. package/dist/runtime/index.js +50 -92
  264. package/dist/scheduling/CronParser.d.ts +0 -29
  265. package/dist/scheduling/Schedule.d.ts +1 -153
  266. package/dist/scheduling/ScheduledTask.d.ts +0 -31
  267. package/dist/scheduling/Scheduler.d.ts +0 -70
  268. package/dist/scheduling/index.js +1 -1
  269. package/dist/scheduling/types.d.ts +4 -65
  270. package/dist/{scheduling-CPiEdtQd.js → scheduling-C6tcOtUl.js} +2 -287
  271. package/dist/storage/StorageManager.d.ts +0 -48
  272. package/dist/storage/drivers/LocalDriver.d.ts +1 -25
  273. package/dist/storage/drivers/MemoryDriver.d.ts +5 -35
  274. package/dist/storage/drivers/S3Driver.d.ts +6 -36
  275. package/dist/storage/drivers/s3-acl.d.ts +5 -10
  276. package/dist/storage/index.js +1 -1
  277. package/dist/storage/types.d.ts +27 -265
  278. package/dist/{storage-TLD9t0Q2.js → storage-BB59f07j.js} +17 -157
  279. package/dist/support/contained-path.d.ts +10 -20
  280. package/dist/support/error-polyfill.d.ts +4 -6
  281. package/dist/support/expiry.d.ts +17 -33
  282. package/dist/support/expiry.js +17 -33
  283. package/dist/support/import-map.d.ts +3 -7
  284. package/dist/support/inertia-defaults.d.ts +5 -10
  285. package/dist/support/redirect-target.d.ts +4 -6
  286. package/dist/support/stack-frames.d.ts +11 -50
  287. package/dist/support/trim-slashes.d.ts +4 -7
  288. package/dist/support/warn-once.d.ts +2 -6
  289. package/dist/{trim-slashes-ZJ_VsY5s.js → trim-slashes-BLY9hKAa.js} +4 -7
  290. package/dist/{vite-manifest-w_RSOvQW.js → vite-manifest-CTQp-SOo.js} +34 -58
  291. package/package.json +2 -2
  292. package/dist/client-Dd7vLcqp.js +0 -27
  293. package/dist/context-DoD0c7J_.js +0 -26
  294. package/dist/endpoint-D-20PiHY.js +0 -46
  295. package/dist/hot-disposables-WsTX2ySN.js +0 -281
  296. package/dist/request-CVQwpu2J.js +0 -129
@@ -1,281 +0,0 @@
1
- //#region src/support/stack-frames.ts
2
- /**
3
- * Which `(` opens the parenthesized location group at the end of a stack frame.
4
- *
5
- * That one question is all the package's two frame readers agree on — the debug
6
- * error page's `parseStackTrace` and the hot-reload registry's
7
- * `parseFrameLocation`. Everything after it differs on purpose: peeling
8
- * `:line[:column]` off the right (the page requires a column and keeps the
9
- * function name; the registry accepts a bare `:line`), and deciding which
10
- * locations are worth keeping at all (the registry rejects `eval` groups and
11
- * synthetic paths, because keying an owner on text that is not a path is worse
12
- * than not keying it; the page is happy to display whatever it was handed).
13
- * Keep every parenthesis fix here so those two cannot drift.
14
- *
15
- * A third reader, `packages/orm/src/active-connections.ts`, carries a copy of
16
- * the function below whose *body* is identical character for character; only
17
- * the prose around it differs, to speak about connections rather than frames.
18
- * That package must not import this one, so the two are kept in step by hand —
19
- * fix both, or neither.
20
- */
21
- const OPEN_PAREN = 40;
22
- const CLOSE_PAREN = 41;
23
- /** The characters a stack frame can never span, so a scan stops at them. */
24
- function isLineTerminator(code) {
25
- return code === 10 || code === 13 || code === 8232 || code === 8233;
26
- }
27
- /**
28
- * The index of the `(` that matches the `)` at `closeIndex`, or `undefined`
29
- * when the frame carries no usable `(` at all.
30
- *
31
- * `closeIndex` is a parameter rather than derived here because each caller
32
- * already knows where its frame ends and gets there differently — two trim a
33
- * copy of the frame, the ORM's twin keeps an `end` offset to avoid allocating
34
- * one. It must point at the frame's final `)`; anything else is rejected.
35
- *
36
- * Neither the leftmost nor the rightmost `(` is right in general. A path may
37
- * contain one — `at fn (/app (old)/x.ts:1:2)` needs the outer, *leftmost* pair
38
- * — and so may the function name in front of it — `at weird (name)
39
- * (/app/x.ts:1:2)` needs the outer, *rightmost* pair. Depth is what actually
40
- * tells the two apart; a fixed "first" or "last" gets one of them wrong, and a
41
- * frame carrying both — `at weird (name) (/app (old)/x.ts:1:2)`, which is one
42
- * developer's checkout directory away from ordinary — is misread by either.
43
- *
44
- * A scan is also the only form that stays linear. Lazily matching from the
45
- * leftmost `(` retries the whole suffix at every parenthesis, which is
46
- * quadratic on a frame carrying many unmatched ones. Characters are compared by
47
- * code rather than tested against a pattern for the same reason the patterns
48
- * went: this loop runs over every character of every frame, and the one input
49
- * whose length nothing bounds is a frame — an error message can embed
50
- * request-derived text, and a continuation line of one that starts `at ` and
51
- * ends `)` is scanned in full.
52
- *
53
- * Depth alone would reject a frame whose location holds an *unmatched* `)`, as
54
- * `/app/name).ts` or a URL ending `?label=)` does — the scan runs off the front
55
- * still owing a paren, and the frame is dropped rather than displayed. So the
56
- * leftmost `(` the scan passed is kept as a fallback for exactly that case.
57
- * Only frames the depth rule rejects outright can reach it, so it is never
58
- * worse than depth alone, and it is the reading that keeps such a path whole.
59
- *
60
- * The scan stops at a line terminator: a path could never span one, so neither
61
- * a balanced `(` nor the fallback may come from the far side of a break.
62
- */
63
- function matchingOpenParen(frame, closeIndex) {
64
- if (frame.charCodeAt(closeIndex) !== CLOSE_PAREN) return;
65
- let depth = 0;
66
- let leftmostOpen;
67
- for (let index = closeIndex; index >= 0; index--) {
68
- const code = frame.charCodeAt(index);
69
- if (isLineTerminator(code)) break;
70
- if (code === CLOSE_PAREN) depth++;
71
- else if (code === OPEN_PAREN) {
72
- if (--depth === 0) return index;
73
- leftmostOpen = index;
74
- }
75
- }
76
- return leftmostOpen;
77
- }
78
- //#endregion
79
- //#region src/hot-reload/hot-disposables.ts
80
- /**
81
- * Stops the timers a previous module evaluation left running.
82
- *
83
- * `bun --hot` re-runs the module graph inside the same process. Anything the
84
- * previous evaluation built is dropped on the floor — but a `setInterval`
85
- * callback keeps its owner reachable, so a store, manager, or scheduler that
86
- * nothing references any more goes on firing forever. One extra timer per
87
- * reload, each one retaining the dead object graph behind it.
88
- *
89
- * `globalThis` survives re-evaluation, so it is where the previous owner's
90
- * teardown is parked — the same storage `Application.listen()` uses for the Bun
91
- * and Vite dev servers, and the same approach `@guren/orm` uses for database
92
- * connections. Bun does not expose `import.meta.hot` to `bun --hot` (checked on
93
- * 1.3.14), so there is no reload hook to register with instead.
94
- *
95
- * This is deliberately not the ORM's registry with the names changed. Closing a
96
- * connection is an async operation that can hang on a wedged socket, which is
97
- * what forces that module's serialized claims and teardown timeout. Every
98
- * teardown here is synchronous — `clearInterval`, and the `destroy()`/`stop()`
99
- * methods wrapping it — so a claim can simply run the previous teardown inline
100
- * and be done. Sharing the registries would buy machinery neither side needs in
101
- * the same shape.
102
- *
103
- * Its twin is `packages/orm/src/active-connections.ts`. `parseFrameLocation` and
104
- * `describeCallerFile`'s walk past a synthetic frame follow the same rule in
105
- * both — a fix to either has to be carried to the other by hand. That has
106
- * already failed once: this walk predates the ORM's, and the ORM kept keying
107
- * handles to `unknown` in the meantime. Nothing forces the duplication —
108
- * `@guren/server` already depends on `@guren/orm`, so this layer could live
109
- * there and be imported here — it is only that the shared part is small next to
110
- * the two packages' very different teardown semantics (see above). Extract the
111
- * rest if it drifts again.
112
- *
113
- * One piece already went that way, for a reason worth recording: the debug error
114
- * page turned out to read frames too, and had written its own, wrong version of
115
- * the paren rule. That scan now lives in `../support/stack-frames`, imported by
116
- * both readers in this package — the ORM's copy of it is still hand-synced like
117
- * everything else here.
118
- *
119
- * An owner is identified by the file that built it plus a discriminator, so it
120
- * is replaced only by a later evaluation of that same file. Keying on the exact
121
- * line would be more precise, but a line number changes the moment anything
122
- * above it does — adding an import would orphan the previous entry and leak the
123
- * timer it was holding, during the very workflow this exists to fix. The file is
124
- * stable across every edit that isn't a rename.
125
- */
126
- const REGISTRY_KEY = Symbol.for("guren.server.hotDisposables");
127
- function getRegistry() {
128
- const scope = globalThis;
129
- return scope[REGISTRY_KEY] ??= /* @__PURE__ */ new Map();
130
- }
131
- /**
132
- * Whether modules can be re-evaluated in this process.
133
- *
134
- * `bun --watch` restarts the process instead, which drops every timer with it,
135
- * so `--hot` is the only mode that leaks. Everywhere else — production, tests,
136
- * CLI commands, serverless — nothing is ever torn down automatically.
137
- *
138
- * Exported so callers can skip building the `Error` whose stack identifies them:
139
- * capturing one formats the whole stack into a string, and outside `--hot` it
140
- * would only be thrown away.
141
- */
142
- function isHotReloadRuntime() {
143
- return typeof process !== "undefined" && Array.isArray(process.execArgv) && process.execArgv.includes("--hot");
144
- }
145
- /**
146
- * Paths the engine reports for code that has no source location.
147
- *
148
- * A class that runs code without declaring a constructor — a subclass, or any
149
- * class carrying a field initializer — gets an implicit one, and JSC reports it
150
- * as `at new Owner (unknown:1:28)`: a frame sitting between the code that ran
151
- * and the code that actually wrote `new`. Taking it would key every such owner
152
- * in the process to the string `unknown`, collapsing owners built in different
153
- * files into one slot where each new one stops the last. `native` shows up the
154
- * same way for built-ins (`at map (native:1:11)`).
155
- */
156
- const SYNTHETIC_FRAME_PATHS = /* @__PURE__ */ new Set([
157
- "unknown",
158
- "native",
159
- "<anonymous>"
160
- ]);
161
- const LOCATION_SUFFIX = /:\d+(?::\d+)?$/;
162
- /** Both match one character, so neither can backtrack the way `\s*` in a pattern can. */
163
- const WHITESPACE = /\s/;
164
- const LINE_TERMINATOR = /[\n\r\u2028\u2029]/;
165
- /**
166
- * What a bare `at …` frame carries, with surrounding whitespace dropped.
167
- *
168
- * Scanned rather than captured with `/^\s*at\s+(.+?)\s*$/`, whose lazy body and
169
- * greedy tail both laid claim to the same spaces: a frame padded with a run of
170
- * them took time cubic in the run's length before concluding it did not match.
171
- *
172
- * One case is read differently on purpose. Where the frame is `at` and nothing
173
- * but whitespace, the pattern handed back a single space as the body; this
174
- * rejects it. The two agree at the only boundary that matters, because a body
175
- * carrying no `:line` is discarded by the caller either way.
176
- */
177
- function parseBareFrame(frame) {
178
- const end = frame.trimEnd().length;
179
- let cursor = 0;
180
- while (cursor < end && WHITESPACE.test(frame[cursor])) cursor += 1;
181
- if (!frame.startsWith("at", cursor)) return void 0;
182
- const afterAt = cursor + 2;
183
- let start = afterAt;
184
- while (start < end && WHITESPACE.test(frame[start])) start += 1;
185
- if (start === afterAt) return void 0;
186
- const body = frame.slice(start, end);
187
- return LINE_TERMINATOR.test(body) ? void 0 : body;
188
- }
189
- /**
190
- * The text inside the parentheses that close a frame, or `undefined` when the
191
- * frame does not end in one.
192
- *
193
- * Which `(` opens them is `matchingOpenParen`'s problem — both the path and the
194
- * function name in front of it may contain parentheses, and neither end of the
195
- * frame is the right place to look in general.
196
- */
197
- function parenthesizedLocation(frame) {
198
- const trimmed = frame.trimEnd();
199
- if (!trimmed.endsWith(")")) return;
200
- const open = matchingOpenParen(trimmed, trimmed.length - 1);
201
- return open === void 0 ? void 0 : trimmed.slice(open + 1, -1);
202
- }
203
- /**
204
- * The path a single stack frame points at, without its line and column.
205
- *
206
- * The parenthesized shape is read first because its parentheses bound the path;
207
- * the bare `at /path/file.ts:1:2` can only be bounded by whitespace, which would
208
- * truncate `/Users/me/My Projects/app.ts` to `Projects/app.ts`. Nothing
209
- * constrains what the path may contain — spaces and parentheses are both
210
- * ordinary in a macOS directory name.
211
- *
212
- * The trailing `:line` is what proves this is a location at all rather than a
213
- * bare function name, so `at native` and `at <anonymous>` yield nothing. An
214
- * `eval` group is rejected outright: V8 nests the real location inside
215
- * `eval at fn (/app/x.ts:1:2), <anonymous>:1:1`, and keying an owner on text
216
- * that is not a path is worse than not keying it — an owner with no key is left
217
- * alone, which is the safe failure.
218
- */
219
- function parseFrameLocation(frame) {
220
- const location = parenthesizedLocation(frame) ?? parseBareFrame(frame);
221
- if (!location || location.startsWith("eval at ") || !LOCATION_SUFFIX.test(location)) return;
222
- return location.replace(LOCATION_SUFFIX, "");
223
- }
224
- /**
225
- * The file that built the timer owner.
226
- *
227
- * `stack` must come from an `Error` constructed inside the constructor or
228
- * factory itself, so frame 0 is `Error`, frame 1 is that function, and frame 2
229
- * is the caller — or the first frame after it that names a real file, since the
230
- * engine may have synthesized the frames in between. Only the path is kept: a
231
- * reload re-runs the same file, but not necessarily at the same line.
232
- */
233
- function describeCallerFile(stack) {
234
- for (const frame of stack?.split("\n").slice(2) ?? []) {
235
- const path = parseFrameLocation(frame);
236
- if (path && !SYNTHETIC_FRAME_PATHS.has(path)) return path;
237
- }
238
- }
239
- /**
240
- * Identity for a timer owner across hot reloads, or `undefined` when the owner
241
- * must be left alone.
242
- *
243
- * `target` separates owners that share a call site — the name of a cache store,
244
- * say — so one module building several does not collapse them into a slot where
245
- * each new one stops the last.
246
- */
247
- function hotReloadKey(scope, stack, target) {
248
- if (!isHotReloadRuntime()) return;
249
- const callerFile = describeCallerFile(stack);
250
- return callerFile ? `${scope}|${callerFile}|${target}` : void 0;
251
- }
252
- /**
253
- * Records `dispose` as the live owner for this identity, stops whichever owner
254
- * held it before, and hands back the claim so the new owner can give it up.
255
- *
256
- * Returns `undefined` outside `--hot`, or when the stack does not name a caller
257
- * — the owner is then simply left alone, which is how things behaved before this
258
- * registry existed.
259
- *
260
- * A teardown that throws is reported and swallowed: the replacement has already
261
- * been built by the time this runs, and refusing to register it would leak the
262
- * very timer this is here to stop.
263
- */
264
- function claimHotDisposable(scope, stack, target, dispose) {
265
- const key = hotReloadKey(scope, stack, target);
266
- if (!key) return;
267
- const registry = getRegistry();
268
- const previous = registry.get(key);
269
- registry.delete(key);
270
- if (previous && previous !== dispose) try {
271
- previous();
272
- } catch (error) {
273
- console.warn("[guren] Failed to stop the previous hot-reload disposable:", error);
274
- }
275
- registry.set(key, dispose);
276
- return { release() {
277
- if (registry.get(key) === dispose) registry.delete(key);
278
- } };
279
- }
280
- //#endregion
281
- export { isHotReloadRuntime as n, matchingOpenParen as r, claimHotDisposable as t };
@@ -1,129 +0,0 @@
1
- //#region src/http/request.ts
2
- function isPlainObject(value) {
3
- return typeof value === "object" && value !== null && !Array.isArray(value);
4
- }
5
- /**
6
- * Parses the incoming request body and returns the parsed value as-is: a JSON
7
- * array stays an array, a JSON string stays a string. Use this wherever the
8
- * result is handed to a schema and *that* decides the shape — a route
9
- * contract's `body`, `Controller.validateBody()`, `validateRequest()`.
10
- *
11
- * Falls back to an empty object when the body cannot be parsed (malformed
12
- * JSON, a form body the parser cannot decode, an empty POST, an unsupported
13
- * content type). That fallback is load bearing: an all-optional object schema
14
- * has to keep passing on an empty body, which `undefined` would break. The
15
- * cost is that a non-object schema sees `{}` there and fails validation,
16
- * rather than receiving nothing.
17
- *
18
- * The fallback does not distinguish whose fault the failure was: a body the
19
- * client could never have sent correctly and a body already consumed upstream
20
- * (middleware reading `ctx.req.raw` directly, bypassing Hono's cache) both read
21
- * as `{}` here. That is deliberate — the JSON branch above has always behaved
22
- * this way, and telling the two apart means matching runtime-specific error
23
- * codes, which would answer differently on Bun, Node and Workers. A parser
24
- * error is a poor signal for a middleware-ordering bug either way.
25
- *
26
- * Form submissions have no non-object shape to preserve, so they normalize to
27
- * a record exactly as {@link parseRequestPayload} does.
28
- */
29
- async function parseRequestBody(ctx) {
30
- if ((ctx.req.header("content-type") ?? "").includes("application/json")) return ctx.req.json().catch(() => ({}));
31
- if (typeof ctx.req.parseBody === "function") try {
32
- const form = await ctx.req.parseBody();
33
- return Object.fromEntries(Object.entries(form).map(([key, value]) => [key, Array.isArray(value) ? value[0] : value]));
34
- } catch {
35
- return {};
36
- }
37
- return {};
38
- }
39
- /**
40
- * The one multipart read behind `Controller.file()` and `Controller.files()`,
41
- * guarded so a body the parser cannot decode carries no files rather than
42
- * crashing the request: it reads as `{}`, which is the same answer both helpers
43
- * already give for a field that is simply absent — `null` and `[]`. Left to
44
- * throw, the parser's `TypeError` escaped as a 500 reporting the exception and
45
- * a stack, the defect {@link parseRequestBody} fixes for the validation paths.
46
- *
47
- * Deliberately *not* routed through {@link parseRequestBody}, which looks like
48
- * the same rule and is not: it parses without `{ all: true }` and flattens a
49
- * repeated field to its first value, so sharing it would silently reduce
50
- * `files()` to one file per field. `{ all: true }` is the contract here, and a
51
- * malformed-body test cannot see its loss — hence the separate function.
52
- *
53
- * There is no media-type gate, deliberately: Hono decides the media type inside
54
- * `parseBody()`, having lowercased it first. A caller that gates before calling
55
- * — or that reads uploads through `Request.formData()`, whose handling of the
56
- * media type is not Hono's — answers `null` for an uppercase
57
- * `MULTIPART/FORM-DATA` body this returns the file for.
58
- *
59
- * That was measured on Bun 1.3.14, and the host half of it has already moved:
60
- * Bun 1.4.0 accepts the same header `1.3.14` rejects, and Node always did. The
61
- * divergence is therefore a property of *where the media type is decided*, not
62
- * of any one runtime — which is the argument for deciding it in one place, and
63
- * why `@guren/testing`'s controller mock reaches this function rather than
64
- * restating it.
65
- *
66
- * try/catch rather than `.catch()`, for the reason given on the shared
67
- * fallback: `parseBody` may throw synchronously as well as reject, and only one
68
- * of those two shapes reaches a `.catch()`.
69
- *
70
- * It fails open in one direction, deliberately and for the same reason
71
- * {@link parseRequestBody} does: a body already consumed upstream reads as
72
- * "no upload" rather than throwing, so a middleware-ordering bug loses the 500
73
- * that used to announce it. Telling that apart from a client's malformed body
74
- * means matching runtime-specific error codes, which answer differently on Bun,
75
- * Node and Workers.
76
- */
77
- async function parseRequestUploads(ctx) {
78
- try {
79
- return await ctx.req.parseBody({ all: true });
80
- } catch {
81
- return {};
82
- }
83
- }
84
- /**
85
- * The record-shaped view of {@link parseRequestBody}, for callers that read the
86
- * payload field by field (`payload.channel`, per-field validation rules,
87
- * `Controller.input()`/`only()`/`except()`/`has()`). A body that is not a plain
88
- * object — an array, a string, `null` — becomes `{}`, because there is no
89
- * field to read on one.
90
- */
91
- async function parseRequestPayload(ctx) {
92
- return asRecord(await parseRequestBody(ctx));
93
- }
94
- /** Narrow a parsed body to the record view described on {@link parseRequestPayload}. */
95
- function asRecord(body) {
96
- return isPlainObject(body) ? body : {};
97
- }
98
- /**
99
- * Collects query parameters preserving repeated keys as arrays while keeping
100
- * single occurrences as plain strings (`?tag=a&tag=b` → `{ tag: ['a', 'b'] }`,
101
- * `?page=2` → `{ page: '2' }`). Use this instead of `ctx.req.query()` when
102
- * feeding query data into validation schemas.
103
- *
104
- * Materialized with `Object.fromEntries`, never by assigning into an object
105
- * literal — the same rule, and for the same reason, as the form branch of
106
- * {@link parseRequestBody} above. Query keys are attacker-controlled, and
107
- * `flat['__proto__'] = …` hits `Object.prototype`'s inherited setter instead
108
- * of defining a field: `?__proto__=one` silently vanished before reaching the
109
- * schema, and `?__proto__=one&__proto__=two` set the returned record's own
110
- * prototype to that array. Hono hands over a null-prototype object, so the
111
- * key arrives here intact; only this last step could lose it.
112
- */
113
- function flattenRequestQueries(ctx) {
114
- return Object.fromEntries(Object.entries(ctx.req.queries()).map(([key, values]) => [key, values.length === 1 ? values[0] : values]));
115
- }
116
- /**
117
- * Converts a Zod-style validation error into a flat record usable by forms.
118
- */
119
- function formatValidationErrors(error, fallbackMessage = "The provided data is invalid.") {
120
- const errors = {};
121
- for (const issue of error.issues ?? []) {
122
- const field = issue.path?.[0];
123
- if (typeof field === "string" && !errors[field]) errors[field] = issue.message;
124
- }
125
- if (Object.keys(errors).length === 0) errors.message = fallbackMessage;
126
- return errors;
127
- }
128
- //#endregion
129
- export { parseRequestPayload as a, parseRequestBody as i, flattenRequestQueries as n, parseRequestUploads as o, formatValidationErrors as r, asRecord as t };