@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,544 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@aurabase/core');
4
-
5
- // src/DatabaseService.ts
6
- function quoteReserved(v) {
7
- const s = String(v);
8
- return /[,()"]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
9
- }
10
- function encodeFilterValue(op, value) {
11
- if (op === "in" || op === "not.in") {
12
- const arr = Array.isArray(value) ? value : [value];
13
- return `${op}.(${arr.map(quoteReserved).join(",")})`;
14
- }
15
- if (op === "cs" || op === "cd" || op === "ov") {
16
- if (Array.isArray(value)) return `${op}.{${value.map(quoteReserved).join(",")}}`;
17
- if (value !== null && typeof value === "object") return `${op}.${JSON.stringify(value)}`;
18
- return `${op}.${value}`;
19
- }
20
- if (op.endsWith("(all)") || op.endsWith("(any)")) {
21
- const arr = Array.isArray(value) ? value : [value];
22
- return `${op}.{${arr.map(quoteReserved).join(",")}}`;
23
- }
24
- return `${op}.${value}`;
25
- }
26
- var PGRST_OBJECT_ACCEPT = "application/vnd.pgrst.object+json";
27
- function mentionsZeroRows(err) {
28
- if (!err) return false;
29
- const details = typeof err.details === "string" ? err.details : JSON.stringify(err.details ?? "");
30
- return /\b0 rows\b/.test(`${err.message ?? ""} ${details}`);
31
- }
32
- function pgrst116(zeroRows) {
33
- return new core.AuraError(406, {
34
- error: {
35
- code: "PGRST116",
36
- message: zeroRows ? "JSON object requested, 0 rows returned" : "JSON object requested, multiple rows returned"
37
- }
38
- });
39
- }
40
- var AuraPostgrestBuilder = class {
41
- _client;
42
- _basePath;
43
- _filters = [];
44
- _orGroups = [];
45
- _selectColumns = null;
46
- // `select()` a-t-il été appelé ? (distinct de `_selectColumns`, que `select('*')`
47
- // remet à `null`) — sert à poser `Prefer: return=representation` sur une mutation
48
- // même avec `select('*')`.
49
- _selectInvoked = false;
50
- _sortColumn = null;
51
- _sortDirection = "asc";
52
- _limit = null;
53
- _offset = null;
54
- _cursor = null;
55
- _count = null;
56
- _rawSelect = false;
57
- _single = false;
58
- _maybeSingle = false;
59
- _throwOnError = false;
60
- _mutation = null;
61
- _rpc = null;
62
- constructor(client, basePath) {
63
- this._client = client;
64
- this._basePath = basePath;
65
- }
66
- throwOnError() {
67
- this._throwOnError = true;
68
- return this;
69
- }
70
- /**
71
- * Positionne l'état interne `rpc` (args + verbe HTTP) — méthode package-interne
72
- * utilisée par `DatabaseService.rpc()` pour éviter un cast sur un champ `protected`.
73
- *
74
- * `count` accepte `'planned'` (parité stricte `RpcOptions`, cf. `DatabaseService.rpc`)
75
- * en plus de `CountMode` (`@aurabase/core`, qui ne connaît que `exact`/`estimated` —
76
- * package partagé, non modifié ici). Le cast vers `_count` reste sans risque runtime :
77
- * `buildQueryString` sérialise la valeur telle quelle en query param `count=`.
78
- */
79
- _initRpc(args, verb, count) {
80
- this._rpc = { args, verb };
81
- if (count) this._count = count;
82
- return this;
83
- }
84
- // -- Query string builder ---------------------------------------------------
85
- buildQueryString() {
86
- const params = new URLSearchParams();
87
- if (this._selectColumns && this._selectColumns.length > 0) {
88
- params.set("select", this._rawSelect ? this._selectColumns[0] : this._selectColumns.join(","));
89
- }
90
- for (const f of this._filters) {
91
- params.append(f.column, encodeFilterValue(f.op, f.value));
92
- }
93
- for (const group of this._orGroups) {
94
- const parts = group.filters.map((f) => `${f.column}.${encodeFilterValue(f.op, f.value)}`);
95
- params.append("or", `(${parts.join(",")})`);
96
- }
97
- if (this._sortColumn) {
98
- params.set("sort_by", this._sortColumn);
99
- params.set("sort_order", this._sortDirection);
100
- }
101
- if (this._limit !== null) params.set("limit", String(this._limit));
102
- if (this._offset !== null) params.set("offset", String(this._offset));
103
- if (this._cursor !== null) params.set("cursor", this._cursor);
104
- if (this._count) params.set("count", this._count);
105
- if (this._rpc && (this._rpc.verb === "GET" || this._rpc.verb === "HEAD") && this._rpc.args && typeof this._rpc.args === "object") {
106
- for (const [k, v] of Object.entries(this._rpc.args)) {
107
- params.set(k, typeof v === "string" ? v : JSON.stringify(v));
108
- }
109
- }
110
- return params.toString();
111
- }
112
- // -- Execution via PromiseLike ----------------------------------------------
113
- then(onfulfilled, onrejected) {
114
- return this._execute().then(onfulfilled, onrejected);
115
- }
116
- async _execute() {
117
- let res;
118
- const acceptSingle = this._single ? { Accept: PGRST_OBJECT_ACCEPT } : void 0;
119
- if (this._rpc) {
120
- const qs = this.buildQueryString();
121
- const sep = qs ? "?" : "";
122
- const url = `${this._client.baseUrl}${this._basePath}${sep}${qs}`;
123
- const init = this._rpc.verb === "POST" ? { method: "POST", body: this._rpc.args, headers: acceptSingle } : { method: this._rpc.verb, headers: acceptSingle };
124
- res = await core.fetchWithAuth(url, init, this._client);
125
- } else if (this._mutation) {
126
- const m = this._mutation;
127
- const hasEffectiveFilter = this._filters.some((f) => f.column !== "") || this._orGroups.some((g) => g.filters.length > 0);
128
- if ((m.type === "update" || m.type === "delete") && m.id === null && !hasEffectiveFilter) {
129
- return {
130
- data: null,
131
- error: new core.AuraError(0, {
132
- error: {
133
- code: "unfiltered_mutation",
134
- message: "update()/delete() sans filtre refus\xE9 (protection anti-wipe) \u2014 ajoutez un filtre .eq()/... ou utilisez une mutation id-based"
135
- }
136
- })
137
- };
138
- }
139
- const prefer = [];
140
- if (this._selectInvoked) prefer.push("return=representation");
141
- if (this._count) prefer.push(`count=${this._count}`);
142
- const merged = { ...acceptSingle };
143
- if (prefer.length > 0) merged.Prefer = prefer.join(", ");
144
- const headers = Object.keys(merged).length > 0 ? merged : void 0;
145
- const qs = this.buildQueryString();
146
- const sep = qs ? "?" : "";
147
- switch (m.type) {
148
- case "insert": {
149
- res = await core.fetchWithAuth(
150
- `${this._client.baseUrl}${this._basePath}${sep}${qs}`,
151
- { method: "POST", body: m.body, headers },
152
- this._client
153
- );
154
- break;
155
- }
156
- case "update": {
157
- const path = m.id !== null ? `${this._basePath}/${m.id}` : this._basePath;
158
- res = await core.fetchWithAuth(
159
- `${this._client.baseUrl}${path}${sep}${qs}`,
160
- { method: "PATCH", body: m.body, headers },
161
- this._client
162
- );
163
- break;
164
- }
165
- case "delete": {
166
- const path = m.id !== null ? `${this._basePath}/${m.id}` : this._basePath;
167
- res = await core.fetchWithAuth(
168
- `${this._client.baseUrl}${path}${sep}${qs}`,
169
- { method: "DELETE", headers },
170
- this._client
171
- );
172
- break;
173
- }
174
- case "upsert": {
175
- const params = new URLSearchParams(qs);
176
- params.set("on_conflict", m.onConflict);
177
- res = await core.fetchWithAuth(
178
- `${this._client.baseUrl}${this._basePath}?${params.toString()}`,
179
- { method: "POST", body: m.body, headers },
180
- this._client
181
- );
182
- break;
183
- }
184
- }
185
- } else {
186
- const qs = this.buildQueryString();
187
- const sep = qs ? "?" : "";
188
- res = await core.fetchWithAuth(
189
- `${this._client.baseUrl}${this._basePath}${sep}${qs}`,
190
- { method: "GET", headers: acceptSingle },
191
- this._client
192
- );
193
- }
194
- if (!this._single && (this._mutation?.type === "insert" || this._mutation?.type === "upsert") && res.data !== null && typeof res.data === "object" && !Array.isArray(res.data)) {
195
- res = { ...res, data: [res.data] };
196
- }
197
- if (this._single) {
198
- if (res.error) {
199
- const zero = res.error.status === 406 ? mentionsZeroRows(res.error) : res.error.status === 404 && res.error.code === "RECORD_NOT_FOUND" ? true : null;
200
- if (zero !== null) {
201
- res = this._maybeSingle && zero ? { ...res, data: null, error: null } : { ...res, data: null, error: pgrst116(zero) };
202
- }
203
- } else if (Array.isArray(res.data)) {
204
- const rows = res.data;
205
- if (this._maybeSingle) {
206
- res = rows.length > 1 ? { ...res, data: null, error: pgrst116(false) } : { ...res, data: rows[0] ?? null };
207
- } else if (rows.length === 1) {
208
- res = { ...res, data: rows[0] };
209
- } else {
210
- res = { ...res, data: null, error: pgrst116(rows.length === 0) };
211
- }
212
- }
213
- }
214
- if (this._throwOnError && res.error) {
215
- const err = new Error(res.error.message);
216
- err.code = res.error.code;
217
- err.details = res.error.details;
218
- throw err;
219
- }
220
- return res;
221
- }
222
- };
223
- var AuraTransformBuilder = class extends AuraPostgrestBuilder {
224
- // -- Column selection & resource embedding -----------------------------------
225
- /**
226
- * Select columns and optionally embed related resources (PostgREST parity).
227
- *
228
- * @example
229
- * // Simple columns
230
- * db.from('users').select('id, name, email')
231
- *
232
- * // All columns (default)
233
- * db.from('users').select('*')
234
- *
235
- * // Embed related table (many-to-one)
236
- * db.from('orders').select('*, customer:customers(name, email)')
237
- *
238
- * // Embed related table (one-to-many)
239
- * db.from('directors').select('last_name, films(title, year)')
240
- *
241
- * // FK disambiguation
242
- * db.from('orders').select('*, billing:addresses!billing_address_id(name)')
243
- *
244
- * // Nested embedding
245
- * db.from('actors').select('first_name, roles(character, films(title))')
246
- */
247
- select(columns) {
248
- this._selectInvoked = true;
249
- const cols = columns;
250
- if (cols === void 0 || cols === "*") {
251
- this._selectColumns = null;
252
- this._rawSelect = false;
253
- } else if (typeof cols === "string") {
254
- if (cols.includes("(")) {
255
- this._selectColumns = [cols];
256
- this._rawSelect = true;
257
- } else {
258
- this._selectColumns = cols.split(",").map((c) => c.trim());
259
- this._rawSelect = false;
260
- }
261
- } else {
262
- this._selectColumns = cols;
263
- this._rawSelect = false;
264
- }
265
- return this;
266
- }
267
- // -- Sort / pagination ------------------------------------------------------
268
- order(column, direction = "asc") {
269
- this._sortColumn = column;
270
- this._sortDirection = direction;
271
- return this;
272
- }
273
- limit(n) {
274
- this._limit = n;
275
- return this;
276
- }
277
- offset(n) {
278
- this._offset = n;
279
- return this;
280
- }
281
- /**
282
- * Pagination keyset : passer le `next_cursor` opaque de la page précédente (préférable à
283
- * `offset` sur les grandes tables : stable, sans dup/skip). Renvoyer tel quel `meta.next_cursor` ;
284
- * ne pas le construire/parser (format opaque).
285
- */
286
- cursor(cursor) {
287
- this._cursor = cursor;
288
- return this;
289
- }
290
- count(mode = "exact") {
291
- this._count = mode;
292
- return this;
293
- }
294
- // -- Modifiers --------------------------------------------------------------
295
- single() {
296
- this._single = true;
297
- return this;
298
- }
299
- maybeSingle() {
300
- this._single = true;
301
- this._maybeSingle = true;
302
- return this;
303
- }
304
- };
305
- var AuraFilterBuilder = class extends AuraTransformBuilder {
306
- // -- Filter methods (each returns this for chaining) ------------------------
307
- //
308
- // Typées sur `Row` : `column` est contraint à `keyof Row & string` (autocomplete +
309
- // erreur de compilation sur colonne inconnue) et `value`/`values` à `Row[C]` (erreur
310
- // sur mauvais type). Runtime inchangé — seules les signatures changent.
311
- eq(column, value) {
312
- this._filters.push({ column, op: "eq", value });
313
- return this;
314
- }
315
- neq(column, value) {
316
- this._filters.push({ column, op: "neq", value });
317
- return this;
318
- }
319
- gt(column, value) {
320
- this._filters.push({ column, op: "gt", value });
321
- return this;
322
- }
323
- gte(column, value) {
324
- this._filters.push({ column, op: "gte", value });
325
- return this;
326
- }
327
- lt(column, value) {
328
- this._filters.push({ column, op: "lt", value });
329
- return this;
330
- }
331
- lte(column, value) {
332
- this._filters.push({ column, op: "lte", value });
333
- return this;
334
- }
335
- like(column, pattern) {
336
- this._filters.push({ column, op: "like", value: pattern });
337
- return this;
338
- }
339
- ilike(column, pattern) {
340
- this._filters.push({ column, op: "ilike", value: pattern });
341
- return this;
342
- }
343
- /**
344
- * IS NULL or IS NOT NULL filter.
345
- * PostgREST accepts: is.null, is.true, is.false (no "not_null" — use neq for that).
346
- * For IS NOT NULL, use `neq(column, null)` or `is(column, 'not.null')`.
347
- */
348
- is(column, value) {
349
- if (value === "not.null") {
350
- this._filters.push({ column, op: "not.is", value: "null" });
351
- } else {
352
- this._filters.push({ column, op: "is", value });
353
- }
354
- return this;
355
- }
356
- in(column, values) {
357
- this._filters.push({ column, op: "in", value: values });
358
- return this;
359
- }
360
- /**
361
- * Add an OR group: `or=(col1.eq.val1,col2.gt.val2)`
362
- */
363
- or(filters) {
364
- this._orGroups.push({
365
- filters: filters.map((f) => ({ column: f.column, op: f.op, value: f.value }))
366
- });
367
- return this;
368
- }
369
- // -- Filtres étendus (parité PostgREST) -------------------------------------
370
- notIn(column, values) {
371
- this._filters.push({ column, op: "not.in", value: values });
372
- return this;
373
- }
374
- contains(column, value) {
375
- this._filters.push({ column, op: "cs", value });
376
- return this;
377
- }
378
- containedBy(column, value) {
379
- this._filters.push({ column, op: "cd", value });
380
- return this;
381
- }
382
- overlaps(column, value) {
383
- this._filters.push({ column, op: "ov", value });
384
- return this;
385
- }
386
- rangeGt(column, range) {
387
- this._filters.push({ column, op: "sr", value: range });
388
- return this;
389
- }
390
- rangeGte(column, range) {
391
- this._filters.push({ column, op: "nxl", value: range });
392
- return this;
393
- }
394
- rangeLt(column, range) {
395
- this._filters.push({ column, op: "sl", value: range });
396
- return this;
397
- }
398
- rangeLte(column, range) {
399
- this._filters.push({ column, op: "nxr", value: range });
400
- return this;
401
- }
402
- rangeAdjacent(column, range) {
403
- this._filters.push({ column, op: "adj", value: range });
404
- return this;
405
- }
406
- isDistinct(column, value) {
407
- this._filters.push({ column, op: "isdistinct", value });
408
- return this;
409
- }
410
- // Échappatoires (parité postgrest-js) : colonne `string` permissive, pas de contrainte sur `Row`.
411
- not(column, op, value) {
412
- this._filters.push({ column, op: `not.${op}`, value });
413
- return this;
414
- }
415
- filter(column, op, value) {
416
- this._filters.push({ column, op, value });
417
- return this;
418
- }
419
- match(query) {
420
- for (const [column, value] of Object.entries(query)) this._filters.push({ column, op: "eq", value });
421
- return this;
422
- }
423
- textSearch(column, query, options) {
424
- const t = options?.type;
425
- const token = t === "plain" ? "plfts" : t === "phrase" ? "phfts" : t === "websearch" ? "wfts" : "fts";
426
- const op = options?.config ? `${token}(${options.config})` : token;
427
- this._filters.push({ column, op, value: query });
428
- return this;
429
- }
430
- likeAllOf(column, patterns) {
431
- this._filters.push({ column, op: "like(all)", value: patterns });
432
- return this;
433
- }
434
- likeAnyOf(column, patterns) {
435
- this._filters.push({ column, op: "like(any)", value: patterns });
436
- return this;
437
- }
438
- ilikeAllOf(column, patterns) {
439
- this._filters.push({ column, op: "ilike(all)", value: patterns });
440
- return this;
441
- }
442
- ilikeAnyOf(column, patterns) {
443
- this._filters.push({ column, op: "ilike(any)", value: patterns });
444
- return this;
445
- }
446
- };
447
- var AuraQueryBuilder = class extends AuraFilterBuilder {
448
- // -- Mutations --------------------------------------------------------------
449
- //
450
- // Typées sur `Relation['Insert']`/`Relation['Update']` (parité postgrest-js) :
451
- // un champ requis manquant côté insert/upsert, ou une colonne inconnue côté
452
- // update, est une erreur de compilation. Runtime inchangé.
453
- //
454
- // Extraction par type conditionnel (plutôt qu'un accès indexé direct
455
- // `Relation['Insert']`) : `Relation` est contraint à `GenericTable | GenericView`
456
- // et `GenericNonUpdatableView` ne porte pas `Insert`/`Update`. `infer` distribue
457
- // sur cette union et retombe sur `never` pour la branche non-updatable, ce qui
458
- // évite l'erreur TS2536 tout en gardant le typage strict pour les tables.
459
- insert(body) {
460
- this._mutation = { type: "insert", body };
461
- return this;
462
- }
463
- update(idOrBody, body) {
464
- if (typeof idOrBody === "string") {
465
- this._mutation = { type: "update", id: idOrBody, body };
466
- } else {
467
- this._mutation = { type: "update", id: null, body: idOrBody };
468
- }
469
- return this;
470
- }
471
- // COMPAT `delete(id)` → route id-based ; FILTRÉ `delete()` → route Table
472
- // (exige un filtre, garde-fou anti-wipe).
473
- delete(id) {
474
- this._mutation = { type: "delete", id: typeof id === "string" ? id : null };
475
- return this;
476
- }
477
- upsert(body, options) {
478
- this._mutation = { type: "upsert", body, onConflict: options?.onConflict ?? "id" };
479
- return this;
480
- }
481
- };
482
-
483
- // src/DatabaseService.ts
484
- var DatabaseService = class extends core.BaseService {
485
- constructor(client) {
486
- super(client);
487
- }
488
- get prefix() {
489
- return `/v1/db/${this.client.projectId}`;
490
- }
491
- from(table) {
492
- return new AuraQueryBuilder(this.client, `${this.prefix}/${table}`);
493
- }
494
- /**
495
- * Exécute une requête SQL brute (passthrough direct vers Postgres).
496
- *
497
- * ⚠️ N'est PAS en lecture seule : SELECT, INSERT, UPDATE, DELETE et DDL
498
- * s'exécutent réellement et persistent, dans la limite des GRANTs du rôle
499
- * Postgres connecté pour ce projet (seule barrière de sécurité — il n'y a
500
- * aucun filtre applicatif par type d'instruction côté serveur). Ne pas
501
- * exposer cet endpoint sans restriction à des clients non fiables.
502
- */
503
- async sql(query, params) {
504
- return this.request("POST", `${this.prefix}/raw`, { query, params });
505
- }
506
- /**
507
- * Appelle une fonction Postgres exposée par PostgREST (`POST|GET|HEAD /rpc/{fn}`).
508
- * Signature forte quand `Schema['Functions']` connaît `fn` (typage vendoré
509
- * `GetRpcFunctionFilterBuilderByArgs`, parité postgrest-js) ; sinon repli permissif.
510
- *
511
- * @example
512
- * const { data } = await db.rpc('add', { a: 1, b: 2 })
513
- * const { data } = await db.rpc('list_things', {}).eq('id', 2).select('id,name').single()
514
- */
515
- rpc(fn, args, options) {
516
- const verb = options?.head ? "HEAD" : options?.get ? "GET" : "POST";
517
- const builder = new AuraFilterBuilder(
518
- this.client,
519
- `${this.prefix}/rpc/${fn}`
520
- )._initRpc(args ?? {}, verb, options?.count);
521
- return builder;
522
- }
523
- /**
524
- * Fetch the schema (tables & colonnes, fonctions Postgres exposées via PostgREST,
525
- * types enum et vues) pour le projet courant.
526
- */
527
- async schema() {
528
- const res = await this.request("GET", `${this.prefix}/schema`);
529
- if (res.error) return { data: null, error: res.error, meta: res.meta };
530
- return {
531
- data: {
532
- tables: res.data?.tables ?? [],
533
- functions: res.data?.functions ?? [],
534
- enums: res.data?.enums ?? [],
535
- views: res.data?.views ?? []
536
- },
537
- error: null,
538
- meta: res.meta
539
- };
540
- }
541
- };
542
-
543
- exports.DatabaseService = DatabaseService;
544
- exports.QueryBuilder = AuraQueryBuilder;