@decaf-ts/decorator-validation 1.10.5 → 1.11.0

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 (218) hide show
  1. package/README.md +1 -1
  2. package/dist/decorator-validation.cjs +1 -1
  3. package/dist/decorator-validation.cjs.map +1 -1
  4. package/dist/decorator-validation.js +1 -1
  5. package/dist/decorator-validation.js.map +1 -1
  6. package/lib/esm/index.d.ts +2 -1
  7. package/lib/esm/index.js +2 -1
  8. package/lib/esm/index.js.map +1 -1
  9. package/lib/esm/model/Builder.d.ts +84 -0
  10. package/lib/esm/model/Builder.js +395 -129
  11. package/lib/esm/model/Builder.js.map +1 -1
  12. package/lib/esm/model/Model.d.ts +21 -19
  13. package/lib/esm/model/Model.js +112 -105
  14. package/lib/esm/model/Model.js.map +1 -1
  15. package/lib/esm/model/constants.d.ts +8 -8
  16. package/lib/esm/model/constants.js +8 -9
  17. package/lib/esm/model/constants.js.map +1 -1
  18. package/lib/esm/model/decorators.d.ts +2 -12
  19. package/lib/esm/model/decorators.js +5 -39
  20. package/lib/esm/model/decorators.js.map +1 -1
  21. package/lib/esm/model/index.d.ts +1 -0
  22. package/lib/esm/model/index.js +1 -0
  23. package/lib/esm/model/index.js.map +1 -1
  24. package/lib/esm/model/types.d.ts +0 -12
  25. package/lib/esm/model/utils.d.ts +0 -3
  26. package/lib/esm/model/utils.js +0 -10
  27. package/lib/esm/model/utils.js.map +1 -1
  28. package/lib/esm/model/validation.d.ts +4 -37
  29. package/lib/esm/model/validation.js +30 -106
  30. package/lib/esm/model/validation.js.map +1 -1
  31. package/lib/esm/overrides/Metadata.d.ts +128 -0
  32. package/lib/esm/overrides/Metadata.js +2 -0
  33. package/lib/esm/overrides/Metadata.js.map +1 -0
  34. package/lib/esm/overrides/index.d.ts +3 -0
  35. package/lib/esm/overrides/index.js +4 -0
  36. package/lib/esm/overrides/index.js.map +1 -0
  37. package/lib/esm/overrides/overrides.d.ts +1 -0
  38. package/lib/esm/overrides/overrides.js +79 -0
  39. package/lib/esm/overrides/overrides.js.map +1 -0
  40. package/lib/esm/overrides/types.d.ts +9 -0
  41. package/lib/esm/overrides/types.js +2 -0
  42. package/lib/esm/overrides/types.js.map +1 -0
  43. package/lib/esm/types/validation.d.ts +4 -2
  44. package/lib/esm/utils/constants.d.ts +4 -18
  45. package/lib/esm/utils/constants.js +4 -17
  46. package/lib/esm/utils/constants.js.map +1 -1
  47. package/lib/esm/utils/dates.d.ts +0 -1
  48. package/lib/esm/utils/dates.js +0 -1
  49. package/lib/esm/utils/dates.js.map +1 -1
  50. package/lib/esm/utils/equality.d.ts +56 -0
  51. package/lib/esm/utils/equality.js +160 -0
  52. package/lib/esm/utils/equality.js.map +1 -0
  53. package/lib/esm/utils/index.d.ts +1 -2
  54. package/lib/esm/utils/index.js +1 -2
  55. package/lib/esm/utils/index.js.map +1 -1
  56. package/lib/esm/utils/registry.d.ts +1 -1
  57. package/lib/esm/utils/serialization.d.ts +2 -2
  58. package/lib/esm/utils/serialization.js +10 -2
  59. package/lib/esm/utils/serialization.js.map +1 -1
  60. package/lib/esm/utils/types.d.ts +0 -102
  61. package/lib/esm/validation/Validation.d.ts +2 -3
  62. package/lib/esm/validation/Validation.js +11 -6
  63. package/lib/esm/validation/Validation.js.map +1 -1
  64. package/lib/esm/validation/Validators/BaseValidator.js +7 -3
  65. package/lib/esm/validation/Validators/BaseValidator.js.map +1 -1
  66. package/lib/esm/validation/Validators/DiffValidator.js +1 -1
  67. package/lib/esm/validation/Validators/DiffValidator.js.map +1 -1
  68. package/lib/esm/validation/Validators/EqualsValidator.js +1 -1
  69. package/lib/esm/validation/Validators/EqualsValidator.js.map +1 -1
  70. package/lib/esm/validation/Validators/GreaterThanOrEqualValidator.js +1 -1
  71. package/lib/esm/validation/Validators/GreaterThanOrEqualValidator.js.map +1 -1
  72. package/lib/esm/validation/Validators/LessThanOrEqualValidator.js +1 -1
  73. package/lib/esm/validation/Validators/LessThanOrEqualValidator.js.map +1 -1
  74. package/lib/esm/validation/Validators/ListValidator.js +4 -4
  75. package/lib/esm/validation/Validators/ListValidator.js.map +1 -1
  76. package/lib/esm/validation/Validators/MaxLengthValidator.js +3 -2
  77. package/lib/esm/validation/Validators/MaxLengthValidator.js.map +1 -1
  78. package/lib/esm/validation/Validators/MaxValidator.js +1 -1
  79. package/lib/esm/validation/Validators/MaxValidator.js.map +1 -1
  80. package/lib/esm/validation/Validators/MinLengthValidator.js +3 -2
  81. package/lib/esm/validation/Validators/MinLengthValidator.js.map +1 -1
  82. package/lib/esm/validation/Validators/MinValidator.js +1 -1
  83. package/lib/esm/validation/Validators/MinValidator.js.map +1 -1
  84. package/lib/esm/validation/Validators/OptionValidator.d.ts +29 -0
  85. package/lib/esm/validation/Validators/OptionValidator.js +61 -0
  86. package/lib/esm/validation/Validators/OptionValidator.js.map +1 -0
  87. package/lib/esm/validation/Validators/TypeValidator.js +2 -2
  88. package/lib/esm/validation/Validators/TypeValidator.js.map +1 -1
  89. package/lib/esm/validation/Validators/constants.d.ts +2 -1
  90. package/lib/esm/validation/Validators/constants.js +3 -2
  91. package/lib/esm/validation/Validators/constants.js.map +1 -1
  92. package/lib/esm/validation/Validators/decorators.d.ts +1 -1
  93. package/lib/esm/validation/Validators/decorators.js +2 -2
  94. package/lib/esm/validation/Validators/decorators.js.map +1 -1
  95. package/lib/esm/validation/Validators/index.d.ts +1 -0
  96. package/lib/esm/validation/Validators/index.js +1 -0
  97. package/lib/esm/validation/Validators/index.js.map +1 -1
  98. package/lib/esm/validation/Validators/utils.d.ts +33 -0
  99. package/lib/esm/validation/Validators/utils.js +62 -0
  100. package/lib/esm/validation/Validators/utils.js.map +1 -1
  101. package/lib/esm/validation/decorators.d.ts +28 -17
  102. package/lib/esm/validation/decorators.js +86 -55
  103. package/lib/esm/validation/decorators.js.map +1 -1
  104. package/lib/esm/validation/types.d.ts +15 -5
  105. package/lib/esm/validation/types.js.map +1 -1
  106. package/lib/index.cjs +2 -1
  107. package/lib/index.d.ts +2 -1
  108. package/lib/index.js.map +1 -1
  109. package/lib/model/Builder.cjs +399 -128
  110. package/lib/model/Builder.d.ts +84 -0
  111. package/lib/model/Builder.js.map +1 -1
  112. package/lib/model/Model.cjs +114 -107
  113. package/lib/model/Model.d.ts +21 -19
  114. package/lib/model/Model.js.map +1 -1
  115. package/lib/model/constants.cjs +8 -9
  116. package/lib/model/constants.d.ts +8 -8
  117. package/lib/model/constants.js.map +1 -1
  118. package/lib/model/decorators.cjs +4 -39
  119. package/lib/model/decorators.d.ts +2 -12
  120. package/lib/model/decorators.js.map +1 -1
  121. package/lib/model/index.cjs +1 -0
  122. package/lib/model/index.d.ts +1 -0
  123. package/lib/model/index.js.map +1 -1
  124. package/lib/model/types.d.ts +0 -12
  125. package/lib/model/utils.cjs +0 -12
  126. package/lib/model/utils.d.ts +0 -3
  127. package/lib/model/utils.js.map +1 -1
  128. package/lib/model/validation.cjs +30 -108
  129. package/lib/model/validation.d.ts +4 -37
  130. package/lib/model/validation.js.map +1 -1
  131. package/lib/overrides/Metadata.cjs +3 -0
  132. package/lib/overrides/Metadata.d.ts +128 -0
  133. package/lib/overrides/Metadata.js.map +1 -0
  134. package/lib/overrides/index.cjs +20 -0
  135. package/lib/overrides/index.d.ts +3 -0
  136. package/lib/overrides/index.js.map +1 -0
  137. package/lib/overrides/overrides.cjs +81 -0
  138. package/lib/overrides/overrides.d.ts +1 -0
  139. package/lib/overrides/overrides.js.map +1 -0
  140. package/lib/overrides/types.cjs +3 -0
  141. package/lib/overrides/types.d.ts +9 -0
  142. package/lib/overrides/types.js.map +1 -0
  143. package/lib/types/validation.d.ts +4 -2
  144. package/lib/utils/constants.cjs +5 -18
  145. package/lib/utils/constants.d.ts +4 -18
  146. package/lib/utils/constants.js.map +1 -1
  147. package/lib/utils/dates.cjs +0 -1
  148. package/lib/utils/dates.d.ts +0 -1
  149. package/lib/utils/dates.js.map +1 -1
  150. package/lib/utils/equality.cjs +163 -0
  151. package/lib/utils/equality.d.ts +56 -0
  152. package/lib/utils/equality.js.map +1 -0
  153. package/lib/utils/index.cjs +1 -2
  154. package/lib/utils/index.d.ts +1 -2
  155. package/lib/utils/index.js.map +1 -1
  156. package/lib/utils/registry.d.ts +1 -1
  157. package/lib/utils/serialization.cjs +10 -2
  158. package/lib/utils/serialization.d.ts +2 -2
  159. package/lib/utils/serialization.js.map +1 -1
  160. package/lib/utils/types.d.ts +0 -102
  161. package/lib/validation/Validation.cjs +11 -6
  162. package/lib/validation/Validation.d.ts +2 -3
  163. package/lib/validation/Validation.js.map +1 -1
  164. package/lib/validation/Validators/BaseValidator.cjs +7 -3
  165. package/lib/validation/Validators/BaseValidator.js.map +1 -1
  166. package/lib/validation/Validators/DiffValidator.cjs +2 -2
  167. package/lib/validation/Validators/DiffValidator.js.map +1 -1
  168. package/lib/validation/Validators/EqualsValidator.cjs +2 -2
  169. package/lib/validation/Validators/EqualsValidator.js.map +1 -1
  170. package/lib/validation/Validators/GreaterThanOrEqualValidator.cjs +2 -2
  171. package/lib/validation/Validators/GreaterThanOrEqualValidator.js.map +1 -1
  172. package/lib/validation/Validators/LessThanOrEqualValidator.cjs +2 -2
  173. package/lib/validation/Validators/LessThanOrEqualValidator.js.map +1 -1
  174. package/lib/validation/Validators/ListValidator.cjs +4 -4
  175. package/lib/validation/Validators/ListValidator.js.map +1 -1
  176. package/lib/validation/Validators/MaxLengthValidator.cjs +3 -2
  177. package/lib/validation/Validators/MaxLengthValidator.js.map +1 -1
  178. package/lib/validation/Validators/MaxValidator.cjs +1 -1
  179. package/lib/validation/Validators/MaxValidator.js.map +1 -1
  180. package/lib/validation/Validators/MinLengthValidator.cjs +3 -2
  181. package/lib/validation/Validators/MinLengthValidator.js.map +1 -1
  182. package/lib/validation/Validators/MinValidator.cjs +1 -1
  183. package/lib/validation/Validators/MinValidator.js.map +1 -1
  184. package/lib/validation/Validators/OptionValidator.cjs +64 -0
  185. package/lib/validation/Validators/OptionValidator.d.ts +29 -0
  186. package/lib/validation/Validators/OptionValidator.js.map +1 -0
  187. package/lib/validation/Validators/TypeValidator.cjs +2 -2
  188. package/lib/validation/Validators/TypeValidator.js.map +1 -1
  189. package/lib/validation/Validators/constants.cjs +5 -4
  190. package/lib/validation/Validators/constants.d.ts +2 -1
  191. package/lib/validation/Validators/constants.js.map +1 -1
  192. package/lib/validation/Validators/decorators.cjs +3 -3
  193. package/lib/validation/Validators/decorators.d.ts +1 -1
  194. package/lib/validation/Validators/decorators.js.map +1 -1
  195. package/lib/validation/Validators/index.cjs +1 -0
  196. package/lib/validation/Validators/index.d.ts +1 -0
  197. package/lib/validation/Validators/index.js.map +1 -1
  198. package/lib/validation/Validators/utils.cjs +66 -0
  199. package/lib/validation/Validators/utils.d.ts +33 -0
  200. package/lib/validation/Validators/utils.js.map +1 -1
  201. package/lib/validation/decorators.cjs +102 -69
  202. package/lib/validation/decorators.d.ts +28 -17
  203. package/lib/validation/decorators.js.map +1 -1
  204. package/lib/validation/types.d.ts +15 -5
  205. package/lib/validation/types.js.map +1 -1
  206. package/package.json +2 -3
  207. package/lib/esm/utils/Decoration.d.ts +0 -135
  208. package/lib/esm/utils/Decoration.js +0 -227
  209. package/lib/esm/utils/Decoration.js.map +0 -1
  210. package/lib/esm/utils/decorators.d.ts +0 -38
  211. package/lib/esm/utils/decorators.js +0 -64
  212. package/lib/esm/utils/decorators.js.map +0 -1
  213. package/lib/utils/Decoration.cjs +0 -231
  214. package/lib/utils/Decoration.d.ts +0 -135
  215. package/lib/utils/Decoration.js.map +0 -1
  216. package/lib/utils/decorators.cjs +0 -68
  217. package/lib/utils/decorators.d.ts +0 -38
  218. package/lib/utils/decorators.js.map +0 -1
@@ -1,231 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Decoration = void 0;
4
- const constants_1 = require("./constants.cjs");
5
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
- function defaultFlavourResolver(target) {
7
- return constants_1.DefaultFlavour;
8
- }
9
- /**
10
- * @description A decorator management class that handles flavoured decorators
11
- * @summary The Decoration class provides a builder pattern for creating and managing decorators with different flavours.
12
- * It supports registering, extending, and applying decorators with context-aware flavour resolution.
13
- * The class implements a fluent interface for defining, extending, and applying decorators with different flavours,
14
- * allowing for framework-specific decorator implementations while maintaining a consistent API.
15
- * @template T Type of the decorator (ClassDecorator | PropertyDecorator | MethodDecorator)
16
- * @param {string} [flavour] Optional flavour parameter for the decorator context
17
- * @class
18
- * @category Model
19
- * @example
20
- * ```typescript
21
- * // Create a new decoration for 'component' with default flavour
22
- * const componentDecorator = new Decoration()
23
- * .for('component')
24
- * .define(customComponentDecorator);
25
- *
26
- * // Create a flavoured decoration
27
- * const vueComponent = new Decoration('vue')
28
- * .for('component')
29
- * .define(vueComponentDecorator);
30
- *
31
- * // Apply the decoration
32
- * @componentDecorator
33
- * class MyComponent {}
34
- * ```
35
- * @mermaid
36
- * sequenceDiagram
37
- * participant C as Client
38
- * participant D as Decoration
39
- * participant R as FlavourResolver
40
- * participant F as DecoratorFactory
41
- *
42
- * C->>D: new Decoration(flavour)
43
- * C->>D: for(key)
44
- * C->>D: define(decorators)
45
- * D->>D: register(key, flavour, decorators)
46
- * D->>F: decoratorFactory(key, flavour)
47
- * F->>R: resolve(target)
48
- * R-->>F: resolved flavour
49
- * F->>F: apply decorators
50
- * F-->>C: decorated target
51
- */
52
- class Decoration {
53
- /**
54
- * @description Static map of registered decorators
55
- * @summary Stores all registered decorators organized by key and flavour
56
- */
57
- static { this.decorators = {}; }
58
- /**
59
- * @description Function to resolve flavour from a target
60
- * @summary Resolver function that determines the appropriate flavour for a given target
61
- */
62
- static { this.flavourResolver = defaultFlavourResolver; }
63
- constructor(flavour = constants_1.DefaultFlavour) {
64
- this.flavour = flavour;
65
- }
66
- /**
67
- * @description Sets the key for the decoration builder
68
- * @summary Initializes a new decoration chain with the specified key
69
- * @param {string} key The identifier for the decorator
70
- * @return {DecorationBuilderMid} Builder instance for method chaining
71
- */
72
- for(key) {
73
- this.key = key;
74
- return this;
75
- }
76
- /**
77
- * @description Adds decorators to the current context
78
- * @summary Internal method to add decorators with addon support
79
- * @param {boolean} [addon=false] Whether the decorators are addons
80
- * @param decorators Array of decorators
81
- * @return {this} Current instance for chaining
82
- */
83
- decorate(addon = false, ...decorators) {
84
- if (!this.key)
85
- throw new Error("key must be provided before decorators can be added");
86
- if ((!decorators || !decorators.length) &&
87
- !addon &&
88
- this.flavour !== constants_1.DefaultFlavour)
89
- throw new Error("Must provide overrides or addons to override or extend decaf's decorators");
90
- if (this.flavour === constants_1.DefaultFlavour && addon)
91
- throw new Error("Default flavour cannot be extended");
92
- this[addon ? "extras" : "decorators"] = new Set([
93
- ...(this[addon ? "extras" : "decorators"] || new Set()).values(),
94
- ...decorators,
95
- ]);
96
- return this;
97
- }
98
- /**
99
- * @description Defines the base decorators
100
- * @summary Sets the primary decorators for the current context
101
- * @param decorators Decorators to define
102
- * @return Builder instance for finishing the chain
103
- */
104
- define(...decorators) {
105
- return this.decorate(false, ...decorators);
106
- }
107
- /**
108
- * @description Extends existing decorators
109
- * @summary Adds additional decorators to the current context
110
- * @param decorators Additional decorators
111
- * @return {DecorationBuilderBuild} Builder instance for building the decorator
112
- */
113
- extend(...decorators) {
114
- return this.decorate(true, ...decorators);
115
- }
116
- decoratorFactory(key, f = constants_1.DefaultFlavour) {
117
- const contextDecorator = function contextDecorator(target, propertyKey, descriptor) {
118
- const flavour = Decoration.flavourResolver(target);
119
- const cache = Decoration.decorators[key];
120
- let decorators;
121
- const extras = cache[flavour]
122
- ? cache[flavour].extras
123
- : cache[constants_1.DefaultFlavour].extras;
124
- const extraArgs = [
125
- ...(cache[constants_1.DefaultFlavour].extras
126
- ? cache[constants_1.DefaultFlavour].extras.values()
127
- : []),
128
- ].reduce((accum, e, i) => {
129
- if (e.args)
130
- accum[i] = e.args;
131
- return accum;
132
- }, {});
133
- if (cache &&
134
- cache[flavour] &&
135
- cache[flavour].decorators &&
136
- cache[flavour].decorators.size) {
137
- decorators = cache[flavour].decorators;
138
- }
139
- else {
140
- decorators = cache[constants_1.DefaultFlavour].decorators;
141
- }
142
- const decoratorArgs = [
143
- ...cache[constants_1.DefaultFlavour].decorators.values(),
144
- ].reduce((accum, e, i) => {
145
- if (e.args)
146
- accum[i] = e.args;
147
- return accum;
148
- }, {});
149
- const toApply = [
150
- ...(decorators ? decorators.values() : []),
151
- ...(extras ? extras.values() : []),
152
- ];
153
- return toApply.reduce((_, d, i) => {
154
- switch (typeof d) {
155
- case "object": {
156
- const { decorator, args, transform } = d;
157
- const argz = args || i < (decorators ? decorators.size : 0)
158
- ? decoratorArgs[i]
159
- : extraArgs[i - (decorators ? decorators.size : 0)] ||
160
- (decorators ? decoratorArgs[i - decorators.size] : []);
161
- const transformed = transform
162
- ? transform(argz || [])
163
- : argz || [];
164
- return decorator(...transformed)(target, propertyKey, descriptor);
165
- }
166
- case "function":
167
- return d(target, propertyKey, descriptor);
168
- default:
169
- throw new Error(`Unexpected decorator type: ${typeof d}`);
170
- }
171
- }, { target, propertyKey, descriptor });
172
- };
173
- Object.defineProperty(contextDecorator, "name", {
174
- value: [f, key].join("_decorator_for_"),
175
- writable: false,
176
- });
177
- return contextDecorator;
178
- }
179
- /**
180
- * @description Creates the final decorator function
181
- * @summary Builds and returns the decorator factory function
182
- * @return {function(any, any?, TypedPropertyDescriptor?): any} The generated decorator function
183
- */
184
- apply() {
185
- if (!this.key)
186
- throw new Error("No key provided for the decoration builder");
187
- Decoration.register(this.key, this.flavour, this.decorators || new Set(), this.extras);
188
- return this.decoratorFactory(this.key, this.flavour);
189
- }
190
- /**
191
- * @description Registers decorators for a specific key and flavour
192
- * @summary Internal method to store decorators in the static registry
193
- * @param {string} key Decorator key
194
- * @param {string} flavour Decorator flavour
195
- * @param [decorators] Primary decorators
196
- * @param [extras] Additional decorators
197
- */
198
- static register(key, flavour, decorators, extras) {
199
- if (!key) {
200
- throw new Error("No key provided for the decoration builder");
201
- }
202
- if (!decorators)
203
- throw new Error("No decorators provided for the decoration builder");
204
- if (!flavour)
205
- throw new Error("No flavour provided for the decoration builder");
206
- if (!Decoration.decorators[key])
207
- Decoration.decorators[key] = {};
208
- if (!Decoration.decorators[key][flavour])
209
- Decoration.decorators[key][flavour] = {};
210
- if (decorators)
211
- Decoration.decorators[key][flavour].decorators = decorators;
212
- if (extras)
213
- Decoration.decorators[key][flavour].extras = extras;
214
- }
215
- /**
216
- * @description Sets the global flavour resolver
217
- * @summary Configures the function used to determine decorator flavours
218
- * @param {FlavourResolver} resolver Function to resolve flavours
219
- */
220
- static setFlavourResolver(resolver) {
221
- Decoration.flavourResolver = resolver;
222
- }
223
- static for(key) {
224
- return new Decoration().for(key);
225
- }
226
- static flavouredAs(flavour) {
227
- return new Decoration(flavour);
228
- }
229
- }
230
- exports.Decoration = Decoration;
231
- //# sourceMappingURL=Decoration.js.map
@@ -1,135 +0,0 @@
1
- import { DecorationBuilderBuild, DecorationBuilderEnd, DecorationBuilderMid, DecorationBuilderStart, FlavourResolver, IDecorationBuilder } from "./types";
2
- export type DecoratorTypes = ClassDecorator | PropertyDecorator | MethodDecorator;
3
- export type DecoratorFactory = (...args: any[]) => DecoratorTypes;
4
- export type DecoratorFactoryArgs = {
5
- decorator: DecoratorFactory;
6
- args?: any[];
7
- transform?: (args: any[]) => any[];
8
- };
9
- export type DecoratorData = DecoratorTypes | DecoratorFactoryArgs;
10
- /**
11
- * @description A decorator management class that handles flavoured decorators
12
- * @summary The Decoration class provides a builder pattern for creating and managing decorators with different flavours.
13
- * It supports registering, extending, and applying decorators with context-aware flavour resolution.
14
- * The class implements a fluent interface for defining, extending, and applying decorators with different flavours,
15
- * allowing for framework-specific decorator implementations while maintaining a consistent API.
16
- * @template T Type of the decorator (ClassDecorator | PropertyDecorator | MethodDecorator)
17
- * @param {string} [flavour] Optional flavour parameter for the decorator context
18
- * @class
19
- * @category Model
20
- * @example
21
- * ```typescript
22
- * // Create a new decoration for 'component' with default flavour
23
- * const componentDecorator = new Decoration()
24
- * .for('component')
25
- * .define(customComponentDecorator);
26
- *
27
- * // Create a flavoured decoration
28
- * const vueComponent = new Decoration('vue')
29
- * .for('component')
30
- * .define(vueComponentDecorator);
31
- *
32
- * // Apply the decoration
33
- * @componentDecorator
34
- * class MyComponent {}
35
- * ```
36
- * @mermaid
37
- * sequenceDiagram
38
- * participant C as Client
39
- * participant D as Decoration
40
- * participant R as FlavourResolver
41
- * participant F as DecoratorFactory
42
- *
43
- * C->>D: new Decoration(flavour)
44
- * C->>D: for(key)
45
- * C->>D: define(decorators)
46
- * D->>D: register(key, flavour, decorators)
47
- * D->>F: decoratorFactory(key, flavour)
48
- * F->>R: resolve(target)
49
- * R-->>F: resolved flavour
50
- * F->>F: apply decorators
51
- * F-->>C: decorated target
52
- */
53
- export declare class Decoration implements IDecorationBuilder {
54
- private flavour;
55
- /**
56
- * @description Static map of registered decorators
57
- * @summary Stores all registered decorators organized by key and flavour
58
- */
59
- private static decorators;
60
- /**
61
- * @description Function to resolve flavour from a target
62
- * @summary Resolver function that determines the appropriate flavour for a given target
63
- */
64
- private static flavourResolver;
65
- /**
66
- * @description Set of decorators for the current context
67
- */
68
- private decorators?;
69
- /**
70
- * @description Set of additional decorators
71
- */
72
- private extras?;
73
- /**
74
- * @description Current decorator key
75
- */
76
- private key?;
77
- constructor(flavour?: string);
78
- /**
79
- * @description Sets the key for the decoration builder
80
- * @summary Initializes a new decoration chain with the specified key
81
- * @param {string} key The identifier for the decorator
82
- * @return {DecorationBuilderMid} Builder instance for method chaining
83
- */
84
- for(key: string): DecorationBuilderMid;
85
- /**
86
- * @description Adds decorators to the current context
87
- * @summary Internal method to add decorators with addon support
88
- * @param {boolean} [addon=false] Whether the decorators are addons
89
- * @param decorators Array of decorators
90
- * @return {this} Current instance for chaining
91
- */
92
- private decorate;
93
- /**
94
- * @description Defines the base decorators
95
- * @summary Sets the primary decorators for the current context
96
- * @param decorators Decorators to define
97
- * @return Builder instance for finishing the chain
98
- */
99
- define(...decorators: DecoratorData[]): DecorationBuilderEnd & DecorationBuilderBuild;
100
- /**
101
- * @description Extends existing decorators
102
- * @summary Adds additional decorators to the current context
103
- * @param decorators Additional decorators
104
- * @return {DecorationBuilderBuild} Builder instance for building the decorator
105
- */
106
- extend(...decorators: DecoratorData[]): DecorationBuilderBuild;
107
- protected decoratorFactory(key: string, f?: string): (target: object, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => {
108
- target: object;
109
- propertyKey: any;
110
- descriptor: TypedPropertyDescriptor<any> | undefined;
111
- };
112
- /**
113
- * @description Creates the final decorator function
114
- * @summary Builds and returns the decorator factory function
115
- * @return {function(any, any?, TypedPropertyDescriptor?): any} The generated decorator function
116
- */
117
- apply(): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
118
- /**
119
- * @description Registers decorators for a specific key and flavour
120
- * @summary Internal method to store decorators in the static registry
121
- * @param {string} key Decorator key
122
- * @param {string} flavour Decorator flavour
123
- * @param [decorators] Primary decorators
124
- * @param [extras] Additional decorators
125
- */
126
- private static register;
127
- /**
128
- * @description Sets the global flavour resolver
129
- * @summary Configures the function used to determine decorator flavours
130
- * @param {FlavourResolver} resolver Function to resolve flavours
131
- */
132
- static setFlavourResolver(resolver: FlavourResolver): void;
133
- static for(key: string): DecorationBuilderMid;
134
- static flavouredAs(flavour: string): DecorationBuilderStart;
135
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"Decoration.js","sourceRoot":"","sources":["../../src/utils/Decoration.ts"],"names":[],"mappings":";;;AAQA,+CAA6C;AAE7C,6DAA6D;AAC7D,SAAS,sBAAsB,CAAC,MAAc;IAC5C,OAAO,0BAAc,CAAC;AACxB,CAAC;AAgBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAa,UAAU;IACrB;;;OAGG;aACY,eAAU,GASrB,EAAE,CAAC;IAEP;;;OAGG;aACY,oBAAe,GAAoB,sBAAsB,CAAC;IAiBzE,YAAoB,UAAkB,0BAAc;QAAhC,YA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AI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAEpE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACjE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;YACtC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QAC3C,IAAI,UAAU;YAAE,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC;QAC5E,IAAI,MAAM;YAAE,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,kBAAkB,CAAC,QAAyB;QACjD,UAAU,CAAC,eAAe,GAAG,QAAQ,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,OAAe;QAChC,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;;AAzPH,gCA0PC"}
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prop = prop;
4
- exports.propMetadata = propMetadata;
5
- const reflection_1 = require("@decaf-ts/reflection");
6
- const constants_1 = require("./constants.cjs");
7
- const Decoration_1 = require("./Decoration.cjs");
8
- /**
9
- * @description Property decorator factory for model attributes
10
- * @summary Creates a decorator that marks class properties as model attributes
11
- *
12
- * @param {string} [key=ModelKeys.ATTRIBUTE] - The metadata key under which to store the property name
13
- * @return {function(object, any?): void} - Decorator function that registers the property
14
- * @function prop
15
- * @category Property Decorators
16
- *
17
- * @mermaid
18
- * sequenceDiagram
19
- * participant D as Decorator
20
- * participant M as Model
21
- *
22
- * D->>M: Check if key exists
23
- * alt key exists
24
- * M-->>D: Return existing props array
25
- * else key doesn't exist
26
- * D->>M: Create new props array
27
- * end
28
- * D->>M: Check if property exists
29
- * alt property not in array
30
- * D->>M: Add property to array
31
- * end
32
- */
33
- function prop(key = constants_1.ModelKeys.ATTRIBUTE) {
34
- return Decoration_1.Decoration.for(key)
35
- .define(function prop(model, propertyKey) {
36
- let props;
37
- if (Object.prototype.hasOwnProperty.call(model, key)) {
38
- props = model[key];
39
- }
40
- else {
41
- Object.defineProperty(model, key, {
42
- enumerable: false,
43
- configurable: false,
44
- writable: false,
45
- value: [],
46
- });
47
- props = model[key];
48
- }
49
- if (!props.includes(propertyKey))
50
- props.push(propertyKey);
51
- })
52
- .apply();
53
- }
54
- /**
55
- * @description Combined property decorator factory for metadata and attribute marking
56
- * @summary Creates a decorator that both marks a property as a model attribute and assigns metadata to it
57
- *
58
- * @template V
59
- * @param {string} key - The metadata key
60
- * @param {V} value - The metadata value to associate with the property
61
- * @return {Function} - Combined decorator function
62
- * @function propMetadata
63
- * @category Property Decorators
64
- */
65
- function propMetadata(key, value) {
66
- return (0, reflection_1.apply)(prop(), (0, reflection_1.metadata)(key, value));
67
- }
68
- //# sourceMappingURL=decorators.js.map
@@ -1,38 +0,0 @@
1
- /**
2
- * @description Property decorator factory for model attributes
3
- * @summary Creates a decorator that marks class properties as model attributes
4
- *
5
- * @param {string} [key=ModelKeys.ATTRIBUTE] - The metadata key under which to store the property name
6
- * @return {function(object, any?): void} - Decorator function that registers the property
7
- * @function prop
8
- * @category Property Decorators
9
- *
10
- * @mermaid
11
- * sequenceDiagram
12
- * participant D as Decorator
13
- * participant M as Model
14
- *
15
- * D->>M: Check if key exists
16
- * alt key exists
17
- * M-->>D: Return existing props array
18
- * else key doesn't exist
19
- * D->>M: Create new props array
20
- * end
21
- * D->>M: Check if property exists
22
- * alt property not in array
23
- * D->>M: Add property to array
24
- * end
25
- */
26
- export declare function prop(key?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
27
- /**
28
- * @description Combined property decorator factory for metadata and attribute marking
29
- * @summary Creates a decorator that both marks a property as a model attribute and assigns metadata to it
30
- *
31
- * @template V
32
- * @param {string} key - The metadata key
33
- * @param {V} value - The metadata value to associate with the property
34
- * @return {Function} - Combined decorator function
35
- * @function propMetadata
36
- * @category Property Decorators
37
- */
38
- export declare function propMetadata<V>(key: string, value: V): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
@@ -1 +0,0 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/utils/decorators.ts"],"names":[],"mappings":";;AA6BA,oBAmBC;AAaD,oCAEC;AA/DD,qDAAuD;AACvD,+CAAwC;AACxC,iDAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,IAAI,CAAC,MAAc,qBAAS,CAAC,SAAS;IACpD,OAAO,uBAAU,CAAC,GAAG,CAAC,GAAG,CAAC;SACvB,MAAM,CAAC,SAAS,IAAI,CAAC,KAAa,EAAE,WAAiB;QACpD,IAAI,KAAe,CAAC;QACpB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YACrD,KAAK,GAAI,KAAa,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE;gBAChC,UAAU,EAAE,KAAK;gBACjB,YAAY,EAAE,KAAK;gBACnB,QAAQ,EAAE,KAAK;gBACf,KAAK,EAAE,EAAE;aACV,CAAC,CAAC;YACH,KAAK,GAAI,KAAa,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAqB,CAAC;YACxC,KAAK,CAAC,IAAI,CAAC,WAAqB,CAAC,CAAC;IACtC,CAAC,CAAC;SACD,KAAK,EAAE,CAAC;AACb,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAAI,GAAW,EAAE,KAAQ;IACnD,OAAO,IAAA,kBAAK,EAAC,IAAI,EAAE,EAAE,IAAA,qBAAQ,EAAI,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAChD,CAAC"}