fix: disable array type in entity predicate types and zod schema validator

Signed-off-by: Sandor Karpf <sandor.karpf@lastpass.com>
This commit is contained in:
Sandor Karpf
2025-12-15 18:32:56 +01:00
parent 8cf6944d82
commit e382000997
7 changed files with 10 additions and 74 deletions
+1 -3
View File
@@ -478,7 +478,6 @@ export const EntityIconLinkBlueprint: ExtensionBlueprint<{
export type EntityPredicate =
| EntityPredicateExpression
| EntityPredicatePrimitive
| never[]
| {
$all: EntityPredicate[];
}
@@ -507,7 +506,6 @@ export function entityPredicateToFilterFunction<T extends JsonValue>(
// @alpha (undocumented)
export type EntityPredicateValue =
| EntityPredicatePrimitive
| EntityPredicatePrimitive[]
| {
$exists: boolean;
}
@@ -515,7 +513,7 @@ export type EntityPredicateValue =
$in: EntityPredicatePrimitive[];
}
| {
$contains: EntityPredicateExpression | string;
$contains: EntityPredicate;
};
// @alpha
@@ -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": {
@@ -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": {
@@ -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": {
@@ -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<EntityPredicate | unknown, EntityPredicate>
> = [
['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 => {
@@ -30,8 +30,6 @@ export function createEntityPredicateSchema(z: typeof zImpl) {
z.boolean(),
]) as ZodType<EntityPredicatePrimitive>;
const onlyEmptyArraySchema = z.array(z.never()) as ZodType<never[]>;
// eslint-disable-next-line prefer-const
let valuePredicateSchema: ZodType<EntityPredicateValue>;
@@ -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<EntityPredicateValue>;
return predicateSchema;
@@ -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;