ddan-js 2.5.5 → 2.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
+ import { Ddan } from '../../typings';
1
2
  declare function to<T = any, U extends object = any>(promise: Promise<T>, errorExt?: object): Promise<[null, T] | [U, undefined]>;
2
3
  declare const _default: {
3
4
  to: typeof to;
4
- go: <T = any>(task?: Function | Promise<T> | undefined) => Promise<[any, undefined] | [null, T]>;
5
+ go: <T = any>(task?: Ddan.PFunction<T> | undefined) => Promise<[any, undefined] | [null, T]>;
5
6
  delay: (ms?: number) => Promise<unknown>;
6
7
  safeDo: <T_1 = any>(func: any) => Promise<[null, T_1] | [any, undefined]>;
7
8
  };
@@ -0,0 +1,17 @@
1
+ import DPipeline from './modules/pipeline';
2
+ import { Ddan } from '../../typings';
3
+ declare const DHooker_base: {
4
+ new (): {};
5
+ __instance__: any;
6
+ readonly Instance: DHooker;
7
+ readonly I: DHooker;
8
+ };
9
+ export default class DHooker extends DHooker_base {
10
+ __lockedMap: Map<string, Ddan.SafeResult<any>>;
11
+ pipeline: DPipeline;
12
+ constructor();
13
+ lock(id: string, func: Ddan.PFunction): Promise<[any, undefined] | [null, any]> | undefined;
14
+ unlock(id: string): void;
15
+ exec(func: Ddan.PFunction, taskId: string): Ddan.SafeResult;
16
+ }
17
+ export {};
@@ -1,27 +1,30 @@
1
+ import { Ddan } from '../../typings';
1
2
  import debounce from './debounce';
2
3
  import throttle from './throttle';
3
4
  import mutex from './mutex';
4
5
  import DPipeTask from '../../class/pipeTask';
5
- import { Ddan } from '../../typings';
6
6
  import polling from './polling';
7
+ import DPipeline from './modules/pipeline';
7
8
  /**
8
9
  *
9
10
  * @param task 任务
10
11
  * @param wait 最小等待时间,单位毫秒
11
12
  * @returns
12
13
  */
13
- declare function run<T = any>(task?: Promise<T> | Function, wait?: number): Promise<[any, undefined] | [null, T]>;
14
+ declare function run<T = any>(task?: Ddan.PFunction<T>, wait?: number): Promise<[any, undefined] | [null, T]>;
14
15
  declare const _default: {
15
16
  sleep: (ms?: number) => Promise<unknown>;
16
17
  run: typeof run;
17
- exec: (func: Function, taskId?: string) => Promise<any[]>;
18
+ exec: (func: Ddan.PFunction<any>, taskId?: string) => Ddan.SafeResult<any>;
18
19
  debounce: typeof debounce;
19
20
  throttle: typeof throttle;
20
21
  task: (param?: Ddan.Func1<any, any> | undefined) => DPipeTask;
21
22
  mutex: typeof mutex;
22
23
  polling: typeof polling;
24
+ pipe: (func: Ddan.PFunction<any>) => DPipeline;
25
+ pipeline: () => DPipeline;
23
26
  to: <T = any, U extends object = any>(promise: Promise<T>, errorExt?: object | undefined) => Promise<[null, T] | [U, undefined]>;
24
- go: <T_1 = any>(task?: Function | Promise<T_1> | undefined) => Promise<[any, undefined] | [null, T_1]>;
27
+ go: <T_1 = any>(task?: Ddan.PFunction<T_1> | undefined) => Promise<[any, undefined] | [null, T_1]>;
25
28
  delay: (ms?: number) => Promise<unknown>;
26
29
  safeDo: <T_2 = any>(func: any) => Promise<[null, T_2] | [any, undefined]>;
27
30
  };
@@ -1,9 +1,10 @@
1
- export default class DPipeline {
2
- __list: any[];
1
+ import { Ddan } from '../../../typings';
2
+ export default class DPipeline implements Ddan.IPipeline {
3
+ __list: Ddan.PFunction[];
3
4
  __running: boolean;
4
5
  __waitting: boolean;
5
6
  constructor();
6
- pipe(_task?: any): this;
7
+ pipe(_task?: Ddan.PFunction): this;
7
8
  delay(t?: number): this;
8
9
  clear(): this;
9
10
  _step(): Promise<void>;
@@ -6,6 +6,7 @@ export declare namespace Ddan {
6
6
  }
7
7
  type KeyValue<T = any> = Required<IKeyValuePart<T>>;
8
8
  type Function = (...args: any[]) => void;
9
+ type PFunction<T = any> = Promise<T> | Function;
9
10
  type Callback<T extends any[] = unknown[], R = any> = (...args: T) => R;
10
11
  type Action<T extends any[] = unknown[]> = Callback<T, void>;
11
12
  type Task<T = any, R = void> = Callback<[T[]], R>;
@@ -15,6 +16,7 @@ export declare namespace Ddan {
15
16
  type Func3<T0 = any, T1 = any, T2 = any, R = any> = Callback<[T0, T1, T2], R>;
16
17
  type Func4<T0 = any, T1 = any, T2 = any, T3 = any, R = any> = Callback<[T0, T1, T2, T3], R>;
17
18
  type Result<T = any> = T | Promise<T>;
19
+ type SafeResult<T = any> = Promise<[any, undefined] | [null, T]>;
18
20
  interface IHttpHost {
19
21
  href: string;
20
22
  url: string;
@@ -122,7 +124,7 @@ export declare namespace Ddan {
122
124
  }
123
125
  interface IRegexRule {
124
126
  key: string;
125
- flag?: "i" | "g" | "m" | "gi" | "mi";
127
+ flag?: 'i' | 'g' | 'm' | 'gi' | 'mi';
126
128
  value: string;
127
129
  }
128
130
  interface IIgnoreParams {
@@ -142,6 +144,12 @@ export declare namespace Ddan {
142
144
  maxWait?: number;
143
145
  trailing?: boolean;
144
146
  }
147
+ interface IPipeline {
148
+ pipe(func?: any): IPipeline;
149
+ delay(t?: number): IPipeline;
150
+ clear(): IPipeline;
151
+ whenAll(): Promise<IPipeline>;
152
+ }
145
153
  }
146
154
  export declare namespace dd {
147
155
  interface IHttpRequest {
@@ -165,7 +173,7 @@ export declare namespace dd {
165
173
  [key: string]: any;
166
174
  url: string;
167
175
  model?: string;
168
- method: "get" | "post" | "put";
176
+ method: 'get' | 'post' | 'put';
169
177
  body?: string;
170
178
  plugins?: Record<string, any>;
171
179
  }
@@ -193,7 +201,7 @@ export declare namespace dd {
193
201
  interface IDWatermarkParams {
194
202
  [key: string]: any;
195
203
  t?: number;
196
- g?: "nw" | "north" | "ne" | "west" | "center" | "east" | "sw" | "south" | "se";
204
+ g?: 'nw' | 'north' | 'ne' | 'west' | 'center' | 'east' | 'sw' | 'south' | 'se';
197
205
  x?: number;
198
206
  y?: number;
199
207
  voffset?: number;
@@ -202,7 +210,7 @@ export declare namespace dd {
202
210
  pady?: number;
203
211
  }
204
212
  interface IDWatermarkText {
205
- type?: "d3F5LXplbmhlaQ" | "d3F5LW1pY3JvaGVp" | "ZmFuZ3poZW5nc2h1c29uZw" | "ZmFuZ3poZW5na2FpdGk" | "ZmFuZ3poZW5naGVpdGk" | "ZmFuZ3poZW5nZmFuZ3Nvbmc" | "ZHJvaWRzYW5zZmFsbGJhY2s";
213
+ type?: 'd3F5LXplbmhlaQ' | 'd3F5LW1pY3JvaGVp' | 'ZmFuZ3poZW5nc2h1c29uZw' | 'ZmFuZ3poZW5na2FpdGk' | 'ZmFuZ3poZW5naGVpdGk' | 'ZmFuZ3poZW5nZmFuZ3Nvbmc' | 'ZHJvaWRzYW5zZmFsbGJhY2s';
206
214
  color?: string;
207
215
  size?: number;
208
216
  shadow?: number;
@@ -7,6 +7,7 @@ declare function singleton<T>(): {
7
7
  new (): {};
8
8
  __instance__: any;
9
9
  readonly Instance: T;
10
+ readonly I: T;
10
11
  };
11
12
  declare function getset<T = any>(t?: T): Ddan.IGetset<T>;
12
13
  declare const _default: {
@@ -6,6 +6,7 @@ declare const _default: {
6
6
  new (): {};
7
7
  __instance__: any;
8
8
  readonly Instance: T;
9
+ readonly I: T;
9
10
  };
10
11
  getset: <T_1 = any>(t?: T_1 | undefined) => import("..").Ddan.IGetset<T_1>;
11
12
  copy: (source: any, options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.5.5",
3
+ "version": "2.5.7",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const base_1 = require("../modules/hook/base");
4
- class DTask {
5
- __source;
6
- constructor(source) {
7
- this.__source = source;
8
- }
9
- run = () => base_1.default.safeDo(this.__source);
10
- static _lockedMap = new Map();
11
- static _lock(id, func) {
12
- if (!id || !func)
13
- return undefined;
14
- const task = new DTask(func).run();
15
- this._lockedMap.set(id, task);
16
- return task;
17
- }
18
- static _unlock(id) {
19
- if (!id)
20
- return;
21
- this._lockedMap.delete(id);
22
- }
23
- static async exec(func, taskId) {
24
- if (!func || !taskId) {
25
- return new DTask(func).run();
26
- }
27
- const _task = this._lockedMap.get(taskId);
28
- if (_task) {
29
- return _task;
30
- }
31
- const _newTask = this._lock(taskId, func);
32
- if (!_newTask)
33
- return new DTask(func).run();
34
- const result = await _newTask;
35
- this._unlock(taskId);
36
- return result;
37
- }
38
- }
39
- exports.default = DTask;
@@ -1,9 +0,0 @@
1
- export default class DTask<T = any> {
2
- __source: any;
3
- constructor(source?: any);
4
- run: () => Promise<[any, undefined] | [null, T]>;
5
- static _lockedMap: Map<string, Promise<any[]>>;
6
- static _lock(id: string, func: Function): Promise<[any, undefined] | [null, any]> | undefined;
7
- static _unlock(id: string): void;
8
- static exec(func: Function, taskId: string): Promise<any[]>;
9
- }