@vuu-ui/vuu-data-remote 4.0.1 → 5.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/package.json +11 -11
  2. package/src/ConnectionManager.js +175 -67
  3. package/src/DedicatedWorker.js +5 -2
  4. package/src/VuuDataSource.js +10 -3
  5. package/src/WebSocketConnection.js +44 -8
  6. package/src/index.js +0 -4
  7. package/src/inlined-worker.js +1 -1
  8. package/src/server-proxy/server-proxy.js +13 -6
  9. package/src/server-proxy/viewport.js +3 -1
  10. package/src/worker.js +4 -3
  11. package/types/ConnectionManager.d.ts +45 -17
  12. package/types/DedicatedWorker.d.ts +10 -3
  13. package/types/VuuDataSource.d.ts +1 -1
  14. package/types/WebSocketConnection.d.ts +18 -3
  15. package/types/index.d.ts +0 -4
  16. package/types/inlined-worker.d.ts +1 -1
  17. package/types/server-proxy/server-proxy.d.ts +6 -2
  18. package/src/LostConnectionHandler.js +0 -89
  19. package/src/VuuAuthProvider.js +0 -78
  20. package/src/VuuAuthenticator.js +0 -36
  21. package/src/authenticate.js +0 -50
  22. package/types/LostConnectionHandler.d.ts +0 -28
  23. package/types/VuuAuthProvider.d.ts +0 -39
  24. package/types/VuuAuthenticator.d.ts +0 -21
  25. package/types/authenticate.d.ts +0 -15
  26. package/types/src/ConnectionManager.d.ts +0 -36
  27. package/types/src/DedicatedWorker.d.ts +0 -9
  28. package/types/src/LostConnectionHandler.d.ts +0 -28
  29. package/types/src/VuuAuthProvider.d.ts +0 -39
  30. package/types/src/VuuAuthenticator.d.ts +0 -21
  31. package/types/src/VuuDataSource.d.ts +0 -74
  32. package/types/src/WebSocketConnection.d.ts +0 -54
  33. package/types/src/authenticate.d.ts +0 -15
  34. package/types/src/constants.d.ts +0 -41
  35. package/types/src/data-source.d.ts +0 -6
  36. package/types/src/index.d.ts +0 -11
  37. package/types/src/inlined-worker.d.ts +0 -1
  38. package/types/src/message-utils.d.ts +0 -20
  39. package/types/src/server-proxy/array-backed-moving-window.d.ts +0 -27
  40. package/types/src/server-proxy/messages.d.ts +0 -33
  41. package/types/src/server-proxy/server-proxy.d.ts +0 -68
  42. package/types/src/server-proxy/viewport.d.ts +0 -132
  43. package/types/src/worker.d.ts +0 -1
@@ -1,35 +1,63 @@
1
- import { ConnectOptions, DataSourceCallbackMessage, ServerAPI } from "@vuu-ui/vuu-data-types";
1
+ import type { ConnectOptions, DataSourceCallbackMessage, ServerAPI } from "@vuu-ui/vuu-data-types";
2
+ import type { VuuLoginSuccessResponse } from "@vuu-ui/vuu-protocol-types";
2
3
  import { EventEmitter } from "@vuu-ui/vuu-utils";
3
- import { ConnectionStatus, WebSocketConnectionEvents } from "./WebSocketConnection";
4
- import { ConnectionQualityMetrics } from "@vuu-ui/vuu-data-types";
4
+ import type { ConnectionQualityMetrics } from "@vuu-ui/vuu-data-types";
5
+ import type { ConnectionStatus, WebSocketConnectionEvents } from "./WebSocketConnection";
6
+ export declare const DEFAULT_CONNECTION_ID = "portal";
5
7
  export type PostMessageToClientCallback = (msg: DataSourceCallbackMessage) => void;
6
8
  export type ConnectionEvents = WebSocketConnectionEvents & {
7
9
  "connection-metrics": (message: ConnectionQualityMetrics) => void;
8
10
  };
11
+ export type ConnectionStatusListener = (status: ConnectionStatus) => void;
12
+ export type VuuConnectionResult = {
13
+ loginResponse: VuuLoginSuccessResponse & {
14
+ sessionId: string;
15
+ };
16
+ status: "connected" | "reconnected";
17
+ } | {
18
+ status: "rejected";
19
+ };
20
+ /**
21
+ * Process-wide registry for VUU server connections.
22
+ *
23
+ * Consumers use the exported singleton to connect, obtain a deferred
24
+ * `ServerAPI`, and control subscriptions. The unscoped methods operate on the
25
+ * legacy `portal` connection, while the `*To` and `*For` methods select an
26
+ * independent connection by ID. This allows remote modules to share the manager
27
+ * without sharing authentication, worker state, or viewport subscriptions.
28
+ *
29
+ * Connection status and metrics events are emitted for the default connection
30
+ * to preserve the existing application-level monitoring API.
31
+ */
9
32
  declare class ConnectionManager extends EventEmitter<ConnectionEvents> {
10
33
  #private;
11
34
  private constructor();
12
35
  static get instance(): ConnectionManager;
36
+ private getConnection;
13
37
  get connectionStatus(): ConnectionStatus;
14
38
  get connected(): boolean;
15
- /**
16
- * Open a connection to the VuuServer. This method opens the websocket connection
17
- * and logs in. It can be called from whichever client code has access to the auth
18
- * token (eg. the login page, or just a hardcoded login script in a sample).
19
- * This will unblock any DataSources which may have already tried to subscribe to data,
20
- * but lacked access to the auth token.
21
- *
22
- * @param serverUrl
23
- * @param token
24
- */
25
- connect(options: ConnectOptions, throwOnRejected?: boolean): Promise<"connected" | "connection-failed" | "reconnected" | "rejected">;
39
+ connectionStatusFor(connectionId: string): ConnectionStatus;
40
+ connectedFor(connectionId: string): boolean;
41
+ onConnectionStatus(connectionId: string, listener: ConnectionStatusListener): () => void;
42
+ connect(options: ConnectOptions, throwOnRejected?: boolean): Promise<"connected" | "connection-failed" | "reconnected">;
43
+ connectTo(connectionId: string, options: ConnectOptions, throwOnRejected?: boolean): Promise<"connected" | "connection-failed" | "reconnected">;
44
+ connectWithLoginResponseTo(connectionId: string, options: ConnectOptions, throwOnRejected?: boolean): Promise<{
45
+ loginResponse: VuuLoginSuccessResponse & {
46
+ sessionId: string;
47
+ };
48
+ status: "connected" | "reconnected";
49
+ } | {
50
+ readonly status: "rejected";
51
+ }>;
26
52
  disableActiveSubscriptions(): void;
27
53
  enableActiveSubscriptions(): void;
28
- private handleMessageFromWorker;
54
+ disableActiveSubscriptionsFor(connectionId: string): void;
55
+ enableActiveSubscriptionsFor(connectionId: string): void;
29
56
  get serverAPI(): Promise<ServerAPI>;
30
- private connectedServerAPI;
31
- private asyncRequest;
57
+ serverAPIFor(connectionId: string): Promise<ServerAPI>;
32
58
  disconnect(): Promise<"disconnected" | "rejected">;
59
+ disconnectFrom(connectionId: string): Promise<"disconnected" | "rejected">;
60
+ destroyConnection(connectionId: string): Promise<void>;
33
61
  destroy(): void;
34
62
  }
35
63
  declare const _default: ConnectionManager;
@@ -1,9 +1,16 @@
1
- import { ConnectOptions, VuuUIMessageIn, VuuUIMessageOut, WithRequestId } from "@vuu-ui/vuu-data-types";
2
- import { SelectRequest, VuuCreateVisualLink, VuuRemoveVisualLink, VuuRpcMenuRequest, VuuRpcServiceRequest } from "@vuu-ui/vuu-protocol-types";
1
+ import type { ConnectOptions, VuuUIMessageIn, VuuUIMessageOut, WithRequestId } from "@vuu-ui/vuu-data-types";
2
+ import type { SelectRequest, VuuLoginSuccessResponse, VuuCreateVisualLink, VuuRemoveVisualLink, VuuRpcMenuRequest, VuuRpcServiceRequest } from "@vuu-ui/vuu-protocol-types";
3
3
  export declare class DedicatedWorker {
4
4
  #private;
5
5
  constructor(onMessage: (msg: VuuUIMessageIn) => void);
6
- connect(options: ConnectOptions): Promise<"connected" | "reconnected" | "rejected">;
6
+ connect(options: ConnectOptions): Promise<{
7
+ loginResponse: VuuLoginSuccessResponse & {
8
+ sessionId: string;
9
+ };
10
+ status: "connected" | "reconnected";
11
+ } | {
12
+ status: "rejected";
13
+ }>;
7
14
  send(message: VuuUIMessageOut | WithRequestId<VuuCreateVisualLink | VuuRemoveVisualLink | VuuRpcServiceRequest | VuuRpcMenuRequest | SelectRequest>): Promise<void>;
8
15
  terminate(): Promise<void>;
9
16
  }
@@ -10,7 +10,7 @@ export declare class VuuDataSource extends BaseDataSource implements DataSourceB
10
10
  rangeRequest: RangeRequest;
11
11
  readonly isRemote = true;
12
12
  table: VuuTable;
13
- constructor({ autosubscribeColumns, columns, session, sessionTableMessageColumn, ...props }: DataSourceConstructorProps);
13
+ constructor({ autosubscribeColumns, columns, session, connectionId, sessionTableMessageColumn, ...props }: DataSourceConstructorProps);
14
14
  subscribe(subscribeProps: DataSourceSubscribeProps, callback: DataSourceSubscribeCallback): Promise<void>;
15
15
  handleMessageFromServer: (message: DataSourceCallbackMessage) => void;
16
16
  handleSessionMessageFromServer: (msg: DataSourceCallbackMessage) => void;
@@ -1,10 +1,15 @@
1
- import { WebSocketProtocol } from "@vuu-ui/vuu-data-types";
2
- import { InvalidSessionReason, InvalidTokenReason, LoginErrorMessage, VuuClientMessage, VuuServerMessage } from "@vuu-ui/vuu-protocol-types";
1
+ import type { WebSocketProtocol } from "@vuu-ui/vuu-data-types";
2
+ import type { InvalidSessionReason, InvalidTokenReason, LoginErrorMessage, VuuClientMessage, VuuServerMessage } from "@vuu-ui/vuu-protocol-types";
3
3
  import { EventEmitter } from "@vuu-ui/vuu-utils";
4
4
  export type ConnectionPhase = "initial-connection" | "post-disconnect-reconnection";
5
5
  export type ConnectingStatus = "connecting" | "reconnecting";
6
6
  export type ConnectedStatus = "connected" | "reconnected";
7
- export type ConnectionStatus = ConnectingStatus | ConnectedStatus | "closed" | "websocket-open" | "disconnected" | "failed" | "inactive";
7
+ export type ConnectionStatus = ConnectingStatus | ConnectedStatus | "closed" | "websocket-open" | "disconnected" | "failed" | "connection-failed" | "inactive"
8
+ /**
9
+ * The server ended the session because the user logged in again
10
+ * elsewhere. Not reconnected: that would evict the other session.
11
+ */
12
+ | "session-evicted";
8
13
  export declare const isInvalidTokenReason: (text: string) => text is InvalidTokenReason;
9
14
  export declare const isInvalidSessionReason: (text: string) => text is InvalidSessionReason;
10
15
  export declare const isWebSocketConnectionStatus: (msg: unknown) => msg is ConnectionStatus;
@@ -21,6 +26,16 @@ export type WebSocketConnectionConfig = {
21
26
  callback: VuuServerMessageCallback;
22
27
  connectionTimeout?: number;
23
28
  };
29
+ /** WebSocket close codes a Vuu server uses to end or refuse a session. */
30
+ export declare const VuuCloseCode: {
31
+ /** The user logged in again and this (oldest) session was evicted. */
32
+ readonly SessionEvicted: 4001;
33
+ readonly InvalidSession: 4002;
34
+ /** Login refused, the user already has maxSessionsPerUser sessions. */
35
+ readonly SessionLimitReached: 4003;
36
+ /** Login refused, e.g. an invalid or expired token. */
37
+ readonly LoginFailed: 4004;
38
+ };
24
39
  export type WebSocketConnectionCloseReason = LoginErrorMessage | "failure" | "shutdown";
25
40
  export type WebSocketConnectionEvents = {
26
41
  "connection-status": (status: ConnectionStatus) => void;
package/types/index.d.ts CHANGED
@@ -1,11 +1,7 @@
1
- export { authenticate, getVuuAuthToken, parseVuuUserFromToken, } from "./authenticate";
2
1
  export * from "./ConnectionManager";
3
2
  export { default as ConnectionManager } from "./ConnectionManager";
4
3
  export * from "./constants";
5
4
  export * from "./data-source";
6
- export { LostConnectionHandler, RetryOptions } from "./LostConnectionHandler";
7
5
  export * from "./message-utils";
8
- export { VuuAuthenticator, VuuAuthTokenIssuePolicy } from "./VuuAuthenticator";
9
- export { VuuAuthProvider, type AuthProvider } from "./VuuAuthProvider";
10
6
  export * from "./VuuDataSource";
11
7
  export { isConnected, type ConnectionStatus } from "./WebSocketConnection";