Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
d264710
Define schemas for simple filter interface
nickpeihl Oct 29, 2025
5989e98
Add descriptions to schemas
nickpeihl Oct 29, 2025
f900770
Remove id and rename indexPattern to dataViewId
nickpeihl Oct 30, 2025
5037bbe
Merge remote-tracking branch 'upstream/main' into simple-filters-schema
nickpeihl Oct 31, 2025
fb0f138
Changes from node scripts/lint_ts_projects --fix
kibanamachine Oct 31, 2025
b49449a
Fix filter value schema arrays to be homogeneous
nickpeihl Nov 5, 2025
ab20892
Fix casing inconsistency
nickpeihl Nov 5, 2025
48689fc
Naming consistency
nickpeihl Nov 5, 2025
f13c024
Stricter discriminated filter conditions
nickpeihl Nov 5, 2025
539a159
Document controlledBy field
nickpeihl Nov 5, 2025
565848a
Remove duplicate stored filter schema
nickpeihl Nov 5, 2025
7f85963
Changes from node scripts/lint_ts_projects --fix
kibanamachine Nov 5, 2025
01553d3
Merge remote-tracking branch 'origin/simple-filters-schema' into simp…
nickpeihl Nov 5, 2025
51c30b1
Rename path
nickpeihl Nov 5, 2025
a2979a9
Merge remote-tracking branch 'refs/remotes/origin/simple-filters-sche…
nickpeihl Nov 5, 2025
1d27d0b
Add conversion functions from/to stored filters
nickpeihl Nov 5, 2025
54960ce
Add es-query-constants package
nickpeihl Nov 5, 2025
b9bc071
Merge remote-tracking branch 'origin/simple-filters-schema' into simp…
nickpeihl Nov 5, 2025
883b3b6
Rename stored filter schema to "storedFilterSchema" and "simpleFilter…
nickpeihl Nov 6, 2025
3cbf28b
Add constants package to avoid circular references
nickpeihl Nov 7, 2025
00bd945
Add isMultiIindex, filterType, and BWC legacy properties
nickpeihl Nov 7, 2025
8aa68b4
Changes from node scripts/generate codeowners
kibanamachine Nov 7, 2025
e72bb46
Merge branch 'main' into simple-filters-schema
nickpeihl Nov 7, 2025
6b5e025
Rename AsCodeFilter types
nickpeihl Nov 7, 2025
f94f926
Merge remote-tracking branch 'origin/simple-filters-schema' into simp…
nickpeihl Nov 7, 2025
d1c1ea2
As "asCode" prefix to exported schemas
nickpeihl Nov 7, 2025
27870ca
Don't export StoredFilter types
nickpeihl Nov 7, 2025
36da619
Use schema extend instead of spread
nickpeihl Nov 7, 2025
7702432
Remove unnecessary nested query object from DSL schema
nickpeihl Nov 7, 2025
6f3a0a2
Merge remote-tracking branch 'origin/simple-filters-schema' into simp…
nickpeihl Nov 7, 2025
be5747f
Fix type names and fixtures
nickpeihl Nov 7, 2025
899ba8a
Update comment
nickpeihl Nov 10, 2025
672a077
Update src/platform/packages/shared/kbn-es-query-constants/package.json
nickpeihl Nov 10, 2025
df7b5dc
Merge branch 'main' into simple-filters-schema
nickpeihl Nov 10, 2025
bd9b5d6
Merge remote-tracking branch 'origin/simple-filters-schema' into simp…
nickpeihl Nov 10, 2025
fb5dc8c
Merge remote-tracking branch 'origin/simple-filters-schema' into simp…
nickpeihl Nov 10, 2025
13f1a62
Better round-trip stored filter conversion
nickpeihl Nov 11, 2025
d64b421
Improve round-trip conversion
nickpeihl Nov 12, 2025
25316a0
Merge remote-tracking branch 'upstream/main' into simple-filters-tran…
nickpeihl Nov 12, 2025
0a930b4
Clean up post merge
nickpeihl Nov 12, 2025
f16f979
Clean up and bug fixes
nickpeihl Nov 18, 2025
dee2b0d
Clean ups
nickpeihl Nov 18, 2025
01687a6
Return early
nickpeihl Nov 18, 2025
7fc89e4
More early returns
nickpeihl Nov 18, 2025
f51ad53
More cleanups
nickpeihl Nov 18, 2025
cc08ab2
Test organization
nickpeihl Nov 19, 2025
24c5e35
Duplicate test cleanup
nickpeihl Nov 19, 2025
6cb4c93
Merge remote-tracking branch 'upstream/main' into simple-filters-tran…
nickpeihl Nov 19, 2025
ff77dbd
Throw early if stored filter is invalid
nickpeihl Nov 19, 2025
da409a6
Clean up unused export
nickpeihl Nov 19, 2025
50cff02
Refactor fromStoredFilter to use meta.type to determine conversion me…
nickpeihl Nov 20, 2025
f350dca
Update test
nickpeihl Nov 20, 2025
50678b2
Simplify conversions
nickpeihl Nov 20, 2025
8c7f02b
Minimize returning weak defaults
nickpeihl Nov 21, 2025
6672d63
Remove `negate` property from condition filters.
nickpeihl Nov 21, 2025
d2ab0dd
Remove pinned from AsCodeFilters
nickpeihl Nov 21, 2025
0c10777
Support format in range type AsCodeFilters
nickpeihl Nov 21, 2025
53a4487
Prefer consts
nickpeihl Nov 21, 2025
0cd3070
lint ts projects
nickpeihl Nov 21, 2025
265270c
OAS refinements
nickpeihl Nov 21, 2025
e6ef2e1
Remove unnecessary fixtures and tests used in debugging
nickpeihl Nov 21, 2025
ff8c7d0
Remove unused export
nickpeihl Nov 21, 2025
8472989
Test fixes
nickpeihl Nov 21, 2025
75d4c5d
Remove unused types
nickpeihl Nov 21, 2025
c7dc9f8
Fix test types
nickpeihl Nov 21, 2025
69099df
Merge branch 'main' into simple-filters-transforms
nickpeihl Nov 21, 2025
6b224f7
AsCodeFilters should not include pinned stored filters
nickpeihl Nov 26, 2025
6338af3
Fix missing negation on range filters
nickpeihl Nov 26, 2025
6c999d4
Merge remote-tracking branch 'upstream' into simple-filters-transforms
nickpeihl Dec 3, 2025
473bdc3
Move AsCode filter validation schemas and types
nickpeihl Dec 3, 2025
8405542
Move AsCode filter transform functions from `
nickpeihl Dec 3, 2025
37a85a2
Changes from node scripts/generate codeowners
kibanamachine Dec 3, 2025
af431eb
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine Dec 3, 2025
8d7df32
Move AS_CODE_FILTER_OPERATOR constant to its own
nickpeihl Dec 3, 2025
21eaa18
Merge branch 'simple-filters-transforms' of https://github.com/nickpe…
nickpeihl Dec 3, 2025
00a4a21
Changes from node scripts/generate codeowners
kibanamachine Dec 3, 2025
ae140e0
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine Dec 3, 2025
70f89dd
Do not return undefined stored filter properties
nickpeihl Dec 4, 2025
cf78b9d
Use snake_case for AsCodeFilter properties
nickpeihl Dec 4, 2025
e6f73bc
Merge remote-tracking branch 'upstream/main' into simple-filters-tran…
nickpeihl Jan 12, 2026
4afaeda
Remove negation operators in favor of negate property for all conditions
nickpeihl Jan 14, 2026
5bdb619
Simplify simple condition filter transform
nickpeihl Jan 15, 2026
22bff4b
Clean up negation handling (follow-up to 4afaeda)
nickpeihl Jan 15, 2026
e655e01
Fix recursive type
nickpeihl Jan 20, 2026
8cc0a78
Review feedback
nickpeihl Jan 20, 2026
756471f
Merge remote-tracking branch 'upstream' into simple-filters-transforms
nickpeihl Jan 20, 2026
3b29891
Remove isLegacyFilter check.
nickpeihl Jan 20, 2026
135a81e
Remove unnecessary `value` property from as code schema
nickpeihl Jan 22, 2026
dd93a49
Use an actual discriminated union for as code filters by adding a `ty…
nickpeihl Jan 22, 2026
288bbf8
Add spatial filter type similar to dsl but preserves SPATIAL type in …
nickpeihl Jan 22, 2026
b3fd494
Remove `filter_type` from as code filters using logic to preserve sto…
nickpeihl Jan 22, 2026
b73ca8b
Remove `key` field from as code filter schema
nickpeihl Jan 22, 2026
586817d
Remove "deprecated" from optional DSL filter properties
nickpeihl Jan 22, 2026
00a7d2a
Use constants for filter types
nickpeihl Jan 22, 2026
9117b66
Remove unused type guard
nickpeihl Jan 29, 2026
1aef0e7
Remvoe unnecessary detection of filter type from custom DSL filters
nickpeihl Jan 29, 2026
2f3dc0f
Merge branch 'main' into simple-filters-transforms
nickpeihl Jan 29, 2026
6c80f36
Merge branch 'main' into simple-filters-transforms
nickpeihl Feb 3, 2026
a76ca59
Use `operator` instead of `type` for condition filters
nickpeihl Feb 5, 2026
9799f1d
Remove unreachable code
nickpeihl Feb 5, 2026
6bc35e1
Add discriminator to conditionSchema
nickpeihl Feb 5, 2026
6521fe9
Function name clarification
nickpeihl Feb 5, 2026
f59453b
Merge branch 'main' into simple-filters-transforms
nickpeihl Feb 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ src/platform/packages/private/kbn-validate-oas @elastic/kibana-core
src/platform/packages/private/opentelemetry/kbn-metrics @elastic/kibana-core @elastic/stack-monitoring
src/platform/packages/private/opentelemetry/kbn-metrics-config @elastic/kibana-core
src/platform/packages/private/shared-ux/storybook/config @elastic/appex-sharedux
src/platform/packages/shared/as-code/filters-constants @elastic/kibana-presentation
src/platform/packages/shared/as-code/filters-schema @elastic/kibana-presentation
src/platform/packages/shared/as-code/filters-transforms @elastic/kibana-presentation
src/platform/packages/shared/chart-expressions-common @elastic/kibana-visualizations
src/platform/packages/shared/chart-test-jest-helpers @elastic/kibana-visualizations
src/platform/packages/shared/cloud @elastic/kibana-core
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@
"@kbn/apm-utils": "link:src/platform/packages/shared/kbn-apm-utils",
"@kbn/app-link-test-plugin": "link:src/platform/test/plugin_functional/plugins/app_link_test",
"@kbn/application-usage-test-plugin": "link:x-pack/platform/test/usage_collection/plugins/application_usage_test",
"@kbn/as-code-filters-constants": "link:src/platform/packages/shared/as-code/filters-constants",
"@kbn/as-code-filters-schema": "link:src/platform/packages/shared/as-code/filters-schema",
"@kbn/as-code-filters-transforms": "link:src/platform/packages/shared/as-code/filters-transforms",
"@kbn/audit-log-plugin": "link:x-pack/platform/test/security_api_integration/plugins/audit_log",
"@kbn/automatic-import-plugin": "link:x-pack/platform/plugins/shared/automatic_import",
"@kbn/automatic-import-v2-plugin": "link:x-pack/platform/plugins/shared/automatic_import_v2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/as-code-filters-constants

Constants that can be used by both `@kbn/as-code-filters-schema` and `@kbn/as-code-filters-transforms` packages to avoid circular references.
12 changes: 12 additions & 0 deletions src/platform/packages/shared/as-code/filters-constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { ASCODE_FILTER_OPERATOR } from './src/constants';
export { ASCODE_GROUPED_CONDITION_TYPE } from './src/constants';
export { ASCODE_FILTER_TYPE } from './src/constants';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../../../..',
roots: ['<rootDir>/src/platform/packages/shared/as-code/filters-constants'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/as-code-filters-constants",
"owner": "@elastic/kibana-presentation",
"group": "platform",
"visibility": "shared"
}
44 changes: 44 additions & 0 deletions src/platform/packages/shared/as-code/filters-constants/moon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This file is generated by the @kbn/moon package. Any manual edits will be erased!
# To extend this, write your extensions/overrides to 'moon.extend.yml'
# then regenerate this file with: 'node scripts/regenerate_moon_projects.js --update --filter @kbn/as-code-filters-constants'

$schema: https://moonrepo.dev/schemas/project.json
id: '@kbn/as-code-filters-constants'
type: unknown
owners:
defaultOwner: '@elastic/kibana-presentation'
toolchain:
default: node
language: typescript
project:
name: '@kbn/as-code-filters-constants'
description: Moon project for @kbn/as-code-filters-constants
channel: ''
owner: '@elastic/kibana-presentation'
metadata:
sourceRoot: src/platform/packages/shared/as-code/filters-constants
dependsOn: []
tags:
- shared-common
- package
- prod
- group-platform
- shared
- jest-unit-tests
fileGroups:
src:
- '**/*.ts'
- '!target/**/*'
tasks:
jest:
args:
- '--config'
- $projectRoot/jest.config.js
inputs:
- '@group(src)'
jestCI:
args:
- '--config'
- $projectRoot/jest.config.js
inputs:
- '@group(src)'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/as-code-filters-constants",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0",
"sideEffects": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

/**
* As Code Filter operator constants
* These operators are used in SimpleFilterCondition to specify how to match field values
*/
export const ASCODE_FILTER_OPERATOR = {
IS: 'is',
IS_ONE_OF: 'is_one_of',
EXISTS: 'exists',
RANGE: 'range',
} as const;
Comment thread
lukasolson marked this conversation as resolved.

export const ASCODE_GROUPED_CONDITION_TYPE = {
AND: 'and',
OR: 'or',
} as const;

export const ASCODE_FILTER_TYPE = {
CONDITION: 'condition',
GROUP: 'group',
DSL: 'dsl',
SPATIAL: 'spatial',
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@kbn/tsconfig-base/tsconfig.json",
"compilerOptions": {
"outDir": "target/types",
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
160 changes: 160 additions & 0 deletions src/platform/packages/shared/as-code/filters-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# @kbn/as-code-filters-schema

Validation schemas and TypeScript types for the **Kibana As Code Filter Interface**.

## Overview

This package provides runtime validation schemas and corresponding TypeScript types for filters in the Kibana As Code API. It uses `@kbn/config-schema` for validation and is designed for server-side use in API route handlers.

## Filter Structure

The As Code filter interface supports three main filter types:

### 1. Condition Filters

Single field-value comparisons with type-safe operators:

```typescript
import {
asCodeConditionFilterSchema,
type AsCodeConditionFilter,
} from '@kbn/as-code-filters-schema';

// Examples of condition filters:
const isFilter: AsCodeConditionFilter = {
condition: { field: 'status', operator: 'is', value: 'active' },
};

const isOneOfFilter: AsCodeConditionFilter = {
condition: { field: 'category', operator: 'is_one_of', value: ['A', 'B', 'C'] },
};

const rangeFilter: AsCodeConditionFilter = {
condition: { field: 'price', operator: 'range', value: { gte: 10, lte: 100 } },
negate: false, // Only range filters have negate property
};

const existsFilter: AsCodeConditionFilter = {
condition: { field: 'description', operator: 'exists' },
};
```

**Operators:**

- `is` / `is_not` - Single value comparison
- `is_one_of` / `is_not_one_of` - Array value comparison
- `range` - Numeric/date range (has `negate` property)
- `exists` / `not_exists` - Field existence check

### 2. Group Filters

Logical combinations of conditions with AND/OR:

```typescript
import { asCodeGroupFilterSchema, type AsCodeGroupFilter } from '@kbn/as-code-filters-schema';

const groupFilter: AsCodeGroupFilter = {
group: {
operator: 'and',
conditions: [
{ field: 'status', operator: 'is', value: 'active' },
{ field: 'priority', operator: 'range', value: { gte: 5 } },
],
},
negate: false, // Can negate entire group
};
```

Groups support nesting for complex logic:

```typescript
const nestedGroup: AsCodeGroupFilter = {
group: {
operator: 'or',
conditions: [
{ field: 'region', operator: 'is', value: 'US' },
{
group: {
operator: 'and',
conditions: [
{ field: 'region', operator: 'is', value: 'EU' },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could compress the number of operators and allow for more flexibility by using a negate param in each condition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I rather like this idea. We could get rid of NOT_EXISTS, IS_NOT, and IS_NOT_ONE_OF operators and allow negate on all operators. We could also introduce negation operators as a later feature if users request it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know when I can re-review!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4afaeda removes the *NOT* operators and introduces the optional negate boolean property in all condition types, including nested conditions in group filters. If we don't like the changes to the syntax, we could revert that commit. Or we could introduce the *NOT* operators as a feature later.

{ field: 'vip', operator: 'is', value: true },
],
},
},
],
},
};
```

### 3. DSL Filters

Raw Elasticsearch Query DSL for advanced queries:

```typescript
import { asCodeDSLFilterSchema, type AsCodeDSLFilter } from '@kbn/as-code-filters-schema';

const dslFilter: AsCodeDSLFilter = {
dsl: {
match_phrase: {
message: 'quick brown fox',
},
},
negate: false,
};
```

## Common Properties

All filters support these optional metadata properties:

```typescript
interface CommonProperties {
disabled?: boolean; // Filter is disabled
controlledBy?: string; // Component managing this filter
dataViewId?: string; // Associated data view
label?: string; // Human-readable label
isMultiIndex?: boolean; // Applies to multiple indices

// Legacy compatibility (deprecated):
filterType?: string; // Legacy filter type
key?: string; // Legacy field name
value?: string; // Legacy value
}
```

## Usage in API Routes

```typescript
import { asCodeFilterSchema, type AsCodeFilter } from '@kbn/as-code-filters-schema';

router.post(
{
path: '/api/dashboards/{id}/filters',
validate: {
body: schema.object({
filters: schema.arrayOf(asCodeFilterSchema),
}),
},
},
async (context, request, response) => {
const { filters } = request.body;
// filters is typed as AsCodeFilter[]
// ... process filters
}
);
```

## Exported Schemas

- `asCodeFilterSchema` - Main discriminated union schema
- `asCodeConditionFilterSchema` - Condition filter schema
- `asCodeGroupFilterSchema` - Group filter schema
- `asCodeDSLFilterSchema` - DSL filter schema

## Exported Types Inferred from Schemas

- `AsCodeFilter` - Main discriminated union type
- `AsCodeConditionFilter` - Condition filter type
- `AsCodeGroupFilter` - Group filter type
- `AsCodeDSLFilter` - DSL filter type
24 changes: 24 additions & 0 deletions src/platform/packages/shared/as-code/filters-schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export {
asCodeFilterSchema,
asCodeConditionFilterSchema,
asCodeGroupFilterSchema,
asCodeDSLFilterSchema,
asCodeSpatialFilterSchema,
} from './src/schemas/filter';

export type {
AsCodeFilter,
AsCodeConditionFilter,
AsCodeGroupFilter,
AsCodeDSLFilter,
AsCodeSpatialFilter,
} from './src/types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../../../..',
roots: ['<rootDir>/src/platform/packages/shared/as-code/filters-schema'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-common",
Copy link
Copy Markdown
Contributor Author

@nickpeihl nickpeihl Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, this would be shared-server, but Lens will need to use this in their schemas which are currently defined in a shared-common package. And common packages can not import production code from server packages.

"id": "@kbn/as-code-filters-schema",
"owner": "@elastic/kibana-presentation",
"group": "platform",
"visibility": "shared"
}
Loading
Loading