Skip to content

Commit

Permalink
Remove legacy SavedObjects (#76852)
Browse files Browse the repository at this point in the history
* remove legacy SO integration

* cleanup integration in the legacy platorm

* remove so schema

* update docs

* remove leftovers, update docs

* update docs after merge master
  • Loading branch information
mshustov authored Sep 8, 2020
1 parent bb2aa42 commit bcaffba
Show file tree
Hide file tree
Showing 44 changed files with 47 additions and 2,026 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export interface SavedObjectsServiceSetup

When plugins access the Saved Objects client, a new client is created using the factory provided to `setClientFactory` and wrapped by all wrappers registered through `addClientWrapper`<!-- -->.

All the setup APIs will throw if called after the service has started, and therefor cannot be used from legacy plugin code. Legacy plugins should use the legacy savedObject service until migrated.

## Example 1


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ See the [mappings format](./kibana-plugin-core-server.savedobjectstypemappingdef
registerType: (type: SavedObjectsType) => void;
```

## Remarks

The type definition is an aggregation of the legacy savedObjects `schema`<!-- -->, `mappings` and `migration` concepts. This API is the single entry point to register saved object types in the new platform.

## Example


Expand Down
2 changes: 0 additions & 2 deletions kibana.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export namespace Legacy {
export type KibanaConfig = LegacyKibanaServer.KibanaConfig;
export type Request = LegacyKibanaServer.Request;
export type ResponseToolkit = LegacyKibanaServer.ResponseToolkit;
export type SavedObjectsClient = LegacyKibanaServer.SavedObjectsClient;
export type SavedObjectsService = LegacyKibanaServer.SavedObjectsLegacyService;
export type Server = LegacyKibanaServer.Server;

export type InitPluginFunction = LegacyKibanaPluginSpec.InitPluginFunction;
Expand Down
2 changes: 0 additions & 2 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ export {
SavedObjectUnsanitizedDoc,
SavedObjectsRepositoryFactory,
SavedObjectsResolveImportErrorsOptions,
SavedObjectsSchema,
SavedObjectsSerializer,
SavedObjectsLegacyService,
SavedObjectsUpdateOptions,
SavedObjectsUpdateResponse,
SavedObjectsAddToNamespacesOptions,
Expand Down
8 changes: 1 addition & 7 deletions src/core/server/legacy/legacy_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ type LegacyServiceMock = jest.Mocked<PublicMethodsOf<LegacyService> & { legacyId

const createDiscoverPluginsMock = (): LegacyServiceDiscoverPlugins => ({
pluginSpecs: [],
uiExports: {
savedObjectSchemas: {},
savedObjectMappings: [],
savedObjectMigrations: {},
savedObjectValidations: {},
savedObjectsManagement: {},
},
uiExports: {},
navLinks: [],
pluginExtendedConfig: {
get: jest.fn(),
Expand Down
2 changes: 0 additions & 2 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,9 @@ export class LegacyService implements CoreService {
registerStaticDir: setupDeps.core.http.registerStaticDir,
},
hapiServer: setupDeps.core.http.server,
kibanaMigrator: startDeps.core.savedObjects.migrator,
uiPlugins: setupDeps.uiPlugins,
elasticsearch: setupDeps.core.elasticsearch,
rendering: setupDeps.core.rendering,
savedObjectsClientProvider: startDeps.core.savedObjects.clientProvider,
legacy: this.legacyInternals,
},
logger: this.coreContext.logger,
Expand Down
5 changes: 2 additions & 3 deletions src/core/server/legacy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { KibanaRequest, LegacyRequest } from '../http';
import { InternalCoreSetup, InternalCoreStart } from '../internal_types';
import { PluginsServiceSetup, PluginsServiceStart, UiPlugins } from '../plugins';
import { InternalRenderingServiceSetup } from '../rendering';
import { SavedObjectsLegacyUiExports } from '../types';

/**
* @internal
Expand Down Expand Up @@ -128,13 +127,13 @@ export type LegacyNavLink = Omit<ChromeNavLink, 'baseUrl' | 'legacy' | 'order' |
* @internal
* @deprecated
*/
export type LegacyUiExports = SavedObjectsLegacyUiExports & {
export interface LegacyUiExports {
defaultInjectedVarProviders?: VarsProvider[];
injectedVarsReplacers?: VarsReplacer[];
navLinkSpecs?: LegacyNavLinkSpec[] | null;
uiAppSpecs?: Array<LegacyAppSpec | undefined>;
unknown?: [{ pluginSpec: LegacyPluginSpec; type: unknown }];
};
}

/**
* @public
Expand Down
184 changes: 0 additions & 184 deletions src/core/server/saved_objects/__snapshots__/utils.test.ts.snap

This file was deleted.

2 changes: 0 additions & 2 deletions src/core/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

export * from './service';

export { SavedObjectsSchema } from './schema';

export * from './import';

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ describe('DocumentMigrator', () => {
return {
kibanaVersion: '25.2.3',
typeRegistry: createRegistry(),
validateDoc: _.noop,
log: mockLogger,
};
}
Expand All @@ -60,7 +59,6 @@ describe('DocumentMigrator', () => {
name: 'foo',
migrations: _.noop as any,
}),
validateDoc: _.noop,
log: mockLogger,
};
expect(() => new DocumentMigrator(invalidDefinition)).toThrow(
Expand All @@ -77,7 +75,6 @@ describe('DocumentMigrator', () => {
bar: (doc) => doc,
},
}),
validateDoc: _.noop,
log: mockLogger,
};
expect(() => new DocumentMigrator(invalidDefinition)).toThrow(
Expand All @@ -94,7 +91,6 @@ describe('DocumentMigrator', () => {
'1.2.3': 23 as any,
},
}),
validateDoc: _.noop,
log: mockLogger,
};
expect(() => new DocumentMigrator(invalidDefinition)).toThrow(
Expand Down Expand Up @@ -633,27 +629,6 @@ describe('DocumentMigrator', () => {
bbb: '3.2.3',
});
});

test('fails if the validate doc throws', () => {
const migrator = new DocumentMigrator({
...testOpts(),
typeRegistry: createRegistry({
name: 'aaa',
migrations: {
'2.3.4': (d) => set(d, 'attributes.counter', 42),
},
}),
validateDoc: (d) => {
if ((d.attributes as any).counter === 42) {
throw new Error('Meaningful!');
}
},
});

const doc = { id: '1', type: 'foo', attributes: {}, migrationVersion: {}, aaa: {} };

expect(() => migrator.migrate(doc)).toThrow(/Meaningful/);
});
});

function renameAttr(path: string, newPath: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ import { SavedObjectMigrationFn } from '../types';

export type TransformFn = (doc: SavedObjectUnsanitizedDoc) => SavedObjectUnsanitizedDoc;

type ValidateDoc = (doc: SavedObjectUnsanitizedDoc) => void;

interface DocumentMigratorOptions {
kibanaVersion: string;
typeRegistry: ISavedObjectTypeRegistry;
validateDoc: ValidateDoc;
log: Logger;
}

Expand Down Expand Up @@ -113,19 +110,16 @@ export class DocumentMigrator implements VersionedTransformer {
* @param {DocumentMigratorOptions} opts
* @prop {string} kibanaVersion - The current version of Kibana
* @prop {SavedObjectTypeRegistry} typeRegistry - The type registry to get type migrations from
* @prop {ValidateDoc} validateDoc - A function which, given a document throws an error if it is
* not up to date. This is used to ensure we don't let unmigrated documents slip through.
* @prop {Logger} log - The migration logger
* @memberof DocumentMigrator
*/
constructor({ typeRegistry, kibanaVersion, log, validateDoc }: DocumentMigratorOptions) {
constructor({ typeRegistry, kibanaVersion, log }: DocumentMigratorOptions) {
validateMigrationDefinition(typeRegistry);

this.migrations = buildActiveMigrations(typeRegistry, log);
this.transformDoc = buildDocumentTransform({
kibanaVersion,
migrations: this.migrations,
validateDoc,
});
}

Expand Down Expand Up @@ -231,21 +225,16 @@ function buildActiveMigrations(
* Creates a function which migrates and validates any document that is passed to it.
*/
function buildDocumentTransform({
kibanaVersion,
migrations,
validateDoc,
}: {
kibanaVersion: string;
migrations: ActiveMigrations;
validateDoc: ValidateDoc;
}): TransformFn {
return function transformAndValidate(doc: SavedObjectUnsanitizedDoc) {
const result = doc.migrationVersion
? applyMigrations(doc, migrations)
: markAsUpToDate(doc, migrations);

validateDoc(result);

// In order to keep tests a bit more stable, we won't
// tack on an empy migrationVersion to docs that have
// no migrations defined.
Expand Down
Loading

0 comments on commit bcaffba

Please sign in to comment.