@c15t/backend 0.0.1-rc.10

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 (521) hide show
  1. package/.turbo/turbo-build.log +11 -0
  2. package/.turbo/turbo-check-types.log +5 -0
  3. package/.turbo/turbo-fmt.log +7 -0
  4. package/.turbo/turbo-lint.log +6 -0
  5. package/.turbo/turbo-test.log +26 -0
  6. package/README-next.md +223 -0
  7. package/README.md +164 -0
  8. package/dist/api/call.d.ts +176 -0
  9. package/dist/api/call.d.ts.map +1 -0
  10. package/dist/api/index.d.ts +935 -0
  11. package/dist/api/index.d.ts.map +1 -0
  12. package/dist/api/middlewares/index.d.ts +39 -0
  13. package/dist/api/middlewares/index.d.ts.map +1 -0
  14. package/dist/api/middlewares/origin-check.d.ts +82 -0
  15. package/dist/api/middlewares/origin-check.d.ts.map +1 -0
  16. package/dist/api/middlewares/validate-context.d.ts +38 -0
  17. package/dist/api/middlewares/validate-context.d.ts.map +1 -0
  18. package/dist/api/routes/__tests__/consent.test.d.ts +2 -0
  19. package/dist/api/routes/__tests__/consent.test.d.ts.map +1 -0
  20. package/dist/api/routes/__tests__/status.test.d.ts +2 -0
  21. package/dist/api/routes/__tests__/status.test.d.ts.map +1 -0
  22. package/dist/api/routes/error.d.ts +57 -0
  23. package/dist/api/routes/error.d.ts.map +1 -0
  24. package/dist/api/routes/generate-consent-receipt.d.ts +130 -0
  25. package/dist/api/routes/generate-consent-receipt.d.ts.map +1 -0
  26. package/dist/api/routes/get-consent-history.d.ts +133 -0
  27. package/dist/api/routes/get-consent-history.d.ts.map +1 -0
  28. package/dist/api/routes/get-consent-policy.d.ts +164 -0
  29. package/dist/api/routes/get-consent-policy.d.ts.map +1 -0
  30. package/dist/api/routes/get-consent.d.ts +148 -0
  31. package/dist/api/routes/get-consent.d.ts.map +1 -0
  32. package/dist/api/routes/index.d.ts +339 -0
  33. package/dist/api/routes/index.d.ts.map +1 -0
  34. package/dist/api/routes/ok.d.ts +87 -0
  35. package/dist/api/routes/ok.d.ts.map +1 -0
  36. package/dist/api/routes/set-consent.d.ts +245 -0
  37. package/dist/api/routes/set-consent.d.ts.map +1 -0
  38. package/dist/api/routes/show-consent-banner.d.ts +127 -0
  39. package/dist/api/routes/show-consent-banner.d.ts.map +1 -0
  40. package/dist/api/routes/status.d.ts +61 -0
  41. package/dist/api/routes/status.d.ts.map +1 -0
  42. package/dist/api/routes/verify-consent.d.ts +179 -0
  43. package/dist/api/routes/verify-consent.d.ts.map +1 -0
  44. package/dist/api/routes/withdraw-consent.d.ts +194 -0
  45. package/dist/api/routes/withdraw-consent.d.ts.map +1 -0
  46. package/dist/api/to-endpoints.d.ts +35 -0
  47. package/dist/api/to-endpoints.d.ts.map +1 -0
  48. package/dist/client/index.cjs +139 -0
  49. package/dist/client/index.d.ts +203 -0
  50. package/dist/client/index.d.ts.map +1 -0
  51. package/dist/client/index.js +106 -0
  52. package/dist/client/types.d.ts +431 -0
  53. package/dist/client/types.d.ts.map +1 -0
  54. package/dist/core.d.ts +124 -0
  55. package/dist/core.d.ts.map +1 -0
  56. package/dist/core.test.d.ts +2 -0
  57. package/dist/core.test.d.ts.map +1 -0
  58. package/dist/db/adapters/drizzle-adapter/drizzle-adapter.d.ts +122 -0
  59. package/dist/db/adapters/drizzle-adapter/drizzle-adapter.d.ts.map +1 -0
  60. package/dist/db/adapters/drizzle-adapter/index.d.ts +2 -0
  61. package/dist/db/adapters/drizzle-adapter/index.d.ts.map +1 -0
  62. package/dist/db/adapters/drizzle.cjs +1531 -0
  63. package/dist/db/adapters/drizzle.js +1489 -0
  64. package/dist/db/adapters/kysely-adapter/dialect.d.ts +72 -0
  65. package/dist/db/adapters/kysely-adapter/dialect.d.ts.map +1 -0
  66. package/dist/db/adapters/kysely-adapter/index.d.ts +4 -0
  67. package/dist/db/adapters/kysely-adapter/index.d.ts.map +1 -0
  68. package/dist/db/adapters/kysely-adapter/kysely-adapter.d.ts +98 -0
  69. package/dist/db/adapters/kysely-adapter/kysely-adapter.d.ts.map +1 -0
  70. package/dist/db/adapters/kysely-adapter/types.d.ts +281 -0
  71. package/dist/db/adapters/kysely-adapter/types.d.ts.map +1 -0
  72. package/dist/db/adapters/kysely.cjs +1551 -0
  73. package/dist/db/adapters/kysely.js +1508 -0
  74. package/dist/db/adapters/memory-adapter/index.d.ts +2 -0
  75. package/dist/db/adapters/memory-adapter/index.d.ts.map +1 -0
  76. package/dist/db/adapters/memory-adapter/memory-adapter.d.ts +56 -0
  77. package/dist/db/adapters/memory-adapter/memory-adapter.d.ts.map +1 -0
  78. package/dist/db/adapters/memory.cjs +1391 -0
  79. package/dist/db/adapters/memory.js +1349 -0
  80. package/dist/db/adapters/prisma-adapter/index.d.ts +2 -0
  81. package/dist/db/adapters/prisma-adapter/index.d.ts.map +1 -0
  82. package/dist/db/adapters/prisma-adapter/prisma-adapter.d.ts +143 -0
  83. package/dist/db/adapters/prisma-adapter/prisma-adapter.d.ts.map +1 -0
  84. package/dist/db/adapters/prisma.cjs +1503 -0
  85. package/dist/db/adapters/prisma.js +1461 -0
  86. package/dist/db/adapters/types.d.ts +154 -0
  87. package/dist/db/adapters/types.d.ts.map +1 -0
  88. package/dist/db/adapters/utils.d.ts +36 -0
  89. package/dist/db/adapters/utils.d.ts.map +1 -0
  90. package/dist/db/core/fields/field-factory.d.ts +383 -0
  91. package/dist/db/core/fields/field-factory.d.ts.map +1 -0
  92. package/dist/db/core/fields/field-inference.d.ts +218 -0
  93. package/dist/db/core/fields/field-inference.d.ts.map +1 -0
  94. package/dist/db/core/fields/field-options-integration.d.ts +90 -0
  95. package/dist/db/core/fields/field-options-integration.d.ts.map +1 -0
  96. package/dist/db/core/fields/field-types.d.ts +182 -0
  97. package/dist/db/core/fields/field-types.d.ts.map +1 -0
  98. package/dist/db/core/fields/id-generator.d.ts +19 -0
  99. package/dist/db/core/fields/id-generator.d.ts.map +1 -0
  100. package/dist/db/core/fields/index.d.ts +8 -0
  101. package/dist/db/core/fields/index.d.ts.map +1 -0
  102. package/dist/db/core/fields/superjson-utils.d.ts +34 -0
  103. package/dist/db/core/fields/superjson-utils.d.ts.map +1 -0
  104. package/dist/db/core/fields/zod-fields.d.ts +1011 -0
  105. package/dist/db/core/fields/zod-fields.d.ts.map +1 -0
  106. package/dist/db/core/get-schema.d.ts +36 -0
  107. package/dist/db/core/get-schema.d.ts.map +1 -0
  108. package/dist/db/core/types.d.ts +41 -0
  109. package/dist/db/core/types.d.ts.map +1 -0
  110. package/dist/db/create-registry.d.ts +760 -0
  111. package/dist/db/create-registry.d.ts.map +1 -0
  112. package/dist/db/hooks/create-hooks.d.ts +32 -0
  113. package/dist/db/hooks/create-hooks.d.ts.map +1 -0
  114. package/dist/db/hooks/index.d.ts +40 -0
  115. package/dist/db/hooks/index.d.ts.map +1 -0
  116. package/dist/db/hooks/types.d.ts +133 -0
  117. package/dist/db/hooks/types.d.ts.map +1 -0
  118. package/dist/db/hooks/update-hooks.d.ts +33 -0
  119. package/dist/db/hooks/update-hooks.d.ts.map +1 -0
  120. package/dist/db/hooks/update-many-hooks.d.ts +55 -0
  121. package/dist/db/hooks/update-many-hooks.d.ts.map +1 -0
  122. package/dist/db/hooks/utils.d.ts +62 -0
  123. package/dist/db/hooks/utils.d.ts.map +1 -0
  124. package/dist/db/hooks/with-hooks-factory.d.ts +33 -0
  125. package/dist/db/hooks/with-hooks-factory.d.ts.map +1 -0
  126. package/dist/db/index.cjs +2458 -0
  127. package/dist/db/index.d.ts +11 -0
  128. package/dist/db/index.d.ts.map +1 -0
  129. package/dist/db/index.js +2404 -0
  130. package/dist/db/migration/get-migration.d.ts +32 -0
  131. package/dist/db/migration/get-migration.d.ts.map +1 -0
  132. package/dist/db/migration/get-schema/get-schema.d.ts +27 -0
  133. package/dist/db/migration/get-schema/get-schema.d.ts.map +1 -0
  134. package/dist/db/migration/get-schema/index.d.ts +21 -0
  135. package/dist/db/migration/get-schema/index.d.ts.map +1 -0
  136. package/dist/db/migration/get-schema/process-fields.d.ts +16 -0
  137. package/dist/db/migration/get-schema/process-fields.d.ts.map +1 -0
  138. package/dist/db/migration/get-schema/process-tables.d.ts +13 -0
  139. package/dist/db/migration/get-schema/process-tables.d.ts.map +1 -0
  140. package/dist/db/migration/get-schema/types.d.ts +17 -0
  141. package/dist/db/migration/get-schema/types.d.ts.map +1 -0
  142. package/dist/db/migration/index.cjs +1613 -0
  143. package/dist/db/migration/index.d.ts +14 -0
  144. package/dist/db/migration/index.d.ts.map +1 -0
  145. package/dist/db/migration/index.js +1571 -0
  146. package/dist/db/migration/migration-builders.d.ts +28 -0
  147. package/dist/db/migration/migration-builders.d.ts.map +1 -0
  148. package/dist/db/migration/migration-execution.d.ts +12 -0
  149. package/dist/db/migration/migration-execution.d.ts.map +1 -0
  150. package/dist/db/migration/schema-comparison.d.ts +54 -0
  151. package/dist/db/migration/schema-comparison.d.ts.map +1 -0
  152. package/dist/db/migration/type-mapping.d.ts +86 -0
  153. package/dist/db/migration/type-mapping.d.ts.map +1 -0
  154. package/dist/db/migration/types.d.ts +37 -0
  155. package/dist/db/migration/types.d.ts.map +1 -0
  156. package/dist/db/schema/audit-log/index.d.ts +4 -0
  157. package/dist/db/schema/audit-log/index.d.ts.map +1 -0
  158. package/dist/db/schema/audit-log/registry.d.ts +128 -0
  159. package/dist/db/schema/audit-log/registry.d.ts.map +1 -0
  160. package/dist/db/schema/audit-log/schema.d.ts +67 -0
  161. package/dist/db/schema/audit-log/schema.d.ts.map +1 -0
  162. package/dist/db/schema/audit-log/table.d.ts +175 -0
  163. package/dist/db/schema/audit-log/table.d.ts.map +1 -0
  164. package/dist/db/schema/audit-log/types.d.ts +29 -0
  165. package/dist/db/schema/audit-log/types.d.ts.map +1 -0
  166. package/dist/db/schema/consent/index.d.ts +4 -0
  167. package/dist/db/schema/consent/index.d.ts.map +1 -0
  168. package/dist/db/schema/consent/registry.d.ts +318 -0
  169. package/dist/db/schema/consent/registry.d.ts.map +1 -0
  170. package/dist/db/schema/consent/schema.d.ts +135 -0
  171. package/dist/db/schema/consent/schema.d.ts.map +1 -0
  172. package/dist/db/schema/consent/table.d.ts +245 -0
  173. package/dist/db/schema/consent/table.d.ts.map +1 -0
  174. package/dist/db/schema/consent/types.d.ts +37 -0
  175. package/dist/db/schema/consent/types.d.ts.map +1 -0
  176. package/dist/db/schema/consent-geo-location/index.d.ts +4 -0
  177. package/dist/db/schema/consent-geo-location/index.d.ts.map +1 -0
  178. package/dist/db/schema/consent-geo-location/registry.d.ts +96 -0
  179. package/dist/db/schema/consent-geo-location/registry.d.ts.map +1 -0
  180. package/dist/db/schema/consent-geo-location/schema.d.ts +71 -0
  181. package/dist/db/schema/consent-geo-location/schema.d.ts.map +1 -0
  182. package/dist/db/schema/consent-geo-location/table.d.ts +167 -0
  183. package/dist/db/schema/consent-geo-location/table.d.ts.map +1 -0
  184. package/dist/db/schema/consent-geo-location/types.d.ts +21 -0
  185. package/dist/db/schema/consent-geo-location/types.d.ts.map +1 -0
  186. package/dist/db/schema/consent-policy/index.d.ts +4 -0
  187. package/dist/db/schema/consent-policy/index.d.ts.map +1 -0
  188. package/dist/db/schema/consent-policy/registry.d.ts +186 -0
  189. package/dist/db/schema/consent-policy/registry.d.ts.map +1 -0
  190. package/dist/db/schema/consent-policy/schema.d.ts +68 -0
  191. package/dist/db/schema/consent-policy/schema.d.ts.map +1 -0
  192. package/dist/db/schema/consent-policy/table.d.ts +147 -0
  193. package/dist/db/schema/consent-policy/table.d.ts.map +1 -0
  194. package/dist/db/schema/consent-policy/types.d.ts +28 -0
  195. package/dist/db/schema/consent-policy/types.d.ts.map +1 -0
  196. package/dist/db/schema/consent-purpose/index.d.ts +4 -0
  197. package/dist/db/schema/consent-purpose/index.d.ts.map +1 -0
  198. package/dist/db/schema/consent-purpose/registry.d.ts +136 -0
  199. package/dist/db/schema/consent-purpose/registry.d.ts.map +1 -0
  200. package/dist/db/schema/consent-purpose/schema.d.ts +79 -0
  201. package/dist/db/schema/consent-purpose/schema.d.ts.map +1 -0
  202. package/dist/db/schema/consent-purpose/table.d.ts +161 -0
  203. package/dist/db/schema/consent-purpose/table.d.ts.map +1 -0
  204. package/dist/db/schema/consent-purpose/types.d.ts +16 -0
  205. package/dist/db/schema/consent-purpose/types.d.ts.map +1 -0
  206. package/dist/db/schema/consent-purpose-junction/index.d.ts +4 -0
  207. package/dist/db/schema/consent-purpose-junction/index.d.ts.map +1 -0
  208. package/dist/db/schema/consent-purpose-junction/registry.d.ts +109 -0
  209. package/dist/db/schema/consent-purpose-junction/registry.d.ts.map +1 -0
  210. package/dist/db/schema/consent-purpose-junction/schema.d.ts +57 -0
  211. package/dist/db/schema/consent-purpose-junction/schema.d.ts.map +1 -0
  212. package/dist/db/schema/consent-purpose-junction/table.d.ts +138 -0
  213. package/dist/db/schema/consent-purpose-junction/table.d.ts.map +1 -0
  214. package/dist/db/schema/consent-purpose-junction/types.d.ts +14 -0
  215. package/dist/db/schema/consent-purpose-junction/types.d.ts.map +1 -0
  216. package/dist/db/schema/consent-record/index.d.ts +4 -0
  217. package/dist/db/schema/consent-record/index.d.ts.map +1 -0
  218. package/dist/db/schema/consent-record/registry.d.ts +119 -0
  219. package/dist/db/schema/consent-record/registry.d.ts.map +1 -0
  220. package/dist/db/schema/consent-record/schema.d.ts +57 -0
  221. package/dist/db/schema/consent-record/schema.d.ts.map +1 -0
  222. package/dist/db/schema/consent-record/table.d.ts +123 -0
  223. package/dist/db/schema/consent-record/table.d.ts.map +1 -0
  224. package/dist/db/schema/consent-record/types.d.ts +21 -0
  225. package/dist/db/schema/consent-record/types.d.ts.map +1 -0
  226. package/dist/db/schema/consent-withdrawal/index.d.ts +4 -0
  227. package/dist/db/schema/consent-withdrawal/index.d.ts.map +1 -0
  228. package/dist/db/schema/consent-withdrawal/registry.d.ts +134 -0
  229. package/dist/db/schema/consent-withdrawal/registry.d.ts.map +1 -0
  230. package/dist/db/schema/consent-withdrawal/schema.d.ts +67 -0
  231. package/dist/db/schema/consent-withdrawal/schema.d.ts.map +1 -0
  232. package/dist/db/schema/consent-withdrawal/table.d.ts +170 -0
  233. package/dist/db/schema/consent-withdrawal/table.d.ts.map +1 -0
  234. package/dist/db/schema/consent-withdrawal/types.d.ts +28 -0
  235. package/dist/db/schema/consent-withdrawal/types.d.ts.map +1 -0
  236. package/dist/db/schema/definition.d.ts +1100 -0
  237. package/dist/db/schema/definition.d.ts.map +1 -0
  238. package/dist/db/schema/domain/index.d.ts +4 -0
  239. package/dist/db/schema/domain/index.d.ts.map +1 -0
  240. package/dist/db/schema/domain/registry.d.ts +169 -0
  241. package/dist/db/schema/domain/registry.d.ts.map +1 -0
  242. package/dist/db/schema/domain/schema.d.ts +60 -0
  243. package/dist/db/schema/domain/schema.d.ts.map +1 -0
  244. package/dist/db/schema/domain/table.d.ts +140 -0
  245. package/dist/db/schema/domain/table.d.ts.map +1 -0
  246. package/dist/db/schema/domain/types.d.ts +27 -0
  247. package/dist/db/schema/domain/types.d.ts.map +1 -0
  248. package/dist/db/schema/geo-location/index.d.ts +4 -0
  249. package/dist/db/schema/geo-location/index.d.ts.map +1 -0
  250. package/dist/db/schema/geo-location/registry.d.ts +114 -0
  251. package/dist/db/schema/geo-location/registry.d.ts.map +1 -0
  252. package/dist/db/schema/geo-location/schema.d.ts +58 -0
  253. package/dist/db/schema/geo-location/schema.d.ts.map +1 -0
  254. package/dist/db/schema/geo-location/table.d.ts +132 -0
  255. package/dist/db/schema/geo-location/table.d.ts.map +1 -0
  256. package/dist/db/schema/geo-location/types.d.ts +17 -0
  257. package/dist/db/schema/geo-location/types.d.ts.map +1 -0
  258. package/dist/db/schema/index.d.ts +85 -0
  259. package/dist/db/schema/index.d.ts.map +1 -0
  260. package/dist/db/schema/parser.d.ts +183 -0
  261. package/dist/db/schema/parser.d.ts.map +1 -0
  262. package/dist/db/schema/schemas.d.ts +383 -0
  263. package/dist/db/schema/schemas.d.ts.map +1 -0
  264. package/dist/db/schema/subject/index.d.ts +4 -0
  265. package/dist/db/schema/subject/index.d.ts.map +1 -0
  266. package/dist/db/schema/subject/registry.d.ts +141 -0
  267. package/dist/db/schema/subject/registry.d.ts.map +1 -0
  268. package/dist/db/schema/subject/schema.d.ts +56 -0
  269. package/dist/db/schema/subject/schema.d.ts.map +1 -0
  270. package/dist/db/schema/subject/table.d.ts +136 -0
  271. package/dist/db/schema/subject/table.d.ts.map +1 -0
  272. package/dist/db/schema/subject/types.d.ts +22 -0
  273. package/dist/db/schema/subject/types.d.ts.map +1 -0
  274. package/dist/db/schema/types.d.ts +136 -0
  275. package/dist/db/schema/types.d.ts.map +1 -0
  276. package/dist/db/utils/adapter-factory.d.ts +21 -0
  277. package/dist/db/utils/adapter-factory.d.ts.map +1 -0
  278. package/dist/db/utils/index.d.ts +10 -0
  279. package/dist/db/utils/index.d.ts.map +1 -0
  280. package/dist/db/utils.d.ts +4 -0
  281. package/dist/db/utils.d.ts.map +1 -0
  282. package/dist/error/codes.cjs +68 -0
  283. package/dist/error/codes.d.ts +175 -0
  284. package/dist/error/codes.d.ts.map +1 -0
  285. package/dist/error/codes.js +35 -0
  286. package/dist/error/error.d.ts +79 -0
  287. package/dist/error/error.d.ts.map +1 -0
  288. package/dist/error/index.cjs +172 -0
  289. package/dist/error/index.d.ts +9 -0
  290. package/dist/error/index.d.ts.map +1 -0
  291. package/dist/error/index.js +129 -0
  292. package/dist/error/logging.d.ts +25 -0
  293. package/dist/error/logging.d.ts.map +1 -0
  294. package/dist/error/pipeline.d.ts +19 -0
  295. package/dist/error/pipeline.d.ts.map +1 -0
  296. package/dist/error/recovery.d.ts +22 -0
  297. package/dist/error/recovery.d.ts.map +1 -0
  298. package/dist/error/results.d.ts +56 -0
  299. package/dist/error/results.d.ts.map +1 -0
  300. package/dist/index.cjs +4777 -0
  301. package/dist/index.d.ts +46 -0
  302. package/dist/index.d.ts.map +1 -0
  303. package/dist/index.js +4708 -0
  304. package/dist/init.d.ts +52 -0
  305. package/dist/init.d.ts.map +1 -0
  306. package/dist/init.test.d.ts +2 -0
  307. package/dist/init.test.d.ts.map +1 -0
  308. package/dist/integrations/index.cjs +281 -0
  309. package/dist/integrations/index.d.ts +7 -0
  310. package/dist/integrations/index.d.ts.map +1 -0
  311. package/dist/integrations/index.js +248 -0
  312. package/dist/integrations/next.cjs +131 -0
  313. package/dist/integrations/next.d.ts +29 -0
  314. package/dist/integrations/next.d.ts.map +1 -0
  315. package/dist/integrations/next.js +99 -0
  316. package/dist/integrations/react.cjs +182 -0
  317. package/dist/integrations/react.d.ts +257 -0
  318. package/dist/integrations/react.d.ts.map +1 -0
  319. package/dist/integrations/react.js +150 -0
  320. package/dist/plugins/geo/index.d.ts +2 -0
  321. package/dist/plugins/geo/index.d.ts.map +1 -0
  322. package/dist/test/utils.d.ts +65 -0
  323. package/dist/test/utils.d.ts.map +1 -0
  324. package/dist/types/api.d.ts +89 -0
  325. package/dist/types/api.d.ts.map +1 -0
  326. package/dist/types/context.d.ts +205 -0
  327. package/dist/types/context.d.ts.map +1 -0
  328. package/dist/types/helper.d.ts +78 -0
  329. package/dist/types/helper.d.ts.map +1 -0
  330. package/dist/types/index.cjs +19 -0
  331. package/dist/types/index.d.ts +6 -0
  332. package/dist/types/index.d.ts.map +1 -0
  333. package/dist/types/index.js +0 -0
  334. package/dist/types/options.d.ts +172 -0
  335. package/dist/types/options.d.ts.map +1 -0
  336. package/dist/types/plugins.d.ts +442 -0
  337. package/dist/types/plugins.d.ts.map +1 -0
  338. package/dist/utils/env.d.ts +77 -0
  339. package/dist/utils/env.d.ts.map +1 -0
  340. package/dist/utils/hide-metadata.d.ts +22 -0
  341. package/dist/utils/hide-metadata.d.ts.map +1 -0
  342. package/dist/utils/index.cjs +268 -0
  343. package/dist/utils/index.d.ts +18 -0
  344. package/dist/utils/index.d.ts.map +1 -0
  345. package/dist/utils/index.js +210 -0
  346. package/dist/utils/ip.d.ts +10 -0
  347. package/dist/utils/ip.d.ts.map +1 -0
  348. package/dist/utils/json.d.ts +14 -0
  349. package/dist/utils/json.d.ts.map +1 -0
  350. package/dist/utils/logger.d.ts +108 -0
  351. package/dist/utils/logger.d.ts.map +1 -0
  352. package/dist/utils/url.d.ts +87 -0
  353. package/dist/utils/url.d.ts.map +1 -0
  354. package/dist/utils/wildcard.d.ts +46 -0
  355. package/dist/utils/wildcard.d.ts.map +1 -0
  356. package/knip.json +37 -0
  357. package/package.json +146 -0
  358. package/rslib.config.ts +104 -0
  359. package/src/api/call.ts +177 -0
  360. package/src/api/index.ts +303 -0
  361. package/src/api/middlewares/index.ts +38 -0
  362. package/src/api/middlewares/origin-check.ts +260 -0
  363. package/src/api/middlewares/validate-context.ts +175 -0
  364. package/src/api/routes/__tests__/consent.test.ts +270 -0
  365. package/src/api/routes/__tests__/status.test.ts +36 -0
  366. package/src/api/routes/error.ts +130 -0
  367. package/src/api/routes/generate-consent-receipt.ts +244 -0
  368. package/src/api/routes/get-consent-history.ts +128 -0
  369. package/src/api/routes/get-consent-policy.ts +327 -0
  370. package/src/api/routes/get-consent.ts +230 -0
  371. package/src/api/routes/index.ts +12 -0
  372. package/src/api/routes/ok.ts +45 -0
  373. package/src/api/routes/set-consent.ts +328 -0
  374. package/src/api/routes/show-consent-banner.ts +149 -0
  375. package/src/api/routes/status.ts +62 -0
  376. package/src/api/routes/verify-consent.ts +272 -0
  377. package/src/api/routes/withdraw-consent.ts +293 -0
  378. package/src/api/to-endpoints.ts +371 -0
  379. package/src/client/index.ts +471 -0
  380. package/src/client/types.ts +458 -0
  381. package/src/core.test.ts +303 -0
  382. package/src/core.ts +267 -0
  383. package/src/db/adapters/drizzle-adapter/drizzle-adapter.ts +711 -0
  384. package/src/db/adapters/drizzle-adapter/index.ts +1 -0
  385. package/src/db/adapters/kysely-adapter/dialect.ts +192 -0
  386. package/src/db/adapters/kysely-adapter/index.ts +3 -0
  387. package/src/db/adapters/kysely-adapter/kysely-adapter.ts +1168 -0
  388. package/src/db/adapters/kysely-adapter/types.ts +307 -0
  389. package/src/db/adapters/memory-adapter/index.ts +1 -0
  390. package/src/db/adapters/memory-adapter/memory-adapter.ts +648 -0
  391. package/src/db/adapters/prisma-adapter/index.ts +1 -0
  392. package/src/db/adapters/prisma-adapter/prisma-adapter.ts +586 -0
  393. package/src/db/adapters/types.ts +203 -0
  394. package/src/db/adapters/utils.ts +51 -0
  395. package/src/db/core/fields/field-factory.ts +804 -0
  396. package/src/db/core/fields/field-inference.ts +298 -0
  397. package/src/db/core/fields/field-options-integration.ts +135 -0
  398. package/src/db/core/fields/field-types.ts +233 -0
  399. package/src/db/core/fields/id-generator.ts +57 -0
  400. package/src/db/core/fields/index.ts +56 -0
  401. package/src/db/core/fields/superjson-utils.ts +155 -0
  402. package/src/db/core/fields/zod-fields.ts +269 -0
  403. package/src/db/core/get-schema.ts +102 -0
  404. package/src/db/core/types.ts +52 -0
  405. package/src/db/create-registry.ts +31 -0
  406. package/src/db/hooks/create-hooks.ts +88 -0
  407. package/src/db/hooks/index.ts +39 -0
  408. package/src/db/hooks/types.ts +164 -0
  409. package/src/db/hooks/update-hooks.ts +91 -0
  410. package/src/db/hooks/update-many-hooks.ts +176 -0
  411. package/src/db/hooks/utils.ts +151 -0
  412. package/src/db/hooks/with-hooks-factory.ts +68 -0
  413. package/src/db/index.ts +32 -0
  414. package/src/db/migration/get-migration.ts +89 -0
  415. package/src/db/migration/get-schema/get-schema.ts +44 -0
  416. package/src/db/migration/get-schema/index.ts +20 -0
  417. package/src/db/migration/get-schema/process-fields.ts +66 -0
  418. package/src/db/migration/get-schema/process-tables.ts +68 -0
  419. package/src/db/migration/get-schema/types.ts +18 -0
  420. package/src/db/migration/index.ts +18 -0
  421. package/src/db/migration/migration-builders.ts +170 -0
  422. package/src/db/migration/migration-execution.ts +79 -0
  423. package/src/db/migration/schema-comparison.ts +216 -0
  424. package/src/db/migration/type-mapping.ts +255 -0
  425. package/src/db/migration/types.ts +46 -0
  426. package/src/db/schema/audit-log/index.ts +3 -0
  427. package/src/db/schema/audit-log/registry.ts +228 -0
  428. package/src/db/schema/audit-log/schema.ts +46 -0
  429. package/src/db/schema/audit-log/table.ts +185 -0
  430. package/src/db/schema/audit-log/types.ts +29 -0
  431. package/src/db/schema/consent/index.ts +3 -0
  432. package/src/db/schema/consent/registry.ts +381 -0
  433. package/src/db/schema/consent/schema.ts +65 -0
  434. package/src/db/schema/consent/table.ts +220 -0
  435. package/src/db/schema/consent/types.ts +39 -0
  436. package/src/db/schema/consent-geo-location/index.ts +3 -0
  437. package/src/db/schema/consent-geo-location/registry.ts +124 -0
  438. package/src/db/schema/consent-geo-location/schema.ts +51 -0
  439. package/src/db/schema/consent-geo-location/table.ts +169 -0
  440. package/src/db/schema/consent-geo-location/types.ts +21 -0
  441. package/src/db/schema/consent-policy/index.ts +3 -0
  442. package/src/db/schema/consent-policy/registry.ts +313 -0
  443. package/src/db/schema/consent-policy/schema.ts +47 -0
  444. package/src/db/schema/consent-policy/table.ts +141 -0
  445. package/src/db/schema/consent-policy/types.ts +28 -0
  446. package/src/db/schema/consent-purpose/index.ts +3 -0
  447. package/src/db/schema/consent-purpose/registry.ts +188 -0
  448. package/src/db/schema/consent-purpose/schema.ts +58 -0
  449. package/src/db/schema/consent-purpose/table.ts +154 -0
  450. package/src/db/schema/consent-purpose/types.ts +16 -0
  451. package/src/db/schema/consent-purpose-junction/index.ts +3 -0
  452. package/src/db/schema/consent-purpose-junction/registry.ts +189 -0
  453. package/src/db/schema/consent-purpose-junction/schema.ts +49 -0
  454. package/src/db/schema/consent-purpose-junction/table.ts +142 -0
  455. package/src/db/schema/consent-purpose-junction/types.ts +14 -0
  456. package/src/db/schema/consent-record/index.ts +3 -0
  457. package/src/db/schema/consent-record/registry.ts +209 -0
  458. package/src/db/schema/consent-record/schema.ts +42 -0
  459. package/src/db/schema/consent-record/table.ts +124 -0
  460. package/src/db/schema/consent-record/types.ts +21 -0
  461. package/src/db/schema/consent-withdrawal/index.ts +3 -0
  462. package/src/db/schema/consent-withdrawal/registry.ts +219 -0
  463. package/src/db/schema/consent-withdrawal/schema.ts +48 -0
  464. package/src/db/schema/consent-withdrawal/table.ts +181 -0
  465. package/src/db/schema/consent-withdrawal/types.ts +29 -0
  466. package/src/db/schema/definition.ts +196 -0
  467. package/src/db/schema/domain/index.ts +3 -0
  468. package/src/db/schema/domain/registry.ts +272 -0
  469. package/src/db/schema/domain/schema.ts +43 -0
  470. package/src/db/schema/domain/table.ts +137 -0
  471. package/src/db/schema/domain/types.ts +27 -0
  472. package/src/db/schema/geo-location/index.ts +3 -0
  473. package/src/db/schema/geo-location/registry.ts +159 -0
  474. package/src/db/schema/geo-location/schema.ts +45 -0
  475. package/src/db/schema/geo-location/table.ts +148 -0
  476. package/src/db/schema/geo-location/types.ts +18 -0
  477. package/src/db/schema/index.ts +96 -0
  478. package/src/db/schema/parser.ts +417 -0
  479. package/src/db/schema/schemas.ts +35 -0
  480. package/src/db/schema/subject/index.ts +3 -0
  481. package/src/db/schema/subject/registry.ts +371 -0
  482. package/src/db/schema/subject/schema.ts +41 -0
  483. package/src/db/schema/subject/table.ts +139 -0
  484. package/src/db/schema/subject/types.ts +22 -0
  485. package/src/db/schema/types.ts +154 -0
  486. package/src/db/utils/adapter-factory.ts +64 -0
  487. package/src/db/utils/index.ts +10 -0
  488. package/src/db/utils.ts +42 -0
  489. package/src/docs/ADVANCED_JSON_HANDLING.md +99 -0
  490. package/src/docs/neverthrow.md +171 -0
  491. package/src/error/codes.ts +201 -0
  492. package/src/error/error.ts +145 -0
  493. package/src/error/index.ts +23 -0
  494. package/src/error/logging.ts +52 -0
  495. package/src/error/pipeline.ts +57 -0
  496. package/src/error/recovery.ts +45 -0
  497. package/src/error/results.ts +100 -0
  498. package/src/index.ts +79 -0
  499. package/src/init.test.ts +235 -0
  500. package/src/init.ts +261 -0
  501. package/src/integrations/index.ts +10 -0
  502. package/src/integrations/next.ts +136 -0
  503. package/src/integrations/react.ts +567 -0
  504. package/src/plugins/geo/index.ts +563 -0
  505. package/src/test/utils.ts +244 -0
  506. package/src/types/api.ts +101 -0
  507. package/src/types/context.ts +235 -0
  508. package/src/types/helper.ts +87 -0
  509. package/src/types/index.ts +5 -0
  510. package/src/types/options.ts +189 -0
  511. package/src/types/plugins.ts +538 -0
  512. package/src/utils/env.ts +103 -0
  513. package/src/utils/hide-metadata.ts +21 -0
  514. package/src/utils/index.ts +17 -0
  515. package/src/utils/ip.ts +45 -0
  516. package/src/utils/json.ts +19 -0
  517. package/src/utils/logger.ts +252 -0
  518. package/src/utils/url.ts +194 -0
  519. package/src/utils/wildcard.ts +253 -0
  520. package/tsconfig.json +12 -0
  521. package/vitest.config.ts +14 -0
@@ -0,0 +1,1168 @@
1
+ import type {
2
+ Expression,
3
+ ExpressionBuilder,
4
+ ExpressionOrFactory,
5
+ InsertQueryBuilder,
6
+ Kysely,
7
+ OperandExpression,
8
+ ReferenceExpression,
9
+ SqlBool,
10
+ UpdateQueryBuilder,
11
+ } from 'kysely';
12
+ import type {
13
+ BinaryOperatorExpression,
14
+ OperandValueExpressionOrList,
15
+ } from 'node_modules/kysely/dist/esm/parser/binary-operation-parser';
16
+ import type { InsertExpression } from 'node_modules/kysely/dist/esm/parser/insert-values-parser';
17
+ import type { TableReference } from 'node_modules/kysely/dist/esm/parser/table-parser';
18
+ import superjson from 'superjson';
19
+ import { type Field, type Primitive, generateId } from '~/db/core/fields';
20
+ import type {
21
+ EntityInput,
22
+ EntityName,
23
+ EntityOutput,
24
+ EntityTypeMap,
25
+ } from '~/db/core/types';
26
+ import { getConsentTables } from '../..';
27
+ import type { C15TOptions } from '../../../types';
28
+ import type { Adapter, TableFields, Where } from '../types';
29
+ import { applyDefaultValue } from '../utils';
30
+ import type { Database, KyselyDatabaseType } from './types';
31
+
32
+ /**
33
+ * Type alias for Kysely field references
34
+ *
35
+ * This type helps bridge the gap between c15t's field paths and Kysely's
36
+ * strongly typed reference expressions.
37
+ *
38
+ * @internal
39
+ */
40
+ type KyselyFieldRef = ReferenceExpression<Database, keyof Database>;
41
+
42
+ /**
43
+ * Type for expression builder functions used in queries
44
+ *
45
+ * @internal
46
+ */
47
+ type ExpressionFn = (
48
+ eb: ExpressionBuilder<Database, keyof Database>
49
+ ) => unknown;
50
+
51
+ /**
52
+ * Interface for where conditions in Kysely queries
53
+ *
54
+ * This interface defines the structure of query conditions used
55
+ * in database operations. It supports various operators and connectors
56
+ * for building complex query conditions.
57
+ *
58
+ * @typeParam EntityType - The entity type being queried
59
+ */
60
+ export interface WhereCondition<EntityType extends EntityName> {
61
+ /**
62
+ * The field to apply the condition to
63
+ */
64
+ field: keyof EntityTypeMap[EntityType] | 'id';
65
+
66
+ /**
67
+ * The value to compare against
68
+ */
69
+ value: unknown;
70
+
71
+ /**
72
+ * The operator to use for comparison
73
+ *
74
+ * @default "="
75
+ */
76
+ operator?:
77
+ | 'in'
78
+ | 'eq'
79
+ | 'ne'
80
+ | 'lt'
81
+ | 'lte'
82
+ | 'gt'
83
+ | 'gte'
84
+ | 'contains'
85
+ | 'starts_with'
86
+ | 'ends_with'
87
+ | 'ilike'
88
+ | '=';
89
+
90
+ /**
91
+ * The logical connector to use with previous conditions
92
+ *
93
+ * @default "AND"
94
+ */
95
+ connector?: 'AND' | 'OR';
96
+ }
97
+
98
+ /**
99
+ * Configuration options for the Kysely adapter
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const config: KyselyAdapterConfig = {
104
+ * type: 'postgres' // Explicitly set the database type
105
+ * };
106
+ * ```
107
+ */
108
+ export interface KyselyAdapterConfig {
109
+ /**
110
+ * Database type to use with the adapter
111
+ *
112
+ * Setting this explicitly can override the auto-detected type
113
+ * and can be necessary in some environments where detection fails.
114
+ */
115
+ type?: KyselyDatabaseType;
116
+ }
117
+
118
+ /**
119
+ * Type alias for expression results in Kysely queries
120
+ *
121
+ * @internal
122
+ */
123
+ type ExpressionResult<DB> = Expression<DB>;
124
+
125
+ // Note: Throughout this adapter, we use "as any" type assertions in several places
126
+ // to bridge the gap between our runtime-generated field references and Kysely's
127
+ // strongly typed query builder. This is necessary due to the dynamic nature of our
128
+ // schema, where field names and references are determined at runtime.
129
+ // An alternative approach would be to generate fully typed interfaces at build time.
130
+
131
+ /**
132
+ * Creates entity transformation utilities for the Kysely adapter
133
+ *
134
+ * This function creates helper methods for converting between c15t's
135
+ * data format and Kysely's query format, handling field mapping,
136
+ * value transformation, and query building.
137
+ *
138
+ * @internal This function is used internally by the kyselyAdapter
139
+ * @param db - The Kysely database instance
140
+ * @param options - The c15t options
141
+ * @param config - Optional Kysely adapter configuration
142
+ * @returns An object containing entity transformation utilities
143
+ */
144
+ const createEntityTransformer = (
145
+ db: Kysely<Database>,
146
+ options: C15TOptions,
147
+ config?: KyselyAdapterConfig
148
+ ) => {
149
+ const schema = getConsentTables(options);
150
+
151
+ /**
152
+ * Gets the database field name for a model field
153
+ *
154
+ * @internal
155
+ * @typeParam EntityType - The entity type
156
+ * @param model - The model name
157
+ * @param field - The field name in the c15t model
158
+ * @returns The corresponding field name in the database schema
159
+ */
160
+ function getField<EntityType extends EntityName>(
161
+ model: EntityType,
162
+ field: keyof EntityTypeMap[EntityType] | string
163
+ ) {
164
+ if (field === 'id') {
165
+ return field;
166
+ }
167
+ const modelFields = schema[model]?.fields;
168
+ const f = modelFields
169
+ ? (modelFields as Record<string, Field>)[field as string]
170
+ : undefined;
171
+ if (!f) {
172
+ // biome-ignore lint/suspicious/noConsoleLog: no Logger implementation
173
+ // biome-ignore lint/suspicious/noConsole: no Logger implementation
174
+ console.log('Field not found', model, field);
175
+ }
176
+ return f?.fieldName || (field as string);
177
+ }
178
+
179
+ /**
180
+ * Transforms a value from c15t format to database format
181
+ *
182
+ * Handles type conversions like booleans to integers for SQLite,
183
+ * dates to ISO strings, etc.
184
+ *
185
+ * @internal
186
+ * @typeParam EntityType - The entity type
187
+ * @param value - The value to transform
188
+ * @param model - The model name
189
+ * @param field - The field name
190
+ * @returns The transformed value for database storage
191
+ */
192
+ function transformValueToDB<EntityType extends EntityName>(
193
+ value: unknown,
194
+ model: EntityType,
195
+ field: keyof EntityTypeMap[EntityType] | string
196
+ ): unknown {
197
+ if (field === 'id') {
198
+ return value;
199
+ }
200
+ const { type = 'sqlite' } = config || {};
201
+ const modelFields = schema[model]?.fields;
202
+ const f = modelFields
203
+ ? (modelFields as Record<string, Field>)[field as string]
204
+ : undefined;
205
+ if (
206
+ f?.type === 'boolean' &&
207
+ (type === 'sqlite' || type === 'mssql') &&
208
+ value !== null &&
209
+ value !== undefined
210
+ ) {
211
+ return value ? 1 : 0;
212
+ }
213
+ if (f?.type === 'date' && value && value instanceof Date) {
214
+ return type === 'sqlite' ? value.toISOString() : value;
215
+ }
216
+ // Handle JSON field type
217
+ if (f?.type === 'json' && value !== null && value !== undefined) {
218
+ // For PostgreSQL and MySQL, we can use the native JSON types
219
+ if (type === 'postgres' || type === 'mysql') {
220
+ // The database handles the JSON as is
221
+ return value;
222
+ }
223
+ // For SQLite and other databases, stringify the JSON using SuperJSON
224
+ return superjson.stringify(value);
225
+ }
226
+ return value;
227
+ }
228
+
229
+ /**
230
+ * Transforms a value from database format to c15t format
231
+ *
232
+ * Handles type conversions like integers to booleans for SQLite,
233
+ * ISO strings to Date objects, etc.
234
+ *
235
+ * @internal
236
+ * @typeParam EntityType - The entity type
237
+ * @param value - The value from the database
238
+ * @param model - The model name
239
+ * @param field - The field name
240
+ * @returns The transformed value for c15t usage
241
+ */
242
+ function transformValueFromDB<EntityType extends EntityName>(
243
+ value: unknown,
244
+ model: EntityType,
245
+ field: keyof EntityTypeMap[EntityType] | string
246
+ ): unknown {
247
+ const { type = 'sqlite' } = config || {};
248
+
249
+ const modelFields = schema[model]?.fields;
250
+ const f = modelFields
251
+ ? (modelFields as Record<string, Field>)[field as string]
252
+ : undefined;
253
+ if (
254
+ f?.type === 'boolean' &&
255
+ (type === 'sqlite' || type === 'mssql') &&
256
+ value !== null
257
+ ) {
258
+ return value === 1;
259
+ }
260
+ if (f?.type === 'date' && value) {
261
+ return new Date(value as string);
262
+ }
263
+ // Handle JSON field type
264
+ if (f?.type === 'json' && value !== null && value !== undefined) {
265
+ // For PostgreSQL and MySQL, the value might already be an object
266
+ if (
267
+ (type === 'postgres' || type === 'mysql') &&
268
+ typeof value === 'object'
269
+ ) {
270
+ return value;
271
+ }
272
+ // For SQLite and other databases or string JSON from any database
273
+ if (typeof value === 'string') {
274
+ try {
275
+ // Use SuperJSON to parse the JSON string, preserving complex types
276
+ return superjson.parse(value as string);
277
+ } catch {
278
+ // If SuperJSON parsing fails, try standard JSON.parse as fallback
279
+ try {
280
+ return JSON.parse(value as string);
281
+ } catch {
282
+ // If all parsing fails, return the original value
283
+ return value;
284
+ }
285
+ }
286
+ }
287
+ }
288
+ return value;
289
+ }
290
+
291
+ /**
292
+ * Gets the database entity name for a model
293
+ *
294
+ * @internal
295
+ * @typeParam EntityType - The entity type
296
+ * @param model - The model name
297
+ * @returns The database table name
298
+ */
299
+ function getEntityName<EntityType extends EntityName>(
300
+ model: EntityType
301
+ ): TableReference<Database> {
302
+ return schema[model].entityName as TableReference<Database>;
303
+ }
304
+
305
+ return {
306
+ /**
307
+ * Transforms input data from c15t format to database format
308
+ *
309
+ * @internal
310
+ * @typeParam EntityType - The entity type
311
+ * @param data - The data to transform
312
+ * @param model - The model name
313
+ * @param action - Whether this is a create or update operation
314
+ * @returns Transformed data for database insertion/update
315
+ */
316
+ transformInput<EntityType extends EntityName>(
317
+ data: EntityInput<EntityType>,
318
+ model: EntityType,
319
+ action: 'create' | 'update'
320
+ ): InsertExpression<Database, keyof Database> {
321
+ // Initialize with empty object
322
+ const transformedData: Record<string, unknown> = {};
323
+
324
+ // Handle ID for create operations
325
+ if (action === 'create') {
326
+ // If an ID is provided in the input data, use it
327
+ // Otherwise generate a new one with the appropriate prefix
328
+ transformedData.id =
329
+ data.id ||
330
+ (options.advanced?.generateId
331
+ ? options.advanced.generateId({ model })
332
+ : generateId(schema[model].entityPrefix));
333
+ }
334
+
335
+ const fields = schema[model].fields;
336
+ for (const field in fields) {
337
+ if (Object.hasOwn(fields, field)) {
338
+ const value = data[field as keyof typeof data];
339
+ const fieldInfo = (fields as Record<string, Field>)[field];
340
+ const fieldName = fieldInfo?.fieldName || field;
341
+ if (fieldInfo) {
342
+ transformedData[fieldName] = applyDefaultValue(
343
+ transformValueToDB(value, model, field) as Primitive,
344
+ fieldInfo,
345
+ action
346
+ );
347
+ }
348
+ }
349
+ }
350
+
351
+ return transformedData as InsertExpression<Database, keyof Database>;
352
+ },
353
+
354
+ /**
355
+ * Transforms output data from database format to c15t format
356
+ *
357
+ * @internal
358
+ * @typeParam EntityType - The entity type
359
+ * @param data - The data from the database
360
+ * @param model - The model name
361
+ * @param select - Optional array of fields to select
362
+ * @returns Transformed data for c15t or null if no data
363
+ */
364
+ transformOutput<EntityType extends EntityName>(
365
+ data: Record<string, unknown> | null,
366
+ model: EntityType,
367
+ select: string[] = []
368
+ ): EntityOutput<EntityType> | null {
369
+ if (!data) {
370
+ return null;
371
+ }
372
+
373
+ // Initialize transformedData based on conditions
374
+ const transformedData: Record<string, unknown> = {};
375
+
376
+ // Add id to transformed data if needed
377
+ if (data.id && (select.length === 0 || select.includes('id'))) {
378
+ transformedData.id = data.id;
379
+ }
380
+
381
+ const tableSchema = schema[model]?.fields;
382
+ for (const key in tableSchema) {
383
+ if (select.length && !select.includes(key)) {
384
+ continue;
385
+ }
386
+ const field = (tableSchema as Record<string, Field>)[key];
387
+ if (field) {
388
+ transformedData[key] = transformValueFromDB(
389
+ data[field.fieldName || key],
390
+ model,
391
+ key
392
+ );
393
+ }
394
+ }
395
+ return transformedData as EntityOutput<EntityType>;
396
+ },
397
+
398
+ /**
399
+ * Converts c15t where clauses to Kysely query conditions
400
+ *
401
+ * @internal
402
+ * @typeParam EntityType - The entity type
403
+ * @param model - The model name
404
+ * @param whereConditions - Array of where conditions
405
+ * @returns Object with AND and OR expressions for Kysely
406
+ */
407
+ convertWhereClause<EntityType extends EntityName>(
408
+ model: EntityType,
409
+ whereConditions?: WhereCondition<EntityType>[]
410
+ ): {
411
+ and: ExpressionFn[] | null;
412
+ or: ExpressionFn[] | null;
413
+ } {
414
+ if (!whereConditions || whereConditions.length === 0) {
415
+ return {
416
+ and: null,
417
+ or: null,
418
+ };
419
+ }
420
+
421
+ const conditions = {
422
+ and: [] as ExpressionFn[],
423
+ or: [] as ExpressionFn[],
424
+ };
425
+
426
+ for (const condition of whereConditions) {
427
+ let {
428
+ field: _field,
429
+ value,
430
+ operator = '=',
431
+ connector = 'AND',
432
+ } = condition;
433
+ const fieldString = getField<EntityType>(model, _field);
434
+ value = transformValueToDB<EntityType>(value, model, _field);
435
+
436
+ const expr: ExpressionFn = (eb) => {
437
+ // For type safety, cast field to a reference expression
438
+ const dbField = fieldString as unknown as KyselyFieldRef;
439
+
440
+ if (operator.toLowerCase() === 'in') {
441
+ return eb(dbField, 'in', Array.isArray(value) ? value : [value]);
442
+ }
443
+
444
+ if (operator === 'contains') {
445
+ return eb(dbField, 'like', `%${value}%`);
446
+ }
447
+
448
+ if (operator === 'starts_with') {
449
+ return eb(dbField, 'like', `${value}%`);
450
+ }
451
+
452
+ if (operator === 'ends_with') {
453
+ return eb(dbField, 'like', `%${value}`);
454
+ }
455
+
456
+ if (operator === 'ilike') {
457
+ // Use SQL LOWER function for case-insensitive comparison
458
+ const lowerField = eb.fn<string>('lower', [dbField]);
459
+ const lowerValue = eb.fn<string>('lower', [
460
+ eb.val(value?.toString()),
461
+ ]);
462
+ return eb(
463
+ lowerField,
464
+ 'like',
465
+ lowerValue
466
+ ) as ExpressionResult<Database>;
467
+ }
468
+
469
+ if (operator === 'eq') {
470
+ return eb(dbField, '=', value);
471
+ }
472
+
473
+ if (operator === 'ne') {
474
+ return eb(dbField, '<>', value);
475
+ }
476
+
477
+ if (operator === 'gt') {
478
+ return eb(dbField, '>', value);
479
+ }
480
+
481
+ if (operator === 'gte') {
482
+ return eb(dbField, '>=', value);
483
+ }
484
+
485
+ if (operator === 'lt') {
486
+ return eb(dbField, '<', value);
487
+ }
488
+
489
+ if (operator === 'lte') {
490
+ return eb(dbField, '<=', value);
491
+ }
492
+
493
+ return eb(dbField, operator as BinaryOperatorExpression, value);
494
+ };
495
+
496
+ if (connector === 'OR') {
497
+ conditions.or.push(expr);
498
+ } else {
499
+ conditions.and.push(expr);
500
+ }
501
+ }
502
+
503
+ return {
504
+ and: conditions.and.length ? conditions.and : null,
505
+ or: conditions.or.length ? conditions.or : null,
506
+ };
507
+ },
508
+
509
+ /**
510
+ * Helper for returning data from operations in different database types
511
+ *
512
+ * @internal
513
+ * @typeParam EntityType - The entity type
514
+ * @param values - The values being inserted/updated
515
+ * @param builder - The query builder
516
+ * @param model - The model name
517
+ * @param where - Where conditions for finding the modified record
518
+ * @returns The result of the operation
519
+ */
520
+ async withReturning<EntityType extends EntityName>(
521
+ values: EntityInput<EntityType>,
522
+ builder:
523
+ | InsertQueryBuilder<Database, keyof Database, keyof Database>
524
+ | UpdateQueryBuilder<
525
+ Database,
526
+ keyof Database,
527
+ keyof Database,
528
+ keyof Database
529
+ >,
530
+ model: EntityType,
531
+ where: WhereCondition<EntityType>[]
532
+ ): Promise<Record<string, unknown> | null> {
533
+ let res: Record<string, unknown> | null = null;
534
+ if (config?.type === 'mysql') {
535
+ //this isn't good, but kysely doesn't support returning in mysql and it doesn't return the inserted id. Change this if there is a better way.
536
+ await builder.execute();
537
+ // Get the field and value to find the created/updated record
538
+ const whereCondition = where[0];
539
+ const field = values.id
540
+ ? 'id'
541
+ : ((whereCondition?.field ?? 'id') as string);
542
+ const value =
543
+ values[field as keyof typeof values] ?? whereCondition?.value;
544
+
545
+ // Safe cast for where field
546
+ const fieldString = getField(
547
+ model,
548
+ field
549
+ ) as unknown as ExpressionOrFactory<
550
+ Database,
551
+ keyof Database,
552
+ KyselyFieldRef
553
+ >;
554
+
555
+ res = (await db
556
+ .selectFrom(getEntityName(model))
557
+ .selectAll()
558
+ .where((eb) =>
559
+ eb(
560
+ fieldString,
561
+ '=',
562
+ value as OperandValueExpressionOrList<
563
+ Database,
564
+ keyof Database,
565
+ KyselyFieldRef
566
+ >
567
+ )
568
+ )
569
+ .executeTakeFirst()) as Record<string, unknown> | null;
570
+ return res;
571
+ }
572
+ if (config?.type === 'mssql') {
573
+ res = (await builder
574
+ .outputAll('inserted')
575
+ .executeTakeFirst()) as Record<string, unknown> | null;
576
+ return res;
577
+ }
578
+ res = (await builder.returningAll().executeTakeFirst()) as Record<
579
+ string,
580
+ unknown
581
+ > | null;
582
+ return res;
583
+ },
584
+ getEntityName,
585
+ getField,
586
+ };
587
+ };
588
+
589
+ /**
590
+ * Creates a c15t adapter for Kysely ORM
591
+ *
592
+ * This factory function creates an adapter that allows c15t to use Kysely ORM
593
+ * as its database layer. It supports PostgreSQL, MySQL, SQLite, and MSSQL.
594
+ *
595
+ * @param db - The Kysely database instance
596
+ * @param config - Optional configuration for the Kysely adapter
597
+ * @returns A c15t adapter factory function
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * import { Kysely, PostgresDialect } from 'kysely';
602
+ * import { Pool } from 'pg';
603
+ * import { c15tInstance } from '@c15t/backend';
604
+ * import { kyselyAdapter } from '@c15t/adapters/kysely';
605
+ *
606
+ * // Create a Postgres connection pool
607
+ * const pool = new Pool({
608
+ * host: 'localhost',
609
+ * database: 'consent_db',
610
+ * user: 'postgres',
611
+ * password: 'password'
612
+ * });
613
+ *
614
+ * // Create Kysely instance
615
+ * const db = new Kysely({
616
+ * dialect: new PostgresDialect({ pool })
617
+ * });
618
+ *
619
+ * // Create the c15t instance with Kysely adapter
620
+ * const c15t = c15tInstance({
621
+ * storage: kyselyAdapter(db, { type: 'postgres' }),
622
+ * // Other c15t options...
623
+ * secret: process.env.SECRET
624
+ * });
625
+ *
626
+ * // Use in your application
627
+ * export default c15tInstance.handler;
628
+ * ```
629
+ */
630
+ export const kyselyAdapter =
631
+ (db: Kysely<Database>, config?: KyselyAdapterConfig) =>
632
+ (opts: C15TOptions): Adapter => {
633
+ const {
634
+ transformInput,
635
+ withReturning,
636
+ transformOutput,
637
+ convertWhereClause,
638
+ getEntityName,
639
+ getField,
640
+ } = createEntityTransformer(db, opts, config);
641
+ return {
642
+ id: 'kysely',
643
+ /**
644
+ * Creates a new record in the database
645
+ *
646
+ * @typeParam Model - The model type
647
+ * @typeParam Data - The data type
648
+ * @typeParam Result - The result type
649
+ * @param data - The data for the create operation
650
+ * @returns The created record
651
+ */
652
+ async create<
653
+ Model extends EntityName,
654
+ Data extends Record<string, unknown>,
655
+ Result extends TableFields<Model>,
656
+ >(data: {
657
+ model: Model;
658
+ data: Data;
659
+ select?: (keyof Result)[];
660
+ }): Promise<Result> {
661
+ const { model, data: values, select } = data;
662
+ const transformed = transformInput(
663
+ values as EntityInput<Model>,
664
+ model,
665
+ 'create'
666
+ );
667
+
668
+ // Safe cast for table name
669
+ const tableName = getEntityName(model);
670
+
671
+ // Use type assertion for builder to match Kysely's expectations
672
+ const builder = db
673
+ .insertInto(tableName as keyof Database)
674
+ .values(transformed);
675
+
676
+ const result = await withReturning(
677
+ transformed as EntityInput<Model>,
678
+ builder as unknown as InsertQueryBuilder<
679
+ Database,
680
+ keyof Database,
681
+ keyof Database
682
+ >,
683
+ model,
684
+ []
685
+ );
686
+
687
+ const output = transformOutput(
688
+ result,
689
+ model,
690
+ select as string[]
691
+ ) as unknown as Result;
692
+
693
+ return output;
694
+ },
695
+ /**
696
+ * Finds a single record matching the where conditions
697
+ *
698
+ * @typeParam Model - The model type
699
+ * @typeParam Result - The result type
700
+ * @param data - The data for the find operation
701
+ * @returns The found record or null if not found
702
+ */
703
+ async findOne<
704
+ Model extends EntityName,
705
+ Result extends TableFields<Model>,
706
+ >(data: {
707
+ model: Model;
708
+ where: Where<Model>;
709
+ select?: (keyof Result)[];
710
+ }): Promise<Result | null> {
711
+ const { model, where, select } = data;
712
+ // Convert Where from Adapter type to internal WhereCondition type
713
+ const whereArray = (Array.isArray(where)
714
+ ? where
715
+ : [where]) as unknown as WhereCondition<Model>[];
716
+ const { and, or } = convertWhereClause(model, whereArray);
717
+
718
+ // Safe cast for table name
719
+ const tableName = getEntityName(model);
720
+ let query = db
721
+ .selectFrom(tableName as unknown as keyof Database)
722
+ .selectAll();
723
+
724
+ if (and) {
725
+ query = query.where((eb) => {
726
+ const conditions = and.map((expr) =>
727
+ expr(eb)
728
+ ) as OperandExpression<SqlBool>[];
729
+ return eb.and(conditions);
730
+ });
731
+ }
732
+ if (or) {
733
+ query = query.where((eb) => {
734
+ const conditions = or.map((expr) =>
735
+ expr(eb)
736
+ ) as OperandExpression<SqlBool>[];
737
+ return eb.or(conditions);
738
+ });
739
+ }
740
+ const res = await query.executeTakeFirst();
741
+ if (!res) {
742
+ return null;
743
+ }
744
+ return transformOutput(
745
+ res as Record<string, unknown>,
746
+ model,
747
+ select as string[]
748
+ ) as unknown as Result | null;
749
+ },
750
+ /**
751
+ * Finds multiple records matching the where conditions
752
+ *
753
+ * @typeParam Model - The model type
754
+ * @typeParam Result - The result type
755
+ * @param data - The data for the find operation
756
+ * @returns Array of matching records
757
+ */
758
+ async findMany<
759
+ Model extends EntityName,
760
+ Result extends TableFields<Model>,
761
+ >(data: {
762
+ model: Model;
763
+ where?: Where<Model>;
764
+ limit?: number;
765
+ sortBy?: { field: 'id' | keyof Result; direction: 'asc' | 'desc' };
766
+ offset?: number;
767
+ }): Promise<Result[]> {
768
+ const { model, where, limit, offset, sortBy } = data;
769
+ // Convert Where from Adapter type to internal WhereCondition type
770
+ const whereArray = where
771
+ ? ((Array.isArray(where)
772
+ ? where
773
+ : [where]) as unknown as WhereCondition<Model>[])
774
+ : undefined;
775
+ const { and, or } = convertWhereClause(model, whereArray);
776
+
777
+ // Safe cast for table name
778
+ const tableName = getEntityName(model);
779
+ let query = db.selectFrom(tableName as unknown as keyof Database);
780
+
781
+ if (and) {
782
+ query = query.where((eb) => {
783
+ const conditions = and.map((expr) =>
784
+ expr(eb)
785
+ ) as OperandExpression<SqlBool>[];
786
+ return eb.and(conditions);
787
+ });
788
+ }
789
+ if (or) {
790
+ query = query.where((eb) => {
791
+ const conditions = or.map((expr) =>
792
+ expr(eb)
793
+ ) as OperandExpression<SqlBool>[];
794
+ return eb.or(conditions);
795
+ });
796
+ }
797
+ if (config?.type === 'mssql') {
798
+ if (!offset) {
799
+ query = query.top(limit || 100);
800
+ }
801
+ } else {
802
+ query = query.limit(limit || 100);
803
+ }
804
+ if (sortBy) {
805
+ // Safe cast for sort field
806
+ const sortFieldString = getField(model, sortBy.field as string);
807
+
808
+ query = query.orderBy(
809
+ sortFieldString as unknown as KyselyFieldRef,
810
+ sortBy.direction
811
+ );
812
+ }
813
+ if (offset) {
814
+ if (config?.type === 'mssql') {
815
+ if (!sortBy) {
816
+ // Safe cast for id field
817
+ query = query.orderBy('id' as unknown as KyselyFieldRef);
818
+ }
819
+ query = query.offset(offset).fetch(limit || 100);
820
+ } else {
821
+ query = query.offset(offset);
822
+ }
823
+ }
824
+
825
+ const res = await query.selectAll().execute();
826
+ if (!res) {
827
+ return [] as unknown as Result[];
828
+ }
829
+ return res.map(
830
+ (r) =>
831
+ transformOutput(
832
+ r as Record<string, unknown>,
833
+ model
834
+ ) as unknown as Result
835
+ );
836
+ },
837
+ /**
838
+ * Updates a single record matching the where conditions
839
+ *
840
+ * @typeParam Model - The model type
841
+ * @typeParam Result - The result type
842
+ * @param data - The data for the update operation
843
+ * @returns The updated record or null if not found
844
+ */
845
+ async update<
846
+ Model extends EntityName,
847
+ Result extends TableFields<Model>,
848
+ >(data: {
849
+ model: Model;
850
+ where: Where<Model>;
851
+ update: EntityInput<Model>;
852
+ }): Promise<Result | null> {
853
+ const { model, where, update: values } = data;
854
+ // Convert Where from Adapter type to internal WhereCondition type
855
+ const whereArray = (Array.isArray(where)
856
+ ? where
857
+ : [where]) as unknown as WhereCondition<Model>[];
858
+ const { and, or } = convertWhereClause(model, whereArray);
859
+ const transformedData = transformInput(
860
+ values as EntityInput<Model>,
861
+ model,
862
+ 'update'
863
+ );
864
+
865
+ // Safe cast for table name
866
+ const tableName = getEntityName(model);
867
+ let query = db
868
+ .updateTable(tableName as unknown as keyof Database)
869
+ .set(transformedData as Record<string, unknown>);
870
+
871
+ if (and) {
872
+ query = query.where((eb) => {
873
+ const conditions = and.map((expr) =>
874
+ expr(eb)
875
+ ) as OperandExpression<SqlBool>[];
876
+ return eb.and(conditions);
877
+ });
878
+ }
879
+ if (or) {
880
+ query = query.where((eb) => {
881
+ const conditions = or.map((expr) =>
882
+ expr(eb)
883
+ ) as OperandExpression<SqlBool>[];
884
+ return eb.or(conditions);
885
+ });
886
+ }
887
+ const result = await withReturning(
888
+ transformedData as EntityInput<Model>,
889
+ query as unknown as UpdateQueryBuilder<
890
+ Database,
891
+ keyof Database,
892
+ keyof Database,
893
+ keyof Database
894
+ >,
895
+ model,
896
+ whereArray
897
+ );
898
+ return transformOutput(result, model) as unknown as Result | null;
899
+ },
900
+ /**
901
+ * Updates multiple records matching the where conditions
902
+ *
903
+ * @typeParam Model - The model type
904
+ * @typeParam Result - The result type
905
+ * @param data - The data for the update operation
906
+ * @returns Array of updated records
907
+ */
908
+ async updateMany<
909
+ Model extends EntityName,
910
+ Result extends TableFields<Model>,
911
+ >(data: {
912
+ model: Model;
913
+ where: Where<Model>;
914
+ update: Partial<EntityInput<Model>>;
915
+ }): Promise<Result[]> {
916
+ const { model, where, update: values } = data;
917
+ // Convert Where from Adapter type to internal WhereCondition type
918
+ const whereArray = (Array.isArray(where)
919
+ ? where
920
+ : [where]) as unknown as WhereCondition<Model>[];
921
+ const { and, or } = convertWhereClause(model, whereArray);
922
+ const transformedData = transformInput(
923
+ values as EntityInput<Model>,
924
+ model,
925
+ 'update'
926
+ );
927
+
928
+ // Safe cast for table name
929
+ const tableName = getEntityName(model);
930
+ let query = db
931
+ .updateTable(tableName as unknown as keyof Database)
932
+ .set(transformedData as Record<string, unknown>);
933
+
934
+ if (and) {
935
+ query = query.where((eb) => {
936
+ const conditions = and.map((expr) =>
937
+ expr(eb)
938
+ ) as OperandExpression<SqlBool>[];
939
+ return eb.and(conditions);
940
+ });
941
+ }
942
+ if (or) {
943
+ query = query.where((eb) => {
944
+ const conditions = or.map((expr) =>
945
+ expr(eb)
946
+ ) as OperandExpression<SqlBool>[];
947
+ return eb.or(conditions);
948
+ });
949
+ }
950
+ await query.execute();
951
+
952
+ // After update is complete, fetch the updated records using the same where conditions
953
+ // Safe cast for table name
954
+ let selectQuery = db
955
+ .selectFrom(tableName as unknown as keyof Database)
956
+ .selectAll();
957
+
958
+ if (and) {
959
+ selectQuery = selectQuery.where((eb) => {
960
+ const conditions = and.map((expr) =>
961
+ expr(eb)
962
+ ) as OperandExpression<SqlBool>[];
963
+ return eb.and(conditions);
964
+ });
965
+ }
966
+ if (or) {
967
+ selectQuery = selectQuery.where((eb) => {
968
+ const conditions = or.map((expr) =>
969
+ expr(eb)
970
+ ) as OperandExpression<SqlBool>[];
971
+ return eb.or(conditions);
972
+ });
973
+ }
974
+
975
+ const fetchedResults = await selectQuery.execute();
976
+
977
+ // Transform the results using the same pattern as findMany
978
+ if (!fetchedResults || fetchedResults.length === 0) {
979
+ return [] as unknown as Result[];
980
+ }
981
+
982
+ return fetchedResults.map(
983
+ (record) =>
984
+ transformOutput(
985
+ record as Record<string, unknown>,
986
+ model
987
+ ) as unknown as Result
988
+ );
989
+ },
990
+ /**
991
+ * Counts records matching the where conditions
992
+ *
993
+ * @typeParam Model - The model type
994
+ * @param data - The data for the count operation
995
+ * @returns The count of matching records
996
+ */
997
+ async count<Model extends EntityName>(data: {
998
+ model: Model;
999
+ where?: Where<Model>;
1000
+ }): Promise<number> {
1001
+ const { model, where } = data;
1002
+ // Convert Where from Adapter type to internal WhereCondition type
1003
+ const whereArray = where
1004
+ ? ((Array.isArray(where)
1005
+ ? where
1006
+ : [where]) as unknown as WhereCondition<Model>[])
1007
+ : undefined;
1008
+ const { and, or } = convertWhereClause(model, whereArray);
1009
+
1010
+ // Safe cast for table name
1011
+ const tableName = getEntityName(model);
1012
+ let query = db
1013
+ .selectFrom(tableName as unknown as keyof Database)
1014
+ .select((eb) => eb.fn.count<number>('id').as('count'));
1015
+
1016
+ if (and) {
1017
+ query = query.where((eb) => {
1018
+ const conditions = and.map((expr) =>
1019
+ expr(eb)
1020
+ ) as OperandExpression<SqlBool>[];
1021
+ return eb.and(conditions);
1022
+ });
1023
+ }
1024
+ if (or) {
1025
+ query = query.where((eb) => {
1026
+ const conditions = or.map((expr) =>
1027
+ expr(eb)
1028
+ ) as OperandExpression<SqlBool>[];
1029
+ return eb.or(conditions);
1030
+ });
1031
+ }
1032
+ const res = await query.execute();
1033
+ // Get count from result
1034
+ const count = (res[0] as Record<string, unknown>)?.count;
1035
+ return typeof count === 'number' ? count : 0;
1036
+ },
1037
+ /**
1038
+ * Deletes a single record matching the where conditions
1039
+ *
1040
+ * @typeParam Model - The model type
1041
+ * @param data - The data for the delete operation
1042
+ */
1043
+ async delete<Model extends EntityName>(data: {
1044
+ model: Model;
1045
+ where: Where<Model>;
1046
+ }): Promise<void> {
1047
+ const { model, where } = data;
1048
+ // Convert Where from Adapter type to internal WhereCondition type
1049
+ const whereArray = (Array.isArray(where)
1050
+ ? where
1051
+ : [where]) as unknown as WhereCondition<Model>[];
1052
+ const { and, or } = convertWhereClause(model, whereArray);
1053
+
1054
+ // Safe cast for table name
1055
+ const tableName = getEntityName(model);
1056
+ let query = db.deleteFrom(tableName as unknown as keyof Database);
1057
+
1058
+ if (and) {
1059
+ query = query.where((eb) => {
1060
+ const conditions = and.map((expr) =>
1061
+ expr(eb)
1062
+ ) as OperandExpression<SqlBool>[];
1063
+ return eb.and(conditions);
1064
+ });
1065
+ }
1066
+
1067
+ if (or) {
1068
+ query = query.where((eb) => {
1069
+ const conditions = or.map((expr) =>
1070
+ expr(eb)
1071
+ ) as OperandExpression<SqlBool>[];
1072
+ return eb.or(conditions);
1073
+ });
1074
+ }
1075
+ await query.execute();
1076
+ },
1077
+ /**
1078
+ * Deletes multiple records matching the where conditions
1079
+ *
1080
+ * @typeParam Model - The model type
1081
+ * @param data - The data for the delete operation
1082
+ * @returns The number of records deleted
1083
+ */
1084
+ async deleteMany<Model extends EntityName>(data: {
1085
+ model: Model;
1086
+ where: Where<Model>;
1087
+ }): Promise<number> {
1088
+ const { model, where } = data;
1089
+ // Convert Where from Adapter type to internal WhereCondition type
1090
+ const whereArray = (Array.isArray(where)
1091
+ ? where
1092
+ : [where]) as unknown as WhereCondition<Model>[];
1093
+ const { and, or } = convertWhereClause(model, whereArray);
1094
+
1095
+ // Safe cast for table name
1096
+ const tableName = getEntityName(model);
1097
+ let query = db.deleteFrom(tableName as unknown as keyof Database);
1098
+ if (and) {
1099
+ query = query.where((eb) => {
1100
+ const conditions = and.map((expr) =>
1101
+ expr(eb)
1102
+ ) as OperandExpression<SqlBool>[];
1103
+ return eb.and(conditions);
1104
+ });
1105
+ }
1106
+ if (or) {
1107
+ query = query.where((eb) => {
1108
+ const conditions = or.map((expr) =>
1109
+ expr(eb)
1110
+ ) as OperandExpression<SqlBool>[];
1111
+ return eb.or(conditions);
1112
+ });
1113
+ }
1114
+ const result = await query.execute();
1115
+ const count = result.length;
1116
+ return count;
1117
+ },
1118
+ /**
1119
+ * Executes a function within a database transaction
1120
+ *
1121
+ * This method wraps Kysely's transaction functionality to provide a consistent interface
1122
+ * for executing multiple database operations atomically. Falls back to direct execution
1123
+ * if transactions are disabled or not supported by the database.
1124
+ *
1125
+ * @typeParam ResultType - The type of data returned by the transaction
1126
+ * @param data - The transaction data containing the callback function
1127
+ * @returns A promise that resolves with the result of the callback function
1128
+ * @throws {Error} If the transaction fails to complete
1129
+ */
1130
+ async transaction<ResultType>(data: {
1131
+ callback: (transactionAdapter: Adapter) => Promise<ResultType>;
1132
+ }): Promise<ResultType> {
1133
+ const { callback } = data;
1134
+
1135
+ // Check if transactions are explicitly disabled
1136
+ if (opts.advanced?.disableTransactions) {
1137
+ const regularAdapter = kyselyAdapter(db, config)(opts);
1138
+ return await callback(regularAdapter);
1139
+ }
1140
+
1141
+ try {
1142
+ return await db.transaction().execute(async (trx) => {
1143
+ const transactionAdapter = kyselyAdapter(trx, config)(opts);
1144
+ return await callback(transactionAdapter);
1145
+ });
1146
+ } catch (error) {
1147
+ // Check if the error indicates transactions are not supported
1148
+ if (
1149
+ error instanceof Error &&
1150
+ (error.message.includes('transactions are not supported') ||
1151
+ error.message.toLowerCase().includes('no transaction support'))
1152
+ ) {
1153
+ // Log warning about disableTransactions option
1154
+ // biome-ignore lint/suspicious/noConsole: this is a warning
1155
+ console.warn(
1156
+ 'Warning: Database transaction failed. If your database does not support transactions, ' +
1157
+ 'you can disable this warning by setting opts.advanced.disableTransactions to true.'
1158
+ );
1159
+ // Fallback: execute without transaction
1160
+ const regularAdapter = kyselyAdapter(db, config)(opts);
1161
+ return await callback(regularAdapter);
1162
+ }
1163
+ throw error;
1164
+ }
1165
+ },
1166
+ options: config,
1167
+ };
1168
+ };