| 15596 | }) |
| 15597 | } |
| 15598 | function graphDecode<N, E, T extends Graph_.Kind>( |
| 15599 | input: EncodedGraph<N, E, T>, |
| 15600 | options: SchemaAST.ParseOptions |
| 15601 | ): Effect.Effect<Graph_.Graph<N, E, T>, SchemaIssue.Issue> { |
| 15602 | let previous = -1 |
| 15603 | const indexes = new Set<Graph_.NodeIndex>() |
| 15604 | for (let i = 0; i < input.nodes.length; i++) { |
| 15605 | const index = input.nodes[i].index |
| 15606 | if (index <= previous) { |
| 15607 | return Effect.fail( |
| 15608 | new SchemaIssue.Pointer( |
| 15609 | ["nodes", i, "index"], |
| 15610 | new SchemaIssue.InvalidValue({ expected: "a strictly increasing node index" }, index, options) |
| 15611 | ) |
| 15612 | ) |
| 15613 | } |
| 15614 | previous = index |
| 15615 | indexes.add(index) |
| 15616 | } |
| 15617 | |
| 15618 | previous = -1 |
| 15619 | for (let i = 0; i < input.edges.length; i++) { |
| 15620 | const edge = input.edges[i] |
| 15621 | if (edge.index <= previous) { |
| 15622 | return Effect.fail( |
| 15623 | new SchemaIssue.Pointer( |
| 15624 | ["edges", i, "index"], |
| 15625 | new SchemaIssue.InvalidValue({ expected: "a strictly increasing edge index" }, edge.index, options) |
| 15626 | ) |
| 15627 | ) |
| 15628 | } |
| 15629 | previous = edge.index |
| 15630 | if (!indexes.has(edge.source)) { |
| 15631 | return Effect.fail( |
| 15632 | new SchemaIssue.Pointer( |
| 15633 | ["edges", i, "source"], |
| 15634 | new SchemaIssue.InvalidValue({ expected: "an encoded node index" }, edge.source, options) |
| 15635 | ) |
| 15636 | ) |
| 15637 | } |
| 15638 | if (!indexes.has(edge.target)) { |
| 15639 | return Effect.fail( |
| 15640 | new SchemaIssue.Pointer( |
| 15641 | ["edges", i, "target"], |
| 15642 | new SchemaIssue.InvalidValue({ expected: "an encoded node index" }, edge.target, options) |
| 15643 | ) |
| 15644 | ) |
| 15645 | } |
| 15646 | } |
| 15647 | |
| 15648 | return Effect.succeed(InternalGraph.hydrate(input)) |
| 15649 | } |
| 15650 | function graphEncode<N, E, T extends Graph_.Kind>( |
| 15651 | input: Graph_.Graph<N, E, T>, |
| 15652 | type: T, |