@aurabase/aurabase-js 0.3.0 → 0.4.0

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 (343) hide show
  1. package/README.md +26 -795
  2. package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.ts → dist/AuraClient-BcFE8u1v.d.cts} +1 -1
  3. package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.cts → dist/AuraClient-BcFE8u1v.d.ts} +1 -1
  4. package/{packages/aurabase/dist → dist}/index.d.cts +1 -1
  5. package/{packages/aurabase/dist → dist}/index.d.ts +1 -1
  6. package/{packages/aurabase/dist → dist}/ssr.d.cts +1 -1
  7. package/{packages/aurabase/dist → dist}/ssr.d.ts +1 -1
  8. package/package.json +72 -82
  9. package/.changeset/config.json +0 -11
  10. package/CHANGELOG.md +0 -30
  11. package/packages/ai/LICENSE +0 -21
  12. package/packages/ai/README.md +0 -106
  13. package/packages/ai/dist/index.cjs +0 -229
  14. package/packages/ai/dist/index.d.cts +0 -139
  15. package/packages/ai/dist/index.d.ts +0 -139
  16. package/packages/ai/dist/index.js +0 -226
  17. package/packages/ai/node_modules/.bin/esbuild +0 -19
  18. package/packages/ai/node_modules/.bin/tsc +0 -22
  19. package/packages/ai/node_modules/.bin/tsserver +0 -22
  20. package/packages/ai/node_modules/.bin/tsup +0 -22
  21. package/packages/ai/node_modules/.bin/tsup-node +0 -22
  22. package/packages/ai/node_modules/.bin/vite +0 -22
  23. package/packages/ai/node_modules/.bin/vitest +0 -22
  24. package/packages/ai/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  25. package/packages/ai/package.json +0 -61
  26. package/packages/ai/src/AiService.ts +0 -226
  27. package/packages/ai/src/index.ts +0 -18
  28. package/packages/ai/src/sse.ts +0 -141
  29. package/packages/ai/src/types.ts +0 -30
  30. package/packages/ai/tests/chat-stream.test.ts +0 -151
  31. package/packages/ai/tests/rag-namespaces.test.ts +0 -54
  32. package/packages/ai/tests/sse.test.ts +0 -69
  33. package/packages/ai/tsconfig.json +0 -5
  34. package/packages/ai/tsup.config.ts +0 -11
  35. package/packages/aurabase/LICENSE +0 -21
  36. package/packages/aurabase/README.md +0 -64
  37. package/packages/aurabase/node_modules/.bin/esbuild +0 -19
  38. package/packages/aurabase/node_modules/.bin/tsc +0 -22
  39. package/packages/aurabase/node_modules/.bin/tsserver +0 -22
  40. package/packages/aurabase/node_modules/.bin/tsup +0 -22
  41. package/packages/aurabase/node_modules/.bin/tsup-node +0 -22
  42. package/packages/aurabase/node_modules/.bin/vite +0 -22
  43. package/packages/aurabase/node_modules/.bin/vitest +0 -22
  44. package/packages/aurabase/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  45. package/packages/aurabase/package.json +0 -80
  46. package/packages/aurabase/src/AuraClient.ts +0 -237
  47. package/packages/aurabase/src/index.ts +0 -152
  48. package/packages/aurabase/src/ssr.ts +0 -156
  49. package/packages/aurabase/tests/ai-streaming-rag-e2e.test.ts +0 -82
  50. package/packages/aurabase/tests/ai.test.ts +0 -111
  51. package/packages/aurabase/tests/auth-admin.test.ts +0 -515
  52. package/packages/aurabase/tests/auth-e2e.test.ts +0 -135
  53. package/packages/aurabase/tests/auth-hardening.test.ts +0 -206
  54. package/packages/aurabase/tests/auth.test.ts +0 -947
  55. package/packages/aurabase/tests/database.test.ts +0 -230
  56. package/packages/aurabase/tests/db-types-e2e.test.ts +0 -217
  57. package/packages/aurabase/tests/dispose.test.ts +0 -23
  58. package/packages/aurabase/tests/foreign-token.e2e.test.ts +0 -129
  59. package/packages/aurabase/tests/functions.test.ts +0 -107
  60. package/packages/aurabase/tests/integration.test.ts +0 -413
  61. package/packages/aurabase/tests/live-production-validation.js +0 -241
  62. package/packages/aurabase/tests/live-sdk-production-validation.js +0 -293
  63. package/packages/aurabase/tests/mocks.ts +0 -139
  64. package/packages/aurabase/tests/notifications.test.ts +0 -314
  65. package/packages/aurabase/tests/observability-backup.test.ts +0 -186
  66. package/packages/aurabase/tests/observability-hook.test.ts +0 -130
  67. package/packages/aurabase/tests/production-robustness.test.ts +0 -268
  68. package/packages/aurabase/tests/public-api-surface.test.ts +0 -53
  69. package/packages/aurabase/tests/query-builder.test.ts +0 -329
  70. package/packages/aurabase/tests/readme-smoke-e2e.test.ts +0 -231
  71. package/packages/aurabase/tests/realtime-filter-e2e.test.ts +0 -344
  72. package/packages/aurabase/tests/refresh-locks.test.ts +0 -210
  73. package/packages/aurabase/tests/retry-option.test.ts +0 -17
  74. package/packages/aurabase/tests/rpc-e2e.test.ts +0 -254
  75. package/packages/aurabase/tests/rs256-local-e2e.test.ts +0 -114
  76. package/packages/aurabase/tests/rt-alias-public-e2e.test.ts +0 -235
  77. package/packages/aurabase/tests/rt-http-broadcast-e2e.test.ts +0 -124
  78. package/packages/aurabase/tests/service-role-guard.test.ts +0 -99
  79. package/packages/aurabase/tests/ssr.test.ts +0 -91
  80. package/packages/aurabase/tests/storage-backend-e2e.test.ts +0 -481
  81. package/packages/aurabase/tests/storage-sdk-parity-e2e.test.ts +0 -104
  82. package/packages/aurabase/tests/storage-transform-e2e.test.ts +0 -684
  83. package/packages/aurabase/tests/storage.test.ts +0 -55
  84. package/packages/aurabase/tests/types/client-generic.test-d.ts +0 -79
  85. package/packages/aurabase/tests/types/docs-snippets.test-d.ts +0 -571
  86. package/packages/aurabase/tests/types/error-code.test-d.ts +0 -53
  87. package/packages/aurabase/tsconfig.json +0 -5
  88. package/packages/aurabase/tsconfig.test-d.json +0 -5
  89. package/packages/aurabase/tsup.config.ts +0 -11
  90. package/packages/aurabase/vitest.config.ts +0 -16
  91. package/packages/aurabase/vitest.e2e.config.ts +0 -9
  92. package/packages/auth/LICENSE +0 -21
  93. package/packages/auth/README.md +0 -215
  94. package/packages/auth/dist/index.cjs +0 -1175
  95. package/packages/auth/dist/index.d.cts +0 -397
  96. package/packages/auth/dist/index.d.ts +0 -397
  97. package/packages/auth/dist/index.js +0 -1170
  98. package/packages/auth/node_modules/.bin/esbuild +0 -19
  99. package/packages/auth/node_modules/.bin/tsc +0 -22
  100. package/packages/auth/node_modules/.bin/tsserver +0 -22
  101. package/packages/auth/node_modules/.bin/tsup +0 -22
  102. package/packages/auth/node_modules/.bin/tsup-node +0 -22
  103. package/packages/auth/node_modules/.bin/vite +0 -22
  104. package/packages/auth/node_modules/.bin/vitest +0 -22
  105. package/packages/auth/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  106. package/packages/auth/package.json +0 -61
  107. package/packages/auth/src/AuthAdminService.ts +0 -149
  108. package/packages/auth/src/AuthService.ts +0 -1166
  109. package/packages/auth/src/SessionManager.ts +0 -92
  110. package/packages/auth/src/index.ts +0 -17
  111. package/packages/auth/src/jwks.ts +0 -337
  112. package/packages/auth/src/pkce.ts +0 -27
  113. package/packages/auth/src/types.ts +0 -89
  114. package/packages/auth/tests/auth-lifecycle.test.ts +0 -149
  115. package/packages/auth/tests/detect-session.test.ts +0 -361
  116. package/packages/auth/tests/getclaims.test.ts +0 -780
  117. package/packages/auth/tests/is-mfa-challenge.test.ts +0 -27
  118. package/packages/auth/tests/password-recovery.test.ts +0 -124
  119. package/packages/auth/tests/pkce.test.ts +0 -192
  120. package/packages/auth/tests/session-manager.test.ts +0 -103
  121. package/packages/auth/tests/set-session.test.ts +0 -139
  122. package/packages/auth/tests/verify-otp.test.ts +0 -153
  123. package/packages/auth/tsconfig.json +0 -5
  124. package/packages/auth/tsup.config.ts +0 -11
  125. package/packages/core/LICENSE +0 -21
  126. package/packages/core/README.md +0 -132
  127. package/packages/core/dist/index.cjs +0 -695
  128. package/packages/core/dist/index.d.cts +0 -1137
  129. package/packages/core/dist/index.d.ts +0 -1137
  130. package/packages/core/dist/index.js +0 -673
  131. package/packages/core/node_modules/.bin/esbuild +0 -22
  132. package/packages/core/node_modules/.bin/tsc +0 -22
  133. package/packages/core/node_modules/.bin/tsserver +0 -22
  134. package/packages/core/node_modules/.bin/tsup +0 -22
  135. package/packages/core/node_modules/.bin/tsup-node +0 -22
  136. package/packages/core/node_modules/.bin/vite +0 -22
  137. package/packages/core/node_modules/.bin/vitest +0 -22
  138. package/packages/core/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  139. package/packages/core/package.json +0 -57
  140. package/packages/core/src/AuraError.ts +0 -89
  141. package/packages/core/src/BaseService.ts +0 -44
  142. package/packages/core/src/client.ts +0 -34
  143. package/packages/core/src/cookie-utils.ts +0 -42
  144. package/packages/core/src/fetch.ts +0 -435
  145. package/packages/core/src/index.ts +0 -22
  146. package/packages/core/src/retry.ts +0 -63
  147. package/packages/core/src/serialize.ts +0 -6
  148. package/packages/core/src/stores/BaseAuthStore.ts +0 -164
  149. package/packages/core/src/stores/LocalAuthStore.ts +0 -199
  150. package/packages/core/src/types.ts +0 -1042
  151. package/packages/core/tests/auth-store.test.ts +0 -300
  152. package/packages/core/tests/error-code.test.ts +0 -61
  153. package/packages/core/tests/error.test.ts +0 -24
  154. package/packages/core/tests/fetch.test.ts +0 -286
  155. package/packages/core/tests/mocks.ts +0 -139
  156. package/packages/core/tests/observability.test.ts +0 -86
  157. package/packages/core/tests/refresh-hardening.test.ts +0 -164
  158. package/packages/core/tests/refresh-observability.test.ts +0 -111
  159. package/packages/core/tests/retry.test.ts +0 -106
  160. package/packages/core/tests/serialize.test.ts +0 -12
  161. package/packages/core/tests/timeout.test.ts +0 -79
  162. package/packages/core/tsconfig.json +0 -5
  163. package/packages/core/tsup.config.ts +0 -11
  164. package/packages/db/LICENSE +0 -21
  165. package/packages/db/README.md +0 -152
  166. package/packages/db/VENDORED.md +0 -93
  167. package/packages/db/dist/index.cjs +0 -544
  168. package/packages/db/dist/index.d.cts +0 -1111
  169. package/packages/db/dist/index.d.ts +0 -1111
  170. package/packages/db/dist/index.js +0 -541
  171. package/packages/db/node_modules/.bin/esbuild +0 -19
  172. package/packages/db/node_modules/.bin/tsc +0 -22
  173. package/packages/db/node_modules/.bin/tsserver +0 -22
  174. package/packages/db/node_modules/.bin/tsup +0 -22
  175. package/packages/db/node_modules/.bin/tsup-node +0 -22
  176. package/packages/db/node_modules/.bin/vite +0 -22
  177. package/packages/db/node_modules/.bin/vitest +0 -22
  178. package/packages/db/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  179. package/packages/db/package.json +0 -62
  180. package/packages/db/src/DatabaseService.ts +0 -170
  181. package/packages/db/src/QueryBuilder.ts +0 -830
  182. package/packages/db/src/index.ts +0 -2
  183. package/packages/db/src/pgrst-types/common/common.ts +0 -86
  184. package/packages/db/src/pgrst-types/common/rpc.ts +0 -151
  185. package/packages/db/src/pgrst-types/feature-flags.ts +0 -20
  186. package/packages/db/src/pgrst-types/types.ts +0 -134
  187. package/packages/db/src/select-query-parser/parser.ts +0 -479
  188. package/packages/db/src/select-query-parser/result.ts +0 -553
  189. package/packages/db/src/select-query-parser/types.ts +0 -132
  190. package/packages/db/src/select-query-parser/utils.ts +0 -707
  191. package/packages/db/tests/filters.test.ts +0 -81
  192. package/packages/db/tests/mutations-filtered.e2e.test.ts +0 -132
  193. package/packages/db/tests/mutations-filtered.test.ts +0 -188
  194. package/packages/db/tests/order.test.ts +0 -45
  195. package/packages/db/tests/rpc.test.ts +0 -41
  196. package/packages/db/tests/scale/build-large-schema.ts +0 -94
  197. package/packages/db/tests/scale/scale-compile.test.ts +0 -167
  198. package/packages/db/tests/schema.test.ts +0 -77
  199. package/packages/db/tests/single-accept.e2e.test.ts +0 -123
  200. package/packages/db/tests/single.test.ts +0 -211
  201. package/packages/db/tests/types/filters.test-d.ts +0 -52
  202. package/packages/db/tests/types/fixtures.ts +0 -40
  203. package/packages/db/tests/types/from-views.test-d.ts +0 -18
  204. package/packages/db/tests/types/mutations.test-d.ts +0 -23
  205. package/packages/db/tests/types/rpc.test-d.ts +0 -60
  206. package/packages/db/tests/types/schema-shape.test-d.ts +0 -8
  207. package/packages/db/tests/types/select-inference.test-d.ts +0 -38
  208. package/packages/db/tests/vendored/fixtures.ts +0 -83
  209. package/packages/db/tests/vendored/get-result.test-d.ts +0 -75
  210. package/packages/db/tsconfig.json +0 -5
  211. package/packages/db/tsconfig.test-d.json +0 -5
  212. package/packages/db/tsup.config.ts +0 -11
  213. package/packages/db/vitest.config.ts +0 -8
  214. package/packages/functions/LICENSE +0 -21
  215. package/packages/functions/README.md +0 -96
  216. package/packages/functions/dist/index.cjs +0 -173
  217. package/packages/functions/dist/index.d.cts +0 -81
  218. package/packages/functions/dist/index.d.ts +0 -81
  219. package/packages/functions/dist/index.js +0 -168
  220. package/packages/functions/node_modules/.bin/esbuild +0 -19
  221. package/packages/functions/node_modules/.bin/tsc +0 -22
  222. package/packages/functions/node_modules/.bin/tsserver +0 -22
  223. package/packages/functions/node_modules/.bin/tsup +0 -22
  224. package/packages/functions/node_modules/.bin/tsup-node +0 -22
  225. package/packages/functions/node_modules/.bin/vite +0 -22
  226. package/packages/functions/node_modules/.bin/vitest +0 -22
  227. package/packages/functions/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  228. package/packages/functions/package.json +0 -60
  229. package/packages/functions/src/FunctionsService.ts +0 -188
  230. package/packages/functions/src/errors.ts +0 -70
  231. package/packages/functions/src/index.ts +0 -6
  232. package/packages/functions/tests/invoke.test.ts +0 -97
  233. package/packages/functions/tests/response-type-errors.test.ts +0 -135
  234. package/packages/functions/tsconfig.json +0 -5
  235. package/packages/functions/tsup.config.ts +0 -11
  236. package/packages/gen/LICENSE +0 -21
  237. package/packages/gen/README.md +0 -84
  238. package/packages/gen/dist/cli.cjs +0 -334
  239. package/packages/gen/dist/cli.d.cts +0 -1
  240. package/packages/gen/dist/cli.d.ts +0 -1
  241. package/packages/gen/dist/cli.js +0 -332
  242. package/packages/gen/dist/index.cjs +0 -257
  243. package/packages/gen/dist/index.d.cts +0 -12
  244. package/packages/gen/dist/index.d.ts +0 -12
  245. package/packages/gen/dist/index.js +0 -255
  246. package/packages/gen/node_modules/.bin/esbuild +0 -19
  247. package/packages/gen/node_modules/.bin/tsc +0 -22
  248. package/packages/gen/node_modules/.bin/tsserver +0 -22
  249. package/packages/gen/node_modules/.bin/tsup +0 -22
  250. package/packages/gen/node_modules/.bin/tsup-node +0 -22
  251. package/packages/gen/node_modules/.bin/vite +0 -22
  252. package/packages/gen/node_modules/.bin/vitest +0 -22
  253. package/packages/gen/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  254. package/packages/gen/package.json +0 -66
  255. package/packages/gen/src/cli.ts +0 -67
  256. package/packages/gen/src/generate.ts +0 -0
  257. package/packages/gen/src/index.ts +0 -2
  258. package/packages/gen/tests/compile.test.ts +0 -213
  259. package/packages/gen/tests/e2e.test.ts +0 -130
  260. package/packages/gen/tests/generate.test.ts +0 -396
  261. package/packages/gen/tsconfig.json +0 -5
  262. package/packages/gen/tsup.config.ts +0 -11
  263. package/packages/notifications/LICENSE +0 -21
  264. package/packages/notifications/README.md +0 -134
  265. package/packages/notifications/dist/index.cjs +0 -128
  266. package/packages/notifications/dist/index.d.cts +0 -81
  267. package/packages/notifications/dist/index.d.ts +0 -81
  268. package/packages/notifications/dist/index.js +0 -125
  269. package/packages/notifications/node_modules/.bin/esbuild +0 -19
  270. package/packages/notifications/node_modules/.bin/tsc +0 -22
  271. package/packages/notifications/node_modules/.bin/tsserver +0 -22
  272. package/packages/notifications/node_modules/.bin/tsup +0 -22
  273. package/packages/notifications/node_modules/.bin/tsup-node +0 -22
  274. package/packages/notifications/node_modules/.bin/vite +0 -22
  275. package/packages/notifications/node_modules/.bin/vitest +0 -22
  276. package/packages/notifications/package.json +0 -60
  277. package/packages/notifications/src/NotificationsService.ts +0 -230
  278. package/packages/notifications/src/index.ts +0 -19
  279. package/packages/notifications/tsconfig.json +0 -5
  280. package/packages/notifications/tsup.config.ts +0 -11
  281. package/packages/realtime/LICENSE +0 -21
  282. package/packages/realtime/README.md +0 -183
  283. package/packages/realtime/dist/index.cjs +0 -977
  284. package/packages/realtime/dist/index.d.cts +0 -259
  285. package/packages/realtime/dist/index.d.ts +0 -259
  286. package/packages/realtime/dist/index.js +0 -973
  287. package/packages/realtime/node_modules/.bin/esbuild +0 -19
  288. package/packages/realtime/node_modules/.bin/tsc +0 -22
  289. package/packages/realtime/node_modules/.bin/tsserver +0 -22
  290. package/packages/realtime/node_modules/.bin/tsup +0 -22
  291. package/packages/realtime/node_modules/.bin/tsup-node +0 -22
  292. package/packages/realtime/node_modules/.bin/vite +0 -22
  293. package/packages/realtime/node_modules/.bin/vitest +0 -22
  294. package/packages/realtime/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  295. package/packages/realtime/package.json +0 -60
  296. package/packages/realtime/src/AuraChannel.ts +0 -485
  297. package/packages/realtime/src/HeartbeatManager.ts +0 -73
  298. package/packages/realtime/src/RealtimeService.ts +0 -505
  299. package/packages/realtime/src/columnFilter.ts +0 -301
  300. package/packages/realtime/src/index.ts +0 -4
  301. package/packages/realtime/tests/ack-routing.test.ts +0 -81
  302. package/packages/realtime/tests/column-filter.test.ts +0 -144
  303. package/packages/realtime/tests/dispatch.test.ts +0 -191
  304. package/packages/realtime/tests/heartbeat.test.ts +0 -67
  305. package/packages/realtime/tests/http-broadcast.test.ts +0 -68
  306. package/packages/realtime/tests/realtime-token.test.ts +0 -43
  307. package/packages/realtime/tests/reconnect-race.test.ts +0 -149
  308. package/packages/realtime/tests/ref-id.test.ts +0 -34
  309. package/packages/realtime/tests/set-auth.test.ts +0 -70
  310. package/packages/realtime/tsconfig.json +0 -5
  311. package/packages/realtime/tsup.config.ts +0 -11
  312. package/packages/storage/LICENSE +0 -21
  313. package/packages/storage/README.md +0 -141
  314. package/packages/storage/dist/index.cjs +0 -333
  315. package/packages/storage/dist/index.d.cts +0 -185
  316. package/packages/storage/dist/index.d.ts +0 -185
  317. package/packages/storage/dist/index.js +0 -329
  318. package/packages/storage/node_modules/.bin/esbuild +0 -19
  319. package/packages/storage/node_modules/.bin/tsc +0 -22
  320. package/packages/storage/node_modules/.bin/tsserver +0 -22
  321. package/packages/storage/node_modules/.bin/tsup +0 -22
  322. package/packages/storage/node_modules/.bin/tsup-node +0 -22
  323. package/packages/storage/node_modules/.bin/vite +0 -22
  324. package/packages/storage/node_modules/.bin/vitest +0 -22
  325. package/packages/storage/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  326. package/packages/storage/package.json +0 -60
  327. package/packages/storage/src/DownloadBuilder.ts +0 -60
  328. package/packages/storage/src/StorageService.ts +0 -323
  329. package/packages/storage/src/index.ts +0 -2
  330. package/packages/storage/src/path.ts +0 -35
  331. package/packages/storage/src/transform.ts +0 -15
  332. package/packages/storage/tests/download.test.ts +0 -64
  333. package/packages/storage/tests/parity.test.ts +0 -154
  334. package/packages/storage/tests/path.test.ts +0 -87
  335. package/packages/storage/tests/transform.test.ts +0 -79
  336. package/packages/storage/tsconfig.json +0 -5
  337. package/packages/storage/tsup.config.ts +0 -11
  338. package/pnpm-workspace.yaml +0 -24
  339. package/tsconfig.base.json +0 -15
  340. /package/{packages/aurabase/dist → dist}/index.cjs +0 -0
  341. /package/{packages/aurabase/dist → dist}/index.js +0 -0
  342. /package/{packages/aurabase/dist → dist}/ssr.cjs +0 -0
  343. /package/{packages/aurabase/dist → dist}/ssr.js +0 -0
@@ -1,553 +0,0 @@
1
- // Vendored from @supabase/postgrest-js (MIT, Copyright (c) Supabase).
2
- // Provenance précise (version amont, SHA, procédure de resync) : voir packages/db/VENDORED.md
3
- // Adapté pour aurabase — ne pas modifier la logique du parser/résolveur.
4
- import { Ast, ParseQuery } from './parser'
5
- import {
6
- AggregateFunctions,
7
- ExtractFirstProperty,
8
- GenericSchema,
9
- IsNonEmptyArray,
10
- Prettify,
11
- TablesAndViews,
12
- TypeScriptTypes,
13
- ContainsNull,
14
- GenericRelationship,
15
- PostgreSQLTypes,
16
- GenericTable,
17
- ClientServerOptions,
18
- } from './types'
19
- import {
20
- CheckDuplicateEmbededReference,
21
- GetComputedFields,
22
- GetFieldNodeResultName,
23
- IsAny,
24
- IsRelationNullable,
25
- IsStringUnion,
26
- JsonPathToType,
27
- ResolveRelationship,
28
- SelectQueryError,
29
- } from './utils'
30
- import type { SpreadOnManyEnabled } from '../pgrst-types/feature-flags'
31
-
32
- /**
33
- * Main entry point for constructing the result type of a PostgREST query.
34
- *
35
- * @param Schema - Database schema.
36
- * @param Row - The type of a row in the current table.
37
- * @param RelationName - The name of the current table or view.
38
- * @param Relationships - Relationships of the current table.
39
- * @param Query - The select query string literal to parse.
40
- */
41
- export type GetResult<
42
- Schema extends GenericSchema,
43
- Row extends Record<string, unknown>,
44
- RelationName,
45
- Relationships,
46
- Query extends string,
47
- ClientOptions extends ClientServerOptions,
48
- > =
49
- IsAny<Schema> extends true
50
- ? ParseQuery<Query> extends infer ParsedQuery
51
- ? ParsedQuery extends Ast.Node[]
52
- ? RelationName extends string
53
- ? ProcessNodesWithoutSchema<ParsedQuery>
54
- : any
55
- : ParsedQuery
56
- : any
57
- : Relationships extends null // For .rpc calls the passed relationships will be null in that case, the result will always be the function return type
58
- ? ParseQuery<Query> extends infer ParsedQuery
59
- ? ParsedQuery extends Ast.Node[]
60
- ? RPCCallNodes<ParsedQuery, RelationName extends string ? RelationName : 'rpc_call', Row>
61
- : ParsedQuery
62
- : Row
63
- : ParseQuery<Query> extends infer ParsedQuery
64
- ? ParsedQuery extends Ast.Node[]
65
- ? RelationName extends string
66
- ? Relationships extends GenericRelationship[]
67
- ? ProcessNodes<ClientOptions, Schema, Row, RelationName, Relationships, ParsedQuery>
68
- : SelectQueryError<'Invalid Relationships cannot infer result type'>
69
- : SelectQueryError<'Invalid RelationName cannot infer result type'>
70
- : ParsedQuery
71
- : never
72
-
73
- type ProcessSimpleFieldWithoutSchema<Field extends Ast.FieldNode> =
74
- Field['aggregateFunction'] extends AggregateFunctions
75
- ? {
76
- // An aggregate function will always override the column name id.sum() will become sum
77
- // except if it has been aliased
78
- [K in GetFieldNodeResultName<Field>]: Field['castType'] extends PostgreSQLTypes
79
- ? TypeScriptTypes<Field['castType']>
80
- : number
81
- }
82
- : {
83
- // Aliases override the property name in the result
84
- [K in GetFieldNodeResultName<Field>]: Field['castType'] extends PostgreSQLTypes // We apply the detected casted as the result type
85
- ? TypeScriptTypes<Field['castType']>
86
- : any
87
- }
88
-
89
- type ProcessFieldNodeWithoutSchema<Node extends Ast.FieldNode> =
90
- IsNonEmptyArray<Node['children']> extends true
91
- ? {
92
- [K in GetFieldNodeResultName<Node>]: Node['children'] extends Ast.Node[]
93
- ? ProcessNodesWithoutSchema<Node['children']>[]
94
- : ProcessSimpleFieldWithoutSchema<Node>
95
- }
96
- : ProcessSimpleFieldWithoutSchema<Node>
97
-
98
- /**
99
- * Processes a single Node without schema and returns the resulting TypeScript type.
100
- */
101
- type ProcessNodeWithoutSchema<Node extends Ast.Node> = Node extends Ast.StarNode
102
- ? any
103
- : Node extends Ast.SpreadNode
104
- ? Node['target']['children'] extends Ast.StarNode[]
105
- ? any
106
- : Node['target']['children'] extends Ast.FieldNode[]
107
- ? {
108
- [P in Node['target']['children'][number] as GetFieldNodeResultName<P>]: P['castType'] extends PostgreSQLTypes
109
- ? TypeScriptTypes<P['castType']>
110
- : any
111
- }
112
- : any
113
- : Node extends Ast.FieldNode
114
- ? ProcessFieldNodeWithoutSchema<Node>
115
- : any
116
-
117
- /**
118
- * Processes nodes when Schema is any, providing basic type inference
119
- */
120
- type ProcessNodesWithoutSchema<
121
- Nodes extends Ast.Node[],
122
- Acc extends Record<string, unknown> = {},
123
- > = Nodes extends [infer FirstNode, ...infer RestNodes]
124
- ? FirstNode extends Ast.Node
125
- ? RestNodes extends Ast.Node[]
126
- ? ProcessNodeWithoutSchema<FirstNode> extends infer FieldResult
127
- ? FieldResult extends Record<string, unknown>
128
- ? ProcessNodesWithoutSchema<RestNodes, Acc & FieldResult>
129
- : FieldResult
130
- : any
131
- : any
132
- : any
133
- : Prettify<Acc>
134
-
135
- /**
136
- * Processes a single Node from a select chained after a rpc call
137
- *
138
- * @param Row - The type of a row in the current table.
139
- * @param RelationName - The name of the current rpc function
140
- * @param NodeType - The Node to process.
141
- */
142
- export type ProcessRPCNode<
143
- Row extends Record<string, unknown>,
144
- RelationName extends string,
145
- NodeType extends Ast.Node,
146
- > = NodeType['type'] extends Ast.StarNode['type'] // If the selection is *
147
- ? Row
148
- : NodeType['type'] extends Ast.FieldNode['type']
149
- ? ProcessSimpleField<Row, RelationName, Extract<NodeType, Ast.FieldNode>>
150
- : SelectQueryError<'RPC Unsupported node type.'>
151
-
152
- /**
153
- * Process select call that can be chained after an rpc call
154
- */
155
- export type RPCCallNodes<
156
- Nodes extends Ast.Node[],
157
- RelationName extends string,
158
- Row extends Record<string, unknown>,
159
- Acc extends Record<string, unknown> = {}, // Acc is now an object
160
- > = Nodes extends [infer FirstNode, ...infer RestNodes]
161
- ? FirstNode extends Ast.Node
162
- ? RestNodes extends Ast.Node[]
163
- ? ProcessRPCNode<Row, RelationName, FirstNode> extends infer FieldResult
164
- ? FieldResult extends Record<string, unknown>
165
- ? RPCCallNodes<RestNodes, RelationName, Row, Acc & FieldResult>
166
- : FieldResult extends SelectQueryError<infer E>
167
- ? SelectQueryError<E>
168
- : SelectQueryError<'Could not retrieve a valid record or error value'>
169
- : SelectQueryError<'Processing node failed.'>
170
- : SelectQueryError<'Invalid rest nodes array in RPC call'>
171
- : SelectQueryError<'Invalid first node in RPC call'>
172
- : Prettify<Acc>
173
-
174
- /**
175
- * Recursively processes an array of Nodes and accumulates the resulting TypeScript type.
176
- *
177
- * @param Schema - Database schema.
178
- * @param Row - The type of a row in the current table.
179
- * @param RelationName - The name of the current table or view.
180
- * @param Relationships - Relationships of the current table.
181
- * @param Nodes - An array of AST nodes to process.
182
- * @param Acc - Accumulator for the constructed type.
183
- */
184
- export type ProcessNodes<
185
- ClientOptions extends ClientServerOptions,
186
- Schema extends GenericSchema,
187
- Row extends Record<string, unknown>,
188
- RelationName extends string,
189
- Relationships extends GenericRelationship[],
190
- Nodes extends Ast.Node[],
191
- Acc extends Record<string, unknown> = {}, // Acc is now an object
192
- > =
193
- CheckDuplicateEmbededReference<Schema, RelationName, Relationships, Nodes> extends false
194
- ? Nodes extends [infer FirstNode, ...infer RestNodes]
195
- ? FirstNode extends Ast.Node
196
- ? RestNodes extends Ast.Node[]
197
- ? ProcessNode<
198
- ClientOptions,
199
- Schema,
200
- Row,
201
- RelationName,
202
- Relationships,
203
- FirstNode
204
- > extends infer FieldResult
205
- ? FieldResult extends Record<string, unknown>
206
- ? ProcessNodes<
207
- ClientOptions,
208
- Schema,
209
- Row,
210
- RelationName,
211
- Relationships,
212
- RestNodes,
213
- // TODO:
214
- // This SHOULD be `Omit<Acc, keyof FieldResult> & FieldResult` since in the case where the key
215
- // is present in the Acc already, the intersection will create bad intersection types
216
- // (eg: `{ a: number } & { a: { property } }` will become `{ a: number & { property } }`)
217
- // but using Omit here explode the inference complexity resulting in "infinite recursion error" from typescript
218
- // very early (see: 'Check that selecting many fields doesn't yield an possibly infinite recursion error') test
219
- // in this case we can't get above ~10 fields before reaching the recursion error
220
- // If someone find a better way to do this, please do it !
221
- // It'll also allow to fix those two tests:
222
- // - `'join over a 1-M relation with both nullables and non-nullables fields using column name hinting on nested relation'`
223
- // - `'self reference relation via column''`
224
- Acc & FieldResult
225
- >
226
- : FieldResult extends SelectQueryError<infer E>
227
- ? SelectQueryError<E>
228
- : SelectQueryError<'Could not retrieve a valid record or error value'>
229
- : SelectQueryError<'Processing node failed.'>
230
- : SelectQueryError<'Invalid rest nodes array type in ProcessNodes'>
231
- : SelectQueryError<'Invalid first node type in ProcessNodes'>
232
- : Prettify<Acc>
233
- : Prettify<CheckDuplicateEmbededReference<Schema, RelationName, Relationships, Nodes>>
234
-
235
- /**
236
- * Processes a single Node and returns the resulting TypeScript type.
237
- *
238
- * @param Schema - Database schema.
239
- * @param Row - The type of a row in the current table.
240
- * @param RelationName - The name of the current table or view.
241
- * @param Relationships - Relationships of the current table.
242
- * @param NodeType - The Node to process.
243
- */
244
- export type ProcessNode<
245
- ClientOptions extends ClientServerOptions,
246
- Schema extends GenericSchema,
247
- Row extends Record<string, unknown>,
248
- RelationName extends string,
249
- Relationships extends GenericRelationship[],
250
- NodeType extends Ast.Node,
251
- > =
252
- // TODO: figure out why comparing the `type` property is necessary vs. `NodeType extends Ast.StarNode`
253
- NodeType['type'] extends Ast.StarNode['type'] // If the selection is *
254
- ? // If the row has computed field, postgrest will omit them from star selection per default
255
- GetComputedFields<Schema, RelationName> extends never
256
- ? // If no computed fields are detected on the row, we can return it as is
257
- Row
258
- : // otherwise we omit all the computed field from the star result return
259
- Omit<Row, GetComputedFields<Schema, RelationName>>
260
- : NodeType['type'] extends Ast.SpreadNode['type'] // If the selection is a ...spread
261
- ? ProcessSpreadNode<
262
- ClientOptions,
263
- Schema,
264
- Row,
265
- RelationName,
266
- Relationships,
267
- Extract<NodeType, Ast.SpreadNode>
268
- >
269
- : NodeType['type'] extends Ast.FieldNode['type']
270
- ? ProcessFieldNode<
271
- ClientOptions,
272
- Schema,
273
- Row,
274
- RelationName,
275
- Relationships,
276
- Extract<NodeType, Ast.FieldNode>
277
- >
278
- : SelectQueryError<'Unsupported node type.'>
279
-
280
- /**
281
- * Processes a FieldNode and returns the resulting TypeScript type.
282
- *
283
- * @param Schema - Database schema.
284
- * @param Row - The type of a row in the current table.
285
- * @param RelationName - The name of the current table or view.
286
- * @param Relationships - Relationships of the current table.
287
- * @param Field - The FieldNode to process.
288
- */
289
- type ProcessFieldNode<
290
- ClientOptions extends ClientServerOptions,
291
- Schema extends GenericSchema,
292
- Row extends Record<string, unknown>,
293
- RelationName extends string,
294
- Relationships extends GenericRelationship[],
295
- Field extends Ast.FieldNode,
296
- > = Field['children'] extends []
297
- ? // Empty `()` — could be a scalar computed column (e.g. `user_count()`).
298
- // Route through ProcessEmbeddedResource so the scalar path returns the correct
299
- // primitive type. For non-scalar embedded resources with empty selection,
300
- // ProcessEmbeddedResource returns {} (no contribution to result type).
301
- ProcessEmbeddedResource<ClientOptions, Schema, Relationships, Field, RelationName>
302
- : IsNonEmptyArray<Field['children']> extends true // Has embedded resource?
303
- ? ProcessEmbeddedResource<ClientOptions, Schema, Relationships, Field, RelationName>
304
- : ProcessSimpleField<Row, RelationName, Field>
305
-
306
- type ResolveJsonPathType<
307
- Value,
308
- Path extends string | undefined,
309
- CastType extends PostgreSQLTypes,
310
- > = Path extends string
311
- ? JsonPathToType<Value, Path> extends never
312
- ? // Always fallback if JsonPathToType returns never
313
- TypeScriptTypes<CastType>
314
- : JsonPathToType<Value, Path> extends infer PathResult
315
- ? PathResult extends string
316
- ? // Use the result if it's a string as we know that even with the string accessor ->> it's a valid type
317
- PathResult
318
- : IsStringUnion<PathResult> extends true
319
- ? // Use the result if it's a union of strings
320
- PathResult
321
- : CastType extends 'json'
322
- ? // If the type is not a string, ensure it was accessed with json accessor ->
323
- PathResult
324
- : // Otherwise it means non-string value accessed with string accessor ->> use the TypeScriptTypes result
325
- TypeScriptTypes<CastType>
326
- : TypeScriptTypes<CastType>
327
- : // No json path, use regular type casting
328
- TypeScriptTypes<CastType>
329
-
330
- /**
331
- * Processes a simple field (without embedded resources).
332
- *
333
- * @param Row - The type of a row in the current table.
334
- * @param RelationName - The name of the current table or view.
335
- * @param Field - The FieldNode to process.
336
- */
337
- type ProcessSimpleField<
338
- Row extends Record<string, unknown>,
339
- RelationName extends string,
340
- Field extends Ast.FieldNode,
341
- > = Field['name'] extends keyof Row | 'count'
342
- ? Field['aggregateFunction'] extends AggregateFunctions
343
- ? {
344
- // An aggregate function will always override the column name id.sum() will become sum
345
- // except if it has been aliased
346
- [K in GetFieldNodeResultName<Field>]: Field['castType'] extends PostgreSQLTypes
347
- ? TypeScriptTypes<Field['castType']>
348
- : number
349
- }
350
- : {
351
- // Aliases override the property name in the result
352
- [K in GetFieldNodeResultName<Field>]: Field['castType'] extends PostgreSQLTypes
353
- ? ResolveJsonPathType<Row[Field['name']], Field['jsonPath'], Field['castType']>
354
- : Row[Field['name']]
355
- }
356
- : SelectQueryError<`column '${Field['name']}' does not exist on '${RelationName}'.`>
357
-
358
- /**
359
- * Processes an embedded resource (relation).
360
- *
361
- * @param Schema - Database schema.
362
- * @param Row - The type of a row in the current table.
363
- * @param RelationName - The name of the current table or view.
364
- * @param Relationships - Relationships of the current table.
365
- * @param Field - The FieldNode to process.
366
- */
367
- export type ProcessEmbeddedResource<
368
- ClientOptions extends ClientServerOptions,
369
- Schema extends GenericSchema,
370
- Relationships extends GenericRelationship[],
371
- Field extends Ast.FieldNode,
372
- CurrentTableOrView extends keyof TablesAndViews<Schema> & string,
373
- > =
374
- ResolveRelationship<Schema, Relationships, Field, CurrentTableOrView> extends infer Resolved
375
- ? Resolved extends {
376
- scalarType: infer ScalarType
377
- relation: { isSetofReturn?: boolean; isNotNullable?: boolean }
378
- }
379
- ? // Scalar computed column: bypass ProcessNodes and return the primitive type directly.
380
- {
381
- [K in GetFieldNodeResultName<Field>]: Resolved['relation']['isSetofReturn'] extends true
382
- ? ScalarType
383
- : Resolved['relation']['isNotNullable'] extends true
384
- ? ScalarType
385
- : ScalarType | null
386
- }
387
- : Resolved extends {
388
- referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>
389
- relation: GenericRelationship & { match: 'refrel' | 'col' | 'fkname' | 'func' }
390
- direction: string
391
- }
392
- ? Field['children'] extends []
393
- ? // Empty `()` on a regular table embed — no fields selected, contribute nothing.
394
- // This preserves the prior behavior: `users()` does not add a `users` key to the result.
395
- {}
396
- : ProcessEmbeddedResourceResult<
397
- ClientOptions,
398
- Schema,
399
- Resolved,
400
- Field,
401
- CurrentTableOrView
402
- >
403
- : // Otherwise the Resolved is a SelectQueryError return it
404
- { [K in GetFieldNodeResultName<Field>]: Resolved }
405
- : {
406
- [K in GetFieldNodeResultName<Field>]: SelectQueryError<'Failed to resolve relationship.'> &
407
- string
408
- }
409
-
410
- /**
411
- * Helper type to process the result of an embedded resource.
412
- */
413
- type ProcessEmbeddedResourceResult<
414
- ClientOptions extends ClientServerOptions,
415
- Schema extends GenericSchema,
416
- Resolved extends {
417
- referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>
418
- relation: GenericRelationship & {
419
- match: 'refrel' | 'col' | 'fkname' | 'func'
420
- isNotNullable?: boolean
421
- referencedRelation: string
422
- isSetofReturn?: boolean
423
- }
424
- direction: string
425
- },
426
- Field extends Ast.FieldNode,
427
- CurrentTableOrView extends keyof TablesAndViews<Schema>,
428
- > =
429
- ProcessNodes<
430
- ClientOptions,
431
- Schema,
432
- Resolved['referencedTable']['Row'],
433
- // For embeded function selection, the source of truth is the 'referencedRelation'
434
- // coming from the SetofOptions.to parameter
435
- Resolved['relation']['match'] extends 'func'
436
- ? Resolved['relation']['referencedRelation']
437
- : Field['name'],
438
- Resolved['referencedTable']['Relationships'],
439
- Field['children'] extends undefined
440
- ? []
441
- : Exclude<Field['children'], undefined> extends Ast.Node[]
442
- ? Exclude<Field['children'], undefined>
443
- : []
444
- > extends infer ProcessedChildren
445
- ? {
446
- [K in GetFieldNodeResultName<Field>]: Resolved['direction'] extends 'forward'
447
- ? Field extends { innerJoin: true }
448
- ? Resolved['relation']['isOneToOne'] extends true
449
- ? ProcessedChildren
450
- : ProcessedChildren[]
451
- : Resolved['relation']['isOneToOne'] extends true
452
- ? Resolved['relation']['match'] extends 'func'
453
- ? Resolved['relation']['isNotNullable'] extends true
454
- ? Resolved['relation']['isSetofReturn'] extends true
455
- ? ProcessedChildren
456
- : // TODO: This shouldn't be necessary but is due in an inconsitency in PostgREST v12/13 where if a function
457
- // is declared with RETURNS <table-name> instead of RETURNS SETOF <table-name> ROWS 1
458
- // In case where there is no object matching the relations, the object will be returned with all the properties within it
459
- // set to null, we mimic this buggy behavior for type safety an issue is opened on postgREST here:
460
- // https://github.com/PostgREST/postgrest/issues/4234
461
- { [P in keyof ProcessedChildren]: ProcessedChildren[P] | null }
462
- : ProcessedChildren | null
463
- : ProcessedChildren | null
464
- : ProcessedChildren[]
465
- : // If the relation is a self-reference it'll always be considered as reverse relationship
466
- Resolved['relation']['referencedRelation'] extends CurrentTableOrView
467
- ? // It can either be a reverse reference via a column inclusion (eg: parent_id(*))
468
- // in such case the result will be a single object
469
- Resolved['relation']['match'] extends 'col'
470
- ? IsRelationNullable<
471
- TablesAndViews<Schema>[CurrentTableOrView],
472
- Resolved['relation']
473
- > extends true
474
- ? ProcessedChildren | null
475
- : ProcessedChildren
476
- : // Or it can be a reference via the reference relation (eg: collections(*))
477
- // in such case, the result will be an array of all the values (all collection with parent_id being the current id)
478
- ProcessedChildren[]
479
- : // Otherwise if it's a non self-reference reverse relationship it's a single object
480
- IsRelationNullable<
481
- TablesAndViews<Schema>[CurrentTableOrView],
482
- Resolved['relation']
483
- > extends true
484
- ? Field extends { innerJoin: true }
485
- ? ProcessedChildren
486
- : ProcessedChildren | null
487
- : ProcessedChildren
488
- }
489
- : {
490
- [K in GetFieldNodeResultName<Field>]: SelectQueryError<'Failed to process embedded resource nodes.'> &
491
- string
492
- }
493
-
494
- /**
495
- * Processes a SpreadNode by processing its target node.
496
- *
497
- * @param Schema - Database schema.
498
- * @param Row - The type of a row in the current table.
499
- * @param RelationName - The name of the current table or view.
500
- * @param Relationships - Relationships of the current table.
501
- * @param Spread - The SpreadNode to process.
502
- */
503
- type ProcessSpreadNode<
504
- ClientOptions extends ClientServerOptions,
505
- Schema extends GenericSchema,
506
- Row extends Record<string, unknown>,
507
- RelationName extends string,
508
- Relationships extends GenericRelationship[],
509
- Spread extends Ast.SpreadNode,
510
- > =
511
- ProcessNode<
512
- ClientOptions,
513
- Schema,
514
- Row,
515
- RelationName,
516
- Relationships,
517
- Spread['target']
518
- > extends infer Result
519
- ? Result extends SelectQueryError<infer E>
520
- ? SelectQueryError<E>
521
- : ExtractFirstProperty<Result> extends unknown[]
522
- ? SpreadOnManyEnabled<ClientOptions['PostgrestVersion']> extends true // Spread over an many-to-many relationship, turn all the result fields into correlated arrays
523
- ? ProcessManyToManySpreadNodeResult<Result>
524
- : {
525
- [K in Spread['target']['name']]: SelectQueryError<`"${RelationName}" and "${Spread['target']['name']}" do not form a many-to-one or one-to-one relationship spread not possible`>
526
- }
527
- : ProcessSpreadNodeResult<Result>
528
- : never
529
-
530
- /**
531
- * Helper type to process the result of a many-to-many spread node.
532
- * Converts all fields in the spread object into arrays.
533
- */
534
- type ProcessManyToManySpreadNodeResult<Result> =
535
- Result extends Record<string, SelectQueryError<string> | null>
536
- ? Result
537
- : ExtractFirstProperty<Result> extends infer SpreadedObject
538
- ? SpreadedObject extends Array<Record<string, unknown>>
539
- ? { [K in keyof SpreadedObject[number]]: Array<SpreadedObject[number][K]> }
540
- : SelectQueryError<'An error occurred spreading the many-to-many object'>
541
- : SelectQueryError<'An error occurred spreading the many-to-many object'>
542
-
543
- /**
544
- * Helper type to process the result of a spread node.
545
- */
546
- type ProcessSpreadNodeResult<Result> =
547
- Result extends Record<string, SelectQueryError<string> | null>
548
- ? Result
549
- : ExtractFirstProperty<Result> extends infer SpreadedObject
550
- ? ContainsNull<SpreadedObject> extends true
551
- ? Exclude<{ [K in keyof SpreadedObject]: SpreadedObject[K] | null }, null>
552
- : Exclude<{ [K in keyof SpreadedObject]: SpreadedObject[K] }, null>
553
- : SelectQueryError<'An error occurred spreading the object'>
@@ -1,132 +0,0 @@
1
- // Vendored from @supabase/postgrest-js (MIT, Copyright (c) Supabase).
2
- // Provenance précise (version amont, SHA, procédure de resync) : voir packages/db/VENDORED.md
3
- // Adapté pour aurabase — ne pas modifier la logique du parser/résolveur.
4
- import type {
5
- GenericRelationship,
6
- GenericSchema,
7
- GenericTable,
8
- ClientServerOptions,
9
- GenericSetofOption,
10
- GenericFunction,
11
- } from '../pgrst-types/common/common'
12
- import type { Prettify } from '../pgrst-types/types'
13
-
14
- export type {
15
- GenericRelationship,
16
- GenericSchema,
17
- GenericTable,
18
- ClientServerOptions,
19
- GenericSetofOption,
20
- Prettify,
21
- GenericFunction,
22
- }
23
-
24
- export type AggregateWithoutColumnFunctions = 'count'
25
-
26
- export type AggregateWithColumnFunctions =
27
- | 'sum'
28
- | 'avg'
29
- | 'min'
30
- | 'max'
31
- | AggregateWithoutColumnFunctions
32
-
33
- export type AggregateFunctions = AggregateWithColumnFunctions
34
-
35
- export type Json =
36
- | string
37
- | number
38
- | boolean
39
- | null
40
- | {
41
- [key: string]: Json | undefined
42
- }
43
- | Json[]
44
-
45
- type PostgresSQLNumberTypes = 'int2' | 'int4' | 'int8' | 'float4' | 'float8' | 'numeric'
46
-
47
- type PostgresSQLStringTypes =
48
- | 'bytea'
49
- | 'bpchar'
50
- | 'varchar'
51
- | 'date'
52
- | 'text'
53
- | 'citext'
54
- | 'time'
55
- | 'timetz'
56
- | 'timestamp'
57
- | 'timestamptz'
58
- | 'uuid'
59
- | 'vector'
60
-
61
- type SingleValuePostgreSQLTypes =
62
- | PostgresSQLNumberTypes
63
- | PostgresSQLStringTypes
64
- | 'bool'
65
- | 'json'
66
- | 'jsonb'
67
- | 'void'
68
- | 'record'
69
- | string
70
-
71
- type ArrayPostgreSQLTypes = `_${SingleValuePostgreSQLTypes}`
72
-
73
- type TypeScriptSingleValueTypes<T extends SingleValuePostgreSQLTypes> = T extends 'bool'
74
- ? boolean
75
- : T extends PostgresSQLNumberTypes
76
- ? number
77
- : T extends PostgresSQLStringTypes
78
- ? string
79
- : T extends 'json' | 'jsonb'
80
- ? Json
81
- : T extends 'void'
82
- ? undefined
83
- : T extends 'record'
84
- ? Record<string, unknown>
85
- : unknown
86
-
87
- type StripUnderscore<T extends string> = T extends `_${infer U}` ? U : T
88
-
89
- // Represents all possible PostgreSQL types, including array types, allow for custom types with 'string' in union
90
- export type PostgreSQLTypes = SingleValuePostgreSQLTypes | ArrayPostgreSQLTypes
91
-
92
- // Helper type to convert PostgreSQL types to their TypeScript equivalents
93
- export type TypeScriptTypes<T extends PostgreSQLTypes> = T extends ArrayPostgreSQLTypes
94
- ? TypeScriptSingleValueTypes<StripUnderscore<Extract<T, SingleValuePostgreSQLTypes>>>[]
95
- : TypeScriptSingleValueTypes<T>
96
-
97
- // Utility types for working with unions
98
- export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
99
- k: infer I
100
- ) => void
101
- ? I
102
- : never
103
-
104
- export type LastOf<T> =
105
- UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never
106
-
107
- export type Push<T extends any[], V> = [...T, V]
108
-
109
- // Converts a union type to a tuple type
110
- export type UnionToTuple<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = N extends true
111
- ? []
112
- : Push<UnionToTuple<Exclude<T, L>>, L>
113
-
114
- export type UnionToArray<T> = UnionToTuple<T>
115
-
116
- // Extracts the type of the first property in an object type
117
- export type ExtractFirstProperty<T> = T extends { [K in keyof T]: infer U } ? U : never
118
-
119
- // Type predicates
120
- export type ContainsNull<T> = null extends T ? true : false
121
-
122
- export type IsNonEmptyArray<T> =
123
- Exclude<T, undefined> extends readonly [unknown, ...unknown[]] ? true : false
124
-
125
- // Types for working with database schemas
126
- export type TablesAndViews<Schema extends GenericSchema> = Schema['Tables'] &
127
- Exclude<Schema['Views'], ''>
128
-
129
- export type GetTableRelationships<
130
- Schema extends GenericSchema,
131
- Tname extends string,
132
- > = TablesAndViews<Schema>[Tname] extends { Relationships: infer R } ? R : false