diff --git a/native/codegen/src/index.js b/native/codegen/src/index.js --- a/native/codegen/src/index.js +++ b/native/codegen/src/index.js @@ -16,3 +16,10 @@ // CommUtilsModule const utilsModuleSchemaPath = path.resolve('./schema/CommUtilsModuleSchema.js'); codeGen('utils', utilsModuleSchemaPath, ['cpp', 'h'], outPath); + +// CommValidationModule +// CommUtilsModule +const validationModuleSchemaPath = path.resolve( + './schema/CommValidationModuleSchema.js', +); +codeGen('validation', validationModuleSchemaPath, ['cpp', 'h'], outPath); diff --git a/native/cpp/CommonCpp/_generated/validationJSI-generated.cpp b/native/cpp/CommonCpp/_generated/validationJSI-generated.cpp new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/_generated/validationJSI-generated.cpp @@ -0,0 +1,26 @@ +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateModuleH.js + */ + +#include "validationJSI.h" + +namespace facebook { +namespace react { + +static jsi::Value __hostFunction_CommValidationModuleSchemaCxxSpecJSI_validateMessageTypes(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->validateMessageTypes(rt, args[0].asObject(rt).asArray(rt)); +} + +CommValidationModuleSchemaCxxSpecJSI::CommValidationModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker) + : TurboModule("CommValidationModule", jsInvoker) { + methodMap_["validateMessageTypes"] = MethodMetadata {1, __hostFunction_CommValidationModuleSchemaCxxSpecJSI_validateMessageTypes}; +} + + +} // namespace react +} // namespace facebook diff --git a/native/cpp/CommonCpp/_generated/validationJSI.h b/native/cpp/CommonCpp/_generated/validationJSI.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/_generated/validationJSI.h @@ -0,0 +1,62 @@ +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateModuleH.js + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +class JSI_EXPORT CommValidationModuleSchemaCxxSpecJSI : public TurboModule { +protected: + CommValidationModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker); + +public: + virtual jsi::Value validateMessageTypes(jsi::Runtime &rt, jsi::Array messageTypes) = 0; + +}; + +template +class JSI_EXPORT CommValidationModuleSchemaCxxSpec : public TurboModule { +public: + jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override { + return delegate_.get(rt, propName); + } + +protected: + CommValidationModuleSchemaCxxSpec(std::shared_ptr jsInvoker) + : TurboModule("CommValidationModule", jsInvoker), + delegate_(static_cast(this), jsInvoker) {} + +private: + class Delegate : public CommValidationModuleSchemaCxxSpecJSI { + public: + Delegate(T *instance, std::shared_ptr jsInvoker) : + CommValidationModuleSchemaCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {} + + jsi::Value validateMessageTypes(jsi::Runtime &rt, jsi::Array messageTypes) override { + static_assert( + bridging::getParameterCount(&T::validateMessageTypes) == 2, + "Expected validateMessageTypes(...) to have 2 parameters"); + + return bridging::callFromJs( + rt, &T::validateMessageTypes, jsInvoker_, instance_, std::move(messageTypes)); + } + + private: + T *instance_; + }; + + Delegate delegate_; +}; + +} // namespace react +} // namespace facebook diff --git a/native/schema/CommValidationModuleSchema.js b/native/schema/CommValidationModuleSchema.js new file mode 100644 --- /dev/null +++ b/native/schema/CommValidationModuleSchema.js @@ -0,0 +1,21 @@ +// @flow + +'use strict'; + +import { TurboModuleRegistry } from 'react-native'; +import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport.js'; + +import { type MessageType } from 'lib/types/message-types-enum.js'; + +export interface Spec extends TurboModule { + +validateMessageTypes: ( + messageTypes: $ReadOnlyArray<{ + +messageTypeKey: string, + +messageType: MessageType, + }>, + ) => Promise; +} + +export default (TurboModuleRegistry.getEnforcing( + 'CommValidationModule', +): Spec);