@langchain/langgraph 0.0.11 → 0.0.13
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/channels/any_value.cjs +57 -0
- package/dist/channels/any_value.d.ts +16 -0
- package/dist/channels/any_value.js +53 -0
- package/dist/channels/base.cjs +19 -28
- package/dist/channels/base.d.ts +13 -19
- package/dist/channels/base.js +17 -24
- package/dist/channels/binop.cjs +4 -3
- package/dist/channels/binop.d.ts +1 -1
- package/dist/channels/binop.js +3 -2
- package/dist/channels/dynamic_barrier_value.cjs +88 -0
- package/dist/channels/dynamic_barrier_value.d.ts +26 -0
- package/dist/channels/dynamic_barrier_value.js +84 -0
- package/dist/channels/ephemeral_value.cjs +64 -0
- package/dist/channels/ephemeral_value.d.ts +14 -0
- package/dist/channels/ephemeral_value.js +60 -0
- package/dist/channels/index.cjs +1 -3
- package/dist/channels/index.d.ts +1 -1
- package/dist/channels/index.js +1 -1
- package/dist/channels/last_value.cjs +11 -5
- package/dist/channels/last_value.d.ts +5 -1
- package/dist/channels/last_value.js +9 -3
- package/dist/channels/named_barrier_value.cjs +71 -0
- package/dist/channels/named_barrier_value.d.ts +18 -0
- package/dist/channels/named_barrier_value.js +66 -0
- package/dist/channels/topic.cjs +5 -3
- package/dist/channels/topic.d.ts +3 -3
- package/dist/channels/topic.js +5 -3
- package/dist/checkpoint/base.cjs +30 -12
- package/dist/checkpoint/base.d.ts +39 -22
- package/dist/checkpoint/base.js +28 -11
- package/dist/checkpoint/id.cjs +40 -0
- package/dist/checkpoint/id.d.ts +2 -0
- package/dist/checkpoint/id.js +35 -0
- package/dist/checkpoint/index.cjs +2 -2
- package/dist/checkpoint/index.d.ts +2 -2
- package/dist/checkpoint/index.js +2 -2
- package/dist/checkpoint/memory.cjs +63 -49
- package/dist/checkpoint/memory.d.ts +7 -10
- package/dist/checkpoint/memory.js +62 -47
- package/dist/checkpoint/sqlite.cjs +170 -0
- package/dist/checkpoint/sqlite.d.ts +14 -0
- package/dist/checkpoint/sqlite.js +163 -0
- package/dist/constants.cjs +3 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/errors.cjs +31 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +24 -0
- package/dist/graph/graph.cjs +234 -96
- package/dist/graph/graph.d.ts +52 -23
- package/dist/graph/graph.js +233 -97
- package/dist/graph/index.cjs +2 -2
- package/dist/graph/index.d.ts +2 -2
- package/dist/graph/index.js +2 -2
- package/dist/graph/message.cjs +4 -3
- package/dist/graph/message.d.ts +4 -1
- package/dist/graph/message.js +4 -3
- package/dist/graph/state.cjs +237 -102
- package/dist/graph/state.d.ts +41 -18
- package/dist/graph/state.js +238 -104
- package/dist/index.cjs +6 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/prebuilt/agent_executor.cjs +22 -36
- package/dist/prebuilt/agent_executor.d.ts +7 -10
- package/dist/prebuilt/agent_executor.js +23 -37
- package/dist/prebuilt/chat_agent_executor.cjs +13 -13
- package/dist/prebuilt/chat_agent_executor.d.ts +3 -1
- package/dist/prebuilt/chat_agent_executor.js +15 -15
- package/dist/prebuilt/index.cjs +4 -1
- package/dist/prebuilt/index.d.ts +1 -0
- package/dist/prebuilt/index.js +1 -0
- package/dist/prebuilt/tool_node.cjs +59 -0
- package/dist/prebuilt/tool_node.d.ts +17 -0
- package/dist/prebuilt/tool_node.js +54 -0
- package/dist/pregel/debug.cjs +6 -8
- package/dist/pregel/debug.d.ts +2 -2
- package/dist/pregel/debug.js +5 -7
- package/dist/pregel/index.cjs +406 -236
- package/dist/pregel/index.d.ts +77 -41
- package/dist/pregel/index.js +408 -241
- package/dist/pregel/io.cjs +117 -30
- package/dist/pregel/io.d.ts +11 -3
- package/dist/pregel/io.js +111 -28
- package/dist/pregel/read.cjs +126 -46
- package/dist/pregel/read.d.ts +27 -18
- package/dist/pregel/read.js +125 -45
- package/dist/pregel/types.cjs +2 -0
- package/dist/pregel/types.d.ts +32 -0
- package/dist/pregel/types.js +1 -0
- package/dist/pregel/validate.cjs +58 -51
- package/dist/pregel/validate.d.ts +14 -13
- package/dist/pregel/validate.js +56 -50
- package/dist/pregel/write.cjs +46 -30
- package/dist/pregel/write.d.ts +18 -8
- package/dist/pregel/write.js +45 -29
- package/dist/serde/base.cjs +2 -0
- package/dist/serde/base.d.ts +4 -0
- package/dist/serde/base.js +1 -0
- package/dist/setup/async_local_storage.cjs +2 -2
- package/dist/setup/async_local_storage.js +1 -1
- package/dist/tests/channels.test.d.ts +1 -0
- package/dist/tests/channels.test.js +151 -0
- package/dist/tests/chatbot.int.test.d.ts +1 -0
- package/dist/tests/chatbot.int.test.js +61 -0
- package/dist/tests/checkpoints.test.d.ts +1 -0
- package/dist/tests/checkpoints.test.js +190 -0
- package/dist/tests/graph.test.d.ts +1 -0
- package/dist/tests/graph.test.js +15 -0
- package/dist/tests/prebuilt.int.test.d.ts +1 -0
- package/dist/tests/prebuilt.int.test.js +101 -0
- package/dist/tests/prebuilt.test.d.ts +1 -0
- package/dist/tests/prebuilt.test.js +195 -0
- package/dist/tests/pregel.io.test.d.ts +1 -0
- package/dist/tests/pregel.io.test.js +332 -0
- package/dist/tests/pregel.read.test.d.ts +1 -0
- package/dist/tests/pregel.read.test.js +109 -0
- package/dist/tests/pregel.test.d.ts +1 -0
- package/dist/tests/pregel.test.js +1879 -0
- package/dist/tests/pregel.validate.test.d.ts +1 -0
- package/dist/tests/pregel.validate.test.js +198 -0
- package/dist/tests/pregel.write.test.d.ts +1 -0
- package/dist/tests/pregel.write.test.js +44 -0
- package/dist/tests/tracing.int.test.d.ts +1 -0
- package/dist/tests/tracing.int.test.js +449 -0
- package/dist/tests/utils.d.ts +22 -0
- package/dist/tests/utils.js +76 -0
- package/dist/utils.cjs +74 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +70 -0
- package/package.json +12 -8
- package/dist/pregel/reserved.cjs +0 -6
- package/dist/pregel/reserved.d.ts +0 -3
- package/dist/pregel/reserved.js +0 -3
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { describe, expect, it } from "@jest/globals";
|
|
2
|
+
import { RunnablePassthrough } from "@langchain/core/runnables";
|
|
3
|
+
import { mapInput, mapOutputUpdates, mapOutputValues, readChannel, readChannels, single, } from "../pregel/io.js";
|
|
4
|
+
import { LastValue } from "../channels/last_value.js";
|
|
5
|
+
import { EmptyChannelError } from "../errors.js";
|
|
6
|
+
describe("single", () => {
|
|
7
|
+
it("returns first value of iterator and closes it", () => {
|
|
8
|
+
let closed = false;
|
|
9
|
+
function* myiter() {
|
|
10
|
+
try {
|
|
11
|
+
yield 1;
|
|
12
|
+
yield 2;
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
closed = true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
expect(single(myiter())).toBe(1);
|
|
19
|
+
expect(closed).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe("readChannel", () => {
|
|
23
|
+
it("should read a channel successfully", () => {
|
|
24
|
+
// set up test
|
|
25
|
+
const channel = new LastValue();
|
|
26
|
+
channel.update([3]);
|
|
27
|
+
const channels = {
|
|
28
|
+
someChannelName: channel,
|
|
29
|
+
};
|
|
30
|
+
// call method / assertions
|
|
31
|
+
const newChannel = readChannel(channels, "someChannelName");
|
|
32
|
+
expect(newChannel).toBe(3);
|
|
33
|
+
});
|
|
34
|
+
it("should return EmptyChannelError when the channel is empty", () => {
|
|
35
|
+
// set up test
|
|
36
|
+
const channels = {
|
|
37
|
+
someChannelName: new LastValue(),
|
|
38
|
+
};
|
|
39
|
+
// call method / assertions
|
|
40
|
+
const error = readChannel(channels, "someChannelName", true, true);
|
|
41
|
+
expect(error).toBeInstanceOf(EmptyChannelError);
|
|
42
|
+
});
|
|
43
|
+
it("should return null when the channel is empty", () => {
|
|
44
|
+
// set up test
|
|
45
|
+
const channels = {
|
|
46
|
+
someChannelName: new LastValue(),
|
|
47
|
+
};
|
|
48
|
+
// call method / assertions
|
|
49
|
+
const error = readChannel(channels, "someChannelName", true, false);
|
|
50
|
+
expect(error).toBeNull();
|
|
51
|
+
});
|
|
52
|
+
it("should throw an error when the channel is empty", () => {
|
|
53
|
+
// set up test
|
|
54
|
+
const channels = {
|
|
55
|
+
someChannelName: new LastValue(),
|
|
56
|
+
};
|
|
57
|
+
// call method / assertions
|
|
58
|
+
expect(() => {
|
|
59
|
+
readChannel(channels, "someChannelName", false, false);
|
|
60
|
+
}).toThrow(EmptyChannelError);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe("readChannels", () => {
|
|
64
|
+
it("should return a single channel value", () => {
|
|
65
|
+
// set up test
|
|
66
|
+
const channel = new LastValue();
|
|
67
|
+
channel.update([3]);
|
|
68
|
+
const channels = {
|
|
69
|
+
someChannelName: channel,
|
|
70
|
+
};
|
|
71
|
+
// call method / assertions
|
|
72
|
+
const newChannel = readChannels(channels, "someChannelName");
|
|
73
|
+
expect(newChannel).toBe(3);
|
|
74
|
+
});
|
|
75
|
+
it("should return multiple channel values", () => {
|
|
76
|
+
// set up test
|
|
77
|
+
const channel1 = new LastValue();
|
|
78
|
+
const channel2 = new LastValue();
|
|
79
|
+
const emptyChannel = new LastValue();
|
|
80
|
+
channel1.update([3]);
|
|
81
|
+
channel2.update([4]);
|
|
82
|
+
const channels = {
|
|
83
|
+
someChannelName1: channel1,
|
|
84
|
+
someChannelName2: channel2,
|
|
85
|
+
someChannelName3: emptyChannel,
|
|
86
|
+
};
|
|
87
|
+
// call method / assertions
|
|
88
|
+
const channelValues = readChannels(channels, [
|
|
89
|
+
"someChannelName1",
|
|
90
|
+
"someChannelName2",
|
|
91
|
+
"someChannelName3",
|
|
92
|
+
]);
|
|
93
|
+
expect(channelValues).toEqual({ someChannelName1: 3, someChannelName2: 4 });
|
|
94
|
+
});
|
|
95
|
+
it("should return multiple channel values including null for empty channels", () => {
|
|
96
|
+
// set up test
|
|
97
|
+
const channel1 = new LastValue();
|
|
98
|
+
const channel2 = new LastValue();
|
|
99
|
+
const emptyChannel = new LastValue();
|
|
100
|
+
channel1.update([3]);
|
|
101
|
+
channel2.update([4]);
|
|
102
|
+
const channels = {
|
|
103
|
+
someChannelName1: channel1,
|
|
104
|
+
someChannelName2: channel2,
|
|
105
|
+
someChannelName3: emptyChannel,
|
|
106
|
+
};
|
|
107
|
+
// call method / assertions
|
|
108
|
+
const channelValues = readChannels(channels, ["someChannelName1", "someChannelName2", "someChannelName3"], false);
|
|
109
|
+
expect(channelValues).toEqual({
|
|
110
|
+
someChannelName1: 3,
|
|
111
|
+
someChannelName2: 4,
|
|
112
|
+
someChannelName3: null,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe("mapInput", () => {
|
|
117
|
+
it("should return an empty Generator", () => {
|
|
118
|
+
// call method / assertions
|
|
119
|
+
const emptyGenerator = mapInput("someChannelName");
|
|
120
|
+
const tuples = [];
|
|
121
|
+
for (const tuple of emptyGenerator) {
|
|
122
|
+
tuples.push(tuple);
|
|
123
|
+
}
|
|
124
|
+
expect(tuples.length).toBe(0);
|
|
125
|
+
});
|
|
126
|
+
it("should return a Generator that yields a single tuple", () => {
|
|
127
|
+
// call method / assertions
|
|
128
|
+
const emptyGenerator = mapInput("someChannelName", "some chunk");
|
|
129
|
+
const tuples = [];
|
|
130
|
+
for (const tuple of emptyGenerator) {
|
|
131
|
+
tuples.push(tuple);
|
|
132
|
+
}
|
|
133
|
+
expect(tuples.length).toBe(1);
|
|
134
|
+
expect(tuples[0]).toEqual(["someChannelName", "some chunk"]);
|
|
135
|
+
});
|
|
136
|
+
it("should return a Generator that yields multiple tuples", () => {
|
|
137
|
+
// set up test
|
|
138
|
+
const channelNames = ["someChannelName1", "someChannelName2"];
|
|
139
|
+
const chunk = {
|
|
140
|
+
someChannelName1: "some chunk 1",
|
|
141
|
+
};
|
|
142
|
+
// call method / assertions
|
|
143
|
+
const emptyGenerator = mapInput(channelNames, chunk);
|
|
144
|
+
const tuples = [];
|
|
145
|
+
for (const tuple of emptyGenerator) {
|
|
146
|
+
tuples.push(tuple);
|
|
147
|
+
}
|
|
148
|
+
expect(tuples.length).toBe(1);
|
|
149
|
+
expect(tuples[0]).toEqual(["someChannelName1", "some chunk 1"]);
|
|
150
|
+
});
|
|
151
|
+
it("should throw an error if an invalid chunk type is provided", async () => {
|
|
152
|
+
// set up test
|
|
153
|
+
const channelNames = ["someChannelName1", "someChannelName2"];
|
|
154
|
+
const chunk = ["array", "of", "chunks"];
|
|
155
|
+
// call method / assertions
|
|
156
|
+
await expect(() => {
|
|
157
|
+
const generator = mapInput(channelNames, chunk);
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
159
|
+
for (const _ of generator) {
|
|
160
|
+
// do nothing, error will be thrown
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
}).toThrow("Input chunk must be an object when inputChannels is an array");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
describe("mapOutputValues", () => {
|
|
167
|
+
it("should return a Generator that yields a single value", () => {
|
|
168
|
+
// set up test
|
|
169
|
+
const outputChannels = "someOutputChannelName2";
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
171
|
+
const pendingWrites = [
|
|
172
|
+
["someOutputChannelName1", 1],
|
|
173
|
+
["someOutputChannelName2", 2],
|
|
174
|
+
];
|
|
175
|
+
const lastValueChannel2 = new LastValue();
|
|
176
|
+
lastValueChannel2.update([3]);
|
|
177
|
+
const channels = {
|
|
178
|
+
someOutputChannelName1: new LastValue(),
|
|
179
|
+
someOutputChannelName2: lastValueChannel2,
|
|
180
|
+
};
|
|
181
|
+
// call method / assertions
|
|
182
|
+
const generator = mapOutputValues(outputChannels, pendingWrites, channels);
|
|
183
|
+
const values = [];
|
|
184
|
+
for (const value of generator) {
|
|
185
|
+
values.push(value);
|
|
186
|
+
}
|
|
187
|
+
expect(values.length).toBe(1);
|
|
188
|
+
// value should be equal to the last value of channel
|
|
189
|
+
expect(values[0]).toBe(3);
|
|
190
|
+
});
|
|
191
|
+
it("should return a Generator that yields an object", () => {
|
|
192
|
+
// set up test
|
|
193
|
+
const outputChannels = ["someOutputChannelName1", "someOutputChannelName2"];
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
195
|
+
const pendingWrites = [
|
|
196
|
+
["someOutputChannelName1", 1],
|
|
197
|
+
["someOutputChannelName2", 2],
|
|
198
|
+
];
|
|
199
|
+
const lastValueChannel1 = new LastValue();
|
|
200
|
+
const lastValueChannel2 = new LastValue();
|
|
201
|
+
lastValueChannel1.update([3]);
|
|
202
|
+
lastValueChannel2.update([4]);
|
|
203
|
+
const channels = {
|
|
204
|
+
someOutputChannelName1: lastValueChannel1,
|
|
205
|
+
someOutputChannelName2: lastValueChannel2,
|
|
206
|
+
};
|
|
207
|
+
// call method / assertions
|
|
208
|
+
const generator = mapOutputValues(outputChannels, pendingWrites, channels);
|
|
209
|
+
const values = [];
|
|
210
|
+
for (const value of generator) {
|
|
211
|
+
values.push(value);
|
|
212
|
+
}
|
|
213
|
+
expect(values.length).toBe(1);
|
|
214
|
+
expect(values[0]).toEqual({
|
|
215
|
+
someOutputChannelName1: 3,
|
|
216
|
+
someOutputChannelName2: 4,
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
it("should return an empty Generator", () => {
|
|
220
|
+
// set up test
|
|
221
|
+
const outputChannels = "someOutputChannelName1";
|
|
222
|
+
const outputChannelsList = ["someOutputChannelName1"];
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
|
+
const pendingWrites = [
|
|
225
|
+
["someOutputChannelName2", 2],
|
|
226
|
+
["someOutputChannelName2", 3],
|
|
227
|
+
];
|
|
228
|
+
const channels = {
|
|
229
|
+
someOutputChannelName1: new LastValue(),
|
|
230
|
+
someOutputChannelName2: new LastValue(),
|
|
231
|
+
};
|
|
232
|
+
// call method / assertions
|
|
233
|
+
const generator1 = mapOutputValues(outputChannels, pendingWrites, channels);
|
|
234
|
+
const values = [];
|
|
235
|
+
for (const value of generator1) {
|
|
236
|
+
values.push(value);
|
|
237
|
+
}
|
|
238
|
+
expect(values.length).toBe(0);
|
|
239
|
+
const generator2 = mapOutputValues(outputChannelsList, pendingWrites, channels);
|
|
240
|
+
for (const value of generator2) {
|
|
241
|
+
values.push(value);
|
|
242
|
+
}
|
|
243
|
+
expect(values.length).toBe(0);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
describe("mapOutputUpdates", () => {
|
|
247
|
+
it("should return a Generator that yields an object - {string: any}", () => {
|
|
248
|
+
// set up test
|
|
249
|
+
const outputChannels = "someOutputChannelName";
|
|
250
|
+
const tasks = [
|
|
251
|
+
{
|
|
252
|
+
name: "task1",
|
|
253
|
+
input: null,
|
|
254
|
+
proc: new RunnablePassthrough(),
|
|
255
|
+
writes: [["someOutputChannelName", 1]],
|
|
256
|
+
config: undefined,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: "task2",
|
|
260
|
+
input: null,
|
|
261
|
+
proc: new RunnablePassthrough(),
|
|
262
|
+
writes: [["someOutputChannelName", 2]],
|
|
263
|
+
config: {
|
|
264
|
+
tags: ["langsmith:hidden"], // this task should be filtered out
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
name: "task3",
|
|
269
|
+
input: null,
|
|
270
|
+
proc: new RunnablePassthrough(),
|
|
271
|
+
// @ts-expect-error invalid write
|
|
272
|
+
writes: [["someOutputChannelNameThatDoesntMatch", 3]], // this task should be filtered out
|
|
273
|
+
config: undefined,
|
|
274
|
+
},
|
|
275
|
+
];
|
|
276
|
+
// call method / assertions
|
|
277
|
+
const generator = mapOutputUpdates(outputChannels, tasks);
|
|
278
|
+
const values = [];
|
|
279
|
+
for (const value of generator) {
|
|
280
|
+
values.push(value);
|
|
281
|
+
}
|
|
282
|
+
expect(values.length).toBe(1);
|
|
283
|
+
expect(values[0]).toEqual({ task1: 1 });
|
|
284
|
+
});
|
|
285
|
+
it("should return a Generator that yields an object - {string: {string: any}}", () => {
|
|
286
|
+
// set up test
|
|
287
|
+
const outputChannels = [
|
|
288
|
+
"someOutputChannelName1",
|
|
289
|
+
"someOutputChannelName2",
|
|
290
|
+
"someOutputChannelName3",
|
|
291
|
+
];
|
|
292
|
+
const tasks = [
|
|
293
|
+
{
|
|
294
|
+
name: "task1",
|
|
295
|
+
input: null,
|
|
296
|
+
proc: new RunnablePassthrough(),
|
|
297
|
+
writes: [
|
|
298
|
+
["someOutputChannelName1", 1],
|
|
299
|
+
["someOutputChannelName2", 2],
|
|
300
|
+
],
|
|
301
|
+
config: undefined,
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
name: "task2",
|
|
305
|
+
input: null,
|
|
306
|
+
proc: new RunnablePassthrough(),
|
|
307
|
+
writes: [
|
|
308
|
+
["someOutputChannelName3", 3],
|
|
309
|
+
["someOutputChannelName4", 4],
|
|
310
|
+
],
|
|
311
|
+
config: undefined,
|
|
312
|
+
},
|
|
313
|
+
];
|
|
314
|
+
// call method / assertions
|
|
315
|
+
const generator = mapOutputUpdates(outputChannels, tasks);
|
|
316
|
+
const values = [];
|
|
317
|
+
for (const value of generator) {
|
|
318
|
+
values.push(value);
|
|
319
|
+
}
|
|
320
|
+
expect(values.length).toBe(1);
|
|
321
|
+
const expectedValue = {
|
|
322
|
+
task1: {
|
|
323
|
+
someOutputChannelName1: 1,
|
|
324
|
+
someOutputChannelName2: 2,
|
|
325
|
+
},
|
|
326
|
+
task2: {
|
|
327
|
+
someOutputChannelName3: 3,
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
expect(values[0]).toEqual(expectedValue);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe, expect, it } from "@jest/globals";
|
|
2
|
+
import { RunnablePassthrough, } from "@langchain/core/runnables";
|
|
3
|
+
import { PregelNode } from "../pregel/read.js";
|
|
4
|
+
import { ChannelWrite } from "../pregel/write.js";
|
|
5
|
+
describe("PregelNode", () => {
|
|
6
|
+
describe("getWriters", () => {
|
|
7
|
+
it("should return the expected array of writers", () => {
|
|
8
|
+
// set up test
|
|
9
|
+
const pregelNode = new PregelNode({
|
|
10
|
+
channels: ["foo"],
|
|
11
|
+
triggers: ["bar"],
|
|
12
|
+
writers: [
|
|
13
|
+
new ChannelWrite([
|
|
14
|
+
{ channel: "channel1", value: 1, skipNone: false },
|
|
15
|
+
{ channel: "channel2", value: 2, skipNone: false },
|
|
16
|
+
]),
|
|
17
|
+
new ChannelWrite([
|
|
18
|
+
{ channel: "channel3", value: 3, skipNone: false },
|
|
19
|
+
{ channel: "channel4", value: 4, skipNone: false },
|
|
20
|
+
]),
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
// call method / assertions
|
|
24
|
+
const newWriters = pregelNode.getWriters();
|
|
25
|
+
expect(newWriters.length).toBe(1);
|
|
26
|
+
expect(newWriters[0].writes.length).toBe(4);
|
|
27
|
+
// TODO: need to assert individual writes
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe("getNode", () => {
|
|
31
|
+
it("should return undefined if bound is default andthere are no writers", () => {
|
|
32
|
+
// set up test
|
|
33
|
+
const pregelNode = new PregelNode({
|
|
34
|
+
channels: ["foo"],
|
|
35
|
+
triggers: ["bar"],
|
|
36
|
+
writers: [],
|
|
37
|
+
// bound is set to default
|
|
38
|
+
});
|
|
39
|
+
// call method / assertions
|
|
40
|
+
expect(pregelNode.getNode()).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
it("should return the only writer if there is only one writer", () => {
|
|
43
|
+
const channelWrite = new ChannelWrite([
|
|
44
|
+
{ channel: "channel1", value: 1, skipNone: false },
|
|
45
|
+
]);
|
|
46
|
+
const pregelNode = new PregelNode({
|
|
47
|
+
channels: ["foo"],
|
|
48
|
+
triggers: ["bar"],
|
|
49
|
+
writers: [channelWrite],
|
|
50
|
+
// bound is set to default
|
|
51
|
+
});
|
|
52
|
+
// call method / assertions
|
|
53
|
+
expect(pregelNode.getNode()).toEqual(channelWrite);
|
|
54
|
+
});
|
|
55
|
+
it("should return a RunnableSequence of writers if there are multiple writers", () => {
|
|
56
|
+
const channelWrite1 = new ChannelWrite([
|
|
57
|
+
{ channel: "channel1", value: 1, skipNone: false },
|
|
58
|
+
]);
|
|
59
|
+
const channelWrite2 = new ChannelWrite([
|
|
60
|
+
{ channel: "channel2", value: 2, skipNone: false },
|
|
61
|
+
]);
|
|
62
|
+
const pregelNode = new PregelNode({
|
|
63
|
+
channels: ["foo"],
|
|
64
|
+
triggers: ["bar"],
|
|
65
|
+
writers: [channelWrite1, channelWrite2, new RunnablePassthrough()],
|
|
66
|
+
// bound is set to default
|
|
67
|
+
});
|
|
68
|
+
// call method / assertions
|
|
69
|
+
const runnableSequence = pregelNode.getNode();
|
|
70
|
+
expect(runnableSequence.steps).toEqual([
|
|
71
|
+
channelWrite1,
|
|
72
|
+
channelWrite2,
|
|
73
|
+
new RunnablePassthrough(),
|
|
74
|
+
]);
|
|
75
|
+
});
|
|
76
|
+
it("should return a RunnableSequence of writers if there are multiple writers (custom bound)", () => {
|
|
77
|
+
const channelWrite1 = new ChannelWrite([
|
|
78
|
+
{ channel: "channel1", value: 1, skipNone: false },
|
|
79
|
+
]);
|
|
80
|
+
const channelWrite2 = new ChannelWrite([
|
|
81
|
+
{ channel: "channel2", value: 2, skipNone: false },
|
|
82
|
+
]);
|
|
83
|
+
const pregelNode = new PregelNode({
|
|
84
|
+
channels: ["foo"],
|
|
85
|
+
triggers: ["bar"],
|
|
86
|
+
writers: [channelWrite1, channelWrite2, new RunnablePassthrough()],
|
|
87
|
+
bound: new RunnablePassthrough(),
|
|
88
|
+
});
|
|
89
|
+
// call method / assertions
|
|
90
|
+
const runnableSequence = pregelNode.getNode();
|
|
91
|
+
expect(runnableSequence.steps).toEqual([
|
|
92
|
+
new RunnablePassthrough(),
|
|
93
|
+
channelWrite1,
|
|
94
|
+
channelWrite2,
|
|
95
|
+
new RunnablePassthrough(),
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
it("should return the custom bound", () => {
|
|
99
|
+
const pregelNode = new PregelNode({
|
|
100
|
+
channels: ["foo"],
|
|
101
|
+
triggers: ["bar"],
|
|
102
|
+
writers: [],
|
|
103
|
+
bound: new RunnablePassthrough(),
|
|
104
|
+
});
|
|
105
|
+
// call method / assertions
|
|
106
|
+
expect(pregelNode.getNode()).toEqual(new RunnablePassthrough());
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|