diff --git a/model.ts b/model.ts index 8d22938..e75fb58 100644 --- a/model.ts +++ b/model.ts @@ -12,11 +12,11 @@ export interface Position { y: number; z?: number; } - +export type Dsl = { fn: Fn; cell: Cell; role: Role }; export type Fn = (label: string, role: RoleDef, position: Position) => TxNode export type Cell = (label: string, initial: number, capacity: number, position: Position) => PlaceNode export type Role = (label: string) => RoleDef -export type DeclarationFunction = (fn: Fn, cell: Cell, role: Role) => void +export type DeclarationFunction = ({fn, cell, role}: Dsl) => void export type Vector = number[]; export type MetaType = "place" | "transition" | "arc"; @@ -956,7 +956,7 @@ export function newModel({schema, declaration, type}: ModelOptions): Model { if (declaration) { if (typeof declaration === "function") { - declaration(fn, cell, role); + declaration({fn, cell, role}); } else { loadDeclarationObject(declaration); } diff --git a/package-lock.json b/package-lock.json index dad4872..d49980b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pflow-dev/metamodel", - "version": "0.7.1", + "version": "0.8.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@pflow-dev/metamodel", - "version": "0.7.1", + "version": "0.8.0", "license": "MIT", "devDependencies": { "@babel/core": "^7.14.3", diff --git a/package.json b/package.json index 3df0700..7eb6a06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pflow-dev/metamodel", - "version": "0.7.1", + "version": "0.8.0", "main": "/index.js", "types": "/index.d.ts", "description": "create workflows and petriNets with a DSL", diff --git a/test/editor.test.ts b/test/editor.test.ts index a659266..3b8b085 100644 --- a/test/editor.test.ts +++ b/test/editor.test.ts @@ -1,6 +1,5 @@ import {expect} from "chai"; -import {inhibitTest} from "./examples"; -import {DeclarationFunction, ModelType, newModel, Cell, Fn, Role} from "../"; +import {DeclarationFunction, ModelType, newModel, Dsl} from "../"; function testModel({declaration, type}: { declaration: DeclarationFunction; type: ModelType }) { @@ -24,7 +23,7 @@ export function pos(x: number, y: number): { x: number; y: number } { return {x: x * 80, y: y * 80}; } -export function declaration(fn: Fn, cell: Cell, role: Role): void { +export function declaration({fn, cell, role}: Dsl): void { const defaultRole = role("default"); const foo = cell("foo", 1, 0, pos(6, 2)); const bar = fn("bar", defaultRole, pos(5, 4)); diff --git a/test/examples/inhibitTest.ts b/test/examples/inhibitTest.ts index d8a0760..638a765 100644 --- a/test/examples/inhibitTest.ts +++ b/test/examples/inhibitTest.ts @@ -4,7 +4,7 @@ export function pos(x: number, y: number): { x: number; y: number } { return {x: x * 80, y: y * 80}; } -export function inhibitTest(fn: mm.Fn, cell: mm.Cell, role: mm.Role): void { +export function inhibitTest({fn, cell, role}: mm.Dsl): void { const defaultRole = role("default"); const foo = cell("foo", 1, 0, pos(6, 2)); const bar = fn("bar", defaultRole, pos(5, 4)); @@ -13,7 +13,7 @@ export function inhibitTest(fn: mm.Fn, cell: mm.Cell, role: mm.Role): void { foo.tx(1, bar); } -export function reverseInhibitTest(fn: mm.Fn, cell: mm.Cell, role: mm.Role): void { +export function reverseInhibitTest({fn, cell, role}: mm.Dsl): void { const defaultRole = role("default"); const foo = cell("foo", 1, 0, pos(6, 2)); const bar = fn("bar", defaultRole, pos(5, 4)); diff --git a/test/examples/tictactoe.ts b/test/examples/tictactoe.ts index 07d71a6..f6e8385 100644 --- a/test/examples/tictactoe.ts +++ b/test/examples/tictactoe.ts @@ -1,11 +1,11 @@ -import {Cell, Fn, PlaceNode, Role, RoleDef} from "../../model"; +import {Dsl, PlaceNode, RoleDef} from "../../model"; // visual spacing const dx = 220; const dy = 140; -export function tictactoe(fn: Fn, cell: Cell, role: Role): void { +export function tictactoe({fn, cell, role}: Dsl): void { function row(n: number) { const y = (n + 1) * dy; diff --git a/test/model.test.ts b/test/model.test.ts index 3d51b79..00137e1 100644 --- a/test/model.test.ts +++ b/test/model.test.ts @@ -1,9 +1,9 @@ import {expect} from "chai"; import {tictactoe} from "./examples"; -import {Cell, DeclarationFunction, Fn, ModelType, newModel, PlaceNode, Role, snapshot, TxNode} from "../"; +import {Dsl, DeclarationFunction, ModelType, newModel, PlaceNode, snapshot, TxNode} from "../"; import * as fs from "fs"; -function testElementaryValid(fn: Fn, cell: Cell, role: Role): { +function testElementaryValid({fn, cell, role}: Dsl): { p1: PlaceNode; p2: PlaceNode; p3: PlaceNode; @@ -21,12 +21,12 @@ function testElementaryValid(fn: Fn, cell: Cell, role: Role): { return {p1, t1, p2, p3}; } -function testElementaryInvalid(fn: Fn, cell: Cell, role: Role): void { - const base = testElementaryValid(fn, cell, role); +function testElementaryInvalid({fn, cell, role}: Dsl): void { + const base = testElementaryValid({fn, cell, role}); base.t1.tx(1, base.p3); // add an extra output making this invalid } -function testWorkflowValid(fn: Fn, cell: Cell, role: Role): void { +function testWorkflowValid({fn, cell, role}: Dsl): void { const r = role("default"); const p1 = cell("p1", 1, 1, {x: 100, y: 100}); const p2 = cell("p2", 0, 1, {x: 300, y: 100});