@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,1508 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_superjson__ from "superjson";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_zod__ from "zod";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_base_x_aeb88370__ from "base-x";
4
+ import "node:crypto";
5
+ import "neverthrow";
6
+ import "kysely";
7
+ const fieldConfigSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
8
+ required: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
9
+ returned: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
10
+ input: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
11
+ defaultValue: __WEBPACK_EXTERNAL_MODULE_zod__.z.union([
12
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
13
+ __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
14
+ ]).optional(),
15
+ transform: __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
16
+ input: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
17
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
18
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.promise(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
19
+ ])).optional(),
20
+ output: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
21
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
22
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.promise(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
23
+ ])).optional()
24
+ }).optional(),
25
+ validator: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
26
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
27
+ __WEBPACK_EXTERNAL_MODULE_zod__.z["null"]()
28
+ ])).optional(),
29
+ unique: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().optional(),
30
+ indexed: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().optional(),
31
+ sortable: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
32
+ fieldName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
33
+ bigint: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false)
34
+ });
35
+ const stringFieldSchema = fieldConfigSchema.extend({
36
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('string'),
37
+ minLength: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
38
+ maxLength: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
39
+ pattern: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional()
40
+ });
41
+ const numberFieldSchema = fieldConfigSchema.extend({
42
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('number'),
43
+ min: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
44
+ max: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional()
45
+ });
46
+ const booleanFieldSchema = fieldConfigSchema.extend({
47
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('boolean')
48
+ });
49
+ const dateFieldSchema = fieldConfigSchema.extend({
50
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('date'),
51
+ minDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
52
+ maxDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
53
+ dateOnly: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
54
+ format: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional()
55
+ });
56
+ const timezoneFieldSchema = fieldConfigSchema.extend({
57
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('timezone'),
58
+ validateTimezone: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
59
+ suggestedValues: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional(),
60
+ restrictToSuggestedValues: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false)
61
+ });
62
+ const jsonFieldSchema = fieldConfigSchema.extend({
63
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('json'),
64
+ validateJson: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true)
65
+ });
66
+ const stringArrayFieldSchema = fieldConfigSchema.extend({
67
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('string[]')
68
+ });
69
+ const numberArrayFieldSchema = fieldConfigSchema.extend({
70
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('number[]')
71
+ });
72
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.discriminatedUnion('type', [
73
+ stringFieldSchema,
74
+ numberFieldSchema,
75
+ booleanFieldSchema,
76
+ dateFieldSchema,
77
+ timezoneFieldSchema,
78
+ jsonFieldSchema,
79
+ stringArrayFieldSchema,
80
+ numberArrayFieldSchema
81
+ ]);
82
+ const COMMON_TIMEZONES = {
83
+ UTC: 'UTC',
84
+ GMT: 'GMT',
85
+ EASTERN: 'America/New_York',
86
+ CENTRAL: 'America/Chicago',
87
+ MOUNTAIN: 'America/Denver',
88
+ PACIFIC: 'America/Los_Angeles',
89
+ LONDON: 'Europe/London',
90
+ PARIS: 'Europe/Paris',
91
+ BERLIN: 'Europe/Berlin',
92
+ TOKYO: 'Asia/Tokyo',
93
+ SHANGHAI: 'Asia/Shanghai',
94
+ SINGAPORE: 'Asia/Singapore',
95
+ SYDNEY: 'Australia/Sydney',
96
+ SAO_PAULO: 'America/Sao_Paulo'
97
+ };
98
+ const b58 = (0, __WEBPACK_EXTERNAL_MODULE_base_x_aeb88370__["default"])('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
99
+ function id_generator_generateId(prefix) {
100
+ const buf = crypto.getRandomValues(new Uint8Array(20));
101
+ const EPOCH_TIMESTAMP = 1700000000000;
102
+ const t = Date.now() - EPOCH_TIMESTAMP;
103
+ const high = Math.floor(t / 0x100000000);
104
+ const low = t >>> 0;
105
+ buf[0] = high >>> 24 & 255;
106
+ buf[1] = high >>> 16 & 255;
107
+ buf[2] = high >>> 8 & 255;
108
+ buf[3] = 255 & high;
109
+ buf[4] = low >>> 24 & 255;
110
+ buf[5] = low >>> 16 & 255;
111
+ buf[6] = low >>> 8 & 255;
112
+ buf[7] = 255 & low;
113
+ return `${prefix}_${b58.encode(buf)}`;
114
+ }
115
+ const definition_getConsentTables = (options)=>{
116
+ const pluginSchema = options.plugins?.reduce((acc, plugin)=>{
117
+ const schema = plugin.schema;
118
+ if (!schema) return acc;
119
+ for (const [key, value] of Object.entries(schema))acc[key] = {
120
+ fields: {
121
+ ...acc[key]?.fields,
122
+ ...value.fields
123
+ },
124
+ entityName: value.entityName || key
125
+ };
126
+ return acc;
127
+ }, {});
128
+ const { subject, consentPurpose, consentPolicy, domain, geoLocation, consent, consentPurposeJunction, record, consentGeoLocation, consentWithdrawal, auditLog, ...pluginTables } = pluginSchema || {};
129
+ return {
130
+ subject: getSubjectTable(options, subject?.fields),
131
+ consentPurpose: getPurposeTable(options, consentPurpose?.fields),
132
+ consentPolicy: getConsentPolicyTable(options, consentPolicy?.fields),
133
+ domain: getDomainTable(options, domain?.fields),
134
+ consent: getConsentTable(options, consent?.fields),
135
+ consentPurposeJunction: getPurposeJunctionTable(options, consentPurposeJunction?.fields),
136
+ consentRecord: getConsentRecordTable(options, record?.fields),
137
+ consentGeoLocation: getConsentGeoLocationTable(options, consentGeoLocation?.fields),
138
+ consentWithdrawal: getConsentWithdrawalTable(options, consentWithdrawal?.fields),
139
+ auditLog: getAuditLogTable(options, auditLog?.fields),
140
+ geoLocation: getGeoLocationTable(options, geoLocation?.fields),
141
+ ...pluginTables
142
+ };
143
+ };
144
+ const auditLogSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
145
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
146
+ entityType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
147
+ entityId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
148
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
149
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
150
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
151
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
152
+ changes: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
153
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
154
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
155
+ });
156
+ function getAuditLogTable(options, auditLogFields) {
157
+ const auditLogConfig = options.tables?.auditLog;
158
+ const subjectConfig = options.tables?.subject;
159
+ return {
160
+ entityName: auditLogConfig?.entityName || 'auditLog',
161
+ entityPrefix: auditLogConfig?.entityPrefix || 'log',
162
+ schema: auditLogSchema,
163
+ fields: {
164
+ entityType: {
165
+ type: 'string',
166
+ required: true,
167
+ fieldName: auditLogConfig?.fields?.entityType || 'entityType'
168
+ },
169
+ entityId: {
170
+ type: 'string',
171
+ required: true,
172
+ fieldName: auditLogConfig?.fields?.entityId || 'entityId'
173
+ },
174
+ actionType: {
175
+ type: 'string',
176
+ required: true,
177
+ fieldName: auditLogConfig?.fields?.actionType || 'actionType'
178
+ },
179
+ subjectId: {
180
+ type: 'string',
181
+ required: false,
182
+ fieldName: auditLogConfig?.fields?.subjectId || 'subjectId',
183
+ references: {
184
+ model: subjectConfig?.entityName || 'subject',
185
+ field: 'id'
186
+ }
187
+ },
188
+ ipAddress: {
189
+ type: 'string',
190
+ required: false,
191
+ fieldName: auditLogConfig?.fields?.ipAddress || 'ipAddress'
192
+ },
193
+ userAgent: {
194
+ type: 'string',
195
+ required: false,
196
+ fieldName: auditLogConfig?.fields?.userAgent || 'userAgent'
197
+ },
198
+ changes: {
199
+ type: 'json',
200
+ required: false,
201
+ fieldName: auditLogConfig?.fields?.changes || 'changes'
202
+ },
203
+ metadata: {
204
+ type: 'json',
205
+ required: false,
206
+ fieldName: auditLogConfig?.fields?.metadata || 'metadata'
207
+ },
208
+ createdAt: {
209
+ type: 'date',
210
+ defaultValue: ()=>new Date(),
211
+ required: true,
212
+ fieldName: auditLogConfig?.fields?.createdAt || 'createdAt'
213
+ },
214
+ eventTimezone: {
215
+ type: 'timezone',
216
+ required: true,
217
+ defaultValue: COMMON_TIMEZONES.UTC,
218
+ fieldName: auditLogConfig?.fields?.eventTimezone || 'eventTimezone'
219
+ },
220
+ ...auditLogFields || {},
221
+ ...auditLogConfig?.additionalFields || {}
222
+ },
223
+ indexes: [
224
+ {
225
+ name: 'entity_index',
226
+ fields: [
227
+ 'entityType',
228
+ 'entityId'
229
+ ]
230
+ },
231
+ {
232
+ name: 'action_type_index',
233
+ fields: [
234
+ 'actionType'
235
+ ]
236
+ },
237
+ {
238
+ name: 'subject_id_index',
239
+ fields: [
240
+ 'subjectId'
241
+ ]
242
+ },
243
+ {
244
+ name: 'created_at_index',
245
+ fields: [
246
+ 'createdAt'
247
+ ]
248
+ }
249
+ ],
250
+ order: 5
251
+ };
252
+ }
253
+ const consentGeoLocationSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
254
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
255
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
256
+ ip: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().ip(),
257
+ country: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
258
+ region: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
259
+ city: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
260
+ latitude: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().min(-90).max(90).optional(),
261
+ longitude: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().min(-180).max(180).optional(),
262
+ timezone: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().regex(/^[A-Za-z_]+\/[A-Za-z_]+$/).optional(),
263
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
264
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
265
+ });
266
+ function getConsentGeoLocationTable(options, geoLocationFields) {
267
+ const consentGeoLocationConfig = options.tables?.consentGeoLocation;
268
+ const consentConfig = options.tables?.consent;
269
+ return {
270
+ entityName: consentGeoLocationConfig?.entityName || 'consentGeoLocation',
271
+ entityPrefix: consentGeoLocationConfig?.entityPrefix || 'cgl',
272
+ schema: consentGeoLocationSchema,
273
+ fields: {
274
+ consentId: {
275
+ type: 'string',
276
+ required: true,
277
+ fieldName: consentGeoLocationConfig?.fields?.consentId || 'consentId',
278
+ references: {
279
+ model: consentConfig?.entityName || 'consent',
280
+ field: 'id'
281
+ }
282
+ },
283
+ ip: {
284
+ type: 'string',
285
+ required: true,
286
+ fieldName: consentGeoLocationConfig?.fields?.ip || 'ip'
287
+ },
288
+ country: {
289
+ type: 'string',
290
+ required: false,
291
+ fieldName: consentGeoLocationConfig?.fields?.country || 'country'
292
+ },
293
+ region: {
294
+ type: 'string',
295
+ required: false,
296
+ fieldName: consentGeoLocationConfig?.fields?.region || 'region'
297
+ },
298
+ city: {
299
+ type: 'string',
300
+ required: false,
301
+ fieldName: consentGeoLocationConfig?.fields?.city || 'city'
302
+ },
303
+ latitude: {
304
+ type: 'number',
305
+ required: false,
306
+ fieldName: consentGeoLocationConfig?.fields?.latitude || 'latitude'
307
+ },
308
+ longitude: {
309
+ type: 'number',
310
+ required: false,
311
+ fieldName: consentGeoLocationConfig?.fields?.longitude || 'longitude'
312
+ },
313
+ timezone: {
314
+ type: 'string',
315
+ required: false,
316
+ fieldName: consentGeoLocationConfig?.fields?.timezone || 'timezone'
317
+ },
318
+ createdAt: {
319
+ type: 'date',
320
+ defaultValue: ()=>new Date(),
321
+ required: true,
322
+ fieldName: consentGeoLocationConfig?.fields?.createdAt || 'createdAt'
323
+ },
324
+ ...geoLocationFields || {},
325
+ ...consentGeoLocationConfig?.additionalFields || {}
326
+ },
327
+ indexes: [
328
+ {
329
+ name: 'consent_id_index',
330
+ fields: [
331
+ 'consentId'
332
+ ]
333
+ },
334
+ {
335
+ name: 'country_index',
336
+ fields: [
337
+ 'country'
338
+ ]
339
+ },
340
+ {
341
+ name: 'created_at_index',
342
+ fields: [
343
+ 'createdAt'
344
+ ]
345
+ }
346
+ ],
347
+ order: 4
348
+ };
349
+ }
350
+ const consentPolicySchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
351
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
352
+ version: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
353
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
354
+ effectiveDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date(),
355
+ expirationDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().nullable().optional(),
356
+ content: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
357
+ contentHash: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
358
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
359
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
360
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
361
+ });
362
+ function getConsentPolicyTable(options, policyFields) {
363
+ const consentPolicyConfig = options.tables?.consentPolicy;
364
+ return {
365
+ entityName: consentPolicyConfig?.entityName || 'consentPolicy',
366
+ entityPrefix: consentPolicyConfig?.entityPrefix || 'pol',
367
+ schema: consentPolicySchema,
368
+ fields: {
369
+ version: {
370
+ type: 'string',
371
+ required: true,
372
+ fieldName: consentPolicyConfig?.fields?.version || 'version'
373
+ },
374
+ name: {
375
+ type: 'string',
376
+ required: true,
377
+ fieldName: consentPolicyConfig?.fields?.name || 'name'
378
+ },
379
+ effectiveDate: {
380
+ type: 'date',
381
+ required: true,
382
+ fieldName: consentPolicyConfig?.fields?.effectiveDate || 'effectiveDate'
383
+ },
384
+ expirationDate: {
385
+ type: 'date',
386
+ required: false,
387
+ fieldName: consentPolicyConfig?.fields?.expirationDate || 'expirationDate'
388
+ },
389
+ content: {
390
+ type: 'string',
391
+ required: true,
392
+ fieldName: consentPolicyConfig?.fields?.content || 'content'
393
+ },
394
+ contentHash: {
395
+ type: 'string',
396
+ required: true,
397
+ fieldName: consentPolicyConfig?.fields?.contentHash || 'contentHash'
398
+ },
399
+ isActive: {
400
+ type: 'boolean',
401
+ defaultValue: true,
402
+ required: true,
403
+ fieldName: consentPolicyConfig?.fields?.isActive || 'isActive'
404
+ },
405
+ createdAt: {
406
+ type: 'date',
407
+ defaultValue: ()=>new Date(),
408
+ required: true,
409
+ fieldName: consentPolicyConfig?.fields?.createdAt || 'createdAt'
410
+ },
411
+ ...policyFields || {},
412
+ ...consentPolicyConfig?.additionalFields || {}
413
+ },
414
+ order: 2
415
+ };
416
+ }
417
+ const consentPurposeJunctionSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
418
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
419
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
420
+ consentPurposeId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
421
+ status: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
422
+ 'active',
423
+ 'withdrawn'
424
+ ], {
425
+ errorMap: ()=>({
426
+ message: "Status must be either 'active' or 'withdrawn'"
427
+ })
428
+ }).default('active'),
429
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
430
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
431
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.number(),
432
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean()
433
+ ])).optional(),
434
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
435
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
436
+ });
437
+ function getPurposeJunctionTable(options, junctionFields) {
438
+ const purposeJunctionConfig = options.tables?.consentPurposeJunction;
439
+ const consentConfig = options.tables?.consent;
440
+ const purposeConfig = options.tables?.consentPurpose;
441
+ return {
442
+ entityName: purposeJunctionConfig?.entityName || 'consentPurposeJunction',
443
+ entityPrefix: purposeJunctionConfig?.entityPrefix || 'pjx',
444
+ schema: consentPurposeJunctionSchema,
445
+ fields: {
446
+ consentId: {
447
+ type: 'string',
448
+ required: true,
449
+ fieldName: purposeJunctionConfig?.fields?.consentId || 'consentId',
450
+ references: {
451
+ model: consentConfig?.entityName || 'consent',
452
+ field: 'id'
453
+ }
454
+ },
455
+ purposeId: {
456
+ type: 'string',
457
+ required: true,
458
+ fieldName: purposeJunctionConfig?.fields?.purposeId || 'purposeId',
459
+ references: {
460
+ model: purposeConfig?.entityName || 'consentPurpose',
461
+ field: 'id'
462
+ }
463
+ },
464
+ status: {
465
+ type: 'string',
466
+ defaultValue: ()=>'active',
467
+ required: true,
468
+ fieldName: purposeJunctionConfig?.fields?.status || 'status'
469
+ },
470
+ metadata: {
471
+ type: 'json',
472
+ required: false,
473
+ fieldName: purposeJunctionConfig?.fields?.metadata || 'metadata'
474
+ },
475
+ createdAt: {
476
+ type: 'date',
477
+ defaultValue: ()=>new Date(),
478
+ required: true,
479
+ fieldName: purposeJunctionConfig?.fields?.createdAt || 'createdAt'
480
+ },
481
+ updatedAt: {
482
+ type: 'date',
483
+ required: false,
484
+ fieldName: purposeJunctionConfig?.fields?.updatedAt || 'updatedAt'
485
+ },
486
+ ...junctionFields || {},
487
+ ...purposeJunctionConfig?.additionalFields || {}
488
+ },
489
+ uniqueConstraints: [
490
+ {
491
+ name: 'unique_consent_purpose',
492
+ fields: [
493
+ 'consentId',
494
+ 'purposeId'
495
+ ]
496
+ }
497
+ ],
498
+ order: 4
499
+ };
500
+ }
501
+ const purposeSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
502
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
503
+ code: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
504
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
505
+ description: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
506
+ isEssential: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
507
+ dataCategory: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
508
+ legalBasis: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
509
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
510
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
511
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
512
+ });
513
+ function getPurposeTable(options, purposeFields) {
514
+ const purposeConfig = options.tables?.consentPurpose;
515
+ return {
516
+ entityName: purposeConfig?.entityName || 'consentPurpose',
517
+ entityPrefix: purposeConfig?.entityPrefix || 'pur',
518
+ schema: purposeSchema,
519
+ fields: {
520
+ code: {
521
+ type: 'string',
522
+ required: true,
523
+ fieldName: purposeConfig?.fields?.code || 'code'
524
+ },
525
+ name: {
526
+ type: 'string',
527
+ required: true,
528
+ fieldName: purposeConfig?.fields?.name || 'name'
529
+ },
530
+ description: {
531
+ type: 'string',
532
+ required: true,
533
+ fieldName: purposeConfig?.fields?.description || "description"
534
+ },
535
+ isEssential: {
536
+ type: 'boolean',
537
+ defaultValue: ()=>false,
538
+ required: true,
539
+ fieldName: purposeConfig?.fields?.isEssential || 'isEssential'
540
+ },
541
+ dataCategory: {
542
+ type: 'string',
543
+ required: false,
544
+ fieldName: purposeConfig?.fields?.dataCategory || 'dataCategory'
545
+ },
546
+ legalBasis: {
547
+ type: 'string',
548
+ required: false,
549
+ fieldName: purposeConfig?.fields?.legalBasis || 'legalBasis'
550
+ },
551
+ isActive: {
552
+ type: 'boolean',
553
+ defaultValue: true,
554
+ required: true,
555
+ fieldName: purposeConfig?.fields?.isActive || 'isActive'
556
+ },
557
+ createdAt: {
558
+ type: 'date',
559
+ defaultValue: ()=>new Date(),
560
+ required: true,
561
+ fieldName: purposeConfig?.fields?.createdAt || 'createdAt'
562
+ },
563
+ updatedAt: {
564
+ type: 'date',
565
+ defaultValue: ()=>new Date(),
566
+ required: true,
567
+ fieldName: purposeConfig?.fields?.updatedAt || 'updatedAt'
568
+ },
569
+ ...purposeFields || {},
570
+ ...purposeConfig?.additionalFields || {}
571
+ },
572
+ order: 1
573
+ };
574
+ }
575
+ const consentRecordSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
576
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
577
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
578
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
579
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
580
+ details: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
581
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
582
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
583
+ });
584
+ function getConsentRecordTable(options, recordFields) {
585
+ const recordConfig = options.tables?.record;
586
+ const subjectConfig = options.tables?.subject;
587
+ const consentConfig = options.tables?.consent;
588
+ return {
589
+ entityName: recordConfig?.entityName || 'consentRecord',
590
+ entityPrefix: recordConfig?.entityPrefix || 'rec',
591
+ schema: consentRecordSchema,
592
+ fields: {
593
+ subjectId: {
594
+ type: 'string',
595
+ required: true,
596
+ fieldName: recordConfig?.fields?.subjectId || 'subjectId',
597
+ references: {
598
+ model: subjectConfig?.entityName || 'subject',
599
+ field: 'id'
600
+ }
601
+ },
602
+ consentId: {
603
+ type: 'string',
604
+ required: false,
605
+ fieldName: recordConfig?.fields?.consentId || 'consentId',
606
+ references: {
607
+ model: consentConfig?.entityName || 'consent',
608
+ field: 'id'
609
+ }
610
+ },
611
+ actionType: {
612
+ type: 'string',
613
+ required: true,
614
+ fieldName: recordConfig?.fields?.actionType || 'actionType'
615
+ },
616
+ details: {
617
+ type: 'json',
618
+ required: false,
619
+ fieldName: recordConfig?.fields?.details || 'details'
620
+ },
621
+ createdAt: {
622
+ type: 'date',
623
+ defaultValue: ()=>new Date(),
624
+ required: true,
625
+ fieldName: recordConfig?.fields?.createdAt || 'createdAt'
626
+ },
627
+ ...recordFields || {},
628
+ ...recordConfig?.additionalFields || {}
629
+ },
630
+ order: 4
631
+ };
632
+ }
633
+ const consentWithdrawalSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
634
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
635
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
636
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
637
+ withdrawalReason: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
638
+ withdrawalMethod: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
639
+ 'subject-initiated',
640
+ 'automatic-expiry',
641
+ 'admin',
642
+ 'api',
643
+ 'other'
644
+ ]).default('subject-initiated'),
645
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
646
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
647
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
648
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
649
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
650
+ });
651
+ function getConsentWithdrawalTable(options, withdrawalFields) {
652
+ const consentWithdrawalConfig = options.tables?.consentWithdrawal;
653
+ const consentConfig = options.tables?.consent;
654
+ const subjectConfig = options.tables?.subject;
655
+ return {
656
+ entityName: consentWithdrawalConfig?.entityName || 'consentWithdrawal',
657
+ entityPrefix: consentWithdrawalConfig?.entityPrefix || 'wdr',
658
+ schema: consentWithdrawalSchema,
659
+ fields: {
660
+ consentId: {
661
+ type: 'string',
662
+ required: true,
663
+ fieldName: consentWithdrawalConfig?.fields?.consentId || 'consentId',
664
+ references: {
665
+ model: consentConfig?.entityName || 'consent',
666
+ field: 'id'
667
+ }
668
+ },
669
+ subjectId: {
670
+ type: 'string',
671
+ required: true,
672
+ fieldName: consentWithdrawalConfig?.fields?.subjectId || 'subjectId',
673
+ references: {
674
+ model: subjectConfig?.entityName || 'subject',
675
+ field: 'id'
676
+ }
677
+ },
678
+ withdrawalReason: {
679
+ type: 'string',
680
+ required: false,
681
+ fieldName: consentWithdrawalConfig?.fields?.withdrawalReason || 'withdrawalReason'
682
+ },
683
+ withdrawalMethod: {
684
+ type: 'string',
685
+ defaultValue: ()=>'subject-initiated',
686
+ required: true,
687
+ fieldName: consentWithdrawalConfig?.fields?.withdrawalMethod || 'withdrawalMethod'
688
+ },
689
+ ipAddress: {
690
+ type: 'string',
691
+ required: false,
692
+ fieldName: consentWithdrawalConfig?.fields?.ipAddress || 'ipAddress'
693
+ },
694
+ userAgent: {
695
+ type: 'string',
696
+ required: false,
697
+ fieldName: consentWithdrawalConfig?.fields?.userAgent || 'userAgent'
698
+ },
699
+ metadata: {
700
+ type: 'json',
701
+ required: false,
702
+ fieldName: consentWithdrawalConfig?.fields?.metadata || 'metadata'
703
+ },
704
+ createdAt: {
705
+ type: 'date',
706
+ defaultValue: ()=>new Date(),
707
+ required: true,
708
+ fieldName: consentWithdrawalConfig?.fields?.createdAt || 'createdAt'
709
+ },
710
+ ...withdrawalFields || {},
711
+ ...consentWithdrawalConfig?.additionalFields || {}
712
+ },
713
+ uniqueConstraints: consentWithdrawalConfig?.preventMultipleWithdrawals !== false ? [
714
+ {
715
+ name: 'unique_consent_withdrawal',
716
+ fields: [
717
+ 'consentId'
718
+ ]
719
+ }
720
+ ] : [],
721
+ indexes: [
722
+ {
723
+ name: 'subject_id_index',
724
+ fields: [
725
+ 'subjectId'
726
+ ]
727
+ },
728
+ {
729
+ name: 'created_at_index',
730
+ fields: [
731
+ 'createdAt'
732
+ ]
733
+ }
734
+ ],
735
+ order: 4
736
+ };
737
+ }
738
+ const consentHistorySchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
739
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
740
+ 'given',
741
+ 'withdrawn',
742
+ 'updated',
743
+ 'expired'
744
+ ]),
745
+ timestamp: __WEBPACK_EXTERNAL_MODULE_zod__.z.date(),
746
+ details: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
747
+ previousState: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
748
+ newState: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional()
749
+ });
750
+ const consentSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
751
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
752
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
753
+ domainId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
754
+ purposeIds: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()),
755
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
756
+ policyId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
757
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
758
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
759
+ status: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
760
+ 'active',
761
+ 'withdrawn',
762
+ 'expired'
763
+ ]).default('active'),
764
+ withdrawalReason: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
765
+ givenAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
766
+ validUntil: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
767
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
768
+ history: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(consentHistorySchema).default([])
769
+ });
770
+ function getConsentTable(options, consentFields) {
771
+ const consentConfig = options.tables?.consent;
772
+ const subjectConfig = options.tables?.subject;
773
+ const domainConfig = options.tables?.domain;
774
+ const policyConfig = options.tables?.consentPolicy;
775
+ const purposeConfig = options.tables?.consentPurpose;
776
+ return {
777
+ entityName: consentConfig?.entityName || 'consent',
778
+ entityPrefix: consentConfig?.entityPrefix || 'cns',
779
+ schema: consentSchema,
780
+ fields: {
781
+ subjectId: {
782
+ type: 'string',
783
+ required: true,
784
+ fieldName: consentConfig?.fields?.subjectId || 'subjectId',
785
+ references: {
786
+ model: subjectConfig?.entityName || 'subject',
787
+ field: 'id'
788
+ }
789
+ },
790
+ domainId: {
791
+ type: 'string',
792
+ required: true,
793
+ fieldName: consentConfig?.fields?.domainId || 'domainId',
794
+ references: {
795
+ model: domainConfig?.entityName || 'domain',
796
+ field: 'id'
797
+ }
798
+ },
799
+ purposeIds: {
800
+ type: 'json',
801
+ required: false,
802
+ fieldName: consentConfig?.fields?.purposeIds || 'purposeIds',
803
+ references: {
804
+ model: purposeConfig?.entityName || 'consentPurpose',
805
+ field: 'id',
806
+ type: 'array'
807
+ }
808
+ },
809
+ metadata: {
810
+ type: 'json',
811
+ required: false,
812
+ fieldName: consentConfig?.fields?.metadata || 'metadata'
813
+ },
814
+ policyId: {
815
+ type: 'string',
816
+ required: false,
817
+ fieldName: consentConfig?.fields?.policyId || 'policyId',
818
+ references: {
819
+ model: policyConfig?.entityName || 'consentPolicy',
820
+ field: 'id'
821
+ }
822
+ },
823
+ ipAddress: {
824
+ type: 'string',
825
+ required: false,
826
+ fieldName: consentConfig?.fields?.ipAddress || 'ipAddress'
827
+ },
828
+ userAgent: {
829
+ type: 'string',
830
+ required: false,
831
+ fieldName: consentConfig?.fields?.userAgent || 'userAgent'
832
+ },
833
+ status: {
834
+ type: 'string',
835
+ defaultValue: ()=>'active',
836
+ required: true,
837
+ fieldName: consentConfig?.fields?.status || 'status'
838
+ },
839
+ withdrawalReason: {
840
+ type: 'string',
841
+ required: false,
842
+ fieldName: consentConfig?.fields?.withdrawalReason || 'withdrawalReason'
843
+ },
844
+ givenAt: {
845
+ type: 'date',
846
+ defaultValue: ()=>new Date(),
847
+ required: true,
848
+ fieldName: consentConfig?.fields?.givenAt || 'givenAt'
849
+ },
850
+ validUntil: {
851
+ type: 'date',
852
+ required: false,
853
+ fieldName: consentConfig?.fields?.validUntil || 'validUntil',
854
+ transform: {
855
+ input: (val, data)=>{
856
+ if (val) return val;
857
+ const expiresIn = consentConfig?.expiresIn || 31536000;
858
+ const givenAt = data.givenAt instanceof Date ? data.givenAt : new Date();
859
+ if (expiresIn > 0) {
860
+ const validUntil = new Date(givenAt);
861
+ validUntil.setSeconds(validUntil.getSeconds() + expiresIn);
862
+ return validUntil;
863
+ }
864
+ }
865
+ }
866
+ },
867
+ isActive: {
868
+ type: 'boolean',
869
+ defaultValue: true,
870
+ required: true,
871
+ fieldName: consentConfig?.fields?.isActive || 'isActive'
872
+ },
873
+ ...consentFields || {},
874
+ ...consentConfig?.additionalFields || {}
875
+ },
876
+ order: 3
877
+ };
878
+ }
879
+ const domainSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
880
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
881
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().min(1),
882
+ description: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
883
+ allowedOrigins: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional().default([]),
884
+ isVerified: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
885
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
886
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
887
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
888
+ });
889
+ function getDomainTable(options, domainFields) {
890
+ const domainConfig = options.tables?.domain;
891
+ return {
892
+ entityName: domainConfig?.entityName || 'domain',
893
+ entityPrefix: domainConfig?.entityPrefix || 'dom',
894
+ schema: domainSchema,
895
+ fields: {
896
+ name: {
897
+ type: 'string',
898
+ required: true,
899
+ unique: true,
900
+ fieldName: domainConfig?.fields?.name || 'name'
901
+ },
902
+ description: {
903
+ type: 'string',
904
+ required: false,
905
+ fieldName: domainConfig?.fields?.description || "description"
906
+ },
907
+ allowedOrigins: {
908
+ type: 'json',
909
+ defaultValue: ()=>[],
910
+ required: false,
911
+ fieldName: domainConfig?.fields?.allowedOrigins || 'allowedOrigins'
912
+ },
913
+ isVerified: {
914
+ type: 'boolean',
915
+ defaultValue: true,
916
+ required: true,
917
+ fieldName: domainConfig?.fields?.isVerified || 'isVerified'
918
+ },
919
+ isActive: {
920
+ type: 'boolean',
921
+ defaultValue: true,
922
+ required: true,
923
+ fieldName: domainConfig?.fields?.isActive || 'isActive'
924
+ },
925
+ createdAt: {
926
+ type: 'date',
927
+ defaultValue: ()=>new Date(),
928
+ required: true,
929
+ fieldName: domainConfig?.fields?.createdAt || 'createdAt'
930
+ },
931
+ updatedAt: {
932
+ type: 'date',
933
+ required: false,
934
+ fieldName: domainConfig?.fields?.updatedAt || 'updatedAt'
935
+ },
936
+ ...domainFields || {},
937
+ ...domainConfig?.additionalFields || {}
938
+ },
939
+ order: 1
940
+ };
941
+ }
942
+ const geoLocationSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
943
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
944
+ countryCode: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().length(2).toUpperCase(),
945
+ countryName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
946
+ regionCode: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
947
+ regionName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
948
+ regulatoryZones: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
949
+ 'GDPR',
950
+ 'CCPA',
951
+ 'CPRA',
952
+ 'LGPD',
953
+ 'PIPEDA'
954
+ ])).optional(),
955
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
956
+ });
957
+ function getGeoLocationTable(options, geoLocationFields) {
958
+ const geoLocationConfig = options.tables?.geoLocation;
959
+ return {
960
+ entityName: geoLocationConfig?.entityName || 'geoLocation',
961
+ entityPrefix: geoLocationConfig?.entityPrefix || 'geo',
962
+ schema: geoLocationSchema,
963
+ fields: {
964
+ countryCode: {
965
+ type: 'string',
966
+ required: true,
967
+ fieldName: geoLocationConfig?.fields?.countryCode || 'countryCode'
968
+ },
969
+ countryName: {
970
+ type: 'string',
971
+ required: true,
972
+ fieldName: geoLocationConfig?.fields?.countryName || 'countryName'
973
+ },
974
+ regionCode: {
975
+ type: 'string',
976
+ required: false,
977
+ fieldName: geoLocationConfig?.fields?.regionCode || 'regionCode'
978
+ },
979
+ regionName: {
980
+ type: 'string',
981
+ required: false,
982
+ fieldName: geoLocationConfig?.fields?.regionName || 'regionName'
983
+ },
984
+ regulatoryZones: {
985
+ type: 'json',
986
+ required: false,
987
+ fieldName: geoLocationConfig?.fields?.regulatoryZones || 'regulatoryZones',
988
+ transformer: {
989
+ input: (value)=>JSON.stringify(value),
990
+ output: (value)=>{
991
+ try {
992
+ return JSON.parse(value);
993
+ } catch {
994
+ return [];
995
+ }
996
+ }
997
+ }
998
+ },
999
+ createdAt: {
1000
+ type: 'date',
1001
+ defaultValue: ()=>new Date(),
1002
+ required: true,
1003
+ fieldName: geoLocationConfig?.fields?.createdAt || 'createdAt'
1004
+ },
1005
+ ...geoLocationFields || {},
1006
+ ...geoLocationConfig?.additionalFields || {}
1007
+ },
1008
+ indexes: [
1009
+ {
1010
+ name: 'country_code_index',
1011
+ fields: [
1012
+ 'countryCode'
1013
+ ]
1014
+ },
1015
+ {
1016
+ name: 'region_code_index',
1017
+ fields: [
1018
+ 'regionCode'
1019
+ ]
1020
+ },
1021
+ {
1022
+ name: 'created_at_index',
1023
+ fields: [
1024
+ 'createdAt'
1025
+ ]
1026
+ }
1027
+ ],
1028
+ order: 1
1029
+ };
1030
+ }
1031
+ const subjectSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
1032
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1033
+ isIdentified: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
1034
+ externalId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().nullable().optional(),
1035
+ identityProvider: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1036
+ lastIpAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1037
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
1038
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
1039
+ });
1040
+ function getSubjectTable(options, subjectFields) {
1041
+ const subjectConfig = options.tables?.subject;
1042
+ return {
1043
+ entityName: subjectConfig?.entityName || 'subject',
1044
+ entityPrefix: subjectConfig?.entityPrefix || 'sub',
1045
+ schema: subjectSchema,
1046
+ fields: {
1047
+ isIdentified: {
1048
+ type: 'boolean',
1049
+ defaultValue: ()=>false,
1050
+ required: true,
1051
+ fieldName: subjectConfig?.fields?.isIdentified || 'isIdentified'
1052
+ },
1053
+ externalId: {
1054
+ type: 'string',
1055
+ required: false,
1056
+ fieldName: subjectConfig?.fields?.externalId || 'externalId'
1057
+ },
1058
+ identityProvider: {
1059
+ type: 'string',
1060
+ required: false,
1061
+ fieldName: subjectConfig?.fields?.identityProvider || 'identityProvider'
1062
+ },
1063
+ lastIpAddress: {
1064
+ type: 'string',
1065
+ required: false,
1066
+ fieldName: subjectConfig?.fields?.lastIpAddress || 'lastIpAddress'
1067
+ },
1068
+ createdAt: {
1069
+ type: 'date',
1070
+ defaultValue: ()=>new Date(),
1071
+ required: true,
1072
+ fieldName: subjectConfig?.fields?.createdAt || 'createdAt'
1073
+ },
1074
+ updatedAt: {
1075
+ type: 'date',
1076
+ defaultValue: ()=>new Date(),
1077
+ required: true,
1078
+ fieldName: subjectConfig?.fields?.updatedAt || 'updatedAt'
1079
+ },
1080
+ subjectTimezone: {
1081
+ type: 'timezone',
1082
+ required: false,
1083
+ defaultValue: COMMON_TIMEZONES.UTC,
1084
+ fieldName: subjectConfig?.fields?.subjectTimezone || 'subjectTimezone'
1085
+ },
1086
+ ...subjectFields || {},
1087
+ ...subjectConfig?.additionalFields || {}
1088
+ },
1089
+ order: 1
1090
+ };
1091
+ }
1092
+ const levels = [
1093
+ 'info',
1094
+ 'success',
1095
+ 'warn',
1096
+ 'error',
1097
+ 'debug'
1098
+ ];
1099
+ function shouldPublishLog(currentLogLevel, logLevel) {
1100
+ return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
1101
+ }
1102
+ const colors = {
1103
+ reset: '\x1b[0m',
1104
+ bright: '\x1b[1m',
1105
+ dim: '\x1b[2m',
1106
+ underscore: '\x1b[4m',
1107
+ blink: '\x1b[5m',
1108
+ reverse: '\x1b[7m',
1109
+ hidden: '\x1b[8m',
1110
+ fg: {
1111
+ black: '\x1b[30m',
1112
+ red: '\x1b[31m',
1113
+ green: '\x1b[32m',
1114
+ yellow: '\x1b[33m',
1115
+ blue: '\x1b[34m',
1116
+ magenta: '\x1b[35m',
1117
+ cyan: '\x1b[36m',
1118
+ white: '\x1b[37m'
1119
+ },
1120
+ bg: {
1121
+ black: '\x1b[40m',
1122
+ red: '\x1b[41m',
1123
+ green: '\x1b[42m',
1124
+ yellow: '\x1b[43m',
1125
+ blue: '\x1b[44m',
1126
+ magenta: '\x1b[45m',
1127
+ cyan: '\x1b[46m',
1128
+ white: '\x1b[47m'
1129
+ }
1130
+ };
1131
+ const levelColors = {
1132
+ info: colors.fg.blue,
1133
+ success: colors.fg.green,
1134
+ warn: colors.fg.yellow,
1135
+ error: colors.fg.red,
1136
+ debug: colors.fg.magenta
1137
+ };
1138
+ const formatMessage = (level, message)=>{
1139
+ const timestamp = new Date().toISOString();
1140
+ return `${colors.dim}${timestamp}${colors.reset} ${levelColors[level]}${level.toUpperCase()}${colors.reset} ${colors.bright}[c15t]:${colors.reset} ${message}`;
1141
+ };
1142
+ const logger_createLogger = (options)=>{
1143
+ const enabled = options?.disabled !== true;
1144
+ const logLevel = options?.level ?? 'error';
1145
+ const LogFunc = (level, message, args = [])=>{
1146
+ if (!enabled || !shouldPublishLog(logLevel, level)) return;
1147
+ const formattedMessage = formatMessage(level, message);
1148
+ if (!options || 'function' != typeof options.log) {
1149
+ if ('error' === level) console.error(formattedMessage, ...args);
1150
+ else if ('warn' === level) console.warn(formattedMessage, ...args);
1151
+ else if ('info' === level) console.log(formattedMessage, ...args);
1152
+ else if ('debug' === level) console.debug(formattedMessage, ...args);
1153
+ else if ('success' === level) console.log(formattedMessage, ...args);
1154
+ return;
1155
+ }
1156
+ options.log('success' === level ? 'info' : level, message, ...args);
1157
+ };
1158
+ return Object.fromEntries(levels.map((level)=>[
1159
+ level,
1160
+ (...[message, ...args])=>LogFunc(level, message, args)
1161
+ ]));
1162
+ };
1163
+ logger_createLogger();
1164
+ function utils_applyDefaultValue(inputValue, field, operation) {
1165
+ if ('update' === operation) return inputValue;
1166
+ if (null == inputValue && field.defaultValue) {
1167
+ if ('function' == typeof field.defaultValue) return field.defaultValue();
1168
+ return field.defaultValue;
1169
+ }
1170
+ return inputValue;
1171
+ }
1172
+ const kysely_adapter_rslib_entry_createEntityTransformer = (db, options, config)=>{
1173
+ const schema = definition_getConsentTables(options);
1174
+ function getField(model, field) {
1175
+ if ('id' === field) return field;
1176
+ const modelFields = schema[model]?.fields;
1177
+ const f = modelFields ? modelFields[field] : void 0;
1178
+ if (!f) console.log('Field not found', model, field);
1179
+ return f?.fieldName || field;
1180
+ }
1181
+ function transformValueToDB(value, model, field) {
1182
+ if ('id' === field) return value;
1183
+ const { type = 'sqlite' } = config || {};
1184
+ const modelFields = schema[model]?.fields;
1185
+ const f = modelFields ? modelFields[field] : void 0;
1186
+ if (f?.type === 'boolean' && ('sqlite' === type || 'mssql' === type) && null != value) return value ? 1 : 0;
1187
+ if (f?.type === 'date' && value && value instanceof Date) return 'sqlite' === type ? value.toISOString() : value;
1188
+ if (f?.type === 'json' && null != value) {
1189
+ if ('postgres' === type || 'mysql' === type) return value;
1190
+ return __WEBPACK_EXTERNAL_MODULE_superjson__["default"].stringify(value);
1191
+ }
1192
+ return value;
1193
+ }
1194
+ function transformValueFromDB(value, model, field) {
1195
+ const { type = 'sqlite' } = config || {};
1196
+ const modelFields = schema[model]?.fields;
1197
+ const f = modelFields ? modelFields[field] : void 0;
1198
+ if (f?.type === 'boolean' && ('sqlite' === type || 'mssql' === type) && null !== value) return 1 === value;
1199
+ if (f?.type === 'date' && value) return new Date(value);
1200
+ if (f?.type === 'json' && null != value) {
1201
+ if (('postgres' === type || 'mysql' === type) && 'object' == typeof value) return value;
1202
+ if ('string' == typeof value) try {
1203
+ return __WEBPACK_EXTERNAL_MODULE_superjson__["default"].parse(value);
1204
+ } catch {
1205
+ try {
1206
+ return JSON.parse(value);
1207
+ } catch {}
1208
+ }
1209
+ }
1210
+ return value;
1211
+ }
1212
+ function getEntityName(model) {
1213
+ return schema[model].entityName;
1214
+ }
1215
+ return {
1216
+ transformInput (data, model, action) {
1217
+ const transformedData = {};
1218
+ if ('create' === action) transformedData.id = data.id || (options.advanced?.generateId ? options.advanced.generateId({
1219
+ model
1220
+ }) : id_generator_generateId(schema[model].entityPrefix));
1221
+ const fields = schema[model].fields;
1222
+ for(const field in fields)if (Object.hasOwn(fields, field)) {
1223
+ const value = data[field];
1224
+ const fieldInfo = fields[field];
1225
+ const fieldName = fieldInfo?.fieldName || field;
1226
+ if (fieldInfo) transformedData[fieldName] = utils_applyDefaultValue(transformValueToDB(value, model, field), fieldInfo, action);
1227
+ }
1228
+ return transformedData;
1229
+ },
1230
+ transformOutput (data, model, select = []) {
1231
+ if (!data) return null;
1232
+ const transformedData = {};
1233
+ if (data.id && (0 === select.length || select.includes('id'))) transformedData.id = data.id;
1234
+ const tableSchema = schema[model]?.fields;
1235
+ for(const key in tableSchema){
1236
+ if (select.length && !select.includes(key)) continue;
1237
+ const field = tableSchema[key];
1238
+ if (field) transformedData[key] = transformValueFromDB(data[field.fieldName || key], model, key);
1239
+ }
1240
+ return transformedData;
1241
+ },
1242
+ convertWhereClause (model, whereConditions) {
1243
+ if (!whereConditions || 0 === whereConditions.length) return {
1244
+ and: null,
1245
+ or: null
1246
+ };
1247
+ const conditions = {
1248
+ and: [],
1249
+ or: []
1250
+ };
1251
+ for (const condition of whereConditions){
1252
+ let { field: _field, value, operator = '=', connector = 'AND' } = condition;
1253
+ const fieldString = getField(model, _field);
1254
+ value = transformValueToDB(value, model, _field);
1255
+ const expr = (eb)=>{
1256
+ const dbField = fieldString;
1257
+ if ('in' === operator.toLowerCase()) return eb(dbField, 'in', Array.isArray(value) ? value : [
1258
+ value
1259
+ ]);
1260
+ if ('contains' === operator) return eb(dbField, 'like', `%${value}%`);
1261
+ if ('starts_with' === operator) return eb(dbField, 'like', `${value}%`);
1262
+ if ('ends_with' === operator) return eb(dbField, 'like', `%${value}`);
1263
+ if ('ilike' === operator) {
1264
+ const lowerField = eb.fn('lower', [
1265
+ dbField
1266
+ ]);
1267
+ const lowerValue = eb.fn('lower', [
1268
+ eb.val(value?.toString())
1269
+ ]);
1270
+ return eb(lowerField, 'like', lowerValue);
1271
+ }
1272
+ if ('eq' === operator) return eb(dbField, '=', value);
1273
+ if ('ne' === operator) return eb(dbField, '<>', value);
1274
+ if ('gt' === operator) return eb(dbField, '>', value);
1275
+ if ('gte' === operator) return eb(dbField, '>=', value);
1276
+ if ('lt' === operator) return eb(dbField, '<', value);
1277
+ if ('lte' === operator) return eb(dbField, '<=', value);
1278
+ return eb(dbField, operator, value);
1279
+ };
1280
+ if ('OR' === connector) conditions.or.push(expr);
1281
+ else conditions.and.push(expr);
1282
+ }
1283
+ return {
1284
+ and: conditions.and.length ? conditions.and : null,
1285
+ or: conditions.or.length ? conditions.or : null
1286
+ };
1287
+ },
1288
+ async withReturning (values, builder, model, where) {
1289
+ let res = null;
1290
+ if (config?.type === 'mysql') {
1291
+ await builder.execute();
1292
+ const whereCondition = where[0];
1293
+ const field = values.id ? 'id' : whereCondition?.field ?? 'id';
1294
+ const value = values[field] ?? whereCondition?.value;
1295
+ const fieldString = getField(model, field);
1296
+ res = await db.selectFrom(getEntityName(model)).selectAll().where((eb)=>eb(fieldString, '=', value)).executeTakeFirst();
1297
+ return res;
1298
+ }
1299
+ if (config?.type === 'mssql') {
1300
+ res = await builder.outputAll('inserted').executeTakeFirst();
1301
+ return res;
1302
+ }
1303
+ res = await builder.returningAll().executeTakeFirst();
1304
+ return res;
1305
+ },
1306
+ getEntityName,
1307
+ getField
1308
+ };
1309
+ };
1310
+ const kysely_adapter_rslib_entry_kyselyAdapter = (db, config)=>(opts)=>{
1311
+ const { transformInput, withReturning, transformOutput, convertWhereClause, getEntityName, getField } = kysely_adapter_rslib_entry_createEntityTransformer(db, opts, config);
1312
+ return {
1313
+ id: 'kysely',
1314
+ async create (data) {
1315
+ const { model, data: values, select } = data;
1316
+ const transformed = transformInput(values, model, 'create');
1317
+ const tableName = getEntityName(model);
1318
+ const builder = db.insertInto(tableName).values(transformed);
1319
+ const result = await withReturning(transformed, builder, model, []);
1320
+ const output = transformOutput(result, model, select);
1321
+ return output;
1322
+ },
1323
+ async findOne (data) {
1324
+ const { model, where, select } = data;
1325
+ const whereArray = Array.isArray(where) ? where : [
1326
+ where
1327
+ ];
1328
+ const { and, or } = convertWhereClause(model, whereArray);
1329
+ const tableName = getEntityName(model);
1330
+ let query = db.selectFrom(tableName).selectAll();
1331
+ if (and) query = query.where((eb)=>{
1332
+ const conditions = and.map((expr)=>expr(eb));
1333
+ return eb.and(conditions);
1334
+ });
1335
+ if (or) query = query.where((eb)=>{
1336
+ const conditions = or.map((expr)=>expr(eb));
1337
+ return eb.or(conditions);
1338
+ });
1339
+ const res = await query.executeTakeFirst();
1340
+ if (!res) return null;
1341
+ return transformOutput(res, model, select);
1342
+ },
1343
+ async findMany (data) {
1344
+ const { model, where, limit, offset, sortBy } = data;
1345
+ const whereArray = where ? Array.isArray(where) ? where : [
1346
+ where
1347
+ ] : void 0;
1348
+ const { and, or } = convertWhereClause(model, whereArray);
1349
+ const tableName = getEntityName(model);
1350
+ let query = db.selectFrom(tableName);
1351
+ if (and) query = query.where((eb)=>{
1352
+ const conditions = and.map((expr)=>expr(eb));
1353
+ return eb.and(conditions);
1354
+ });
1355
+ if (or) query = query.where((eb)=>{
1356
+ const conditions = or.map((expr)=>expr(eb));
1357
+ return eb.or(conditions);
1358
+ });
1359
+ if (config?.type === 'mssql') {
1360
+ if (!offset) query = query.top(limit || 100);
1361
+ } else query = query.limit(limit || 100);
1362
+ if (sortBy) {
1363
+ const sortFieldString = getField(model, sortBy.field);
1364
+ query = query.orderBy(sortFieldString, sortBy.direction);
1365
+ }
1366
+ if (offset) {
1367
+ if (config?.type === 'mssql') {
1368
+ if (!sortBy) query = query.orderBy('id');
1369
+ query = query.offset(offset).fetch(limit || 100);
1370
+ } else query = query.offset(offset);
1371
+ }
1372
+ const res = await query.selectAll().execute();
1373
+ if (!res) return [];
1374
+ return res.map((r)=>transformOutput(r, model));
1375
+ },
1376
+ async update (data) {
1377
+ const { model, where, update: values } = data;
1378
+ const whereArray = Array.isArray(where) ? where : [
1379
+ where
1380
+ ];
1381
+ const { and, or } = convertWhereClause(model, whereArray);
1382
+ const transformedData = transformInput(values, model, 'update');
1383
+ const tableName = getEntityName(model);
1384
+ let query = db.updateTable(tableName).set(transformedData);
1385
+ if (and) query = query.where((eb)=>{
1386
+ const conditions = and.map((expr)=>expr(eb));
1387
+ return eb.and(conditions);
1388
+ });
1389
+ if (or) query = query.where((eb)=>{
1390
+ const conditions = or.map((expr)=>expr(eb));
1391
+ return eb.or(conditions);
1392
+ });
1393
+ const result = await withReturning(transformedData, query, model, whereArray);
1394
+ return transformOutput(result, model);
1395
+ },
1396
+ async updateMany (data) {
1397
+ const { model, where, update: values } = data;
1398
+ const whereArray = Array.isArray(where) ? where : [
1399
+ where
1400
+ ];
1401
+ const { and, or } = convertWhereClause(model, whereArray);
1402
+ const transformedData = transformInput(values, model, 'update');
1403
+ const tableName = getEntityName(model);
1404
+ let query = db.updateTable(tableName).set(transformedData);
1405
+ if (and) query = query.where((eb)=>{
1406
+ const conditions = and.map((expr)=>expr(eb));
1407
+ return eb.and(conditions);
1408
+ });
1409
+ if (or) query = query.where((eb)=>{
1410
+ const conditions = or.map((expr)=>expr(eb));
1411
+ return eb.or(conditions);
1412
+ });
1413
+ await query.execute();
1414
+ let selectQuery = db.selectFrom(tableName).selectAll();
1415
+ if (and) selectQuery = selectQuery.where((eb)=>{
1416
+ const conditions = and.map((expr)=>expr(eb));
1417
+ return eb.and(conditions);
1418
+ });
1419
+ if (or) selectQuery = selectQuery.where((eb)=>{
1420
+ const conditions = or.map((expr)=>expr(eb));
1421
+ return eb.or(conditions);
1422
+ });
1423
+ const fetchedResults = await selectQuery.execute();
1424
+ if (!fetchedResults || 0 === fetchedResults.length) return [];
1425
+ return fetchedResults.map((record)=>transformOutput(record, model));
1426
+ },
1427
+ async count (data) {
1428
+ const { model, where } = data;
1429
+ const whereArray = where ? Array.isArray(where) ? where : [
1430
+ where
1431
+ ] : void 0;
1432
+ const { and, or } = convertWhereClause(model, whereArray);
1433
+ const tableName = getEntityName(model);
1434
+ let query = db.selectFrom(tableName).select((eb)=>eb.fn.count('id').as('count'));
1435
+ if (and) query = query.where((eb)=>{
1436
+ const conditions = and.map((expr)=>expr(eb));
1437
+ return eb.and(conditions);
1438
+ });
1439
+ if (or) query = query.where((eb)=>{
1440
+ const conditions = or.map((expr)=>expr(eb));
1441
+ return eb.or(conditions);
1442
+ });
1443
+ const res = await query.execute();
1444
+ const count = res[0]?.count;
1445
+ return 'number' == typeof count ? count : 0;
1446
+ },
1447
+ async delete (data) {
1448
+ const { model, where } = data;
1449
+ const whereArray = Array.isArray(where) ? where : [
1450
+ where
1451
+ ];
1452
+ const { and, or } = convertWhereClause(model, whereArray);
1453
+ const tableName = getEntityName(model);
1454
+ let query = db.deleteFrom(tableName);
1455
+ if (and) query = query.where((eb)=>{
1456
+ const conditions = and.map((expr)=>expr(eb));
1457
+ return eb.and(conditions);
1458
+ });
1459
+ if (or) query = query.where((eb)=>{
1460
+ const conditions = or.map((expr)=>expr(eb));
1461
+ return eb.or(conditions);
1462
+ });
1463
+ await query.execute();
1464
+ },
1465
+ async deleteMany (data) {
1466
+ const { model, where } = data;
1467
+ const whereArray = Array.isArray(where) ? where : [
1468
+ where
1469
+ ];
1470
+ const { and, or } = convertWhereClause(model, whereArray);
1471
+ const tableName = getEntityName(model);
1472
+ let query = db.deleteFrom(tableName);
1473
+ if (and) query = query.where((eb)=>{
1474
+ const conditions = and.map((expr)=>expr(eb));
1475
+ return eb.and(conditions);
1476
+ });
1477
+ if (or) query = query.where((eb)=>{
1478
+ const conditions = or.map((expr)=>expr(eb));
1479
+ return eb.or(conditions);
1480
+ });
1481
+ const result = await query.execute();
1482
+ const count = result.length;
1483
+ return count;
1484
+ },
1485
+ async transaction (data) {
1486
+ const { callback } = data;
1487
+ if (opts.advanced?.disableTransactions) {
1488
+ const regularAdapter = kysely_adapter_rslib_entry_kyselyAdapter(db, config)(opts);
1489
+ return await callback(regularAdapter);
1490
+ }
1491
+ try {
1492
+ return await db.transaction().execute(async (trx)=>{
1493
+ const transactionAdapter = kysely_adapter_rslib_entry_kyselyAdapter(trx, config)(opts);
1494
+ return await callback(transactionAdapter);
1495
+ });
1496
+ } catch (error) {
1497
+ if (error instanceof Error && (error.message.includes('transactions are not supported') || error.message.toLowerCase().includes('no transaction support'))) {
1498
+ console.warn("Warning: Database transaction failed. If your database does not support transactions, you can disable this warning by setting opts.advanced.disableTransactions to true.");
1499
+ const regularAdapter = kysely_adapter_rslib_entry_kyselyAdapter(db, config)(opts);
1500
+ return await callback(regularAdapter);
1501
+ }
1502
+ throw error;
1503
+ }
1504
+ },
1505
+ options: config
1506
+ };
1507
+ };
1508
+ export { kysely_adapter_rslib_entry_kyselyAdapter as kyselyAdapter };