@mantaq/traversal 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyActor, Snapshot } from "@mantaq/core";
1
+ import { AnyActor, Context, Snapshot } from "@mantaq/core";
2
2
  //#region src/types.d.ts
3
3
  interface GraphNode {
4
4
  id: string;
@@ -77,11 +77,11 @@ interface InstrumentedActor {
77
77
  history: History;
78
78
  send(event: unknown): void;
79
79
  state: AnyActor["state"];
80
- snapshot(): Snapshot;
80
+ snapshot(): Snapshot<Record<string, unknown>>;
81
81
  regions: Record<string, AnyActor>;
82
82
  context?: Record<string, unknown>;
83
83
  clock: AnyActor["clock"];
84
- on(event: "change", fn: (snapshot: Snapshot) => void): () => void;
84
+ on(event: "change", fn: (snapshot: Snapshot<Record<string, unknown>>, prev: Snapshot<Record<string, unknown>>) => void): () => void;
85
85
  on(event: "error", fn: (error: unknown) => void): () => void;
86
86
  on(event: "done", fn: () => void): () => void;
87
87
  settled(): Promise<void>;
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { Context } from "@mantaq/core";
1
2
  import { Either } from "@mantaq/utils";
2
3
  //#region src/graph.ts
3
4
  const INITIAL_NODE_ID = "__initial__";
@@ -23,10 +24,10 @@ function buildNodesFromStates(states, activeSet, pathPrefix) {
23
24
  };
24
25
  });
25
26
  }
26
- function invokeHandler(handler, eventId, ctx, actor) {
27
+ function invokeHandler(handler, eventId, context, actor) {
27
28
  return Either.from(() => {
28
29
  const result = handler({ id: eventId }, {
29
- context: ctx,
30
+ context: new Context(() => context, () => {}),
30
31
  actor
31
32
  });
32
33
  return {
@@ -58,8 +59,8 @@ function processStateTransitions(stateTransitions, pass) {
58
59
  for (const [eventId, handler] of Object.entries(stateTransitions)) {
59
60
  if (typeof handler !== "function") continue;
60
61
  for (const ctxName of pass.traversal.contextNames) {
61
- const ctx = pass.traversal.contexts[ctxName];
62
- const handled = Either.getOrElse(invokeHandler(handler, eventId, ctx, pass.traversal.actor), () => ({
62
+ const sampleContext = pass.traversal.contexts[ctxName];
63
+ const handled = Either.getOrElse(invokeHandler(handler, eventId, sampleContext, pass.traversal.actor), () => ({
63
64
  targetName: void 0,
64
65
  emitNames: []
65
66
  }));
@@ -78,8 +79,8 @@ function mergeAnyTransitions(anyTransitions, stateTransitionedEvents, pass) {
78
79
  if (typeof handler !== "function") continue;
79
80
  if (stateTransitionedEvents.has(eventId)) continue;
80
81
  for (const ctxName of pass.traversal.contextNames) {
81
- const ctx = pass.traversal.contexts[ctxName];
82
- const handled = Either.getOrElse(invokeHandler(handler, eventId, ctx, pass.traversal.actor), () => ({
82
+ const sampleContext = pass.traversal.contexts[ctxName];
83
+ const handled = Either.getOrElse(invokeHandler(handler, eventId, sampleContext, pass.traversal.actor), () => ({
83
84
  targetName: void 0,
84
85
  emitNames: []
85
86
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantaq/traversal",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Graph extraction, traversal algorithms, and runtime tracking for mantaq actors.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,7 +20,7 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@mantaq/core": "0.0.1",
23
+ "@mantaq/core": "0.0.2",
24
24
  "@mantaq/utils": "0.0.1"
25
25
  },
26
26
  "devDependencies": {