From 348ef984952d9fcbddf36b7cf4074c2eacf944fd Mon Sep 17 00:00:00 2001 From: Larry Gregory Date: Thu, 20 Jun 2019 11:10:04 -0400 Subject: [PATCH] use relative imports for SavedObjectsNamespace --- .../saved_objects/serialization/index.ts | 10 +++++++++- .../lib/__snapshots__/repository.test.js.snap | 18 ++++++++++++++++++ .../saved_objects/service/lib/namespace.ts | 2 +- .../service/lib/search_dsl/query_params.ts | 2 +- .../service/lib/search_dsl/search_dsl.ts | 2 +- .../service/saved_objects_client.ts | 4 +--- x-pack/typings/core.d.ts | 13 ------------- 7 files changed, 31 insertions(+), 20 deletions(-) delete mode 100644 x-pack/typings/core.d.ts diff --git a/src/core/server/saved_objects/serialization/index.ts b/src/core/server/saved_objects/serialization/index.ts index 0e755d1aba55b..8b28bc55774d9 100644 --- a/src/core/server/saved_objects/serialization/index.ts +++ b/src/core/server/saved_objects/serialization/index.ts @@ -25,7 +25,7 @@ /* eslint-disable @typescript-eslint/camelcase */ import uuid from 'uuid'; -import { SavedObjectsNamespace } from 'src/core/server/saved_objects'; +import { SavedObjectsNamespace } from '../'; import { SavedObjectsSchema } from '../schema'; import { decodeVersion, encodeVersion } from '../version'; import { @@ -81,6 +81,12 @@ function assertNonEmptyString(value: string, name: string) { } } +function assertNotSymbol(value: unknown, name: string) { + if (typeof value === 'symbol') { + throw new TypeError(`Expected "${String(value)}" to be a ${name}`); + } +} + export class SavedObjectsSerializer { private readonly schema: SavedObjectsSchema; @@ -169,6 +175,7 @@ export class SavedObjectsSerializer { * @param {string} id - The id of the saved object */ public generateRawId(namespace: SavedObjectsNamespace, type: string, id?: string) { + assertNotSymbol(namespace, 'namespace'); const namespacePrefix = namespace && !this.schema.isNamespaceAgnostic(type) ? `${String(namespace)}:` : ''; return `${namespacePrefix}${type}:${id || uuid.v1()}`; @@ -177,6 +184,7 @@ export class SavedObjectsSerializer { private trimIdPrefix(namespace: SavedObjectsNamespace, type: string, id: string) { assertNonEmptyString(id, 'document id'); assertNonEmptyString(type, 'saved object type'); + assertNotSymbol(namespace, 'namespace'); const namespacePrefix = namespace && !this.schema.isNamespaceAgnostic(type) ? `${String(namespace)}:` : ''; diff --git a/src/core/server/saved_objects/service/lib/__snapshots__/repository.test.js.snap b/src/core/server/saved_objects/service/lib/__snapshots__/repository.test.js.snap index 609906c97d599..c363dcb42aadb 100644 --- a/src/core/server/saved_objects/service/lib/__snapshots__/repository.test.js.snap +++ b/src/core/server/saved_objects/service/lib/__snapshots__/repository.test.js.snap @@ -1,5 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`SavedObjectsRepository #bulkCreate doesn't support Symbol namespaces 1`] = `"Expected \\"Symbol(foo-namespace)\\" to be a namespace"`; + +exports[`SavedObjectsRepository #bulkGet doesn't support Symbol namespaces 1`] = `"Expected \\"Symbol(foo)\\" to be a namespace"`; + +exports[`SavedObjectsRepository #create doesn't support Symbol namespaces 1`] = `"Expected \\"Symbol(foo-namespace)\\" to be a namespace"`; + +exports[`SavedObjectsRepository #delete doesn't support Symbol namespaces 1`] = `"Expected \\"Symbol(foo-namespace)\\" to be a namespace"`; + +exports[`SavedObjectsRepository #deleteByNamespace doesn't support Symbol namespaces 1`] = `"namespace is required, and must be a string"`; + exports[`SavedObjectsRepository #deleteByNamespace requires namespace to be a string 1`] = `"namespace is required, and must be a string"`; exports[`SavedObjectsRepository #deleteByNamespace requires namespace to be defined 1`] = `"namespace is required, and must be a string"`; + +exports[`SavedObjectsRepository #find doesn't support Symbol namespaces 1`] = `"options.namespace must not be a Symbol"`; + +exports[`SavedObjectsRepository #get doesn't support Symbol namespaces 1`] = `"Expected \\"Symbol(foo-namespace)\\" to be a namespace"`; + +exports[`SavedObjectsRepository #incrementCounter doesn't support Symbol namespaces 1`] = `"Expected \\"Symbol(foo-namespace)\\" to be a namespace"`; + +exports[`SavedObjectsRepository #update doesn't support Symbol namespaces 1`] = `"Expected \\"Symbol(foo-namespace)\\" to be a namespace"`; diff --git a/src/core/server/saved_objects/service/lib/namespace.ts b/src/core/server/saved_objects/service/lib/namespace.ts index 7de9bbad6edc2..915f3a63c1c31 100644 --- a/src/core/server/saved_objects/service/lib/namespace.ts +++ b/src/core/server/saved_objects/service/lib/namespace.ts @@ -21,4 +21,4 @@ * Saved Objects Namespace. * @public */ -export type SavedObjectsNamespace = string | undefined; +export type SavedObjectsNamespace = string | undefined | symbol; diff --git a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts index 4d9e5108a917a..6fd23e86a2915 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SavedObjectsNamespace } from 'src/core/server/saved_objects'; +import { SavedObjectsNamespace } from '../namespace'; import { getRootPropertiesObjects, IndexMapping } from '../../../mappings'; import { SavedObjectsSchema } from '../../../schema'; diff --git a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts index b91965d6ce63a..16f6b8c438cdb 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts @@ -19,7 +19,7 @@ import Boom from 'boom'; -import { SavedObjectsNamespace } from 'src/core/server/saved_objects'; +import { SavedObjectsNamespace } from '../namespace'; import { IndexMapping } from '../../../mappings'; import { SavedObjectsSchema } from '../../../schema'; import { getQueryParams } from './query_params'; diff --git a/src/core/server/saved_objects/service/saved_objects_client.ts b/src/core/server/saved_objects/service/saved_objects_client.ts index e8fae3df333c3..88824868e869e 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.ts @@ -16,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { SavedObjectsNamespace } from 'src/core/server'; -import { SavedObjectsRepository } from './lib'; - +import { SavedObjectsRepository, SavedObjectsNamespace } from './lib'; import { SavedObjectsErrorHelpers } from './lib/errors'; type Omit = Pick>; diff --git a/x-pack/typings/core.d.ts b/x-pack/typings/core.d.ts deleted file mode 100644 index 97d50fa15562a..0000000000000 --- a/x-pack/typings/core.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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. - */ -import { SavedObjectsClient } from 'src/core/server/saved_objects'; - -declare module 'src/core/server/saved_objects' { - type SavedObjectsNamespace = string | undefined | symbol; - interface SavedObjectsBaseOptions { - namespace?: SavedObjectsNamespace; - } -}