-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use HTTP request schemas to create types, use those types in the clie…
…nt (#59340) * wip * wip * wip * will this work? * wip but it works * pedro * remove thing * remove TODOs * fix type issue * add tests to check that alert index api works * Revert "add tests to check that alert index api works" This reverts commit 5d40ca18337cf8deb63a0291150780ec094db016. * Moved schema * undoing my evils * fix comments. fix incorrect import Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
655f23b
commit 193926f
Showing
18 changed files
with
192 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Schemas | ||
|
||
These schemas are used to validate, coerce, and provide types for the comms between the client, server, and ES. | ||
|
||
# Future work | ||
In the future, we may be able to locate these under 'server'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/endpoint/public/common/clone_http_fetch_query.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { cloneHttpFetchQuery } from './clone_http_fetch_query'; | ||
import { Immutable } from '../../common/types'; | ||
import { HttpFetchQuery } from '../../../../../src/core/public'; | ||
|
||
describe('cloneHttpFetchQuery', () => { | ||
it('can clone complex queries', () => { | ||
const query: Immutable<HttpFetchQuery> = { | ||
a: 'a', | ||
'1': 1, | ||
undefined, | ||
array: [1, 2, undefined], | ||
}; | ||
expect(cloneHttpFetchQuery(query)).toMatchInlineSnapshot(` | ||
Object { | ||
"1": 1, | ||
"a": "a", | ||
"array": Array [ | ||
1, | ||
2, | ||
undefined, | ||
], | ||
"undefined": undefined, | ||
} | ||
`); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/endpoint/public/common/clone_http_fetch_query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Immutable } from '../../common/types'; | ||
|
||
import { HttpFetchQuery } from '../../../../../src/core/public'; | ||
|
||
export function cloneHttpFetchQuery(query: Immutable<HttpFetchQuery>): HttpFetchQuery { | ||
const clone: HttpFetchQuery = {}; | ||
for (const [key, value] of Object.entries(query)) { | ||
if (Array.isArray(value)) { | ||
clone[key] = [...value]; | ||
} else { | ||
// Array.isArray is not removing ImmutableArray from the union. | ||
clone[key] = value as string | number | boolean; | ||
} | ||
} | ||
return clone; | ||
} |
Oops, something went wrong.