@3plate/graph-core 0.1.7 → 0.1.10

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/dist/index.d.cts CHANGED
@@ -3,6 +3,7 @@ type MergeOrder = Side[];
3
3
  type NodeAlign = 'natural' | 'top' | 'bottom' | 'left' | 'right';
4
4
  type Orientation = 'TB' | 'BT' | 'LR' | 'RL';
5
5
  type Nav = 'first' | 'last' | 'prev' | 'next';
6
+ type PortStyle = 'inside' | 'outside' | 'custom';
6
7
  type LayoutStep = 'alignChildren' | 'alignParents' | 'compact';
7
8
  type Dims = {
8
9
  w: number;
@@ -11,11 +12,38 @@ type Dims = {
11
12
 
12
13
  type MarkerType = 'arrow' | 'circle' | 'diamond' | 'bar' | 'none';
13
14
 
15
+ /** WebSocket ingestion configuration */
16
+ type WebSocketIngestionConfig = {
17
+ type: 'websocket';
18
+ /** WebSocket URL */
19
+ url: string;
20
+ /** Reconnect interval in milliseconds */
21
+ reconnectMs?: number;
22
+ /** Callback when the WebSocket connection is established */
23
+ onConnect?: () => void;
24
+ /** Callback when the WebSocket connection is closed */
25
+ onDisconnect?: () => void;
26
+ /** Callback when the WebSocket connection encounters an error */
27
+ onError?: (error: Error) => void;
28
+ };
29
+ /** File ingestion configuration */
30
+ type FileIngestionConfig = {
31
+ type: 'file';
32
+ /** File URL */
33
+ url: string;
34
+ /** Polling interval in milliseconds */
35
+ intervalMs?: number;
36
+ };
37
+ /**
38
+ * Ingestion source configuration.
39
+ * Used to connect to an external data source for graph updates.
40
+ */
41
+ type IngestionConfig = WebSocketIngestionConfig | FileIngestionConfig;
14
42
  /**
15
43
  * Arguments to the API constructor.
16
44
  *
17
- * The caller can specify nodes and edges, or history,
18
- * but not both.
45
+ * The caller can specify nodes and edges, history, or ingestion config,
46
+ * but not multiple.
19
47
  *
20
48
  * The root element ID is required.
21
49
  */
@@ -28,6 +56,8 @@ type APIArguments<N, E> = {
28
56
  edges?: E[];
29
57
  /** Initial history */
30
58
  history?: Update<N, E>[];
59
+ /** Ingestion source configuration */
60
+ ingestion?: IngestionConfig;
31
61
  /** Events */
32
62
  events?: EventsOptions<N, E>;
33
63
  /** Root element ID */
@@ -370,11 +400,19 @@ declare class API<N, E> {
370
400
  private nextNodeId;
371
401
  private nextEdgeId;
372
402
  private events;
403
+ private ingest?;
404
+ private ingestionSource?;
405
+ private ingestionConfig?;
406
+ private prevProps;
373
407
  root: string;
374
408
  constructor(args: APIArguments<N, E>);
375
409
  reset(): void;
376
410
  /** Initialize the API */
377
411
  init(): Promise<void>;
412
+ /** Connect to the configured ingestion source */
413
+ private connectIngestion;
414
+ /** Disconnect from the ingestion source */
415
+ private disconnectIngestion;
378
416
  private applyHistory;
379
417
  /** Current history index (0-based) */
380
418
  getHistoryIndex(): number;
@@ -446,6 +484,20 @@ declare class API<N, E> {
446
484
  }): void;
447
485
  /** Update color mode without recreating the canvas */
448
486
  setColorMode(colorMode: 'light' | 'dark' | 'system'): void;
487
+ /**
488
+ * Apply prop changes by diffing against previously applied props.
489
+ * This is a convenience method for framework wrappers that centralizes
490
+ * the logic for detecting and applying changes to nodes, edges, history, and options.
491
+ * The API stores the previous props internally, so you just pass the new props.
492
+ *
493
+ * @param props - The new props to apply
494
+ */
495
+ applyProps(props: {
496
+ nodes?: N[];
497
+ edges?: E[];
498
+ history?: Update<N, E>[];
499
+ options?: APIOptions<N, E>;
500
+ }): void;
449
501
  /** Cleanup resources when the graph is destroyed */
450
502
  destroy(): void;
451
503
  }
@@ -481,7 +533,14 @@ declare class Ingest<N, E> {
481
533
  apply(msg: IngestMessage<N, E>): Promise<void>;
482
534
  }
483
535
 
484
- type StatusListener$2 = (status: 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error', detail?: any) => void;
536
+ type WebSocketStatus = 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error';
537
+ type WebSocketStatusListener = (status: WebSocketStatus, detail?: any) => void;
538
+ type WebSocketSourceArgs<N, E> = {
539
+ url: string;
540
+ onMessage: (msg: IngestMessage<N, E>) => void;
541
+ onStatus?: WebSocketStatusListener;
542
+ reconnectMs?: number;
543
+ };
485
544
  declare class WebSocketSource<N, E> {
486
545
  private url;
487
546
  private ws;
@@ -492,7 +551,7 @@ declare class WebSocketSource<N, E> {
492
551
  private connectStartTime;
493
552
  private totalTimeoutMs;
494
553
  private totalTimeoutTimer;
495
- constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$2, reconnectMs?: number);
554
+ constructor(args: WebSocketSourceArgs<N, E>);
496
555
  connect(): void;
497
556
  disconnect(): void;
498
557
  private startTotalTimeout;
@@ -501,6 +560,12 @@ declare class WebSocketSource<N, E> {
501
560
  }
502
561
 
503
562
  type StatusListener$1 = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
563
+ type FileSystemSourceArgs<N, E> = {
564
+ filename: string;
565
+ onMessage: (msg: IngestMessage<N, E>) => void;
566
+ onStatus?: StatusListener$1;
567
+ intervalMs?: number;
568
+ };
504
569
  declare class FileSystemSource<N, E> {
505
570
  private handle;
506
571
  private onMessage;
@@ -509,7 +574,7 @@ declare class FileSystemSource<N, E> {
509
574
  private lastSize;
510
575
  private filename;
511
576
  private intervalMs;
512
- constructor(onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$1, filename?: string, intervalMs?: number);
577
+ constructor(args: FileSystemSourceArgs<N, E>);
513
578
  openDirectory(): Promise<void>;
514
579
  close(): void;
515
580
  private startPolling;
@@ -517,6 +582,12 @@ declare class FileSystemSource<N, E> {
517
582
  }
518
583
 
519
584
  type StatusListener = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
585
+ type FileSourceArgs<N, E> = {
586
+ url: string;
587
+ onMessage: (msg: IngestMessage<N, E>) => void;
588
+ onStatus?: StatusListener;
589
+ intervalMs?: number;
590
+ };
520
591
  declare class FileSource<N, E> {
521
592
  private url;
522
593
  private onMessage;
@@ -526,7 +597,7 @@ declare class FileSource<N, E> {
526
597
  private lastContent;
527
598
  private intervalMs;
528
599
  private closed;
529
- constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener, intervalMs?: number);
600
+ constructor(args: FileSourceArgs<N, E>);
530
601
  connect(): Promise<void>;
531
602
  close(): void;
532
603
  private startPolling;
@@ -648,4 +719,4 @@ declare class Playground {
648
719
 
649
720
  declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
650
721
 
651
- export { API, type APIArguments, type APIOptions, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, FileSystemSource, type HistoryMessage, Ingest, type IngestMessage, Playground, type PlaygroundOptions, type SnapshotMessage, type Update, type UpdateMessage, Updater, WebSocketSource, graph as default, graph };
722
+ export { API, type APIArguments, type APIOptions, type CanvasTheme, type ColorMode, type EdgeProps, type EdgeTheme, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, type FileSourceArgs, FileSystemSource, type FileSystemSourceArgs, type HistoryMessage, Ingest, type IngestMessage, type IngestionConfig, type NewEdge, type NewNode, type NodeAlign, type NodeProps, type NodeTheme, type Orientation, Playground, type PlaygroundOptions, type PortProps, type PortStyle, type PortTheme, type RenderNode, type SnapshotMessage, type ThemeVars, type Update, type UpdateMessage, Updater, WebSocketSource, type WebSocketSourceArgs, type WebSocketStatus, type WebSocketStatusListener, graph as default, graph };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ type MergeOrder = Side[];
3
3
  type NodeAlign = 'natural' | 'top' | 'bottom' | 'left' | 'right';
4
4
  type Orientation = 'TB' | 'BT' | 'LR' | 'RL';
5
5
  type Nav = 'first' | 'last' | 'prev' | 'next';
6
+ type PortStyle = 'inside' | 'outside' | 'custom';
6
7
  type LayoutStep = 'alignChildren' | 'alignParents' | 'compact';
7
8
  type Dims = {
8
9
  w: number;
@@ -11,11 +12,38 @@ type Dims = {
11
12
 
12
13
  type MarkerType = 'arrow' | 'circle' | 'diamond' | 'bar' | 'none';
13
14
 
15
+ /** WebSocket ingestion configuration */
16
+ type WebSocketIngestionConfig = {
17
+ type: 'websocket';
18
+ /** WebSocket URL */
19
+ url: string;
20
+ /** Reconnect interval in milliseconds */
21
+ reconnectMs?: number;
22
+ /** Callback when the WebSocket connection is established */
23
+ onConnect?: () => void;
24
+ /** Callback when the WebSocket connection is closed */
25
+ onDisconnect?: () => void;
26
+ /** Callback when the WebSocket connection encounters an error */
27
+ onError?: (error: Error) => void;
28
+ };
29
+ /** File ingestion configuration */
30
+ type FileIngestionConfig = {
31
+ type: 'file';
32
+ /** File URL */
33
+ url: string;
34
+ /** Polling interval in milliseconds */
35
+ intervalMs?: number;
36
+ };
37
+ /**
38
+ * Ingestion source configuration.
39
+ * Used to connect to an external data source for graph updates.
40
+ */
41
+ type IngestionConfig = WebSocketIngestionConfig | FileIngestionConfig;
14
42
  /**
15
43
  * Arguments to the API constructor.
16
44
  *
17
- * The caller can specify nodes and edges, or history,
18
- * but not both.
45
+ * The caller can specify nodes and edges, history, or ingestion config,
46
+ * but not multiple.
19
47
  *
20
48
  * The root element ID is required.
21
49
  */
@@ -28,6 +56,8 @@ type APIArguments<N, E> = {
28
56
  edges?: E[];
29
57
  /** Initial history */
30
58
  history?: Update<N, E>[];
59
+ /** Ingestion source configuration */
60
+ ingestion?: IngestionConfig;
31
61
  /** Events */
32
62
  events?: EventsOptions<N, E>;
33
63
  /** Root element ID */
@@ -370,11 +400,19 @@ declare class API<N, E> {
370
400
  private nextNodeId;
371
401
  private nextEdgeId;
372
402
  private events;
403
+ private ingest?;
404
+ private ingestionSource?;
405
+ private ingestionConfig?;
406
+ private prevProps;
373
407
  root: string;
374
408
  constructor(args: APIArguments<N, E>);
375
409
  reset(): void;
376
410
  /** Initialize the API */
377
411
  init(): Promise<void>;
412
+ /** Connect to the configured ingestion source */
413
+ private connectIngestion;
414
+ /** Disconnect from the ingestion source */
415
+ private disconnectIngestion;
378
416
  private applyHistory;
379
417
  /** Current history index (0-based) */
380
418
  getHistoryIndex(): number;
@@ -446,6 +484,20 @@ declare class API<N, E> {
446
484
  }): void;
447
485
  /** Update color mode without recreating the canvas */
448
486
  setColorMode(colorMode: 'light' | 'dark' | 'system'): void;
487
+ /**
488
+ * Apply prop changes by diffing against previously applied props.
489
+ * This is a convenience method for framework wrappers that centralizes
490
+ * the logic for detecting and applying changes to nodes, edges, history, and options.
491
+ * The API stores the previous props internally, so you just pass the new props.
492
+ *
493
+ * @param props - The new props to apply
494
+ */
495
+ applyProps(props: {
496
+ nodes?: N[];
497
+ edges?: E[];
498
+ history?: Update<N, E>[];
499
+ options?: APIOptions<N, E>;
500
+ }): void;
449
501
  /** Cleanup resources when the graph is destroyed */
450
502
  destroy(): void;
451
503
  }
@@ -481,7 +533,14 @@ declare class Ingest<N, E> {
481
533
  apply(msg: IngestMessage<N, E>): Promise<void>;
482
534
  }
483
535
 
484
- type StatusListener$2 = (status: 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error', detail?: any) => void;
536
+ type WebSocketStatus = 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error';
537
+ type WebSocketStatusListener = (status: WebSocketStatus, detail?: any) => void;
538
+ type WebSocketSourceArgs<N, E> = {
539
+ url: string;
540
+ onMessage: (msg: IngestMessage<N, E>) => void;
541
+ onStatus?: WebSocketStatusListener;
542
+ reconnectMs?: number;
543
+ };
485
544
  declare class WebSocketSource<N, E> {
486
545
  private url;
487
546
  private ws;
@@ -492,7 +551,7 @@ declare class WebSocketSource<N, E> {
492
551
  private connectStartTime;
493
552
  private totalTimeoutMs;
494
553
  private totalTimeoutTimer;
495
- constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$2, reconnectMs?: number);
554
+ constructor(args: WebSocketSourceArgs<N, E>);
496
555
  connect(): void;
497
556
  disconnect(): void;
498
557
  private startTotalTimeout;
@@ -501,6 +560,12 @@ declare class WebSocketSource<N, E> {
501
560
  }
502
561
 
503
562
  type StatusListener$1 = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
563
+ type FileSystemSourceArgs<N, E> = {
564
+ filename: string;
565
+ onMessage: (msg: IngestMessage<N, E>) => void;
566
+ onStatus?: StatusListener$1;
567
+ intervalMs?: number;
568
+ };
504
569
  declare class FileSystemSource<N, E> {
505
570
  private handle;
506
571
  private onMessage;
@@ -509,7 +574,7 @@ declare class FileSystemSource<N, E> {
509
574
  private lastSize;
510
575
  private filename;
511
576
  private intervalMs;
512
- constructor(onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$1, filename?: string, intervalMs?: number);
577
+ constructor(args: FileSystemSourceArgs<N, E>);
513
578
  openDirectory(): Promise<void>;
514
579
  close(): void;
515
580
  private startPolling;
@@ -517,6 +582,12 @@ declare class FileSystemSource<N, E> {
517
582
  }
518
583
 
519
584
  type StatusListener = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
585
+ type FileSourceArgs<N, E> = {
586
+ url: string;
587
+ onMessage: (msg: IngestMessage<N, E>) => void;
588
+ onStatus?: StatusListener;
589
+ intervalMs?: number;
590
+ };
520
591
  declare class FileSource<N, E> {
521
592
  private url;
522
593
  private onMessage;
@@ -526,7 +597,7 @@ declare class FileSource<N, E> {
526
597
  private lastContent;
527
598
  private intervalMs;
528
599
  private closed;
529
- constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener, intervalMs?: number);
600
+ constructor(args: FileSourceArgs<N, E>);
530
601
  connect(): Promise<void>;
531
602
  close(): void;
532
603
  private startPolling;
@@ -648,4 +719,4 @@ declare class Playground {
648
719
 
649
720
  declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
650
721
 
651
- export { API, type APIArguments, type APIOptions, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, FileSystemSource, type HistoryMessage, Ingest, type IngestMessage, Playground, type PlaygroundOptions, type SnapshotMessage, type Update, type UpdateMessage, Updater, WebSocketSource, graph as default, graph };
722
+ export { API, type APIArguments, type APIOptions, type CanvasTheme, type ColorMode, type EdgeProps, type EdgeTheme, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, type FileSourceArgs, FileSystemSource, type FileSystemSourceArgs, type HistoryMessage, Ingest, type IngestMessage, type IngestionConfig, type NewEdge, type NewNode, type NodeAlign, type NodeProps, type NodeTheme, type Orientation, Playground, type PlaygroundOptions, type PortProps, type PortStyle, type PortTheme, type RenderNode, type SnapshotMessage, type ThemeVars, type Update, type UpdateMessage, Updater, WebSocketSource, type WebSocketSourceArgs, type WebSocketStatus, type WebSocketStatusListener, graph as default, graph };