Here are a few copy-pasteable scenarios you can drop directly into your
mesh-edge> REPL.
These examples cover the complete lifecycle: publishing a routine, testing the
validation middleware, running it locally vs. remotely, and demonstrating the
WebSocket hot-reload.
Scenario 1: The Tax Calculator (Testing Validation & Execution)
Copy and paste this block into the REPL. This creates a function, defines its
parameter requirements (including a default region), and publishes it to the
registry.
const calculateTax = async (params) => {
// Finland VAT was recently updated to 25.5%
const rate = params.region === 'FI' ? 0.255 : 0.20;
return params.subtotal + (params.subtotal * rate);
};
await saveAs('calculate_tax', calculateTax, {
subtotal: { type: 'number', required: true },
region: { type: 'string', default: 'FI' }
});
You should see: Successfully published. Edge node automatically subscribed to
[calculate_tax].
Now, test the execution and the validation middleware:
/ 1. Run locally (uses the default 'FI' region)
await edge.run('calculate_tax', { subtotal: 100 })
/ 2. Run remotely on the Registry Sandbox (overriding the region)
await remoteRun('calculate_tax', { subtotal: 100, region: 'UK' })
/ 3. Trigger a validation error (missing required parameter)
await remoteRun('calculate_tax', { region: 'US' })
Scenario 2: Data Formatter (Testing State & Network Lists)
Let's publish a second routine to verify that the registry properly tracks
multiple functions and that your edge node only executes what it has
subscribed to.
const formatLog = async (params) => {
return `[${new Date().toISOString()}] [${params.level.toUpperCase()}]
node: ${params.nodeId} | ${params.message}`;
};
await saveAs('format_log', formatLog, {
level: { type: 'string', default: 'info' },
message: { type: 'string', required: true },
nodeId: { type: 'string', default: 'edge-01' }
});
Check the registry state:
/ Ask the registry to list all known routines
await list()
/ Run the new formatter locally
await edge.run('format_log', { message: 'Routine service successfully
initialized.' })
Scenario 3: The Hot-Reload (Testing Zero-Downtime Updates)
Let's modify the calculate_tax routine we made in Scenario 1 so it returns a
detailed JSON object instead of just a number.
Watch your REPL closely when you paste thisthe WebSocket will stream the
update and inject it straight into memory.
const calculateTaxV2 = async (params) => {
const rate = params.region === 'FI' ? 0.255 : 0.20;
return {
input_subtotal: params.subtotal,
applied_rate: rate,
final_total: params.subtotal + (params.subtotal * rate),
timestamp: Date.now()
};
};
/ Overwrite the existing routine.
/ We don't need to pass the spec again if we just want to update the code.
await saveAs('calculate_tax', calculateTaxV2);
You should see: [Edge] Hot-reloaded [calculate_tax] directly into memory.
Now immediately test it. The edge node instantly uses the new logic:
await edge.run('calculate_tax', { subtotal: 500 })
==
Mesh Edge REPL starting...
Connected to registry: http://localhost:3377
Available commands:
- await list() : List all registry
routines - await edge.run('name', params) : Execute a routine
locally - await remoteRun('name', args) : Execue a routine on the
registry server
- edge.subscribe('name') : Stream a routine to local memory
- await saveAs('name', fn, spec) : Publish a local function to the network
mesh-edge>