@midwayjs/decorator 3.0.0-beta.9 → 3.0.4

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,5 +1,7 @@
1
1
  import { ScopeEnum } from '../../index';
2
2
  export declare function Init(): MethodDecorator;
3
3
  export declare function Destroy(): MethodDecorator;
4
- export declare function Scope(scope: ScopeEnum): ClassDecorator;
4
+ export declare function Scope(scope: ScopeEnum, scopeOptions?: {
5
+ allowDowngrade?: boolean;
6
+ }): ClassDecorator;
5
7
  //# sourceMappingURL=objectDef.d.ts.map
@@ -16,9 +16,9 @@ function Destroy() {
16
16
  };
17
17
  }
18
18
  exports.Destroy = Destroy;
19
- function Scope(scope) {
19
+ function Scope(scope, scopeOptions) {
20
20
  return function (target) {
21
- (0, index_1.saveObjectDefinition)(target, { scope });
21
+ (0, index_1.saveObjectDefinition)(target, { scope, ...scopeOptions });
22
22
  };
23
23
  }
24
24
  exports.Scope = Scope;
@@ -1,20 +1,3 @@
1
- export interface GetFileStreamOptions {
2
- requireFile?: boolean;
3
- defCharset?: string;
4
- limits?: {
5
- fieldNameSize?: number;
6
- fieldSize?: number;
7
- fields?: number;
8
- fileSize?: number;
9
- files?: number;
10
- parts?: number;
11
- headerPairs?: number;
12
- };
13
- checkFile?(fieldname: string, file: any, filename: string, encoding: string, mimetype: string): void | Error;
14
- }
15
- export interface GetFilesStreamOptions extends GetFileStreamOptions {
16
- autoFields?: boolean;
17
- }
18
1
  export declare enum RouteParamTypes {
19
2
  QUERY = 0,
20
3
  BODY = 1,
@@ -26,7 +9,8 @@ export declare enum RouteParamTypes {
26
9
  NEXT = 7,
27
10
  REQUEST_PATH = 8,
28
11
  REQUEST_IP = 9,
29
- QUERIES = 10
12
+ QUERIES = 10,
13
+ FIELDS = 11
30
14
  }
31
15
  export interface RouterParamValue {
32
16
  index: number;
@@ -38,9 +22,10 @@ export declare const Body: (property?: string) => ParameterDecorator;
38
22
  export declare const Query: (property?: string) => ParameterDecorator;
39
23
  export declare const Param: (property?: string) => ParameterDecorator;
40
24
  export declare const Headers: (property?: string) => ParameterDecorator;
41
- export declare const File: (property?: GetFileStreamOptions) => ParameterDecorator;
42
- export declare const Files: (property?: GetFilesStreamOptions) => ParameterDecorator;
25
+ export declare const File: (property?: any) => ParameterDecorator;
26
+ export declare const Files: (property?: any) => ParameterDecorator;
43
27
  export declare const RequestPath: () => ParameterDecorator;
44
28
  export declare const RequestIP: () => ParameterDecorator;
45
29
  export declare const Queries: (property?: string) => ParameterDecorator;
30
+ export declare const Fields: (property?: string) => ParameterDecorator;
46
31
  //# sourceMappingURL=paramMapping.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queries = exports.RequestIP = exports.RequestPath = exports.Files = exports.File = exports.Headers = exports.Param = exports.Query = exports.Body = exports.Session = exports.RouteParamTypes = void 0;
3
+ exports.Fields = exports.Queries = exports.RequestIP = exports.RequestPath = exports.Files = exports.File = exports.Headers = exports.Param = exports.Query = exports.Body = exports.Session = exports.RouteParamTypes = void 0;
4
4
  const __1 = require("../../");
5
5
  var RouteParamTypes;
6
6
  (function (RouteParamTypes) {
@@ -15,6 +15,7 @@ var RouteParamTypes;
15
15
  RouteParamTypes[RouteParamTypes["REQUEST_PATH"] = 8] = "REQUEST_PATH";
16
16
  RouteParamTypes[RouteParamTypes["REQUEST_IP"] = 9] = "REQUEST_IP";
17
17
  RouteParamTypes[RouteParamTypes["QUERIES"] = 10] = "QUERIES";
18
+ RouteParamTypes[RouteParamTypes["FIELDS"] = 11] = "FIELDS";
18
19
  })(RouteParamTypes = exports.RouteParamTypes || (exports.RouteParamTypes = {}));
19
20
  const createParamMapping = function (type) {
20
21
  return (propertyData) => {
@@ -44,4 +45,6 @@ const RequestIP = () => createParamMapping(RouteParamTypes.REQUEST_IP)();
44
45
  exports.RequestIP = RequestIP;
45
46
  const Queries = (property) => createParamMapping(RouteParamTypes.QUERIES)(property);
46
47
  exports.Queries = Queries;
48
+ const Fields = (property) => createParamMapping(RouteParamTypes.FIELDS)(property);
49
+ exports.Fields = Fields;
47
50
  //# sourceMappingURL=paramMapping.js.map
@@ -22,10 +22,12 @@ export interface RouterOption {
22
22
  middleware?: MiddlewareParamArray;
23
23
  /**
24
24
  * router summary, for swagger
25
+ * @deprecated
25
26
  */
26
27
  summary?: string;
27
28
  /**
28
29
  * router description, for swagger
30
+ * @deprecated
29
31
  */
30
32
  description?: string;
31
33
  /**
@@ -281,8 +281,21 @@ export declare function getMethodReturnTypes(target: any, methodName: string | s
281
281
  * create a custom property inject
282
282
  * @param decoratorKey
283
283
  * @param metadata
284
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
284
285
  */
285
- export declare function createCustomPropertyDecorator(decoratorKey: string, metadata: any): PropertyDecorator;
286
- export declare function createCustomMethodDecorator(decoratorKey: string, metadata: any): MethodDecorator;
287
- export declare function createCustomParamDecorator(decoratorKey: string, metadata: any): ParameterDecorator;
286
+ export declare function createCustomPropertyDecorator(decoratorKey: string, metadata: any, impl?: boolean): PropertyDecorator;
287
+ /**
288
+ *
289
+ * @param decoratorKey
290
+ * @param metadata
291
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
292
+ */
293
+ export declare function createCustomMethodDecorator(decoratorKey: string, metadata: any, impl?: boolean): MethodDecorator;
294
+ /**
295
+ *
296
+ * @param decoratorKey
297
+ * @param metadata
298
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
299
+ */
300
+ export declare function createCustomParamDecorator(decoratorKey: string, metadata: any, impl?: boolean): ParameterDecorator;
288
301
  //# sourceMappingURL=decoratorManager.d.ts.map
@@ -4,6 +4,7 @@ exports.createCustomParamDecorator = exports.createCustomMethodDecorator = expor
4
4
  require("reflect-metadata");
5
5
  const constant_1 = require("./constant");
6
6
  const util_1 = require("./util");
7
+ const camelCase_1 = require("./util/camelCase");
7
8
  const debug = require('util').debuglog('midway:decorator');
8
9
  exports.PRELOAD_MODULE_KEY = 'INJECTION_PRELOAD_MODULE_KEY';
9
10
  exports.INJECT_CLASS_KEY_PREFIX = 'INJECTION_CLASS_META_DATA';
@@ -565,7 +566,7 @@ function saveProviderId(identifier, target) {
565
566
  id: identifier,
566
567
  originName: target.name,
567
568
  uuid,
568
- name: (0, util_1.classNamed)(target.name),
569
+ name: (0, camelCase_1.camelCase)(target.name),
569
570
  }, target);
570
571
  debug(`save provide: ${target.name} -> ${uuid}`);
571
572
  }
@@ -650,28 +651,43 @@ exports.getMethodReturnTypes = getMethodReturnTypes;
650
651
  * create a custom property inject
651
652
  * @param decoratorKey
652
653
  * @param metadata
654
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
653
655
  */
654
- function createCustomPropertyDecorator(decoratorKey, metadata) {
656
+ function createCustomPropertyDecorator(decoratorKey, metadata, impl = true) {
655
657
  return function (target, propertyName) {
656
658
  attachClassMetadata(constant_1.INJECT_CUSTOM_PROPERTY, {
657
659
  propertyName,
658
660
  key: decoratorKey,
659
661
  metadata,
662
+ impl,
660
663
  }, target, propertyName);
661
664
  };
662
665
  }
663
666
  exports.createCustomPropertyDecorator = createCustomPropertyDecorator;
664
- function createCustomMethodDecorator(decoratorKey, metadata) {
667
+ /**
668
+ *
669
+ * @param decoratorKey
670
+ * @param metadata
671
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
672
+ */
673
+ function createCustomMethodDecorator(decoratorKey, metadata, impl = true) {
665
674
  return function (target, propertyName, descriptor) {
666
675
  attachClassMetadata(constant_1.INJECT_CUSTOM_METHOD, {
667
676
  propertyName,
668
677
  key: decoratorKey,
669
678
  metadata,
679
+ impl,
670
680
  }, target);
671
681
  };
672
682
  }
673
683
  exports.createCustomMethodDecorator = createCustomMethodDecorator;
674
- function createCustomParamDecorator(decoratorKey, metadata) {
684
+ /**
685
+ *
686
+ * @param decoratorKey
687
+ * @param metadata
688
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
689
+ */
690
+ function createCustomParamDecorator(decoratorKey, metadata, impl = true) {
675
691
  return function (target, propertyName, parameterIndex) {
676
692
  // const parameterName = getParamNames(target[methodName])[parameterIndex];
677
693
  attachClassMetadata(constant_1.INJECT_CUSTOM_PARAM, {
@@ -679,6 +695,7 @@ function createCustomParamDecorator(decoratorKey, metadata) {
679
695
  parameterIndex,
680
696
  propertyName,
681
697
  metadata,
698
+ impl,
682
699
  }, target, propertyName, 'multi');
683
700
  };
684
701
  }
package/dist/index.d.ts CHANGED
@@ -2,5 +2,7 @@ export * from './decorator';
2
2
  export * from './interface';
3
3
  export * from './constant';
4
4
  export * from './decoratorManager';
5
- export * from './util/index';
5
+ export { Types, Utils, sleep } from './util/index';
6
+ export { FileUtils } from './util/fs';
7
+ export * from './util/format';
6
8
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -10,9 +10,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.FileUtils = exports.sleep = exports.Utils = exports.Types = void 0;
13
14
  __exportStar(require("./decorator"), exports);
14
15
  __exportStar(require("./interface"), exports);
15
16
  __exportStar(require("./constant"), exports);
16
17
  __exportStar(require("./decoratorManager"), exports);
17
- __exportStar(require("./util/index"), exports);
18
+ var index_1 = require("./util/index");
19
+ Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return index_1.Types; } });
20
+ Object.defineProperty(exports, "Utils", { enumerable: true, get: function () { return index_1.Utils; } });
21
+ Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return index_1.sleep; } });
22
+ var fs_1 = require("./util/fs");
23
+ Object.defineProperty(exports, "FileUtils", { enumerable: true, get: function () { return fs_1.FileUtils; } });
24
+ __exportStar(require("./util/format"), exports);
18
25
  //# sourceMappingURL=index.js.map
@@ -22,6 +22,7 @@ export interface ObjectDefinitionOptions {
22
22
  constructorArgs?: any[];
23
23
  namespace?: string;
24
24
  srcPath?: string;
25
+ allowDowngrade?: boolean;
25
26
  }
26
27
  export interface TagPropsMetadata {
27
28
  key: string | number | symbol;
@@ -0,0 +1,3 @@
1
+ export declare function camelCase(input: string): string;
2
+ export declare function pascalCase(input: string): string;
3
+ //# sourceMappingURL=camelCase.d.ts.map
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pascalCase = exports.camelCase = void 0;
4
+ const UPPERCASE = /[\p{Lu}]/u;
5
+ const LOWERCASE = /[\p{Ll}]/u;
6
+ const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
7
+ const SEPARATORS = /[_.\- ]+/;
8
+ const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
9
+ const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');
10
+ const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu');
11
+ const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
12
+ let isLastCharLower = false;
13
+ let isLastCharUpper = false;
14
+ let isLastLastCharUpper = false;
15
+ for (let i = 0; i < string.length; i++) {
16
+ const character = string[i];
17
+ if (isLastCharLower && UPPERCASE.test(character)) {
18
+ string = string.slice(0, i) + '-' + string.slice(i);
19
+ isLastCharLower = false;
20
+ isLastLastCharUpper = isLastCharUpper;
21
+ isLastCharUpper = true;
22
+ i++;
23
+ }
24
+ else if (isLastCharUpper &&
25
+ isLastLastCharUpper &&
26
+ LOWERCASE.test(character)) {
27
+ string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
28
+ isLastLastCharUpper = isLastCharUpper;
29
+ isLastCharUpper = false;
30
+ isLastCharLower = true;
31
+ }
32
+ else {
33
+ isLastCharLower =
34
+ toLowerCase(character) === character &&
35
+ toUpperCase(character) !== character;
36
+ isLastLastCharUpper = isLastCharUpper;
37
+ isLastCharUpper =
38
+ toUpperCase(character) === character &&
39
+ toLowerCase(character) !== character;
40
+ }
41
+ }
42
+ return string;
43
+ };
44
+ const postProcess = (input, toUpperCase) => {
45
+ SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
46
+ NUMBERS_AND_IDENTIFIER.lastIndex = 0;
47
+ return input
48
+ .replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
49
+ .replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
50
+ };
51
+ function camelCaseOrigin(input, options) {
52
+ options = {
53
+ pascalCase: false,
54
+ ...options,
55
+ };
56
+ input = input.trim();
57
+ if (input.length === 0) {
58
+ return '';
59
+ }
60
+ const toLowerCase = string => string.toLowerCase();
61
+ const toUpperCase = string => string.toUpperCase();
62
+ if (input.length === 1) {
63
+ return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
64
+ }
65
+ const hasUpperCase = input !== toLowerCase(input);
66
+ if (hasUpperCase) {
67
+ input = preserveCamelCase(input, toLowerCase, toUpperCase);
68
+ }
69
+ input = input.replace(LEADING_SEPARATORS, '');
70
+ input = toLowerCase(input);
71
+ if (options.pascalCase) {
72
+ input = toUpperCase(input.charAt(0)) + input.slice(1);
73
+ }
74
+ return postProcess(input, toUpperCase);
75
+ }
76
+ function camelCase(input) {
77
+ return camelCaseOrigin(input, {
78
+ pascalCase: false,
79
+ });
80
+ }
81
+ exports.camelCase = camelCase;
82
+ function pascalCase(input) {
83
+ return camelCaseOrigin(input, {
84
+ pascalCase: true,
85
+ });
86
+ }
87
+ exports.pascalCase = pascalCase;
88
+ //# sourceMappingURL=camelCase.js.map
@@ -0,0 +1,25 @@
1
+ export declare const FORMAT: {
2
+ MS: {
3
+ ONE_SECOND: number;
4
+ ONE_MINUTE: number;
5
+ ONE_HOUR: number;
6
+ ONE_DAY: number;
7
+ ONE_WEEK: number;
8
+ ONE_YEAR: number;
9
+ };
10
+ CRONTAB: {
11
+ EVERY_SECOND: string;
12
+ EVERY_MINUTE: string;
13
+ EVERY_HOUR: string;
14
+ EVERY_DAY: string;
15
+ EVERY_DAY_ZERO_FIFTEEN: string;
16
+ EVERY_DAY_ONE_FIFTEEN: string;
17
+ EVERY_PER_5_SECOND: string;
18
+ EVERY_PER_10_SECOND: string;
19
+ EVERY_PER_30_SECOND: string;
20
+ EVERY_PER_5_MINUTE: string;
21
+ EVERY_PER_10_MINUTE: string;
22
+ EVERY_PER_30_MINUTE: string;
23
+ };
24
+ };
25
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FORMAT = void 0;
4
+ // value from ms package
5
+ const s = 1000;
6
+ const m = s * 60;
7
+ const h = m * 60;
8
+ const d = h * 24;
9
+ const w = d * 7;
10
+ const y = d * 365.25;
11
+ const MS = {
12
+ ONE_SECOND: s,
13
+ ONE_MINUTE: m,
14
+ ONE_HOUR: h,
15
+ ONE_DAY: d,
16
+ ONE_WEEK: w,
17
+ ONE_YEAR: y,
18
+ };
19
+ // crontab pre format
20
+ const CRONTAB = {
21
+ EVERY_SECOND: '* * * * * *',
22
+ EVERY_MINUTE: '0 * * * * *',
23
+ EVERY_HOUR: '0 0 * * * *',
24
+ EVERY_DAY: '0 0 0 * * *',
25
+ EVERY_DAY_ZERO_FIFTEEN: '0 15 0 * * *',
26
+ EVERY_DAY_ONE_FIFTEEN: '0 15 1 * * *',
27
+ EVERY_PER_5_SECOND: '*/5 * * * * *',
28
+ EVERY_PER_10_SECOND: '*/10 * * * * *',
29
+ EVERY_PER_30_SECOND: '*/30 * * * * *',
30
+ EVERY_PER_5_MINUTE: '0 */5 * * * *',
31
+ EVERY_PER_10_MINUTE: '0 */10 * * * *',
32
+ EVERY_PER_30_MINUTE: '0 */30 * * * *',
33
+ };
34
+ exports.FORMAT = {
35
+ MS,
36
+ CRONTAB,
37
+ };
38
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1,5 @@
1
+ export declare function exists(p: any): Promise<boolean>;
2
+ export declare const FileUtils: {
3
+ exists: typeof exists;
4
+ };
5
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileUtils = exports.exists = void 0;
4
+ const fs_1 = require("fs");
5
+ async function exists(p) {
6
+ return fs_1.promises
7
+ .access(p, fs_1.constants.F_OK)
8
+ .then(() => true)
9
+ .catch(() => false);
10
+ }
11
+ exports.exists = exists;
12
+ exports.FileUtils = {
13
+ exists,
14
+ };
15
+ //# sourceMappingURL=fs.js.map
@@ -1,9 +1,13 @@
1
+ import { camelCase, pascalCase } from './camelCase';
2
+ import { randomUUID } from './uuid';
3
+ export declare function isString(value: any): boolean;
1
4
  export declare function isClass(fn: any): boolean;
2
5
  export declare function isAsyncFunction(value: any): boolean;
3
6
  export declare function isGeneratorFunction(value: any): boolean;
4
7
  export declare function isPromise(value: any): boolean;
5
8
  export declare function isFunction(value: any): boolean;
6
9
  export declare function isObject(value: any): boolean;
10
+ export declare function isPlainObject(obj: any): any;
7
11
  export declare function isNumber(value: any): boolean;
8
12
  export declare function isProxy(value: any): boolean;
9
13
  export declare function isMap(value: any): boolean;
@@ -19,13 +23,37 @@ export declare function sleep(sleepTime?: number): Promise<void>;
19
23
  */
20
24
  export declare function getParamNames(func: any): string[];
21
25
  /**
22
- * 按照框架规则返回类名字
23
- * @param name 类名称
24
- */
25
- export declare function classNamed(name: string): string;
26
- /**
27
- * generate a lightweight random id, enough for ioc container
26
+ * generate a lightweight 32 bit random id, enough for ioc container
28
27
  */
29
28
  export declare function generateRandomId(): string;
30
29
  export declare function merge(target: any, src: any): any;
30
+ export declare function toAsyncFunction<T extends (...args: any[]) => any>(method: T): (...args: Parameters<T>) => Promise<ReturnType<T>>;
31
+ export declare const Types: {
32
+ isClass: typeof isClass;
33
+ isAsyncFunction: typeof isAsyncFunction;
34
+ isGeneratorFunction: typeof isGeneratorFunction;
35
+ isString: typeof isString;
36
+ isPromise: typeof isPromise;
37
+ isFunction: typeof isFunction;
38
+ isObject: typeof isObject;
39
+ isPlainObject: typeof isPlainObject;
40
+ isNumber: typeof isNumber;
41
+ isProxy: typeof isProxy;
42
+ isMap: typeof isMap;
43
+ isSet: typeof isSet;
44
+ isRegExp: typeof isRegExp;
45
+ isUndefined: typeof isUndefined;
46
+ isNull: typeof isNull;
47
+ isNullOrUndefined: typeof isNullOrUndefined;
48
+ };
49
+ export declare const Utils: {
50
+ sleep: typeof sleep;
51
+ getParamNames: typeof getParamNames;
52
+ generateRandomId: typeof generateRandomId;
53
+ merge: typeof merge;
54
+ camelCase: typeof camelCase;
55
+ pascalCase: typeof pascalCase;
56
+ randomUUID: typeof randomUUID;
57
+ toAsyncFunction: typeof toAsyncFunction;
58
+ };
31
59
  //# sourceMappingURL=index.d.ts.map
@@ -1,15 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.merge = exports.generateRandomId = exports.classNamed = exports.getParamNames = exports.sleep = exports.isNullOrUndefined = exports.isNull = exports.isUndefined = exports.isRegExp = exports.isSet = exports.isMap = exports.isProxy = exports.isNumber = exports.isObject = exports.isFunction = exports.isPromise = exports.isGeneratorFunction = exports.isAsyncFunction = exports.isClass = void 0;
3
+ exports.Utils = exports.Types = exports.toAsyncFunction = exports.merge = exports.generateRandomId = exports.getParamNames = exports.sleep = exports.isNullOrUndefined = exports.isNull = exports.isUndefined = exports.isRegExp = exports.isSet = exports.isMap = exports.isProxy = exports.isNumber = exports.isPlainObject = exports.isObject = exports.isFunction = exports.isPromise = exports.isGeneratorFunction = exports.isAsyncFunction = exports.isClass = exports.isString = void 0;
4
4
  const util = require("util");
5
- const camelcase = require("camelcase");
6
5
  const crypto = require("crypto");
6
+ const camelCase_1 = require("./camelCase");
7
+ const uuid_1 = require("./uuid");
7
8
  const ToString = Function.prototype.toString;
9
+ const hasOwn = Object.prototype.hasOwnProperty;
10
+ const toStr = Object.prototype.toString;
8
11
  function fnBody(fn) {
9
12
  return ToString.call(fn)
10
13
  .replace(/^[^{]*{\s*/, '')
11
14
  .replace(/\s*}[^}]*$/, '');
12
15
  }
16
+ function isString(value) {
17
+ return typeof value === 'string';
18
+ }
19
+ exports.isString = isString;
13
20
  function isClass(fn) {
14
21
  if (typeof fn !== 'function') {
15
22
  return false;
@@ -43,6 +50,27 @@ function isObject(value) {
43
50
  return value !== null && typeof value === 'object';
44
51
  }
45
52
  exports.isObject = isObject;
53
+ function isPlainObject(obj) {
54
+ if (!obj || toStr.call(obj) !== '[object Object]') {
55
+ return false;
56
+ }
57
+ const hasOwnConstructor = hasOwn.call(obj, 'constructor');
58
+ const hasIsPrototypeOf = obj.constructor &&
59
+ obj.constructor.prototype &&
60
+ hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
61
+ // Not own constructor property must be Object
62
+ if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
63
+ return false;
64
+ }
65
+ // Own properties are enumerated firstly, so to speed up,
66
+ // if last one is own, then all properties are own.
67
+ let key;
68
+ for (key in obj) {
69
+ /**/
70
+ }
71
+ return typeof key === 'undefined' || hasOwn.call(obj, key);
72
+ }
73
+ exports.isPlainObject = isPlainObject;
46
74
  function isNumber(value) {
47
75
  return typeof value === 'number';
48
76
  }
@@ -103,15 +131,7 @@ function getParamNames(func) {
103
131
  }
104
132
  exports.getParamNames = getParamNames;
105
133
  /**
106
- * 按照框架规则返回类名字
107
- * @param name 类名称
108
- */
109
- function classNamed(name) {
110
- return camelcase(name);
111
- }
112
- exports.classNamed = classNamed;
113
- /**
114
- * generate a lightweight random id, enough for ioc container
134
+ * generate a lightweight 32 bit random id, enough for ioc container
115
135
  */
116
136
  function generateRandomId() {
117
137
  // => f9b327e70bbcf42494ccb28b2d98e00e
@@ -135,4 +155,43 @@ function merge(target, src) {
135
155
  throw new Error('can not merge meta that type of ' + typeof target);
136
156
  }
137
157
  exports.merge = merge;
158
+ function toAsyncFunction(method) {
159
+ if (isAsyncFunction(method)) {
160
+ return method;
161
+ }
162
+ else {
163
+ return async function (...args) {
164
+ return Promise.resolve(method.call(this, ...args));
165
+ };
166
+ }
167
+ }
168
+ exports.toAsyncFunction = toAsyncFunction;
169
+ exports.Types = {
170
+ isClass,
171
+ isAsyncFunction,
172
+ isGeneratorFunction,
173
+ isString,
174
+ isPromise,
175
+ isFunction,
176
+ isObject,
177
+ isPlainObject,
178
+ isNumber,
179
+ isProxy,
180
+ isMap,
181
+ isSet,
182
+ isRegExp,
183
+ isUndefined,
184
+ isNull,
185
+ isNullOrUndefined,
186
+ };
187
+ exports.Utils = {
188
+ sleep,
189
+ getParamNames,
190
+ generateRandomId,
191
+ merge,
192
+ camelCase: camelCase_1.camelCase,
193
+ pascalCase: camelCase_1.pascalCase,
194
+ randomUUID: uuid_1.randomUUID,
195
+ toAsyncFunction,
196
+ };
138
197
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * a easy uuid v4 generator
3
+ */
4
+ export declare function randomUUID(): string;
5
+ //# sourceMappingURL=uuid.d.ts.map
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randomUUID = void 0;
4
+ const crypto = require("crypto");
5
+ /**
6
+ * code fork from https://github.com/uuidjs/uuid/blob/main/src/stringify.js
7
+ */
8
+ const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
9
+ let poolPtr = rnds8Pool.length;
10
+ function rng() {
11
+ if (poolPtr > rnds8Pool.length - 16) {
12
+ crypto.randomFillSync(rnds8Pool);
13
+ poolPtr = 0;
14
+ }
15
+ return rnds8Pool.slice(poolPtr, (poolPtr += 16));
16
+ }
17
+ /**
18
+ * Convert array of 16 byte values to UUID string format of the form:
19
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
20
+ */
21
+ const byteToHex = [];
22
+ for (let i = 0; i < 256; ++i) {
23
+ byteToHex.push((i + 0x100).toString(16).substr(1));
24
+ }
25
+ function unsafeStringify(arr, offset = 0) {
26
+ // Note: Be careful editing this code! It's been tuned for performance
27
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
28
+ return (byteToHex[arr[offset + 0]] +
29
+ byteToHex[arr[offset + 1]] +
30
+ byteToHex[arr[offset + 2]] +
31
+ byteToHex[arr[offset + 3]] +
32
+ '-' +
33
+ byteToHex[arr[offset + 4]] +
34
+ byteToHex[arr[offset + 5]] +
35
+ '-' +
36
+ byteToHex[arr[offset + 6]] +
37
+ byteToHex[arr[offset + 7]] +
38
+ '-' +
39
+ byteToHex[arr[offset + 8]] +
40
+ byteToHex[arr[offset + 9]] +
41
+ '-' +
42
+ byteToHex[arr[offset + 10]] +
43
+ byteToHex[arr[offset + 11]] +
44
+ byteToHex[arr[offset + 12]] +
45
+ byteToHex[arr[offset + 13]] +
46
+ byteToHex[arr[offset + 14]] +
47
+ byteToHex[arr[offset + 15]]).toLowerCase();
48
+ }
49
+ /**
50
+ * a easy uuid v4 generator
51
+ */
52
+ function randomUUID() {
53
+ // node > v14.17
54
+ if (crypto['randomUUID']) {
55
+ return crypto['randomUUID']();
56
+ }
57
+ const rnds = rng();
58
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
59
+ rnds[6] = (rnds[6] & 0x0f) | 0x40;
60
+ rnds[8] = (rnds[8] & 0x3f) | 0x80;
61
+ return unsafeStringify(rnds);
62
+ }
63
+ exports.randomUUID = randomUUID;
64
+ //# sourceMappingURL=uuid.js.map