Skip to content

Commit 2c36a31

Browse files
committed
Wrap namespace utility methods in SavedObjectsUtils class
1 parent ba8c72d commit 2c36a31

File tree

16 files changed

+174
-138
lines changed

16 files changed

+174
-138
lines changed

docs/development/core/server/kibana-plugin-core-server.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
2828
| [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) | |
2929
| [SavedObjectsRepository](./kibana-plugin-core-server.savedobjectsrepository.md) | |
3030
| [SavedObjectsSerializer](./kibana-plugin-core-server.savedobjectsserializer.md) | A serializer that can be used to manually convert [raw](./kibana-plugin-core-server.savedobjectsrawdoc.md) or [sanitized](./kibana-plugin-core-server.savedobjectsanitizeddoc.md) documents to the other kind. |
31+
| [SavedObjectsUtils](./kibana-plugin-core-server.savedobjectsutils.md) | |
3132
| [SavedObjectTypeRegistry](./kibana-plugin-core-server.savedobjecttyperegistry.md) | Registry holding information about all the registered [saved object types](./kibana-plugin-core-server.savedobjectstype.md)<!-- -->. |
3233

3334
## Enumerations
@@ -224,8 +225,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
224225
| Variable | Description |
225226
| --- | --- |
226227
| [kibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) | Set of helpers used to create <code>KibanaResponse</code> to form HTTP response on an incoming request. Should be returned as a result of [RequestHandler](./kibana-plugin-core-server.requesthandler.md) execution. |
227-
| [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 <code>undefined</code> namespace ID (which has a namespace string of <code>'default'</code>). |
228-
| [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 <code>'default'</code> namespace string (which has a namespace ID of <code>undefined</code>). |
229228
| [ServiceStatusLevels](./kibana-plugin-core-server.servicestatuslevels.md) | The current "level" of availability of a service. |
230229
| [validBodyOutput](./kibana-plugin-core-server.validbodyoutput.md) | The set of valid body.output |
231230

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsUtils](./kibana-plugin-core-server.savedobjectsutils.md)
4+
5+
## SavedObjectsUtils class
6+
7+
8+
<b>Signature:</b>
9+
10+
```typescript
11+
export declare class SavedObjectsUtils
12+
```
13+
14+
## Properties
15+
16+
| Property | Modifiers | Type | Description |
17+
| --- | --- | --- | --- |
18+
| [namespaceIdToString](./kibana-plugin-core-server.savedobjectsutils.namespaceidtostring.md) | <code>static</code> | <code>(namespace?: string &#124; undefined) =&gt; string</code> | Converts a given saved object namespace ID to its string representation. All namespace IDs have an identical string representation, with the exception of the <code>undefined</code> namespace ID (which has a namespace string of <code>'default'</code>). |
19+
| [namespaceStringToId](./kibana-plugin-core-server.savedobjectsutils.namespacestringtoid.md) | <code>static</code> | <code>(namespace: string) =&gt; string &#124; undefined</code> | Converts a given saved object namespace string to its ID representation. All namespace strings have an identical ID representation, with the exception of the <code>'default'</code> namespace string (which has a namespace ID of <code>undefined</code>). |
20+
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
22

3-
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [namespaceIdToString](./kibana-plugin-core-server.namespaceidtostring.md)
3+
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsUtils](./kibana-plugin-core-server.savedobjectsutils.md) &gt; [namespaceIdToString](./kibana-plugin-core-server.savedobjectsutils.namespaceidtostring.md)
44

5-
## namespaceIdToString variable
5+
## SavedObjectsUtils.namespaceIdToString property
66

77
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'`<!-- -->).
88

99
<b>Signature:</b>
1010

1111
```typescript
12-
namespaceIdToString: (namespace?: string | undefined) => string
12+
static namespaceIdToString: (namespace?: string | undefined) => string;
1313
```
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
22

3-
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [namespaceStringToId](./kibana-plugin-core-server.namespacestringtoid.md)
3+
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsUtils](./kibana-plugin-core-server.savedobjectsutils.md) &gt; [namespaceStringToId](./kibana-plugin-core-server.savedobjectsutils.namespacestringtoid.md)
44

5-
## namespaceStringToId variable
5+
## SavedObjectsUtils.namespaceStringToId property
66

77
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`<!-- -->).
88

99
<b>Signature:</b>
1010

1111
```typescript
12-
namespaceStringToId: (namespace: string) => string | undefined
12+
static namespaceStringToId: (namespace: string) => string | undefined;
1313
```

src/core/server/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,10 @@ export {
300300
SavedObjectsTypeManagementDefinition,
301301
SavedObjectMigrationMap,
302302
SavedObjectMigrationFn,
303+
SavedObjectsUtils,
303304
exportSavedObjectsToStream,
304305
importSavedObjectsFromStream,
305306
resolveSavedObjectsImportErrors,
306-
namespaceIdToString,
307-
namespaceStringToId,
308307
} from './saved_objects';
309308

310309
export {

src/core/server/saved_objects/service/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ export {
5858
SavedObjectsErrorHelpers,
5959
SavedObjectsClientFactory,
6060
SavedObjectsClientFactoryProvider,
61-
namespaceIdToString,
62-
namespaceStringToId,
61+
SavedObjectsUtils,
6362
} from './lib';
6463

6564
export * from './saved_objects_client';

src/core/server/saved_objects/service/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ export {
3131

3232
export { SavedObjectsErrorHelpers } from './errors';
3333

34-
export { namespaceIdToString, namespaceStringToId } from './namespace';
34+
export { SavedObjectsUtils } from './utils';

src/core/server/saved_objects/service/lib/namespace.test.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/core/server/saved_objects/service/lib/namespace.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/core/server/saved_objects/service/lib/repository.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import {
6767
} from '../../types';
6868
import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry';
6969
import { validateConvertFilterToKueryNode } from './filter_utils';
70-
import { namespaceIdToString, namespaceStringToId } from './namespace';
70+
import { SavedObjectsUtils } from './utils';
7171

7272
// BEWARE: The SavedObjectClient depends on the implementation details of the SavedObjectsRepository
7373
// so any breaking changes to this repository are considered breaking changes to the SavedObjectsClient.
@@ -563,7 +563,7 @@ export class SavedObjectsRepository {
563563
preflightResult = await this.preflightCheckIncludesNamespace(type, id, namespace);
564564
const existingNamespaces = getSavedObjectNamespaces(undefined, preflightResult);
565565
const remainingNamespaces = existingNamespaces?.filter(
566-
(x) => x !== namespaceIdToString(namespace)
566+
(x) => x !== SavedObjectsUtils.namespaceIdToString(namespace)
567567
);
568568

569569
if (remainingNamespaces?.length) {
@@ -887,7 +887,9 @@ export class SavedObjectsRepository {
887887
const { originId, updated_at: updatedAt } = doc._source;
888888
let namespaces = [];
889889
if (!this._registry.isNamespaceAgnostic(type)) {
890-
namespaces = doc._source.namespaces ?? [namespaceIdToString(doc._source.namespace)];
890+
namespaces = doc._source.namespaces ?? [
891+
SavedObjectsUtils.namespaceIdToString(doc._source.namespace),
892+
];
891893
}
892894

893895
return {
@@ -944,7 +946,9 @@ export class SavedObjectsRepository {
944946

945947
let namespaces: string[] = [];
946948
if (!this._registry.isNamespaceAgnostic(type)) {
947-
namespaces = body._source.namespaces ?? [namespaceIdToString(body._source.namespace)];
949+
namespaces = body._source.namespaces ?? [
950+
SavedObjectsUtils.namespaceIdToString(body._source.namespace),
951+
];
948952
}
949953

950954
return {
@@ -1020,7 +1024,9 @@ export class SavedObjectsRepository {
10201024
const { originId } = body.get._source;
10211025
let namespaces = [];
10221026
if (!this._registry.isNamespaceAgnostic(type)) {
1023-
namespaces = body.get._source.namespaces ?? [namespaceIdToString(body.get._source.namespace)];
1027+
namespaces = body.get._source.namespaces ?? [
1028+
SavedObjectsUtils.namespaceIdToString(body.get._source.namespace),
1029+
];
10241030
}
10251031

10261032
return {
@@ -1257,9 +1263,11 @@ export class SavedObjectsRepository {
12571263
});
12581264

12591265
const getNamespaceId = (objectNamespace?: string) =>
1260-
objectNamespace !== undefined ? namespaceStringToId(objectNamespace) : namespace;
1266+
objectNamespace !== undefined
1267+
? SavedObjectsUtils.namespaceStringToId(objectNamespace)
1268+
: namespace;
12611269
const getNamespaceString = (objectNamespace?: string) =>
1262-
objectNamespace ?? namespaceIdToString(namespace);
1270+
objectNamespace ?? SavedObjectsUtils.namespaceIdToString(namespace);
12631271

12641272
const bulkGetDocs = expectedBulkGetResults
12651273
.filter(isRight)
@@ -1319,7 +1327,7 @@ export class SavedObjectsRepository {
13191327
};
13201328
}
13211329
namespaces = actualResult._source.namespaces ?? [
1322-
namespaceIdToString(actualResult._source.namespace),
1330+
SavedObjectsUtils.namespaceIdToString(actualResult._source.namespace),
13231331
];
13241332
versionProperties = getExpectedVersionProperties(version, actualResult);
13251333
} else {
@@ -1522,7 +1530,7 @@ export class SavedObjectsRepository {
15221530
const savedObject = this._serializer.rawToSavedObject(raw);
15231531
const { namespace, type } = savedObject;
15241532
if (this._registry.isSingleNamespace(type)) {
1525-
savedObject.namespaces = [namespaceIdToString(namespace)];
1533+
savedObject.namespaces = [SavedObjectsUtils.namespaceIdToString(namespace)];
15261534
}
15271535
return omit(savedObject, 'namespace') as SavedObject<T>;
15281536
}
@@ -1545,7 +1553,7 @@ export class SavedObjectsRepository {
15451553
}
15461554

15471555
const namespaces = raw._source.namespaces;
1548-
return namespaces?.includes(namespaceIdToString(namespace)) ?? false;
1556+
return namespaces?.includes(SavedObjectsUtils.namespaceIdToString(namespace)) ?? false;
15491557
}
15501558

15511559
/**
@@ -1665,15 +1673,15 @@ function getSavedObjectNamespaces(
16651673
if (document) {
16661674
return document._source?.namespaces;
16671675
}
1668-
return [namespaceIdToString(namespace)];
1676+
return [SavedObjectsUtils.namespaceIdToString(namespace)];
16691677
}
16701678

16711679
/**
16721680
* Ensure that a namespace is always in its namespace ID representation.
16731681
* This allows `'default'` to be used interchangeably with `undefined`.
16741682
*/
16751683
const normalizeNamespace = (namespace?: string) =>
1676-
namespace === undefined ? namespace : namespaceStringToId(namespace);
1684+
namespace === undefined ? namespace : SavedObjectsUtils.namespaceStringToId(namespace);
16771685

16781686
/**
16791687
* Extracts the contents of a decorated error to return the attributes for bulk operations.

0 commit comments

Comments
 (0)