From c15dcfedcd5382bdc4c193a500011bf8a0f3b7b6 Mon Sep 17 00:00:00 2001 From: Tomasz Ciecierski Date: Fri, 30 Aug 2024 13:47:51 +0200 Subject: [PATCH 1/7] temporary solution to error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. --- .../src/template_service/register_helpers.ts | 10 +++ .../templates/zod_operation_schema.handlebars | 9 +++ .../model/exception_list_item_entry.gen.ts | 9 ++- .../model/rule_schema/rule_schemas.gen.ts | 62 ++++++++++++++----- .../bulk_actions/bulk_actions_route.gen.ts | 9 ++- 5 files changed, 81 insertions(+), 18 deletions(-) diff --git a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts index f02f295954465..3c2235b780b87 100644 --- a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts +++ b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts @@ -87,4 +87,14 @@ export function registerHelpers(handlebarsInstance: typeof Handlebars) { return circularRefs.has(`#/components/schemas/${schemaName}`); } ); + + handlebarsInstance.registerHelper('shouldCastExplicitly', function ({ anyOf }, options) { + if (anyOf?.length > 2) { + // @ts-expect-error + return options.fn(this); + } else { + // @ts-expect-error + return options.inverse(this); + } + }); } diff --git a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars index fa750c7d1f8ab..4fe524deed91b 100644 --- a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars +++ b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars @@ -31,8 +31,17 @@ export type {{@key}} = {{> ts_type}}; export type {{@key}}Input = {{> ts_input_type }}; export const {{@key}}: z.ZodType<{{@key}}, ZodTypeDef, {{@key}}Input> = {{> zod_schema_item }}; {{else}} +{{#shouldCastExplicitly this}} +// We need this temporary type to infer from it below, but in the end we want to export as a casted {{@key}} type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const {{@key}}Internal = {{> zod_schema_item}}; + +export type {{@key}} = z.infer; +export const {{@key}} = {{@key}}Internal as z.ZodType as z.ZodType<{{@key}}>; +{{else}} export type {{@key}} = z.infer; export const {{@key}} = {{> zod_schema_item}}; +{{/shouldCastExplicitly}} {{/if}} {{#if enum}} {{#unless (isSingle enum)}} diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts index d7a0e54487783..3ee29eb437962 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts @@ -85,8 +85,9 @@ export const ExceptionListItemEntryMatchWildcard = z.object({ operator: ExceptionListItemEntryOperator, }); -export type ExceptionListItemEntry = z.infer; -export const ExceptionListItemEntry = z.discriminatedUnion('type', [ +// We need this temporary type to infer from it below, but in the end we want to export as a casted ExceptionListItemEntry type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const ExceptionListItemEntryInternal = z.discriminatedUnion('type', [ ExceptionListItemEntryMatch, ExceptionListItemEntryMatchAny, ExceptionListItemEntryList, @@ -95,5 +96,9 @@ export const ExceptionListItemEntry = z.discriminatedUnion('type', [ ExceptionListItemEntryMatchWildcard, ]); +export type ExceptionListItemEntry = z.infer; +export const ExceptionListItemEntry = + ExceptionListItemEntryInternal as z.ZodType as z.ZodType; + export type ExceptionListItemEntryArray = z.infer; export const ExceptionListItemEntryArray = z.array(ExceptionListItemEntry); diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts index 972c0ce519044..05b5a01baec77 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts @@ -597,8 +597,9 @@ export const EsqlRuleUpdateProps = SharedUpdateProps.merge(EsqlRuleCreateFields) export type EsqlRulePatchProps = z.infer; export const EsqlRulePatchProps = SharedPatchProps.merge(EsqlRulePatchFields.partial()); -export type TypeSpecificCreateProps = z.infer; -export const TypeSpecificCreateProps = z.discriminatedUnion('type', [ +// We need this temporary type to infer from it below, but in the end we want to export as a casted TypeSpecificCreateProps type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const TypeSpecificCreatePropsInternal = z.discriminatedUnion('type', [ EqlRuleCreateFields, QueryRuleCreateFields, SavedQueryRuleCreateFields, @@ -609,8 +610,13 @@ export const TypeSpecificCreateProps = z.discriminatedUnion('type', [ EsqlRuleCreateFields, ]); -export type TypeSpecificPatchProps = z.infer; -export const TypeSpecificPatchProps = z.union([ +export type TypeSpecificCreateProps = z.infer; +export const TypeSpecificCreateProps = + TypeSpecificCreatePropsInternal as z.ZodType as z.ZodType; + +// We need this temporary type to infer from it below, but in the end we want to export as a casted TypeSpecificPatchProps type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const TypeSpecificPatchPropsInternal = z.union([ EqlRulePatchFields, QueryRulePatchFields, SavedQueryRulePatchFields, @@ -621,8 +627,13 @@ export const TypeSpecificPatchProps = z.union([ EsqlRulePatchFields, ]); -export type TypeSpecificResponse = z.infer; -export const TypeSpecificResponse = z.discriminatedUnion('type', [ +export type TypeSpecificPatchProps = z.infer; +export const TypeSpecificPatchProps = + TypeSpecificPatchPropsInternal as z.ZodType as z.ZodType; + +// We need this temporary type to infer from it below, but in the end we want to export as a casted TypeSpecificResponse type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const TypeSpecificResponseInternal = z.discriminatedUnion('type', [ EqlRuleResponseFields, QueryRuleResponseFields, SavedQueryRuleResponseFields, @@ -633,8 +644,13 @@ export const TypeSpecificResponse = z.discriminatedUnion('type', [ EsqlRuleResponseFields, ]); -export type RuleCreateProps = z.infer; -export const RuleCreateProps = z.discriminatedUnion('type', [ +export type TypeSpecificResponse = z.infer; +export const TypeSpecificResponse = + TypeSpecificResponseInternal as z.ZodType as z.ZodType; + +// We need this temporary type to infer from it below, but in the end we want to export as a casted RuleCreateProps type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const RuleCreatePropsInternal = z.discriminatedUnion('type', [ EqlRuleCreateProps, QueryRuleCreateProps, SavedQueryRuleCreateProps, @@ -645,8 +661,13 @@ export const RuleCreateProps = z.discriminatedUnion('type', [ EsqlRuleCreateProps, ]); -export type RuleUpdateProps = z.infer; -export const RuleUpdateProps = z.discriminatedUnion('type', [ +export type RuleCreateProps = z.infer; +export const RuleCreateProps = + RuleCreatePropsInternal as z.ZodType as z.ZodType; + +// We need this temporary type to infer from it below, but in the end we want to export as a casted RuleUpdateProps type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const RuleUpdatePropsInternal = z.discriminatedUnion('type', [ EqlRuleUpdateProps, QueryRuleUpdateProps, SavedQueryRuleUpdateProps, @@ -657,8 +678,13 @@ export const RuleUpdateProps = z.discriminatedUnion('type', [ EsqlRuleUpdateProps, ]); -export type RulePatchProps = z.infer; -export const RulePatchProps = z.union([ +export type RuleUpdateProps = z.infer; +export const RuleUpdateProps = + RuleUpdatePropsInternal as z.ZodType as z.ZodType; + +// We need this temporary type to infer from it below, but in the end we want to export as a casted RulePatchProps type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const RulePatchPropsInternal = z.union([ EqlRulePatchProps, QueryRulePatchProps, SavedQueryRulePatchProps, @@ -669,8 +695,13 @@ export const RulePatchProps = z.union([ EsqlRulePatchProps, ]); -export type RuleResponse = z.infer; -export const RuleResponse = z.discriminatedUnion('type', [ +export type RulePatchProps = z.infer; +export const RulePatchProps = + RulePatchPropsInternal as z.ZodType as z.ZodType; + +// We need this temporary type to infer from it below, but in the end we want to export as a casted RuleResponse type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const RuleResponseInternal = z.discriminatedUnion('type', [ EqlRule, QueryRule, SavedQueryRule, @@ -680,3 +711,6 @@ export const RuleResponse = z.discriminatedUnion('type', [ NewTermsRule, EsqlRule, ]); + +export type RuleResponse = z.infer; +export const RuleResponse = RuleResponseInternal as z.ZodType as z.ZodType; diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts index cf8d75576564d..0b506d2577c83 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts @@ -284,8 +284,9 @@ export const BulkActionEditPayloadTimeline = z.object({ }), }); -export type BulkActionEditPayload = z.infer; -export const BulkActionEditPayload = z.union([ +// We need this temporary type to infer from it below, but in the end we want to export as a casted BulkActionEditPayload type +// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +const BulkActionEditPayloadInternal = z.union([ BulkActionEditPayloadTags, BulkActionEditPayloadIndexPatterns, BulkActionEditPayloadInvestigationFields, @@ -294,6 +295,10 @@ export const BulkActionEditPayload = z.union([ BulkActionEditPayloadSchedule, ]); +export type BulkActionEditPayload = z.infer; +export const BulkActionEditPayload = + BulkActionEditPayloadInternal as z.ZodType as z.ZodType; + export type BulkEditRules = z.infer; export const BulkEditRules = BulkActionBase.merge( z.object({ From ff1173bb09ba2d0fd68b53fa57f3ed6184bc591d Mon Sep 17 00:00:00 2001 From: Tomasz Ciecierski Date: Fri, 30 Aug 2024 14:01:39 +0200 Subject: [PATCH 2/7] remove unknown --- .../templates/zod_operation_schema.handlebars | 2 +- .../api/model/exception_list_item_entry.gen.ts | 2 +- .../model/rule_schema/rule_schemas.gen.ts | 18 +++++++----------- .../bulk_actions/bulk_actions_route.gen.ts | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars index 4fe524deed91b..945af97e55367 100644 --- a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars +++ b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars @@ -37,7 +37,7 @@ export const {{@key}}: z.ZodType<{{@key}}, ZodTypeDef, {{@key}}Input> = {{> zod_ const {{@key}}Internal = {{> zod_schema_item}}; export type {{@key}} = z.infer; -export const {{@key}} = {{@key}}Internal as z.ZodType as z.ZodType<{{@key}}>; +export const {{@key}} = {{@key}}Internal as z.ZodType<{{@key}}>; {{else}} export type {{@key}} = z.infer; export const {{@key}} = {{> zod_schema_item}}; diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts index 3ee29eb437962..dd9dcca85d84f 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts @@ -98,7 +98,7 @@ const ExceptionListItemEntryInternal = z.discriminatedUnion('type', [ export type ExceptionListItemEntry = z.infer; export const ExceptionListItemEntry = - ExceptionListItemEntryInternal as z.ZodType as z.ZodType; + ExceptionListItemEntryInternal as z.ZodType; export type ExceptionListItemEntryArray = z.infer; export const ExceptionListItemEntryArray = z.array(ExceptionListItemEntry); diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts index 05b5a01baec77..3285b7ac4bd1e 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts @@ -612,7 +612,7 @@ const TypeSpecificCreatePropsInternal = z.discriminatedUnion('type', [ export type TypeSpecificCreateProps = z.infer; export const TypeSpecificCreateProps = - TypeSpecificCreatePropsInternal as z.ZodType as z.ZodType; + TypeSpecificCreatePropsInternal as z.ZodType; // We need this temporary type to infer from it below, but in the end we want to export as a casted TypeSpecificPatchProps type // error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. @@ -629,7 +629,7 @@ const TypeSpecificPatchPropsInternal = z.union([ export type TypeSpecificPatchProps = z.infer; export const TypeSpecificPatchProps = - TypeSpecificPatchPropsInternal as z.ZodType as z.ZodType; + TypeSpecificPatchPropsInternal as z.ZodType; // We need this temporary type to infer from it below, but in the end we want to export as a casted TypeSpecificResponse type // error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. @@ -645,8 +645,7 @@ const TypeSpecificResponseInternal = z.discriminatedUnion('type', [ ]); export type TypeSpecificResponse = z.infer; -export const TypeSpecificResponse = - TypeSpecificResponseInternal as z.ZodType as z.ZodType; +export const TypeSpecificResponse = TypeSpecificResponseInternal as z.ZodType; // We need this temporary type to infer from it below, but in the end we want to export as a casted RuleCreateProps type // error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. @@ -662,8 +661,7 @@ const RuleCreatePropsInternal = z.discriminatedUnion('type', [ ]); export type RuleCreateProps = z.infer; -export const RuleCreateProps = - RuleCreatePropsInternal as z.ZodType as z.ZodType; +export const RuleCreateProps = RuleCreatePropsInternal as z.ZodType; // We need this temporary type to infer from it below, but in the end we want to export as a casted RuleUpdateProps type // error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. @@ -679,8 +677,7 @@ const RuleUpdatePropsInternal = z.discriminatedUnion('type', [ ]); export type RuleUpdateProps = z.infer; -export const RuleUpdateProps = - RuleUpdatePropsInternal as z.ZodType as z.ZodType; +export const RuleUpdateProps = RuleUpdatePropsInternal as z.ZodType; // We need this temporary type to infer from it below, but in the end we want to export as a casted RulePatchProps type // error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. @@ -696,8 +693,7 @@ const RulePatchPropsInternal = z.union([ ]); export type RulePatchProps = z.infer; -export const RulePatchProps = - RulePatchPropsInternal as z.ZodType as z.ZodType; +export const RulePatchProps = RulePatchPropsInternal as z.ZodType; // We need this temporary type to infer from it below, but in the end we want to export as a casted RuleResponse type // error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. @@ -713,4 +709,4 @@ const RuleResponseInternal = z.discriminatedUnion('type', [ ]); export type RuleResponse = z.infer; -export const RuleResponse = RuleResponseInternal as z.ZodType as z.ZodType; +export const RuleResponse = RuleResponseInternal as z.ZodType; diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts index 0b506d2577c83..d951c53459604 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts @@ -297,7 +297,7 @@ const BulkActionEditPayloadInternal = z.union([ export type BulkActionEditPayload = z.infer; export const BulkActionEditPayload = - BulkActionEditPayloadInternal as z.ZodType as z.ZodType; + BulkActionEditPayloadInternal as z.ZodType; export type BulkEditRules = z.infer; export const BulkEditRules = BulkActionBase.merge( From 98092bfe305292a153f1a712c512951e46b6afed Mon Sep 17 00:00:00 2001 From: Tomasz Ciecierski Date: Fri, 30 Aug 2024 14:43:31 +0200 Subject: [PATCH 3/7] clean up --- .../src/template_service/register_helpers.ts | 10 +--------- .../templates/zod_operation_schema.handlebars | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts index 3c2235b780b87..bd21397d24165 100644 --- a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts +++ b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts @@ -88,13 +88,5 @@ export function registerHelpers(handlebarsInstance: typeof Handlebars) { } ); - handlebarsInstance.registerHelper('shouldCastExplicitly', function ({ anyOf }, options) { - if (anyOf?.length > 2) { - // @ts-expect-error - return options.fn(this); - } else { - // @ts-expect-error - return options.inverse(this); - } - }); + handlebarsInstance.registerHelper('shouldCastExplicitly', ({ anyOf }) => anyOf?.length > 2); } diff --git a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars index 945af97e55367..09988d656ab42 100644 --- a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars +++ b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars @@ -31,7 +31,7 @@ export type {{@key}} = {{> ts_type}}; export type {{@key}}Input = {{> ts_input_type }}; export const {{@key}}: z.ZodType<{{@key}}, ZodTypeDef, {{@key}}Input> = {{> zod_schema_item }}; {{else}} -{{#shouldCastExplicitly this}} +{{#if (shouldCastExplicitly this)}} // We need this temporary type to infer from it below, but in the end we want to export as a casted {{@key}} type // error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const {{@key}}Internal = {{> zod_schema_item}}; @@ -41,7 +41,7 @@ export const {{@key}} = {{@key}}Internal as z.ZodType<{{@key}}>; {{else}} export type {{@key}} = z.infer; export const {{@key}} = {{> zod_schema_item}}; -{{/shouldCastExplicitly}} +{{/if }} {{/if}} {{#if enum}} {{#unless (isSingle enum)}} From a614824565f503a7c9e37c0f725b78a552f90d67 Mon Sep 17 00:00:00 2001 From: Tomasz Ciecierski Date: Mon, 2 Sep 2024 08:50:34 +0200 Subject: [PATCH 4/7] response actions in eql and esql rules --- .../src/template_service/register_helpers.ts | 3 +++ .../templates/zod_operation_schema.handlebars | 4 ++-- .../api/model/exception_list_item_entry.gen.ts | 2 -- .../model/rule_schema/rule_schemas.gen.ts | 14 -------------- .../bulk_actions/bulk_actions_route.gen.ts | 2 -- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts index bd21397d24165..ea4b38474008a 100644 --- a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts +++ b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts @@ -88,5 +88,8 @@ export function registerHelpers(handlebarsInstance: typeof Handlebars) { } ); + /** + In case of anyOf schemas, we should cast explicitly to the type because TS doesn't handle big sized z.infer types + */ handlebarsInstance.registerHelper('shouldCastExplicitly', ({ anyOf }) => anyOf?.length > 2); } diff --git a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars index 09988d656ab42..80ca766585c03 100644 --- a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars +++ b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars @@ -32,8 +32,8 @@ export type {{@key}}Input = {{> ts_input_type }}; export const {{@key}}: z.ZodType<{{@key}}, ZodTypeDef, {{@key}}Input> = {{> zod_schema_item }}; {{else}} {{#if (shouldCastExplicitly this)}} -// We need this temporary type to infer from it below, but in the end we want to export as a casted {{@key}} type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. +{{!-- We need this temporary type to infer from it below, but in the end we want to export as a casted {{@key}} type --}} +{{!-- error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. --}} const {{@key}}Internal = {{> zod_schema_item}}; export type {{@key}} = z.infer; diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts index dd9dcca85d84f..d63e12c28f358 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts @@ -85,8 +85,6 @@ export const ExceptionListItemEntryMatchWildcard = z.object({ operator: ExceptionListItemEntryOperator, }); -// We need this temporary type to infer from it below, but in the end we want to export as a casted ExceptionListItemEntry type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const ExceptionListItemEntryInternal = z.discriminatedUnion('type', [ ExceptionListItemEntryMatch, ExceptionListItemEntryMatchAny, diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts index 3285b7ac4bd1e..c207f86639b73 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/rule_schemas.gen.ts @@ -597,8 +597,6 @@ export const EsqlRuleUpdateProps = SharedUpdateProps.merge(EsqlRuleCreateFields) export type EsqlRulePatchProps = z.infer; export const EsqlRulePatchProps = SharedPatchProps.merge(EsqlRulePatchFields.partial()); -// We need this temporary type to infer from it below, but in the end we want to export as a casted TypeSpecificCreateProps type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const TypeSpecificCreatePropsInternal = z.discriminatedUnion('type', [ EqlRuleCreateFields, QueryRuleCreateFields, @@ -614,8 +612,6 @@ export type TypeSpecificCreateProps = z.infer; -// We need this temporary type to infer from it below, but in the end we want to export as a casted TypeSpecificPatchProps type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const TypeSpecificPatchPropsInternal = z.union([ EqlRulePatchFields, QueryRulePatchFields, @@ -631,8 +627,6 @@ export type TypeSpecificPatchProps = z.infer; -// We need this temporary type to infer from it below, but in the end we want to export as a casted TypeSpecificResponse type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const TypeSpecificResponseInternal = z.discriminatedUnion('type', [ EqlRuleResponseFields, QueryRuleResponseFields, @@ -647,8 +641,6 @@ const TypeSpecificResponseInternal = z.discriminatedUnion('type', [ export type TypeSpecificResponse = z.infer; export const TypeSpecificResponse = TypeSpecificResponseInternal as z.ZodType; -// We need this temporary type to infer from it below, but in the end we want to export as a casted RuleCreateProps type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const RuleCreatePropsInternal = z.discriminatedUnion('type', [ EqlRuleCreateProps, QueryRuleCreateProps, @@ -663,8 +655,6 @@ const RuleCreatePropsInternal = z.discriminatedUnion('type', [ export type RuleCreateProps = z.infer; export const RuleCreateProps = RuleCreatePropsInternal as z.ZodType; -// We need this temporary type to infer from it below, but in the end we want to export as a casted RuleUpdateProps type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const RuleUpdatePropsInternal = z.discriminatedUnion('type', [ EqlRuleUpdateProps, QueryRuleUpdateProps, @@ -679,8 +669,6 @@ const RuleUpdatePropsInternal = z.discriminatedUnion('type', [ export type RuleUpdateProps = z.infer; export const RuleUpdateProps = RuleUpdatePropsInternal as z.ZodType; -// We need this temporary type to infer from it below, but in the end we want to export as a casted RulePatchProps type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const RulePatchPropsInternal = z.union([ EqlRulePatchProps, QueryRulePatchProps, @@ -695,8 +683,6 @@ const RulePatchPropsInternal = z.union([ export type RulePatchProps = z.infer; export const RulePatchProps = RulePatchPropsInternal as z.ZodType; -// We need this temporary type to infer from it below, but in the end we want to export as a casted RuleResponse type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const RuleResponseInternal = z.discriminatedUnion('type', [ EqlRule, QueryRule, diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts index d951c53459604..52a52442df42f 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/rule_management/bulk_actions/bulk_actions_route.gen.ts @@ -284,8 +284,6 @@ export const BulkActionEditPayloadTimeline = z.object({ }), }); -// We need this temporary type to infer from it below, but in the end we want to export as a casted BulkActionEditPayload type -// error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. const BulkActionEditPayloadInternal = z.union([ BulkActionEditPayloadTags, BulkActionEditPayloadIndexPatterns, From aec9da03ac32dfed6e9cb6d60c5e8603e3deed70 Mon Sep 17 00:00:00 2001 From: Tomasz Ciecierski Date: Mon, 2 Sep 2024 08:52:16 +0200 Subject: [PATCH 5/7] support anyof --- .../src/template_service/register_helpers.ts | 5 ++++- .../api/model/exception_list_item_entry.gen.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts index ea4b38474008a..d4246938d7078 100644 --- a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts +++ b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts @@ -91,5 +91,8 @@ export function registerHelpers(handlebarsInstance: typeof Handlebars) { /** In case of anyOf schemas, we should cast explicitly to the type because TS doesn't handle big sized z.infer types */ - handlebarsInstance.registerHelper('shouldCastExplicitly', ({ anyOf }) => anyOf?.length > 2); + handlebarsInstance.registerHelper( + 'shouldCastExplicitly', + ({ anyOf, oneOf }) => anyOf?.length > 2 || oneOf?.length > 2 + ); } diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts index d63e12c28f358..2678831db3d60 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts @@ -59,15 +59,18 @@ export const ExceptionListItemEntryExists = z.object({ operator: ExceptionListItemEntryOperator, }); -export type ExceptionListItemEntryNestedEntryItem = z.infer< - typeof ExceptionListItemEntryNestedEntryItem ->; -export const ExceptionListItemEntryNestedEntryItem = z.union([ +const ExceptionListItemEntryNestedEntryItemInternal = z.union([ ExceptionListItemEntryMatch, ExceptionListItemEntryMatchAny, ExceptionListItemEntryExists, ]); +export type ExceptionListItemEntryNestedEntryItem = z.infer< + typeof ExceptionListItemEntryNestedEntryItemInternal +>; +export const ExceptionListItemEntryNestedEntryItem = + ExceptionListItemEntryNestedEntryItemInternal as z.ZodType; + export type ExceptionListItemEntryNested = z.infer; export const ExceptionListItemEntryNested = z.object({ type: z.literal('nested'), From 49006c9031b73c6c0a64360f33203829c76d676a Mon Sep 17 00:00:00 2001 From: Tomasz Ciecierski Date: Mon, 2 Sep 2024 13:06:28 +0200 Subject: [PATCH 6/7] Update packages/kbn-openapi-generator/src/template_service/register_helpers.ts Co-authored-by: Maxim Palenov --- .../src/template_service/register_helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts index d4246938d7078..3663eec835d8f 100644 --- a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts +++ b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts @@ -89,7 +89,7 @@ export function registerHelpers(handlebarsInstance: typeof Handlebars) { ); /** - In case of anyOf schemas, we should cast explicitly to the type because TS doesn't handle big sized z.infer types + * Large Zod schemas might lead to TypeScript type serialization limit. The hotfix applies type hinting for all schemas using `anyOf` or `oneOf`. */ handlebarsInstance.registerHelper( 'shouldCastExplicitly', From 7108b8811c08783ea6fd99f82bf5440ecd345c27 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:49:25 +0000 Subject: [PATCH 7/7] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../src/template_service/register_helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts index 3663eec835d8f..8df6d4c1fe2c2 100644 --- a/packages/kbn-openapi-generator/src/template_service/register_helpers.ts +++ b/packages/kbn-openapi-generator/src/template_service/register_helpers.ts @@ -89,8 +89,8 @@ export function registerHelpers(handlebarsInstance: typeof Handlebars) { ); /** - * Large Zod schemas might lead to TypeScript type serialization limit. The hotfix applies type hinting for all schemas using `anyOf` or `oneOf`. - */ + * Large Zod schemas might lead to TypeScript type serialization limit. The hotfix applies type hinting for all schemas using `anyOf` or `oneOf`. + */ handlebarsInstance.registerHelper( 'shouldCastExplicitly', ({ anyOf, oneOf }) => anyOf?.length > 2 || oneOf?.length > 2