diff --git a/.changeset/lazy-planes-repair.md b/.changeset/lazy-planes-repair.md new file mode 100644 index 0000000000..00ecfb095e --- /dev/null +++ b/.changeset/lazy-planes-repair.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-tasks': patch +--- + +Deprecated the `HumanDuration` type, which should now instead be imported from `@backstage/types`. diff --git a/.changeset/sharp-goats-itch.md b/.changeset/sharp-goats-itch.md new file mode 100644 index 0000000000..601d6a7e9d --- /dev/null +++ b/.changeset/sharp-goats-itch.md @@ -0,0 +1,5 @@ +--- +'@backstage/types': patch +--- + +Added the `HumanDuration` type, moved here from `@backstage/backend-tasks`. This type matches the `Duration.fromObject` form of `luxon`. diff --git a/.changeset/three-houses-agree.md b/.changeset/three-houses-agree.md new file mode 100644 index 0000000000..041cd471d3 --- /dev/null +++ b/.changeset/three-houses-agree.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-tech-insights-backend': patch +'@backstage/plugin-tech-insights-node': patch +--- + +Use `HumanDuration` from `@backstage/types` diff --git a/packages/backend-tasks/api-report.md b/packages/backend-tasks/api-report.md index a60f6dba37..8f53d1e5ae 100644 --- a/packages/backend-tasks/api-report.md +++ b/packages/backend-tasks/api-report.md @@ -7,19 +7,11 @@ import { AbortSignal as AbortSignal_2 } from 'node-abort-controller'; import { Config } from '@backstage/config'; import { DatabaseManager } from '@backstage/backend-common'; import { Duration } from 'luxon'; +import { HumanDuration as HumanDuration_2 } from '@backstage/types'; import { Logger } from 'winston'; -// @public -export type HumanDuration = { - years?: number; - months?: number; - weeks?: number; - days?: number; - hours?: number; - minutes?: number; - seconds?: number; - milliseconds?: number; -}; +// @public @deprecated +export type HumanDuration = HumanDuration_2; // @public export interface PluginTaskScheduler { @@ -59,10 +51,10 @@ export interface TaskScheduleDefinition { cron: string; } | Duration - | HumanDuration; - initialDelay?: Duration | HumanDuration; + | HumanDuration_2; + initialDelay?: Duration | HumanDuration_2; scope?: 'global' | 'local'; - timeout: Duration | HumanDuration; + timeout: Duration | HumanDuration_2; } // @public @@ -72,10 +64,10 @@ export interface TaskScheduleDefinitionConfig { cron: string; } | string - | HumanDuration; - initialDelay?: string | HumanDuration; + | HumanDuration_2; + initialDelay?: string | HumanDuration_2; scope?: 'global' | 'local'; - timeout: string | HumanDuration; + timeout: string | HumanDuration_2; } // @public diff --git a/packages/backend-tasks/src/deprecated.ts b/packages/backend-tasks/src/deprecated.ts new file mode 100644 index 0000000000..4d86cb1700 --- /dev/null +++ b/packages/backend-tasks/src/deprecated.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { HumanDuration as TypesHumanDuration } from '@backstage/types'; + +/** + * Human friendly durations object. + * + * @public + * @deprecated Import from `@backstage/types` instead + */ +export type HumanDuration = TypesHumanDuration; diff --git a/packages/backend-tasks/src/index.ts b/packages/backend-tasks/src/index.ts index dd75aca68c..d35917056c 100644 --- a/packages/backend-tasks/src/index.ts +++ b/packages/backend-tasks/src/index.ts @@ -21,3 +21,4 @@ */ export * from './tasks'; +export * from './deprecated'; diff --git a/packages/backend-tasks/src/tasks/index.ts b/packages/backend-tasks/src/tasks/index.ts index 8f30e5c8dd..f2037ac9dd 100644 --- a/packages/backend-tasks/src/tasks/index.ts +++ b/packages/backend-tasks/src/tasks/index.ts @@ -23,5 +23,4 @@ export type { TaskRunner, TaskScheduleDefinition, TaskScheduleDefinitionConfig, - HumanDuration, } from './types'; diff --git a/packages/backend-tasks/src/tasks/readTaskScheduleDefinitionFromConfig.test.ts b/packages/backend-tasks/src/tasks/readTaskScheduleDefinitionFromConfig.test.ts index 115ef89168..fc2a045614 100644 --- a/packages/backend-tasks/src/tasks/readTaskScheduleDefinitionFromConfig.test.ts +++ b/packages/backend-tasks/src/tasks/readTaskScheduleDefinitionFromConfig.test.ts @@ -15,9 +15,9 @@ */ import { ConfigReader } from '@backstage/config'; +import { HumanDuration } from '@backstage/types'; import { Duration } from 'luxon'; import { readTaskScheduleDefinitionFromConfig } from './readTaskScheduleDefinitionFromConfig'; -import { HumanDuration } from './types'; describe('readTaskScheduleDefinitionFromConfig', () => { it('all valid values', () => { diff --git a/packages/backend-tasks/src/tasks/readTaskScheduleDefinitionFromConfig.ts b/packages/backend-tasks/src/tasks/readTaskScheduleDefinitionFromConfig.ts index 3267d8ef14..1448a328f8 100644 --- a/packages/backend-tasks/src/tasks/readTaskScheduleDefinitionFromConfig.ts +++ b/packages/backend-tasks/src/tasks/readTaskScheduleDefinitionFromConfig.ts @@ -15,8 +15,8 @@ */ import { Config } from '@backstage/config'; -import { JsonObject } from '@backstage/types'; -import { HumanDuration, TaskScheduleDefinition } from './types'; +import { HumanDuration, JsonObject } from '@backstage/types'; +import { TaskScheduleDefinition } from './types'; import { Duration } from 'luxon'; const propsOfHumanDuration = [ diff --git a/packages/backend-tasks/src/tasks/types.ts b/packages/backend-tasks/src/tasks/types.ts index 92ec045605..dbf2595e1d 100644 --- a/packages/backend-tasks/src/tasks/types.ts +++ b/packages/backend-tasks/src/tasks/types.ts @@ -14,26 +14,12 @@ * limitations under the License. */ +import { HumanDuration } from '@backstage/types'; import { CronTime } from 'cron'; import { Duration } from 'luxon'; import { AbortSignal } from 'node-abort-controller'; import { z } from 'zod'; -/** - * Human friendly durations object - * @public - */ -export type HumanDuration = { - years?: number; - months?: number; - weeks?: number; - days?: number; - hours?: number; - minutes?: number; - seconds?: number; - milliseconds?: number; -}; - /** * A function that can be called as a scheduled task. * diff --git a/packages/types/api-report.md b/packages/types/api-report.md index 43e3cfee0e..4b43f5daa6 100644 --- a/packages/types/api-report.md +++ b/packages/types/api-report.md @@ -3,6 +3,18 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts +// @public +export type HumanDuration = { + years?: number; + months?: number; + weeks?: number; + days?: number; + hours?: number; + minutes?: number; + seconds?: number; + milliseconds?: number; +}; + // @public export interface JsonArray extends Array {} diff --git a/packages/types/package.json b/packages/types/package.json index b8ebeffce8..3c2bea13c0 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -34,6 +34,7 @@ "devDependencies": { "@backstage/cli": "workspace:^", "@types/zen-observable": "^0.8.0", + "luxon": "^3.0.0", "zen-observable": "^0.8.15" }, "files": [ diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 1f1b13c349..0b5c8689b3 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -22,3 +22,4 @@ export type { JsonArray, JsonObject, JsonPrimitive, JsonValue } from './json'; export type { Observable, Observer, Subscription } from './observable'; +export type { HumanDuration } from './time'; diff --git a/packages/types/src/time.test.ts b/packages/types/src/time.test.ts new file mode 100644 index 0000000000..a1175c9e9b --- /dev/null +++ b/packages/types/src/time.test.ts @@ -0,0 +1,36 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { HumanDuration } from './time'; +import { Duration } from 'luxon'; + +describe('time', () => { + describe('HumanDuration', () => { + const durations: HumanDuration[] = [ + { years: 1 }, + { months: 1 }, + { weeks: 1 }, + { days: 1 }, + { hours: 1 }, + { minutes: 1 }, + { seconds: 1 }, + { milliseconds: 1 }, + ]; + it.each(durations)('successfully parsed by luxon, %p', d => { + expect(Duration.fromObject(d).toObject()).toEqual(d); + }); + }); +}); diff --git a/packages/types/src/time.ts b/packages/types/src/time.ts new file mode 100644 index 0000000000..7ab8288cea --- /dev/null +++ b/packages/types/src/time.ts @@ -0,0 +1,31 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Human friendly durations object. + * + * @public + */ +export type HumanDuration = { + years?: number; + months?: number; + weeks?: number; + days?: number; + hours?: number; + minutes?: number; + seconds?: number; + milliseconds?: number; +}; diff --git a/plugins/tech-insights-backend/api-report.md b/plugins/tech-insights-backend/api-report.md index 94ac35ad9f..dea5fe376c 100644 --- a/plugins/tech-insights-backend/api-report.md +++ b/plugins/tech-insights-backend/api-report.md @@ -13,7 +13,7 @@ import { FactLifecycle } from '@backstage/plugin-tech-insights-node'; import { FactRetriever } from '@backstage/plugin-tech-insights-node'; import { FactRetrieverRegistration } from '@backstage/plugin-tech-insights-node'; import { FactSchema } from '@backstage/plugin-tech-insights-node'; -import { HumanDuration } from '@backstage/backend-tasks'; +import { HumanDuration } from '@backstage/types'; import { Logger } from 'winston'; import { PluginDatabaseManager } from '@backstage/backend-common'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; diff --git a/plugins/tech-insights-backend/package.json b/plugins/tech-insights-backend/package.json index 402cbc49d5..dd918cfc4f 100644 --- a/plugins/tech-insights-backend/package.json +++ b/plugins/tech-insights-backend/package.json @@ -41,6 +41,7 @@ "@backstage/errors": "workspace:^", "@backstage/plugin-tech-insights-common": "workspace:^", "@backstage/plugin-tech-insights-node": "workspace:^", + "@backstage/types": "workspace:^", "@types/express": "^4.17.6", "@types/luxon": "^3.0.0", "express": "^4.17.1", diff --git a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts index aaba29ecb1..6200790e6e 100644 --- a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { HumanDuration } from '@backstage/backend-tasks'; + +import { HumanDuration } from '@backstage/types'; import { FactLifecycle, FactRetriever, diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index a57cf3ec4a..293e2fd76b 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -8,7 +8,7 @@ import { Config } from '@backstage/config'; import { DateTime } from 'luxon'; import { Duration } from 'luxon'; import { DurationLike } from 'luxon'; -import { HumanDuration } from '@backstage/backend-tasks'; +import { HumanDuration } from '@backstage/types'; import { JsonValue } from '@backstage/types'; import { Logger } from 'winston'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index 41db302fd5..2aab9ee73f 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -15,13 +15,12 @@ */ import { DateTime, Duration, DurationLike } from 'luxon'; import { Config } from '@backstage/config'; -import { JsonValue } from '@backstage/types'; +import { HumanDuration, JsonValue } from '@backstage/types'; import { PluginEndpointDiscovery, TokenManager, } from '@backstage/backend-common'; import { Logger } from 'winston'; -import { HumanDuration } from '@backstage/backend-tasks'; /** * A container for facts. The shape of the fact records needs to correspond to the FactSchema with same `ref` value. diff --git a/yarn.lock b/yarn.lock index 359685cdd0..2a8174d11b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7111,6 +7111,7 @@ __metadata: "@backstage/errors": "workspace:^" "@backstage/plugin-tech-insights-common": "workspace:^" "@backstage/plugin-tech-insights-node": "workspace:^" + "@backstage/types": "workspace:^" "@types/express": ^4.17.6 "@types/luxon": ^3.0.0 "@types/semver": ^7.3.8 @@ -7689,6 +7690,7 @@ __metadata: dependencies: "@backstage/cli": "workspace:^" "@types/zen-observable": ^0.8.0 + luxon: ^3.0.0 zen-observable: ^0.8.15 languageName: unknown linkType: soft