Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app-compose/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grlt-hub/app-compose",
"version": "3.0.0-alpha.12",
"version": "3.0.0-alpha.13",
"private": false,
"publishConfig": {
"access": "public"
Expand Down
6 changes: 3 additions & 3 deletions packages/app-compose/src/__tests__/is.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createTag, createTask } from "@runnable"
import { createTask, tag } from "@runnable"
import { describe, expect, it } from "vitest"
import { is } from "../is"

describe("is.tag", () => {
it("returns true for a tag", () => {
const tag = createTag({ name: "_" })
const value = tag("_")

expect(is.tag(tag)).toBe(true)
expect(is.tag(value)).toBe(true)
})

it("returns false for a non object", () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/app-compose/src/compose/__tests__/compose.bench.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { literal, shape, type Spot } from "@computable"
import { bind, createTag, createTask } from "@runnable"
import { createWire, tag, createTask } from "@runnable"
import { bench, describe, vi } from "vitest"
import { compose } from "../compose"

const double = (x: number) => x * 2

describe("multi layer, compute shapes", () => {
const rootTag = createTag<number>({ name: "root" })
const rootTag = tag<number>("root")

let app = compose()
.meta({ name: "bench" })
.step(bind(rootTag, literal(1)))
.step(createWire(rootTag, literal(1)))

let previous: Spot<number> = rootTag.value

for (let layer = 0; layer < 20; layer++) {
const l = shape({ layer: literal(layer), previous }, ({ layer, previous }) => layer + previous)

const a = createTag<number>({ name: `${layer}:a` })
const b = createTag<number>({ name: `${layer}:b` })
const c = createTag<number>({ name: `${layer}:c` })
const d = createTag<number>({ name: `${layer}:d` })
const a = tag<number>(`${layer}:a`)
const b = tag<number>(`${layer}:b`)
const c = tag<number>(`${layer}:c`)
const d = tag<number>(`${layer}:d`)

const task = createTask({
name: `${layer}:task`,
Expand All @@ -31,8 +31,8 @@ describe("multi layer, compute shapes", () => {
})

app = app
.step([bind(a, shape(l, double)), bind(b, shape(l, double))])
.step([bind(c, shape(l, double)), bind(d, shape(l, double))])
.step([createWire(a, shape(l, double)), createWire(b, shape(l, double))])
.step([createWire(c, shape(l, double)), createWire(d, shape(l, double))])
.step(task)

previous = task.result
Expand Down
28 changes: 14 additions & 14 deletions packages/app-compose/src/compose/__tests__/compose.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { literal } from "@computable"
import { bind, createTag, createTask } from "@runnable"
import { createTask, createWire, tag } from "@runnable"
import { LIBRARY_NAME } from "@shared"
import { describe, expect, it } from "vitest"
import { compose } from "../compose"
Expand All @@ -19,37 +19,37 @@ describe("compose", () => {

describe("guard", () => {
it("throws on warning graph", () => {
const tag = createTag<number>({ name: "alpha" })
const app = compose().step(bind(tag, literal(1)))
const alpha = tag<number>("alpha")
const wire = createWire(alpha, literal(1))

const message = `Unused Binding found with name Tag[alpha] in step root > #1.`
const app = compose().step(wire)

const message = `Unused Wire found with name Tag[alpha] in step root > #1.`

expect(() => app.guard()).toThrowError(message)
})

it("throws on error graph", () => {
const tag = createTag<number>({ name: "alpha" })
const alpha = tag<number>("alpha")

const app = compose()
.step(bind(tag, literal(1)))
.step(bind(tag, literal(2)))
.step(createWire(alpha, literal(1)))
.step(createWire(alpha, literal(2)))

const message = `A duplicate Binding found with name Tag[alpha] in step root > #2.`
const message = `A duplicate Wire found with name Tag[alpha] in step root > #2.`

expect(() => app.guard()).toThrowError(message)
})
})

describe("graph", () => {
it("provides correct graph structure", () => {
const alpha = tag<number>("alpha")

const task = createTask({ name: "task", run: { fn: () => {} } })
const tag = createTag<number>({ name: "alpha" })
const wire = createWire(alpha, literal(1))

const graph = compose()
.meta({ name: "app" })
.step(bind(tag, literal(1)))
.step(task)
.graph()
const graph = compose().meta({ name: "app" }).step(wire).step(task).graph()

const result = { type: "seq", meta: { name: "app" }, children: [{ type: "run" }, { type: "run" }] }
expect(graph).toMatchObject(result)
Expand Down
28 changes: 14 additions & 14 deletions packages/app-compose/src/compose/__tests__/graph.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { literal, optional } from "@computable"
import { bind, createTag, createTask } from "@runnable"
import { createTask, createWire, tag } from "@runnable"
import { describe, expect, it, vi } from "vitest"
import { compose, Node$ } from "../compose"
import { graph } from "../graph"
Expand Down Expand Up @@ -135,10 +135,10 @@ describe("graph", () => {

describe("tags", () => {
it("dependency on a task via a tag", () => {
const valueTag = createTag<boolean>({ name: "value" })
const valueTag = tag<boolean>("value")
const betaTask = createTask({ name: "beta", run: { fn: vi.fn(), context: valueTag.value } })

const app = compose().step(alphaTask).step(bind(valueTag, alphaTask.result.value)).step(betaTask)
const app = compose().step(alphaTask).step(createWire(valueTag, alphaTask.result.value)).step(betaTask)
const result = graph(app[Node$])

const expected = {
Expand All @@ -154,7 +154,7 @@ describe("graph", () => {
{
type: "run",
id: 1,
meta: { name: "value", kind: "binding" },
meta: { name: "value", kind: "wire" },
dependencies: { required: [0], optional: [] },
},
{
Expand All @@ -170,12 +170,12 @@ describe("graph", () => {
})

it("dependency on a task via a tag [optional]", () => {
const valueTag = createTag<boolean>({ name: "value" })
const valueTag = tag<boolean>("value")
const betaTask = createTask({ name: "beta", run: { fn: vi.fn(), context: optional(valueTag.value) } })

const app = compose()
.step(alphaTask)
.step(bind(valueTag, optional(alphaTask.result.value)))
.step(createWire(valueTag, optional(alphaTask.result.value)))
.step(betaTask)

const result = graph(app[Node$])
Expand All @@ -193,7 +193,7 @@ describe("graph", () => {
{
type: "run",
id: 1,
meta: { name: "value", kind: "binding" },
meta: { name: "value", kind: "wire" },
dependencies: { required: [], optional: [0] },
},
{
Expand All @@ -209,11 +209,11 @@ describe("graph", () => {
})

it("task depends on a literal via tag", () => {
const valueTag = createTag<boolean>({ name: "value" })
const valueTag = tag<boolean>("value")
const betaTask = createTask({ name: "beta", run: { fn: vi.fn(), context: valueTag.value } })

const app = compose()
.step(bind(valueTag, literal(false)))
.step(createWire(valueTag, literal(false)))
.step(betaTask)

const result = graph(app[Node$])
Expand All @@ -225,7 +225,7 @@ describe("graph", () => {
{
type: "run",
id: 0,
meta: { name: "value", kind: "binding" },
meta: { name: "value", kind: "wire" },
dependencies: { required: [], optional: [] },
},
{
Expand Down Expand Up @@ -262,19 +262,19 @@ describe("graph", () => {

describe("mixed dependencies", () => {
it("required and optional", () => {
const fnTag = createTag<() => void>({ name: "fn" })
const fn = tag<() => void>("fn")

const betaTask = createTask({
name: "beta",
run: {
context: { value: alphaTask.result.value, fn: optional(fnTag.value) },
context: { value: alphaTask.result.value, fn: optional(fn.value) },
fn: vi.fn(),
},
})

const app = compose()
.step(alphaTask)
.step(bind(fnTag, literal(vi.fn())))
.step(createWire(fn, literal(vi.fn())))
.step(betaTask)

const result = graph(app[Node$])
Expand All @@ -292,7 +292,7 @@ describe("graph", () => {
{
type: "run",
id: 1,
meta: { name: "fn", kind: "binding" },
meta: { name: "fn", kind: "wire" },
dependencies: { required: [], optional: [] },
},
{
Expand Down
Loading
Loading