Package Exports
- @sequentialos/sequential-fetch
Readme
Sequential Fetch
Implicit xstate VM - automatic pause/resume on every fetch() call.
Installation
npm install sequential-fetchUsage
const { SequentialFetchVM, executeCode } = require('sequential-fetch');
const result = await executeCode('const x = 10; x * 2');
const vm = new SequentialFetchVM();
await vm.initialize();
const pauseResult = await vm.executeCode(`
const userId = 123;
const user = fetch('https://api.example.com/user/' + userId);
user.name
`);
const finalResult = await vm.resumeExecution(pauseResult.state, { name: 'Alice' });
vm.dispose();API
SequentialFetchVM
new SequentialFetchVM(options)Methods:
initialize()- Initialize VMexecuteCode(code)- Execute code, returns pause/complete/error resultresumeExecution(fetchId, response)- Resume from paused fetchdispose()- Clean up
Result Types
Pause (fetch encountered):
{ type: 'pause', state: fetchId, fetchRequest: { id, url, options } }Complete (execution finished):
{ type: 'complete', result: value }Supported
- Variable assignment
- Expressions and arithmetic
- Property access
- String concatenation
- Objects and arrays
- Fetch pausing
Not Supported (by design)
- Loops
- Conditionals
- Functions
- async/await
- Closures
Cross-runtime compatible: Node.js, Bun, Deno.
License
MIT