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
/
static-amendment.ts
127 lines (122 loc) · 4.47 KB
/
static-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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { Class } from '@proc7ts/primitives';
import { AmendablePropertyDescriptor, Amendatory } from '../base';
import { AeClass, AmendableClass } from '../class';
import { AeStatic, DecoratedAeStatic } from './ae-static';
/**
* An amendment of static class member (static property).
*
* Can be used as static property decorator, unless expects an amended entity other than {@link AeStatic}.
*
* @typeParam TValue - Amended member value type.
* @typeParam TClass - A type of amended class.
* @typeParam TUpdate - Amended member update type accepted by its setter.
* @typeParam TAmended - A type of the entity representing a static member to amend.
*/
export type StaticAmendment<
TValue extends TUpdate,
TClass extends AmendableClass = Class,
TUpdate = TValue,
TAmended extends AeStatic<TValue, TClass, TUpdate> = AeStatic<TValue, TClass, TUpdate>,
> = StaticAmendment.ForBase<
AeClass<TClass>,
AeStatic<TValue, TClass, TUpdate>,
TValue,
TClass,
TUpdate,
TAmended
>;
export namespace StaticAmendment {
export type ForBase<
TClassBase extends AeClass<TClass>,
TStaticBase extends TClassBase & AeStatic<TValue, TClass, TUpdate>,
TValue extends TUpdate,
TClass extends AmendableClass,
TUpdate,
TAmended extends TStaticBase,
> = TStaticBase extends TAmended
? StaticAmendmentDecorator<TValue, TClass, TUpdate>
: StaticAmendatory.ForBase<TClassBase, TStaticBase, TValue, TClass, TUpdate, TAmended>;
}
/**
* Static class member amendatory instance.
*
* @typeParam TValue - Amended member value type.
* @typeParam TClass - A type of amended class.
* @typeParam TUpdate - Amended member update type accepted by its setter.
* @typeParam TAmended - A type of the entity representing a static member to amend.
*/
export interface StaticAmendatory<
TValue extends TUpdate,
TClass extends AmendableClass = Class,
TUpdate = TValue,
TAmended extends AeStatic<TValue, TClass, TUpdate> = AeStatic<TValue, TClass, TUpdate>,
> extends StaticAmendatory.ForBase<
AeClass<TClass>,
AeStatic<TValue, TClass, TUpdate>,
TValue,
TClass,
TUpdate,
TAmended
> {
/**
* Decorates the given static member.
*
* @param decorated - Decorated static member representation.
* @param key - Decorated property key.
* @param descriptor - Decorated property descriptor, or nothing when decorating a static field.
*
* @returns Either nothing, or updated property descriptor.
*/
decorateAmended<TStaticValue extends TValue>(
this: void,
decorated: DecoratedAeStatic<TClass, TAmended>,
key: string | symbol,
descriptor?: AmendablePropertyDescriptor<TStaticValue, TClass, TUpdate>,
): void | AmendablePropertyDescriptor<TStaticValue, TClass, TUpdate>;
}
export namespace StaticAmendatory {
export interface ForBase<
TClassBase extends AeClass<TClass>,
TStaticBase extends TClassBase & AeStatic<TValue, TClass, TUpdate>,
TValue extends TUpdate,
TClass extends AmendableClass,
TUpdate,
TAmended extends TStaticBase,
> extends Amendatory<TAmended> {
decorateAmended<TStaticValue extends TValue>(
this: void,
decorated: DecoratedAeStatic.ForBase<TClassBase, TStaticBase, TClass, TAmended>,
key: string | symbol,
descriptor?: AmendablePropertyDescriptor<TStaticValue, InstanceType<TClass>, TUpdate>,
): void | AmendablePropertyDescriptor<TStaticValue, InstanceType<TClass>, TUpdate>;
}
}
/**
* An amendment of static class member (static property) that can be used as static property decorator.
*
* @typeParam TValue - Amended member value type.
* @typeParam TClass - A type of amended class.
* @typeParam TUpdate - Amended member update type accepted by its setter.
*/
export interface StaticAmendmentDecorator<
TValue extends TUpdate,
TClass extends AmendableClass = Class,
TUpdate = TValue,
> extends StaticAmendatory<TValue, TClass, TUpdate, AeStatic<TValue, TClass, TUpdate>> {
/**
* Applies this amendment to decorated static property.
*
* @typeParam TMemberValue - Decorated property value type.
* @param classConstructor - Decorated class constructor.
* @param key - Decorated property key.
* @param descriptor - Decorated property descriptor, or nothing when decorating a static instance field.
*
* @returns Either nothing, or updated property descriptor.
*/
<TMemberValue extends TValue>(
this: void,
classConstructor: TClass,
key: string | symbol,
descriptor?: AmendablePropertyDescriptor<TMemberValue, TClass, TUpdate>,
): void | any;
}