test('`setup` registers plugin config schema in config service', async () => { const configSchema = schema.string(); jest.spyOn(configService, 'setSchema').mockImplementation(() => Promise.resolve()); jest.doMock( join('path-with-schema', 'server'), () => ({ config: { schema: configSchema, }, }), { virtual: true, } ); mockDiscover.mockReturnValue({ error$: from([]), plugin$: from([ new PluginWrapper( 'path-with-schema', { id: 'some-id', version: 'some-version', configPath: 'path', kibanaVersion: '7.0.0', requiredPlugins: [], optionalPlugins: [], server: true, ui: true, }, { logger } as any ), ]), }); await pluginsService.setup(setupDeps); expect(configService.setSchema).toBeCalledWith('path', configSchema); });
/** * @param url * @param data * @param config */ post<T, U = string>(url: string, data?: any, config: AxiosRequestConfig = {}): Observable<IResult<T, U>> { return from(axios.post(url, data, config)) .pipe( map(response => response.data), catchError((error: AxiosResponse | undefined) => { console.log(error); if (error === undefined) { return message.error('请求出错'); } this.error$ = of(error); this.handleError(); return this.error$; }) ); }
/** * Adds a comment to a process instance. * @param processInstanceId ID of the target process instance * @param message Text for the comment * @returns Details of the comment added */ addProcessInstanceComment(processInstanceId: string, message: string): Observable<CommentModel> { return from( this.apiService.getInstance().activiti.commentsApi.addProcessInstanceComment({ message: message }, processInstanceId) ).pipe( map((response: CommentModel) => { return new CommentModel({ id: response.id, message: response.message, created: response.created, createdBy: response.createdBy }); }), catchError((err: any) => this.handleError(err)) ); }
export function wrapIntoObservable<T>(value: T | NgModuleFactory<T>| Promise<T>| Observable<T>): Observable<T> { if (isObservable(value)) { return value; } if (isPromise(value)) { // Use `Promise.resolve()` to wrap promise-like instances. // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the // change detection. return from(Promise.resolve(value)); } return of (value as T); }
it('should map values to resolved promises and concatenate', (done) => { const source = from([4, 3, 2, 1]); const project = (value: number, index: number) => Observable.from(Promise.resolve(value + index)); const results: number[] = []; source.concatMap(project).subscribe( (x) => { results.push(x); }, (err) => { done(new Error('Subscriber error handler not supposed to be called.')); }, () => { expect(results).to.deep.equal([4, 4, 4, 4]); done(); }); });
/** * Gets process instances for a filter and optionally a process definition. * @param requestNode Filter for instances * @param processDefinitionKey Limits returned instances to a process definition * @returns List of process instances */ getProcessInstances(requestNode: ProcessFilterParamRepresentationModel, processDefinitionKey?: string): Observable<ProcessListModel> { return from(this.alfrescoApiService.getInstance().activiti.processApi.getProcessInstances(requestNode)) .pipe( map((res: any) => { if (processDefinitionKey) { const filtered = res.data.filter((process) => process.processDefinitionKey === processDefinitionKey); res.data = filtered; return res; } else { return res; } }), catchError((err) => this.handleProcessError(err)) ); }
mergeMap(() => { const state = state$.value; const contentRef$ = from( state.core.entities.contents.byRef .filter( // Don't bother with non-file and non-notebook types for saving // (no dummy or directory) content => content.type === "file" || content.type === "notebook" ) .keys() ); return contentRef$; }),
export function getNpmPackageJson( packageName: string, logger: logging.LoggerApi, options?: { registryUrl?: string; usingYarn?: boolean; verbose?: boolean; }, ): Observable<Partial<NpmRepositoryPackageJson>> { const cachedResponse = npmPackageJsonCache.get(packageName); if (cachedResponse) { return cachedResponse; } if (!npmrc) { try { npmrc = readOptions(logger, false, options && options.verbose); } catch { } if (options && options.usingYarn) { try { npmrc = { ...npmrc, ...readOptions(logger, true, options && options.verbose) }; } catch { } } } const resultPromise: Promise<NpmRepositoryPackageJson> = pacote.packument( packageName, { 'full-metadata': true, ...npmrc, ...(options && options.registryUrl ? { registry: options.registryUrl } : {}), }, ); // TODO: find some way to test this const response = from(resultPromise).pipe( shareReplay(), catchError(err => { logger.warn(err.message || err); return EMPTY; }), ); npmPackageJsonCache.set(packageName, response); return response; }
/** * Finds groups filtered by name. * @param searchParams Object containing the name filter string * @returns List of group information */ findGroupsByName(searchParams: GroupSearchParam): Observable<any> { if (searchParams.name === '') { return of([]); } const url = this.getGroupsApi(); const httpMethod = 'GET', pathParams = {}, queryParams = {search: searchParams.name}, bodyParam = {}, headerParams = {}, formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; return (from(this.apiService.getInstance().oauth2Auth.callCustomApi( url, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts, Object, null, null) )).pipe( catchError((err) => this.handleError(err)) ); }
switchMap(user => { if (user) { return from(user.getIdToken()) .pipe( switchMap((token) => { return next.handle(req.clone({ setHeaders: { Authorization: token } })); }) ); } else { return next.handle(req); } })