@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,1111 +0,0 @@
1
- import { AuraResponse, AuraClientLike, CountMode, BaseService, SchemaTable, SchemaFunction, SchemaEnum } from '@aurabase/core';
2
-
3
- type GenericRelationship = {
4
- foreignKeyName: string;
5
- columns: string[];
6
- isOneToOne?: boolean;
7
- referencedRelation: string;
8
- referencedColumns: string[];
9
- };
10
- type GenericTable = {
11
- Row: Record<string, unknown>;
12
- Insert: Record<string, unknown>;
13
- Update: Record<string, unknown>;
14
- Relationships: GenericRelationship[];
15
- };
16
- type GenericUpdatableView = {
17
- Row: Record<string, unknown>;
18
- Insert: Record<string, unknown>;
19
- Update: Record<string, unknown>;
20
- Relationships: GenericRelationship[];
21
- };
22
- type GenericNonUpdatableView = {
23
- Row: Record<string, unknown>;
24
- Relationships: GenericRelationship[];
25
- };
26
- type GenericView = GenericUpdatableView | GenericNonUpdatableView;
27
- type GenericSetofOption = {
28
- isSetofReturn?: boolean | undefined;
29
- isOneToOne?: boolean | undefined;
30
- isNotNullable?: boolean | undefined;
31
- to: string;
32
- from: string;
33
- };
34
- type GenericFunction = {
35
- Args: Record<string, unknown> | never;
36
- Returns: unknown;
37
- SetofOptions?: GenericSetofOption;
38
- };
39
- type GenericSchema = {
40
- Tables: Record<string, GenericTable>;
41
- Views: Record<string, GenericView>;
42
- Functions: Record<string, GenericFunction>;
43
- };
44
- type ClientServerOptions = {
45
- PostgrestVersion?: string;
46
- };
47
-
48
- type AggregateWithoutColumnFunctions = 'count';
49
- type AggregateWithColumnFunctions = 'sum' | 'avg' | 'min' | 'max' | AggregateWithoutColumnFunctions;
50
- type AggregateFunctions = AggregateWithColumnFunctions;
51
- type Json = string | number | boolean | null | {
52
- [key: string]: Json | undefined;
53
- } | Json[];
54
- type PostgresSQLNumberTypes = 'int2' | 'int4' | 'int8' | 'float4' | 'float8' | 'numeric';
55
- type PostgresSQLStringTypes = 'bytea' | 'bpchar' | 'varchar' | 'date' | 'text' | 'citext' | 'time' | 'timetz' | 'timestamp' | 'timestamptz' | 'uuid' | 'vector';
56
- type SingleValuePostgreSQLTypes = PostgresSQLNumberTypes | PostgresSQLStringTypes | 'bool' | 'json' | 'jsonb' | 'void' | 'record' | string;
57
- type ArrayPostgreSQLTypes = `_${SingleValuePostgreSQLTypes}`;
58
- type TypeScriptSingleValueTypes<T extends SingleValuePostgreSQLTypes> = T extends 'bool' ? boolean : T extends PostgresSQLNumberTypes ? number : T extends PostgresSQLStringTypes ? string : T extends 'json' | 'jsonb' ? Json : T extends 'void' ? undefined : T extends 'record' ? Record<string, unknown> : unknown;
59
- type StripUnderscore<T extends string> = T extends `_${infer U}` ? U : T;
60
- type PostgreSQLTypes = SingleValuePostgreSQLTypes | ArrayPostgreSQLTypes;
61
- type TypeScriptTypes<T extends PostgreSQLTypes> = T extends ArrayPostgreSQLTypes ? TypeScriptSingleValueTypes<StripUnderscore<Extract<T, SingleValuePostgreSQLTypes>>>[] : TypeScriptSingleValueTypes<T>;
62
- type UnionToIntersection$1<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
63
- type LastOf$1<T> = UnionToIntersection$1<T extends any ? () => T : never> extends () => infer R ? R : never;
64
- type Push<T extends any[], V> = [...T, V];
65
- type UnionToTuple<T, L = LastOf$1<T>, N = [T] extends [never] ? true : false> = N extends true ? [] : Push<UnionToTuple<Exclude<T, L>>, L>;
66
- type UnionToArray<T> = UnionToTuple<T>;
67
- type ExtractFirstProperty<T> = T extends {
68
- [K in keyof T]: infer U;
69
- } ? U : never;
70
- type ContainsNull<T> = null extends T ? true : false;
71
- type IsNonEmptyArray<T> = Exclude<T, undefined> extends readonly [unknown, ...unknown[]] ? true : false;
72
- type TablesAndViews$1<Schema extends GenericSchema> = Schema['Tables'] & Exclude<Schema['Views'], ''>;
73
-
74
- type IsAny$1<T> = 0 extends 1 & T ? true : false;
75
- type SelectQueryError<Message extends string> = {
76
- error: true;
77
- } & Message;
78
- type DeduplicateRelationships<T extends readonly unknown[]> = T extends readonly [
79
- infer First,
80
- ...infer Rest
81
- ] ? First extends Rest[number] ? DeduplicateRelationships<Rest extends readonly unknown[] ? Rest : []> : [First, ...DeduplicateRelationships<Rest extends readonly unknown[] ? Rest : []>] : T;
82
- type GetFieldNodeResultName<Field extends Ast.FieldNode> = Field['alias'] extends string ? Field['alias'] : Field['aggregateFunction'] extends AggregateFunctions ? Field['aggregateFunction'] : Field['name'];
83
- type FilterRelationNodes<Nodes extends Ast.Node[]> = UnionToArray<{
84
- [K in keyof Nodes]: Nodes[K] extends Ast.SpreadNode ? Nodes[K]['target'] : Nodes[K] extends Ast.FieldNode ? IsNonEmptyArray<Nodes[K]['children']> extends true ? Nodes[K] : never : never;
85
- }[number]>;
86
- type ResolveRelationships<Schema extends GenericSchema, RelationName extends string, Relationships extends GenericRelationship[], Nodes extends Ast.FieldNode[]> = UnionToArray<{
87
- [K in keyof Nodes]: Nodes[K] extends Ast.FieldNode ? ResolveRelationship<Schema, Relationships, Nodes[K], RelationName> extends infer Relation ? Relation extends {
88
- relation: {
89
- referencedRelation: string;
90
- foreignKeyName: string;
91
- match: string;
92
- };
93
- from: string;
94
- } ? {
95
- referencedTable: Relation['relation']['referencedRelation'];
96
- fkName: Relation['relation']['foreignKeyName'];
97
- from: Relation['from'];
98
- match: Relation['relation']['match'];
99
- fieldName: GetFieldNodeResultName<Nodes[K]>;
100
- } : Relation : never : never;
101
- }>[0];
102
- /**
103
- * Checks if a relation is implicitly referenced twice, requiring disambiguation
104
- */
105
- type IsDoubleReference<T, U> = T extends {
106
- referencedTable: infer RT;
107
- fieldName: infer FN;
108
- match: infer M;
109
- } ? M extends 'col' | 'refrel' ? U extends {
110
- referencedTable: RT;
111
- fieldName: FN;
112
- match: M;
113
- } ? true : false : false : false;
114
- /**
115
- * Compares one element with all other elements in the array to find duplicates
116
- */
117
- type CheckDuplicates<Arr extends any[], Current> = Arr extends [infer Head, ...infer Tail] ? IsDoubleReference<Current, Head> extends true ? Head | CheckDuplicates<Tail, Current> : CheckDuplicates<Tail, Current> : never;
118
- /**
119
- * Iterates over the elements of the array to find duplicates
120
- */
121
- type FindDuplicatesWithinDeduplicated<Arr extends any[]> = Arr extends [infer Head, ...infer Tail] ? CheckDuplicates<Tail, Head> | FindDuplicatesWithinDeduplicated<Tail> : never;
122
- type FindDuplicates<Arr extends any[]> = FindDuplicatesWithinDeduplicated<DeduplicateRelationships<Arr>>;
123
- type CheckDuplicateEmbededReference<Schema extends GenericSchema, RelationName extends string, Relationships extends GenericRelationship[], Nodes extends Ast.Node[]> = FilterRelationNodes<Nodes> extends infer RelationsNodes ? RelationsNodes extends Ast.FieldNode[] ? ResolveRelationships<Schema, RelationName, Relationships, RelationsNodes> extends infer ResolvedRels ? ResolvedRels extends unknown[] ? FindDuplicates<ResolvedRels> extends infer Duplicates ? Duplicates extends never ? false : Duplicates extends {
124
- fieldName: infer FieldName;
125
- } ? FieldName extends string ? {
126
- [K in FieldName]: SelectQueryError<`table "${RelationName}" specified more than once use hinting for desambiguation`>;
127
- } : false : false : false : false : false : false : false;
128
- /**
129
- * Returns a boolean representing whether there is a foreign key referencing
130
- * a given relation.
131
- */
132
- type HasFKeyToFRel<FRelName, Relationships> = Relationships extends [infer R] ? R extends {
133
- referencedRelation: FRelName;
134
- } ? true : false : Relationships extends [infer R, ...infer Rest] ? HasFKeyToFRel<FRelName, [R]> extends true ? true : HasFKeyToFRel<FRelName, Rest> : false;
135
- /**
136
- * Checks if there is more than one relation to a given foreign relation name in the Relationships.
137
- */
138
- type HasMultipleFKeysToFRelDeduplicated<FRelName, Relationships> = Relationships extends [
139
- infer R,
140
- ...infer Rest
141
- ] ? R extends {
142
- referencedRelation: FRelName;
143
- } ? HasFKeyToFRel<FRelName, Rest> extends true ? true : HasMultipleFKeysToFRelDeduplicated<FRelName, Rest> : HasMultipleFKeysToFRelDeduplicated<FRelName, Rest> : false;
144
- type HasMultipleFKeysToFRel<FRelName, Relationships extends unknown[]> = HasMultipleFKeysToFRelDeduplicated<FRelName, DeduplicateRelationships<Relationships>>;
145
- type CheckRelationshipError<Schema extends GenericSchema, Relationships extends GenericRelationship[], CurrentTableOrView extends keyof TablesAndViews$1<Schema> & string, FoundRelation> = FoundRelation extends SelectQueryError<string> ? FoundRelation : FoundRelation extends {
146
- relation: {
147
- referencedRelation: infer RelatedRelationName;
148
- name: string;
149
- };
150
- direction: 'reverse';
151
- } ? RelatedRelationName extends string ? HasMultipleFKeysToFRel<RelatedRelationName, Relationships> extends true ? SelectQueryError<`Could not embed because more than one relationship was found for '${RelatedRelationName}' and '${CurrentTableOrView}' you need to hint the column with ${RelatedRelationName}!<columnName> ?`> : FoundRelation : never : FoundRelation extends {
152
- relation: {
153
- referencedRelation: infer RelatedRelationName;
154
- name: string;
155
- };
156
- direction: 'forward';
157
- from: infer From;
158
- } ? RelatedRelationName extends string ? From extends keyof TablesAndViews$1<Schema> & string ? HasMultipleFKeysToFRel<RelatedRelationName, TablesAndViews$1<Schema>[From]['Relationships']> extends true ? SelectQueryError<`Could not embed because more than one relationship was found for '${From}' and '${RelatedRelationName}' you need to hint the column with ${From}!<columnName> ?`> : FoundRelation : never : never : FoundRelation;
159
- /**
160
- * Resolves relationships for embedded resources and retrieves the referenced Table
161
- */
162
- type ResolveRelationship<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$1<Schema> & string> = ResolveReverseRelationship<Schema, Relationships, Field, CurrentTableOrView> extends infer ReverseRelationship ? ReverseRelationship extends false ? CheckRelationshipError<Schema, Relationships, CurrentTableOrView, ResolveForwardRelationship<Schema, Field, CurrentTableOrView>> : CheckRelationshipError<Schema, Relationships, CurrentTableOrView, ReverseRelationship> : never;
163
- /**
164
- * Resolves reverse relationships (from children to parent)
165
- */
166
- type ResolveReverseRelationship<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$1<Schema> & string> = FindFieldMatchingRelationships<Schema, Relationships, Field> extends infer FoundRelation ? FoundRelation extends never ? false : FoundRelation extends {
167
- referencedRelation: infer RelatedRelationName;
168
- } ? RelatedRelationName extends string ? RelatedRelationName extends keyof TablesAndViews$1<Schema> ? FoundRelation extends {
169
- hint: string;
170
- } ? {
171
- referencedTable: TablesAndViews$1<Schema>[RelatedRelationName];
172
- relation: FoundRelation;
173
- direction: 'reverse';
174
- from: CurrentTableOrView;
175
- } : HasMultipleFKeysToFRel<RelatedRelationName, Relationships> extends true ? SelectQueryError<`Could not embed because more than one relationship was found for '${RelatedRelationName}' and '${CurrentTableOrView}' you need to hint the column with ${RelatedRelationName}!<columnName> ?`> : {
176
- referencedTable: TablesAndViews$1<Schema>[RelatedRelationName];
177
- relation: FoundRelation;
178
- direction: 'reverse';
179
- from: CurrentTableOrView;
180
- } : SelectQueryError<`Relation '${RelatedRelationName}' not found in schema.`> : false : false : false;
181
- type FindMatchingTableRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], value extends string> = Relationships extends [infer R, ...infer Rest] ? Rest extends GenericRelationship[] ? R extends {
182
- referencedRelation: infer ReferencedRelation;
183
- } ? ReferencedRelation extends keyof Schema['Tables'] ? R extends {
184
- foreignKeyName: value;
185
- } ? R & {
186
- match: 'fkname';
187
- } : R extends {
188
- referencedRelation: value;
189
- } ? R & {
190
- match: 'refrel';
191
- } : R extends {
192
- columns: [value];
193
- } ? R & {
194
- match: 'col';
195
- } : FindMatchingTableRelationships<Schema, Rest, value> : FindMatchingTableRelationships<Schema, Rest, value> : false : false : false;
196
- type FindMatchingViewRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], value extends string> = Relationships extends [infer R, ...infer Rest] ? Rest extends GenericRelationship[] ? R extends {
197
- referencedRelation: infer ReferencedRelation;
198
- } ? ReferencedRelation extends keyof Schema['Views'] ? R extends {
199
- foreignKeyName: value;
200
- } ? R & {
201
- match: 'fkname';
202
- } : R extends {
203
- referencedRelation: value;
204
- } ? R & {
205
- match: 'refrel';
206
- } : R extends {
207
- columns: [value];
208
- } ? R & {
209
- match: 'col';
210
- } : FindMatchingViewRelationships<Schema, Rest, value> : FindMatchingViewRelationships<Schema, Rest, value> : false : false : false;
211
- type FindMatchingHintTableRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], hint extends string, name extends string> = Relationships extends [infer R, ...infer Rest] ? Rest extends GenericRelationship[] ? R extends {
212
- referencedRelation: infer ReferencedRelation;
213
- } ? ReferencedRelation extends name ? R extends {
214
- foreignKeyName: hint;
215
- } ? R & {
216
- match: 'fkname';
217
- } : R extends {
218
- referencedRelation: hint;
219
- } ? R & {
220
- match: 'refrel';
221
- } : R extends {
222
- columns: [hint];
223
- } ? R & {
224
- match: 'col';
225
- } : FindMatchingHintTableRelationships<Schema, Rest, hint, name> : FindMatchingHintTableRelationships<Schema, Rest, hint, name> : false : false : false;
226
- type FindMatchingHintViewRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], hint extends string, name extends string> = Relationships extends [infer R, ...infer Rest] ? Rest extends GenericRelationship[] ? R extends {
227
- referencedRelation: infer ReferencedRelation;
228
- } ? ReferencedRelation extends name ? R extends {
229
- foreignKeyName: hint;
230
- } ? R & {
231
- match: 'fkname';
232
- } : R extends {
233
- referencedRelation: hint;
234
- } ? R & {
235
- match: 'refrel';
236
- } : R extends {
237
- columns: [hint];
238
- } ? R & {
239
- match: 'col';
240
- } : FindMatchingHintViewRelationships<Schema, Rest, hint, name> : FindMatchingHintViewRelationships<Schema, Rest, hint, name> : false : false : false;
241
- type IsColumnsNullable<Table extends Pick<GenericTable, 'Row'>, Columns extends (keyof Table['Row'])[]> = Columns extends [infer Column, ...infer Rest] ? Column extends keyof Table['Row'] ? ContainsNull<Table['Row'][Column]> extends true ? true : IsColumnsNullable<Table, Rest extends (keyof Table['Row'])[] ? Rest : []> : false : false;
242
- type IsRelationNullable<Table extends GenericTable, Relation extends GenericRelationship> = IsColumnsNullable<Table, Relation['columns']>;
243
- type TableForwardRelationships<Schema extends GenericSchema, TName> = TName extends keyof TablesAndViews$1<Schema> ? UnionToArray<RecursivelyFindRelationships<Schema, TName, keyof TablesAndViews$1<Schema>>> extends infer R ? R extends (GenericRelationship & {
244
- from: keyof TablesAndViews$1<Schema>;
245
- })[] ? R : [] : [] : [];
246
- type RecursivelyFindRelationships<Schema extends GenericSchema, TName, Keys extends keyof TablesAndViews$1<Schema>> = Keys extends infer K ? K extends keyof TablesAndViews$1<Schema> ? FilterRelationships<TablesAndViews$1<Schema>[K]['Relationships'], TName, K> extends never ? RecursivelyFindRelationships<Schema, TName, Exclude<Keys, K>> : FilterRelationships<TablesAndViews$1<Schema>[K]['Relationships'], TName, K> | RecursivelyFindRelationships<Schema, TName, Exclude<Keys, K>> : false : false;
247
- type FilterRelationships<R, TName, From> = R extends readonly (infer Rel)[] ? Rel extends {
248
- referencedRelation: TName;
249
- } ? Rel & {
250
- from: From;
251
- } : never : never;
252
- type ResolveForwardRelationship<Schema extends GenericSchema, Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$1<Schema> & string> = FindFieldMatchingRelationships<Schema, TablesAndViews$1<Schema>[Field['name']]['Relationships'], Ast.FieldNode & {
253
- name: CurrentTableOrView;
254
- hint: Field['hint'];
255
- }> extends infer FoundByName ? FoundByName extends GenericRelationship ? {
256
- referencedTable: TablesAndViews$1<Schema>[Field['name']];
257
- relation: FoundByName;
258
- direction: 'forward';
259
- from: Field['name'];
260
- type: 'found-by-name';
261
- } : FindFieldMatchingRelationships<Schema, TableForwardRelationships<Schema, CurrentTableOrView>, Field> extends infer FoundByMatch ? FoundByMatch extends GenericRelationship & {
262
- from: keyof TablesAndViews$1<Schema>;
263
- } ? {
264
- referencedTable: TablesAndViews$1<Schema>[FoundByMatch['from']];
265
- relation: FoundByMatch;
266
- direction: 'forward';
267
- from: CurrentTableOrView;
268
- type: 'found-by-match';
269
- } : FindJoinTableRelationship<Schema, CurrentTableOrView, Field['name']> extends infer FoundByJoinTable ? FoundByJoinTable extends GenericRelationship ? {
270
- referencedTable: TablesAndViews$1<Schema>[FoundByJoinTable['referencedRelation']];
271
- relation: FoundByJoinTable & {
272
- match: 'refrel';
273
- };
274
- direction: 'forward';
275
- from: CurrentTableOrView;
276
- type: 'found-by-join-table';
277
- } : ResolveEmbededFunctionJoinTableRelationship<Schema, CurrentTableOrView, Field['name']> extends infer FoundEmbededFunctionJoinTableRelation ? FoundEmbededFunctionJoinTableRelation extends GenericFunction ? FoundEmbededFunctionJoinTableRelation['SetofOptions'] extends GenericSetofOption ? FoundEmbededFunctionJoinTableRelation['SetofOptions']['to'] extends '' ? {
278
- referencedTable: {
279
- Row: Record<string, never>;
280
- Relationships: [];
281
- };
282
- relation: {
283
- foreignKeyName: `${Field['name']}_${CurrentTableOrView}_scalar_forward`;
284
- columns: [];
285
- isOneToOne: false;
286
- referencedColumns: [];
287
- referencedRelation: '';
288
- } & {
289
- match: 'func';
290
- isNotNullable: FoundEmbededFunctionJoinTableRelation['SetofOptions']['isNotNullable'] extends true ? true : FoundEmbededFunctionJoinTableRelation['SetofOptions']['isSetofReturn'] extends true ? false : true;
291
- isSetofReturn: FoundEmbededFunctionJoinTableRelation['SetofOptions']['isSetofReturn'];
292
- };
293
- scalarType: FoundEmbededFunctionJoinTableRelation['Returns'];
294
- direction: 'forward';
295
- from: CurrentTableOrView;
296
- type: 'found-by-embeded-scalar-function';
297
- } : {
298
- referencedTable: TablesAndViews$1<Schema>[FoundEmbededFunctionJoinTableRelation['SetofOptions']['to']];
299
- relation: {
300
- foreignKeyName: `${Field['name']}_${CurrentTableOrView}_${FoundEmbededFunctionJoinTableRelation['SetofOptions']['to']}_forward`;
301
- columns: [];
302
- isOneToOne: FoundEmbededFunctionJoinTableRelation['SetofOptions']['isOneToOne'] extends true ? true : false;
303
- referencedColumns: [];
304
- referencedRelation: FoundEmbededFunctionJoinTableRelation['SetofOptions']['to'];
305
- } & {
306
- match: 'func';
307
- isNotNullable: FoundEmbededFunctionJoinTableRelation['SetofOptions']['isNotNullable'] extends true ? true : FoundEmbededFunctionJoinTableRelation['SetofOptions']['isSetofReturn'] extends true ? false : true;
308
- isSetofReturn: FoundEmbededFunctionJoinTableRelation['SetofOptions']['isSetofReturn'];
309
- };
310
- direction: 'forward';
311
- from: CurrentTableOrView;
312
- type: 'found-by-embeded-function';
313
- } : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`>;
314
- /**
315
- * Given a CurrentTableOrView, finds all join tables to this relation.
316
- * For example, if products and categories are linked via product_categories table:
317
- *
318
- * @example Find join table relationship
319
- * Given:
320
- * - CurrentTableView = 'products'
321
- * - FieldName = "categories"
322
- *
323
- * It should return this relationship from product_categories:
324
- * {
325
- * foreignKeyName: "product_categories_category_id_fkey",
326
- * columns: ["category_id"],
327
- * isOneToOne: false,
328
- * referencedRelation: "categories",
329
- * referencedColumns: ["id"]
330
- * }
331
- */
332
- type ResolveJoinTableRelationship<Schema extends GenericSchema, CurrentTableOrView extends keyof TablesAndViews$1<Schema> & string, FieldName extends string> = {
333
- [TableName in keyof TablesAndViews$1<Schema>]: DeduplicateRelationships<TablesAndViews$1<Schema>[TableName]['Relationships']> extends readonly (infer Rel)[] ? Rel extends {
334
- referencedRelation: CurrentTableOrView;
335
- } ? DeduplicateRelationships<TablesAndViews$1<Schema>[TableName]['Relationships']> extends readonly (infer OtherRel)[] ? OtherRel extends {
336
- referencedRelation: FieldName;
337
- } ? OtherRel : never : never : never : never;
338
- }[keyof TablesAndViews$1<Schema>];
339
- type ResolveEmbededFunctionJoinTableRelationship<Schema extends GenericSchema, CurrentTableOrView extends keyof TablesAndViews$1<Schema> & string, FieldName extends string> = FindMatchingFunctionBySetofFrom<Schema['Functions'][FieldName], CurrentTableOrView> extends infer Fn ? Fn extends GenericFunction ? Fn : false : false;
340
- type FindJoinTableRelationship<Schema extends GenericSchema, CurrentTableOrView extends keyof TablesAndViews$1<Schema> & string, FieldName extends string> = ResolveJoinTableRelationship<Schema, CurrentTableOrView, FieldName> extends infer Result ? [Result] extends [never] ? false : Result : never;
341
- /**
342
- * Finds a matching relationship based on the FieldNode's name and optional hint.
343
- */
344
- type FindFieldMatchingRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field extends Ast.FieldNode> = Field extends {
345
- hint: string;
346
- } ? FindMatchingHintTableRelationships<Schema, Relationships, Field['hint'], Field['name']> extends GenericRelationship ? FindMatchingHintTableRelationships<Schema, Relationships, Field['hint'], Field['name']> & {
347
- branch: 'found-in-table-via-hint';
348
- hint: Field['hint'];
349
- } : FindMatchingHintViewRelationships<Schema, Relationships, Field['hint'], Field['name']> extends GenericRelationship ? FindMatchingHintViewRelationships<Schema, Relationships, Field['hint'], Field['name']> & {
350
- branch: 'found-in-view-via-hint';
351
- hint: Field['hint'];
352
- } : SelectQueryError<'Failed to find matching relation via hint'> : FindMatchingTableRelationships<Schema, Relationships, Field['name']> extends GenericRelationship ? FindMatchingTableRelationships<Schema, Relationships, Field['name']> & {
353
- branch: 'found-in-table-via-name';
354
- name: Field['name'];
355
- } : FindMatchingViewRelationships<Schema, Relationships, Field['name']> extends GenericRelationship ? FindMatchingViewRelationships<Schema, Relationships, Field['name']> & {
356
- branch: 'found-in-view-via-name';
357
- name: Field['name'];
358
- } : SelectQueryError<'Failed to find matching relation via name'>;
359
- type JsonPathToAccessor<Path extends string> = Path extends `${infer P1}->${infer P2}` ? P2 extends `>${infer Rest}` ? JsonPathToAccessor<`${P1}.${Rest}`> : P2 extends string ? JsonPathToAccessor<`${P1}.${P2}`> : Path : Path extends `>${infer Rest}` ? JsonPathToAccessor<Rest> : Path extends `${infer P1}::${infer _}` ? JsonPathToAccessor<P1> : Path extends `${infer P1}${')' | ','}${infer _}` ? P1 : Path;
360
- type JsonPathToType<T, Path extends string> = Path extends '' ? T : ContainsNull<T> extends true ? JsonPathToType<Exclude<T, null>, Path> : Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? JsonPathToType<T[Key], Rest> : never : Path extends keyof T ? T[Path] : never;
361
- type IsStringUnion<T> = string extends T ? false : T extends string ? [T] extends [never] ? false : true : false;
362
- type MatchingFunctionBySetofFrom<Fn extends GenericFunction, TableName extends string> = Fn['SetofOptions'] extends GenericSetofOption ? TableName extends Fn['SetofOptions']['from'] ? Fn : never : false;
363
- type FindMatchingFunctionBySetofFrom<FnUnion, TableName extends string> = FnUnion extends infer Fn extends GenericFunction ? MatchingFunctionBySetofFrom<Fn, TableName> : false;
364
- type ComputedField<Schema extends GenericSchema, RelationName extends keyof TablesAndViews$1<Schema>, FieldName extends keyof TablesAndViews$1<Schema>[RelationName]['Row']> = FieldName extends keyof Schema['Functions'] ? [Schema['Functions'][FieldName]['Args']] extends [never] ? never : Schema['Functions'][FieldName] extends {
365
- Args: {
366
- '': TablesAndViews$1<Schema>[RelationName]['Row'];
367
- };
368
- Returns: any;
369
- } ? FieldName : never : never;
370
- type GetComputedFields<Schema extends GenericSchema, RelationName extends keyof TablesAndViews$1<Schema>> = {
371
- [K in keyof TablesAndViews$1<Schema>[RelationName]['Row']]: ComputedField<Schema, RelationName, K>;
372
- }[keyof TablesAndViews$1<Schema>[RelationName]['Row']];
373
-
374
- type Prettify<T> = {
375
- [K in keyof T]: T[K];
376
- } & {};
377
- type SimplifyDeep<Type, ExcludeType = never> = ConditionalSimplifyDeep<Type, ExcludeType | NonRecursiveType | Set<unknown> | Map<unknown, unknown>, object>;
378
- type ConditionalSimplifyDeep<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType ? Type : Type extends IncludeType ? {
379
- [TypeKey in keyof Type]: ConditionalSimplifyDeep<Type[TypeKey], ExcludeType, IncludeType>;
380
- } : Type;
381
- type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
382
- type BuiltIns = Primitive | void | Date | RegExp;
383
- type Primitive = null | undefined | string | number | boolean | symbol | bigint;
384
-
385
- /**
386
- * Parses a query.
387
- * A query is a sequence of nodes, separated by `,`, ensuring that there is
388
- * no remaining input after all nodes have been parsed.
389
- *
390
- * Returns an array of parsed nodes, or an error.
391
- */
392
- type ParseQuery<Query extends string> = string extends Query ? GenericStringError : ParseNodes<EatWhitespace<Query>> extends [infer Nodes, `${infer Remainder}`] ? Nodes extends Ast.Node[] ? EatWhitespace<Remainder> extends '' ? SimplifyDeep<Nodes> : ParserError<`Unexpected input: ${Remainder}`> : ParserError<'Invalid nodes array structure'> : ParseNodes<EatWhitespace<Query>>;
393
- /**
394
- * Notes: all `Parse*` types assume that their input strings have their whitespace
395
- * removed. They return tuples of ["Return Value", "Remainder of text"] or
396
- * a `ParserError`.
397
- */
398
- /**
399
- * Parses a sequence of nodes, separated by `,`.
400
- *
401
- * Returns a tuple of ["Parsed fields", "Remainder of text"] or an error.
402
- */
403
- type ParseNodes<Input extends string> = string extends Input ? GenericStringError : ParseNodesHelper<Input, []>;
404
- type ParseNodesHelper<Input extends string, Nodes extends Ast.Node[]> = ParseNode<Input> extends [infer Node, `${infer Remainder}`] ? Node extends Ast.Node ? EatWhitespace<Remainder> extends `,${infer Remainder}` ? ParseNodesHelper<EatWhitespace<Remainder>, [...Nodes, Node]> : [[...Nodes, Node], EatWhitespace<Remainder>] : ParserError<'Invalid node type in nodes helper'> : ParseNode<Input>;
405
- /**
406
- * Parses a node.
407
- * A node is one of the following:
408
- * - `*`
409
- * - a field, as defined above
410
- * - a renamed field, `renamed_field:field`
411
- * - a spread field, `...field`
412
- */
413
- type ParseNode<Input extends string> = Input extends '' ? ParserError<'Empty string'> : Input extends `*${infer Remainder}` ? [Ast.StarNode, EatWhitespace<Remainder>] : Input extends `...${infer Remainder}` ? ParseField<EatWhitespace<Remainder>> extends [infer TargetField, `${infer Remainder}`] ? TargetField extends Ast.FieldNode ? [{
414
- type: 'spread';
415
- target: TargetField;
416
- }, EatWhitespace<Remainder>] : ParserError<'Invalid target field type in spread'> : ParserError<`Unable to parse spread resource at \`${Input}\``> : ParseIdentifier<Input> extends [infer NameOrAlias, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `::${infer _}` ? ParseField<Input> : EatWhitespace<Remainder> extends `:${infer Remainder}` ? ParseField<EatWhitespace<Remainder>> extends [infer Field, `${infer Remainder}`] ? Field extends Ast.FieldNode ? [Omit<Field, 'alias'> & {
417
- alias: NameOrAlias;
418
- }, EatWhitespace<Remainder>] : ParserError<'Invalid field type in alias parsing'> : ParserError<`Unable to parse renamed field at \`${Input}\``> : ParseField<Input> : ParserError<`Expected identifier at \`${Input}\``>;
419
- /**
420
- * Parses a field without preceding alias.
421
- * A field is one of the following:
422
- * - a top-level `count` field: https://docs.postgrest.org/en/v12/references/api/aggregate_functions.html#the-case-of-count
423
- * - a field with an embedded resource
424
- * - `field(nodes)`
425
- * - `field!hint(nodes)`
426
- * - `field!inner(nodes)`
427
- * - `field!left(nodes)`
428
- * - `field!hint!inner(nodes)`
429
- * - `field!hint!left(nodes)`
430
- * - a field without an embedded resource (see {@link ParseNonEmbeddedResourceField})
431
- */
432
- type ParseField<Input extends string> = Input extends '' ? ParserError<'Empty string'> : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? Name extends 'count' ? ParseCountField<Input> : Remainder extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
433
- infer Children,
434
- `${infer Remainder}`
435
- ] ? Children extends Ast.Node[] ? [
436
- {
437
- type: 'field';
438
- name: Name;
439
- innerJoin: true;
440
- children: Children;
441
- },
442
- Remainder
443
- ] : ParserError<'Invalid children array in inner join'> : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, `Expected embedded resource after "!inner" at \`${Remainder}\``> : EatWhitespace<Remainder> extends `!left${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
444
- infer Children,
445
- `${infer Remainder}`
446
- ] ? Children extends Ast.Node[] ? [
447
- {
448
- type: 'field';
449
- name: Name;
450
- children: Children;
451
- },
452
- EatWhitespace<Remainder>
453
- ] : ParserError<'Invalid children array in left join'> : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, `Expected embedded resource after "!left" at \`${EatWhitespace<Remainder>}\``> : EatWhitespace<Remainder> extends `!${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer Hint, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
454
- infer Children,
455
- `${infer Remainder}`
456
- ] ? Children extends Ast.Node[] ? [
457
- {
458
- type: 'field';
459
- name: Name;
460
- hint: Hint;
461
- innerJoin: true;
462
- children: Children;
463
- },
464
- EatWhitespace<Remainder>
465
- ] : ParserError<'Invalid children array in hint inner join'> : ParseEmbeddedResource<EatWhitespace<Remainder>> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
466
- infer Children,
467
- `${infer Remainder}`
468
- ] ? Children extends Ast.Node[] ? [
469
- {
470
- type: 'field';
471
- name: Name;
472
- hint: Hint;
473
- children: Children;
474
- },
475
- EatWhitespace<Remainder>
476
- ] : ParserError<'Invalid children array in hint'> : ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<`Expected identifier after "!" at \`${EatWhitespace<Remainder>}\``> : EatWhitespace<Remainder> extends `(${infer _}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
477
- infer Children,
478
- `${infer Remainder}`
479
- ] ? Children extends Ast.Node[] ? [
480
- {
481
- type: 'field';
482
- name: Name;
483
- children: Children;
484
- },
485
- EatWhitespace<Remainder>
486
- ] : ParserError<'Invalid children array in field'> : ParseEmbeddedResource<EatWhitespace<Remainder>> : ParseNonEmbeddedResourceField<Input> : ParserError<`Expected identifier at \`${Input}\``>;
487
- type ParseCountField<Input extends string> = ParseIdentifier<Input> extends ['count', `${infer Remainder}`] ? (EatWhitespace<Remainder> extends `()${infer Remainder_}` ? EatWhitespace<Remainder_> : EatWhitespace<Remainder>) extends `${infer Remainder}` ? Remainder extends `::${infer _}` ? ParseFieldTypeCast<Remainder> extends [infer CastType, `${infer Remainder}`] ? [
488
- {
489
- type: 'field';
490
- name: 'count';
491
- aggregateFunction: 'count';
492
- castType: CastType;
493
- },
494
- Remainder
495
- ] : ParseFieldTypeCast<Remainder> : [{
496
- type: 'field';
497
- name: 'count';
498
- aggregateFunction: 'count';
499
- }, Remainder] : never : ParserError<`Expected "count" at \`${Input}\``>;
500
- /**
501
- * Parses an embedded resource, which is an opening `(`, followed by a sequence of
502
- * 0 or more nodes separated by `,`, then a closing `)`.
503
- *
504
- * Returns a tuple of ["Parsed fields", "Remainder of text"], an error,
505
- * or the original string input indicating that no opening `(` was found.
506
- */
507
- type ParseEmbeddedResource<Input extends string> = Input extends `(${infer Remainder}` ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? [[], EatWhitespace<Remainder>] : ParseNodes<EatWhitespace<Remainder>> extends [infer Nodes, `${infer Remainder}`] ? Nodes extends Ast.Node[] ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? [Nodes, EatWhitespace<Remainder>] : ParserError<`Expected ")" at \`${EatWhitespace<Remainder>}\``> : ParserError<'Invalid nodes array in embedded resource'> : ParseNodes<EatWhitespace<Remainder>> : ParserError<`Expected "(" at \`${Input}\``>;
508
- /**
509
- * Parses a field excluding embedded resources, without preceding field renaming.
510
- * This is one of the following:
511
- * - `field`
512
- * - `field.aggregate()`
513
- * - `field.aggregate()::type`
514
- * - `field::type`
515
- * - `field::type.aggregate()`
516
- * - `field::type.aggregate()::type`
517
- * - `field->json...`
518
- * - `field->json.aggregate()`
519
- * - `field->json.aggregate()::type`
520
- * - `field->json::type`
521
- * - `field->json::type.aggregate()`
522
- * - `field->json::type.aggregate()::type`
523
- */
524
- type ParseNonEmbeddedResourceField<Input extends string> = ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? (Remainder extends `->${infer PathAndRest}` ? ParseJsonAccessor<Remainder> extends [
525
- infer PropertyName,
526
- infer PropertyType,
527
- `${infer Remainder}`
528
- ] ? [
529
- {
530
- type: 'field';
531
- name: Name;
532
- alias: PropertyName;
533
- castType: PropertyType;
534
- jsonPath: JsonPathToAccessor<PathAndRest extends `${infer Path},${string}` ? Path : PathAndRest>;
535
- },
536
- Remainder
537
- ] : ParseJsonAccessor<Remainder> : [{
538
- type: 'field';
539
- name: Name;
540
- }, Remainder]) extends infer Parsed ? Parsed extends [infer Field, `${infer Remainder}`] ? (Remainder extends `::${infer _}` ? ParseFieldTypeCast<Remainder> extends [infer CastType, `${infer Remainder}`] ? [Omit<Field, 'castType'> & {
541
- castType: CastType;
542
- }, Remainder] : ParseFieldTypeCast<Remainder> : [Field, Remainder]) extends infer Parsed ? Parsed extends [infer Field, `${infer Remainder}`] ? Remainder extends `.${infer _}` ? ParseFieldAggregation<Remainder> extends [
543
- infer AggregateFunction,
544
- `${infer Remainder}`
545
- ] ? Remainder extends `::${infer _}` ? ParseFieldTypeCast<Remainder> extends [infer CastType, `${infer Remainder}`] ? [
546
- Omit<Field, 'castType'> & {
547
- aggregateFunction: AggregateFunction;
548
- castType: CastType;
549
- },
550
- Remainder
551
- ] : ParseFieldTypeCast<Remainder> : [Field & {
552
- aggregateFunction: AggregateFunction;
553
- }, Remainder] : ParseFieldAggregation<Remainder> : [Field, Remainder] : Parsed : never : Parsed : never : ParserError<`Expected identifier at \`${Input}\``>;
554
- /**
555
- * Parses a JSON property accessor of the shape `->a->b->c`. The last accessor in
556
- * the series may convert to text by using the ->> operator instead of ->.
557
- *
558
- * Returns a tuple of ["Last property name", "Last property type", "Remainder of text"]
559
- */
560
- type ParseJsonAccessor<Input extends string> = Input extends `->${infer Remainder}` ? Remainder extends `>${infer Remainder}` ? ParseIdentifier<Remainder> extends [infer Name, `${infer Remainder}`] ? [Name, 'text', EatWhitespace<Remainder>] : ParserError<'Expected property name after `->>`'> : ParseIdentifier<Remainder> extends [infer Name, `${infer Remainder}`] ? ParseJsonAccessor<Remainder> extends [
561
- infer PropertyName,
562
- infer PropertyType,
563
- `${infer Remainder}`
564
- ] ? [PropertyName, PropertyType, EatWhitespace<Remainder>] : [Name, 'json', EatWhitespace<Remainder>] : ParserError<'Expected property name after `->`'> : ParserError<'Expected ->'>;
565
- /**
566
- * Parses a field typecast (`::type`), returning a tuple of ["Type", "Remainder of text"].
567
- */
568
- type ParseFieldTypeCast<Input extends string> = EatWhitespace<Input> extends `::${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [`${infer CastType}`, `${infer Remainder}`] ? [CastType, EatWhitespace<Remainder>] : ParserError<`Invalid type for \`::\` operator at \`${Remainder}\``> : ParserError<'Expected ::'>;
569
- /**
570
- * Parses a field aggregation (`.max()`), returning a tuple of ["Aggregate function", "Remainder of text"]
571
- */
572
- type ParseFieldAggregation<Input extends string> = EatWhitespace<Input> extends `.${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [
573
- `${infer FunctionName}`,
574
- `${infer Remainder}`
575
- ] ? FunctionName extends Token.AggregateFunction ? EatWhitespace<Remainder> extends `()${infer Remainder}` ? [FunctionName, EatWhitespace<Remainder>] : ParserError<`Expected \`()\` after \`.\` operator \`${FunctionName}\``> : ParserError<`Invalid type for \`.\` operator \`${FunctionName}\``> : ParserError<`Invalid type for \`.\` operator at \`${Remainder}\``> : ParserError<'Expected .'>;
576
- /**
577
- * Parses a (possibly double-quoted) identifier.
578
- * Identifiers are sequences of 1 or more letters.
579
- */
580
- type ParseIdentifier<Input extends string> = ParseLetters<Input> extends [infer Name, `${infer Remainder}`] ? [Name, EatWhitespace<Remainder>] : ParseQuotedLetters<Input> extends [infer Name, `${infer Remainder}`] ? [Name, EatWhitespace<Remainder>] : ParserError<`No (possibly double-quoted) identifier at \`${Input}\``>;
581
- /**
582
- * Parse a consecutive sequence of 1 or more letter, where letters are `[0-9a-zA-Z_]`.
583
- */
584
- type ParseLetters<Input extends string> = string extends Input ? GenericStringError : ParseLettersHelper<Input, ''> extends [`${infer Letters}`, `${infer Remainder}`] ? Letters extends '' ? ParserError<`Expected letter at \`${Input}\``> : [Letters, Remainder] : ParseLettersHelper<Input, ''>;
585
- type ParseLettersHelper<Input extends string, Acc extends string> = string extends Input ? GenericStringError : Input extends `${infer L}${infer Remainder}` ? L extends Token.Letter ? ParseLettersHelper<Remainder, `${Acc}${L}`> : [Acc, Input] : [Acc, ''];
586
- /**
587
- * Parse a consecutive sequence of 1 or more double-quoted letters,
588
- * where letters are `[^"]`.
589
- */
590
- type ParseQuotedLetters<Input extends string> = string extends Input ? GenericStringError : Input extends `"${infer Remainder}` ? ParseQuotedLettersHelper<Remainder, ''> extends [`${infer Letters}`, `${infer Remainder}`] ? Letters extends '' ? ParserError<`Expected string at \`${Remainder}\``> : [Letters, Remainder] : ParseQuotedLettersHelper<Remainder, ''> : ParserError<`Not a double-quoted string at \`${Input}\``>;
591
- type ParseQuotedLettersHelper<Input extends string, Acc extends string> = string extends Input ? GenericStringError : Input extends `${infer L}${infer Remainder}` ? L extends '"' ? [Acc, Remainder] : ParseQuotedLettersHelper<Remainder, `${Acc}${L}`> : ParserError<`Missing closing double-quote in \`"${Acc}${Input}\``>;
592
- /**
593
- * Trims whitespace from the left of the input.
594
- */
595
- type EatWhitespace<Input extends string> = string extends Input ? GenericStringError : Input extends `${Token.Whitespace}${infer Remainder}` ? EatWhitespace<Remainder> : Input;
596
- /**
597
- * Creates a new {@link ParserError} if the given input is not already a parser error.
598
- */
599
- type CreateParserErrorIfRequired<Input, Message extends string> = Input extends ParserError<string> ? Input : ParserError<Message>;
600
- /**
601
- * Parser errors.
602
- */
603
- type ParserError<Message extends string> = {
604
- error: true;
605
- } & Message;
606
- type GenericStringError = ParserError<'Received a generic string'>;
607
- declare namespace Ast {
608
- type Node = FieldNode | StarNode | SpreadNode;
609
- type FieldNode = {
610
- type: 'field';
611
- name: string;
612
- alias?: string;
613
- hint?: string;
614
- innerJoin?: true;
615
- castType?: string;
616
- jsonPath?: string;
617
- aggregateFunction?: Token.AggregateFunction;
618
- children?: Node[];
619
- };
620
- type StarNode = {
621
- type: 'star';
622
- };
623
- type SpreadNode = {
624
- type: 'spread';
625
- target: FieldNode & {
626
- children: Node[];
627
- };
628
- };
629
- }
630
- declare namespace Token {
631
- export type Whitespace = ' ' | '\n' | '\t';
632
- type LowerAlphabet = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
633
- type Alphabet = LowerAlphabet | Uppercase<LowerAlphabet>;
634
- type Digit = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '0';
635
- export type Letter = Alphabet | Digit | '_';
636
- export type AggregateFunction = 'count' | 'sum' | 'avg' | 'min' | 'max';
637
- export { };
638
- }
639
-
640
- type IsPostgrest13<PostgrestVersion extends string | undefined> = PostgrestVersion extends `13${string}` ? true : false;
641
- type IsPostgrest14<PostgrestVersion extends string | undefined> = PostgrestVersion extends `14${string}` ? true : false;
642
- type IsPostgrestVersionGreaterThan12<PostgrestVersion extends string | undefined> = IsPostgrest13<PostgrestVersion> extends true ? true : IsPostgrest14<PostgrestVersion> extends true ? true : false;
643
- type SpreadOnManyEnabled<PostgrestVersion extends string | undefined> = IsPostgrestVersionGreaterThan12<PostgrestVersion> extends true ? true : false;
644
-
645
- /**
646
- * Main entry point for constructing the result type of a PostgREST query.
647
- *
648
- * @param Schema - Database schema.
649
- * @param Row - The type of a row in the current table.
650
- * @param RelationName - The name of the current table or view.
651
- * @param Relationships - Relationships of the current table.
652
- * @param Query - The select query string literal to parse.
653
- */
654
- type GetResult<Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName, Relationships, Query extends string, ClientOptions extends ClientServerOptions> = IsAny$1<Schema> extends true ? ParseQuery<Query> extends infer ParsedQuery ? ParsedQuery extends Ast.Node[] ? RelationName extends string ? ProcessNodesWithoutSchema<ParsedQuery> : any : ParsedQuery : any : Relationships extends null ? ParseQuery<Query> extends infer ParsedQuery ? ParsedQuery extends Ast.Node[] ? RPCCallNodes<ParsedQuery, RelationName extends string ? RelationName : 'rpc_call', Row> : ParsedQuery : Row : ParseQuery<Query> extends infer ParsedQuery ? ParsedQuery extends Ast.Node[] ? RelationName extends string ? Relationships extends GenericRelationship[] ? ProcessNodes<ClientOptions, Schema, Row, RelationName, Relationships, ParsedQuery> : SelectQueryError<'Invalid Relationships cannot infer result type'> : SelectQueryError<'Invalid RelationName cannot infer result type'> : ParsedQuery : never;
655
- type ProcessSimpleFieldWithoutSchema<Field extends Ast.FieldNode> = Field['aggregateFunction'] extends AggregateFunctions ? {
656
- [K in GetFieldNodeResultName<Field>]: Field['castType'] extends PostgreSQLTypes ? TypeScriptTypes<Field['castType']> : number;
657
- } : {
658
- [K in GetFieldNodeResultName<Field>]: Field['castType'] extends PostgreSQLTypes ? TypeScriptTypes<Field['castType']> : any;
659
- };
660
- type ProcessFieldNodeWithoutSchema<Node extends Ast.FieldNode> = IsNonEmptyArray<Node['children']> extends true ? {
661
- [K in GetFieldNodeResultName<Node>]: Node['children'] extends Ast.Node[] ? ProcessNodesWithoutSchema<Node['children']>[] : ProcessSimpleFieldWithoutSchema<Node>;
662
- } : ProcessSimpleFieldWithoutSchema<Node>;
663
- /**
664
- * Processes a single Node without schema and returns the resulting TypeScript type.
665
- */
666
- type ProcessNodeWithoutSchema<Node extends Ast.Node> = Node extends Ast.StarNode ? any : Node extends Ast.SpreadNode ? Node['target']['children'] extends Ast.StarNode[] ? any : Node['target']['children'] extends Ast.FieldNode[] ? {
667
- [P in Node['target']['children'][number] as GetFieldNodeResultName<P>]: P['castType'] extends PostgreSQLTypes ? TypeScriptTypes<P['castType']> : any;
668
- } : any : Node extends Ast.FieldNode ? ProcessFieldNodeWithoutSchema<Node> : any;
669
- /**
670
- * Processes nodes when Schema is any, providing basic type inference
671
- */
672
- type ProcessNodesWithoutSchema<Nodes extends Ast.Node[], Acc extends Record<string, unknown> = {}> = Nodes extends [infer FirstNode, ...infer RestNodes] ? FirstNode extends Ast.Node ? RestNodes extends Ast.Node[] ? ProcessNodeWithoutSchema<FirstNode> extends infer FieldResult ? FieldResult extends Record<string, unknown> ? ProcessNodesWithoutSchema<RestNodes, Acc & FieldResult> : FieldResult : any : any : any : Prettify<Acc>;
673
- /**
674
- * Processes a single Node from a select chained after a rpc call
675
- *
676
- * @param Row - The type of a row in the current table.
677
- * @param RelationName - The name of the current rpc function
678
- * @param NodeType - The Node to process.
679
- */
680
- type ProcessRPCNode<Row extends Record<string, unknown>, RelationName extends string, NodeType extends Ast.Node> = NodeType['type'] extends Ast.StarNode['type'] ? Row : NodeType['type'] extends Ast.FieldNode['type'] ? ProcessSimpleField<Row, RelationName, Extract<NodeType, Ast.FieldNode>> : SelectQueryError<'RPC Unsupported node type.'>;
681
- /**
682
- * Process select call that can be chained after an rpc call
683
- */
684
- type RPCCallNodes<Nodes extends Ast.Node[], RelationName extends string, Row extends Record<string, unknown>, Acc extends Record<string, unknown> = {}> = Nodes extends [infer FirstNode, ...infer RestNodes] ? FirstNode extends Ast.Node ? RestNodes extends Ast.Node[] ? ProcessRPCNode<Row, RelationName, FirstNode> extends infer FieldResult ? FieldResult extends Record<string, unknown> ? RPCCallNodes<RestNodes, RelationName, Row, Acc & FieldResult> : FieldResult extends SelectQueryError<infer E> ? SelectQueryError<E> : SelectQueryError<'Could not retrieve a valid record or error value'> : SelectQueryError<'Processing node failed.'> : SelectQueryError<'Invalid rest nodes array in RPC call'> : SelectQueryError<'Invalid first node in RPC call'> : Prettify<Acc>;
685
- /**
686
- * Recursively processes an array of Nodes and accumulates the resulting TypeScript type.
687
- *
688
- * @param Schema - Database schema.
689
- * @param Row - The type of a row in the current table.
690
- * @param RelationName - The name of the current table or view.
691
- * @param Relationships - Relationships of the current table.
692
- * @param Nodes - An array of AST nodes to process.
693
- * @param Acc - Accumulator for the constructed type.
694
- */
695
- type ProcessNodes<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName extends string, Relationships extends GenericRelationship[], Nodes extends Ast.Node[], Acc extends Record<string, unknown> = {}> = CheckDuplicateEmbededReference<Schema, RelationName, Relationships, Nodes> extends false ? Nodes extends [infer FirstNode, ...infer RestNodes] ? FirstNode extends Ast.Node ? RestNodes extends Ast.Node[] ? ProcessNode<ClientOptions, Schema, Row, RelationName, Relationships, FirstNode> extends infer FieldResult ? FieldResult extends Record<string, unknown> ? ProcessNodes<ClientOptions, Schema, Row, RelationName, Relationships, RestNodes, Acc & FieldResult> : FieldResult extends SelectQueryError<infer E> ? SelectQueryError<E> : SelectQueryError<'Could not retrieve a valid record or error value'> : SelectQueryError<'Processing node failed.'> : SelectQueryError<'Invalid rest nodes array type in ProcessNodes'> : SelectQueryError<'Invalid first node type in ProcessNodes'> : Prettify<Acc> : Prettify<CheckDuplicateEmbededReference<Schema, RelationName, Relationships, Nodes>>;
696
- /**
697
- * Processes a single Node and returns the resulting TypeScript type.
698
- *
699
- * @param Schema - Database schema.
700
- * @param Row - The type of a row in the current table.
701
- * @param RelationName - The name of the current table or view.
702
- * @param Relationships - Relationships of the current table.
703
- * @param NodeType - The Node to process.
704
- */
705
- type ProcessNode<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName extends string, Relationships extends GenericRelationship[], NodeType extends Ast.Node> = NodeType['type'] extends Ast.StarNode['type'] ? GetComputedFields<Schema, RelationName> extends never ? Row : Omit<Row, GetComputedFields<Schema, RelationName>> : NodeType['type'] extends Ast.SpreadNode['type'] ? ProcessSpreadNode<ClientOptions, Schema, Row, RelationName, Relationships, Extract<NodeType, Ast.SpreadNode>> : NodeType['type'] extends Ast.FieldNode['type'] ? ProcessFieldNode<ClientOptions, Schema, Row, RelationName, Relationships, Extract<NodeType, Ast.FieldNode>> : SelectQueryError<'Unsupported node type.'>;
706
- /**
707
- * Processes a FieldNode and returns the resulting TypeScript type.
708
- *
709
- * @param Schema - Database schema.
710
- * @param Row - The type of a row in the current table.
711
- * @param RelationName - The name of the current table or view.
712
- * @param Relationships - Relationships of the current table.
713
- * @param Field - The FieldNode to process.
714
- */
715
- type ProcessFieldNode<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName extends string, Relationships extends GenericRelationship[], Field extends Ast.FieldNode> = Field['children'] extends [] ? ProcessEmbeddedResource<ClientOptions, Schema, Relationships, Field, RelationName> : IsNonEmptyArray<Field['children']> extends true ? ProcessEmbeddedResource<ClientOptions, Schema, Relationships, Field, RelationName> : ProcessSimpleField<Row, RelationName, Field>;
716
- type ResolveJsonPathType<Value, Path extends string | undefined, CastType extends PostgreSQLTypes> = Path extends string ? JsonPathToType<Value, Path> extends never ? TypeScriptTypes<CastType> : JsonPathToType<Value, Path> extends infer PathResult ? PathResult extends string ? PathResult : IsStringUnion<PathResult> extends true ? PathResult : CastType extends 'json' ? PathResult : TypeScriptTypes<CastType> : TypeScriptTypes<CastType> : TypeScriptTypes<CastType>;
717
- /**
718
- * Processes a simple field (without embedded resources).
719
- *
720
- * @param Row - The type of a row in the current table.
721
- * @param RelationName - The name of the current table or view.
722
- * @param Field - The FieldNode to process.
723
- */
724
- type ProcessSimpleField<Row extends Record<string, unknown>, RelationName extends string, Field extends Ast.FieldNode> = Field['name'] extends keyof Row | 'count' ? Field['aggregateFunction'] extends AggregateFunctions ? {
725
- [K in GetFieldNodeResultName<Field>]: Field['castType'] extends PostgreSQLTypes ? TypeScriptTypes<Field['castType']> : number;
726
- } : {
727
- [K in GetFieldNodeResultName<Field>]: Field['castType'] extends PostgreSQLTypes ? ResolveJsonPathType<Row[Field['name']], Field['jsonPath'], Field['castType']> : Row[Field['name']];
728
- } : SelectQueryError<`column '${Field['name']}' does not exist on '${RelationName}'.`>;
729
- /**
730
- * Processes an embedded resource (relation).
731
- *
732
- * @param Schema - Database schema.
733
- * @param Row - The type of a row in the current table.
734
- * @param RelationName - The name of the current table or view.
735
- * @param Relationships - Relationships of the current table.
736
- * @param Field - The FieldNode to process.
737
- */
738
- type ProcessEmbeddedResource<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Relationships extends GenericRelationship[], Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$1<Schema> & string> = ResolveRelationship<Schema, Relationships, Field, CurrentTableOrView> extends infer Resolved ? Resolved extends {
739
- scalarType: infer ScalarType;
740
- relation: {
741
- isSetofReturn?: boolean;
742
- isNotNullable?: boolean;
743
- };
744
- } ? {
745
- [K in GetFieldNodeResultName<Field>]: Resolved['relation']['isSetofReturn'] extends true ? ScalarType : Resolved['relation']['isNotNullable'] extends true ? ScalarType : ScalarType | null;
746
- } : Resolved extends {
747
- referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>;
748
- relation: GenericRelationship & {
749
- match: 'refrel' | 'col' | 'fkname' | 'func';
750
- };
751
- direction: string;
752
- } ? Field['children'] extends [] ? {} : ProcessEmbeddedResourceResult<ClientOptions, Schema, Resolved, Field, CurrentTableOrView> : {
753
- [K in GetFieldNodeResultName<Field>]: Resolved;
754
- } : {
755
- [K in GetFieldNodeResultName<Field>]: SelectQueryError<'Failed to resolve relationship.'> & string;
756
- };
757
- /**
758
- * Helper type to process the result of an embedded resource.
759
- */
760
- type ProcessEmbeddedResourceResult<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Resolved extends {
761
- referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>;
762
- relation: GenericRelationship & {
763
- match: 'refrel' | 'col' | 'fkname' | 'func';
764
- isNotNullable?: boolean;
765
- referencedRelation: string;
766
- isSetofReturn?: boolean;
767
- };
768
- direction: string;
769
- }, Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$1<Schema>> = ProcessNodes<ClientOptions, Schema, Resolved['referencedTable']['Row'], Resolved['relation']['match'] extends 'func' ? Resolved['relation']['referencedRelation'] : Field['name'], Resolved['referencedTable']['Relationships'], Field['children'] extends undefined ? [] : Exclude<Field['children'], undefined> extends Ast.Node[] ? Exclude<Field['children'], undefined> : []> extends infer ProcessedChildren ? {
770
- [K in GetFieldNodeResultName<Field>]: Resolved['direction'] extends 'forward' ? Field extends {
771
- innerJoin: true;
772
- } ? Resolved['relation']['isOneToOne'] extends true ? ProcessedChildren : ProcessedChildren[] : Resolved['relation']['isOneToOne'] extends true ? Resolved['relation']['match'] extends 'func' ? Resolved['relation']['isNotNullable'] extends true ? Resolved['relation']['isSetofReturn'] extends true ? ProcessedChildren : {
773
- [P in keyof ProcessedChildren]: ProcessedChildren[P] | null;
774
- } : ProcessedChildren | null : ProcessedChildren | null : ProcessedChildren[] : Resolved['relation']['referencedRelation'] extends CurrentTableOrView ? Resolved['relation']['match'] extends 'col' ? IsRelationNullable<TablesAndViews$1<Schema>[CurrentTableOrView], Resolved['relation']> extends true ? ProcessedChildren | null : ProcessedChildren : ProcessedChildren[] : IsRelationNullable<TablesAndViews$1<Schema>[CurrentTableOrView], Resolved['relation']> extends true ? Field extends {
775
- innerJoin: true;
776
- } ? ProcessedChildren : ProcessedChildren | null : ProcessedChildren;
777
- } : {
778
- [K in GetFieldNodeResultName<Field>]: SelectQueryError<'Failed to process embedded resource nodes.'> & string;
779
- };
780
- /**
781
- * Processes a SpreadNode by processing its target node.
782
- *
783
- * @param Schema - Database schema.
784
- * @param Row - The type of a row in the current table.
785
- * @param RelationName - The name of the current table or view.
786
- * @param Relationships - Relationships of the current table.
787
- * @param Spread - The SpreadNode to process.
788
- */
789
- type ProcessSpreadNode<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName extends string, Relationships extends GenericRelationship[], Spread extends Ast.SpreadNode> = ProcessNode<ClientOptions, Schema, Row, RelationName, Relationships, Spread['target']> extends infer Result ? Result extends SelectQueryError<infer E> ? SelectQueryError<E> : ExtractFirstProperty<Result> extends unknown[] ? SpreadOnManyEnabled<ClientOptions['PostgrestVersion']> extends true ? ProcessManyToManySpreadNodeResult<Result> : {
790
- [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`>;
791
- } : ProcessSpreadNodeResult<Result> : never;
792
- /**
793
- * Helper type to process the result of a many-to-many spread node.
794
- * Converts all fields in the spread object into arrays.
795
- */
796
- type ProcessManyToManySpreadNodeResult<Result> = Result extends Record<string, SelectQueryError<string> | null> ? Result : ExtractFirstProperty<Result> extends infer SpreadedObject ? SpreadedObject extends Array<Record<string, unknown>> ? {
797
- [K in keyof SpreadedObject[number]]: Array<SpreadedObject[number][K]>;
798
- } : SelectQueryError<'An error occurred spreading the many-to-many object'> : SelectQueryError<'An error occurred spreading the many-to-many object'>;
799
- /**
800
- * Helper type to process the result of a spread node.
801
- */
802
- type ProcessSpreadNodeResult<Result> = Result extends Record<string, SelectQueryError<string> | null> ? Result : ExtractFirstProperty<Result> extends infer SpreadedObject ? ContainsNull<SpreadedObject> extends true ? Exclude<{
803
- [K in keyof SpreadedObject]: SpreadedObject[K] | null;
804
- }, null> : Exclude<{
805
- [K in keyof SpreadedObject]: SpreadedObject[K];
806
- }, null> : SelectQueryError<'An error occurred spreading the object'>;
807
-
808
- /**
809
- * `ClientOptions` figé pour aurabase — PostgREST v12. Satisfait `ClientServerOptions`
810
- * et sert de défaut au threading de types (pas de configuration exposée côté SDK).
811
- */
812
- type AuraClientOptionsT = {
813
- PostgrestVersion: '12';
814
- };
815
- interface StoredFilter {
816
- column: string;
817
- op: string;
818
- value: unknown;
819
- }
820
- interface OrGroup {
821
- filters: StoredFilter[];
822
- }
823
- type MutationMode = {
824
- type: 'insert';
825
- body: unknown;
826
- } | {
827
- type: 'update';
828
- id: string | null;
829
- body: unknown;
830
- } | {
831
- type: 'delete';
832
- id: string | null;
833
- } | {
834
- type: 'upsert';
835
- body: unknown;
836
- onConflict: string;
837
- };
838
- /** État d'un builder en mode `rpc` (`DatabaseService.rpc()`) : args + verbe HTTP. */
839
- type RpcMode = {
840
- args: unknown;
841
- verb: 'POST' | 'GET' | 'HEAD';
842
- };
843
- /**
844
- * Base class : état partagé, constructeur, exécution HTTP (`then`/`_execute`),
845
- * `throwOnError` et `buildQueryString`. Implements PromiseLike so it can be
846
- * awaited directly.
847
- */
848
- declare class AuraPostgrestBuilder<ClientOptions extends ClientServerOptions = AuraClientOptionsT, Result = Record<string, unknown>, ThrowOnError extends boolean = false> implements PromiseLike<AuraResponse<Result>> {
849
- protected readonly _client: AuraClientLike;
850
- protected readonly _basePath: string;
851
- protected _filters: StoredFilter[];
852
- protected _orGroups: OrGroup[];
853
- protected _selectColumns: string[] | null;
854
- protected _selectInvoked: boolean;
855
- protected _sortColumn: string | null;
856
- protected _sortDirection: 'asc' | 'desc';
857
- protected _limit: number | null;
858
- protected _offset: number | null;
859
- protected _cursor: string | null;
860
- protected _count: CountMode | null;
861
- protected _rawSelect: boolean;
862
- protected _single: boolean;
863
- protected _maybeSingle: boolean;
864
- protected _throwOnError: boolean;
865
- protected _mutation: MutationMode | null;
866
- protected _rpc: RpcMode | null;
867
- constructor(client: AuraClientLike, basePath: string);
868
- throwOnError(): this;
869
- /**
870
- * Positionne l'état interne `rpc` (args + verbe HTTP) — méthode package-interne
871
- * utilisée par `DatabaseService.rpc()` pour éviter un cast sur un champ `protected`.
872
- *
873
- * `count` accepte `'planned'` (parité stricte `RpcOptions`, cf. `DatabaseService.rpc`)
874
- * en plus de `CountMode` (`@aurabase/core`, qui ne connaît que `exact`/`estimated` —
875
- * package partagé, non modifié ici). Le cast vers `_count` reste sans risque runtime :
876
- * `buildQueryString` sérialise la valeur telle quelle en query param `count=`.
877
- */
878
- _initRpc(args: unknown, verb: 'POST' | 'GET' | 'HEAD', count?: 'exact' | 'planned' | 'estimated'): this;
879
- buildQueryString(): string;
880
- then<TResult1 = AuraResponse<Result>, TResult2 = never>(onfulfilled?: ((value: AuraResponse<Result>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
881
- private _execute;
882
- }
883
- /**
884
- * Sélection de colonnes, tri, pagination et modificateurs de cardinalité
885
- * (`single`/`maybeSingle`/`count`).
886
- */
887
- declare class AuraTransformBuilder<Schema extends GenericSchema = GenericSchema, Row extends Record<string, unknown> = Record<string, unknown>, RelationName = unknown, Relationships = unknown, Result = Record<string, unknown>, ClientOptions extends ClientServerOptions = AuraClientOptionsT, ThrowOnError extends boolean = false> extends AuraPostgrestBuilder<ClientOptions, Result, ThrowOnError> {
888
- /**
889
- * Select columns and optionally embed related resources (PostgREST parity).
890
- *
891
- * @example
892
- * // Simple columns
893
- * db.from('users').select('id, name, email')
894
- *
895
- * // All columns (default)
896
- * db.from('users').select('*')
897
- *
898
- * // Embed related table (many-to-one)
899
- * db.from('orders').select('*, customer:customers(name, email)')
900
- *
901
- * // Embed related table (one-to-many)
902
- * db.from('directors').select('last_name, films(title, year)')
903
- *
904
- * // FK disambiguation
905
- * db.from('orders').select('*, billing:addresses!billing_address_id(name)')
906
- *
907
- * // Nested embedding
908
- * db.from('actors').select('first_name, roles(character, films(title))')
909
- */
910
- select<Query extends string = '*', NewResultOne = GetResult<Schema, Row, RelationName, Relationships, Query, ClientOptions>>(columns?: Query): AuraFilterBuilder<Schema, Row, RelationName, Relationships, NewResultOne[], ClientOptions, ThrowOnError>;
911
- order(column: string, direction?: 'asc' | 'desc'): this;
912
- limit(n: number): this;
913
- offset(n: number): this;
914
- /**
915
- * Pagination keyset : passer le `next_cursor` opaque de la page précédente (préférable à
916
- * `offset` sur les grandes tables : stable, sans dup/skip). Renvoyer tel quel `meta.next_cursor` ;
917
- * ne pas le construire/parser (format opaque).
918
- */
919
- cursor(cursor: string): this;
920
- count(mode?: CountMode): this;
921
- single<ResultOne = Result extends (infer U)[] ? U : Result>(): AuraPostgrestBuilder<ClientOptions, ResultOne, ThrowOnError>;
922
- maybeSingle<ResultOne = Result extends (infer U)[] ? U : Result>(): AuraPostgrestBuilder<ClientOptions, ResultOne | null, ThrowOnError>;
923
- }
924
- /**
925
- * Tous les filtres PostgREST (`eq`, `neq`, ... `ilikeAnyOf`).
926
- */
927
- declare class AuraFilterBuilder<Schema extends GenericSchema = GenericSchema, Row extends Record<string, unknown> = Record<string, unknown>, RelationName = unknown, Relationships = unknown, Result = Record<string, unknown>, ClientOptions extends ClientServerOptions = AuraClientOptionsT, ThrowOnError extends boolean = false> extends AuraTransformBuilder<Schema, Row, RelationName, Relationships, Result, ClientOptions, ThrowOnError> {
928
- eq<C extends keyof Row & string>(column: C, value: Row[C]): this;
929
- neq<C extends keyof Row & string>(column: C, value: Row[C]): this;
930
- gt<C extends keyof Row & string>(column: C, value: Row[C]): this;
931
- gte<C extends keyof Row & string>(column: C, value: Row[C]): this;
932
- lt<C extends keyof Row & string>(column: C, value: Row[C]): this;
933
- lte<C extends keyof Row & string>(column: C, value: Row[C]): this;
934
- like(column: keyof Row & string, pattern: string): this;
935
- ilike(column: keyof Row & string, pattern: string): this;
936
- /**
937
- * IS NULL or IS NOT NULL filter.
938
- * PostgREST accepts: is.null, is.true, is.false (no "not_null" — use neq for that).
939
- * For IS NOT NULL, use `neq(column, null)` or `is(column, 'not.null')`.
940
- */
941
- is(column: keyof Row & string, value: 'null' | 'true' | 'false' | 'unknown' | 'not.null'): this;
942
- in<C extends keyof Row & string>(column: C, values: Row[C][]): this;
943
- /**
944
- * Add an OR group: `or=(col1.eq.val1,col2.gt.val2)`
945
- */
946
- or(filters: Array<{
947
- column: string;
948
- op: string;
949
- value: unknown;
950
- }>): this;
951
- notIn<C extends keyof Row & string>(column: C, values: Row[C][]): this;
952
- contains(column: keyof Row & string, value: unknown): this;
953
- containedBy(column: keyof Row & string, value: unknown): this;
954
- overlaps(column: keyof Row & string, value: unknown): this;
955
- rangeGt(column: keyof Row & string, range: string): this;
956
- rangeGte(column: keyof Row & string, range: string): this;
957
- rangeLt(column: keyof Row & string, range: string): this;
958
- rangeLte(column: keyof Row & string, range: string): this;
959
- rangeAdjacent(column: keyof Row & string, range: string): this;
960
- isDistinct(column: keyof Row & string, value: unknown): this;
961
- not(column: string, op: string, value: unknown): this;
962
- filter(column: string, op: string, value: unknown): this;
963
- match(query: Record<string, unknown>): this;
964
- textSearch(column: keyof Row & string, query: string, options?: {
965
- type?: 'plain' | 'phrase' | 'websearch';
966
- config?: string;
967
- }): this;
968
- likeAllOf(column: keyof Row & string, patterns: string[]): this;
969
- likeAnyOf(column: keyof Row & string, patterns: string[]): this;
970
- ilikeAllOf(column: keyof Row & string, patterns: string[]): this;
971
- ilikeAnyOf(column: keyof Row & string, patterns: string[]): this;
972
- }
973
- /**
974
- * Chainable query builder that compiles to URL query parameters
975
- * matching the backend's QueryOptions / FilterOp format.
976
- *
977
- * Point d'entrée concret retourné par `DatabaseService.from()` : ajoute les
978
- * mutations (`insert`/`update`/`delete`/`upsert`) au-dessus de la chaîne
979
- * Base → Transform → Filter.
980
- */
981
- declare class AuraQueryBuilder<Schema extends GenericSchema = GenericSchema, Relation extends GenericTable | GenericView = GenericTable, RelationName = unknown, ClientOptions extends ClientServerOptions = AuraClientOptionsT> extends AuraFilterBuilder<Schema, Relation['Row'], RelationName, Relation['Relationships'], Relation['Row'][], ClientOptions, false> {
982
- insert(body: Relation extends {
983
- Insert: infer I;
984
- } ? I | I[] : never): this;
985
- update(id: string, body: Relation extends {
986
- Update: infer U;
987
- } ? U : never): AuraFilterBuilder<Schema, Relation['Row'], RelationName, Relation['Relationships'], Relation['Row'][], ClientOptions, false>;
988
- update(body: Relation extends {
989
- Update: infer U;
990
- } ? U : never): AuraFilterBuilder<Schema, Relation['Row'], RelationName, Relation['Relationships'], Relation['Row'][], ClientOptions, false>;
991
- delete(id?: string): AuraFilterBuilder<Schema, Relation['Row'], RelationName, Relation['Relationships'], Relation['Row'][], ClientOptions, false>;
992
- upsert(body: Relation extends {
993
- Insert: infer I;
994
- } ? I | I[] : never, options?: {
995
- onConflict?: string;
996
- }): AuraFilterBuilder<Schema, Relation['Row'], RelationName, Relation['Relationships'], Relation['Row'][], ClientOptions, false>;
997
- }
998
-
999
- type IsMatchingArgs<FnArgs extends GenericFunction['Args'], PassedArgs extends GenericFunction['Args']> = [FnArgs] extends [Record<PropertyKey, never>] ? PassedArgs extends Record<PropertyKey, never> ? true : false : keyof PassedArgs extends keyof FnArgs ? PassedArgs extends FnArgs ? true : false : false;
1000
- type MatchingFunctionArgs<Fn extends GenericFunction, Args extends GenericFunction['Args']> = Fn extends {
1001
- Args: infer A extends GenericFunction['Args'];
1002
- } ? IsMatchingArgs<A, Args> extends true ? Fn : never : false;
1003
- type FindMatchingFunctionByArgs<FnUnion, Args extends GenericFunction['Args']> = FnUnion extends infer Fn extends GenericFunction ? MatchingFunctionArgs<Fn, Args> : false;
1004
- type TablesAndViews<Schema extends GenericSchema> = Schema['Tables'] & Exclude<Schema['Views'], ''>;
1005
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
1006
- type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
1007
- type IsAny<T> = 0 extends 1 & T ? true : false;
1008
- type ExactMatch<T, S> = [T] extends [S] ? ([S] extends [T] ? true : false) : false;
1009
- type ExtractExactFunction<Fns, Args> = Fns extends infer F ? F extends GenericFunction ? ExactMatch<F['Args'], Args> extends true ? F : never : never : never;
1010
- type IsNever<T> = [T] extends [never] ? true : false;
1011
- type RpcFunctionNotFound<FnName> = {
1012
- Row: any;
1013
- Result: {
1014
- error: true;
1015
- } & "Couldn't infer function definition matching provided arguments";
1016
- RelationName: FnName;
1017
- Relationships: null;
1018
- };
1019
- type CrossSchemaError<TableRef extends string> = {
1020
- error: true;
1021
- } & `Function returns SETOF from a different schema ('${TableRef}'). Use .overrideTypes<YourReturnType>() to specify the return type explicitly.`;
1022
- type GetRpcFunctionFilterBuilderByArgs<Schema extends GenericSchema, FnName extends string & keyof Schema['Functions'], Args> = {
1023
- 0: Schema['Functions'][FnName];
1024
- 1: IsAny<Schema> extends true ? any : IsNever<Args> extends true ? IsNever<ExtractExactFunction<Schema['Functions'][FnName], Args>> extends true ? LastOf<Schema['Functions'][FnName]> : ExtractExactFunction<Schema['Functions'][FnName], Args> : Args extends Record<PropertyKey, never> ? LastOf<Schema['Functions'][FnName]> : Args extends GenericFunction['Args'] ? IsNever<LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>> extends true ? LastOf<Schema['Functions'][FnName]> : LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>> : ExtractExactFunction<Schema['Functions'][FnName], Args> extends GenericFunction ? ExtractExactFunction<Schema['Functions'][FnName], Args> : any;
1025
- }[1] extends infer Fn ? IsAny<Fn> extends true ? {
1026
- Row: any;
1027
- Result: any;
1028
- RelationName: FnName;
1029
- Relationships: null;
1030
- } : Fn extends GenericFunction ? {
1031
- Row: Fn['SetofOptions'] extends GenericSetofOption ? Fn['SetofOptions']['to'] extends keyof TablesAndViews<Schema> ? TablesAndViews<Schema>[Fn['SetofOptions']['to']]['Row'] : Fn['Returns'] extends any[] ? Fn['Returns'][number] extends Record<string, unknown> ? Fn['Returns'][number] : CrossSchemaError<Fn['SetofOptions']['to'] & string> : Fn['Returns'] extends Record<string, unknown> ? Fn['Returns'] : CrossSchemaError<Fn['SetofOptions']['to'] & string> : Fn['Returns'] extends any[] ? Fn['Returns'][number] extends Record<string, unknown> ? Fn['Returns'][number] : never : Fn['Returns'] extends Record<string, unknown> ? Fn['Returns'] : never;
1032
- Result: Fn['SetofOptions'] extends GenericSetofOption ? Fn['SetofOptions']['isSetofReturn'] extends true ? Fn['SetofOptions']['isOneToOne'] extends true ? Fn['Returns'][] : Fn['Returns'] : Fn['Returns'] : Fn['Returns'];
1033
- RelationName: Fn['SetofOptions'] extends GenericSetofOption ? Fn['SetofOptions']['to'] : FnName;
1034
- Relationships: Fn['SetofOptions'] extends GenericSetofOption ? Fn['SetofOptions']['to'] extends keyof Schema['Tables'] ? Schema['Tables'][Fn['SetofOptions']['to']]['Relationships'] : Fn['SetofOptions']['to'] extends keyof Schema['Views'] ? Schema['Views'][Fn['SetofOptions']['to']]['Relationships'] : null : null;
1035
- } : Fn extends false ? RpcFunctionNotFound<FnName> : RpcFunctionNotFound<FnName> : RpcFunctionNotFound<FnName>;
1036
-
1037
- interface RpcOptions {
1038
- count?: 'exact' | 'planned' | 'estimated';
1039
- head?: boolean;
1040
- get?: boolean;
1041
- }
1042
- type RpcArgsFor<Schema extends GenericSchema, FnName extends string> = [
1043
- Schema['Functions'][FnName]
1044
- ] extends [never] ? Record<string, unknown> : FnName extends keyof Schema['Functions'] ? Schema['Functions'][FnName]['Args'] : Record<string, unknown>;
1045
- type RpcResultFor<Schema extends GenericSchema, FnName extends string, Args> = [
1046
- Schema['Functions'][FnName]
1047
- ] extends [never] ? {
1048
- Row: any;
1049
- Result: any;
1050
- RelationName: any;
1051
- Relationships: any;
1052
- } : FnName extends string & keyof Schema['Functions'] ? GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args> : {
1053
- Row: any;
1054
- Result: any;
1055
- RelationName: any;
1056
- Relationships: any;
1057
- };
1058
- declare class DatabaseService<Database = any, Schema extends GenericSchema = Database extends {
1059
- public: infer S;
1060
- } ? S extends GenericSchema ? S : any : any> extends BaseService {
1061
- constructor(client: AuraClientLike);
1062
- private get prefix();
1063
- /**
1064
- * Start a query on a table. Returns a chainable QueryBuilder dont `.select()`
1065
- * infère son type de résultat via `GetResult` (parité PostgREST/Supabase) quand
1066
- * un `Database` typé est fourni à `createClient<Database>()`.
1067
- *
1068
- * @example
1069
- * const { data, error } = await db.from('posts').eq('published', true).limit(10)
1070
- */
1071
- from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(table: TableName): AuraQueryBuilder<Schema, Table, TableName, AuraClientOptionsT>;
1072
- from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(view: ViewName): AuraQueryBuilder<Schema, View, ViewName, AuraClientOptionsT>;
1073
- from(table: string): AuraQueryBuilder<any, any, any, AuraClientOptionsT>;
1074
- /**
1075
- * Exécute une requête SQL brute (passthrough direct vers Postgres).
1076
- *
1077
- * ⚠️ N'est PAS en lecture seule : SELECT, INSERT, UPDATE, DELETE et DDL
1078
- * s'exécutent réellement et persistent, dans la limite des GRANTs du rôle
1079
- * Postgres connecté pour ce projet (seule barrière de sécurité — il n'y a
1080
- * aucun filtre applicatif par type d'instruction côté serveur). Ne pas
1081
- * exposer cet endpoint sans restriction à des clients non fiables.
1082
- */
1083
- sql<T = unknown>(query: string, params?: unknown[]): Promise<AuraResponse<T>>;
1084
- /**
1085
- * Appelle une fonction Postgres exposée par PostgREST (`POST|GET|HEAD /rpc/{fn}`).
1086
- * Signature forte quand `Schema['Functions']` connaît `fn` (typage vendoré
1087
- * `GetRpcFunctionFilterBuilderByArgs`, parité postgrest-js) ; sinon repli permissif.
1088
- *
1089
- * @example
1090
- * const { data } = await db.rpc('add', { a: 1, b: 2 })
1091
- * const { data } = await db.rpc('list_things', {}).eq('id', 2).select('id,name').single()
1092
- */
1093
- rpc<FnName extends string, Args extends RpcArgsFor<Schema, FnName> = RpcArgsFor<Schema, FnName>, Fn extends {
1094
- Row: any;
1095
- Result: any;
1096
- RelationName: any;
1097
- Relationships: any;
1098
- } = RpcResultFor<Schema, FnName, Args>>(fn: FnName, args?: Args, options?: RpcOptions): AuraFilterBuilder<Schema, Fn['Row'], Fn['RelationName'], Fn['Relationships'], Fn['Result'], AuraClientOptionsT>;
1099
- /**
1100
- * Fetch the schema (tables & colonnes, fonctions Postgres exposées via PostgREST,
1101
- * types enum et vues) pour le projet courant.
1102
- */
1103
- schema(): Promise<AuraResponse<{
1104
- tables: SchemaTable[];
1105
- functions: SchemaFunction[];
1106
- enums: SchemaEnum[];
1107
- views: SchemaTable[];
1108
- }>>;
1109
- }
1110
-
1111
- export { DatabaseService, AuraQueryBuilder as QueryBuilder };