@prostojs/mate 0.0.2 → 0.1.1
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.
- package/README.md +53 -2
- package/dist/mate.cjs.prod.js +46 -13
- package/dist/mate.d.ts +14 -5
- package/dist/mate.esm-browser.prod.js +1 -1
- package/dist/mate.esm-bundler.js +46 -13
- package/dist/mate.global.prod.js +1 -1
- package/dist/src/mate.d.ts +12 -4
- package/dist/src/mate.d.ts.map +1 -1
- package/dist/src/reflect.d.ts +7 -0
- package/dist/src/reflect.d.ts.map +1 -0
- package/dist/src/tests/mate.artifacts.d.ts +19 -3
- package/dist/src/tests/mate.artifacts.d.ts.map +1 -1
- package/dist/src/tests/reflect.artifacts.d.ts +5 -0
- package/dist/src/tests/reflect.artifacts.d.ts.map +1 -0
- package/dist/src/tests/reflect.spec.d.ts +2 -0
- package/dist/src/tests/reflect.spec.d.ts.map +1 -0
- package/dist/src/utils/helpers.d.ts +3 -3
- package/dist/src/utils/helpers.d.ts.map +1 -1
- package/dist/src/utils/log.d.ts +1 -0
- package/dist/src/utils/log.d.ts.map +1 -1
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -58,6 +58,8 @@ console.log(mate.read(MyClass, 'methodName'))
|
|
|
58
58
|
|
|
59
59
|
## Constructor Params Decorators
|
|
60
60
|
|
|
61
|
+
`params[].type` are filled from `design:paramtypes` automatically
|
|
62
|
+
|
|
61
63
|
```ts
|
|
62
64
|
import { Mate } from '@prostojs/mate'
|
|
63
65
|
const mate = new Mate('my-metadata-key')
|
|
@@ -80,6 +82,8 @@ console.log(mate.read(MyClass))
|
|
|
80
82
|
|
|
81
83
|
## Method Params Decorators
|
|
82
84
|
|
|
85
|
+
`params[].type` are filled from `design:paramtypes` automatically
|
|
86
|
+
|
|
83
87
|
```ts
|
|
84
88
|
import { Mate } from '@prostojs/mate'
|
|
85
89
|
const mate = new Mate('my-metadata-key')
|
|
@@ -112,7 +116,11 @@ interface MyMeta extends TProstoMetadata {
|
|
|
112
116
|
n: number
|
|
113
117
|
simple: boolean
|
|
114
118
|
}
|
|
115
|
-
const mate = new Mate<MyMeta>('my-metadata-key'
|
|
119
|
+
const mate = new Mate<MyMeta>('my-metadata-key', {
|
|
120
|
+
readReturnType: true, // to copy `design:returntype` -> `returnType` of metadata object
|
|
121
|
+
readType: true, // to copy `design:type` -> `type` of metadata object
|
|
122
|
+
inherit: false, // allow or disable metadata inheritance
|
|
123
|
+
})
|
|
116
124
|
|
|
117
125
|
// Example of simple decorator
|
|
118
126
|
const SimpleDecorator = mate.decorate('simple', true)
|
|
@@ -196,4 +204,47 @@ interface TMyMeta extends TProstoMetadata<TMyParamsMeta> {
|
|
|
196
204
|
|
|
197
205
|
// pass TMyMeta to Mate constructor to define types for mate instance
|
|
198
206
|
const mate = new Mate<TMyMeta>('my-metadata-key')
|
|
199
|
-
```
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Metadata Inheritance
|
|
210
|
+
|
|
211
|
+
It's possible to enable metadata inheritance and set some rules on whether it should be inherited from parent classes or not
|
|
212
|
+
|
|
213
|
+
### Metadata Inheritance ON
|
|
214
|
+
|
|
215
|
+
Simply use `true` on `inherit` key to enable metadata inheritance
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const mate = new Mate<MyMeta>('my-metadata-key', {
|
|
219
|
+
inherit: true, // this will enable metadata inheritance for all the classes
|
|
220
|
+
})
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Conditional Metadata Inheritance
|
|
224
|
+
|
|
225
|
+
This example illustrates how to set a callback with logic to decide whether to inherit or not
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
const mate = new Mate<MyMeta>('my-metadata-key', {
|
|
229
|
+
inherit(classMeta, prop, methodMeta) {
|
|
230
|
+
if (prop) {
|
|
231
|
+
// if it is a method metadata
|
|
232
|
+
// we require a key `inherit` to be true for inheritance
|
|
233
|
+
return !!methodMeta?.inherit || !!(classMeta?.inherit && !methodMeta)
|
|
234
|
+
}
|
|
235
|
+
// otherwise (in case of class metadata) we require a key `inherit`
|
|
236
|
+
// to be true for inheritance on class metadata
|
|
237
|
+
return !!classMeta?.inherit
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Use or **reflect-metadata**
|
|
243
|
+
|
|
244
|
+
It is recomended to include `reflect-metadata` dependency to rely on the original implementation. Although it's still possible to use `@prostojs/mate` with no dependency on `reflect-metadata` because it already includes its own limited implementation of reflect-metadata which ships only the features used by `@prostojs/mate` such as:
|
|
245
|
+
|
|
246
|
+
- `getOwnMetadata(key, target, prop?)`
|
|
247
|
+
|
|
248
|
+
- `defineMetadata(key, data, target, prop?)`
|
|
249
|
+
|
|
250
|
+
- `metadata(key, data)`
|
package/dist/mate.cjs.prod.js
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
function getConstructor(instance) {
|
|
6
|
+
return isConstructor(instance) ?
|
|
7
|
+
instance : instance.constructor ?
|
|
8
|
+
instance.constructor : Object.getPrototypeOf(instance).constructor;
|
|
9
|
+
}
|
|
10
|
+
function isConstructor(v) {
|
|
11
|
+
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
6
15
|
|
|
7
16
|
function logError(error) {
|
|
@@ -13,26 +22,25 @@ function panic(error) {
|
|
|
13
22
|
return new Error(error);
|
|
14
23
|
}
|
|
15
24
|
|
|
16
|
-
function getConstructor(instance) {
|
|
17
|
-
return Object.getPrototypeOf(instance).constructor;
|
|
18
|
-
}
|
|
19
|
-
function isConstructor(v) {
|
|
20
|
-
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
require('reflect-metadata');
|
|
24
25
|
class Mate {
|
|
25
|
-
constructor(workspace) {
|
|
26
|
+
constructor(workspace, options = {}) {
|
|
26
27
|
this.workspace = workspace;
|
|
28
|
+
this.options = options;
|
|
27
29
|
}
|
|
28
30
|
set(args, key, value, isArray) {
|
|
29
31
|
var _a;
|
|
30
|
-
let meta = Reflect.
|
|
32
|
+
let meta = Reflect.getOwnMetadata(this.workspace, args.target, args.propKey) || {};
|
|
33
|
+
if (args.propKey && this.options.readReturnType && !meta.returnType) {
|
|
34
|
+
meta.returnType = Reflect.getOwnMetadata('design:returntype', args.target, args.propKey);
|
|
35
|
+
}
|
|
36
|
+
if (args.propKey && this.options.readType && !meta.type) {
|
|
37
|
+
meta.type = Reflect.getOwnMetadata('design:type', args.target, args.propKey);
|
|
38
|
+
}
|
|
31
39
|
const { index } = args;
|
|
32
40
|
const cb = typeof key === 'function' ? key : undefined;
|
|
33
41
|
let data = meta;
|
|
34
42
|
if (!data.params) {
|
|
35
|
-
data.params = (_a = Reflect.
|
|
43
|
+
data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', args.target, args.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
|
|
36
44
|
}
|
|
37
45
|
if (typeof index === 'number') {
|
|
38
46
|
data.params = data.params || [];
|
|
@@ -65,7 +73,31 @@ class Mate {
|
|
|
65
73
|
Reflect.defineMetadata(this.workspace, meta, args.target, args.propKey);
|
|
66
74
|
}
|
|
67
75
|
read(target, propKey) {
|
|
68
|
-
|
|
76
|
+
const isConstr = isConstructor(target);
|
|
77
|
+
const constructor = isConstr ? target : getConstructor(target);
|
|
78
|
+
const proto = constructor.prototype;
|
|
79
|
+
let ownMeta = Reflect.getOwnMetadata(this.workspace, typeof propKey === 'string' ? proto : constructor, propKey);
|
|
80
|
+
if (this.options.inherit) {
|
|
81
|
+
const inheritFn = typeof this.options.inherit === 'function' ? this.options.inherit : undefined;
|
|
82
|
+
let shouldInherit = this.options.inherit;
|
|
83
|
+
if (inheritFn) {
|
|
84
|
+
if (typeof propKey === 'string') {
|
|
85
|
+
const classMeta = Reflect.getOwnMetadata(this.workspace, constructor);
|
|
86
|
+
shouldInherit = inheritFn(classMeta, propKey, ownMeta);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
shouldInherit = inheritFn(ownMeta);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (shouldInherit) {
|
|
93
|
+
const parent = Object.getPrototypeOf(constructor);
|
|
94
|
+
if (typeof parent === 'function' && parent !== fnProto && parent !== constructor) {
|
|
95
|
+
const inheritedMeta = this.read(parent, propKey);
|
|
96
|
+
ownMeta = { ...inheritedMeta, ...ownMeta, params: ownMeta === null || ownMeta === void 0 ? void 0 : ownMeta.params };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return ownMeta;
|
|
69
101
|
}
|
|
70
102
|
apply(...decorators) {
|
|
71
103
|
return ((target, propKey, descriptor) => {
|
|
@@ -85,7 +117,8 @@ class Mate {
|
|
|
85
117
|
this.set(args, key, value, isArray);
|
|
86
118
|
});
|
|
87
119
|
}
|
|
88
|
-
}
|
|
120
|
+
}
|
|
121
|
+
const fnProto = Object.getPrototypeOf(Function);
|
|
89
122
|
|
|
90
123
|
exports.Mate = Mate;
|
|
91
124
|
exports.getConstructor = getConstructor;
|
package/dist/mate.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export declare function getConstructor<T =
|
|
1
|
+
export declare function getConstructor<T = TAny>(instance: T): TFunction;
|
|
2
2
|
|
|
3
|
-
export declare function isConstructor<T = TAny>(v: T): v is T & TClassConstructor;
|
|
3
|
+
export declare function isConstructor<T = TAny>(v: T): v is (T & TClassConstructor);
|
|
4
4
|
|
|
5
5
|
export declare class Mate<T extends TProstoMetadata = TProstoMetadata> {
|
|
6
6
|
protected workspace: string;
|
|
7
|
-
|
|
7
|
+
protected options: TMateOptions<T>;
|
|
8
|
+
constructor(workspace: string, options?: TMateOptions<T>);
|
|
8
9
|
set<R extends T = T, RP = R['params'][0]>(args: TMergedDecoratorArgs, cb: ((meta: R & RP) => R & RP)): void;
|
|
9
10
|
set<R extends T = T, RP = R['params'][0]>(args: TMergedDecoratorArgs, key: keyof R | keyof RP, value: ((R & RP)[keyof R] & (R & RP)[keyof RP]) | undefined): void;
|
|
10
11
|
set<R extends T = T, RP = R['params'][0]>(args: TMergedDecoratorArgs, key: keyof R | keyof RP, value: ((R & RP)[keyof R] & (R & RP)[keyof RP]) | undefined, isArray: boolean | undefined): void;
|
|
11
|
-
read<R = T>(target: TFunction | TObject, propKey?: string | symbol): R | undefined;
|
|
12
|
+
read<R extends T = T>(target: TFunction | TObject, propKey?: string | symbol): R | undefined;
|
|
12
13
|
apply(...decorators: (MethodDecorator & ClassDecorator & ParameterDecorator)[]): MethodDecorator & ClassDecorator & ParameterDecorator;
|
|
13
14
|
decorate<R extends T = T, RP = R['params'][0]>(cb: ((meta: R & RP) => R & RP)): MethodDecorator & ClassDecorator & ParameterDecorator;
|
|
14
15
|
decorate<R extends T = T, RP = R['params'][0]>(key: keyof R | keyof RP | ((meta: R & RP) => R & RP), value: ((R & RP)[keyof R] & (R & RP)[keyof RP]) | undefined): MethodDecorator & ClassDecorator & ParameterDecorator;
|
|
@@ -21,6 +22,12 @@ declare type TClassConstructor<T = unknown> = new (...args: TAny[]) => T;
|
|
|
21
22
|
|
|
22
23
|
declare type TFunction = Function;
|
|
23
24
|
|
|
25
|
+
export declare interface TMateOptions<T extends TProstoMetadata = TProstoMetadata> {
|
|
26
|
+
readReturnType?: boolean;
|
|
27
|
+
readType?: boolean;
|
|
28
|
+
inherit?: boolean | ((classMeta: T, propKey?: string, methodMeta?: T) => boolean);
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
export declare interface TMergedDecoratorArgs {
|
|
25
32
|
target: TFunction | TObject;
|
|
26
33
|
propKey?: string | symbol;
|
|
@@ -32,10 +39,12 @@ declare type TObject = object;
|
|
|
32
39
|
|
|
33
40
|
export declare interface TProstoMetadata<TParams extends TProstoParamsMetadata = TProstoParamsMetadata> {
|
|
34
41
|
params: TParams[];
|
|
42
|
+
type?: TFunction;
|
|
43
|
+
returnType?: TFunction;
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
export declare interface TProstoParamsMetadata {
|
|
38
|
-
type
|
|
47
|
+
type?: TFunction;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
export { }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){console.error(`[91m[1m[prostojs/mate][${(new Date).toISOString().replace("T"," ").replace(/\.\d{3}z$/i,"")}] `+
|
|
1
|
+
function t(t){return e(t)?t:t.constructor?t.constructor:Object.getPrototypeOf(t).constructor}function e(t){return"function"==typeof t&&Object.getOwnPropertyNames(t).includes("prototype")&&!Object.getOwnPropertyNames(t).includes("caller")&&!!t.name}function r(t){console.error(`[91m[1m[prostojs/mate][${(new Date).toISOString().replace("T"," ").replace(/\.\d{3}z$/i,"")}] `+t+"[0m")}class o{constructor(t,e={}){this.workspace=t,this.options=e}set(t,e,o,a){var n;let p=Reflect.getOwnMetadata(this.workspace,t.target,t.propKey)||{};t.propKey&&this.options.readReturnType&&!p.returnType&&(p.returnType=Reflect.getOwnMetadata("design:returntype",t.target,t.propKey)),t.propKey&&this.options.readType&&!p.type&&(p.type=Reflect.getOwnMetadata("design:type",t.target,t.propKey));const{index:s}=t,i="function"==typeof e?e:void 0;let c=p;if(c.params||(c.params=null===(n=Reflect.getOwnMetadata("design:paramtypes",t.target,t.propKey))||void 0===n?void 0:n.map((t=>({type:t})))),"number"==typeof s&&(c.params=c.params||[],c.params[s]=c.params[s]||{type:void 0},i?c.params[s]=i(c.params[s]):c=c.params[s]),"function"!=typeof e)if(a){const t=c[e]||[];Array.isArray(t)||(r(y="Mate.add (isArray=true) called for non-array metadata"),new Error(y)),t.unshift(o),c[e]=t}else c[e]=o;else i&&"number"!=typeof s&&(p=i(c));var y;Reflect.defineMetadata(this.workspace,p,t.target,t.propKey)}read(r,o){const n=e(r)?r:t(r);let p=Reflect.getOwnMetadata(this.workspace,"string"==typeof o?n.prototype:n,o);if(this.options.inherit){const t="function"==typeof this.options.inherit?this.options.inherit:void 0;let e=this.options.inherit;if(t)if("string"==typeof o){e=t(Reflect.getOwnMetadata(this.workspace,n),o,p)}else e=t(p);if(e){const t=Object.getPrototypeOf(n);if("function"==typeof t&&t!==a&&t!==n){p={...this.read(t,o),...p,params:null==p?void 0:p.params}}}}return p}apply(...t){return(e,r,o)=>{for(const a of t)a(e,r,o)}}decorate(t,e,r){return(o,a,n)=>{this.set({target:o,propKey:a,descriptor:"number"==typeof n?void 0:n,index:"number"==typeof n?n:void 0},t,e,r)}}}const a=Object.getPrototypeOf(Function);export{o as Mate,t as getConstructor,e as isConstructor};
|
package/dist/mate.esm-bundler.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
function getConstructor(instance) {
|
|
2
|
+
return isConstructor(instance) ?
|
|
3
|
+
instance : instance.constructor ?
|
|
4
|
+
instance.constructor : Object.getPrototypeOf(instance).constructor;
|
|
5
|
+
}
|
|
6
|
+
function isConstructor(v) {
|
|
7
|
+
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
2
11
|
|
|
3
12
|
function logError(error) {
|
|
@@ -9,26 +18,25 @@ function panic(error) {
|
|
|
9
18
|
return new Error(error);
|
|
10
19
|
}
|
|
11
20
|
|
|
12
|
-
function getConstructor(instance) {
|
|
13
|
-
return Object.getPrototypeOf(instance).constructor;
|
|
14
|
-
}
|
|
15
|
-
function isConstructor(v) {
|
|
16
|
-
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
require('reflect-metadata');
|
|
20
21
|
class Mate {
|
|
21
|
-
constructor(workspace) {
|
|
22
|
+
constructor(workspace, options = {}) {
|
|
22
23
|
this.workspace = workspace;
|
|
24
|
+
this.options = options;
|
|
23
25
|
}
|
|
24
26
|
set(args, key, value, isArray) {
|
|
25
27
|
var _a;
|
|
26
|
-
let meta = Reflect.
|
|
28
|
+
let meta = Reflect.getOwnMetadata(this.workspace, args.target, args.propKey) || {};
|
|
29
|
+
if (args.propKey && this.options.readReturnType && !meta.returnType) {
|
|
30
|
+
meta.returnType = Reflect.getOwnMetadata('design:returntype', args.target, args.propKey);
|
|
31
|
+
}
|
|
32
|
+
if (args.propKey && this.options.readType && !meta.type) {
|
|
33
|
+
meta.type = Reflect.getOwnMetadata('design:type', args.target, args.propKey);
|
|
34
|
+
}
|
|
27
35
|
const { index } = args;
|
|
28
36
|
const cb = typeof key === 'function' ? key : undefined;
|
|
29
37
|
let data = meta;
|
|
30
38
|
if (!data.params) {
|
|
31
|
-
data.params = (_a = Reflect.
|
|
39
|
+
data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', args.target, args.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
|
|
32
40
|
}
|
|
33
41
|
if (typeof index === 'number') {
|
|
34
42
|
data.params = data.params || [];
|
|
@@ -61,7 +69,31 @@ class Mate {
|
|
|
61
69
|
Reflect.defineMetadata(this.workspace, meta, args.target, args.propKey);
|
|
62
70
|
}
|
|
63
71
|
read(target, propKey) {
|
|
64
|
-
|
|
72
|
+
const isConstr = isConstructor(target);
|
|
73
|
+
const constructor = isConstr ? target : getConstructor(target);
|
|
74
|
+
const proto = constructor.prototype;
|
|
75
|
+
let ownMeta = Reflect.getOwnMetadata(this.workspace, typeof propKey === 'string' ? proto : constructor, propKey);
|
|
76
|
+
if (this.options.inherit) {
|
|
77
|
+
const inheritFn = typeof this.options.inherit === 'function' ? this.options.inherit : undefined;
|
|
78
|
+
let shouldInherit = this.options.inherit;
|
|
79
|
+
if (inheritFn) {
|
|
80
|
+
if (typeof propKey === 'string') {
|
|
81
|
+
const classMeta = Reflect.getOwnMetadata(this.workspace, constructor);
|
|
82
|
+
shouldInherit = inheritFn(classMeta, propKey, ownMeta);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
shouldInherit = inheritFn(ownMeta);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (shouldInherit) {
|
|
89
|
+
const parent = Object.getPrototypeOf(constructor);
|
|
90
|
+
if (typeof parent === 'function' && parent !== fnProto && parent !== constructor) {
|
|
91
|
+
const inheritedMeta = this.read(parent, propKey);
|
|
92
|
+
ownMeta = { ...inheritedMeta, ...ownMeta, params: ownMeta === null || ownMeta === void 0 ? void 0 : ownMeta.params };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return ownMeta;
|
|
65
97
|
}
|
|
66
98
|
apply(...decorators) {
|
|
67
99
|
return ((target, propKey, descriptor) => {
|
|
@@ -81,6 +113,7 @@ class Mate {
|
|
|
81
113
|
this.set(args, key, value, isArray);
|
|
82
114
|
});
|
|
83
115
|
}
|
|
84
|
-
}
|
|
116
|
+
}
|
|
117
|
+
const fnProto = Object.getPrototypeOf(Function);
|
|
85
118
|
|
|
86
119
|
export { Mate, getConstructor, isConstructor };
|
package/dist/mate.global.prod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ProstoMate=function(
|
|
1
|
+
var ProstoMate=function(t){"use strict";function e(t){return r(t)?t:t.constructor?t.constructor:Object.getPrototypeOf(t).constructor}function r(t){return"function"==typeof t&&Object.getOwnPropertyNames(t).includes("prototype")&&!Object.getOwnPropertyNames(t).includes("caller")&&!!t.name}function o(t){console.error(`[91m[1m[prostojs/mate][${(new Date).toISOString().replace("T"," ").replace(/\.\d{3}z$/i,"")}] `+t+"[0m")}const a=Object.getPrototypeOf(Function);return t.Mate=class{constructor(t,e={}){this.workspace=t,this.options=e}set(t,e,r,a){var n;let p=Reflect.getOwnMetadata(this.workspace,t.target,t.propKey)||{};t.propKey&&this.options.readReturnType&&!p.returnType&&(p.returnType=Reflect.getOwnMetadata("design:returntype",t.target,t.propKey)),t.propKey&&this.options.readType&&!p.type&&(p.type=Reflect.getOwnMetadata("design:type",t.target,t.propKey));const{index:s}=t,i="function"==typeof e?e:void 0;let c=p;if(c.params||(c.params=null===(n=Reflect.getOwnMetadata("design:paramtypes",t.target,t.propKey))||void 0===n?void 0:n.map((t=>({type:t})))),"number"==typeof s&&(c.params=c.params||[],c.params[s]=c.params[s]||{type:void 0},i?c.params[s]=i(c.params[s]):c=c.params[s]),"function"!=typeof e)if(a){const t=c[e]||[];Array.isArray(t)||(o(f="Mate.add (isArray=true) called for non-array metadata"),new Error(f)),t.unshift(r),c[e]=t}else c[e]=r;else i&&"number"!=typeof s&&(p=i(c));var f;Reflect.defineMetadata(this.workspace,p,t.target,t.propKey)}read(t,o){const n=r(t)?t:e(t);let p=Reflect.getOwnMetadata(this.workspace,"string"==typeof o?n.prototype:n,o);if(this.options.inherit){const t="function"==typeof this.options.inherit?this.options.inherit:void 0;let e=this.options.inherit;if(t)if("string"==typeof o){e=t(Reflect.getOwnMetadata(this.workspace,n),o,p)}else e=t(p);if(e){const t=Object.getPrototypeOf(n);if("function"==typeof t&&t!==a&&t!==n){p={...this.read(t,o),...p,params:null==p?void 0:p.params}}}}return p}apply(...t){return(e,r,o)=>{for(const a of t)a(e,r,o)}}decorate(t,e,r){return(o,a,n)=>{this.set({target:o,propKey:a,descriptor:"number"==typeof n?void 0:n,index:"number"==typeof n?n:void 0},t,e,r)}}},t.getConstructor=e,t.isConstructor=r,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
|
package/dist/src/mate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import 'reflect
|
|
1
|
+
import './reflect';
|
|
2
2
|
import { TAny, TFunction, TObject } from './types';
|
|
3
3
|
export interface TMergedDecoratorArgs {
|
|
4
4
|
target: TFunction | TObject;
|
|
@@ -8,17 +8,25 @@ export interface TMergedDecoratorArgs {
|
|
|
8
8
|
}
|
|
9
9
|
export interface TProstoMetadata<TParams extends TProstoParamsMetadata = TProstoParamsMetadata> {
|
|
10
10
|
params: TParams[];
|
|
11
|
+
type?: TFunction;
|
|
12
|
+
returnType?: TFunction;
|
|
11
13
|
}
|
|
12
14
|
export interface TProstoParamsMetadata {
|
|
13
|
-
type
|
|
15
|
+
type?: TFunction;
|
|
16
|
+
}
|
|
17
|
+
export interface TMateOptions<T extends TProstoMetadata = TProstoMetadata> {
|
|
18
|
+
readReturnType?: boolean;
|
|
19
|
+
readType?: boolean;
|
|
20
|
+
inherit?: boolean | ((classMeta: T, propKey?: string, methodMeta?: T) => boolean);
|
|
14
21
|
}
|
|
15
22
|
export declare class Mate<T extends TProstoMetadata = TProstoMetadata> {
|
|
16
23
|
protected workspace: string;
|
|
17
|
-
|
|
24
|
+
protected options: TMateOptions<T>;
|
|
25
|
+
constructor(workspace: string, options?: TMateOptions<T>);
|
|
18
26
|
set<R extends T = T, RP = R['params'][0]>(args: TMergedDecoratorArgs, cb: ((meta: R & RP) => R & RP)): void;
|
|
19
27
|
set<R extends T = T, RP = R['params'][0]>(args: TMergedDecoratorArgs, key: keyof R | keyof RP, value: ((R & RP)[keyof R] & (R & RP)[keyof RP]) | undefined): void;
|
|
20
28
|
set<R extends T = T, RP = R['params'][0]>(args: TMergedDecoratorArgs, key: keyof R | keyof RP, value: ((R & RP)[keyof R] & (R & RP)[keyof RP]) | undefined, isArray: boolean | undefined): void;
|
|
21
|
-
read<R = T>(target: TFunction | TObject, propKey?: string | symbol): R | undefined;
|
|
29
|
+
read<R extends T = T>(target: TFunction | TObject, propKey?: string | symbol): R | undefined;
|
|
22
30
|
apply(...decorators: (MethodDecorator & ClassDecorator & ParameterDecorator)[]): MethodDecorator & ClassDecorator & ParameterDecorator;
|
|
23
31
|
decorate<R extends T = T, RP = R['params'][0]>(cb: ((meta: R & RP) => R & RP)): MethodDecorator & ClassDecorator & ParameterDecorator;
|
|
24
32
|
decorate<R extends T = T, RP = R['params'][0]>(key: keyof R | keyof RP | ((meta: R & RP) => R & RP), value: ((R & RP)[keyof R] & (R & RP)[keyof RP]) | undefined): MethodDecorator & ClassDecorator & ParameterDecorator;
|
package/dist/src/mate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mate.d.ts","sourceRoot":"","sources":["../../src/mate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mate.d.ts","sourceRoot":"","sources":["../../src/mate.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,CAAA;AAElB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAK,SAAS,CAAA;AAGjD,MAAM,WAAW,oBAAoB;IACjC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,UAAU,CAAC,EAAE,uBAAuB,CAAC,IAAI,CAAC,CAAA;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,qBAAqB,GAAG,qBAAqB;IAC1F,MAAM,EAAE,OAAO,EAAE,CAAA;IACjB,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,UAAU,CAAC,EAAE,SAAS,CAAA;CACzB;AAED,MAAM,WAAW,qBAAqB;IAClC,IAAI,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe;IACrE,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,OA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AC,GAAG,EAAE,CAAC,EACrD,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,EAC3D,OAAO,EAAE,OAAO,GAAG,SAAS,GAC7B,eAAe,GAAG,cAAc,GAAG,kBAAkB;CAiB3D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TFunction, TObject } from './types';
|
|
2
|
+
export declare const Reflect: {
|
|
3
|
+
getOwnMetadata(key: string | symbol, target: TObject | TFunction, prop?: string | symbol): unknown;
|
|
4
|
+
defineMetadata(key: string | symbol, data: unknown, target: TObject | TFunction, prop?: string | symbol): void;
|
|
5
|
+
metadata(key: string | symbol, data: unknown): ClassDecorator & MethodDecorator & ParameterDecorator;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=reflect.d.ts.map
|
|
@@ -0,0 +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,9 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import { Mate, TProstoMetadata } from '..';
|
|
2
|
+
export declare const mate: Mate<{
|
|
3
|
+
inherit?: boolean | undefined;
|
|
4
|
+
} & TProstoMetadata<import("..").TProstoParamsMetadata>>;
|
|
5
|
+
export declare class MateTestClass {
|
|
2
6
|
constructor(_a: string);
|
|
3
|
-
test(_b: string):
|
|
7
|
+
test(_b: string): string;
|
|
4
8
|
viaCB(_c: string): void;
|
|
5
9
|
}
|
|
6
|
-
export declare class
|
|
10
|
+
export declare class MateTestClass2 {
|
|
11
|
+
constructor(a: string);
|
|
7
12
|
test(): void;
|
|
13
|
+
toOverwriteMeta(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class MateTestClass3 extends MateTestClass2 {
|
|
16
|
+
constructor();
|
|
17
|
+
test2(): void;
|
|
18
|
+
toOverwriteMeta(): void;
|
|
19
|
+
}
|
|
20
|
+
export declare class MateTestClass4 extends MateTestClass2 {
|
|
21
|
+
constructor();
|
|
22
|
+
test2(): void;
|
|
23
|
+
toOverwriteMeta(): void;
|
|
8
24
|
}
|
|
9
25
|
//# sourceMappingURL=mate.artifacts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mate.artifacts.d.ts","sourceRoot":"","sources":["../../../src/tests/mate.artifacts.ts"],"names":[],"mappings":"
|
|
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;CAGrB;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflect.artifacts.d.ts","sourceRoot":"","sources":["../../../src/tests/reflect.artifacts.ts"],"names":[],"mappings":"AAIA,qBAEa,gBAAgB;gBAIrB,CAAC,EAAE,OAAO,EAGV,CAAC,EAAE,IAAI;IAKX,MAAM,CAGF,CAAC,EAAE,MAAM,EAGT,CAAC,EAAE,MAAM;CAEhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflect.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/reflect.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TAny, TClassConstructor, TFunction
|
|
2
|
-
export declare function getConstructor<T =
|
|
3
|
-
export declare function isConstructor<T = TAny>(v: T): v is T & TClassConstructor;
|
|
1
|
+
import { TAny, TClassConstructor, TFunction } from '../types';
|
|
2
|
+
export declare function getConstructor<T = TAny>(instance: T): TFunction;
|
|
3
|
+
export declare function isConstructor<T = TAny>(v: T): v is (T & TClassConstructor);
|
|
4
4
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAW,MAAM,UAAU,CAAA;AAEtE,wBAAgB,cAAc,CAAC,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,CAK/D;AAED,wBAAgB,aAAa,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAE1E"}
|
package/dist/src/utils/log.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/utils/log.ts"],"names":[],"mappings":"AAGA,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,QAE/B;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,QAErC"}
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/utils/log.ts"],"names":[],"mappings":"AAGA,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,QAE/B;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,QAEhC;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,QAErC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prostojs/mate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "MATE is TS Metadata Organizer",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/mate.esm-bundler.js",
|
|
@@ -39,9 +39,7 @@
|
|
|
39
39
|
"global"
|
|
40
40
|
]
|
|
41
41
|
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"reflect-metadata": "^0.1.13"
|
|
44
|
-
},
|
|
42
|
+
"dependencies": {},
|
|
45
43
|
"gitHooks": {
|
|
46
44
|
"commit-msg": "node scripts/verifyCommit.js"
|
|
47
45
|
},
|
|
@@ -52,16 +50,17 @@
|
|
|
52
50
|
},
|
|
53
51
|
"homepage": "https://github.com/prostojs/mate#readme",
|
|
54
52
|
"devDependencies": {
|
|
55
|
-
"
|
|
56
|
-
"@
|
|
53
|
+
"reflect-metadata": "^0.1.13",
|
|
54
|
+
"@microsoft/api-extractor": "^7.30.0",
|
|
55
|
+
"@prostojs/dye": "^0.3.0",
|
|
57
56
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
58
57
|
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
59
58
|
"@rollup/plugin-replace": "^3.0.0",
|
|
60
|
-
"@types/jest": "^27.
|
|
61
|
-
"@types/node": "^16.
|
|
59
|
+
"@types/jest": "^27.5.2",
|
|
60
|
+
"@types/node": "^16.11.57",
|
|
62
61
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
63
62
|
"@typescript-eslint/parser": "^4.33.0",
|
|
64
|
-
"brotli": "^1.3.
|
|
63
|
+
"brotli": "^1.3.3",
|
|
65
64
|
"conventional-changelog": "^3.1.24",
|
|
66
65
|
"conventional-changelog-cli": "^2.1.1",
|
|
67
66
|
"enquirer": "^2.3.6",
|
|
@@ -71,15 +70,15 @@
|
|
|
71
70
|
"execa": "^5.1.1",
|
|
72
71
|
"fs-extra": "^10.0.0",
|
|
73
72
|
"jest": "^27.2.5",
|
|
74
|
-
"minimist": "^1.2.
|
|
73
|
+
"minimist": "^1.2.6",
|
|
75
74
|
"rollup": "^2.58.0",
|
|
76
75
|
"rollup-plugin-terser": "^7.0.2",
|
|
77
76
|
"rollup-plugin-typescript2": "^0.30.0",
|
|
78
77
|
"semver": "^7.3.5",
|
|
79
78
|
"ts-jest": "^27.0.5",
|
|
80
|
-
"ts-node": "^10.
|
|
79
|
+
"ts-node": "^10.9.1",
|
|
81
80
|
"tslib": "^2.3.1",
|
|
82
|
-
"typescript": "^4.
|
|
81
|
+
"typescript": "^4.8.2",
|
|
83
82
|
"yorkie": "^2.0.0",
|
|
84
83
|
"zlib": "^1.0.5"
|
|
85
84
|
}
|