Skip to content

Commit a85c8fd

Browse files
committed
Added code.
1 parent b707542 commit a85c8fd

File tree

8 files changed

+169
-13
lines changed

8 files changed

+169
-13
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:dart_comfy_frontend/dart_comfy_frontend.dart';
22

33
void main() {
4-
var awesome = Awesome();
5-
print('awesome: ${awesome.isAwesome}');
4+
var workflow = WorkflowNode.fromJSON({'id': 1});
65
}

lib/dart_comfy_frontend.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// More dartdocs go here.
44
library;
55

6-
export 'src/dart_comfy_frontend_base.dart';
7-
8-
// TODO: Export any libraries intended for clients of this package.
6+
export 'src/workflow.dart' show Workflow;
7+
export 'src/workflow/node.dart' show WorkflowNode;
8+
export 'src/workflow/input.dart' show WorkflowInput;
9+
export 'src/workflow/output.dart' show WorkflowOutput;

lib/src/dart_comfy_frontend_base.dart

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/src/workflow.dart

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import 'dart:convert';
2+
import 'workflow/node.dart';
3+
4+
class Workflow{
5+
final Map<String, dynamic> _json;
6+
Workflow() : _json = jsonDecode(documentJson);
7+
8+
int get lastNodeId {
9+
if (_json case {'last_node_id': int lastNodeId}) {
10+
return lastNodeId;
11+
} else {
12+
throw const FormatException('Unexpected JSON');
13+
}
14+
}
15+
16+
int get lastLinkId {
17+
if (_json case {'last_link_id': int lastLinkId}) {
18+
return lastLinkId;
19+
} else {
20+
throw const FormatException('Unexpected JSON');
21+
}
22+
}
23+
24+
List<dynamic> get nodes {
25+
if (_json case {'nodes': List<dynamic> nodes}) {
26+
return nodes.map((node) => WorkflowNode.fromJSON(node)).toList();
27+
} else {
28+
throw const FormatException('Unexpected JSON');
29+
}
30+
}
31+
32+
List<dynamic> get links {
33+
if (_json case {'links': List<dynamic> links}) {
34+
return links;
35+
} else {
36+
throw const FormatException('Unexpected JSON');
37+
}
38+
}
39+
40+
List<dynamic> get groups {
41+
if (_json case {'groups': List<dynamic> links}) {
42+
return groups;
43+
} else {
44+
throw const FormatException('Unexpected JSON');
45+
}
46+
}
47+
48+
Map get config {
49+
if (_json case {'config': Map config}) {
50+
return config;
51+
} else {
52+
throw const FormatException('Unexpected JSON');
53+
}
54+
}
55+
56+
List<dynamic> get extra {
57+
if (_json case {'extra': List<dynamic> extra}) {
58+
return extra;
59+
} else {
60+
throw const FormatException('Unexpected JSON');
61+
}
62+
}
63+
64+
String get version {
65+
if (_json case {'version': String version}) {
66+
return version;
67+
} else {
68+
throw const FormatException('Unexpected JSON');
69+
}
70+
}
71+
}
72+
73+
const documentJson = '''
74+
{
75+
"last_node_id": 1,
76+
"last_link_id": 1,
77+
"nodes": [],
78+
"links": [],
79+
"groups": [],
80+
"config": {},
81+
"extra": {},
82+
"version": 0.4
83+
}
84+
''';

lib/src/workflow/input.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class WorkflowInput {
2+
final Map<String, dynamic> item;
3+
WorkflowInput( this.item );
4+
}

lib/src/workflow/node.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import 'input.dart';
2+
import 'output.dart';
3+
4+
class WorkflowNode {
5+
final int id;
6+
final String type;
7+
final List<double> position;
8+
final List<double> size;
9+
final Map<String, dynamic> flags;
10+
final int order;
11+
final int mode;
12+
final List<WorkflowInput> inputs;
13+
final List<WorkflowOutput> outputs;
14+
final Map properties;
15+
final String? color = null;
16+
final String? bgcolor = null;
17+
final List<dynamic>? widgets_values = [];
18+
19+
WorkflowNode(
20+
this.id,
21+
this.type,
22+
this.position,
23+
this.size,
24+
this.flags,
25+
this.order,
26+
this.mode,
27+
this.inputs,
28+
this.outputs,
29+
this.properties,
30+
{
31+
String? color,
32+
String? bgcolor,
33+
List<dynamic>? widgets_values
34+
}
35+
);
36+
37+
factory WorkflowNode.fromJSON(Map<String, dynamic> json) {
38+
int x;
39+
int y;
40+
41+
final id = json['id'] as int;
42+
final type = json['type'] as String;
43+
final pos = json['pos'].map<double>((item) => item as double).toList();
44+
final size = json['size'].map<double>((item) => item as double).toList();
45+
final flags = json['flags'] as Map<String, dynamic>;
46+
final order = json['order'] as int;
47+
final mode = json['mode'] as int;
48+
final inputs = json['inputs'].map<WorkflowInput>((item) => WorkflowInput(item)).toList();
49+
final outputs = json['outputs'].map<WorkflowOutput>((item) => WorkflowOutput(item)).toList();
50+
final properties = json['properties'] as Map;
51+
final color = json['color'] as String?;
52+
final bgcolor = json['bgcolor'] as String?;
53+
final widgets_values = json['widgets_values'] as List<dynamic>?;
54+
55+
return WorkflowNode(
56+
id,
57+
type,
58+
pos,
59+
size,
60+
flags,
61+
order,
62+
mode,
63+
inputs,
64+
outputs,
65+
properties,
66+
color: color,
67+
bgcolor: bgcolor,
68+
widgets_values: widgets_values
69+
);
70+
}
71+
}

lib/src/workflow/output.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class WorkflowOutput {
2+
final Map<String, dynamic> item;
3+
WorkflowOutput( this.item );
4+
}

test/dart_comfy_frontend_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import 'package:test/test.dart';
33

44
void main() {
55
group('A group of tests', () {
6-
final awesome = Awesome();
76

87
setUp(() {
98
// Additional setup goes here.
109
});
1110

1211
test('First Test', () {
13-
expect(awesome.isAwesome, isTrue);
12+
expect(true, isTrue);
1413
});
1514
});
1615
}

0 commit comments

Comments
 (0)