@decaf-ts/decoration 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -367
- package/dist/decoration.cjs +1 -1
- package/dist/decoration.cjs.map +1 -1
- package/dist/decoration.js +1 -1
- package/dist/decoration.js.map +1 -1
- package/lib/esm/metadata/Metadata.d.ts +2 -0
- package/lib/esm/metadata/Metadata.js +5 -1
- package/lib/esm/metadata/Metadata.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/metadata/Metadata.cjs +5 -1
- package/lib/metadata/Metadata.d.ts +2 -0
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/version.cjs +1 -1
- package/lib/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
The decoration module provides a small, composable system for building and applying TypeScript decorators with flavour-aware resolution and a centralized runtime Metadata store. It lets you define base decorators, provide framework-specific overrides and extensions ("flavours"), and record/read rich metadata for classes and their members at runtime.
|
|
5
5
|
|
|
6
|
+
### Core Concepts
|
|
7
|
+
|
|
8
|
+
* **Metadata**: A centralized, static class for reading and writing metadata for classes and their members. It supports nested keys and can mirror metadata on the constructor for easy access.
|
|
9
|
+
* **Decoration**: A builder class for creating and managing decorators. It allows you to define a base set of decorators and then override or extend them with different "flavours".
|
|
10
|
+
* **Flavours**: A mechanism for providing framework-specific implementations of decorators. This allows you to create libraries that are agnostic of the underlying framework, and then provide specific implementations for different environments (e.g., Angular, React, Vue).
|
|
11
|
+
* **Decorators**: A set of utility decorators (`@metadata`, `@prop`, `@method`, `@param`, `@apply`) for working with the metadata system.
|
|
12
|
+
|
|
6
13
|

|
|
7
14
|

|
|
8
15
|

|
|
@@ -26,7 +33,7 @@ The decoration module provides a small, composable system for building and apply
|
|
|
26
33
|
|
|
27
34
|
Documentation available [here](https://decaf-ts.github.io/ts-workspace/)
|
|
28
35
|
|
|
29
|
-
Minimal size: 5.
|
|
36
|
+
Minimal size: 5.5 KB kb gzipped
|
|
30
37
|
|
|
31
38
|
|
|
32
39
|
# Description
|
|
@@ -81,426 +88,165 @@ Design highlights
|
|
|
81
88
|
|
|
82
89
|
# How to Use
|
|
83
90
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
## Prerequisites
|
|
87
|
-
|
|
88
|
-
- Enable experimental decorators and decorator metadata in `tsconfig.json`:
|
|
89
|
-
|
|
90
|
-
```json
|
|
91
|
-
{
|
|
92
|
-
"compilerOptions": {
|
|
93
|
-
"experimentalDecorators": true,
|
|
94
|
-
"emitDecoratorMetadata": true
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
- Import `reflect-metadata` once (before decorators execute):
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
import "reflect-metadata";
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
## Decoration Builder
|
|
106
|
-
|
|
107
|
-
The `Decoration` class exposes a fluent builder that lets you define base decorators, add flavour-specific extras, or override behaviour entirely.
|
|
108
|
-
|
|
109
|
-
Important behaviour note:
|
|
110
|
-
- Calling `define()` registers (or replaces) the *base* decorators for a key/flavour. If you call `define()` again for the same key/flavour, the previously registered base decorators are replaced with the new ones.
|
|
111
|
-
- Calling `extend()` (or providing extras) registers additional flavour-specific decorators that are applied after the base decorators. Crucially, calls to `define()` will NOT remove or clear previously registered extras — extras persist until they are explicitly changed via `extend()` (or a `define()`/`apply()` that provides explicit extras).
|
|
112
|
-
|
|
113
|
-
These guarantees let you safely replace base behaviour without losing already-registered platform-specific additions.
|
|
114
|
-
|
|
115
|
-
### 1. Register base decorators for the default flavour
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
import { Decoration } from "@decaf-ts/decoration";
|
|
119
|
-
|
|
120
|
-
const markAsComponent: ClassDecorator = (target) => {
|
|
121
|
-
(target as any).__isComponent = true;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const tagFactory = (tag: string): ClassDecorator => (target) => {
|
|
125
|
-
(target as any).__tag = tag;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const component = () =>
|
|
129
|
-
Decoration.for("component")
|
|
130
|
-
.define({ decorator: tagFactory, args: ["base"] }, markAsComponent)
|
|
131
|
-
.apply();
|
|
132
|
-
|
|
133
|
-
@component()
|
|
134
|
-
class DefaultComponent {}
|
|
135
|
-
|
|
136
|
-
(DefaultComponent as any).__isComponent; // true
|
|
137
|
-
(DefaultComponent as any).__tag; // "base"
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Replace base decorators (base only — extras persist)
|
|
141
|
-
|
|
142
|
-
If you need to change the base behaviour later, call `define()` again for the same key/flavour — this REPLACES the previously registered base decorators but does not remove extras that were registered with `extend()`.
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
const calls: string[] = [];
|
|
146
|
-
|
|
147
|
-
const baseA = () =>
|
|
148
|
-
Decoration.for("widget")
|
|
149
|
-
.define(((t: any) => {
|
|
150
|
-
calls.push(`baseA:${t.name}`);
|
|
151
|
-
}) as any)
|
|
152
|
-
.apply();
|
|
153
|
-
|
|
154
|
-
Decoration.for("widget")
|
|
155
|
-
.extend(((t: any) => {
|
|
156
|
-
calls.push(`extra:${t.name}`);
|
|
157
|
-
}) as any)
|
|
158
|
-
.apply();
|
|
159
|
-
|
|
160
|
-
@baseA()
|
|
161
|
-
class Widget1 {}
|
|
162
|
-
|
|
163
|
-
// Later we replace the base behaviour for the same key. Extras remain.
|
|
164
|
-
Decoration.for("widget")
|
|
165
|
-
.define(((t: any) => {
|
|
166
|
-
calls.push(`baseB:${t.name}`);
|
|
167
|
-
}) as any)
|
|
168
|
-
.apply();
|
|
169
|
-
|
|
170
|
-
@Decoration.for("widget").apply()
|
|
171
|
-
class Widget2 {}
|
|
172
|
-
|
|
173
|
-
// calls === [
|
|
174
|
-
// `baseA:Widget1`,
|
|
175
|
-
// `extra:Widget1`,
|
|
176
|
-
// `baseB:Widget2`, // base replaced
|
|
177
|
-
// `extra:Widget2` // extra persists
|
|
178
|
-
// ]
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### 2. Extend base decorators with flavour-specific extras
|
|
182
|
-
|
|
183
|
-
```ts
|
|
184
|
-
// Register the same base behaviour as above.
|
|
185
|
-
const baseComponent = () =>
|
|
186
|
-
Decoration.for("component")
|
|
187
|
-
.define(((target: any) => target) as ClassDecorator)
|
|
188
|
-
.apply();
|
|
189
|
-
|
|
190
|
-
@baseComponent()
|
|
191
|
-
class BaseComponent {}
|
|
192
|
-
|
|
193
|
-
Decoration.setFlavourResolver(() => "web");
|
|
194
|
-
|
|
195
|
-
const decorate = () =>
|
|
196
|
-
Decoration.flavouredAs("web")
|
|
197
|
-
.for("component")
|
|
198
|
-
.extend({
|
|
199
|
-
decorator: (platform: string): ClassDecorator => (target) => {
|
|
200
|
-
(target as any).__platform = platform;
|
|
201
|
-
},
|
|
202
|
-
args: ["web"],
|
|
203
|
-
})
|
|
204
|
-
.apply();
|
|
205
|
-
|
|
206
|
-
@decorate()
|
|
207
|
-
class WebComponent {}
|
|
208
|
-
|
|
209
|
-
(WebComponent as any).__platform; // "web"
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### 3. Override decorators for an alternate flavour
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
const base = () =>
|
|
216
|
-
Decoration.for("component")
|
|
217
|
-
.define(((target: any) => {
|
|
218
|
-
(target as any).__base = true;
|
|
219
|
-
}) as ClassDecorator)
|
|
220
|
-
.apply();
|
|
221
|
-
|
|
222
|
-
@base()
|
|
223
|
-
class BaseBehaviour {}
|
|
91
|
+
This guide provides examples of how to use the main features of the `@decaf-ts/decoration` library.
|
|
224
92
|
|
|
225
|
-
|
|
93
|
+
## Metadata
|
|
226
94
|
|
|
227
|
-
|
|
228
|
-
Decoration.flavouredAs("mobile")
|
|
229
|
-
.for("component")
|
|
230
|
-
.define(((target: any) => {
|
|
231
|
-
(target as any).__mobile = true;
|
|
232
|
-
}) as ClassDecorator)
|
|
233
|
-
.apply();
|
|
234
|
-
|
|
235
|
-
@mobileComponent()
|
|
236
|
-
class MobileComponent {}
|
|
237
|
-
|
|
238
|
-
(MobileComponent as any).__base; // undefined – overridden
|
|
239
|
-
(MobileComponent as any).__mobile; // true
|
|
240
|
-
```
|
|
95
|
+
The `Metadata` class is a centralized store for runtime type information and other metadata.
|
|
241
96
|
|
|
242
|
-
###
|
|
243
|
-
|
|
244
|
-
The builder throws when misused; tests assert these guards and you can rely on them in your own code.
|
|
245
|
-
|
|
246
|
-
```ts
|
|
247
|
-
const base = Decoration.for("guarded");
|
|
248
|
-
|
|
249
|
-
// Missing key before define/extend
|
|
250
|
-
expect(() => (new Decoration() as any).define(() => () => undefined)).toThrow();
|
|
251
|
-
|
|
252
|
-
// Multiple overridable decorators are rejected
|
|
253
|
-
const overridable = {
|
|
254
|
-
decorator: (() => ((target: any) => target)) as any,
|
|
255
|
-
args: [],
|
|
256
|
-
};
|
|
257
|
-
expect(() => base.define(overridable as any, overridable as any)).toThrow();
|
|
258
|
-
|
|
259
|
-
// Extending the default flavour is blocked
|
|
260
|
-
expect(() => Decoration.for("guarded").extend(((t: any) => t) as any)).toThrow();
|
|
261
|
-
```
|
|
97
|
+
### Storing and Retrieving Metadata
|
|
262
98
|
|
|
263
|
-
|
|
99
|
+
You can use the `@metadata` decorator or the `Metadata.set()` and `Metadata.get()` methods to store and retrieve metadata for a class or its members.
|
|
264
100
|
|
|
265
|
-
|
|
101
|
+
```typescript
|
|
102
|
+
import { metadata, Metadata } from '@decaf-ts/decoration';
|
|
266
103
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
@metadata("role", "entity")
|
|
273
|
-
class User {}
|
|
274
|
-
|
|
275
|
-
Metadata.get(User, "role"); // "entity"
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
### prop()
|
|
279
|
-
|
|
280
|
-
```ts
|
|
281
|
-
import { prop, Metadata } from "@decaf-ts/decoration";
|
|
282
|
-
|
|
283
|
-
class Article {
|
|
284
|
-
@prop()
|
|
285
|
-
title!: string;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
Metadata.type(Article, "title") === String; // true
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
### apply(...decorators)
|
|
292
|
-
|
|
293
|
-
```ts
|
|
294
|
-
import { apply } from "@decaf-ts/decoration";
|
|
295
|
-
|
|
296
|
-
const logClass: ClassDecorator = (target) => {
|
|
297
|
-
console.log("class", (target as any).name);
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
const withLogging = () => apply(logClass);
|
|
301
|
-
const logProperty = () => apply((_, key) => console.log("prop", String(key)));
|
|
302
|
-
|
|
303
|
-
@withLogging()
|
|
304
|
-
class Box {
|
|
305
|
-
@logProperty()
|
|
306
|
-
size!: number;
|
|
104
|
+
@metadata('my-class-key', 'my-class-value')
|
|
105
|
+
class MyClass {
|
|
106
|
+
@metadata('my-prop-key', 'my-prop-value')
|
|
107
|
+
myProp: string;
|
|
307
108
|
}
|
|
308
|
-
```
|
|
309
109
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
import { propMetadata, Metadata } from "@decaf-ts/decoration";
|
|
314
|
-
|
|
315
|
-
class Product {
|
|
316
|
-
@propMetadata("column", "price")
|
|
317
|
-
price!: number;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
Metadata.get(Product, "column"); // "price"
|
|
321
|
-
Metadata.type(Product, "price") === Number; // true
|
|
110
|
+
// Retrieve metadata
|
|
111
|
+
const classMetadata = Metadata.get(MyClass, 'my-class-key'); // 'my-class-value'
|
|
112
|
+
const propMetadata = Metadata.get(MyClass, 'my-prop-key'); // 'my-prop-value'
|
|
322
113
|
```
|
|
323
114
|
|
|
324
|
-
###
|
|
325
|
-
|
|
326
|
-
```ts
|
|
327
|
-
import { description, Metadata } from "@decaf-ts/decoration";
|
|
328
|
-
|
|
329
|
-
@description("User entity")
|
|
330
|
-
class User {
|
|
331
|
-
@description("Primary email address")
|
|
332
|
-
email!: string;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
Metadata.description(User); // "User entity"
|
|
336
|
-
Metadata.description<User>(User, "email" as keyof User); // "Primary email address"
|
|
337
|
-
```
|
|
115
|
+
### Working with Property and Method Types
|
|
338
116
|
|
|
339
|
-
|
|
117
|
+
The `@prop` and `@method` decorators automatically capture design-time type information.
|
|
340
118
|
|
|
341
|
-
|
|
119
|
+
```typescript
|
|
120
|
+
import { prop, method, Metadata } from '@decaf-ts/decoration';
|
|
342
121
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
import { Metadata, DecorationKeys } from "@decaf-ts/decoration";
|
|
347
|
-
|
|
348
|
-
class Person {
|
|
349
|
-
name!: string;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
Metadata.set(Person, `${DecorationKeys.DESCRIPTION}.class`, "Person model");
|
|
353
|
-
Metadata.set(Person, `${DecorationKeys.PROPERTIES}.name`, String);
|
|
354
|
-
|
|
355
|
-
Metadata.description(Person); // "Person model"
|
|
356
|
-
Metadata.properties(Person); // ["name"]
|
|
357
|
-
|
|
358
|
-
const mirror = Object.getOwnPropertyDescriptor(Person, DecorationKeys.REFLECT);
|
|
359
|
-
mirror?.enumerable; // false
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
### Opt out of mirroring
|
|
363
|
-
|
|
364
|
-
```ts
|
|
365
|
-
(Metadata as any).mirror = false;
|
|
366
|
-
|
|
367
|
-
Metadata.set(Person, `${DecorationKeys.DESCRIPTION}.class`, "No mirror");
|
|
368
|
-
Object.getOwnPropertyDescriptor(Person, DecorationKeys.REFLECT); // undefined
|
|
369
|
-
|
|
370
|
-
(Metadata as any).mirror = true; // reset when you are done
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
### Work with method metadata
|
|
122
|
+
class MyService {
|
|
123
|
+
@prop()
|
|
124
|
+
myProperty: string;
|
|
374
125
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return "value";
|
|
126
|
+
@method()
|
|
127
|
+
myMethod(param1: number): boolean {
|
|
128
|
+
// ...
|
|
379
129
|
}
|
|
380
130
|
}
|
|
381
131
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
);
|
|
387
|
-
Metadata.set(
|
|
388
|
-
Service,
|
|
389
|
-
`${DecorationKeys.METHODS}.get.${DecorationKeys.DESIGN_RETURN}`,
|
|
390
|
-
String
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
Metadata.methods(Service); // ["get"]
|
|
394
|
-
Metadata.params(Service, "get"); // []
|
|
395
|
-
Metadata.return(Service, "get") === String; // true
|
|
132
|
+
// Retrieve type information
|
|
133
|
+
const propType = Metadata.type(MyService, 'myProperty'); // String
|
|
134
|
+
const returnType = Metadata.return(MyService, 'myMethod'); // Boolean
|
|
135
|
+
const paramTypes = Metadata.params(MyService, 'myMethod'); // [Number]
|
|
396
136
|
```
|
|
397
137
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
```ts
|
|
401
|
-
Metadata.type(Person, "name"); // Reflects design type recorded by @prop()
|
|
402
|
-
Metadata.get(Person); // Full metadata payload for advanced inspection
|
|
403
|
-
Metadata.get(Person, DecorationKeys.CONSTRUCTOR); // Underlying constructor reference
|
|
404
|
-
```
|
|
138
|
+
## Decoration
|
|
405
139
|
|
|
406
|
-
|
|
140
|
+
The `Decoration` class allows you to create and manage decorators with different "flavours".
|
|
407
141
|
|
|
408
|
-
|
|
142
|
+
### Creating a Simple Decorator
|
|
409
143
|
|
|
410
|
-
```
|
|
411
|
-
import {
|
|
144
|
+
```typescript
|
|
145
|
+
import { Decoration } from '@decaf-ts/decoration';
|
|
412
146
|
|
|
413
|
-
|
|
147
|
+
const myDecorator = Decoration.for('my-decorator')
|
|
148
|
+
.define((target: any) => {
|
|
149
|
+
console.log('My decorator was applied to', target.name);
|
|
150
|
+
})
|
|
151
|
+
.apply();
|
|
414
152
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
).toThrow(/already/);
|
|
153
|
+
@myDecorator
|
|
154
|
+
class MyDecoratedClass {}
|
|
418
155
|
```
|
|
419
156
|
|
|
420
|
-
|
|
157
|
+
### Creating a Flavoured Decorator
|
|
421
158
|
|
|
422
|
-
|
|
159
|
+
You can create different versions of a decorator for different "flavours".
|
|
423
160
|
|
|
424
|
-
|
|
161
|
+
```typescript
|
|
162
|
+
import { Decoration, DefaultFlavour } from '@decaf-ts/decoration';
|
|
425
163
|
|
|
426
|
-
|
|
164
|
+
// Define the default decorator
|
|
165
|
+
const defaultDecorator = Decoration.for('my-flavoured-decorator')
|
|
166
|
+
.define((target: any) => {
|
|
167
|
+
console.log('Default decorator applied to', target.name);
|
|
168
|
+
})
|
|
169
|
+
.apply();
|
|
427
170
|
|
|
428
|
-
|
|
429
|
-
|
|
171
|
+
// Define a decorator for the 'vue' flavour
|
|
172
|
+
const vueDecorator = Decoration.flavouredAs('vue')
|
|
173
|
+
.for('my-flavoured-decorator')
|
|
174
|
+
.define((target: any) => {
|
|
175
|
+
console.log('Vue decorator applied to', target.name);
|
|
176
|
+
})
|
|
177
|
+
.apply();
|
|
430
178
|
|
|
431
|
-
|
|
179
|
+
// Use the default decorator
|
|
180
|
+
@defaultDecorator
|
|
181
|
+
class MyDefaultClass {}
|
|
432
182
|
|
|
433
|
-
|
|
434
|
-
|
|
183
|
+
// Use the 'vue' decorator by setting the flavour
|
|
184
|
+
Decoration.setResolver(() => 'vue');
|
|
435
185
|
|
|
436
|
-
|
|
437
|
-
|
|
186
|
+
@defaultDecorator
|
|
187
|
+
class MyVueClass {}
|
|
438
188
|
```
|
|
439
189
|
|
|
440
|
-
|
|
190
|
+
### Extending Decorators
|
|
441
191
|
|
|
442
|
-
|
|
192
|
+
You can extend an existing decorator with additional functionality.
|
|
443
193
|
|
|
444
|
-
```
|
|
445
|
-
import {
|
|
194
|
+
```typescript
|
|
195
|
+
import { Decoration } from '@decaf-ts/decoration';
|
|
446
196
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
197
|
+
const baseDecorator = Decoration.for('my-extended-decorator')
|
|
198
|
+
.define((target: any) => {
|
|
199
|
+
console.log('Base decorator applied');
|
|
200
|
+
})
|
|
201
|
+
.apply();
|
|
451
202
|
|
|
452
|
-
|
|
453
|
-
|
|
203
|
+
const extendedDecorator = Decoration.for('my-extended-decorator')
|
|
204
|
+
.extend((target: any) => {
|
|
205
|
+
console.log('Extended decorator applied');
|
|
206
|
+
})
|
|
207
|
+
.apply();
|
|
454
208
|
|
|
455
|
-
|
|
209
|
+
@extendedDecorator
|
|
210
|
+
class MyExtendedClass {}
|
|
211
|
+
// Console output:
|
|
212
|
+
// Base decorator applied
|
|
213
|
+
// Extended decorator applied
|
|
456
214
|
```
|
|
457
215
|
|
|
458
|
-
|
|
216
|
+
## Utility Decorators
|
|
459
217
|
|
|
460
|
-
|
|
218
|
+
### `@apply`
|
|
461
219
|
|
|
462
|
-
|
|
463
|
-
import { Metadata, DecorationKeys } from "@decaf-ts/decoration";
|
|
220
|
+
The `@apply` decorator allows you to apply multiple decorators to a single target.
|
|
464
221
|
|
|
465
|
-
|
|
466
|
-
|
|
222
|
+
```typescript
|
|
223
|
+
import { apply } from '@decaf-ts/decoration';
|
|
467
224
|
|
|
468
|
-
|
|
225
|
+
const decorator1 = (target: any) => { console.log('Decorator 1'); };
|
|
226
|
+
const decorator2 = (target: any) => { console.log('Decorator 2'); };
|
|
469
227
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
;(Metadata as any).mirror = true;
|
|
228
|
+
@apply(decorator1, decorator2)
|
|
229
|
+
class MyMultipliedClass {}
|
|
473
230
|
```
|
|
474
231
|
|
|
475
|
-
|
|
232
|
+
### `@propMetadata` and `@methodMetadata`
|
|
476
233
|
|
|
477
|
-
|
|
234
|
+
These decorators are shortcuts for applying metadata and capturing type information at the same time.
|
|
478
235
|
|
|
479
|
-
```
|
|
480
|
-
import {
|
|
236
|
+
```typescript
|
|
237
|
+
import { propMetadata, methodMetadata, Metadata } from '@decaf-ts/decoration';
|
|
481
238
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
```
|
|
239
|
+
class MyMetaClass {
|
|
240
|
+
@propMetadata('my-key', 'my-value')
|
|
241
|
+
myProp: string;
|
|
486
242
|
|
|
243
|
+
@methodMetadata('my-method-key', 'my-method-value')
|
|
244
|
+
myMethod() {}
|
|
245
|
+
}
|
|
487
246
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
- one class per file;
|
|
492
|
-
- one interface per file (unless interface is just used as a type);
|
|
493
|
-
- group types as other interfaces in a types.ts file per folder;
|
|
494
|
-
- group constants or enums in a constants.ts file per folder;
|
|
495
|
-
- group decorators in a decorators.ts file per folder;
|
|
496
|
-
- always import from the specific file, never from a folder or index file (exceptions for dependencies on other packages);
|
|
497
|
-
- prefer the usage of established design patters where applicable:
|
|
498
|
-
- Singleton (can be an anti-pattern. use with care);
|
|
499
|
-
- factory;
|
|
500
|
-
- observer;
|
|
501
|
-
- strategy;
|
|
502
|
-
- builder;
|
|
503
|
-
- etc;
|
|
247
|
+
const propMeta = Metadata.get(MyMetaClass, 'my-key'); // 'my-value'
|
|
248
|
+
const propType = Metadata.type(MyMetaClass, 'myProp'); // String
|
|
249
|
+
const methodMeta = Metadata.get(MyMetaClass, 'my-method-key'); // 'my-method-value'
|
|
504
250
|
```
|
|
505
251
|
|
|
506
252
|
|
package/dist/decoration.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t,e;t=this,e=function(t){"use strict";const e="decaf",r=".";var o,i;t.DecorationKeys=void 0,(o=t.DecorationKeys||(t.DecorationKeys={})).LIBRARIES="libraries",o.REFLECT="__decaf",o.PROPERTIES="properties",o.METHODS="methods",o.CLASS="class",o.DESCRIPTION="description",o.CONSTRUCTOR="__original",o.PARAMETERS="parameters",o.FLAVOUR="flavour",o.DECORATION="decoration",o.DESIGN_TYPE="design:type",o.DESIGN_PARAMS="design:paramtypes",o.DESIGN_RETURN="design:returntype",t.DecorationState=void 0,(i=t.DecorationState||(t.DecorationState={})).PENDING="pending",i.ONGOING="ongoing";const a={[t.DecorationKeys.PROPERTIES]:[]},s="##VERSION##",n="##PACKAGE##";let c,l;function d(t){c=t}function u(t){return c?c(t):e}function f(t){l=t}function p(t,e){l&&l(t,e)}function y(t,e,o=r){const i=e.split(o);let a=t;for(const t of i){if(null==a||!Object.prototype.hasOwnProperty.call(a,t))return;a=a[t]}return a}function h(t,e,o,i=r){const a=e.split(i).filter(t=>t.length>0);if(0===a.length)return;let s=t;for(let t=0;t<a.length-1;t++){const e=a[t];void 0!==s[e]&&null!==s[e]&&"object"==typeof s[e]||(s[e]={}),s=s[e]}s[a[a.length-1]]=o}class v{static{this._metadata={}}static{this._propertiesIndex={}}static{this.splitter=r}static{this.baseKey=t.DecorationKeys.REFLECT}static{this.mirror=!0}constructor(){}static Symbol(t){return Symbol.for([t.toString(),t.name].join(" - "))}static properties(t){const e=this.constr(t),r=this.Symbol(e),o=this._propertiesIndex[r];if(o&&o.size)return[...o];const i=this.get(e);return i&&i.properties?Object.keys(i.properties):void 0}static methods(e){const r=this.get(e,t.DecorationKeys.METHODS);if(r)return Object.keys(r)}static description(e,r){return this.get(e,this.key(t.DecorationKeys.DESCRIPTION,r||t.DecorationKeys.CLASS))}static flavourOf(t){return u(t)}static flavouredAs(e){return this.innerGet(Symbol.for(t.DecorationKeys.FLAVOUR),e)||[]}static registeredFlavour(r){const o=this.innerGet(Symbol.for(t.DecorationKeys.FLAVOUR));if(!o)return;const i=this.constr(r);let a;for(const[t,r]of Object.entries(o))if(Array.isArray(r)&&r.some(t=>this.constr(t)===i)){if(t===e){a=a||t;continue}return t}return a}static params(e,r){return this.get(e,this.key(t.DecorationKeys.METHODS,r,t.DecorationKeys.DESIGN_PARAMS))}static param(t,e,r){const o=this.params(t,e);if(o){if(r>o.length-1)throw Error(`Parameter index ${r} out of range for ${e+""}`);return o[r]}}static return(e,r){return this.get(e,this.key(t.DecorationKeys.METHODS,r,t.DecorationKeys.DESIGN_RETURN))}static type(e,r){return this.get(e,this.key(t.DecorationKeys.PROPERTIES,r))}static constr(e){return e[t.DecorationKeys.CONSTRUCTOR]||e}static get(e,r){if(r===t.DecorationKeys.CONSTRUCTOR)return this.constr(e);const o=this.constr(e),i=this.collectConstructorChain(o);if(i.filter(e=>this.isDecorated(e)===t.DecorationState.PENDING).forEach(t=>{p(t)}),0===i.length){const t=Symbol.for(o.toString());return this.innerGet(t,r)}const a=i.map(t=>this.innerGet(this.Symbol(t),r)).filter(t=>void 0!==t);return 0!==a.length?this.mergeMetadataChain(a):void 0}static isDecorated(e){const r=this.constr(e);return this.innerGet(this.Symbol(r),t.DecorationKeys.DECORATION)||!1}static innerGet(t,e){if(this._metadata[t])return e?"string"==typeof e?y(this._metadata[t],e,this.splitter):this._metadata[t][e]:this._metadata[t]}static collectConstructorChain(t){const e=[];let r=t;for(;"function"==typeof r&&r!==Function;){e.push(r);const t=Object.getPrototypeOf(r);if(!t||t===Function||t===Object)break;r=t}return e.reverse()}static mergeMetadataChain(t){let e;for(const r of t)e=void 0!==e&&this.isPlainObject(e)&&this.isPlainObject(r)?this.mergePlainObjects(e,r):this.cloneMetadataValue(r);return e}static cloneMetadataValue(t){return Array.isArray(t)?[...t]:this.isPlainObject(t)?this.mergePlainObjects({},t):t}static mergePlainObjects(t,e){const r={...t};for(const t of Object.keys(e)){const o=e[t],i=r[t];this.isPlainObject(o)?r[t]=this.isPlainObject(i)?this.mergePlainObjects(i,o):this.mergePlainObjects({},o):r[t]=Array.isArray(o)?[...o]:o}return r}static isPlainObject(t){if(null===t||"object"!=typeof t||Array.isArray(t))return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}static innerSet(t,e,r){if(this._metadata[t]||(this._metadata[t]={}),"string"==typeof e)return h(this._metadata[t],e,r,this.splitter);this._metadata[t][e]=r}static set(e,r,o){if(r===t.DecorationKeys.CONSTRUCTOR)return void Object.defineProperty(e,t.DecorationKeys.CONSTRUCTOR,{enumerable:!1,configurable:!1,writable:!1,value:o});"string"!=typeof e&&(e=this.constr(e)||e);const i="string"==typeof e?Symbol.for(e):this.Symbol(e);if("string"==typeof r){const e=`${t.DecorationKeys.PROPERTIES}${this.splitter}`;if(r.startsWith(e)){const t=r.slice(e.length);if(t.length){const e=this._propertiesIndex[i]||new Set;e.add(t),this._propertiesIndex[i]=e}}else if(r===t.DecorationKeys.PROPERTIES&&this.isPlainObject(o)){const t=this._propertiesIndex[i]||new Set;Object.keys(o).forEach(e=>{t.add(e)}),t.size&&(this._propertiesIndex[i]=t)}}this.innerSet(i,r,o),"string"!=typeof e&&v.mirror&&!Object.prototype.hasOwnProperty.call(e,this.baseKey)&&Object.defineProperty(e,this.baseKey,{enumerable:!1,configurable:!1,writable:!1,value:this._metadata[i]})}static registerLibrary(e,r){const o=Symbol.for(t.DecorationKeys.LIBRARIES);if(this.innerGet(o,e))throw Error(`Library already ${e} registered with version ${r}`);this.innerSet(o,e,r)}static libraries(){const e=Symbol.for(t.DecorationKeys.LIBRARIES);return this.innerGet(e)||{}}static key(...t){return t.join(this.splitter)}}v.registerLibrary(n,s);const g=Symbol.for(t.DecorationKeys.FLAVOUR);function D(e,r,o){const i=v.constr(e),a=v.innerGet(v.Symbol(e),t.DecorationKeys.FLAVOUR)||o,s=(v.innerGet(g,a)||[]).filter(t=>v.constr(t)!==i);v.set(t.DecorationKeys.FLAVOUR,a,s);const n=new Set(v.innerGet(g,r)||[]);return n.add(e),v.set(t.DecorationKeys.FLAVOUR,r,[...n]),v.set(i,t.DecorationKeys.FLAVOUR,r),i}function O(e,r){return(o,i,a)=>{let s=o;if(i&&(s="function"==typeof o?o:o.constructor||o,void 0===a)){const e="function"==typeof o?o.prototype:o,r=Reflect.getOwnMetadata(t.DecorationKeys.DESIGN_TYPE,e,i),a=v.key(t.DecorationKeys.PROPERTIES,i.toString()),n=v.get(s,a);void 0===r&&void 0!==n||v.set(s,a,r)}v.set(s,e,r)}}function S(){return(e,r)=>{const o="function"==typeof e?e.prototype:e,i=Reflect.getOwnMetadata(t.DecorationKeys.DESIGN_TYPE,o,r);return O(v.key(t.DecorationKeys.PROPERTIES,r),i)(e,r)}}function b(){return(e,r,o)=>{if(!r)throw Error("The @param decorator can only be applied to methods");E()(e,r,Object.getOwnPropertyDescriptor(e,r));const i=v.params(e.constructor,r);if(!i)throw Error("Missing parameter types for "+r);if(o>=i.length)throw Error(`Parameter index ${o} out of range for ${r+""}`);O(v.key(t.DecorationKeys.METHODS,r,o.toString()),i[o])(e,r)}}function E(){return(e,r,o)=>{const i=Reflect.getOwnMetadata(t.DecorationKeys.DESIGN_PARAMS,e,r),a=Reflect.getOwnMetadata(t.DecorationKeys.DESIGN_RETURN,e,r);return m(O(v.key(t.DecorationKeys.METHODS,r,t.DecorationKeys.DESIGN_PARAMS),i),O(v.key(t.DecorationKeys.METHODS,r,t.DecorationKeys.DESIGN_RETURN),a))(e,r,o)}}function m(...t){return(e,r,o)=>{for(const i of t)void 0!==r?i(e,r,o):i(e)}}function R(e){const r=v.constr("function"==typeof e?e:e?.constructor),o=v.innerGet(v.Symbol(r),t.DecorationKeys.FLAVOUR);if(o&&o!==j.defaultFlavour)return o;const i="function"==typeof v.registeredFlavour?v.registeredFlavour(r):void 0;return i&&i!==j.defaultFlavour?i:o??j.defaultFlavour}function P(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}function A(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(t=>A(t));if(t instanceof Date)return new Date(t.getTime());if(t instanceof Set)return new Set(Array.from(t).map(t=>A(t)));if(t instanceof Map)return new Map(Array.from(t.entries()).map(([t,e])=>[t,A(e)]));if(t.constructor!==Object)return t;const e={};return Reflect.ownKeys(t).forEach(r=>{e[r]=A(t[r])}),e}function K(t,e,r=[],o=[]){return new Set([...t?Reflect.ownKeys(t):[],...e?Reflect.ownKeys(e):[]]).forEach(i=>{const a=!!t&&Object.prototype.hasOwnProperty.call(t,i),s=!!e&&Object.prototype.hasOwnProperty.call(e,i),n=a?t?.[i]:void 0,c=s?e?.[i]:void 0;if(s)return a?void(P(n)&&P(c)?K(n,c,[...r,i],o):n!==c&&o.push({path:[...r,i],previousValue:A(n),existed:!0})):P(c)?void K(void 0,c,[...r,i],o):void o.push({path:[...r,i],previousValue:void 0,existed:!1});o.push({path:[...r,i],previousValue:A(n),existed:!0})}),o}function F(t){if(!t)return;const e={};return Object.keys(t).forEach(r=>{e[r]=t[r].map(t=>"object"==typeof t&&null!==t?A(t):t)}),e}function w(t,e){let r=t;for(const t of e){if(!r||!P(r[t]))return;r=r[t]}return r}class j{static{this.defaultFlavour=e}static{this.targetStates=new WeakMap}static{this.decorators={}}static{this.flavourResolver=R}static{d(t=>this.flavourResolver(t)),f((t,e)=>this.resolvePendingDecorators(t,e))}constructor(t=j.defaultFlavour){this.flavour=t}static getTargetState(t){if(!t)throw Error("Invalid target provided to Decoration state tracker");let e=this.targetStates.get(t);return e||(e={pending:[],flavour:void 0,directApply:!1},this.targetStates.set(t,e)),e}static applyPendingEntry(t,e){const r=v._metadata,o=v.Symbol(t.owner),i=void 0===t.metadataDiff?A(r[o]):void 0;try{if(void 0!==t.propertyKey&&void 0===t.descriptorSnapshot&&t.target){const e=Object.getOwnPropertyDescriptor(t.target,t.propertyKey);t.descriptorWasOwn=Object.prototype.hasOwnProperty.call(t.target,t.propertyKey),t.descriptorSnapshot=e?{...e}:void 0}const a=t.argsFactory?t.argsFactory():F(t.argsOverride),s=t.callback(e,a)(t.target,t.propertyKey,t.descriptor);if(void 0!==t.propertyKey&&s&&t.target&&Object.defineProperty(t.target,t.propertyKey,s),void 0!==t.propertyKey&&void 0===t.descriptor&&S()(t.owner??t.target,t.propertyKey),void 0===t.metadataDiff){const e=A(r[o]);t.metadataDiff=K(i,e)}}catch(t){}}static markPending(e){if(!e)return;const r=this.getTargetState(e);r.resolved=!1,r.flavour||(r.flavour=j.defaultFlavour),v.set(e,t.DecorationKeys.DECORATION,t.DecorationState.PENDING)}static ensureDefaultFlavour(t){if(!t)return;const e=D(t,j.defaultFlavour,j.defaultFlavour);let r;try{r=j.flavourResolver?j.flavourResolver(e):void 0}catch{r=void 0}r&&r!==j.defaultFlavour?j.resolvePendingDecorators(e,r):j.markPending(e)}static scheduleDefaultResolve(t){if(!t)return;const e=this.getTargetState(t);e.resolveScheduled||e.resolved||e.applying||(e.resolveScheduled=!0,Promise.resolve().then(()=>{e.resolveScheduled=!1,e.resolved||this.resolvePendingDecorators(t)}))}static registerPendingDecorator(e,r,o,i,a,s,n){const c=`${e?.name||"anonymous"}:${(i||"class")+""}:${Date.now()}:${Math.random()}`,l=this.getTargetState(e),d=F(s),u={owner:e,target:r,propertyKey:i,descriptor:a,callback:o,argsOverride:d,argsFactory:()=>F(d),key:c,definitionKey:n},f=()=>{const r=l.flavour||v.get(e,t.DecorationKeys.FLAVOUR)||j.defaultFlavour;return this.applyPendingEntry(u,r),u.lastAppliedPass=l.passId,u.lastAppliedFlavour=r,r},p=()=>(l.pending.push(u),u);if(l.directApply){p();const r=f();return l.appliedCount=l.pending.length,l.flavour=r,v.set(e,t.DecorationKeys.DECORATION,!0),c}if(p(),l.applying)return f(),c;if(j.flavourResolver!==R)try{const t=j.flavourResolver(e);if(t&&t!==j.defaultFlavour)return this.resolvePendingDecorators(e,t),c}catch{}return this.scheduleDefaultResolve(e),c}static resolvePendingDecorators(e,r){const o="function"==typeof e?e:e?.constructor||e;if(!o)return;const i=this.getTargetState(o);if(i.resolveScheduled=!1,!i.pending.length&&!r)return;const a=r||i.flavour||v.get(o,t.DecorationKeys.FLAVOUR)||j.defaultFlavour;if(i.applying)return;const s=i.appliedCount||0;if(!r&&i.lastAppliedFlavour===a&&s>=i.pending.length)return;const n=!(!r||r===j.defaultFlavour)||i.directApply;if(!i.pending.length)return;const c=(i.passId||0)+1;i.passId=c,i.applying=!0;try{if(n)for(const t of i.pending){if(!t)continue;if(t.lastAppliedPass===c)continue;const e=this.shouldOverrideEntry(t,a);void 0!==t.metadataDiff||void 0!==t.descriptorSnapshot?t.lastAppliedFlavour!==a&&e?(t.metadataDiff?.length&&I(t.owner,t.metadataDiff),T(t),this.applyPendingEntry(t,a),t.lastAppliedPass=c,t.lastAppliedFlavour=a):t.lastAppliedPass=c:(this.applyPendingEntry(t,a),t.lastAppliedPass=c,t.lastAppliedFlavour=a)}else{let t=s;for(;t<i.pending.length;){const e=i.pending[t++];e&&e.lastAppliedPass!==c&&(this.applyPendingEntry(e,a),e.lastAppliedPass=c,e.lastAppliedFlavour=a)}i.appliedCount=i.pending.length}}finally{i.applying=!1}i.flavour=a,i.resolved=!0,i.lastAppliedFlavour=a,n&&(i.appliedCount=i.pending.length,a!==j.defaultFlavour&&(i.directApply=!0)),v.set(o,t.DecorationKeys.DECORATION,!0)}for(t){return this.key=t,this}decorate(t=!1,...e){if(!this.key)throw Error("key must be provided before decorators can be added");if(!(e&&e.length||t||this.flavour===j.defaultFlavour))throw Error("Must provide overrides or addons to override or extend decaf's decorators");return t?this.extras=new Set([...(this.extras||new Set).values(),...e]):this.decorators=new Set([...e]),this}snapshotDecoratorArgs(){if(!this.decorators||!this.decorators.size)return;const t={};return Array.from(this.decorators.values()).forEach((e,r)=>{"object"==typeof e&&"args"in e&&Array.isArray(e.args)&&(t[r]=e.args.map(t=>"object"==typeof t&&null!==t?A(t):t))}),Object.keys(t).length?t:void 0}define(...t){if(t.find(t=>"object"==typeof t)&&1!==t.length)throw Error("When using an overridable decorator, only one is allowed");return this.decorate(!1,...t)}extend(...t){if(t.find(t=>"object"==typeof t)&&1!==t.length)throw Error("When extending using an overridable decorator, only one is allowed");return this.decorate(!0,...t)}decoratorFactory(t,e,r){function o(o,i,a){const s=e??j.flavourResolver(o),n=j.decorators[t];let c;const l=n[s]?n[s].extras:n[j.defaultFlavour].extras;c=n&&n[s]&&n[s].decorators&&n[s].decorators.size?n[s].decorators:n[j.defaultFlavour].decorators;const d=[...c?c.values():[]],u=[...(n[j.defaultFlavour]?.decorators||new Set).values()],f=d.reduce((t,e,r)=>("object"==typeof e&&"args"in e&&Array.isArray(e.args)&&(t[r]=e.args),t),{}),p=u.reduce((t,e,r)=>("object"==typeof e&&"args"in e&&Array.isArray(e.args)&&(t[r]=e.args),t),{}),y=[...d,...l?l.values():[]],h=d.length,v=r||{};let g=o,D=a;return y.forEach((t,e)=>{let r;if("object"==typeof t){const o=t,i=h>e?e:0,a=((h>e?v[i]:void 0)||("args"in o&&Array.isArray(o.args)?o.args:f[i]??p[i]??p[0]??[])).map(t=>"object"==typeof t&&null!==t?A(t):t);r=o.decorator(...a)}else{if("function"!=typeof t)throw Error("Unexpected decorator type: "+typeof t);r=t}const a=r(void 0===i?g:o,i,D);void 0===i?"function"==typeof a&&(g=a):void 0!==a&&(D=a)}),void 0===i?g:D}return Object.defineProperty(o,"name",{value:[e||"dynamic",t].join("_decorator_for_"),writable:!1}),o}apply(){if(!this.key)throw Error("No key provided for the decoration builder");const e=this.key,r=j.decorators[this.key]?.[this.flavour]?.decorators,o=this.decorators||r||new Set,i=void 0!==this.extras?this.extras:void 0;j.register(this.key,this.flavour,o,i);const a=(r,o,i)=>{const a=void 0!==o,s="function"==typeof r?r:r?.constructor||r;if(s&&a){v.innerGet(v.Symbol(s),t.DecorationKeys.FLAVOUR)||j.ensureDefaultFlavour(s);const a=this.snapshotDecoratorArgs();return j.registerPendingDecorator(s,r,t=>this.decoratorFactory(e,t,a),o,i,a,e),j.resolvePendingDecorators(s),o&&!i&&S()(s,o),o&&i&&E()(s,o,i),i}const n=this.flavour===j.defaultFlavour?void 0:this.flavour;return this.decoratorFactory(e,n)(r,o,i)};try{Object.defineProperty(a,"name",{value:[this.flavour,e].join("_decorator_for_"),writable:!1})}catch(t){}return a}static register(t,e,r,o){if(!t)throw Error("No key provided for the decoration builder");if(!r)throw Error("No decorators provided for the decoration builder");if(!e)throw Error("No flavour provided for the decoration builder");j.decorators[t]||(j.decorators[t]={}),j.decorators[t][e]||(j.decorators[t][e]={}),j.decorators[t][e].decorators=r,void 0!==o&&(j.decorators[t][e].extras=o)}static setResolver(t){j.flavourResolver=t}static shouldOverrideEntry(t,e){if(!t.definitionKey)return!1;if(e===j.defaultFlavour)return!1;const r=j.decorators[t.definitionKey];if(!r)return!1;const o=r[e];if(!o)return!1;const i=r[j.defaultFlavour],a=o.decorators&&o.decorators.size>0,s=o.extras instanceof Set&&o.extras.size>0;if(!a&&!s)return!1;if(!i)return!0;const n=!a||o.decorators===i.decorators,c=!s||o.extras===i.extras;return!(n&&c)}static for(t){return(new j).for(t)}static flavouredAs(t){return new j(t)}}function I(e,r){if(!r||!r.length)return;const o=v._metadata,i=v.Symbol(e),a=o[i]||(o[i]={});r.forEach(({path:e,previousValue:r,existed:o})=>{if(!e.length)return;if(e[0]===t.DecorationKeys.PROPERTIES)return;let i=a;for(let t=0;t<e.length-1;t++){const r=e[t];P(i[r])||(i[r]={}),i=i[r]}const s=e[e.length-1];o?i[s]=A(r):(delete i[s],((t,e)=>{for(let r=e.length;r>0;r--){const o=e.slice(0,r),i=o.slice(0,-1),a=o[o.length-1],s=0===i.length?t:w(t,i);if(!s||!P(s))break;const n=s[a];if(!P(n)||Reflect.ownKeys(n).length>0)break;delete s[a]}})(a,e.slice(0,-1)))})}function T(t){if(!t||void 0===t.propertyKey)return;const e=t.target;if(!e||void 0===t.descriptorWasOwn)return;const r=t.propertyKey,o=t.descriptorSnapshot;t.descriptorWasOwn?o?Object.defineProperty(e,r,o):delete e[r]:(delete e[r],o&&Object.defineProperty(e,r,o))}t.Decoration=j,t.DefaultFlavour=e,t.DefaultMetadata=a,t.Metadata=v,t.ObjectKeySplitter=r,t.PACKAGE_NAME=n,t.VERSION=s,t.apply=m,t.assignFlavour=D,t.description=e=>j.for(t.DecorationKeys.DESCRIPTION).define({decorator:e=>(r,o,i)=>O(v.key(t.DecorationKeys.DESCRIPTION,o?o.toString():t.DecorationKeys.CLASS),e)(r,o,i),args:[e]}).apply(),t.getValueBySplitter=y,t.metadata=O,t.metadataArray=(t,...e)=>(r,o,i)=>{const a=v.get(r,t)||[];return m(O(o?v.key(t,o):t,[...new Set([...a,...e])]))(r,o,i)},t.method=E,t.methodMetadata=(t,e)=>m(O(t,e),E()),t.param=b,t.paramMetadata=(e,r)=>(o,i,a)=>m(b(),O(v.key(t.DecorationKeys.METHODS,i,e),r))(o,i,a),t.prop=S,t.propMetadata=(t,e)=>m(O(t,e),S()),t.registerFlavourResolver=d,t.registerPendingResolver=f,t.resolveFlavour=u,t.resolvePendingDecorators=p,t.setValueBySplitter=h,t.uses=t=>e=>{const r=D(e,t,j.defaultFlavour);if(t!==j.defaultFlavour)j.resolvePendingDecorators(r,t);else{let t;try{t=j.flavourResolver?j.flavourResolver(r):void 0}catch{t=void 0}t&&t!==j.defaultFlavour?j.resolvePendingDecorators(r,t):j.markPending(r)}return e}},"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("reflect-metadata")):"function"==typeof define&&define.amd?define(["exports","reflect-metadata"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).decoration={});
|
|
1
|
+
var t,e;t=this,e=function(t){"use strict";const e="decaf",r=".";var o,i;t.DecorationKeys=void 0,(o=t.DecorationKeys||(t.DecorationKeys={})).LIBRARIES="libraries",o.REFLECT="__decaf",o.PROPERTIES="properties",o.METHODS="methods",o.CLASS="class",o.DESCRIPTION="description",o.CONSTRUCTOR="__original",o.PARAMETERS="parameters",o.FLAVOUR="flavour",o.DECORATION="decoration",o.DESIGN_TYPE="design:type",o.DESIGN_PARAMS="design:paramtypes",o.DESIGN_RETURN="design:returntype",t.DecorationState=void 0,(i=t.DecorationState||(t.DecorationState={})).PENDING="pending",i.ONGOING="ongoing";const a={[t.DecorationKeys.PROPERTIES]:[]},s="##VERSION##",n="##PACKAGE##";let c,l;function d(t){c=t}function u(t){return c?c(t):e}function f(t){l=t}function p(t,e){l&&l(t,e)}function y(t,e,o=r){const i=e.split(o);let a=t;for(const t of i){if(null==a||!Object.prototype.hasOwnProperty.call(a,t))return;a=a[t]}return a}function h(t,e,o,i=r){const a=e.split(i).filter((t=>t.length>0));if(0===a.length)return;let s=t;for(let t=0;t<a.length-1;t++){const e=a[t];void 0!==s[e]&&null!==s[e]&&"object"==typeof s[e]||(s[e]={}),s=s[e]}s[a[a.length-1]]=o}class v{static{this._allowReRegistration=!1}static{this._metadata={}}static{this._propertiesIndex={}}static{this.splitter=r}static{this.baseKey=t.DecorationKeys.REFLECT}static{this.mirror=!0}constructor(){}static Symbol(t){return Symbol.for([t.toString(),t.name].join(" - "))}static properties(t){const e=this.constr(t),r=this.Symbol(e),o=this._propertiesIndex[r];if(o&&o.size)return[...o];const i=this.get(e);return i&&i.properties?Object.keys(i.properties):void 0}static allowReregistration(t=!0){this._allowReRegistration=t}static methods(e){const r=this.get(e,t.DecorationKeys.METHODS);if(r)return Object.keys(r)}static description(e,r){return this.get(e,this.key(t.DecorationKeys.DESCRIPTION,r||t.DecorationKeys.CLASS))}static flavourOf(t){return u(t)}static flavouredAs(e){return this.innerGet(Symbol.for(t.DecorationKeys.FLAVOUR),e)||[]}static registeredFlavour(r){const o=this.innerGet(Symbol.for(t.DecorationKeys.FLAVOUR));if(!o)return;const i=this.constr(r);let a;for(const[t,r]of Object.entries(o))if(Array.isArray(r)&&r.some((t=>this.constr(t)===i))){if(t===e){a=a||t;continue}return t}return a}static params(e,r){return this.get(e,this.key(t.DecorationKeys.METHODS,r,t.DecorationKeys.DESIGN_PARAMS))}static param(t,e,r){const o=this.params(t,e);if(o){if(r>o.length-1)throw Error(`Parameter index ${r} out of range for ${e+""}`);return o[r]}}static return(e,r){return this.get(e,this.key(t.DecorationKeys.METHODS,r,t.DecorationKeys.DESIGN_RETURN))}static type(e,r){return this.get(e,this.key(t.DecorationKeys.PROPERTIES,r))}static constr(e){return e[t.DecorationKeys.CONSTRUCTOR]||e}static get(e,r){if(r===t.DecorationKeys.CONSTRUCTOR)return this.constr(e);const o=this.constr(e),i=this.collectConstructorChain(o);if(i.filter((e=>this.isDecorated(e)===t.DecorationState.PENDING)).forEach((t=>{p(t)})),0===i.length){const t=Symbol.for(o.toString());return this.innerGet(t,r)}const a=i.map((t=>this.innerGet(this.Symbol(t),r))).filter((t=>void 0!==t));return 0!==a.length?this.mergeMetadataChain(a):void 0}static isDecorated(e){const r=this.constr(e);return this.innerGet(this.Symbol(r),t.DecorationKeys.DECORATION)||!1}static innerGet(t,e){if(this._metadata[t])return e?"string"==typeof e?y(this._metadata[t],e,this.splitter):this._metadata[t][e]:this._metadata[t]}static collectConstructorChain(t){const e=[];let r=t;for(;"function"==typeof r&&r!==Function;){e.push(r);const t=Object.getPrototypeOf(r);if(!t||t===Function||t===Object)break;r=t}return e.reverse()}static mergeMetadataChain(t){let e;for(const r of t)e=void 0!==e&&this.isPlainObject(e)&&this.isPlainObject(r)?this.mergePlainObjects(e,r):this.cloneMetadataValue(r);return e}static cloneMetadataValue(t){return Array.isArray(t)?[...t]:this.isPlainObject(t)?this.mergePlainObjects({},t):t}static mergePlainObjects(t,e){const r={...t};for(const t of Object.keys(e)){const o=e[t],i=r[t];this.isPlainObject(o)?r[t]=this.isPlainObject(i)?this.mergePlainObjects(i,o):this.mergePlainObjects({},o):r[t]=Array.isArray(o)?[...o]:o}return r}static isPlainObject(t){if(null===t||"object"!=typeof t||Array.isArray(t))return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}static innerSet(t,e,r){if(this._metadata[t]||(this._metadata[t]={}),"string"==typeof e)return h(this._metadata[t],e,r,this.splitter);this._metadata[t][e]=r}static set(e,r,o){if(r===t.DecorationKeys.CONSTRUCTOR)return void Object.defineProperty(e,t.DecorationKeys.CONSTRUCTOR,{enumerable:!1,configurable:!1,writable:!1,value:o});"string"!=typeof e&&(e=this.constr(e)||e);const i="string"==typeof e?Symbol.for(e):this.Symbol(e);if("string"==typeof r){const e=`${t.DecorationKeys.PROPERTIES}${this.splitter}`;if(r.startsWith(e)){const t=r.slice(e.length);if(t.length){const e=this._propertiesIndex[i]||new Set;e.add(t),this._propertiesIndex[i]=e}}else if(r===t.DecorationKeys.PROPERTIES&&this.isPlainObject(o)){const t=this._propertiesIndex[i]||new Set;Object.keys(o).forEach((e=>{t.add(e)})),t.size&&(this._propertiesIndex[i]=t)}}this.innerSet(i,r,o),"string"!=typeof e&&v.mirror&&!Object.prototype.hasOwnProperty.call(e,this.baseKey)&&Object.defineProperty(e,this.baseKey,{enumerable:!1,configurable:!1,writable:!1,value:this._metadata[i]})}static registerLibrary(e,r){const o=Symbol.for(t.DecorationKeys.LIBRARIES);if(this.innerGet(o,e)&&!this._allowReRegistration)throw Error(`Library already ${e} registered with version ${r}`);this.innerSet(o,e,r)}static libraries(){const e=Symbol.for(t.DecorationKeys.LIBRARIES);return this.innerGet(e)||{}}static key(...t){return t.join(this.splitter)}}v.registerLibrary(n,s);const g=Symbol.for(t.DecorationKeys.FLAVOUR);function D(e,r,o){const i=v.constr(e),a=v.innerGet(v.Symbol(e),t.DecorationKeys.FLAVOUR)||o,s=(v.innerGet(g,a)||[]).filter((t=>v.constr(t)!==i));v.set(t.DecorationKeys.FLAVOUR,a,s);const n=new Set(v.innerGet(g,r)||[]);return n.add(e),v.set(t.DecorationKeys.FLAVOUR,r,[...n]),v.set(i,t.DecorationKeys.FLAVOUR,r),i}function O(e,r){return(o,i,a)=>{let s=o;if(i&&(s="function"==typeof o?o:o.constructor||o,void 0===a)){const e="function"==typeof o?o.prototype:o,r=Reflect.getOwnMetadata(t.DecorationKeys.DESIGN_TYPE,e,i),a=v.key(t.DecorationKeys.PROPERTIES,i.toString()),n=v.get(s,a);void 0===r&&void 0!==n||v.set(s,a,r)}v.set(s,e,r)}}function S(){return(e,r)=>{const o="function"==typeof e?e.prototype:e,i=Reflect.getOwnMetadata(t.DecorationKeys.DESIGN_TYPE,o,r);return O(v.key(t.DecorationKeys.PROPERTIES,r),i)(e,r)}}function b(){return(e,r,o)=>{if(!r)throw Error("The @param decorator can only be applied to methods");R()(e,r,Object.getOwnPropertyDescriptor(e,r));const i=v.params(e.constructor,r);if(!i)throw Error("Missing parameter types for "+r);if(o>=i.length)throw Error(`Parameter index ${o} out of range for ${r+""}`);O(v.key(t.DecorationKeys.METHODS,r,o.toString()),i[o])(e,r)}}function R(){return(e,r,o)=>{const i=Reflect.getOwnMetadata(t.DecorationKeys.DESIGN_PARAMS,e,r),a=Reflect.getOwnMetadata(t.DecorationKeys.DESIGN_RETURN,e,r);return E(O(v.key(t.DecorationKeys.METHODS,r,t.DecorationKeys.DESIGN_PARAMS),i),O(v.key(t.DecorationKeys.METHODS,r,t.DecorationKeys.DESIGN_RETURN),a))(e,r,o)}}function E(...t){return(e,r,o)=>{for(const i of t)void 0!==r?i(e,r,o):i(e)}}function m(e){const r=v.constr("function"==typeof e?e:e?.constructor),o=v.innerGet(v.Symbol(r),t.DecorationKeys.FLAVOUR);if(o&&o!==j.defaultFlavour)return o;const i="function"==typeof v.registeredFlavour?v.registeredFlavour(r):void 0;return i&&i!==j.defaultFlavour?i:o??j.defaultFlavour}function P(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}function A(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map((t=>A(t)));if(t instanceof Date)return new Date(t.getTime());if(t instanceof Set)return new Set(Array.from(t).map((t=>A(t))));if(t instanceof Map)return new Map(Array.from(t.entries()).map((([t,e])=>[t,A(e)])));if(t.constructor!==Object)return t;const e={};return Reflect.ownKeys(t).forEach((r=>{e[r]=A(t[r])})),e}function K(t,e,r=[],o=[]){return new Set([...t?Reflect.ownKeys(t):[],...e?Reflect.ownKeys(e):[]]).forEach((i=>{const a=!!t&&Object.prototype.hasOwnProperty.call(t,i),s=!!e&&Object.prototype.hasOwnProperty.call(e,i),n=a?t?.[i]:void 0,c=s?e?.[i]:void 0;if(s)return a?void(P(n)&&P(c)?K(n,c,[...r,i],o):n!==c&&o.push({path:[...r,i],previousValue:A(n),existed:!0})):P(c)?void K(void 0,c,[...r,i],o):void o.push({path:[...r,i],previousValue:void 0,existed:!1});o.push({path:[...r,i],previousValue:A(n),existed:!0})})),o}function w(t){if(!t)return;const e={};return Object.keys(t).forEach((r=>{e[r]=t[r].map((t=>"object"==typeof t&&null!==t?A(t):t))})),e}function F(t,e){let r=t;for(const t of e){if(!r||!P(r[t]))return;r=r[t]}return r}class j{static{this.defaultFlavour=e}static{this.targetStates=new WeakMap}static{this.decorators={}}static{this.flavourResolver=m}static{d((t=>this.flavourResolver(t))),f(((t,e)=>this.resolvePendingDecorators(t,e)))}constructor(t=j.defaultFlavour){this.flavour=t}static getTargetState(t){if(!t)throw Error("Invalid target provided to Decoration state tracker");let e=this.targetStates.get(t);return e||(e={pending:[],flavour:void 0,directApply:!1},this.targetStates.set(t,e)),e}static applyPendingEntry(t,e){const r=v._metadata,o=v.Symbol(t.owner),i=void 0===t.metadataDiff?A(r[o]):void 0;try{if(void 0!==t.propertyKey&&void 0===t.descriptorSnapshot&&t.target){const e=Object.getOwnPropertyDescriptor(t.target,t.propertyKey);t.descriptorWasOwn=Object.prototype.hasOwnProperty.call(t.target,t.propertyKey),t.descriptorSnapshot=e?{...e}:void 0}const a=t.argsFactory?t.argsFactory():w(t.argsOverride),s=t.callback(e,a)(t.target,t.propertyKey,t.descriptor);if(void 0!==t.propertyKey&&s&&t.target&&Object.defineProperty(t.target,t.propertyKey,s),void 0!==t.propertyKey&&void 0===t.descriptor&&S()(t.owner??t.target,t.propertyKey),void 0===t.metadataDiff){const e=A(r[o]);t.metadataDiff=K(i,e)}}catch(t){}}static markPending(e){if(!e)return;const r=this.getTargetState(e);r.resolved=!1,r.flavour||(r.flavour=j.defaultFlavour),v.set(e,t.DecorationKeys.DECORATION,t.DecorationState.PENDING)}static ensureDefaultFlavour(t){if(!t)return;const e=D(t,j.defaultFlavour,j.defaultFlavour);let r;try{r=j.flavourResolver?j.flavourResolver(e):void 0}catch{r=void 0}r&&r!==j.defaultFlavour?j.resolvePendingDecorators(e,r):j.markPending(e)}static scheduleDefaultResolve(t){if(!t)return;const e=this.getTargetState(t);e.resolveScheduled||e.resolved||e.applying||(e.resolveScheduled=!0,Promise.resolve().then((()=>{e.resolveScheduled=!1,e.resolved||this.resolvePendingDecorators(t)})))}static registerPendingDecorator(e,r,o,i,a,s,n){const c=`${e?.name||"anonymous"}:${(i||"class")+""}:${Date.now()}:${Math.random()}`,l=this.getTargetState(e),d=w(s),u={owner:e,target:r,propertyKey:i,descriptor:a,callback:o,argsOverride:d,argsFactory:()=>w(d),key:c,definitionKey:n},f=()=>{const r=l.flavour||v.get(e,t.DecorationKeys.FLAVOUR)||j.defaultFlavour;return this.applyPendingEntry(u,r),u.lastAppliedPass=l.passId,u.lastAppliedFlavour=r,r},p=()=>(l.pending.push(u),u);if(l.directApply){p();const r=f();return l.appliedCount=l.pending.length,l.flavour=r,v.set(e,t.DecorationKeys.DECORATION,!0),c}if(p(),l.applying)return f(),c;if(j.flavourResolver!==m)try{const t=j.flavourResolver(e);if(t&&t!==j.defaultFlavour)return this.resolvePendingDecorators(e,t),c}catch{}return this.scheduleDefaultResolve(e),c}static resolvePendingDecorators(e,r){const o="function"==typeof e?e:e?.constructor||e;if(!o)return;const i=this.getTargetState(o);if(i.resolveScheduled=!1,!i.pending.length&&!r)return;const a=r||i.flavour||v.get(o,t.DecorationKeys.FLAVOUR)||j.defaultFlavour;if(i.applying)return;const s=i.appliedCount||0;if(!r&&i.lastAppliedFlavour===a&&s>=i.pending.length)return;const n=!(!r||r===j.defaultFlavour)||i.directApply;if(!i.pending.length)return;const c=(i.passId||0)+1;i.passId=c,i.applying=!0;try{if(n)for(const t of i.pending){if(!t)continue;if(t.lastAppliedPass===c)continue;const e=this.shouldOverrideEntry(t,a);void 0!==t.metadataDiff||void 0!==t.descriptorSnapshot?t.lastAppliedFlavour!==a&&e?(t.metadataDiff?.length&&I(t.owner,t.metadataDiff),T(t),this.applyPendingEntry(t,a),t.lastAppliedPass=c,t.lastAppliedFlavour=a):t.lastAppliedPass=c:(this.applyPendingEntry(t,a),t.lastAppliedPass=c,t.lastAppliedFlavour=a)}else{let t=s;for(;t<i.pending.length;){const e=i.pending[t++];e&&e.lastAppliedPass!==c&&(this.applyPendingEntry(e,a),e.lastAppliedPass=c,e.lastAppliedFlavour=a)}i.appliedCount=i.pending.length}}finally{i.applying=!1}i.flavour=a,i.resolved=!0,i.lastAppliedFlavour=a,n&&(i.appliedCount=i.pending.length,a!==j.defaultFlavour&&(i.directApply=!0)),v.set(o,t.DecorationKeys.DECORATION,!0)}for(t){return this.key=t,this}decorate(t=!1,...e){if(!this.key)throw Error("key must be provided before decorators can be added");if(!(e&&e.length||t||this.flavour===j.defaultFlavour))throw Error("Must provide overrides or addons to override or extend decaf's decorators");return t?this.extras=new Set([...(this.extras||new Set).values(),...e]):this.decorators=new Set([...e]),this}snapshotDecoratorArgs(){if(!this.decorators||!this.decorators.size)return;const t={};return Array.from(this.decorators.values()).forEach(((e,r)=>{"object"==typeof e&&"args"in e&&Array.isArray(e.args)&&(t[r]=e.args.map((t=>"object"==typeof t&&null!==t?A(t):t)))})),Object.keys(t).length?t:void 0}define(...t){if(t.find((t=>"object"==typeof t))&&1!==t.length)throw Error("When using an overridable decorator, only one is allowed");return this.decorate(!1,...t)}extend(...t){if(t.find((t=>"object"==typeof t))&&1!==t.length)throw Error("When extending using an overridable decorator, only one is allowed");return this.decorate(!0,...t)}decoratorFactory(t,e,r){function o(o,i,a){const s=e??j.flavourResolver(o),n=j.decorators[t];let c;const l=n[s]?n[s].extras:n[j.defaultFlavour].extras;c=n&&n[s]&&n[s].decorators&&n[s].decorators.size?n[s].decorators:n[j.defaultFlavour].decorators;const d=[...c?c.values():[]],u=[...(n[j.defaultFlavour]?.decorators||new Set).values()],f=d.reduce(((t,e,r)=>("object"==typeof e&&"args"in e&&Array.isArray(e.args)&&(t[r]=e.args),t)),{}),p=u.reduce(((t,e,r)=>("object"==typeof e&&"args"in e&&Array.isArray(e.args)&&(t[r]=e.args),t)),{}),y=[...d,...l?l.values():[]],h=d.length,v=r||{};let g=o,D=a;return y.forEach(((t,e)=>{let r;if("object"==typeof t){const o=t,i=h>e?e:0,a=((h>e?v[i]:void 0)||("args"in o&&Array.isArray(o.args)?o.args:f[i]??p[i]??p[0]??[])).map((t=>"object"==typeof t&&null!==t?A(t):t));r=o.decorator(...a)}else{if("function"!=typeof t)throw Error("Unexpected decorator type: "+typeof t);r=t}const a=r(void 0===i?g:o,i,D);void 0===i?"function"==typeof a&&(g=a):void 0!==a&&(D=a)})),void 0===i?g:D}return Object.defineProperty(o,"name",{value:[e||"dynamic",t].join("_decorator_for_"),writable:!1}),o}apply(){if(!this.key)throw Error("No key provided for the decoration builder");const e=this.key,r=j.decorators[this.key]?.[this.flavour]?.decorators,o=this.decorators||r||new Set,i=void 0!==this.extras?this.extras:void 0;j.register(this.key,this.flavour,o,i);const a=(r,o,i)=>{const a=void 0!==o,s="function"==typeof r?r:r?.constructor||r;if(s&&a){v.innerGet(v.Symbol(s),t.DecorationKeys.FLAVOUR)||j.ensureDefaultFlavour(s);const a=this.snapshotDecoratorArgs();return j.registerPendingDecorator(s,r,(t=>this.decoratorFactory(e,t,a)),o,i,a,e),j.resolvePendingDecorators(s),o&&!i&&S()(s,o),o&&i&&R()(s,o,i),i}const n=this.flavour===j.defaultFlavour?void 0:this.flavour;return this.decoratorFactory(e,n)(r,o,i)};try{Object.defineProperty(a,"name",{value:[this.flavour,e].join("_decorator_for_"),writable:!1})}catch(t){}return a}static register(t,e,r,o){if(!t)throw Error("No key provided for the decoration builder");if(!r)throw Error("No decorators provided for the decoration builder");if(!e)throw Error("No flavour provided for the decoration builder");j.decorators[t]||(j.decorators[t]={}),j.decorators[t][e]||(j.decorators[t][e]={}),j.decorators[t][e].decorators=r,void 0!==o&&(j.decorators[t][e].extras=o)}static setResolver(t){j.flavourResolver=t}static shouldOverrideEntry(t,e){if(!t.definitionKey)return!1;if(e===j.defaultFlavour)return!1;const r=j.decorators[t.definitionKey];if(!r)return!1;const o=r[e];if(!o)return!1;const i=r[j.defaultFlavour],a=o.decorators&&o.decorators.size>0,s=o.extras instanceof Set&&o.extras.size>0;if(!a&&!s)return!1;if(!i)return!0;const n=!a||o.decorators===i.decorators,c=!s||o.extras===i.extras;return!(n&&c)}static for(t){return(new j).for(t)}static flavouredAs(t){return new j(t)}}function I(e,r){if(!r||!r.length)return;const o=v._metadata,i=v.Symbol(e),a=o[i]||(o[i]={});r.forEach((({path:e,previousValue:r,existed:o})=>{if(!e.length)return;if(e[0]===t.DecorationKeys.PROPERTIES)return;let i=a;for(let t=0;t<e.length-1;t++){const r=e[t];P(i[r])||(i[r]={}),i=i[r]}const s=e[e.length-1];o?i[s]=A(r):(delete i[s],((t,e)=>{for(let r=e.length;r>0;r--){const o=e.slice(0,r),i=o.slice(0,-1),a=o[o.length-1],s=0===i.length?t:F(t,i);if(!s||!P(s))break;const n=s[a];if(!P(n)||Reflect.ownKeys(n).length>0)break;delete s[a]}})(a,e.slice(0,-1)))}))}function T(t){if(!t||void 0===t.propertyKey)return;const e=t.target;if(!e||void 0===t.descriptorWasOwn)return;const r=t.propertyKey,o=t.descriptorSnapshot;t.descriptorWasOwn?o?Object.defineProperty(e,r,o):delete e[r]:(delete e[r],o&&Object.defineProperty(e,r,o))}t.Decoration=j,t.DefaultFlavour=e,t.DefaultMetadata=a,t.Metadata=v,t.ObjectKeySplitter=r,t.PACKAGE_NAME=n,t.VERSION=s,t.apply=E,t.assignFlavour=D,t.description=e=>j.for(t.DecorationKeys.DESCRIPTION).define({decorator:e=>(r,o,i)=>O(v.key(t.DecorationKeys.DESCRIPTION,o?o.toString():t.DecorationKeys.CLASS),e)(r,o,i),args:[e]}).apply(),t.getValueBySplitter=y,t.metadata=O,t.metadataArray=(t,...e)=>(r,o,i)=>{const a=v.get(r,t)||[];return E(O(o?v.key(t,o):t,[...new Set([...a,...e])]))(r,o,i)},t.method=R,t.methodMetadata=(t,e)=>E(O(t,e),R()),t.param=b,t.paramMetadata=(e,r)=>(o,i,a)=>E(b(),O(v.key(t.DecorationKeys.METHODS,i,e),r))(o,i,a),t.prop=S,t.propMetadata=(t,e)=>E(O(t,e),S()),t.registerFlavourResolver=d,t.registerPendingResolver=f,t.resolveFlavour=u,t.resolvePendingDecorators=p,t.setValueBySplitter=h,t.uses=t=>e=>{const r=D(e,t,j.defaultFlavour);if(t!==j.defaultFlavour)j.resolvePendingDecorators(r,t);else{let t;try{t=j.flavourResolver?j.flavourResolver(r):void 0}catch{t=void 0}t&&t!==j.defaultFlavour?j.resolvePendingDecorators(r,t):j.markPending(r)}return e}},"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("reflect-metadata")):"function"==typeof define&&define.amd?define(["exports","reflect-metadata"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).decoration={});
|
|
2
2
|
//# sourceMappingURL=decoration.cjs.map
|