Skip to content

Commit

Permalink
chore: expose types in esm
Browse files Browse the repository at this point in the history
  • Loading branch information
c100k committed Dec 5, 2024
1 parent 9415160 commit 9bf9159
Show file tree
Hide file tree
Showing 20 changed files with 257 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"ignore": ["dist/*"]
},
"formatter": {
"indentStyle": "space",
"indentWidth": 4
Expand Down
21 changes: 21 additions & 0 deletions dist/esm/index.d.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 2 additions & 0 deletions dist/esm/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/esm/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions dist/esm/spec/model/dashboard.d.ts
Original file line number Diff line number Diff line change
@@ -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<Dashboard>;
export type ListDashboardMetricsRes = ListRes<DashboardMetric>;
2 changes: 2 additions & 0 deletions dist/esm/spec/model/dashboard.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/esm/spec/model/dashboard.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 108 additions & 0 deletions dist/esm/spec/model/runnable.d.ts
Original file line number Diff line number Diff line change
@@ -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<Runnable>;
/**
* 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;
}
12 changes: 12 additions & 0 deletions dist/esm/spec/model/runnable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/esm/spec/model/runnable.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions dist/esm/spec/schema/error.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface ErrorRes {
/**
* Provided in english in a human readable way
*/
message: string;
}
2 changes: 2 additions & 0 deletions dist/esm/spec/schema/error.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/esm/spec/schema/error.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions dist/esm/spec/schema/list.d.ts
Original file line number Diff line number Diff line change
@@ -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<T extends {}> {
items: T[];
/**
* @isInt
* @minimum 0
*/
total: number;
}
2 changes: 2 additions & 0 deletions dist/esm/spec/schema/list.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/esm/spec/schema/list.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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';
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "./dist"
},
"include": ["index.ts"]
}

0 comments on commit 9bf9159

Please sign in to comment.