move HumanDuration to @backstage/types

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-10-21 17:12:36 +02:00
parent fda7d90c28
commit 30e43717c7
21 changed files with 144 additions and 41 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-tasks': patch
---
Deprecated the `HumanDuration` type, which should now instead be imported from `@backstage/types`.
+5
View File
@@ -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`.
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-tech-insights-backend': patch
'@backstage/plugin-tech-insights-node': patch
---
Use `HumanDuration` from `@backstage/types`
+9 -17
View File
@@ -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
+25
View File
@@ -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;
+1
View File
@@ -21,3 +21,4 @@
*/
export * from './tasks';
export * from './deprecated';
@@ -23,5 +23,4 @@ export type {
TaskRunner,
TaskScheduleDefinition,
TaskScheduleDefinitionConfig,
HumanDuration,
} from './types';
@@ -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', () => {
@@ -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 = [
+1 -15
View File
@@ -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.
*
+12
View File
@@ -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<JsonValue> {}
+1
View File
@@ -34,6 +34,7 @@
"devDependencies": {
"@backstage/cli": "workspace:^",
"@types/zen-observable": "^0.8.0",
"luxon": "^3.0.0",
"zen-observable": "^0.8.15"
},
"files": [
+1
View File
@@ -22,3 +22,4 @@
export type { JsonArray, JsonObject, JsonPrimitive, JsonValue } from './json';
export type { Observable, Observer, Subscription } from './observable';
export type { HumanDuration } from './time';
+36
View File
@@ -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);
});
});
});
+31
View File
@@ -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;
};
+1 -1
View File
@@ -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';
@@ -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",
@@ -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,
+1 -1
View File
@@ -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';
+1 -2
View File
@@ -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.
+2
View File
@@ -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