This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-amendment.ts
83 lines (78 loc) · 2.49 KB
/
class-amendment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { AbstractClass } from '@proc7ts/primitives';
import { Amendatory } from '../base';
import { AeClass, DecoratedAeClass } from './ae-class';
/**
* Class amendment.
*
* Can be used as class decorator, unless expects an amended entity other than {@link AeClass}.
*
* @typeParam TClass - A type of amended class.
* @typeParam TAmended - A type of amended entity representing a class to amend.
*/
export type ClassAmendment<
TClass extends AbstractClass,
TAmended extends AeClass<TClass> = AeClass<TClass>,
> = AeClass<any> extends TAmended
? ClassAmendmentDecorator<TClass>
: ClassAmendatory<TClass, TAmended>;
export namespace ClassAmendment {
export type ForBase<
TBase extends AeClass<TClass>,
TClass extends AbstractClass,
TAmended extends TBase,
> = TBase extends TAmended
? ClassAmendmentDecorator<TClass>
: ClassAmendatory.ForBase<TBase, TClass, TAmended>;
}
/**
* Class amendatory instance.
*
* @typeParam TClass - A type of amended class.
* @typeParam TAmended - A type of amended entity representing a class to amend.
*/
export interface ClassAmendatory<
TClass extends AbstractClass,
TAmended extends AeClass<TClass> = AeClass<TClass>,
> extends ClassAmendatory.ForBase<AeClass<TClass>, TClass, TAmended> {
/**
* Decorates the given class.
*
* @param decorated - Decorated class representation.
*/
decorateAmended(this: void, decorated: DecoratedAeClass<TClass, TAmended>): void;
}
export namespace ClassAmendatory {
/**
* Class amendatory instance for the given base amended entity type..
*
* @typeParam TBase - Base amended entity type.
* @typeParam TClass - A type of amended class.
* @typeParam TAmended - A type of amended entity representing a class to amend.
*/
export interface ForBase<
TBase extends AeClass<TClass>,
TClass extends AbstractClass,
TAmended extends TBase,
> extends Amendatory<TAmended> {
/**
* Decorates the given class.
*
* @param decorated - Decorated class representation.
*/
decorateAmended(this: void, decorated: DecoratedAeClass.ForBase<TBase, TClass, TAmended>): void;
}
}
/**
* Class amendment that can be used as class decorator.
*
* @typeParam TClass - A type of amended class.
*/
export interface ClassAmendmentDecorator<TClass extends AbstractClass>
extends ClassAmendatory<TClass> {
/**
* Applies this amendment to decorated class.
*
* @param classConstructor - Decorated class constructor.
*/
(this: void, classConstructor: TClass): void;
}