@vuu-ui/vuu-data-remote 4.0.0-alpha.8 → 4.0.0-beta.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 (39) hide show
  1. package/package.json +12 -12
  2. package/src/ConnectionManager.js +65 -158
  3. package/src/DedicatedWorker.js +1 -4
  4. package/src/LostConnectionHandler.js +89 -0
  5. package/src/VuuAuthProvider.js +78 -0
  6. package/src/VuuAuthenticator.js +36 -0
  7. package/src/VuuDataSource.js +7 -10
  8. package/src/WebSocketConnection.js +1 -8
  9. package/src/authenticate.js +50 -0
  10. package/src/index.js +4 -0
  11. package/src/inlined-worker.js +1 -2805
  12. package/src/server-proxy/array-backed-moving-window.js +12 -17
  13. package/src/server-proxy/server-proxy.js +4 -7
  14. package/src/worker.js +2 -3
  15. package/types/ConnectionManager.d.ts +17 -45
  16. package/types/DedicatedWorker.d.ts +3 -10
  17. package/types/VuuDataSource.d.ts +1 -1
  18. package/types/WebSocketConnection.d.ts +3 -3
  19. package/types/index.d.ts +4 -0
  20. package/types/inlined-worker.d.ts +1 -1
  21. package/types/server-proxy/server-proxy.d.ts +2 -4
  22. package/types/src/ConnectionManager.d.ts +0 -36
  23. package/types/src/DedicatedWorker.d.ts +0 -9
  24. package/types/src/LostConnectionHandler.d.ts +0 -28
  25. package/types/src/VuuAuthProvider.d.ts +0 -39
  26. package/types/src/VuuAuthenticator.d.ts +0 -21
  27. package/types/src/VuuDataSource.d.ts +0 -74
  28. package/types/src/WebSocketConnection.d.ts +0 -54
  29. package/types/src/authenticate.d.ts +0 -15
  30. package/types/src/constants.d.ts +0 -41
  31. package/types/src/data-source.d.ts +0 -6
  32. package/types/src/index.d.ts +0 -11
  33. package/types/src/inlined-worker.d.ts +0 -1
  34. package/types/src/message-utils.d.ts +0 -20
  35. package/types/src/server-proxy/array-backed-moving-window.d.ts +0 -27
  36. package/types/src/server-proxy/messages.d.ts +0 -33
  37. package/types/src/server-proxy/server-proxy.d.ts +0 -68
  38. package/types/src/server-proxy/viewport.d.ts +0 -132
  39. package/types/src/worker.d.ts +0 -1
@@ -33,7 +33,8 @@ class ArrayBackedMovingWindow {
33
33
  }
34
34
  setRowCount = (rowCount)=>{
35
35
  log.info?.(`setRowCount ${rowCount}`);
36
- if (rowCount < this.internalData.length) this.internalData.length = rowCount;
36
+ const dataLength = Math.max(0, rowCount - this.#range.from);
37
+ if (dataLength < this.internalData.length) this.internalData.length = dataLength;
37
38
  if (rowCount < this.rowCount) {
38
39
  this.rowsWithinRange = 0;
39
40
  const end = Math.min(rowCount, this.clientRange.to);
@@ -68,10 +69,13 @@ class ArrayBackedMovingWindow {
68
69
  log.debug?.(`setClientRange ${from} - ${to}`);
69
70
  const currentFrom = this.clientRange.from;
70
71
  const currentTo = Math.min(this.clientRange.to, this.rowCount);
71
- if (from === currentFrom && to === currentTo) return [
72
- false,
73
- EMPTY_ARRAY
74
- ];
72
+ if (from === currentFrom && to === currentTo) {
73
+ this.clientRange.to = to;
74
+ return [
75
+ false,
76
+ EMPTY_ARRAY
77
+ ];
78
+ }
75
79
  const originalRange = this.clientRange.copy();
76
80
  this.clientRange.from = from;
77
81
  this.clientRange.to = to;
@@ -82,18 +86,9 @@ class ArrayBackedMovingWindow {
82
86
  }
83
87
  const clientRows = [];
84
88
  const offset = this.#range.from;
85
- if (to > originalRange.to) {
86
- const start = Math.max(from, originalRange.to);
87
- for(let i = start - offset; i < to - offset; i++){
88
- const row = this.internalData[i];
89
- if (row) clientRows.push(row);
90
- }
91
- } else {
92
- const end = Math.min(originalRange.from, to);
93
- for(let i = from - offset; i < end - offset; i++){
94
- const row = this.internalData[i];
95
- if (row) clientRows.push(row);
96
- }
89
+ for(let i = from; i < to; i++)if (i < originalRange.from || i >= originalRange.to) {
90
+ const row = this.internalData[i - offset];
91
+ if (row) clientRows.push(row);
97
92
  }
98
93
  const serverDataRequired = this.bufferBreakout(from, to);
99
94
  return [
@@ -180,8 +180,6 @@ class ServerProxy {
180
180
  unsubscribe(clientViewportId) {
181
181
  const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
182
182
  if (serverViewportId) {
183
- this.mapClientToServerViewport.delete(clientViewportId);
184
- this.viewports.delete(serverViewportId);
185
183
  info?.(`Unsubscribe Message (Client to Server):
186
184
  ${serverViewportId}`);
187
185
  this.sendMessageToServer({
@@ -516,13 +514,12 @@ class ServerProxy {
516
514
  case "LOGIN_SUCCESS":
517
515
  if (sessionId) {
518
516
  this.sessionId = sessionId;
519
- const loginResponse = {
517
+ this.pendingLogin?.resolve(sessionId);
518
+ this.pendingLogin = void 0;
519
+ this.postMessageToClient({
520
520
  ...body,
521
521
  sessionId
522
- };
523
- this.pendingLogin?.resolve(loginResponse);
524
- this.pendingLogin = void 0;
525
- this.postMessageToClient(loginResponse);
522
+ });
526
523
  } else throw Error("LOGIN_SUCCESS did not provide sessionId");
527
524
  break;
528
525
  case "REMOVE_VP_SUCCESS":
package/src/worker.js CHANGED
@@ -30,11 +30,10 @@ const handleMessageFromClient = async ({ data: message })=>{
30
30
  switch(message.type){
31
31
  case "connect":
32
32
  try {
33
- const loginResponse = await connectToServer(message.url, message.protocol, message.token);
34
- if (!loginResponse) throw Error("VUU server did not return a LOGIN_SUCCESS response");
33
+ const sessionId = await connectToServer(message.url, message.protocol, message.token);
35
34
  postMessage({
36
35
  type: "connected",
37
- loginResponse
36
+ sessionId
38
37
  });
39
38
  } catch (err) {
40
39
  postMessage({
@@ -1,63 +1,35 @@
1
- import type { ConnectOptions, DataSourceCallbackMessage, ServerAPI } from "@vuu-ui/vuu-data-types";
2
- import type { VuuLoginSuccessResponse } from "@vuu-ui/vuu-protocol-types";
1
+ import { ConnectOptions, DataSourceCallbackMessage, ServerAPI } from "@vuu-ui/vuu-data-types";
3
2
  import { EventEmitter } from "@vuu-ui/vuu-utils";
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";
3
+ import { ConnectionStatus, WebSocketConnectionEvents } from "./WebSocketConnection";
4
+ import { ConnectionQualityMetrics } from "@vuu-ui/vuu-data-types";
7
5
  export type PostMessageToClientCallback = (msg: DataSourceCallbackMessage) => void;
8
6
  export type ConnectionEvents = WebSocketConnectionEvents & {
9
7
  "connection-metrics": (message: ConnectionQualityMetrics) => void;
10
8
  };
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
- */
32
9
  declare class ConnectionManager extends EventEmitter<ConnectionEvents> {
33
10
  #private;
34
11
  private constructor();
35
12
  static get instance(): ConnectionManager;
36
- private getConnection;
37
13
  get connectionStatus(): ConnectionStatus;
38
14
  get connected(): boolean;
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
- }>;
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">;
52
26
  disableActiveSubscriptions(): void;
53
27
  enableActiveSubscriptions(): void;
54
- disableActiveSubscriptionsFor(connectionId: string): void;
55
- enableActiveSubscriptionsFor(connectionId: string): void;
28
+ private handleMessageFromWorker;
56
29
  get serverAPI(): Promise<ServerAPI>;
57
- serverAPIFor(connectionId: string): Promise<ServerAPI>;
30
+ private connectedServerAPI;
31
+ private asyncRequest;
58
32
  disconnect(): Promise<"disconnected" | "rejected">;
59
- disconnectFrom(connectionId: string): Promise<"disconnected" | "rejected">;
60
- destroyConnection(connectionId: string): Promise<void>;
61
33
  destroy(): void;
62
34
  }
63
35
  declare const _default: ConnectionManager;
@@ -1,16 +1,9 @@
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";
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";
3
3
  export declare class DedicatedWorker {
4
4
  #private;
5
5
  constructor(onMessage: (msg: VuuUIMessageIn) => void);
6
- connect(options: ConnectOptions): Promise<{
7
- loginResponse: VuuLoginSuccessResponse & {
8
- sessionId: string;
9
- };
10
- status: "connected" | "reconnected";
11
- } | {
12
- status: "rejected";
13
- }>;
6
+ connect(options: ConnectOptions): Promise<"connected" | "reconnected" | "rejected">;
14
7
  send(message: VuuUIMessageOut | WithRequestId<VuuCreateVisualLink | VuuRemoveVisualLink | VuuRpcServiceRequest | VuuRpcMenuRequest | SelectRequest>): Promise<void>;
15
8
  terminate(): Promise<void>;
16
9
  }
@@ -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({ session, connectionId, sessionTableMessageColumn, ...props }: DataSourceConstructorProps);
13
+ constructor({ session, 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,10 @@
1
- import type { WebSocketProtocol } from "@vuu-ui/vuu-data-types";
2
- import type { InvalidSessionReason, InvalidTokenReason, LoginErrorMessage, VuuClientMessage, VuuServerMessage } from "@vuu-ui/vuu-protocol-types";
1
+ import { WebSocketProtocol } from "@vuu-ui/vuu-data-types";
2
+ import { 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" | "connection-failed" | "inactive";
7
+ export type ConnectionStatus = ConnectingStatus | ConnectedStatus | "closed" | "websocket-open" | "disconnected" | "failed" | "inactive";
8
8
  export declare const isInvalidTokenReason: (text: string) => text is InvalidTokenReason;
9
9
  export declare const isInvalidSessionReason: (text: string) => text is InvalidSessionReason;
10
10
  export declare const isWebSocketConnectionStatus: (msg: unknown) => msg is ConnectionStatus;
package/types/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
+ export { authenticate, getVuuAuthToken, parseVuuUserFromToken, } from "./authenticate";
1
2
  export * from "./ConnectionManager";
2
3
  export { default as ConnectionManager } from "./ConnectionManager";
3
4
  export * from "./constants";
4
5
  export * from "./data-source";
6
+ export { LostConnectionHandler, RetryOptions } from "./LostConnectionHandler";
5
7
  export * from "./message-utils";
8
+ export { VuuAuthenticator, VuuAuthTokenIssuePolicy } from "./VuuAuthenticator";
9
+ export { VuuAuthProvider, type AuthProvider } from "./VuuAuthProvider";
6
10
  export * from "./VuuDataSource";
7
11
  export { isConnected, type ConnectionStatus } from "./WebSocketConnection";