@alterior/annotations 3.13.3 → 3.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,385 +1,385 @@
1
- /**
2
- * @alterior/annotations
3
- * A class library for handling Typescript metadata decorators via "annotation" classes
4
- *
5
- * (C) 2017-2019 William Lahti
6
- *
7
- */
8
- import { NotSupportedError } from '@alterior/common';
9
- /**
10
- * Represents an annotation which could be stored in the standard annotation lists
11
- * on a class.
12
- */
13
- export interface IAnnotation {
14
- $metadataName?: string;
15
- }
16
- export declare const ANNOTATIONS_KEY = "__annotations__";
17
- export declare const CONSTRUCTOR_PARAMETERS_ANNOTATIONS_KEY = "__parameters__";
18
- export declare const PROPERTY_ANNOTATIONS_KEY = "__prop__metadata__";
19
- export declare const METHOD_PARAMETER_ANNOTATIONS_KEY = "__parameter__metadata__";
20
- /**
21
- * Represents an Annotation subclass from the perspective of using it to
22
- * construct itself by passing an options object.
23
- */
24
- interface AnnotationConstructor<AnnoT extends Annotation, TS extends any[]> {
25
- new (...args: TS): AnnoT;
26
- getMetadataName(): any;
27
- }
28
- export type AnnotationClassDecorator<TS extends any[]> = (...args: TS) => ((target: any) => void);
29
- export type AnnotationPropertyDecorator<TS extends any[]> = (...args: TS) => ((target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void);
30
- export type AnnotationMethodDecorator<TS extends any[]> = (...args: TS) => ((target: any, propertyKey: string | symbol) => void);
31
- export type AnnotationParameterDecorator<TS extends any[]> = (...args: TS) => ((target: any, propertyKey: string | symbol, index: number) => void);
32
- type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
33
- type DecoratorTypeUnionForValidTargets<Targets> = Targets extends 'class' ? ClassDecorator : Targets extends 'method' ? MethodDecorator : Targets extends 'property' ? PropertyDecorator : Targets extends 'parameter' ? ParameterDecorator : never;
34
- type DecoratorTypeForValidTargets<Targets> = UnionToIntersection<DecoratorTypeUnionForValidTargets<Targets>>;
35
- /**
36
- * Represents a decorator which accepts an Annotation's options object.
37
- */
38
- export type AnnotationDecorator<TS extends any[]> = (...args: TS) => ClassDecorator & PropertyDecorator & MethodDecorator & ParameterDecorator;
39
- export interface DecoratorSite {
40
- type: 'class' | 'method' | 'property' | 'parameter';
41
- target: any;
42
- propertyKey?: string;
43
- propertyDescriptor?: PropertyDescriptor;
44
- index?: number;
45
- }
46
- export type AnnotationDecoratorTarget = 'class' | 'property' | 'method' | 'parameter';
47
- export interface AnnotationDecoratorOptions<AnnoT, TS extends any[] = []> {
48
- factory?: (target: DecoratorSite, ...args: TS) => AnnoT | void;
49
- validTargets?: AnnotationDecoratorTarget[];
50
- allowMultiple?: boolean;
51
- }
52
- /**
53
- * Thrown when a caller attempts to decorate an annotation target when the
54
- * annotation does not support that target.
55
- */
56
- export declare class AnnotationTargetError extends NotSupportedError {
57
- constructor(annotationClass: any, invalidType: string, supportedTypes: string[], message?: string);
58
- private _invalidType;
59
- private _annotationClass;
60
- private _supportedTypes;
61
- get invalidType(): string;
62
- get supportedTypes(): string[];
63
- get annotationClass(): Function;
64
- }
65
- export declare function MetadataName(name: string): (target: any) => any;
66
- export interface MutatorDefinition {
67
- invoke: (site: DecoratorSite) => void;
68
- options?: AnnotationDecoratorOptions<void>;
69
- }
70
- /**
71
- * Represents a metadata annotation which can be applied to classes,
72
- * constructor parameters, methods, properties, or method parameters
73
- * via decorators.
74
- *
75
- * Custom annotations are defined as subclasses of this class.
76
- * By convention, all custom annotation classes should have a name
77
- * which ends in "Annotation" such as "NameAnnotation".
78
- *
79
- * To create a new annotation create a subclass of `Annotation`
80
- * with a constructor that takes the parameters you are interested in
81
- * storing, and save the appropriate information onto fields of the
82
- * new instance. For your convenience, Annotation provides a default
83
- * constructor which takes a map object and applies its properties onto
84
- * the current instance, but you may replace it with a constructor that
85
- * takes any arguments you wish.
86
- *
87
- * You may wish to add type safety to the default constructor parameter.
88
- * To do so, override the constructor and define it:
89
- *
90
- ```
91
- class XYZ extends Annotation {
92
- constructor(
93
- options : MyOptions
94
- ) {
95
- super(options);
96
- }
97
- }
98
- ```
99
- *
100
- * Annotations are applied by using decorators.
101
- * When you define a custom annotation, you must also define a
102
- * custom decorator:
103
- *
104
- ```
105
- const Name =
106
- NameAnnotation.decorator();
107
- ```
108
- * You can then use that decorator:
109
- ```
110
- @Name()
111
- class ABC {
112
- // ...
113
- }
114
- ```
115
- *
116
- */
117
- export declare class Annotation implements IAnnotation {
118
- constructor(props?: any);
119
- readonly $metadataName: string;
120
- toString(): string;
121
- static getMetadataName(): string;
122
- /**
123
- * Construct a decorator suitable for attaching annotations of the called type
124
- * onto classes, constructor parameters, methods, properties, and parameters.
125
- * Must be called while referencing the subclass of Annotation you wish to construct
126
- * the decorator for. E.g., for FooAnnotation, call FooAnnotation.decorator().
127
- *
128
- * @param this The Annotation subclass for which the decorator is being constructed
129
- * @param options Allows for specifying options which will modify the behavior of the decorator.
130
- * See the DecoratorOptions documentation for more information.
131
- */
132
- static decorator<T extends Annotation, TS extends any[], U extends AnnotationDecoratorTarget>(this: AnnotationConstructor<T, TS>, options?: Exclude<AnnotationDecoratorOptions<T, TS>, 'validTargets'> & {
133
- validTargets: U[];
134
- }): (...args: TS) => DecoratorTypeForValidTargets<U>;
135
- static decorator<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, options?: AnnotationDecoratorOptions<T, TS>): AnnotationDecorator<TS>;
136
- /**
137
- * Clone this annotation instance into a new one. This is not a deep copy.
138
- */
139
- clone(): this;
140
- /**
141
- * Apply this annotation to a given target.
142
- * @param target
143
- */
144
- applyToClass(target: any): this;
145
- /**
146
- * Apply this annotation instance to the given property.
147
- * @param target
148
- * @param name
149
- */
150
- applyToProperty(target: any, name: string): this;
151
- /**
152
- * Apply this annotation instance to the given method.
153
- * @param target
154
- * @param name
155
- */
156
- applyToMethod(target: any, name: string): this;
157
- /**
158
- * Apply this annotation instance to the given method parameter.
159
- * @param target
160
- * @param name
161
- * @param index
162
- */
163
- applyToParameter(target: any, name: string, index: number): this;
164
- /**
165
- * Apply this annotation instance to the given constructor parameter.
166
- * @param target
167
- * @param name
168
- * @param index
169
- */
170
- applyToConstructorParameter(target: any, index: number): this;
171
- /**
172
- * Filter the given list of annotations for the ones which match this annotation class
173
- * based on matching $metadataName.
174
- *
175
- * @param this
176
- * @param annotations
177
- */
178
- static filter<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, annotations: IAnnotation[]): T[];
179
- /**
180
- * Get all instances of this annotation class attached to the given class.
181
- * If called on a subclass of Annotation, it returns only annotations that match
182
- * that subclass.
183
- * @param this
184
- * @param type The class to check
185
- */
186
- static getAllForClass<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any): T[];
187
- /**
188
- * Get a single instance of this annotation class attached to the given class.
189
- * If called on a subclass of Annotation, it returns only annotations that match
190
- * that subclass.
191
- *
192
- * @param this
193
- * @param type
194
- */
195
- static getForClass<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any): T;
196
- /**
197
- * Get all instances of this annotation class attached to the given method.
198
- * If called on a subclass of Annotation, it returns only annotations that match
199
- * that subclass.
200
- *
201
- * @param this
202
- * @param type The class where the method is defined
203
- * @param methodName The name of the method to check
204
- */
205
- static getAllForMethod<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, methodName: string): T[];
206
- /**
207
- * Get one instance of this annotation class attached to the given method.
208
- * If called on a subclass of Annotation, it returns only annotations that match
209
- * that subclass.
210
- *
211
- * @param this
212
- * @param type The class where the method is defined
213
- * @param methodName The name of the method to check
214
- */
215
- static getForMethod<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, methodName: string): T;
216
- /**
217
- * Get all instances of this annotation class attached to the given property.
218
- * If called on a subclass of Annotation, it returns only annotations that match
219
- * that subclass.
220
- *
221
- * @param this
222
- * @param type The class where the property is defined
223
- * @param propertyName The name of the property to check
224
- */
225
- static getAllForProperty<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, propertyName: string): T[];
226
- /**
227
- * Get one instance of this annotation class attached to the given property.
228
- * If called on a subclass of Annotation, it returns only annotations that match
229
- * that subclass.
230
- *
231
- * @param this
232
- * @param type The class where the property is defined
233
- * @param propertyName The name of the property to check
234
- */
235
- static getForProperty<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, propertyName: string): T;
236
- /**
237
- * Get all instances of this annotation class attached to the parameters of the given method.
238
- * If called on a subclass of Annotation, it returns only annotations that match
239
- * that subclass.
240
- *
241
- * @param this
242
- * @param type The class where the method is defined
243
- * @param methodName The name of the method where parameter annotations should be checked for
244
- */
245
- static getAllForParameters<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, methodName: string): T[][];
246
- /**
247
- * Get all instances of this annotation class attached to the parameters of the constructor
248
- * for the given class.
249
- * If called on a subclass of Annotation, it returns only annotations that match
250
- * that subclass.
251
- *
252
- * @param this
253
- * @param type The class where constructor parameter annotations should be checked for
254
- */
255
- static getAllForConstructorParameters<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any): T[][];
256
- }
257
- /**
258
- * A helper class for managing annotations
259
- */
260
- export declare class Annotations {
261
- /**
262
- * Copy the annotations defined for one class onto another.
263
- * @param from The class to copy annotations from
264
- * @param to The class to copy annotations to
265
- */
266
- static copyClassAnnotations(from: Function, to: Function): void;
267
- /**
268
- * Apply this annotation to a given target.
269
- * @param target
270
- */
271
- static applyToClass<T extends IAnnotation>(annotation: T, target: any): T;
272
- /**
273
- * Apply this annotation instance to the given property.
274
- * @param target
275
- * @param name
276
- */
277
- static applyToProperty<T extends IAnnotation>(annotation: T, target: any, name: string): T;
278
- /**
279
- * Apply this annotation instance to the given method.
280
- * @param target
281
- * @param name
282
- */
283
- static applyToMethod<T extends IAnnotation>(annotation: T, target: any, name: string): T;
284
- /**
285
- * Apply this annotation instance to the given method parameter.
286
- * @param target
287
- * @param name
288
- * @param index
289
- */
290
- static applyToParameter<T extends IAnnotation>(annotation: T, target: any, name: string, index: number): T;
291
- /**
292
- * Apply this annotation instance to the given constructor parameter.
293
- * @param target
294
- * @param name
295
- * @param index
296
- */
297
- static applyToConstructorParameter<T extends IAnnotation>(annotation: T, target: any, index: number): T;
298
- /**
299
- * Clone the given Annotation instance into a new instance. This is not
300
- * a deep copy.
301
- *
302
- * @param annotation
303
- */
304
- static clone<T extends IAnnotation>(annotation: T): T;
305
- /**
306
- * Get all annotations (including from Angular and other compatible
307
- * frameworks).
308
- *
309
- * @param target The target to fetch annotations for
310
- */
311
- static getClassAnnotations(target: any): IAnnotation[];
312
- /**
313
- * Get all annotations (including from Angular and other compatible
314
- * frameworks).
315
- *
316
- * @param target The target to fetch annotations for
317
- */
318
- static getMethodAnnotations(target: any, methodName: string, isStatic?: boolean): IAnnotation[];
319
- /**
320
- * Get all annotations (including from Angular and other compatible
321
- * frameworks).
322
- *
323
- * @param target The target to fetch annotations for
324
- */
325
- static getPropertyAnnotations(target: any, methodName: string, isStatic?: boolean): IAnnotation[];
326
- /**
327
- * Get the annotations defined on the parameters of the given method of the given
328
- * class.
329
- *
330
- * @param type
331
- * @param methodName
332
- * @param isStatic Whether `type` itself (isStatic = true), or `type.prototype` (isStatic = false) should be the target.
333
- * Note that passing true may indicate that the passed `type` is already the prototype of a class.
334
- */
335
- static getParameterAnnotations(type: any, methodName: string, isStatic?: boolean): IAnnotation[][];
336
- /**
337
- * Get the annotations defined on the parameters of the given method of the given
338
- * class.
339
- *
340
- * @param type
341
- * @param methodName
342
- */
343
- static getConstructorParameterAnnotations(type: any): IAnnotation[][];
344
- /**
345
- * Get a list of annotations for the given class.
346
- * @param target
347
- */
348
- private static getListForClass;
349
- /**
350
- * Get a list of own annotations for the given class, or create that list.
351
- * @param target
352
- */
353
- private static getOrCreateListForClass;
354
- /**
355
- * Gets a map of the annotations defined on all properties of the given class/function. To get the annotations of instance fields,
356
- * make sure to use `Class.prototype`, otherwise static annotations are returned.
357
- */
358
- static getMapForClassProperties(target: Object, mapToPopulate?: Record<string, IAnnotation[]>): Record<string, IAnnotation[]>;
359
- private static getOrCreateMapForClassProperties;
360
- private static getListForProperty;
361
- private static getOrCreateListForProperty;
362
- private static getOrCreateListForMethod;
363
- private static getListForMethod;
364
- /**
365
- * Get a map of the annotations defined on all parameters of all methods of the given class/function.
366
- * To get instance methods, make sure to pass `Class.prototype`, otherwise the results are for static fields.
367
- */
368
- static getMapForMethodParameters(target: Object, mapToPopulate?: Record<string, IAnnotation[][]>): Record<string, IAnnotation[][]>;
369
- private static getOrCreateMapForMethodParameters;
370
- private static getListForMethodParameters;
371
- private static getOrCreateListForMethodParameters;
372
- private static getOrCreateListForConstructorParameters;
373
- private static getListForConstructorParameters;
374
- }
375
- /**
376
- * An annotation for attaching a label to a programmatic element.
377
- * Can be queried with LabelAnnotation.getForClass() for example.
378
- */
379
- export declare class LabelAnnotation extends Annotation {
380
- readonly text: string;
381
- constructor(text: string);
382
- }
383
- export declare const Label: (text: string) => ClassDecorator & PropertyDecorator & MethodDecorator & ParameterDecorator;
384
- export {};
1
+ /**
2
+ * @alterior/annotations
3
+ * A class library for handling Typescript metadata decorators via "annotation" classes
4
+ *
5
+ * (C) 2017-2019 William Lahti
6
+ *
7
+ */
8
+ import { NotSupportedError } from '@alterior/common';
9
+ /**
10
+ * Represents an annotation which could be stored in the standard annotation lists
11
+ * on a class.
12
+ */
13
+ export interface IAnnotation {
14
+ $metadataName?: string;
15
+ }
16
+ export declare const ANNOTATIONS_KEY = "__annotations__";
17
+ export declare const CONSTRUCTOR_PARAMETERS_ANNOTATIONS_KEY = "__parameters__";
18
+ export declare const PROPERTY_ANNOTATIONS_KEY = "__prop__metadata__";
19
+ export declare const METHOD_PARAMETER_ANNOTATIONS_KEY = "__parameter__metadata__";
20
+ /**
21
+ * Represents an Annotation subclass from the perspective of using it to
22
+ * construct itself by passing an options object.
23
+ */
24
+ interface AnnotationConstructor<AnnoT extends Annotation, TS extends any[]> {
25
+ new (...args: TS): AnnoT;
26
+ getMetadataName(): any;
27
+ }
28
+ export type AnnotationClassDecorator<TS extends any[]> = (...args: TS) => ((target: any) => void);
29
+ export type AnnotationPropertyDecorator<TS extends any[]> = (...args: TS) => ((target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void);
30
+ export type AnnotationMethodDecorator<TS extends any[]> = (...args: TS) => ((target: any, propertyKey: string | symbol) => void);
31
+ export type AnnotationParameterDecorator<TS extends any[]> = (...args: TS) => ((target: any, propertyKey: string | symbol, index: number) => void);
32
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
33
+ type DecoratorTypeUnionForValidTargets<Targets> = Targets extends 'class' ? ClassDecorator : Targets extends 'method' ? MethodDecorator : Targets extends 'property' ? PropertyDecorator : Targets extends 'parameter' ? ParameterDecorator : never;
34
+ type DecoratorTypeForValidTargets<Targets> = UnionToIntersection<DecoratorTypeUnionForValidTargets<Targets>>;
35
+ /**
36
+ * Represents a decorator which accepts an Annotation's options object.
37
+ */
38
+ export type AnnotationDecorator<TS extends any[]> = (...args: TS) => ClassDecorator & PropertyDecorator & MethodDecorator & ParameterDecorator;
39
+ export interface DecoratorSite {
40
+ type: 'class' | 'method' | 'property' | 'parameter';
41
+ target: any;
42
+ propertyKey?: string;
43
+ propertyDescriptor?: PropertyDescriptor;
44
+ index?: number;
45
+ }
46
+ export type AnnotationDecoratorTarget = 'class' | 'property' | 'method' | 'parameter';
47
+ export interface AnnotationDecoratorOptions<AnnoT, TS extends any[] = []> {
48
+ factory?: (target: DecoratorSite, ...args: TS) => AnnoT | void;
49
+ validTargets?: AnnotationDecoratorTarget[];
50
+ allowMultiple?: boolean;
51
+ }
52
+ /**
53
+ * Thrown when a caller attempts to decorate an annotation target when the
54
+ * annotation does not support that target.
55
+ */
56
+ export declare class AnnotationTargetError extends NotSupportedError {
57
+ constructor(annotationClass: any, invalidType: string, supportedTypes: string[], message?: string);
58
+ private _invalidType;
59
+ private _annotationClass;
60
+ private _supportedTypes;
61
+ get invalidType(): string;
62
+ get supportedTypes(): string[];
63
+ get annotationClass(): Function;
64
+ }
65
+ export declare function MetadataName(name: string): (target: any) => any;
66
+ export interface MutatorDefinition {
67
+ invoke: (site: DecoratorSite) => void;
68
+ options?: AnnotationDecoratorOptions<void>;
69
+ }
70
+ /**
71
+ * Represents a metadata annotation which can be applied to classes,
72
+ * constructor parameters, methods, properties, or method parameters
73
+ * via decorators.
74
+ *
75
+ * Custom annotations are defined as subclasses of this class.
76
+ * By convention, all custom annotation classes should have a name
77
+ * which ends in "Annotation" such as "NameAnnotation".
78
+ *
79
+ * To create a new annotation create a subclass of `Annotation`
80
+ * with a constructor that takes the parameters you are interested in
81
+ * storing, and save the appropriate information onto fields of the
82
+ * new instance. For your convenience, Annotation provides a default
83
+ * constructor which takes a map object and applies its properties onto
84
+ * the current instance, but you may replace it with a constructor that
85
+ * takes any arguments you wish.
86
+ *
87
+ * You may wish to add type safety to the default constructor parameter.
88
+ * To do so, override the constructor and define it:
89
+ *
90
+ ```
91
+ class XYZ extends Annotation {
92
+ constructor(
93
+ options : MyOptions
94
+ ) {
95
+ super(options);
96
+ }
97
+ }
98
+ ```
99
+ *
100
+ * Annotations are applied by using decorators.
101
+ * When you define a custom annotation, you must also define a
102
+ * custom decorator:
103
+ *
104
+ ```
105
+ const Name =
106
+ NameAnnotation.decorator();
107
+ ```
108
+ * You can then use that decorator:
109
+ ```
110
+ @Name()
111
+ class ABC {
112
+ // ...
113
+ }
114
+ ```
115
+ *
116
+ */
117
+ export declare class Annotation implements IAnnotation {
118
+ constructor(props?: any);
119
+ readonly $metadataName: string;
120
+ toString(): string;
121
+ static getMetadataName(): string;
122
+ /**
123
+ * Construct a decorator suitable for attaching annotations of the called type
124
+ * onto classes, constructor parameters, methods, properties, and parameters.
125
+ * Must be called while referencing the subclass of Annotation you wish to construct
126
+ * the decorator for. E.g., for FooAnnotation, call FooAnnotation.decorator().
127
+ *
128
+ * @param this The Annotation subclass for which the decorator is being constructed
129
+ * @param options Allows for specifying options which will modify the behavior of the decorator.
130
+ * See the DecoratorOptions documentation for more information.
131
+ */
132
+ static decorator<T extends Annotation, TS extends any[], U extends AnnotationDecoratorTarget>(this: AnnotationConstructor<T, TS>, options?: Exclude<AnnotationDecoratorOptions<T, TS>, 'validTargets'> & {
133
+ validTargets: U[];
134
+ }): (...args: TS) => DecoratorTypeForValidTargets<U>;
135
+ static decorator<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, options?: AnnotationDecoratorOptions<T, TS>): AnnotationDecorator<TS>;
136
+ /**
137
+ * Clone this annotation instance into a new one. This is not a deep copy.
138
+ */
139
+ clone(): this;
140
+ /**
141
+ * Apply this annotation to a given target.
142
+ * @param target
143
+ */
144
+ applyToClass(target: any): this;
145
+ /**
146
+ * Apply this annotation instance to the given property.
147
+ * @param target
148
+ * @param name
149
+ */
150
+ applyToProperty(target: any, name: string): this;
151
+ /**
152
+ * Apply this annotation instance to the given method.
153
+ * @param target
154
+ * @param name
155
+ */
156
+ applyToMethod(target: any, name: string): this;
157
+ /**
158
+ * Apply this annotation instance to the given method parameter.
159
+ * @param target
160
+ * @param name
161
+ * @param index
162
+ */
163
+ applyToParameter(target: any, name: string, index: number): this;
164
+ /**
165
+ * Apply this annotation instance to the given constructor parameter.
166
+ * @param target
167
+ * @param name
168
+ * @param index
169
+ */
170
+ applyToConstructorParameter(target: any, index: number): this;
171
+ /**
172
+ * Filter the given list of annotations for the ones which match this annotation class
173
+ * based on matching $metadataName.
174
+ *
175
+ * @param this
176
+ * @param annotations
177
+ */
178
+ static filter<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, annotations: IAnnotation[]): T[];
179
+ /**
180
+ * Get all instances of this annotation class attached to the given class.
181
+ * If called on a subclass of Annotation, it returns only annotations that match
182
+ * that subclass.
183
+ * @param this
184
+ * @param type The class to check
185
+ */
186
+ static getAllForClass<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any): T[];
187
+ /**
188
+ * Get a single instance of this annotation class attached to the given class.
189
+ * If called on a subclass of Annotation, it returns only annotations that match
190
+ * that subclass.
191
+ *
192
+ * @param this
193
+ * @param type
194
+ */
195
+ static getForClass<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any): T;
196
+ /**
197
+ * Get all instances of this annotation class attached to the given method.
198
+ * If called on a subclass of Annotation, it returns only annotations that match
199
+ * that subclass.
200
+ *
201
+ * @param this
202
+ * @param type The class where the method is defined
203
+ * @param methodName The name of the method to check
204
+ */
205
+ static getAllForMethod<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, methodName: string): T[];
206
+ /**
207
+ * Get one instance of this annotation class attached to the given method.
208
+ * If called on a subclass of Annotation, it returns only annotations that match
209
+ * that subclass.
210
+ *
211
+ * @param this
212
+ * @param type The class where the method is defined
213
+ * @param methodName The name of the method to check
214
+ */
215
+ static getForMethod<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, methodName: string): T;
216
+ /**
217
+ * Get all instances of this annotation class attached to the given property.
218
+ * If called on a subclass of Annotation, it returns only annotations that match
219
+ * that subclass.
220
+ *
221
+ * @param this
222
+ * @param type The class where the property is defined
223
+ * @param propertyName The name of the property to check
224
+ */
225
+ static getAllForProperty<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, propertyName: string): T[];
226
+ /**
227
+ * Get one instance of this annotation class attached to the given property.
228
+ * If called on a subclass of Annotation, it returns only annotations that match
229
+ * that subclass.
230
+ *
231
+ * @param this
232
+ * @param type The class where the property is defined
233
+ * @param propertyName The name of the property to check
234
+ */
235
+ static getForProperty<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, propertyName: string): T;
236
+ /**
237
+ * Get all instances of this annotation class attached to the parameters of the given method.
238
+ * If called on a subclass of Annotation, it returns only annotations that match
239
+ * that subclass.
240
+ *
241
+ * @param this
242
+ * @param type The class where the method is defined
243
+ * @param methodName The name of the method where parameter annotations should be checked for
244
+ */
245
+ static getAllForParameters<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any, methodName: string): T[][];
246
+ /**
247
+ * Get all instances of this annotation class attached to the parameters of the constructor
248
+ * for the given class.
249
+ * If called on a subclass of Annotation, it returns only annotations that match
250
+ * that subclass.
251
+ *
252
+ * @param this
253
+ * @param type The class where constructor parameter annotations should be checked for
254
+ */
255
+ static getAllForConstructorParameters<T extends Annotation, TS extends any[]>(this: AnnotationConstructor<T, TS>, type: any): T[][];
256
+ }
257
+ /**
258
+ * A helper class for managing annotations
259
+ */
260
+ export declare class Annotations {
261
+ /**
262
+ * Copy the annotations defined for one class onto another.
263
+ * @param from The class to copy annotations from
264
+ * @param to The class to copy annotations to
265
+ */
266
+ static copyClassAnnotations(from: Function, to: Function): void;
267
+ /**
268
+ * Apply this annotation to a given target.
269
+ * @param target
270
+ */
271
+ static applyToClass<T extends IAnnotation>(annotation: T, target: any): T;
272
+ /**
273
+ * Apply this annotation instance to the given property.
274
+ * @param target
275
+ * @param name
276
+ */
277
+ static applyToProperty<T extends IAnnotation>(annotation: T, target: any, name: string): T;
278
+ /**
279
+ * Apply this annotation instance to the given method.
280
+ * @param target
281
+ * @param name
282
+ */
283
+ static applyToMethod<T extends IAnnotation>(annotation: T, target: any, name: string): T;
284
+ /**
285
+ * Apply this annotation instance to the given method parameter.
286
+ * @param target
287
+ * @param name
288
+ * @param index
289
+ */
290
+ static applyToParameter<T extends IAnnotation>(annotation: T, target: any, name: string, index: number): T;
291
+ /**
292
+ * Apply this annotation instance to the given constructor parameter.
293
+ * @param target
294
+ * @param name
295
+ * @param index
296
+ */
297
+ static applyToConstructorParameter<T extends IAnnotation>(annotation: T, target: any, index: number): T;
298
+ /**
299
+ * Clone the given Annotation instance into a new instance. This is not
300
+ * a deep copy.
301
+ *
302
+ * @param annotation
303
+ */
304
+ static clone<T extends IAnnotation>(annotation: T): T;
305
+ /**
306
+ * Get all annotations (including from Angular and other compatible
307
+ * frameworks).
308
+ *
309
+ * @param target The target to fetch annotations for
310
+ */
311
+ static getClassAnnotations(target: any): IAnnotation[];
312
+ /**
313
+ * Get all annotations (including from Angular and other compatible
314
+ * frameworks).
315
+ *
316
+ * @param target The target to fetch annotations for
317
+ */
318
+ static getMethodAnnotations(target: any, methodName: string, isStatic?: boolean): IAnnotation[];
319
+ /**
320
+ * Get all annotations (including from Angular and other compatible
321
+ * frameworks).
322
+ *
323
+ * @param target The target to fetch annotations for
324
+ */
325
+ static getPropertyAnnotations(target: any, methodName: string, isStatic?: boolean): IAnnotation[];
326
+ /**
327
+ * Get the annotations defined on the parameters of the given method of the given
328
+ * class.
329
+ *
330
+ * @param type
331
+ * @param methodName
332
+ * @param isStatic Whether `type` itself (isStatic = true), or `type.prototype` (isStatic = false) should be the target.
333
+ * Note that passing true may indicate that the passed `type` is already the prototype of a class.
334
+ */
335
+ static getParameterAnnotations(type: any, methodName: string, isStatic?: boolean): IAnnotation[][];
336
+ /**
337
+ * Get the annotations defined on the parameters of the given method of the given
338
+ * class.
339
+ *
340
+ * @param type
341
+ * @param methodName
342
+ */
343
+ static getConstructorParameterAnnotations(type: any): IAnnotation[][];
344
+ /**
345
+ * Get a list of annotations for the given class.
346
+ * @param target
347
+ */
348
+ private static getListForClass;
349
+ /**
350
+ * Get a list of own annotations for the given class, or create that list.
351
+ * @param target
352
+ */
353
+ private static getOrCreateListForClass;
354
+ /**
355
+ * Gets a map of the annotations defined on all properties of the given class/function. To get the annotations of instance fields,
356
+ * make sure to use `Class.prototype`, otherwise static annotations are returned.
357
+ */
358
+ static getMapForClassProperties(target: Object, mapToPopulate?: Record<string, IAnnotation[]>): Record<string, IAnnotation[]>;
359
+ private static getOrCreateMapForClassProperties;
360
+ private static getListForProperty;
361
+ private static getOrCreateListForProperty;
362
+ private static getOrCreateListForMethod;
363
+ private static getListForMethod;
364
+ /**
365
+ * Get a map of the annotations defined on all parameters of all methods of the given class/function.
366
+ * To get instance methods, make sure to pass `Class.prototype`, otherwise the results are for static fields.
367
+ */
368
+ static getMapForMethodParameters(target: Object, mapToPopulate?: Record<string, IAnnotation[][]>): Record<string, IAnnotation[][]>;
369
+ private static getOrCreateMapForMethodParameters;
370
+ private static getListForMethodParameters;
371
+ private static getOrCreateListForMethodParameters;
372
+ private static getOrCreateListForConstructorParameters;
373
+ private static getListForConstructorParameters;
374
+ }
375
+ /**
376
+ * An annotation for attaching a label to a programmatic element.
377
+ * Can be queried with LabelAnnotation.getForClass() for example.
378
+ */
379
+ export declare class LabelAnnotation extends Annotation {
380
+ readonly text: string;
381
+ constructor(text: string);
382
+ }
383
+ export declare const Label: (text: string) => ClassDecorator & PropertyDecorator & MethodDecorator & ParameterDecorator;
384
+ export {};
385
385
  //# sourceMappingURL=annotations.d.ts.map