Class DataBag
Methods
keys
-
Its keys, in the order each was first set.
Returns readonly string[]
read
-
Reads the value under
keyas the typetypechecks, 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 byfromValuefor a class named withclassOf; absent; or of another type, whentyperefuses the value, throws, or checks it asynchronously, or when afromValuethrows. With a type wrapped inoptional, the key is never absent: it reads present, asNonewhen it holds no value and asSomeof 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>>
-
read<S extends StandardSchemaV1<unknown, unknown>>(
key: string,
type: Optional<S>,
): Read<Option<InferInput<S>>>Reads the value under
keyas the typetypechecks, 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 byfromValuefor a class named withclassOf; absent; or of another type, whentyperefuses the value, throws, or checks it asynchronously, or when afromValuethrows. With a type wrapped inoptional, the key is never absent: it reads present, asNonewhen it holds no value and asSomeof 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>
Returns Read<Option<InferInput<S>>>
-
Reads the value under
keyas the typetypechecks, 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 byfromValuefor a class named withclassOf; absent; or of another type, whentyperefuses the value, throws, or checks it asynchronously, or when afromValuethrows. With a type wrapped inoptional, the key is never absent: it reads present, asNonewhen it holds no value and asSomeof 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
- key: string
- type: RequestType
Returns Read<unknown>
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.