@alterior/annotations 3.0.0-rc.5 → 3.0.0

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.
@@ -2,7 +2,7 @@
2
2
  /// <reference types="reflect-metadata" />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Label = exports.LabelAnnotation = exports.Annotations = exports.Annotation = exports.Mutator = exports.MetadataName = exports.AnnotationTargetError = exports.METHOD_PARAMETER_ANNOTATIONS_KEY = exports.PROPERTY_ANNOTATIONS_KEY = exports.CONSTRUCTOR_PARAMETERS_ANNOTATIONS_KEY = exports.ANNOTATIONS_KEY = void 0;
5
- var tslib_1 = require("tslib");
5
+ const tslib_1 = require("tslib");
6
6
  /**
7
7
  * @alterior/annotations
8
8
  * A class library for handling Typescript metadata decorators via "annotation" classes
@@ -10,7 +10,7 @@ var tslib_1 = require("tslib");
10
10
  * (C) 2017-2019 William Lahti
11
11
  *
12
12
  */
13
- var common_1 = require("@alterior/common");
13
+ const common_1 = require("@alterior/common");
14
14
  // These are the properties on a class where annotation metadata is deposited
15
15
  // when annotation decorators are executed. Note that these are intended to
16
16
  // be compatible with Angular 6's model
@@ -22,38 +22,23 @@ exports.METHOD_PARAMETER_ANNOTATIONS_KEY = '__parameter__metadata__';
22
22
  * Thrown when a caller attempts to decorate an annotation target when the
23
23
  * annotation does not support that target.
24
24
  */
25
- var AnnotationTargetError = /** @class */ (function (_super) {
26
- (0, tslib_1.__extends)(AnnotationTargetError, _super);
27
- function AnnotationTargetError(annotationClass, invalidType, supportedTypes, message) {
28
- var _this = _super.call(this, message || "You cannot decorate a " + invalidType + " with annotation " + annotationClass.name + ". Valid targets: " + supportedTypes.join(', ')) || this;
29
- _this._invalidType = invalidType;
30
- _this._annotationClass = annotationClass;
31
- _this._supportedTypes = supportedTypes;
32
- return _this;
33
- }
34
- Object.defineProperty(AnnotationTargetError.prototype, "invalidType", {
35
- get: function () {
36
- return this._invalidType;
37
- },
38
- enumerable: false,
39
- configurable: true
40
- });
41
- Object.defineProperty(AnnotationTargetError.prototype, "supportedTypes", {
42
- get: function () {
43
- return this._supportedTypes;
44
- },
45
- enumerable: false,
46
- configurable: true
47
- });
48
- Object.defineProperty(AnnotationTargetError.prototype, "annotationClass", {
49
- get: function () {
50
- return this._annotationClass;
51
- },
52
- enumerable: false,
53
- configurable: true
54
- });
55
- return AnnotationTargetError;
56
- }(common_1.NotSupportedError));
25
+ class AnnotationTargetError extends common_1.NotSupportedError {
26
+ constructor(annotationClass, invalidType, supportedTypes, message) {
27
+ super(message || `You cannot decorate a ${invalidType} with annotation ${annotationClass.name}. Valid targets: ${supportedTypes.join(', ')}`);
28
+ this._invalidType = invalidType;
29
+ this._annotationClass = annotationClass;
30
+ this._supportedTypes = supportedTypes;
31
+ }
32
+ get invalidType() {
33
+ return this._invalidType;
34
+ }
35
+ get supportedTypes() {
36
+ return this._supportedTypes;
37
+ }
38
+ get annotationClass() {
39
+ return this._annotationClass;
40
+ }
41
+ }
57
42
  exports.AnnotationTargetError = AnnotationTargetError;
58
43
  /**
59
44
  * Create a decorator suitable for use along with an Annotation class.
@@ -64,10 +49,10 @@ exports.AnnotationTargetError = AnnotationTargetError;
64
49
  */
65
50
  function makeDecorator(ctor, options) {
66
51
  if (!ctor)
67
- throw new Error("Cannot create decorator: Passed class reference was undefined/null: This can happen due to circular dependencies.");
68
- var factory = null;
69
- var validTargets = null;
70
- var allowMultiple = false;
52
+ throw new Error(`Cannot create decorator: Passed class reference was undefined/null: This can happen due to circular dependencies.`);
53
+ let factory = null;
54
+ let validTargets = null;
55
+ let allowMultiple = false;
71
56
  if (options) {
72
57
  if (options.factory)
73
58
  factory = options.factory;
@@ -77,58 +62,44 @@ function makeDecorator(ctor, options) {
77
62
  allowMultiple = options.allowMultiple;
78
63
  }
79
64
  if (!factory)
80
- factory = function (target) {
81
- var args = [];
82
- for (var _i = 1; _i < arguments.length; _i++) {
83
- args[_i - 1] = arguments[_i];
84
- }
85
- return new (ctor.bind.apply(ctor, (0, tslib_1.__spreadArray)([void 0], (0, tslib_1.__read)(args), false)))();
86
- };
65
+ factory = (target, ...args) => new ctor(...args);
87
66
  if (!validTargets)
88
67
  validTargets = ['class', 'method', 'property', 'parameter'];
89
- return function () {
90
- var decoratorArgs = [];
91
- for (var _i = 0; _i < arguments.length; _i++) {
92
- decoratorArgs[_i] = arguments[_i];
93
- }
94
- return function (target) {
68
+ return (...decoratorArgs) => {
69
+ return (target, ...args) => {
95
70
  // Note that checking the length is not enough, because for properties
96
71
  // two arguments are passed, but the property descriptor is `undefined`.
97
72
  // So we make sure that we have a valid property descriptor (args[1])
98
- var args = [];
99
- for (var _i = 1; _i < arguments.length; _i++) {
100
- args[_i - 1] = arguments[_i];
101
- }
102
73
  if (args.length === 2 && args[1] !== undefined) {
103
74
  if (typeof args[1] === 'number') {
104
75
  // Parameter decorator on a method or a constructor (methodName will be undefined)
105
- var methodName = args[0];
106
- var index = args[1];
76
+ let methodName = args[0];
77
+ let index = args[1];
107
78
  if (!validTargets.includes('parameter'))
108
79
  throw new AnnotationTargetError(ctor, 'parameter', validTargets);
109
80
  if (!allowMultiple) {
110
- var existingParamDecs = Annotations.getParameterAnnotations(target, methodName, true);
111
- var existingParamAnnots = existingParamDecs[index] || [];
112
- if (existingParamAnnots.find(function (x) { return x.$metadataName === ctor['$metadataName']; }))
113
- throw new Error("Annotation " + ctor.name + " can only be applied to an element once.");
81
+ let existingParamDecs = Annotations.getParameterAnnotations(target, methodName, true);
82
+ let existingParamAnnots = existingParamDecs[index] || [];
83
+ if (existingParamAnnots.find(x => x.$metadataName === ctor['$metadataName']))
84
+ throw new Error(`Annotation ${ctor.name} can only be applied to an element once.`);
114
85
  }
115
86
  if (methodName) {
116
- var annotation = factory.apply(void 0, (0, tslib_1.__spreadArray)([{
117
- type: 'parameter',
118
- target: target,
119
- propertyKey: methodName,
120
- index: index
121
- }], (0, tslib_1.__read)(decoratorArgs), false));
87
+ let annotation = factory({
88
+ type: 'parameter',
89
+ target,
90
+ propertyKey: methodName,
91
+ index
92
+ }, ...decoratorArgs);
122
93
  if (!annotation)
123
94
  return;
124
95
  annotation.applyToParameter(target, methodName, index);
125
96
  }
126
97
  else {
127
- var annotation = factory.apply(void 0, (0, tslib_1.__spreadArray)([{
128
- type: 'parameter',
129
- target: target,
130
- index: index
131
- }], (0, tslib_1.__read)(decoratorArgs), false));
98
+ let annotation = factory({
99
+ type: 'parameter',
100
+ target,
101
+ index
102
+ }, ...decoratorArgs);
132
103
  if (!annotation)
133
104
  return;
134
105
  annotation.applyToConstructorParameter(target, index);
@@ -136,21 +107,21 @@ function makeDecorator(ctor, options) {
136
107
  }
137
108
  else {
138
109
  // Method decorator
139
- var methodName = args[0];
140
- var descriptor = args[1];
110
+ let methodName = args[0];
111
+ let descriptor = args[1];
141
112
  if (!validTargets.includes('method'))
142
113
  throw new AnnotationTargetError(ctor, 'method', validTargets);
143
114
  if (!allowMultiple) {
144
- var existingAnnots = Annotations.getMethodAnnotations(target, methodName, true);
145
- if (existingAnnots.find(function (x) { return x.$metadataName === ctor['$metadataName']; }))
146
- throw new Error("Annotation " + ctor.name + " can only be applied to an element once.");
115
+ let existingAnnots = Annotations.getMethodAnnotations(target, methodName, true);
116
+ if (existingAnnots.find(x => x.$metadataName === ctor['$metadataName']))
117
+ throw new Error(`Annotation ${ctor.name} can only be applied to an element once.`);
147
118
  }
148
- var annotation = factory.apply(void 0, (0, tslib_1.__spreadArray)([{
149
- type: 'method',
150
- target: target,
151
- propertyKey: methodName,
152
- propertyDescriptor: descriptor
153
- }], (0, tslib_1.__read)(decoratorArgs), false));
119
+ let annotation = factory({
120
+ type: 'method',
121
+ target,
122
+ propertyKey: methodName,
123
+ propertyDescriptor: descriptor
124
+ }, ...decoratorArgs);
154
125
  if (!annotation)
155
126
  return;
156
127
  annotation.applyToMethod(target, methodName);
@@ -158,19 +129,19 @@ function makeDecorator(ctor, options) {
158
129
  }
159
130
  else if (args.length >= 1) {
160
131
  // Property decorator
161
- var propertyKey = args[0];
132
+ let propertyKey = args[0];
162
133
  if (!validTargets.includes('property'))
163
134
  throw new AnnotationTargetError(ctor, 'property', validTargets);
164
135
  if (!allowMultiple) {
165
- var existingAnnots = Annotations.getPropertyAnnotations(target, propertyKey, true);
166
- if (existingAnnots.find(function (x) { return x.$metadataName === ctor['$metadataName']; }))
167
- throw new Error("Annotation " + ctor.name + " can only be applied to an element once.");
136
+ let existingAnnots = Annotations.getPropertyAnnotations(target, propertyKey, true);
137
+ if (existingAnnots.find(x => x.$metadataName === ctor['$metadataName']))
138
+ throw new Error(`Annotation ${ctor.name} can only be applied to an element once.`);
168
139
  }
169
- var annotation = factory.apply(void 0, (0, tslib_1.__spreadArray)([{
170
- type: 'property',
171
- target: target,
172
- propertyKey: propertyKey
173
- }], (0, tslib_1.__read)(decoratorArgs), false));
140
+ let annotation = factory({
141
+ type: 'property',
142
+ target,
143
+ propertyKey
144
+ }, ...decoratorArgs);
174
145
  if (!annotation)
175
146
  return;
176
147
  annotation.applyToProperty(target, propertyKey);
@@ -180,27 +151,27 @@ function makeDecorator(ctor, options) {
180
151
  if (!validTargets.includes('class'))
181
152
  throw new AnnotationTargetError(ctor, 'class', validTargets);
182
153
  if (!allowMultiple) {
183
- var existingAnnots = Annotations.getClassAnnotations(target);
184
- if (existingAnnots.find(function (x) { return x.$metadataName === ctor['$metadataName']; }))
185
- throw new Error("Annotation " + ctor.name + " can only be applied to an element once.");
154
+ let existingAnnots = Annotations.getClassAnnotations(target);
155
+ if (existingAnnots.find(x => x.$metadataName === ctor['$metadataName']))
156
+ throw new Error(`Annotation ${ctor.name} can only be applied to an element once.`);
186
157
  }
187
- var annotation = factory.apply(void 0, (0, tslib_1.__spreadArray)([{
188
- type: 'class',
189
- target: target
190
- }], (0, tslib_1.__read)(decoratorArgs), false));
158
+ let annotation = factory({
159
+ type: 'class',
160
+ target
161
+ }, ...decoratorArgs);
191
162
  if (!annotation)
192
163
  return;
193
164
  annotation.applyToClass(target);
194
165
  }
195
166
  else {
196
167
  // Invalid, or future decorator types we don't support yet.
197
- throw new Error("Encountered unknown decorator invocation with " + (args.length + 1) + " parameters.");
168
+ throw new Error(`Encountered unknown decorator invocation with ${args.length + 1} parameters.`);
198
169
  }
199
170
  };
200
171
  };
201
172
  }
202
173
  function MetadataName(name) {
203
- return function (target) { return Object.defineProperty(target, '$metadataName', { value: name }); };
174
+ return target => Object.defineProperty(target, '$metadataName', { value: name });
204
175
  }
205
176
  exports.MetadataName = MetadataName;
206
177
  /**
@@ -210,24 +181,18 @@ exports.MetadataName = MetadataName;
210
181
  *
211
182
  * Create a mutator with Mutator.create().
212
183
  */
213
- var Mutator = /** @class */ (function () {
214
- function Mutator() {
215
- }
184
+ class Mutator {
216
185
  /**
217
186
  * Low-level method to ceate a new mutation decorator (mutator) based on the given function.
218
187
  * Use `Mutator.define()` instead.
219
188
  */
220
- Mutator.create = function (mutator, options) {
189
+ static create(mutator, options) {
221
190
  return Annotation.decorator(Object.assign({}, options || {}, {
222
- factory: function (target) {
223
- var args = [];
224
- for (var _i = 1; _i < arguments.length; _i++) {
225
- args[_i - 1] = arguments[_i];
226
- }
227
- mutator.apply(void 0, (0, tslib_1.__spreadArray)([target], (0, tslib_1.__read)(args), false));
191
+ factory: (target, ...args) => {
192
+ mutator(target, ...args);
228
193
  }
229
194
  }));
230
- };
195
+ }
231
196
  /**
232
197
  * Define a new mutation decorator (mutator).
233
198
  * This should be called and returned from a
@@ -265,11 +230,10 @@ export function RunTwice() {
265
230
  )
266
231
  * ```
267
232
  */
268
- Mutator.define = function (definition) {
233
+ static define(definition) {
269
234
  return this.create(definition.invoke, definition.options)();
270
- };
271
- return Mutator;
272
- }());
235
+ }
236
+ }
273
237
  exports.Mutator = Mutator;
274
238
  /**
275
239
  * Represents a metadata annotation which can be applied to classes,
@@ -318,23 +282,23 @@ class ABC {
318
282
  ```
319
283
  *
320
284
  */
321
- var Annotation = /** @class */ (function () {
322
- function Annotation(props) {
285
+ class Annotation {
286
+ constructor(props) {
323
287
  this.$metadataName = this.constructor['$metadataName'];
324
288
  if (!this.$metadataName || !this.$metadataName.includes(':')) {
325
- throw new Error("You must specify a metadata name for this annotation in the form of "
326
- + (" 'mynamespace:myproperty'. You specified: '" + (this.$metadataName || '<none>') + "'"));
289
+ throw new Error(`You must specify a metadata name for this annotation in the form of `
290
+ + ` 'mynamespace:myproperty'. You specified: '${this.$metadataName || '<none>'}'`);
327
291
  }
328
292
  Object.assign(this, props || {});
329
293
  }
330
- Annotation.prototype.toString = function () {
331
- return "@" + this.constructor.name;
332
- };
333
- Annotation.getMetadataName = function () {
294
+ toString() {
295
+ return `@${this.constructor.name}`;
296
+ }
297
+ static getMetadataName() {
334
298
  if (!this['$metadataName'])
335
- throw new Error("Annotation subclass " + this.name + " must have @MetadataName()");
299
+ throw new Error(`Annotation subclass ${this.name} must have @MetadataName()`);
336
300
  return this['$metadataName'];
337
- };
301
+ }
338
302
  /**
339
303
  * Construct a decorator suitable for attaching annotations of the called type
340
304
  * onto classes, constructor parameters, methods, properties, and parameters.
@@ -345,61 +309,61 @@ var Annotation = /** @class */ (function () {
345
309
  * @param options Allows for specifying options which will modify the behavior of the decorator.
346
310
  * See the DecoratorOptions documentation for more information.
347
311
  */
348
- Annotation.decorator = function (options) {
312
+ static decorator(options) {
349
313
  if (this === Annotation) {
350
314
  if (!options || !options.factory) {
351
- throw new Error("When calling Annotation.decorator() to create a mutator, you must specify a factory (or use Mutator.decorator())");
315
+ throw new Error(`When calling Annotation.decorator() to create a mutator, you must specify a factory (or use Mutator.decorator())`);
352
316
  }
353
317
  }
354
318
  return makeDecorator(this, options);
355
- };
319
+ }
356
320
  /**
357
321
  * Clone this annotation instance into a new one. This is not a deep copy.
358
322
  */
359
- Annotation.prototype.clone = function () {
323
+ clone() {
360
324
  return Annotations.clone(this);
361
- };
325
+ }
362
326
  /**
363
327
  * Apply this annotation to a given target.
364
328
  * @param target
365
329
  */
366
- Annotation.prototype.applyToClass = function (target) {
330
+ applyToClass(target) {
367
331
  return Annotations.applyToClass(this, target);
368
- };
332
+ }
369
333
  /**
370
334
  * Apply this annotation instance to the given property.
371
335
  * @param target
372
336
  * @param name
373
337
  */
374
- Annotation.prototype.applyToProperty = function (target, name) {
338
+ applyToProperty(target, name) {
375
339
  return Annotations.applyToProperty(this, target, name);
376
- };
340
+ }
377
341
  /**
378
342
  * Apply this annotation instance to the given method.
379
343
  * @param target
380
344
  * @param name
381
345
  */
382
- Annotation.prototype.applyToMethod = function (target, name) {
346
+ applyToMethod(target, name) {
383
347
  return Annotations.applyToMethod(this, target, name);
384
- };
348
+ }
385
349
  /**
386
350
  * Apply this annotation instance to the given method parameter.
387
351
  * @param target
388
352
  * @param name
389
353
  * @param index
390
354
  */
391
- Annotation.prototype.applyToParameter = function (target, name, index) {
355
+ applyToParameter(target, name, index) {
392
356
  return Annotations.applyToParameter(this, target, name, index);
393
- };
357
+ }
394
358
  /**
395
359
  * Apply this annotation instance to the given constructor parameter.
396
360
  * @param target
397
361
  * @param name
398
362
  * @param index
399
363
  */
400
- Annotation.prototype.applyToConstructorParameter = function (target, index) {
364
+ applyToConstructorParameter(target, index) {
401
365
  return Annotations.applyToConstructorParameter(this, target, index);
402
- };
366
+ }
403
367
  /**
404
368
  * Filter the given list of annotations for the ones which match this annotation class
405
369
  * based on matching $metadataName.
@@ -407,10 +371,9 @@ var Annotation = /** @class */ (function () {
407
371
  * @param this
408
372
  * @param annotations
409
373
  */
410
- Annotation.filter = function (annotations) {
411
- var _this = this;
412
- return annotations.filter(function (x) { return x.$metadataName === _this.getMetadataName(); });
413
- };
374
+ static filter(annotations) {
375
+ return annotations.filter(x => x.$metadataName === this.getMetadataName());
376
+ }
414
377
  /**
415
378
  * Get all instances of this annotation class attached to the given class.
416
379
  * If called on a subclass of Annotation, it returns only annotations that match
@@ -418,11 +381,10 @@ var Annotation = /** @class */ (function () {
418
381
  * @param this
419
382
  * @param type The class to check
420
383
  */
421
- Annotation.getAllForClass = function (type) {
422
- var _this = this;
384
+ static getAllForClass(type) {
423
385
  return Annotations.getClassAnnotations(type)
424
- .filter(function (x) { return x.$metadataName === _this.getMetadataName(); });
425
- };
386
+ .filter(x => x.$metadataName === this.getMetadataName());
387
+ }
426
388
  /**
427
389
  * Get a single instance of this annotation class attached to the given class.
428
390
  * If called on a subclass of Annotation, it returns only annotations that match
@@ -431,9 +393,9 @@ var Annotation = /** @class */ (function () {
431
393
  * @param this
432
394
  * @param type
433
395
  */
434
- Annotation.getForClass = function (type) {
396
+ static getForClass(type) {
435
397
  return this.getAllForClass(type)[0];
436
- };
398
+ }
437
399
  /**
438
400
  * Get all instances of this annotation class attached to the given method.
439
401
  * If called on a subclass of Annotation, it returns only annotations that match
@@ -443,11 +405,10 @@ var Annotation = /** @class */ (function () {
443
405
  * @param type The class where the method is defined
444
406
  * @param methodName The name of the method to check
445
407
  */
446
- Annotation.getAllForMethod = function (type, methodName) {
447
- var _this = this;
408
+ static getAllForMethod(type, methodName) {
448
409
  return Annotations.getMethodAnnotations(type, methodName)
449
- .filter(function (x) { return x.$metadataName === _this.getMetadataName(); });
450
- };
410
+ .filter(x => x.$metadataName === this.getMetadataName());
411
+ }
451
412
  /**
452
413
  * Get one instance of this annotation class attached to the given method.
453
414
  * If called on a subclass of Annotation, it returns only annotations that match
@@ -457,9 +418,9 @@ var Annotation = /** @class */ (function () {
457
418
  * @param type The class where the method is defined
458
419
  * @param methodName The name of the method to check
459
420
  */
460
- Annotation.getForMethod = function (type, methodName) {
421
+ static getForMethod(type, methodName) {
461
422
  return this.getAllForMethod(type, methodName)[0];
462
- };
423
+ }
463
424
  /**
464
425
  * Get all instances of this annotation class attached to the given property.
465
426
  * If called on a subclass of Annotation, it returns only annotations that match
@@ -469,11 +430,10 @@ var Annotation = /** @class */ (function () {
469
430
  * @param type The class where the property is defined
470
431
  * @param propertyName The name of the property to check
471
432
  */
472
- Annotation.getAllForProperty = function (type, propertyName) {
473
- var _this = this;
433
+ static getAllForProperty(type, propertyName) {
474
434
  return Annotations.getPropertyAnnotations(type, propertyName)
475
- .filter(function (x) { return x.$metadataName === _this.getMetadataName(); });
476
- };
435
+ .filter(x => x.$metadataName === this.getMetadataName());
436
+ }
477
437
  /**
478
438
  * Get one instance of this annotation class attached to the given property.
479
439
  * If called on a subclass of Annotation, it returns only annotations that match
@@ -483,9 +443,9 @@ var Annotation = /** @class */ (function () {
483
443
  * @param type The class where the property is defined
484
444
  * @param propertyName The name of the property to check
485
445
  */
486
- Annotation.getForProperty = function (type, propertyName) {
446
+ static getForProperty(type, propertyName) {
487
447
  return this.getAllForProperty(type, propertyName)[0];
488
- };
448
+ }
489
449
  /**
490
450
  * Get all instances of this annotation class attached to the parameters of the given method.
491
451
  * If called on a subclass of Annotation, it returns only annotations that match
@@ -495,11 +455,10 @@ var Annotation = /** @class */ (function () {
495
455
  * @param type The class where the method is defined
496
456
  * @param methodName The name of the method where parameter annotations should be checked for
497
457
  */
498
- Annotation.getAllForParameters = function (type, methodName) {
499
- var _this = this;
458
+ static getAllForParameters(type, methodName) {
500
459
  return Annotations.getParameterAnnotations(type, methodName)
501
- .map(function (set) { return (set || []).filter(function (x) { return _this === Annotation ? true : (x.$metadataName === _this.getMetadataName()); }); });
502
- };
460
+ .map(set => (set || []).filter(x => this === Annotation ? true : (x.$metadataName === this.getMetadataName())));
461
+ }
503
462
  /**
504
463
  * Get all instances of this annotation class attached to the parameters of the constructor
505
464
  * for the given class.
@@ -509,168 +468,159 @@ var Annotation = /** @class */ (function () {
509
468
  * @param this
510
469
  * @param type The class where constructor parameter annotations should be checked for
511
470
  */
512
- Annotation.getAllForConstructorParameters = function (type) {
513
- var _this = this;
514
- var finalSet = new Array(type.length).fill(undefined);
515
- var annotations = Annotations.getConstructorParameterAnnotations(type)
516
- .map(function (set) { return (set || []).filter(function (x) { return _this === Annotation ? true : (x.$metadataName === _this.getMetadataName()); }); });
517
- for (var i = 0, max = annotations.length; i < max; ++i)
471
+ static getAllForConstructorParameters(type) {
472
+ let finalSet = new Array(type.length).fill(undefined);
473
+ let annotations = Annotations.getConstructorParameterAnnotations(type)
474
+ .map(set => (set || []).filter(x => this === Annotation ? true : (x.$metadataName === this.getMetadataName())));
475
+ for (let i = 0, max = annotations.length; i < max; ++i)
518
476
  finalSet[i] = annotations[i];
519
477
  return finalSet;
520
- };
521
- return Annotation;
522
- }());
478
+ }
479
+ }
523
480
  exports.Annotation = Annotation;
524
481
  /**
525
482
  * A helper class for managing annotations
526
483
  */
527
- var Annotations = /** @class */ (function () {
528
- function Annotations() {
529
- }
484
+ class Annotations {
530
485
  /**
531
486
  * Copy the annotations defined for one class onto another.
532
487
  * @param from The class to copy annotations from
533
488
  * @param to The class to copy annotations to
534
489
  */
535
- Annotations.copyClassAnnotations = function (from, to) {
536
- var annotations = Annotations.getClassAnnotations(from);
537
- annotations.forEach(function (x) { return Annotations.applyToClass(x, to); });
538
- };
490
+ static copyClassAnnotations(from, to) {
491
+ let annotations = Annotations.getClassAnnotations(from);
492
+ annotations.forEach(x => Annotations.applyToClass(x, to));
493
+ }
539
494
  /**
540
495
  * Apply this annotation to a given target.
541
496
  * @param target
542
497
  */
543
- Annotations.applyToClass = function (annotation, target) {
544
- var list = this.getOrCreateListForClass(target);
545
- var clone = this.clone(annotation);
498
+ static applyToClass(annotation, target) {
499
+ let list = this.getOrCreateListForClass(target);
500
+ let clone = this.clone(annotation);
546
501
  list.push(clone);
547
502
  if (Reflect.getOwnMetadata) {
548
- var reflectedAnnotations = Reflect.getOwnMetadata('annotations', target) || [];
549
- reflectedAnnotations.push({ toString: function () { return "" + clone.$metadataName; }, annotation: clone });
503
+ let reflectedAnnotations = Reflect.getOwnMetadata('annotations', target) || [];
504
+ reflectedAnnotations.push({ toString() { return `${clone.$metadataName}`; }, annotation: clone });
550
505
  Reflect.defineMetadata('annotations', reflectedAnnotations, target);
551
506
  }
552
507
  return clone;
553
- };
508
+ }
554
509
  /**
555
510
  * Apply this annotation instance to the given property.
556
511
  * @param target
557
512
  * @param name
558
513
  */
559
- Annotations.applyToProperty = function (annotation, target, name) {
560
- var list = this.getOrCreateListForProperty(target, name);
561
- var clone = this.clone(annotation);
514
+ static applyToProperty(annotation, target, name) {
515
+ let list = this.getOrCreateListForProperty(target, name);
516
+ let clone = this.clone(annotation);
562
517
  list.push(clone);
563
518
  if (Reflect.getOwnMetadata) {
564
- var reflectedAnnotations = Reflect.getOwnMetadata('propMetadata', target, name) || [];
565
- reflectedAnnotations.push({ toString: function () { return "" + clone.$metadataName; }, annotation: clone });
519
+ let reflectedAnnotations = Reflect.getOwnMetadata('propMetadata', target, name) || [];
520
+ reflectedAnnotations.push({ toString() { return `${clone.$metadataName}`; }, annotation: clone });
566
521
  Reflect.defineMetadata('propMetadata', reflectedAnnotations, target, name);
567
522
  }
568
523
  return clone;
569
- };
524
+ }
570
525
  /**
571
526
  * Apply this annotation instance to the given method.
572
527
  * @param target
573
528
  * @param name
574
529
  */
575
- Annotations.applyToMethod = function (annotation, target, name) {
576
- var list = this.getOrCreateListForMethod(target, name);
577
- var clone = Annotations.clone(annotation);
530
+ static applyToMethod(annotation, target, name) {
531
+ let list = this.getOrCreateListForMethod(target, name);
532
+ let clone = Annotations.clone(annotation);
578
533
  list.push(clone);
579
534
  if (Reflect.getOwnMetadata && target.constructor) {
580
- var meta = Reflect.getOwnMetadata('propMetadata', target.constructor) || {};
535
+ const meta = Reflect.getOwnMetadata('propMetadata', target.constructor) || {};
581
536
  meta[name] = (meta.hasOwnProperty(name) && meta[name]) || [];
582
- meta[name].unshift({ toString: function () { return "" + clone.$metadataName; }, annotation: clone });
537
+ meta[name].unshift({ toString() { return `${clone.$metadataName}`; }, annotation: clone });
583
538
  Reflect.defineMetadata('propMetadata', meta, target.constructor);
584
539
  }
585
540
  return clone;
586
- };
541
+ }
587
542
  /**
588
543
  * Apply this annotation instance to the given method parameter.
589
544
  * @param target
590
545
  * @param name
591
546
  * @param index
592
547
  */
593
- Annotations.applyToParameter = function (annotation, target, name, index) {
594
- var list = this.getOrCreateListForMethodParameters(target, name);
548
+ static applyToParameter(annotation, target, name, index) {
549
+ let list = this.getOrCreateListForMethodParameters(target, name);
595
550
  while (list.length < index)
596
551
  list.push(null);
597
- var paramList = list[index] || [];
598
- var clone = this.clone(annotation);
552
+ let paramList = list[index] || [];
553
+ let clone = this.clone(annotation);
599
554
  paramList.push(clone);
600
555
  list[index] = paramList;
601
556
  return clone;
602
- };
557
+ }
603
558
  /**
604
559
  * Apply this annotation instance to the given constructor parameter.
605
560
  * @param target
606
561
  * @param name
607
562
  * @param index
608
563
  */
609
- Annotations.applyToConstructorParameter = function (annotation, target, index) {
610
- var list = this.getOrCreateListForConstructorParameters(target);
564
+ static applyToConstructorParameter(annotation, target, index) {
565
+ let list = this.getOrCreateListForConstructorParameters(target);
611
566
  while (list.length < index)
612
567
  list.push(null);
613
- var paramList = list[index] || [];
614
- var clone = this.clone(annotation);
568
+ let paramList = list[index] || [];
569
+ let clone = this.clone(annotation);
615
570
  paramList.push(clone);
616
571
  list[index] = paramList;
617
572
  if (Reflect.getOwnMetadata) {
618
- var parameterList = Reflect.getOwnMetadata('parameters', target) || [];
573
+ let parameterList = Reflect.getOwnMetadata('parameters', target) || [];
619
574
  while (parameterList.length < index)
620
575
  parameterList.push(null);
621
- var parameterAnnotes = parameterList[index] || [];
576
+ let parameterAnnotes = parameterList[index] || [];
622
577
  parameterAnnotes.push(clone);
623
578
  parameterList[index] = parameterAnnotes;
624
579
  Reflect.defineMetadata('parameters', parameterList, target);
625
580
  }
626
581
  return clone;
627
- };
582
+ }
628
583
  /**
629
584
  * Clone the given Annotation instance into a new instance. This is not
630
585
  * a deep copy.
631
586
  *
632
587
  * @param annotation
633
588
  */
634
- Annotations.clone = function (annotation) {
589
+ static clone(annotation) {
635
590
  if (!annotation)
636
591
  return annotation;
637
592
  return Object.assign(Object.create(Object.getPrototypeOf(annotation)), annotation);
638
- };
593
+ }
639
594
  /**
640
595
  * Get all annotations (including from Angular and other compatible
641
596
  * frameworks).
642
597
  *
643
598
  * @param target The target to fetch annotations for
644
599
  */
645
- Annotations.getClassAnnotations = function (target) {
646
- var _this = this;
600
+ static getClassAnnotations(target) {
647
601
  return (this.getListForClass(target) || [])
648
- .map(function (x) { return _this.clone(x); });
649
- };
602
+ .map(x => this.clone(x));
603
+ }
650
604
  /**
651
605
  * Get all annotations (including from Angular and other compatible
652
606
  * frameworks).
653
607
  *
654
608
  * @param target The target to fetch annotations for
655
609
  */
656
- Annotations.getMethodAnnotations = function (target, methodName, isStatic) {
657
- var _this = this;
658
- if (isStatic === void 0) { isStatic = false; }
610
+ static getMethodAnnotations(target, methodName, isStatic = false) {
659
611
  return (this.getListForMethod(isStatic ? target : target.prototype, methodName) || [])
660
- .map(function (x) { return _this.clone(x); });
661
- };
612
+ .map(x => this.clone(x));
613
+ }
662
614
  /**
663
615
  * Get all annotations (including from Angular and other compatible
664
616
  * frameworks).
665
617
  *
666
618
  * @param target The target to fetch annotations for
667
619
  */
668
- Annotations.getPropertyAnnotations = function (target, methodName, isStatic) {
669
- var _this = this;
670
- if (isStatic === void 0) { isStatic = false; }
620
+ static getPropertyAnnotations(target, methodName, isStatic = false) {
671
621
  return (this.getListForProperty(isStatic ? target : target.prototype, methodName) || [])
672
- .map(function (x) { return _this.clone(x); });
673
- };
622
+ .map(x => this.clone(x));
623
+ }
674
624
  /**
675
625
  * Get the annotations defined on the parameters of the given method of the given
676
626
  * class.
@@ -680,12 +630,10 @@ var Annotations = /** @class */ (function () {
680
630
  * @param isStatic Whether `type` itself (isStatic = true), or `type.prototype` (isStatic = false) should be the target.
681
631
  * Note that passing true may indicate that the passed `type` is already the prototype of a class.
682
632
  */
683
- Annotations.getParameterAnnotations = function (type, methodName, isStatic) {
684
- var _this = this;
685
- if (isStatic === void 0) { isStatic = false; }
633
+ static getParameterAnnotations(type, methodName, isStatic = false) {
686
634
  return (this.getListForMethodParameters(isStatic ? type : type.prototype, methodName) || [])
687
- .map(function (set) { return set ? set.map(function (anno) { return _this.clone(anno); }) : []; });
688
- };
635
+ .map(set => set ? set.map(anno => this.clone(anno)) : []);
636
+ }
689
637
  /**
690
638
  * Get the annotations defined on the parameters of the given method of the given
691
639
  * class.
@@ -693,165 +641,137 @@ var Annotations = /** @class */ (function () {
693
641
  * @param type
694
642
  * @param methodName
695
643
  */
696
- Annotations.getConstructorParameterAnnotations = function (type) {
697
- var _this = this;
644
+ static getConstructorParameterAnnotations(type) {
698
645
  return (this.getListForConstructorParameters(type) || [])
699
- .map(function (set) { return set ? set.map(function (anno) { return _this.clone(anno); }) : []; });
700
- };
646
+ .map(set => set ? set.map(anno => this.clone(anno)) : []);
647
+ }
701
648
  /**
702
649
  * Get a list of annotations for the given class.
703
650
  * @param target
704
651
  */
705
- Annotations.getListForClass = function (target) {
652
+ static getListForClass(target) {
706
653
  if (!target)
707
654
  return [];
708
- var combinedSet = [];
709
- var superclass = Object.getPrototypeOf(target);
655
+ let combinedSet = [];
656
+ let superclass = Object.getPrototypeOf(target);
710
657
  if (superclass && superclass !== Function)
711
658
  combinedSet = combinedSet.concat(this.getListForClass(superclass));
712
659
  if (target.hasOwnProperty(exports.ANNOTATIONS_KEY))
713
660
  combinedSet = combinedSet.concat(target[exports.ANNOTATIONS_KEY] || []);
714
661
  return combinedSet;
715
- };
662
+ }
716
663
  /**
717
664
  * Get a list of own annotations for the given class, or create that list.
718
665
  * @param target
719
666
  */
720
- Annotations.getOrCreateListForClass = function (target) {
667
+ static getOrCreateListForClass(target) {
721
668
  if (!target.hasOwnProperty(exports.ANNOTATIONS_KEY))
722
669
  Object.defineProperty(target, exports.ANNOTATIONS_KEY, { enumerable: false, value: [] });
723
670
  return target[exports.ANNOTATIONS_KEY];
724
- };
671
+ }
725
672
  /**
726
673
  * Gets a map of the annotations defined on all properties of the given class/function. To get the annotations of instance fields,
727
674
  * make sure to use `Class.prototype`, otherwise static annotations are returned.
728
675
  */
729
- Annotations.getMapForClassProperties = function (target, mapToPopulate) {
730
- var e_1, _a;
731
- var combinedSet = mapToPopulate || {};
676
+ static getMapForClassProperties(target, mapToPopulate) {
677
+ let combinedSet = mapToPopulate || {};
732
678
  if (!target || target === Function)
733
679
  return combinedSet;
734
680
  this.getMapForClassProperties(Object.getPrototypeOf(target), combinedSet);
735
681
  if (target.hasOwnProperty(exports.PROPERTY_ANNOTATIONS_KEY)) {
736
- var ownMap = target[exports.PROPERTY_ANNOTATIONS_KEY] || {};
737
- try {
738
- for (var _b = (0, tslib_1.__values)(Object.keys(ownMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
739
- var key = _c.value;
740
- combinedSet[key] = (combinedSet[key] || []).concat(ownMap[key]);
741
- }
742
- }
743
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
744
- finally {
745
- try {
746
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
747
- }
748
- finally { if (e_1) throw e_1.error; }
749
- }
682
+ let ownMap = target[exports.PROPERTY_ANNOTATIONS_KEY] || {};
683
+ for (let key of Object.keys(ownMap))
684
+ combinedSet[key] = (combinedSet[key] || []).concat(ownMap[key]);
750
685
  }
751
686
  return combinedSet;
752
- };
753
- Annotations.getOrCreateMapForClassProperties = function (target) {
687
+ }
688
+ static getOrCreateMapForClassProperties(target) {
754
689
  if (!target.hasOwnProperty(exports.PROPERTY_ANNOTATIONS_KEY))
755
690
  Object.defineProperty(target, exports.PROPERTY_ANNOTATIONS_KEY, { enumerable: false, value: [] });
756
691
  return target[exports.PROPERTY_ANNOTATIONS_KEY];
757
- };
758
- Annotations.getListForProperty = function (target, propertyKey) {
759
- var map = this.getMapForClassProperties(target);
692
+ }
693
+ static getListForProperty(target, propertyKey) {
694
+ let map = this.getMapForClassProperties(target);
760
695
  if (!map)
761
696
  return null;
762
697
  return map[propertyKey];
763
- };
764
- Annotations.getOrCreateListForProperty = function (target, propertyKey) {
765
- var map = this.getOrCreateMapForClassProperties(target);
698
+ }
699
+ static getOrCreateListForProperty(target, propertyKey) {
700
+ let map = this.getOrCreateMapForClassProperties(target);
766
701
  if (!map[propertyKey])
767
702
  map[propertyKey] = [];
768
703
  return map[propertyKey];
769
- };
770
- Annotations.getOrCreateListForMethod = function (target, methodName) {
704
+ }
705
+ static getOrCreateListForMethod(target, methodName) {
771
706
  return this.getOrCreateListForProperty(target, methodName);
772
- };
773
- Annotations.getListForMethod = function (target, methodName) {
707
+ }
708
+ static getListForMethod(target, methodName) {
774
709
  return this.getListForProperty(target, methodName);
775
- };
710
+ }
776
711
  /**
777
712
  * Get a map of the annotations defined on all parameters of all methods of the given class/function.
778
713
  * To get instance methods, make sure to pass `Class.prototype`, otherwise the results are for static fields.
779
714
  */
780
- Annotations.getMapForMethodParameters = function (target, mapToPopulate) {
781
- var e_2, _a;
782
- var combinedMap = mapToPopulate || {};
715
+ static getMapForMethodParameters(target, mapToPopulate) {
716
+ let combinedMap = mapToPopulate || {};
783
717
  if (!target || target === Function)
784
718
  return combinedMap;
785
719
  // superclass/prototype
786
720
  this.getMapForMethodParameters(Object.getPrototypeOf(target), combinedMap);
787
721
  if (target.hasOwnProperty(exports.METHOD_PARAMETER_ANNOTATIONS_KEY)) {
788
- var ownMap = target[exports.METHOD_PARAMETER_ANNOTATIONS_KEY] || {};
789
- try {
790
- for (var _b = (0, tslib_1.__values)(Object.keys(ownMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
791
- var methodName = _c.value;
792
- var parameters = ownMap[methodName];
793
- var combinedMethodMap = combinedMap[methodName] || [];
794
- for (var i = 0, max = parameters.length; i < max; ++i) {
795
- combinedMethodMap[i] = (combinedMethodMap[i] || []).concat(parameters[i] || []);
796
- }
797
- combinedMap[methodName] = combinedMethodMap;
798
- }
799
- }
800
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
801
- finally {
802
- try {
803
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
722
+ let ownMap = target[exports.METHOD_PARAMETER_ANNOTATIONS_KEY] || {};
723
+ for (let methodName of Object.keys(ownMap)) {
724
+ let parameters = ownMap[methodName];
725
+ let combinedMethodMap = combinedMap[methodName] || [];
726
+ for (let i = 0, max = parameters.length; i < max; ++i) {
727
+ combinedMethodMap[i] = (combinedMethodMap[i] || []).concat(parameters[i] || []);
804
728
  }
805
- finally { if (e_2) throw e_2.error; }
729
+ combinedMap[methodName] = combinedMethodMap;
806
730
  }
807
731
  }
808
732
  return combinedMap;
809
- };
810
- Annotations.getOrCreateMapForMethodParameters = function (target) {
733
+ }
734
+ static getOrCreateMapForMethodParameters(target) {
811
735
  if (!target.hasOwnProperty(exports.METHOD_PARAMETER_ANNOTATIONS_KEY))
812
736
  Object.defineProperty(target, exports.METHOD_PARAMETER_ANNOTATIONS_KEY, { enumerable: false, value: [] });
813
737
  return target[exports.METHOD_PARAMETER_ANNOTATIONS_KEY];
814
- };
815
- Annotations.getListForMethodParameters = function (target, methodName) {
816
- var map = this.getMapForMethodParameters(target);
738
+ }
739
+ static getListForMethodParameters(target, methodName) {
740
+ let map = this.getMapForMethodParameters(target);
817
741
  if (!map)
818
742
  return null;
819
743
  return map[methodName];
820
- };
821
- Annotations.getOrCreateListForMethodParameters = function (target, methodName) {
822
- var map = this.getOrCreateMapForMethodParameters(target);
744
+ }
745
+ static getOrCreateListForMethodParameters(target, methodName) {
746
+ let map = this.getOrCreateMapForMethodParameters(target);
823
747
  if (!map[methodName])
824
748
  map[methodName] = [];
825
749
  return map[methodName];
826
- };
827
- Annotations.getOrCreateListForConstructorParameters = function (target) {
750
+ }
751
+ static getOrCreateListForConstructorParameters(target) {
828
752
  if (!target[exports.CONSTRUCTOR_PARAMETERS_ANNOTATIONS_KEY])
829
753
  Object.defineProperty(target, exports.CONSTRUCTOR_PARAMETERS_ANNOTATIONS_KEY, { enumerable: false, value: [] });
830
754
  return target[exports.CONSTRUCTOR_PARAMETERS_ANNOTATIONS_KEY];
831
- };
832
- Annotations.getListForConstructorParameters = function (target) {
755
+ }
756
+ static getListForConstructorParameters(target) {
833
757
  return target[exports.CONSTRUCTOR_PARAMETERS_ANNOTATIONS_KEY];
834
- };
835
- return Annotations;
836
- }());
758
+ }
759
+ }
837
760
  exports.Annotations = Annotations;
838
761
  /**
839
762
  * An annotation for attaching a label to a programmatic element.
840
763
  * Can be queried with LabelAnnotation.getForClass() for example.
841
764
  */
842
- var LabelAnnotation = /** @class */ (function (_super) {
843
- (0, tslib_1.__extends)(LabelAnnotation, _super);
844
- function LabelAnnotation(text) {
845
- var _this = _super.call(this) || this;
846
- _this.text = text;
847
- return _this;
848
- }
849
- LabelAnnotation = (0, tslib_1.__decorate)([
850
- MetadataName('alterior:Label'),
851
- (0, tslib_1.__metadata)("design:paramtypes", [String])
852
- ], LabelAnnotation);
853
- return LabelAnnotation;
854
- }(Annotation));
765
+ let LabelAnnotation = class LabelAnnotation extends Annotation {
766
+ constructor(text) {
767
+ super();
768
+ this.text = text;
769
+ }
770
+ };
771
+ LabelAnnotation = (0, tslib_1.__decorate)([
772
+ MetadataName('alterior:Label'),
773
+ (0, tslib_1.__metadata)("design:paramtypes", [String])
774
+ ], LabelAnnotation);
855
775
  exports.LabelAnnotation = LabelAnnotation;
856
776
  exports.Label = LabelAnnotation.decorator();
857
777
  //# sourceMappingURL=annotations.js.map