๐ง โ๏ธ ProxyBuilder (Generic Pipeline Builder)
The ProxyBuilder allows you to create chainable function pipelines dynamically.
โจ๐ Basic Usage
1import { Builder } from "hbh-proxies";3const api = new Builder()4 .use("upper", s => s.toUpperCase())5 .use("exclaim", s => s + "!")6 .use("repeat", (s, n) => s.repeat(n));8api.upper.exclaim.repeat("hello", 2);9// โ "HELLO!HELLO!"
๐๐งฉ How It Works
Each chained property corresponds to a function stored in an internal map. When the proxy is invoked, each function runs in order.
1api.upper.exclaim("test")2// upper โ exclaim โ result
๐งฉ๐ Supported Invocation Styles
โถ๏ธ Normal Call
1api.upper("hello")
๐ท Tagged Template
1api.upper`hello world`
๐งช Explicit Execution
1api.upper.exclaim.done("hello")2api.upper.exclaim.run("hello")3api.upper.exclaim.pipe("hello")
โฑโก Async Pipelines
If your functions return promises:
1api.use("delay", async s => {2 await new Promise(r => setTimeout(r, 100));3 return s + " done";4});6await api.delay.asyncDone("task");
๐๐ Introspection
1api.upper.exclaim.steps2// โ ["upper", "exclaim"]
โ ๏ธ๐ซ Error Handling
Accessing an undefined method throws:
1api.unknown("test");2// Error: Method "unknown" not found.