diff --git a/compiler/src/model/metamodel.ts b/compiler/src/model/metamodel.ts index 3802951a3c..8c28e2847d 100644 --- a/compiler/src/model/metamodel.ts +++ b/compiler/src/model/metamodel.ts @@ -209,6 +209,7 @@ export class Container extends VariantBase { export class Untagged extends VariantBase { kind: 'untagged' + untyped_variant: Inherits } /** diff --git a/compiler/src/model/utils.ts b/compiler/src/model/utils.ts index dc4f3787a8..ed9f92ae4c 100644 --- a/compiler/src/model/utils.ts +++ b/compiler/src/model/utils.ts @@ -1110,24 +1110,34 @@ export function parseVariantsTag (jsDoc: JSDoc[]): model.Variants | undefined { } } + if (type === 'internal') { + const pairs = parseKeyValues(jsDoc, values, 'tag', 'default') + assert(jsDoc, typeof pairs.tag === 'string', 'Internal variant requires a tag definition') + return { + kind: 'internal_tag', + nonExhaustive: nonExhaustive, + tag: pairs.tag, + defaultTag: pairs.default + } + } + if (type === 'untagged') { + const pairs = parseKeyValues(jsDoc, values, 'untyped') + assert(jsDoc, typeof pairs.untyped === 'string', 'Untagged variant requires an untyped definition') + const fqn = pairs.untyped.split('.') return { kind: 'untagged', - nonExhaustive: nonExhaustive + nonExhaustive: nonExhaustive, + untyped_variant: { + type: { + namespace: fqn.slice(0, fqn.length - 1).join('.'), + name: fqn[fqn.length - 1] + } + } } } - assert(jsDoc, type === 'internal', `Bad variant type: ${type}`) - - const pairs = parseKeyValues(jsDoc, values, 'tag', 'default') - assert(jsDoc, typeof pairs.tag === 'string', 'Internal variant requires a tag definition') - - return { - kind: 'internal_tag', - nonExhaustive: nonExhaustive, - tag: pairs.tag, - defaultTag: pairs.default - } + assert(jsDoc, false, `Bad variant type: ${type}`) } /** diff --git a/compiler/src/steps/validate-model.ts b/compiler/src/steps/validate-model.ts index 5c9b9a94ed..269ef660f6 100644 --- a/compiler/src/steps/validate-model.ts +++ b/compiler/src/steps/validate-model.ts @@ -559,14 +559,14 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma if (typeDef.type.kind !== 'union_of') { modelError('The "variants" tag only applies to unions') } else { - validateTaggedUnion(typeDef.type, typeDef.variants) + validateTaggedUnion(typeDef.name, typeDef.type, typeDef.variants) } } else { validateValueOf(typeDef.type, openGenerics) } } - function validateTaggedUnion (valueOf: model.UnionOf, variants: model.InternalTag | model.ExternalTag | model.Untagged): void { + function validateTaggedUnion (parentName: TypeName, valueOf: model.UnionOf, variants: model.InternalTag | model.ExternalTag | model.Untagged): void { if (variants.kind === 'external_tag') { // All items must have a 'variant' attribute const items = flattenUnionMembers(valueOf) @@ -611,9 +611,20 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma validateValueOf(valueOf, new Set()) } else if (variants.kind === 'untagged') { - const items = flattenUnionMembers(valueOf) + if (fqn(parentName) !== '_types.query_dsl:DecayFunction' && + fqn(parentName) !== '_types.query_dsl:DistanceFeatureQuery' && + fqn(parentName) !== '_types.query_dsl:RangeQuery') { + throw new Error(`Please contact the devtools team before adding new untagged variant ${fqn(parentName)}`) + } + + const untyped_variant = getTypeDef(variants.untyped_variant.type) + if (untyped_variant == null) { + modelError(`Type ${fqn(variants.untyped_variant.type)} not found`) + } + const items = flattenUnionMembers(valueOf) const baseTypes = new Set() + let found_untyped = false; for (const item of items) { if (item.kind !== 'instance_of') { @@ -628,6 +639,10 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma modelError(`Type ${fqn(item.type)} must be an interface to be used in an untagged union`) continue } + + if (fqn(item.type) === fqn(untyped_variant!.name)) { + found_untyped = true + } if (type.inherits == null) { modelError(`Type ${fqn(item.type)} must derive from a base type to be used in an untagged union`) @@ -657,6 +672,10 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma if (baseTypes.size !== 1) { modelError('All items of an untagged union must derive from the same common base type') } + + if (!found_untyped) { + modelError('The untyped variant of an untagged variant must be contained in the union items') + } } } diff --git a/docs/modeling-guide.md b/docs/modeling-guide.md index fab7329982..123a844acb 100644 --- a/docs/modeling-guide.md +++ b/docs/modeling-guide.md @@ -455,16 +455,17 @@ For example: ```ts export class MyTypeBase { ... } +export class MyTypeUntyped extends MyTypeBase {} export class MyTypeSpecialized1 extends MyTypeBase {} export class MyTypeSpecialized2 extends MyTypeBase {} export class MyTypeSpecialized3 extends MyTypeBase {} /** - * @codegen_names mytype1, mytypet2, mytype3 - * @variant untagged + * @codegen_names untyped, mytype1, mytypet2, mytype3 + * @variant untagged untyped=_types.MyTypeUntyped */ // Note: deserialization depends on value types -export type MyType = MyTypeSpecialized1 | MyTypeSpecialized2 | MyTypeSpecialized3 +export type MyType = MyTypeUntyped | MyTypeSpecialized1 | MyTypeSpecialized2 | MyTypeSpecialized3 ``` ### Shortcut properties diff --git a/output/schema/schema.json b/output/schema/schema.json index 6a7ea111e5..7947ab75dc 100644 --- a/output/schema/schema.json +++ b/output/schema/schema.json @@ -75116,7 +75116,7 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L28-L52" + "specLocation": "_types/query_dsl/compound.ts#L29-L53" }, { "inherits": { @@ -75168,7 +75168,7 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L54-L67" + "specLocation": "_types/query_dsl/compound.ts#L55-L68" }, { "kind": "enum", @@ -75434,57 +75434,45 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L69-L76" + "specLocation": "_types/query_dsl/compound.ts#L70-L77" }, { "attachedBehaviors": [ "AdditionalProperty" ], - "behaviors": [ - { - "generics": [ - { - "kind": "instance_of", - "type": { - "name": "Field", - "namespace": "_types" - } - }, - { - "generics": [ - { - "kind": "instance_of", - "type": { - "name": "DateMath", - "namespace": "_types" - } - }, - { - "kind": "instance_of", - "type": { - "name": "Duration", - "namespace": "_types" - } + "inherits": { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "Field", + "namespace": "_types" + } + }, + { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "DateMath", + "namespace": "_types" + } + }, + { + "kind": "instance_of", + "type": { + "name": "Duration", + "namespace": "_types" } - ], - "kind": "instance_of", - "type": { - "name": "DecayPlacement", - "namespace": "_types.query_dsl" } + ], + "kind": "instance_of", + "type": { + "name": "DecayPlacement", + "namespace": "_types.query_dsl" } - ], - "meta": { - "key": "field", - "value": "placement" - }, - "type": { - "name": "AdditionalProperty", - "namespace": "_spec_utils" } - } - ], - "inherits": { + ], "type": { "name": "DecayFunctionBase", "namespace": "_types.query_dsl" @@ -75496,7 +75484,7 @@ "namespace": "_types.query_dsl" }, "properties": [], - "specLocation": "_types/query_dsl/compound.ts#L189-L194" + "specLocation": "_types/query_dsl/compound.ts#L190-L190" }, { "inherits": { @@ -75527,10 +75515,19 @@ "namespace": "_types.query_dsl" }, "properties": [], - "specLocation": "_types/query_dsl/specialized.ts#L67-L70" + "specLocation": "_types/query_dsl/specialized.ts#L72-L75" }, { "inherits": { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "DateMath", + "namespace": "_types" + } + } + ], "type": { "name": "RangeQueryBase", "namespace": "_types.query_dsl" @@ -75542,100 +75539,6 @@ "namespace": "_types.query_dsl" }, "properties": [ - { - "description": "Greater than.", - "name": "gt", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "DateMath", - "namespace": "_types" - } - } - }, - { - "description": "Greater than or equal to.", - "name": "gte", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "DateMath", - "namespace": "_types" - } - } - }, - { - "description": "Less than.", - "name": "lt", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "DateMath", - "namespace": "_types" - } - } - }, - { - "description": "Less than or equal to.", - "name": "lte", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "DateMath", - "namespace": "_types" - } - } - }, - { - "name": "from", - "required": false, - "type": { - "items": [ - { - "kind": "instance_of", - "type": { - "name": "DateMath", - "namespace": "_types" - } - }, - { - "kind": "instance_of", - "type": { - "name": "null", - "namespace": "_builtins" - } - } - ], - "kind": "union_of" - } - }, - { - "name": "to", - "required": false, - "type": { - "items": [ - { - "kind": "instance_of", - "type": { - "name": "DateMath", - "namespace": "_types" - } - }, - { - "kind": "instance_of", - "type": { - "name": "null", - "namespace": "_builtins" - } - } - ], - "kind": "union_of" - } - }, { "description": "Date format used to convert `date` values in the query.", "name": "format", @@ -75661,10 +75564,11 @@ } } ], - "specLocation": "_types/query_dsl/term.ts#L116-L143" + "specLocation": "_types/query_dsl/term.ts#L146-L155" }, { "codegenNames": [ + "untyped", "date", "numeric", "geo" @@ -75674,9 +75578,16 @@ "name": "DecayFunction", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/compound.ts#L203-L208", + "specLocation": "_types/query_dsl/compound.ts#L193-L202", "type": { "items": [ + { + "kind": "instance_of", + "type": { + "name": "UntypedDecayFunction", + "namespace": "_types.query_dsl" + } + }, { "kind": "instance_of", "type": { @@ -75700,9 +75611,59 @@ } ], "kind": "union_of" + }, + "variants": { + "kind": "untagged", + "untyped_variant": { + "type": { + "name": "UntypedDecayFunction", + "namespace": "_types.query_dsl" + } + } } }, { + "attachedBehaviors": [ + "AdditionalProperty" + ], + "behaviors": [ + { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "TOrigin", + "namespace": "_types.query_dsl.DecayFunctionBase" + } + }, + { + "kind": "instance_of", + "type": { + "name": "TScale", + "namespace": "_types.query_dsl.DecayFunctionBase" + } + } + ], + "meta": { + "key": "field", + "value": "placement" + }, + "type": { + "name": "AdditionalProperty", + "namespace": "_spec_utils" + } + } + ], + "generics": [ + { + "name": "TOrigin", + "namespace": "_types.query_dsl.DecayFunctionBase" + }, + { + "name": "TScale", + "namespace": "_types.query_dsl.DecayFunctionBase" + } + ], "kind": "interface", "name": { "name": "DecayFunctionBase", @@ -75723,7 +75684,7 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L174-L180" + "specLocation": "_types/query_dsl/compound.ts#L175-L186" }, { "generics": [ @@ -75793,7 +75754,7 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L153-L172" + "specLocation": "_types/query_dsl/compound.ts#L154-L173" }, { "inherits": { @@ -75837,10 +75798,11 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L78-L90" + "specLocation": "_types/query_dsl/compound.ts#L79-L91" }, { "codegenNames": [ + "untyped", "geo", "date" ], @@ -75849,9 +75811,16 @@ "name": "DistanceFeatureQuery", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/specialized.ts#L72-L76", + "specLocation": "_types/query_dsl/specialized.ts#L77-L85", "type": { "items": [ + { + "kind": "instance_of", + "type": { + "name": "UntypedDistanceFeatureQuery", + "namespace": "_types.query_dsl" + } + }, { "kind": "instance_of", "type": { @@ -75868,6 +75837,15 @@ } ], "kind": "union_of" + }, + "variants": { + "kind": "untagged", + "untyped_variant": { + "type": { + "name": "UntypedDistanceFeatureQuery", + "namespace": "_types.query_dsl" + } + } } }, { @@ -75958,7 +75936,7 @@ } } ], - "specLocation": "_types/query_dsl/term.ts#L36-L41" + "specLocation": "_types/query_dsl/term.ts#L37-L42" }, { "description": "A reference to a field with formatting instructions on how to return the value", @@ -76113,7 +76091,7 @@ "name": "FieldValueFactorModifier", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/compound.ts#L307-L350" + "specLocation": "_types/query_dsl/compound.ts#L301-L344" }, { "kind": "interface", @@ -76172,7 +76150,7 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L132-L151" + "specLocation": "_types/query_dsl/compound.ts#L133-L152" }, { "kind": "enum", @@ -76206,7 +76184,7 @@ "name": "FunctionBoostMode", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/compound.ts#L279-L305" + "specLocation": "_types/query_dsl/compound.ts#L273-L299" }, { "esQuirk": "this container is valid without a variant. Despite being documented as a function, 'weight'\nis actually a container property that can be combined with a function. Comment in the ES code\n(SearchModule#registerScoreFunctions) says: Weight doesn't have its own parser, so every function\nsupports it out of the box. Can be a single function too when not associated to any other function,\nwhich is why it needs to be registered manually here.", @@ -76313,7 +76291,7 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L210-L250", + "specLocation": "_types/query_dsl/compound.ts#L204-L244", "variants": { "kind": "container" } @@ -76350,7 +76328,7 @@ "name": "FunctionScoreMode", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/compound.ts#L252-L277" + "specLocation": "_types/query_dsl/compound.ts#L246-L271" }, { "inherits": { @@ -76443,7 +76421,7 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L92-L118" + "specLocation": "_types/query_dsl/compound.ts#L93-L119" }, { "inherits": { @@ -76559,7 +76537,7 @@ } ], "shortcutProperty": "value", - "specLocation": "_types/query_dsl/term.ts#L43-L78" + "specLocation": "_types/query_dsl/term.ts#L44-L79" }, { "attachedBehaviors": [ @@ -76653,51 +76631,39 @@ "attachedBehaviors": [ "AdditionalProperty" ], - "behaviors": [ - { - "generics": [ - { - "kind": "instance_of", - "type": { - "name": "Field", - "namespace": "_types" - } - }, - { - "generics": [ - { - "kind": "instance_of", - "type": { - "name": "GeoLocation", - "namespace": "_types" - } - }, - { - "kind": "instance_of", - "type": { - "name": "Distance", - "namespace": "_types" - } + "inherits": { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "Field", + "namespace": "_types" + } + }, + { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "GeoLocation", + "namespace": "_types" + } + }, + { + "kind": "instance_of", + "type": { + "name": "Distance", + "namespace": "_types" } - ], - "kind": "instance_of", - "type": { - "name": "DecayPlacement", - "namespace": "_types.query_dsl" } + ], + "kind": "instance_of", + "type": { + "name": "DecayPlacement", + "namespace": "_types.query_dsl" } - ], - "meta": { - "key": "field", - "value": "placement" - }, - "type": { - "name": "AdditionalProperty", - "namespace": "_spec_utils" } - } - ], - "inherits": { + ], "type": { "name": "DecayFunctionBase", "namespace": "_types.query_dsl" @@ -76709,7 +76675,7 @@ "namespace": "_types.query_dsl" }, "properties": [], - "specLocation": "_types/query_dsl/compound.ts#L196-L201" + "specLocation": "_types/query_dsl/compound.ts#L191-L191" }, { "inherits": { @@ -76740,7 +76706,7 @@ "namespace": "_types.query_dsl" }, "properties": [], - "specLocation": "_types/query_dsl/specialized.ts#L62-L65" + "specLocation": "_types/query_dsl/specialized.ts#L67-L70" }, { "attachedBehaviors": [ @@ -77293,7 +77259,7 @@ } } ], - "specLocation": "_types/query_dsl/term.ts#L80-L85" + "specLocation": "_types/query_dsl/term.ts#L81-L86" }, { "kind": "interface", @@ -77974,7 +77940,7 @@ "name": "Like", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/specialized.ts#L186-L191", + "specLocation": "_types/query_dsl/specialized.ts#L195-L200", "type": { "items": [ { @@ -78106,7 +78072,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L162-L184" + "specLocation": "_types/query_dsl/specialized.ts#L171-L193" }, { "inherits": { @@ -78909,7 +78875,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L78-L160" + "specLocation": "_types/query_dsl/specialized.ts#L87-L169" }, { "inherits": { @@ -79176,7 +79142,7 @@ "name": "MultiValueMode", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/compound.ts#L352-L369" + "specLocation": "_types/query_dsl/compound.ts#L346-L363" }, { "inherits": { @@ -79260,6 +79226,15 @@ }, { "inherits": { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "double", + "namespace": "_types" + } + } + ], "type": { "name": "RangeQueryBase", "namespace": "_types.query_dsl" @@ -79270,60 +79245,24 @@ "name": "NumberRangeQuery", "namespace": "_types.query_dsl" }, - "properties": [ - { - "description": "Greater than.", - "name": "gt", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "double", - "namespace": "_types" - } - } - }, - { - "description": "Greater than or equal to.", - "name": "gte", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "double", - "namespace": "_types" - } - } - }, - { - "description": "Less than.", - "name": "lt", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "double", - "namespace": "_types" - } - } - }, - { - "description": "Less than or equal to.", - "name": "lte", - "required": false, - "type": { + "properties": [], + "specLocation": "_types/query_dsl/term.ts#L157-L157" + }, + { + "attachedBehaviors": [ + "AdditionalProperty" + ], + "inherits": { + "generics": [ + { "kind": "instance_of", "type": { - "name": "double", + "name": "Field", "namespace": "_types" } - } - }, - { - "name": "from", - "required": false, - "type": { - "items": [ + }, + { + "generics": [ { "kind": "instance_of", "type": { @@ -79331,92 +79270,21 @@ "namespace": "_types" } }, - { - "kind": "instance_of", - "type": { - "name": "null", - "namespace": "_builtins" - } - } - ], - "kind": "union_of" - } - }, - { - "name": "to", - "required": false, - "type": { - "items": [ { "kind": "instance_of", "type": { "name": "double", "namespace": "_types" } - }, - { - "kind": "instance_of", - "type": { - "name": "null", - "namespace": "_builtins" - } } ], - "kind": "union_of" - } - } - ], - "specLocation": "_types/query_dsl/term.ts#L145-L164" - }, - { - "attachedBehaviors": [ - "AdditionalProperty" - ], - "behaviors": [ - { - "generics": [ - { - "kind": "instance_of", - "type": { - "name": "Field", - "namespace": "_types" - } - }, - { - "generics": [ - { - "kind": "instance_of", - "type": { - "name": "double", - "namespace": "_types" - } - }, - { - "kind": "instance_of", - "type": { - "name": "double", - "namespace": "_types" - } - } - ], - "kind": "instance_of", - "type": { - "name": "DecayPlacement", - "namespace": "_types.query_dsl" - } + "kind": "instance_of", + "type": { + "name": "DecayPlacement", + "namespace": "_types.query_dsl" } - ], - "meta": { - "key": "field", - "value": "placement" - }, - "type": { - "name": "AdditionalProperty", - "namespace": "_spec_utils" } - } - ], - "inherits": { + ], "type": { "name": "DecayFunctionBase", "namespace": "_types.query_dsl" @@ -79428,7 +79296,7 @@ "namespace": "_types.query_dsl" }, "properties": [], - "specLocation": "_types/query_dsl/compound.ts#L182-L187" + "specLocation": "_types/query_dsl/compound.ts#L189-L189" }, { "kind": "enum", @@ -79622,7 +79490,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L193-L230" + "specLocation": "_types/query_dsl/specialized.ts#L202-L239" }, { "kind": "interface", @@ -79656,7 +79524,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L253-L262" + "specLocation": "_types/query_dsl/specialized.ts#L262-L271" }, { "inherits": { @@ -79715,7 +79583,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L232-L251", + "specLocation": "_types/query_dsl/specialized.ts#L241-L260", "variants": { "kind": "container" } @@ -79781,7 +79649,7 @@ } ], "shortcutProperty": "value", - "specLocation": "_types/query_dsl/term.ts#L87-L106" + "specLocation": "_types/query_dsl/term.ts#L88-L107" }, { "kind": "interface", @@ -81272,22 +81140,30 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L127-L130" + "specLocation": "_types/query_dsl/compound.ts#L128-L131" }, { "codegenNames": [ + "untyped", "date", "number", - "terms" + "term" ], "kind": "type_alias", "name": { "name": "RangeQuery", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/term.ts#L187-L189", + "specLocation": "_types/query_dsl/term.ts#L161-L166", "type": { "items": [ + { + "kind": "instance_of", + "type": { + "name": "UntypedRangeQuery", + "namespace": "_types.query_dsl" + } + }, { "kind": "instance_of", "type": { @@ -81305,15 +81181,30 @@ { "kind": "instance_of", "type": { - "name": "TermsRangeQuery", + "name": "TermRangeQuery", "namespace": "_types.query_dsl" } } ], "kind": "union_of" + }, + "variants": { + "kind": "untagged", + "untyped_variant": { + "type": { + "name": "UntypedRangeQuery", + "namespace": "_types.query_dsl" + } + } } }, { + "generics": [ + { + "name": "T", + "namespace": "_types.query_dsl.RangeQueryBase" + } + ], "inherits": { "type": { "name": "QueryBase", @@ -81327,20 +81218,114 @@ }, "properties": [ { - "description": "Indicates how the range query matches values for `range` fields.", - "name": "relation", + "description": "Indicates how the range query matches values for `range` fields.", + "name": "relation", + "required": false, + "serverDefault": "intersects", + "type": { + "kind": "instance_of", + "type": { + "name": "RangeRelation", + "namespace": "_types.query_dsl" + } + } + }, + { + "description": "Greater than.", + "name": "gt", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "T", + "namespace": "_types.query_dsl.RangeQueryBase" + } + } + }, + { + "description": "Greater than or equal to.", + "name": "gte", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "T", + "namespace": "_types.query_dsl.RangeQueryBase" + } + } + }, + { + "description": "Less than.", + "name": "lt", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "T", + "namespace": "_types.query_dsl.RangeQueryBase" + } + } + }, + { + "description": "Less than or equal to.", + "name": "lte", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "T", + "namespace": "_types.query_dsl.RangeQueryBase" + } + } + }, + { + "name": "from", + "required": false, + "type": { + "items": [ + { + "kind": "instance_of", + "type": { + "name": "T", + "namespace": "_types.query_dsl.RangeQueryBase" + } + }, + { + "kind": "instance_of", + "type": { + "name": "null", + "namespace": "_builtins" + } + } + ], + "kind": "union_of" + } + }, + { + "name": "to", "required": false, - "serverDefault": "intersects", "type": { - "kind": "instance_of", - "type": { - "name": "RangeRelation", - "namespace": "_types.query_dsl" - } + "items": [ + { + "kind": "instance_of", + "type": { + "name": "T", + "namespace": "_types.query_dsl.RangeQueryBase" + } + }, + { + "kind": "instance_of", + "type": { + "name": "null", + "namespace": "_builtins" + } + } + ], + "kind": "union_of" } } ], - "specLocation": "_types/query_dsl/term.ts#L108-L114" + "specLocation": "_types/query_dsl/term.ts#L109-L133" }, { "kind": "enum", @@ -81362,7 +81347,7 @@ "name": "RangeRelation", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/term.ts#L191-L204" + "specLocation": "_types/query_dsl/term.ts#L168-L181" }, { "kind": "interface", @@ -81371,7 +81356,7 @@ "namespace": "_types.query_dsl" }, "properties": [], - "specLocation": "_types/query_dsl/specialized.ts#L264-L264" + "specLocation": "_types/query_dsl/specialized.ts#L273-L273" }, { "inherits": { @@ -81386,7 +81371,7 @@ "namespace": "_types.query_dsl" }, "properties": [], - "specLocation": "_types/query_dsl/specialized.ts#L266-L266" + "specLocation": "_types/query_dsl/specialized.ts#L275-L275" }, { "inherits": { @@ -81414,7 +81399,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L268-L273" + "specLocation": "_types/query_dsl/specialized.ts#L277-L282" }, { "inherits": { @@ -81442,7 +81427,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L275-L280" + "specLocation": "_types/query_dsl/specialized.ts#L284-L289" }, { "inherits": { @@ -81482,7 +81467,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L282-L291" + "specLocation": "_types/query_dsl/specialized.ts#L291-L300" }, { "inherits": { @@ -81558,7 +81543,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L293-L316" + "specLocation": "_types/query_dsl/specialized.ts#L302-L325" }, { "inherits": { @@ -81650,7 +81635,7 @@ } ], "shortcutProperty": "value", - "specLocation": "_types/query_dsl/term.ts#L206-L236" + "specLocation": "_types/query_dsl/term.ts#L183-L213" }, { "inherits": { @@ -81698,7 +81683,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L372-L376" + "specLocation": "_types/query_dsl/specialized.ts#L381-L385" }, { "inherits": { @@ -81726,7 +81711,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L318-L324" + "specLocation": "_types/query_dsl/specialized.ts#L327-L333" }, { "kind": "interface", @@ -81748,7 +81733,7 @@ } } ], - "specLocation": "_types/query_dsl/compound.ts#L120-L125" + "specLocation": "_types/query_dsl/compound.ts#L121-L126" }, { "inherits": { @@ -81800,7 +81785,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L326-L340" + "specLocation": "_types/query_dsl/specialized.ts#L335-L349" }, { "inherits": { @@ -81886,7 +81871,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L357-L370" + "specLocation": "_types/query_dsl/specialized.ts#L366-L379" }, { "attachedBehaviors": [ @@ -81945,7 +81930,7 @@ } } ], - "specLocation": "_types/query_dsl/specialized.ts#L342-L355" + "specLocation": "_types/query_dsl/specialized.ts#L351-L364" }, { "kind": "enum", @@ -82946,7 +82931,31 @@ } ], "shortcutProperty": "value", - "specLocation": "_types/query_dsl/term.ts#L238-L252" + "specLocation": "_types/query_dsl/term.ts#L215-L229" + }, + { + "inherits": { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" + } + } + ], + "type": { + "name": "RangeQueryBase", + "namespace": "_types.query_dsl" + } + }, + "kind": "interface", + "name": { + "name": "TermRangeQuery", + "namespace": "_types.query_dsl" + }, + "properties": [], + "specLocation": "_types/query_dsl/term.ts#L159-L159" }, { "kind": "interface", @@ -83000,7 +83009,7 @@ } } ], - "specLocation": "_types/query_dsl/term.ts#L266-L271" + "specLocation": "_types/query_dsl/term.ts#L243-L248" }, { "attachedBehaviors": [ @@ -83046,7 +83055,7 @@ "namespace": "_types.query_dsl" }, "properties": [], - "specLocation": "_types/query_dsl/term.ts#L254-L259" + "specLocation": "_types/query_dsl/term.ts#L231-L236" }, { "codegenNames": [ @@ -83058,7 +83067,7 @@ "name": "TermsQueryField", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/term.ts#L261-L264", + "specLocation": "_types/query_dsl/term.ts#L238-L241", "type": { "items": [ { @@ -83082,116 +83091,6 @@ "kind": "union_of" } }, - { - "inherits": { - "type": { - "name": "RangeQueryBase", - "namespace": "_types.query_dsl" - } - }, - "kind": "interface", - "name": { - "name": "TermsRangeQuery", - "namespace": "_types.query_dsl" - }, - "properties": [ - { - "description": "Greater than.", - "name": "gt", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "string", - "namespace": "_builtins" - } - } - }, - { - "description": "Greater than or equal to.", - "name": "gte", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "string", - "namespace": "_builtins" - } - } - }, - { - "description": "Less than.", - "name": "lt", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "string", - "namespace": "_builtins" - } - } - }, - { - "description": "Less than or equal to.", - "name": "lte", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "string", - "namespace": "_builtins" - } - } - }, - { - "name": "from", - "required": false, - "type": { - "items": [ - { - "kind": "instance_of", - "type": { - "name": "string", - "namespace": "_builtins" - } - }, - { - "kind": "instance_of", - "type": { - "name": "null", - "namespace": "_builtins" - } - } - ], - "kind": "union_of" - } - }, - { - "name": "to", - "required": false, - "type": { - "items": [ - { - "kind": "instance_of", - "type": { - "name": "string", - "namespace": "_builtins" - } - }, - { - "kind": "instance_of", - "type": { - "name": "null", - "namespace": "_builtins" - } - } - ], - "kind": "union_of" - } - } - ], - "specLocation": "_types/query_dsl/term.ts#L166-L185" - }, { "inherits": { "type": { @@ -83245,7 +83144,7 @@ } } ], - "specLocation": "_types/query_dsl/term.ts#L273-L286" + "specLocation": "_types/query_dsl/term.ts#L250-L263" }, { "inherits": { @@ -83418,7 +83317,105 @@ } } ], - "specLocation": "_types/query_dsl/term.ts#L288-L290" + "specLocation": "_types/query_dsl/term.ts#L265-L267" + }, + { + "attachedBehaviors": [ + "AdditionalProperty" + ], + "inherits": { + "generics": [ + { + "kind": "instance_of", + "type": { + "name": "Field", + "namespace": "_types" + } + }, + { + "kind": "user_defined_value" + } + ], + "type": { + "name": "DecayFunctionBase", + "namespace": "_types.query_dsl" + } + }, + "kind": "interface", + "name": { + "name": "UntypedDecayFunction", + "namespace": "_types.query_dsl" + }, + "properties": [], + "specLocation": "_types/query_dsl/compound.ts#L188-L188" + }, + { + "inherits": { + "generics": [ + { + "kind": "user_defined_value" + }, + { + "kind": "user_defined_value" + } + ], + "type": { + "name": "DistanceFeatureQueryBase", + "namespace": "_types.query_dsl" + } + }, + "kind": "interface", + "name": { + "name": "UntypedDistanceFeatureQuery", + "namespace": "_types.query_dsl" + }, + "properties": [], + "specLocation": "_types/query_dsl/specialized.ts#L62-L65" + }, + { + "inherits": { + "generics": [ + { + "kind": "user_defined_value" + } + ], + "type": { + "name": "RangeQueryBase", + "namespace": "_types.query_dsl" + } + }, + "kind": "interface", + "name": { + "name": "UntypedRangeQuery", + "namespace": "_types.query_dsl" + }, + "properties": [ + { + "description": "Date format used to convert `date` values in the query.", + "name": "format", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "DateFormat", + "namespace": "_types" + } + } + }, + { + "description": "Coordinated Universal Time (UTC) offset or IANA time zone used to convert `date` values in the query to UTC.", + "name": "time_zone", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "TimeZone", + "namespace": "_types" + } + } + } + ], + "specLocation": "_types/query_dsl/term.ts#L135-L144" }, { "inherits": { @@ -83543,7 +83540,7 @@ } ], "shortcutProperty": "value", - "specLocation": "_types/query_dsl/term.ts#L292-L309" + "specLocation": "_types/query_dsl/term.ts#L269-L286" }, { "inherits": { diff --git a/specification/_types/query_dsl/compound.ts b/specification/_types/query_dsl/compound.ts index d613b08a76..7e256f0385 100644 --- a/specification/_types/query_dsl/compound.ts +++ b/specification/_types/query_dsl/compound.ts @@ -24,6 +24,7 @@ import { double, float, long } from '@_types/Numeric' import { Script } from '@_types/Scripting' import { DateMath, Duration } from '@_types/Time' import { QueryBase, QueryContainer } from './abstractions' +import { UserDefinedValue } from '@spec_utils/UserDefinedValue' export class BoolQuery extends QueryBase { /** @@ -171,7 +172,12 @@ export class DecayPlacement { origin?: TOrigin } -export class DecayFunctionBase { +/** + * @behavior_meta AdditionalProperty key=field value=placement + */ +export class DecayFunctionBase + implements AdditionalProperty +{ /** * Determines how the distance is calculated when a field used for computing the decay contains multiple values. * @server_default min @@ -179,30 +185,18 @@ export class DecayFunctionBase { multi_value_mode?: MultiValueMode } -/** - * @behavior_meta AdditionalProperty key=field value=placement - */ -export class NumericDecayFunction - extends DecayFunctionBase - implements AdditionalProperty> {} - -/** - * @behavior_meta AdditionalProperty key=field value=placement - */ -export class DateDecayFunction - extends DecayFunctionBase - implements AdditionalProperty> {} +export class UntypedDecayFunction extends DecayFunctionBase {} +export class NumericDecayFunction extends DecayFunctionBase> {} +export class DateDecayFunction extends DecayFunctionBase> {} +export class GeoDecayFunction extends DecayFunctionBase> {} /** - * @behavior_meta AdditionalProperty key=field value=placement + * @codegen_names untyped, date, numeric, geo + * @variants untagged untyped=_types.query_dsl.UntypedDecayFunction */ -export class GeoDecayFunction - extends DecayFunctionBase - implements AdditionalProperty> {} - -/** @codegen_names date, numeric, geo */ // Note: deserialization depends on value types export type DecayFunction = + | UntypedDecayFunction | DateDecayFunction | NumericDecayFunction | GeoDecayFunction diff --git a/specification/_types/query_dsl/specialized.ts b/specification/_types/query_dsl/specialized.ts index 29fb2d81c4..5d9997f5fd 100644 --- a/specification/_types/query_dsl/specialized.ts +++ b/specification/_types/query_dsl/specialized.ts @@ -59,6 +59,11 @@ export class DistanceFeatureQueryBase extends QueryBase { field: Field } +export class UntypedDistanceFeatureQuery extends DistanceFeatureQueryBase< + UserDefinedValue, + UserDefinedValue +> {} + export class GeoDistanceFeatureQuery extends DistanceFeatureQueryBase< GeoLocation, Distance @@ -70,11 +75,12 @@ export class DateDistanceFeatureQuery extends DistanceFeatureQueryBase< > {} /** - * @codegen_names geo, date - * @variants untagged + * @codegen_names untyped, geo, date + * @variants untagged untyped=_types.query_dsl.UntypedDistanceFeatureQuery */ // Note: deserialization depends on value types export type DistanceFeatureQuery = + | UntypedDistanceFeatureQuery | GeoDistanceFeatureQuery | DateDistanceFeatureQuery diff --git a/specification/_types/query_dsl/term.ts b/specification/_types/query_dsl/term.ts index 6de7bd40c2..e1a9f76347 100644 --- a/specification/_types/query_dsl/term.ts +++ b/specification/_types/query_dsl/term.ts @@ -32,6 +32,7 @@ import { Script } from '@_types/Scripting' import { DateFormat, DateMath, TimeZone } from '@_types/Time' import { QueryBase } from './abstractions' import { AdditionalProperty } from '@spec_utils/behaviors' +import { UserDefinedValue } from '@spec_utils/UserDefinedValue' export class ExistsQuery extends QueryBase { /** @@ -129,6 +130,9 @@ export class RangeQueryBase extends QueryBase { lte?: T from?: T | null to?: T | null +} + +export class UntypedRangeQuery extends RangeQueryBase { /** * Date format used to convert `date` values in the query. */ @@ -139,18 +143,27 @@ export class RangeQueryBase extends QueryBase { time_zone?: TimeZone } -export class DateRangeQuery extends RangeQueryBase {} +export class DateRangeQuery extends RangeQueryBase { + /** + * Date format used to convert `date` values in the query. + */ + format?: DateFormat + /** + * Coordinated Universal Time (UTC) offset or IANA time zone used to convert `date` values in the query to UTC. + */ + time_zone?: TimeZone +} export class NumberRangeQuery extends RangeQueryBase {} export class TermRangeQuery extends RangeQueryBase {} /** - * @codegen_names date, number, term - * @variants untagged + * @codegen_names untyped, date, number, term + * @variants untagged untyped=_types.query_dsl.UntypedRangeQuery */ // Note: deserialization depends on value types -export type RangeQuery = DateRangeQuery | NumberRangeQuery | TermRangeQuery +export type RangeQuery = UntypedRangeQuery | DateRangeQuery | NumberRangeQuery | TermRangeQuery export enum RangeRelation { /** diff --git a/typescript-generator/src/metamodel.ts b/typescript-generator/src/metamodel.ts index 3802951a3c..8c28e2847d 100644 --- a/typescript-generator/src/metamodel.ts +++ b/typescript-generator/src/metamodel.ts @@ -209,6 +209,7 @@ export class Container extends VariantBase { export class Untagged extends VariantBase { kind: 'untagged' + untyped_variant: Inherits } /**