(fields: Fields, records: Records)
| 2769 | const preserveMissingMessageAnnotation = AST.pickAnnotations([AST.MissingMessageAnnotationId]) |
| 2770 | |
| 2771 | const getDefaultTypeLiteralAST = < |
| 2772 | Fields extends Struct.Fields, |
| 2773 | const Records extends IndexSignature.Records |
| 2774 | >(fields: Fields, records: Records) => { |
| 2775 | const ownKeys = Reflect.ownKeys(fields) |
| 2776 | const pss: Array<AST.PropertySignature> = [] |
| 2777 | if (ownKeys.length > 0) { |
| 2778 | const from: Array<AST.PropertySignature> = [] |
| 2779 | const to: Array<AST.PropertySignature> = [] |
| 2780 | const transformations: Array<AST.PropertySignatureTransformation> = [] |
| 2781 | for (let i = 0; i < ownKeys.length; i++) { |
| 2782 | const key = ownKeys[i] |
| 2783 | const field = fields[key] |
| 2784 | if (isPropertySignature(field)) { |
| 2785 | const ast: PropertySignature.AST = field.ast |
| 2786 | switch (ast._tag) { |
| 2787 | case "PropertySignatureDeclaration": { |
| 2788 | const type = ast.type |
| 2789 | const isOptional = ast.isOptional |
| 2790 | const toAnnotations = ast.annotations |
| 2791 | from.push(new AST.PropertySignature(key, type, isOptional, true, preserveMissingMessageAnnotation(ast))) |
| 2792 | to.push(new AST.PropertySignature(key, AST.typeAST(type), isOptional, true, toAnnotations)) |
| 2793 | pss.push( |
| 2794 | new AST.PropertySignature(key, type, isOptional, true, toAnnotations) |
| 2795 | ) |
| 2796 | break |
| 2797 | } |
| 2798 | case "PropertySignatureTransformation": { |
| 2799 | const fromKey = ast.from.fromKey ?? key |
| 2800 | from.push( |
| 2801 | new AST.PropertySignature(fromKey, ast.from.type, ast.from.isOptional, true, ast.from.annotations) |
| 2802 | ) |
| 2803 | to.push( |
| 2804 | new AST.PropertySignature(key, ast.to.type, ast.to.isOptional, true, ast.to.annotations) |
| 2805 | ) |
| 2806 | transformations.push(new AST.PropertySignatureTransformation(fromKey, key, ast.decode, ast.encode)) |
| 2807 | break |
| 2808 | } |
| 2809 | } |
| 2810 | } else { |
| 2811 | from.push(new AST.PropertySignature(key, field.ast, false, true)) |
| 2812 | to.push(new AST.PropertySignature(key, AST.typeAST(field.ast), false, true)) |
| 2813 | pss.push(new AST.PropertySignature(key, field.ast, false, true)) |
| 2814 | } |
| 2815 | } |
| 2816 | if (array_.isNonEmptyReadonlyArray(transformations)) { |
| 2817 | const issFrom: Array<AST.IndexSignature> = [] |
| 2818 | const issTo: Array<AST.IndexSignature> = [] |
| 2819 | for (const r of records) { |
| 2820 | const { indexSignatures, propertySignatures } = AST.record(r.key.ast, r.value.ast) |
| 2821 | propertySignatures.forEach((ps) => { |
| 2822 | from.push(ps) |
| 2823 | to.push( |
| 2824 | new AST.PropertySignature(ps.name, AST.typeAST(ps.type), ps.isOptional, ps.isReadonly, ps.annotations) |
| 2825 | ) |
| 2826 | }) |
| 2827 | indexSignatures.forEach((is) => { |
| 2828 | issFrom.push(is) |
no test coverage detected