55
66/**
77 * Includes JSON data types and `undefined`.
8+ *
9+ * @see {@link https://fibo.github.io/dflow/#dflowdata }
810 */
911export type DflowData =
1012 | undefined
@@ -19,6 +21,11 @@ export type DflowObject = { [Key in string]: DflowData };
1921
2022export type DflowArray = DflowData [ ] ;
2123
24+ /**
25+ * Dflow data types represent values that can be serialized as JSON.
26+ *
27+ * @see {@link https://fibo.github.io/dflow/#dflowdatatype }
28+ */
2229export type DflowDataType =
2330 | "null"
2431 | "boolean"
@@ -30,7 +37,11 @@ export type DflowDataType =
3037// Inputs, outputs, links and nodes.
3138// ////////////////////////////////////////////////////////////////////
3239
33- /** Connects two nodes in the graph. */
40+ /**
41+ * Connects two nodes in the graph.
42+ *
43+ * @see {@link https://fibo.github.io/dflow/#dflowlink }
44+ */
3445export type DflowLink = [
3546 sourceNodeId : string ,
3647 sourcePosition : number ,
@@ -46,6 +57,8 @@ export type DflowLink = [
4657 * ```json
4758 * { "name": "label", "types": ["string"] }
4859 * ```
60+ *
61+ * @see {@link https://fibo.github.io/dflow/#dflowinput }
4962 */
5063export type DflowInput = {
5164 /** Ignored by Dflow, but could be used by UI. */
@@ -70,6 +83,8 @@ export type DflowInput = {
7083 * ```json
7184 * { "name": "sum", "types": ["number"] }
7285 * ```
86+ *
87+ * @see {@link https://fibo.github.io/dflow/#dflowoutput }
7388 */
7489export type DflowOutput = {
7590 /** Ignored by Dflow, but could be used by UI. */
@@ -78,7 +93,11 @@ export type DflowOutput = {
7893 types : DflowDataType [ ] ;
7994} ;
8095
81- /** Defines a block of code: it can have inputs and outputs. */
96+ /**
97+ * Defines a block of code: it can have inputs and outputs.
98+ *
99+ * @see {@link https://fibo.github.io/dflow/#dflownode }
100+ */
82101export type DflowNode = {
83102 kind : string ;
84103 inputs ?: DflowInput [ ] ;
@@ -102,6 +121,8 @@ export type DflowGraph = {
102121 * A `Dflow` represents a program as an executable graph.
103122 * A graph can contain nodes and links.
104123 * Nodes are executed, sorted by their connections.
124+ *
125+ * @see {@link https://fibo.github.io/dflow/#api }
105126 */
106127export class Dflow {
107128 /** Node definitions indexed by node kind. */
@@ -155,6 +176,11 @@ export class Dflow {
155176 */
156177 ERR ?: ( ...data : any [ ] ) => void ;
157178
179+ /**
180+ * Dflow constructor requires a list of node definitions which is an `Array<DflowNode>`.
181+ *
182+ * @see {@link https://fibo.github.io/dflow/#constructor }
183+ */
158184 constructor ( nodeDefinitions : Array < DflowNode > ) {
159185 // Add given node definitions, followed by builtin nodes.
160186 for ( const nodeDefinition of nodeDefinitions )
@@ -227,18 +253,20 @@ export class Dflow {
227253 // Output types are stored in output items.
228254 const sourceOutput = this . #outputs. get ( sourceNodeId ) ?. [ sourcePosition ] ;
229255 if ( ! sourceOutput ) return false ;
230- const sourceTypes = sourceOutput . types ;
231-
232- // If source can have any type or
233- // target can have any type,
256+ // If source can have any type or target can have any type,
234257 // then source and target are compatible.
235- if ( ! sourceTypes . length || ! targetTypes . length ) return true ;
236-
258+ if ( ! sourceOutput . types . length || ! targetTypes . length ) return true ;
237259 // Check if target accepts some of the `dataType` source can have.
238- return targetTypes . some ( ( dataType ) => sourceTypes . includes ( dataType ) ) ;
260+ return targetTypes . some ( ( dataType ) =>
261+ sourceOutput . types . includes ( dataType )
262+ ) ;
239263 }
240264
241- /** Create a new node. Returns node id. */
265+ /**
266+ * Create a new node. Returns node id.
267+ *
268+ * @see {@link https://fibo.github.io/dflow/#dflow.node }
269+ */
242270 node ( kind : string , wantedId ?: string ) : string {
243271 const nodeDef = this . #nodeDefinitions. get ( kind ) ;
244272 if ( ! nodeDef ) throw new Error ( "Cannot create node" , { cause : { kind } } ) ;
@@ -286,7 +314,11 @@ export class Dflow {
286314 return id ;
287315 }
288316
289- /** Delete node or link with given id. */
317+ /**
318+ * Delete node or link with given id.
319+ *
320+ * @see {@link https://fibo.github.io/dflow/#dflow.delete }
321+ */
290322 delete ( id : string ) {
291323 // Delete node.
292324 if ( this . #kinds. delete ( id ) ) {
@@ -306,7 +338,11 @@ export class Dflow {
306338 if ( targetInput ) targetInput . source = undefined ;
307339 }
308340
309- /** Create a new data node. Returns node id. */
341+ /**
342+ * Create a new data node. Returns node id.
343+ *
344+ * @see {@link https://fibo.github.io/dflow/#dflow.data }
345+ */
310346 data ( value : unknown , wantedId ?: string ) : string {
311347 const id = this . #newId( this . #kinds, "n" , wantedId ) ;
312348 this . #kinds. set ( id , "data" ) ;
@@ -324,7 +360,11 @@ export class Dflow {
324360 return id ;
325361 }
326362
327- /** Create a new link and connect two nodes. Returns link id. */
363+ /**
364+ * Create a new link and connect two nodes. Returns link id.
365+ *
366+ * @see {@link https://fibo.github.io/dflow/#dflow.link }
367+ */
328368 link (
329369 source : string | [ nodeId : string , position : number ] ,
330370 target : string | [ nodeId : string , position : number ] ,
@@ -368,7 +408,11 @@ export class Dflow {
368408 throw error ;
369409 }
370410
371- /** Execute all nodes, sorted by their connections. */
411+ /**
412+ * Execute all nodes, sorted by their connections.
413+ *
414+ * @see {@link https://fibo.github.io/dflow/#dflow.run }
415+ */
372416 async run ( ) : Promise < void > {
373417 // Reset errors.
374418 this . #errors. clear ( ) ;
@@ -431,7 +475,11 @@ export class Dflow {
431475 }
432476 }
433477
434- /** A graph contains nodes and links. */
478+ /**
479+ * A graph contains nodes and links.
480+ *
481+ * @see {@link https://fibo.github.io/dflow/#dflow.graph }
482+ */
435483 get graph ( ) : DflowGraph {
436484 const node : DflowGraph [ "node" ] = { } ;
437485 const data : DflowGraph [ "data" ] = { } ;
@@ -447,12 +495,20 @@ export class Dflow {
447495 } ;
448496 }
449497
450- /** Get error messages from last run, indexed by node id. */
498+ /**
499+ * Get error messages from last run, indexed by node id.
500+ *
501+ * @see {@link https://fibo.github.io/dflow/#dflow.error }
502+ */
451503 get error ( ) : Record < string , string > {
452504 return Object . fromEntries ( this . #errors. entries ( ) ) ;
453505 }
454506
455- /** Get output data of last run, indexed by node id. */
507+ /**
508+ * Get output data of last run, indexed by node id.
509+ *
510+ * @see {@link https://fibo.github.io/dflow/#dflow.out }
511+ */
456512 get out ( ) : Record < string , DflowArray > {
457513 const out : Record < string , DflowArray > = { } ;
458514 for ( const nodeId of this . #kinds. keys ( ) ) {
0 commit comments