diff --git a/packages/opencode/test/effect/layer-node.test.ts b/packages/opencode/test/effect/layer-node.test.ts index 353cb7d230..036d4a501b 100644 --- a/packages/opencode/test/effect/layer-node.test.ts +++ b/packages/opencode/test/effect/layer-node.test.ts @@ -35,7 +35,9 @@ describe("layer node", () => { test("replaces a layer by identity", async () => { const replacement = Layer.succeed(Value, Value.of({ value: "simulation" })) const program = Effect.map(Greeting, (item) => item.value).pipe( - Effect.provide(LayerNode.buildLayer(greeting, { tiers, replacements: [LayerNode.replace(valueLayer, replacement)] })), + Effect.provide( + LayerNode.buildLayer(greeting, { tiers, replacements: [LayerNode.replace(valueLayer, replacement)] }), + ), ) expect(await Effect.runPromise(program)).toBe("hello simulation") }) @@ -74,7 +76,9 @@ describe("layer node", () => { ) await Effect.runPromise( Effect.map(Greeting, (item) => item.value).pipe( - Effect.provide(LayerNode.buildLayer(greeting, { tiers, replacements: [LayerNode.replace(other, replacement)] })), + Effect.provide( + LayerNode.buildLayer(greeting, { tiers, replacements: [LayerNode.replace(other, replacement)] }), + ), ), ) expect(acquisitions).toBe(0) diff --git a/specs/layer-node-tiers.md b/specs/layer-node-tiers.md index 888e949efb..fc2212ece8 100644 --- a/specs/layer-node-tiers.md +++ b/specs/layer-node-tiers.md @@ -32,10 +32,7 @@ export const node = makeLocationNode({ Tiers are declared bottom-up, from the most specific lifecycle to the most foundational: ```ts -const tiers = LayerNode.tiers([ - "location", - "global", -]) +const tiers = LayerNode.tiers(["location", "global"]) ``` An earlier tier may depend on its own tier or any later tier. A later tier cannot depend on an earlier tier. @@ -157,27 +154,18 @@ Without a custom build function, a tier's sorted layers are combined with the de The optional third argument customizes how each tier's sorted layers are constructed: ```ts -const appLayer = LayerNode.buildLayer( - root, - tiers, - (tier, layers) => { - const combined = LayerNode.combine(layers) +const appLayer = LayerNode.buildLayer(root, tiers, (tier, layers) => { + const combined = LayerNode.combine(layers) - if (tier !== "location") return combined + if (tier !== "location") return combined - return Layer.effect( - LocationServiceMap, - LayerMap.make( - (ref: Location.Ref) => - combined.pipe( - Layer.provide(Location.layer(ref)), - Layer.fresh, - ), - { idleTimeToLive: "60 minutes" }, - ), - ) - }, -) + return Layer.effect( + LocationServiceMap, + LayerMap.make((ref: Location.Ref) => combined.pipe(Layer.provide(Location.layer(ref)), Layer.fresh), { + idleTimeToLive: "60 minutes", + }), + ) +}) ``` The callback receives: @@ -192,12 +180,7 @@ It returns the final layer representing that tier. This permits a tier to introd Tests and alternate runtimes may replace a specific layer implementation by exact object identity: ```ts -const layer = LayerNode.buildLayer( - root, - tiers, - buildTier, - [LayerNode.replace(Config.layer, testConfigLayer)], -) +const layer = LayerNode.buildLayer(root, tiers, buildTier, [LayerNode.replace(Config.layer, testConfigLayer)]) ``` The replacement applies to every placement of that exact source layer in the generated plans. Unused replacements are not acquired. A replacement must provide the same service output, must not introduce new errors, and must not have unresolved dependencies. @@ -207,9 +190,7 @@ The replacement applies to every placement of that exact source layer in the gen Global implementations must remain outside the location freshness boundary. Conceptually: ```ts -locationTier - .pipe(Layer.fresh) - .pipe(Layer.provideMerge(globalTier)) +locationTier.pipe(Layer.fresh).pipe(Layer.provideMerge(globalTier)) ``` The location tier contains only location implementations. Global dependencies are connected after the location build function creates its fresh or `LayerMap` boundary, so global services remain shared.