Domain.ExternalSystem reference
ExternalSystem
Section titled “ExternalSystem”Source:
packages/domain/src/ExternalSystem.ts
An outside system your model calls, such as a payment provider or a fraud
scorer, declared as the operations the model uses. It’s an Effect service:
policies yield* it, an adapter implements it with toLayer, and stories
answer its calls themselves, so the model depends on what it asks for and
never on a vendor.
ExternalSystem: Declaring an external system and an adapter
Section titled “ExternalSystem: Declaring an external system and an adapter”import * as Domain from "@alchemy.run/domain";import * as Effect from "effect/Effect";import * as Schema from "effect/Schema";
export class FraudCheck extends Domain.ExternalSystem("FraudCheck", { score: { args: { accountId: Schema.String, amount: Schema.Int }, success: { risk: Schema.Number } },}) {}
export const SiftFraudCheck = FraudCheck.toLayer( Effect.succeed({ score: ({ amount }) => Effect.succeed({ risk: amount >= 80_000 ? 0.95 : 0.05 }), }),);