Skip to content

Commit

Permalink
Export internal types
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdjere committed Sep 11, 2024
1 parent fafd9b2 commit 2f6773d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const {{@key}}: z.ZodType<{{@key}}, ZodTypeDef, {{@key}}Input> = {{> zod_
{{#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}};
export const {{@key}}Internal = {{> zod_schema_item}};

export type {{@key}} = z.infer<typeof {{@key}}Internal>;
export const {{@key}} = {{@key}}Internal as z.ZodType<{{@key}}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ export const EsqlRuleUpdateProps = SharedUpdateProps.merge(EsqlRuleCreateFields)
export type EsqlRulePatchProps = z.infer<typeof EsqlRulePatchProps>;
export const EsqlRulePatchProps = SharedPatchProps.merge(EsqlRulePatchFields.partial());

const TypeSpecificCreatePropsInternal = z.discriminatedUnion('type', [
export const TypeSpecificCreatePropsInternal = z.discriminatedUnion('type', [
EqlRuleCreateFields,
QueryRuleCreateFields,
SavedQueryRuleCreateFields,
Expand All @@ -612,7 +612,7 @@ export type TypeSpecificCreateProps = z.infer<typeof TypeSpecificCreatePropsInte
export const TypeSpecificCreateProps =
TypeSpecificCreatePropsInternal as z.ZodType<TypeSpecificCreateProps>;

const TypeSpecificPatchPropsInternal = z.union([
export const TypeSpecificPatchPropsInternal = z.union([
EqlRulePatchFields,
QueryRulePatchFields,
SavedQueryRulePatchFields,
Expand All @@ -627,7 +627,7 @@ export type TypeSpecificPatchProps = z.infer<typeof TypeSpecificPatchPropsIntern
export const TypeSpecificPatchProps =
TypeSpecificPatchPropsInternal as z.ZodType<TypeSpecificPatchProps>;

const TypeSpecificResponseInternal = z.discriminatedUnion('type', [
export const TypeSpecificResponseInternal = z.discriminatedUnion('type', [
EqlRuleResponseFields,
QueryRuleResponseFields,
SavedQueryRuleResponseFields,
Expand All @@ -641,7 +641,7 @@ const TypeSpecificResponseInternal = z.discriminatedUnion('type', [
export type TypeSpecificResponse = z.infer<typeof TypeSpecificResponseInternal>;
export const TypeSpecificResponse = TypeSpecificResponseInternal as z.ZodType<TypeSpecificResponse>;

const RuleCreatePropsInternal = z.discriminatedUnion('type', [
export const RuleCreatePropsInternal = z.discriminatedUnion('type', [
EqlRuleCreateProps,
QueryRuleCreateProps,
SavedQueryRuleCreateProps,
Expand All @@ -655,7 +655,7 @@ const RuleCreatePropsInternal = z.discriminatedUnion('type', [
export type RuleCreateProps = z.infer<typeof RuleCreatePropsInternal>;
export const RuleCreateProps = RuleCreatePropsInternal as z.ZodType<RuleCreateProps>;

const RuleUpdatePropsInternal = z.discriminatedUnion('type', [
export const RuleUpdatePropsInternal = z.discriminatedUnion('type', [
EqlRuleUpdateProps,
QueryRuleUpdateProps,
SavedQueryRuleUpdateProps,
Expand All @@ -669,7 +669,7 @@ const RuleUpdatePropsInternal = z.discriminatedUnion('type', [
export type RuleUpdateProps = z.infer<typeof RuleUpdatePropsInternal>;
export const RuleUpdateProps = RuleUpdatePropsInternal as z.ZodType<RuleUpdateProps>;

const RulePatchPropsInternal = z.union([
export const RulePatchPropsInternal = z.union([
EqlRulePatchProps,
QueryRulePatchProps,
SavedQueryRulePatchProps,
Expand All @@ -683,7 +683,7 @@ const RulePatchPropsInternal = z.union([
export type RulePatchProps = z.infer<typeof RulePatchPropsInternal>;
export const RulePatchProps = RulePatchPropsInternal as z.ZodType<RulePatchProps>;

const RuleResponseInternal = z.discriminatedUnion('type', [
export const RuleResponseInternal = z.discriminatedUnion('type', [
EqlRule,
QueryRule,
SavedQueryRule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export const BulkActionEditPayloadTimeline = z.object({
}),
});

const BulkActionEditPayloadInternal = z.union([
export const BulkActionEditPayloadInternal = z.union([
BulkActionEditPayloadTags,
BulkActionEditPayloadIndexPatterns,
BulkActionEditPayloadInvestigationFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { expectParseError, expectParseSuccess, stringifyZodError } from '@kbn/zo
import { getListArrayMock } from '../../../../../../common/detection_engine/schemas/types/lists.mock';
import { PrebuiltRuleAsset, TypeSpecificFields } from './prebuilt_rule_asset';
import { getPrebuiltRuleMock, getPrebuiltThreatMatchRuleMock } from './prebuilt_rule_asset.mock';
import { TypeSpecificCreateProps } from '../../../../../../common/api/detection_engine';
import { TypeSpecificCreatePropsInternal } from '../../../../../../common/api/detection_engine';

describe('Prebuilt rule asset schema', () => {
it('can be of all rule types that are supported', () => {
// Check that the discriminated union TypeSpecificFields, which is used to create
// the PrebuiltRuleAsset schema, contains all the rule types that are supported.
const createPropsTypes = TypeSpecificCreateProps.options.map(
const createPropsTypes = TypeSpecificCreatePropsInternal.options.map(
(option) => option.shape.type.value
);
const fieldsTypes = TypeSpecificFields.options.map((option) => option.shape.type.value);
Expand Down

0 comments on commit 2f6773d

Please sign in to comment.