Skip to content

Commit

Permalink
Typings for saved object client (elastic#29951) (elastic#30367)
Browse files Browse the repository at this point in the history
* WIP typings for saved object client

* Move more files to TS

* type saved objects client

* clean up typings for saved object client

* tie typings form server and client for saved objects together

* add missing html import typing to x-pack

* Add missing buildSourcePatterns

* Removed accidental comma

* add typings for saved_object_client tests and fix test cases

* duplicate case_conversion helpers for the moment

* Address PR review

* Fix some documentation

* Replace ts-ignore by any imports

* Remove expect.js from test

* Add more typings to prevent CI failure
  • Loading branch information
timroes authored Feb 7, 2019
1 parent dd4031a commit c983516
Show file tree
Hide file tree
Showing 23 changed files with 970 additions and 733 deletions.
3 changes: 3 additions & 0 deletions src/server/saved_objects/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/

export {
MigrationVersion,
SavedObject,
SavedObjectAttributes,
SavedObjectsClient,
SavedObjectsClientWrapperFactory,
SavedObjectReference,
SavedObjectsService,
} from './service';
12 changes: 11 additions & 1 deletion src/server/saved_objects/service/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@

export { SavedObjectsService } from './create_saved_objects_service';
export { SavedObjectsClientWrapperFactory } from './lib';
export { SavedObject, SavedObjectsClient } from './saved_objects_client';
export {
FindOptions,
GetResponse,
UpdateResponse,
CreateResponse,
MigrationVersion,
SavedObject,
SavedObjectAttributes,
SavedObjectsClient,
SavedObjectReference,
} from './saved_objects_client';
17 changes: 14 additions & 3 deletions src/server/saved_objects/service/saved_objects_client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface BaseOptions {
export interface CreateOptions extends BaseOptions {
id?: string;
override?: boolean;
references?: SavedObjectReference[];
}

export interface BulkCreateObject<T extends SavedObjectAttributes = any> {
Expand All @@ -48,6 +49,7 @@ export interface FindOptions extends BaseOptions {
fields?: string[];
search?: string;
searchFields?: string[];
hasReference?: { type: string; id: string };
}

export interface FindResponse<T extends SavedObjectAttributes = any> {
Expand All @@ -71,6 +73,10 @@ export interface BulkGetResponse<T extends SavedObjectAttributes = any> {
saved_objects: Array<SavedObject<T>>;
}

export interface MigrationVersion {
[pluginName: string]: string;
}

export interface SavedObjectAttributes {
[key: string]: SavedObjectAttributes | string | number | boolean | null;
}
Expand All @@ -85,6 +91,7 @@ export interface SavedObject<T extends SavedObjectAttributes = any> {
};
attributes: T;
references: SavedObjectReference[];
migrationVersion?: MigrationVersion;
}

export interface SavedObjectReference {
Expand All @@ -93,6 +100,10 @@ export interface SavedObjectReference {
id: string;
}

export type GetResponse<T extends SavedObjectAttributes = any> = SavedObject<T>;
export type CreateResponse<T extends SavedObjectAttributes = any> = SavedObject<T>;
export type UpdateResponse<T extends SavedObjectAttributes = any> = SavedObject<T>;

export declare class SavedObjectsClient {
public static errors: typeof errors;
public errors: typeof errors;
Expand All @@ -103,7 +114,7 @@ export declare class SavedObjectsClient {
type: string,
attributes: T,
options?: CreateOptions
): Promise<SavedObject<T>>;
): Promise<CreateResponse<T>>;
public bulkCreate<T extends SavedObjectAttributes = any>(
objects: Array<BulkCreateObject<T>>,
options?: CreateOptions
Expand All @@ -120,11 +131,11 @@ export declare class SavedObjectsClient {
type: string,
id: string,
options?: BaseOptions
): Promise<SavedObject<T>>;
): Promise<GetResponse<T>>;
public update<T extends SavedObjectAttributes = any>(
type: string,
id: string,
attributes: Partial<T>,
options?: UpdateOptions
): Promise<SavedObject<T>>;
): Promise<UpdateResponse<T>>;
}
3 changes: 2 additions & 1 deletion src/ui/public/chrome/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { Brand } from '../../../core/public/chrome';
import { SavedObjectsClient } from '../saved_objects';
import { BreadcrumbsApi } from './api/breadcrumbs';
import { HelpExtensionApi } from './api/help_extension';
import { ChromeNavLinks } from './api/nav';
Expand All @@ -34,6 +35,7 @@ declare interface Chrome extends ChromeNavLinks {
getBasePath(): string;
getXsrfToken(): string;
getKibanaVersion(): string;
getSavedObjectsClient(): SavedObjectsClient;
getUiSettingsClient(): any;
setVisible(visible: boolean): any;
getInjected(key: string, defaultValue?: any): any;
Expand All @@ -43,7 +45,6 @@ declare interface Chrome extends ChromeNavLinks {
addApplicationClass(classNames: string | string[]): this;
removeApplicationClass(classNames: string | string[]): this;
getApplicationClasses(): string;
getSavedObjectsClient(): any;
}

declare const chrome: Chrome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ import uiRoutes from '../routes';

import template from './error_auto_create_index.html';

uiRoutes
.when('/error/action.auto_create_index', {
template,
k7Breadcrumbs: () => [{ text: i18n.translate('common.ui.errorAutoCreateIndex.breadcrumbs.errorText', { defaultMessage: 'Error' }) }],
});
uiRoutes.when('/error/action.auto_create_index', {
template,
k7Breadcrumbs: () => [
{
text: i18n.translate('common.ui.errorAutoCreateIndex.breadcrumbs.errorText', {
defaultMessage: 'Error',
}),
},
],
});

export function isAutoCreateIndexError(error) {
export function isAutoCreateIndexError(error: object) {
return (
get(error, 'res.status') === 503 &&
get(error, 'body.code') === 'ES_AUTO_CREATE_INDEX_ERROR'
get(error, 'res.status') === 503 && get(error, 'body.code') === 'ES_AUTO_CREATE_INDEX_ERROR'
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/kfetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

export { kfetch, addInterceptor, KFetchOptions } from './kfetch';
export { kfetch, addInterceptor, KFetchOptions, KFetchQuery } from './kfetch';
export { kfetchAbortable } from './kfetch_abortable';
2 changes: 1 addition & 1 deletion src/ui/public/kfetch/kfetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import url from 'url';
import chrome from '../chrome';
import { KFetchError } from './kfetch_error';

interface KFetchQuery {
export interface KFetchQuery {
[key: string]: string | number | boolean | undefined;
}

Expand Down
20 changes: 20 additions & 0 deletions src/ui/public/promises/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

export { PromiseService } from './promises';
25 changes: 25 additions & 0 deletions src/ui/public/promises/promises.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

export interface PromiseService {
resolve: <T>(value: T | PromiseLike<T>) => ng.IPromise<T>;

// TODO: add additional typing
[key: string]: any;
}
Loading

0 comments on commit c983516

Please sign in to comment.