Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor saved object types to use namespaceType #63217

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ This is only internal for now, and will only be public when we expose the regist
| [mappings](./kibana-plugin-core-server.savedobjectstype.mappings.md) | <code>SavedObjectsTypeMappingDefinition</code> | The [mapping definition](./kibana-plugin-core-server.savedobjectstypemappingdefinition.md) for the type. |
| [migrations](./kibana-plugin-core-server.savedobjectstype.migrations.md) | <code>SavedObjectMigrationMap</code> | An optional map of [migrations](./kibana-plugin-core-server.savedobjectmigrationfn.md) to be used to migrate the type. |
| [name](./kibana-plugin-core-server.savedobjectstype.name.md) | <code>string</code> | The name of the type, which is also used as the internal id. |
| [namespaceAgnostic](./kibana-plugin-core-server.savedobjectstype.namespaceagnostic.md) | <code>boolean</code> | Is the type global (true), or not (false). |
| [namespaceType](./kibana-plugin-core-server.savedobjectstype.namespacetype.md) | <code>SavedObjectsNamespaceType</code> | The [namespace type](./kibana-plugin-core-server.savedobjectsnamespacetype.md) for the type. |

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The [namespace type](./kibana-plugin-core-server.savedobjectsnamespacetype.md) f
<b>Signature:</b>

```typescript
namespaceType?: SavedObjectsNamespaceType;
namespaceType: SavedObjectsNamespaceType;
```
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const createRegistry = (...types: Array<Partial<SavedObjectsType>>) => {
types.forEach(type =>
registry.registerType({
name: 'unknown',
namespaceAgnostic: false,
namespaceType: 'single',
hidden: false,
mappings: { properties: {} },
migrations: {},
Expand All @@ -41,7 +41,7 @@ test('mappings without index pattern goes to default index', () => {
kibanaIndexName: '.kibana',
registry: createRegistry({
name: 'type1',
namespaceAgnostic: false,
namespaceType: 'single',
}),
indexMap: {
type1: {
Expand Down Expand Up @@ -73,7 +73,7 @@ test(`mappings with custom index pattern doesn't go to default index`, () => {
kibanaIndexName: '.kibana',
registry: createRegistry({
name: 'type1',
namespaceAgnostic: false,
namespaceType: 'single',
indexPattern: '.other_kibana',
}),
indexMap: {
Expand Down Expand Up @@ -106,7 +106,7 @@ test('creating a script gets added to the index pattern', () => {
kibanaIndexName: '.kibana',
registry: createRegistry({
name: 'type1',
namespaceAgnostic: false,
namespaceType: 'single',
indexPattern: '.other_kibana',
convertToAliasScript: `ctx._id = ctx._source.type + ':' + ctx._id`,
}),
Expand Down Expand Up @@ -141,12 +141,12 @@ test('throws when two scripts are defined for an index pattern', () => {
const registry = createRegistry(
{
name: 'type1',
namespaceAgnostic: false,
namespaceType: 'single',
convertToAliasScript: `ctx._id = ctx._source.type + ':' + ctx._id`,
},
{
name: 'type2',
namespaceAgnostic: false,
namespaceType: 'single',
convertToAliasScript: `ctx._id = ctx._source.type + ':' + ctx._id`,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createRegistry = (...types: Array<Partial<SavedObjectsType>>) => {
types.forEach(type =>
registry.registerType({
name: 'unknown',
namespaceAgnostic: false,
namespaceType: 'single',
hidden: false,
mappings: { properties: {} },
migrations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const defaultSavedObjectTypes: SavedObjectsType[] = [
{
name: 'testtype',
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
mappings: {
properties: {
name: { type: 'keyword' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const createRegistry = (types: Array<Partial<SavedObjectsType>>) => {
types.forEach(type =>
registry.registerType({
name: 'unknown',
namespaceAgnostic: false,
hidden: false,
namespaceType: 'single',
mappings: { properties: {} },
migrations: {},
...type,
Expand Down Expand Up @@ -120,7 +120,7 @@ function mockOptions(): KibanaMigratorOptions {
{
name: 'testtype',
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
mappings: {
properties: {
name: { type: 'keyword' },
Expand All @@ -131,7 +131,7 @@ function mockOptions(): KibanaMigratorOptions {
{
name: 'testtype2',
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
indexPattern: 'other-index',
mappings: {
properties: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const createExportableType = (name: string): SavedObjectsType => {
return {
name,
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
mappings: {
properties: {},
},
Expand Down
24 changes: 0 additions & 24 deletions src/core/server/saved_objects/saved_objects_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,6 @@ describe('SavedObjectTypeRegistry', () => {
expectResult(false, { namespaceType: 'single' });
expectResult(false, { namespaceType: undefined });
});

// deprecated test cases
it(`returns true when namespaceAgnostic is true`, () => {
expectResult(true, { namespaceAgnostic: true, namespaceType: 'agnostic' });
expectResult(true, { namespaceAgnostic: true, namespaceType: 'multiple' });
expectResult(true, { namespaceAgnostic: true, namespaceType: 'single' });
expectResult(true, { namespaceAgnostic: true, namespaceType: undefined });
});
});

describe('#isSingleNamespace', () => {
Expand All @@ -213,14 +205,6 @@ describe('SavedObjectTypeRegistry', () => {
expectResult(false, { namespaceType: 'agnostic' });
expectResult(false, { namespaceType: 'multiple' });
});

// deprecated test cases
it(`returns false when namespaceAgnostic is true`, () => {
expectResult(false, { namespaceAgnostic: true, namespaceType: 'agnostic' });
expectResult(false, { namespaceAgnostic: true, namespaceType: 'multiple' });
expectResult(false, { namespaceAgnostic: true, namespaceType: 'single' });
expectResult(false, { namespaceAgnostic: true, namespaceType: undefined });
});
});

describe('#isMultiNamespace', () => {
Expand All @@ -243,14 +227,6 @@ describe('SavedObjectTypeRegistry', () => {
expectResult(false, { namespaceType: 'single' });
expectResult(false, { namespaceType: undefined });
});

// deprecated test cases
it(`returns false when namespaceAgnostic is true`, () => {
expectResult(false, { namespaceAgnostic: true, namespaceType: 'agnostic' });
expectResult(false, { namespaceAgnostic: true, namespaceType: 'multiple' });
expectResult(false, { namespaceAgnostic: true, namespaceType: 'single' });
expectResult(false, { namespaceAgnostic: true, namespaceType: undefined });
});
});

describe('#isHidden', () => {
Expand Down
9 changes: 3 additions & 6 deletions src/core/server/saved_objects/saved_objects_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,15 @@ export class SavedObjectTypeRegistry {
* resolves to `false` if the type is not registered
*/
public isNamespaceAgnostic(type: string) {
return (
this.types.get(type)?.namespaceType === 'agnostic' ||
this.types.get(type)?.namespaceAgnostic ||
false
);
return this.types.get(type)?.namespaceType === 'agnostic';
}

/**
* Returns whether the type is single-namespace (isolated);
* resolves to `true` if the type is not registered
*/
public isSingleNamespace(type: string) {
// in the case we somehow registered a type with an invalid `namespaceType`, treat it as single-namespace
return !this.isNamespaceAgnostic(type) && !this.isMultiNamespace(type);
jportner marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -92,7 +89,7 @@ export class SavedObjectTypeRegistry {
* resolves to `false` if the type is not registered
*/
public isMultiNamespace(type: string) {
return !this.isNamespaceAgnostic(type) && this.types.get(type)?.namespaceType === 'multiple';
return this.types.get(type)?.namespaceType === 'multiple';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('SavedObjectsRepository#createRepository', () => {
typeRegistry.registerType({
name: 'nsAgnosticType',
hidden: false,
namespaceAgnostic: true,
namespaceType: 'agnostic',
mappings: {
properties: {
name: { type: 'keyword' },
Expand All @@ -44,7 +44,7 @@ describe('SavedObjectsRepository#createRepository', () => {
typeRegistry.registerType({
name: 'nsType',
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
indexPattern: 'beats',
mappings: {
properties: {
Expand All @@ -56,7 +56,7 @@ describe('SavedObjectsRepository#createRepository', () => {
typeRegistry.registerType({
name: 'hiddenType',
hidden: true,
namespaceAgnostic: true,
namespaceType: 'agnostic',
mappings: {
properties: {
name: { type: 'keyword' },
Expand Down
7 changes: 1 addition & 6 deletions src/core/server/saved_objects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,10 @@ export interface SavedObjectsType {
* See {@link SavedObjectsServiceStart.createInternalRepository | createInternalRepository}.
*/
hidden: boolean;
/**
* Is the type global (true), or not (false).
* @deprecated Use `namespaceType` instead.
*/
namespaceAgnostic?: boolean;
/**
* The {@link SavedObjectsNamespaceType | namespace type} for the type.
*/
namespaceType?: SavedObjectsNamespaceType;
namespaceType: SavedObjectsNamespaceType;
Comment on lines -213 to +208
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before #54605 was merged, the namespaceAgnostic field was required. Now that we are removing it, the namespaceType field should be required.

/**
* If defined, the type instances will be stored in the given index instead of the default one.
*/
Expand Down
14 changes: 0 additions & 14 deletions src/core/server/saved_objects/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,6 @@ describe('convertTypesToLegacySchema', () => {
namespaceType: 'multiple',
mappings: { properties: {} },
},
// deprecated test case
{
name: 'typeD',
hidden: false,
namespaceAgnostic: true,
namespaceType: 'multiple', // if namespaceAgnostic and namespaceType are both set, namespaceAgnostic takes precedence
mappings: { properties: {} },
},
];
expect(convertTypesToLegacySchema(types)).toEqual({
typeA: {
Expand All @@ -448,12 +440,6 @@ describe('convertTypesToLegacySchema', () => {
isNamespaceAgnostic: false,
multiNamespace: true,
},
// deprecated test case
typeD: {
hidden: false,
isNamespaceAgnostic: true,
multiNamespace: false,
},
});
});
});
4 changes: 2 additions & 2 deletions src/core/server/saved_objects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export const convertTypesToLegacySchema = (
return {
...schema,
[type.name]: {
isNamespaceAgnostic: type.namespaceAgnostic || type.namespaceType === 'agnostic',
multiNamespace: !type.namespaceAgnostic && type.namespaceType === 'multiple',
isNamespaceAgnostic: type.namespaceType === 'agnostic',
multiNamespace: type.namespaceType === 'multiple',
hidden: type.hidden,
indexPattern: type.indexPattern,
convertToAliasScript: type.convertToAliasScript,
Expand Down
4 changes: 1 addition & 3 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2253,9 +2253,7 @@ export interface SavedObjectsType {
mappings: SavedObjectsTypeMappingDefinition;
migrations?: SavedObjectMigrationMap;
name: string;
// @deprecated
namespaceAgnostic?: boolean;
namespaceType?: SavedObjectsNamespaceType;
namespaceType: SavedObjectsNamespaceType;
}

// @public
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/ui_settings/saved_objects/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { SavedObjectsType } from '../../saved_objects';
export const uiSettingsType: SavedObjectsType = {
name: 'config',
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
mappings: {
// we don't want to allow `true` in the public `SavedObjectsTypeMappingDefinition` type, however
// this is needed for the config that is kinda a special type. To avoid adding additional internal types
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/saved_objects/index_patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { indexPatternSavedObjectTypeMigrations } from './index_pattern_migration
export const indexPatternSavedObjectType: SavedObjectsType = {
name: 'index-pattern',
hidden: false,
namespaceAgnostic: false,
jportner marked this conversation as resolved.
Show resolved Hide resolved
namespaceType: 'single',
management: {
icon: 'indexPatternApp',
defaultSearchField: 'title',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/saved_objects/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { SavedObjectsType } from 'kibana/server';
export const querySavedObjectType: SavedObjectsType = {
name: 'query',
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
management: {
icon: 'search',
defaultSearchField: 'title',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/saved_objects/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { searchSavedObjectTypeMigrations } from './search_migrations';
export const searchSavedObjectType: SavedObjectsType = {
name: 'search',
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
management: {
icon: 'discoverApp',
defaultSearchField: 'title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('SavedObjectsManagement', () => {
registry.registerType({
name: 'unknown',
hidden: false,
namespaceAgnostic: false,
namespaceType: 'single',
mappings: { properties: {} },
migrations: {},
...type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function registerMappings(registerType: SavedObjectsServiceSetup['registe
registerType({
name: 'application_usage_totals',
hidden: false,
namespaceAgnostic: true,
namespaceType: 'agnostic',
mappings: {
properties: {
appId: { type: 'keyword' },
Expand All @@ -46,7 +46,7 @@ export function registerMappings(registerType: SavedObjectsServiceSetup['registe
registerType({
name: 'application_usage_transactional',
hidden: false,
namespaceAgnostic: true,
namespaceType: 'agnostic',
mappings: {
properties: {
timestamp: { type: 'date' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function registerUiMetricUsageCollector(
registerType({
name: 'ui-metric',
hidden: false,
namespaceAgnostic: true,
namespaceType: 'agnostic',
mappings: {
properties: {
count: {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/telemetry/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class TelemetryPlugin implements Plugin {
registerType({
name: 'telemetry',
hidden: false,
namespaceAgnostic: true,
namespaceType: 'agnostic',
mappings: {
properties: {
enabled: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const resetCount: SavedObjectMigrationFn = doc => ({
export const tsvbTelemetrySavedObjectType: SavedObjectsType = {
name: 'tsvb-validation-telemetry',
hidden: false,
namespaceAgnostic: true,
namespaceType: 'agnostic',
mappings: {
properties: {
failedRequests: {
Expand Down
Loading