@react-native-windows/codegen 0.73.0 → 0.74.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,15 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- * @format
5
- */
6
- import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema';
7
- import type { CppStringTypes } from './ObjectTypes';
8
- export type { CppStringTypes } from './ObjectTypes';
9
- type FilesOutput = Map<string, string>;
10
- export declare function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }: {
11
- methodOnly: boolean;
12
- namespace: string;
13
- cppStringType: CppStringTypes;
14
- separateDataTypes: boolean;
15
- }): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema';
7
+ import type { CppStringTypes } from './ObjectTypes';
8
+ export type { CppStringTypes } from './ObjectTypes';
9
+ type FilesOutput = Map<string, string>;
10
+ export declare function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }: {
11
+ methodOnly: boolean;
12
+ namespace: string;
13
+ cppStringType: CppStringTypes;
14
+ separateDataTypes: boolean;
15
+ }): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
@@ -1,15 +1,15 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- * @format
5
- */
6
- 'use strict';
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.createNM2Generator = void 0;
9
- const AliasManaging_1 = require("./AliasManaging");
10
- const AliasGen_1 = require("./AliasGen");
11
- const ValidateConstants_1 = require("./ValidateConstants");
12
- const ValidateMethods_1 = require("./ValidateMethods");
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.createNM2Generator = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ const AliasGen_1 = require("./AliasGen");
11
+ const ValidateConstants_1 = require("./ValidateConstants");
12
+ const ValidateMethods_1 = require("./ValidateMethods");
13
13
  const headerTemplate = `/*
14
14
  * This file is auto-generated from a NativeModule spec file in js.
15
15
  *
@@ -17,7 +17,7 @@ const headerTemplate = `/*
17
17
  * in a way that also verifies at compile time that the native module matches the interface required
18
18
  * by the TurboModule JS spec.
19
19
  */
20
- #pragma once`;
20
+ #pragma once`;
21
21
  const specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::
22
22
  struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
23
23
  ::_MODULE_MEMBERS_TUPLES_::
@@ -27,7 +27,7 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
27
27
  ::_MODULE_MEMBERS_CHECKS_::
28
28
 
29
29
  ::_MODULE_MEMBERS_ERRORS_::
30
- }`;
30
+ }`;
31
31
  const typeOnlyTemplate = `
32
32
  ${headerTemplate}
33
33
 
@@ -39,7 +39,7 @@ ${headerTemplate}
39
39
  namespace ::_NAMESPACE_:: {
40
40
  ::_MODULE_CUSTPM_TYPES_::
41
41
  } // namespace ::_NAMESPACE_::
42
- `;
42
+ `;
43
43
  const moduleOnlyTemplate = `
44
44
  ${headerTemplate}
45
45
 
@@ -52,7 +52,7 @@ ${specTemplate}
52
52
  };
53
53
 
54
54
  } // namespace ::_NAMESPACE_::
55
- `;
55
+ `;
56
56
  const allInOneTemplate = `
57
57
  ${headerTemplate}
58
58
 
@@ -65,78 +65,78 @@ ${specTemplate}
65
65
  };
66
66
 
67
67
  } // namespace ::_NAMESPACE_::
68
- `;
69
- function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }) {
70
- return (_libraryName, schema, _moduleSpecName) => {
71
- const files = new Map();
72
- for (const moduleName of Object.keys(schema.modules)) {
73
- const nativeModule = schema.modules[moduleName];
74
- // from 0.65 facebook's react-native-codegen
75
- // the module name has the Native prefix comparing to 0.63
76
- // when reading files we provided
77
- const preferredModuleName = moduleName.startsWith('Native')
78
- ? moduleName.substr(6)
79
- : moduleName;
80
- (0, AliasManaging_1.setPreferredModuleName)(preferredModuleName);
81
- if (nativeModule.type === 'NativeModule') {
82
- console.log(`Generating Native${preferredModuleName}Spec.g.h`);
83
- // copy all explicit to a map
84
- const aliases = (0, AliasGen_1.createAliasMap)(nativeModule.aliasMap);
85
- // prepare methods
86
- const methods = (0, ValidateMethods_1.generateValidateMethods)(nativeModule, aliases, {
87
- cppStringType,
88
- });
68
+ `;
69
+ function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }) {
70
+ return (_libraryName, schema, _moduleSpecName) => {
71
+ const files = new Map();
72
+ for (const moduleName of Object.keys(schema.modules)) {
73
+ const nativeModule = schema.modules[moduleName];
74
+ // from 0.65 facebook's react-native-codegen
75
+ // the module name has the Native prefix comparing to 0.63
76
+ // when reading files we provided
77
+ const preferredModuleName = moduleName.startsWith('Native')
78
+ ? moduleName.substr(6)
79
+ : moduleName;
80
+ (0, AliasManaging_1.setPreferredModuleName)(preferredModuleName);
81
+ if (nativeModule.type === 'NativeModule') {
82
+ console.log(`Generating Native${preferredModuleName}Spec.g.h`);
83
+ // copy all explicit to a map
84
+ const aliases = (0, AliasGen_1.createAliasMap)(nativeModule.aliasMap);
85
+ // prepare methods
86
+ const methods = (0, ValidateMethods_1.generateValidateMethods)(nativeModule, aliases, {
87
+ cppStringType,
88
+ });
89
89
  let tuples = `
90
90
  static constexpr auto methods = std::tuple{
91
91
  ${methods[0]}
92
- };`;
92
+ };`;
93
93
  let checks = `
94
- constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;
95
- let errors = methods[1];
96
- // prepare constants
97
- const constants = (0, ValidateConstants_1.generateValidateConstants)(nativeModule, aliases);
98
- if (constants !== undefined && !methodOnly) {
94
+ constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;
95
+ let errors = methods[1];
96
+ // prepare constants
97
+ const constants = (0, ValidateConstants_1.generateValidateConstants)(nativeModule, aliases);
98
+ if (constants !== undefined && !methodOnly) {
99
99
  tuples = `
100
100
  static constexpr auto constants = std::tuple{
101
101
  ${constants[0]}
102
- };${tuples}`;
102
+ };${tuples}`;
103
103
  checks = `
104
- constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;
104
+ constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;
105
105
  errors = `${constants[1]}
106
106
 
107
- ${errors}`;
108
- }
109
- // generate code for structs
110
- const [customTypes, customReflection] = (0, AliasGen_1.generateAliases)(aliases, {
111
- cppStringType,
112
- });
113
- const customTypesExist = customTypes !== '';
114
- const replaceContent = function (template) {
115
- return template
116
- .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
117
- .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
118
- .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
119
- .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
120
- .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
121
- .replace(/::_MODULE_NAME_::/g, preferredModuleName)
122
- .replace(/::_TYPE_DEFINITION_INCLUDE_::/g, customTypesExist
123
- ? `// #include "Native${preferredModuleName}DataTypes.g.h" before this file to use the generated type definition`
124
- : '')
125
- .replace(/::_NAMESPACE_::/g, namespace);
126
- };
127
- if (separateDataTypes) {
128
- if (customTypesExist) {
129
- files.set(`Native${preferredModuleName}DataTypes.g.h`, replaceContent(typeOnlyTemplate));
130
- }
131
- files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(moduleOnlyTemplate));
132
- }
133
- else {
134
- files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(allInOneTemplate));
135
- }
136
- }
137
- }
138
- return files;
139
- };
140
- }
141
- exports.createNM2Generator = createNM2Generator;
107
+ ${errors}`;
108
+ }
109
+ // generate code for structs
110
+ const [customTypes, customReflection] = (0, AliasGen_1.generateAliases)(aliases, {
111
+ cppStringType,
112
+ });
113
+ const customTypesExist = customTypes !== '';
114
+ const replaceContent = function (template) {
115
+ return template
116
+ .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
117
+ .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
118
+ .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
119
+ .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
120
+ .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
121
+ .replace(/::_MODULE_NAME_::/g, preferredModuleName)
122
+ .replace(/::_TYPE_DEFINITION_INCLUDE_::/g, customTypesExist
123
+ ? `// #include "Native${preferredModuleName}DataTypes.g.h" before this file to use the generated type definition`
124
+ : '')
125
+ .replace(/::_NAMESPACE_::/g, namespace);
126
+ };
127
+ if (separateDataTypes) {
128
+ if (customTypesExist) {
129
+ files.set(`Native${preferredModuleName}DataTypes.g.h`, replaceContent(typeOnlyTemplate));
130
+ }
131
+ files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(moduleOnlyTemplate));
132
+ }
133
+ else {
134
+ files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(allInOneTemplate));
135
+ }
136
+ }
137
+ }
138
+ return files;
139
+ };
140
+ }
141
+ exports.createNM2Generator = createNM2Generator;
142
142
  //# sourceMappingURL=GenerateNM2.js.map
@@ -1,11 +1,11 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- * @format
5
- */
6
- import type { NativeModuleSchema, SchemaType } from '@react-native/codegen/lib/CodegenSchema';
7
- export declare function setOptionalTurboModule(schema: NativeModuleSchema, optional: boolean): void;
8
- export declare function getOptionalTurboModule(schema: NativeModuleSchema): boolean;
9
- type FilesOutput = Map<string, string>;
10
- export declare function generateTypeScript(_libraryName: string, schema: SchemaType, _moduleSpecName: string): FilesOutput;
11
- export {};
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import type { NativeModuleSchema, SchemaType } from '@react-native/codegen/lib/CodegenSchema';
7
+ export declare function setOptionalTurboModule(schema: NativeModuleSchema, optional: boolean): void;
8
+ export declare function getOptionalTurboModule(schema: NativeModuleSchema): boolean;
9
+ type FilesOutput = Map<string, string>;
10
+ export declare function generateTypeScript(_libraryName: string, schema: SchemaType, _moduleSpecName: string): FilesOutput;
11
+ export {};
@@ -1,21 +1,21 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- * @format
5
- */
6
- 'use strict';
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.generateTypeScript = exports.getOptionalTurboModule = exports.setOptionalTurboModule = void 0;
9
- function setOptionalTurboModule(schema, optional) {
10
- const cs = schema;
11
- cs.optionalTurboModule = optional;
12
- }
13
- exports.setOptionalTurboModule = setOptionalTurboModule;
14
- function getOptionalTurboModule(schema) {
15
- var _a;
16
- return (_a = schema.optionalTurboModule) !== null && _a !== void 0 ? _a : false;
17
- }
18
- exports.getOptionalTurboModule = getOptionalTurboModule;
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.generateTypeScript = exports.getOptionalTurboModule = exports.setOptionalTurboModule = void 0;
9
+ function setOptionalTurboModule(schema, optional) {
10
+ const cs = schema;
11
+ cs.optionalTurboModule = optional;
12
+ }
13
+ exports.setOptionalTurboModule = setOptionalTurboModule;
14
+ function getOptionalTurboModule(schema) {
15
+ var _a;
16
+ return (_a = schema.optionalTurboModule) !== null && _a !== void 0 ? _a : false;
17
+ }
18
+ exports.getOptionalTurboModule = getOptionalTurboModule;
19
19
  const moduleTemplate = `
20
20
  /*
21
21
  * This file is auto-generated from a NativeModule spec file in js.
@@ -31,136 +31,136 @@ export interface Spec extends TurboModule {
31
31
  }
32
32
 
33
33
  export default TurboModuleRegistry.::_MODULE_GETTER_::<Spec>('::_MODULE_NAME_::');
34
- `;
35
- function optionalSign(obj) {
36
- return obj.optional ? '?' : '';
37
- }
38
- function translateType(type) {
39
- // avoid: Property 'type' does not exist on type 'never'
40
- const returnType = type.type;
41
- switch (type.type) {
42
- case 'StringTypeAnnotation':
43
- return 'string';
44
- case 'NumberTypeAnnotation':
45
- case 'FloatTypeAnnotation':
46
- case 'DoubleTypeAnnotation':
47
- case 'Int32TypeAnnotation':
48
- return 'number';
49
- case 'BooleanTypeAnnotation':
50
- return 'boolean';
51
- case 'ArrayTypeAnnotation':
52
- if (type.elementType) {
53
- return `${translateType(type.elementType)}[]`;
54
- }
55
- else {
56
- return `Array`;
57
- }
58
- case 'GenericObjectTypeAnnotation':
59
- return 'object';
60
- case 'ObjectTypeAnnotation':
61
- return `{${type.properties
62
- .map((prop) => {
63
- return `${prop.name}${optionalSign(prop)}: ${translateType(prop.typeAnnotation)}`;
64
- })
65
- .join(', ')}}`;
66
- case 'ReservedTypeAnnotation': {
67
- // avoid: Property 'name' does not exist on type 'never'
68
- const name = type.name;
69
- // (#6597)
70
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
71
- if (name !== 'RootTag')
72
- throw new Error(`Unknown reserved function: ${name} in translateReturnType`);
73
- return 'number';
74
- }
75
- case 'TypeAliasTypeAnnotation':
76
- return type.name;
77
- case 'NullableTypeAnnotation':
78
- return `(${translateType(type.typeAnnotation)} | null | undefined)`;
79
- case 'VoidTypeAnnotation':
80
- return `void`;
81
- case 'PromiseTypeAnnotation':
82
- return `Promise`;
83
- case `FunctionTypeAnnotation`:
84
- return `((${type.params
85
- .map((param) => {
86
- return `${param.name}${optionalSign(param)}: ${translateType(param.typeAnnotation)}`;
87
- })
88
- .join(', ')}) => ${translateType(type.returnTypeAnnotation)})`;
89
- default:
90
- throw new Error(`Unhandled type in translateReturnType: ${returnType}`);
91
- }
92
- }
93
- function translateAlias(name, type) {
34
+ `;
35
+ function optionalSign(obj) {
36
+ return obj.optional ? '?' : '';
37
+ }
38
+ function translateType(type) {
39
+ // avoid: Property 'type' does not exist on type 'never'
40
+ const returnType = type.type;
41
+ switch (type.type) {
42
+ case 'StringTypeAnnotation':
43
+ return 'string';
44
+ case 'NumberTypeAnnotation':
45
+ case 'FloatTypeAnnotation':
46
+ case 'DoubleTypeAnnotation':
47
+ case 'Int32TypeAnnotation':
48
+ return 'number';
49
+ case 'BooleanTypeAnnotation':
50
+ return 'boolean';
51
+ case 'ArrayTypeAnnotation':
52
+ if (type.elementType) {
53
+ return `${translateType(type.elementType)}[]`;
54
+ }
55
+ else {
56
+ return `Array`;
57
+ }
58
+ case 'GenericObjectTypeAnnotation':
59
+ return 'object';
60
+ case 'ObjectTypeAnnotation':
61
+ return `{${type.properties
62
+ .map((prop) => {
63
+ return `${prop.name}${optionalSign(prop)}: ${translateType(prop.typeAnnotation)}`;
64
+ })
65
+ .join(', ')}}`;
66
+ case 'ReservedTypeAnnotation': {
67
+ // avoid: Property 'name' does not exist on type 'never'
68
+ const name = type.name;
69
+ // (#6597)
70
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
71
+ if (name !== 'RootTag')
72
+ throw new Error(`Unknown reserved function: ${name} in translateReturnType`);
73
+ return 'number';
74
+ }
75
+ case 'TypeAliasTypeAnnotation':
76
+ return type.name;
77
+ case 'NullableTypeAnnotation':
78
+ return `(${translateType(type.typeAnnotation)} | null | undefined)`;
79
+ case 'VoidTypeAnnotation':
80
+ return `void`;
81
+ case 'PromiseTypeAnnotation':
82
+ return `Promise`;
83
+ case `FunctionTypeAnnotation`:
84
+ return `((${type.params
85
+ .map((param) => {
86
+ return `${param.name}${optionalSign(param)}: ${translateType(param.typeAnnotation)}`;
87
+ })
88
+ .join(', ')}) => ${translateType(type.returnTypeAnnotation)})`;
89
+ default:
90
+ throw new Error(`Unhandled type in translateReturnType: ${returnType}`);
91
+ }
92
+ }
93
+ function translateAlias(name, type) {
94
94
  return `
95
95
  export interface ${name} {
96
- ${type.properties
97
- .map((prop) => {
98
- return ` ${prop.name}${optionalSign(prop)}: ${translateType(prop.typeAnnotation)};`;
99
- })
96
+ ${type.properties
97
+ .map((prop) => {
98
+ return ` ${prop.name}${optionalSign(prop)}: ${translateType(prop.typeAnnotation)};`;
99
+ })
100
100
  .join('\n')}
101
101
  }
102
- `;
103
- }
104
- function tryGetConstantType(nativeModule) {
105
- const candidates = nativeModule.spec.properties.filter(prop => prop.name === 'getConstants');
106
- if (candidates.length === 0) {
107
- return undefined;
108
- }
109
- const getConstant = candidates[0];
110
- const funcType = getConstant.typeAnnotation.type === 'NullableTypeAnnotation'
111
- ? getConstant.typeAnnotation.typeAnnotation
112
- : getConstant.typeAnnotation;
113
- if (funcType.params.length > 0 ||
114
- funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation') {
115
- return undefined;
116
- }
117
- const constantType = funcType.returnTypeAnnotation;
118
- if (constantType.properties.length === 0) {
119
- return undefined;
120
- }
121
- return constantType;
122
- }
123
- function translateMethod(func) {
124
- const funcType = func.typeAnnotation.type === 'NullableTypeAnnotation'
125
- ? func.typeAnnotation.typeAnnotation
126
- : func.typeAnnotation;
102
+ `;
103
+ }
104
+ function tryGetConstantType(nativeModule) {
105
+ const candidates = nativeModule.spec.properties.filter(prop => prop.name === 'getConstants');
106
+ if (candidates.length === 0) {
107
+ return undefined;
108
+ }
109
+ const getConstant = candidates[0];
110
+ const funcType = getConstant.typeAnnotation.type === 'NullableTypeAnnotation'
111
+ ? getConstant.typeAnnotation.typeAnnotation
112
+ : getConstant.typeAnnotation;
113
+ if (funcType.params.length > 0 ||
114
+ funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation') {
115
+ return undefined;
116
+ }
117
+ const constantType = funcType.returnTypeAnnotation;
118
+ if (constantType.properties.length === 0) {
119
+ return undefined;
120
+ }
121
+ return constantType;
122
+ }
123
+ function translateMethod(func) {
124
+ const funcType = func.typeAnnotation.type === 'NullableTypeAnnotation'
125
+ ? func.typeAnnotation.typeAnnotation
126
+ : func.typeAnnotation;
127
127
  return `
128
- ${func.name}(${funcType.params
129
- .map((param) => {
130
- return `${param.name}${optionalSign(param)}: ${translateType(param.typeAnnotation)}`;
131
- })
132
- .join(', ')})${optionalSign(func)}: ${translateType(funcType.returnTypeAnnotation)}${funcType.returnTypeAnnotation.type === 'ObjectTypeAnnotation' ? '' : ';'}`;
133
- }
134
- function generateTypeScript(_libraryName, schema, _moduleSpecName) {
135
- const files = new Map();
136
- for (const moduleName of Object.keys(schema.modules)) {
137
- const nativeModule = schema.modules[moduleName];
138
- // from 0.65 facebook's react-native-codegen
139
- // the module name has the Native prefix comparing to 0.63
140
- // when reading files we provided
141
- const nativePrefix = 'Native';
142
- const preferredModuleName = moduleName.startsWith(nativePrefix)
143
- ? moduleName.substr(nativePrefix.length)
144
- : moduleName;
145
- if (nativeModule.type === 'NativeModule') {
146
- console.log(`Generating ${preferredModuleName}Spec.g.ts`);
147
- const aliasCode = Object.keys(nativeModule.aliasMap)
148
- .map(name => translateAlias(name, nativeModule.aliasMap[name]))
149
- .join('');
150
- const constantType = tryGetConstantType(nativeModule);
151
- const constantCode = constantType === undefined
152
- ? ''
153
- : ` getConstants(): ${translateType(constantType)}`;
154
- const methods = nativeModule.spec.properties.filter(prop => prop.name !== 'getConstants');
155
- const membersCode = methods.map(translateMethod).join('');
156
- files.set(`${preferredModuleName}Spec.g.ts`, moduleTemplate
157
- .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)
158
- .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)
159
- .replace(/::_MODULE_NAME_::/g, preferredModuleName)
160
- .replace(/::_MODULE_GETTER_::/g, getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing'));
161
- }
162
- }
163
- return files;
164
- }
165
- exports.generateTypeScript = generateTypeScript;
128
+ ${func.name}(${funcType.params
129
+ .map((param) => {
130
+ return `${param.name}${optionalSign(param)}: ${translateType(param.typeAnnotation)}`;
131
+ })
132
+ .join(', ')})${optionalSign(func)}: ${translateType(funcType.returnTypeAnnotation)}${funcType.returnTypeAnnotation.type === 'ObjectTypeAnnotation' ? '' : ';'}`;
133
+ }
134
+ function generateTypeScript(_libraryName, schema, _moduleSpecName) {
135
+ const files = new Map();
136
+ for (const moduleName of Object.keys(schema.modules)) {
137
+ const nativeModule = schema.modules[moduleName];
138
+ // from 0.65 facebook's react-native-codegen
139
+ // the module name has the Native prefix comparing to 0.63
140
+ // when reading files we provided
141
+ const nativePrefix = 'Native';
142
+ const preferredModuleName = moduleName.startsWith(nativePrefix)
143
+ ? moduleName.substr(nativePrefix.length)
144
+ : moduleName;
145
+ if (nativeModule.type === 'NativeModule') {
146
+ console.log(`Generating ${preferredModuleName}Spec.g.ts`);
147
+ const aliasCode = Object.keys(nativeModule.aliasMap)
148
+ .map(name => translateAlias(name, nativeModule.aliasMap[name]))
149
+ .join('');
150
+ const constantType = tryGetConstantType(nativeModule);
151
+ const constantCode = constantType === undefined
152
+ ? ''
153
+ : ` getConstants(): ${translateType(constantType)}`;
154
+ const methods = nativeModule.spec.properties.filter(prop => prop.name !== 'getConstants');
155
+ const membersCode = methods.map(translateMethod).join('');
156
+ files.set(`${preferredModuleName}Spec.g.ts`, moduleTemplate
157
+ .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)
158
+ .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)
159
+ .replace(/::_MODULE_NAME_::/g, preferredModuleName)
160
+ .replace(/::_MODULE_GETTER_::/g, getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing'));
161
+ }
162
+ }
163
+ return files;
164
+ }
165
+ exports.generateTypeScript = generateTypeScript;
166
166
  //# sourceMappingURL=GenerateTypeScript.js.map
@@ -1,13 +1,13 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- * @format
5
- */
6
- import type { NativeModuleBaseTypeAnnotation, NativeModuleStringTypeAnnotation, NativeModuleFunctionTypeAnnotation, Nullable } from '@react-native/codegen/lib/CodegenSchema';
7
- import { AliasMap } from './AliasManaging';
8
- export type CppStringTypes = 'std::string' | 'std::wstring';
9
- export interface CppCodegenOptions {
10
- cppStringType: CppStringTypes;
11
- }
12
- export declare function translateFieldOrReturnType(type: Nullable<NativeModuleBaseTypeAnnotation | NativeModuleStringTypeAnnotation | NativeModuleFunctionTypeAnnotation>, aliases: AliasMap, baseAliasName: string, callerName: 'translateField' | 'translateReturnType', options: CppCodegenOptions): string;
13
- export declare function translateField(type: Nullable<NativeModuleBaseTypeAnnotation>, aliases: AliasMap, baseAliasName: string, options: CppCodegenOptions): string;
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import type { NativeModuleBaseTypeAnnotation, NativeModuleStringTypeAnnotation, NativeModuleFunctionTypeAnnotation, Nullable } from '@react-native/codegen/lib/CodegenSchema';
7
+ import { AliasMap } from './AliasManaging';
8
+ export type CppStringTypes = 'std::string' | 'std::wstring';
9
+ export interface CppCodegenOptions {
10
+ cppStringType: CppStringTypes;
11
+ }
12
+ export declare function translateFieldOrReturnType(type: Nullable<NativeModuleBaseTypeAnnotation | NativeModuleStringTypeAnnotation | NativeModuleFunctionTypeAnnotation>, aliases: AliasMap, baseAliasName: string, callerName: 'translateField' | 'translateReturnType', options: CppCodegenOptions): string;
13
+ export declare function translateField(type: Nullable<NativeModuleBaseTypeAnnotation>, aliases: AliasMap, baseAliasName: string, options: CppCodegenOptions): string;