{"version":3,"file":"TreeFormatter.cjs","names":["tsplus_module_1","tsplus_module_3","tsplus_module_2","tsplus_module_4","tsplus_module_5"],"sources":["../../esm/ParseError/TreeFormatter.js"],"sourcesContent":["import * as tsplus_module_1 from \"@fncts/base/collection/immutable/RoseTree/api\";\nimport * as tsplus_module_2 from \"@fncts/schema/ASTAnnotation\";\nimport * as tsplus_module_3 from \"@fncts/base/data/Maybe/api\";\nimport * as tsplus_module_4 from \"@fncts/base/collection/immutable/Vector/api\";\nimport * as tsplus_module_5 from \"@fncts/base/data/Maybe/destructors\";\nimport { showWithOptions } from \"@fncts/base/data/Showable\";\n/**\n * @tsplus static fncts.schema.ParseErrorOps drawTree\n * @tsplus getter fncts.schema.ParseError drawTree\n */\nexport function format(error) {\n    return tsplus_module_1.draw(go(error));\n}\nfunction formatActual(actual) {\n    return showWithOptions(actual, { colors: false });\n}\nfunction formatRefinementKind(error) {\n    switch (error.kind) {\n        case \"From\": {\n            return \"From side refinement failure\";\n        }\n        case \"Predicate\": {\n            return \"Predicate refinement failure\";\n        }\n    }\n}\nfunction formatTransformationKind(error) {\n    switch (error.kind) {\n        case \"Encoded\": {\n            return \"Encoded side transformation failure\";\n        }\n        case \"Transformation\": {\n            return \"Transformation process failure\";\n        }\n        case \"Type\": {\n            return \"Type side transformation failure\";\n        }\n    }\n}\nexport function getMessage(error) {\n    return tsplus_module_3.map((f) => f(error))(error.ast.annotations.get(tsplus_module_2.Message));\n}\nexport function formatTypeError(error) {\n    return tsplus_module_3.getOrElse(() => `Expected ${error.ast.toString(true)}, actual ${formatActual(error.actual)}`)(getMessage(error));\n}\nfunction formatKeyErrors(errors) {\n    return tsplus_module_4.map((error) => {\n        if (error._tag === 3 /* ParseErrorTag.Key */) {\n            return tsplus_module_1.make(`[${String(error.keyAST)}]`, tsplus_module_4.vector(go(error.error)));\n        }\n        else {\n            return tsplus_module_1.make(`[${error.index}]`, tsplus_module_4.vector(go(error.error)));\n        }\n    })(errors);\n}\nfunction getRoseTree(error, orElse) {\n    return tsplus_module_5.match(() => orElse(), (message) => tsplus_module_1.make(message))(getMessage(error));\n}\nfunction go(error) {\n    switch (error._tag) {\n        case 1 /* ParseErrorTag.Type */:\n            return tsplus_module_1.make(formatTypeError(error));\n        case 0 /* ParseErrorTag.Declaration */:\n            return getRoseTree(error, () => {\n                const shouldSkipDefaultMessage = error.error._tag === 1 /* ParseErrorTag.Type */ && error.error.ast === error.ast;\n                if (shouldSkipDefaultMessage) {\n                    return go(error.error);\n                }\n                else {\n                    return tsplus_module_1.make(error.ast.toString(true), tsplus_module_4.vector(go(error.error)));\n                }\n            });\n        case 5 /* ParseErrorTag.Unexpected */:\n            return tsplus_module_1.make(\"is unexpected\");\n        case 4 /* ParseErrorTag.Missing */:\n            return tsplus_module_1.make(\"is missing\");\n        case 9 /* ParseErrorTag.TypeLiteral */:\n            return getRoseTree(error, () => {\n                return tsplus_module_1.make(error.ast.toString(true), formatKeyErrors(error.errors));\n            });\n        case 10 /* ParseErrorTag.Tuple */:\n            return getRoseTree(error, () => {\n                return tsplus_module_1.make(error.ast.toString(true), formatKeyErrors(error.errors));\n            });\n        case 11 /* ParseErrorTag.Union */:\n            return tsplus_module_1.make(error.ast.toString(true), tsplus_module_4.map((error) => {\n                switch (error._tag) {\n                    case 6 /* ParseErrorTag.UnionMember */:\n                        return tsplus_module_1.make(\"Union member\", tsplus_module_4.vector(go(error.error)));\n                    default:\n                        return go(error);\n                }\n            })(error.errors));\n        case 7 /* ParseErrorTag.Refinement */:\n            return getRoseTree(error, () => {\n                return tsplus_module_1.make(formatRefinementKind(error), tsplus_module_4.vector(go(error.error)));\n            });\n        case 8 /* ParseErrorTag.Transformation */:\n            return getRoseTree(error, () => {\n                return tsplus_module_1.make(formatTransformationKind(error), tsplus_module_4.vector(go(error.error)));\n            });\n        case 12 /* ParseErrorTag.Iterable */:\n            return getRoseTree(error, () => {\n                return tsplus_module_1.make(error.ast.toString(true), formatKeyErrors(error.errors));\n            });\n    }\n}\n//# sourceMapp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