@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,191 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { RealtimeService } from '../src/RealtimeService'
|
|
3
|
-
import { AuraChannel } from '../src/AuraChannel'
|
|
4
|
-
import { BaseAuthStore } from '@aurabase/core'
|
|
5
|
-
import type { AuraClientLike } from '@aurabase/core'
|
|
6
|
-
|
|
7
|
-
function client(): AuraClientLike {
|
|
8
|
-
return {
|
|
9
|
-
baseUrl: 'http://x',
|
|
10
|
-
projectId: 'proj',
|
|
11
|
-
apiKey: 'k',
|
|
12
|
-
authStore: new BaseAuthStore(),
|
|
13
|
-
fetchFn: (async () => new Response('{}')) as unknown as typeof globalThis.fetch,
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
auth: { refreshSession: async () => ({ data: null, error: null }) as any },
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe('RealtimeService._dispatch — routage CDC borné par ":"', () => {
|
|
20
|
-
it('un event de `room2` ne fuite pas vers le channel `room` (préfixe)', () => {
|
|
21
|
-
const rt = new RealtimeService(client())
|
|
22
|
-
const room = new AuraChannel('room', 'proj')
|
|
23
|
-
const room2 = new AuraChannel('room2', 'proj')
|
|
24
|
-
// Insère `room` en PREMIER (l'ancien startsWith non borné l'aurait fait matcher d'abord).
|
|
25
|
-
const map = (rt as unknown as { _channels: Map<string, AuraChannel> })._channels
|
|
26
|
-
map.set('room', room)
|
|
27
|
-
map.set('room2', room2)
|
|
28
|
-
const spyRoom = vi.spyOn(room, '_onMessage').mockImplementation(() => {})
|
|
29
|
-
const spyRoom2 = vi.spyOn(room2, '_onMessage').mockImplementation(() => {})
|
|
30
|
-
|
|
31
|
-
// Message CDC : topic composite `proj:room2:public.x` (pas de channel exact de ce nom).
|
|
32
|
-
;(rt as unknown as { _dispatch: (m: unknown) => void })._dispatch({
|
|
33
|
-
type: 'event',
|
|
34
|
-
id: '1',
|
|
35
|
-
event: 'insert',
|
|
36
|
-
topic: 'proj:room2:public.x',
|
|
37
|
-
payload: {},
|
|
38
|
-
timestamp: '',
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
expect(spyRoom2).toHaveBeenCalledTimes(1)
|
|
42
|
-
expect(spyRoom).not.toHaveBeenCalled()
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
describe('AuraChannel._dispatchEvent — fallback client filtre colonne (second rideau)', () => {
|
|
47
|
-
it("un event dont le record ne matche pas `filter` n'atteint pas le callback", () => {
|
|
48
|
-
const channel = new AuraChannel('room', 'proj')
|
|
49
|
-
const cb = vi.fn()
|
|
50
|
-
channel.on(
|
|
51
|
-
'postgres_changes',
|
|
52
|
-
{ event: '*', schema: 'public', table: 'messages', filter: 'room_id=eq.42' },
|
|
53
|
-
cb,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
channel._onMessage({
|
|
57
|
-
type: 'event',
|
|
58
|
-
id: '1',
|
|
59
|
-
event: 'insert',
|
|
60
|
-
topic: 'proj:room:public.messages',
|
|
61
|
-
payload: {
|
|
62
|
-
schema: 'public',
|
|
63
|
-
table: 'messages',
|
|
64
|
-
type: 'INSERT',
|
|
65
|
-
record: { room_id: 7 },
|
|
66
|
-
old_record: null,
|
|
67
|
-
},
|
|
68
|
-
timestamp: '',
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
expect(cb).not.toHaveBeenCalled()
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('un event dont le record matche `filter` atteint le callback', () => {
|
|
75
|
-
const channel = new AuraChannel('room', 'proj')
|
|
76
|
-
const cb = vi.fn()
|
|
77
|
-
channel.on(
|
|
78
|
-
'postgres_changes',
|
|
79
|
-
{ event: '*', schema: 'public', table: 'messages', filter: 'room_id=eq.42' },
|
|
80
|
-
cb,
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
channel._onMessage({
|
|
84
|
-
type: 'event',
|
|
85
|
-
id: '2',
|
|
86
|
-
event: 'insert',
|
|
87
|
-
topic: 'proj:room:public.messages',
|
|
88
|
-
payload: {
|
|
89
|
-
schema: 'public',
|
|
90
|
-
table: 'messages',
|
|
91
|
-
type: 'INSERT',
|
|
92
|
-
record: { room_id: 42 },
|
|
93
|
-
old_record: null,
|
|
94
|
-
},
|
|
95
|
-
timestamp: '',
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
expect(cb).toHaveBeenCalledTimes(1)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('DELETE : le filtre est évalué sur old_record (record CDC vide)', () => {
|
|
102
|
-
const channel = new AuraChannel('room', 'proj')
|
|
103
|
-
const matched = vi.fn()
|
|
104
|
-
const notMatched = vi.fn()
|
|
105
|
-
channel.on(
|
|
106
|
-
'postgres_changes',
|
|
107
|
-
{ event: '*', schema: 'public', table: 'messages', filter: 'room_id=eq.42' },
|
|
108
|
-
matched,
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
channel._onMessage({
|
|
112
|
-
type: 'event',
|
|
113
|
-
id: '3',
|
|
114
|
-
event: 'delete',
|
|
115
|
-
topic: 'proj:room:public.messages',
|
|
116
|
-
payload: {
|
|
117
|
-
schema: 'public',
|
|
118
|
-
table: 'messages',
|
|
119
|
-
type: 'DELETE',
|
|
120
|
-
record: {},
|
|
121
|
-
old_record: { room_id: 42 },
|
|
122
|
-
},
|
|
123
|
-
timestamp: '',
|
|
124
|
-
})
|
|
125
|
-
expect(matched).toHaveBeenCalledTimes(1)
|
|
126
|
-
|
|
127
|
-
channel.on(
|
|
128
|
-
'postgres_changes',
|
|
129
|
-
{ event: '*', schema: 'public', table: 'messages', filter: 'room_id=eq.42' },
|
|
130
|
-
notMatched,
|
|
131
|
-
)
|
|
132
|
-
channel._onMessage({
|
|
133
|
-
type: 'event',
|
|
134
|
-
id: '4',
|
|
135
|
-
event: 'delete',
|
|
136
|
-
topic: 'proj:room:public.messages',
|
|
137
|
-
payload: {
|
|
138
|
-
schema: 'public',
|
|
139
|
-
table: 'messages',
|
|
140
|
-
type: 'DELETE',
|
|
141
|
-
record: {},
|
|
142
|
-
old_record: { room_id: 7 },
|
|
143
|
-
},
|
|
144
|
-
timestamp: '',
|
|
145
|
-
})
|
|
146
|
-
expect(notMatched).not.toHaveBeenCalled()
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
it('cible absente/non-objet => ne filtre pas (le serveur a déjà filtré, pas de faux négatif)', () => {
|
|
150
|
-
const channel = new AuraChannel('room', 'proj')
|
|
151
|
-
const cb = vi.fn()
|
|
152
|
-
channel.on(
|
|
153
|
-
'postgres_changes',
|
|
154
|
-
{ event: '*', schema: 'public', table: 'messages', filter: 'room_id=eq.42' },
|
|
155
|
-
cb,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
channel._onMessage({
|
|
159
|
-
type: 'event',
|
|
160
|
-
id: '5',
|
|
161
|
-
event: 'insert',
|
|
162
|
-
topic: 'proj:room:public.messages',
|
|
163
|
-
payload: {
|
|
164
|
-
schema: 'public',
|
|
165
|
-
table: 'messages',
|
|
166
|
-
type: 'INSERT',
|
|
167
|
-
// pas de champ `record` du tout
|
|
168
|
-
},
|
|
169
|
-
timestamp: '',
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
expect(cb).toHaveBeenCalledTimes(1)
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
it('filtre absent (non défini) => pas de fallback appliqué, event livré normalement', () => {
|
|
176
|
-
const channel = new AuraChannel('room', 'proj')
|
|
177
|
-
const cb = vi.fn()
|
|
178
|
-
channel.on('postgres_changes', { event: '*', schema: 'public', table: 'messages' }, cb)
|
|
179
|
-
|
|
180
|
-
channel._onMessage({
|
|
181
|
-
type: 'event',
|
|
182
|
-
id: '6',
|
|
183
|
-
event: 'insert',
|
|
184
|
-
topic: 'proj:room:public.messages',
|
|
185
|
-
payload: { schema: 'public', table: 'messages', type: 'INSERT', record: { room_id: 999 } },
|
|
186
|
-
timestamp: '',
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
expect(cb).toHaveBeenCalledTimes(1)
|
|
190
|
-
})
|
|
191
|
-
})
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'
|
|
2
|
-
import { HeartbeatManager } from '../src/HeartbeatManager'
|
|
3
|
-
|
|
4
|
-
class FakeWorker {
|
|
5
|
-
static instances: FakeWorker[] = []
|
|
6
|
-
onmessage: ((e: unknown) => void) | null = null
|
|
7
|
-
posted: unknown[] = []
|
|
8
|
-
terminated = false
|
|
9
|
-
constructor(public url: string) {
|
|
10
|
-
FakeWorker.instances.push(this)
|
|
11
|
-
}
|
|
12
|
-
postMessage(d: unknown) {
|
|
13
|
-
this.posted.push(d)
|
|
14
|
-
}
|
|
15
|
-
terminate() {
|
|
16
|
-
this.terminated = true
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const g = globalThis as unknown as Record<string, unknown>
|
|
21
|
-
let revoke: ReturnType<typeof vi.fn>
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
FakeWorker.instances = []
|
|
25
|
-
revoke = vi.fn()
|
|
26
|
-
g.Worker = FakeWorker
|
|
27
|
-
g.URL = { createObjectURL: vi.fn(() => 'blob:x'), revokeObjectURL: revoke }
|
|
28
|
-
})
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
vi.useRealTimers()
|
|
31
|
-
delete g.Worker
|
|
32
|
-
delete g.URL
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
describe('HeartbeatManager — Worker dédié', () => {
|
|
36
|
-
it('start() crée un Worker, ping au message worker, URL non révoquée avant stop', () => {
|
|
37
|
-
const hm = new HeartbeatManager()
|
|
38
|
-
const ping = vi.fn()
|
|
39
|
-
hm.start(ping, 25000)
|
|
40
|
-
expect(FakeWorker.instances.length).toBe(1)
|
|
41
|
-
expect(revoke).not.toHaveBeenCalled()
|
|
42
|
-
FakeWorker.instances[0].onmessage!({})
|
|
43
|
-
expect(ping).toHaveBeenCalledTimes(1)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('stop() termine le worker et révoque l’URL', () => {
|
|
47
|
-
const hm = new HeartbeatManager()
|
|
48
|
-
hm.start(vi.fn())
|
|
49
|
-
hm.stop()
|
|
50
|
-
expect(FakeWorker.instances[0].terminated).toBe(true)
|
|
51
|
-
expect(revoke).toHaveBeenCalledWith('blob:x')
|
|
52
|
-
expect(hm.isActive).toBe(false)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('sans Worker → fallback setInterval', () => {
|
|
56
|
-
delete g.Worker
|
|
57
|
-
vi.useFakeTimers()
|
|
58
|
-
const hm = new HeartbeatManager()
|
|
59
|
-
const ping = vi.fn()
|
|
60
|
-
hm.start(ping, 1000)
|
|
61
|
-
vi.advanceTimersByTime(1000)
|
|
62
|
-
expect(ping).toHaveBeenCalledTimes(1)
|
|
63
|
-
hm.stop()
|
|
64
|
-
vi.advanceTimersByTime(2000)
|
|
65
|
-
expect(ping).toHaveBeenCalledTimes(1)
|
|
66
|
-
})
|
|
67
|
-
})
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { RealtimeService } from '../src/RealtimeService'
|
|
3
|
-
import { BaseAuthStore } from '@aurabase/core'
|
|
4
|
-
import type { AuraClientLike } from '@aurabase/core'
|
|
5
|
-
|
|
6
|
-
type Captured = { url: string; init: RequestInit }
|
|
7
|
-
|
|
8
|
-
function clientWithSpy(): { client: AuraClientLike; calls: Captured[] } {
|
|
9
|
-
const calls: Captured[] = []
|
|
10
|
-
const fetchFn = (async (url: string, init: RequestInit) => {
|
|
11
|
-
calls.push({ url, init })
|
|
12
|
-
return new Response(JSON.stringify({ data: null, meta: null }), {
|
|
13
|
-
status: 200,
|
|
14
|
-
headers: { 'content-type': 'application/json' },
|
|
15
|
-
})
|
|
16
|
-
}) as unknown as typeof globalThis.fetch
|
|
17
|
-
const store = new BaseAuthStore()
|
|
18
|
-
return {
|
|
19
|
-
calls,
|
|
20
|
-
client: {
|
|
21
|
-
baseUrl: 'http://x',
|
|
22
|
-
projectId: 'proj',
|
|
23
|
-
apiKey: 'k',
|
|
24
|
-
authStore: store,
|
|
25
|
-
fetchFn,
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
-
auth: { refreshSession: async () => ({ data: null, error: null }) as any },
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('RealtimeService.httpBroadcast — envoi REST hors WebSocket', () => {
|
|
33
|
-
it('POST /v1/realtime/{projectId}/broadcast avec corps { channel, payload:{event,...} } + apikey', async () => {
|
|
34
|
-
const { client, calls } = clientWithSpy()
|
|
35
|
-
const rt = new RealtimeService(client)
|
|
36
|
-
|
|
37
|
-
const res = await rt.httpBroadcast('room-1', 'ping', { a: 1 })
|
|
38
|
-
|
|
39
|
-
expect(res.error).toBeNull()
|
|
40
|
-
expect(calls).toHaveLength(1)
|
|
41
|
-
const { url, init } = calls[0]!
|
|
42
|
-
expect(url).toBe('http://x/v1/realtime/proj/broadcast')
|
|
43
|
-
expect(init.method).toBe('POST')
|
|
44
|
-
expect(JSON.parse(init.body as string)).toEqual({
|
|
45
|
-
channel: 'proj:room-1',
|
|
46
|
-
payload: { event: 'ping', a: 1 },
|
|
47
|
-
})
|
|
48
|
-
expect((init.headers as Record<string, string>)['apikey']).toBe('k')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it("ne préfixe pas deux fois un canal déjà préfixé par le projet", async () => {
|
|
52
|
-
const { client, calls } = clientWithSpy()
|
|
53
|
-
const rt = new RealtimeService(client)
|
|
54
|
-
|
|
55
|
-
await rt.httpBroadcast('proj:room-x', 'evt', {})
|
|
56
|
-
|
|
57
|
-
expect(JSON.parse(calls[0]!.init.body as string).channel).toBe('proj:room-x')
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it("n'ouvre aucune connexion WebSocket", async () => {
|
|
61
|
-
const { client } = clientWithSpy()
|
|
62
|
-
const rt = new RealtimeService(client)
|
|
63
|
-
|
|
64
|
-
await rt.httpBroadcast('room-1', 'ping', {})
|
|
65
|
-
|
|
66
|
-
expect(rt.connectionState).toBe('disconnected')
|
|
67
|
-
})
|
|
68
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { RealtimeService } from '../src/RealtimeService'
|
|
3
|
-
import { BaseAuthStore } from '@aurabase/core'
|
|
4
|
-
import type { AuraClientLike } from '@aurabase/core'
|
|
5
|
-
|
|
6
|
-
function makeClient(): AuraClientLike {
|
|
7
|
-
return {
|
|
8
|
-
baseUrl: 'http://x',
|
|
9
|
-
projectId: 'p',
|
|
10
|
-
apiKey: 'k',
|
|
11
|
-
fetchFn: (async () => new Response('{}')) as unknown as typeof globalThis.fetch,
|
|
12
|
-
authStore: new BaseAuthStore(), // vide → _scheduleTokenRefresh no-op
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
auth: { refreshSession: async () => ({ data: null, error: null }) as any },
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe('RealtimeService — propagation token différentielle', () => {
|
|
19
|
-
it('ne renvoie pas un token identique, renvoie un token changé', () => {
|
|
20
|
-
const rt = new RealtimeService(makeClient())
|
|
21
|
-
const send = vi
|
|
22
|
-
.spyOn(rt as unknown as { _send: (d: string) => void }, '_send')
|
|
23
|
-
.mockImplementation(() => {})
|
|
24
|
-
rt.refreshToken('t1')
|
|
25
|
-
expect(send).toHaveBeenCalledTimes(1)
|
|
26
|
-
rt.refreshToken('t1')
|
|
27
|
-
expect(send).toHaveBeenCalledTimes(1) // identique → pas renvoyé
|
|
28
|
-
rt.refreshToken('t2')
|
|
29
|
-
expect(send).toHaveBeenCalledTimes(2)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('disconnect() réarme la propagation (renvoie le token après reconnexion)', () => {
|
|
33
|
-
const rt = new RealtimeService(makeClient())
|
|
34
|
-
const send = vi
|
|
35
|
-
.spyOn(rt as unknown as { _send: (d: string) => void }, '_send')
|
|
36
|
-
.mockImplementation(() => {})
|
|
37
|
-
rt.refreshToken('t1')
|
|
38
|
-
expect(send).toHaveBeenCalledTimes(1)
|
|
39
|
-
rt.disconnect()
|
|
40
|
-
rt.refreshToken('t1')
|
|
41
|
-
expect(send).toHaveBeenCalledTimes(2) // _lastSentToken reset → renvoyé
|
|
42
|
-
})
|
|
43
|
-
})
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
|
2
|
-
import { RealtimeService } from '../src/RealtimeService'
|
|
3
|
-
import { BaseAuthStore } from '@aurabase/core'
|
|
4
|
-
import type { AuraClientLike } from '@aurabase/core'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Faux WebSocket contrôlable : les transitions (open/close) sont déclenchées
|
|
8
|
-
* manuellement pour reproduire de façon déterministe la race « stale onclose »
|
|
9
|
-
* (un ancien socket dont le onclose se déclenche APRÈS qu'un nouveau socket a
|
|
10
|
-
* été créé).
|
|
11
|
-
*/
|
|
12
|
-
class FakeWebSocket {
|
|
13
|
-
static readonly CONNECTING = 0
|
|
14
|
-
static readonly OPEN = 1
|
|
15
|
-
static readonly CLOSING = 2
|
|
16
|
-
static readonly CLOSED = 3
|
|
17
|
-
static instances: FakeWebSocket[] = []
|
|
18
|
-
|
|
19
|
-
url: string
|
|
20
|
-
readyState: number = FakeWebSocket.CONNECTING
|
|
21
|
-
onopen: (() => void) | null = null
|
|
22
|
-
onmessage: ((evt: { data: string }) => void) | null = null
|
|
23
|
-
onclose: (() => void) | null = null
|
|
24
|
-
onerror: ((evt: unknown) => void) | null = null
|
|
25
|
-
sent: string[] = []
|
|
26
|
-
|
|
27
|
-
constructor(url: string) {
|
|
28
|
-
this.url = url
|
|
29
|
-
FakeWebSocket.instances.push(this)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
send(data: string): void {
|
|
33
|
-
this.sent.push(data)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
close(): void {
|
|
37
|
-
this.readyState = FakeWebSocket.CLOSING
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ─── Helpers de test ───
|
|
41
|
-
fireOpen(): void {
|
|
42
|
-
this.readyState = FakeWebSocket.OPEN
|
|
43
|
-
this.onopen?.()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
fireClose(): void {
|
|
47
|
-
this.readyState = FakeWebSocket.CLOSED
|
|
48
|
-
this.onclose?.()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function client(): AuraClientLike {
|
|
53
|
-
return {
|
|
54
|
-
baseUrl: 'http://x',
|
|
55
|
-
projectId: 'proj',
|
|
56
|
-
apiKey: 'k',
|
|
57
|
-
authStore: new BaseAuthStore(),
|
|
58
|
-
fetchFn: (async () => new Response('{}')) as unknown as typeof globalThis.fetch,
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
auth: { refreshSession: async () => ({ data: null, error: null }) as any },
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
describe('RealtimeService — race « stale onclose »', () => {
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
vi.useFakeTimers()
|
|
67
|
-
FakeWebSocket.instances = []
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
-
;(globalThis as any).WebSocket = FakeWebSocket
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
-
delete (globalThis as any).WebSocket
|
|
75
|
-
vi.useRealTimers()
|
|
76
|
-
vi.restoreAllMocks()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it("le onclose tardif d'un ancien socket n'écrase PAS la connexion courante", () => {
|
|
80
|
-
const rt = new RealtimeService(client())
|
|
81
|
-
rt.setAutoReconnect(false) // isole le test du scheduler de reconnexion
|
|
82
|
-
|
|
83
|
-
rt.connect()
|
|
84
|
-
const ws1 = FakeWebSocket.instances[0]
|
|
85
|
-
ws1.fireOpen()
|
|
86
|
-
expect(rt.connectionState).toBe('connected')
|
|
87
|
-
|
|
88
|
-
// Déconnexion intentionnelle : ferme ws1, mais son onclose est différé.
|
|
89
|
-
rt.disconnect()
|
|
90
|
-
expect(rt.connectionState).toBe('disconnected')
|
|
91
|
-
|
|
92
|
-
// Une nouvelle connexion est établie AVANT que le onclose de ws1 n'arrive.
|
|
93
|
-
rt.connect()
|
|
94
|
-
const ws2 = FakeWebSocket.instances[1]
|
|
95
|
-
expect(ws2).toBeDefined()
|
|
96
|
-
ws2.fireOpen()
|
|
97
|
-
expect(rt.connectionState).toBe('connected')
|
|
98
|
-
|
|
99
|
-
// Le onclose TARDIF de l'ancien socket se déclenche maintenant.
|
|
100
|
-
ws1.fireClose()
|
|
101
|
-
|
|
102
|
-
// Il ne doit ni annuler l'état 'connected', ni détacher le nouveau socket.
|
|
103
|
-
expect(rt.connectionState).toBe('connected')
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
-
expect((rt as any)._ws).toBe(ws2)
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('un socket périmé qui s\'ouvre tardivement est fermé et n\'active rien', () => {
|
|
109
|
-
const rt = new RealtimeService(client())
|
|
110
|
-
rt.setAutoReconnect(false)
|
|
111
|
-
|
|
112
|
-
rt.connect()
|
|
113
|
-
const ws1 = FakeWebSocket.instances[0]
|
|
114
|
-
|
|
115
|
-
// Avant que ws1 ne s'ouvre, on repart sur une nouvelle connexion.
|
|
116
|
-
rt.disconnect()
|
|
117
|
-
rt.connect()
|
|
118
|
-
const ws2 = FakeWebSocket.instances[1]
|
|
119
|
-
ws2.fireOpen()
|
|
120
|
-
expect(rt.connectionState).toBe('connected')
|
|
121
|
-
|
|
122
|
-
// ws1 (périmé) s'ouvre tardivement : doit être fermé, sans toucher l'état.
|
|
123
|
-
const closeSpy = vi.spyOn(ws1, 'close')
|
|
124
|
-
ws1.fireOpen()
|
|
125
|
-
expect(closeSpy).toHaveBeenCalled()
|
|
126
|
-
expect(rt.connectionState).toBe('connected')
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
-
expect((rt as any)._ws).toBe(ws2)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('après disconnect+reconnect, une coupure inattendue reconnecte bien (flag _intentionalClose non bloqué)', () => {
|
|
132
|
-
const rt = new RealtimeService(client())
|
|
133
|
-
|
|
134
|
-
rt.connect()
|
|
135
|
-
const ws1 = FakeWebSocket.instances[0]
|
|
136
|
-
ws1.fireOpen()
|
|
137
|
-
|
|
138
|
-
rt.disconnect() // pose _intentionalClose = true
|
|
139
|
-
rt.connect() // doit remettre le flag à false
|
|
140
|
-
const ws2 = FakeWebSocket.instances[1]
|
|
141
|
-
ws2.fireOpen()
|
|
142
|
-
expect(rt.connectionState).toBe('connected')
|
|
143
|
-
|
|
144
|
-
// Coupure inattendue de ws2 : doit repasser en 'reconnecting'
|
|
145
|
-
// (et non rester 'disconnected' à cause d'un flag resté à true).
|
|
146
|
-
ws2.fireClose()
|
|
147
|
-
expect(rt.connectionState).toBe('reconnecting')
|
|
148
|
-
})
|
|
149
|
-
})
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
2
|
-
import { AuraChannel } from '../src/AuraChannel'
|
|
3
|
-
|
|
4
|
-
afterEach(() => vi.useRealTimers())
|
|
5
|
-
|
|
6
|
-
describe('AuraChannel — ref_id global-unique', () => {
|
|
7
|
-
it('deux channels produisent des refs distincts préfixés par fullName', () => {
|
|
8
|
-
vi.useFakeTimers()
|
|
9
|
-
const a = new AuraChannel('a', 'p', { broadcast: { ack: true } })
|
|
10
|
-
const b = new AuraChannel('b', 'p', { broadcast: { ack: true } })
|
|
11
|
-
const sentA: Array<Record<string, unknown>> = []
|
|
12
|
-
const sentB: Array<Record<string, unknown>> = []
|
|
13
|
-
a._bindSend((d) => sentA.push(JSON.parse(d)))
|
|
14
|
-
b._bindSend((d) => sentB.push(JSON.parse(d)))
|
|
15
|
-
|
|
16
|
-
const pa = a.send({ type: 'broadcast', event: 'e', payload: {} })
|
|
17
|
-
const pb = b.send({ type: 'broadcast', event: 'e', payload: {} })
|
|
18
|
-
|
|
19
|
-
const rA = sentA[0].ref_id as string
|
|
20
|
-
const rB = sentB[0].ref_id as string
|
|
21
|
-
expect(rA).not.toBe(rB)
|
|
22
|
-
expect(rA.startsWith('p:a:')).toBe(true)
|
|
23
|
-
expect(rB.startsWith('p:b:')).toBe(true)
|
|
24
|
-
|
|
25
|
-
// broadcast_ack du ref de A → seul A résout ; le pending de B reste
|
|
26
|
-
a._onMessage({ type: 'broadcast_ack', ref_id: rA } as never)
|
|
27
|
-
return Promise.resolve().then(async () => {
|
|
28
|
-
await expect(pa).resolves.toBe('ok')
|
|
29
|
-
expect((b as unknown as { _pendingAcks: Map<string, unknown> })._pendingAcks.has(rB)).toBe(true)
|
|
30
|
-
vi.advanceTimersByTime(5000) // laisse pb timeout (nettoyage)
|
|
31
|
-
await expect(pb).resolves.toBe('timeout')
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
})
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { RealtimeService } from '../src/RealtimeService'
|
|
3
|
-
import { BaseAuthStore } from '@aurabase/core'
|
|
4
|
-
import type { AuraClientLike } from '@aurabase/core'
|
|
5
|
-
|
|
6
|
-
function makeClient(store = new BaseAuthStore()): AuraClientLike {
|
|
7
|
-
return {
|
|
8
|
-
baseUrl: 'http://x',
|
|
9
|
-
projectId: 'p',
|
|
10
|
-
apiKey: 'k',
|
|
11
|
-
fetchFn: (async () => new Response('{}')) as unknown as typeof globalThis.fetch,
|
|
12
|
-
authStore: store,
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
auth: { refreshSession: async () => ({ data: null, error: null }) as any },
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function spySend(rt: RealtimeService) {
|
|
19
|
-
return vi
|
|
20
|
-
.spyOn(rt as unknown as { _send: (d: string) => void }, '_send')
|
|
21
|
-
.mockImplementation(() => {})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe('RealtimeService.setAuth — parité Supabase', () => {
|
|
25
|
-
it("setAuth(token) pousse un seul { type:'access_token', token } (dédupliqué)", () => {
|
|
26
|
-
const rt = new RealtimeService(makeClient())
|
|
27
|
-
const send = spySend(rt)
|
|
28
|
-
|
|
29
|
-
rt.setAuth('tok')
|
|
30
|
-
expect(send).toHaveBeenCalledTimes(1)
|
|
31
|
-
expect(JSON.parse(send.mock.calls[0]![0] as string)).toEqual({
|
|
32
|
-
type: 'access_token',
|
|
33
|
-
token: 'tok',
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
// Second appel identique → pas de renvoi (déduplication _lastSentToken).
|
|
37
|
-
rt.setAuth('tok')
|
|
38
|
-
expect(send).toHaveBeenCalledTimes(1)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('setAuth() sans argument reprend client.authStore.token', () => {
|
|
42
|
-
const store = new BaseAuthStore()
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
store.save('from-store', 'r', {} as any)
|
|
45
|
-
const rt = new RealtimeService(makeClient(store))
|
|
46
|
-
const send = spySend(rt)
|
|
47
|
-
|
|
48
|
-
rt.setAuth()
|
|
49
|
-
|
|
50
|
-
expect(send).toHaveBeenCalledTimes(1)
|
|
51
|
-
expect(JSON.parse(send.mock.calls[0]![0] as string)).toEqual({
|
|
52
|
-
type: 'access_token',
|
|
53
|
-
token: 'from-store',
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it("setAuth() no-op si aucun token disponible", () => {
|
|
58
|
-
const rt = new RealtimeService(makeClient())
|
|
59
|
-
const send = spySend(rt)
|
|
60
|
-
rt.setAuth()
|
|
61
|
-
expect(send).not.toHaveBeenCalled()
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('ne provoque aucune reconnexion WS', () => {
|
|
65
|
-
const rt = new RealtimeService(makeClient())
|
|
66
|
-
spySend(rt)
|
|
67
|
-
rt.setAuth('tok')
|
|
68
|
-
expect(rt.connectionState).toBe('disconnected')
|
|
69
|
-
})
|
|
70
|
-
})
|
package/packages/storage/LICENSE
DELETED
|
@@ -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.
|