Skip to content

Commit

Permalink
use Dsl type for declaration inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
stackdump committed Dec 27, 2023
1 parent 8225933 commit 10e0f03
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
6 changes: 3 additions & 3 deletions model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 2 additions & 3 deletions test/editor.test.ts
Original file line number Diff line number Diff line change
@@ -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 }) {
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions test/examples/inhibitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions test/examples/tictactoe.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 5 additions & 5 deletions test/model.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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});
Expand Down

0 comments on commit 10e0f03

Please sign in to comment.