@loopback/metadata 4.0.0-alpha.7 → 4.0.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.
Files changed (97) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +273 -150
  3. package/dist/decorator-factory.d.ts +297 -0
  4. package/{dist6/src → dist}/decorator-factory.js +197 -90
  5. package/dist/decorator-factory.js.map +1 -0
  6. package/dist/index.d.ts +22 -1
  7. package/dist/index.js +24 -7
  8. package/dist/index.js.map +1 -0
  9. package/dist/inspector.d.ts +120 -0
  10. package/dist/inspector.js +186 -0
  11. package/dist/inspector.js.map +1 -0
  12. package/dist/{src/reflect.d.ts → reflect.d.ts} +16 -15
  13. package/dist/{src/reflect.js → reflect.js} +7 -8
  14. package/dist/reflect.js.map +1 -0
  15. package/dist/types.d.ts +70 -0
  16. package/dist/types.js +32 -0
  17. package/dist/types.js.map +1 -0
  18. package/package.json +43 -44
  19. package/src/decorator-factory.ts +289 -140
  20. package/src/index.ts +22 -2
  21. package/src/inspector.ts +118 -126
  22. package/src/reflect.ts +32 -21
  23. package/src/types.ts +94 -0
  24. package/CHANGELOG.md +0 -83
  25. package/api-docs/apple-touch-icon-114x114-precomposed.png +0 -0
  26. package/api-docs/apple-touch-icon-144x144-precomposed.png +0 -0
  27. package/api-docs/apple-touch-icon-57x57-precomposed.png +0 -0
  28. package/api-docs/apple-touch-icon-72x72-precomposed.png +0 -0
  29. package/api-docs/apple-touch-icon-precomposed.png +0 -0
  30. package/api-docs/apple-touch-icon.png +0 -0
  31. package/api-docs/css/bootstrap.min.css +0 -9
  32. package/api-docs/css/code-themes/arta.css +0 -158
  33. package/api-docs/css/code-themes/ascetic.css +0 -50
  34. package/api-docs/css/code-themes/brown_paper.css +0 -104
  35. package/api-docs/css/code-themes/brown_papersq.png +0 -0
  36. package/api-docs/css/code-themes/dark.css +0 -103
  37. package/api-docs/css/code-themes/default.css +0 -135
  38. package/api-docs/css/code-themes/far.css +0 -111
  39. package/api-docs/css/code-themes/github.css +0 -127
  40. package/api-docs/css/code-themes/googlecode.css +0 -144
  41. package/api-docs/css/code-themes/idea.css +0 -121
  42. package/api-docs/css/code-themes/ir_black.css +0 -104
  43. package/api-docs/css/code-themes/magula.css +0 -121
  44. package/api-docs/css/code-themes/monokai.css +0 -114
  45. package/api-docs/css/code-themes/pojoaque.css +0 -104
  46. package/api-docs/css/code-themes/pojoaque.jpg +0 -0
  47. package/api-docs/css/code-themes/rainbow.css +0 -114
  48. package/api-docs/css/code-themes/school_book.css +0 -111
  49. package/api-docs/css/code-themes/school_book.png +0 -0
  50. package/api-docs/css/code-themes/sl-theme.css +0 -45
  51. package/api-docs/css/code-themes/solarized_dark.css +0 -88
  52. package/api-docs/css/code-themes/solarized_light.css +0 -88
  53. package/api-docs/css/code-themes/sunburst.css +0 -158
  54. package/api-docs/css/code-themes/tomorrow-night-blue.css +0 -52
  55. package/api-docs/css/code-themes/tomorrow-night-bright.css +0 -51
  56. package/api-docs/css/code-themes/tomorrow-night-eighties.css +0 -51
  57. package/api-docs/css/code-themes/tomorrow-night.css +0 -52
  58. package/api-docs/css/code-themes/tomorrow.css +0 -49
  59. package/api-docs/css/code-themes/vs.css +0 -86
  60. package/api-docs/css/code-themes/xcode.css +0 -154
  61. package/api-docs/css/code-themes/zenburn.css +0 -115
  62. package/api-docs/css/main.css +0 -139
  63. package/api-docs/favicon.ico +0 -0
  64. package/api-docs/fonts/0ihfXUL2emPh0ROJezvraLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  65. package/api-docs/fonts/OsJ2DjdpjqFRVUSto6IffLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  66. package/api-docs/fonts/_aijTyevf54tkVDLy-dlnLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  67. package/api-docs/index.html +0 -4594
  68. package/api-docs/js/main.js +0 -19
  69. package/api-docs/js/vendor/bootstrap.min.js +0 -6
  70. package/api-docs/js/vendor/jquery-1.10.1.min.js +0 -6
  71. package/api-docs/js/vendor/jquery.scrollTo-1.4.3.1.js +0 -218
  72. package/api-docs/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js +0 -11
  73. package/dist/src/decorator-factory.d.ts +0 -252
  74. package/dist/src/decorator-factory.js +0 -468
  75. package/dist/src/decorator-factory.js.map +0 -1
  76. package/dist/src/index.d.ts +0 -3
  77. package/dist/src/index.js +0 -13
  78. package/dist/src/index.js.map +0 -1
  79. package/dist/src/inspector.d.ts +0 -150
  80. package/dist/src/inspector.js +0 -163
  81. package/dist/src/inspector.js.map +0 -1
  82. package/dist/src/reflect.js.map +0 -1
  83. package/dist6/index.d.ts +0 -1
  84. package/dist6/index.js +0 -13
  85. package/dist6/src/decorator-factory.d.ts +0 -252
  86. package/dist6/src/decorator-factory.js.map +0 -1
  87. package/dist6/src/index.d.ts +0 -3
  88. package/dist6/src/index.js +0 -13
  89. package/dist6/src/index.js.map +0 -1
  90. package/dist6/src/inspector.d.ts +0 -150
  91. package/dist6/src/inspector.js +0 -163
  92. package/dist6/src/inspector.js.map +0 -1
  93. package/dist6/src/reflect.d.ts +0 -38
  94. package/dist6/src/reflect.js +0 -143
  95. package/dist6/src/reflect.js.map +0 -1
  96. package/index.d.ts +0 -6
  97. package/index.js +0 -7
@@ -0,0 +1,297 @@
1
+ import { DecoratorType, MetadataKey, MetadataMap } from './types';
2
+ /**
3
+ * Options for a decorator
4
+ */
5
+ export interface DecoratorOptions {
6
+ /**
7
+ * Controls if inherited metadata will be honored. Default to `true`.
8
+ */
9
+ allowInheritance?: boolean;
10
+ /**
11
+ * Controls if the value of `spec` argument will be cloned. Sometimes we
12
+ * use shared spec for the decoration, but the decorator function might need
13
+ * to mutate the object. Cloning the input spec makes it safe to use the same
14
+ * spec (`template`) to decorate different members.
15
+ *
16
+ * Default to `true`.
17
+ */
18
+ cloneInputSpec?: boolean;
19
+ /**
20
+ * Name of the decorator for debugging purpose, such as `@inject`
21
+ */
22
+ decoratorName?: string;
23
+ [name: string]: any;
24
+ }
25
+ /**
26
+ * Base factory class for decorator functions
27
+ *
28
+ * @example
29
+ * ```
30
+ * function classDecorator(spec: MySpec): ClassDecorator {
31
+ * return ClassDecoratorFactory.createDecorator('my-key', spec);
32
+ * }
33
+ * ```
34
+ * or
35
+ * ```
36
+ * function classDecorator(spec: MySpec): ClassDecorator {
37
+ * const factory: ClassDecoratorFactory<MySpec>('my-key', spec);
38
+ * return factory.create();
39
+ * }
40
+ * ```
41
+ * These functions above declare `@classDecorator` that can be used as follows:
42
+ * ```
43
+ * @classDecorator({x: 1})
44
+ * class MyController {}
45
+ * ```
46
+ */
47
+ export declare class DecoratorFactory<T, // Type of the metadata spec for individual class/method/property/parameter
48
+ M extends T | MetadataMap<T> | MetadataMap<T[]>, // Type of the metadata
49
+ D extends DecoratorType> {
50
+ protected key: string;
51
+ protected spec: T;
52
+ protected options: DecoratorOptions;
53
+ protected decoratorName: string;
54
+ /**
55
+ * A constant to reference the target of a decoration
56
+ */
57
+ static TARGET: string;
58
+ /**
59
+ * Construct a new class decorator factory
60
+ * @param key - Metadata key
61
+ * @param spec - Metadata object from the decorator function
62
+ * @param options - Options for the decorator. Default to
63
+ * `{allowInheritance: true}` if not provided
64
+ */
65
+ constructor(key: string, spec: T, options?: DecoratorOptions);
66
+ protected allowInheritance(): boolean;
67
+ /**
68
+ * Inherit metadata from base classes. By default, this method merges base
69
+ * metadata into the spec if `allowInheritance` is set to `true`. To customize
70
+ * the behavior, this method can be overridden by sub classes.
71
+ *
72
+ * @param inheritedMetadata - Metadata from base classes for the member
73
+ */
74
+ protected inherit(inheritedMetadata: T | undefined | null): T;
75
+ /**
76
+ * Get the qualified name of a decoration target.
77
+ *
78
+ * @remarks
79
+ *
80
+ * Example of target names:
81
+ *
82
+ * - class MyClass
83
+ * - MyClass.constructor[0] // First parameter of the constructor
84
+ * - MyClass.myStaticProperty
85
+ * - MyClass.myStaticMethod()
86
+ * - MyClass.myStaticMethod[0] // First parameter of the myStaticMethod
87
+ * - MyClass.prototype.myProperty
88
+ * - MyClass.prototype.myMethod()
89
+ * - MyClass.prototype.myMethod[1] // Second parameter of myMethod
90
+ *
91
+ * @param target - Class or prototype of a class
92
+ * @param member - Optional property/method name
93
+ * @param descriptorOrIndex - Optional method descriptor or parameter index
94
+ */
95
+ static getTargetName(target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): string;
96
+ /**
97
+ * Get the number of parameters for a given constructor or method
98
+ * @param target - Class or the prototype
99
+ * @param member - Method name
100
+ */
101
+ static getNumberOfParameters(target: Object, member?: string): number;
102
+ /**
103
+ * Set a reference to the target class or prototype for a given spec if
104
+ * it's an object
105
+ * @param spec - Metadata spec
106
+ * @param target - Target of the decoration. It is a class or the prototype of
107
+ * a class.
108
+ */
109
+ withTarget(spec: T, target: Object): T;
110
+ /**
111
+ * Get the optional decoration target of a given spec
112
+ * @param spec - Metadata spec
113
+ */
114
+ getTarget(spec: T): any;
115
+ /**
116
+ * This method is called by the default implementation of the decorator
117
+ * function to merge the spec argument from the decoration with the inherited
118
+ * metadata for a class, all properties, all methods, or all method
119
+ * parameters that are decorated by this decorator.
120
+ *
121
+ * It MUST be overridden by subclasses to process inherited metadata.
122
+ *
123
+ * @param inheritedMetadata - Metadata inherited from the base classes
124
+ * @param target - Decoration target
125
+ * @param member - Optional property or method
126
+ * @param descriptorOrIndex - Optional parameter index or method descriptor
127
+ */
128
+ protected mergeWithInherited(inheritedMetadata: M, target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): M;
129
+ /**
130
+ * This method is called by the default implementation of the decorator
131
+ * function to merge the spec argument from the decoration with the own
132
+ * metadata for a class, all properties, all methods, or all method
133
+ * parameters that are decorated by this decorator.
134
+ *
135
+ * It MUST be overridden by subclasses to process own metadata.
136
+ *
137
+ * @param ownMetadata - Own Metadata exists locally on the target
138
+ * @param target - Decoration target
139
+ * @param member - Optional property or method
140
+ * @param descriptorOrIndex - Optional parameter index or method descriptor
141
+ */
142
+ protected mergeWithOwn(ownMetadata: M, target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): M;
143
+ /**
144
+ * Create an error to report if the decorator is applied to the target more
145
+ * than once
146
+ * @param target - Decoration target
147
+ * @param member - Optional property or method
148
+ * @param descriptorOrIndex - Optional parameter index or method descriptor
149
+ */
150
+ protected duplicateDecorationError(target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): Error;
151
+ /**
152
+ * Create a decorator function of the given type. Each sub class MUST
153
+ * implement this method.
154
+ */
155
+ create(): D;
156
+ /**
157
+ * Base implementation of the decorator function
158
+ * @param target - Decorator target
159
+ * @param member - Optional property or method
160
+ * @param descriptorOrIndex - Optional method descriptor or parameter index
161
+ */
162
+ protected decorate(target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): void;
163
+ /**
164
+ * Create a decorator function
165
+ * @param key - Metadata key
166
+ * @param spec - Metadata object from the decorator function
167
+ * @param options - Options for the decorator
168
+ */
169
+ protected static _createDecorator<S, MT extends S | MetadataMap<S> | MetadataMap<S[]>, DT extends DecoratorType>(key: MetadataKey<S, DT>, spec: S, options?: DecoratorOptions): DT;
170
+ private static _cloneableTypes;
171
+ static cloneDeep<V>(val: Readonly<V>): V;
172
+ }
173
+ /**
174
+ * Factory for class decorators
175
+ */
176
+ export declare class ClassDecoratorFactory<T> extends DecoratorFactory<T, T, ClassDecorator> {
177
+ protected mergeWithInherited(inheritedMetadata: T, target: Object, member?: string, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): T;
178
+ protected mergeWithOwn(ownMetadata: T, target: Object, member?: string, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): T;
179
+ create(): ClassDecorator;
180
+ /**
181
+ * Create a class decorator function
182
+ * @param key - Metadata key
183
+ * @param spec - Metadata object from the decorator function
184
+ * @param options - Options for the decorator
185
+ */
186
+ static createDecorator<S>(key: MetadataKey<S, ClassDecorator>, spec: S, options?: DecoratorOptions): ClassDecorator;
187
+ }
188
+ /**
189
+ * Factory for property decorators
190
+ */
191
+ export declare class PropertyDecoratorFactory<T> extends DecoratorFactory<T, MetadataMap<T>, PropertyDecorator> {
192
+ protected mergeWithInherited(inheritedMetadata: MetadataMap<T>, target: Object, propertyName?: string, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): MetadataMap<T>;
193
+ protected mergeWithOwn(ownMetadata: MetadataMap<T>, target: Object, propertyName?: string, descriptorOrParameterIndex?: TypedPropertyDescriptor<any> | number): MetadataMap<T>;
194
+ create(): PropertyDecorator;
195
+ /**
196
+ * Create a property decorator function
197
+ * @param key - Metadata key
198
+ * @param spec - Metadata object from the decorator function
199
+ * @param options - Options for the decorator
200
+ */
201
+ static createDecorator<S>(key: MetadataKey<S, PropertyDecorator>, spec: S, options?: DecoratorOptions): PropertyDecorator;
202
+ }
203
+ /**
204
+ * Factory for method decorators
205
+ */
206
+ export declare class MethodDecoratorFactory<T> extends DecoratorFactory<T, MetadataMap<T>, MethodDecorator> {
207
+ protected mergeWithInherited(inheritedMetadata: MetadataMap<T>, target: Object, methodName?: string, methodDescriptor?: TypedPropertyDescriptor<any> | number): MetadataMap<T>;
208
+ protected mergeWithOwn(ownMetadata: MetadataMap<T>, target: Object, methodName?: string, methodDescriptor?: TypedPropertyDescriptor<any> | number): MetadataMap<T>;
209
+ create(): MethodDecorator;
210
+ /**
211
+ * Create a method decorator function
212
+ * @param key - Metadata key
213
+ * @param spec - Metadata object from the decorator function
214
+ * @param options - Options for the decorator
215
+ */
216
+ static createDecorator<S>(key: MetadataKey<S, MethodDecorator>, spec: S, options?: DecoratorOptions): MethodDecorator;
217
+ }
218
+ /**
219
+ * Factory for parameter decorators
220
+ */
221
+ export declare class ParameterDecoratorFactory<T> extends DecoratorFactory<T, MetadataMap<T[]>, ParameterDecorator> {
222
+ private getOrInitMetadata;
223
+ protected mergeWithInherited(inheritedMetadata: MetadataMap<T[]>, target: Object, methodName?: string, parameterIndex?: TypedPropertyDescriptor<any> | number): MetadataMap<T[]>;
224
+ protected mergeWithOwn(ownMetadata: MetadataMap<T[]>, target: Object, methodName?: string, parameterIndex?: TypedPropertyDescriptor<any> | number): MetadataMap<T[]>;
225
+ create(): ParameterDecorator;
226
+ /**
227
+ * Create a parameter decorator function
228
+ * @param key - Metadata key
229
+ * @param spec - Metadata object from the decorator function
230
+ * @param options - Options for the decorator
231
+ */
232
+ static createDecorator<S>(key: MetadataKey<S, ParameterDecorator>, spec: S, options?: DecoratorOptions): ParameterDecorator;
233
+ }
234
+ /**
235
+ * Factory for method level parameter decorator.
236
+ *
237
+ * @example
238
+ * For example, the following code uses `@param` to declare two parameters for
239
+ * `greet()`.
240
+ * ```ts
241
+ * class MyController {
242
+ * @param('name') // Parameter 0
243
+ * @param('msg') // Parameter 1
244
+ * greet() {}
245
+ * }
246
+ * ```
247
+ */
248
+ export declare class MethodParameterDecoratorFactory<T> extends DecoratorFactory<T, MetadataMap<T[]>, MethodDecorator> {
249
+ /**
250
+ * Find the corresponding parameter index for the decoration
251
+ * @param target
252
+ * @param methodName
253
+ * @param methodDescriptor
254
+ */
255
+ private getParameterIndex;
256
+ protected mergeWithInherited(inheritedMetadata: MetadataMap<T[]>, target: Object, methodName?: string, methodDescriptor?: TypedPropertyDescriptor<any> | number): MetadataMap<T[]>;
257
+ protected mergeWithOwn(ownMetadata: MetadataMap<T[]>, target: Object, methodName?: string, methodDescriptor?: TypedPropertyDescriptor<any> | number): MetadataMap<T[]>;
258
+ create(): MethodDecorator;
259
+ /**
260
+ * Create a method decorator function
261
+ * @param key - Metadata key
262
+ * @param spec - Metadata object from the decorator function
263
+ * @param options - Options for the decorator
264
+ */
265
+ static createDecorator<S>(key: MetadataKey<S, MethodDecorator>, spec: S, options?: DecoratorOptions): MethodDecorator;
266
+ }
267
+ /**
268
+ * Factory for an append-array of method-level decorators
269
+ * The `@response` metadata for a method is an array.
270
+ * Each item in the array should be a single value, containing
271
+ * a response code and a single spec or Model. This should allow:
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * @response(200, MyFirstModel)
276
+ * @response(403, [NotAuthorizedReasonOne, NotAuthorizedReasonTwo])
277
+ * @response(404, NotFoundOne)
278
+ * @response(404, NotFoundTwo)
279
+ * @response(409, {schema: {}})
280
+ * public async myMethod() {}
281
+ * ```
282
+ *
283
+ * In the case that a ResponseObject is passed, it becomes the
284
+ * default for description/content, and if possible, further Models are
285
+ * incorporated as a `oneOf: []` array.
286
+ *
287
+ * In the case that a ReferenceObject is passed, it and it alone is used, since
288
+ * references can be external and we cannot `oneOf` their content.
289
+ *
290
+ * The factory creates and updates an array of items T[], and the getter
291
+ * provides the values as that array.
292
+ */
293
+ export declare class MethodMultiDecoratorFactory<T> extends MethodDecoratorFactory<T[]> {
294
+ protected mergeWithInherited(inheritedMetadata: MetadataMap<T[]>, target: Object, methodName?: string): MetadataMap<T[]>;
295
+ protected mergeWithOwn(ownMetadata: MetadataMap<T[]>, target: Object, methodName?: string, methodDescriptor?: TypedPropertyDescriptor<any> | number): MetadataMap<T[]>;
296
+ private _mergeArray;
297
+ }