Class DataBag

The data of one journey: values by key, in the order each key was first set. It starts as the instance's initial data, and a journey that succeeds or fails hands it over in its result, as the journey's output. An input adapter that requests it reads it while the step is built. Only itinera makes one, and it has no method that writes.

import assert from "node:assert/strict";
import { LocalExecutor } from "itinera/executor";
import type { Read } from "itinera/journey";
import { None, Some } from "itinera/option";
import { Step } from "itinera/step";
import { Workflow } from "itinera/workflow";
import { integer, string } from "itinera/value";

class Charge extends Step {
override run() {
return this.succeed();
}
}

class Orders extends Workflow {}

export default (async () => {
const orders = Orders.builder()
.name("orders")
.step(Charge.builder("charge"))
.build();
const instance = orders.instance(
new Map<string, string | number>([
["order", "A-1"],
["amount", 1250],
]),
);

const result = await new LocalExecutor().run(instance);

assert.ok(result.isSucceeded());
const { dataBag } = result.status;
const amount: Read<number> = dataBag.read("amount", integer);
assert.equal(amount.kind, "present");
assert.deepEqual(amount.option(), Some(1250));
assert.equal(dataBag.read("order", integer).kind, "other type");
assert.equal(dataBag.read("shop", string).kind, "absent");
assert.equal(dataBag.read("shop", string).option(), None);
})();

Index

  • Its keys, in the order each was first set.

    Returns readonly string[]

  • Reads the value under key as the type type checks, which may be one of itinera's tokens or any other Standard Schema validator: present, as the reader's own copy, or an instance made by fromValue for a class named with classOf; absent; or of another type, when type refuses the value, throws, or checks it asynchronously, or when a fromValue throws. With a type wrapped in optional, the key is never absent: it reads present, as None when it holds no value and as Some of a value of the type.

    import assert from "node:assert/strict";
    import { LocalExecutor } from "itinera/executor";
    import type { Read } from "itinera/journey";
    import { None, Some } from "itinera/option";
    import { Step } from "itinera/step";
    import { Workflow } from "itinera/workflow";
    import { integer, string } from "itinera/value";

    class Charge extends Step {
    override run() {
    return this.succeed();
    }
    }

    class Orders extends Workflow {}

    export default (async () => {
    const orders = Orders.builder()
    .name("orders")
    .step(Charge.builder("charge"))
    .build();
    const instance = orders.instance(
    new Map<string, string | number>([
    ["order", "A-1"],
    ["amount", 1250],
    ]),
    );

    const result = await new LocalExecutor().run(instance);

    assert.ok(result.isSucceeded());
    const { dataBag } = result.status;
    const amount: Read<number> = dataBag.read("amount", integer);
    assert.equal(amount.kind, "present");
    assert.deepEqual(amount.option(), Some(1250));
    assert.equal(dataBag.read("order", integer).kind, "other type");
    assert.equal(dataBag.read("shop", string).kind, "absent");
    assert.equal(dataBag.read("shop", string).option(), None);
    })();

    Type Parameters

    • S extends StandardSchemaV1<unknown, unknown>

    Parameters

    • key: string
    • type: S

    Returns Read<InferInput<S>>

  • Reads the value under key as the type type checks, which may be one of itinera's tokens or any other Standard Schema validator: present, as the reader's own copy, or an instance made by fromValue for a class named with classOf; absent; or of another type, when type refuses the value, throws, or checks it asynchronously, or when a fromValue throws. With a type wrapped in optional, the key is never absent: it reads present, as None when it holds no value and as Some of a value of the type.

    import assert from "node:assert/strict";
    import { LocalExecutor } from "itinera/executor";
    import type { Read } from "itinera/journey";
    import { None, Some } from "itinera/option";
    import { Step } from "itinera/step";
    import { Workflow } from "itinera/workflow";
    import { integer, string } from "itinera/value";

    class Charge extends Step {
    override run() {
    return this.succeed();
    }
    }

    class Orders extends Workflow {}

    export default (async () => {
    const orders = Orders.builder()
    .name("orders")
    .step(Charge.builder("charge"))
    .build();
    const instance = orders.instance(
    new Map<string, string | number>([
    ["order", "A-1"],
    ["amount", 1250],
    ]),
    );

    const result = await new LocalExecutor().run(instance);

    assert.ok(result.isSucceeded());
    const { dataBag } = result.status;
    const amount: Read<number> = dataBag.read("amount", integer);
    assert.equal(amount.kind, "present");
    assert.deepEqual(amount.option(), Some(1250));
    assert.equal(dataBag.read("order", integer).kind, "other type");
    assert.equal(dataBag.read("shop", string).kind, "absent");
    assert.equal(dataBag.read("shop", string).option(), None);
    })();

    Type Parameters

    • S extends StandardSchemaV1<unknown, unknown>

    Parameters

    Returns Read<Option<InferInput<S>>>

  • Reads the value under key as the type type checks, which may be one of itinera's tokens or any other Standard Schema validator: present, as the reader's own copy, or an instance made by fromValue for a class named with classOf; absent; or of another type, when type refuses the value, throws, or checks it asynchronously, or when a fromValue throws. With a type wrapped in optional, the key is never absent: it reads present, as None when it holds no value and as Some of a value of the type.

    import assert from "node:assert/strict";
    import { LocalExecutor } from "itinera/executor";
    import type { Read } from "itinera/journey";
    import { None, Some } from "itinera/option";
    import { Step } from "itinera/step";
    import { Workflow } from "itinera/workflow";
    import { integer, string } from "itinera/value";

    class Charge extends Step {
    override run() {
    return this.succeed();
    }
    }

    class Orders extends Workflow {}

    export default (async () => {
    const orders = Orders.builder()
    .name("orders")
    .step(Charge.builder("charge"))
    .build();
    const instance = orders.instance(
    new Map<string, string | number>([
    ["order", "A-1"],
    ["amount", 1250],
    ]),
    );

    const result = await new LocalExecutor().run(instance);

    assert.ok(result.isSucceeded());
    const { dataBag } = result.status;
    const amount: Read<number> = dataBag.read("amount", integer);
    assert.equal(amount.kind, "present");
    assert.deepEqual(amount.option(), Some(1250));
    assert.equal(dataBag.read("order", integer).kind, "other type");
    assert.equal(dataBag.read("shop", string).kind, "absent");
    assert.equal(dataBag.read("shop", string).option(), None);
    })();

    Parameters

    Returns Read<unknown>