Skip to content

Commit e2f5d65

Browse files
committed
Address remaining items from fifth round of PR review feedback
1 parent 418f1cd commit e2f5d65

6 files changed

Lines changed: 24 additions & 12 deletions

File tree

docs/api/saved-objects/bulk_create.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The API returns the following:
104104
"type": "dashboard",
105105
"error": {
106106
"statusCode": 409,
107-
"message": "version conflict, document already exists"
107+
"message": "Saved object [dashboard/be3733a0-9efe-11e7-acb3-3dab96693fab] conflict"
108108
}
109109
}
110110
]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## SavedObjectsRepository.addToNamespaces() method
66

7+
Adds one or more namespaces to a given multi-namespace saved object. This method and \[`deleteFromNamespaces`<!-- -->\][SavedObjectsRepository.deleteFromNamespaces()](./kibana-plugin-core-server.savedobjectsrepository.deletefromnamespaces.md) are the only ways to change which Spaces a multi-namespace saved object is shared to.
8+
79
<b>Signature:</b>
810

911
```typescript

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## SavedObjectsRepository.deleteFromNamespaces() method
66

7+
Removes one or more namespaces from a given multi-namespace saved object. If no namespaces remain, the saved object is deleted entirely. This method and \[`addToNamespaces`<!-- -->\][SavedObjectsRepository.addToNamespaces()](./kibana-plugin-core-server.savedobjectsrepository.addtonamespaces.md) are the only ways to change which Spaces a multi-namespace saved object is shared to.
8+
79
<b>Signature:</b>
810

911
```typescript

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ export declare class SavedObjectsRepository
1515

1616
| Method | Modifiers | Description |
1717
| --- | --- | --- |
18-
| [addToNamespaces(type, id, namespaces, options)](./kibana-plugin-core-server.savedobjectsrepository.addtonamespaces.md) | | |
18+
| [addToNamespaces(type, id, namespaces, options)](./kibana-plugin-core-server.savedobjectsrepository.addtonamespaces.md) | | Adds one or more namespaces to a given multi-namespace saved object. This method and \[<code>deleteFromNamespaces</code>\][SavedObjectsRepository.deleteFromNamespaces()](./kibana-plugin-core-server.savedobjectsrepository.deletefromnamespaces.md) are the only ways to change which Spaces a multi-namespace saved object is shared to. |
1919
| [bulkCreate(objects, options)](./kibana-plugin-core-server.savedobjectsrepository.bulkcreate.md) | | Creates multiple documents at once |
2020
| [bulkGet(objects, options)](./kibana-plugin-core-server.savedobjectsrepository.bulkget.md) | | Returns an array of objects by id |
2121
| [bulkUpdate(objects, options)](./kibana-plugin-core-server.savedobjectsrepository.bulkupdate.md) | | Updates multiple objects in bulk |
2222
| [create(type, attributes, options)](./kibana-plugin-core-server.savedobjectsrepository.create.md) | | Persists an object |
2323
| [delete(type, id, options)](./kibana-plugin-core-server.savedobjectsrepository.delete.md) | | Deletes an object |
2424
| [deleteByNamespace(namespace, options)](./kibana-plugin-core-server.savedobjectsrepository.deletebynamespace.md) | | Deletes all objects from the provided namespace. |
25-
| [deleteFromNamespaces(type, id, namespaces, options)](./kibana-plugin-core-server.savedobjectsrepository.deletefromnamespaces.md) | | |
25+
| [deleteFromNamespaces(type, id, namespaces, options)](./kibana-plugin-core-server.savedobjectsrepository.deletefromnamespaces.md) | | Removes one or more namespaces from a given multi-namespace saved object. If no namespaces remain, the saved object is deleted entirely. This method and \[<code>addToNamespaces</code>\][SavedObjectsRepository.addToNamespaces()](./kibana-plugin-core-server.savedobjectsrepository.addtonamespaces.md) are the only ways to change which Spaces a multi-namespace saved object is shared to. |
2626
| [find({ search, defaultSearchOperator, searchFields, hasReference, page, perPage, sortField, sortOrder, fields, namespace, type, filter, })](./kibana-plugin-core-server.savedobjectsrepository.find.md) | | |
2727
| [get(type, id, options)](./kibana-plugin-core-server.savedobjectsrepository.get.md) | | Gets a single object |
2828
| [incrementCounter(type, id, counterFieldName, options)](./kibana-plugin-core-server.savedobjectsrepository.incrementcounter.md) | | Increases a counter field by one. Creates the document if one doesn't exist for the given id. |

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export class SavedObjectsRepository {
349349
const indexFound = bulkGetResponse.status !== 404;
350350
const actualResult = indexFound ? bulkGetResponse.docs[esRequestIndex] : undefined;
351351
const docFound = indexFound && actualResult.found === true;
352-
if (docFound && !this._rawInNamespaces(actualResult, namespace)) {
352+
if (docFound && !this.rawDocExistsInNamespace(actualResult, namespace)) {
353353
const { id, type } = object;
354354
return {
355355
tag: 'Left' as 'Left',
@@ -768,7 +768,7 @@ export class SavedObjectsRepository {
768768
const { type, id, esRequestIndex } = expectedResult.value;
769769
const doc = bulkGetResponse.docs[esRequestIndex];
770770

771-
if (!doc.found || !this._rawInNamespaces(doc, namespace)) {
771+
if (!doc.found || !this.rawDocExistsInNamespace(doc, namespace)) {
772772
return ({
773773
id,
774774
type,
@@ -819,7 +819,7 @@ export class SavedObjectsRepository {
819819

820820
const docNotFound = response.found === false;
821821
const indexNotFound = response.status === 404;
822-
if (docNotFound || indexNotFound || !this._rawInNamespaces(response, namespace)) {
822+
if (docNotFound || indexNotFound || !this.rawDocExistsInNamespace(response, namespace)) {
823823
// see "404s from missing index" above
824824
throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
825825
}
@@ -904,6 +904,11 @@ export class SavedObjectsRepository {
904904
};
905905
}
906906

907+
/**
908+
* Adds one or more namespaces to a given multi-namespace saved object. This method and
909+
* [`deleteFromNamespaces`]{@link SavedObjectsRepository.deleteFromNamespaces} are the only ways to change which Spaces a multi-namespace
910+
* saved object is shared to.
911+
*/
907912
async addToNamespaces(
908913
type: string,
909914
id: string,
@@ -957,6 +962,11 @@ export class SavedObjectsRepository {
957962
return {};
958963
}
959964

965+
/**
966+
* Removes one or more namespaces from a given multi-namespace saved object. If no namespaces remain, the saved object is deleted
967+
* entirely. This method and [`addToNamespaces`]{@link SavedObjectsRepository.addToNamespaces} are the only ways to change which Spaces a
968+
* multi-namespace saved object is shared to.
969+
*/
960970
async deleteFromNamespaces(
961971
type: string,
962972
id: string,
@@ -1127,7 +1137,7 @@ export class SavedObjectsRepository {
11271137
const indexFound = bulkGetResponse.status !== 404;
11281138
const actualResult = indexFound ? bulkGetResponse.docs[esRequestIndex] : undefined;
11291139
const docFound = indexFound && actualResult.found === true;
1130-
if (!docFound || !this._rawInNamespaces(actualResult, namespace)) {
1140+
if (!docFound || !this.rawDocExistsInNamespace(actualResult, namespace)) {
11311141
return {
11321142
tag: 'Left' as 'Left',
11331143
error: {
@@ -1344,7 +1354,7 @@ export class SavedObjectsRepository {
13441354
return omit(savedObject, 'namespace');
13451355
}
13461356

1347-
private _rawInNamespaces(raw: SavedObjectsRawDoc, namespace?: string) {
1357+
private rawDocExistsInNamespace(raw: SavedObjectsRawDoc, namespace?: string) {
13481358
const rawDocType = raw._source.type as string;
13491359

13501360
// if the type is namespace isolated, or namespace agnostic, we can continue to rely on the guarantees
@@ -1383,7 +1393,7 @@ export class SavedObjectsRepository {
13831393
const indexFound = response.status !== 404;
13841394
const docFound = indexFound && response.found === true;
13851395
if (docFound) {
1386-
if (!this._rawInNamespaces(response, namespace)) {
1396+
if (!this.rawDocExistsInNamespace(response, namespace)) {
13871397
throw SavedObjectsErrorHelpers.createConflictError(type, id);
13881398
}
13891399
return getSavedObjectNamespaces(namespace, response);
@@ -1415,7 +1425,7 @@ export class SavedObjectsRepository {
14151425

14161426
const indexFound = response.status !== 404;
14171427
const docFound = indexFound && response.found === true;
1418-
if (!docFound || !this._rawInNamespaces(response, namespace)) {
1428+
if (!docFound || !this.rawDocExistsInNamespace(response, namespace)) {
14191429
throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
14201430
}
14211431
return response as SavedObjectsRawDoc;

src/core/server/server.api.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,6 @@ export interface SavedObjectsRawDoc {
21112111

21122112
// @public (undocumented)
21132113
export class SavedObjectsRepository {
2114-
// (undocumented)
21152114
addToNamespaces(type: string, id: string, namespaces: string[], options?: SavedObjectsAddToNamespacesOptions): Promise<{}>;
21162115
bulkCreate<T = unknown>(objects: Array<SavedObjectsBulkCreateObject<T>>, options?: SavedObjectsCreateOptions): Promise<SavedObjectsBulkResponse<T>>;
21172116
bulkGet<T = unknown>(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise<SavedObjectsBulkResponse<T>>;
@@ -2123,7 +2122,6 @@ export class SavedObjectsRepository {
21232122
static createRepository(migrator: KibanaMigrator, typeRegistry: SavedObjectTypeRegistry, indexName: string, callCluster: APICaller, extraTypes?: string[], injectedConstructor?: any): ISavedObjectsRepository;
21242123
delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>;
21252124
deleteByNamespace(namespace: string, options?: SavedObjectsDeleteByNamespaceOptions): Promise<any>;
2126-
// (undocumented)
21272125
deleteFromNamespaces(type: string, id: string, namespaces: string[], options?: SavedObjectsDeleteFromNamespacesOptions): Promise<{}>;
21282126
// (undocumented)
21292127
find<T = unknown>({ search, defaultSearchOperator, searchFields, hasReference, page, perPage, sortField, sortOrder, fields, namespace, type, filter, }: SavedObjectsFindOptions): Promise<SavedObjectsFindResponse<T>>;

0 commit comments

Comments
 (0)