@aurabase/aurabase-js 0.3.0 → 0.3.1

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