drizzle-orm 0.38.4-b776df4 → 0.38.4-e36471e

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 (693) hide show
  1. package/_relations.cjs +328 -0
  2. package/_relations.cjs.map +1 -0
  3. package/_relations.d.cts +215 -0
  4. package/_relations.d.ts +215 -0
  5. package/_relations.js +316 -0
  6. package/_relations.js.map +1 -0
  7. package/alias.cjs.map +1 -1
  8. package/alias.d.cts +3 -3
  9. package/alias.d.ts +3 -3
  10. package/alias.js.map +1 -1
  11. package/aws-data-api/pg/driver.cjs +19 -5
  12. package/aws-data-api/pg/driver.cjs.map +1 -1
  13. package/aws-data-api/pg/driver.d.cts +9 -8
  14. package/aws-data-api/pg/driver.d.ts +9 -8
  15. package/aws-data-api/pg/driver.js +9 -8
  16. package/aws-data-api/pg/driver.js.map +1 -1
  17. package/aws-data-api/pg/migrator.cjs.map +1 -1
  18. package/aws-data-api/pg/migrator.d.cts +2 -1
  19. package/aws-data-api/pg/migrator.d.ts +2 -1
  20. package/aws-data-api/pg/migrator.js.map +1 -1
  21. package/aws-data-api/pg/session.cjs +67 -4
  22. package/aws-data-api/pg/session.cjs.map +1 -1
  23. package/aws-data-api/pg/session.d.cts +13 -8
  24. package/aws-data-api/pg/session.d.ts +13 -8
  25. package/aws-data-api/pg/session.js +67 -4
  26. package/aws-data-api/pg/session.js.map +1 -1
  27. package/better-sqlite3/driver.cjs +12 -5
  28. package/better-sqlite3/driver.cjs.map +1 -1
  29. package/better-sqlite3/driver.d.cts +7 -6
  30. package/better-sqlite3/driver.d.ts +7 -6
  31. package/better-sqlite3/driver.js +12 -8
  32. package/better-sqlite3/driver.js.map +1 -1
  33. package/better-sqlite3/migrator.cjs.map +1 -1
  34. package/better-sqlite3/migrator.d.cts +2 -1
  35. package/better-sqlite3/migrator.d.ts +2 -1
  36. package/better-sqlite3/migrator.js.map +1 -1
  37. package/better-sqlite3/session.cjs +49 -4
  38. package/better-sqlite3/session.cjs.map +1 -1
  39. package/better-sqlite3/session.d.cts +14 -8
  40. package/better-sqlite3/session.d.ts +14 -8
  41. package/better-sqlite3/session.js +49 -4
  42. package/better-sqlite3/session.js.map +1 -1
  43. package/bun-sqlite/driver.cjs +22 -5
  44. package/bun-sqlite/driver.cjs.map +1 -1
  45. package/bun-sqlite/driver.d.cts +7 -6
  46. package/bun-sqlite/driver.d.ts +7 -6
  47. package/bun-sqlite/driver.js +12 -8
  48. package/bun-sqlite/driver.js.map +1 -1
  49. package/bun-sqlite/migrator.cjs.map +1 -1
  50. package/bun-sqlite/migrator.d.cts +2 -1
  51. package/bun-sqlite/migrator.d.ts +2 -1
  52. package/bun-sqlite/migrator.js.map +1 -1
  53. package/bun-sqlite/session.cjs +49 -4
  54. package/bun-sqlite/session.cjs.map +1 -1
  55. package/bun-sqlite/session.d.cts +14 -8
  56. package/bun-sqlite/session.d.ts +14 -8
  57. package/bun-sqlite/session.js +49 -4
  58. package/bun-sqlite/session.js.map +1 -1
  59. package/d1/driver.cjs +22 -5
  60. package/d1/driver.cjs.map +1 -1
  61. package/d1/driver.d.cts +3 -2
  62. package/d1/driver.d.ts +3 -2
  63. package/d1/driver.js +12 -8
  64. package/d1/driver.js.map +1 -1
  65. package/d1/migrator.cjs.map +1 -1
  66. package/d1/migrator.d.cts +2 -1
  67. package/d1/migrator.d.ts +2 -1
  68. package/d1/migrator.js.map +1 -1
  69. package/d1/session.cjs +48 -6
  70. package/d1/session.cjs.map +1 -1
  71. package/d1/session.d.cts +15 -8
  72. package/d1/session.d.ts +15 -8
  73. package/d1/session.js +48 -6
  74. package/d1/session.js.map +1 -1
  75. package/durable-sqlite/driver.cjs +16 -5
  76. package/durable-sqlite/driver.cjs.map +1 -1
  77. package/durable-sqlite/driver.d.cts +3 -2
  78. package/durable-sqlite/driver.d.ts +3 -2
  79. package/durable-sqlite/driver.js +6 -8
  80. package/durable-sqlite/driver.js.map +1 -1
  81. package/durable-sqlite/migrator.cjs.map +1 -1
  82. package/durable-sqlite/migrator.d.cts +2 -1
  83. package/durable-sqlite/migrator.d.ts +2 -1
  84. package/durable-sqlite/migrator.js.map +1 -1
  85. package/durable-sqlite/session.cjs +46 -4
  86. package/durable-sqlite/session.cjs.map +1 -1
  87. package/durable-sqlite/session.d.cts +14 -8
  88. package/durable-sqlite/session.d.ts +14 -8
  89. package/durable-sqlite/session.js +46 -4
  90. package/durable-sqlite/session.js.map +1 -1
  91. package/expo-sqlite/driver.cjs +22 -5
  92. package/expo-sqlite/driver.cjs.map +1 -1
  93. package/expo-sqlite/driver.d.cts +3 -2
  94. package/expo-sqlite/driver.d.ts +3 -2
  95. package/expo-sqlite/driver.js +12 -8
  96. package/expo-sqlite/driver.js.map +1 -1
  97. package/expo-sqlite/migrator.cjs.map +1 -1
  98. package/expo-sqlite/migrator.d.cts +3 -2
  99. package/expo-sqlite/migrator.d.ts +3 -2
  100. package/expo-sqlite/migrator.js.map +1 -1
  101. package/expo-sqlite/query.cjs +13 -2
  102. package/expo-sqlite/query.cjs.map +1 -1
  103. package/expo-sqlite/query.d.cts +2 -1
  104. package/expo-sqlite/query.d.ts +2 -1
  105. package/expo-sqlite/query.js +3 -2
  106. package/expo-sqlite/query.js.map +1 -1
  107. package/expo-sqlite/session.cjs +47 -4
  108. package/expo-sqlite/session.cjs.map +1 -1
  109. package/expo-sqlite/session.d.cts +14 -8
  110. package/expo-sqlite/session.d.ts +14 -8
  111. package/expo-sqlite/session.js +47 -4
  112. package/expo-sqlite/session.js.map +1 -1
  113. package/libsql/driver-core.cjs +22 -5
  114. package/libsql/driver-core.cjs.map +1 -1
  115. package/libsql/driver-core.d.cts +2 -1
  116. package/libsql/driver-core.d.ts +2 -1
  117. package/libsql/driver-core.js +12 -8
  118. package/libsql/driver-core.js.map +1 -1
  119. package/libsql/driver.cjs.map +1 -1
  120. package/libsql/driver.d.cts +6 -5
  121. package/libsql/driver.d.ts +6 -5
  122. package/libsql/driver.js.map +1 -1
  123. package/libsql/http/index.cjs.map +1 -1
  124. package/libsql/http/index.d.cts +6 -5
  125. package/libsql/http/index.d.ts +6 -5
  126. package/libsql/http/index.js.map +1 -1
  127. package/libsql/migrator.cjs.map +1 -1
  128. package/libsql/migrator.d.cts +2 -1
  129. package/libsql/migrator.d.ts +2 -1
  130. package/libsql/migrator.js.map +1 -1
  131. package/libsql/node/index.cjs.map +1 -1
  132. package/libsql/node/index.d.cts +6 -5
  133. package/libsql/node/index.d.ts +6 -5
  134. package/libsql/node/index.js.map +1 -1
  135. package/libsql/session.cjs +56 -4
  136. package/libsql/session.cjs.map +1 -1
  137. package/libsql/session.d.cts +15 -9
  138. package/libsql/session.d.ts +15 -9
  139. package/libsql/session.js +56 -4
  140. package/libsql/session.js.map +1 -1
  141. package/libsql/sqlite3/index.cjs.map +1 -1
  142. package/libsql/sqlite3/index.d.cts +6 -5
  143. package/libsql/sqlite3/index.d.ts +6 -5
  144. package/libsql/sqlite3/index.js.map +1 -1
  145. package/libsql/wasm/index.cjs.map +1 -1
  146. package/libsql/wasm/index.d.cts +6 -5
  147. package/libsql/wasm/index.d.ts +6 -5
  148. package/libsql/wasm/index.js.map +1 -1
  149. package/libsql/web/index.cjs.map +1 -1
  150. package/libsql/web/index.d.cts +6 -5
  151. package/libsql/web/index.d.ts +6 -5
  152. package/libsql/web/index.js.map +1 -1
  153. package/libsql/ws/index.cjs.map +1 -1
  154. package/libsql/ws/index.d.cts +6 -5
  155. package/libsql/ws/index.d.ts +6 -5
  156. package/libsql/ws/index.js.map +1 -1
  157. package/mysql-core/db.cjs +40 -25
  158. package/mysql-core/db.cjs.map +1 -1
  159. package/mysql-core/db.d.cts +22 -12
  160. package/mysql-core/db.d.ts +22 -12
  161. package/mysql-core/db.js +39 -24
  162. package/mysql-core/db.js.map +1 -1
  163. package/mysql-core/dialect.cjs +194 -15
  164. package/mysql-core/dialect.cjs.map +1 -1
  165. package/mysql-core/dialect.d.cts +33 -13
  166. package/mysql-core/dialect.d.ts +33 -13
  167. package/mysql-core/dialect.js +191 -21
  168. package/mysql-core/dialect.js.map +1 -1
  169. package/mysql-core/query-builders/_query.cjs +149 -0
  170. package/mysql-core/query-builders/_query.cjs.map +1 -0
  171. package/mysql-core/query-builders/_query.d.cts +44 -0
  172. package/mysql-core/query-builders/_query.d.ts +44 -0
  173. package/mysql-core/query-builders/_query.js +114 -0
  174. package/mysql-core/query-builders/_query.js.map +1 -0
  175. package/mysql-core/query-builders/count.cjs.map +1 -1
  176. package/mysql-core/query-builders/count.d.cts +1 -1
  177. package/mysql-core/query-builders/count.d.ts +1 -1
  178. package/mysql-core/query-builders/count.js.map +1 -1
  179. package/mysql-core/query-builders/query-builder.cjs +11 -15
  180. package/mysql-core/query-builders/query-builder.cjs.map +1 -1
  181. package/mysql-core/query-builders/query-builder.d.cts +6 -2
  182. package/mysql-core/query-builders/query-builder.d.ts +6 -2
  183. package/mysql-core/query-builders/query-builder.js +11 -15
  184. package/mysql-core/query-builders/query-builder.js.map +1 -1
  185. package/mysql-core/query-builders/query.cjs +18 -31
  186. package/mysql-core/query-builders/query.cjs.map +1 -1
  187. package/mysql-core/query-builders/query.d.cts +8 -10
  188. package/mysql-core/query-builders/query.d.ts +8 -10
  189. package/mysql-core/query-builders/query.js +18 -31
  190. package/mysql-core/query-builders/query.js.map +1 -1
  191. package/mysql-core/session.cjs +3 -2
  192. package/mysql-core/session.cjs.map +1 -1
  193. package/mysql-core/session.d.cts +10 -7
  194. package/mysql-core/session.d.ts +10 -7
  195. package/mysql-core/session.js +3 -2
  196. package/mysql-core/session.js.map +1 -1
  197. package/mysql-core/subquery.cjs.map +1 -1
  198. package/mysql-core/subquery.d.cts +2 -15
  199. package/mysql-core/subquery.d.ts +2 -15
  200. package/mysql-proxy/driver.cjs +22 -5
  201. package/mysql-proxy/driver.cjs.map +1 -1
  202. package/mysql-proxy/driver.d.cts +3 -2
  203. package/mysql-proxy/driver.d.ts +3 -2
  204. package/mysql-proxy/driver.js +12 -8
  205. package/mysql-proxy/driver.js.map +1 -1
  206. package/mysql-proxy/migrator.cjs.map +1 -1
  207. package/mysql-proxy/migrator.d.cts +2 -1
  208. package/mysql-proxy/migrator.d.ts +2 -1
  209. package/mysql-proxy/migrator.js.map +1 -1
  210. package/mysql-proxy/session.cjs +27 -2
  211. package/mysql-proxy/session.cjs.map +1 -1
  212. package/mysql-proxy/session.d.cts +13 -8
  213. package/mysql-proxy/session.d.ts +13 -8
  214. package/mysql-proxy/session.js +27 -2
  215. package/mysql-proxy/session.js.map +1 -1
  216. package/mysql2/driver.cjs +24 -7
  217. package/mysql2/driver.cjs.map +1 -1
  218. package/mysql2/driver.d.cts +10 -9
  219. package/mysql2/driver.d.ts +10 -9
  220. package/mysql2/driver.js +14 -10
  221. package/mysql2/driver.js.map +1 -1
  222. package/mysql2/migrator.cjs.map +1 -1
  223. package/mysql2/migrator.d.cts +2 -1
  224. package/mysql2/migrator.d.ts +2 -1
  225. package/mysql2/migrator.js.map +1 -1
  226. package/mysql2/session.cjs +30 -2
  227. package/mysql2/session.cjs.map +1 -1
  228. package/mysql2/session.d.cts +13 -8
  229. package/mysql2/session.d.ts +13 -8
  230. package/mysql2/session.js +30 -2
  231. package/mysql2/session.js.map +1 -1
  232. package/neon/index.cjs +0 -2
  233. package/neon/index.cjs.map +1 -1
  234. package/neon/index.d.cts +0 -1
  235. package/neon/index.d.ts +0 -1
  236. package/neon/index.js +0 -1
  237. package/neon/index.js.map +1 -1
  238. package/neon-http/driver.cjs +21 -7
  239. package/neon-http/driver.cjs.map +1 -1
  240. package/neon-http/driver.d.cts +10 -9
  241. package/neon-http/driver.d.ts +10 -9
  242. package/neon-http/driver.js +11 -7
  243. package/neon-http/driver.js.map +1 -1
  244. package/neon-http/migrator.cjs.map +1 -1
  245. package/neon-http/migrator.d.cts +2 -1
  246. package/neon-http/migrator.d.ts +2 -1
  247. package/neon-http/migrator.js.map +1 -1
  248. package/neon-http/session.cjs +32 -2
  249. package/neon-http/session.cjs.map +1 -1
  250. package/neon-http/session.d.cts +13 -8
  251. package/neon-http/session.d.ts +13 -8
  252. package/neon-http/session.js +32 -2
  253. package/neon-http/session.js.map +1 -1
  254. package/neon-serverless/driver.cjs +18 -7
  255. package/neon-serverless/driver.cjs.map +1 -1
  256. package/neon-serverless/driver.d.cts +9 -8
  257. package/neon-serverless/driver.d.ts +9 -8
  258. package/neon-serverless/driver.js +8 -10
  259. package/neon-serverless/driver.js.map +1 -1
  260. package/neon-serverless/migrator.cjs.map +1 -1
  261. package/neon-serverless/migrator.d.cts +2 -1
  262. package/neon-serverless/migrator.d.ts +2 -1
  263. package/neon-serverless/migrator.js.map +1 -1
  264. package/neon-serverless/session.cjs +40 -5
  265. package/neon-serverless/session.cjs.map +1 -1
  266. package/neon-serverless/session.d.cts +13 -8
  267. package/neon-serverless/session.d.ts +13 -8
  268. package/neon-serverless/session.js +40 -5
  269. package/neon-serverless/session.js.map +1 -1
  270. package/node-postgres/driver.cjs +13 -7
  271. package/node-postgres/driver.cjs.map +1 -1
  272. package/node-postgres/driver.d.cts +9 -8
  273. package/node-postgres/driver.d.ts +9 -8
  274. package/node-postgres/driver.js +13 -10
  275. package/node-postgres/driver.js.map +1 -1
  276. package/node-postgres/migrator.cjs.map +1 -1
  277. package/node-postgres/migrator.d.cts +2 -1
  278. package/node-postgres/migrator.d.ts +2 -1
  279. package/node-postgres/migrator.js.map +1 -1
  280. package/node-postgres/session.cjs +45 -4
  281. package/node-postgres/session.cjs.map +1 -1
  282. package/node-postgres/session.d.cts +13 -8
  283. package/node-postgres/session.d.ts +13 -8
  284. package/node-postgres/session.js +45 -4
  285. package/node-postgres/session.js.map +1 -1
  286. package/op-sqlite/driver.cjs +22 -5
  287. package/op-sqlite/driver.cjs.map +1 -1
  288. package/op-sqlite/driver.d.cts +3 -2
  289. package/op-sqlite/driver.d.ts +3 -2
  290. package/op-sqlite/driver.js +12 -8
  291. package/op-sqlite/driver.js.map +1 -1
  292. package/op-sqlite/migrator.cjs.map +1 -1
  293. package/op-sqlite/migrator.d.cts +3 -2
  294. package/op-sqlite/migrator.d.ts +3 -2
  295. package/op-sqlite/migrator.js.map +1 -1
  296. package/op-sqlite/session.cjs +47 -4
  297. package/op-sqlite/session.cjs.map +1 -1
  298. package/op-sqlite/session.d.cts +14 -8
  299. package/op-sqlite/session.d.ts +14 -8
  300. package/op-sqlite/session.js +47 -4
  301. package/op-sqlite/session.js.map +1 -1
  302. package/package.json +51 -15
  303. package/pg-core/db.cjs +42 -24
  304. package/pg-core/db.cjs.map +1 -1
  305. package/pg-core/db.d.cts +23 -13
  306. package/pg-core/db.d.ts +23 -13
  307. package/pg-core/db.js +41 -23
  308. package/pg-core/db.js.map +1 -1
  309. package/pg-core/dialect.cjs +161 -488
  310. package/pg-core/dialect.cjs.map +1 -1
  311. package/pg-core/dialect.d.cts +24 -7
  312. package/pg-core/dialect.d.ts +24 -7
  313. package/pg-core/dialect.js +158 -494
  314. package/pg-core/dialect.js.map +1 -1
  315. package/pg-core/query-builders/_query.cjs +155 -0
  316. package/pg-core/query-builders/_query.cjs.map +1 -0
  317. package/pg-core/query-builders/_query.d.cts +47 -0
  318. package/pg-core/query-builders/_query.d.ts +47 -0
  319. package/pg-core/query-builders/_query.js +120 -0
  320. package/pg-core/query-builders/_query.js.map +1 -0
  321. package/pg-core/query-builders/count.cjs.map +1 -1
  322. package/pg-core/query-builders/count.d.cts +1 -1
  323. package/pg-core/query-builders/count.d.ts +1 -1
  324. package/pg-core/query-builders/count.js.map +1 -1
  325. package/pg-core/query-builders/delete.cjs +0 -13
  326. package/pg-core/query-builders/delete.cjs.map +1 -1
  327. package/pg-core/query-builders/delete.d.cts +10 -13
  328. package/pg-core/query-builders/delete.d.ts +10 -13
  329. package/pg-core/query-builders/delete.js +1 -14
  330. package/pg-core/query-builders/delete.js.map +1 -1
  331. package/pg-core/query-builders/insert.cjs +0 -13
  332. package/pg-core/query-builders/insert.cjs.map +1 -1
  333. package/pg-core/query-builders/insert.d.cts +8 -10
  334. package/pg-core/query-builders/insert.d.ts +8 -10
  335. package/pg-core/query-builders/insert.js +1 -14
  336. package/pg-core/query-builders/insert.js.map +1 -1
  337. package/pg-core/query-builders/query-builder.cjs +11 -15
  338. package/pg-core/query-builders/query-builder.cjs.map +1 -1
  339. package/pg-core/query-builders/query-builder.d.cts +6 -3
  340. package/pg-core/query-builders/query-builder.d.ts +6 -3
  341. package/pg-core/query-builders/query-builder.js +11 -15
  342. package/pg-core/query-builders/query-builder.js.map +1 -1
  343. package/pg-core/query-builders/query.cjs +15 -18
  344. package/pg-core/query-builders/query.cjs.map +1 -1
  345. package/pg-core/query-builders/query.d.cts +6 -6
  346. package/pg-core/query-builders/query.d.ts +6 -6
  347. package/pg-core/query-builders/query.js +15 -18
  348. package/pg-core/query-builders/query.js.map +1 -1
  349. package/pg-core/query-builders/select.cjs +7 -8
  350. package/pg-core/query-builders/select.cjs.map +1 -1
  351. package/pg-core/query-builders/select.d.cts +3 -3
  352. package/pg-core/query-builders/select.d.ts +3 -3
  353. package/pg-core/query-builders/select.js +7 -8
  354. package/pg-core/query-builders/select.js.map +1 -1
  355. package/pg-core/query-builders/select.types.cjs.map +1 -1
  356. package/pg-core/query-builders/select.types.d.cts +2 -3
  357. package/pg-core/query-builders/select.types.d.ts +2 -3
  358. package/pg-core/query-builders/update.cjs +2 -15
  359. package/pg-core/query-builders/update.cjs.map +1 -1
  360. package/pg-core/query-builders/update.d.cts +13 -18
  361. package/pg-core/query-builders/update.d.ts +13 -18
  362. package/pg-core/query-builders/update.js +3 -16
  363. package/pg-core/query-builders/update.js.map +1 -1
  364. package/pg-core/session.cjs +3 -2
  365. package/pg-core/session.cjs.map +1 -1
  366. package/pg-core/session.d.cts +9 -6
  367. package/pg-core/session.d.ts +9 -6
  368. package/pg-core/session.js +3 -2
  369. package/pg-core/session.js.map +1 -1
  370. package/pg-core/subquery.cjs.map +1 -1
  371. package/pg-core/subquery.d.cts +2 -15
  372. package/pg-core/subquery.d.ts +2 -15
  373. package/pg-proxy/driver.cjs +21 -5
  374. package/pg-proxy/driver.cjs.map +1 -1
  375. package/pg-proxy/driver.d.cts +3 -2
  376. package/pg-proxy/driver.d.ts +3 -2
  377. package/pg-proxy/driver.js +11 -8
  378. package/pg-proxy/driver.js.map +1 -1
  379. package/pg-proxy/migrator.cjs.map +1 -1
  380. package/pg-proxy/migrator.d.cts +2 -1
  381. package/pg-proxy/migrator.d.ts +2 -1
  382. package/pg-proxy/migrator.js.map +1 -1
  383. package/pg-proxy/session.cjs +37 -2
  384. package/pg-proxy/session.cjs.map +1 -1
  385. package/pg-proxy/session.d.cts +13 -8
  386. package/pg-proxy/session.d.ts +13 -8
  387. package/pg-proxy/session.js +37 -2
  388. package/pg-proxy/session.js.map +1 -1
  389. package/pglite/driver.cjs +23 -7
  390. package/pglite/driver.cjs.map +1 -1
  391. package/pglite/driver.d.cts +9 -8
  392. package/pglite/driver.d.ts +9 -8
  393. package/pglite/driver.js +13 -10
  394. package/pglite/driver.js.map +1 -1
  395. package/pglite/migrator.cjs.map +1 -1
  396. package/pglite/migrator.d.cts +2 -1
  397. package/pglite/migrator.d.ts +2 -1
  398. package/pglite/migrator.js.map +1 -1
  399. package/pglite/session.cjs +34 -3
  400. package/pglite/session.cjs.map +1 -1
  401. package/pglite/session.d.cts +13 -8
  402. package/pglite/session.d.ts +13 -8
  403. package/pglite/session.js +34 -3
  404. package/pglite/session.js.map +1 -1
  405. package/planetscale-serverless/driver.cjs +22 -5
  406. package/planetscale-serverless/driver.cjs.map +1 -1
  407. package/planetscale-serverless/driver.d.cts +7 -6
  408. package/planetscale-serverless/driver.d.ts +7 -6
  409. package/planetscale-serverless/driver.js +12 -8
  410. package/planetscale-serverless/driver.js.map +1 -1
  411. package/planetscale-serverless/migrator.cjs.map +1 -1
  412. package/planetscale-serverless/migrator.d.cts +2 -1
  413. package/planetscale-serverless/migrator.d.ts +2 -1
  414. package/planetscale-serverless/migrator.js.map +1 -1
  415. package/planetscale-serverless/session.cjs +45 -5
  416. package/planetscale-serverless/session.cjs.map +1 -1
  417. package/planetscale-serverless/session.d.cts +14 -9
  418. package/planetscale-serverless/session.d.ts +14 -9
  419. package/planetscale-serverless/session.js +45 -5
  420. package/planetscale-serverless/session.js.map +1 -1
  421. package/postgres-js/driver.cjs +6 -5
  422. package/postgres-js/driver.cjs.map +1 -1
  423. package/postgres-js/driver.d.cts +7 -6
  424. package/postgres-js/driver.d.ts +7 -6
  425. package/postgres-js/driver.js +6 -8
  426. package/postgres-js/driver.js.map +1 -1
  427. package/postgres-js/migrator.cjs.map +1 -1
  428. package/postgres-js/migrator.d.cts +2 -1
  429. package/postgres-js/migrator.d.ts +2 -1
  430. package/postgres-js/migrator.js.map +1 -1
  431. package/postgres-js/session.cjs +51 -6
  432. package/postgres-js/session.cjs.map +1 -1
  433. package/postgres-js/session.d.cts +15 -9
  434. package/postgres-js/session.d.ts +15 -9
  435. package/postgres-js/session.js +51 -6
  436. package/postgres-js/session.js.map +1 -1
  437. package/prisma/mysql/driver.cjs +1 -1
  438. package/prisma/mysql/driver.cjs.map +1 -1
  439. package/prisma/mysql/driver.js +1 -1
  440. package/prisma/mysql/driver.js.map +1 -1
  441. package/prisma/mysql/session.cjs +3 -0
  442. package/prisma/mysql/session.cjs.map +1 -1
  443. package/prisma/mysql/session.d.cts +3 -1
  444. package/prisma/mysql/session.d.ts +3 -1
  445. package/prisma/mysql/session.js +3 -0
  446. package/prisma/mysql/session.js.map +1 -1
  447. package/prisma/pg/driver.cjs +1 -1
  448. package/prisma/pg/driver.cjs.map +1 -1
  449. package/prisma/pg/driver.js +1 -1
  450. package/prisma/pg/driver.js.map +1 -1
  451. package/prisma/pg/session.cjs +3 -0
  452. package/prisma/pg/session.cjs.map +1 -1
  453. package/prisma/pg/session.d.cts +3 -1
  454. package/prisma/pg/session.d.ts +3 -1
  455. package/prisma/pg/session.js +3 -0
  456. package/prisma/pg/session.js.map +1 -1
  457. package/prisma/sqlite/driver.cjs +1 -1
  458. package/prisma/sqlite/driver.cjs.map +1 -1
  459. package/prisma/sqlite/driver.js +1 -1
  460. package/prisma/sqlite/driver.js.map +1 -1
  461. package/prisma/sqlite/session.cjs +3 -0
  462. package/prisma/sqlite/session.cjs.map +1 -1
  463. package/prisma/sqlite/session.d.cts +4 -2
  464. package/prisma/sqlite/session.d.ts +4 -2
  465. package/prisma/sqlite/session.js +3 -0
  466. package/prisma/sqlite/session.js.map +1 -1
  467. package/query-builders/select.types.cjs.map +1 -1
  468. package/query-builders/select.types.d.cts +1 -1
  469. package/query-builders/select.types.d.ts +1 -1
  470. package/relations.cjs +595 -245
  471. package/relations.cjs.map +1 -1
  472. package/relations.d.cts +276 -131
  473. package/relations.d.ts +276 -131
  474. package/relations.js +589 -239
  475. package/relations.js.map +1 -1
  476. package/singlestore/driver.cjs +1 -1
  477. package/singlestore/driver.cjs.map +1 -1
  478. package/singlestore/driver.d.cts +1 -1
  479. package/singlestore/driver.d.ts +1 -1
  480. package/singlestore/driver.js +3 -3
  481. package/singlestore/driver.js.map +1 -1
  482. package/singlestore/session.cjs.map +1 -1
  483. package/singlestore/session.d.cts +4 -4
  484. package/singlestore/session.d.ts +4 -4
  485. package/singlestore/session.js.map +1 -1
  486. package/singlestore-core/db.cjs +11 -17
  487. package/singlestore-core/db.cjs.map +1 -1
  488. package/singlestore-core/db.d.cts +10 -7
  489. package/singlestore-core/db.d.ts +10 -7
  490. package/singlestore-core/db.js +11 -17
  491. package/singlestore-core/db.js.map +1 -1
  492. package/singlestore-core/dialect.cjs +16 -6
  493. package/singlestore-core/dialect.cjs.map +1 -1
  494. package/singlestore-core/dialect.d.cts +6 -6
  495. package/singlestore-core/dialect.d.ts +6 -6
  496. package/singlestore-core/dialect.js +6 -12
  497. package/singlestore-core/dialect.js.map +1 -1
  498. package/singlestore-core/query-builders/query-builder.cjs +11 -15
  499. package/singlestore-core/query-builders/query-builder.cjs.map +1 -1
  500. package/singlestore-core/query-builders/query-builder.d.cts +6 -2
  501. package/singlestore-core/query-builders/query-builder.d.ts +6 -2
  502. package/singlestore-core/query-builders/query-builder.js +11 -15
  503. package/singlestore-core/query-builders/query-builder.js.map +1 -1
  504. package/singlestore-core/query-builders/query.cjs +12 -2
  505. package/singlestore-core/query-builders/query.cjs.map +1 -1
  506. package/singlestore-core/query-builders/query.d.cts +6 -6
  507. package/singlestore-core/query-builders/query.d.ts +6 -6
  508. package/singlestore-core/query-builders/query.js +2 -4
  509. package/singlestore-core/query-builders/query.js.map +1 -1
  510. package/singlestore-core/session.cjs.map +1 -1
  511. package/singlestore-core/session.d.cts +5 -5
  512. package/singlestore-core/session.d.ts +5 -5
  513. package/singlestore-core/session.js.map +1 -1
  514. package/singlestore-core/subquery.cjs.map +1 -1
  515. package/singlestore-core/subquery.d.cts +2 -15
  516. package/singlestore-core/subquery.d.ts +2 -15
  517. package/singlestore-proxy/driver.cjs +1 -1
  518. package/singlestore-proxy/driver.cjs.map +1 -1
  519. package/singlestore-proxy/driver.js +3 -3
  520. package/singlestore-proxy/driver.js.map +1 -1
  521. package/singlestore-proxy/session.cjs.map +1 -1
  522. package/singlestore-proxy/session.d.cts +4 -4
  523. package/singlestore-proxy/session.d.ts +4 -4
  524. package/singlestore-proxy/session.js.map +1 -1
  525. package/sql/sql.cjs +1 -6
  526. package/sql/sql.cjs.map +1 -1
  527. package/sql/sql.d.cts +8 -9
  528. package/sql/sql.d.ts +8 -9
  529. package/sql/sql.js +1 -5
  530. package/sql/sql.js.map +1 -1
  531. package/sql-js/driver.cjs +16 -5
  532. package/sql-js/driver.cjs.map +1 -1
  533. package/sql-js/driver.d.cts +3 -2
  534. package/sql-js/driver.d.ts +3 -2
  535. package/sql-js/driver.js +6 -8
  536. package/sql-js/driver.js.map +1 -1
  537. package/sql-js/migrator.cjs.map +1 -1
  538. package/sql-js/migrator.d.cts +2 -1
  539. package/sql-js/migrator.d.ts +2 -1
  540. package/sql-js/migrator.js.map +1 -1
  541. package/sql-js/session.cjs +76 -4
  542. package/sql-js/session.cjs.map +1 -1
  543. package/sql-js/session.d.cts +15 -8
  544. package/sql-js/session.d.ts +15 -8
  545. package/sql-js/session.js +76 -4
  546. package/sql-js/session.js.map +1 -1
  547. package/sqlite-core/db.cjs +49 -31
  548. package/sqlite-core/db.cjs.map +1 -1
  549. package/sqlite-core/db.d.cts +23 -12
  550. package/sqlite-core/db.d.ts +23 -12
  551. package/sqlite-core/db.js +48 -30
  552. package/sqlite-core/db.js.map +1 -1
  553. package/sqlite-core/dialect.cjs +183 -7
  554. package/sqlite-core/dialect.cjs.map +1 -1
  555. package/sqlite-core/dialect.d.cts +28 -9
  556. package/sqlite-core/dialect.d.ts +28 -9
  557. package/sqlite-core/dialect.js +180 -13
  558. package/sqlite-core/dialect.js.map +1 -1
  559. package/sqlite-core/query-builders/_query.cjs +187 -0
  560. package/sqlite-core/query-builders/_query.cjs.map +1 -0
  561. package/sqlite-core/query-builders/_query.d.cts +55 -0
  562. package/sqlite-core/query-builders/_query.d.ts +55 -0
  563. package/sqlite-core/query-builders/_query.js +151 -0
  564. package/sqlite-core/query-builders/_query.js.map +1 -0
  565. package/sqlite-core/query-builders/count.cjs.map +1 -1
  566. package/sqlite-core/query-builders/count.d.cts +1 -1
  567. package/sqlite-core/query-builders/count.d.ts +1 -1
  568. package/sqlite-core/query-builders/count.js.map +1 -1
  569. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  570. package/sqlite-core/query-builders/delete.d.cts +1 -1
  571. package/sqlite-core/query-builders/delete.d.ts +1 -1
  572. package/sqlite-core/query-builders/delete.js.map +1 -1
  573. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  574. package/sqlite-core/query-builders/insert.d.cts +3 -3
  575. package/sqlite-core/query-builders/insert.d.ts +3 -3
  576. package/sqlite-core/query-builders/insert.js.map +1 -1
  577. package/sqlite-core/query-builders/query-builder.cjs +11 -15
  578. package/sqlite-core/query-builders/query-builder.cjs.map +1 -1
  579. package/sqlite-core/query-builders/query-builder.d.cts +6 -2
  580. package/sqlite-core/query-builders/query-builder.d.ts +6 -2
  581. package/sqlite-core/query-builders/query-builder.js +11 -15
  582. package/sqlite-core/query-builders/query-builder.js.map +1 -1
  583. package/sqlite-core/query-builders/query.cjs +53 -32
  584. package/sqlite-core/query-builders/query.cjs.map +1 -1
  585. package/sqlite-core/query-builders/query.d.cts +18 -17
  586. package/sqlite-core/query-builders/query.d.ts +18 -17
  587. package/sqlite-core/query-builders/query.js +53 -32
  588. package/sqlite-core/query-builders/query.js.map +1 -1
  589. package/sqlite-core/query-builders/select.cjs.map +1 -1
  590. package/sqlite-core/query-builders/select.d.cts +3 -3
  591. package/sqlite-core/query-builders/select.d.ts +3 -3
  592. package/sqlite-core/query-builders/select.js.map +1 -1
  593. package/sqlite-core/query-builders/update.cjs.map +1 -1
  594. package/sqlite-core/query-builders/update.d.cts +3 -3
  595. package/sqlite-core/query-builders/update.d.ts +3 -3
  596. package/sqlite-core/query-builders/update.js.map +1 -1
  597. package/sqlite-core/session.cjs +6 -2
  598. package/sqlite-core/session.cjs.map +1 -1
  599. package/sqlite-core/session.d.cts +15 -7
  600. package/sqlite-core/session.d.ts +15 -7
  601. package/sqlite-core/session.js +6 -2
  602. package/sqlite-core/session.js.map +1 -1
  603. package/sqlite-core/subquery.cjs.map +1 -1
  604. package/sqlite-core/subquery.d.cts +2 -15
  605. package/sqlite-core/subquery.d.ts +2 -15
  606. package/sqlite-proxy/driver.cjs +23 -5
  607. package/sqlite-proxy/driver.cjs.map +1 -1
  608. package/sqlite-proxy/driver.d.cts +4 -3
  609. package/sqlite-proxy/driver.d.ts +4 -3
  610. package/sqlite-proxy/driver.js +13 -5
  611. package/sqlite-proxy/driver.js.map +1 -1
  612. package/sqlite-proxy/migrator.cjs.map +1 -1
  613. package/sqlite-proxy/migrator.d.cts +2 -1
  614. package/sqlite-proxy/migrator.d.ts +2 -1
  615. package/sqlite-proxy/migrator.js.map +1 -1
  616. package/sqlite-proxy/session.cjs +50 -6
  617. package/sqlite-proxy/session.cjs.map +1 -1
  618. package/sqlite-proxy/session.d.cts +14 -8
  619. package/sqlite-proxy/session.d.ts +14 -8
  620. package/sqlite-proxy/session.js +50 -6
  621. package/sqlite-proxy/session.js.map +1 -1
  622. package/subquery.cjs.map +1 -1
  623. package/subquery.d.cts +0 -1
  624. package/subquery.d.ts +0 -1
  625. package/subquery.js.map +1 -1
  626. package/table.cjs.map +1 -1
  627. package/table.d.cts +1 -1
  628. package/table.d.ts +1 -1
  629. package/table.js.map +1 -1
  630. package/tidb-serverless/driver.cjs +22 -5
  631. package/tidb-serverless/driver.cjs.map +1 -1
  632. package/tidb-serverless/driver.d.cts +7 -6
  633. package/tidb-serverless/driver.d.ts +7 -6
  634. package/tidb-serverless/driver.js +12 -8
  635. package/tidb-serverless/driver.js.map +1 -1
  636. package/tidb-serverless/migrator.cjs.map +1 -1
  637. package/tidb-serverless/migrator.d.cts +2 -1
  638. package/tidb-serverless/migrator.d.ts +2 -1
  639. package/tidb-serverless/migrator.js.map +1 -1
  640. package/tidb-serverless/session.cjs +62 -5
  641. package/tidb-serverless/session.cjs.map +1 -1
  642. package/tidb-serverless/session.d.cts +14 -9
  643. package/tidb-serverless/session.d.ts +14 -9
  644. package/tidb-serverless/session.js +62 -5
  645. package/tidb-serverless/session.js.map +1 -1
  646. package/utils.cjs +2 -2
  647. package/utils.cjs.map +1 -1
  648. package/utils.d.cts +3 -1
  649. package/utils.d.ts +3 -1
  650. package/utils.js +2 -2
  651. package/utils.js.map +1 -1
  652. package/vercel-postgres/driver.cjs +23 -7
  653. package/vercel-postgres/driver.cjs.map +1 -1
  654. package/vercel-postgres/driver.d.cts +9 -8
  655. package/vercel-postgres/driver.d.ts +9 -8
  656. package/vercel-postgres/driver.js +13 -10
  657. package/vercel-postgres/driver.js.map +1 -1
  658. package/vercel-postgres/migrator.cjs.map +1 -1
  659. package/vercel-postgres/migrator.d.cts +2 -1
  660. package/vercel-postgres/migrator.d.ts +2 -1
  661. package/vercel-postgres/migrator.js.map +1 -1
  662. package/vercel-postgres/session.cjs +34 -8
  663. package/vercel-postgres/session.cjs.map +1 -1
  664. package/vercel-postgres/session.d.cts +14 -10
  665. package/vercel-postgres/session.d.ts +14 -10
  666. package/vercel-postgres/session.js +34 -8
  667. package/vercel-postgres/session.js.map +1 -1
  668. package/version.cjs +1 -1
  669. package/version.d.cts +1 -1
  670. package/version.d.ts +1 -1
  671. package/version.js +1 -1
  672. package/xata-http/driver.cjs +17 -5
  673. package/xata-http/driver.cjs.map +1 -1
  674. package/xata-http/driver.d.cts +5 -4
  675. package/xata-http/driver.d.ts +5 -4
  676. package/xata-http/driver.js +7 -5
  677. package/xata-http/driver.js.map +1 -1
  678. package/xata-http/migrator.cjs.map +1 -1
  679. package/xata-http/migrator.d.cts +2 -1
  680. package/xata-http/migrator.d.ts +2 -1
  681. package/xata-http/migrator.js.map +1 -1
  682. package/xata-http/session.cjs +30 -2
  683. package/xata-http/session.cjs.map +1 -1
  684. package/xata-http/session.d.cts +13 -8
  685. package/xata-http/session.d.ts +13 -8
  686. package/xata-http/session.js +30 -2
  687. package/xata-http/session.js.map +1 -1
  688. package/neon/neon-identity.cjs +0 -38
  689. package/neon/neon-identity.cjs.map +0 -1
  690. package/neon/neon-identity.d.cts +0 -116
  691. package/neon/neon-identity.d.ts +0 -116
  692. package/neon/neon-identity.js +0 -14
  693. package/neon/neon-identity.js.map +0 -1
package/relations.js CHANGED
@@ -1,4 +1,11 @@
1
- import { getTableUniqueName, Table } from "./table.js";
1
+ import {
2
+ getTableUniqueName,
3
+ IsAlias,
4
+ OriginalName,
5
+ Schema,
6
+ Table
7
+ } from "./table.js";
8
+ import { Columns, getTableName } from "./table.js";
2
9
  import { Column } from "./column.js";
3
10
  import { entityKind, is } from "./entity.js";
4
11
  import { PrimaryKeyBuilder } from "./pg-core/primary-keys.js";
@@ -28,289 +35,632 @@ import {
28
35
  or
29
36
  } from "./sql/expressions/index.js";
30
37
  import { SQL, sql } from "./sql/sql.js";
31
- class Relation {
32
- constructor(sourceTable, referencedTable, relationName) {
33
- this.sourceTable = sourceTable;
34
- this.referencedTable = referencedTable;
35
- this.relationName = relationName;
36
- this.referencedTableName = referencedTable[Table.Symbol.Name];
37
- }
38
- static [entityKind] = "Relation";
39
- referencedTableName;
40
- fieldName;
41
- }
38
+ import { getTableColumns } from "./utils.js";
42
39
  class Relations {
43
- constructor(table, config) {
44
- this.table = table;
40
+ constructor(schema, tables, config) {
41
+ this.schema = schema;
42
+ this.tables = tables;
45
43
  this.config = config;
46
- }
47
- static [entityKind] = "Relations";
48
- }
49
- class One extends Relation {
50
- constructor(sourceTable, referencedTable, config, isNullable) {
51
- super(sourceTable, referencedTable, config?.relationName);
52
- this.config = config;
53
- this.isNullable = isNullable;
54
- }
55
- static [entityKind] = "One";
56
- withFieldName(fieldName) {
57
- const relation = new One(
58
- this.sourceTable,
59
- this.referencedTable,
60
- this.config,
61
- this.isNullable
62
- );
63
- relation.fieldName = fieldName;
64
- return relation;
65
- }
66
- }
67
- class Many extends Relation {
68
- constructor(sourceTable, referencedTable, config) {
69
- super(sourceTable, referencedTable, config?.relationName);
70
- this.config = config;
71
- }
72
- static [entityKind] = "Many";
73
- withFieldName(fieldName) {
74
- const relation = new Many(
75
- this.sourceTable,
76
- this.referencedTable,
77
- this.config
78
- );
79
- relation.fieldName = fieldName;
80
- return relation;
81
- }
82
- }
83
- function getOperators() {
84
- return {
85
- and,
86
- between,
87
- eq,
88
- exists,
89
- gt,
90
- gte,
91
- ilike,
92
- inArray,
93
- isNull,
94
- isNotNull,
95
- like,
96
- lt,
97
- lte,
98
- ne,
99
- not,
100
- notBetween,
101
- notExists,
102
- notLike,
103
- notIlike,
104
- notInArray,
105
- or,
106
- sql
107
- };
108
- }
109
- function getOrderByOperators() {
110
- return {
111
- sql,
112
- asc,
113
- desc
114
- };
115
- }
116
- function extractTablesRelationalConfig(schema, configHelpers) {
117
- if (Object.keys(schema).length === 1 && "default" in schema && !is(schema["default"], Table)) {
118
- schema = schema["default"];
119
- }
120
- const tableNamesMap = {};
121
- const relationsBuffer = {};
122
- const tablesConfig = {};
123
- for (const [key, value] of Object.entries(schema)) {
124
- if (is(value, Table)) {
125
- const dbName = getTableUniqueName(value);
126
- const bufferedRelations = relationsBuffer[dbName];
127
- tableNamesMap[dbName] = key;
128
- tablesConfig[key] = {
129
- tsName: key,
130
- dbName: value[Table.Symbol.Name],
131
- schema: value[Table.Symbol.Schema],
132
- columns: value[Table.Symbol.Columns],
133
- relations: bufferedRelations?.relations ?? {},
134
- primaryKey: bufferedRelations?.primaryKey ?? []
44
+ for (const [tsName, table] of Object.entries(tables)) {
45
+ if (!is(table, Table))
46
+ continue;
47
+ this.tableNamesMap[getTableUniqueName(table)] = tsName;
48
+ const tableConfig = this.tablesConfig[tsName] = {
49
+ table,
50
+ tsName,
51
+ dbName: table[Table.Symbol.Name],
52
+ schema: table[Table.Symbol.Schema],
53
+ columns: table[Table.Symbol.Columns],
54
+ relations: config[tsName] || {},
55
+ primaryKey: []
135
56
  };
136
- for (const column of Object.values(
137
- value[Table.Symbol.Columns]
138
- )) {
57
+ for (const column of Object.values(table[Table.Symbol.Columns])) {
139
58
  if (column.primary) {
140
- tablesConfig[key].primaryKey.push(column);
59
+ tableConfig.primaryKey.push(column);
141
60
  }
142
61
  }
143
- const extraConfig = value[Table.Symbol.ExtraConfigBuilder]?.(value[Table.Symbol.ExtraConfigColumns]);
62
+ const extraConfig = table[Table.Symbol.ExtraConfigBuilder]?.(table);
144
63
  if (extraConfig) {
145
64
  for (const configEntry of Object.values(extraConfig)) {
146
65
  if (is(configEntry, PrimaryKeyBuilder)) {
147
- tablesConfig[key].primaryKey.push(...configEntry.columns);
66
+ tableConfig.primaryKey.push(...configEntry.columns);
148
67
  }
149
68
  }
150
69
  }
151
- } else if (is(value, Relations)) {
152
- const dbName = getTableUniqueName(value.table);
153
- const tableName = tableNamesMap[dbName];
154
- const relations2 = value.config(
155
- configHelpers(value.table)
156
- );
157
- let primaryKey;
158
- for (const [relationName, relation] of Object.entries(relations2)) {
159
- if (tableName) {
160
- const tableConfig = tablesConfig[tableName];
161
- tableConfig.relations[relationName] = relation;
162
- if (primaryKey) {
163
- tableConfig.primaryKey.push(...primaryKey);
70
+ }
71
+ for (const tableConfig of Object.values(this.tablesConfig)) {
72
+ for (const [relationFieldName, relation] of Object.entries(tableConfig.relations)) {
73
+ if (!is(relation, Relation)) {
74
+ continue;
75
+ }
76
+ relation.sourceTable = tableConfig.table;
77
+ relation.fieldName = relationFieldName;
78
+ }
79
+ }
80
+ for (const tableConfig of Object.values(this.tablesConfig)) {
81
+ for (const [relationFieldName, relation] of Object.entries(tableConfig.relations)) {
82
+ const relationPrintName = `relations -> ${tableConfig.tsName}.${relationFieldName}`;
83
+ if (!is(relation, Relation)) {
84
+ continue;
85
+ }
86
+ if (typeof relation.alias === "string" && !relation.alias) {
87
+ throw new Error(`${relationPrintName}: "alias" cannot be an empty string - omit it if you don't need it`);
88
+ }
89
+ if (relation.sourceColumns?.length === 0) {
90
+ throw new Error(`${relationPrintName}: "from" cannot be an empty array`);
91
+ }
92
+ if (relation.targetColumns?.length === 0) {
93
+ throw new Error(`${relationPrintName}: "to" cannot be an empty array`);
94
+ }
95
+ if (relation.sourceColumns && relation.targetColumns) {
96
+ if (relation.sourceColumns.length !== relation.targetColumns.length) {
97
+ throw new Error(
98
+ `${relationPrintName}: "from" and "to" fields must have the same length`
99
+ );
100
+ }
101
+ if (relation.through) {
102
+ if (relation.through.source.length !== relation.through.target.length || relation.through.source.length !== relation.sourceColumns.length || relation.through.target.length !== relation.targetColumns.length) {
103
+ throw new Error(
104
+ `${relationPrintName}: ".through(column)" must be used either on all columns in "from" and "to" or not defined on any of them`
105
+ );
106
+ }
107
+ for (const column of relation.through.source) {
108
+ if (column.table !== relation.throughTable) {
109
+ throw new Error(
110
+ `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
111
+ );
112
+ }
113
+ }
114
+ for (const column of relation.through.target) {
115
+ if (column.table !== relation.throughTable) {
116
+ throw new Error(
117
+ `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
118
+ );
119
+ }
120
+ }
121
+ }
122
+ continue;
123
+ }
124
+ if (relation.sourceColumns || relation.targetColumns) {
125
+ throw new Error(
126
+ `${relationPrintName}: relation must have either both "from" and "to" defined, or none of them`
127
+ );
128
+ }
129
+ let reverseRelation;
130
+ const targetTableTsName = this.tableNamesMap[getTableUniqueName(relation.targetTable)];
131
+ if (!targetTableTsName) {
132
+ throw new Error(
133
+ `Table "${getTableUniqueName(relation.targetTable)}" not found in provided TS schema`
134
+ );
135
+ }
136
+ const reverseTableConfig = this.tablesConfig[targetTableTsName];
137
+ if (!reverseTableConfig) {
138
+ throw new Error(
139
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${targetTableTsName}" were found"`
140
+ );
141
+ }
142
+ if (relation.alias) {
143
+ const reverseRelations = Object.values(reverseTableConfig.relations).filter(
144
+ (it) => is(it, Relation) && it.alias === relation.alias
145
+ );
146
+ if (reverseRelations.length > 1) {
147
+ throw new Error(
148
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${relation.alias}" found in table "${targetTableTsName}": ${reverseRelations.map((it) => `"${it.fieldName}"`).join(", ")}`
149
+ );
150
+ }
151
+ reverseRelation = reverseRelations[0];
152
+ if (!reverseRelation) {
153
+ throw new Error(
154
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${targetTableTsName}" with alias "${relation.alias}"`
155
+ );
164
156
  }
165
157
  } else {
166
- if (!(dbName in relationsBuffer)) {
167
- relationsBuffer[dbName] = {
168
- relations: {},
169
- primaryKey
170
- };
158
+ const reverseRelations = Object.values(reverseTableConfig.relations).filter(
159
+ (it) => is(it, Relation) && it.targetTable === relation.sourceTable && !it.alias
160
+ );
161
+ if (reverseRelations.length > 1) {
162
+ throw new Error(
163
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${targetTableTsName}" and "${getTableUniqueName(relation.sourceTable)}" were found.
164
+ Hint: you can specify "alias" on both sides of the relation with the same value`
165
+ );
166
+ }
167
+ reverseRelation = reverseRelations[0];
168
+ if (!reverseRelation) {
169
+ throw new Error(
170
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${targetTableTsName}" with target table "${getTableUniqueName(relation.sourceTable)}" was found`
171
+ );
171
172
  }
172
- relationsBuffer[dbName].relations[relationName] = relation;
173
173
  }
174
+ if (!reverseRelation.sourceColumns || !reverseRelation.targetColumns) {
175
+ throw new Error(
176
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${targetTableTsName}.${reverseRelation.fieldName}" does not have "from"/"to" defined`
177
+ );
178
+ }
179
+ relation.sourceColumns = reverseRelation.targetColumns;
180
+ relation.targetColumns = reverseRelation.sourceColumns;
181
+ relation.through = reverseRelation.through ? {
182
+ source: reverseRelation.through.target,
183
+ target: reverseRelation.through.source
184
+ } : void 0;
185
+ relation.throughTable = reverseRelation.throughTable;
186
+ relation.isReversed = !relation.where;
187
+ relation.where = relation.where ?? reverseRelation.where;
174
188
  }
175
189
  }
176
190
  }
177
- return { tables: tablesConfig, tableNamesMap };
191
+ static [entityKind] = "RelationsV2";
192
+ /** table DB name -> schema table key */
193
+ tableNamesMap = {};
194
+ tablesConfig = {};
178
195
  }
179
- function relations(table, relations2) {
180
- return new Relations(
181
- table,
182
- (helpers) => Object.fromEntries(
183
- Object.entries(relations2(helpers)).map(([key, value]) => [
184
- key,
185
- value.withFieldName(key)
186
- ])
187
- )
188
- );
196
+ class Relation {
197
+ constructor(targetTable) {
198
+ this.targetTable = targetTable;
199
+ }
200
+ static [entityKind] = "RelationV2";
201
+ fieldName;
202
+ sourceColumns;
203
+ targetColumns;
204
+ alias;
205
+ where;
206
+ sourceTable;
207
+ through;
208
+ throughTable;
209
+ isReversed;
189
210
  }
190
- function createOne(sourceTable) {
191
- return function one(table, config) {
192
- return new One(
193
- sourceTable,
194
- table,
195
- config,
196
- config?.fields.reduce((res, f) => res && f.notNull, true) ?? false
197
- );
198
- };
211
+ class One extends Relation {
212
+ static [entityKind] = "OneV2";
213
+ optional;
214
+ constructor(targetTable, config) {
215
+ super(targetTable);
216
+ this.alias = config?.alias;
217
+ this.where = config?.where;
218
+ if (config?.from) {
219
+ this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
220
+ this.throughTable ??= it._.through?._.column.table;
221
+ return it._.column;
222
+ });
223
+ }
224
+ if (config?.to) {
225
+ this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
226
+ this.throughTable ??= it._.through?._.column.table;
227
+ return it._.column;
228
+ });
229
+ }
230
+ if (this.throughTable) {
231
+ this.through = Array.isArray(config?.from) ? {
232
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain -- in case it's undefined, error will be thrown in Relations constructor
233
+ source: config.from.map((e) => e._.through?._.column),
234
+ target: (config.to ?? []).map((e) => e._.column)
235
+ } : {
236
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain -- in case it's undefined, error will be thrown in Relations constructor
237
+ source: [config?.from?._.through?._.column],
238
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
239
+ target: [config?.to?._.through?._.column]
240
+ };
241
+ }
242
+ this.optional = config?.optional ?? true;
243
+ }
199
244
  }
200
- function createMany(sourceTable) {
201
- return function many(referencedTable, config) {
202
- return new Many(sourceTable, referencedTable, config);
203
- };
245
+ class Many extends Relation {
246
+ constructor(targetTable, config) {
247
+ super(targetTable);
248
+ this.config = config;
249
+ this.alias = config?.alias;
250
+ this.where = config?.where;
251
+ if (config?.from) {
252
+ this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
253
+ this.throughTable ??= it._.through?._.column.table;
254
+ return it._.column;
255
+ });
256
+ }
257
+ if (config?.to) {
258
+ this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
259
+ this.throughTable ??= it._.through?._.column.table;
260
+ return it._.column;
261
+ });
262
+ }
263
+ if (this.throughTable) {
264
+ this.through = Array.isArray(config?.from) ? {
265
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain -- in case it's undefined, error will be thrown in Relations constructor
266
+ source: config.from.map((e) => e._.through?._.column),
267
+ target: (config.to ?? []).map((e) => e._.column)
268
+ } : {
269
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain -- in case it's undefined, error will be thrown in Relations constructor
270
+ source: [config?.from?._.through?._.column],
271
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
272
+ target: [config?.to?._.through?._.column]
273
+ };
274
+ }
275
+ }
276
+ static [entityKind] = "ManyV2";
204
277
  }
205
- function normalizeRelation(schema, tableNamesMap, relation) {
206
- if (is(relation, One) && relation.config) {
207
- return {
208
- fields: relation.config.fields,
209
- references: relation.config.references
210
- };
278
+ class AggregatedField {
279
+ static [entityKind] = "AggregatedField";
280
+ table;
281
+ onTable(table) {
282
+ this.table = table;
283
+ return this;
211
284
  }
212
- const referencedTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
213
- if (!referencedTableTsName) {
214
- throw new Error(
215
- `Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`
216
- );
285
+ }
286
+ class Count extends AggregatedField {
287
+ static [entityKind] = "AggregatedFieldCount";
288
+ query;
289
+ getSQL() {
290
+ if (!this.query) {
291
+ if (!this.table)
292
+ throw new Error("Table must be set before building aggregate field");
293
+ const table = this.table;
294
+ this.query = sql`select count(*) as ${sql.identifier("r")} from ${table[IsAlias] ? sql`${sql`${sql.identifier(table[Schema] ?? "")}.`.if(table[Schema])}${sql.identifier(table[OriginalName])} as ${table}` : table}`.mapWith(Number);
295
+ }
296
+ return this.query;
217
297
  }
218
- const referencedTableConfig = schema[referencedTableTsName];
219
- if (!referencedTableConfig) {
220
- throw new Error(`Table "${referencedTableTsName}" not found in schema`);
298
+ }
299
+ const operators = {
300
+ and,
301
+ between,
302
+ eq,
303
+ exists,
304
+ gt,
305
+ gte,
306
+ ilike,
307
+ inArray,
308
+ isNull,
309
+ isNotNull,
310
+ like,
311
+ lt,
312
+ lte,
313
+ ne,
314
+ not,
315
+ notBetween,
316
+ notExists,
317
+ notLike,
318
+ notIlike,
319
+ notInArray,
320
+ or,
321
+ sql
322
+ };
323
+ const orderByOperators = {
324
+ sql,
325
+ asc,
326
+ desc
327
+ };
328
+ function getOrderByOperators() {
329
+ return orderByOperators;
330
+ }
331
+ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, path) {
332
+ for (const selectionItem of buildQueryResultSelection) {
333
+ const field = selectionItem.field;
334
+ if (is(field, Table)) {
335
+ const currentPath = `${path ? `${path}.` : ""}${selectionItem.key}`;
336
+ if (row[selectionItem.key] === null)
337
+ continue;
338
+ if (parseJson)
339
+ row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
340
+ if (selectionItem.isArray) {
341
+ for (const item of row[selectionItem.key]) {
342
+ mapRelationalRow(
343
+ item,
344
+ selectionItem.selection,
345
+ mapColumnValue,
346
+ false,
347
+ currentPath
348
+ );
349
+ }
350
+ continue;
351
+ }
352
+ mapRelationalRow(
353
+ row[selectionItem.key],
354
+ selectionItem.selection,
355
+ mapColumnValue,
356
+ false,
357
+ currentPath
358
+ );
359
+ continue;
360
+ }
361
+ const value = mapColumnValue(row[selectionItem.key]);
362
+ if (value === null)
363
+ continue;
364
+ let decoder;
365
+ if (is(field, Column)) {
366
+ decoder = field;
367
+ } else if (is(field, SQL)) {
368
+ decoder = field.decoder;
369
+ } else if (is(field, SQL.Aliased)) {
370
+ decoder = field.sql.decoder;
371
+ } else {
372
+ decoder = field.getSQL().decoder;
373
+ }
374
+ row[selectionItem.key] = decoder.mapFromDriverValue(value);
221
375
  }
222
- const sourceTable = relation.sourceTable;
223
- const sourceTableTsName = tableNamesMap[getTableUniqueName(sourceTable)];
224
- if (!sourceTableTsName) {
225
- throw new Error(
226
- `Table "${sourceTable[Table.Symbol.Name]}" not found in schema`
227
- );
376
+ return row;
377
+ }
378
+ class RelationsBuilderTable {
379
+ static [entityKind] = "RelationsBuilderTable";
380
+ _;
381
+ constructor(table) {
382
+ this._ = {
383
+ name: getTableName(table),
384
+ table
385
+ };
228
386
  }
229
- const reverseRelations = [];
230
- for (const referencedTableRelation of Object.values(
231
- referencedTableConfig.relations
232
- )) {
233
- if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) {
234
- reverseRelations.push(referencedTableRelation);
235
- }
387
+ getSQL() {
388
+ return this._.table.getSQL();
236
389
  }
237
- if (reverseRelations.length > 1) {
238
- throw relation.relationName ? new Error(
239
- `There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`
240
- ) : new Error(
241
- `There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[Table.Symbol.Name]}". Please specify relation name`
242
- );
390
+ }
391
+ class RelationsBuilderColumn {
392
+ static [entityKind] = "RelationsBuilderColumn";
393
+ _;
394
+ constructor(column, through) {
395
+ this._ = {
396
+ tableName: getTableName(column.table),
397
+ data: void 0,
398
+ column,
399
+ through
400
+ };
243
401
  }
244
- if (reverseRelations[0] && is(reverseRelations[0], One) && reverseRelations[0].config) {
245
- return {
246
- fields: reverseRelations[0].config.references,
247
- references: reverseRelations[0].config.fields
402
+ through(column) {
403
+ return new RelationsBuilderColumn(this._.column, column);
404
+ }
405
+ getSQL() {
406
+ return this._.column.getSQL();
407
+ }
408
+ }
409
+ class RelationsHelperStatic {
410
+ static [entityKind] = "RelationsHelperStatic";
411
+ _;
412
+ constructor(tables) {
413
+ this._ = {
414
+ tables
248
415
  };
416
+ const one = {};
417
+ const many = {};
418
+ for (const [tableName, table] of Object.entries(tables)) {
419
+ one[tableName] = (config) => {
420
+ return new One(table, config);
421
+ };
422
+ many[tableName] = (config) => {
423
+ return new Many(table, config);
424
+ };
425
+ }
426
+ this.one = one;
427
+ this.many = many;
249
428
  }
250
- throw new Error(
251
- `There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`
429
+ one;
430
+ many;
431
+ aggs = {
432
+ count() {
433
+ return new Count();
434
+ }
435
+ };
436
+ }
437
+ function createRelationsHelper(schema) {
438
+ const schemaTables = Object.fromEntries(
439
+ Object.entries(schema).filter((e) => is(e[1], Table))
440
+ );
441
+ const helperStatic = new RelationsHelperStatic(schemaTables);
442
+ const tables = Object.entries(schema).reduce((acc, [key, value]) => {
443
+ if (is(value, Table)) {
444
+ const rTable = new RelationsBuilderTable(value);
445
+ const columns = Object.entries(getTableColumns(value)).reduce(
446
+ (acc2, [key2, column]) => {
447
+ const rbColumn = new RelationsBuilderColumn(column);
448
+ acc2[key2] = rbColumn;
449
+ return acc2;
450
+ },
451
+ {}
452
+ );
453
+ acc[key] = Object.assign(rTable, columns);
454
+ }
455
+ return acc;
456
+ }, {});
457
+ return Object.assign(helperStatic, tables);
458
+ }
459
+ function defineRelations(schema, relations) {
460
+ return new Relations(
461
+ schema,
462
+ schema,
463
+ relations(createRelationsHelper(schema))
252
464
  );
253
465
  }
254
- function createTableRelationsHelpers(sourceTable) {
466
+ function relationsFieldFilterToSQL(column, filter) {
467
+ if (typeof filter !== "object")
468
+ return eq(column, filter);
469
+ const entries = Object.entries(filter);
470
+ if (!entries.length)
471
+ return void 0;
472
+ const parts = [];
473
+ for (const [target, value] of entries) {
474
+ if (value === void 0)
475
+ continue;
476
+ switch (target) {
477
+ case "NOT": {
478
+ const res = relationsFieldFilterToSQL(column, value);
479
+ if (!res)
480
+ continue;
481
+ parts.push(not(res));
482
+ continue;
483
+ }
484
+ case "OR": {
485
+ if (!value.length)
486
+ continue;
487
+ parts.push(
488
+ or(
489
+ ...value.map((subFilter) => relationsFieldFilterToSQL(column, subFilter))
490
+ )
491
+ );
492
+ continue;
493
+ }
494
+ case "isNotNull":
495
+ case "isNull": {
496
+ if (!value)
497
+ continue;
498
+ parts.push(operators[target](column));
499
+ continue;
500
+ }
501
+ case "in": {
502
+ parts.push(operators.inArray(column, value));
503
+ continue;
504
+ }
505
+ case "notIn": {
506
+ parts.push(operators.notInArray(column, value));
507
+ continue;
508
+ }
509
+ default: {
510
+ parts.push(
511
+ operators[target](
512
+ column,
513
+ value
514
+ )
515
+ );
516
+ continue;
517
+ }
518
+ }
519
+ }
520
+ if (!parts.length)
521
+ return void 0;
522
+ return and(...parts);
523
+ }
524
+ function relationsFilterToSQL(table, filter) {
525
+ const entries = Object.entries(filter);
526
+ if (!entries.length)
527
+ return void 0;
528
+ const parts = [];
529
+ for (const [target, value] of entries) {
530
+ if (value === void 0)
531
+ continue;
532
+ switch (target) {
533
+ case "RAW": {
534
+ if (value) {
535
+ parts.push(
536
+ value(table, operators)
537
+ );
538
+ }
539
+ continue;
540
+ }
541
+ case "OR": {
542
+ if (!value?.length)
543
+ continue;
544
+ parts.push(
545
+ or(
546
+ ...value.map(
547
+ (subFilter) => relationsFilterToSQL(table, subFilter)
548
+ )
549
+ )
550
+ );
551
+ continue;
552
+ }
553
+ case "NOT": {
554
+ if (value === void 0)
555
+ continue;
556
+ const built = relationsFilterToSQL(table, value);
557
+ if (!built)
558
+ continue;
559
+ parts.push(not(built));
560
+ continue;
561
+ }
562
+ default: {
563
+ const colFilter = relationsFieldFilterToSQL(
564
+ table[target],
565
+ value
566
+ );
567
+ if (colFilter)
568
+ parts.push(colFilter);
569
+ continue;
570
+ }
571
+ }
572
+ }
573
+ return and(...parts);
574
+ }
575
+ function relationsOrderToSQL(table, orders) {
576
+ if (typeof orders === "function") {
577
+ const data = orders(table, orderByOperators);
578
+ return is(data, SQL) ? data : Array.isArray(data) ? data.length ? sql.join(data.map((o) => is(o, SQL) ? o : asc(o)), sql`, `) : void 0 : is(data, Column) ? asc(data) : void 0;
579
+ }
580
+ const entries = Object.entries(orders).filter(([_, value]) => value);
581
+ if (!entries.length)
582
+ return void 0;
583
+ return sql.join(entries.map(([column, value]) => (value === "asc" ? asc : desc)(table[Columns][column])), sql`, `);
584
+ }
585
+ function relationExtrasToSQL(table, extras) {
586
+ const subqueries = [];
587
+ const selection = [];
588
+ for (const [key, extra] of Object.entries(
589
+ typeof extras === "function" ? extras(table, { sql: operators.sql }) : extras
590
+ )) {
591
+ if (!extra)
592
+ continue;
593
+ const query = sql`(${extra.getSQL()}) as ${sql.identifier(key)}`;
594
+ query.decoder = extra.getSQL().decoder;
595
+ subqueries.push(query);
596
+ selection.push({
597
+ key,
598
+ field: query
599
+ });
600
+ }
255
601
  return {
256
- one: createOne(sourceTable),
257
- many: createMany(sourceTable)
602
+ sql: subqueries.length ? sql.join(subqueries, sql`, `) : void 0,
603
+ selection
258
604
  };
259
605
  }
260
- function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
261
- const result = {};
262
- for (const [
263
- selectionItemIndex,
264
- selectionItem
265
- ] of buildQueryResultSelection.entries()) {
266
- if (selectionItem.isJson) {
267
- const relation = tableConfig.relations[selectionItem.tsKey];
268
- const rawSubRows = row[selectionItemIndex];
269
- const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
270
- result[selectionItem.tsKey] = is(relation, One) ? subRows && mapRelationalRow(
271
- tablesConfig,
272
- tablesConfig[selectionItem.relationTableTsKey],
273
- subRows,
274
- selectionItem.selection,
275
- mapColumnValue
276
- ) : subRows.map(
277
- (subRow) => mapRelationalRow(
278
- tablesConfig,
279
- tablesConfig[selectionItem.relationTableTsKey],
280
- subRow,
281
- selectionItem.selection,
282
- mapColumnValue
283
- )
606
+ function relationToSQL(relation, sourceTable, targetTable, throughTable) {
607
+ if (relation.through) {
608
+ const outerColumnWhere = relation.sourceColumns.map((s, i) => {
609
+ const t = relation.through.source[i];
610
+ return eq(
611
+ sql`${sourceTable}.${sql.identifier(s.name)}`,
612
+ sql`${throughTable}.${sql.identifier(t.name)}`
284
613
  );
285
- } else {
286
- const value = mapColumnValue(row[selectionItemIndex]);
287
- const field = selectionItem.field;
288
- let decoder;
289
- if (is(field, Column)) {
290
- decoder = field;
291
- } else if (is(field, SQL)) {
292
- decoder = field.decoder;
293
- } else {
294
- decoder = field.sql.decoder;
295
- }
296
- result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
297
- }
614
+ });
615
+ const innerColumnWhere = relation.targetColumns.map((s, i) => {
616
+ const t = relation.through.target[i];
617
+ return eq(
618
+ sql`${throughTable}.${sql.identifier(t.name)}`,
619
+ sql`${targetTable}.${sql.identifier(s.name)}`
620
+ );
621
+ });
622
+ return {
623
+ filter: and(
624
+ relation.where ? relation.isReversed ? relationsFilterToSQL(targetTable, relation.where) : relationsFilterToSQL(sourceTable, relation.where) : void 0
625
+ ),
626
+ joinCondition: and(
627
+ ...outerColumnWhere,
628
+ ...innerColumnWhere
629
+ )
630
+ };
298
631
  }
299
- return result;
632
+ const columnWhere = relation.sourceColumns.map((s, i) => {
633
+ const t = relation.targetColumns[i];
634
+ return eq(
635
+ sql`${sourceTable}.${sql.identifier(s.name)}`,
636
+ sql`${targetTable}.${sql.identifier(t.name)}`
637
+ );
638
+ });
639
+ const fullWhere = and(
640
+ ...columnWhere,
641
+ relation.where ? relation.isReversed ? relationsFilterToSQL(targetTable, relation.where) : relationsFilterToSQL(sourceTable, relation.where) : void 0
642
+ );
643
+ return { filter: fullWhere };
300
644
  }
301
645
  export {
646
+ AggregatedField,
647
+ Count,
302
648
  Many,
303
649
  One,
304
650
  Relation,
305
651
  Relations,
306
- createMany,
307
- createOne,
308
- createTableRelationsHelpers,
309
- extractTablesRelationalConfig,
310
- getOperators,
652
+ RelationsBuilderColumn,
653
+ RelationsBuilderTable,
654
+ RelationsHelperStatic,
655
+ createRelationsHelper,
656
+ defineRelations,
311
657
  getOrderByOperators,
312
658
  mapRelationalRow,
313
- normalizeRelation,
314
- relations
659
+ operators,
660
+ orderByOperators,
661
+ relationExtrasToSQL,
662
+ relationToSQL,
663
+ relationsFilterToSQL,
664
+ relationsOrderToSQL
315
665
  };
316
666
  //# sourceMappingURL=relations.js.map