MCPcopy Create free account
hub / github.com/Effect-TS/effect / Graph

Function Graph

packages/effect/src/Schema.ts:15767–15809  ·  view source on GitHub ↗
(
  type: T,
  node: Node,
  edge: Edge
)

Source from the content-addressed store, hash-verified

15765 edge: Edge
15766): Graph<T, Node, Edge>
15767export function Graph<T extends Graph_.Kind, Node extends Constraint, Edge extends Constraint>(
15768 type: T,
15769 node: Node,
15770 edge: Edge
15771): Graph<T, Node, Edge> {
15772 const schema = declareConstructor<
15773 Graph_.Graph<Node["Type"], Edge["Type"], T>,
15774 Graph_.Graph<Node["Encoded"], Edge["Encoded"], T>,
15775 GraphIso<T, Node, Edge>
15776 >()(
15777 [node, edge],
15778 ([node, edge]) => {
15779 const encoded = graphEncodedSchema(type, node, edge)
15780 return (input, ast, options) => {
15781 if (!InternalGraph.isGraph(input) || input.mutable || input.type !== type) {
15782 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
15783 }
15784 return Effect.flatMap(
15785 SchemaParser.decodeUnknownEffect(encoded)(InternalGraph.snapshot(input), options),
15786 (snapshot) => graphDecode(snapshot, options)
15787 )
15788 }
15789 },
15790 {
15791 representation: {
15792 id: "effect/schema/Graph",
15793 payload: type
15794 },
15795 expected: `an immutable ${type} Graph`,
15796 toCodec: ([node, edge]) =>
15797 link<Graph_.Graph<Node["Encoded"], Edge["Encoded"], T>>()(
15798 graphEncodedSchema(type, node, edge),
15799 SchemaTransformation.transformEffect({
15800 decode: graphDecode,
15801 encode: (graph, options) => graphEncode(graph, type, options)
15802 })
15803 ),
15804 toCodecArbitrary: ({ typeParameters: [node, edge] }) => graphToArbitrary(type, node, edge),
15805 toEquivalence: ([node, edge]) => graphToEquivalence(node, edge)
15806 }
15807 )
15808 return make(schema.ast, { type, node, edge })
15809}
15810
15811// -----------------------------------------------------------------------------
15812// HashMap schemas

Callers

nothing calls this directly

Calls 10

graphEncodedSchemaFunction · 0.85
graphDecodeFunction · 0.85
graphEncodeFunction · 0.85
graphToArbitraryFunction · 0.85
graphToEquivalenceFunction · 0.85
declareConstructorFunction · 0.70
linkFunction · 0.70
makeFunction · 0.70
failMethod · 0.65
snapshotMethod · 0.45

Tested by

no test coverage detected