Skip to content

Commit

Permalink
Merge branch 'main' into migrate-to-shared-ux-router
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 authored Feb 13, 2023
2 parents 766a997 + c6641c9 commit c087f88
Show file tree
Hide file tree
Showing 121 changed files with 2,172 additions and 1,031 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfAnyTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerBulkCreateRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.post(
{
Expand Down Expand Up @@ -49,6 +51,9 @@ export const registerBulkCreateRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn(
"The bulk create saved object API '/api/saved_objects/_bulk_create' is deprecated."
);
const { overwrite } = req.query;

const usageStatsClient = coreUsageData.getClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfAnyTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerBulkDeleteRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.post(
{
Expand All @@ -35,6 +37,9 @@ export const registerBulkDeleteRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn(
"The bulk update saved object API '/api/saved_objects/_bulk_update' is deprecated."
);
const { force } = req.query;
const usageStatsClient = coreUsageData.getClient();
usageStatsClient.incrementSavedObjectsBulkDelete({ request: req }).catch(() => {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfAnyTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerBulkGetRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.post(
{
Expand All @@ -34,6 +36,7 @@ export const registerBulkGetRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn("The bulk get saved object API '/api/saved_objects/_bulk_get' is deprecated.");
const usageStatsClient = coreUsageData.getClient();
usageStatsClient.incrementSavedObjectsBulkGet({ request: req }).catch(() => {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfAnyTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerBulkResolveRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.post(
{
Expand All @@ -32,6 +34,9 @@ export const registerBulkResolveRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn(
"The bulk resolve saved object API '/api/saved_objects/_bulk_resolve' is deprecated."
);
const usageStatsClient = coreUsageData.getClient();
usageStatsClient.incrementSavedObjectsBulkResolve({ request: req }).catch(() => {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfAnyTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerBulkUpdateRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.put(
{
Expand All @@ -44,6 +46,9 @@ export const registerBulkUpdateRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn(
"The bulk update saved object API '/api/saved_objects/_bulk_update' is deprecated."
);
const usageStatsClient = coreUsageData.getClient();
usageStatsClient.incrementSavedObjectsBulkUpdate({ request: req }).catch(() => {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerCreateRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.post(
{
Expand Down Expand Up @@ -48,6 +50,7 @@ export const registerCreateRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn("The create saved object API '/api/saved_objects/{type}/{id}' is deprecated.");
const { type, id } = req.params;
const { overwrite } = req.query;
const { attributes, migrationVersion, coreMigrationVersion, references, initialNamespaces } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerDeleteRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.delete(
{
Expand All @@ -33,6 +35,7 @@ export const registerDeleteRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn("The delete saved object API '/api/saved_objects/{type}/{id}' is deprecated.");
const { type, id } = req.params;
const { force } = req.query;
const { getClient, typeRegistry } = (await context.core).savedObjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwOnHttpHiddenTypes } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerFindRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
const referenceSchema = schema.object({
type: schema.string(),
Expand Down Expand Up @@ -59,6 +61,7 @@ export const registerFindRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn("The find saved object API '/api/saved_objects/_find' is deprecated.");
const query = req.query;

const namespaces =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerGetRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.get(
{
Expand All @@ -30,6 +32,7 @@ export const registerGetRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn("The get saved object API '/api/saved_objects/{type}/{id}' is deprecated.");
const { type, id } = req.params;

const usageStatsClient = coreUsageData.getClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ export function registerRoutes({
const router =
http.createRouter<InternalSavedObjectsRequestHandlerContext>('/api/saved_objects/');

registerGetRoute(router, { coreUsageData });
registerResolveRoute(router, { coreUsageData });
registerCreateRoute(router, { coreUsageData });
registerDeleteRoute(router, { coreUsageData });
registerFindRoute(router, { coreUsageData });
registerUpdateRoute(router, { coreUsageData });
registerBulkGetRoute(router, { coreUsageData });
registerBulkCreateRoute(router, { coreUsageData });
registerBulkResolveRoute(router, { coreUsageData });
registerBulkUpdateRoute(router, { coreUsageData });
registerBulkDeleteRoute(router, { coreUsageData });
registerGetRoute(router, { coreUsageData, logger });
registerResolveRoute(router, { coreUsageData, logger });
registerCreateRoute(router, { coreUsageData, logger });
registerDeleteRoute(router, { coreUsageData, logger });
registerFindRoute(router, { coreUsageData, logger });
registerUpdateRoute(router, { coreUsageData, logger });
registerBulkGetRoute(router, { coreUsageData, logger });
registerBulkCreateRoute(router, { coreUsageData, logger });
registerBulkResolveRoute(router, { coreUsageData, logger });
registerBulkUpdateRoute(router, { coreUsageData, logger });
registerBulkDeleteRoute(router, { coreUsageData, logger });
registerExportRoute(router, { config, coreUsageData });
registerImportRoute(router, { config, coreUsageData });
registerResolveImportErrorsRoute(router, { config, coreUsageData });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import { schema } from '@kbn/config-schema';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
import type { InternalSavedObjectRouter } from '../internal_types';
import { throwIfTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerResolveRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.get(
{
Expand All @@ -30,6 +32,9 @@ export const registerResolveRoute = (
},
},
router.handleLegacyErrors(async (context, req, res) => {
logger.warn(
"The resolve saved object API '/api/saved_objects/resolve/{type}/{id}' is deprecated."
);
const { type, id } = req.params;
const { savedObjects } = await context.core;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@

import { schema } from '@kbn/config-schema';
import type { SavedObjectsUpdateOptions } from '@kbn/core-saved-objects-api-server';
import type { Logger } from '@kbn/logging';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { InternalSavedObjectRouter } from '../internal_types';
import { catchAndReturnBoomErrors, throwIfTypeNotVisibleByAPI } from './utils';

interface RouteDependencies {
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
}

export const registerUpdateRoute = (
router: InternalSavedObjectRouter,
{ coreUsageData }: RouteDependencies
{ coreUsageData, logger }: RouteDependencies
) => {
router.put(
{
Expand All @@ -45,6 +47,7 @@ export const registerUpdateRoute = (
},
},
catchAndReturnBoomErrors(async (context, req, res) => {
logger.warn("The update saved object API '/api/saved_objects/{type}/{id}' is deprecated.");
const { type, id } = req.params;
const { attributes, version, references, upsert } = req.body;
const options: SavedObjectsUpdateOptions = { version, references, upsert };
Expand Down
18 changes: 14 additions & 4 deletions packages/kbn-apm-synthtrace-client/src/lib/timerange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import datemath from '@kbn/datemath';
import type { Moment } from 'moment';
import { Interval } from './interval';

Expand All @@ -23,12 +23,22 @@ export class Timerange {

type DateLike = Date | number | Moment | string;

function getDateFrom(date: DateLike): Date {
function getDateFrom(date: DateLike, now: Date): Date {
if (date instanceof Date) return date;

if (typeof date === 'string') {
const parsed = datemath.parse(date, { forceNow: now });
if (parsed && parsed.isValid()) {
return parsed.toDate();
}
}

if (typeof date === 'number' || typeof date === 'string') return new Date(date);

return date.toDate();
}

export function timerange(from: Date | number | Moment, to: Date | number | Moment) {
return new Timerange(getDateFrom(from), getDateFrom(to));
export function timerange(from: DateLike, to: DateLike) {
const now = new Date();
return new Timerange(getDateFrom(from, now), getDateFrom(to, now));
}
3 changes: 3 additions & 0 deletions packages/kbn-apm-synthtrace-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"include": ["**/*.ts"],
"exclude": [
"target/**/*",
],
"kbn_references": [
"@kbn/datemath",
]
}
Loading

0 comments on commit c087f88

Please sign in to comment.