Add new typeing for System Task (#45489)

Co-authored-by: leo lam <leo.lam@uptake.com>
This commit is contained in:
llam 2020-06-23 12:20:55 -04:00 committed by GitHub
parent 21779203f3
commit ac096c0d79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 0 deletions

26
types/system-task/index.d.ts vendored Normal file
View 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>;
}

View 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();

View 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"
]
}

View File

@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"npm-naming": false
}
}