| 128 | |
| 129 | const router = Router(StreamyRsc)({ |
| 130 | *effect(match) { |
| 131 | return match({ |
| 132 | StreamTicks: () => Stream.fromIterable([10, 20, 30]), |
| 133 | StreamCountTo: ({ to }: { readonly to: number }) => |
| 134 | Effect |
| 135 | .gen(function*() { |
| 136 | return Stream.range(1, to) |
| 137 | }) |
| 138 | .pipe(Stream.unwrap), |
| 139 | // emits 3 values 100ms apart so the test can prove element-by-element |
| 140 | // delivery rather than a single batched response |
| 141 | StreamRealtime: () => |
| 142 | Stream.fromIterable([1, 2, 3]).pipe( |
| 143 | Stream.mapEffect((n) => Effect.sleep("100 millis").pipe(Effect.as(n))) |
| 144 | ), |
| 145 | StreamFailStream: () => Stream.fail(new StreamBoom({ reason: "from-stream" })), |
| 146 | StreamNoSuccess: () => Stream.empty, |
| 147 | // handlers below are unreachable when middleware-auth fails; bodies exist |
| 148 | // only so the resource type-checks |
| 149 | StreamRequiresAuth: () => Stream.fromIterable([1, 2, 3]), |
| 150 | CommandRequiresAuth: () => Effect.succeed(1), |
| 151 | QueryRequiresAuth: () => Effect.succeed(1) |
| 152 | }) |
| 153 | } |
| 154 | }) |
| 155 | |
| 156 | const RpcRouterLayer = matchAll({ router }) |