[ML] Fix runtime field validations not supporting special script types (#122469) (#125300)

* Fix validations not handling extra things like params or lang

* Add translations

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit f8d932f70a)
This commit is contained in:
Quynh Nguyen 2022-02-10 15:07:37 -06:00 committed by GitHub
parent 27362eb699
commit d5a9f0b375
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 39 deletions

View file

@ -14,11 +14,12 @@ export function isRuntimeField(arg: unknown): arg is estypes.MappingRuntimeField
return (
((isPopulatedObject(arg, ['type']) && Object.keys(arg).length === 1) ||
(isPopulatedObject(arg, ['type', 'script']) &&
Object.keys(arg).length === 2 &&
// Can be a string
(typeof arg.script === 'string' ||
(isPopulatedObject(arg.script, ['source']) &&
Object.keys(arg.script).length === 1 &&
typeof arg.script.source === 'string')))) &&
// Can be InlineScript
(isPopulatedObject(arg.script, ['source']) && typeof arg.script.source === 'string') ||
// Can be StoredScriptId
(isPopulatedObject(arg.script, ['id']) && typeof arg.script.id === 'string')))) &&
RUNTIME_FIELD_TYPES.includes(arg.type as RuntimeType)
);
}