Skip to content
Documentation
1.0.0-beta.10 · latest

Fetch composition

Source e69e4b6f1381 · Published v1.0.0-beta.10

Compares one structured origin, sequential composition, and explicit portable concurrency in one project. Comments in the handler mark each form.

import { Pulse } from '@pulse-compute/pulse'
interface User {
id: number
name: string
}
interface Stats {
score: number
}
interface Flags {
enabled: boolean
}
const app = new Pulse({ auto: true })
// One structured origin.
app.get('/user', async (ctx) => {
const user = await ctx
.fetch('https://users.example.test/users/123')
.json<User>()
return ctx.json({ found: true, user })
})
// Multiple origins with explicit sequential awaits.
app.get('/user-summary', async (ctx) => {
const user = await ctx
.fetch('https://users.example.test/users/123')
.json<User>()
const stats = await ctx
.fetch('https://stats.example.test/users/123')
.json<Stats>()
const flags = await ctx
.fetch('https://flags.example.test/users/123')
.json<Flags>()
return ctx.json({
id: user.id,
name: user.name,
score: stats.score,
enabled: flags.enabled,
})
})
// Multiple origins with explicit portable concurrency.
app.get('/user-summary-parallel', async (ctx) => {
const { user, stats, flags } = await ctx.parallel({
user: ctx.fetch('https://users.example.test/users/123').json<User>(),
stats: ctx.fetch('https://stats.example.test/users/123').json<Stats>(),
flags: ctx.fetch('https://flags.example.test/users/123').json<Flags>(),
})
return ctx.json({
id: user.id,
name: user.name,
score: stats.score,
enabled: flags.enabled,
})
})
export default app
import { defineConfig } from '@pulse-compute/pulse'
export default defineConfig((_scope) => ({
pulse: {
entry: 'src/index.ts',
tests: 'tests/pulse.harness.ts',
defaultProfile: 'local',
strict: true,
},
local: {
host: 'node',
target: 'native',
outDir: 'dist',
dev: {
fetches: {
'https://users.example.test/users/123': {
value: { id: 123, name: 'Ada' },
delayMs: 15,
},
'https://stats.example.test/users/123': {
value: { score: 42 },
delayMs: 5,
},
'https://flags.example.test/users/123': {
value: { enabled: true },
delayMs: 1,
},
},
},
},
}))

Generated from the executable test harness below; these are tested requests or event frames, not an exhaustive application specification. Expected errors and emitted events are included; fixtures and provider setup remain in the harness.

RequestExpected response
single
GET /user
{"status":200,"json":{"found":true,"user":{"id":123,"name":"Ada"}}}
sequential
GET /user-summary
{"status":200,"json":{"id":123,"name":"Ada","score":42,"enabled":true}}
parallel
GET /user-summary-parallel
{"status":200,"json":{"id":123,"name":"Ada","score":42,"enabled":true}}

The selected profile is local; this checked excerpt identifies its target, provider and recognized capabilities. Paths, hashes and additional inspection fields are omitted.

Terminal window
npm run inspect -- --json
{
"status": "ok",
"project": {
"target": "native"
},
"provider": {
"id": "node"
},
"compiler": {
"capabilities": [
"fetch",
"response.json",
"response.text"
]
}
}

Check this project and its local toolchain before execution. This selected result is verified by the documentation gate; another machine may report different prerequisite checks.

Terminal window
npm run doctor -- --json
{
"status": "passed",
"summary": {
"warnings": 0,
"failed": 0
}
}

Build once into a separate directory, then replay the retained artifact without running or rebuilding the application. This checked excerpt accounts for registered handlers in the build evidence; it is not runtime request coverage.

Terminal window
npm run build -- --out .pulse-docs-build
npm exec -- pulse report --artifact .pulse-docs-build/pulse-build.json --json
{
"kind": "pulse.application-report",
"reportVersion": 1,
"analytics": {
"coverage": {
"handlers": {
"expected": 3,
"observed": 3,
"reason": null,
"status": "complete"
}
}
}
}

Optional offline HTML uses the same retained evidence:

Terminal window
npm exec -- pulse report --artifact .pulse-docs-build/pulse-build.json --html

Review reports before sharing. Missing, stale or incompatible evidence is an error; timings, paths and hashes are not presented as stable output.

Interactive report captured from this example at source e69e4b6f1381. Build evidence describes this captured build, not a runtime guarantee.

Open full report · Capture provenance

Terminal window
pulse doctor
pulse inspect
pulse test
pulse dev
pulse build

The documented test result below is executed by the documentation gate.

See dynamic-probes for a runtime-sized endpoint list, a bounded effects collection, and explicit concurrent flush.

Terminal window
pulse test --json
{
"status": "passed",
"provider": "node",
"summary": {
"total": 3,
"passed": 3,
"failed": 0
},
"cases": [
{
"name": "single",
"status": "passed",
"response": {
"status": 200
}
}
]
}
const fetches = {
'https://users.example.test/users/123': {
value: { id: 123, name: 'Ada' },
delayMs: 15,
},
'https://stats.example.test/users/123': {
value: { score: 42 },
delayMs: 5,
},
'https://flags.example.test/users/123': {
value: { enabled: true },
delayMs: 1,
},
}
const summary = {
id: 123,
name: 'Ada',
score: 42,
enabled: true,
}
export default {
cases: [
{
name: 'single',
request: { path: '/user' },
fetches,
expect: {
status: 200,
json: { found: true, user: { id: 123, name: 'Ada' } },
},
},
{
name: 'sequential',
request: { path: '/user-summary' },
fetches,
expect: { status: 200, json: summary },
},
{
name: 'parallel',
request: { path: '/user-summary-parallel' },
fetches,
expect: { status: 200, json: summary },
},
],
}

For build settings, see Native build optimization.

ArtifactDefault build
Portable guest canonical-native.wasm4.5 KiB (4,572 bytes)

The executable documentation gate rebuilds and measures the default artifact. Measured with Node 24.18.0 and lockfile-pinned AssemblyScript 0.28.18. These are uncompressed on-disk sizes, not transfer sizes or platform limits.