Create NativeModuleSchema and ComponentSchema

Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

## Description
The Codegen deals with "Modules". Hence:
```
type SchemaType = {
  modules: {
    [moduleName]: ...
  }
};
```

Each "Module" has a name, and represents a file. The `moduleName` is the base name of the file. This file can contain a component specification or a NativeModule specification. Hence:

```
type SchemaType = {
  modules: {
    [moduleName]: ComponentSchema | NativeModuleSchema
  }
};
```

The `ComponentSchema` can contain specifications for many different components. Hence:

```
type ComponentSchema = {
  type: 'Component'
  components: {
    [componentName]: ComponentShape
  }
}
```

The `NativeModuleSchema` contains
1. Type aliases (no surprises/nothing new).
2. One Flow interface that extends `TurboModule`.
3. Potentially many different NativeModule requires (for now) via `TurboModuleRegistry.get(Enforcing)?<specName>('moduleName')`.

Hence, the shape looks like:
```
type NativeModuleSchema = {
  type: 'NativeModule',
  aliases: NativeModuleAliasMap, // nothing new
  spec: NativeModuleSpec,
  moduleNames: $ReadOnlyArray<string>
}

type NativeModuleSpec = {
  properties: $ReadOnlyArray<...>,
}
```

## Major Notes
1. We now parse the NativeModule requires (TurboModuleRegistry.get(Enforcing)?<Spec> calls) and record them in the schema.
2. A Codegen "Module" can contain either a Component schema, or a NativeModule schema, but **not** both.

## Snapshot Updates
The changes to the schema are visible in the snapshots updated in D24236505.

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: fkgozali

Differential Revision: D24236510

fbshipit-source-id: bd344d67136418725d840e7332fd2f6957326bb4
This commit is contained in:
Ramanpreet Nara
2020-10-15 22:53:55 -07:00
committed by Facebook GitHub Bot
parent 81a97de546
commit 3a75b376cc
+16 -11
View File
@@ -244,24 +244,29 @@ export type ComponentShape = $ReadOnly<{|
|}>;
export type SchemaType = $ReadOnly<{|
modules: $ReadOnly<{
[module: string]: $ReadOnly<{|
components?: $ReadOnly<{[component: string]: ComponentShape, ...}>,
nativeModules?: $ReadOnly<{
[nativeModule: string]: NativeModuleSchema,
...,
}>,
|}>,
...,
}>,
modules: $ReadOnly<{|
[moduleName: string]: ComponentSchema | NativeModuleSchema,
|}>,
|}>;
export type ComponentSchema = $ReadOnly<{|
type: 'Component',
components: $ReadOnly<{|
[componentName: string]: ComponentShape,
|}>,
|}>;
/**
* NativeModule Types
*/
export type NativeModuleSchema = $ReadOnly<{|
// We only support aliases to Objects
type: 'NativeModule',
aliases: NativeModuleAliasMap,
spec: NativeModuleSpec,
moduleNames: $ReadOnlyArray<string>,
|}>;
type NativeModuleSpec = $ReadOnly<{|
properties: $ReadOnlyArray<NativeModulePropertySchema>,
|}>;