@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.
- package/README.md +26 -795
- package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.ts → dist/AuraClient-BcFE8u1v.d.cts} +1 -1
- package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.cts → dist/AuraClient-BcFE8u1v.d.ts} +1 -1
- package/{packages/aurabase/dist → dist}/index.d.cts +1 -1
- package/{packages/aurabase/dist → dist}/index.d.ts +1 -1
- package/{packages/aurabase/dist → dist}/ssr.d.cts +1 -1
- package/{packages/aurabase/dist → dist}/ssr.d.ts +1 -1
- package/package.json +72 -82
- package/.changeset/config.json +0 -11
- package/CHANGELOG.md +0 -30
- package/packages/ai/LICENSE +0 -21
- package/packages/ai/README.md +0 -106
- package/packages/ai/dist/index.cjs +0 -229
- package/packages/ai/dist/index.d.cts +0 -139
- package/packages/ai/dist/index.d.ts +0 -139
- package/packages/ai/dist/index.js +0 -226
- package/packages/ai/node_modules/.bin/esbuild +0 -19
- package/packages/ai/node_modules/.bin/tsc +0 -22
- package/packages/ai/node_modules/.bin/tsserver +0 -22
- package/packages/ai/node_modules/.bin/tsup +0 -22
- package/packages/ai/node_modules/.bin/tsup-node +0 -22
- package/packages/ai/node_modules/.bin/vite +0 -22
- package/packages/ai/node_modules/.bin/vitest +0 -22
- package/packages/ai/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/ai/package.json +0 -61
- package/packages/ai/src/AiService.ts +0 -226
- package/packages/ai/src/index.ts +0 -18
- package/packages/ai/src/sse.ts +0 -141
- package/packages/ai/src/types.ts +0 -30
- package/packages/ai/tests/chat-stream.test.ts +0 -151
- package/packages/ai/tests/rag-namespaces.test.ts +0 -54
- package/packages/ai/tests/sse.test.ts +0 -69
- package/packages/ai/tsconfig.json +0 -5
- package/packages/ai/tsup.config.ts +0 -11
- package/packages/aurabase/LICENSE +0 -21
- package/packages/aurabase/README.md +0 -64
- package/packages/aurabase/node_modules/.bin/esbuild +0 -19
- package/packages/aurabase/node_modules/.bin/tsc +0 -22
- package/packages/aurabase/node_modules/.bin/tsserver +0 -22
- package/packages/aurabase/node_modules/.bin/tsup +0 -22
- package/packages/aurabase/node_modules/.bin/tsup-node +0 -22
- package/packages/aurabase/node_modules/.bin/vite +0 -22
- package/packages/aurabase/node_modules/.bin/vitest +0 -22
- package/packages/aurabase/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/aurabase/package.json +0 -80
- package/packages/aurabase/src/AuraClient.ts +0 -237
- package/packages/aurabase/src/index.ts +0 -152
- package/packages/aurabase/src/ssr.ts +0 -156
- package/packages/aurabase/tests/ai-streaming-rag-e2e.test.ts +0 -82
- package/packages/aurabase/tests/ai.test.ts +0 -111
- package/packages/aurabase/tests/auth-admin.test.ts +0 -515
- package/packages/aurabase/tests/auth-e2e.test.ts +0 -135
- package/packages/aurabase/tests/auth-hardening.test.ts +0 -206
- package/packages/aurabase/tests/auth.test.ts +0 -947
- package/packages/aurabase/tests/database.test.ts +0 -230
- package/packages/aurabase/tests/db-types-e2e.test.ts +0 -217
- package/packages/aurabase/tests/dispose.test.ts +0 -23
- package/packages/aurabase/tests/foreign-token.e2e.test.ts +0 -129
- package/packages/aurabase/tests/functions.test.ts +0 -107
- package/packages/aurabase/tests/integration.test.ts +0 -413
- package/packages/aurabase/tests/live-production-validation.js +0 -241
- package/packages/aurabase/tests/live-sdk-production-validation.js +0 -293
- package/packages/aurabase/tests/mocks.ts +0 -139
- package/packages/aurabase/tests/notifications.test.ts +0 -314
- package/packages/aurabase/tests/observability-backup.test.ts +0 -186
- package/packages/aurabase/tests/observability-hook.test.ts +0 -130
- package/packages/aurabase/tests/production-robustness.test.ts +0 -268
- package/packages/aurabase/tests/public-api-surface.test.ts +0 -53
- package/packages/aurabase/tests/query-builder.test.ts +0 -329
- package/packages/aurabase/tests/readme-smoke-e2e.test.ts +0 -231
- package/packages/aurabase/tests/realtime-filter-e2e.test.ts +0 -344
- package/packages/aurabase/tests/refresh-locks.test.ts +0 -210
- package/packages/aurabase/tests/retry-option.test.ts +0 -17
- package/packages/aurabase/tests/rpc-e2e.test.ts +0 -254
- package/packages/aurabase/tests/rs256-local-e2e.test.ts +0 -114
- package/packages/aurabase/tests/rt-alias-public-e2e.test.ts +0 -235
- package/packages/aurabase/tests/rt-http-broadcast-e2e.test.ts +0 -124
- package/packages/aurabase/tests/service-role-guard.test.ts +0 -99
- package/packages/aurabase/tests/ssr.test.ts +0 -91
- package/packages/aurabase/tests/storage-backend-e2e.test.ts +0 -481
- package/packages/aurabase/tests/storage-sdk-parity-e2e.test.ts +0 -104
- package/packages/aurabase/tests/storage-transform-e2e.test.ts +0 -684
- package/packages/aurabase/tests/storage.test.ts +0 -55
- package/packages/aurabase/tests/types/client-generic.test-d.ts +0 -79
- package/packages/aurabase/tests/types/docs-snippets.test-d.ts +0 -571
- package/packages/aurabase/tests/types/error-code.test-d.ts +0 -53
- package/packages/aurabase/tsconfig.json +0 -5
- package/packages/aurabase/tsconfig.test-d.json +0 -5
- package/packages/aurabase/tsup.config.ts +0 -11
- package/packages/aurabase/vitest.config.ts +0 -16
- package/packages/aurabase/vitest.e2e.config.ts +0 -9
- package/packages/auth/LICENSE +0 -21
- package/packages/auth/README.md +0 -215
- package/packages/auth/dist/index.cjs +0 -1175
- package/packages/auth/dist/index.d.cts +0 -397
- package/packages/auth/dist/index.d.ts +0 -397
- package/packages/auth/dist/index.js +0 -1170
- package/packages/auth/node_modules/.bin/esbuild +0 -19
- package/packages/auth/node_modules/.bin/tsc +0 -22
- package/packages/auth/node_modules/.bin/tsserver +0 -22
- package/packages/auth/node_modules/.bin/tsup +0 -22
- package/packages/auth/node_modules/.bin/tsup-node +0 -22
- package/packages/auth/node_modules/.bin/vite +0 -22
- package/packages/auth/node_modules/.bin/vitest +0 -22
- package/packages/auth/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/auth/package.json +0 -61
- package/packages/auth/src/AuthAdminService.ts +0 -149
- package/packages/auth/src/AuthService.ts +0 -1166
- package/packages/auth/src/SessionManager.ts +0 -92
- package/packages/auth/src/index.ts +0 -17
- package/packages/auth/src/jwks.ts +0 -337
- package/packages/auth/src/pkce.ts +0 -27
- package/packages/auth/src/types.ts +0 -89
- package/packages/auth/tests/auth-lifecycle.test.ts +0 -149
- package/packages/auth/tests/detect-session.test.ts +0 -361
- package/packages/auth/tests/getclaims.test.ts +0 -780
- package/packages/auth/tests/is-mfa-challenge.test.ts +0 -27
- package/packages/auth/tests/password-recovery.test.ts +0 -124
- package/packages/auth/tests/pkce.test.ts +0 -192
- package/packages/auth/tests/session-manager.test.ts +0 -103
- package/packages/auth/tests/set-session.test.ts +0 -139
- package/packages/auth/tests/verify-otp.test.ts +0 -153
- package/packages/auth/tsconfig.json +0 -5
- package/packages/auth/tsup.config.ts +0 -11
- package/packages/core/LICENSE +0 -21
- package/packages/core/README.md +0 -132
- package/packages/core/dist/index.cjs +0 -695
- package/packages/core/dist/index.d.cts +0 -1137
- package/packages/core/dist/index.d.ts +0 -1137
- package/packages/core/dist/index.js +0 -673
- package/packages/core/node_modules/.bin/esbuild +0 -22
- package/packages/core/node_modules/.bin/tsc +0 -22
- package/packages/core/node_modules/.bin/tsserver +0 -22
- package/packages/core/node_modules/.bin/tsup +0 -22
- package/packages/core/node_modules/.bin/tsup-node +0 -22
- package/packages/core/node_modules/.bin/vite +0 -22
- package/packages/core/node_modules/.bin/vitest +0 -22
- package/packages/core/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/core/package.json +0 -57
- package/packages/core/src/AuraError.ts +0 -89
- package/packages/core/src/BaseService.ts +0 -44
- package/packages/core/src/client.ts +0 -34
- package/packages/core/src/cookie-utils.ts +0 -42
- package/packages/core/src/fetch.ts +0 -435
- package/packages/core/src/index.ts +0 -22
- package/packages/core/src/retry.ts +0 -63
- package/packages/core/src/serialize.ts +0 -6
- package/packages/core/src/stores/BaseAuthStore.ts +0 -164
- package/packages/core/src/stores/LocalAuthStore.ts +0 -199
- package/packages/core/src/types.ts +0 -1042
- package/packages/core/tests/auth-store.test.ts +0 -300
- package/packages/core/tests/error-code.test.ts +0 -61
- package/packages/core/tests/error.test.ts +0 -24
- package/packages/core/tests/fetch.test.ts +0 -286
- package/packages/core/tests/mocks.ts +0 -139
- package/packages/core/tests/observability.test.ts +0 -86
- package/packages/core/tests/refresh-hardening.test.ts +0 -164
- package/packages/core/tests/refresh-observability.test.ts +0 -111
- package/packages/core/tests/retry.test.ts +0 -106
- package/packages/core/tests/serialize.test.ts +0 -12
- package/packages/core/tests/timeout.test.ts +0 -79
- package/packages/core/tsconfig.json +0 -5
- package/packages/core/tsup.config.ts +0 -11
- package/packages/db/LICENSE +0 -21
- package/packages/db/README.md +0 -152
- package/packages/db/VENDORED.md +0 -93
- package/packages/db/dist/index.cjs +0 -544
- package/packages/db/dist/index.d.cts +0 -1111
- package/packages/db/dist/index.d.ts +0 -1111
- package/packages/db/dist/index.js +0 -541
- package/packages/db/node_modules/.bin/esbuild +0 -19
- package/packages/db/node_modules/.bin/tsc +0 -22
- package/packages/db/node_modules/.bin/tsserver +0 -22
- package/packages/db/node_modules/.bin/tsup +0 -22
- package/packages/db/node_modules/.bin/tsup-node +0 -22
- package/packages/db/node_modules/.bin/vite +0 -22
- package/packages/db/node_modules/.bin/vitest +0 -22
- package/packages/db/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/db/package.json +0 -62
- package/packages/db/src/DatabaseService.ts +0 -170
- package/packages/db/src/QueryBuilder.ts +0 -830
- package/packages/db/src/index.ts +0 -2
- package/packages/db/src/pgrst-types/common/common.ts +0 -86
- package/packages/db/src/pgrst-types/common/rpc.ts +0 -151
- package/packages/db/src/pgrst-types/feature-flags.ts +0 -20
- package/packages/db/src/pgrst-types/types.ts +0 -134
- package/packages/db/src/select-query-parser/parser.ts +0 -479
- package/packages/db/src/select-query-parser/result.ts +0 -553
- package/packages/db/src/select-query-parser/types.ts +0 -132
- package/packages/db/src/select-query-parser/utils.ts +0 -707
- package/packages/db/tests/filters.test.ts +0 -81
- package/packages/db/tests/mutations-filtered.e2e.test.ts +0 -132
- package/packages/db/tests/mutations-filtered.test.ts +0 -188
- package/packages/db/tests/order.test.ts +0 -45
- package/packages/db/tests/rpc.test.ts +0 -41
- package/packages/db/tests/scale/build-large-schema.ts +0 -94
- package/packages/db/tests/scale/scale-compile.test.ts +0 -167
- package/packages/db/tests/schema.test.ts +0 -77
- package/packages/db/tests/single-accept.e2e.test.ts +0 -123
- package/packages/db/tests/single.test.ts +0 -211
- package/packages/db/tests/types/filters.test-d.ts +0 -52
- package/packages/db/tests/types/fixtures.ts +0 -40
- package/packages/db/tests/types/from-views.test-d.ts +0 -18
- package/packages/db/tests/types/mutations.test-d.ts +0 -23
- package/packages/db/tests/types/rpc.test-d.ts +0 -60
- package/packages/db/tests/types/schema-shape.test-d.ts +0 -8
- package/packages/db/tests/types/select-inference.test-d.ts +0 -38
- package/packages/db/tests/vendored/fixtures.ts +0 -83
- package/packages/db/tests/vendored/get-result.test-d.ts +0 -75
- package/packages/db/tsconfig.json +0 -5
- package/packages/db/tsconfig.test-d.json +0 -5
- package/packages/db/tsup.config.ts +0 -11
- package/packages/db/vitest.config.ts +0 -8
- package/packages/functions/LICENSE +0 -21
- package/packages/functions/README.md +0 -96
- package/packages/functions/dist/index.cjs +0 -173
- package/packages/functions/dist/index.d.cts +0 -81
- package/packages/functions/dist/index.d.ts +0 -81
- package/packages/functions/dist/index.js +0 -168
- package/packages/functions/node_modules/.bin/esbuild +0 -19
- package/packages/functions/node_modules/.bin/tsc +0 -22
- package/packages/functions/node_modules/.bin/tsserver +0 -22
- package/packages/functions/node_modules/.bin/tsup +0 -22
- package/packages/functions/node_modules/.bin/tsup-node +0 -22
- package/packages/functions/node_modules/.bin/vite +0 -22
- package/packages/functions/node_modules/.bin/vitest +0 -22
- package/packages/functions/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/functions/package.json +0 -60
- package/packages/functions/src/FunctionsService.ts +0 -188
- package/packages/functions/src/errors.ts +0 -70
- package/packages/functions/src/index.ts +0 -6
- package/packages/functions/tests/invoke.test.ts +0 -97
- package/packages/functions/tests/response-type-errors.test.ts +0 -135
- package/packages/functions/tsconfig.json +0 -5
- package/packages/functions/tsup.config.ts +0 -11
- package/packages/gen/LICENSE +0 -21
- package/packages/gen/README.md +0 -84
- package/packages/gen/dist/cli.cjs +0 -334
- package/packages/gen/dist/cli.d.cts +0 -1
- package/packages/gen/dist/cli.d.ts +0 -1
- package/packages/gen/dist/cli.js +0 -332
- package/packages/gen/dist/index.cjs +0 -257
- package/packages/gen/dist/index.d.cts +0 -12
- package/packages/gen/dist/index.d.ts +0 -12
- package/packages/gen/dist/index.js +0 -255
- package/packages/gen/node_modules/.bin/esbuild +0 -19
- package/packages/gen/node_modules/.bin/tsc +0 -22
- package/packages/gen/node_modules/.bin/tsserver +0 -22
- package/packages/gen/node_modules/.bin/tsup +0 -22
- package/packages/gen/node_modules/.bin/tsup-node +0 -22
- package/packages/gen/node_modules/.bin/vite +0 -22
- package/packages/gen/node_modules/.bin/vitest +0 -22
- package/packages/gen/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/gen/package.json +0 -66
- package/packages/gen/src/cli.ts +0 -67
- package/packages/gen/src/generate.ts +0 -0
- package/packages/gen/src/index.ts +0 -2
- package/packages/gen/tests/compile.test.ts +0 -213
- package/packages/gen/tests/e2e.test.ts +0 -130
- package/packages/gen/tests/generate.test.ts +0 -396
- package/packages/gen/tsconfig.json +0 -5
- package/packages/gen/tsup.config.ts +0 -11
- package/packages/notifications/LICENSE +0 -21
- package/packages/notifications/README.md +0 -134
- package/packages/notifications/dist/index.cjs +0 -128
- package/packages/notifications/dist/index.d.cts +0 -81
- package/packages/notifications/dist/index.d.ts +0 -81
- package/packages/notifications/dist/index.js +0 -125
- package/packages/notifications/node_modules/.bin/esbuild +0 -19
- package/packages/notifications/node_modules/.bin/tsc +0 -22
- package/packages/notifications/node_modules/.bin/tsserver +0 -22
- package/packages/notifications/node_modules/.bin/tsup +0 -22
- package/packages/notifications/node_modules/.bin/tsup-node +0 -22
- package/packages/notifications/node_modules/.bin/vite +0 -22
- package/packages/notifications/node_modules/.bin/vitest +0 -22
- package/packages/notifications/package.json +0 -60
- package/packages/notifications/src/NotificationsService.ts +0 -230
- package/packages/notifications/src/index.ts +0 -19
- package/packages/notifications/tsconfig.json +0 -5
- package/packages/notifications/tsup.config.ts +0 -11
- package/packages/realtime/LICENSE +0 -21
- package/packages/realtime/README.md +0 -183
- package/packages/realtime/dist/index.cjs +0 -977
- package/packages/realtime/dist/index.d.cts +0 -259
- package/packages/realtime/dist/index.d.ts +0 -259
- package/packages/realtime/dist/index.js +0 -973
- package/packages/realtime/node_modules/.bin/esbuild +0 -19
- package/packages/realtime/node_modules/.bin/tsc +0 -22
- package/packages/realtime/node_modules/.bin/tsserver +0 -22
- package/packages/realtime/node_modules/.bin/tsup +0 -22
- package/packages/realtime/node_modules/.bin/tsup-node +0 -22
- package/packages/realtime/node_modules/.bin/vite +0 -22
- package/packages/realtime/node_modules/.bin/vitest +0 -22
- package/packages/realtime/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/realtime/package.json +0 -60
- package/packages/realtime/src/AuraChannel.ts +0 -485
- package/packages/realtime/src/HeartbeatManager.ts +0 -73
- package/packages/realtime/src/RealtimeService.ts +0 -505
- package/packages/realtime/src/columnFilter.ts +0 -301
- package/packages/realtime/src/index.ts +0 -4
- package/packages/realtime/tests/ack-routing.test.ts +0 -81
- package/packages/realtime/tests/column-filter.test.ts +0 -144
- package/packages/realtime/tests/dispatch.test.ts +0 -191
- package/packages/realtime/tests/heartbeat.test.ts +0 -67
- package/packages/realtime/tests/http-broadcast.test.ts +0 -68
- package/packages/realtime/tests/realtime-token.test.ts +0 -43
- package/packages/realtime/tests/reconnect-race.test.ts +0 -149
- package/packages/realtime/tests/ref-id.test.ts +0 -34
- package/packages/realtime/tests/set-auth.test.ts +0 -70
- package/packages/realtime/tsconfig.json +0 -5
- package/packages/realtime/tsup.config.ts +0 -11
- package/packages/storage/LICENSE +0 -21
- package/packages/storage/README.md +0 -141
- package/packages/storage/dist/index.cjs +0 -333
- package/packages/storage/dist/index.d.cts +0 -185
- package/packages/storage/dist/index.d.ts +0 -185
- package/packages/storage/dist/index.js +0 -329
- package/packages/storage/node_modules/.bin/esbuild +0 -19
- package/packages/storage/node_modules/.bin/tsc +0 -22
- package/packages/storage/node_modules/.bin/tsserver +0 -22
- package/packages/storage/node_modules/.bin/tsup +0 -22
- package/packages/storage/node_modules/.bin/tsup-node +0 -22
- package/packages/storage/node_modules/.bin/vite +0 -22
- package/packages/storage/node_modules/.bin/vitest +0 -22
- package/packages/storage/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/packages/storage/package.json +0 -60
- package/packages/storage/src/DownloadBuilder.ts +0 -60
- package/packages/storage/src/StorageService.ts +0 -323
- package/packages/storage/src/index.ts +0 -2
- package/packages/storage/src/path.ts +0 -35
- package/packages/storage/src/transform.ts +0 -15
- package/packages/storage/tests/download.test.ts +0 -64
- package/packages/storage/tests/parity.test.ts +0 -154
- package/packages/storage/tests/path.test.ts +0 -87
- package/packages/storage/tests/transform.test.ts +0 -79
- package/packages/storage/tsconfig.json +0 -5
- package/packages/storage/tsup.config.ts +0 -11
- package/pnpm-workspace.yaml +0 -24
- package/tsconfig.base.json +0 -15
- /package/{packages/aurabase/dist → dist}/index.cjs +0 -0
- /package/{packages/aurabase/dist → dist}/index.js +0 -0
- /package/{packages/aurabase/dist → dist}/ssr.cjs +0 -0
- /package/{packages/aurabase/dist → dist}/ssr.js +0 -0
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from 'vitest'
|
|
2
|
-
import { DatabaseService } from '../../src/DatabaseService'
|
|
3
|
-
import type { Database } from './fixtures'
|
|
4
|
-
|
|
5
|
-
declare const db: DatabaseService<Database>
|
|
6
|
-
|
|
7
|
-
// COMPL LOT 4 : `from()` accepte les Views (générées par LOT C), pas seulement les
|
|
8
|
-
// Tables. La vue `active_users` est non updatable → uniquement queryable en lecture.
|
|
9
|
-
|
|
10
|
-
test('from(view).select(col) compile et infère le Row de la vue', async () => {
|
|
11
|
-
const { data } = await db.from('active_users').select('email')
|
|
12
|
-
expectTypeOf(data).toEqualTypeOf<{ email: string }[] | null>()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('from(view).select(*) → Row complète de la vue', async () => {
|
|
16
|
-
const { data } = await db.from('active_users').select('*')
|
|
17
|
-
expectTypeOf(data).toEqualTypeOf<{ id: string; email: string }[] | null>()
|
|
18
|
-
})
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DatabaseService } from '../../src/DatabaseService'
|
|
2
|
-
import type { Database } from './fixtures'
|
|
3
|
-
|
|
4
|
-
declare const db: DatabaseService<Database>
|
|
5
|
-
|
|
6
|
-
test('insert exige les champs requis', () => {
|
|
7
|
-
db.from('posts').insert({ author_id: 'u', title: 't' }) // OK (id optionnel)
|
|
8
|
-
// @ts-expect-error title requis manquant
|
|
9
|
-
db.from('posts').insert({ author_id: 'u' })
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
test('update accepte un body partiel typé', () => {
|
|
13
|
-
db.from('posts').update('id1', { title: 'new' }) // OK
|
|
14
|
-
// @ts-expect-error colonne inconnue
|
|
15
|
-
db.from('posts').update('id1', { nope: 1 })
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('upsert typé sur Insert (array ou objet)', () => {
|
|
19
|
-
db.from('posts').upsert({ author_id: 'u', title: 't' }) // OK
|
|
20
|
-
db.from('posts').upsert([{ author_id: 'u', title: 't' }]) // OK
|
|
21
|
-
// @ts-expect-error title requis manquant
|
|
22
|
-
db.from('posts').upsert({ author_id: 'u' })
|
|
23
|
-
})
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from 'vitest'
|
|
2
|
-
import { DatabaseService } from '../../src/DatabaseService'
|
|
3
|
-
|
|
4
|
-
// Fixture Database locale avec une fonction scalaire et une fonction SETOF liée
|
|
5
|
-
// à une table (parité avec la sortie attendue de `@aurabase/gen` Phase B).
|
|
6
|
-
type DB = {
|
|
7
|
-
public: {
|
|
8
|
-
Tables: {
|
|
9
|
-
things: {
|
|
10
|
-
Row: { id: number; name: string }
|
|
11
|
-
Insert: { id?: number; name: string }
|
|
12
|
-
Update: { id?: number; name?: string }
|
|
13
|
-
Relationships: []
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
Views: Record<string, never>
|
|
17
|
-
Functions: {
|
|
18
|
-
add: { Args: { a: number; b: number }; Returns: number }
|
|
19
|
-
list_things: {
|
|
20
|
-
Args: Record<string, never>
|
|
21
|
-
Returns: { id: number; name: string }[]
|
|
22
|
-
SetofOptions: { isSetofReturn: true; isOneToOne: false; to: 'things'; from: '*' }
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
Enums: Record<string, never>
|
|
26
|
-
CompositeTypes: Record<string, never>
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare const db: DatabaseService<DB>
|
|
31
|
-
// Fallback permissif : Database = any (comportement historique conservé).
|
|
32
|
-
declare const untyped: DatabaseService
|
|
33
|
-
|
|
34
|
-
test('rpc fort : args typés sur Schema["Functions"]', () => {
|
|
35
|
-
db.rpc('add', { a: 1, b: 2 }) // OK
|
|
36
|
-
// @ts-expect-error mauvais type d'arg (a doit être number)
|
|
37
|
-
db.rpc('add', { a: 'x', b: 2 })
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
test('rpc SETOF : select post-rpc typé sur la table liée (SetofOptions.to)', async () => {
|
|
41
|
-
const { data } = await db.rpc('list_things', {}).select('id,name').single()
|
|
42
|
-
expectTypeOf(data).toMatchTypeOf<{ id: number; name: string } | null>()
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// Verrouille le fix #1 (double-emballage) : `Fn['Result']` est DÉJÀ la charge
|
|
46
|
-
// utile complète (scalaire pour une fonction scalaire, tableau pour un SETOF)
|
|
47
|
-
// — le 5e générique du builder ne doit PAS ajouter un `[]` par-dessus.
|
|
48
|
-
test('rpc fort : retour scalaire (Result), pas de sur-emballage en tableau', async () => {
|
|
49
|
-
const { data } = await db.rpc('add', { a: 1, b: 2 })
|
|
50
|
-
expectTypeOf(data).toEqualTypeOf<number | null>()
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test('rpc SETOF sans .select() : Result est déjà un tableau (pas `[][]`)', async () => {
|
|
54
|
-
const { data } = await db.rpc('list_things', {})
|
|
55
|
-
expectTypeOf(data).toEqualTypeOf<{ id: number; name: string }[] | null>()
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('rpc fallback permissif (Database = any)', () => {
|
|
59
|
-
untyped.rpc('whatever', { anything: true }) // OK, pas d'erreur de compilation
|
|
60
|
-
})
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from 'vitest'
|
|
2
|
-
import type { GenericSchema } from '../../src/pgrst-types/common/common'
|
|
3
|
-
import type { Database } from './fixtures'
|
|
4
|
-
|
|
5
|
-
// Un Database à la forme générée par @aurabase/gen (Phase 1) doit satisfaire GenericSchema.
|
|
6
|
-
test('le Database généré satisfait GenericSchema', () => {
|
|
7
|
-
expectTypeOf<Database['public']>().toMatchTypeOf<GenericSchema>()
|
|
8
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from 'vitest'
|
|
2
|
-
import { DatabaseService } from '../../src/DatabaseService'
|
|
3
|
-
import type { Database } from './fixtures'
|
|
4
|
-
|
|
5
|
-
declare const db: DatabaseService<Database>
|
|
6
|
-
|
|
7
|
-
test('select colonnes → type restreint', async () => {
|
|
8
|
-
const { data } = await db.from('users').select('id, email')
|
|
9
|
-
expectTypeOf(data).toEqualTypeOf<{ id: string; email: string }[] | null>()
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
test('select embed many-to-one → objet imbriqué', async () => {
|
|
13
|
-
// Contrat postgrest-js : la FK `posts.author_id` étant NOT NULL dans la Row,
|
|
14
|
-
// l'embed many-to-one est non nullable (deviendrait `| null` si author_id: string | null).
|
|
15
|
-
const { data } = await db.from('posts').select('title, author:users(email)')
|
|
16
|
-
expectTypeOf(data).toEqualTypeOf<{ title: string; author: { email: string } }[] | null>()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('single() → objet | null', async () => {
|
|
20
|
-
const { data } = await db.from('users').select('id').single()
|
|
21
|
-
expectTypeOf(data).toEqualTypeOf<{ id: string } | null>()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('maybeSingle() → objet | null', async () => {
|
|
25
|
-
const { data } = await db.from('users').select('email').maybeSingle()
|
|
26
|
-
expectTypeOf(data).toEqualTypeOf<{ email: string } | null>()
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('select * → Row complète', async () => {
|
|
30
|
-
const { data } = await db.from('users').select('*')
|
|
31
|
-
expectTypeOf(data).toEqualTypeOf<{ id: string; email: string; bio: string | null }[] | null>()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test("client non typé (Database = any) → data permissif, pas d'erreur de compilation", async () => {
|
|
35
|
-
const untyped = db as unknown as DatabaseService
|
|
36
|
-
const { data } = await untyped.from('whatever').select('a, b')
|
|
37
|
-
expectTypeOf(data).not.toBeNever()
|
|
38
|
-
})
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// LOT 6 (I7 — vendoré sans tests type-level) : fixture dédiée aux tests de
|
|
2
|
-
// régression sur le code vendoré (`select-query-parser/*`, `pgrst-types/*`).
|
|
3
|
-
// Volontairement distincte de `tests/types/fixtures.ts` (utilisé par les tests
|
|
4
|
-
// de `DatabaseService`/`QueryBuilder`) : celle-ci couvre en plus le cas
|
|
5
|
-
// one-to-many (tableau) et un embed imbriqué sur 2 niveaux, nécessaires pour
|
|
6
|
-
// tester `GetResult` directement (voir `get-result.test-d.ts`).
|
|
7
|
-
export interface Database {
|
|
8
|
-
public: {
|
|
9
|
-
Tables: {
|
|
10
|
-
users: {
|
|
11
|
-
Row: { id: string; email: string }
|
|
12
|
-
Insert: { id?: string; email: string }
|
|
13
|
-
Update: { id?: string; email?: string }
|
|
14
|
-
Relationships: []
|
|
15
|
-
}
|
|
16
|
-
// many-to-one NOT NULL : posts.author_id -> users.id
|
|
17
|
-
posts: {
|
|
18
|
-
Row: { id: string; author_id: string; title: string }
|
|
19
|
-
Insert: { id?: string; author_id: string; title: string }
|
|
20
|
-
Update: { id?: string; author_id?: string; title?: string }
|
|
21
|
-
Relationships: [
|
|
22
|
-
{
|
|
23
|
-
foreignKeyName: 'posts_author_id_fkey'
|
|
24
|
-
columns: ['author_id']
|
|
25
|
-
isOneToOne: false
|
|
26
|
-
referencedRelation: 'users'
|
|
27
|
-
referencedColumns: ['id']
|
|
28
|
-
},
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
// many-to-one NULLABLE : reviews.reviewer_id -> users.id (nullable)
|
|
32
|
-
reviews: {
|
|
33
|
-
Row: { id: string; reviewer_id: string | null; comment: string }
|
|
34
|
-
Insert: { id?: string; reviewer_id?: string | null; comment: string }
|
|
35
|
-
Update: { id?: string; reviewer_id?: string | null; comment?: string }
|
|
36
|
-
Relationships: [
|
|
37
|
-
{
|
|
38
|
-
foreignKeyName: 'reviews_reviewer_id_fkey'
|
|
39
|
-
columns: ['reviewer_id']
|
|
40
|
-
isOneToOne: false
|
|
41
|
-
referencedRelation: 'users'
|
|
42
|
-
referencedColumns: ['id']
|
|
43
|
-
},
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
// one-to-many (côté "many") : comments.post_id -> posts.id NOT NULL.
|
|
47
|
-
// Embedder `comments` DEPUIS `posts` donne un tableau (voir get-result.test-d.ts).
|
|
48
|
-
comments: {
|
|
49
|
-
Row: { id: string; post_id: string; body: string }
|
|
50
|
-
Insert: { id?: string; post_id: string; body: string }
|
|
51
|
-
Update: { id?: string; post_id?: string; body?: string }
|
|
52
|
-
Relationships: [
|
|
53
|
-
{
|
|
54
|
-
foreignKeyName: 'comments_post_id_fkey'
|
|
55
|
-
columns: ['post_id']
|
|
56
|
-
isOneToOne: false
|
|
57
|
-
referencedRelation: 'posts'
|
|
58
|
-
referencedColumns: ['id']
|
|
59
|
-
},
|
|
60
|
-
]
|
|
61
|
-
}
|
|
62
|
-
// 2e niveau d'imbrication pour l'embed profond : replies.comment_id -> comments.id.
|
|
63
|
-
replies: {
|
|
64
|
-
Row: { id: string; comment_id: string; text: string }
|
|
65
|
-
Insert: { id?: string; comment_id: string; text: string }
|
|
66
|
-
Update: { id?: string; comment_id?: string; text?: string }
|
|
67
|
-
Relationships: [
|
|
68
|
-
{
|
|
69
|
-
foreignKeyName: 'replies_comment_id_fkey'
|
|
70
|
-
columns: ['comment_id']
|
|
71
|
-
isOneToOne: false
|
|
72
|
-
referencedRelation: 'comments'
|
|
73
|
-
referencedColumns: ['id']
|
|
74
|
-
},
|
|
75
|
-
]
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
Views: Record<string, never>
|
|
79
|
-
Functions: Record<string, never>
|
|
80
|
-
Enums: Record<string, never>
|
|
81
|
-
CompositeTypes: Record<string, never>
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// LOT 6 (I7 — vendoré sans tests type-level) : régression de forme sur le
|
|
2
|
-
// résolveur vendoré (`GetResult`, `select-query-parser/*`), testé ICI
|
|
3
|
-
// directement (pas via `DatabaseService`/`QueryBuilder`) pour détecter une
|
|
4
|
-
// régression de comportement dès le prochain resync (voir VENDORED.md),
|
|
5
|
-
// indépendamment de l'évolution du reste du query builder.
|
|
6
|
-
//
|
|
7
|
-
// Couvre les trois formes d'embed dont la nullabilité/l'arité diffère :
|
|
8
|
-
// - many-to-one NOT NULL → objet non-null
|
|
9
|
-
// - many-to-one NULLABLE → objet | null
|
|
10
|
-
// - one-to-many → tableau
|
|
11
|
-
// … plus l'aliasing (colonne scalaire + clé d'embed) et un embed imbriqué sur
|
|
12
|
-
// 2 niveaux (tableau de tableaux correctement typé).
|
|
13
|
-
import { expectTypeOf } from 'vitest'
|
|
14
|
-
import type { GetResult } from '../../src/select-query-parser/result'
|
|
15
|
-
import type { Database } from './fixtures'
|
|
16
|
-
|
|
17
|
-
type Public = Database['public']
|
|
18
|
-
// Même pin que `AuraClientOptionsT` (src/QueryBuilder.ts) — voir VENDORED.md
|
|
19
|
-
// « PostgrestVersion figé à '12' ».
|
|
20
|
-
type ClientOpts = { PostgrestVersion: '12' }
|
|
21
|
-
|
|
22
|
-
type PostsRow = Public['Tables']['posts']['Row']
|
|
23
|
-
type PostsRel = Public['Tables']['posts']['Relationships']
|
|
24
|
-
type ReviewsRow = Public['Tables']['reviews']['Row']
|
|
25
|
-
type ReviewsRel = Public['Tables']['reviews']['Relationships']
|
|
26
|
-
|
|
27
|
-
test('embed many-to-one NOT NULL (posts.author_id -> users, NOT NULL) → objet non-null, clé aliasée', () => {
|
|
28
|
-
type Result = GetResult<Public, PostsRow, 'posts', PostsRel, '*, author:users(email)', ClientOpts>
|
|
29
|
-
expectTypeOf<Result>().toEqualTypeOf<{
|
|
30
|
-
id: string
|
|
31
|
-
author_id: string
|
|
32
|
-
title: string
|
|
33
|
-
author: { email: string }
|
|
34
|
-
}>()
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test('embed many-to-one NULLABLE (reviews.reviewer_id -> users, nullable) → objet | null', () => {
|
|
38
|
-
type Result = GetResult<Public, ReviewsRow, 'reviews', ReviewsRel, '*, reviewer:users(email)', ClientOpts>
|
|
39
|
-
expectTypeOf<Result>().toEqualTypeOf<{
|
|
40
|
-
id: string
|
|
41
|
-
reviewer_id: string | null
|
|
42
|
-
comment: string
|
|
43
|
-
reviewer: { email: string } | null
|
|
44
|
-
}>()
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('embed one-to-many (posts -> comments, comments.post_id -> posts) → tableau', () => {
|
|
48
|
-
type Result = GetResult<Public, PostsRow, 'posts', PostsRel, '*, comments(*)', ClientOpts>
|
|
49
|
-
expectTypeOf<Result>().toEqualTypeOf<{
|
|
50
|
-
id: string
|
|
51
|
-
author_id: string
|
|
52
|
-
title: string
|
|
53
|
-
comments: { id: string; post_id: string; body: string }[]
|
|
54
|
-
}>()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('alias sur colonne scalaire', () => {
|
|
58
|
-
type Result = GetResult<Public, PostsRow, 'posts', PostsRel, 'renamedTitle:title', ClientOpts>
|
|
59
|
-
expectTypeOf<Result>().toEqualTypeOf<{ renamedTitle: string }>()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('embed imbriqué 2 niveaux (posts -> comments -> replies) → forme correcte (tableau de tableaux)', () => {
|
|
63
|
-
type Result = GetResult<Public, PostsRow, 'posts', PostsRel, '*, comments(*, replies(*))', ClientOpts>
|
|
64
|
-
expectTypeOf<Result>().toEqualTypeOf<{
|
|
65
|
-
id: string
|
|
66
|
-
author_id: string
|
|
67
|
-
title: string
|
|
68
|
-
comments: {
|
|
69
|
-
id: string
|
|
70
|
-
post_id: string
|
|
71
|
-
body: string
|
|
72
|
-
replies: { id: string; comment_id: string; text: string }[]
|
|
73
|
-
}[]
|
|
74
|
-
}>()
|
|
75
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Aurabase
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# @aurabase/functions
|
|
2
|
-
|
|
3
|
-
Service d'invocation d'edge functions du SDK Aurabase : appel de fonctions avec enveloppe routée (méthode/chemin/headers), jobs asynchrones et cron.
|
|
4
|
-
|
|
5
|
-
 
|
|
6
|
-
|
|
7
|
-
> Pre-release — pas encore publié sur npm.
|
|
8
|
-
|
|
9
|
-
Fait partie du SDK **[aurabase](../aurabase)**. Installé automatiquement avec `aurabase` ; ce package est publié séparément pour un usage ciblé / tree-shaking.
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm i @aurabase/functions
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
> Ce package dépend de `@aurabase/core` (`workspace:*` en interne, résolu en semver côté npm). Si vous utilisez déjà le package `aurabase`, `@aurabase/functions` est déjà inclus — cette installation ciblée n'est utile que pour composer votre propre client ou limiter la taille du bundle.
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
Dans l'usage courant, `FunctionsService` n'est jamais instancié directement : il est exposé par le client principal sous `aura.functions`.
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import { createClient } from 'aurabase'
|
|
25
|
-
|
|
26
|
-
const aura = createClient('http://localhost:8080', 'my-project', 'aura_anon_xxx')
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Invocation
|
|
30
|
-
|
|
31
|
-
`invoke<T>()` enveloppe la requête (`{ method, path, headers, body }`) et dé-wrap la réponse JSON du backend — tout est bufferisé, pas de streaming (voir Limitations).
|
|
32
|
-
|
|
33
|
-
```ts
|
|
34
|
-
const { data, error } = await aura.functions.invoke<{ ok: boolean }>('hello-world', {
|
|
35
|
-
body: { name: 'Ada' },
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
if (error) throw error
|
|
39
|
-
console.log(data!.ok)
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Options complètes : `method`, `path` (sous-route à l'intérieur de la fonction), `headers` (transmis à la fonction elle-même, pas des headers de transport), `signal`, `timeout`.
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
const controller = new AbortController()
|
|
46
|
-
|
|
47
|
-
const { error } = await aura.functions.invoke('slow-job', {
|
|
48
|
-
method: 'POST',
|
|
49
|
-
path: '/process',
|
|
50
|
-
headers: { 'x-request-source': 'studio' },
|
|
51
|
-
timeout: 5000, // ms — annule automatiquement au-delà
|
|
52
|
-
signal: controller.signal, // ou : annulation manuelle via controller.abort()
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
// Une annulation (timeout ou signal) remonte toujours en AuraError code 'timeout'.
|
|
56
|
-
if (error?.code === 'timeout') {
|
|
57
|
-
console.warn('invocation annulée ou trop lente')
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Fonctions (métadonnées)
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
const { data: fns } = await aura.functions.list()
|
|
65
|
-
const { data: fn } = await aura.functions.get(fns![0]!.id)
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Jobs asynchrones (extra vs `@supabase/functions-js`)
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
const { data: jobs } = await aura.functions.listJobs({ status: 'pending', limit: 20 })
|
|
72
|
-
const { data: job } = await aura.functions.getJob(jobs![0]!.id)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Cron (extra vs `@supabase/functions-js`)
|
|
76
|
-
|
|
77
|
-
```ts
|
|
78
|
-
await aura.functions.createCronJob('nightly-cleanup', '0 3 * * *', 'cleanup-fn', {
|
|
79
|
-
payload: { dryRun: false },
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
const { data: crons } = await aura.functions.listCronJobs()
|
|
83
|
-
await aura.functions.deleteCronJob('nightly-cleanup')
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Limitations
|
|
87
|
-
|
|
88
|
-
- Pas de streaming de réponse : `invoke()` bufferise toujours l'intégralité du corps JSON avant de résoudre (pas de lecture incrémentale, pas de réponse SSE/chunked exploitable).
|
|
89
|
-
- Pas de `responseType` (`json`/`text`/`blob`) : la réponse est toujours parsée comme JSON puis dé-wrappée (`{data}` → contenu).
|
|
90
|
-
- Pas de sélection de région d'exécution.
|
|
91
|
-
- `headers` est transmis tel quel à la fonction invoquée — ce ne sont pas des headers de transport HTTP (pas de contrôle sur ceux injectés par le pipeline : `apikey`, `Authorization`, `Content-Type`).
|
|
92
|
-
- Pas de `getCronJob()` ni `updateCronJob()` : seuls `listCronJobs`, `createCronJob` et `deleteCronJob` sont exposés.
|
|
93
|
-
|
|
94
|
-
## Documentation
|
|
95
|
-
|
|
96
|
-
Référence complète du SDK (tous les services, types partagés, SSR) : [README racine](../../README.md).
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@aurabase/core');
|
|
4
|
-
|
|
5
|
-
// src/FunctionsService.ts
|
|
6
|
-
var RELAY_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
7
|
-
function isRelayStatus(status) {
|
|
8
|
-
return status === 0 || RELAY_STATUSES.has(status);
|
|
9
|
-
}
|
|
10
|
-
var FunctionsHttpError = class _FunctionsHttpError extends core.AuraError {
|
|
11
|
-
context;
|
|
12
|
-
constructor(status, body, context) {
|
|
13
|
-
super(status, body);
|
|
14
|
-
this.name = "FunctionsHttpError";
|
|
15
|
-
this.context = context;
|
|
16
|
-
Object.setPrototypeOf(this, _FunctionsHttpError.prototype);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var FunctionsRelayError = class _FunctionsRelayError extends core.AuraError {
|
|
20
|
-
context;
|
|
21
|
-
constructor(status, body, context) {
|
|
22
|
-
super(status, body);
|
|
23
|
-
this.name = "FunctionsRelayError";
|
|
24
|
-
this.context = context;
|
|
25
|
-
Object.setPrototypeOf(this, _FunctionsRelayError.prototype);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
function toFunctionsError(err, context) {
|
|
29
|
-
const body = err.details != null ? err.details : { error: { code: err.code, message: err.message } };
|
|
30
|
-
return isRelayStatus(err.status) ? new FunctionsRelayError(err.status, body, err.details) : new FunctionsHttpError(err.status, body, err.details);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/FunctionsService.ts
|
|
34
|
-
var FunctionsService = class extends core.BaseService {
|
|
35
|
-
constructor(client) {
|
|
36
|
-
super(client);
|
|
37
|
-
}
|
|
38
|
-
get prefix() {
|
|
39
|
-
return `/v1/functions/${this.client.projectId}`;
|
|
40
|
-
}
|
|
41
|
-
// -- Function invocation ----------------------------------------------------
|
|
42
|
-
/**
|
|
43
|
-
* Invoque une edge function.
|
|
44
|
-
*
|
|
45
|
-
* `responseType` (parité `@supabase/functions-js`, défaut `'json'`) :
|
|
46
|
-
* - `'json'` : chemin PIPELINE inchangé (refresh proactif centralisé, injection
|
|
47
|
-
* apikey/Authorization, dé-wrapping `{data,meta}`, retryConfig). Non-régression.
|
|
48
|
-
* - `'text' | 'blob' | 'arrayBuffer'` : chemin TRANSPORT BRUT `client.fetchFn`
|
|
49
|
-
* (patron `StorageService`, SANS toucher `core/fetch.ts`) — refresh proactif
|
|
50
|
-
* manuel, pose de `Authorization`/`apikey`, puis `res.text()/blob()/arrayBuffer()`
|
|
51
|
-
* sans dé-wrapping (le corps HTTP est renvoyé tel quel).
|
|
52
|
-
*
|
|
53
|
-
* Erreurs typées (parité) : une réponse HTTP non-2xx → `FunctionsHttpError`, une
|
|
54
|
-
* panne de relais/infra (réseau, 502/503/504) → `FunctionsRelayError` ; les deux
|
|
55
|
-
* sous-classent `AuraError` (rétrocompat `isAuraError`/champ `error`). `timeout`/
|
|
56
|
-
* `signal` continuent de produire le code `timeout`.
|
|
57
|
-
*/
|
|
58
|
-
async invoke(slug, options) {
|
|
59
|
-
const controller = new AbortController();
|
|
60
|
-
let timeoutId;
|
|
61
|
-
const userSignal = options?.signal;
|
|
62
|
-
const onAbort = () => controller.abort();
|
|
63
|
-
if (options?.timeout) timeoutId = setTimeout(() => controller.abort(), options.timeout);
|
|
64
|
-
if (userSignal) {
|
|
65
|
-
if (userSignal.aborted) controller.abort();
|
|
66
|
-
else userSignal.addEventListener("abort", onAbort, { once: true });
|
|
67
|
-
}
|
|
68
|
-
const cleanup = () => {
|
|
69
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
70
|
-
if (userSignal) userSignal.removeEventListener("abort", onAbort);
|
|
71
|
-
};
|
|
72
|
-
const envelope = { method: options?.method, path: options?.path, headers: options?.headers, body: options?.body };
|
|
73
|
-
const responseType = options?.responseType ?? "json";
|
|
74
|
-
const timeoutError = () => ({
|
|
75
|
-
data: null,
|
|
76
|
-
error: new core.AuraError(0, {
|
|
77
|
-
error: { code: "timeout", message: "Function invocation aborted or timed out" }
|
|
78
|
-
})
|
|
79
|
-
});
|
|
80
|
-
try {
|
|
81
|
-
if (responseType === "json") {
|
|
82
|
-
const res2 = await this.request("POST", `${this.prefix}/${slug}/invoke`, envelope, {
|
|
83
|
-
signal: controller.signal
|
|
84
|
-
});
|
|
85
|
-
if (res2.error && controller.signal.aborted) return timeoutError();
|
|
86
|
-
if (res2.error) return { data: null, error: toFunctionsError(res2.error) };
|
|
87
|
-
return res2;
|
|
88
|
-
}
|
|
89
|
-
const client = this.client;
|
|
90
|
-
const store = client.authStore;
|
|
91
|
-
if (store.token && store.refreshToken && core.isTokenExpired(store.token, 30)) {
|
|
92
|
-
await core.refreshOnce(client);
|
|
93
|
-
}
|
|
94
|
-
const headers = {
|
|
95
|
-
"Content-Type": "application/json",
|
|
96
|
-
// Négocie le mode passthrough côté backend : réponse HTTP BRUTE (statut réel de la
|
|
97
|
-
// fonction + content-type réel + corps brut) au lieu de l'enveloppe `{data,meta}`.
|
|
98
|
-
// Indispensable pour que `res.text()/blob()/arrayBuffer()` reçoive le corps de la
|
|
99
|
-
// fonction (et non l'enveloppe JSON) et que `res.status` porte le statut fonction.
|
|
100
|
-
"X-Aurabase-Invoke-Mode": "raw"
|
|
101
|
-
};
|
|
102
|
-
if (store.token) headers["Authorization"] = `Bearer ${store.token}`;
|
|
103
|
-
if (client.apiKey) headers["apikey"] = client.apiKey;
|
|
104
|
-
const res = await client.fetchFn(this.url(`${this.prefix}/${slug}/invoke`), {
|
|
105
|
-
method: "POST",
|
|
106
|
-
headers,
|
|
107
|
-
body: JSON.stringify(envelope),
|
|
108
|
-
signal: controller.signal
|
|
109
|
-
});
|
|
110
|
-
if (!res.ok) {
|
|
111
|
-
let parsed = null;
|
|
112
|
-
try {
|
|
113
|
-
parsed = await res.json();
|
|
114
|
-
} catch {
|
|
115
|
-
}
|
|
116
|
-
return { data: null, error: toFunctionsError(new core.AuraError(res.status, parsed)) };
|
|
117
|
-
}
|
|
118
|
-
let data;
|
|
119
|
-
if (responseType === "text") data = await res.text();
|
|
120
|
-
else if (responseType === "blob") data = await res.blob();
|
|
121
|
-
else data = await res.arrayBuffer();
|
|
122
|
-
return { data, error: null };
|
|
123
|
-
} catch (err) {
|
|
124
|
-
if (controller.signal.aborted || core.isAbortError(err)) return timeoutError();
|
|
125
|
-
return {
|
|
126
|
-
data: null,
|
|
127
|
-
error: new FunctionsRelayError(0, {
|
|
128
|
-
error: { code: "network_error", message: err instanceof Error ? err.message : "Function relay error" }
|
|
129
|
-
})
|
|
130
|
-
};
|
|
131
|
-
} finally {
|
|
132
|
-
cleanup();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// -- Function CRUD ----------------------------------------------------------
|
|
136
|
-
async list() {
|
|
137
|
-
return this.request("GET", `${this.prefix}`);
|
|
138
|
-
}
|
|
139
|
-
async get(id) {
|
|
140
|
-
return this.request("GET", `${this.prefix}/${id}`);
|
|
141
|
-
}
|
|
142
|
-
// -- Jobs -------------------------------------------------------------------
|
|
143
|
-
async listJobs(options) {
|
|
144
|
-
const params = new URLSearchParams();
|
|
145
|
-
if (options?.status) params.set("status", options.status);
|
|
146
|
-
if (options?.limit !== void 0) params.set("limit", String(options.limit));
|
|
147
|
-
const qs = params.toString() ? `?${params.toString()}` : "";
|
|
148
|
-
return this.request("GET", `${this.prefix}/jobs${qs}`);
|
|
149
|
-
}
|
|
150
|
-
async getJob(jobId) {
|
|
151
|
-
return this.request("GET", `${this.prefix}/jobs/${jobId}`);
|
|
152
|
-
}
|
|
153
|
-
// -- Cron -------------------------------------------------------------------
|
|
154
|
-
async listCronJobs() {
|
|
155
|
-
return this.request("GET", `${this.prefix}/cron`);
|
|
156
|
-
}
|
|
157
|
-
async createCronJob(name, schedule, functionName, options) {
|
|
158
|
-
return this.request("POST", `${this.prefix}/cron`, {
|
|
159
|
-
name,
|
|
160
|
-
schedule,
|
|
161
|
-
function_name: functionName,
|
|
162
|
-
payload: options?.payload
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
async deleteCronJob(name) {
|
|
166
|
-
return this.request("DELETE", `${this.prefix}/cron/${name}`);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
exports.FunctionsHttpError = FunctionsHttpError;
|
|
171
|
-
exports.FunctionsRelayError = FunctionsRelayError;
|
|
172
|
-
exports.FunctionsService = FunctionsService;
|
|
173
|
-
exports.isRelayStatus = isRelayStatus;
|