mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
Merge pull request #34599 from purmac/typedef-lightship
Add type definition for lightship
This commit is contained in:
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
// Type definitions for lightship 3.0
|
||||
// Project: https://github.com/gajus/lightship#readme
|
||||
// Definitions by: Scott Chang <https://github.com/purmac>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference types="node" />
|
||||
|
||||
/**
|
||||
* A teardown function called when shutdown is initialized.
|
||||
* @param userConfiguration User configuration object
|
||||
*/
|
||||
export function createLightship(userConfiguration?: UserConfigurationType): LightshipType;
|
||||
|
||||
export interface UserConfigurationType {
|
||||
/* Run Iapetus only if service is detected ro be running in Kubernetes. Default: true. */
|
||||
detectKubernetes?: boolean;
|
||||
/* The port on which the Lightship service listens. This port must be different than your main service port, if any. The default port is 9000.*/
|
||||
port?: number;
|
||||
/* An a array of [signal events]{@link https://nodejs.org/api/process.html#process_signal_events}. Default: [SIGTERM]. */
|
||||
signals?: ReadonlyArray<NodeJS.Signals>;
|
||||
/* A number of milliseconds before force full termination. Default: 60000. */
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export interface LightshipType {
|
||||
/* Checks if server is in SERVER_IS_READY state */
|
||||
isServerReady: () => boolean;
|
||||
/* Checks if server is in SERVER_IS_SHUTTING_DOWN state */
|
||||
isServerShuttingDown: () => boolean;
|
||||
/**
|
||||
* Registers teardown functions that are called when shutdown is initialized.
|
||||
* All registered shutdown handlers are executed in the order they have been registered.
|
||||
* After all shutdown handlers have been executed, Lightship asks `process.exit()` to terminate the process synchronously.
|
||||
*/
|
||||
registerShutdownHandler: (shutdownHandler: ShutdownHandlerType) => void;
|
||||
/* Changes server state to SERVER_IS_SHUTTING_DOWN and initialises the shutdown of the application.*/
|
||||
shutdown: () => Promise<void>;
|
||||
/* Changes server state to SERVER_IS_NOT_READY. */
|
||||
signalNotReady: () => void;
|
||||
/* Changes server state to SERVER_IS_READY. */
|
||||
signalReady: () => void;
|
||||
}
|
||||
|
||||
export type ShutdownHandlerType = () => Promise<void> | void;
|
||||
@@ -0,0 +1,17 @@
|
||||
import { createLightship, UserConfigurationType, LightshipType } from 'lightship';
|
||||
|
||||
const lightshipParams: UserConfigurationType = {
|
||||
detectKubernetes: false,
|
||||
timeout: 1000,
|
||||
port: 50,
|
||||
signals: ['SIGBUS']
|
||||
};
|
||||
|
||||
const lightship: LightshipType = createLightship(lightshipParams);
|
||||
|
||||
lightship.isServerReady(); // $ExpectType boolean
|
||||
lightship.isServerShuttingDown(); // $ExpectType boolean
|
||||
lightship.registerShutdownHandler(() => {}); // $ExpectType void
|
||||
lightship.shutdown(); // $ExpectType Promise<void>
|
||||
lightship.signalNotReady(); // $ExpectType void
|
||||
lightship.signalReady(); // $ExpectType void
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"lightship-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user