@midwayjs/decorator 3.0.0 → 3.0.6

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,5 @@
1
1
  import 'reflect-metadata';
2
- import { ObjectDefinitionOptions, ObjectIdentifier, TagPropsMetadata, IModuleStore, GroupModeType } from './interface';
2
+ import { GroupModeType, IModuleStore, ObjectDefinitionOptions, ObjectIdentifier, TagPropsMetadata } from './interface';
3
3
  export declare const PRELOAD_MODULE_KEY = "INJECTION_PRELOAD_MODULE_KEY";
4
4
  export declare const INJECT_CLASS_KEY_PREFIX = "INJECTION_CLASS_META_DATA";
5
5
  export declare class DecoratorManager extends Map implements IModuleStore {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCustomParamDecorator = exports.createCustomMethodDecorator = exports.createCustomPropertyDecorator = exports.getMethodReturnTypes = exports.getPropertyType = exports.getMethodParamTypes = exports.BaseType = exports.isProvide = exports.getProviderUUId = exports.getProviderName = exports.getProviderId = exports.saveProviderId = exports.getObjectDefinition = exports.saveObjectDefinition = exports.getPropertyInject = exports.savePropertyInject = exports.clearAllModule = exports.resetModule = exports.listModule = exports.clearBindContainer = exports.bindContainer = exports.saveModule = exports.listPreloadModule = exports.savePreloadModule = exports.getPropertyMetadata = exports.attachPropertyMetadata = exports.savePropertyMetadata = exports.listPropertyDataFromClass = exports.getPropertyDataFromClass = exports.attachPropertyDataToClass = exports.savePropertyDataToClass = exports.getClassMetadata = exports.getClassExtendedMetadata = exports.attachClassMetadata = exports.saveClassMetadata = exports.DecoratorManager = exports.INJECT_CLASS_KEY_PREFIX = exports.PRELOAD_MODULE_KEY = void 0;
4
4
  require("reflect-metadata");
5
+ const interface_1 = require("./interface");
5
6
  const constant_1 = require("./constant");
6
7
  const util_1 = require("./util");
7
8
  const camelCase_1 = require("./util/camelCase");
@@ -494,6 +495,7 @@ function transformTypeFromTSDesign(designFn) {
494
495
  function savePropertyInject(opts) {
495
496
  // 1、use identifier by user
496
497
  let identifier = opts.identifier;
498
+ let injectMode = interface_1.InjectModeEnum.Identifier;
497
499
  // 2、use identifier by class uuid
498
500
  if (!identifier) {
499
501
  const type = getPropertyType(opts.target, opts.targetKey);
@@ -501,16 +503,19 @@ function savePropertyInject(opts) {
501
503
  (0, util_1.isClass)(type.originDesign) &&
502
504
  isProvide(type.originDesign)) {
503
505
  identifier = getProviderUUId(type.originDesign);
506
+ injectMode = interface_1.InjectModeEnum.Class;
504
507
  }
505
508
  if (!identifier) {
506
509
  // 3、use identifier by property name
507
510
  identifier = opts.targetKey;
511
+ injectMode = interface_1.InjectModeEnum.PropertyName;
508
512
  }
509
513
  }
510
514
  attachClassMetadata(constant_1.INJECT_TAG, {
511
515
  targetKey: opts.targetKey,
512
516
  value: identifier,
513
- args: opts.args, // 注入的其他参数
517
+ args: opts.args,
518
+ injectMode,
514
519
  }, opts.target, opts.targetKey);
515
520
  }
516
521
  exports.savePropertyInject = savePropertyInject;
@@ -6,6 +6,11 @@ export declare enum ScopeEnum {
6
6
  Request = "Request",
7
7
  Prototype = "Prototype"
8
8
  }
9
+ export declare enum InjectModeEnum {
10
+ Identifier = "Identifier",
11
+ Class = "Class",
12
+ PropertyName = "PropertyName"
13
+ }
9
14
  /**
10
15
  * 内部管理的属性、json、ref等解析实例存储
11
16
  */
package/dist/interface.js CHANGED
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServerlessTriggerType = exports.MidwayFrameworkType = exports.FrameworkType = exports.MSListenerType = exports.MSProviderType = exports.ScopeEnum = void 0;
3
+ exports.ServerlessTriggerType = exports.MidwayFrameworkType = exports.FrameworkType = exports.MSListenerType = exports.MSProviderType = exports.InjectModeEnum = exports.ScopeEnum = void 0;
4
4
  var ScopeEnum;
5
5
  (function (ScopeEnum) {
6
6
  ScopeEnum["Singleton"] = "Singleton";
7
7
  ScopeEnum["Request"] = "Request";
8
8
  ScopeEnum["Prototype"] = "Prototype";
9
9
  })(ScopeEnum = exports.ScopeEnum || (exports.ScopeEnum = {}));
10
+ var InjectModeEnum;
11
+ (function (InjectModeEnum) {
12
+ InjectModeEnum["Identifier"] = "Identifier";
13
+ InjectModeEnum["Class"] = "Class";
14
+ InjectModeEnum["PropertyName"] = "PropertyName";
15
+ })(InjectModeEnum = exports.InjectModeEnum || (exports.InjectModeEnum = {}));
10
16
  var MSProviderType;
11
17
  (function (MSProviderType) {
12
18
  MSProviderType["DUBBO"] = "dubbo";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * code fork from https://github.com/WebReflection/flatted/blob/main/cjs/index.js
3
+ */
4
+ /*! (c) 2020 Andrea Giammarchi */
5
+ export declare function safeParse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
6
+ export declare function safeStringify(value: any, replacer?: any, space?: string | number): string;
7
+ //# sourceMappingURL=flatted.d.ts.map
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /**
3
+ * code fork from https://github.com/WebReflection/flatted/blob/main/cjs/index.js
4
+ */
5
+ /*! (c) 2020 Andrea Giammarchi */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.safeStringify = exports.safeParse = void 0;
8
+ const { parse: $parse, stringify: $stringify } = JSON;
9
+ const { keys } = Object;
10
+ const Primitive = String; // it could be Number
11
+ const primitive = 'string'; // it could be 'number'
12
+ const ignore = {};
13
+ const object = 'object';
14
+ const noop = (_, value) => value;
15
+ const primitives = value => value instanceof Primitive ? Primitive(value) : value;
16
+ const Primitives = (_, value) => typeof value === primitive ? new Primitive(value) : value;
17
+ const revive = (input, parsed, output, $) => {
18
+ const lazy = [];
19
+ for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
20
+ const k = ke[y];
21
+ const value = output[k];
22
+ if (value instanceof Primitive) {
23
+ const tmp = input[value];
24
+ if (typeof tmp === object && !parsed.has(tmp)) {
25
+ parsed.add(tmp);
26
+ output[k] = ignore;
27
+ lazy.push({ k, a: [input, parsed, tmp, $] });
28
+ }
29
+ else
30
+ output[k] = $.call(output, k, tmp);
31
+ }
32
+ else if (output[k] !== ignore)
33
+ output[k] = $.call(output, k, value);
34
+ }
35
+ for (let { length } = lazy, i = 0; i < length; i++) {
36
+ const { k, a } = lazy[i];
37
+ // eslint-disable-next-line prefer-spread
38
+ output[k] = $.call(output, k, revive.apply(null, a));
39
+ }
40
+ return output;
41
+ };
42
+ const set = (known, input, value) => {
43
+ const index = Primitive(input.push(value) - 1);
44
+ known.set(value, index);
45
+ return index;
46
+ };
47
+ function safeParse(text, reviver) {
48
+ const input = $parse(text, Primitives).map(primitives);
49
+ const value = input[0];
50
+ const $ = reviver || noop;
51
+ const tmp = typeof value === object && value
52
+ ? revive(input, new Set(), value, $)
53
+ : value;
54
+ return $.call({ '': tmp }, '', tmp);
55
+ }
56
+ exports.safeParse = safeParse;
57
+ function safeStringify(value, replacer, space) {
58
+ const $ = replacer && typeof replacer === object
59
+ ? (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0)
60
+ : replacer || noop;
61
+ const known = new Map();
62
+ const input = [];
63
+ const output = [];
64
+ let i = +set(known, input, $.call({ '': value }, '', value));
65
+ let firstRun = !i;
66
+ while (i < input.length) {
67
+ firstRun = true;
68
+ output[i] = $stringify(input[i++], replace, space);
69
+ }
70
+ return '[' + output.join(',') + ']';
71
+ function replace(key, value) {
72
+ if (firstRun) {
73
+ firstRun = !firstRun;
74
+ return value;
75
+ }
76
+ const after = $.call(this, key, value);
77
+ switch (typeof after) {
78
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
79
+ // @ts-ignore
80
+ case object:
81
+ if (after === null)
82
+ return after;
83
+ // eslint-disable-next-line no-fallthrough
84
+ case primitive:
85
+ return known.get(after) || set(known, input, after);
86
+ }
87
+ return after;
88
+ }
89
+ }
90
+ exports.safeStringify = safeStringify;
91
+ //# sourceMappingURL=flatted.js.map
@@ -1,5 +1,6 @@
1
1
  import { camelCase, pascalCase } from './camelCase';
2
2
  import { randomUUID } from './uuid';
3
+ import { safeStringify, safeParse } from './flatted';
3
4
  export declare function isString(value: any): boolean;
4
5
  export declare function isClass(fn: any): boolean;
5
6
  export declare function isAsyncFunction(value: any): boolean;
@@ -55,5 +56,7 @@ export declare const Utils: {
55
56
  pascalCase: typeof pascalCase;
56
57
  randomUUID: typeof randomUUID;
57
58
  toAsyncFunction: typeof toAsyncFunction;
59
+ safeStringify: typeof safeStringify;
60
+ safeParse: typeof safeParse;
58
61
  };
59
62
  //# sourceMappingURL=index.d.ts.map
@@ -5,6 +5,7 @@ const util = require("util");
5
5
  const crypto = require("crypto");
6
6
  const camelCase_1 = require("./camelCase");
7
7
  const uuid_1 = require("./uuid");
8
+ const flatted_1 = require("./flatted");
8
9
  const ToString = Function.prototype.toString;
9
10
  const hasOwn = Object.prototype.hasOwnProperty;
10
11
  const toStr = Object.prototype.toString;
@@ -193,5 +194,7 @@ exports.Utils = {
193
194
  pascalCase: camelCase_1.pascalCase,
194
195
  randomUUID: uuid_1.randomUUID,
195
196
  toAsyncFunction,
197
+ safeStringify: flatted_1.safeStringify,
198
+ safeParse: flatted_1.safeParse,
196
199
  };
197
200
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/decorator",
3
- "version": "3.0.0",
3
+ "version": "3.0.6",
4
4
  "description": "definition decorator for midway project",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "55c26029bccf7bbb739fa1597e8f418dafa2caa0"
39
+ "gitHead": "afaa5b59a2be85e915233a9268c0e05965dd5c61"
40
40
  }