@andro.dev/jsonflow-engine 1.0.0

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/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # JSONFLOW Engine
2
+
3
+ Schema-aware engine for validating JSON graphs and producing Cytoscape-ready elements.
4
+
5
+ ## What It Does
6
+
7
+ - Validates JSON via Zod schemas
8
+ - Outputs Cytoscape-compatible nodes and edges
9
+ - Headless: no UI required
10
+
11
+ ## Install (local)
12
+
13
+ ```bash
14
+ pnpm -C engine install
15
+ ```
16
+
17
+ ## Build
18
+
19
+ ```bash
20
+ pnpm -C engine build
21
+ ```
22
+
23
+ ## Test
24
+
25
+ ```bash
26
+ pnpm -C engine test
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ts
32
+ import { Engine } from "jsonflow-engine";
33
+
34
+ const engine = new Engine();
35
+ const result = engine.parse({
36
+ type: "flow",
37
+ nodes: [{ id: "A" }, { id: "B" }],
38
+ edges: [{ from: "A", to: "B" }],
39
+ });
40
+
41
+ if (result.ok) {
42
+ console.log(result.cytoscape);
43
+ }
44
+ ```
45
+
46
+ ## Schema (Summary)
47
+
48
+ - Graph: `type`, `layout.direction`, `nodes`, `edges`
49
+ - Node: `id`, `label`, `type`, `kind`, `properties`
50
+ - Edge: `from`, `to`, `label`, `kind`, `link_type`
51
+
52
+ See `docs/diagram-spec.md` for details.
@@ -0,0 +1,132 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const NodeSchema: z.ZodObject<{
4
+ id: z.ZodString;
5
+ label: z.ZodOptional<z.ZodString>;
6
+ type: z.ZodOptional<z.ZodString>;
7
+ kind: z.ZodOptional<z.ZodEnum<{
8
+ actor: "actor";
9
+ lifeline: "lifeline";
10
+ message: "message";
11
+ activity: "activity";
12
+ state: "state";
13
+ class: "class";
14
+ }>>;
15
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
16
+ }, z.core.$strip>;
17
+ declare const EdgeSchema: z.ZodObject<{
18
+ from: z.ZodString;
19
+ to: z.ZodString;
20
+ label: z.ZodOptional<z.ZodString>;
21
+ kind: z.ZodOptional<z.ZodEnum<{
22
+ next: "next";
23
+ call: "call";
24
+ return: "return";
25
+ async: "async";
26
+ transition: "transition";
27
+ inherit: "inherit";
28
+ association: "association";
29
+ }>>;
30
+ link_type: z.ZodOptional<z.ZodEnum<{
31
+ solid: "solid";
32
+ dash: "dash";
33
+ dot: "dot";
34
+ double: "double";
35
+ bold: "bold";
36
+ arrow: "arrow";
37
+ "open-arrow": "open-arrow";
38
+ }>>;
39
+ }, z.core.$strip>;
40
+ declare const GraphSchema: z.ZodObject<{
41
+ type: z.ZodDefault<z.ZodEnum<{
42
+ graph: "graph";
43
+ sequence: "sequence";
44
+ flow: "flow";
45
+ }>>;
46
+ layout: z.ZodOptional<z.ZodObject<{
47
+ direction: z.ZodDefault<z.ZodEnum<{
48
+ LR: "LR";
49
+ RL: "RL";
50
+ TB: "TB";
51
+ BT: "BT";
52
+ }>>;
53
+ }, z.core.$strip>>;
54
+ nodes: z.ZodArray<z.ZodObject<{
55
+ id: z.ZodString;
56
+ label: z.ZodOptional<z.ZodString>;
57
+ type: z.ZodOptional<z.ZodString>;
58
+ kind: z.ZodOptional<z.ZodEnum<{
59
+ actor: "actor";
60
+ lifeline: "lifeline";
61
+ message: "message";
62
+ activity: "activity";
63
+ state: "state";
64
+ class: "class";
65
+ }>>;
66
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
67
+ }, z.core.$strip>>;
68
+ edges: z.ZodArray<z.ZodObject<{
69
+ from: z.ZodString;
70
+ to: z.ZodString;
71
+ label: z.ZodOptional<z.ZodString>;
72
+ kind: z.ZodOptional<z.ZodEnum<{
73
+ next: "next";
74
+ call: "call";
75
+ return: "return";
76
+ async: "async";
77
+ transition: "transition";
78
+ inherit: "inherit";
79
+ association: "association";
80
+ }>>;
81
+ link_type: z.ZodOptional<z.ZodEnum<{
82
+ solid: "solid";
83
+ dash: "dash";
84
+ dot: "dot";
85
+ double: "double";
86
+ bold: "bold";
87
+ arrow: "arrow";
88
+ "open-arrow": "open-arrow";
89
+ }>>;
90
+ }, z.core.$strip>>;
91
+ }, z.core.$strip>;
92
+
93
+ type Graph = z.infer<typeof GraphSchema>;
94
+ type CytoscapeNode = {
95
+ data: {
96
+ id: string;
97
+ label?: string;
98
+ type?: string;
99
+ kind?: string;
100
+ properties?: Record<string, unknown>;
101
+ };
102
+ };
103
+ type CytoscapeEdge = {
104
+ data: {
105
+ id: string;
106
+ source: string;
107
+ target: string;
108
+ label?: string;
109
+ kind?: string;
110
+ link_type?: string;
111
+ };
112
+ };
113
+ type CytoscapeGraph = {
114
+ nodes: CytoscapeNode[];
115
+ edges: CytoscapeEdge[];
116
+ };
117
+
118
+ type EngineResult = {
119
+ ok: true;
120
+ graph: Graph;
121
+ cytoscape: CytoscapeGraph;
122
+ } | {
123
+ ok: false;
124
+ error: z.ZodError;
125
+ };
126
+ declare class Engine {
127
+ validate(input: unknown): Graph;
128
+ safeValidate(input: unknown): ReturnType<typeof GraphSchema.safeParse>;
129
+ parse(input: unknown): EngineResult;
130
+ }
131
+
132
+ export { EdgeSchema, Engine, type EngineResult, GraphSchema, NodeSchema };
@@ -0,0 +1,132 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const NodeSchema: z.ZodObject<{
4
+ id: z.ZodString;
5
+ label: z.ZodOptional<z.ZodString>;
6
+ type: z.ZodOptional<z.ZodString>;
7
+ kind: z.ZodOptional<z.ZodEnum<{
8
+ actor: "actor";
9
+ lifeline: "lifeline";
10
+ message: "message";
11
+ activity: "activity";
12
+ state: "state";
13
+ class: "class";
14
+ }>>;
15
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
16
+ }, z.core.$strip>;
17
+ declare const EdgeSchema: z.ZodObject<{
18
+ from: z.ZodString;
19
+ to: z.ZodString;
20
+ label: z.ZodOptional<z.ZodString>;
21
+ kind: z.ZodOptional<z.ZodEnum<{
22
+ next: "next";
23
+ call: "call";
24
+ return: "return";
25
+ async: "async";
26
+ transition: "transition";
27
+ inherit: "inherit";
28
+ association: "association";
29
+ }>>;
30
+ link_type: z.ZodOptional<z.ZodEnum<{
31
+ solid: "solid";
32
+ dash: "dash";
33
+ dot: "dot";
34
+ double: "double";
35
+ bold: "bold";
36
+ arrow: "arrow";
37
+ "open-arrow": "open-arrow";
38
+ }>>;
39
+ }, z.core.$strip>;
40
+ declare const GraphSchema: z.ZodObject<{
41
+ type: z.ZodDefault<z.ZodEnum<{
42
+ graph: "graph";
43
+ sequence: "sequence";
44
+ flow: "flow";
45
+ }>>;
46
+ layout: z.ZodOptional<z.ZodObject<{
47
+ direction: z.ZodDefault<z.ZodEnum<{
48
+ LR: "LR";
49
+ RL: "RL";
50
+ TB: "TB";
51
+ BT: "BT";
52
+ }>>;
53
+ }, z.core.$strip>>;
54
+ nodes: z.ZodArray<z.ZodObject<{
55
+ id: z.ZodString;
56
+ label: z.ZodOptional<z.ZodString>;
57
+ type: z.ZodOptional<z.ZodString>;
58
+ kind: z.ZodOptional<z.ZodEnum<{
59
+ actor: "actor";
60
+ lifeline: "lifeline";
61
+ message: "message";
62
+ activity: "activity";
63
+ state: "state";
64
+ class: "class";
65
+ }>>;
66
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
67
+ }, z.core.$strip>>;
68
+ edges: z.ZodArray<z.ZodObject<{
69
+ from: z.ZodString;
70
+ to: z.ZodString;
71
+ label: z.ZodOptional<z.ZodString>;
72
+ kind: z.ZodOptional<z.ZodEnum<{
73
+ next: "next";
74
+ call: "call";
75
+ return: "return";
76
+ async: "async";
77
+ transition: "transition";
78
+ inherit: "inherit";
79
+ association: "association";
80
+ }>>;
81
+ link_type: z.ZodOptional<z.ZodEnum<{
82
+ solid: "solid";
83
+ dash: "dash";
84
+ dot: "dot";
85
+ double: "double";
86
+ bold: "bold";
87
+ arrow: "arrow";
88
+ "open-arrow": "open-arrow";
89
+ }>>;
90
+ }, z.core.$strip>>;
91
+ }, z.core.$strip>;
92
+
93
+ type Graph = z.infer<typeof GraphSchema>;
94
+ type CytoscapeNode = {
95
+ data: {
96
+ id: string;
97
+ label?: string;
98
+ type?: string;
99
+ kind?: string;
100
+ properties?: Record<string, unknown>;
101
+ };
102
+ };
103
+ type CytoscapeEdge = {
104
+ data: {
105
+ id: string;
106
+ source: string;
107
+ target: string;
108
+ label?: string;
109
+ kind?: string;
110
+ link_type?: string;
111
+ };
112
+ };
113
+ type CytoscapeGraph = {
114
+ nodes: CytoscapeNode[];
115
+ edges: CytoscapeEdge[];
116
+ };
117
+
118
+ type EngineResult = {
119
+ ok: true;
120
+ graph: Graph;
121
+ cytoscape: CytoscapeGraph;
122
+ } | {
123
+ ok: false;
124
+ error: z.ZodError;
125
+ };
126
+ declare class Engine {
127
+ validate(input: unknown): Graph;
128
+ safeValidate(input: unknown): ReturnType<typeof GraphSchema.safeParse>;
129
+ parse(input: unknown): EngineResult;
130
+ }
131
+
132
+ export { EdgeSchema, Engine, type EngineResult, GraphSchema, NodeSchema };
package/dist/index.js ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ EdgeSchema: () => EdgeSchema,
24
+ Engine: () => Engine,
25
+ GraphSchema: () => GraphSchema,
26
+ NodeSchema: () => NodeSchema
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/schema/graph.ts
31
+ var import_zod = require("zod");
32
+ var GraphTypeSchema = import_zod.z.enum(["graph", "sequence", "flow"]);
33
+ var NodeKindSchema = import_zod.z.enum([
34
+ "actor",
35
+ "lifeline",
36
+ "message",
37
+ "activity",
38
+ "state",
39
+ "class"
40
+ ]);
41
+ var EdgeLinkTypeSchema = import_zod.z.enum([
42
+ "solid",
43
+ "dash",
44
+ "dot",
45
+ "double",
46
+ "bold",
47
+ "arrow",
48
+ "open-arrow"
49
+ ]);
50
+ var EdgeKindSchema = import_zod.z.enum([
51
+ "next",
52
+ "call",
53
+ "return",
54
+ "async",
55
+ "transition",
56
+ "inherit",
57
+ "association"
58
+ ]);
59
+ var LayoutDirectionSchema = import_zod.z.enum(["LR", "RL", "TB", "BT"]);
60
+ var LayoutSchema = import_zod.z.object({
61
+ direction: LayoutDirectionSchema.default("LR")
62
+ });
63
+ var NodeSchema = import_zod.z.object({
64
+ id: import_zod.z.string(),
65
+ label: import_zod.z.string().optional(),
66
+ type: import_zod.z.string().optional(),
67
+ kind: NodeKindSchema.optional(),
68
+ properties: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
69
+ });
70
+ var EdgeSchema = import_zod.z.object({
71
+ from: import_zod.z.string(),
72
+ to: import_zod.z.string(),
73
+ label: import_zod.z.string().optional(),
74
+ kind: EdgeKindSchema.optional(),
75
+ link_type: EdgeLinkTypeSchema.optional()
76
+ });
77
+ var GraphSchema = import_zod.z.object({
78
+ type: GraphTypeSchema.default("flow"),
79
+ layout: LayoutSchema.optional(),
80
+ nodes: import_zod.z.array(NodeSchema),
81
+ edges: import_zod.z.array(EdgeSchema)
82
+ });
83
+
84
+ // src/index.ts
85
+ var toCytoscape = (graph) => {
86
+ const nodes = graph.nodes.map((node) => {
87
+ const data = {
88
+ id: node.id
89
+ };
90
+ if (node.label !== void 0) {
91
+ data.label = node.label;
92
+ }
93
+ if (node.type !== void 0) {
94
+ data.type = node.type;
95
+ }
96
+ if (node.kind !== void 0) {
97
+ data.kind = node.kind;
98
+ }
99
+ if (node.properties !== void 0) {
100
+ data.properties = node.properties;
101
+ }
102
+ return { data };
103
+ });
104
+ const edges = graph.edges.map((edge) => {
105
+ const data = {
106
+ id: `${edge.from}->${edge.to}`,
107
+ source: edge.from,
108
+ target: edge.to
109
+ };
110
+ if (edge.label !== void 0) {
111
+ data.label = edge.label;
112
+ }
113
+ if (edge.kind !== void 0) {
114
+ data.kind = edge.kind;
115
+ }
116
+ if (edge.link_type !== void 0) {
117
+ data.link_type = edge.link_type;
118
+ }
119
+ return { data };
120
+ });
121
+ return { nodes, edges };
122
+ };
123
+ var Engine = class {
124
+ validate(input) {
125
+ return GraphSchema.parse(input);
126
+ }
127
+ safeValidate(input) {
128
+ return GraphSchema.safeParse(input);
129
+ }
130
+ parse(input) {
131
+ const result = GraphSchema.safeParse(input);
132
+ if (!result.success) {
133
+ return { ok: false, error: result.error };
134
+ }
135
+ const graph = result.data;
136
+ const cytoscape = toCytoscape(graph);
137
+ if (graph.type === "flow") {
138
+ const flowchart = cytoscape;
139
+ return { ok: true, graph, cytoscape: flowchart };
140
+ }
141
+ return { ok: true, graph, cytoscape };
142
+ }
143
+ };
144
+ // Annotate the CommonJS export names for ESM import in node:
145
+ 0 && (module.exports = {
146
+ EdgeSchema,
147
+ Engine,
148
+ GraphSchema,
149
+ NodeSchema
150
+ });
151
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/schema/graph.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { EdgeSchema, GraphSchema, NodeSchema } from \"@engine/schema/graph\";\nimport type {\n CytoscapeGraph,\n Edge,\n FlowchartCytoscapeGraph,\n Graph,\n Node,\n} from \"@engine/types/graph\";\n\nexport type EngineResult =\n | { ok: true; graph: Graph; cytoscape: CytoscapeGraph }\n | { ok: false; error: z.ZodError };\n\nconst toCytoscape = (graph: Graph): CytoscapeGraph => {\n const nodes = graph.nodes.map((node) => {\n const data: {\n id: string;\n label?: string;\n type?: string;\n kind?: string;\n properties?: Record<string, unknown>;\n } = {\n id: node.id,\n };\n\n if (node.label !== undefined) {\n data.label = node.label;\n }\n if (node.type !== undefined) {\n data.type = node.type;\n }\n if (node.kind !== undefined) {\n data.kind = node.kind;\n }\n if (node.properties !== undefined) {\n data.properties = node.properties;\n }\n\n return { data };\n });\n\n const edges = graph.edges.map((edge) => {\n const data: {\n id: string;\n source: string;\n target: string;\n label?: string;\n kind?: string;\n link_type?: string;\n } = {\n id: `${edge.from}->${edge.to}`,\n source: edge.from,\n target: edge.to,\n };\n\n if (edge.label !== undefined) {\n data.label = edge.label;\n }\n if (edge.kind !== undefined) {\n data.kind = edge.kind;\n }\n if (edge.link_type !== undefined) {\n data.link_type = edge.link_type;\n }\n\n return { data };\n });\n\n return { nodes, edges };\n};\n\nexport class Engine {\n validate(input: unknown): Graph {\n return GraphSchema.parse(input);\n }\n\n safeValidate(input: unknown): ReturnType<typeof GraphSchema.safeParse> {\n return GraphSchema.safeParse(input);\n }\n\n parse(input: unknown): EngineResult {\n const result = GraphSchema.safeParse(input);\n if (!result.success) {\n return { ok: false, error: result.error };\n }\n\n const graph = result.data;\n const cytoscape = toCytoscape(graph);\n\n if (graph.type === \"flow\") {\n const flowchart: FlowchartCytoscapeGraph = cytoscape;\n return { ok: true, graph, cytoscape: flowchart };\n }\n\n return { ok: true, graph, cytoscape };\n }\n}\n\nexport {\n EdgeSchema,\n GraphSchema,\n NodeSchema,\n};\n","import { z } from \"zod\";\n\nexport const GraphTypeSchema = z.enum([\"graph\", \"sequence\", \"flow\"]);\n\nexport const NodeKindSchema = z.enum([\n \"actor\",\n \"lifeline\",\n \"message\",\n \"activity\",\n \"state\",\n \"class\",\n]);\n\nexport const EdgeLinkTypeSchema = z.enum([\n \"solid\",\n \"dash\",\n \"dot\",\n \"double\",\n \"bold\",\n \"arrow\",\n \"open-arrow\",\n]);\n\nexport const EdgeKindSchema = z.enum([\n \"next\",\n \"call\",\n \"return\",\n \"async\",\n \"transition\",\n \"inherit\",\n \"association\",\n]);\n\nexport const LayoutDirectionSchema = z.enum([\"LR\", \"RL\", \"TB\", \"BT\"]);\n\nexport const LayoutSchema = z.object({\n direction: LayoutDirectionSchema.default(\"LR\"),\n});\n\nexport const NodeSchema = z.object({\n id: z.string(),\n label: z.string().optional(),\n type: z.string().optional(),\n kind: NodeKindSchema.optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const EdgeSchema = z.object({\n from: z.string(),\n to: z.string(),\n label: z.string().optional(),\n kind: EdgeKindSchema.optional(),\n link_type: EdgeLinkTypeSchema.optional(),\n});\n\nexport const GraphSchema = z.object({\n type: GraphTypeSchema.default(\"flow\"),\n layout: LayoutSchema.optional(),\n nodes: z.array(NodeSchema),\n edges: z.array(EdgeSchema),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAEX,IAAM,kBAAkB,aAAE,KAAK,CAAC,SAAS,YAAY,MAAM,CAAC;AAE5D,IAAM,iBAAiB,aAAE,KAAK;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,qBAAqB,aAAE,KAAK;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,iBAAiB,aAAE,KAAK;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,wBAAwB,aAAE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C;AAED,QAAM,QAAQ,MAAM,MAAM,IAAI,CAAC,SAAS;AACtC,UAAM,OAOF;AAAA,MACF,IAAI,GAAG,KAAK,IAAI,KAAK,KAAK,EAAE;AAAA,MAC5B,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK;AAAA,IACf;AAEA,QAAI,KAAK,UAAU,QAAW;AAC5B,WAAK,QAAQ,KAAK;AAAA,IACpB;AACA,QAAI,KAAK,SAAS,QAAW;AAC3B,WAAK,OAAO,KAAK;AAAA,IACnB;AACA,QAAI,KAAK,cAAc,QAAW;AAChC,WAAK,YAAY,KAAK;AAAA,IACxB;AAEA,WAAO,EAAE,KAAK;AAAA,EAChB,CAAC;AAED,SAAO,EAAE,OAAO,MAAM;AACxB;AAEO,IAAM,SAAN,MAAa;AAAA,EAClB,SAAS,OAAuB;AAC9B,WAAO,YAAY,MAAM,KAAK;AAAA,EAChC;AAAA,EAEA,aAAa,OAA0D;AACrE,WAAO,YAAY,UAAU,KAAK;AAAA,EACpC;AAAA,EAEA,MAAM,OAA8B;AAClC,UAAM,SAAS,YAAY,UAAU,KAAK;AAC1C,QAAI,CAAC,OAAO,SAAS;AACnB,aAAO,EAAE,IAAI,OAAO,OAAO,OAAO,MAAM;AAAA,IAC1C;AAEA,UAAM,QAAQ,OAAO;AACrB,UAAM,YAAY,YAAY,KAAK;AAEnC,QAAI,MAAM,SAAS,QAAQ;AACzB,YAAM,YAAqC;AAC3C,aAAO,EAAE,IAAI,MAAM,OAAO,WAAW,UAAU;AAAA,IACjD;AAEA,WAAO,EAAE,IAAI,MAAM,OAAO,UAAU;AAAA,EACtC;AACF;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,121 @@
1
+ // src/schema/graph.ts
2
+ import { z } from "zod";
3
+ var GraphTypeSchema = z.enum(["graph", "sequence", "flow"]);
4
+ var NodeKindSchema = z.enum([
5
+ "actor",
6
+ "lifeline",
7
+ "message",
8
+ "activity",
9
+ "state",
10
+ "class"
11
+ ]);
12
+ var EdgeLinkTypeSchema = z.enum([
13
+ "solid",
14
+ "dash",
15
+ "dot",
16
+ "double",
17
+ "bold",
18
+ "arrow",
19
+ "open-arrow"
20
+ ]);
21
+ var EdgeKindSchema = z.enum([
22
+ "next",
23
+ "call",
24
+ "return",
25
+ "async",
26
+ "transition",
27
+ "inherit",
28
+ "association"
29
+ ]);
30
+ var LayoutDirectionSchema = z.enum(["LR", "RL", "TB", "BT"]);
31
+ var LayoutSchema = z.object({
32
+ direction: LayoutDirectionSchema.default("LR")
33
+ });
34
+ var NodeSchema = z.object({
35
+ id: z.string(),
36
+ label: z.string().optional(),
37
+ type: z.string().optional(),
38
+ kind: NodeKindSchema.optional(),
39
+ properties: z.record(z.string(), z.unknown()).optional()
40
+ });
41
+ var EdgeSchema = z.object({
42
+ from: z.string(),
43
+ to: z.string(),
44
+ label: z.string().optional(),
45
+ kind: EdgeKindSchema.optional(),
46
+ link_type: EdgeLinkTypeSchema.optional()
47
+ });
48
+ var GraphSchema = z.object({
49
+ type: GraphTypeSchema.default("flow"),
50
+ layout: LayoutSchema.optional(),
51
+ nodes: z.array(NodeSchema),
52
+ edges: z.array(EdgeSchema)
53
+ });
54
+
55
+ // src/index.ts
56
+ var toCytoscape = (graph) => {
57
+ const nodes = graph.nodes.map((node) => {
58
+ const data = {
59
+ id: node.id
60
+ };
61
+ if (node.label !== void 0) {
62
+ data.label = node.label;
63
+ }
64
+ if (node.type !== void 0) {
65
+ data.type = node.type;
66
+ }
67
+ if (node.kind !== void 0) {
68
+ data.kind = node.kind;
69
+ }
70
+ if (node.properties !== void 0) {
71
+ data.properties = node.properties;
72
+ }
73
+ return { data };
74
+ });
75
+ const edges = graph.edges.map((edge) => {
76
+ const data = {
77
+ id: `${edge.from}->${edge.to}`,
78
+ source: edge.from,
79
+ target: edge.to
80
+ };
81
+ if (edge.label !== void 0) {
82
+ data.label = edge.label;
83
+ }
84
+ if (edge.kind !== void 0) {
85
+ data.kind = edge.kind;
86
+ }
87
+ if (edge.link_type !== void 0) {
88
+ data.link_type = edge.link_type;
89
+ }
90
+ return { data };
91
+ });
92
+ return { nodes, edges };
93
+ };
94
+ var Engine = class {
95
+ validate(input) {
96
+ return GraphSchema.parse(input);
97
+ }
98
+ safeValidate(input) {
99
+ return GraphSchema.safeParse(input);
100
+ }
101
+ parse(input) {
102
+ const result = GraphSchema.safeParse(input);
103
+ if (!result.success) {
104
+ return { ok: false, error: result.error };
105
+ }
106
+ const graph = result.data;
107
+ const cytoscape = toCytoscape(graph);
108
+ if (graph.type === "flow") {
109
+ const flowchart = cytoscape;
110
+ return { ok: true, graph, cytoscape: flowchart };
111
+ }
112
+ return { ok: true, graph, cytoscape };
113
+ }
114
+ };
115
+ export {
116
+ EdgeSchema,
117
+ Engine,
118
+ GraphSchema,
119
+ NodeSchema
120
+ };
121
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schema/graph.ts","../src/index.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const GraphTypeSchema = z.enum([\"graph\", \"sequence\", \"flow\"]);\n\nexport const NodeKindSchema = z.enum([\n \"actor\",\n \"lifeline\",\n \"message\",\n \"activity\",\n \"state\",\n \"class\",\n]);\n\nexport const EdgeLinkTypeSchema = z.enum([\n \"solid\",\n \"dash\",\n \"dot\",\n \"double\",\n \"bold\",\n \"arrow\",\n \"open-arrow\",\n]);\n\nexport const EdgeKindSchema = z.enum([\n \"next\",\n \"call\",\n \"return\",\n \"async\",\n \"transition\",\n \"inherit\",\n \"association\",\n]);\n\nexport const LayoutDirectionSchema = z.enum([\"LR\", \"RL\", \"TB\", \"BT\"]);\n\nexport const LayoutSchema = z.object({\n direction: LayoutDirectionSchema.default(\"LR\"),\n});\n\nexport const NodeSchema = z.object({\n id: z.string(),\n label: z.string().optional(),\n type: z.string().optional(),\n kind: NodeKindSchema.optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const EdgeSchema = z.object({\n from: z.string(),\n to: z.string(),\n label: z.string().optional(),\n kind: EdgeKindSchema.optional(),\n link_type: EdgeLinkTypeSchema.optional(),\n});\n\nexport const GraphSchema = z.object({\n type: GraphTypeSchema.default(\"flow\"),\n layout: LayoutSchema.optional(),\n nodes: z.array(NodeSchema),\n edges: z.array(EdgeSchema),\n});\n","import { z } from \"zod\";\nimport { EdgeSchema, GraphSchema, NodeSchema } from \"@engine/schema/graph\";\nimport type {\n CytoscapeGraph,\n Edge,\n FlowchartCytoscapeGraph,\n Graph,\n Node,\n} from \"@engine/types/graph\";\n\nexport type EngineResult =\n | { ok: true; graph: Graph; cytoscape: CytoscapeGraph }\n | { ok: false; error: z.ZodError };\n\nconst toCytoscape = (graph: Graph): CytoscapeGraph => {\n const nodes = graph.nodes.map((node) => {\n const data: {\n id: string;\n label?: string;\n type?: string;\n kind?: string;\n properties?: Record<string, unknown>;\n } = {\n id: node.id,\n };\n\n if (node.label !== undefined) {\n data.label = node.label;\n }\n if (node.type !== undefined) {\n data.type = node.type;\n }\n if (node.kind !== undefined) {\n data.kind = node.kind;\n }\n if (node.properties !== undefined) {\n data.properties = node.properties;\n }\n\n return { data };\n });\n\n const edges = graph.edges.map((edge) => {\n const data: {\n id: string;\n source: string;\n target: string;\n label?: string;\n kind?: string;\n link_type?: string;\n } = {\n id: `${edge.from}->${edge.to}`,\n source: edge.from,\n target: edge.to,\n };\n\n if (edge.label !== undefined) {\n data.label = edge.label;\n }\n if (edge.kind !== undefined) {\n data.kind = edge.kind;\n }\n if (edge.link_type !== undefined) {\n data.link_type = edge.link_type;\n }\n\n return { data };\n });\n\n return { nodes, edges };\n};\n\nexport class Engine {\n validate(input: unknown): Graph {\n return GraphSchema.parse(input);\n }\n\n safeValidate(input: unknown): ReturnType<typeof GraphSchema.safeParse> {\n return GraphSchema.safeParse(input);\n }\n\n parse(input: unknown): EngineResult {\n const result = GraphSchema.safeParse(input);\n if (!result.success) {\n return { ok: false, error: result.error };\n }\n\n const graph = result.data;\n const cytoscape = toCytoscape(graph);\n\n if (graph.type === \"flow\") {\n const flowchart: FlowchartCytoscapeGraph = cytoscape;\n return { ok: true, graph, cytoscape: flowchart };\n }\n\n return { ok: true, graph, cytoscape };\n }\n}\n\nexport {\n EdgeSchema,\n GraphSchema,\n NodeSchema,\n};\n"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,kBAAkB,EAAE,KAAK,CAAC,SAAS,YAAY,MAAM,CAAC;AAE5D,IAAM,iBAAiB,EAAE,KAAK;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,qBAAqB,EAAE,KAAK;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,iBAAiB,EAAE,KAAK;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,wBAAwB,EAAE,KAAK,CAAC,MAAM,MAAM,MAAM,IAAI,CAAC;AAE7D,IAAM,eAAe,EAAE,OAAO;AAAA,EACnC,WAAW,sBAAsB,QAAQ,IAAI;AAC/C,CAAC;AAEM,IAAM,aAAa,EAAE,OAAO;AAAA,EACjC,IAAI,EAAE,OAAO;AAAA,EACb,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,MAAM,eAAe,SAAS;AAAA,EAC9B,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,SAAS;AACzD,CAAC;AAEM,IAAM,aAAa,EAAE,OAAO;AAAA,EACjC,MAAM,EAAE,OAAO;AAAA,EACf,IAAI,EAAE,OAAO;AAAA,EACb,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,MAAM,eAAe,SAAS;AAAA,EAC9B,WAAW,mBAAmB,SAAS;AACzC,CAAC;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AAK;AAAA,EACpC;AAAA,EAEA,MAAM,OAA8B;AAClC,UAAM,SAAS,YAAY,UAAU,KAAK;AAC1C,QAAI,CAAC,OAAO,SAAS;AACnB,aAAO,EAAE,IAAI,OAAO,OAAO,OAAO,MAAM;AAAA,IAC1C;AAEA,UAAM,QAAQ,OAAO;AACrB,UAAM,YAAY,YAAY,KAAK;AAEnC,QAAI,MAAM,SAAS,QAAQ;AACzB,YAAM,YAAqC;AAC3C,aAAO,EAAE,IAAI,MAAM,OAAO,WAAW,UAAU;AAAA,IACjD;AAEA,WAAO,EAAE,IAAI,MAAM,OAAO,UAAU;AAAA,EACtC;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@andro.dev/jsonflow-engine",
3
+ "version": "1.0.0",
4
+ "description": "JSONFLOW engine (logic + parser) for schema-validated diagrams.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "build": "tsup",
24
+ "dev": "tsup --watch",
25
+ "test": "vitest",
26
+ "test:run": "vitest run"
27
+ },
28
+ "keywords": [],
29
+ "author": "",
30
+ "license": "MIT",
31
+ "packageManager": "pnpm@10.28.1",
32
+ "dependencies": {
33
+ "zod": "^4.1.11"
34
+ },
35
+ "devDependencies": {
36
+ "tsup": "^8.5.0",
37
+ "typescript": "^5.9.3",
38
+ "vitest": "^3.2.4",
39
+ "@types/node": "^25.2.0"
40
+ }
41
+ }