-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into chore/apollo-3
- Loading branch information
Showing
506 changed files
with
6,077 additions
and
3,270 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
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Observable } from 'rxjs'; | ||
import { | ||
ISearchContext, | ||
TSearchStrategyProvider, | ||
ISearchStrategy, | ||
} from '../../../src/plugins/data/public'; | ||
|
||
import { ASYNC_DEMO_SEARCH_STRATEGY, IAsyncDemoResponse } from '../common'; | ||
import { ASYNC_SEARCH_STRATEGY } from '../../../x-pack/plugins/data_enhanced/public'; | ||
|
||
/** | ||
* This demo search strategy provider simply provides a shortcut for calling the DEMO_ASYNC_SEARCH_STRATEGY | ||
* on the server side, without users having to pass it in explicitly, and it takes advantage of the | ||
* already registered ASYNC_SEARCH_STRATEGY that exists on the client. | ||
* | ||
* so instead of callers having to do: | ||
* | ||
* ``` | ||
* search( | ||
* { ...request, serverStrategy: DEMO_ASYNC_SEARCH_STRATEGY }, | ||
* options, | ||
* ASYNC_SEARCH_STRATEGY | ||
* ) as Observable<IDemoResponse>, | ||
*``` | ||
* They can instead just do | ||
* | ||
* ``` | ||
* search(request, options, DEMO_ASYNC_SEARCH_STRATEGY); | ||
* ``` | ||
* | ||
* and are ensured type safety in regard to the request and response objects. | ||
* | ||
* @param context - context supplied by other plugins. | ||
* @param search - a search function to access other strategies that have already been registered. | ||
*/ | ||
export const asyncDemoClientSearchStrategyProvider: TSearchStrategyProvider<typeof ASYNC_DEMO_SEARCH_STRATEGY> = ( | ||
context: ISearchContext | ||
): ISearchStrategy<typeof ASYNC_DEMO_SEARCH_STRATEGY> => { | ||
const asyncStrategyProvider = context.getSearchStrategy(ASYNC_SEARCH_STRATEGY); | ||
const { search } = asyncStrategyProvider(context); | ||
return { | ||
search: (request, options) => { | ||
return search( | ||
{ ...request, serverStrategy: ASYNC_DEMO_SEARCH_STRATEGY }, | ||
options | ||
) as Observable<IAsyncDemoResponse>; | ||
}, | ||
}; | ||
}; |
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,60 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { TSearchStrategyProvider } from '../../../src/plugins/data/server'; | ||
import { ASYNC_DEMO_SEARCH_STRATEGY } from '../common'; | ||
|
||
function getFibonacciSequence(n = 0) { | ||
const beginning = [0, 1].slice(0, n); | ||
return Array(Math.max(0, n)) | ||
.fill(null) | ||
.reduce((sequence, value, i) => { | ||
if (i < 2) return sequence; | ||
return [...sequence, sequence[i - 1] + sequence[i - 2]]; | ||
}, beginning); | ||
} | ||
|
||
const generateId = (() => { | ||
let id = 0; | ||
return () => `${id++}`; | ||
})(); | ||
|
||
const loadedMap = new Map<string, number>(); | ||
const totalMap = new Map<string, number>(); | ||
|
||
export const asyncDemoSearchStrategyProvider: TSearchStrategyProvider<typeof ASYNC_DEMO_SEARCH_STRATEGY> = () => { | ||
return { | ||
search: async request => { | ||
const id = request.id ?? generateId(); | ||
|
||
const loaded = (loadedMap.get(id) ?? 0) + 1; | ||
loadedMap.set(id, loaded); | ||
|
||
const total = request.fibonacciNumbers ?? totalMap.get(id); | ||
totalMap.set(id, total); | ||
|
||
const fibonacciSequence = getFibonacciSequence(loaded); | ||
return { id, total, loaded, fibonacciSequence }; | ||
}, | ||
cancel: async id => { | ||
loadedMap.delete(id); | ||
totalMap.delete(id); | ||
}, | ||
}; | ||
}; |
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
Oops, something went wrong.