mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add new typeing for System Task (#45489)
Co-authored-by: leo lam <leo.lam@uptake.com>
This commit is contained in:
parent
21779203f3
commit
ac096c0d79
26
types/system-task/index.d.ts
vendored
Normal file
26
types/system-task/index.d.ts
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
// Type definitions for system-task 1.0
|
||||
// Project: https://github.com/leocwlam/system-task
|
||||
// Definitions by: Leo Lam <https://github.com/leocwlam>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// Minimum TypeScript Version: 3.1
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export = SystemTask;
|
||||
|
||||
declare class SystemTask {
|
||||
type: string;
|
||||
constructor(taskType: string, isAsyncProcess?: boolean, logMethod?: any);
|
||||
log(type: string, message: string, detail?: any): void;
|
||||
insertPreprocessItemsHandler(task: SystemTask): Promise<any>;
|
||||
preprocessHandler(task: SystemTask, preProcessItem: any): Promise<any>;
|
||||
processHandler(task: SystemTask, processItem: any): Promise<any>;
|
||||
cleanupHandler(task: SystemTask, cleanupItems: any[]): Promise<any>;
|
||||
isValidProcess(): void;
|
||||
start(): void;
|
||||
}
|
||||
|
||||
declare namespace SystemTask {
|
||||
function asyncProcess(items: any[], executeAsyncCall: any, task: SystemTask, errors: any[]): Promise<any>;
|
||||
function syncProcess(items: any[], executeSyncCall: any, task: SystemTask, errors: any[]): Promise<any>;
|
||||
}
|
||||
45
types/system-task/system-task-tests.ts
Normal file
45
types/system-task/system-task-tests.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import * as SystemTask from 'system-task';
|
||||
|
||||
const TYPE = 'Demo Task';
|
||||
const REQUIREASYNCEPROCESS = true;
|
||||
|
||||
const DEMOASSET = {
|
||||
name: 'DEMO ASSET',
|
||||
async execute(message: string) {
|
||||
return new Promise((res) => {
|
||||
setTimeout(() => {
|
||||
console.log(`Done with ${message}`);
|
||||
res();
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const logMethod = (messageType: string, message: string, detailMessage?: any) => {
|
||||
console.log(messageType, message, detailMessage);
|
||||
};
|
||||
|
||||
class DemoTask extends SystemTask {
|
||||
constructor() {
|
||||
super(TYPE, REQUIREASYNCEPROCESS, logMethod);
|
||||
}
|
||||
|
||||
async insertPreprocessItemsHandler(task: DemoTask): Promise<any> {
|
||||
if (!task) {
|
||||
throw new Error('missing task');
|
||||
}
|
||||
return [
|
||||
{...DEMOASSET, name: 'Asset 1' },
|
||||
{...DEMOASSET, name: 'Asset 2' }
|
||||
];
|
||||
}
|
||||
|
||||
async processHandler(task: DemoTask, processItem: any): Promise<any> {
|
||||
await processItem.execute(processItem.name);
|
||||
|
||||
return processItem;
|
||||
}
|
||||
}
|
||||
|
||||
const task: DemoTask = new DemoTask();
|
||||
task.start();
|
||||
25
types/system-task/tsconfig.json
Normal file
25
types/system-task/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"target": "es2017",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"system-task-tests.ts"
|
||||
]
|
||||
}
|
||||
6
types/system-task/tslint.json
Normal file
6
types/system-task/tslint.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"npm-naming": false
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user