فهرست منبع

chore: generate

opencode-agent[bot] 2 ماه پیش
والد
کامیت
0870a838a8
2فایلهای تغییر یافته به همراه21 افزوده شده و 36 حذف شده
  1. 6 2
      packages/opencode/test/effect/layer-node.test.ts
  2. 15 34
      specs/layer-node-tiers.md

+ 6 - 2
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)

+ 15 - 34
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)
-
-    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" },
-      ),
-    )
-  },
-)
+const appLayer = LayerNode.buildLayer(root, tiers, (tier, layers) => {
+  const combined = LayerNode.combine(layers)
+
+  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",
+    }),
+  )
+})
 ```
 
 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.