Skip to content

Commit

Permalink
[Saved Objects] Browser-side client deprecation notice (elastic#148979)
Browse files Browse the repository at this point in the history
## Summary

In the near future we will remove Saved Object (SO) HTTP APIs. This PR
deprecates all browser-side SO types and interfaces.

General comments on the approach taken here:

* Add a deprecation notice that links to a GitHub issue that can be
referenced by all teams
* Do not break existing imports/exports
* Mocks are also an indication of SO browser-side use, added deprecation
notices
* Some common types must also be deprecated, some may remain. For those
to be removed they are moved to a separate file, with a deprecated
type-alias re-exported

## Notes to reviewers

* Easiest way to get an overview of the changes is to have the file-tree
open in the "Files changed" view
* Are there any other ways browser-side code can get knowledge of Saved
Objects?
* Please go through some client code and test that the DX is working as
expected (the GitHub issue is discoverable)

## Related
* elastic#147150
* elastic/dev#2194

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and wayneseymour committed Jan 19, 2023
1 parent f494c4c commit 30f91b8
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SimpleSavedObject } from '../simple_saved_object';
* Batch response for simple saved objects
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsBatchResponse<T = unknown> {
/** Array of simple saved objects */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { SavedObjectsCreateOptions } from './create';
* Per-object parameters for bulk create operation
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsBulkCreateObject<T = unknown> extends SavedObjectsCreateOptions {
/** Create a SavedObject of this type. */
Expand All @@ -24,6 +25,7 @@ export interface SavedObjectsBulkCreateObject<T = unknown> extends SavedObjectsC
* Options for bulk create operation
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
* */
export interface SavedObjectsBulkCreateOptions {
/** If a document with the given `id` already exists, overwrite its contents (default=false). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SavedObjectError } from '@kbn/core-saved-objects-common';
* Options for bulk delete operation
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsBulkDeleteOptions {
/** Force deletion of any objects that exist in multiple namespaces (default=false) */
Expand All @@ -22,6 +23,7 @@ export interface SavedObjectsBulkDeleteOptions {
* Single item within the statuses array of the bulk delete response
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsBulkDeleteResponseItem {
/** saved object id */
Expand All @@ -38,6 +40,7 @@ export interface SavedObjectsBulkDeleteResponseItem {
* Return type of the Saved Objects `bulkDelete()` method.
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsBulkDeleteResponse {
/** array of statuses per object */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { ResolvedSimpleSavedObject } from './resolve';
* Return type of the Saved Objects `bulkResolve()` method.
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsBulkResolveResponse<T = unknown> {
/** Array of {@link ResolvedSimpleSavedObject} that were resolved */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { SavedObjectReference } from '@kbn/core-saved-objects-common';
* Per-object parameters for bulk update operation
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsBulkUpdateObject<T = unknown> {
/** Type of the saved object to update */
Expand All @@ -30,6 +31,7 @@ export interface SavedObjectsBulkUpdateObject<T = unknown> {
* Options for bulk update operation
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
* */
export interface SavedObjectsBulkUpdateOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
* Options for creating a saved object.
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsCreateOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Options for deleting a saved object.
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsDeleteOptions {
/** Force deletion of an object that exists in multiple namespaces (default=false) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type { SavedObjectsFindOptionsReference } from '@kbn/core-saved-objects-a
* Browser options for finding saved objects
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export type SavedObjectsFindOptions = Omit<
SavedObjectFindOptionsServer,
Expand All @@ -25,6 +26,7 @@ export type SavedObjectsFindOptions = Omit<
* Return type of the Saved Objects `find()` method.
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsFindResponse<T = unknown, A = unknown>
extends SavedObjectsBatchResponse<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { SimpleSavedObject } from '../simple_saved_object';
* with the {@link SavedObjectsClientContract}.
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface ResolvedSimpleSavedObject<T = unknown> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { SavedObjectReference } from '@kbn/core-saved-objects-common';
* Options for updating a saved object
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsUpdateOptions<Attributes = unknown> {
/** version of the saved object */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type { SimpleSavedObject } from './simple_saved_object';
* HTTP API for interacting with Saved Objects.
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsClientContract {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { SavedObject as SavedObjectType } from '@kbn/core-saved-objects-com
* but doesn't include any type-specific implementations.
*
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SimpleSavedObject<T = unknown> {
/** attributes of the object, templated */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const getObjectsToResolve = (queue: BatchResolveQueueEntry[]) => {
* HTTP API for interacting with Saved Objects.
*
* @internal
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export class SavedObjectsClient implements SavedObjectsClientContract {
private http: HttpSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import type { HttpStart } from '@kbn/core-http-browser';
import type { SavedObjectsStart } from '@kbn/core-saved-objects-browser';
import { SavedObjectsClient } from './saved_objects_client';

/**
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export class SavedObjectsService implements CoreService<void, SavedObjectsStart> {
public async setup() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
* Core internal implementation of {@link SimpleSavedObject}
*
* @internal Should use the {@link SimpleSavedObject} interface instead
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export class SimpleSavedObjectImpl<T = unknown> implements SimpleSavedObject<T> {
public attributes: T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const createMock = () => {
return mocked;
};

/**
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export const savedObjectsServiceMock = {
create: createMock,
createStartContract: createStartContractMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const createSimpleSavedObjectMock = (
return mock;
};

/**
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export const simpleSavedObjectMock = {
create: (client: SavedObjectsClientContract, savedObject: SavedObject) =>
createSimpleSavedObjectMock(savedObject),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-bro

/**
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export interface SavedObjectsStart {
/** {@link SavedObjectsClientContract} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,7 @@
* Side Public License, v 1.
*/

/**
* Don't use this type, it's simply a helper type for {@link SavedObjectAttribute}
*
* @public
*/
export type SavedObjectAttributeSingle =
| string
| number
| boolean
| null
| undefined
| SavedObjectAttributes;

/**
* Type definition for a Saved Object attribute value
*
* @public
*/
export type SavedObjectAttribute = SavedObjectAttributeSingle | SavedObjectAttributeSingle[];

/**
* The data for a Saved Object is stored as an object in the `attributes`
* property.
*
* @public
* @deprecated This type reduces the type safety of your code. Create an interface for your specific saved object type or use `unknown` instead.
*/
export interface SavedObjectAttributes {
[key: string]: SavedObjectAttribute;
}

/**
* A reference to another saved object.
*
* @public
*/
export interface SavedObjectReference {
name: string;
type: string;
id: string;
}
import * as serverTypes from './server_types';

/**
* Information about the migrations that have been applied to this SavedObject.
Expand All @@ -68,41 +28,6 @@ export interface SavedObjectsMigrationVersion {
[pluginName: string]: string;
}

export interface SavedObject<T = unknown> {
/** The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` */
id: string;
/** The type of Saved Object. Each plugin can define it's own custom Saved Object types. */
type: string;
/** An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. */
version?: string;
/** Timestamp of the time this document had been created. */
created_at?: string;
/** Timestamp of the last time this document had been updated. */
updated_at?: string;
/** Error associated with this object, populated if an operation failed for this object. */
error?: SavedObjectError;
/** The data for a Saved Object is stored as an object in the `attributes` property. **/
attributes: T;
/** {@inheritdoc SavedObjectReference} */
references: SavedObjectReference[];
/** {@inheritdoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
/** A semver value that is used when upgrading objects between Kibana versions. */
coreMigrationVersion?: string;
/**
* Space(s) that this saved object exists in. This attribute is not used for "global" saved object types which are registered with
* `namespaceType: 'agnostic'`.
*/
namespaces?: string[];
/**
* The ID of the saved object this originated from. This is set if this object's `id` was regenerated; that can happen during migration
* from a legacy single-namespace type, or during import. It is only set during migration or create operations. This is used during import
* to ensure that ID regeneration is deterministic, so saved objects will be overwritten if they are imported multiple times into a given
* space.
*/
originId?: string;
}

/**
* The namespace type dictates how a saved object can be interacted in relation to namespaces. Each type is mutually exclusive:
* * single (default): This type of saved object is namespace-isolated, e.g., it exists in only one namespace.
Expand All @@ -123,3 +48,33 @@ export interface SavedObjectError {
statusCode: number;
metadata?: Record<string, unknown>;
}

/**
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export type SavedObjectAttributeSingle = serverTypes.SavedObjectAttributeSingle;

/**
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export type SavedObjectAttribute = serverTypes.SavedObjectAttribute;

/**
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export type SavedObjectAttributes = serverTypes.SavedObjectAttributes;

/**
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export type SavedObjectReference = serverTypes.SavedObjectReference;

/**
* @public
* @deprecated See https://github.com/elastic/kibana/issues/149098
*/
export type SavedObject<T = unknown> = serverTypes.SavedObject<T>;
Loading

0 comments on commit 30f91b8

Please sign in to comment.