@sixthsummit/ship-api 0.0.0-stage → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (556) hide show
  1. package/CHANGELOG.md +605 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +4 -0
  4. package/README.md +58 -2
  5. package/cli/commands/add.js +537 -0
  6. package/cli/commands/contract.js +2 -0
  7. package/cli/commands/create.js +250 -0
  8. package/cli/commands/dev.js +227 -0
  9. package/cli/commands/doctor.js +286 -0
  10. package/cli/commands/generate.js +937 -0
  11. package/cli/commands/graph.js +2 -0
  12. package/cli/commands/migrate-orm.js +1171 -0
  13. package/cli/commands/update.js +37 -0
  14. package/cli/ship-api.js +285 -0
  15. package/lib/app/auth/AuthProvider.d.ts +91 -0
  16. package/lib/app/auth/AuthProvider.d.ts.map +1 -0
  17. package/lib/app/auth/AuthProvider.js +13 -0
  18. package/lib/app/auth/AuthProvider.js.map +1 -0
  19. package/lib/app/auth/adapters/firebase.d.ts +79 -0
  20. package/lib/app/auth/adapters/firebase.d.ts.map +1 -0
  21. package/lib/app/auth/adapters/firebase.js +122 -0
  22. package/lib/app/auth/adapters/firebase.js.map +1 -0
  23. package/lib/app/auth/adapters/jwtCookie.d.ts +55 -0
  24. package/lib/app/auth/adapters/jwtCookie.d.ts.map +1 -0
  25. package/lib/app/auth/adapters/jwtCookie.js +120 -0
  26. package/lib/app/auth/adapters/jwtCookie.js.map +1 -0
  27. package/lib/app/auth/index.d.ts +8 -0
  28. package/lib/app/auth/index.d.ts.map +1 -0
  29. package/lib/app/auth/index.js +7 -0
  30. package/lib/app/auth/index.js.map +1 -0
  31. package/lib/app/auth/jwt/AuthFlow.d.ts +94 -0
  32. package/lib/app/auth/jwt/AuthFlow.d.ts.map +1 -0
  33. package/lib/app/auth/jwt/AuthFlow.js +127 -0
  34. package/lib/app/auth/jwt/AuthFlow.js.map +1 -0
  35. package/lib/app/auth/jwt/DrizzleRefreshTokenStore.d.ts +80 -0
  36. package/lib/app/auth/jwt/DrizzleRefreshTokenStore.d.ts.map +1 -0
  37. package/lib/app/auth/jwt/DrizzleRefreshTokenStore.js +134 -0
  38. package/lib/app/auth/jwt/DrizzleRefreshTokenStore.js.map +1 -0
  39. package/lib/app/auth/jwt/JwtSigner.d.ts +123 -0
  40. package/lib/app/auth/jwt/JwtSigner.d.ts.map +1 -0
  41. package/lib/app/auth/jwt/JwtSigner.js +118 -0
  42. package/lib/app/auth/jwt/JwtSigner.js.map +1 -0
  43. package/lib/app/auth/jwt/RefreshTokenStore.d.ts +97 -0
  44. package/lib/app/auth/jwt/RefreshTokenStore.d.ts.map +1 -0
  45. package/lib/app/auth/jwt/RefreshTokenStore.js +122 -0
  46. package/lib/app/auth/jwt/RefreshTokenStore.js.map +1 -0
  47. package/lib/app/auth/permissionDefinition.d.ts +20 -0
  48. package/lib/app/auth/permissionDefinition.d.ts.map +1 -0
  49. package/lib/app/auth/permissionDefinition.js +2 -0
  50. package/lib/app/auth/permissionDefinition.js.map +1 -0
  51. package/lib/app/context/RequestContext.d.ts +59 -0
  52. package/lib/app/context/RequestContext.d.ts.map +1 -0
  53. package/lib/app/context/RequestContext.js +25 -0
  54. package/lib/app/context/RequestContext.js.map +1 -0
  55. package/lib/app/db/QueryOptions.d.ts +82 -0
  56. package/lib/app/db/QueryOptions.d.ts.map +1 -0
  57. package/lib/app/db/QueryOptions.js +37 -0
  58. package/lib/app/db/QueryOptions.js.map +1 -0
  59. package/lib/app/db/baseFields.d.ts +60 -0
  60. package/lib/app/db/baseFields.d.ts.map +1 -0
  61. package/lib/app/db/baseFields.js +54 -0
  62. package/lib/app/db/baseFields.js.map +1 -0
  63. package/lib/app/db/buildWhere.d.ts +22 -0
  64. package/lib/app/db/buildWhere.d.ts.map +1 -0
  65. package/lib/app/db/buildWhere.js +75 -0
  66. package/lib/app/db/buildWhere.js.map +1 -0
  67. package/lib/app/db/client.d.ts +111 -0
  68. package/lib/app/db/client.d.ts.map +1 -0
  69. package/lib/app/db/client.js +99 -0
  70. package/lib/app/db/client.js.map +1 -0
  71. package/lib/app/db/tenantScoped.d.ts +59 -0
  72. package/lib/app/db/tenantScoped.d.ts.map +1 -0
  73. package/lib/app/db/tenantScoped.js +54 -0
  74. package/lib/app/db/tenantScoped.js.map +1 -0
  75. package/lib/app/db/transaction.d.ts +58 -0
  76. package/lib/app/db/transaction.d.ts.map +1 -0
  77. package/lib/app/db/transaction.js +106 -0
  78. package/lib/app/db/transaction.js.map +1 -0
  79. package/lib/app/health/HealthCheck.d.ts +121 -0
  80. package/lib/app/health/HealthCheck.d.ts.map +1 -0
  81. package/lib/app/health/HealthCheck.js +151 -0
  82. package/lib/app/health/HealthCheck.js.map +1 -0
  83. package/lib/app/health/redisHealthCheck.d.ts +14 -0
  84. package/lib/app/health/redisHealthCheck.d.ts.map +1 -0
  85. package/lib/app/health/redisHealthCheck.js +21 -0
  86. package/lib/app/health/redisHealthCheck.js.map +1 -0
  87. package/lib/app/lifecycle/Bootstrapper.d.ts +92 -0
  88. package/lib/app/lifecycle/Bootstrapper.d.ts.map +1 -0
  89. package/lib/app/lifecycle/Bootstrapper.js +99 -0
  90. package/lib/app/lifecycle/Bootstrapper.js.map +1 -0
  91. package/lib/app/registry/routes.d.ts +89 -0
  92. package/lib/app/registry/routes.d.ts.map +1 -0
  93. package/lib/app/registry/routes.js +72 -0
  94. package/lib/app/registry/routes.js.map +1 -0
  95. package/lib/app/services/DrizzleEntityService.d.ts +123 -0
  96. package/lib/app/services/DrizzleEntityService.d.ts.map +1 -0
  97. package/lib/app/services/DrizzleEntityService.js +342 -0
  98. package/lib/app/services/DrizzleEntityService.js.map +1 -0
  99. package/lib/app/services/RedisProvider.d.ts +52 -0
  100. package/lib/app/services/RedisProvider.d.ts.map +1 -0
  101. package/lib/app/services/RedisProvider.js +75 -0
  102. package/lib/app/services/RedisProvider.js.map +1 -0
  103. package/lib/app/services/cache/Cache.d.ts +70 -0
  104. package/lib/app/services/cache/Cache.d.ts.map +1 -0
  105. package/lib/app/services/cache/Cache.js +18 -0
  106. package/lib/app/services/cache/Cache.js.map +1 -0
  107. package/lib/app/services/cache/InMemoryCache.d.ts +35 -0
  108. package/lib/app/services/cache/InMemoryCache.d.ts.map +1 -0
  109. package/lib/app/services/cache/InMemoryCache.js +76 -0
  110. package/lib/app/services/cache/InMemoryCache.js.map +1 -0
  111. package/lib/app/services/cache/RedisCache.d.ts +99 -0
  112. package/lib/app/services/cache/RedisCache.d.ts.map +1 -0
  113. package/lib/app/services/cache/RedisCache.js +150 -0
  114. package/lib/app/services/cache/RedisCache.js.map +1 -0
  115. package/lib/app/services/cache/cached.d.ts +30 -0
  116. package/lib/app/services/cache/cached.d.ts.map +1 -0
  117. package/lib/app/services/cache/cached.js +38 -0
  118. package/lib/app/services/cache/cached.js.map +1 -0
  119. package/lib/app/services/cache/index.d.ts +5 -0
  120. package/lib/app/services/cache/index.d.ts.map +1 -0
  121. package/lib/app/services/cache/index.js +4 -0
  122. package/lib/app/services/cache/index.js.map +1 -0
  123. package/lib/app/services/cron/defineCron.d.ts +57 -0
  124. package/lib/app/services/cron/defineCron.d.ts.map +1 -0
  125. package/lib/app/services/cron/defineCron.js +15 -0
  126. package/lib/app/services/cron/defineCron.js.map +1 -0
  127. package/lib/app/services/cron/index.d.ts +2 -0
  128. package/lib/app/services/cron/index.d.ts.map +1 -0
  129. package/lib/app/services/cron/index.js +2 -0
  130. package/lib/app/services/cron/index.js.map +1 -0
  131. package/lib/app/services/hooks/LifecycleHooks.d.ts +61 -0
  132. package/lib/app/services/hooks/LifecycleHooks.d.ts.map +1 -0
  133. package/lib/app/services/hooks/LifecycleHooks.js +85 -0
  134. package/lib/app/services/hooks/LifecycleHooks.js.map +1 -0
  135. package/lib/app/services/jobs/JobsManager.d.ts +67 -0
  136. package/lib/app/services/jobs/JobsManager.d.ts.map +1 -0
  137. package/lib/app/services/jobs/JobsManager.js +121 -0
  138. package/lib/app/services/jobs/JobsManager.js.map +1 -0
  139. package/lib/app/services/jobs/bullBoard.d.ts +72 -0
  140. package/lib/app/services/jobs/bullBoard.d.ts.map +1 -0
  141. package/lib/app/services/jobs/bullBoard.js +96 -0
  142. package/lib/app/services/jobs/bullBoard.js.map +1 -0
  143. package/lib/app/services/jobs/defineJob.d.ts +81 -0
  144. package/lib/app/services/jobs/defineJob.d.ts.map +1 -0
  145. package/lib/app/services/jobs/defineJob.js +49 -0
  146. package/lib/app/services/jobs/defineJob.js.map +1 -0
  147. package/lib/app/services/jobs/index.d.ts +4 -0
  148. package/lib/app/services/jobs/index.d.ts.map +1 -0
  149. package/lib/app/services/jobs/index.js +4 -0
  150. package/lib/app/services/jobs/index.js.map +1 -0
  151. package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.d.ts +23 -0
  152. package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.d.ts.map +1 -0
  153. package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.js +51 -0
  154. package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.js.map +1 -0
  155. package/lib/app/services/rateLimit/RateLimitBackend.d.ts +41 -0
  156. package/lib/app/services/rateLimit/RateLimitBackend.d.ts.map +1 -0
  157. package/lib/app/services/rateLimit/RateLimitBackend.js +19 -0
  158. package/lib/app/services/rateLimit/RateLimitBackend.js.map +1 -0
  159. package/lib/app/services/rateLimit/RedisSlidingWindowBackend.d.ts +16 -0
  160. package/lib/app/services/rateLimit/RedisSlidingWindowBackend.d.ts.map +1 -0
  161. package/lib/app/services/rateLimit/RedisSlidingWindowBackend.js +80 -0
  162. package/lib/app/services/rateLimit/RedisSlidingWindowBackend.js.map +1 -0
  163. package/lib/app/services/rateLimit/index.d.ts +4 -0
  164. package/lib/app/services/rateLimit/index.d.ts.map +1 -0
  165. package/lib/app/services/rateLimit/index.js +3 -0
  166. package/lib/app/services/rateLimit/index.js.map +1 -0
  167. package/lib/app/services/storage/DiskStorageAdapter.d.ts +62 -0
  168. package/lib/app/services/storage/DiskStorageAdapter.d.ts.map +1 -0
  169. package/lib/app/services/storage/DiskStorageAdapter.js +295 -0
  170. package/lib/app/services/storage/DiskStorageAdapter.js.map +1 -0
  171. package/lib/app/services/storage/GCSStorageAdapter.d.ts +44 -0
  172. package/lib/app/services/storage/GCSStorageAdapter.d.ts.map +1 -0
  173. package/lib/app/services/storage/GCSStorageAdapter.js +133 -0
  174. package/lib/app/services/storage/GCSStorageAdapter.js.map +1 -0
  175. package/lib/app/services/storage/S3StorageAdapter.d.ts +57 -0
  176. package/lib/app/services/storage/S3StorageAdapter.d.ts.map +1 -0
  177. package/lib/app/services/storage/S3StorageAdapter.js +162 -0
  178. package/lib/app/services/storage/S3StorageAdapter.js.map +1 -0
  179. package/lib/app/services/storage/StorageService.d.ts +88 -0
  180. package/lib/app/services/storage/StorageService.d.ts.map +1 -0
  181. package/lib/app/services/storage/StorageService.js +18 -0
  182. package/lib/app/services/storage/StorageService.js.map +1 -0
  183. package/lib/app/services/storage/index.d.ts +5 -0
  184. package/lib/app/services/storage/index.d.ts.map +1 -0
  185. package/lib/app/services/storage/index.js +4 -0
  186. package/lib/app/services/storage/index.js.map +1 -0
  187. package/lib/app/utils/ContextValidators.d.ts +46 -0
  188. package/lib/app/utils/ContextValidators.d.ts.map +1 -0
  189. package/lib/app/utils/ContextValidators.js +81 -0
  190. package/lib/app/utils/ContextValidators.js.map +1 -0
  191. package/lib/app/utils/defineEnv.d.ts +80 -0
  192. package/lib/app/utils/defineEnv.d.ts.map +1 -0
  193. package/lib/app/utils/defineEnv.js +95 -0
  194. package/lib/app/utils/defineEnv.js.map +1 -0
  195. package/lib/client.d.ts +139 -0
  196. package/lib/client.d.ts.map +1 -0
  197. package/lib/client.js +98 -0
  198. package/lib/client.js.map +1 -0
  199. package/lib/contract/application.d.ts +3 -0
  200. package/lib/contract/application.d.ts.map +1 -0
  201. package/lib/contract/application.js +2 -0
  202. package/lib/contract/application.js.map +1 -0
  203. package/lib/contract/client.d.ts +3 -0
  204. package/lib/contract/client.d.ts.map +1 -0
  205. package/lib/contract/client.js +3 -0
  206. package/lib/contract/client.js.map +1 -0
  207. package/lib/contract/index.d.ts +3 -0
  208. package/lib/contract/index.d.ts.map +1 -0
  209. package/lib/contract/index.js +3 -0
  210. package/lib/contract/index.js.map +1 -0
  211. package/lib/contract/manifest.d.ts +3 -0
  212. package/lib/contract/manifest.d.ts.map +1 -0
  213. package/lib/contract/manifest.js +2 -0
  214. package/lib/contract/manifest.js.map +1 -0
  215. package/lib/contract/openapi.d.ts +3 -0
  216. package/lib/contract/openapi.d.ts.map +1 -0
  217. package/lib/contract/openapi.js +3 -0
  218. package/lib/contract/openapi.js.map +1 -0
  219. package/lib/contract/project.d.ts +3 -0
  220. package/lib/contract/project.d.ts.map +1 -0
  221. package/lib/contract/project.js +3 -0
  222. package/lib/contract/project.js.map +1 -0
  223. package/lib/contract/schema.d.ts +3 -0
  224. package/lib/contract/schema.d.ts.map +1 -0
  225. package/lib/contract/schema.js +3 -0
  226. package/lib/contract/schema.js.map +1 -0
  227. package/lib/drizzle/index.d.ts +3 -0
  228. package/lib/drizzle/index.d.ts.map +1 -0
  229. package/lib/drizzle/index.js +3 -0
  230. package/lib/drizzle/index.js.map +1 -0
  231. package/lib/hono/auth.d.ts +6 -0
  232. package/lib/hono/auth.d.ts.map +1 -0
  233. package/lib/hono/auth.js +54 -0
  234. package/lib/hono/auth.js.map +1 -0
  235. package/lib/hono/index.d.ts +4 -0
  236. package/lib/hono/index.d.ts.map +1 -0
  237. package/lib/hono/index.js +4 -0
  238. package/lib/hono/index.js.map +1 -0
  239. package/lib/http/app/createApp.d.ts +132 -0
  240. package/lib/http/app/createApp.d.ts.map +1 -0
  241. package/lib/http/app/createApp.js +215 -0
  242. package/lib/http/app/createApp.js.map +1 -0
  243. package/lib/http/app/devRoutes.d.ts +31 -0
  244. package/lib/http/app/devRoutes.d.ts.map +1 -0
  245. package/lib/http/app/devRoutes.js +145 -0
  246. package/lib/http/app/devRoutes.js.map +1 -0
  247. package/lib/http/app/errors.d.ts +45 -0
  248. package/lib/http/app/errors.d.ts.map +1 -0
  249. package/lib/http/app/errors.js +93 -0
  250. package/lib/http/app/errors.js.map +1 -0
  251. package/lib/http/app/health.d.ts +66 -0
  252. package/lib/http/app/health.d.ts.map +1 -0
  253. package/lib/http/app/health.js +104 -0
  254. package/lib/http/app/health.js.map +1 -0
  255. package/lib/http/errors/AppError.d.ts +10 -0
  256. package/lib/http/errors/AppError.d.ts.map +1 -0
  257. package/lib/http/errors/AppError.js +19 -0
  258. package/lib/http/errors/AppError.js.map +1 -0
  259. package/lib/http/errors/AuthenticationError.d.ts +8 -0
  260. package/lib/http/errors/AuthenticationError.d.ts.map +1 -0
  261. package/lib/http/errors/AuthenticationError.js +10 -0
  262. package/lib/http/errors/AuthenticationError.js.map +1 -0
  263. package/lib/http/errors/AuthorizationError.d.ts +8 -0
  264. package/lib/http/errors/AuthorizationError.d.ts.map +1 -0
  265. package/lib/http/errors/AuthorizationError.js +10 -0
  266. package/lib/http/errors/AuthorizationError.js.map +1 -0
  267. package/lib/http/errors/BadRequestError.d.ts +8 -0
  268. package/lib/http/errors/BadRequestError.d.ts.map +1 -0
  269. package/lib/http/errors/BadRequestError.js +10 -0
  270. package/lib/http/errors/BadRequestError.js.map +1 -0
  271. package/lib/http/errors/ConflictError.d.ts +8 -0
  272. package/lib/http/errors/ConflictError.d.ts.map +1 -0
  273. package/lib/http/errors/ConflictError.js +10 -0
  274. package/lib/http/errors/ConflictError.js.map +1 -0
  275. package/lib/http/errors/InternalServerError.d.ts +8 -0
  276. package/lib/http/errors/InternalServerError.d.ts.map +1 -0
  277. package/lib/http/errors/InternalServerError.js +10 -0
  278. package/lib/http/errors/InternalServerError.js.map +1 -0
  279. package/lib/http/errors/NotFoundError.d.ts +8 -0
  280. package/lib/http/errors/NotFoundError.d.ts.map +1 -0
  281. package/lib/http/errors/NotFoundError.js +10 -0
  282. package/lib/http/errors/NotFoundError.js.map +1 -0
  283. package/lib/http/errors/RateLimitError.d.ts +13 -0
  284. package/lib/http/errors/RateLimitError.d.ts.map +1 -0
  285. package/lib/http/errors/RateLimitError.js +16 -0
  286. package/lib/http/errors/RateLimitError.js.map +1 -0
  287. package/lib/http/errors/ServiceUnavailableError.d.ts +8 -0
  288. package/lib/http/errors/ServiceUnavailableError.d.ts.map +1 -0
  289. package/lib/http/errors/ServiceUnavailableError.js +10 -0
  290. package/lib/http/errors/ServiceUnavailableError.js.map +1 -0
  291. package/lib/http/errors/ValidationError.d.ts +9 -0
  292. package/lib/http/errors/ValidationError.d.ts.map +1 -0
  293. package/lib/http/errors/ValidationError.js +12 -0
  294. package/lib/http/errors/ValidationError.js.map +1 -0
  295. package/lib/http/errors/index.d.ts +11 -0
  296. package/lib/http/errors/index.d.ts.map +1 -0
  297. package/lib/http/errors/index.js +12 -0
  298. package/lib/http/errors/index.js.map +1 -0
  299. package/lib/http/middleware/apiKey.d.ts +9 -0
  300. package/lib/http/middleware/apiKey.d.ts.map +1 -0
  301. package/lib/http/middleware/apiKey.js +71 -0
  302. package/lib/http/middleware/apiKey.js.map +1 -0
  303. package/lib/http/middleware/csrf.d.ts +63 -0
  304. package/lib/http/middleware/csrf.d.ts.map +1 -0
  305. package/lib/http/middleware/csrf.js +169 -0
  306. package/lib/http/middleware/csrf.js.map +1 -0
  307. package/lib/http/middleware/httpLogger.d.ts +39 -0
  308. package/lib/http/middleware/httpLogger.d.ts.map +1 -0
  309. package/lib/http/middleware/httpLogger.js +118 -0
  310. package/lib/http/middleware/httpLogger.js.map +1 -0
  311. package/lib/http/middleware/idempotency.d.ts +48 -0
  312. package/lib/http/middleware/idempotency.d.ts.map +1 -0
  313. package/lib/http/middleware/idempotency.js +180 -0
  314. package/lib/http/middleware/idempotency.js.map +1 -0
  315. package/lib/http/middleware/rateLimit.d.ts +105 -0
  316. package/lib/http/middleware/rateLimit.d.ts.map +1 -0
  317. package/lib/http/middleware/rateLimit.js +84 -0
  318. package/lib/http/middleware/rateLimit.js.map +1 -0
  319. package/lib/http/middleware/requireAuth.d.ts +58 -0
  320. package/lib/http/middleware/requireAuth.d.ts.map +1 -0
  321. package/lib/http/middleware/requireAuth.js +63 -0
  322. package/lib/http/middleware/requireAuth.js.map +1 -0
  323. package/lib/http/middleware/requirePermission.d.ts +23 -0
  324. package/lib/http/middleware/requirePermission.d.ts.map +1 -0
  325. package/lib/http/middleware/requirePermission.js +50 -0
  326. package/lib/http/middleware/requirePermission.js.map +1 -0
  327. package/lib/http/middleware/resolveTenant.d.ts +41 -0
  328. package/lib/http/middleware/resolveTenant.d.ts.map +1 -0
  329. package/lib/http/middleware/resolveTenant.js +17 -0
  330. package/lib/http/middleware/resolveTenant.js.map +1 -0
  331. package/lib/http/streaming/sse.d.ts +31 -0
  332. package/lib/http/streaming/sse.d.ts.map +1 -0
  333. package/lib/http/streaming/sse.js +11 -0
  334. package/lib/http/streaming/sse.js.map +1 -0
  335. package/lib/http/streaming/streamLLM.d.ts +94 -0
  336. package/lib/http/streaming/streamLLM.d.ts.map +1 -0
  337. package/lib/http/streaming/streamLLM.js +94 -0
  338. package/lib/http/streaming/streamLLM.js.map +1 -0
  339. package/lib/http/utils/authCookies.d.ts +74 -0
  340. package/lib/http/utils/authCookies.d.ts.map +1 -0
  341. package/lib/http/utils/authCookies.js +102 -0
  342. package/lib/http/utils/authCookies.js.map +1 -0
  343. package/lib/http/utils/clientIp.d.ts +85 -0
  344. package/lib/http/utils/clientIp.d.ts.map +1 -0
  345. package/lib/http/utils/clientIp.js +249 -0
  346. package/lib/http/utils/clientIp.js.map +1 -0
  347. package/lib/http/utils/index.d.ts +4 -0
  348. package/lib/http/utils/index.d.ts.map +1 -0
  349. package/lib/http/utils/index.js +5 -0
  350. package/lib/http/utils/index.js.map +1 -0
  351. package/lib/http/utils/metaTags.d.ts +49 -0
  352. package/lib/http/utils/metaTags.d.ts.map +1 -0
  353. package/lib/http/utils/metaTags.js +32 -0
  354. package/lib/http/utils/metaTags.js.map +1 -0
  355. package/lib/http/utils/publicSuffix.d.ts +34 -0
  356. package/lib/http/utils/publicSuffix.d.ts.map +1 -0
  357. package/lib/http/utils/publicSuffix.js +276 -0
  358. package/lib/http/utils/publicSuffix.js.map +1 -0
  359. package/lib/http/utils/uploads.d.ts +92 -0
  360. package/lib/http/utils/uploads.d.ts.map +1 -0
  361. package/lib/http/utils/uploads.js +126 -0
  362. package/lib/http/utils/uploads.js.map +1 -0
  363. package/lib/http/utils/validate.d.ts +41 -0
  364. package/lib/http/utils/validate.d.ts.map +1 -0
  365. package/lib/http/utils/validate.js +55 -0
  366. package/lib/http/utils/validate.js.map +1 -0
  367. package/lib/http/utils/webhooks.d.ts +63 -0
  368. package/lib/http/utils/webhooks.d.ts.map +1 -0
  369. package/lib/http/utils/webhooks.js +133 -0
  370. package/lib/http/utils/webhooks.js.map +1 -0
  371. package/lib/http/ws/auth.d.ts +46 -0
  372. package/lib/http/ws/auth.d.ts.map +1 -0
  373. package/lib/http/ws/auth.js +123 -0
  374. package/lib/http/ws/auth.js.map +1 -0
  375. package/lib/index.d.ts +80 -0
  376. package/lib/index.d.ts.map +1 -0
  377. package/lib/index.js +61 -0
  378. package/lib/index.js.map +1 -0
  379. package/lib/kernel/index.d.ts +3 -0
  380. package/lib/kernel/index.d.ts.map +1 -0
  381. package/lib/kernel/index.js +3 -0
  382. package/lib/kernel/index.js.map +1 -0
  383. package/lib/libraries/.gitkeep +0 -0
  384. package/lib/libraries/ai/CHANGELOG.md +17 -0
  385. package/lib/libraries/ai/README.md +164 -0
  386. package/lib/libraries/ai/adapters/AnthropicAdapter.ts +382 -0
  387. package/lib/libraries/ai/adapters/LLMProvider.ts +76 -0
  388. package/lib/libraries/ai/adapters/OpenAIAdapter.ts +466 -0
  389. package/lib/libraries/ai/experimental/index.ts +20 -0
  390. package/lib/libraries/ai/index.ts +128 -0
  391. package/lib/libraries/ai/library.json +19 -0
  392. package/lib/libraries/ai/loop/agentLoop.ts +377 -0
  393. package/lib/libraries/ai/prompts/definePrompt.ts +0 -0
  394. package/lib/libraries/ai/rag/retrieveAndAnswer.ts +177 -0
  395. package/lib/libraries/ai/streaming/streamLLM.ts +94 -0
  396. package/lib/libraries/ai/structured/completeStructured.ts +143 -0
  397. package/lib/libraries/ai/tokens/Tokenizer.ts +216 -0
  398. package/lib/libraries/ai/tools/defineTool.ts +208 -0
  399. package/lib/libraries/ai/types.ts +260 -0
  400. package/lib/libraries/chunking/ChunkingService.ts +103 -0
  401. package/lib/libraries/chunking/README.md +104 -0
  402. package/lib/libraries/chunking/docs/api-reference.md +549 -0
  403. package/lib/libraries/chunking/docs/best-practices.md +321 -0
  404. package/lib/libraries/chunking/docs/code-organization.md +538 -0
  405. package/lib/libraries/chunking/docs/configuration.md +418 -0
  406. package/lib/libraries/chunking/docs/index.md +236 -0
  407. package/lib/libraries/chunking/docs/quick-start.md +298 -0
  408. package/lib/libraries/chunking/docs/strategies.md +407 -0
  409. package/lib/libraries/chunking/docs/summary.md +258 -0
  410. package/lib/libraries/chunking/docs/troubleshooting.md +527 -0
  411. package/lib/libraries/chunking/index.ts +17 -0
  412. package/lib/libraries/chunking/library.json +16 -0
  413. package/lib/libraries/chunking/strategies/ChunkingStrategy.ts +13 -0
  414. package/lib/libraries/chunking/strategies/FixedLengthChunkingStrategy.ts +88 -0
  415. package/lib/libraries/chunking/strategies/SemanticChunkingStrategy.ts +389 -0
  416. package/lib/libraries/chunking/strategies/SlidingWindowChunkingStrategy.ts +258 -0
  417. package/lib/libraries/chunking/types/index.ts +63 -0
  418. package/lib/libraries/email/EmailService.ts +591 -0
  419. package/lib/libraries/email/README.md +777 -0
  420. package/lib/libraries/email/TemplateRegistry.ts +148 -0
  421. package/lib/libraries/email/TemplateRenderer.ts +273 -0
  422. package/lib/libraries/email/index.ts +4 -0
  423. package/lib/libraries/email/initializeEmailService.ts +60 -0
  424. package/lib/libraries/email/library.json +12 -0
  425. package/lib/libraries/email/types/EmailAddress.ts +4 -0
  426. package/lib/libraries/email/types/EmailAttachment.ts +11 -0
  427. package/lib/libraries/email/types/EmailTag.ts +9 -0
  428. package/lib/libraries/email/types/EmailTemplate.ts +124 -0
  429. package/lib/libraries/email/types/SendBatchEmailsOptions.ts +9 -0
  430. package/lib/libraries/email/types/SendBatchEmailsResult.ts +9 -0
  431. package/lib/libraries/email/types/SendEmailOptions.ts +33 -0
  432. package/lib/libraries/email/types/SendEmailResult.ts +9 -0
  433. package/lib/libraries/email/types/index.ts +8 -0
  434. package/lib/libraries/weaviate/QueryBuilder.ts +292 -0
  435. package/lib/libraries/weaviate/README.md +284 -0
  436. package/lib/libraries/weaviate/Weaviate.ts +1419 -0
  437. package/lib/libraries/weaviate/WeaviateConfig.ts +268 -0
  438. package/lib/libraries/weaviate/docs/.gitkeep +1 -0
  439. package/lib/libraries/weaviate/docs/API_REFERENCE.md +1067 -0
  440. package/lib/libraries/weaviate/docs/CONFIGURATION.md +320 -0
  441. package/lib/libraries/weaviate/docs/ERROR_HANDLING.md +271 -0
  442. package/lib/libraries/weaviate/docs/MULTI_TENANCY.md +348 -0
  443. package/lib/libraries/weaviate/docs/PERFORMANCE.md +602 -0
  444. package/lib/libraries/weaviate/docs/PLUGIN_DEVELOPMENT.md +547 -0
  445. package/lib/libraries/weaviate/docs/QUICK_START.md +443 -0
  446. package/lib/libraries/weaviate/docs/README.md +269 -0
  447. package/lib/libraries/weaviate/docs/SCHEMA_GUIDE.md +630 -0
  448. package/lib/libraries/weaviate/docs/WEAVIATE_README.md +520 -0
  449. package/lib/libraries/weaviate/errors/WeaviateError.ts +92 -0
  450. package/lib/libraries/weaviate/errors/index.ts +1 -0
  451. package/lib/libraries/weaviate/index.ts +35 -0
  452. package/lib/libraries/weaviate/library.json +26 -0
  453. package/lib/libraries/weaviate/plugins/index.ts +2 -0
  454. package/lib/libraries/weaviate/schemas/SchemaRegistry.ts +284 -0
  455. package/lib/libraries/weaviate/schemas/index.ts +2 -0
  456. package/lib/libraries/weaviate/types/BM25SearchOptions.ts +9 -0
  457. package/lib/libraries/weaviate/types/ExtendedWeaviateClient.ts +7 -0
  458. package/lib/libraries/weaviate/types/HybridSearchOptions.ts +11 -0
  459. package/lib/libraries/weaviate/types/MultiTenancy.ts +81 -0
  460. package/lib/libraries/weaviate/types/Plugin.ts +17 -0
  461. package/lib/libraries/weaviate/types/SchemaConfig.ts +25 -0
  462. package/lib/libraries/weaviate/types/SearchMethod.ts +8 -0
  463. package/lib/libraries/weaviate/types/SearchOptions.ts +16 -0
  464. package/lib/libraries/weaviate/types/SearchRequest.ts +19 -0
  465. package/lib/libraries/weaviate/types/SearchResult.ts +16 -0
  466. package/lib/libraries/weaviate/types/SearchableField.ts +87 -0
  467. package/lib/libraries/weaviate/types/VectorIndexConfig.ts +19 -0
  468. package/lib/libraries/weaviate/types/VectorSearchOptions.ts +18 -0
  469. package/lib/libraries/weaviate/types/VectorizerConfig.ts +8 -0
  470. package/lib/libraries/weaviate/types/index.ts +29 -0
  471. package/lib/libraries/weaviate/utils/TenantContextManager.ts +94 -0
  472. package/lib/modules/accounts/index.ts +47 -0
  473. package/lib/modules/accounts/module.json +15 -0
  474. package/lib/modules/accounts/permissions.ts +33 -0
  475. package/lib/modules/accounts/routes.ts +200 -0
  476. package/lib/modules/accounts/schema.ts +219 -0
  477. package/lib/modules/accounts/services/AccountService.ts +44 -0
  478. package/lib/modules/accounts/validation/schemas.ts +70 -0
  479. package/lib/modules/oauth/adapters/GmailOAuthAdapter.ts +35 -0
  480. package/lib/modules/oauth/adapters/GoogleOAuthAdapter.ts +278 -0
  481. package/lib/modules/oauth/adapters/MicrosoftOAuthAdapter.ts +269 -0
  482. package/lib/modules/oauth/adapters/MockOAuthAdapter.ts +138 -0
  483. package/lib/modules/oauth/adapters/OAuthAdapter.ts +211 -0
  484. package/lib/modules/oauth/adapters/OAuthAdapterRegistry.ts +77 -0
  485. package/lib/modules/oauth/adapters/OutlookOAuthAdapter.ts +38 -0
  486. package/lib/modules/oauth/index.ts +79 -0
  487. package/lib/modules/oauth/module.json +23 -0
  488. package/lib/modules/oauth/permissions.ts +39 -0
  489. package/lib/modules/oauth/routes.ts +497 -0
  490. package/lib/modules/oauth/schema.ts +127 -0
  491. package/lib/modules/oauth/services/OAuthConnectionService.ts +147 -0
  492. package/lib/modules/oauth/state.ts +234 -0
  493. package/lib/modules/oauth/stateJtiCache.ts +85 -0
  494. package/lib/modules/oauth/verifyIdToken.ts +178 -0
  495. package/lib/modules/outbox/EventEmitter.ts +106 -0
  496. package/lib/modules/outbox/OutboxDrainer.ts +163 -0
  497. package/lib/modules/outbox/handlers/EventHandler.ts +115 -0
  498. package/lib/modules/outbox/index.ts +43 -0
  499. package/lib/modules/outbox/module.json +15 -0
  500. package/lib/modules/outbox/permissions.ts +36 -0
  501. package/lib/modules/outbox/routes.ts +219 -0
  502. package/lib/modules/outbox/schema.ts +207 -0
  503. package/lib/modules/outbox/services/OutboxEventService.ts +223 -0
  504. package/lib/observability/logger.d.ts +30 -0
  505. package/lib/observability/logger.d.ts.map +1 -0
  506. package/lib/observability/logger.js +110 -0
  507. package/lib/observability/logger.js.map +1 -0
  508. package/lib/observability/metrics.d.ts +3 -0
  509. package/lib/observability/metrics.d.ts.map +1 -0
  510. package/lib/observability/metrics.js +3 -0
  511. package/lib/observability/metrics.js.map +1 -0
  512. package/lib/observability/otel.d.ts +3 -0
  513. package/lib/observability/otel.d.ts.map +1 -0
  514. package/lib/observability/otel.js +3 -0
  515. package/lib/observability/otel.js.map +1 -0
  516. package/lib/observability/safeErrorFields.d.ts +14 -0
  517. package/lib/observability/safeErrorFields.d.ts.map +1 -0
  518. package/lib/observability/safeErrorFields.js +14 -0
  519. package/lib/observability/safeErrorFields.js.map +1 -0
  520. package/lib/observability/tracing.d.ts +3 -0
  521. package/lib/observability/tracing.d.ts.map +1 -0
  522. package/lib/observability/tracing.js +3 -0
  523. package/lib/observability/tracing.js.map +1 -0
  524. package/lib/package.json +4 -0
  525. package/lib/testing.d.ts +3 -0
  526. package/lib/testing.d.ts.map +1 -0
  527. package/lib/testing.js +3 -0
  528. package/lib/testing.js.map +1 -0
  529. package/package.json +193 -3
  530. package/templates/default/.claude/agents/qa-brief.md +106 -0
  531. package/templates/default/.claude/commands/sherpa-brief.md +23 -0
  532. package/templates/default/.cursor/rules/api.mdc +80 -0
  533. package/templates/default/.cursor/rules/commits.mdc +88 -0
  534. package/templates/default/.cursor/rules/security.mdc +92 -0
  535. package/templates/default/.cursor/rules/testing.mdc +123 -0
  536. package/templates/default/.cursor/rules/typescript.mdc +86 -0
  537. package/templates/default/.env.example +79 -0
  538. package/templates/default/.github/workflows/sherpa-brief.yml +180 -0
  539. package/templates/default/AGENTS.md +166 -0
  540. package/templates/default/CLAUDE.md +17 -0
  541. package/templates/default/README.md +97 -0
  542. package/templates/default/_gitignore +27 -0
  543. package/templates/default/docker-compose.yml +83 -0
  544. package/templates/default/drizzle.config.ts +34 -0
  545. package/templates/default/eslint.config.mjs +106 -0
  546. package/templates/default/package.json +57 -0
  547. package/templates/default/ship-api.config.ts +21 -0
  548. package/templates/default/src/client.ts +34 -0
  549. package/templates/default/src/config/modules.ts +23 -0
  550. package/templates/default/src/db/schema.ts +26 -0
  551. package/templates/default/src/environment.ts +81 -0
  552. package/templates/default/src/index.test.ts +53 -0
  553. package/templates/default/src/index.ts +11 -0
  554. package/templates/default/src/instrumentation.ts +13 -0
  555. package/templates/default/src/server.ts +90 -0
  556. package/templates/default/tsconfig.json +24 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissionDefinition.js","sourceRoot":"","sources":["../../../src/app/auth/permissionDefinition.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ /**
3
+ * Canonical per-request context for the framework.
4
+ *
5
+ * One `AsyncLocalStorage` instance shared across the whole stack so the same
6
+ * `requestId` / `userId` / `tenantId` flow into:
7
+ * - the pino logger's mixin (every log line auto-includes them)
8
+ * - `DrizzleEntityService` lifecycle hooks (audit / CDC / multi-tenant scoping)
9
+ * - OTel span attributes (via the framework's `withSpan` helper, when wired)
10
+ *
11
+ * The shape is intentionally narrow: framework-stable fields up top, free-form
12
+ * overflow under `extra` so consumers can attach module-specific data without
13
+ * mutating the type. The optional `tx` field is populated inside
14
+ * `withTransaction(...)` so lifecycle hooks know they're inside an active
15
+ * transaction (and what `tx` to use for nested writes).
16
+ *
17
+ * `tx` is typed `unknown` here to avoid a circular dep on Drizzle types from
18
+ * the context layer; callers cast to `DrizzleTx` (or equivalent) at the use
19
+ * site. This keeps `RequestContext` a pure type primitive that both the
20
+ * logger and the data layer can depend on without importing each other.
21
+ */
22
+ export interface RequestContext {
23
+ /** Stable per-request identifier propagated end-to-end. */
24
+ requestId?: string;
25
+ /** Authenticated account identifier set by `requireAuth`. */
26
+ userId?: string;
27
+ /**
28
+ * Active tenant for the request, published by `resolveTenant()`. Read the
29
+ * active tenant from here — never from `account.tenantId` directly — so a
30
+ * future one-tenant-per-user → membership move (Model A → B) stays a
31
+ * one-middleware change. `undefined` for single-tenant products.
32
+ */
33
+ tenantId?: string;
34
+ /**
35
+ * Active database transaction handle when running inside `withTransaction`.
36
+ * `unknown` here to avoid a context → Drizzle dependency.
37
+ */
38
+ tx?: unknown;
39
+ /**
40
+ * Free-form extras included under their own keys in log lines and
41
+ * available to lifecycle hooks. Use sparingly; prefer first-class fields
42
+ * if a value is framework-wide.
43
+ */
44
+ extra?: Record<string, unknown>;
45
+ }
46
+ /**
47
+ * The single framework-wide `AsyncLocalStorage`. All context-aware code
48
+ * (logger, services, hooks, tracing) reads from this one store.
49
+ */
50
+ export declare const requestContextStore: AsyncLocalStorage<RequestContext>;
51
+ export declare function getRequestContext(): RequestContext | undefined;
52
+ export declare function runWithRequestContext<T>(ctx: RequestContext, fn: () => T): T;
53
+ /**
54
+ * Mutate the *current* context if one is active. Returns `false` if no context
55
+ * exists (e.g., called outside an HTTP request). Useful from middleware that
56
+ * resolves a user mid-request, or from `withTransaction` setting `tx`.
57
+ */
58
+ export declare function setRequestContextField<K extends keyof RequestContext>(key: K, value: RequestContext[K]): boolean;
59
+ //# sourceMappingURL=RequestContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequestContext.d.ts","sourceRoot":"","sources":["../../../src/app/context/RequestContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC;IAEb;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,mCAA0C,CAAC;AAE3E,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAE9D;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE5E;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,cAAc,EACnE,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GACvB,OAAO,CAKT"}
@@ -0,0 +1,25 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ /**
3
+ * The single framework-wide `AsyncLocalStorage`. All context-aware code
4
+ * (logger, services, hooks, tracing) reads from this one store.
5
+ */
6
+ export const requestContextStore = new AsyncLocalStorage();
7
+ export function getRequestContext() {
8
+ return requestContextStore.getStore();
9
+ }
10
+ export function runWithRequestContext(ctx, fn) {
11
+ return requestContextStore.run(ctx, fn);
12
+ }
13
+ /**
14
+ * Mutate the *current* context if one is active. Returns `false` if no context
15
+ * exists (e.g., called outside an HTTP request). Useful from middleware that
16
+ * resolves a user mid-request, or from `withTransaction` setting `tx`.
17
+ */
18
+ export function setRequestContextField(key, value) {
19
+ const ctx = requestContextStore.getStore();
20
+ if (!ctx)
21
+ return false;
22
+ ctx[key] = value;
23
+ return true;
24
+ }
25
+ //# sourceMappingURL=RequestContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequestContext.js","sourceRoot":"","sources":["../../../src/app/context/RequestContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAmDrD;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,iBAAiB,EAAkB,CAAC;AAE3E,MAAM,UAAU,iBAAiB;IAC/B,OAAO,mBAAmB,CAAC,QAAQ,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAI,GAAmB,EAAE,EAAW;IACvE,OAAO,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,GAAM,EACN,KAAwB;IAExB,MAAM,GAAG,GAAG,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IAC3C,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACjB,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Neutral query-operator DSL — load-bearing decision #2 from the v4 plan.
3
+ *
4
+ * The DSL is the contract between the HTTP layer (which parses query-strings
5
+ * like `?where[name][ilike]=foo&where[age][gte]=18`) and the data layer
6
+ * (`DrizzleEntityService` translates DSL → Drizzle `where` SQL). It is
7
+ * deliberately ORM-neutral: keeping query semantics decoupled from Drizzle
8
+ * means a future ORM swap doesn't break the public REST contract, and the
9
+ * same DSL feeds both Drizzle and any future read-replica / cache-aware
10
+ * variants.
11
+ *
12
+ * Documented operators only. Anything outside this set rejects at parse
13
+ * time so consumers can't smuggle ORM-specific syntax through.
14
+ *
15
+ * v3's `services/interfaces/QueryOptions.ts` (TypeORM-flavored) stays in
16
+ * place during the parallel-path build; this v4 module replaces it at the
17
+ * cut-over.
18
+ */
19
+ export type QueryOperator = "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "ilike" | "isNull";
20
+ /**
21
+ * One column's filter clause. Either a bare value (shorthand for `eq`) or an
22
+ * operator-keyed object. Multiple operators on one column are AND-combined
23
+ * (e.g., `{ age: { gte: 18, lt: 30 } }`).
24
+ */
25
+ export type ColumnFilter<TValue = unknown> = TValue | {
26
+ eq?: TValue;
27
+ ne?: TValue;
28
+ gt?: TValue;
29
+ gte?: TValue;
30
+ lt?: TValue;
31
+ lte?: TValue;
32
+ in?: readonly TValue[];
33
+ /** SQL `LIKE`. Pattern uses `%` / `_` wildcards. */
34
+ like?: string;
35
+ /** Case-insensitive `LIKE` (Postgres `ILIKE`). */
36
+ ilike?: string;
37
+ /** `IS NULL` (true) or `IS NOT NULL` (false). */
38
+ isNull?: boolean;
39
+ };
40
+ /**
41
+ * A `where` filter — record of column names to per-column filters.
42
+ *
43
+ * Multiple columns are AND-combined. To express OR, callers pass an array
44
+ * of filters at the service level (`getAll({ where: [filterA, filterB] })`)
45
+ * — the OR layer is at the service surface, not the DSL — keeps the DSL
46
+ * flat and analyzable.
47
+ */
48
+ export type DslQueryFilter<TRow = Record<string, unknown>> = {
49
+ [K in keyof TRow]?: ColumnFilter<TRow[K]>;
50
+ };
51
+ /** A single `ORDER BY` clause. */
52
+ export interface OrderClause<TRow = Record<string, unknown>> {
53
+ field: keyof TRow & string;
54
+ direction: "asc" | "desc";
55
+ /** `nulls first|last` — defaults to Postgres' default per direction. */
56
+ nulls?: "first" | "last";
57
+ }
58
+ /**
59
+ * Full query options accepted by `DrizzleEntityService` reads. Used by both
60
+ * controller-side parsing (from query strings) and direct service calls.
61
+ */
62
+ export interface QueryOptions<TRow = Record<string, unknown>, TRelation extends string = string> {
63
+ where?: DslQueryFilter<TRow>;
64
+ /** Relations to eager-load (Drizzle `with: { role: true }`). */
65
+ relations?: readonly TRelation[];
66
+ order?: readonly OrderClause<TRow>[];
67
+ limit?: number;
68
+ offset?: number;
69
+ /** Free-text search across the entity's `getDefaultSearchFields()`. */
70
+ search?: string;
71
+ /**
72
+ * Include soft-deleted rows (rows with non-null `deletedAt`). Defaults
73
+ * `false` — soft-deleted rows are filtered out automatically.
74
+ */
75
+ includeDeleted?: boolean;
76
+ }
77
+ /**
78
+ * Type guards / refinement helpers for the parser layer.
79
+ */
80
+ export declare const QUERY_OPERATORS: ReadonlySet<QueryOperator>;
81
+ export declare function isQueryOperator(value: unknown): value is QueryOperator;
82
+ //# sourceMappingURL=QueryOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryOptions.d.ts","sourceRoot":"","sources":["../../../src/app/db/QueryOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,aAAa,GACrB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,MAAM,GACN,OAAO,GACP,QAAQ,CAAC;AAEb;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,GAAG,OAAO,IACrC,MAAM,GACN;IACE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvB,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,KAAK,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SL — load-bearing decision #2 from the v4 plan.
3
+ *
4
+ * The DSL is the contract between the HTTP layer (which parses query-strings
5
+ * like `?where[name][ilike]=foo&where[age][gte]=18`) and the data layer
6
+ * (`DrizzleEntityService` translates DSL → Drizzle `where` SQL). It is
7
+ * deliberately ORM-neutral: keeping query semantics decoupled from Drizzle
8
+ * means a future ORM swap doesn't break the public REST contract, and the
9
+ * same DSL feeds both Drizzle and any future read-replica / cache-aware
10
+ * variants.
11
+ *
12
+ * Documented operators only. Anything outside this set rejects at parse
13
+ * time so consumers can't smuggle ORM-specific syntax through.
14
+ *
15
+ * v3's `services/interfaces/QueryOptions.ts` (TypeORM-flavored) stays in
16
+ * place during the parallel-path build; this v4 module replaces it at the
17
+ * cut-over.
18
+ */
19
+ /**
20
+ * Type guards / refinement helpers for the parser layer.
21
+ */
22
+ export const QUERY_OPERATORS = new Set([
23
+ "eq",
24
+ "ne",
25
+ "gt",
26
+ "gte",
27
+ "lt",
28
+ "lte",
29
+ "in",
30
+ "like",
31
+ "ilike",
32
+ "isNull",
33
+ ]);
34
+ export function isQueryOperator(value) {
35
+ return typeof value === "string" && QUERY_OPERATORS.has(value);
36
+ }
37
+ //# sourceMappingURL=QueryOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryOptions.js","sourceRoot":"","sources":["../../../src/app/db/QueryOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA6EH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA+B,IAAI,GAAG,CAAgB;IAChF,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,MAAM;IACN,OAAO;IACP,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,eAAe,CAAC,GAAG,CAAC,KAAsB,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Audit + soft-delete columns spread into every framework `pgTable` definition.
3
+ *
4
+ * The v4 standard column set, replacing v3's `createdDate` / `updatedDate` /
5
+ * `deletedDate`. Renamed for consistency with industry convention (`*At` suffix
6
+ * for timestamps, separate `*By` foreign keys for audit attribution).
7
+ *
8
+ * - `createdAt` / `updatedAt`: `timestamptz` defaulting to `now()`. `updatedAt`
9
+ * is also auto-updated on row modification at the SQL level (`$onUpdateFn`)
10
+ * so consumers don't have to remember to set it. Drizzle propagates this
11
+ * into `update()` calls.
12
+ * - `deletedAt`: nullable timestamp. Soft-delete-aware services (see
13
+ * `DrizzleEntityService`) filter `isNull(deletedAt)` by default.
14
+ * - `createdBy` / `updatedBy`: nullable UUIDs referencing the actor who
15
+ * created / last modified the row. Auto-stamped from `RequestContext.userId`
16
+ * by `DrizzleEntityService` lifecycle hooks.
17
+ *
18
+ * Usage:
19
+ *
20
+ * ```ts
21
+ * import { pgTable, varchar } from "drizzle-orm/pg-core";
22
+ * import { baseFields } from "@sixthsummit/ship-api/app/db/baseFields";
23
+ *
24
+ * export const accounts = pgTable("accounts", {
25
+ * id: uuid("id").primaryKey().defaultRandom(),
26
+ * email: varchar("email", { length: 255 }).notNull().unique(),
27
+ * ...baseFields,
28
+ * });
29
+ * ```
30
+ */
31
+ export declare const baseFields: {
32
+ readonly createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"created_at">>>;
33
+ readonly updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>>;
34
+ readonly deletedAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"deleted_at">;
35
+ readonly createdBy: import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"created_by">;
36
+ readonly updatedBy: import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"updated_by">;
37
+ };
38
+ /**
39
+ * Subset for tables that need only the timestamps, not the actor columns
40
+ * (e.g., system-generated rows where attribution is meaningless: rate-limit
41
+ * logs, idempotency-key cache, OTel-like telemetry). Use sparingly — most
42
+ * domain tables should use the full `baseFields`.
43
+ */
44
+ export declare const baseFieldsTimestampsOnly: {
45
+ readonly createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"created_at">>>;
46
+ readonly updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>>;
47
+ readonly deletedAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"deleted_at">;
48
+ };
49
+ /**
50
+ * Type alias representing the shape of a row that includes `baseFields`
51
+ * (for use in service-level type constraints).
52
+ */
53
+ export type BaseFields = {
54
+ createdAt: Date;
55
+ updatedAt: Date;
56
+ deletedAt: Date | null;
57
+ createdBy: string | null;
58
+ updatedBy: string | null;
59
+ };
60
+ //# sourceMappingURL=baseFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseFields.d.ts","sourceRoot":"","sources":["../../../src/app/db/baseFields.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,UAAU;;;;;;CASb,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB;;;;CAI3B,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { timestamp, uuid } from "drizzle-orm/pg-core";
3
+ /**
4
+ * Audit + soft-delete columns spread into every framework `pgTable` definition.
5
+ *
6
+ * The v4 standard column set, replacing v3's `createdDate` / `updatedDate` /
7
+ * `deletedDate`. Renamed for consistency with industry convention (`*At` suffix
8
+ * for timestamps, separate `*By` foreign keys for audit attribution).
9
+ *
10
+ * - `createdAt` / `updatedAt`: `timestamptz` defaulting to `now()`. `updatedAt`
11
+ * is also auto-updated on row modification at the SQL level (`$onUpdateFn`)
12
+ * so consumers don't have to remember to set it. Drizzle propagates this
13
+ * into `update()` calls.
14
+ * - `deletedAt`: nullable timestamp. Soft-delete-aware services (see
15
+ * `DrizzleEntityService`) filter `isNull(deletedAt)` by default.
16
+ * - `createdBy` / `updatedBy`: nullable UUIDs referencing the actor who
17
+ * created / last modified the row. Auto-stamped from `RequestContext.userId`
18
+ * by `DrizzleEntityService` lifecycle hooks.
19
+ *
20
+ * Usage:
21
+ *
22
+ * ```ts
23
+ * import { pgTable, varchar } from "drizzle-orm/pg-core";
24
+ * import { baseFields } from "@sixthsummit/ship-api/app/db/baseFields";
25
+ *
26
+ * export const accounts = pgTable("accounts", {
27
+ * id: uuid("id").primaryKey().defaultRandom(),
28
+ * email: varchar("email", { length: 255 }).notNull().unique(),
29
+ * ...baseFields,
30
+ * });
31
+ * ```
32
+ */
33
+ export const baseFields = {
34
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().default(sql `now()`),
35
+ updatedAt: timestamp("updated_at", { withTimezone: true })
36
+ .notNull()
37
+ .default(sql `now()`)
38
+ .$onUpdate(() => new Date()),
39
+ deletedAt: timestamp("deleted_at", { withTimezone: true }),
40
+ createdBy: uuid("created_by"),
41
+ updatedBy: uuid("updated_by"),
42
+ };
43
+ /**
44
+ * Subset for tables that need only the timestamps, not the actor columns
45
+ * (e.g., system-generated rows where attribution is meaningless: rate-limit
46
+ * logs, idempotency-key cache, OTel-like telemetry). Use sparingly — most
47
+ * domain tables should use the full `baseFields`.
48
+ */
49
+ export const baseFieldsTimestampsOnly = {
50
+ createdAt: baseFields.createdAt,
51
+ updatedAt: baseFields.updatedAt,
52
+ deletedAt: baseFields.deletedAt,
53
+ };
54
+ //# sourceMappingURL=baseFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseFields.js","sourceRoot":"","sources":["../../../src/app/db/baseFields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA,OAAO,CAAC;IACxF,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;SACvD,OAAO,EAAE;SACT,OAAO,CAAC,GAAG,CAAA,OAAO,CAAC;SACnB,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;IAC9B,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC1D,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC;IAC7B,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC;CACrB,CAAC;AAEX;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,SAAS,EAAE,UAAU,CAAC,SAAS;IAC/B,SAAS,EAAE,UAAU,CAAC,SAAS;IAC/B,SAAS,EAAE,UAAU,CAAC,SAAS;CACvB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Table } from "drizzle-orm";
2
+ import { type SQL } from "drizzle-orm";
3
+ import type { DslQueryFilter } from "./QueryOptions.js";
4
+ /**
5
+ * Translate the neutral `DslQueryFilter` DSL into a Drizzle `SQL` expression
6
+ * suitable for `db.query.<table>.findMany({ where: ... })` or
7
+ * `db.select().from(table).where(...)`.
8
+ *
9
+ * Filters are AND-combined across columns. Per-column filter objects with
10
+ * multiple operators are also AND-combined (e.g., `{ age: { gte: 18, lt: 30 } }`
11
+ * → `age >= 18 AND age < 30`).
12
+ *
13
+ * Returns `undefined` when the filter is empty so callers can spread it
14
+ * conditionally without producing an empty `WHERE`.
15
+ *
16
+ * Unknown columns (not present on the table) are *silently dropped*, which
17
+ * matches the `validate('query', schema)` upstream contract — by the time
18
+ * a filter reaches `buildWhere`, the schema layer has already validated
19
+ * shape; this function is the ORM-translation step, not validation.
20
+ */
21
+ export declare function buildWhere<TTable extends Table>(table: TTable, filter?: DslQueryFilter): SQL | undefined;
22
+ //# sourceMappingURL=buildWhere.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildWhere.d.ts","sourceRoot":"","sources":["../../../src/app/db/buildWhere.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAaL,KAAK,GAAG,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAgB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,MAAM,SAAS,KAAK,EAC7C,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,cAAc,GACtB,GAAG,GAAG,SAAS,CAkBjB"}
@@ -0,0 +1,75 @@
1
+ import { and, eq, gt, gte, ilike, inArray, isNotNull, isNull, like, lt, lte, ne, } from "drizzle-orm";
2
+ /**
3
+ * Translate the neutral `DslQueryFilter` DSL into a Drizzle `SQL` expression
4
+ * suitable for `db.query.<table>.findMany({ where: ... })` or
5
+ * `db.select().from(table).where(...)`.
6
+ *
7
+ * Filters are AND-combined across columns. Per-column filter objects with
8
+ * multiple operators are also AND-combined (e.g., `{ age: { gte: 18, lt: 30 } }`
9
+ * → `age >= 18 AND age < 30`).
10
+ *
11
+ * Returns `undefined` when the filter is empty so callers can spread it
12
+ * conditionally without producing an empty `WHERE`.
13
+ *
14
+ * Unknown columns (not present on the table) are *silently dropped*, which
15
+ * matches the `validate('query', schema)` upstream contract — by the time
16
+ * a filter reaches `buildWhere`, the schema layer has already validated
17
+ * shape; this function is the ORM-translation step, not validation.
18
+ */
19
+ export function buildWhere(table, filter) {
20
+ if (!filter)
21
+ return undefined;
22
+ const columns = table;
23
+ const conditions = [];
24
+ for (const [key, raw] of Object.entries(filter)) {
25
+ if (raw === undefined)
26
+ continue;
27
+ const column = columns[key];
28
+ if (!column || !isColumn(column))
29
+ continue; // silently drop unknown columns
30
+ appendColumnConditions(column, raw, conditions);
31
+ }
32
+ if (conditions.length === 0)
33
+ return undefined;
34
+ if (conditions.length === 1)
35
+ return conditions[0];
36
+ return and(...conditions);
37
+ }
38
+ function isColumn(value) {
39
+ return (typeof value === "object" &&
40
+ value !== null &&
41
+ // Drizzle columns expose `.name` and `.dataType` consistently.
42
+ typeof value.name === "string");
43
+ }
44
+ function appendColumnConditions(column, raw, out) {
45
+ // Bare value → eq shorthand
46
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw) || raw instanceof Date) {
47
+ out.push(eq(column, raw));
48
+ return;
49
+ }
50
+ const f = raw;
51
+ const filter = f;
52
+ if ("eq" in filter && filter.eq !== undefined)
53
+ out.push(eq(column, filter.eq));
54
+ if ("ne" in filter && filter.ne !== undefined)
55
+ out.push(ne(column, filter.ne));
56
+ if ("gt" in filter && filter.gt !== undefined)
57
+ out.push(gt(column, filter.gt));
58
+ if ("gte" in filter && filter.gte !== undefined)
59
+ out.push(gte(column, filter.gte));
60
+ if ("lt" in filter && filter.lt !== undefined)
61
+ out.push(lt(column, filter.lt));
62
+ if ("lte" in filter && filter.lte !== undefined)
63
+ out.push(lte(column, filter.lte));
64
+ if ("in" in filter && Array.isArray(filter.in)) {
65
+ out.push(inArray(column, filter.in));
66
+ }
67
+ if ("like" in filter && typeof filter.like === "string")
68
+ out.push(like(column, filter.like));
69
+ if ("ilike" in filter && typeof filter.ilike === "string")
70
+ out.push(ilike(column, filter.ilike));
71
+ if ("isNull" in filter && typeof filter.isNull === "boolean") {
72
+ out.push(filter.isNull ? isNull(column) : isNotNull(column));
73
+ }
74
+ }
75
+ //# sourceMappingURL=buildWhere.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildWhere.js","sourceRoot":"","sources":["../../../src/app/db/buildWhere.ts"],"names":[],"mappings":"AACA,OAAO,EACL,GAAG,EACH,EAAE,EACF,EAAE,EACF,GAAG,EACH,KAAK,EACL,OAAO,EACP,SAAS,EACT,MAAM,EACN,IAAI,EACJ,EAAE,EACF,GAAG,EACH,EAAE,GAEH,MAAM,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU,CACxB,KAAa,EACb,MAAuB;IAEvB,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAE9B,MAAM,OAAO,GAAG,KAAqE,CAAC;IACtF,MAAM,UAAU,GAAU,EAAE,CAAC;IAE7B,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,IAAI,GAAG,KAAK,SAAS;YAAE,SAAS;QAEhC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,SAAS,CAAC,gCAAgC;QAE5E,sBAAsB,CAAC,MAAM,EAAE,GAAmB,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9C,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC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heck, type HealthCheckRegistry } from "../health/HealthCheck.js";
4
+ /**
5
+ * Drizzle client + `pg.Pool` factory for ShipAPI v4.
6
+ *
7
+ * Replaces the v3 TypeORM `DataSource` initialization. One shared `pg.Pool`
8
+ * underlies the Drizzle client; the `pool` is exposed for callers that need
9
+ * raw access (e.g., `LISTEN/NOTIFY`, `pg-boss`-compatible workers, the
10
+ * graceful-shutdown manager which calls `pool.end()`).
11
+ *
12
+ * Connection-pool defaults are deliberately conservative for production
13
+ * Postgres: `max: 20` connections, 30s idle timeout, 5s acquire timeout, and
14
+ * a per-statement timeout to bound runaway queries. All overridable via
15
+ * `DbConfig` at construction time.
16
+ *
17
+ * The factory is **schema-agnostic** — pass your composed schema as the
18
+ * `TSchema` generic so `db.query.<table>` is fully typed against the consumer's
19
+ * tables. The framework ships no default tables; compose each module's schema
20
+ * fragment (e.g. `accountsSchema` from the accounts module) into your schema.
21
+ */
22
+ export interface DbConfig {
23
+ /** Full Postgres connection URL (`postgres://...`). Preferred. */
24
+ connectionString?: string;
25
+ /** Or piecewise. Used when `connectionString` is not provided. */
26
+ host?: string;
27
+ port?: number;
28
+ database?: string;
29
+ user?: string;
30
+ password?: string;
31
+ ssl?: boolean | pg.ConnectionConfig["ssl"];
32
+ /** Max connections in pool. Default 20. */
33
+ max?: number;
34
+ /** Idle timeout (ms) before a pooled connection is released. Default 30_000. */
35
+ idleTimeoutMillis?: number;
36
+ /** Max time (ms) to wait for an available connection. Default 5_000. */
37
+ connectionTimeoutMillis?: number;
38
+ /**
39
+ * Per-statement timeout in ms. Set as a session-level Postgres parameter
40
+ * via the pg `application_name` + `statement_timeout` mechanism. Default
41
+ * 30_000 (30 seconds). Set to `0` to disable.
42
+ */
43
+ statementTimeoutMillis?: number;
44
+ /** Optional `application_name` reported to Postgres. */
45
+ applicationName?: string;
46
+ }
47
+ export declare function createPool(config: DbConfig): pg.Pool;
48
+ /**
49
+ * Keep a broken idle connection from killing the process.
50
+ *
51
+ * `pg` emits `error` on the pool when an idle pooled client's connection fails. A Cloud SQL
52
+ * restart, failover or maintenance window ends every connection with `57P01 terminating
53
+ * connection due to administrator command`, and with no listener Node treats that event as an
54
+ * uncaught exception and exits. The pool has already discarded the broken client and the next
55
+ * checkout opens a fresh connection, so logging is all that is needed. Only the error's code,
56
+ * name and syscall are logged (the same fields `/readyz` logs for a thrown check error), because
57
+ * connection error messages can name the database host or user.
58
+ *
59
+ * `createPool` and `createDb` call this; call it yourself on any pool you build with
60
+ * `new pg.Pool()` (migration scripts, workers). A pool that already has an `error` listener is
61
+ * left alone, so a caller's own handling wins.
62
+ */
63
+ export declare function handleIdleClientErrors(pool: pg.Pool): pg.Pool;
64
+ export interface DbHealthCheckOptions {
65
+ /** Check name reported by `/readyz`. Default `"db.primary"`. */
66
+ name?: string;
67
+ /** Registry to add the check to. Default: the framework-wide `healthCheckRegistry`. */
68
+ registry?: HealthCheckRegistry;
69
+ }
70
+ /**
71
+ * Readiness check that runs `select 1` on `pool`. The registry measures the
72
+ * latency and enforces the per-check timeout; a failure throws, so the raw
73
+ * error reaches the registry's failure callback (which `/readyz` logs as
74
+ * code/name/syscall only) rather than the response body. This is the
75
+ * recommended database check: a thrown driver error never puts its message in
76
+ * the log, where a hand-written check returning `error: err.message` would.
77
+ */
78
+ export declare function dbHealthCheck(pool: pg.Pool, opts?: {
79
+ name?: string;
80
+ }): HealthCheck;
81
+ export interface CreateDbResult<TSchema extends Record<string, unknown>> {
82
+ pool: pg.Pool;
83
+ db: NodePgDatabase<TSchema>;
84
+ }
85
+ /**
86
+ * Build a Drizzle client + pool. The `schema` is the composed schema record
87
+ * (`{ accounts, roles, permissions, ...customTables }`); `db.query.<key>` is
88
+ * typed against it.
89
+ */
90
+ export declare function createDb<TSchema extends Record<string, unknown>>(args: {
91
+ config: DbConfig;
92
+ schema: TSchema;
93
+ /** Inject an existing pool (e.g., shared with another worker). */
94
+ pool?: pg.Pool;
95
+ /**
96
+ * Readiness check. By default `createDb` adds a `db.primary` check (runs
97
+ * `select 1` on this pool) to the framework-wide `healthCheckRegistry`, so
98
+ * `/readyz` reflects database reachability with no extra wiring.
99
+ *
100
+ * The check is registered as replaceable: if the app later adds its own
101
+ * check with the same name, that check replaces this one. If a check with
102
+ * the name already exists (say, a second `createDb` call), this one is
103
+ * skipped — the first pool's check stays. Either way exactly one runs.
104
+ *
105
+ * Pass `false` to register nothing (e.g. a secondary pool for a worker or
106
+ * migration script), or an object to change the name or registry.
107
+ */
108
+ healthCheck?: false | DbHealthCheckOptions;
109
+ }): CreateDbResult<TSchema>;
110
+ export type ShipDb<TSchema extends Record<string, unknown>> = NodePgDatabase<TSchema>;
111
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/app/db/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,MAAM,IAAI,CAAC;AAGpB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAEzB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,QAAQ;IACvB,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,OAAO,GAAG,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC3C,2CAA2C;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,wEAAwE;IACxE,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC;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