@getstrata/core 2.2.59 → 3.0.3

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 (330) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/core/audit/exportAuditLogs.d.ts +12 -3
  3. package/dist/core/audit/exportStore.d.ts +6 -2
  4. package/dist/core/audit/siemFormatter.d.ts +2 -2
  5. package/dist/core/auth/abilityCatalog.d.ts +1 -9
  6. package/dist/core/auth/authContext.d.ts +2 -0
  7. package/dist/core/auth/authOutcome.d.ts +32 -0
  8. package/dist/core/auth/authReader.d.ts +22 -0
  9. package/dist/core/auth/basicAuthGuard.d.ts +19 -3
  10. package/dist/core/auth/emailVerification.d.ts +1 -1
  11. package/dist/core/auth/guard.d.ts +27 -6
  12. package/dist/core/auth/intendedUrlCookie.d.ts +13 -7
  13. package/dist/core/auth/jwt.d.ts +5 -4
  14. package/dist/core/auth/jwtGuard.d.ts +7 -6
  15. package/dist/core/auth/membershipContext.d.ts +10 -7
  16. package/dist/core/auth/membershipContextMiddleware.d.ts +3 -3
  17. package/dist/core/auth/membershipMiddleware.d.ts +1 -2
  18. package/dist/core/auth/membershipServiceImplementation.d.ts +1 -1
  19. package/dist/core/auth/oauth/oidcIdToken.d.ts +25 -16
  20. package/dist/core/auth/oauth/oidcProvider.d.ts +6 -4
  21. package/dist/core/auth/oauth/providers.d.ts +3 -1
  22. package/dist/core/auth/oneTimeToken.d.ts +2 -3
  23. package/dist/core/auth/passwordConfirmCookie.d.ts +15 -6
  24. package/dist/core/auth/passwordLogin.d.ts +5 -5
  25. package/dist/core/auth/pendingMfaCookie.d.ts +2 -2
  26. package/dist/core/auth/policy.d.ts +23 -10
  27. package/dist/core/auth/requireAuthCapability.d.ts +3 -0
  28. package/dist/core/auth/resolveMembershipService.d.ts +3 -2
  29. package/dist/core/auth/saml/samlAssertionReplay.d.ts +4 -4
  30. package/dist/core/auth/saml/samlServiceProvider.d.ts +11 -7
  31. package/dist/core/auth/scimAuthMiddleware.d.ts +10 -3
  32. package/dist/core/auth/sessionCookie.d.ts +20 -9
  33. package/dist/core/auth/sessionGuard.d.ts +14 -3
  34. package/dist/core/cache/createCacheStore.d.ts +6 -3
  35. package/dist/core/cache/redisCacheStore.d.ts +5 -1
  36. package/dist/core/cache/repository.d.ts +5 -1
  37. package/dist/core/cache/simpleCache.d.ts +2 -1
  38. package/dist/core/cache/tokens.d.ts +8 -0
  39. package/dist/core/config/applicationConfig.d.ts +21 -0
  40. package/dist/core/config/configSnapshot.d.ts +3 -0
  41. package/dist/core/config/envSchema.d.ts +3 -2
  42. package/dist/core/contracts/application.d.ts +153 -0
  43. package/dist/core/contracts/authUserDirectory.d.ts +24 -7
  44. package/dist/core/contracts/container.d.ts +20 -23
  45. package/dist/core/contracts/di.d.ts +4 -2
  46. package/dist/core/contracts/executionContext.d.ts +5 -0
  47. package/dist/core/contracts/executionOperations.d.ts +10 -0
  48. package/dist/core/contracts/executionOwnership.d.ts +38 -0
  49. package/dist/core/contracts/persistence.d.ts +20 -0
  50. package/dist/core/contracts/serviceTokens.d.ts +32 -18
  51. package/dist/core/contracts/services.d.ts +63 -0
  52. package/dist/core/contracts/token.d.ts +19 -0
  53. package/dist/core/crypto/fieldEncryption.d.ts +19 -7
  54. package/dist/core/crypto/fieldEncryptionRotation.d.ts +21 -5
  55. package/dist/core/crypto/mfaSecret.d.ts +10 -3
  56. package/dist/core/database/baseRepository.d.ts +14 -10
  57. package/dist/core/database/bindings.d.ts +6 -0
  58. package/dist/core/database/bunSql.d.ts +3 -12
  59. package/dist/core/database/definitions.d.ts +209 -0
  60. package/dist/core/database/dialect.d.ts +5 -24
  61. package/dist/core/database/driverPorts.d.ts +116 -0
  62. package/dist/core/database/errors.d.ts +47 -7
  63. package/dist/core/database/factory.d.ts +51 -31
  64. package/dist/core/database/index.d.ts +9 -10
  65. package/dist/core/database/keyset.d.ts +2 -1
  66. package/dist/core/database/legacyNativeTransaction.d.ts +5 -0
  67. package/dist/core/database/manager.d.ts +12 -0
  68. package/dist/core/database/model.d.ts +91 -97
  69. package/dist/core/database/modelQuery.d.ts +9 -5
  70. package/dist/core/database/modelRegistry.d.ts +52 -33
  71. package/dist/core/database/mysqlConnection.d.ts +1 -19
  72. package/dist/core/database/mysqlNative.d.ts +38 -0
  73. package/dist/core/database/nativeTransactions.d.ts +16 -0
  74. package/dist/core/database/ormInternal.d.ts +85 -0
  75. package/dist/core/database/ormRuntime.d.ts +4 -0
  76. package/dist/core/database/ownedReadOnlyObservation.d.ts +16 -0
  77. package/dist/core/database/postgresNative.d.ts +11 -0
  78. package/dist/core/database/query.d.ts +24 -23
  79. package/dist/core/database/queryPlanSnapshot.d.ts +7 -0
  80. package/dist/core/database/rawMysql.d.ts +7 -0
  81. package/dist/core/database/rawPostgres.d.ts +23 -0
  82. package/dist/core/database/rawSqlite.d.ts +6 -0
  83. package/dist/core/database/relationQueries.d.ts +3 -2
  84. package/dist/core/database/relationQuery.d.ts +24 -6
  85. package/dist/core/database/repositoryQuery.d.ts +6 -1
  86. package/dist/core/database/schema/driver.d.ts +1 -1
  87. package/dist/core/database/seeders/types.d.ts +1 -1
  88. package/dist/core/database/session.d.ts +13 -0
  89. package/dist/core/database/sessionFactory.d.ts +9 -0
  90. package/dist/core/database/sqlDialects.d.ts +22 -0
  91. package/dist/core/database/tokens.d.ts +7 -0
  92. package/dist/core/database/transactionSession.d.ts +43 -0
  93. package/dist/core/errors/http.d.ts +4 -1
  94. package/dist/core/events/{eventBus.d.ts → eventBusClass.d.ts} +1 -3
  95. package/dist/core/events/index.d.ts +2 -3
  96. package/dist/core/events/outbox/index.d.ts +44 -13
  97. package/dist/core/events/outbox/metrics.d.ts +4 -4
  98. package/dist/core/events/outbox/workerTransport.d.ts +17 -0
  99. package/dist/core/http/authMiddleware.d.ts +2 -2
  100. package/dist/core/http/authorizeMiddleware.d.ts +2 -2
  101. package/dist/core/http/bodySizeLimitMiddleware.d.ts +1 -1
  102. package/dist/core/http/conditionalResponse.d.ts +7 -2
  103. package/dist/core/http/contentSecurityPolicy.d.ts +4 -3
  104. package/dist/core/http/corsMiddleware.d.ts +2 -1
  105. package/dist/core/http/csrfMiddleware.d.ts +6 -1
  106. package/dist/core/http/csrfToken.d.ts +17 -7
  107. package/dist/core/http/databaseError.d.ts +4 -0
  108. package/dist/core/http/etag.d.ts +5 -2
  109. package/dist/core/http/flashMiddleware.d.ts +1 -1
  110. package/dist/core/http/flashSession.d.ts +13 -7
  111. package/dist/core/http/index.d.ts +1 -1
  112. package/dist/core/http/loginThrottleMiddleware.d.ts +3 -3
  113. package/dist/core/http/memoryThrottleMiddleware.d.ts +2 -2
  114. package/dist/core/http/parseMultipartUpload.d.ts +3 -2
  115. package/dist/core/http/requestMetaContext.d.ts +5 -0
  116. package/dist/core/http/requireAbilityMiddleware.d.ts +1 -1
  117. package/dist/core/http/requireAuthMiddleware.d.ts +2 -2
  118. package/dist/core/http/requirePasswordConfirmMiddleware.d.ts +2 -1
  119. package/dist/core/http/requireVerifiedMiddleware.d.ts +2 -2
  120. package/dist/core/http/requireWebAuthMiddleware.d.ts +2 -2
  121. package/dist/core/http/response.d.ts +4 -3
  122. package/dist/core/http/scimThrottleMiddleware.d.ts +4 -3
  123. package/dist/core/http/securedRouteModelBinding.d.ts +10 -3
  124. package/dist/core/http/securityHeadersMiddleware.d.ts +1 -2
  125. package/dist/core/http/signedUrl.d.ts +8 -6
  126. package/dist/core/http/throttleMiddleware.d.ts +9 -5
  127. package/dist/core/http/uploads.d.ts +9 -3
  128. package/dist/core/http/webErrorResponse.d.ts +8 -2
  129. package/dist/core/jobs/exportAuditLogsJob.d.ts +5 -2
  130. package/dist/core/jobs/invalidateCacheTagsJob.d.ts +5 -4
  131. package/dist/core/lifecycle/gracefulShutdown.d.ts +2 -5
  132. package/dist/core/logging/requestLoggingMiddleware.d.ts +1 -1
  133. package/dist/core/mail/mailer.d.ts +7 -5
  134. package/dist/core/openapi/generator.d.ts +12 -4
  135. package/dist/core/openapi/registeredRoute.d.ts +4 -4
  136. package/dist/core/queue/createAppQueue.d.ts +9 -4
  137. package/dist/core/queue/failedJobMetrics.d.ts +11 -2
  138. package/dist/core/queue/failedJobRepository.d.ts +6 -3
  139. package/dist/core/queue/failedJobService.d.ts +1 -0
  140. package/dist/core/queue/index.d.ts +16 -6
  141. package/dist/core/queue/jobRegistry.d.ts +3 -2
  142. package/dist/core/queue/jobRunner.d.ts +10 -4
  143. package/dist/core/queue/publicQueue.d.ts +18 -9
  144. package/dist/core/queue/queueConfig.d.ts +20 -10
  145. package/dist/core/queue/queueHandoff.d.ts +31 -0
  146. package/dist/core/queue/queueMetrics.d.ts +10 -3
  147. package/dist/core/queue/queueServices.d.ts +28 -0
  148. package/dist/core/queue/queueWorkerTransport.d.ts +28 -0
  149. package/dist/core/queue/redisQueue.d.ts +19 -10
  150. package/dist/core/queue/redisQueueKeys.d.ts +5 -5
  151. package/dist/core/queue/redisStreams.d.ts +17 -10
  152. package/dist/core/queue/resilientQueue.d.ts +10 -4
  153. package/dist/core/queue/types.d.ts +1 -0
  154. package/dist/core/runtime/appKeyPrefix.d.ts +5 -5
  155. package/dist/core/runtime/application.d.ts +7 -0
  156. package/dist/core/runtime/executionContext.d.ts +9 -0
  157. package/dist/core/runtime/executionTasks.d.ts +49 -0
  158. package/dist/core/runtime/resourceJournal.d.ts +67 -0
  159. package/dist/core/runtime/serviceGraph.d.ts +14 -0
  160. package/dist/core/security/oauthState.d.ts +13 -9
  161. package/dist/core/security/publicReads.d.ts +2 -2
  162. package/dist/core/security/safeFetch.d.ts +1 -0
  163. package/dist/core/security/safeUrl.d.ts +3 -0
  164. package/dist/core/security/scimTenantTokens.d.ts +1 -1
  165. package/dist/core/security/tokenExpiry.d.ts +1 -1
  166. package/dist/core/security/webhookSignature.d.ts +1 -1
  167. package/dist/core/storage/storage.d.ts +24 -16
  168. package/dist/core/tenant/databaseTenantContext.d.ts +5 -7
  169. package/dist/core/tenant/resolveTenant.d.ts +2 -2
  170. package/dist/core/tenant/scopedDatabasePolicy.d.ts +8 -0
  171. package/dist/core/tenant/tenantDatabaseScope.d.ts +3 -7
  172. package/dist/core/tenant/tenantMiddleware.d.ts +15 -4
  173. package/dist/core/tracing/otel.d.ts +4 -6
  174. package/dist/core/tracing/tracingMiddleware.d.ts +3 -3
  175. package/dist/core/view/etaViewEngine.d.ts +1 -1
  176. package/dist/core/view/index.d.ts +5 -4
  177. package/dist/core/view/tokens.d.ts +8 -0
  178. package/dist/core/view/viewRenderer.d.ts +2 -2
  179. package/dist/core/view/webErrorView.d.ts +8 -7
  180. package/dist/core/view/webLayoutData.d.ts +6 -4
  181. package/dist/entries/audit/exportAuditLogs.js +87 -1024
  182. package/dist/entries/audit/siemFormatter.js +4 -90
  183. package/dist/entries/auth/abilityCatalog.js +28 -0
  184. package/dist/entries/auth/accessControl.js +5 -16
  185. package/dist/entries/auth/accountStateMigration.js +216 -236
  186. package/dist/entries/auth/authOutcome.js +80 -0
  187. package/dist/entries/auth/authReader.js +68 -0
  188. package/dist/entries/auth/basicAuthGuard.js +144 -1249
  189. package/dist/entries/auth/emailVerification.js +2 -2
  190. package/dist/entries/auth/intendedUrlCookie.js +35 -59
  191. package/dist/entries/auth/jwt.js +22 -47
  192. package/dist/entries/auth/jwtGuard.js +99 -231
  193. package/dist/entries/auth/membershipMiddleware.js +71 -10
  194. package/dist/entries/auth/membershipScope.js +16 -22
  195. package/dist/entries/auth/membershipService.js +11 -28
  196. package/dist/entries/auth/oauth/oidcProvider.js +59 -64
  197. package/dist/entries/auth/oauth/providers.js +12 -95
  198. package/dist/entries/auth/oauth/samlProvider.js +53 -1080
  199. package/dist/entries/auth/oneTimeToken.js +27 -289
  200. package/dist/entries/auth/passwordConfirmCookie.js +40 -63
  201. package/dist/entries/auth/passwordLogin.js +94 -399
  202. package/dist/entries/auth/pendingMfaCookie.js +6 -6
  203. package/dist/entries/auth/policy.js +22 -56
  204. package/dist/entries/auth/saml/samlServiceProvider.js +55 -1084
  205. package/dist/entries/auth/scimAuthMiddleware.js +16 -3358
  206. package/dist/entries/auth/sessionCookie.js +58 -73
  207. package/dist/entries/auth/sessionGuard.js +95 -248
  208. package/dist/entries/auth/tokenHash.js +11 -43
  209. package/dist/entries/cache/createCacheStore.js +126 -117
  210. package/dist/entries/cache/repository.js +25 -0
  211. package/dist/entries/cache/simpleCache.js +12 -7
  212. package/dist/entries/cache/tokens.js +9 -0
  213. package/dist/entries/config/applicationConfig.js +163 -0
  214. package/dist/entries/config/envSchema.js +21 -4
  215. package/dist/entries/contracts/application.js +1 -0
  216. package/dist/entries/contracts/authUserDirectory.js +10 -0
  217. package/dist/entries/contracts/container.js +99 -26
  218. package/dist/entries/contracts/di.js +3 -0
  219. package/dist/entries/contracts/executionContext.js +7 -0
  220. package/dist/entries/contracts/executionOperations.js +7 -0
  221. package/dist/entries/contracts/executionOwnership.js +7 -0
  222. package/dist/entries/contracts/membership.js +1 -0
  223. package/dist/entries/contracts/persistence.js +1 -0
  224. package/dist/entries/contracts/serviceTokens.js +26 -116
  225. package/dist/entries/contracts/services.js +98 -0
  226. package/dist/entries/contracts/token.js +41 -0
  227. package/dist/entries/crypto/fieldEncryption.js +49 -50
  228. package/dist/entries/crypto/mfaSecret.js +86 -82
  229. package/dist/entries/database/acquisitionMetrics.js +107 -0
  230. package/dist/entries/database/baseRepository.d.ts +2 -0
  231. package/dist/entries/database/bindings.js +2082 -0
  232. package/dist/entries/database/definitions.js +175 -0
  233. package/dist/entries/database/errors.js +114 -89
  234. package/dist/entries/database/factory.js +67 -28
  235. package/dist/entries/database/migrations.js +172 -224
  236. package/dist/entries/database/model.d.ts +1 -0
  237. package/dist/entries/database/ownedReadOnlyObservation.js +1282 -0
  238. package/dist/entries/database/query.js +159 -161
  239. package/dist/entries/database/repositoryQuery.d.ts +1 -0
  240. package/dist/entries/database/repositoryQuery.js +1 -1373
  241. package/dist/entries/database/schema.js +216 -236
  242. package/dist/entries/database/session.js +1 -0
  243. package/dist/entries/database/sqliteConnection.js +525 -83
  244. package/dist/entries/database/tokens.js +9 -0
  245. package/dist/entries/errors/http.js +118 -1
  246. package/dist/entries/http/authMiddleware.js +8 -5
  247. package/dist/entries/http/authorizeMiddleware.js +1 -1
  248. package/dist/entries/http/bodySizeLimitMiddleware.js +2 -2
  249. package/dist/entries/http/clientIp.js +2 -2
  250. package/dist/entries/http/conditionalResponse.js +19 -7
  251. package/dist/entries/http/corsMiddleware.js +6 -101
  252. package/dist/entries/http/csrfMiddleware.js +92 -106
  253. package/dist/entries/http/csrfToken.js +58 -94
  254. package/dist/entries/http/etag.js +7 -4
  255. package/dist/entries/http/flashMiddleware.js +57 -99
  256. package/dist/entries/http/flashSession.js +41 -68
  257. package/dist/entries/http/memoryThrottleMiddleware.js +43 -186
  258. package/dist/entries/http/metricsMiddleware.js +2 -16
  259. package/dist/entries/http/parseMultipartUpload.js +15 -29
  260. package/dist/entries/http/requireAbilityMiddleware.js +2 -2
  261. package/dist/entries/http/requirePasswordConfirmMiddleware.js +19 -31
  262. package/dist/entries/http/requireVerifiedMiddleware.js +4 -7
  263. package/dist/entries/http/requireWebAuthMiddleware.js +2 -2
  264. package/dist/entries/http/response.js +67 -233
  265. package/dist/entries/http/routeMiddleware.js +0 -14
  266. package/dist/entries/http/scimThrottleMiddleware.js +43 -237
  267. package/dist/entries/http/securedRouteModelBinding.js +37 -25
  268. package/dist/entries/http/securityHeadersMiddleware.js +8 -25
  269. package/dist/entries/http/signedUrl.js +20 -110
  270. package/dist/entries/http/throttleMiddleware.js +41 -185
  271. package/dist/entries/http/uploads.js +9 -24
  272. package/dist/entries/jobs/exportAuditLogsJob.js +17 -1498
  273. package/dist/entries/jobs/invalidateCacheTagsJob.js +12 -47
  274. package/dist/entries/logging/requestLoggingMiddleware.js +4 -4
  275. package/dist/entries/mail/mailer.js +68 -78
  276. package/dist/entries/openapi/generator.js +33 -100
  277. package/dist/entries/queue/createAppQueue.js +416 -254
  278. package/dist/entries/queue/failedJobRepository.js +19 -8
  279. package/dist/entries/queue/failedJobService.js +1 -0
  280. package/dist/entries/queue/jobRunner.js +141 -66
  281. package/dist/entries/queue/publicQueue.js +411 -255
  282. package/dist/entries/queue/queueConfig.js +61 -0
  283. package/dist/entries/queue/queueHandoff.js +318 -0
  284. package/dist/entries/queue/queueMetrics.js +989 -1384
  285. package/dist/entries/queue/queueServices.js +133 -0
  286. package/dist/entries/queue/queueWorkerTransport.js +1703 -0
  287. package/dist/entries/queue/redisQueue.js +282 -180
  288. package/dist/entries/queue.js +6 -45
  289. package/dist/entries/runtime/application.js +1585 -0
  290. package/dist/entries/runtime/asyncContextStore.js +0 -16
  291. package/dist/entries/security/oauthState.js +35 -67
  292. package/dist/entries/security/publicReads.js +4 -4
  293. package/dist/entries/security/safeFetch.js +1 -0
  294. package/dist/entries/security/scimTenantTokens.js +3 -3
  295. package/dist/entries/security/tokenExpiry.js +2 -2
  296. package/dist/entries/security/totp.js +1 -87
  297. package/dist/entries/security/webhookSignature.js +2 -90
  298. package/dist/entries/storage/storage.js +120 -45
  299. package/dist/entries/tenant/databaseTenantContext.js +6 -907
  300. package/dist/entries/tenant/publicTenantHost.js +78 -0
  301. package/dist/entries/tenant/resolveTenant.js +14 -0
  302. package/dist/entries/tenant/scopedDatabasePolicy.js +75 -0
  303. package/dist/entries/tenant/tenancyConfig.js +1 -19
  304. package/dist/entries/tenant/tenantDatabaseScope.js +3 -892
  305. package/dist/entries/tracing/tracingMiddleware.js +104 -173
  306. package/dist/entries/view/tokens.js +11 -0
  307. package/dist/framework/public-api.d.ts +62 -44
  308. package/dist/index.js +10433 -11347
  309. package/dist/internal/ormInternal.js +117 -0
  310. package/dist/internal/ormRuntime.js +5000 -0
  311. package/package.json +158 -46
  312. package/dist/core/database/bindConnection.d.ts +0 -1
  313. package/dist/core/database/boundConnection.d.ts +0 -5
  314. package/dist/core/database/defaultConnection.d.ts +0 -7
  315. package/dist/core/database/namedConnections.d.ts +0 -15
  316. package/dist/core/database/readOnlyCollector.d.ts +0 -7
  317. package/dist/core/database/repositoryConnection.d.ts +0 -4
  318. package/dist/core/database/transaction.d.ts +0 -23
  319. package/dist/core/database/transactionControl.d.ts +0 -6
  320. package/dist/core/events/deferredModelEvents.d.ts +0 -7
  321. package/dist/core/facades/index.d.ts +0 -10
  322. package/dist/core/runtime/applicationRegistry.d.ts +0 -18
  323. package/dist/entries/database/bindConnection.js +0 -1
  324. package/dist/entries/database/boundConnection.js +0 -1
  325. package/dist/entries/database/defaultConnection.js +0 -1
  326. package/dist/entries/database/namedConnections.js +0 -1
  327. package/dist/entries/database/repositoryConnection.js +0 -1
  328. package/dist/entries/database/transaction.js +0 -1
  329. package/dist/entries/facades.js +0 -711
  330. package/dist/entries/runtime/applicationRegistry.js +0 -1
@@ -1,125 +1,17 @@
1
1
  // @bun
2
- var __esm = (fn, res, err) => () => {
3
- if (fn)
4
- try {
5
- res = fn(fn = 0);
6
- } catch (e) {
7
- err = [e];
8
- }
9
- if (err)
10
- throw err[0];
11
- return res;
12
- };
13
-
14
- // ../../src/core/runtime/asyncContextStore.ts
15
- import { AsyncLocalStorage } from "async_hooks";
16
- function createAsyncContextStore(key) {
17
- const symbol = Symbol.for(key);
18
- const globalRecord = globalThis;
19
- const existing = globalRecord[symbol];
20
- if (existing) {
21
- return existing;
22
- }
23
- const store = new AsyncLocalStorage;
24
- globalRecord[symbol] = store;
25
- return store;
26
- }
27
- var init_asyncContextStore = () => {};
28
-
29
- // ../../src/core/database/connectionContext.ts
30
- function runWithDatabaseConnection(connection, callback) {
31
- return activeConnection.run(connection, callback);
32
- }
33
- function getActiveDatabaseConnection(fallback) {
34
- return activeConnection.getStore() ?? fallback;
35
- }
36
- function hasActiveDatabaseConnection() {
37
- return activeConnection.getStore() !== undefined;
38
- }
39
- var activeConnection;
40
- var init_connectionContext = __esm(() => {
41
- init_asyncContextStore();
42
- activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
43
- });
44
-
45
- // ../../src/core/database/transactionControl.ts
46
- function unwrapTransactionRollback(error, depth = 0) {
47
- if (error instanceof TransactionRollback) {
48
- return error;
49
- }
50
- if (depth >= 5 || !(error instanceof Error) || error.cause === undefined) {
51
- return null;
52
- }
53
- return unwrapTransactionRollback(error.cause, depth + 1);
54
- }
55
- function hasActiveTransaction() {
56
- return hasActiveDatabaseConnection() && (transactionScopes.getStore()?.rollback.length ?? 0) > 0;
57
- }
58
- function requestTransactionRollback() {
59
- const state = transactionScopes.getStore();
60
- const index = state ? state.rollback.length - 1 : -1;
61
- if (!state || index < 0) {
62
- return;
63
- }
64
- state.rollback[index] = true;
65
- }
66
- function scopeRequestsRollback() {
67
- const state = transactionScopes.getStore();
68
- if (!state || state.rollback.length === 0) {
69
- return false;
70
- }
71
- return state.rollback[state.rollback.length - 1] === true;
72
- }
73
- async function commitOrRollbackScope(result) {
74
- if (scopeRequestsRollback()) {
75
- throw new TransactionRollback(result);
76
- }
77
- return result;
78
- }
79
- async function settleTransaction(work) {
80
- try {
81
- return await work();
82
- } catch (error) {
83
- const rollback = unwrapTransactionRollback(error);
84
- if (rollback) {
85
- return rollback.result;
86
- }
87
- throw error;
88
- }
89
- }
90
- async function runWithTransactionScope(callback) {
91
- const existing = transactionScopes.getStore();
92
- if (existing) {
93
- existing.rollback.push(false);
94
- try {
95
- return await callback();
96
- } finally {
97
- existing.rollback.pop();
98
- }
99
- }
100
- const state = { rollback: [false] };
101
- return await transactionScopes.run(state, callback);
102
- }
103
- var TransactionRollback, transactionScopes;
104
- var init_transactionControl = __esm(() => {
105
- init_asyncContextStore();
106
- init_connectionContext();
107
- TransactionRollback = class TransactionRollback extends Error {
108
- result;
109
- constructor(result) {
110
- super("Transaction rolled back");
111
- this.name = "TransactionRollback";
112
- this.result = result;
113
- }
114
- };
115
- transactionScopes = createAsyncContextStore("@getstrata/transactionScopes");
116
- });
117
-
118
2
  // ../../src/core/http/response.ts
119
3
  import { toHttpError as toHttpError2 } from "@getstrata/core/errors/http";
120
- import { logServerError, webErrorResponse } from "@getstrata/core/http/webErrorResponse";
4
+ import {
5
+ logServerError,
6
+ webErrorResponse
7
+ } from "@getstrata/core/http/webErrorResponse";
121
8
 
122
- // ../../src/core/database/errors.ts
9
+ // ../../src/core/http/databaseError.ts
10
+ import {
11
+ isPostgresError,
12
+ mapDatabaseError,
13
+ PersistenceError
14
+ } from "@getstrata/core/database/errors";
123
15
  import {
124
16
  BadRequestError,
125
17
  ConflictError,
@@ -127,122 +19,60 @@ import {
127
19
  toHttpError,
128
20
  UnprocessableEntityError
129
21
  } from "@getstrata/core/errors/http";
130
- function isPostgresError(error) {
131
- return typeof error === "object" && error !== null && (("errno" in error) || ("code" in error));
132
- }
133
- function getPostgresSqlState(error) {
134
- if (typeof error.errno === "string" && /^\d{5}$/.test(error.errno)) {
135
- return error.errno;
136
- }
137
- if (typeof error.errno === "number") {
138
- return String(error.errno).padStart(5, "0");
139
- }
140
- if (typeof error.code === "string" && /^\d{5}$/.test(error.code)) {
141
- return error.code;
142
- }
143
- return;
144
- }
145
- var MYSQL_ERRNO_MESSAGES = {
146
- 1062: () => new ConflictError("A record with these values already exists."),
147
- 1451: () => new UnprocessableEntityError("Record is still referenced by other records."),
148
- 1452: () => new UnprocessableEntityError("Referenced record does not exist."),
149
- 1048: () => new BadRequestError("Required field is missing."),
150
- 3819: () => new BadRequestError("Value violates a database constraint.")
151
- };
152
- function mapSqliteError(error) {
153
- const code = typeof error.code === "string" ? error.code : "";
154
- if (!code.startsWith("SQLITE_")) {
155
- return null;
156
- }
157
- if (code === "SQLITE_CONSTRAINT_UNIQUE" || code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
158
- return new ConflictError("A record with these values already exists.");
159
- }
160
- if (code === "SQLITE_CONSTRAINT_FOREIGNKEY") {
161
- return new UnprocessableEntityError("Operation conflicts with related records.");
162
- }
163
- if (code === "SQLITE_CONSTRAINT_NOTNULL") {
164
- return new BadRequestError("Required field is missing.");
165
- }
166
- if (code.startsWith("SQLITE_CONSTRAINT")) {
167
- return new BadRequestError("Value violates a database constraint.");
168
- }
169
- return new InternalServerError("Database operation failed.");
170
- }
171
- function mapMysqlError(error) {
172
- const code = typeof error.code === "string" ? error.code : "";
173
- if (!code.startsWith("ER_")) {
174
- return null;
175
- }
176
- const factory = typeof error.errno === "number" ? MYSQL_ERRNO_MESSAGES[error.errno] : undefined;
177
- return factory ? factory() : new InternalServerError("Database operation failed.");
178
- }
179
- function mapDatabaseError(error) {
180
- const httpError = toHttpError(error);
181
- if (httpError) {
182
- return httpError;
183
- }
184
- if (!isPostgresError(error)) {
22
+ function mapDatabaseHttpError(error) {
23
+ const existing = toHttpError(error);
24
+ if (existing)
25
+ return existing;
26
+ if (!(error instanceof PersistenceError) && !isPostgresError(error))
185
27
  return new InternalServerError;
28
+ const outer = mapDatabaseError(error);
29
+ let failure = outer;
30
+ if ((outer.code === "DATABASE_TRANSACTION_UNKNOWN" || outer.code === "DATABASE_TRANSACTION_FAILED") && outer.data !== "committed") {
31
+ const cause = Object.getOwnPropertyDescriptor(outer, "cause")?.value;
32
+ if (!(cause instanceof AggregateError) && (cause instanceof PersistenceError || isPostgresError(cause))) {
33
+ const direct = mapDatabaseError(cause);
34
+ if ([
35
+ "DATABASE_UNIQUE_CONSTRAINT",
36
+ "DATABASE_FOREIGN_KEY_CONSTRAINT",
37
+ "DATABASE_REFERENCED_RECORD",
38
+ "DATABASE_RELATED_RECORD_CONSTRAINT",
39
+ "DATABASE_NOT_NULL_CONSTRAINT",
40
+ "DATABASE_CHECK_CONSTRAINT"
41
+ ].includes(direct.code))
42
+ failure = direct;
43
+ }
186
44
  }
187
- const sqlite = mapSqliteError(error);
188
- if (sqlite) {
189
- return sqlite;
190
- }
191
- const mysql = mapMysqlError(error);
192
- if (mysql) {
193
- return mysql;
194
- }
195
- const sqlState = getPostgresSqlState(error);
196
- switch (sqlState) {
197
- case "23505":
198
- if (error.detail) {
199
- console.error("[database] unique violation", error.detail);
200
- }
201
- return new ConflictError("A record with these values already exists.");
202
- case "23503":
203
- if (error.detail) {
204
- console.error("[database] foreign-key violation", error.detail);
205
- }
206
- return new UnprocessableEntityError("Operation conflicts with related records.");
207
- case "23502":
208
- if (error.detail) {
209
- console.error("[database] not-null violation", error.detail);
210
- }
211
- return new BadRequestError("Required field is missing.");
212
- case "23514":
213
- if (error.detail) {
214
- console.error("[database] check violation", error.detail);
215
- }
216
- return new BadRequestError("Value violates a database constraint.");
45
+ switch (failure.code) {
46
+ case "DATABASE_UNIQUE_CONSTRAINT":
47
+ case "DATABASE_TRANSACTION_ROLLBACK_ONLY":
48
+ return new ConflictError(failure.message);
49
+ case "DATABASE_FOREIGN_KEY_CONSTRAINT":
50
+ case "DATABASE_REFERENCED_RECORD":
51
+ case "DATABASE_RELATED_RECORD_CONSTRAINT":
52
+ return new UnprocessableEntityError(failure.message);
53
+ case "DATABASE_NOT_NULL_CONSTRAINT":
54
+ case "DATABASE_CHECK_CONSTRAINT":
55
+ return new BadRequestError(failure.message);
217
56
  default:
218
- return new InternalServerError("Database operation failed.");
57
+ return new InternalServerError(failure.message);
219
58
  }
220
59
  }
221
- async function withDatabaseErrorHandling(operation) {
222
- try {
223
- return await operation();
224
- } catch (error) {
225
- throw mapDatabaseError(error);
226
- }
227
- }
228
- function isUniqueConstraintError(error) {
229
- if (!isPostgresError(error)) {
230
- return false;
231
- }
232
- if (error.code === "SQLITE_CONSTRAINT_UNIQUE" || error.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
233
- return true;
234
- }
235
- if (error.errno === 1062) {
236
- return true;
60
+
61
+ // ../../src/core/runtime/asyncContextStore.ts
62
+ import { AsyncLocalStorage } from "async_hooks";
63
+ function createAsyncContextStore(key) {
64
+ const symbol = Symbol.for(key);
65
+ const globalRecord = globalThis;
66
+ const existing = globalRecord[symbol];
67
+ if (existing) {
68
+ return existing;
237
69
  }
238
- return getPostgresSqlState(error) === "23505";
70
+ const store = new AsyncLocalStorage;
71
+ globalRecord[symbol] = store;
72
+ return store;
239
73
  }
240
74
 
241
- // ../../src/core/http/response.ts
242
- init_transactionControl();
243
-
244
75
  // ../../src/core/http/requestMetaContext.ts
245
- init_asyncContextStore();
246
76
  var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
247
77
  function runWithRequestMeta(meta, callback) {
248
78
  return requestMetaContext.run(meta, callback);
@@ -273,21 +103,21 @@ function noContentResponse() {
273
103
  return new Response(null, { status: 204 });
274
104
  }
275
105
  function errorResponse(error) {
276
- const mappedError = toHttpError2(error) ?? mapDatabaseError(error);
106
+ const mappedError = toHttpError2(error) ?? mapDatabaseHttpError(error);
277
107
  logServerError(error, mappedError);
278
108
  return Response.json({
279
109
  error: mappedError.message,
280
110
  ...mappedError.details === undefined ? {} : { details: mappedError.details }
281
111
  }, { status: mappedError.status, headers: { "Cache-Control": "no-store" } });
282
112
  }
283
- function withErrorHandling(handler) {
113
+ function withErrorHandling(handler, options = {}) {
114
+ const captured = { ...options };
284
115
  return async (...args) => {
285
116
  try {
286
117
  return await handler(...args);
287
118
  } catch (error) {
288
- requestTransactionRollback();
289
119
  const request = args.find((arg) => arg instanceof Request);
290
- const webResponse = await webErrorResponse(error, request);
120
+ const webResponse = await webErrorResponse(error, request, captured);
291
121
  if (webResponse) {
292
122
  return webResponse;
293
123
  }
@@ -300,7 +130,6 @@ function withJsonErrorHandling(handler) {
300
130
  try {
301
131
  return await handler(...args);
302
132
  } catch (error) {
303
- requestTransactionRollback();
304
133
  return errorResponse(error);
305
134
  }
306
135
  };
@@ -310,13 +139,18 @@ function createJsonErrorMiddleware() {
310
139
  try {
311
140
  return await next();
312
141
  } catch (error) {
313
- requestTransactionRollback();
314
142
  return errorResponse(error);
315
143
  }
316
144
  });
317
145
  }
318
- function createWebErrorMiddleware() {
319
- return async (request, next) => await withErrorHandling(async (_request) => next())(request);
146
+ function createWebErrorMiddleware(options = {}) {
147
+ const captured = { ...options };
148
+ return async (request, next) => await runWithRequestMeta({
149
+ ...currentRequestMeta(),
150
+ webErrorView: captured.render,
151
+ viewsEnabled: captured.enabled ?? false,
152
+ webErrorsProduction: captured.production ?? true
153
+ }, () => withErrorHandling(async (_request) => next(), captured)(request));
320
154
  }
321
155
  export {
322
156
  createJsonErrorMiddleware,
@@ -1,16 +1,4 @@
1
1
  // @bun
2
- var __esm = (fn, res, err) => () => {
3
- if (fn)
4
- try {
5
- res = fn(fn = 0);
6
- } catch (e) {
7
- err = [e];
8
- }
9
- if (err)
10
- throw err[0];
11
- return res;
12
- };
13
-
14
2
  // ../../src/core/runtime/asyncContextStore.ts
15
3
  import { AsyncLocalStorage } from "async_hooks";
16
4
  function createAsyncContextStore(key) {
@@ -24,10 +12,8 @@ function createAsyncContextStore(key) {
24
12
  globalRecord[symbol] = store;
25
13
  return store;
26
14
  }
27
- var init_asyncContextStore = () => {};
28
15
 
29
16
  // ../../src/core/http/requestMetaContext.ts
30
- init_asyncContextStore();
31
17
  var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
32
18
  function runWithRequestMeta(meta, callback) {
33
19
  return requestMetaContext.run(meta, callback);