From e38200099700d6d4a4a0148452d85eada00ca8e3 Mon Sep 17 00:00:00 2001 From: Sandor Karpf Date: Mon, 15 Dec 2025 18:32:56 +0100 Subject: [PATCH] fix: disable array type in entity predicate types and zod schema validator Signed-off-by: Sandor Karpf --- plugins/catalog-react/report-alpha.api.md | 4 +--- .../blueprints/EntityCardBlueprint.test.tsx | 21 +------------------ .../EntityContentBlueprint.test.tsx | 21 +------------------ .../EntityContextMenuItemBlueprint.test.tsx | 21 +------------------ .../createEntityPredicateSchema.test.ts | 7 ++++--- .../predicates/createEntityPredicateSchema.ts | 6 +----- .../src/alpha/predicates/types.ts | 4 +--- 7 files changed, 10 insertions(+), 74 deletions(-) diff --git a/plugins/catalog-react/report-alpha.api.md b/plugins/catalog-react/report-alpha.api.md index 40a83851b6..49c27318a7 100644 --- a/plugins/catalog-react/report-alpha.api.md +++ b/plugins/catalog-react/report-alpha.api.md @@ -478,7 +478,6 @@ export const EntityIconLinkBlueprint: ExtensionBlueprint<{ export type EntityPredicate = | EntityPredicateExpression | EntityPredicatePrimitive - | never[] | { $all: EntityPredicate[]; } @@ -507,7 +506,6 @@ export function entityPredicateToFilterFunction( // @alpha (undocumented) export type EntityPredicateValue = | EntityPredicatePrimitive - | EntityPredicatePrimitive[] | { $exists: boolean; } @@ -515,7 +513,7 @@ export type EntityPredicateValue = $in: EntityPredicatePrimitive[]; } | { - $contains: EntityPredicateExpression | string; + $contains: EntityPredicate; }; // @alpha diff --git a/plugins/catalog-react/src/alpha/blueprints/EntityCardBlueprint.test.tsx b/plugins/catalog-react/src/alpha/blueprints/EntityCardBlueprint.test.tsx index 8780a9f14f..090f559915 100644 --- a/plugins/catalog-react/src/alpha/blueprints/EntityCardBlueprint.test.tsx +++ b/plugins/catalog-react/src/alpha/blueprints/EntityCardBlueprint.test.tsx @@ -69,12 +69,6 @@ describe('EntityCardBlueprint', () => { "boolean", ], }, - { - "items": { - "$ref": "#/properties/filter/anyOf/1/anyOf/0/anyOf/0/additionalProperties/anyOf/0", - }, - "type": "array", - }, { "additionalProperties": false, "properties": { @@ -106,14 +100,7 @@ describe('EntityCardBlueprint', () => { "additionalProperties": false, "properties": { "$contains": { - "anyOf": [ - { - "$ref": "#/properties/filter/anyOf/1/anyOf/0", - }, - { - "type": "string", - }, - ], + "$ref": "#/properties/filter/anyOf/1", }, }, "required": [ @@ -142,12 +129,6 @@ describe('EntityCardBlueprint', () => { { "$ref": "#/properties/filter/anyOf/1/anyOf/0/anyOf/0/additionalProperties/anyOf/0", }, - { - "items": { - "not": {}, - }, - "type": "array", - }, { "additionalProperties": false, "properties": { diff --git a/plugins/catalog-react/src/alpha/blueprints/EntityContentBlueprint.test.tsx b/plugins/catalog-react/src/alpha/blueprints/EntityContentBlueprint.test.tsx index 7275651315..6c0f99b5b4 100644 --- a/plugins/catalog-react/src/alpha/blueprints/EntityContentBlueprint.test.tsx +++ b/plugins/catalog-react/src/alpha/blueprints/EntityContentBlueprint.test.tsx @@ -71,12 +71,6 @@ describe('EntityContentBlueprint', () => { "boolean", ], }, - { - "items": { - "$ref": "#/properties/filter/anyOf/1/anyOf/0/anyOf/0/additionalProperties/anyOf/0", - }, - "type": "array", - }, { "additionalProperties": false, "properties": { @@ -108,14 +102,7 @@ describe('EntityContentBlueprint', () => { "additionalProperties": false, "properties": { "$contains": { - "anyOf": [ - { - "$ref": "#/properties/filter/anyOf/1/anyOf/0", - }, - { - "type": "string", - }, - ], + "$ref": "#/properties/filter/anyOf/1", }, }, "required": [ @@ -144,12 +131,6 @@ describe('EntityContentBlueprint', () => { { "$ref": "#/properties/filter/anyOf/1/anyOf/0/anyOf/0/additionalProperties/anyOf/0", }, - { - "items": { - "not": {}, - }, - "type": "array", - }, { "additionalProperties": false, "properties": { diff --git a/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.test.tsx b/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.test.tsx index 25339130a7..ddfe63e7e6 100644 --- a/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.test.tsx +++ b/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.test.tsx @@ -82,12 +82,6 @@ describe('EntityContextMenuItemBlueprint', () => { "boolean", ], }, - { - "items": { - "$ref": "#/properties/filter/anyOf/0/anyOf/0/additionalProperties/anyOf/0", - }, - "type": "array", - }, { "additionalProperties": false, "properties": { @@ -119,14 +113,7 @@ describe('EntityContextMenuItemBlueprint', () => { "additionalProperties": false, "properties": { "$contains": { - "anyOf": [ - { - "$ref": "#/properties/filter/anyOf/0", - }, - { - "type": "string", - }, - ], + "$ref": "#/properties/filter", }, }, "required": [ @@ -155,12 +142,6 @@ describe('EntityContextMenuItemBlueprint', () => { { "$ref": "#/properties/filter/anyOf/0/anyOf/0/additionalProperties/anyOf/0", }, - { - "items": { - "not": {}, - }, - "type": "array", - }, { "additionalProperties": false, "properties": { diff --git a/plugins/catalog-react/src/alpha/predicates/createEntityPredicateSchema.test.ts b/plugins/catalog-react/src/alpha/predicates/createEntityPredicateSchema.test.ts index 52e4d097af..3553fa932b 100644 --- a/plugins/catalog-react/src/alpha/predicates/createEntityPredicateSchema.test.ts +++ b/plugins/catalog-react/src/alpha/predicates/createEntityPredicateSchema.test.ts @@ -25,17 +25,16 @@ describe('createEntityPredicateSchema', () => { const predicates: EntityPredicate[] = [ 'string', '', - [], 1, { kind: 'component', 'spec.type': 'service' }, { 'metadata.tags': { $in: ['java'] } }, + { 'metadata.tags': { $contains: 'java' } }, { $all: [ { 'metadata.tags': { $contains: 'java' } }, { 'metadata.tags': { $contains: 'spring' } }, ], }, - { 'metadata.tags': ['java', 'spring'] }, { 'metadata.tags': { $in: ['go'] } }, { 'metadata.tags.0': 'java' }, { $not: { 'metadata.tags': { $in: ['java'] } } }, @@ -91,7 +90,8 @@ describe('createEntityPredicateSchema', () => { const predicates: Array< Exclude > = [ - ['service', 'website'], + [], + ['foo', 'bar'], { kind: { 1: 'foo' } }, { kind: { foo: 'bar' } }, { kind: { $unknown: 'foo' } }, @@ -104,6 +104,7 @@ describe('createEntityPredicateSchema', () => { { $not: { x: { $unknown: true } } }, { $not: { $all: [{ x: { $unknown: true } }] } }, { $unknown: 'foo' }, + { 'metadata.tags': ['foo', 'bar'] }, ]; it.each(predicates)('should reject invalid predicate %j', predicate => { diff --git a/plugins/catalog-react/src/alpha/predicates/createEntityPredicateSchema.ts b/plugins/catalog-react/src/alpha/predicates/createEntityPredicateSchema.ts index 2dcdadd826..c04a74db57 100644 --- a/plugins/catalog-react/src/alpha/predicates/createEntityPredicateSchema.ts +++ b/plugins/catalog-react/src/alpha/predicates/createEntityPredicateSchema.ts @@ -30,8 +30,6 @@ export function createEntityPredicateSchema(z: typeof zImpl) { z.boolean(), ]) as ZodType; - const onlyEmptyArraySchema = z.array(z.never()) as ZodType; - // eslint-disable-next-line prefer-const let valuePredicateSchema: ZodType; @@ -46,7 +44,6 @@ export function createEntityPredicateSchema(z: typeof zImpl) { z.union([ expressionSchema, primitiveSchema, - onlyEmptyArraySchema, z.object({ $all: z.array(predicateSchema) }), z.object({ $any: z.array(predicateSchema) }), z.object({ $not: predicateSchema }), @@ -55,10 +52,9 @@ export function createEntityPredicateSchema(z: typeof zImpl) { valuePredicateSchema = z.union([ primitiveSchema, - z.array(primitiveSchema), z.object({ $exists: z.boolean() }), z.object({ $in: z.array(primitiveSchema) }), - z.object({ $contains: z.union([expressionSchema, z.string()]) }), + z.object({ $contains: predicateSchema }), ]) as ZodType; return predicateSchema; diff --git a/plugins/catalog-react/src/alpha/predicates/types.ts b/plugins/catalog-react/src/alpha/predicates/types.ts index 8745610eae..f19026c01b 100644 --- a/plugins/catalog-react/src/alpha/predicates/types.ts +++ b/plugins/catalog-react/src/alpha/predicates/types.ts @@ -18,7 +18,6 @@ export type EntityPredicate = | EntityPredicateExpression | EntityPredicatePrimitive - | never[] | { $all: EntityPredicate[] } | { $any: EntityPredicate[] } | { $not: EntityPredicate }; @@ -33,10 +32,9 @@ export type EntityPredicateExpression = { /** @alpha */ export type EntityPredicateValue = | EntityPredicatePrimitive - | EntityPredicatePrimitive[] | { $exists: boolean } | { $in: EntityPredicatePrimitive[] } - | { $contains: EntityPredicateExpression | string }; + | { $contains: EntityPredicate }; /** @alpha */ export type EntityPredicatePrimitive = string | number | boolean;