(left: SchemaAST.AST, right: SchemaAST.AST)
| 651 | } |
| 652 | |
| 653 | function sameEncoding(left: SchemaAST.AST, right: SchemaAST.AST): boolean { |
| 654 | if (left._tag !== right._tag || left.encoding?.length !== right.encoding?.length) return false |
| 655 | if ( |
| 656 | left.encoding?.some((link, index) => { |
| 657 | const other = right.encoding?.[index] |
| 658 | return other === undefined || link.transformation !== other.transformation || !sameEncoding(link.to, other.to) |
| 659 | }) |
| 660 | ) |
| 661 | return false |
| 662 | if (!sameChecks(left.checks, right.checks) || !sameContext(left.context, right.context)) return false |
| 663 | if (SchemaAST.isSuspend(left) && SchemaAST.isSuspend(right)) return sameEncoding(left.thunk(), right.thunk()) |
| 664 | if (SchemaAST.isUnion(left) && SchemaAST.isUnion(right)) { |
| 665 | return ( |
| 666 | left.types.length === right.types.length && |
| 667 | left.types.every((ast, index) => sameEncoding(ast, right.types[index])) |
| 668 | ) |
| 669 | } |
| 670 | if (SchemaAST.isArrays(left) && SchemaAST.isArrays(right)) { |
| 671 | return ( |
| 672 | left.elements.length === right.elements.length && |
| 673 | left.rest.length === right.rest.length && |
| 674 | left.elements.every((ast, index) => sameEncoding(ast, right.elements[index])) && |
| 675 | left.rest.every((ast, index) => sameEncoding(ast, right.rest[index])) |
| 676 | ) |
| 677 | } |
| 678 | if (SchemaAST.isObjects(left) && SchemaAST.isObjects(right)) { |
| 679 | return ( |
| 680 | left.propertySignatures.length === right.propertySignatures.length && |
| 681 | left.indexSignatures.length === right.indexSignatures.length && |
| 682 | left.propertySignatures.every((field, index) => sameEncoding(field.type, right.propertySignatures[index].type)) && |
| 683 | left.indexSignatures.every( |
| 684 | (field, index) => |
| 685 | sameEncoding(field.parameter, right.indexSignatures[index].parameter) && |
| 686 | sameEncoding(field.type, right.indexSignatures[index].type), |
| 687 | ) |
| 688 | ) |
| 689 | } |
| 690 | return true |
| 691 | } |
| 692 | |
| 693 | function sameChecks(left: SchemaAST.Checks | undefined, right: SchemaAST.Checks | undefined): boolean { |
| 694 | if (left?.length !== right?.length) return false |
no test coverage detected