@forgehive/record-tape 0.2.0 → 0.2.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.
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("../index");
4
+ describe('RecordTape Data Methods', () => {
5
+ let tape;
6
+ beforeEach(() => {
7
+ tape = new index_1.RecordTape();
8
+ });
9
+ describe('getLength', () => {
10
+ test('should return 0 for empty tape', () => {
11
+ expect(tape.getLength()).toBe(0);
12
+ });
13
+ test('should return correct length after adding records', () => {
14
+ const record1 = {
15
+ input: { userId: 1 },
16
+ output: { name: 'John' },
17
+ taskName: 'getUser',
18
+ boundaries: {},
19
+ type: 'success'
20
+ };
21
+ const record2 = {
22
+ input: { userId: 2 },
23
+ output: { name: 'Jane' },
24
+ taskName: 'getUser',
25
+ boundaries: {},
26
+ type: 'success'
27
+ };
28
+ tape.push(record1);
29
+ expect(tape.getLength()).toBe(1);
30
+ tape.push(record2);
31
+ expect(tape.getLength()).toBe(2);
32
+ });
33
+ test('should return correct length after removing records', () => {
34
+ const record = {
35
+ input: { userId: 1 },
36
+ output: { name: 'John' },
37
+ taskName: 'getUser',
38
+ boundaries: {},
39
+ type: 'success'
40
+ };
41
+ tape.push(record);
42
+ tape.push(record);
43
+ expect(tape.getLength()).toBe(2);
44
+ tape.shift();
45
+ expect(tape.getLength()).toBe(1);
46
+ tape.shift();
47
+ expect(tape.getLength()).toBe(0);
48
+ });
49
+ });
50
+ describe('shift', () => {
51
+ test('should return undefined for empty tape', () => {
52
+ expect(tape.shift()).toBeUndefined();
53
+ });
54
+ test('should return and remove first record', () => {
55
+ const record1 = {
56
+ input: { userId: 1 },
57
+ output: { name: 'John' },
58
+ taskName: 'getUser',
59
+ boundaries: {},
60
+ type: 'success'
61
+ };
62
+ const record2 = {
63
+ input: { userId: 2 },
64
+ output: { name: 'Jane' },
65
+ taskName: 'getUser',
66
+ boundaries: {},
67
+ type: 'success'
68
+ };
69
+ tape.push(record1);
70
+ tape.push(record2);
71
+ const shiftedRecord = tape.shift();
72
+ // Should return the first record
73
+ expect(shiftedRecord).toEqual(expect.objectContaining({
74
+ taskName: 'getUser',
75
+ input: { userId: 1 },
76
+ output: { name: 'John' },
77
+ type: 'success'
78
+ }));
79
+ // Should have removed the first record
80
+ expect(tape.getLength()).toBe(1);
81
+ expect(tape.getLog()[0]).toEqual(expect.objectContaining({
82
+ taskName: 'getUser',
83
+ input: { userId: 2 },
84
+ output: { name: 'Jane' },
85
+ type: 'success'
86
+ }));
87
+ });
88
+ test('should work correctly with multiple shifts', () => {
89
+ const records = [
90
+ {
91
+ input: { userId: 1 },
92
+ output: { name: 'John' },
93
+ taskName: 'getUser',
94
+ boundaries: {},
95
+ type: 'success'
96
+ },
97
+ {
98
+ input: { userId: 2 },
99
+ output: { name: 'Jane' },
100
+ taskName: 'getUser',
101
+ boundaries: {},
102
+ type: 'success'
103
+ },
104
+ {
105
+ input: { userId: 3 },
106
+ output: { name: 'Bob' },
107
+ taskName: 'getUser',
108
+ boundaries: {},
109
+ type: 'success'
110
+ }
111
+ ];
112
+ records.forEach(record => tape.push(record));
113
+ expect(tape.getLength()).toBe(3);
114
+ const first = tape.shift();
115
+ expect(first === null || first === void 0 ? void 0 : first.input).toEqual({ userId: 1 });
116
+ expect(tape.getLength()).toBe(2);
117
+ const second = tape.shift();
118
+ expect(second === null || second === void 0 ? void 0 : second.input).toEqual({ userId: 2 });
119
+ expect(tape.getLength()).toBe(1);
120
+ const third = tape.shift();
121
+ expect(third === null || third === void 0 ? void 0 : third.input).toEqual({ userId: 3 });
122
+ expect(tape.getLength()).toBe(0);
123
+ const fourth = tape.shift();
124
+ expect(fourth).toBeUndefined();
125
+ expect(tape.getLength()).toBe(0);
126
+ });
127
+ });
128
+ });
129
+ //# sourceMappingURL=data-methods.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-methods.test.js","sourceRoot":"","sources":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AM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAEhC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,CAAA;YAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAA;YAC9B,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -74,8 +74,8 @@ describe('Base tests', () => {
74
74
  });
75
75
  it('Should create a new tape with generic types', () => {
76
76
  const tape = new index_1.RecordTape({ path: emptyPath });
77
- tape.addLogRecord({ name: 'test', input: [{ name: 'test' }], output: { age: 1 }, type: 'success', boundaries: {} });
78
- tape.addLogRecord({ name: 'test', input: [{ name: 'test' }], error: 'test', type: 'error', boundaries: {} });
77
+ tape.push({ input: [{ name: 'test' }], output: { age: 1 }, type: 'success', boundaries: {}, taskName: 'test' });
78
+ tape.push({ input: [{ name: 'test' }], error: 'test', type: 'error', boundaries: {}, taskName: 'test' });
79
79
  const data = tape.getLog();
80
80
  expect(data.length).toBe(2);
81
81
  const input = data[0].input;
@@ -1 +1 @@
1
- {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/tests/index.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAC5B,oCAAqC;AAErC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAA;AAE3D,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,IAAI,GAAG,IAAI,kBAAU,CAAC,EAAE,IAAI,EA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AAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;QAClC,MAAM,CAAC,KAAK,CAAC,CAAC,aAAa,EAAE,CAAA;QAC7B,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAE5B,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;QAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QAE5B,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC,CAAC,CAAA;QACxC,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,CAAA;QAC/B,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC9B,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -4,23 +4,23 @@ const index_1 = require("../index");
4
4
  describe('Test log item formating', () => {
5
5
  it('Should format a log items into valid JSON', async () => {
6
6
  const tape = new index_1.RecordTape({});
7
- tape.addLogRecord({ name: 'name', input: true, output: true, boundaries: {}, type: 'success' });
8
- tape.addLogRecord({ name: 'name', input: true, error: 'invalid data', boundaries: {}, type: 'error' });
7
+ tape.push({ input: true, output: true, boundaries: {}, type: 'success', taskName: 'name' });
8
+ tape.push({ input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name' });
9
9
  const str = tape.stringify();
10
- expect(str).toEqual(`{"name":"name","input":true,"output":true,"boundaries":{},"type":"success"}
11
- {"name":"name","input":true,"error":"invalid data","boundaries":{},"type":"error"}
10
+ expect(str).toEqual(`{"input":true,"output":true,"boundaries":{},"type":"success","taskName":"name","metadata":{}}
11
+ {"input":true,"error":"invalid data","boundaries":{},"type":"error","taskName":"name","metadata":{}}
12
12
  `);
13
13
  });
14
14
  it('Should parse the string to a list of records', async () => {
15
15
  const tape = new index_1.RecordTape({});
16
- tape.addLogRecord({ name: 'name', input: true, output: true, boundaries: {}, type: 'success' });
17
- tape.addLogRecord({ name: 'name', input: true, error: 'invalid data', boundaries: {}, type: 'error' });
16
+ tape.push({ input: true, output: true, boundaries: {}, type: 'success', taskName: 'name' });
17
+ tape.push({ input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name' });
18
18
  const str = tape.stringify();
19
19
  const tape2 = new index_1.RecordTape({});
20
20
  const records = tape2.parse(str);
21
21
  expect(records).toEqual([
22
- { name: 'name', input: true, output: true, boundaries: {}, type: 'success' },
23
- { name: 'name', input: true, error: 'invalid data', boundaries: {}, type: 'error' }
22
+ { input: true, output: true, boundaries: {}, type: 'success', taskName: 'name', metadata: {} },
23
+ { input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name', metadata: {} }
24
24
  ]);
25
25
  });
26
26
  });
@@ -1 +1 @@
1
- {"version":3,"file":"log-format.test.js","sourceRoot":"","sources":["../../src/tests/log-format.test.ts"],"names":[],"mappings":";;AAAA,oCAAqC;AAErC,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QAIzD,MAAM,IAAI,GAAG,IAAI,kBAAU,CAAwB,EAAE,CAAC,CAAA;QACtD,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QAC/F,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,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,CAAC,CAAA;QAElG,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;QAC5B,MAAM,KAAK,GAAG,IAAI,kBAAU,CAAwB,EAAE,CAAC,CAAA;QACvD,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAEhC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;YACtB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;YAC9F,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;SACtG,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,310 +1,149 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_1 = require("../index");
4
3
  const task_1 = require("@forgehive/task");
5
- describe('RecordTape safeRun integration tests', () => {
6
- it('should record log items directly from safeRun result', async () => {
7
- // Create a schema
8
- const schema = new task_1.Schema({
9
- value: task_1.Schema.number()
10
- });
11
- // Define the boundaries
12
- const boundaries = {
13
- fetchData: async (value) => {
14
- return value * 2;
15
- }
16
- };
17
- // Create the task
18
- const task = (0, task_1.createTask)({
19
- schema,
20
- boundaries,
21
- fn: async function ({ value }, { fetchData }) {
22
- const result = await fetchData(value);
23
- return { result, success: true };
24
- }
25
- });
26
- // Create a record tape
27
- const tape = new index_1.RecordTape();
28
- // Run the task with safeRun and directly use the logItem
29
- const [result, error, record] = await task.safeRun({ value: 5 });
30
- tape.push('test-task', record);
31
- // Verify the execution was successful
32
- expect(error).toBeNull();
33
- expect(result).toEqual({ result: 10, success: true });
34
- // Get the recorded log from the tape
35
- const recordedLog = tape.getLog();
36
- // Verify the log was recorded correctly
37
- expect(recordedLog).toHaveLength(1);
38
- const logItem = recordedLog[0];
39
- expect(logItem.name).toEqual('test-task');
40
- expect(logItem.type).toEqual('success');
41
- expect(logItem.input).toEqual({ value: 5 });
42
- expect(logItem.output).toEqual({ result: 10, success: true });
43
- expect(logItem.boundaries).toEqual({
44
- fetchData: [{
45
- input: [5],
46
- output: 10,
47
- error: null
48
- }]
49
- });
50
- });
51
- it('should record log items from safeRun successfully', async () => {
52
- // Create a schema
53
- const schema = new task_1.Schema({
54
- value: task_1.Schema.number()
55
- });
56
- // Define the boundaries
57
- const boundaries = {
58
- fetchData: async (value) => {
59
- return value * 2;
60
- }
61
- };
62
- // Create the task
4
+ const index_1 = require("../index");
5
+ describe('Safe run', () => {
6
+ it('Should run a simple task with no boundaries and register to a tape', async () => {
7
+ const tape = new index_1.RecordTape({});
63
8
  const task = (0, task_1.createTask)({
64
- schema,
65
- boundaries,
66
- fn: async function ({ value }, { fetchData }) {
67
- const result = await fetchData(value);
68
- return { result, success: true };
9
+ name: 'simple-task',
10
+ schema: new task_1.Schema({
11
+ value: task_1.Schema.number()
12
+ }),
13
+ boundaries: {},
14
+ fn: async ({ value }) => {
15
+ return { doubled: value * 2 };
69
16
  }
70
17
  });
71
- // Create a record tape
72
- const tape = new index_1.RecordTape();
73
- // Add listener to record the log items
74
18
  task.addListener((record) => {
75
- // Manually ensure boundary records have error field for consistency with safeRun
76
- if (record.boundaries && record.boundaries.fetchData && Array.isArray(record.boundaries.fetchData)) {
77
- record.boundaries.fetchData = record.boundaries.fetchData.map((entry) => {
78
- var _a, _b;
79
- return (Object.assign(Object.assign({}, entry), { error: (_a = entry.error) !== null && _a !== void 0 ? _a : null, output: (_b = entry.output) !== null && _b !== void 0 ? _b : null }));
80
- });
81
- }
82
- // Add the record using push method
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- tape.push('test-task', record);
19
+ tape.push(record);
85
20
  });
86
- // Run the task with safeRun
21
+ // Test simple execution
87
22
  const [result, error] = await task.safeRun({ value: 5 });
88
- // Verify the execution was successful
89
23
  expect(error).toBeNull();
90
- expect(result).toEqual({ result: 10, success: true });
91
- // Get the recorded log from the tape
92
- const recordedLog = tape.getLog();
93
- // Verify the log was recorded correctly
94
- expect(recordedLog).toHaveLength(1);
95
- expect(recordedLog[0]).toEqual({
96
- name: 'test-task',
24
+ expect(result).toEqual({ doubled: 10 });
25
+ const log = tape.getLog();
26
+ expect(log).toHaveLength(1);
27
+ expect(log[0]).toEqual({
97
28
  type: 'success',
98
29
  input: { value: 5 },
99
- output: { result: 10, success: true },
100
- boundaries: {
101
- fetchData: [{
102
- input: [5],
103
- output: 10,
104
- error: null
105
- }]
106
- },
30
+ output: { doubled: 10 },
31
+ boundaries: {},
107
32
  metadata: {},
108
- taskName: undefined
33
+ taskName: 'simple-task'
109
34
  });
110
35
  });
111
- it('should record error log items from safeRun', async () => {
112
- // Create a schema
113
- const schema = new task_1.Schema({
114
- value: task_1.Schema.number()
115
- });
116
- // Define the boundaries with a function that will throw an error
117
- const boundaries = {
118
- fetchData: async (value) => {
119
- if (value < 0) {
120
- throw new Error('Value cannot be negative');
121
- }
122
- return value * 2;
123
- }
124
- };
125
- // Create the task
36
+ it('Should run a task with boundaries and register to a tape', async () => {
37
+ const tape = new index_1.RecordTape({});
126
38
  const task = (0, task_1.createTask)({
127
- schema,
128
- boundaries,
129
- fn: async function ({ value }, { fetchData }) {
130
- const result = await fetchData(value);
131
- return { result, success: true };
39
+ name: 'test',
40
+ schema: new task_1.Schema({
41
+ value: task_1.Schema.number().min(10).max(20)
42
+ }),
43
+ boundaries: {
44
+ multiply: async (value) => {
45
+ return value * 2;
46
+ }
47
+ },
48
+ fn: async ({ value }, { multiply }) => {
49
+ const result = await multiply(value);
50
+ return { result, success: result > 10 };
132
51
  }
133
52
  });
134
- // Create a record tape
135
- const tape = new index_1.RecordTape();
136
- // Add listener to record the log items
137
53
  task.addListener((record) => {
138
- // Manually ensure boundary records have error field for consistency with safeRun
139
- if (record.boundaries && record.boundaries.fetchData && Array.isArray(record.boundaries.fetchData)) {
140
- record.boundaries.fetchData = record.boundaries.fetchData.map((entry) => {
141
- var _a, _b;
142
- return (Object.assign(Object.assign({}, entry), { error: (_a = entry.error) !== null && _a !== void 0 ? _a : null, output: (_b = entry.output) !== null && _b !== void 0 ? _b : null }));
143
- });
144
- }
145
- // Add the record using push method
146
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
- tape.push('test-task', record);
54
+ tape.push(record);
148
55
  });
149
- // Run the task with safeRun with a value that will cause an error
150
- const [result, error] = await task.safeRun({ value: -5 });
151
- // Verify the execution failed as expected
152
- expect(result).toBeNull();
153
- expect(error).not.toBeNull();
154
- expect(error === null || error === void 0 ? void 0 : error.message).toContain('Value cannot be negative');
155
- // Get the recorded log from the tape
156
- const recordedLog = tape.getLog();
157
- // Verify the error log was recorded correctly
158
- expect(recordedLog).toHaveLength(1);
159
- expect(recordedLog[0]).toEqual({
160
- name: 'test-task',
56
+ // Test invalid input
57
+ let [result, error] = await task.safeRun({ value: 5 });
58
+ expect(error).toBeDefined();
59
+ expect(error === null || error === void 0 ? void 0 : error.message).toContain('Invalid input');
60
+ [result, error] = await task.safeRun({ value: 15 });
61
+ expect(error).toBeNull();
62
+ expect(result).toEqual({ result: 30, success: true });
63
+ const log = tape.getLog();
64
+ expect(log).toHaveLength(2);
65
+ expect(log[0]).toEqual({
161
66
  type: 'error',
162
- input: { value: -5 },
163
- error: 'Value cannot be negative',
67
+ input: { value: 5 },
68
+ error: 'Invalid input on: value: Number must be greater than or equal to 10',
164
69
  boundaries: {
165
- fetchData: [{
166
- input: [-5],
167
- error: 'Value cannot be negative',
168
- output: null
169
- }]
70
+ multiply: []
170
71
  },
171
72
  metadata: {},
172
- output: undefined,
173
- taskName: undefined
174
- });
175
- });
176
- it('should handle error records directly with push', async () => {
177
- // Create a schema
178
- const schema = new task_1.Schema({
179
- value: task_1.Schema.number()
180
- });
181
- // Define the boundaries with a function that will throw an error
182
- const boundaries = {
183
- fetchData: async (value) => {
184
- if (value < 0) {
185
- throw new Error('Value cannot be negative');
186
- }
187
- return value * 2;
188
- }
189
- };
190
- // Create the task
191
- const task = (0, task_1.createTask)({
192
- schema,
193
- boundaries,
194
- fn: async function ({ value }, { fetchData }) {
195
- const result = await fetchData(value);
196
- return { result, success: true };
197
- }
73
+ taskName: 'test'
198
74
  });
199
- // Create a record tape
200
- const tape = new index_1.RecordTape();
201
- // Run the task with safeRun with a value that will cause an error
202
- const [result, error, record] = await task.safeRun({ value: -5 });
203
- // Push the error record directly with type parameter
204
- tape.push('test-error', record);
205
- // Verify the execution failed as expected
206
- expect(result).toBeNull();
207
- expect(error).not.toBeNull();
208
- expect(error instanceof Error).toBe(true);
209
- if (error instanceof Error) {
210
- expect(error.message).toContain('Value cannot be negative');
211
- }
212
- // Get the recorded log from the tape
213
- const recordedLog = tape.getLog();
214
- // Verify the error log was recorded correctly
215
- expect(recordedLog).toHaveLength(1);
216
- expect(recordedLog[0]).toEqual({
217
- name: 'test-error',
218
- type: 'error',
219
- input: { value: -5 },
220
- error: 'Value cannot be negative',
75
+ expect(log[1]).toEqual({
76
+ type: 'success',
77
+ input: { value: 15 },
78
+ output: { result: 30, success: true },
221
79
  boundaries: {
222
- fetchData: [{
223
- input: [-5],
224
- output: null,
225
- error: 'Value cannot be negative'
80
+ multiply: [{
81
+ input: [15],
82
+ output: 30
226
83
  }]
227
84
  },
228
85
  metadata: {},
229
- output: undefined,
230
- taskName: undefined
86
+ taskName: 'test'
231
87
  });
232
88
  });
233
- it('should handle custom execution records with push', async () => {
234
- // Create a record tape
235
- const tape = new index_1.RecordTape();
236
- // Create a custom execution record
237
- const customRecord = {
238
- input: { value: 10 },
239
- output: { result: 20 },
240
- type: 'success',
89
+ it('Should run a task with boundaries and register errors to a tape', async () => {
90
+ const tape = new index_1.RecordTape({});
91
+ const task = (0, task_1.createTask)({
92
+ name: 'test',
93
+ schema: new task_1.Schema({
94
+ value: task_1.Schema.number()
95
+ }),
241
96
  boundaries: {
242
- fetchData: [
243
- {
244
- input: [10],
245
- output: 20
97
+ divide: async (value) => {
98
+ if (value === 0) {
99
+ throw new Error('Division by zero');
246
100
  }
247
- ]
101
+ return 100 / value;
102
+ }
103
+ },
104
+ fn: async ({ value }, { divide }) => {
105
+ const result = await divide(value);
106
+ return { result };
248
107
  }
249
- };
250
- // Push the custom record
251
- tape.push('custom-record', customRecord);
252
- // Get the recorded log from the tape
253
- const recordedLog = tape.getLog();
254
- // Verify the log was recorded correctly
255
- expect(recordedLog).toHaveLength(1);
256
- expect(recordedLog[0]).toEqual({
257
- name: 'custom-record',
258
- type: 'success',
259
- input: { value: 10 },
260
- output: { result: 20 },
108
+ });
109
+ task.addListener((record) => {
110
+ tape.push(record);
111
+ });
112
+ // Test division by zero
113
+ const [, error] = await task.safeRun({ value: 0 });
114
+ expect(error).toBeDefined();
115
+ expect(error === null || error === void 0 ? void 0 : error.message).toBe('Division by zero');
116
+ // Test valid input
117
+ const [secondResult, secondError] = await task.safeRun({ value: 10 });
118
+ expect(secondError).toBeNull();
119
+ expect(secondResult).toEqual({ result: 10 });
120
+ const log = tape.getLog();
121
+ expect(log).toHaveLength(2);
122
+ expect(log[0]).toEqual({
123
+ type: 'error',
124
+ input: { value: 0 },
125
+ error: 'Division by zero',
261
126
  boundaries: {
262
- fetchData: [{
263
- input: [10],
264
- output: 20,
265
- error: null
127
+ divide: [{
128
+ input: [0],
129
+ error: 'Division by zero'
266
130
  }]
267
131
  },
268
- metadata: {}
132
+ metadata: {},
133
+ taskName: 'test'
269
134
  });
270
- });
271
- it('should handle execution records with Promise outputs correctly', async () => {
272
- // Create a record tape
273
- const tape = new index_1.RecordTape();
274
- // Create a custom execution record with a Promise output
275
- const promiseResult = Promise.resolve({ result: 30 });
276
- const promiseRecord = {
277
- input: { value: 15 },
278
- output: promiseResult,
279
- type: 'success',
280
- boundaries: {
281
- fetchData: [
282
- {
283
- input: [15],
284
- output: 30
285
- }
286
- ]
287
- }
288
- };
289
- // Push the record with Promise output using type parameter
290
- tape.push('promise-record', promiseRecord);
291
- // Get the recorded log from the tape
292
- const recordedLog = tape.getLog();
293
- // Verify the log was recorded correctly, with Promise output set to null
294
- expect(recordedLog).toHaveLength(1);
295
- expect(recordedLog[0]).toEqual({
296
- name: 'promise-record',
135
+ expect(log[1]).toEqual({
297
136
  type: 'success',
298
- input: { value: 15 },
299
- output: null, // Promise output should be set to null
137
+ input: { value: 10 },
138
+ output: { result: 10 },
300
139
  boundaries: {
301
- fetchData: [{
302
- input: [15],
303
- output: 30,
304
- error: null
140
+ divide: [{
141
+ input: [10],
142
+ output: 10
305
143
  }]
306
144
  },
307
- metadata: {}
145
+ metadata: {},
146
+ taskName: 'test'
308
147
  });
309
148
  });
310
149
  });