From 9bf9159134e5b66cb24ed8bab7aeadb99d18d381 Mon Sep 17 00:00:00 2001 From: Chafik H'nini Date: Thu, 5 Dec 2024 18:51:59 +0100 Subject: [PATCH] chore: expose types in esm --- CHANGELOG.md | 1 + biome.json | 3 + dist/esm/index.d.ts | 21 ++++++ dist/esm/index.js | 2 + dist/esm/index.js.map | 1 + dist/esm/spec/model/dashboard.d.ts | 34 +++++++++ dist/esm/spec/model/dashboard.js | 2 + dist/esm/spec/model/dashboard.js.map | 1 + dist/esm/spec/model/runnable.d.ts | 108 +++++++++++++++++++++++++++ dist/esm/spec/model/runnable.js | 12 +++ dist/esm/spec/model/runnable.js.map | 1 + dist/esm/spec/schema/error.d.ts | 6 ++ dist/esm/spec/schema/error.js | 2 + dist/esm/spec/schema/error.js.map | 1 + dist/esm/spec/schema/list.d.ts | 22 ++++++ dist/esm/spec/schema/list.js | 2 + dist/esm/spec/schema/list.js.map | 1 + index.ts | 22 ++++++ package.json | 7 ++ tsconfig.build.json | 8 ++ 20 files changed, 257 insertions(+) create mode 100644 dist/esm/index.d.ts create mode 100644 dist/esm/index.js create mode 100644 dist/esm/index.js.map create mode 100644 dist/esm/spec/model/dashboard.d.ts create mode 100644 dist/esm/spec/model/dashboard.js create mode 100644 dist/esm/spec/model/dashboard.js.map create mode 100644 dist/esm/spec/model/runnable.d.ts create mode 100644 dist/esm/spec/model/runnable.js create mode 100644 dist/esm/spec/model/runnable.js.map create mode 100644 dist/esm/spec/schema/error.d.ts create mode 100644 dist/esm/spec/schema/error.js create mode 100644 dist/esm/spec/schema/error.js.map create mode 100644 dist/esm/spec/schema/list.d.ts create mode 100644 dist/esm/spec/schema/list.js create mode 100644 dist/esm/spec/schema/list.js.map create mode 100644 index.ts create mode 100644 tsconfig.build.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a5ab5c..a7cf0d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ## spec/v0.4.1 (unreleased) +* chore: expose types in esm * refactor: remove barrel files * refactor: simplify read version from package.json * chore: replace eslint/prettier by biome diff --git a/biome.json b/biome.json index d3bc644..2c5a3d3 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,8 @@ { "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", + "files": { + "ignore": ["dist/*"] + }, "formatter": { "indentStyle": "space", "indentWidth": 4 diff --git a/dist/esm/index.d.ts b/dist/esm/index.d.ts new file mode 100644 index 0000000..d0d44a4 --- /dev/null +++ b/dist/esm/index.d.ts @@ -0,0 +1,21 @@ +export type { + Dashboard, + DashboardMetric, + GetDashboardMetricRes, + ListDashboardMetricsRes, + ListDashboardsQueryParams, + ListDashboardsRes, +} from './spec/model/dashboard.js'; +export { + type ListRunnablesQueryParams, + type ListRunnablesRes, + type Runnable, + type RunnableMetric, + type RunnableOperationRes, + type RunnableSSH, + type RunnableScope, + type RunnableScopes, + RunnableStatus, +} from './spec/model/runnable.js'; +export type { ErrorRes } from './spec/schema/error.js'; +export type { ListQueryParams, ListRes } from './spec/schema/list.js'; diff --git a/dist/esm/index.js b/dist/esm/index.js new file mode 100644 index 0000000..041eb6a --- /dev/null +++ b/dist/esm/index.js @@ -0,0 +1,2 @@ +export { RunnableStatus } from './spec/model/runnable.js'; +//# sourceMappingURL=index.js.map diff --git a/dist/esm/index.js.map b/dist/esm/index.js.map new file mode 100644 index 0000000..76c8f2a --- /dev/null +++ b/dist/esm/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAQA,OAAO,EASH,cAAc,GACjB,MAAM,0BAA0B,CAAC"} \ No newline at end of file diff --git a/dist/esm/spec/model/dashboard.d.ts b/dist/esm/spec/model/dashboard.d.ts new file mode 100644 index 0000000..a4f3cda --- /dev/null +++ b/dist/esm/spec/model/dashboard.d.ts @@ -0,0 +1,34 @@ +import type { ListQueryParams, ListRes } from '../schema/list.js'; +/** + * A collection of metrics + */ +export interface Dashboard { + id: string; + metrics: DashboardMetric[] | null; + name: string; +} +export interface DashboardMetric { + id: string; + /** + * Unlike `RunnableMetric`, this label can be longer to fit your needs + */ + label: string | null; + /** + * Try to keep it short to have a great and more readable display (i.e. "MB", "%", "GB/s") + */ + unit: string | null; + /** + * Format it so it's displayed correctly in the app. + * If it's a percentage, unlike ratio, put directly the actual value (i.e. 25 and not 0.25) + */ + value: number | null; +} +export type GetDashboardMetricRes = DashboardMetric; +export interface ListDashboardsQueryParams extends ListQueryParams { + /** + * Filter on one or multiple properties. It's up to you to implement the filtering that you want. It can be as simple as equality check on one specific field (e.g. `name`). It can also be a partial check (e.g. `ILIKE` pattern) on multiple fields. + */ + q?: string; +} +export type ListDashboardsRes = ListRes; +export type ListDashboardMetricsRes = ListRes; diff --git a/dist/esm/spec/model/dashboard.js b/dist/esm/spec/model/dashboard.js new file mode 100644 index 0000000..23483a3 --- /dev/null +++ b/dist/esm/spec/model/dashboard.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=dashboard.js.map diff --git a/dist/esm/spec/model/dashboard.js.map b/dist/esm/spec/model/dashboard.js.map new file mode 100644 index 0000000..2ec380b --- /dev/null +++ b/dist/esm/spec/model/dashboard.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dashboard.js","sourceRoot":"","sources":["../../../../spec/model/dashboard.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/spec/model/runnable.d.ts b/dist/esm/spec/model/runnable.d.ts new file mode 100644 index 0000000..6cb385e --- /dev/null +++ b/dist/esm/spec/model/runnable.d.ts @@ -0,0 +1,108 @@ +import type { ListQueryParams, ListRes } from '../schema/list.js'; +export interface ListRunnablesQueryParams extends ListQueryParams { + /** + * Filter on one or multiple properties. It's up to you to implement the filtering that you want. It can be as simple as equality check on one specific field (e.g. `name`). It can also be a partial check (e.g. `ILIKE` pattern) on multiple fields. + */ + q?: string; +} +export type ListRunnablesRes = ListRes; +/** + * A metric associated to a runnable + */ +export interface RunnableMetric { + /** + * Try to keep it short to have a great and more readable display in the app (i.e. "CPU", "RAM", "Proc #") + */ + label: string | null; + /** + * The ratio of the value compared to its maximum. + * For example, if you have 1024 of RAM and 256 are being used, the ratio should be 256 / 1024 = 0.25 + * @maximum 1.0 + * @minimum 0.0 + */ + ratio: number | null; + /** + * If provided, it must be an array of two numbers. + * They respectively define the limits for "warning" and "danger". + * To illustrate with CPU usage, these values could be [60, 80]. + * In this case, if value < 60, it will be "success". + * If value < 80 it will be "warning". + * Everything else will be "danger". + * If the first value is greater than the second one (i.e. higher is better), the semantics are reversed. + * @maxItems 2 + * @minItems 2 + */ + thresholds: number[] | null; + /** + * Like for the label, try to keep it short to have a great and more readable display (i.e. "MB", "%", "GB/s") + */ + unit: string | null; + /** + * Format it so it's displayed correctly in the app. + * If it's a percentage, unlike ratio, put directly the actual value (i.e. 25 and not 0.25) + */ + value: number | null; +} +/** + * The status of a runnable + * Any intermediary status that you have on your side must be mapped to the `pending` status. + */ +export declare enum RunnableStatus { + OFF = 'off', + ON = 'on', + PENDING = 'pending', + UNKNOWN = 'unknown', +} +/** + * The context in which a runnable is + * It can be `geo`, defining the geographical zone where the runnable is (e.g. AWS regions code). + * It can also be `logical`, defining an abstract structure where the runnable is (e.g. GCP project). + */ +export interface RunnableScope { + label: string; + value: string; +} +/** + * The configuration to define how to SSH into the runnable + */ +export interface RunnableSSH { + keyName: string | null; + /** + * @isInt + * @minimum 0 + */ + port: number; + username: string; +} +/** + * The scopes in which the runnable is + */ +export interface RunnableScopes { + geo: RunnableScope | null; + logical: RunnableScope | null; +} +/** + * Anything that runs, can be stopped and rebooted + * Typical examples are cloud VMs, containers, PaaS applications, etc. + */ +export interface Runnable { + flavor: string | null; + fqdn: string | null; + id: string; + ipv4: string | null; + metrics: RunnableMetric[] | null; + name: string; + scopes: RunnableScopes; + ssh: RunnableSSH | null; + stack: string | null; + status: RunnableStatus; +} +/** + * The response of a reboot, stop operation + */ +export interface RunnableOperationRes { + /** + * If the operation is triggered via an asynchronous queue and will eventually succeed, the id can be provided here for information + */ + jobId: string | null; +} diff --git a/dist/esm/spec/model/runnable.js b/dist/esm/spec/model/runnable.js new file mode 100644 index 0000000..3ae535e --- /dev/null +++ b/dist/esm/spec/model/runnable.js @@ -0,0 +1,12 @@ +/** + * The status of a runnable + * Any intermediary status that you have on your side must be mapped to the `pending` status. + */ +export var RunnableStatus; +((RunnableStatus) => { + RunnableStatus['OFF'] = 'off'; + RunnableStatus['ON'] = 'on'; + RunnableStatus['PENDING'] = 'pending'; + RunnableStatus['UNKNOWN'] = 'unknown'; +})(RunnableStatus || (RunnableStatus = {})); +//# sourceMappingURL=runnable.js.map diff --git a/dist/esm/spec/model/runnable.js.map b/dist/esm/spec/model/runnable.js.map new file mode 100644 index 0000000..1370dcd --- /dev/null +++ b/dist/esm/spec/model/runnable.js.map @@ -0,0 +1 @@ +{"version":3,"file":"runnable.js","sourceRoot":"","sources":["../../../../spec/model/runnable.ts"],"names":[],"mappings":"AAqDA;;;GAGG;AACH,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACtB,6BAAW,CAAA;IACX,2BAAS,CAAA;IACT,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;AACvB,CAAC,EALW,cAAc,KAAd,cAAc,QAKzB"} \ No newline at end of file diff --git a/dist/esm/spec/schema/error.d.ts b/dist/esm/spec/schema/error.d.ts new file mode 100644 index 0000000..659d361 --- /dev/null +++ b/dist/esm/spec/schema/error.d.ts @@ -0,0 +1,6 @@ +export interface ErrorRes { + /** + * Provided in english in a human readable way + */ + message: string; +} diff --git a/dist/esm/spec/schema/error.js b/dist/esm/spec/schema/error.js new file mode 100644 index 0000000..0c096a7 --- /dev/null +++ b/dist/esm/spec/schema/error.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=error.js.map diff --git a/dist/esm/spec/schema/error.js.map b/dist/esm/spec/schema/error.js.map new file mode 100644 index 0000000..54c0847 --- /dev/null +++ b/dist/esm/spec/schema/error.js.map @@ -0,0 +1 @@ +{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../spec/schema/error.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/spec/schema/list.d.ts b/dist/esm/spec/schema/list.d.ts new file mode 100644 index 0000000..e10ef38 --- /dev/null +++ b/dist/esm/spec/schema/list.d.ts @@ -0,0 +1,22 @@ +export interface ListQueryParams { + /** + * Max number of items to return in the response. Set a reasonable default value (e.g. `50`) in your implementation. Avoid returning too many items at once for client performance reasons. + * @isInt + * @minimum 0 + */ + limit?: number; + /** + * Cursor from where to start fetching when paginating. The default value should be `0`. + * @isInt + * @minimum 0 + */ + offset?: number; +} +export interface ListRes { + items: T[]; + /** + * @isInt + * @minimum 0 + */ + total: number; +} diff --git a/dist/esm/spec/schema/list.js b/dist/esm/spec/schema/list.js new file mode 100644 index 0000000..6aae729 --- /dev/null +++ b/dist/esm/spec/schema/list.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=list.js.map diff --git a/dist/esm/spec/schema/list.js.map b/dist/esm/spec/schema/list.js.map new file mode 100644 index 0000000..a0bdc14 --- /dev/null +++ b/dist/esm/spec/schema/list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../../spec/schema/list.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..c021bb8 --- /dev/null +++ b/index.ts @@ -0,0 +1,22 @@ +export type { + Dashboard, + DashboardMetric, + GetDashboardMetricRes, + ListDashboardMetricsRes, + ListDashboardsQueryParams, + ListDashboardsRes, +} from './spec/model/dashboard.js'; +export { + type ListRunnablesQueryParams, + type ListRunnablesRes, + type Runnable, + type RunnableMetric, + type RunnableOperationRes, + type RunnableSSH, + type RunnableScope, + type RunnableScopes, + RunnableStatus, +} from './spec/model/runnable.js'; + +export type { ErrorRes } from './spec/schema/error.js'; +export type { ListQueryParams, ListRes } from './spec/schema/list.js'; diff --git a/package.json b/package.json index 6aa7ff7..e4bed68 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,14 @@ "name": "rebootx-on-prem", "version": "0.4.0", "type": "module", + "exports": { + ".": { + "import": "./dist/esm/index.js" + } + }, "scripts": { + "build": "rm -Rf dist && yarn build:esm", + "build:esm": "tsc --project tsconfig.build.json -outDir ./dist/esm", "lint": "biome check --write .", "lint:ci": "biome check", "test": "tsc" diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..5121185 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "./dist" + }, + "include": ["index.ts"] +}