Skip to content

Commit

Permalink
add generic typings for SavedObjectMigrationFn
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Apr 20, 2020
1 parent 7b57caf commit b769c2a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A migration function for a [saved object type](./kibana-plugin-core-server.saved
<b>Signature:</b>

```typescript
export declare type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc;
export declare type SavedObjectMigrationFn<InputProps = any, MigratedProps = any> = (doc: SavedObjectUnsanitizedDoc<InputProps>, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc<MigratedProps>;
```

## Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<b>Signature:</b>

```typescript
export declare type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
export declare type SavedObjectSanitizedDoc<T = unknown> = SavedObjectDoc<T> & Referencable;
```
6 changes: 3 additions & 3 deletions src/core/server/saved_objects/migrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import { SavedObjectsMigrationLogger } from './core/migration_logger';
*
* @public
*/
export type SavedObjectMigrationFn = (
doc: SavedObjectUnsanitizedDoc,
export type SavedObjectMigrationFn<InputProps = any, MigratedProps = any> = (
doc: SavedObjectUnsanitizedDoc<InputProps>,
context: SavedObjectMigrationContext
) => SavedObjectUnsanitizedDoc;
) => SavedObjectUnsanitizedDoc<MigratedProps>;

/**
* Migration context provided when invoking a {@link SavedObjectMigrationFn | migration handler}
Expand Down
8 changes: 4 additions & 4 deletions src/core/server/saved_objects/serialization/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export interface SavedObjectsRawDocSource {
* that future props are likely to be added. Migrations support this
* scenario out of the box.
*/
interface SavedObjectDoc {
attributes: any;
interface SavedObjectDoc<T = unknown> {
attributes: T;
id?: string; // NOTE: SavedObjectDoc is used for uncreated objects where `id` is optional
type: string;
namespace?: string;
Expand All @@ -75,7 +75,7 @@ interface Referencable {
*
* @public
*/
export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial<Referencable>;
export type SavedObjectUnsanitizedDoc<T = unknown> = SavedObjectDoc<T> & Partial<Referencable>;

/** @public */
export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
export type SavedObjectSanitizedDoc<T = unknown> = SavedObjectDoc<T> & Referencable;
4 changes: 2 additions & 2 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ export interface SavedObjectMigrationContext {
// Warning: (ae-forgotten-export) The symbol "SavedObjectUnsanitizedDoc" needs to be exported by the entry point index.d.ts
//
// @public
export type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc;
export type SavedObjectMigrationFn<InputProps = any, MigratedProps = any> = (doc: SavedObjectUnsanitizedDoc<InputProps>, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc<MigratedProps>;

// @public
export interface SavedObjectMigrationMap {
Expand Down Expand Up @@ -1710,7 +1710,7 @@ export interface SavedObjectsAddToNamespacesOptions extends SavedObjectsBaseOpti
// Warning: (ae-forgotten-export) The symbol "Referencable" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
export type SavedObjectSanitizedDoc<T = unknown> = SavedObjectDoc<T> & Referencable;

// @public (undocumented)
export interface SavedObjectsBaseOptions {
Expand Down

0 comments on commit b769c2a

Please sign in to comment.