|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * |
| 8 | + * @format |
| 9 | + */ |
| 10 | + |
| 11 | +import type { |
| 12 | + CompleteTypeAnnotation, |
| 13 | + NamedShape, |
| 14 | + NativeModuleEnumMember, |
| 15 | +} from "@react-native/codegen/src/CodegenSchema"; |
| 16 | +type TypeAnnotationComparisonError = { |
| 17 | + type: "TypeAnnotationComparisonError"; |
| 18 | + message: string; |
| 19 | + newerAnnotation: CompleteTypeAnnotation; |
| 20 | + olderAnnotation: CompleteTypeAnnotation; |
| 21 | + previousError?: TypeComparisonError; |
| 22 | +}; |
| 23 | +type TypeInformationComparisonError = { |
| 24 | + type: "TypeInformationComparisonError"; |
| 25 | + message: string; |
| 26 | + newerType: CompleteTypeAnnotation; |
| 27 | + olderType: CompleteTypeAnnotation; |
| 28 | + previousError?: TypeComparisonError; |
| 29 | +}; |
| 30 | +type PropertyComparisonError = { |
| 31 | + type: "PropertyComparisonError"; |
| 32 | + message: string; |
| 33 | + mismatchedProperties: Array<{ |
| 34 | + property: string; |
| 35 | + fault?: TypeComparisonError; |
| 36 | + }>; |
| 37 | + previousError?: TypeComparisonError; |
| 38 | +}; |
| 39 | +type PositionalComparisonError = { |
| 40 | + type: "PositionalComparisonError"; |
| 41 | + message: string; |
| 42 | + erroneousItems: Array<[number, CompleteTypeAnnotation]>; |
| 43 | + previousError?: TypeComparisonError; |
| 44 | +}; |
| 45 | +type MemberComparisonError = { |
| 46 | + type: "MemberComparisonError"; |
| 47 | + message: string; |
| 48 | + mismatchedMembers: Array<{ member: string; fault?: TypeComparisonError }>; |
| 49 | + previousError?: TypeComparisonError; |
| 50 | +}; |
| 51 | +export type TypeComparisonError = |
| 52 | + | TypeAnnotationComparisonError |
| 53 | + | TypeInformationComparisonError |
| 54 | + | PropertyComparisonError |
| 55 | + | PositionalComparisonError |
| 56 | + | MemberComparisonError; |
| 57 | +export type PositionalComparisonResult = { |
| 58 | + typeKind: "stringUnion" | "union" | "intersection" | "parameter" | "tuple"; |
| 59 | + nestedChanges: Array<[number, number, ComparisonResult]>; |
| 60 | + addedElements?: Array<[number, CompleteTypeAnnotation]>; |
| 61 | + removedElements?: Array<[number, CompleteTypeAnnotation]>; |
| 62 | +}; |
| 63 | +export type FunctionComparisonResult = { |
| 64 | + returnType?: ComparisonResult; |
| 65 | + parameterTypes?: PositionalComparisonResult; |
| 66 | +}; |
| 67 | +export type PropertiesComparisonResult = { |
| 68 | + addedProperties?: ReadonlyArray<NamedShape<CompleteTypeAnnotation>>; |
| 69 | + missingProperties?: ReadonlyArray<NamedShape<CompleteTypeAnnotation>>; |
| 70 | + errorProperties?: Array<{ property: string; fault?: TypeComparisonError }>; |
| 71 | + madeStrict?: Array<{ property: string; furtherChanges?: ComparisonResult }>; |
| 72 | + madeOptional?: Array<{ property: string; furtherChanges?: ComparisonResult }>; |
| 73 | + nestedPropertyChanges?: Array<[string, ComparisonResult]>; |
| 74 | +}; |
| 75 | +export type MembersComparisonResult = { |
| 76 | + addedMembers?: Array<NativeModuleEnumMember>; |
| 77 | + missingMembers?: Array<NativeModuleEnumMember>; |
| 78 | + errorMembers?: Array<{ member: string; fault?: TypeComparisonError }>; |
| 79 | +}; |
| 80 | +export type NullableComparisonResult = { |
| 81 | + typeRefined: boolean; |
| 82 | + optionsReduced: boolean; |
| 83 | + interiorLog: null | undefined | ComparisonResult; |
| 84 | + newType: null | undefined | CompleteTypeAnnotation; |
| 85 | + oldType: null | undefined | CompleteTypeAnnotation; |
| 86 | +}; |
| 87 | +export type ComparisonResult = |
| 88 | + | { status: "matching" } |
| 89 | + | { status: "skipped" } |
| 90 | + | { status: "nullableChange"; nullableLog: NullableComparisonResult } |
| 91 | + | { status: "properties"; propertyLog: PropertiesComparisonResult } |
| 92 | + | { status: "members"; memberLog: MembersComparisonResult } |
| 93 | + | { status: "functionChange"; functionChangeLog: FunctionComparisonResult } |
| 94 | + | { status: "positionalTypeChange"; changeLog: PositionalComparisonResult } |
| 95 | + | { status: "error"; errorLog: TypeComparisonError }; |
| 96 | +export declare function isPropertyLogEmpty( |
| 97 | + result: PropertiesComparisonResult |
| 98 | +): boolean; |
| 99 | +export declare function isMemberLogEmpty( |
| 100 | + result: MembersComparisonResult |
| 101 | +): boolean; |
| 102 | +export declare function isFunctionLogEmpty( |
| 103 | + result: FunctionComparisonResult |
| 104 | +): boolean; |
| 105 | +export declare function makeError(error: TypeComparisonError): ComparisonResult; |
| 106 | +export declare function typeInformationComparisonError( |
| 107 | + message: string, |
| 108 | + newerType: CompleteTypeAnnotation, |
| 109 | + olderType: CompleteTypeAnnotation, |
| 110 | + previousError?: TypeComparisonError |
| 111 | +): TypeComparisonError; |
| 112 | +export declare function typeAnnotationComparisonError( |
| 113 | + message: string, |
| 114 | + newerAnnotation: CompleteTypeAnnotation, |
| 115 | + olderAnnotation: CompleteTypeAnnotation, |
| 116 | + previousError?: TypeComparisonError |
| 117 | +): TypeComparisonError; |
| 118 | +export declare function propertyComparisonError( |
| 119 | + message: string, |
| 120 | + mismatchedProperties: Array<{ |
| 121 | + property: string; |
| 122 | + fault?: TypeComparisonError; |
| 123 | + }>, |
| 124 | + previousError?: TypeComparisonError |
| 125 | +): TypeComparisonError; |
| 126 | +export declare function memberComparisonError( |
| 127 | + message: string, |
| 128 | + mismatchedMembers: Array<{ member: string; fault?: TypeComparisonError }>, |
| 129 | + previousError?: TypeComparisonError |
| 130 | +): TypeComparisonError; |
| 131 | +export declare function positionalComparisonError( |
| 132 | + message: string, |
| 133 | + erroneousItems: Array<[number, CompleteTypeAnnotation]>, |
| 134 | + previousError?: TypeComparisonError |
| 135 | +): TypeComparisonError; |
0 commit comments