Skip to content

Commit

Permalink
Modify the type of extendedSavedObjectsMappings
Browse files Browse the repository at this point in the history
Signed-off-by: gaobinlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong committed Feb 28, 2024
1 parent 38d3f65 commit ffec458
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ import {
*/
export function buildActiveMappings(
typeDefinitions: SavedObjectsTypeMappingDefinitions | SavedObjectsMappingProperties,
extendedMappings?: SavedObjectsMappingProperties
extendedMappings?: SavedObjectsMappingProperties[]
): IndexMapping {
const mapping = defaultMapping();

let mergedProperties = validateAndMerge(mapping.properties, typeDefinitions);
if (extendedMappings) {
mergedProperties = validateAndMerge(mergedProperties, extendedMappings);
extendedMappings.forEach(
(mappings) => (mergedProperties = validateAndMerge(mergedProperties, mappings))
);
}

return cloneDeep({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface OpenSearchDashboardsMigratorOptions {
opensearchDashboardsConfig: OpenSearchDashboardsConfigType;
opensearchDashboardsVersion: string;
logger: Logger;
extendedSavedObjectsMappings?: SavedObjectsMappingProperties;
extendedSavedObjectsMappings?: SavedObjectsMappingProperties[];
}

export type IOpenSearchDashboardsMigrator = Pick<
Expand Down Expand Up @@ -88,7 +88,7 @@ export class OpenSearchDashboardsMigrator {
status: 'waiting',
});
private readonly activeMappings: IndexMapping;
private readonly extendedMappingProperties?: SavedObjectsMappingProperties;
private readonly extendedMappingProperties?: SavedObjectsMappingProperties[];

/**
* Creates an instance of OpenSearchDashboardsMigrator.
Expand Down
14 changes: 9 additions & 5 deletions src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export interface SavedObjectsServiceSetup {
/**
* Allow a plugin to add extended saved objects mappings
*/
addExtendedSavedObjectsMappings: (mappings: SavedObjectsMappingProperties) => void;
addExtendedSavedObjectsMappings: (mappings: SavedObjectsMappingProperties[]) => void;
}

/**
Expand Down Expand Up @@ -320,7 +320,7 @@ export class SavedObjectsService
level: ServiceStatusLevels.unavailable,
summary: `waiting`,
});
private extendedSavedObjectsMappings?: SavedObjectsMappingProperties;
private extendedSavedObjectsMappings?: SavedObjectsMappingProperties[];

constructor(private readonly coreContext: CoreContext) {
this.logger = coreContext.logger.get('savedobjects-service');
Expand Down Expand Up @@ -396,8 +396,12 @@ export class SavedObjectsService
}
this.savedObjectServiceCustomStatus$ = status$;
},
addExtendedSavedObjectsMappings: (mappings: SavedObjectsMappingProperties) => {
this.extendedSavedObjectsMappings = mappings;
addExtendedSavedObjectsMappings: (mappings: SavedObjectsMappingProperties[]) => {
if (!this.extendedSavedObjectsMappings) {
this.extendedSavedObjectsMappings = mappings;
} else {
this.extendedSavedObjectsMappings = [...this.extendedSavedObjectsMappings, ...mappings];
}
},
};
}
Expand Down Expand Up @@ -557,7 +561,7 @@ export class SavedObjectsService
opensearchDashboardsConfig: OpenSearchDashboardsConfigType,
savedObjectsConfig: SavedObjectsMigrationConfigType,
client: IClusterClient,
extendedSavedObjectsMappings?: SavedObjectsMappingProperties,
extendedSavedObjectsMappings?: SavedObjectsMappingProperties[],
migrationsRetryDelay?: number
): IOpenSearchDashboardsMigrator {
return new OpenSearchDashboardsMigrator({
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
};
}

core.savedObjects.addExtendedSavedObjectsMappings(extendedSavedObjectsMappings);
core.savedObjects.addExtendedSavedObjectsMappings([extendedSavedObjectsMappings]);

this.proxyWorkspaceTrafficToRealHandler(core);

Expand Down

0 comments on commit ffec458

Please sign in to comment.