Move SavedObjectClient types alongside js source (#26448) (#26563)

This commit is contained in:
Felix Stürmer 2018-12-04 00:13:15 +01:00 committed by GitHub
parent 1d1296a483
commit 5062de8e65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 169 additions and 19 deletions

25
src/server/saved_objects/index.d.ts vendored Normal file
View file

@ -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';

View file

@ -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<Request = any> {
// ATTENTION: these types are incomplete
addScopedSavedObjectsClientWrapperFactory: ScopedSavedObjectsClientProvider<
Request
>['addClientWrapperFactory'];
types: string[];
}

View file

@ -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';

View file

@ -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';

View file

@ -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<Request = any> {
client: SavedObjectsClient;
request: Request;
}
export type SavedObjectsClientWrapperFactory<Request = any> = (
options: SavedObjectsClientWrapperOptions<Request>
) => SavedObjectsClient;
export interface ScopedSavedObjectsClientProvider<Request = any> {
// ATTENTION: these types are incomplete
addClientWrapperFactory(
priority: number,
wrapperFactory: SavedObjectsClientWrapperFactory<Request>
): void;
}

View file

@ -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<SavedObject>;
}
export interface SOCWrapperOptions {
client: SavedObjectsClient;
request: any;
}
export type SOCWrapperFactory = (options: SOCWrapperOptions) => SavedObjectsClient;

View file

@ -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)

View file

@ -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,

View file

@ -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;

View file

@ -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', () => {