Skip to content

Commit 5d6d8a6

Browse files
committed
Remove SO root property index signature (#64434)
* Remove SO root property index signature * Update documentation
1 parent d48b412 commit 5d6d8a6

8 files changed

Lines changed: 35 additions & 21 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,14 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
263263
| [SavedObjectAttribute](./kibana-plugin-core-server.savedobjectattribute.md) | Type definition for a Saved Object attribute value |
264264
| [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) |
265265
| [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 |
266-
| [SavedObjectSanitizedDoc](./kibana-plugin-core-server.savedobjectsanitizeddoc.md) | |
266+
| [SavedObjectSanitizedDoc](./kibana-plugin-core-server.savedobjectsanitizeddoc.md) | Describes Saved Object documents that have passed through the migration framework and are guaranteed to have a <code>references</code> root property. |
267267
| [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 errors<!-- -->Since 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 <code>isXYZError()</code> helpers exposed at <code>SavedObjectsErrorHelpers</code> should be used to understand and manage error responses from the <code>SavedObjectsClient</code>.<!-- -->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 <code>error.body.error.type</code> or doing substring checks on <code>error.body.error.reason</code>, 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 index<!-- -->From 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) |
268268
| [SavedObjectsClientFactory](./kibana-plugin-core-server.savedobjectsclientfactory.md) | Describes the factory used to create instances of the Saved Objects Client. |
269269
| [SavedObjectsClientFactoryProvider](./kibana-plugin-core-server.savedobjectsclientfactoryprovider.md) | Provider to invoke to retrieve a [SavedObjectsClientFactory](./kibana-plugin-core-server.savedobjectsclientfactory.md)<!-- -->. |
270270
| [SavedObjectsClientWrapperFactory](./kibana-plugin-core-server.savedobjectsclientwrapperfactory.md) | Describes the factory used to create instances of Saved Objects Client Wrappers. |
271271
| [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 |
272272
| [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)<!-- -->. |
273+
| [SavedObjectUnsanitizedDoc](./kibana-plugin-core-server.savedobjectunsanitizeddoc.md) | Describes Saved Object documents from Kibana &lt; 7.0.0 which don't have a <code>references</code> root property defined. This type should only be used in migrations. |
273274
| [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)<!-- -->. |
274275
| [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)<!-- -->. |
275276
| [SharedGlobalConfig](./kibana-plugin-core-server.sharedglobalconfig.md) | |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## SavedObjectSanitizedDoc type
66

7+
Describes Saved Object documents that have passed through the migration framework and are guaranteed to have a `references` root property.
78

89
<b>Signature:</b>
910

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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; [SavedObjectUnsanitizedDoc](./kibana-plugin-core-server.savedobjectunsanitizeddoc.md)
4+
5+
## SavedObjectUnsanitizedDoc type
6+
7+
Describes Saved Object documents from Kibana &lt; 7.0.0 which don't have a `references` root property defined. This type should only be used in migrations.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export declare type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial<Referencable>;
13+
```

src/core/server/saved_objects/migrations/core/document_migrator.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ describe('DocumentMigrator', () => {
149149
expect(_.get(migratedDoc, 'attributes.name')).toBe('Mike');
150150
});
151151

152-
it('migrates meta properties', () => {
152+
it('migrates root properties', () => {
153153
const migrator = new DocumentMigrator({
154154
...testOpts(),
155155
typeRegistry: createRegistry({
156156
name: 'acl',
157157
migrations: {
158-
'2.3.5': setAttr('acl', 'admins-only,sucka!'),
158+
'2.3.5': setAttr('acl', 'admins-only, sucka!'),
159159
},
160160
}),
161161
});
@@ -165,13 +165,13 @@ describe('DocumentMigrator', () => {
165165
attributes: { name: 'Tyler' },
166166
acl: 'anyone',
167167
migrationVersion: {},
168-
});
168+
} as SavedObjectUnsanitizedDoc);
169169
expect(actual).toEqual({
170170
id: 'me',
171171
type: 'user',
172172
attributes: { name: 'Tyler' },
173173
migrationVersion: { acl: '2.3.5' },
174-
acl: 'admins-only,sucka!',
174+
acl: 'admins-only, sucka!',
175175
});
176176
});
177177

@@ -241,7 +241,7 @@ describe('DocumentMigrator', () => {
241241
type: 'user',
242242
attributes: { name: 'Tyler' },
243243
bbb: 'Shazm',
244-
});
244+
} as SavedObjectUnsanitizedDoc);
245245
expect(actual).toEqual({
246246
id: 'me',
247247
type: 'user',
@@ -405,7 +405,7 @@ describe('DocumentMigrator', () => {
405405
attributes: { name: 'Callie' },
406406
dawg: 'Yo',
407407
migrationVersion: {},
408-
});
408+
} as SavedObjectUnsanitizedDoc);
409409
expect(actual).toEqual({
410410
id: 'smelly',
411411
type: 'foo',

src/core/server/saved_objects/migrations/core/document_migrator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ function props(doc: SavedObjectUnsanitizedDoc) {
279279
*/
280280
function propVersion(doc: SavedObjectUnsanitizedDoc | ActiveMigrations, prop: string) {
281281
return (
282-
(doc[prop] && doc[prop].latestVersion) ||
282+
((doc as any)[prop] && (doc as any)[prop].latestVersion) ||
283283
(doc.migrationVersion && (doc as any).migrationVersion[prop])
284284
);
285285
}

src/core/server/saved_objects/serialization/types.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ export interface SavedObjectsRawDocSource {
4545
}
4646

4747
/**
48-
* A saved object type definition that allows for miscellaneous, unknown
49-
* properties, as current discussions around security, ACLs, etc indicate
50-
* that future props are likely to be added. Migrations support this
51-
* scenario out of the box.
48+
* Saved Object base document
5249
*/
5350
interface SavedObjectDoc {
5451
attributes: any;
@@ -59,23 +56,25 @@ interface SavedObjectDoc {
5956
migrationVersion?: SavedObjectsMigrationVersion;
6057
version?: string;
6158
updated_at?: string;
62-
63-
[rootProp: string]: any;
6459
}
6560

6661
interface Referencable {
6762
references: SavedObjectReference[];
6863
}
6964

7065
/**
71-
* We want to have two types, one that guarantees a "references" attribute
72-
* will exist and one that allows it to be null. Since we're not migrating
73-
* all the saved objects to have a "references" array, we need to support
74-
* the scenarios where it may be missing (ex migrations).
66+
* Describes Saved Object documents from Kibana < 7.0.0 which don't have a
67+
* `references` root property defined. This type should only be used in
68+
* migrations.
7569
*
7670
* @public
7771
*/
7872
export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial<Referencable>;
7973

80-
/** @public */
74+
/**
75+
* Describes Saved Object documents that have passed through the migration
76+
* framework and are guaranteed to have a `references` root property.
77+
*
78+
* @public
79+
*/
8180
export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;

src/core/server/server.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ export interface SavedObjectsAddToNamespacesOptions extends SavedObjectsBaseOpti
17071707
// Warning: (ae-forgotten-export) The symbol "SavedObjectDoc" needs to be exported by the entry point index.d.ts
17081708
// Warning: (ae-forgotten-export) The symbol "Referencable" needs to be exported by the entry point index.d.ts
17091709
//
1710-
// @public (undocumented)
1710+
// @public
17111711
export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
17121712

17131713
// @public (undocumented)

src/dev/run_check_published_api_changes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ async function run(
250250
Options:
251251
--accept {dim Accepts all changes by updating the API Review files and documentation}
252252
--docs {dim Updates the Core API documentation}
253-
--only {dim RegExp that folder names must match, folders: [${folders.join(', ')}]}
253+
--filter {dim RegExp that folder names must match, folders: [${folders.join(', ')}]}
254254
--help {dim Show this message}
255255
`)
256256
);

0 commit comments

Comments
 (0)