From 5062de8e655b19355cbaf5f103aa5c4feceb0ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Tue, 4 Dec 2018 00:13:15 +0100 Subject: [PATCH] Move SavedObjectClient types alongside js source (#26448) (#26563) --- src/server/saved_objects/index.d.ts | 25 ++++++++++++ .../service/create_saved_objects_service.d.ts | 29 ++++++++++++++ src/server/saved_objects/service/index.d.ts | 22 +++++++++++ .../saved_objects/service/lib/index.d.ts | 24 ++++++++++++ .../service/lib/scoped_client_provider.d.ts | 38 +++++++++++++++++++ .../service/saved_objects_client.d.ts | 26 ++++++++----- x-pack/plugins/spaces/index.ts | 7 +++- .../saved_objects_client_wrapper_factory.ts | 6 +-- .../spaces_saved_objects_client.ts | 6 +-- .../lib/space_request_interceptors.test.ts | 5 ++- 10 files changed, 169 insertions(+), 19 deletions(-) create mode 100644 src/server/saved_objects/index.d.ts create mode 100644 src/server/saved_objects/service/create_saved_objects_service.d.ts create mode 100644 src/server/saved_objects/service/index.d.ts create mode 100644 src/server/saved_objects/service/lib/index.d.ts create mode 100644 src/server/saved_objects/service/lib/scoped_client_provider.d.ts rename x-pack/plugins/spaces/server/lib/saved_objects_client/saved_objects_client_types.ts => src/server/saved_objects/service/saved_objects_client.d.ts (71%) diff --git a/src/server/saved_objects/index.d.ts b/src/server/saved_objects/index.d.ts new file mode 100644 index 000000000000..99b6af3c787a --- /dev/null +++ b/src/server/saved_objects/index.d.ts @@ -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 { + SavedObject, + SavedObjectsClient, + SavedObjectsClientWrapperFactory, + SavedObjectsService, +} from './service'; diff --git a/src/server/saved_objects/service/create_saved_objects_service.d.ts b/src/server/saved_objects/service/create_saved_objects_service.d.ts new file mode 100644 index 000000000000..a371a4d91a35 --- /dev/null +++ b/src/server/saved_objects/service/create_saved_objects_service.d.ts @@ -0,0 +1,29 @@ +/* + * 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 { ScopedSavedObjectsClientProvider } from './lib'; + +export interface SavedObjectsService { + // ATTENTION: these types are incomplete + + addScopedSavedObjectsClientWrapperFactory: ScopedSavedObjectsClientProvider< + Request + >['addClientWrapperFactory']; + types: string[]; +} diff --git a/src/server/saved_objects/service/index.d.ts b/src/server/saved_objects/service/index.d.ts new file mode 100644 index 000000000000..dc6b2c545ca7 --- /dev/null +++ b/src/server/saved_objects/service/index.d.ts @@ -0,0 +1,22 @@ +/* + * 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 { SavedObjectsService } from './create_saved_objects_service'; +export { SavedObjectsClientWrapperFactory } from './lib'; +export { SavedObject, SavedObjectsClient } from './saved_objects_client'; diff --git a/src/server/saved_objects/service/lib/index.d.ts b/src/server/saved_objects/service/lib/index.d.ts new file mode 100644 index 000000000000..2c0f99103d30 --- /dev/null +++ b/src/server/saved_objects/service/lib/index.d.ts @@ -0,0 +1,24 @@ +/* + * 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 { + SavedObjectsClientWrapperFactory, + SavedObjectsClientWrapperOptions, + ScopedSavedObjectsClientProvider, +} from './scoped_client_provider'; diff --git a/src/server/saved_objects/service/lib/scoped_client_provider.d.ts b/src/server/saved_objects/service/lib/scoped_client_provider.d.ts new file mode 100644 index 000000000000..c77875ea802f --- /dev/null +++ b/src/server/saved_objects/service/lib/scoped_client_provider.d.ts @@ -0,0 +1,38 @@ +/* + * 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 { SavedObjectsClient } from '..'; + +export interface SavedObjectsClientWrapperOptions { + client: SavedObjectsClient; + request: Request; +} + +export type SavedObjectsClientWrapperFactory = ( + options: SavedObjectsClientWrapperOptions +) => SavedObjectsClient; + +export interface ScopedSavedObjectsClientProvider { + // ATTENTION: these types are incomplete + + addClientWrapperFactory( + priority: number, + wrapperFactory: SavedObjectsClientWrapperFactory + ): void; +} diff --git a/x-pack/plugins/spaces/server/lib/saved_objects_client/saved_objects_client_types.ts b/src/server/saved_objects/service/saved_objects_client.d.ts similarity index 71% rename from x-pack/plugins/spaces/server/lib/saved_objects_client/saved_objects_client_types.ts rename to src/server/saved_objects/service/saved_objects_client.d.ts index b2cdc09d66a1..1c3c9c0d5947 100644 --- a/x-pack/plugins/spaces/server/lib/saved_objects_client/saved_objects_client_types.ts +++ b/src/server/saved_objects/service/saved_objects_client.d.ts @@ -1,7 +1,20 @@ /* - * 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. + * 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 BaseOptions { @@ -88,10 +101,3 @@ export interface SavedObjectsClient { options?: UpdateOptions ) => Promise; } - -export interface SOCWrapperOptions { - client: SavedObjectsClient; - request: any; -} - -export type SOCWrapperFactory = (options: SOCWrapperOptions) => SavedObjectsClient; diff --git a/x-pack/plugins/spaces/index.ts b/x-pack/plugins/spaces/index.ts index 1a23f9b55404..e61edfe5380c 100644 --- a/x-pack/plugins/spaces/index.ts +++ b/x-pack/plugins/spaces/index.ts @@ -5,6 +5,8 @@ */ import { resolve } from 'path'; + +import { SavedObjectsService } from 'src/server/saved_objects'; // @ts-ignore import { AuditLogger } from '../../server/lib/audit_logger'; // @ts-ignore @@ -132,7 +134,10 @@ export const spaces = (kibana: any) => }, }); - const { addScopedSavedObjectsClientWrapperFactory, types } = server.savedObjects; + const { + addScopedSavedObjectsClientWrapperFactory, + types, + } = server.savedObjects as SavedObjectsService; addScopedSavedObjectsClientWrapperFactory( Number.MAX_VALUE, spacesSavedObjectsClientWrapperFactory(spacesService, types) diff --git a/x-pack/plugins/spaces/server/lib/saved_objects_client/saved_objects_client_wrapper_factory.ts b/x-pack/plugins/spaces/server/lib/saved_objects_client/saved_objects_client_wrapper_factory.ts index 9e19556abd20..05f17300b3fd 100644 --- a/x-pack/plugins/spaces/server/lib/saved_objects_client/saved_objects_client_wrapper_factory.ts +++ b/x-pack/plugins/spaces/server/lib/saved_objects_client/saved_objects_client_wrapper_factory.ts @@ -4,15 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ +import { SavedObjectsClientWrapperFactory } from 'src/server/saved_objects'; import { SpacesService } from '../create_spaces_service'; -import { SOCWrapperOptions } from './saved_objects_client_types'; import { SpacesSavedObjectsClient } from './spaces_saved_objects_client'; export function spacesSavedObjectsClientWrapperFactory( spacesService: SpacesService, types: string[] -) { - return ({ client, request }: SOCWrapperOptions) => +): SavedObjectsClientWrapperFactory { + return ({ client, request }) => new SpacesSavedObjectsClient({ baseClient: client, request, diff --git a/x-pack/plugins/spaces/server/lib/saved_objects_client/spaces_saved_objects_client.ts b/x-pack/plugins/spaces/server/lib/saved_objects_client/spaces_saved_objects_client.ts index dc2131afee2b..ccb93b6d326f 100644 --- a/x-pack/plugins/spaces/server/lib/saved_objects_client/spaces_saved_objects_client.ts +++ b/x-pack/plugins/spaces/server/lib/saved_objects_client/spaces_saved_objects_client.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { DEFAULT_SPACE_ID } from '../../../common/constants'; -import { SpacesService } from '../create_spaces_service'; import { BaseOptions, BulkCreateObject, @@ -15,7 +13,9 @@ import { SavedObjectAttributes, SavedObjectsClient, UpdateOptions, -} from './saved_objects_client_types'; +} from 'src/server/saved_objects/service/saved_objects_client'; +import { DEFAULT_SPACE_ID } from '../../../common/constants'; +import { SpacesService } from '../create_spaces_service'; interface SpacesSavedObjectsClientOptions { baseClient: SavedObjectsClient; diff --git a/x-pack/plugins/spaces/server/lib/space_request_interceptors.test.ts b/x-pack/plugins/spaces/server/lib/space_request_interceptors.test.ts index 5fbe98a8a2f1..9d9ad1417a3e 100644 --- a/x-pack/plugins/spaces/server/lib/space_request_interceptors.test.ts +++ b/x-pack/plugins/spaces/server/lib/space_request_interceptors.test.ts @@ -3,10 +3,11 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -// @ts-ignore + import { Server } from 'hapi'; import sinon from 'sinon'; -import { SavedObject } from './saved_objects_client/saved_objects_client_types'; + +import { SavedObject } from 'src/server/saved_objects'; import { initSpacesRequestInterceptors } from './space_request_interceptors'; describe('interceptors', () => {