chore: generate
This commit is contained in:
@@ -35,7 +35,9 @@ describe("layer node", () => {
|
|||||||
test("replaces a layer by identity", async () => {
|
test("replaces a layer by identity", async () => {
|
||||||
const replacement = Layer.succeed(Value, Value.of({ value: "simulation" }))
|
const replacement = Layer.succeed(Value, Value.of({ value: "simulation" }))
|
||||||
const program = Effect.map(Greeting, (item) => item.value).pipe(
|
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")
|
expect(await Effect.runPromise(program)).toBe("hello simulation")
|
||||||
})
|
})
|
||||||
@@ -74,7 +76,9 @@ describe("layer node", () => {
|
|||||||
)
|
)
|
||||||
await Effect.runPromise(
|
await Effect.runPromise(
|
||||||
Effect.map(Greeting, (item) => item.value).pipe(
|
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)
|
expect(acquisitions).toBe(0)
|
||||||
|
|||||||
@@ -32,10 +32,7 @@ export const node = makeLocationNode({
|
|||||||
Tiers are declared bottom-up, from the most specific lifecycle to the most foundational:
|
Tiers are declared bottom-up, from the most specific lifecycle to the most foundational:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const tiers = LayerNode.tiers([
|
const tiers = LayerNode.tiers(["location", "global"])
|
||||||
"location",
|
|
||||||
"global",
|
|
||||||
])
|
|
||||||
```
|
```
|
||||||
|
|
||||||
An earlier tier may depend on its own tier or any later tier. A later tier cannot depend on an earlier tier.
|
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:
|
The optional third argument customizes how each tier's sorted layers are constructed:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const appLayer = LayerNode.buildLayer(
|
const appLayer = LayerNode.buildLayer(root, tiers, (tier, layers) => {
|
||||||
root,
|
|
||||||
tiers,
|
|
||||||
(tier, layers) => {
|
|
||||||
const combined = LayerNode.combine(layers)
|
const combined = LayerNode.combine(layers)
|
||||||
|
|
||||||
if (tier !== "location") return combined
|
if (tier !== "location") return combined
|
||||||
|
|
||||||
return Layer.effect(
|
return Layer.effect(
|
||||||
LocationServiceMap,
|
LocationServiceMap,
|
||||||
LayerMap.make(
|
LayerMap.make((ref: Location.Ref) => combined.pipe(Layer.provide(Location.layer(ref)), Layer.fresh), {
|
||||||
(ref: Location.Ref) =>
|
idleTimeToLive: "60 minutes",
|
||||||
combined.pipe(
|
}),
|
||||||
Layer.provide(Location.layer(ref)),
|
|
||||||
Layer.fresh,
|
|
||||||
),
|
|
||||||
{ idleTimeToLive: "60 minutes" },
|
|
||||||
),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
The callback receives:
|
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:
|
Tests and alternate runtimes may replace a specific layer implementation by exact object identity:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const layer = LayerNode.buildLayer(
|
const layer = LayerNode.buildLayer(root, tiers, buildTier, [LayerNode.replace(Config.layer, testConfigLayer)])
|
||||||
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.
|
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:
|
Global implementations must remain outside the location freshness boundary. Conceptually:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
locationTier
|
locationTier.pipe(Layer.fresh).pipe(Layer.provideMerge(globalTier))
|
||||||
.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.
|
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user