@prostojs/mate 0.1.9 → 0.1.11

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.
@@ -11,15 +11,6 @@ function isConstructor(v) {
11
11
  return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
12
12
  }
13
13
 
14
- const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
15
-
16
- function warn(text) {
17
- console.log('' + banner() + text + '');
18
- }
19
- function logError(error) {
20
- console.error('' + '' + banner() + error + '');
21
- }
22
-
23
14
  const classMetadata = {};
24
15
  const paramMetadata = {};
25
16
  const root = typeof global === 'object' ? global : typeof self === 'object' ? self : {};
@@ -56,19 +47,20 @@ else {
56
47
  'metadata',
57
48
  ];
58
49
  const target = root.Reflect;
59
- let isOriginalReflectMetadata = true;
60
50
  for (const func of funcs) {
61
51
  if (typeof target[func] !== 'function') {
62
52
  Object.defineProperty(target, func, { configurable: true, writable: true, value: _reflect[func] });
63
- isOriginalReflectMetadata = false;
64
53
  }
65
54
  }
66
- if (!isOriginalReflectMetadata) {
67
- warn('A limited \'reflect-metadata\' implementation is used. In case of any issues include original \'reflect-metadata\' package and require it before any @prostojs/mate import.');
68
- }
69
55
  }
70
56
  const Reflect$1 = _reflect;
71
57
 
58
+ const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
59
+
60
+ function logError(error) {
61
+ console.error('' + '' + banner() + error + '');
62
+ }
63
+
72
64
  function panic(error) {
73
65
  logError(error);
74
66
  return new Error(error);
@@ -96,7 +88,7 @@ class Mate {
96
88
  const cb = typeof key === 'function' ? key : undefined;
97
89
  let data = meta;
98
90
  if (!data.params) {
99
- data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', args.target, args.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
91
+ data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', newArgs.target, newArgs.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
100
92
  }
101
93
  if (typeof index === 'number') {
102
94
  data.params = data.params || [];
@@ -7,15 +7,6 @@ function isConstructor(v) {
7
7
  return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
8
8
  }
9
9
 
10
- const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
11
-
12
- function warn(text) {
13
- console.log('' + banner() + text + '');
14
- }
15
- function logError(error) {
16
- console.error('' + '' + banner() + error + '');
17
- }
18
-
19
10
  const classMetadata = {};
20
11
  const paramMetadata = {};
21
12
  const root = typeof global === 'object' ? global : typeof self === 'object' ? self : {};
@@ -52,19 +43,20 @@ else {
52
43
  'metadata',
53
44
  ];
54
45
  const target = root.Reflect;
55
- let isOriginalReflectMetadata = true;
56
46
  for (const func of funcs) {
57
47
  if (typeof target[func] !== 'function') {
58
48
  Object.defineProperty(target, func, { configurable: true, writable: true, value: _reflect[func] });
59
- isOriginalReflectMetadata = false;
60
49
  }
61
50
  }
62
- if (!isOriginalReflectMetadata) {
63
- warn('A limited \'reflect-metadata\' implementation is used. In case of any issues include original \'reflect-metadata\' package and require it before any @prostojs/mate import.');
64
- }
65
51
  }
66
52
  const Reflect$1 = _reflect;
67
53
 
54
+ const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
55
+
56
+ function logError(error) {
57
+ console.error('' + '' + banner() + error + '');
58
+ }
59
+
68
60
  function panic(error) {
69
61
  logError(error);
70
62
  return new Error(error);
@@ -92,7 +84,7 @@ class Mate {
92
84
  const cb = typeof key === 'function' ? key : undefined;
93
85
  let data = meta;
94
86
  if (!data.params) {
95
- data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', args.target, args.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
87
+ data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', newArgs.target, newArgs.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
96
88
  }
97
89
  if (typeof index === 'number') {
98
90
  data.params = data.params || [];
@@ -1 +1 @@
1
- {"version":3,"file":"reflect.d.ts","sourceRoot":"","sources":["../../src/reflect.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAuD5C,eAAO,MAAM,OAAO;wBAnCI,MAAM,GAAG,MAAM,UAAU,OAAO,GAAG,SAAS,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO;wBAG9E,MAAM,GAAG,MAAM,QAAQ,OAAO,UAAU,OAAO,GAAG,SAAS,SAAS,MAAM,GAAG,MAAM,GAAG,IAAI;kBAIhG,MAAM,GAAG,MAAM,QAAQ,OAAO,GAAG,cAAc,GAAG,eAAe,GAAG,kBAAkB;CA4BzE,CAAA"}
1
+ {"version":3,"file":"reflect.d.ts","sourceRoot":"","sources":["../../src/reflect.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAsD5C,eAAO,MAAM,OAAO;wBAnCI,MAAM,GAAG,MAAM,UAAU,OAAO,GAAG,SAAS,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO;wBAG9E,MAAM,GAAG,MAAM,QAAQ,OAAO,UAAU,OAAO,GAAG,SAAS,SAAS,MAAM,GAAG,MAAM,GAAG,IAAI;kBAIhG,MAAM,GAAG,MAAM,QAAQ,OAAO,GAAG,cAAc,GAAG,eAAe,GAAG,kBAAkB;CA4BzE,CAAA"}
@@ -11,7 +11,7 @@ export declare class MateTestClass {
11
11
  }
12
12
  export declare class MateTestClass2 {
13
13
  constructor(a: string);
14
- test(): void;
14
+ test(arg1: number, arg2: boolean): void;
15
15
  toOverwriteMeta(): void;
16
16
  }
17
17
  export declare class MateTestClass3 extends MateTestClass2 {
@@ -1 +1 @@
1
- {"version":3,"file":"mate.artifacts.d.ts","sourceRoot":"","sources":["../../../src/tests/mate.artifacts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,IAAI,CAAA;AAE1C,eAAO,MAAM,IAAI;;;wDASf,CAAA;AAMF,qBAGa,aAAa;gBAKd,EAAE,EAAE,MAAM;IAQlB,IAAI,CAII,EAAE,EAAE,MAAM,GAAG,MAAM;IAgB3B,KAAK,CAMG,EAAE,EAAE,MAAM;IAWlB,KAAK,EAAE,MAAM,CAAK;CACrB;AAED,qBACa,cAAc;gBACX,CAAC,EAAE,MAAM;IAOrB,IAAI;IAMJ,eAAe;CAGlB;AAED,qBACa,cAAe,SAAQ,cAAc;;IAM9C,KAAK;IAML,eAAe;CAGlB;AAED,qBACa,cAAe,SAAQ,cAAc;;IAM9C,KAAK;IAKL,eAAe;CAGlB"}
1
+ {"version":3,"file":"mate.artifacts.d.ts","sourceRoot":"","sources":["../../../src/tests/mate.artifacts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,IAAI,CAAA;AAE1C,eAAO,MAAM,IAAI;;;wDASf,CAAA;AAMF,qBAGa,aAAa;gBAKd,EAAE,EAAE,MAAM;IAQlB,IAAI,CAII,EAAE,EAAE,MAAM,GAAG,MAAM;IAgB3B,KAAK,CAMG,EAAE,EAAE,MAAM;IAWlB,KAAK,EAAE,MAAM,CAAK;CACrB;AAED,qBACa,cAAc;gBACX,CAAC,EAAE,MAAM;IAOrB,IAAI,CAGD,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;IAM9B,eAAe;CAGlB;AAED,qBACa,cAAe,SAAQ,cAAc;;IAM9C,KAAK;IAML,eAAe;CAGlB;AAED,qBACa,cAAe,SAAQ,cAAc;;IAM9C,KAAK;IAKL,eAAe;CAGlB"}
package/package.json CHANGED
@@ -1,11 +1,9 @@
1
1
  {
2
2
  "name": "@prostojs/mate",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "MATE is TS Metadata Organizer",
5
5
  "main": "index.js",
6
6
  "module": "dist/mate.esm-bundler.js",
7
- "unpkg": "dist/mate.global.prod.js",
8
- "jsdelivr": "dist/mate.global.prod.js",
9
7
  "types": "dist/mate.d.ts",
10
8
  "files": [
11
9
  "index.js",
@@ -34,9 +32,7 @@
34
32
  "name": "ProstoMate",
35
33
  "formats": [
36
34
  "esm-bundler",
37
- "esm-browser",
38
- "cjs",
39
- "global"
35
+ "cjs"
40
36
  ]
41
37
  },
42
38
  "dependencies": {},
@@ -1 +0,0 @@
1
- function e(e){return t(e)?e:e.constructor?e.constructor:Object.getPrototypeOf(e).constructor}function t(e){return"function"==typeof e&&Object.getOwnPropertyNames(e).includes("prototype")&&!Object.getOwnPropertyNames(e).includes("caller")&&!!e.name}const o=()=>`[prostojs/mate][${(new Date).toISOString().replace("T"," ").replace(/\.\d{3}z$/i,"")}] `;const r={},a={},n="object"==typeof global?global:"object"==typeof self?self:{};function i(t,o){const n=void 0!==o,i=n?a:r,s=Symbol.for(e(t));let p=i[s]=i[s]||{};return n&&(p=p[o]=p[o]||{}),p}const s={getOwnMetadata:(e,t,o)=>i(t,o)[e],defineMetadata(e,t,o,r){i(o,r)[e]=t},metadata:(e,t)=>(o,r)=>{c.defineMetadata(e,t,o,r)}};if(n.Reflect){const e=["getOwnMetadata","defineMetadata","metadata"],t=n.Reflect;let r=!0;for(const o of e)"function"!=typeof t[o]&&(Object.defineProperty(t,o,{configurable:!0,writable:!0,value:s[o]}),r=!1);r||(p="A limited 'reflect-metadata' implementation is used. In case of any issues include original 'reflect-metadata' package and require it before any @prostojs/mate import.",console.log(""+o()+p+""))}else n.Reflect=s;var p;const c=s;function l(e){return function(e){console.error(""+o()+e+"")}(e),new Error(e)}const f=(null===global||void 0===global?void 0:global.Reflect)||(null===self||void 0===self?void 0:self.Reflect)||c;class d{constructor(e,t={}){this.workspace=e,this.options=t}set(e,t,o,r){var a;const n="CLASS"===e.level?{target:e.target}:"PROPERTY"===e.level?{target:e.target,propKey:e.propKey}:e;let i=f.getOwnMetadata(this.workspace,n.target,n.propKey)||{};n.propKey&&this.options.readReturnType&&!i.returnType&&(i.returnType=f.getOwnMetadata("design:returntype",n.target,n.propKey)),n.propKey&&this.options.readType&&!i.type&&(i.type=f.getOwnMetadata("design:type",n.target,n.propKey));const{index:s}=n,p="function"==typeof t?t:void 0;let c=i;if(c.params||(c.params=null===(a=f.getOwnMetadata("design:paramtypes",e.target,e.propKey))||void 0===a?void 0:a.map((e=>({type:e})))),"number"==typeof s&&(c.params=c.params||[],c.params[s]=c.params[s]||{type:void 0},p?c.params[s]=p(c.params[s],e.propKey,"number"==typeof e.index?e.index:void 0):c=c.params[s]),"function"!=typeof t)if(r){const e=c[t]||[];Array.isArray(e)||l("Mate.add (isArray=true) called for non-array metadata"),e.unshift(o),c[t]=e}else c[t]=o;else p&&"number"!=typeof s&&(i=p(c,e.propKey,"number"==typeof e.index?e.index:void 0));f.defineMetadata(this.workspace,i,n.target,n.propKey)}read(o,r,a){const n=t(o)?o:e(o);let i=f.getOwnMetadata(this.workspace,"string"==typeof r?n.prototype:n,r);if(this.options.inherit){const e="function"==typeof this.options.inherit?this.options.inherit:void 0;let t=this.options.inherit;if(e)if("string"==typeof r){t=e(f.getOwnMetadata(this.workspace,n),r,i)}else t=e(i);if(t){const e=Object.getPrototypeOf(n);if("function"==typeof e&&e!==y&&e!==n){i={...this.read(e,r),...i,params:null==i?void 0:i.params}}}}return i}apply(...e){return(t,o,r)=>{for(const a of e)a(t,o,r)}}decorate(e,t,o,r){return(a,n,i)=>{this.set({target:a,propKey:n,descriptor:"number"==typeof i?void 0:i,index:"number"==typeof i?i:void 0,level:r},e,t,o)}}decorateClass(e,t,o){return this.decorate(e,t,o,"CLASS")}}const y=Object.getPrototypeOf(Function);export{d as Mate,e as getConstructor,t as isConstructor};
@@ -1 +0,0 @@
1
- var ProstoMate=function(e){"use strict";function t(e){return o(e)?e:e.constructor?e.constructor:Object.getPrototypeOf(e).constructor}function o(e){return"function"==typeof e&&Object.getOwnPropertyNames(e).includes("prototype")&&!Object.getOwnPropertyNames(e).includes("caller")&&!!e.name}const r=()=>`[prostojs/mate][${(new Date).toISOString().replace("T"," ").replace(/\.\d{3}z$/i,"")}] `;const a={},n={},i="object"==typeof global?global:"object"==typeof self?self:{};function s(e,o){const r=void 0!==o,i=r?n:a,s=Symbol.for(t(e));let p=i[s]=i[s]||{};return r&&(p=p[o]=p[o]||{}),p}const p={getOwnMetadata:(e,t,o)=>s(t,o)[e],defineMetadata(e,t,o,r){s(o,r)[e]=t},metadata:(e,t)=>(o,r)=>{l.defineMetadata(e,t,o,r)}};if(i.Reflect){const e=["getOwnMetadata","defineMetadata","metadata"],t=i.Reflect;let o=!0;for(const r of e)"function"!=typeof t[r]&&(Object.defineProperty(t,r,{configurable:!0,writable:!0,value:p[r]}),o=!1);o||(c="A limited 'reflect-metadata' implementation is used. In case of any issues include original 'reflect-metadata' package and require it before any @prostojs/mate import.",console.log(""+r()+c+""))}else i.Reflect=p;var c;const l=p;function f(e){return function(e){console.error(""+r()+e+"")}(e),new Error(e)}const d=(null===global||void 0===global?void 0:global.Reflect)||(null===self||void 0===self?void 0:self.Reflect)||l;const y=Object.getPrototypeOf(Function);return e.Mate=class{constructor(e,t={}){this.workspace=e,this.options=t}set(e,t,o,r){var a;const n="CLASS"===e.level?{target:e.target}:"PROPERTY"===e.level?{target:e.target,propKey:e.propKey}:e;let i=d.getOwnMetadata(this.workspace,n.target,n.propKey)||{};n.propKey&&this.options.readReturnType&&!i.returnType&&(i.returnType=d.getOwnMetadata("design:returntype",n.target,n.propKey)),n.propKey&&this.options.readType&&!i.type&&(i.type=d.getOwnMetadata("design:type",n.target,n.propKey));const{index:s}=n,p="function"==typeof t?t:void 0;let c=i;if(c.params||(c.params=null===(a=d.getOwnMetadata("design:paramtypes",e.target,e.propKey))||void 0===a?void 0:a.map((e=>({type:e})))),"number"==typeof s&&(c.params=c.params||[],c.params[s]=c.params[s]||{type:void 0},p?c.params[s]=p(c.params[s],e.propKey,"number"==typeof e.index?e.index:void 0):c=c.params[s]),"function"!=typeof t)if(r){const e=c[t]||[];Array.isArray(e)||f("Mate.add (isArray=true) called for non-array metadata"),e.unshift(o),c[t]=e}else c[t]=o;else p&&"number"!=typeof s&&(i=p(c,e.propKey,"number"==typeof e.index?e.index:void 0));d.defineMetadata(this.workspace,i,n.target,n.propKey)}read(e,r,a){const n=o(e)?e:t(e);let i=d.getOwnMetadata(this.workspace,"string"==typeof r?n.prototype:n,r);if(this.options.inherit){const e="function"==typeof this.options.inherit?this.options.inherit:void 0;let t=this.options.inherit;if(e)if("string"==typeof r){t=e(d.getOwnMetadata(this.workspace,n),r,i)}else t=e(i);if(t){const e=Object.getPrototypeOf(n);if("function"==typeof e&&e!==y&&e!==n){i={...this.read(e,r),...i,params:null==i?void 0:i.params}}}}return i}apply(...e){return(t,o,r)=>{for(const a of e)a(t,o,r)}}decorate(e,t,o,r){return(a,n,i)=>{this.set({target:a,propKey:n,descriptor:"number"==typeof i?void 0:i,index:"number"==typeof i?i:void 0,level:r},e,t,o)}}decorateClass(e,t,o){return this.decorate(e,t,o,"CLASS")}},e.getConstructor=t,e.isConstructor=o,Object.defineProperty(e,"__esModule",{value:!0}),e}({});