@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
@@ -0,0 +1,11 @@
1
+ import { SQL } from "bun";
2
+ interface CreateBunSqlPoolOptions {
3
+ url: string;
4
+ max?: number;
5
+ idleTimeout?: number;
6
+ maxLifetime?: number;
7
+ connectionTimeout?: number;
8
+ }
9
+ declare function createNativePostgresPool(options: CreateBunSqlPoolOptions): InstanceType<typeof SQL>;
10
+ export type { CreateBunSqlPoolOptions };
11
+ export { createNativePostgresPool };
@@ -1,42 +1,43 @@
1
+ import type { SqlDialect } from "./sqlDialects.ts";
1
2
  import type { TableDefinition } from "./table.ts";
2
3
  import type { MutationValues, QueryJoin, QueryOptions, QueryWhere, UpdateValues } from "./types.ts";
3
4
  import type { WhereNode } from "./whereBuilder.ts";
4
- declare function quoteIdentifier(identifier: string): string;
5
- declare function qualifyColumn(tableName: string, column: string): string;
6
- declare function resolveQualifiedColumn(defaultTable: string, columnName: string): string;
5
+ declare function quoteIdentifier(dialect: SqlDialect, identifier: string): string;
6
+ declare function qualifyColumn(dialect: SqlDialect, tableName: string, column: string): string;
7
+ declare function resolveQualifiedColumn(dialect: SqlDialect, defaultTable: string, columnName: string): string;
7
8
  declare function parseQualifiedColumn(reference: string): {
8
9
  table: string;
9
10
  column: string;
10
11
  };
11
- declare function buildWhereClause<TEntity extends object>(tableName: string, where?: QueryWhere<TEntity>): {
12
+ declare function buildWhereClause<TEntity extends object>(dialect: SqlDialect, tableName: string, where?: QueryWhere<TEntity>): {
12
13
  clause: string;
13
14
  params: unknown[];
14
15
  };
15
- declare function buildAdvancedWhereClause<TEntity extends object>(tableName: string, where?: QueryWhere<TEntity>, whereNodes?: readonly WhereNode<TEntity>[], params?: unknown[]): {
16
+ declare function buildAdvancedWhereClause<TEntity extends object>(dialect: SqlDialect, tableName: string, where?: QueryWhere<TEntity>, whereNodes?: readonly WhereNode<TEntity>[], params?: unknown[]): {
16
17
  clause: string;
17
18
  params: unknown[];
18
19
  };
19
20
  declare function resolveSoftDeleteColumn<TEntity>(table: TableDefinition<TEntity>): string | null;
20
- declare function buildQueryWhereClause<TEntity extends object>(table: TableDefinition<TEntity>, options?: Pick<QueryOptions<TEntity>, "where" | "withTrashed" | "onlyTrashed">, whereNodes?: readonly WhereNode<TEntity>[], params?: unknown[]): {
21
+ declare function buildQueryWhereClause<TEntity extends object>(dialect: SqlDialect, table: TableDefinition<TEntity>, options?: Pick<QueryOptions<TEntity>, "where" | "withTrashed" | "onlyTrashed">, whereNodes?: readonly WhereNode<TEntity>[], params?: unknown[]): {
21
22
  clause: string;
22
23
  params: unknown[];
23
24
  };
24
- declare function buildOrderByClause<TEntity extends object>(tableName: string, orderBy?: QueryOptions<TEntity>["orderBy"]): string;
25
- declare function buildJoinClause(joins?: readonly QueryJoin[]): string;
26
- declare function buildSelectQuery<TEntity extends object>(table: TableDefinition<TEntity>, options?: QueryOptions<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
25
+ declare function buildOrderByClause<TEntity extends object>(dialect: SqlDialect, tableName: string, orderBy?: QueryOptions<TEntity>["orderBy"]): string;
26
+ declare function buildJoinClause(dialect: SqlDialect, joins?: readonly QueryJoin[]): string;
27
+ declare function buildSelectQuery<TEntity extends object>(dialect: SqlDialect, table: TableDefinition<TEntity>, options?: QueryOptions<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
27
28
  text: string;
28
29
  params: unknown[];
29
30
  };
30
31
  declare const EAGER_ROW_NUMBER = "__strata_eager_row_number";
31
32
  /** Database-side per-owner bounds; never fetch an unbounded batch to slice in JS. */
32
- declare function buildLimitedRelationQuery<TEntity extends object>(table: TableDefinition<TEntity>, options: QueryOptions<TEntity>, partition: {
33
+ declare function buildLimitedRelationQuery<TEntity extends object>(dialect: SqlDialect, table: TableDefinition<TEntity>, options: QueryOptions<TEntity>, partition: {
33
34
  table: string;
34
35
  column: string;
35
36
  }, source: (columns: string, rank: string, params: unknown[]) => string): {
36
37
  text: string;
37
38
  params: unknown[];
38
39
  };
39
- declare function buildLimitedHasManyQuery<TEntity extends object>(table: TableDefinition<TEntity>, options: QueryOptions<TEntity>, partition: {
40
+ declare function buildLimitedHasManyQuery<TEntity extends object>(dialect: SqlDialect, table: TableDefinition<TEntity>, options: QueryOptions<TEntity>, partition: {
40
41
  table: string;
41
42
  column: string;
42
43
  ownerAlias?: string;
@@ -44,54 +45,54 @@ declare function buildLimitedHasManyQuery<TEntity extends object>(table: TableDe
44
45
  text: string;
45
46
  params: unknown[];
46
47
  };
47
- declare function buildCountQuery<TEntity extends object>(table: TableDefinition<TEntity>, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed" | "joins" | "groupBy">, whereNodes?: readonly WhereNode<TEntity>[]): {
48
+ declare function buildCountQuery<TEntity extends object>(dialect: SqlDialect, table: TableDefinition<TEntity>, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed" | "joins" | "groupBy">, whereNodes?: readonly WhereNode<TEntity>[]): {
48
49
  text: string;
49
50
  params: unknown[];
50
51
  };
51
- declare function buildProjectionQuery<TEntity extends object>(table: TableDefinition<TEntity>, expression: string, alias: string, options?: QueryOptions<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
52
+ declare function buildProjectionQuery<TEntity extends object>(dialect: SqlDialect, table: TableDefinition<TEntity>, expression: string, alias: string, options?: QueryOptions<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
52
53
  text: string;
53
54
  params: unknown[];
54
55
  };
55
56
  declare function assertSafeProjectionExpression(expression: string): void;
56
57
  /** Fixed aliases and textual totals avoid driver-dependent JavaScript precision loss. */
57
- declare function buildGroupedSumQuery<TEntity extends object, K extends keyof TEntity & string>(table: TableDefinition<TEntity>, groupColumn: K, column: keyof TEntity & string, options?: QueryOptions<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
58
+ declare function buildGroupedSumQuery<TEntity extends object, K extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity>, groupColumn: K, column: keyof TEntity & string, options?: QueryOptions<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
58
59
  text: string;
59
60
  params: unknown[];
60
61
  };
61
- declare function buildGroupedCountQuery<TEntity extends object, K extends keyof TEntity & string>(table: TableDefinition<TEntity>, column: K, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed">): {
62
+ declare function buildGroupedCountQuery<TEntity extends object, K extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity>, column: K, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed">): {
62
63
  text: string;
63
64
  params: unknown[];
64
65
  };
65
- declare function buildInsertQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, values: MutationValues<TEntity>): {
66
+ declare function buildInsertQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity, PrimaryKey>, values: MutationValues<TEntity>): {
66
67
  text: string;
67
68
  params: unknown[];
68
69
  };
69
- declare function buildUpsertQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, values: MutationValues<TEntity>, conflictColumns: readonly string[], updateColumns?: readonly string[]): {
70
+ declare function buildUpsertQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity, PrimaryKey>, values: MutationValues<TEntity>, conflictColumns: readonly string[], updateColumns?: readonly string[]): {
70
71
  text: string;
71
72
  params: unknown[];
72
73
  };
73
- declare function buildIncrementQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], column: keyof TEntity & string, amount: number, extra?: UpdateValues<TEntity, PrimaryKey>): {
74
+ declare function buildIncrementQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], column: keyof TEntity & string, amount: number, extra?: UpdateValues<TEntity, PrimaryKey>): {
74
75
  text: string;
75
76
  params: unknown[];
76
77
  };
77
- declare function buildUpdateQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], changes: UpdateValues<TEntity, PrimaryKey>): {
78
+ declare function buildUpdateQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], changes: UpdateValues<TEntity, PrimaryKey>): {
78
79
  text: string;
79
80
  params: unknown[];
80
81
  };
81
- declare function buildSoftDeleteByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], deletedAt: Date): {
82
+ declare function buildSoftDeleteByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], deletedAt: Date): {
82
83
  text: string;
83
84
  params: unknown[];
84
85
  };
85
- declare function buildRestoreByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey]): {
86
+ declare function buildRestoreByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey]): {
86
87
  text: string;
87
88
  params: unknown[];
88
89
  };
89
- declare function buildDeleteByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey]): {
90
+ declare function buildDeleteByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey]): {
90
91
  text: string;
91
92
  params: unknown[];
92
93
  };
93
94
  /** Single-statement writes: predicates and protected scopes stay in the mutation. */
94
- declare function buildConditionalWriteQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, operation: "update" | "delete", changes: UpdateValues<TEntity, PrimaryKey>, options: QueryOptions<TEntity>, returning?: readonly (keyof TEntity & string)[]): {
95
+ declare function buildConditionalWriteQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(dialect: SqlDialect, table: TableDefinition<TEntity, PrimaryKey>, operation: "update" | "delete", changes: UpdateValues<TEntity, PrimaryKey>, options: QueryOptions<TEntity>, returning?: readonly (keyof TEntity & string)[]): {
95
96
  text: string;
96
97
  params: unknown[];
97
98
  };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Detach an admitted terminal plan before hooks or SQL can yield. Only containers
3
+ * and supported database values are copied; explicit services/callbacks retain
4
+ * identity and are checked by the owning binding before use.
5
+ */
6
+ declare function snapshotQueryPlan<T>(value: T, seen?: Map<object, unknown>, opaque?: (value: object) => unknown): T;
7
+ export { snapshotQueryPlan };
@@ -0,0 +1,7 @@
1
+ import type { DisposeAck, MysqlDatabaseOptions, RawPin, RawPool } from "./driverPorts";
2
+ import { type MysqlPoolConnection } from "./mysqlNative";
3
+ /** mysql2 destroy() only calls stream.end(); its void return is not socket closure. */
4
+ declare function destroyMysqlConnection(connection: MysqlPoolConnection): Promise<DisposeAck>;
5
+ declare function createMysqlPin(connection: MysqlPoolConnection): RawPin;
6
+ declare function createRawMysqlPool(options: MysqlDatabaseOptions): Promise<RawPool>;
7
+ export { createMysqlPin, createRawMysqlPool, destroyMysqlConnection };
@@ -0,0 +1,23 @@
1
+ import type { PostgresDatabaseOptions, RawPool } from "./driverPorts";
2
+ type PostgresNativeRows = readonly unknown[] & {
3
+ readonly command?: string | null;
4
+ };
5
+ interface PostgresNativeExecutable {
6
+ unsafe(text: string, params: unknown[]): PromiseLike<PostgresNativeRows>;
7
+ }
8
+ interface PostgresNativeReserved extends PostgresNativeExecutable {
9
+ release(): void | Promise<void>;
10
+ close(options?: {
11
+ timeout?: number;
12
+ }): void | Promise<void>;
13
+ }
14
+ interface PostgresNativePool extends PostgresNativeExecutable {
15
+ reserve(options?: {
16
+ signal?: AbortSignal;
17
+ }): Promise<PostgresNativeReserved>;
18
+ close(): void | Promise<void>;
19
+ }
20
+ declare function createRawPostgresPoolFromNative(pool: PostgresNativePool): RawPool;
21
+ declare function createRawPostgresPool(options: PostgresDatabaseOptions): RawPool;
22
+ export type { PostgresNativePool, PostgresNativeReserved, PostgresNativeRows };
23
+ export { createRawPostgresPool, createRawPostgresPoolFromNative };
@@ -0,0 +1,6 @@
1
+ import type { OpenOutcome } from "../contracts/application";
2
+ import type { RawPool, SqliteDatabaseOptions } from "./driverPorts";
3
+ declare function sqliteFilename(filename: string): string;
4
+ declare function openRawSqlitePool(options: SqliteDatabaseOptions): OpenOutcome<RawPool>;
5
+ declare function createRawSqlitePool(options: SqliteDatabaseOptions): RawPool;
6
+ export { createRawSqlitePool, openRawSqlitePool, sqliteFilename };
@@ -1,6 +1,7 @@
1
+ import type { SqlDialect } from "./sqlDialects.ts";
1
2
  import type { TableDefinition } from "./table.ts";
2
3
  import type { QueryOptions } from "./types.ts";
3
- declare function buildHasManyThroughQuery<TEntity extends object>(table: TableDefinition<TEntity>, relation: {
4
+ declare function buildHasManyThroughQuery<TEntity extends object>(dialect: SqlDialect, table: TableDefinition<TEntity>, relation: {
4
5
  throughTable: string;
5
6
  firstKey: string;
6
7
  secondLocalKey: string;
@@ -10,7 +11,7 @@ declare function buildHasManyThroughQuery<TEntity extends object>(table: TableDe
10
11
  text: string;
11
12
  params: unknown[];
12
13
  };
13
- declare function buildPivotLookupQuery(relation: {
14
+ declare function buildPivotLookupQuery(dialect: SqlDialect, relation: {
14
15
  pivotTable: string;
15
16
  foreignPivotKey: string;
16
17
  }, parentIds: readonly unknown[]): {
@@ -30,6 +30,8 @@ declare class HasManyRelationQuery<TParent extends object, ParentKey extends key
30
30
  private extraWhere;
31
31
  private extraOptions;
32
32
  constructor(parent: RelationHost<TParent, ParentKey>, related: RelatedModelClass<TChild, ChildKey>, relation: HasManyRelation<TParent, TChild, ParentKey, keyof TChild & string>);
33
+ snapshot(): HasManyRelationQuery<TParent, ParentKey, TChild, ChildKey>;
34
+ private terminal;
33
35
  where(where: QueryWhere<TChild>): this;
34
36
  orderBy(orderBy: QueryOptions<TChild>["orderBy"]): this;
35
37
  limit(limit: number): this;
@@ -45,17 +47,18 @@ declare class HasManyRelationQuery<TParent extends object, ParentKey extends key
45
47
  value(column: string): Promise<unknown>;
46
48
  then(onfulfilled?: ((value: RelatedRecord[]) => unknown) | null, onrejected?: ((reason: unknown) => unknown) | null): Promise<unknown>;
47
49
  create(attributes?: Record<string, unknown>): Promise<RelatedRecord>;
48
- save(related: RelatedRecord | (Record<string, unknown> & {
49
- save?: () => Promise<unknown>;
50
- mergeAttributes?: (patch: Record<string, unknown>) => unknown;
51
- })): Promise<RelatedRecord>;
50
+ save(related: RelatedRecord | Record<string, unknown>): Promise<RelatedRecord>;
52
51
  createMany(records: ReadonlyArray<Record<string, unknown>>): Promise<RelatedRecord[]>;
53
52
  }
54
53
  declare class HasOneRelationQuery<TParent extends object, ParentKey extends keyof TParent & string, TChild extends object, ChildKey extends keyof TChild & string> {
54
+ private readonly parent;
55
+ private readonly related;
55
56
  readonly relation: HasOneRelation<TParent, TChild, ParentKey, keyof TChild & string>;
56
57
  readonly kind: RelationKind;
57
- private readonly inner;
58
+ private inner;
58
59
  constructor(parent: RelationHost<TParent, ParentKey>, related: RelatedModelClass<TChild, ChildKey>, relation: HasOneRelation<TParent, TChild, ParentKey, keyof TChild & string>);
60
+ snapshot(): HasOneRelationQuery<TParent, ParentKey, TChild, ChildKey>;
61
+ private terminal;
59
62
  where(where: QueryWhere<TChild>): this;
60
63
  orderBy(orderBy: QueryOptions<TChild>["orderBy"]): this;
61
64
  applyEagerLoad(query: RepositoryQuery<TParent, ParentKey>, alias: string): void;
@@ -79,6 +82,8 @@ declare class BelongsToRelationQuery<TChild extends object, ChildKey extends key
79
82
  private extraWhere;
80
83
  private extraOptions;
81
84
  constructor(parent: RelationHost<TChild, ChildKey>, related: RelatedModelClass<TParent, ParentKey>, relation: BelongsToRelation<TChild, TParent, keyof TChild & string, ParentKey>);
85
+ snapshot(): BelongsToRelationQuery<TChild, ChildKey, TParent, ParentKey>;
86
+ private terminal;
82
87
  where(where: QueryWhere<TParent>): this;
83
88
  orderBy(orderBy: QueryOptions<TParent>["orderBy"]): this;
84
89
  applyEagerLoad(query: RepositoryQuery<TChild, ChildKey>, alias: string): void;
@@ -105,6 +110,8 @@ declare class BelongsToManyRelationQuery<TParent extends object, ParentKey exten
105
110
  private extraOptions;
106
111
  private pivotValues;
107
112
  constructor(parent: RelationHost<TParent, ParentKey>, related: RelatedModelClass<TRelated, RelatedKey>, relation: BelongsToManyRelation<TParent, TRelated, Pivot, ParentKey, RelatedKey, keyof Pivot & string, keyof Pivot & string>);
113
+ snapshot(): BelongsToManyRelationQuery<TParent, ParentKey, TRelated, RelatedKey, Pivot>;
114
+ private terminal;
108
115
  where(where: QueryWhere<TRelated>): this;
109
116
  orderBy(orderBy: QueryOptions<TRelated>["orderBy"]): this;
110
117
  applyEagerLoad(query: RepositoryQuery<TParent, ParentKey>, alias: string): void;
@@ -138,6 +145,8 @@ declare class MorphManyRelationQuery<TParent extends object, ParentKey extends k
138
145
  private extraWhere;
139
146
  private extraOptions;
140
147
  constructor(parent: RelationHost<TParent, ParentKey>, related: RelatedModelClass<TChild, ChildKey>, relation: MorphManyRelation<TParent, TChild, ParentKey, keyof TChild & string, keyof TChild & string>);
148
+ snapshot(): MorphManyRelationQuery<TParent, ParentKey, TChild, ChildKey>;
149
+ private terminal;
141
150
  where(where: QueryWhere<TChild>): this;
142
151
  applyEagerLoad(query: RepositoryQuery<TParent, ParentKey>, alias: string): void;
143
152
  hydrateEager(row: Record<string, unknown>, alias: string): unknown;
@@ -153,10 +162,14 @@ declare class MorphManyRelationQuery<TParent extends object, ParentKey extends k
153
162
  create(attributes?: Record<string, unknown>): Promise<RelatedRecord>;
154
163
  }
155
164
  declare class MorphOneRelationQuery<TParent extends object, ParentKey extends keyof TParent & string, TChild extends object, ChildKey extends keyof TChild & string> {
165
+ private readonly parent;
166
+ private readonly related;
156
167
  readonly relation: MorphOneRelation<TParent, TChild, ParentKey, keyof TChild & string, keyof TChild & string>;
157
168
  readonly kind: RelationKind;
158
- private readonly inner;
169
+ private inner;
159
170
  constructor(parent: RelationHost<TParent, ParentKey>, related: RelatedModelClass<TChild, ChildKey>, relation: MorphOneRelation<TParent, TChild, ParentKey, keyof TChild & string, keyof TChild & string>);
171
+ snapshot(): MorphOneRelationQuery<TParent, ParentKey, TChild, ChildKey>;
172
+ private terminal;
160
173
  where(where: QueryWhere<TChild>): this;
161
174
  applyEagerLoad(query: RepositoryQuery<TParent, ParentKey>, alias: string): void;
162
175
  hydrateEager(row: Record<string, unknown>, alias: string): unknown;
@@ -177,6 +190,8 @@ declare class MorphToRelationQuery<TChild extends object, ChildKey extends keyof
177
190
  readonly kind: RelationKind;
178
191
  private extraWhere;
179
192
  constructor(parent: RelationHost<TChild, ChildKey>, relatedByType: Record<string, RelatedModelClass<Record<string, unknown>, "id">>, relation: MorphToRelation<TChild, keyof TChild & string, keyof TChild & string>);
193
+ snapshot(): MorphToRelationQuery<TChild, ChildKey>;
194
+ private terminal;
180
195
  where(where: QueryWhere<Record<string, unknown>>): this;
181
196
  applyEagerLoad(query: RepositoryQuery<TChild, ChildKey>, alias: string): void;
182
197
  hydrateEager(row: Record<string, unknown>, alias: string, forNestedLoading?: boolean): unknown;
@@ -197,6 +212,8 @@ declare class HasManyThroughRelationQuery<TParent extends object, ParentKey exte
197
212
  private extraWhere;
198
213
  private extraOptions;
199
214
  constructor(parent: RelationHost<TParent, ParentKey>, related: RelatedModelClass<TFar, FarKey>, relation: HasManyThroughRelation<TParent, TFar, ParentKey, string, string, keyof TFar & string>);
215
+ snapshot(): HasManyThroughRelationQuery<TParent, ParentKey, TFar, FarKey>;
216
+ private terminal;
200
217
  where(where: QueryWhere<TFar>): this;
201
218
  orderBy(orderBy: QueryOptions<TFar>["orderBy"]): this;
202
219
  limit(limit: number): this;
@@ -214,6 +231,7 @@ declare class HasManyThroughRelationQuery<TParent extends object, ParentKey exte
214
231
  }
215
232
  type AnyRelationQuery = {
216
233
  kind: RelationKind;
234
+ snapshot(): AnyRelationQuery;
217
235
  applyEagerLoad(query: unknown, alias: string): void;
218
236
  hydrateEager(row: Record<string, unknown>, alias: string, forNestedLoading?: boolean): unknown;
219
237
  get(): Promise<unknown>;
@@ -4,6 +4,7 @@ import type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasMany
4
4
  import type { QueryLockOptions, QueryOptions, QueryWhere, UpdateValues } from "./types.ts";
5
5
  import { WhereBuilder } from "./whereBuilder.ts";
6
6
  type LoadedRow = Record<string, unknown>;
7
+ declare let snapshotRepositoryQuery: <R extends object, K extends keyof R & string>(query: RepositoryQuery<R, K>) => RepositoryQuery<R, K>;
7
8
  declare class RepositoryQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string> {
8
9
  private readonly repository;
9
10
  private whereClause;
@@ -80,10 +81,14 @@ declare class RepositoryQuery<TEntity extends object, PrimaryKey extends keyof T
80
81
  }>;
81
82
  /** Compiled query filters for batched relationship loaders. */
82
83
  getOptions(): QueryOptions<TEntity>;
84
+ private relatedDefinition;
85
+ private resolveRepository;
86
+ private snapshot;
87
+ private runTerminal;
83
88
  private buildOptions;
84
89
  private addJoin;
85
90
  private attach;
86
91
  private hydrateEagerLoad;
87
92
  }
88
93
  export { projectPluck, uniqueColumnSelect } from "./pluck.ts";
89
- export { RepositoryQuery };
94
+ export { RepositoryQuery, snapshotRepositoryQuery };
@@ -3,6 +3,6 @@ interface ResolveDatabaseDriverOptions {
3
3
  url?: string;
4
4
  connection?: string;
5
5
  }
6
- declare function resolveDatabaseDriver(options?: ResolveDatabaseDriverOptions): DatabaseDriver;
6
+ declare function resolveDatabaseDriver(options: ResolveDatabaseDriverOptions): DatabaseDriver;
7
7
  export type { DatabaseDriver, ResolveDatabaseDriverOptions };
8
8
  export { resolveDatabaseDriver };
@@ -1,5 +1,5 @@
1
1
  interface SeederDatabase {
2
- unsafe(query: string): Promise<unknown>;
2
+ unsafe(query: string, params?: readonly unknown[]): Promise<unknown>;
3
3
  }
4
4
  interface Seeder {
5
5
  name: string;
@@ -0,0 +1,13 @@
1
+ import type { DatabaseCapabilities, SqlStatement, TransactionOptions } from "./driverPorts";
2
+ import type { BoundRegistry } from "./modelRegistry";
3
+ import type { SqlDialect } from "./sqlDialects";
4
+ import type { TransactionSession } from "./transactionSession";
5
+ interface DatabaseSession extends BoundRegistry {
6
+ readonly dialect: SqlDialect;
7
+ readonly capabilities: DatabaseCapabilities;
8
+ execute<Row>(statement: SqlStatement): Promise<readonly Row[]>;
9
+ transaction<T>(work: (tx: TransactionSession) => T | Promise<T>, options?: TransactionOptions): Promise<T>;
10
+ connection(name: string): DatabaseSession;
11
+ }
12
+ export type { DatabaseCapabilities, DatabaseConnectionOptions, DatabaseDefinition, SqlStatement, TransactionOptions, } from "./driverPorts";
13
+ export type { DatabaseSession, TransactionSession };
@@ -0,0 +1,9 @@
1
+ import type { ExecutionContext } from "../contracts/application";
2
+ import type { ExecutionOperations } from "../contracts/executionOperations";
3
+ import type { OwnedExecution } from "../contracts/executionOwnership";
4
+ import type { DatabaseManager } from "./manager";
5
+ import { type PreparedRegistry } from "./modelRegistry";
6
+ import type { DatabaseSession } from "./session";
7
+ /** Execution value facade; native pool disposal belongs exclusively to the application. */
8
+ declare function createDatabaseSession(manager: DatabaseManager, context: ExecutionContext, operations: ExecutionOperations, ownership: OwnedExecution, prepared: PreparedRegistry): DatabaseSession;
9
+ export { createDatabaseSession };
@@ -0,0 +1,22 @@
1
+ type SqlDriver = "pgsql" | "mysql" | "sqlite";
2
+ interface SqlDialect {
3
+ readonly driver: SqlDriver;
4
+ placeholder(index: number): string;
5
+ quoteIdentifier(identifier: string): string;
6
+ nowExpression(): string;
7
+ /** Authoritative database wall clock for persisted lease/retry deadlines. */
8
+ epochMillisecondsExpression(): string;
9
+ /** Current reads/row locks; SQLite serializes writes at transaction admission. */
10
+ rowLockClause(skipLocked?: boolean): string;
11
+ /** Render a Date as a literal this engine accepts for a timestamp column. */
12
+ timestampValue(value: Date): string;
13
+ returningClause(columns: string): string;
14
+ ilikeOperator(): "ILIKE" | "LIKE";
15
+ nullsLastSuffix(): string;
16
+ castToText(expression: string): string;
17
+ /** Conflict handling appended to an INSERT. Empty updates mean "do nothing". */
18
+ upsertSuffix(conflictColumns: readonly string[], updateColumns: readonly string[]): string;
19
+ }
20
+ declare function dialectFor(driver: SqlDriver): SqlDialect;
21
+ export type { SqlDialect, SqlDriver };
22
+ export { dialectFor };
@@ -0,0 +1,7 @@
1
+ import type { DatabaseManager } from "./manager";
2
+ import type { DatabaseSession } from "./session";
3
+ /** Canonical execution session; constructors and business code receive its narrow value. */
4
+ declare const DATABASE_SESSION_TOKEN: import("@getstrata/core/contracts/token").ServiceToken<DatabaseSession>;
5
+ /** Internal application assembly; callers never use it as an execution facade. */
6
+ declare const DATABASE_MANAGER_TOKEN: import("@getstrata/core/contracts/token").ServiceToken<DatabaseManager>;
7
+ export { DATABASE_MANAGER_TOKEN, DATABASE_SESSION_TOKEN };
@@ -0,0 +1,43 @@
1
+ import { type SessionOwnerIdentity } from "#strata-orm-internal";
2
+ import type { ExecutionContext } from "../contracts/application";
3
+ import type { ExecutionOperations } from "../contracts/executionOperations";
4
+ import type { OwnedExecution } from "../contracts/executionOwnership";
5
+ import type { DatabaseCapabilities, RawPool, SqlStatement, TransactionOptions } from "./driverPorts";
6
+ import type { BoundRegistry, SessionAuthority } from "./modelRegistry";
7
+ import type { DatabaseSession } from "./session";
8
+ import type { SqlDialect } from "./sqlDialects";
9
+ interface TransactionSession extends BoundRegistry {
10
+ readonly dialect: SqlDialect;
11
+ readonly capabilities: DatabaseCapabilities;
12
+ execute<Row>(statement: SqlStatement): Promise<readonly Row[]>;
13
+ transaction<T>(work: (tx: TransactionSession) => T | Promise<T>): Promise<T>;
14
+ afterCommit(work: () => void | Promise<void>): void;
15
+ requestRollback(): void;
16
+ }
17
+ /** Captures the parameter ARRAY; native bind-value codec/reference semantics remain unchanged. */
18
+ declare function snapshotStatement(input: SqlStatement): SqlStatement;
19
+ /** One execution-local persistence context; task and resource ownership stay in the kernel. */
20
+ declare class TransactionRuntime {
21
+ private readonly context;
22
+ private readonly operations;
23
+ private readonly ownership;
24
+ private readonly attachRegistry;
25
+ private readonly rootSession;
26
+ private readonly ownerForPool;
27
+ private readonly storage;
28
+ constructor(context: ExecutionContext, operations: ExecutionOperations, ownership: OwnedExecution, attachRegistry: (session: TransactionSession, authority: SessionAuthority) => BoundRegistry, rootSession: (pool: RawPool) => DatabaseSession, ownerForPool: (pool: RawPool) => SessionOwnerIdentity);
29
+ assertOutside(): void;
30
+ private assertBranch;
31
+ private facade;
32
+ private business;
33
+ private newAttempt;
34
+ private control;
35
+ private evidence;
36
+ private result;
37
+ private markUnknown;
38
+ private restoreHistory;
39
+ private nested;
40
+ run<T>(pool: RawPool, work: (tx: TransactionSession) => T | Promise<T>, options?: TransactionOptions): Promise<T>;
41
+ }
42
+ export type { TransactionSession };
43
+ export { snapshotStatement, TransactionRuntime };
@@ -24,6 +24,9 @@ declare class ForbiddenError extends HttpError {
24
24
  declare class UnauthorizedError extends HttpError {
25
25
  constructor(message?: string, details?: unknown);
26
26
  }
27
+ /** A supplied credential failed verification; retrying via login redirect cannot repair it. */
28
+ declare class InvalidCredentialsError extends UnauthorizedError {
29
+ }
27
30
  declare class PayloadTooLargeError extends HttpError {
28
31
  constructor(message?: string, details?: unknown);
29
32
  }
@@ -40,4 +43,4 @@ interface HttpErrorLike {
40
43
  }
41
44
  declare function isHttpErrorLike(error: unknown): error is HttpErrorLike;
42
45
  declare function toHttpError(error: unknown): HttpError | null;
43
- export { BadRequestError, ConflictError, ForbiddenError, HttpError, InternalServerError, isHttpErrorLike, NotFoundError, PayloadTooLargeError, PreconditionFailedError, toHttpError, UnauthorizedError, UnprocessableEntityError, ValidationError, };
46
+ export { BadRequestError, ConflictError, ForbiddenError, HttpError, InternalServerError, InvalidCredentialsError, isHttpErrorLike, NotFoundError, PayloadTooLargeError, PreconditionFailedError, toHttpError, UnauthorizedError, UnprocessableEntityError, ValidationError, };
@@ -11,7 +11,5 @@ declare class EventBus {
11
11
  emit(event: string, payload: unknown): Promise<void>;
12
12
  dispatch(event: string, payload: unknown): Promise<void>;
13
13
  }
14
- declare function readSharedEventBus(): EventBus;
15
- declare const eventBus: EventBus;
16
14
  export type { EventListener };
17
- export { EventBus, eventBus, readSharedEventBus };
15
+ export { EventBus };
@@ -1,5 +1,4 @@
1
- export { dispatchModelEvent, runWithDeferredModelEvents } from "./deferredModelEvents";
2
- export type { EventListener } from "./eventBus";
3
- export { EventBus, eventBus, readSharedEventBus } from "./eventBus";
1
+ export type { EventListener } from "./eventBusClass";
2
+ export { EventBus } from "./eventBusClass";
4
3
  declare function modelEventName(tableName: string, action: string): string;
5
4
  export { modelEventName };
@@ -1,3 +1,8 @@
1
+ import { type ServiceDeclaration } from "@getstrata/core/contracts/services";
2
+ import { type ServiceToken } from "@getstrata/core/contracts/token";
3
+ import { type SessionOwnerIdentity } from "#strata-orm-internal";
4
+ import type { PersistenceInvocation, SelectedSession } from "../../contracts/persistence";
5
+ import type { TransactionSession } from "../../database/session";
1
6
  import { type TenantContext } from "../../tenant/tenantContext";
2
7
  interface DurableEvent {
3
8
  readonly id: string;
@@ -9,9 +14,10 @@ interface DurableEvent {
9
14
  interface DurableListener {
10
15
  readonly name: string;
11
16
  readonly event: string;
12
- handle(event: DurableEvent, context: {
17
+ handle(event: DurableEvent, context: Readonly<{
13
18
  signal: AbortSignal;
14
- }): Promise<void>;
19
+ database: SelectedSession;
20
+ }>): Promise<void>;
15
21
  }
16
22
  type OutboxDeliveryStatus = "pending" | "processing" | "failed" | "completed";
17
23
  interface OutboxDeliverySnapshot {
@@ -19,14 +25,30 @@ interface OutboxDeliverySnapshot {
19
25
  readonly attempts: number;
20
26
  readonly maxAttempts: number;
21
27
  }
22
- interface SqlOutboxOptions {
23
- listeners: readonly DurableListener[];
24
- leaseMs?: number;
25
- maxAttempts?: number;
26
- retryDelayMs?: number;
27
- maxPayloadBytes?: number;
28
- resolveTenant?: (id: number) => Promise<TenantContext | null>;
28
+ declare const ownerBrand: unique symbol;
29
+ interface SqlOutboxOwner extends SessionOwnerIdentity {
30
+ readonly invoke: PersistenceInvocation;
31
+ readonly [ownerBrand]: object;
32
+ }
33
+ interface SqlOutboxBindingOptions {
34
+ readonly invoke: PersistenceInvocation;
35
+ readonly connection: string;
36
+ readonly tenancy: "none" | "column" | "rls";
37
+ readonly listeners: readonly DurableListener[];
38
+ readonly leaseMs?: number;
39
+ readonly maxAttempts?: number;
40
+ readonly retryDelayMs?: number;
41
+ readonly maxPayloadBytes?: number;
42
+ readonly resolveTenant?: (selected: TransactionSession, id: number) => Promise<TenantContext | null>;
43
+ }
44
+ interface SqlOutboxOptions extends Omit<SqlOutboxBindingOptions, "invoke" | "connection"> {
45
+ readonly owner: SqlOutboxOwner;
46
+ }
47
+ interface SqlOutboxBindings {
48
+ readonly token: ServiceToken<SqlOutbox>;
49
+ readonly services: readonly ServiceDeclaration[];
29
50
  }
51
+ declare function createSqlOutboxBindings(options: SqlOutboxBindingOptions): SqlOutboxBindings;
30
52
  /** Opt-in SQL effects. Publishing writes only; workers execute listeners at least once. */
31
53
  declare class SqlOutbox {
32
54
  private readonly listeners;
@@ -35,11 +57,16 @@ declare class SqlOutbox {
35
57
  private readonly retryDelayMs;
36
58
  private readonly maxPayloadBytes;
37
59
  private readonly tenantResolver;
60
+ private readonly owner;
61
+ private readonly tenancy;
38
62
  constructor(options: SqlOutboxOptions);
63
+ private privileged;
39
64
  hasListener(name: string, event?: string): boolean;
40
65
  /** Read-only advisory observation: caller owns tenant/RLS scope; no implicit bypass. */
41
- getDelivery(eventId: string, listenerName: string): Promise<OutboxDeliverySnapshot | null>;
42
- publish(name: string, payload: unknown, options?: {
66
+ getDelivery(db: SelectedSession, eventId: string, listenerName: string): Promise<OutboxDeliverySnapshot | null>;
67
+ private readDelivery;
68
+ publish(db: TransactionSession, name: string, payload: unknown, options: {
69
+ tenantId: number | null;
43
70
  id?: string;
44
71
  version?: number;
45
72
  }): Promise<string>;
@@ -50,6 +77,8 @@ declare class SqlOutbox {
50
77
  processNext(options?: {
51
78
  signal?: AbortSignal;
52
79
  }): Promise<boolean>;
80
+ private processOwned;
81
+ private processSelected;
53
82
  /** Stop admission on cancellation; handlers must observe the supplied signal to drain. */
54
83
  work(options: {
55
84
  signal: AbortSignal;
@@ -61,5 +90,7 @@ declare class SqlOutbox {
61
90
  export type { OutboxMetricState, OutboxMetricsCollector, OutboxMetricsOptions, OutboxMetricsSnapshot, } from "./metrics";
62
91
  export { createOutboxMetricsCollector, renderOutboxMetrics } from "./metrics";
63
92
  export { createOutboxMigration } from "./migration";
64
- export type { DurableEvent, DurableListener, OutboxDeliverySnapshot, OutboxDeliveryStatus, SqlOutboxOptions, };
65
- export { SqlOutbox };
93
+ export type { OutboxWorkerTransport } from "./workerTransport";
94
+ export { createOutboxWorkerTransport } from "./workerTransport";
95
+ export type { DurableEvent, DurableListener, OutboxDeliverySnapshot, OutboxDeliveryStatus, SqlOutboxBindingOptions, SqlOutboxBindings, SqlOutboxOptions, SqlOutboxOwner, };
96
+ export { createSqlOutboxBindings, SqlOutbox };
@@ -1,3 +1,4 @@
1
+ import type { ReadOnlyObservation } from "../../database/ownedReadOnlyObservation";
1
2
  type OutboxMetricState = "pending_due" | "pending_waiting" | "processing_active" | "processing_expired" | "processing_unleased" | "failed";
2
3
  interface OutboxMetricsSnapshot {
3
4
  sampleLimit: number;
@@ -9,6 +10,7 @@ interface OutboxMetricsSnapshot {
9
10
  }[];
10
11
  }
11
12
  interface OutboxMetricsOptions {
13
+ observeReadOnly: ReadOnlyObservation;
12
14
  timeoutMs?: number;
13
15
  sampleLimit?: number;
14
16
  }
@@ -18,10 +20,8 @@ interface OutboxMetricsCollector {
18
20
  close(): Promise<void>;
19
21
  }
20
22
  declare const snapshotQuery: string;
21
- /** Explicit platform observation, using the same transaction-local RLS bypass as coordination.
22
- * Postgres uses scoped bypass; official SQLite/MySQL adapters use isolated read-only snapshots.
23
- */
24
- declare function createOutboxMetricsCollector(options?: OutboxMetricsOptions): OutboxMetricsCollector;
23
+ /** Explicit app-owned platform observation; the configured runner owns native policy and snapshot lifetime. */
24
+ declare function createOutboxMetricsCollector(options: OutboxMetricsOptions): OutboxMetricsCollector;
25
25
  declare function renderOutboxMetrics(snapshot: OutboxMetricsSnapshot): string;
26
26
  export type { OutboxMetricState, OutboxMetricsCollector, OutboxMetricsOptions, OutboxMetricsSnapshot, };
27
27
  export { createOutboxMetricsCollector, renderOutboxMetrics, snapshotQuery };
@@ -0,0 +1,17 @@
1
+ import { type ServiceToken } from "@getstrata/core/contracts/token";
2
+ import type { TransportDefinition } from "../../contracts/application";
3
+ import type { SqlOutbox } from "./index";
4
+ export declare const workerApplicationShutdown: unique symbol;
5
+ interface OutboxWorkerTransport {
6
+ readonly transport: TransportDefinition;
7
+ start(): Promise<void>;
8
+ stop(): Promise<void>;
9
+ readonly completion: Promise<void>;
10
+ }
11
+ /** One application resource owns actual polling; SQL/pins remain in the canonical graph. */
12
+ declare function createOutboxWorkerTransport(token: ServiceToken<SqlOutbox>, options?: Readonly<{
13
+ pollMs?: number;
14
+ name?: string;
15
+ }>): OutboxWorkerTransport;
16
+ export type { OutboxWorkerTransport };
17
+ export { createOutboxWorkerTransport };