diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md
index a29d550e831ae..89330d2a86f76 100644
--- a/docs/development/core/server/kibana-plugin-core-server.md
+++ b/docs/development/core/server/kibana-plugin-core-server.md
@@ -224,8 +224,6 @@ The plugin integrates with the core system via lifecycle events: `setup`
| Variable | Description |
| --- | --- |
| [kibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) | Set of helpers used to create KibanaResponse
to form HTTP response on an incoming request. Should be returned as a result of [RequestHandler](./kibana-plugin-core-server.requesthandler.md) execution. |
-| [namespaceIdToString](./kibana-plugin-core-server.namespaceidtostring.md) | Converts a given saved object namespace ID to its string representation. All namespace IDs have an identical string representation, with the exception of the undefined
namespace ID (which has a namespace string of 'default'
). |
-| [namespaceStringToId](./kibana-plugin-core-server.namespacestringtoid.md) | Converts a given saved object namespace string to its ID representation. All namespace strings have an identical ID representation, with the exception of the 'default'
namespace string (which has a namespace ID of undefined
). |
| [ServiceStatusLevels](./kibana-plugin-core-server.servicestatuslevels.md) | The current "level" of availability of a service. |
| [validBodyOutput](./kibana-plugin-core-server.validbodyoutput.md) | The set of valid body.output |
diff --git a/docs/development/core/server/kibana-plugin-core-server.namespaceidtostring.md b/docs/development/core/server/kibana-plugin-core-server.namespaceidtostring.md
deleted file mode 100644
index 5c9f093531e1c..0000000000000
--- a/docs/development/core/server/kibana-plugin-core-server.namespaceidtostring.md
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [namespaceIdToString](./kibana-plugin-core-server.namespaceidtostring.md)
-
-## namespaceIdToString variable
-
-Converts a given saved object namespace ID to its string representation. All namespace IDs have an identical string representation, with the exception of the `undefined` namespace ID (which has a namespace string of `'default'`).
-
-Signature:
-
-```typescript
-namespaceIdToString: (namespace?: string | undefined) => string
-```
diff --git a/docs/development/core/server/kibana-plugin-core-server.namespacestringtoid.md b/docs/development/core/server/kibana-plugin-core-server.namespacestringtoid.md
deleted file mode 100644
index 39d6a13aa7fb0..0000000000000
--- a/docs/development/core/server/kibana-plugin-core-server.namespacestringtoid.md
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [namespaceStringToId](./kibana-plugin-core-server.namespacestringtoid.md)
-
-## namespaceStringToId variable
-
-Converts a given saved object namespace string to its ID representation. All namespace strings have an identical ID representation, with the exception of the `'default'` namespace string (which has a namespace ID of `undefined`).
-
-Signature:
-
-```typescript
-namespaceStringToId: (namespace: string) => string | undefined
-```
diff --git a/src/core/server/index.ts b/src/core/server/index.ts
index 9753f725c7c96..5422cbc2180ef 100644
--- a/src/core/server/index.ts
+++ b/src/core/server/index.ts
@@ -303,8 +303,6 @@ export {
exportSavedObjectsToStream,
importSavedObjectsFromStream,
resolveSavedObjectsImportErrors,
- namespaceIdToString,
- namespaceStringToId,
} from './saved_objects';
export {
diff --git a/src/core/server/saved_objects/service/index.ts b/src/core/server/saved_objects/service/index.ts
index 245df328db665..9f625b4732e26 100644
--- a/src/core/server/saved_objects/service/index.ts
+++ b/src/core/server/saved_objects/service/index.ts
@@ -58,8 +58,6 @@ export {
SavedObjectsErrorHelpers,
SavedObjectsClientFactory,
SavedObjectsClientFactoryProvider,
- namespaceIdToString,
- namespaceStringToId,
} from './lib';
export * from './saved_objects_client';
diff --git a/src/core/server/saved_objects/service/lib/index.ts b/src/core/server/saved_objects/service/lib/index.ts
index cfae6ae9b62d5..e103120388e35 100644
--- a/src/core/server/saved_objects/service/lib/index.ts
+++ b/src/core/server/saved_objects/service/lib/index.ts
@@ -30,5 +30,3 @@ export {
} from './scoped_client_provider';
export { SavedObjectsErrorHelpers } from './errors';
-
-export { namespaceIdToString, namespaceStringToId } from './namespace';
diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md
index 4924685769011..dd6fa64278290 100644
--- a/src/core/server/server.api.md
+++ b/src/core/server/server.api.md
@@ -1596,12 +1596,6 @@ export function modifyUrl(url: string, urlModifier: (urlParts: URLMeaningfulPart
// @public
export type MutatingOperationRefreshSetting = boolean | 'wait_for';
-// @public
-export const namespaceIdToString: (namespace?: string | undefined) => string;
-
-// @public
-export const namespaceStringToId: (namespace: string) => string | undefined;
-
// Warning: (ae-missing-release-tag) "NodesVersionCompatibility" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
diff --git a/x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.test.ts b/x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.test.ts
index 1cec7b769fa26..d49dfa2015dc6 100644
--- a/x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.test.ts
+++ b/x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.test.ts
@@ -20,7 +20,6 @@ import { copySavedObjectsToSpacesFactory } from './copy_to_spaces';
jest.mock('../../../../../../src/core/server', () => {
return {
- ...(jest.requireActual('../../../../../../src/core/server') as Record),
exportSavedObjectsToStream: jest.fn(),
importSavedObjectsFromStream: jest.fn(),
};
diff --git a/x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.test.ts b/x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.test.ts
index 37181c9d81649..6a77bf7397cb5 100644
--- a/x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.test.ts
+++ b/x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.test.ts
@@ -20,7 +20,6 @@ import { resolveCopySavedObjectsToSpacesConflictsFactory } from './resolve_copy_
jest.mock('../../../../../../src/core/server', () => {
return {
- ...(jest.requireActual('../../../../../../src/core/server') as Record),
exportSavedObjectsToStream: jest.fn(),
resolveSavedObjectsImportErrors: jest.fn(),
};
diff --git a/x-pack/plugins/spaces/server/lib/utils/__mocks__/index.ts b/x-pack/plugins/spaces/server/lib/utils/__mocks__/index.ts
deleted file mode 100644
index 2bb23d0304858..0000000000000
--- a/x-pack/plugins/spaces/server/lib/utils/__mocks__/index.ts
+++ /dev/null
@@ -1,14 +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.
- */
-
-const mockNamespaceIdToString = jest.fn();
-const mockNamespaceStringToId = jest.fn();
-jest.mock('../../../../../../../src/core/server', () => ({
- namespaceIdToString: mockNamespaceIdToString,
- namespaceStringToId: mockNamespaceStringToId,
-}));
-
-export { mockNamespaceIdToString, mockNamespaceStringToId };
diff --git a/x-pack/plugins/spaces/server/lib/utils/namespace.test.ts b/x-pack/plugins/spaces/server/lib/utils/namespace.test.ts
index 79d3dda301045..a81a5f3cee187 100644
--- a/x-pack/plugins/spaces/server/lib/utils/namespace.test.ts
+++ b/x-pack/plugins/spaces/server/lib/utils/namespace.test.ts
@@ -4,29 +4,45 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { mockNamespaceIdToString, mockNamespaceStringToId } from './__mocks__';
+import { DEFAULT_SPACE_ID } from '../../../common/constants';
import { spaceIdToNamespace, namespaceToSpaceId } from './namespace';
-beforeEach(() => {
- jest.clearAllMocks();
-});
-
describe('#spaceIdToNamespace', () => {
- it('returns result of namespaceStringToId', () => {
- mockNamespaceStringToId.mockReturnValue('bar');
+ it('converts the default space to undefined', () => {
+ expect(spaceIdToNamespace(DEFAULT_SPACE_ID)).toBeUndefined();
+ });
+
+ it('returns non-default spaces as-is', () => {
+ expect(spaceIdToNamespace('foo')).toEqual('foo');
+ });
- const result = spaceIdToNamespace('foo');
- expect(mockNamespaceStringToId).toHaveBeenCalledWith('foo');
- expect(result).toEqual('bar');
+ it('throws an error when a spaceId is not provided', () => {
+ // @ts-ignore ts knows this isn't right
+ expect(() => spaceIdToNamespace()).toThrowErrorMatchingInlineSnapshot(`"spaceId is required"`);
+
+ // @ts-ignore ts knows this isn't right
+ expect(() => spaceIdToNamespace(null)).toThrowErrorMatchingInlineSnapshot(
+ `"spaceId is required"`
+ );
+
+ expect(() => spaceIdToNamespace('')).toThrowErrorMatchingInlineSnapshot(
+ `"spaceId is required"`
+ );
});
});
describe('#namespaceToSpaceId', () => {
- it('returns result of namespaceIdToString', () => {
- mockNamespaceIdToString.mockReturnValue('bar');
+ it('returns the default space id for undefined namespaces', () => {
+ expect(namespaceToSpaceId(undefined)).toEqual(DEFAULT_SPACE_ID);
+ });
+
+ it('returns all other namespaces as-is', () => {
+ expect(namespaceToSpaceId('foo')).toEqual('foo');
+ });
- const result = namespaceToSpaceId('foo');
- expect(mockNamespaceIdToString).toHaveBeenCalledWith('foo');
- expect(result).toEqual('bar');
+ it('throws an error when an empty string is provided', () => {
+ expect(() => namespaceToSpaceId('')).toThrowErrorMatchingInlineSnapshot(
+ `"namespace cannot be an empty string"`
+ );
});
});
diff --git a/x-pack/plugins/spaces/server/lib/utils/namespace.ts b/x-pack/plugins/spaces/server/lib/utils/namespace.ts
index 6861d0141ea02..8c7ed2ea1797d 100644
--- a/x-pack/plugins/spaces/server/lib/utils/namespace.ts
+++ b/x-pack/plugins/spaces/server/lib/utils/namespace.ts
@@ -4,22 +4,28 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { namespaceStringToId, namespaceIdToString } from '../../../../../../src/core/server';
+import { DEFAULT_SPACE_ID } from '../../../common/constants';
-/**
- * Converts a Space ID string to its namespace ID representation. Note that a Space ID string is equivalent to a namespace string.
- *
- * See also: {@link namespaceStringToId}.
- */
-export function spaceIdToNamespace(spaceId: string) {
- return namespaceStringToId(spaceId);
+export function spaceIdToNamespace(spaceId: string): string | undefined {
+ if (!spaceId) {
+ throw new TypeError('spaceId is required');
+ }
+
+ if (spaceId === DEFAULT_SPACE_ID) {
+ return undefined;
+ }
+
+ return spaceId;
}
-/**
- * Converts a namespace ID to its Space ID string representation. Note that a Space ID string is equivalent to a namespace string.
- *
- * See also: {@link namespaceIdToString}.
- */
-export function namespaceToSpaceId(namespace?: string) {
- return namespaceIdToString(namespace);
+export function namespaceToSpaceId(namespace: string | undefined): string {
+ if (namespace === '') {
+ throw new TypeError('namespace cannot be an empty string');
+ }
+
+ if (!namespace) {
+ return DEFAULT_SPACE_ID;
+ }
+
+ return namespace;
}
diff --git a/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts b/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts
index dce6de908cfcb..bec3a5dcb0b71 100644
--- a/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts
+++ b/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts
@@ -30,10 +30,10 @@ import { securityMock } from '../../../../../security/server/mocks';
import { ObjectType } from '@kbn/config-schema';
jest.mock('../../../../../../../src/core/server', () => {
return {
- ...(jest.requireActual('../../../../../../../src/core/server') as Record),
exportSavedObjectsToStream: jest.fn(),
importSavedObjectsFromStream: jest.fn(),
resolveSavedObjectsImportErrors: jest.fn(),
+ kibanaResponseFactory: jest.requireActual('src/core/server').kibanaResponseFactory,
};
});
import {