diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md
index b8cffb36b821a..a91a5bec988b7 100644
--- a/docs/development/core/server/kibana-plugin-core-server.md
+++ b/docs/development/core/server/kibana-plugin-core-server.md
@@ -263,13 +263,14 @@ The plugin integrates with the core system via lifecycle events: `setup`
| [SavedObjectAttribute](./kibana-plugin-core-server.savedobjectattribute.md) | Type definition for a Saved Object attribute value |
| [SavedObjectAttributeSingle](./kibana-plugin-core-server.savedobjectattributesingle.md) | Don't use this type, it's simply a helper type for [SavedObjectAttribute](./kibana-plugin-core-server.savedobjectattribute.md) |
| [SavedObjectMigrationFn](./kibana-plugin-core-server.savedobjectmigrationfn.md) | A migration function for a [saved object type](./kibana-plugin-core-server.savedobjectstype.md) used to migrate it to a given version |
-| [SavedObjectSanitizedDoc](./kibana-plugin-core-server.savedobjectsanitizeddoc.md) | |
+| [SavedObjectSanitizedDoc](./kibana-plugin-core-server.savedobjectsanitizeddoc.md) | Describes Saved Object documents that have passed through the migration framework and are guaranteed to have a references
root property. |
| [SavedObjectsClientContract](./kibana-plugin-core-server.savedobjectsclientcontract.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state.\#\# SavedObjectsClient errorsSince the SavedObjectsClient has its hands in everything we are a little paranoid about the way we present errors back to to application code. Ideally, all errors will be either:1. Caused by bad implementation (ie. undefined is not a function) and as such unpredictable 2. An error that has been classified and decorated appropriately by the decorators in [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md)Type 1 errors are inevitable, but since all expected/handle-able errors should be Type 2 the isXYZError()
helpers exposed at SavedObjectsErrorHelpers
should be used to understand and manage error responses from the SavedObjectsClient
.Type 2 errors are decorated versions of the source error, so if the elasticsearch client threw an error it will be decorated based on its type. That means that rather than looking for error.body.error.type
or doing substring checks on error.body.error.reason
, just use the helpers to understand the meaning of the error:\`\`\`js if (SavedObjectsErrorHelpers.isNotFoundError(error)) { // handle 404 }if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { // 401 handling should be automatic, but in case you wanted to know }// always rethrow the error unless you handle it throw error; \`\`\`\#\#\# 404s from missing indexFrom the perspective of application code and APIs the SavedObjectsClient is a black box that persists objects. One of the internal details that users have no control over is that we use an elasticsearch index for persistance and that index might be missing.At the time of writing we are in the process of transitioning away from the operating assumption that the SavedObjects index is always available. Part of this transition is handling errors resulting from an index missing. These used to trigger a 500 error in most cases, and in others cause 404s with different error messages.From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The object the request/call was targeting could not be found. This is why \#14141 takes special care to ensure that 404 errors are generic and don't distinguish between index missing or document missing.See [SavedObjectsClient](./kibana-plugin-core-server.savedobjectsclient.md) See [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) |
| [SavedObjectsClientFactory](./kibana-plugin-core-server.savedobjectsclientfactory.md) | Describes the factory used to create instances of the Saved Objects Client. |
| [SavedObjectsClientFactoryProvider](./kibana-plugin-core-server.savedobjectsclientfactoryprovider.md) | Provider to invoke to retrieve a [SavedObjectsClientFactory](./kibana-plugin-core-server.savedobjectsclientfactory.md). |
| [SavedObjectsClientWrapperFactory](./kibana-plugin-core-server.savedobjectsclientwrapperfactory.md) | Describes the factory used to create instances of Saved Objects Client Wrappers. |
| [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) | Describe a [saved object type mapping](./kibana-plugin-core-server.savedobjectstypemappingdefinition.md) field.Please refer to [elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html) For the mapping documentation |
| [SavedObjectsNamespaceType](./kibana-plugin-core-server.savedobjectsnamespacetype.md) | The namespace type dictates how a saved object can be interacted in relation to namespaces. Each type is mutually exclusive: \* single (default): this type of saved object is namespace-isolated, e.g., it exists in only one namespace. \* multiple: this type of saved object is shareable, e.g., it can exist in one or more namespaces. \* agnostic: this type of saved object is global.Note: do not write logic that uses this value directly; instead, use the appropriate accessors in the [type registry](./kibana-plugin-core-server.savedobjecttyperegistry.md). |
+| [SavedObjectUnsanitizedDoc](./kibana-plugin-core-server.savedobjectunsanitizeddoc.md) | Describes Saved Object documents from Kibana < 7.0.0 which don't have a references
root property defined. This type should only be used in migrations. |
| [ScopeableRequest](./kibana-plugin-core-server.scopeablerequest.md) | A user credentials container. It accommodates the necessary auth credentials to impersonate the current user.See [KibanaRequest](./kibana-plugin-core-server.kibanarequest.md). |
| [ServiceStatusLevel](./kibana-plugin-core-server.servicestatuslevel.md) | A convenience type that represents the union of each value in [ServiceStatusLevels](./kibana-plugin-core-server.servicestatuslevels.md). |
| [SharedGlobalConfig](./kibana-plugin-core-server.sharedglobalconfig.md) | |
diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectsanitizeddoc.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectsanitizeddoc.md
index 47feb50e9a827..6d4e252fe7532 100644
--- a/docs/development/core/server/kibana-plugin-core-server.savedobjectsanitizeddoc.md
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectsanitizeddoc.md
@@ -4,6 +4,7 @@
## SavedObjectSanitizedDoc type
+Describes Saved Object documents that have passed through the migration framework and are guaranteed to have a `references` root property.
Signature:
diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectunsanitizeddoc.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectunsanitizeddoc.md
new file mode 100644
index 0000000000000..be51400addbbc
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectunsanitizeddoc.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectUnsanitizedDoc](./kibana-plugin-core-server.savedobjectunsanitizeddoc.md)
+
+## SavedObjectUnsanitizedDoc type
+
+Describes Saved Object documents from Kibana < 7.0.0 which don't have a `references` root property defined. This type should only be used in migrations.
+
+Signature:
+
+```typescript
+export declare type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
+```
diff --git a/src/core/server/saved_objects/migrations/core/document_migrator.test.ts b/src/core/server/saved_objects/migrations/core/document_migrator.test.ts
index 64270c677ff20..3ec478e3ca28d 100644
--- a/src/core/server/saved_objects/migrations/core/document_migrator.test.ts
+++ b/src/core/server/saved_objects/migrations/core/document_migrator.test.ts
@@ -149,13 +149,13 @@ describe('DocumentMigrator', () => {
expect(_.get(migratedDoc, 'attributes.name')).toBe('Mike');
});
- it('migrates meta properties', () => {
+ it('migrates root properties', () => {
const migrator = new DocumentMigrator({
...testOpts(),
typeRegistry: createRegistry({
name: 'acl',
migrations: {
- '2.3.5': setAttr('acl', 'admins-only,sucka!'),
+ '2.3.5': setAttr('acl', 'admins-only, sucka!'),
},
}),
});
@@ -165,13 +165,13 @@ describe('DocumentMigrator', () => {
attributes: { name: 'Tyler' },
acl: 'anyone',
migrationVersion: {},
- });
+ } as SavedObjectUnsanitizedDoc);
expect(actual).toEqual({
id: 'me',
type: 'user',
attributes: { name: 'Tyler' },
migrationVersion: { acl: '2.3.5' },
- acl: 'admins-only,sucka!',
+ acl: 'admins-only, sucka!',
});
});
@@ -241,7 +241,7 @@ describe('DocumentMigrator', () => {
type: 'user',
attributes: { name: 'Tyler' },
bbb: 'Shazm',
- });
+ } as SavedObjectUnsanitizedDoc);
expect(actual).toEqual({
id: 'me',
type: 'user',
@@ -405,7 +405,7 @@ describe('DocumentMigrator', () => {
attributes: { name: 'Callie' },
dawg: 'Yo',
migrationVersion: {},
- });
+ } as SavedObjectUnsanitizedDoc);
expect(actual).toEqual({
id: 'smelly',
type: 'foo',
diff --git a/src/core/server/saved_objects/migrations/core/document_migrator.ts b/src/core/server/saved_objects/migrations/core/document_migrator.ts
index 0284f513a361c..4ddb2b070d3ac 100644
--- a/src/core/server/saved_objects/migrations/core/document_migrator.ts
+++ b/src/core/server/saved_objects/migrations/core/document_migrator.ts
@@ -279,7 +279,7 @@ function props(doc: SavedObjectUnsanitizedDoc) {
*/
function propVersion(doc: SavedObjectUnsanitizedDoc | ActiveMigrations, prop: string) {
return (
- (doc[prop] && doc[prop].latestVersion) ||
+ ((doc as any)[prop] && (doc as any)[prop].latestVersion) ||
(doc.migrationVersion && (doc as any).migrationVersion[prop])
);
}
diff --git a/src/core/server/saved_objects/serialization/types.ts b/src/core/server/saved_objects/serialization/types.ts
index 7ea61f67e9496..a33e16895078e 100644
--- a/src/core/server/saved_objects/serialization/types.ts
+++ b/src/core/server/saved_objects/serialization/types.ts
@@ -45,10 +45,7 @@ export interface SavedObjectsRawDocSource {
}
/**
- * A saved object type definition that allows for miscellaneous, unknown
- * properties, as current discussions around security, ACLs, etc indicate
- * that future props are likely to be added. Migrations support this
- * scenario out of the box.
+ * Saved Object base document
*/
interface SavedObjectDoc {
attributes: any;
@@ -59,8 +56,6 @@ interface SavedObjectDoc {
migrationVersion?: SavedObjectsMigrationVersion;
version?: string;
updated_at?: string;
-
- [rootProp: string]: any;
}
interface Referencable {
@@ -68,14 +63,18 @@ interface Referencable {
}
/**
- * We want to have two types, one that guarantees a "references" attribute
- * will exist and one that allows it to be null. Since we're not migrating
- * all the saved objects to have a "references" array, we need to support
- * the scenarios where it may be missing (ex migrations).
+ * Describes Saved Object documents from Kibana < 7.0.0 which don't have a
+ * `references` root property defined. This type should only be used in
+ * migrations.
*
* @public
*/
export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
-/** @public */
+/**
+ * Describes Saved Object documents that have passed through the migration
+ * framework and are guaranteed to have a `references` root property.
+ *
+ * @public
+ */
export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md
index 2efa7dac393b4..a36e746f6d940 100644
--- a/src/core/server/server.api.md
+++ b/src/core/server/server.api.md
@@ -1707,7 +1707,7 @@ export interface SavedObjectsAddToNamespacesOptions extends SavedObjectsBaseOpti
// Warning: (ae-forgotten-export) The symbol "SavedObjectDoc" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Referencable" needs to be exported by the entry point index.d.ts
//
-// @public (undocumented)
+// @public
export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
// @public (undocumented)
diff --git a/src/dev/run_check_published_api_changes.ts b/src/dev/run_check_published_api_changes.ts
index ba3cd1280f34b..6d5fa04a93951 100644
--- a/src/dev/run_check_published_api_changes.ts
+++ b/src/dev/run_check_published_api_changes.ts
@@ -250,7 +250,7 @@ async function run(
Options:
--accept {dim Accepts all changes by updating the API Review files and documentation}
--docs {dim Updates the Core API documentation}
- --only {dim RegExp that folder names must match, folders: [${folders.join(', ')}]}
+ --filter {dim RegExp that folder names must match, folders: [${folders.join(', ')}]}
--help {dim Show this message}
`)
);