@3plate/graph-core 0.1.5 → 0.1.6

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
@@ -323,11 +323,17 @@ declare class Updater<N, E> {
323
323
  constructor();
324
324
  describe(desc: string): Updater<N, E>;
325
325
  addNode(node: any): Updater<N, E>;
326
+ addNodes(...nodes: any[]): Updater<N, E>;
326
327
  deleteNode(node: any): Updater<N, E>;
328
+ deleteNodes(...nodes: any[]): Updater<N, E>;
327
329
  updateNode(node: any): Updater<N, E>;
330
+ updateNodes(...nodes: any[]): Updater<N, E>;
328
331
  addEdge(edge: any): Updater<N, E>;
332
+ addEdges(...edges: any[]): Updater<N, E>;
329
333
  deleteEdge(edge: any): Updater<N, E>;
334
+ deleteEdges(...edges: any[]): Updater<N, E>;
330
335
  updateEdge(edge: any): Updater<N, E>;
336
+ updateEdges(...edges: any[]): Updater<N, E>;
331
337
  static add<N, E>(nodes: N[], edges: E[]): Updater<N, E>;
332
338
  }
333
339
 
@@ -364,15 +370,21 @@ declare class API<N, E> {
364
370
  private events;
365
371
  private root;
366
372
  constructor(args: APIArguments<N, E>);
373
+ reset(): void;
374
+ /** Initialize the API */
375
+ init(): Promise<void>;
376
+ private applyHistory;
367
377
  /** Current history index (0-based) */
368
378
  getHistoryIndex(): number;
369
379
  /** Current history length */
370
380
  getHistoryLength(): number;
371
381
  /** Toggle canvas editable mode without re-creating the graph */
372
382
  setEditable(editable: boolean): void;
383
+ /** Replace entire history (clears prior) */
384
+ replaceHistory(frames: Update<N, E>[]): Promise<void>;
385
+ /** Rebuild from snapshot (nodes/edges) */
386
+ replaceSnapshot(nodes: N[], edges: E[], description?: string): Promise<void>;
373
387
  private get graph();
374
- /** Initialize the API */
375
- init(): Promise<void>;
376
388
  /** Navigate to a different state */
377
389
  nav(nav: Nav): void;
378
390
  private applyDiff;
@@ -426,6 +438,189 @@ declare class API<N, E> {
426
438
  handleDeleteEdge(id: EdgeId): Promise<void>;
427
439
  }
428
440
 
441
+ type SnapshotMessage<N, E> = {
442
+ type: 'snapshot';
443
+ nodes: N[];
444
+ edges: E[];
445
+ description?: string;
446
+ };
447
+ type UpdateMessage<N, E> = {
448
+ type: 'update';
449
+ description?: string;
450
+ } & Update<N, E>;
451
+ type HistoryMessage<N, E> = {
452
+ type: 'history';
453
+ frames: Update<N, E>[];
454
+ };
455
+ type IngestMessage<N, E> = SnapshotMessage<N, E> | UpdateMessage<N, E> | HistoryMessage<N, E>;
456
+ /**
457
+ * Ingest class handles applying ingest messages to an API instance.
458
+ * This is the core ingestion functionality, separate from UI concerns.
459
+ */
460
+ declare class Ingest<N, E> {
461
+ api: API<N, E>;
462
+ constructor(api: API<N, E>);
463
+ /**
464
+ * Apply an incoming ingest message to the API.
465
+ * - snapshot: rebuild state from nodes/edges (clears prior history)
466
+ * - update: apply incremental update
467
+ * - history: initialize from a set of frames (clears prior history)
468
+ */
469
+ apply(msg: IngestMessage<N, E>): Promise<void>;
470
+ }
471
+
472
+ type StatusListener$2 = (status: 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error', detail?: any) => void;
473
+ declare class WebSocketSource<N, E> {
474
+ private url;
475
+ private ws;
476
+ private onMessage;
477
+ private onStatus?;
478
+ private reconnectMs;
479
+ private closedByUser;
480
+ private connectStartTime;
481
+ private totalTimeoutMs;
482
+ private totalTimeoutTimer;
483
+ constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$2, reconnectMs?: number);
484
+ connect(): void;
485
+ disconnect(): void;
486
+ private startTotalTimeout;
487
+ private clearTotalTimeout;
488
+ private open;
489
+ }
490
+
491
+ type StatusListener$1 = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
492
+ declare class FileSystemSource<N, E> {
493
+ private handle;
494
+ private onMessage;
495
+ private onStatus?;
496
+ private timer;
497
+ private lastSize;
498
+ private filename;
499
+ private intervalMs;
500
+ constructor(onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$1, filename?: string, intervalMs?: number);
501
+ openDirectory(): Promise<void>;
502
+ close(): void;
503
+ private startPolling;
504
+ private readNewLines;
505
+ }
506
+
507
+ type StatusListener = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
508
+ declare class FileSource<N, E> {
509
+ private url;
510
+ private onMessage;
511
+ private onStatus?;
512
+ private timer;
513
+ private lastETag;
514
+ private lastContent;
515
+ private intervalMs;
516
+ private closed;
517
+ constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener, intervalMs?: number);
518
+ connect(): Promise<void>;
519
+ close(): void;
520
+ private startPolling;
521
+ private poll;
522
+ }
523
+
524
+ /**
525
+ * Types for the Playground component
526
+ */
527
+ type ExampleNode = string | {
528
+ id: string;
529
+ title?: string;
530
+ type?: string;
531
+ ports?: {
532
+ in?: string[];
533
+ out?: string[];
534
+ };
535
+ };
536
+ type ExampleEdgeEnd = string | {
537
+ id: string;
538
+ port?: string;
539
+ marker?: 'arrow' | 'circle' | 'diamond' | 'bar';
540
+ };
541
+ type ExampleEdge = string | {
542
+ source: ExampleEdgeEnd;
543
+ target: ExampleEdgeEnd;
544
+ type?: string;
545
+ };
546
+ type ExampleOptions = {
547
+ canvas?: {
548
+ colorMode?: 'light' | 'dark' | 'system';
549
+ nodeTypes?: Record<string, Record<string, string>>;
550
+ edgeTypes?: Record<string, Record<string, string>>;
551
+ };
552
+ };
553
+ type ExampleSource = {
554
+ type: 'file';
555
+ path: string;
556
+ } | {
557
+ type: 'websocket';
558
+ url: string;
559
+ };
560
+ type Example = {
561
+ name: string;
562
+ description?: string;
563
+ nodes: ExampleNode[];
564
+ edges: ExampleEdge[];
565
+ options?: ExampleOptions;
566
+ source?: ExampleSource;
567
+ };
568
+ type PlaygroundOptions = {
569
+ root: string | HTMLElement;
570
+ examples: Record<string, Example>;
571
+ defaultExample?: string;
572
+ };
573
+
574
+ declare class Playground {
575
+ private options;
576
+ private rootElement;
577
+ private currentExample;
578
+ private currentGraph;
579
+ private ingest;
580
+ private isEditable;
581
+ private wsSource;
582
+ private fsSource;
583
+ private fileSource;
584
+ private wsStatus;
585
+ private fsStatus;
586
+ private fileStatus;
587
+ private activeSourceType;
588
+ private wsUrl;
589
+ private sourceModal;
590
+ private helpOverlay;
591
+ private exampleList;
592
+ private graphContainerId;
593
+ constructor(options: PlaygroundOptions);
594
+ init(): Promise<void>;
595
+ private injectStyles;
596
+ private createDOM;
597
+ private setupEventListeners;
598
+ private getResolvedColorMode;
599
+ private getOptions;
600
+ private renderGraph;
601
+ private updateHistoryLabel;
602
+ private connectExampleSource;
603
+ private disconnectAllSources;
604
+ private openHelp;
605
+ private closeHelp;
606
+ private handleIngestMessage;
607
+ private updateSourceIcon;
608
+ private updateWsStatus;
609
+ private updateFsStatus;
610
+ private updateFileStatus;
611
+ private createSourceModal;
612
+ private selectSourceType;
613
+ private updateSourceModalContent;
614
+ private updateSourceModal;
615
+ private openSourceModal;
616
+ private closeSourceModal;
617
+ private handleConnect;
618
+ private handleDisconnect;
619
+ private handleChangeConnection;
620
+ private handleOpenFolder;
621
+ private handleCloseFolder;
622
+ }
623
+
429
624
  declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
430
625
 
431
- export { graph as default, graph };
626
+ export { type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, FileSystemSource, type HistoryMessage, Ingest, type IngestMessage, Playground, type PlaygroundOptions, type SnapshotMessage, type UpdateMessage, WebSocketSource, graph as default, graph };
package/dist/index.d.ts CHANGED
@@ -323,11 +323,17 @@ declare class Updater<N, E> {
323
323
  constructor();
324
324
  describe(desc: string): Updater<N, E>;
325
325
  addNode(node: any): Updater<N, E>;
326
+ addNodes(...nodes: any[]): Updater<N, E>;
326
327
  deleteNode(node: any): Updater<N, E>;
328
+ deleteNodes(...nodes: any[]): Updater<N, E>;
327
329
  updateNode(node: any): Updater<N, E>;
330
+ updateNodes(...nodes: any[]): Updater<N, E>;
328
331
  addEdge(edge: any): Updater<N, E>;
332
+ addEdges(...edges: any[]): Updater<N, E>;
329
333
  deleteEdge(edge: any): Updater<N, E>;
334
+ deleteEdges(...edges: any[]): Updater<N, E>;
330
335
  updateEdge(edge: any): Updater<N, E>;
336
+ updateEdges(...edges: any[]): Updater<N, E>;
331
337
  static add<N, E>(nodes: N[], edges: E[]): Updater<N, E>;
332
338
  }
333
339
 
@@ -364,15 +370,21 @@ declare class API<N, E> {
364
370
  private events;
365
371
  private root;
366
372
  constructor(args: APIArguments<N, E>);
373
+ reset(): void;
374
+ /** Initialize the API */
375
+ init(): Promise<void>;
376
+ private applyHistory;
367
377
  /** Current history index (0-based) */
368
378
  getHistoryIndex(): number;
369
379
  /** Current history length */
370
380
  getHistoryLength(): number;
371
381
  /** Toggle canvas editable mode without re-creating the graph */
372
382
  setEditable(editable: boolean): void;
383
+ /** Replace entire history (clears prior) */
384
+ replaceHistory(frames: Update<N, E>[]): Promise<void>;
385
+ /** Rebuild from snapshot (nodes/edges) */
386
+ replaceSnapshot(nodes: N[], edges: E[], description?: string): Promise<void>;
373
387
  private get graph();
374
- /** Initialize the API */
375
- init(): Promise<void>;
376
388
  /** Navigate to a different state */
377
389
  nav(nav: Nav): void;
378
390
  private applyDiff;
@@ -426,6 +438,189 @@ declare class API<N, E> {
426
438
  handleDeleteEdge(id: EdgeId): Promise<void>;
427
439
  }
428
440
 
441
+ type SnapshotMessage<N, E> = {
442
+ type: 'snapshot';
443
+ nodes: N[];
444
+ edges: E[];
445
+ description?: string;
446
+ };
447
+ type UpdateMessage<N, E> = {
448
+ type: 'update';
449
+ description?: string;
450
+ } & Update<N, E>;
451
+ type HistoryMessage<N, E> = {
452
+ type: 'history';
453
+ frames: Update<N, E>[];
454
+ };
455
+ type IngestMessage<N, E> = SnapshotMessage<N, E> | UpdateMessage<N, E> | HistoryMessage<N, E>;
456
+ /**
457
+ * Ingest class handles applying ingest messages to an API instance.
458
+ * This is the core ingestion functionality, separate from UI concerns.
459
+ */
460
+ declare class Ingest<N, E> {
461
+ api: API<N, E>;
462
+ constructor(api: API<N, E>);
463
+ /**
464
+ * Apply an incoming ingest message to the API.
465
+ * - snapshot: rebuild state from nodes/edges (clears prior history)
466
+ * - update: apply incremental update
467
+ * - history: initialize from a set of frames (clears prior history)
468
+ */
469
+ apply(msg: IngestMessage<N, E>): Promise<void>;
470
+ }
471
+
472
+ type StatusListener$2 = (status: 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error', detail?: any) => void;
473
+ declare class WebSocketSource<N, E> {
474
+ private url;
475
+ private ws;
476
+ private onMessage;
477
+ private onStatus?;
478
+ private reconnectMs;
479
+ private closedByUser;
480
+ private connectStartTime;
481
+ private totalTimeoutMs;
482
+ private totalTimeoutTimer;
483
+ constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$2, reconnectMs?: number);
484
+ connect(): void;
485
+ disconnect(): void;
486
+ private startTotalTimeout;
487
+ private clearTotalTimeout;
488
+ private open;
489
+ }
490
+
491
+ type StatusListener$1 = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
492
+ declare class FileSystemSource<N, E> {
493
+ private handle;
494
+ private onMessage;
495
+ private onStatus?;
496
+ private timer;
497
+ private lastSize;
498
+ private filename;
499
+ private intervalMs;
500
+ constructor(onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$1, filename?: string, intervalMs?: number);
501
+ openDirectory(): Promise<void>;
502
+ close(): void;
503
+ private startPolling;
504
+ private readNewLines;
505
+ }
506
+
507
+ type StatusListener = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
508
+ declare class FileSource<N, E> {
509
+ private url;
510
+ private onMessage;
511
+ private onStatus?;
512
+ private timer;
513
+ private lastETag;
514
+ private lastContent;
515
+ private intervalMs;
516
+ private closed;
517
+ constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener, intervalMs?: number);
518
+ connect(): Promise<void>;
519
+ close(): void;
520
+ private startPolling;
521
+ private poll;
522
+ }
523
+
524
+ /**
525
+ * Types for the Playground component
526
+ */
527
+ type ExampleNode = string | {
528
+ id: string;
529
+ title?: string;
530
+ type?: string;
531
+ ports?: {
532
+ in?: string[];
533
+ out?: string[];
534
+ };
535
+ };
536
+ type ExampleEdgeEnd = string | {
537
+ id: string;
538
+ port?: string;
539
+ marker?: 'arrow' | 'circle' | 'diamond' | 'bar';
540
+ };
541
+ type ExampleEdge = string | {
542
+ source: ExampleEdgeEnd;
543
+ target: ExampleEdgeEnd;
544
+ type?: string;
545
+ };
546
+ type ExampleOptions = {
547
+ canvas?: {
548
+ colorMode?: 'light' | 'dark' | 'system';
549
+ nodeTypes?: Record<string, Record<string, string>>;
550
+ edgeTypes?: Record<string, Record<string, string>>;
551
+ };
552
+ };
553
+ type ExampleSource = {
554
+ type: 'file';
555
+ path: string;
556
+ } | {
557
+ type: 'websocket';
558
+ url: string;
559
+ };
560
+ type Example = {
561
+ name: string;
562
+ description?: string;
563
+ nodes: ExampleNode[];
564
+ edges: ExampleEdge[];
565
+ options?: ExampleOptions;
566
+ source?: ExampleSource;
567
+ };
568
+ type PlaygroundOptions = {
569
+ root: string | HTMLElement;
570
+ examples: Record<string, Example>;
571
+ defaultExample?: string;
572
+ };
573
+
574
+ declare class Playground {
575
+ private options;
576
+ private rootElement;
577
+ private currentExample;
578
+ private currentGraph;
579
+ private ingest;
580
+ private isEditable;
581
+ private wsSource;
582
+ private fsSource;
583
+ private fileSource;
584
+ private wsStatus;
585
+ private fsStatus;
586
+ private fileStatus;
587
+ private activeSourceType;
588
+ private wsUrl;
589
+ private sourceModal;
590
+ private helpOverlay;
591
+ private exampleList;
592
+ private graphContainerId;
593
+ constructor(options: PlaygroundOptions);
594
+ init(): Promise<void>;
595
+ private injectStyles;
596
+ private createDOM;
597
+ private setupEventListeners;
598
+ private getResolvedColorMode;
599
+ private getOptions;
600
+ private renderGraph;
601
+ private updateHistoryLabel;
602
+ private connectExampleSource;
603
+ private disconnectAllSources;
604
+ private openHelp;
605
+ private closeHelp;
606
+ private handleIngestMessage;
607
+ private updateSourceIcon;
608
+ private updateWsStatus;
609
+ private updateFsStatus;
610
+ private updateFileStatus;
611
+ private createSourceModal;
612
+ private selectSourceType;
613
+ private updateSourceModalContent;
614
+ private updateSourceModal;
615
+ private openSourceModal;
616
+ private closeSourceModal;
617
+ private handleConnect;
618
+ private handleDisconnect;
619
+ private handleChangeConnection;
620
+ private handleOpenFolder;
621
+ private handleCloseFolder;
622
+ }
623
+
429
624
  declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
430
625
 
431
- export { graph as default, graph };
626
+ export { type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, FileSystemSource, type HistoryMessage, Ingest, type IngestMessage, Playground, type PlaygroundOptions, type SnapshotMessage, type UpdateMessage, WebSocketSource, graph as default, graph };