Skip to content

Commit 45e9f44

Browse files
authored
Rename ESQL version, add constants for default versions (#2534) (#2535)
1 parent 3b02342 commit 45e9f44

File tree

5 files changed

+66
-10
lines changed

5 files changed

+66
-10
lines changed

compiler/src/steps/validate-model.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as model from '../model/metamodel'
2121
import { ValidationErrors } from '../validation-errors'
2222
import { JsonSpec } from '../model/json-spec'
2323
import assert from 'assert'
24+
import { TypeName } from '../model/metamodel'
2425

2526
// Superclasses (i.e. non-leaf types, who are inherited or implemented) that are ok to be used as field types because
2627
// they're used as definition reuse and not as polymorphic types.
@@ -170,8 +171,14 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
170171
})
171172
}
172173

173-
// ErrorResponse is not referenced anywhere, but any API could return it if an error happens.
174-
validateTypeRef({ namespace: '_types', name: 'ErrorResponseBase' }, undefined, new Set())
174+
const additionalRoots: TypeName[] = [
175+
// ErrorResponse is not referenced anywhere, but any API could return it if an error happens.
176+
{ namespace: '_types', name: 'ErrorResponseBase' },
177+
// ESQL base versions are pseudo-constants
178+
{ namespace: 'esql._types', name: 'BaseStatefulEsqlVersion' },
179+
{ namespace: 'esql._types', name: 'BaseServerlessEsqlVersion' }
180+
]
181+
additionalRoots.forEach(t => validateTypeRef(t, undefined, new Set()))
175182

176183
// ----- Alright, let's go!
177184

output/schema/schema.json

Lines changed: 29 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/typescript/types.ts

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/esql/_types/Version.ts renamed to specification/esql/_types/EsqlVersion.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,29 @@
2020
/**
2121
* The version of the ES|QL language in which the "query" field was written.
2222
*/
23-
export enum Version {
23+
export enum EsqlVersion {
2424
/**
2525
* Run against the first version of ES|QL.
2626
* @codegen_name V2024_04_01
2727
*/
2828
'2024.04.01'
2929
}
30+
31+
// Note: ideally this should be a constant of type EsqlVersion, but the schema.json model doesn't
32+
// has support for this. So define a new type that is just a literal value, to be used by code generators.
33+
34+
/**
35+
* Version of the ES|QL language that should be used by default in stateful client libraries.
36+
*
37+
* This value is guaranteed to be stable within a major version of the Elastic Stack, even if newer versions
38+
* of the ES|QL language are added within that major version.
39+
*/
40+
export type BaseStatefulEsqlVersion = '2024.04.01'
41+
42+
/**
43+
* Version of the ES|QL language that should be used by default in serverless client libraries.
44+
*
45+
* This value is guaranteed to be stable for a given value of the Serverless API version, even if newer versions
46+
* of the ES|QL language are added within that API version.
47+
*/
48+
export type BaseServerlessEsqlVersion = '2024.04.01'

specification/esql/query/QueryRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import { RequestBase } from '@_types/Base'
2121
import { QueryContainer } from '@_types/query_dsl/abstractions'
2222
import { ScalarValue } from '@_types/common'
23-
import { Version } from '@esql/_types/Version'
23+
import { EsqlVersion } from '@esql/_types/EsqlVersion'
2424

2525
/**
2626
* Executes an ES|QL request
@@ -64,6 +64,6 @@ export interface Request extends RequestBase {
6464
/**
6565
* The version of the ES|QL language in which the "query" field was written.
6666
*/
67-
version: Version
67+
version: EsqlVersion
6868
}
6969
}

0 commit comments

Comments
 (0)