mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
247fc6774f
Summary: Previously we accepted only very limited set of types for schema parser. However, in many cases we want to provide more specific typings e.g. accept enum or touple. Currently, we don't take any advantages for codegen from specifying type of elements for object or array. All of them fallback to the same cpp code. That's why I decided not to throw exception if types of arrays' and objects' elements are different than currently supported. Then I want to fallback to `undefined`. Reviewed By: rickhanlonii Differential Revision: D16325028 fbshipit-source-id: 3d7990ca0207c31f0ed522e7316a9cb17b6b1bcb
267 lines
6.7 KiB
JavaScript
267 lines
6.7 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
export type CommandsFunctionTypeAnnotation = $ReadOnly<{|
|
|
type: 'FunctionTypeAnnotation',
|
|
params: $ReadOnlyArray<CommandsFunctionTypeParamAnnotation>,
|
|
|}>;
|
|
|
|
export type CommandsFunctionTypeParamAnnotation = $ReadOnly<{|
|
|
name: string,
|
|
typeAnnotation: CommandsTypeAnnotation,
|
|
|}>;
|
|
|
|
export type CommandsTypeAnnotation =
|
|
| BooleanTypeAnnotation
|
|
| Int32TypeAnnotation;
|
|
|
|
export type BooleanTypeAnnotation = $ReadOnly<{|
|
|
type: 'BooleanTypeAnnotation',
|
|
|}>;
|
|
|
|
export type Int32TypeAnnotation = $ReadOnly<{|
|
|
type: 'Int32TypeAnnotation',
|
|
|}>;
|
|
|
|
export type ObjectPropertyType =
|
|
| $ReadOnly<{|
|
|
type: 'BooleanTypeAnnotation',
|
|
name: string,
|
|
optional: boolean,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'StringTypeAnnotation',
|
|
name: string,
|
|
optional: boolean,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'FloatTypeAnnotation',
|
|
name: string,
|
|
optional: boolean,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'Int32TypeAnnotation',
|
|
name: string,
|
|
optional: boolean,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'StringEnumTypeAnnotation',
|
|
name: string,
|
|
optional: boolean,
|
|
options: $ReadOnlyArray<{|
|
|
name: string,
|
|
|}>,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'ObjectTypeAnnotation',
|
|
name: string,
|
|
optional: boolean,
|
|
properties: $ReadOnlyArray<ObjectPropertyType>,
|
|
|}>;
|
|
|
|
type PropTypeTypeAnnotation =
|
|
| $ReadOnly<{|
|
|
type: 'BooleanTypeAnnotation',
|
|
default: boolean,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'StringTypeAnnotation',
|
|
default: string | null,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'FloatTypeAnnotation',
|
|
default: number,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'Int32TypeAnnotation',
|
|
default: number,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'StringEnumTypeAnnotation',
|
|
default: string,
|
|
options: $ReadOnlyArray<{|
|
|
name: string,
|
|
|}>,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'NativePrimitiveTypeAnnotation',
|
|
name: 'ColorPrimitive' | 'ImageSourcePrimitive' | 'PointPrimitive',
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'ArrayTypeAnnotation',
|
|
elementType:
|
|
| $ReadOnly<{|
|
|
type: 'BooleanTypeAnnotation',
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'StringTypeAnnotation',
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'FloatTypeAnnotation',
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'Int32TypeAnnotation',
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'StringEnumTypeAnnotation',
|
|
default: string,
|
|
options: $ReadOnlyArray<{|
|
|
name: string,
|
|
|}>,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'NativePrimitiveTypeAnnotation',
|
|
name: 'ColorPrimitive' | 'ImageSourcePrimitive' | 'PointPrimitive',
|
|
|}>,
|
|
|}>;
|
|
|
|
export type PropTypeShape = $ReadOnly<{|
|
|
name: string,
|
|
optional: boolean,
|
|
typeAnnotation: PropTypeTypeAnnotation,
|
|
|}>;
|
|
|
|
export type PrimitiveTypeAnnotationType =
|
|
| 'StringTypeAnnotation'
|
|
| 'NumberTypeAnnotation'
|
|
| 'Int32TypeAnnotation'
|
|
| 'FloatTypeAnnotation'
|
|
| 'BooleanTypeAnnotation'
|
|
| 'GenericObjectTypeAnnotation';
|
|
|
|
export type PrimitiveTypeAnnotation = $ReadOnly<{|
|
|
type: PrimitiveTypeAnnotationType,
|
|
|}>;
|
|
|
|
export type FunctionTypeAnnotationParamTypeAnnotation =
|
|
| $ReadOnly<{|
|
|
type: 'AnyTypeAnnotation' | PrimitiveTypeAnnotationType,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'ArrayTypeAnnotation',
|
|
elementType: ?FunctionTypeAnnotationParamTypeAnnotation,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'ObjectTypeAnnotation',
|
|
properties: ?$ReadOnlyArray<ObjectParamTypeAnnotation>,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'FunctionTypeAnnotation',
|
|
params: $ReadOnlyArray<FunctionTypeAnnotationParam>,
|
|
returnTypeAnnotation: FunctionTypeAnnotationReturn,
|
|
|}>;
|
|
|
|
export type FunctionTypeAnnotationReturnArrayElementType = FunctionTypeAnnotationParamTypeAnnotation;
|
|
|
|
export type ObjectParamTypeAnnotation = $ReadOnly<{|
|
|
optional: boolean,
|
|
name: string,
|
|
typeAnnotation: FunctionTypeAnnotationParamTypeAnnotation,
|
|
|}>;
|
|
|
|
export type FunctionTypeAnnotationReturn =
|
|
| $ReadOnly<{|
|
|
type: PrimitiveTypeAnnotationType | 'VoidTypeAnnotation',
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'ArrayTypeAnnotation',
|
|
elementType: ?FunctionTypeAnnotationReturnArrayElementType,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'GenericPromiseTypeAnnotation',
|
|
resolvedType: FunctionTypeAnnotationReturn,
|
|
|}>
|
|
| $ReadOnly<{|
|
|
type: 'ObjectTypeAnnotation',
|
|
properties: ?$ReadOnlyArray<ObjectParamTypeAnnotation>,
|
|
|}>;
|
|
|
|
export type FunctionTypeAnnotationParam = $ReadOnly<{|
|
|
nullable: boolean,
|
|
name: string,
|
|
typeAnnotation: FunctionTypeAnnotationParamTypeAnnotation,
|
|
|}>;
|
|
|
|
export type FunctionTypeAnnotation = $ReadOnly<{|
|
|
type: 'FunctionTypeAnnotation',
|
|
params: $ReadOnlyArray<FunctionTypeAnnotationParam>,
|
|
returnTypeAnnotation: FunctionTypeAnnotationReturn,
|
|
optional: boolean,
|
|
|}>;
|
|
|
|
export type MethodTypeShape = $ReadOnly<{|
|
|
name: string,
|
|
typeAnnotation: FunctionTypeAnnotation,
|
|
|}>;
|
|
|
|
export type NativeModuleShape = $ReadOnly<{|
|
|
properties: $ReadOnlyArray<MethodTypeShape>,
|
|
|}>;
|
|
|
|
export type EventTypeShape = $ReadOnly<{|
|
|
name: string,
|
|
bubblingType: 'direct' | 'bubble',
|
|
optional: boolean,
|
|
paperTopLevelNameDeprecated?: string,
|
|
typeAnnotation: $ReadOnly<{|
|
|
type: 'EventTypeAnnotation',
|
|
argument?: $ReadOnly<{|
|
|
type: 'ObjectTypeAnnotation',
|
|
properties: $ReadOnlyArray<ObjectPropertyType>,
|
|
|}>,
|
|
|}>,
|
|
|}>;
|
|
|
|
export type CommandTypeShape = $ReadOnly<{|
|
|
name: string,
|
|
optional: boolean,
|
|
typeAnnotation: CommandsFunctionTypeAnnotation,
|
|
|}>;
|
|
|
|
export type OptionsShape = $ReadOnly<{|
|
|
interfaceOnly?: boolean,
|
|
|
|
// Use for components with no current paper rename in progress
|
|
// Does not check for new name
|
|
paperComponentName?: string,
|
|
|
|
// Use for components currently being renamed in paper
|
|
// Will use new name if it is available and fallback to this name
|
|
paperComponentNameDeprecated?: string,
|
|
|}>;
|
|
|
|
export type ExtendsPropsShape = $ReadOnly<{|
|
|
type: 'ReactNativeBuiltInType',
|
|
knownTypeName: 'ReactNativeCoreViewProps',
|
|
|}>;
|
|
|
|
export type ComponentShape = $ReadOnly<{|
|
|
...OptionsShape,
|
|
extendsProps: $ReadOnlyArray<ExtendsPropsShape>,
|
|
events: $ReadOnlyArray<EventTypeShape>,
|
|
props: $ReadOnlyArray<PropTypeShape>,
|
|
commands: $ReadOnlyArray<CommandTypeShape>,
|
|
|}>;
|
|
|
|
export type SchemaType = $ReadOnly<{|
|
|
modules: $ReadOnly<{
|
|
[module: string]: $ReadOnly<{|
|
|
components?: $ReadOnly<{
|
|
[component: string]: ComponentShape,
|
|
}>,
|
|
nativeModules?: $ReadOnly<{
|
|
[nativeModule: string]: NativeModuleShape,
|
|
}>,
|
|
|}>,
|
|
}>,
|
|
|}>;
|