import type { ISavedObjectsRepository , ISavedObjectsPointInTimeFinder , SavedObjectsCreatePointInTimeFinderOptions , SavedObjectsCreatePointInTimeFinderDependencies , SavedObjectsCollectMultiNamespaceReferencesObject , SavedObjectsCollectMultiNamespaceReferencesOptions , SavedObjectsCollectMultiNamespaceReferencesResponse , SavedObjectsUpdateObjectsSpacesObject , SavedObjectsUpdateObjectsSpacesOptions , } from './lib' ; import { SavedObject , SavedObjectError , SavedObjectReference , SavedObjectsMigrationVersion , SavedObjectsBaseOptions , MutatingOperationRefreshSetting , SavedObjectsFindOptions , } from '../types' ; import { SavedObjectsErrorHelpers } from './lib/errors' ; public export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions { /** (not recommended) Specify an id for the document */ id ? : string ; /** Overwrite existing documents (defaults to false) */ overwrite ? : boolean ; /**
     * An opaque version number which changes on each successful write operation.
     * Can be used in conjunction with `overwrite` for implementing optimistic concurrency control.
     **/ version ? : string ; /** {@inheritDoc SavedObjectsMigrationVersion} */ migrationVersion ? : SavedObjectsMigrationVersion ; remarks coreMigrationVersion ? : string ; references ? : SavedObjectReference [ ] ; /** The Elasticsearch Refresh setting for this operation */ refresh ? : MutatingOperationRefreshSetting ; /** Optional ID of the original saved object, if this object's `id` was regenerated */ originId ? : string ; /**
     * Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in
     *  SavedObjectsCreateOptions .
     *
     * * For shareable object types (registered with `namespaceType: 'multiple'`): this option can be used to specify one or more spaces,
     *   including the "All spaces" identifier (`'*'`).
     * * For isolated object types (registered with `namespaceType: 'single'` or `namespaceType: 'multiple-isolated'`): this option can only
     *   be used to specify a single space, and the "All spaces" identifier (`'*'`) is not allowed.
     * * For global object types (registered with `namespaceType: 'agnostic'`): this option cannot be used.
      initialNamespaces ? : string [ ] ; } public export interface SavedObjectsBulkCreateObject < T = unknown > { id ? : string ; type : string ; attributes : T ; version ? : string ; references ? : SavedObjectReference [ ] ; /** {@inheritDoc SavedObjectsMigrationVersion} */ migrationVersion ? : SavedObjectsMigrationVersion ; remarks coreMigrationVersion ? : string ; /** Optional ID of the original saved object, if this object's `id` was regenerated */ originId ? : string ; /**
     * Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in
     *  SavedObjectsCreateOptions .
     *
     * * For shareable object types (registered with `namespaceType: 'multiple'`): this option can be used to specify one or more spaces,
     *   including the "All spaces" identifier (`'*'`).
     * * For isolated object types (registered with `namespaceType: 'single'` or `namespaceType: 'multiple-isolated'`): this option can only
     *   be used to specify a single space, and the "All spaces" identifier (`'*'`) is not allowed.
     * * For global object types (registered with `namespaceType: 'agnostic'`): this option cannot be used.
      initialNamespaces ? : string [ ] ; } public export interface SavedObjectsBulkUpdateObject < T = unknown > extends Pick < SavedObjectsUpdateOptions < T > , 'version' | 'references' > { /** The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` */ id : string ; /**  The type of this Saved Object. Each plugin can define it's own custom Saved Object types. */ type : string ; /** {@inheritdoc SavedObjectAttributes} */ attributes : Partial < T > ; /**
     * Optional namespace string to use when searching for this object. If this is defined, it will supersede the namespace ID that is in
     *  SavedObjectsBulkUpdateOptions .
     *
     * Note: the default namespace's string representation is `'default'`, and its ID representation is `undefined`.
     * namespace ? : string ; } public export interface SavedObjectsBulkResponse < T = unknown > { saved_objects : Array < SavedObject < T > > ; } public export interface SavedObjectsFindResult < T = unknown > extends SavedObject < T > { /**
     * The Elasticsearch `_score` of this result.
     */ score : number ; remarks This can be passed directly to the `searchAfter` param in the  SavedObjectsFindOptions * in order to page through large numbers of hits. It is recommended you use this alongside
     * a Point In Time (PIT) that was opened with  SavedObjectsClient . openPointInTimeForType .
     *
     *  example sort ? : string [ ] ; } public export interface SavedObjectsFindResponse < T = unknown , A = unknown > { aggregations ? : A ; saved_objects : Array < SavedObjectsFindResult < T > > ; total : number ; per_page : number ; page : number ; pit_id ? : string ; } public export interface SavedObjectsCheckConflictsObject { id : string ; type : string ; } public export interface SavedObjectsCheckConflictsResponse { errors : Array < { id : string ; type : string ; error : SavedObjectError ; } > ; } public export interface SavedObjectsUpdateOptions < Attributes = unknown > extends SavedObjectsBaseOptions { /** An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. */ version ? : string ; /** {@inheritdoc SavedObjectReference} */ references ? : SavedObjectReference [ ] ; /** The Elasticsearch Refresh setting for this operation */ refresh ? : MutatingOperationRefreshSetting ; /** If specified, will be used to perform an upsert if the document doesn't exist */ upsert ? : Attributes ; } public export interface SavedObjectsRemoveReferencesToOptions extends SavedObjectsBaseOptions { /** The Elasticsearch Refresh setting for this operation. Defaults to `true` */ refresh ? : boolean ; } public export interface SavedObjectsRemoveReferencesToResponse extends SavedObjectsBaseOptions { /** The number of objects that have been updated by this operation */ updated : number ; } public export interface SavedObjectsBulkUpdateOptions extends SavedObjectsBaseOptions { /** The Elasticsearch Refresh setting for this operation */ refresh ? : MutatingOperationRefreshSetting ; } public export interface SavedObjectsDeleteOptions extends SavedObjectsBaseOptions { /** The Elasticsearch Refresh setting for this operation */ refresh ? : MutatingOperationRefreshSetting ; /** Force deletion of an object that exists in multiple namespaces */ force ? : boolean ; } public export interface SavedObjectsBulkGetObject { id : string ; type : string ; /** SavedObject fields to include in the response */ fields ? : string [ ] ; /**
     * Optional namespace(s) for the object to be retrieved in. If this is defined, it will supersede the namespace ID that is in the
     * top-level options.
     *
     * * For shareable object types (registered with `namespaceType: 'multiple'`): this option can be used to specify one or more spaces,
     *   including the "All spaces" identifier (`'*'`).
     * * For isolated object types (registered with `namespaceType: 'single'` or `namespaceType: 'multiple-isolated'`): this option can only
     *   be used to specify a single space, and the "All spaces" identifier (`'*'`) is not allowed.
     * * For global object types (registered with `namespaceType: 'agnostic'`): this option cannot be used.
     */ namespaces ? : string [ ] ; } public export interface SavedObjectsBulkResponse < T = unknown > { saved_objects : Array < SavedObject < T > > ; } public export interface SavedObjectsBulkUpdateResponse < T = unknown > { saved_objects : Array < SavedObjectsUpdateResponse < T > > ; } public export interface SavedObjectsUpdateResponse < T = unknown > extends Omit < SavedObject < T > , 'attributes' | 'references' > { attributes : Partial < T > ; references : SavedObjectReference [ ] | undefined ; } public export interface SavedObjectsBulkResolveObject { id : string ; type : string ; } public export interface SavedObjectsBulkResolveResponse < T = unknown > { resolved_objects : Array < SavedObjectsResolveResponse < T > > ; } public export interface SavedObjectsResolveResponse < T = unknown > { /**
     * The saved object that was found.
     */ saved_object : SavedObject < T > ; /**
     * The outcome for a successful `resolve` call is one of the following values:
     *
     *  * `'exactMatch'` -- One document exactly matched the given ID.
     *  * `'aliasMatch'` -- One document with a legacy URL alias matched the given ID; in this case the `saved_object.id` field is different
     *    than the given ID.
     *  * `'conflict'` -- Two documents matched the given ID, one was an exact match and another with a legacy URL alias; in this case the
     *    `saved_object` object is the exact match, and the `saved_object.id` field is the same as the given ID.
     */ outcome : 'exactMatch' | 'aliasMatch' | 'conflict' ; /**
     * The ID of the object that the legacy URL alias points to. This is only defined when the outcome is `'aliasMatch'` or `'conflict'`.
     */ alias_target_id ? : string ; } public export interface SavedObjectsOpenPointInTimeOptions { /**
     * Optionally specify how long ES should keep the PIT alive until the next request. Defaults to `5m`.
     */ keepAlive ? : string ; /**
     * An optional ES preference value to be used for the query.
     */ preference ? : string ; /**
     * An optional list of namespaces to be used when opening the PIT.
     *
     * When the spaces plugin is enabled:
     *  - this will default to the user's current space (as determined by the URL)
     *  - if specified, the user's current space will be ignored
     *  - `['*']` will search across all available spaces
     */ namespaces ? : string [ ] ; } public export interface SavedObjectsOpenPointInTimeResponse { /**
     * PIT ID returned from ES.
     */ id : string ; } public export type SavedObjectsClosePointInTimeOptions = SavedObjectsBaseOptions ; public export interface SavedObjectsClosePointInTimeResponse { /**
     * If true, all search contexts associated with the PIT id are
     * successfully closed.
     */ succeeded : boolean ; /**
     * The number of search contexts that have been successfully closed.
     */ num_freed : number ; } public export class SavedObjectsClient { public static errors = SavedObjectsErrorHelpers ; public errors = SavedObjectsErrorHelpers ; private _repository : ISavedObjectsRepository ; internal constructor ( repository ) { this . _repository = repository ; } param type param attributes param options async create < T = unknown > ( type , attributes , options ? ) { return await this . _repository . create ( type , attributes , options ) ; } param objects param options async bulkCreate < T = unknown > ( objects , options ? ) { return await this . _repository . bulkCreate ( objects , options ) ; } param objects param options async checkConflicts ( objects = [ ] , options = { } ) { return await this . _repository . checkConflicts ( objects , options ) ; } param type param id param options async delete ( type , id , options = { } ) { return await this . _repository . delete ( type , id , options ) ; } param options async find < T = unknown , A = unknown > ( options ) { return await this . _repository . find ( options ) ; } param objects example async bulkGet < T = unknown > ( objects = [ ] , options = { } ) { return await this . _repository . bulkGet ( objects , options ) ; } param type param id param options async get < T = unknown > ( type , id , options = { } ) { return await this . _repository . get ( type , id , options ) ; } param objects example note async bulkResolve < T = unknown > ( objects , options ? ) { return await this . _repository . bulkResolve ( objects , options ) ; } param type param id param options async resolve < T = unknown > ( type , id , options = { } ) { return await this . _repository . resolve ( type , id , options ) ; } param type param id param options async update < T = unknown > ( type , id , attributes , options = { } ) { return await this . _repository . update ( type , id , attributes , options ) ; } param objects async bulkUpdate < T = unknown > ( objects , options ? ) { return await this . _repository . bulkUpdate ( objects , options ) ; } /**
     * Updates all objects containing a reference to the given {type, id} tuple to remove the said reference.
     */ async removeReferencesTo ( type , id , options ? ) { return await this . _repository . removeReferencesTo ( type , id , options ) ; } /**
     * Opens a Point In Time (PIT) against the indices for the specified Saved Object types.
     * The returned `id` can then be passed to  SavedObjectsClient . find to search
     * against that PIT.
     *
     * Only use this API if you have an advanced use case that's not solved by the
     *  SavedObjectsClient . createPointInTimeFinder method.
      async openPointInTimeForType ( type , options = { } ) { return await this . _repository . openPointInTimeForType ( type , options ) ; } /**
     * Closes a Point In Time (PIT) by ID. This simply proxies the request to ES via the
     * Elasticsearch client, and is included in the Saved Objects Client as a convenience
     * for consumers who are using  SavedObjectsClient . openPointInTimeForType .
     *
     * Only use this API if you have an advanced use case that's not solved by the
     *  SavedObjectsClient . createPointInTimeFinder method.
      async closePointInTime ( id , options ? ) { return await this . _repository . closePointInTime ( id , options ) ; } /**
     * Returns a  ISavedObjectsPointInTimeFinder to help page through
     * large sets of saved objects. We strongly recommend using this API for
     * any `find` queries that might return more than 1000 saved objects,
     * however this API is only intended for use in server-side "batch"
     * processing of objects where you are collecting all objects in memory
     * or streaming them back to the client.
     *
     * Do NOT use this API in a route handler to facilitate paging through
     * saved objects on the client-side unless you are streaming all of the
     * results back to the client at once. Because the returned generator is
     * stateful, you cannot rely on subsequent http requests retrieving new
     * pages from the same Kibana server in multi-instance deployments.
     *
     * The generator wraps calls to  SavedObjectsClient . find and iterates
     * over multiple pages of results using `_pit` and `search_after`. This will
     * open a new Point-In-Time (PIT), and continue paging until a set of
     * results is received that's smaller than the designated `perPage`.
     *
     * Once you have retrieved all of the results you need, it is recommended
     * to call `close()` to clean up the PIT and prevent Elasticsearch from
     * consuming resources unnecessarily. This is only required if you are
     * done iterating and have not yet paged through all of the results: the
     * PIT will automatically be closed for you once you reach the last page
     * of results, or if the underlying call to `find` fails for any reason.
     *
     *  example createPointInTimeFinder < T = unknown , A = unknown > ( findOptions , dependencies ? ) { return this . _repository . createPointInTimeFinder ( findOptions , { client : this , ... dependencies , } ) ; } param objects param options async collectMultiNamespaceReferences ( objects , options ? ) { return await this . _repository . collectMultiNamespaceReferences ( objects , options ) ; } param objects param spacesToAdd param spacesToRemove param options async updateObjectsSpaces ( objects , spacesToAdd , spacesToRemove , options ? ) { return await this . _repository . updateObjectsSpaces ( objects , spacesToAdd , spacesToRemove , options ) ; } }