@decaf-ts/decoration 0.0.2
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/LICENSE.md +21 -0
- package/README.md +385 -0
- package/dist/decoration.cjs +649 -0
- package/dist/decoration.esm.cjs +633 -0
- package/lib/constants.cjs +64 -0
- package/lib/constants.d.ts +58 -0
- package/lib/decoration/Decoration.cjs +270 -0
- package/lib/decoration/Decoration.d.ts +196 -0
- package/lib/decoration/index.cjs +19 -0
- package/lib/decoration/index.d.ts +2 -0
- package/lib/decoration/types.cjs +3 -0
- package/lib/decoration/types.d.ts +95 -0
- package/lib/decorators.cjs +97 -0
- package/lib/decorators.d.ts +57 -0
- package/lib/esm/constants.d.ts +58 -0
- package/lib/esm/constants.js +61 -0
- package/lib/esm/decoration/Decoration.d.ts +196 -0
- package/lib/esm/decoration/Decoration.js +266 -0
- package/lib/esm/decoration/index.d.ts +2 -0
- package/lib/esm/decoration/index.js +3 -0
- package/lib/esm/decoration/types.d.ts +95 -0
- package/lib/esm/decoration/types.js +2 -0
- package/lib/esm/decorators.d.ts +57 -0
- package/lib/esm/decorators.js +90 -0
- package/lib/esm/index.d.ts +21 -0
- package/lib/esm/index.js +22 -0
- package/lib/esm/metadata/Metadata.d.ts +99 -0
- package/lib/esm/metadata/Metadata.js +199 -0
- package/lib/esm/metadata/index.d.ts +2 -0
- package/lib/esm/metadata/index.js +3 -0
- package/lib/esm/metadata/types.d.ts +16 -0
- package/lib/esm/metadata/types.js +2 -0
- package/lib/index.cjs +39 -0
- package/lib/index.d.ts +21 -0
- package/lib/metadata/Metadata.cjs +203 -0
- package/lib/metadata/Metadata.d.ts +99 -0
- package/lib/metadata/index.cjs +19 -0
- package/lib/metadata/index.d.ts +2 -0
- package/lib/metadata/types.cjs +4 -0
- package/lib/metadata/types.d.ts +16 -0
- package/package.json +114 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Decoration.cjs"), exports);
|
|
18
|
+
__exportStar(require("./types.cjs"), exports);
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZGVjb3JhdGlvbi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsbURBQTZCO0FBQzdCLDhDQUF3QiIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gXCIuL0RlY29yYXRpb25cIjtcbmV4cG9ydCAqIGZyb20gXCIuL3R5cGVzXCI7XG4iXX0=
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6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VybWluZXMgdGhlIGFwcHJvcHJpYXRlIGZsYXZvdXIgZm9yIGEgZ2l2ZW4gdGFyZ2V0IG9iamVjdC5cbiAqIFRoaXMgaXMgdXNlZCBieSB0aGUgRGVjb3JhdGlvbiBjbGFzcyB0byByZXNvbHZlIHdoaWNoIGZsYXZvdXIgb2YgZGVjb3JhdG9yIHRvIGFwcGx5IGJhc2VkIG9uIHRoZSB0YXJnZXQuXG4gKlxuICogQHR5cGVkZWYge2Z1bmN0aW9uKG9iamVjdCk6IHN0cmluZ30gRmxhdm91clJlc29sdmVyXG4gKlxuICogQHBhcmFtIHtvYmplY3R9IHRhcmdldCAtIFRoZSB0YXJnZXQgb2JqZWN0IHRvIHJlc29sdmUgdGhlIGZsYXZvdXIgZm9yXG4gKiBAcmV0dXJuIHtzdHJpbmd9IFRoZSByZXNvbHZlZCBmbGF2b3VyIGlkZW50aWZpZXJcbiAqIEBtZW1iZXJPZiBtb2R1bGU6ZGVjb3JhdGlvblxuICovXG5leHBvcnQgdHlwZSBGbGF2b3VyUmVzb2x2ZXIgPSAodGFyZ2V0OiBvYmplY3QpID0+IHN0cmluZztcbiJdfQ==
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { DecoratorData } from "./Decoration";
|
|
2
|
+
/**
|
|
3
|
+
* @description Interface for the final stage of the decoration builder pattern
|
|
4
|
+
* @summary Represents the build stage of the decoration builder, providing the ability to apply
|
|
5
|
+
* the configured decorator to a target. This is the final stage in the builder chain.
|
|
6
|
+
*
|
|
7
|
+
* @interface DecorationBuilderBuild
|
|
8
|
+
*/
|
|
9
|
+
export interface DecorationBuilderBuild {
|
|
10
|
+
/**
|
|
11
|
+
* @description Creates and returns the decorator function
|
|
12
|
+
* @summary Finalizes the builder process and returns a decorator function that can be applied to a class,
|
|
13
|
+
* property, or method.
|
|
14
|
+
*
|
|
15
|
+
* @returns {function} A decorator function that can be applied to a target
|
|
16
|
+
*/
|
|
17
|
+
apply(): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @description Interface for the extension stage of the decoration builder pattern
|
|
21
|
+
* @summary Represents the extension stage of the decoration builder, providing the ability to add
|
|
22
|
+
* additional decorators to the existing configuration.
|
|
23
|
+
*
|
|
24
|
+
* @interface DecorationBuilderEnd
|
|
25
|
+
* @memberOf module:decoration
|
|
26
|
+
*/
|
|
27
|
+
export interface DecorationBuilderEnd {
|
|
28
|
+
/**
|
|
29
|
+
* @description Adds additional decorators to the existing configuration
|
|
30
|
+
* @summary Extends the current decorator configuration with additional decorators.
|
|
31
|
+
* This is useful for adding behavior to existing decorators.
|
|
32
|
+
*
|
|
33
|
+
* @param {...(ClassDecorator|PropertyDecorator|MethodDecorator)} decorators - Additional decorators to add
|
|
34
|
+
* @returns {DecorationBuilderBuild} The build stage of the builder pattern
|
|
35
|
+
*/
|
|
36
|
+
extend(...decorators: DecoratorData[]): DecorationBuilderBuild;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @description Interface for the middle stage of the decoration builder pattern
|
|
40
|
+
* @summary Represents the middle stage of the decoration builder, extending the end stage
|
|
41
|
+
* and providing the ability to define the primary decorators for the configuration.
|
|
42
|
+
*
|
|
43
|
+
* @interface DecorationBuilderMid
|
|
44
|
+
* @memberOf module:decoration
|
|
45
|
+
*/
|
|
46
|
+
export interface DecorationBuilderMid extends DecorationBuilderEnd {
|
|
47
|
+
/**
|
|
48
|
+
* @description Defines the primary decorators for the configuration
|
|
49
|
+
* @summary Sets the main decorators for the current context. This is typically
|
|
50
|
+
* called after specifying the key with the 'for' method.
|
|
51
|
+
*/
|
|
52
|
+
define(...decorators: DecoratorData[]): DecorationBuilderEnd & DecorationBuilderBuild;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @description Interface for the starting stage of the decoration builder pattern
|
|
56
|
+
* @summary Represents the initial stage of the decoration builder, providing the entry point
|
|
57
|
+
* for the builder pattern by specifying the key for the decorator.
|
|
58
|
+
*
|
|
59
|
+
* @interface DecorationBuilderStart
|
|
60
|
+
* @memberOf module:decoration
|
|
61
|
+
*/
|
|
62
|
+
export interface DecorationBuilderStart {
|
|
63
|
+
/**
|
|
64
|
+
* @description Specifies the key for the decorator
|
|
65
|
+
* @summary Sets the identifier for the decorator, which is used to register and retrieve
|
|
66
|
+
* the decorator in the decoration registry.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} id - The identifier for the decorator
|
|
69
|
+
* @return {DecorationBuilderMid} The middle stage of the builder pattern
|
|
70
|
+
*/
|
|
71
|
+
for(id: string): DecorationBuilderMid;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @description Comprehensive interface for the complete decoration builder pattern
|
|
75
|
+
* @summary A unified interface that combines all stages of the decoration builder pattern,
|
|
76
|
+
* providing a complete API for creating, configuring, and applying decorators.
|
|
77
|
+
* This interface is implemented by the Decoration class.
|
|
78
|
+
*
|
|
79
|
+
* @interface IDecorationBuilder
|
|
80
|
+
* @memberOf module:decoration
|
|
81
|
+
*/
|
|
82
|
+
export interface IDecorationBuilder extends DecorationBuilderStart, DecorationBuilderMid, DecorationBuilderEnd, DecorationBuilderBuild {
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @description Type definition for a function that resolves the flavour for a target
|
|
86
|
+
* @summary Defines a function type that determines the appropriate flavour for a given target object.
|
|
87
|
+
* This is used by the Decoration class to resolve which flavour of decorator to apply based on the target.
|
|
88
|
+
*
|
|
89
|
+
* @typedef {function(object): string} FlavourResolver
|
|
90
|
+
*
|
|
91
|
+
* @param {object} target - The target object to resolve the flavour for
|
|
92
|
+
* @return {string} The resolved flavour identifier
|
|
93
|
+
* @memberOf module:decoration
|
|
94
|
+
*/
|
|
95
|
+
export type FlavourResolver = (target: object) => string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.metadata = metadata;
|
|
4
|
+
exports.prop = prop;
|
|
5
|
+
exports.apply = apply;
|
|
6
|
+
exports.propMetadata = propMetadata;
|
|
7
|
+
exports.description = description;
|
|
8
|
+
const Metadata_1 = require("./metadata/Metadata.cjs");
|
|
9
|
+
const constants_1 = require("./constants.cjs");
|
|
10
|
+
/**
|
|
11
|
+
* @description Assigns arbitrary metadata to a target using a string key
|
|
12
|
+
* @summary Decorator factory that stores a key/value pair in the central Metadata store for the provided class or member.
|
|
13
|
+
* @param {string} key The metadata key to associate with the target
|
|
14
|
+
* @param {*} value The metadata value to store under the given key
|
|
15
|
+
* @return A decorator that writes the metadata when applied
|
|
16
|
+
* @function metadata
|
|
17
|
+
* @category Decorators
|
|
18
|
+
*/
|
|
19
|
+
function metadata(key, value) {
|
|
20
|
+
return function metadata(model, prop,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
|
+
descriptor) {
|
|
23
|
+
Metadata_1.Metadata.set(prop ? model.constructor : model, key, value);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @description Captures and stores a property's design type
|
|
28
|
+
* @summary Decorator factory that reads the reflected design:type for a property and registers it in the Metadata store under the properties map.
|
|
29
|
+
* @return A decorator that records the property's type metadata when applied
|
|
30
|
+
* @function prop
|
|
31
|
+
* @category Property Decorators
|
|
32
|
+
*/
|
|
33
|
+
function prop() {
|
|
34
|
+
return function prop(model, prop) {
|
|
35
|
+
const designType = Reflect.getOwnMetadata(constants_1.DecorationKeys.DESIGN_TYPE, model, prop);
|
|
36
|
+
return metadata(`${constants_1.DecorationKeys.PROPERTIES}.${prop}`, designType)(model, prop);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @description Decorator factory that applies multiple decorators to a single target
|
|
41
|
+
* @summary Creates a composite decorator that applies multiple decorators in sequence, correctly handling class, method, and property decorators.
|
|
42
|
+
* @param {Array<ClassDecorator | MethodDecorator | PropertyDecorator>} decorators - Array of decorators to apply
|
|
43
|
+
* @return {Function} A decorator function that applies all provided decorators to the target
|
|
44
|
+
* @function apply
|
|
45
|
+
* @mermaid
|
|
46
|
+
* sequenceDiagram
|
|
47
|
+
* participant U as User Code
|
|
48
|
+
* participant A as apply(...decorators)
|
|
49
|
+
* participant D as Decorator
|
|
50
|
+
* U->>A: get decorator(...decorators)
|
|
51
|
+
* A->>U: returns (target, key?, desc?) => void
|
|
52
|
+
* U->>A: invoke on target
|
|
53
|
+
* loop for each decorator
|
|
54
|
+
* A->>D: invoke appropriate decorator type
|
|
55
|
+
* end
|
|
56
|
+
* @category Decorators
|
|
57
|
+
*/
|
|
58
|
+
function apply(...decorators) {
|
|
59
|
+
return (target, propertyKey, descriptor) => {
|
|
60
|
+
for (const decorator of decorators) {
|
|
61
|
+
if (target instanceof Function && !descriptor) {
|
|
62
|
+
decorator(target);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
decorator(target, propertyKey, descriptor);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @description Creates a property metadata decorator
|
|
71
|
+
* @summary Convenience factory that combines metadata(key, value) and prop() to both set an arbitrary metadata key and record the property's design type.
|
|
72
|
+
* @param {string} key The metadata key to set for the property
|
|
73
|
+
* @param {*} value The metadata value to associate with the key
|
|
74
|
+
* @return A decorator that sets the metadata and captures the property's type
|
|
75
|
+
* @function propMetadata
|
|
76
|
+
* @category Property Decorators
|
|
77
|
+
*/
|
|
78
|
+
function propMetadata(key, value) {
|
|
79
|
+
return apply(metadata(key, value), prop());
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @description Attaches a human-readable description to a class or member
|
|
83
|
+
* @summary Decorator factory that stores a textual description in the Metadata store under the appropriate description key for a class or its property.
|
|
84
|
+
* @param {string} desc The descriptive text to associate with the class or property
|
|
85
|
+
* @return A decorator that records the description when applied
|
|
86
|
+
* @function description
|
|
87
|
+
* @category Decorators
|
|
88
|
+
*/
|
|
89
|
+
function description(desc) {
|
|
90
|
+
return function description(original, prop, descriptor) {
|
|
91
|
+
return metadata([
|
|
92
|
+
constants_1.DecorationKeys.DESCRIPTION,
|
|
93
|
+
prop ? prop.toString() : constants_1.DecorationKeys.CLASS,
|
|
94
|
+
].join(constants_1.ObjectKeySplitter), desc)(original, prop, descriptor);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVjb3JhdG9ycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9kZWNvcmF0b3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBWUEsNEJBVUM7QUFTRCxvQkFZQztBQXFCRCxzQkFvQkM7QUFXRCxvQ0FFQztBQVVELGtDQVVDO0FBckhELHNEQUErQztBQUMvQywrQ0FBZ0U7QUFFaEU7Ozs7Ozs7O0dBUUc7QUFDSCxTQUFnQixRQUFRLENBQUMsR0FBVyxFQUFFLEtBQVU7SUFDOUMsT0FBTyxTQUFTLFFBQVEsQ0FDdEIsS0FBVSxFQUVWLElBQVU7SUFDViw2REFBNkQ7SUFDN0QsVUFBK0I7UUFFL0IsbUJBQVEsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsR0FBRyxFQUFFLEtBQUssQ0FBQyxDQUFDO0lBQzdELENBQUMsQ0FBQztBQUNKLENBQUM7QUFFRDs7Ozs7O0dBTUc7QUFDSCxTQUFnQixJQUFJO0lBQ2xCLE9BQU8sU0FBUyxJQUFJLENBQUMsS0FBYSxFQUFFLElBQVM7UUFDM0MsTUFBTSxVQUFVLEdBQUcsT0FBTyxDQUFDLGNBQWMsQ0FDdkMsMEJBQWMsQ0FBQyxXQUFXLEVBQzFCLEtBQUss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3ByaWF0ZSBkZXNjcmlwdGlvbiBrZXkgZm9yIGEgY2xhc3Mgb3IgaXRzIHByb3BlcnR5LlxuICogQHBhcmFtIHtzdHJpbmd9IGRlc2MgVGhlIGRlc2NyaXB0aXZlIHRleHQgdG8gYXNzb2NpYXRlIHdpdGggdGhlIGNsYXNzIG9yIHByb3BlcnR5XG4gKiBAcmV0dXJuIEEgZGVjb3JhdG9yIHRoYXQgcmVjb3JkcyB0aGUgZGVzY3JpcHRpb24gd2hlbiBhcHBsaWVkXG4gKiBAZnVuY3Rpb24gZGVzY3JpcHRpb25cbiAqIEBjYXRlZ29yeSBEZWNvcmF0b3JzXG4gKi9cbmV4cG9ydCBmdW5jdGlvbiBkZXNjcmlwdGlvbihkZXNjOiBzdHJpbmcpIHtcbiAgcmV0dXJuIGZ1bmN0aW9uIGRlc2NyaXB0aW9uKG9yaWdpbmFsOiBhbnksIHByb3A6IGFueSwgZGVzY3JpcHRvcj86IGFueSkge1xuICAgIHJldHVybiBtZXRhZGF0YShcbiAgICAgIFtcbiAgICAgICAgRGVjb3JhdGlvbktleXMuREVTQ1JJUFRJT04sXG4gICAgICAgIHByb3AgPyBwcm9wLnRvU3RyaW5nKCkgOiBEZWNvcmF0aW9uS2V5cy5DTEFTUyxcbiAgICAgIF0uam9pbihPYmplY3RLZXlTcGxpdHRlciksXG4gICAgICBkZXNjXG4gICAgKShvcmlnaW5hbCwgcHJvcCwgZGVzY3JpcHRvcik7XG4gIH07XG59XG4iXX0=
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Assigns arbitrary metadata to a target using a string key
|
|
3
|
+
* @summary Decorator factory that stores a key/value pair in the central Metadata store for the provided class or member.
|
|
4
|
+
* @param {string} key The metadata key to associate with the target
|
|
5
|
+
* @param {*} value The metadata value to store under the given key
|
|
6
|
+
* @return A decorator that writes the metadata when applied
|
|
7
|
+
* @function metadata
|
|
8
|
+
* @category Decorators
|
|
9
|
+
*/
|
|
10
|
+
export declare function metadata(key: string, value: any): (model: any, prop?: any, descriptor?: PropertyDescriptor) => void;
|
|
11
|
+
/**
|
|
12
|
+
* @description Captures and stores a property's design type
|
|
13
|
+
* @summary Decorator factory that reads the reflected design:type for a property and registers it in the Metadata store under the properties map.
|
|
14
|
+
* @return A decorator that records the property's type metadata when applied
|
|
15
|
+
* @function prop
|
|
16
|
+
* @category Property Decorators
|
|
17
|
+
*/
|
|
18
|
+
export declare function prop(): (model: object, prop: any) => void;
|
|
19
|
+
/**
|
|
20
|
+
* @description Decorator factory that applies multiple decorators to a single target
|
|
21
|
+
* @summary Creates a composite decorator that applies multiple decorators in sequence, correctly handling class, method, and property decorators.
|
|
22
|
+
* @param {Array<ClassDecorator | MethodDecorator | PropertyDecorator>} decorators - Array of decorators to apply
|
|
23
|
+
* @return {Function} A decorator function that applies all provided decorators to the target
|
|
24
|
+
* @function apply
|
|
25
|
+
* @mermaid
|
|
26
|
+
* sequenceDiagram
|
|
27
|
+
* participant U as User Code
|
|
28
|
+
* participant A as apply(...decorators)
|
|
29
|
+
* participant D as Decorator
|
|
30
|
+
* U->>A: get decorator(...decorators)
|
|
31
|
+
* A->>U: returns (target, key?, desc?) => void
|
|
32
|
+
* U->>A: invoke on target
|
|
33
|
+
* loop for each decorator
|
|
34
|
+
* A->>D: invoke appropriate decorator type
|
|
35
|
+
* end
|
|
36
|
+
* @category Decorators
|
|
37
|
+
*/
|
|
38
|
+
export declare function apply(...decorators: Array<ClassDecorator | MethodDecorator | PropertyDecorator>): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
39
|
+
/**
|
|
40
|
+
* @description Creates a property metadata decorator
|
|
41
|
+
* @summary Convenience factory that combines metadata(key, value) and prop() to both set an arbitrary metadata key and record the property's design type.
|
|
42
|
+
* @param {string} key The metadata key to set for the property
|
|
43
|
+
* @param {*} value The metadata value to associate with the key
|
|
44
|
+
* @return A decorator that sets the metadata and captures the property's type
|
|
45
|
+
* @function propMetadata
|
|
46
|
+
* @category Property Decorators
|
|
47
|
+
*/
|
|
48
|
+
export declare function propMetadata(key: string, value: any): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
49
|
+
/**
|
|
50
|
+
* @description Attaches a human-readable description to a class or member
|
|
51
|
+
* @summary Decorator factory that stores a textual description in the Metadata store under the appropriate description key for a class or its property.
|
|
52
|
+
* @param {string} desc The descriptive text to associate with the class or property
|
|
53
|
+
* @return A decorator that records the description when applied
|
|
54
|
+
* @function description
|
|
55
|
+
* @category Decorators
|
|
56
|
+
*/
|
|
57
|
+
export declare function description(desc: string): (original: any, prop: any, descriptor?: any) => void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BasicMetadata } from "./metadata/types";
|
|
2
|
+
/**
|
|
3
|
+
* @description Default flavour identifier for the decorator system
|
|
4
|
+
* @summary Defines the default flavour used by the Decoration class when no specific flavour is provided.
|
|
5
|
+
* This constant is used throughout the library as the fallback flavour for decorators.
|
|
6
|
+
* @const DefaultFlavour
|
|
7
|
+
* @memberOf module:decoration
|
|
8
|
+
*/
|
|
9
|
+
export declare const DefaultFlavour = "decaf";
|
|
10
|
+
/**
|
|
11
|
+
* @description Character used to split nested metadata keys
|
|
12
|
+
* @summary The delimiter used by the metadata store to traverse nested object paths when reading/writing values.
|
|
13
|
+
* @const ObjectKeySplitter
|
|
14
|
+
* @memberOf module:decoration
|
|
15
|
+
*/
|
|
16
|
+
export declare const ObjectKeySplitter = ".";
|
|
17
|
+
/**
|
|
18
|
+
* @description Enum containing metadata keys used for reflection in the model system
|
|
19
|
+
* @summary Defines the various Model keys used for reflection and metadata storage.
|
|
20
|
+
* These keys are used throughout the library to store and retrieve metadata about models,
|
|
21
|
+
* their properties, and their behavior.
|
|
22
|
+
* @readonly
|
|
23
|
+
* @enum {string}
|
|
24
|
+
* @readonly
|
|
25
|
+
* @memberOf module:decoration
|
|
26
|
+
*/
|
|
27
|
+
export declare enum DecorationKeys {
|
|
28
|
+
/** Storage key used on the constructor to mirror runtime metadata */
|
|
29
|
+
REFLECT = "__decaf",
|
|
30
|
+
/** Map of model property keys to their reflected design types */
|
|
31
|
+
PROPERTIES = "properties",
|
|
32
|
+
/** Key under which the model's constructor is stored */
|
|
33
|
+
CLASS = "class",
|
|
34
|
+
/** Container of human-friendly descriptions per class and property */
|
|
35
|
+
DESCRIPTION = "description",
|
|
36
|
+
/** Reflect metadata key for design time type of a property */
|
|
37
|
+
DESIGN_TYPE = "design:type",
|
|
38
|
+
/** Reflect metadata key for constructor parameter types */
|
|
39
|
+
DESIGN_PARAMS = "design:paramtypes",
|
|
40
|
+
/** Reflect metadata key for method return type */
|
|
41
|
+
DESIGN_RETURN = "design:returntype"
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @description Typedef for the default metadata object shape
|
|
45
|
+
* @summary Describes the minimal structure persisted for a model before any metadata is recorded.
|
|
46
|
+
* @template M
|
|
47
|
+
* @typedef {object} DefaultMetadataType<M>
|
|
48
|
+
* @property {Record<string, Constructor | undefined>} properties - Mapping of property names to their design types
|
|
49
|
+
* @memberOf module:decoration
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* @description Default metadata instance
|
|
53
|
+
* @summary Concrete default metadata object used when initializing metadata for a model
|
|
54
|
+
* @type {DefaultMetadataType<any>}
|
|
55
|
+
* @const DefaultMetadata
|
|
56
|
+
* @memberOf module:decoration
|
|
57
|
+
*/
|
|
58
|
+
export declare const DefaultMetadata: BasicMetadata<any>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Default flavour identifier for the decorator system
|
|
3
|
+
* @summary Defines the default flavour used by the Decoration class when no specific flavour is provided.
|
|
4
|
+
* This constant is used throughout the library as the fallback flavour for decorators.
|
|
5
|
+
* @const DefaultFlavour
|
|
6
|
+
* @memberOf module:decoration
|
|
7
|
+
*/
|
|
8
|
+
export const DefaultFlavour = "decaf";
|
|
9
|
+
/**
|
|
10
|
+
* @description Character used to split nested metadata keys
|
|
11
|
+
* @summary The delimiter used by the metadata store to traverse nested object paths when reading/writing values.
|
|
12
|
+
* @const ObjectKeySplitter
|
|
13
|
+
* @memberOf module:decoration
|
|
14
|
+
*/
|
|
15
|
+
export const ObjectKeySplitter = ".";
|
|
16
|
+
/**
|
|
17
|
+
* @description Enum containing metadata keys used for reflection in the model system
|
|
18
|
+
* @summary Defines the various Model keys used for reflection and metadata storage.
|
|
19
|
+
* These keys are used throughout the library to store and retrieve metadata about models,
|
|
20
|
+
* their properties, and their behavior.
|
|
21
|
+
* @readonly
|
|
22
|
+
* @enum {string}
|
|
23
|
+
* @readonly
|
|
24
|
+
* @memberOf module:decoration
|
|
25
|
+
*/
|
|
26
|
+
export var DecorationKeys;
|
|
27
|
+
(function (DecorationKeys) {
|
|
28
|
+
/** Storage key used on the constructor to mirror runtime metadata */
|
|
29
|
+
DecorationKeys["REFLECT"] = "__decaf";
|
|
30
|
+
/** Map of model property keys to their reflected design types */
|
|
31
|
+
DecorationKeys["PROPERTIES"] = "properties";
|
|
32
|
+
/** Key under which the model's constructor is stored */
|
|
33
|
+
DecorationKeys["CLASS"] = "class";
|
|
34
|
+
/** Container of human-friendly descriptions per class and property */
|
|
35
|
+
DecorationKeys["DESCRIPTION"] = "description";
|
|
36
|
+
/** Reflect metadata key for design time type of a property */
|
|
37
|
+
DecorationKeys["DESIGN_TYPE"] = "design:type";
|
|
38
|
+
/** Reflect metadata key for constructor parameter types */
|
|
39
|
+
DecorationKeys["DESIGN_PARAMS"] = "design:paramtypes";
|
|
40
|
+
/** Reflect metadata key for method return type */
|
|
41
|
+
DecorationKeys["DESIGN_RETURN"] = "design:returntype";
|
|
42
|
+
})(DecorationKeys || (DecorationKeys = {}));
|
|
43
|
+
/**
|
|
44
|
+
* @description Typedef for the default metadata object shape
|
|
45
|
+
* @summary Describes the minimal structure persisted for a model before any metadata is recorded.
|
|
46
|
+
* @template M
|
|
47
|
+
* @typedef {object} DefaultMetadataType<M>
|
|
48
|
+
* @property {Record<string, Constructor | undefined>} properties - Mapping of property names to their design types
|
|
49
|
+
* @memberOf module:decoration
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* @description Default metadata instance
|
|
53
|
+
* @summary Concrete default metadata object used when initializing metadata for a model
|
|
54
|
+
* @type {DefaultMetadataType<any>}
|
|
55
|
+
* @const DefaultMetadata
|
|
56
|
+
* @memberOf module:decoration
|
|
57
|
+
*/
|
|
58
|
+
export const DefaultMetadata = {
|
|
59
|
+
[DecorationKeys.PROPERTIES]: [],
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnN0YW50cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQTs7Ozs7O0dBTUc7QUFDSCxNQUFNLENBQUMsTUFBTSxjQUFjLEdBQUcsT0FBTyxDQUFDO0FBRXRDOzs7OztHQUtHO0FBQ0gsTUFBTSxDQUFDLE1BQU0saUJBQWlCLEdBQUcsR0FBRyxDQUFDO0FBRXJDOzs7Ozs7Ozs7R0FTRztBQUNILE1BQU0sQ0FBTixJQUFZLGNBZVg7QUFmRCxXQUFZLGNBQWM7SUFDeEIscUVBQXFFO0lBQ3JFLHFDQUErQixDQUFBO0lBQy9CLGlFQUFpRTtJQUNqRSwyQ0FBeUIsQ0FBQTtJQUN6Qix3REFBd0Q7SUFDeEQsaUNBQWUsQ0FBQTtJQUNmLHNFQUFzRTtJQUN0RSw2Q0FBMkIsQ0FBQTtJQUMzQiw4REFBOEQ7SUFDOUQsNkNBQTJCLENBQUE7SUFDM0IsMkRBQTJEO0lBQzNELHFEQUFtQyxDQUFBO0lBQ25DLGtEQUFrRDtJQUNsRCxxREFBbUMsQ0FBQTtBQUNyQyxDQUFDLEVBZlcsY0FBYyxLQUFkLGNBQWMs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ogQGRlc2NyaXB0aW9uIERlZmF1bHQgbWV0YWRhdGEgaW5zdGFuY2VcbiAqIEBzdW1tYXJ5IENvbmNyZXRlIGRlZmF1bHQgbWV0YWRhdGEgb2JqZWN0IHVzZWQgd2hlbiBpbml0aWFsaXppbmcgbWV0YWRhdGEgZm9yIGEgbW9kZWxcbiAqIEB0eXBlIHtEZWZhdWx0TWV0YWRhdGFUeXBlPGFueT59XG4gKiBAY29uc3QgRGVmYXVsdE1ldGFkYXRhXG4gKiBAbWVtYmVyT2YgbW9kdWxlOmRlY29yYXRpb25cbiAqL1xuZXhwb3J0IGNvbnN0IERlZmF1bHRNZXRhZGF0YTogQmFzaWNNZXRhZGF0YTxhbnk+ID0ge1xuICBbRGVjb3JhdGlvbktleXMuUFJPUEVSVElFU106IFtdLFxufSBhcyB1bmtub3duIGFzIEJhc2ljTWV0YWRhdGE8YW55PjtcbiJdfQ==
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { DecorationBuilderBuild, DecorationBuilderEnd, DecorationBuilderMid, DecorationBuilderStart, FlavourResolver, IDecorationBuilder } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @description Union type covering supported decorator kinds
|
|
4
|
+
* @summary Represents any of the standard TypeScript decorator signatures (class, property, or method), enabling flexible registration and application within the Decoration system.
|
|
5
|
+
* @template T
|
|
6
|
+
* @typeDef DecoratorTypes
|
|
7
|
+
* @memberOf module:decoration
|
|
8
|
+
*/
|
|
9
|
+
export type DecoratorTypes = ClassDecorator | PropertyDecorator | MethodDecorator;
|
|
10
|
+
/**
|
|
11
|
+
* @description Type definition for a decorator factory function
|
|
12
|
+
* @summary Represents a function that accepts arbitrary arguments and returns a concrete decorator function to be applied to a target.
|
|
13
|
+
* @template A
|
|
14
|
+
* @typeDef DecoratorFactory
|
|
15
|
+
* @memberOf module:decoration
|
|
16
|
+
*/
|
|
17
|
+
export type DecoratorFactory = (...args: any[]) => DecoratorTypes;
|
|
18
|
+
/**
|
|
19
|
+
* @description Argument bundle for a decorator factory
|
|
20
|
+
* @summary Object form used to defer decorator creation, carrying both the factory function and its argument list to be invoked later during application.
|
|
21
|
+
* @typeDef DecoratorFactoryArgs
|
|
22
|
+
* @property {DecoratorFactory} decorator The factory function that produces a decorator when invoked
|
|
23
|
+
* @property {any[]} [args] Optional list of arguments to pass to the decorator factory
|
|
24
|
+
* @memberOf module:decoration
|
|
25
|
+
*/
|
|
26
|
+
export type DecoratorFactoryArgs = {
|
|
27
|
+
decorator: DecoratorFactory;
|
|
28
|
+
args?: any[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* @description Union that represents either a ready-to-apply decorator or a factory with arguments
|
|
32
|
+
* @summary Allows registering decorators in two forms: as direct decorator functions or as deferred factories paired with their argument lists for later instantiation.
|
|
33
|
+
* @typeDef DecoratorData
|
|
34
|
+
* @memberOf module:decoration
|
|
35
|
+
*/
|
|
36
|
+
export type DecoratorData = DecoratorTypes | DecoratorFactoryArgs;
|
|
37
|
+
/**
|
|
38
|
+
* @description A decorator management class that handles flavoured decorators
|
|
39
|
+
* @summary The Decoration class provides a builder pattern for creating and managing decorators with different flavours.
|
|
40
|
+
* It supports registering, extending, and applying decorators with context-aware flavour resolution.
|
|
41
|
+
* The class implements a fluent interface for defining, extending, and applying decorators with different flavours,
|
|
42
|
+
* allowing for framework-specific decorator implementations while maintaining a consistent API.
|
|
43
|
+
* @template T Type of the decorator (ClassDecorator | PropertyDecorator | MethodDecorator)
|
|
44
|
+
* @param {string} [flavour] Optional flavour parameter for the decorator context
|
|
45
|
+
* @class
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Create a new decoration for 'component' with default flavour
|
|
49
|
+
* const componentDecorator = new Decoration()
|
|
50
|
+
* .for('component')
|
|
51
|
+
* .define(customComponentDecorator);
|
|
52
|
+
*
|
|
53
|
+
* // Create a flavoured decoration
|
|
54
|
+
* const vueComponent = new Decoration('vue')
|
|
55
|
+
* .for('component')
|
|
56
|
+
* .define(vueComponentDecorator);
|
|
57
|
+
*
|
|
58
|
+
* // Apply the decoration
|
|
59
|
+
* @componentDecorator
|
|
60
|
+
* class MyComponent {}
|
|
61
|
+
* ```
|
|
62
|
+
* @mermaid
|
|
63
|
+
* sequenceDiagram
|
|
64
|
+
* participant C as Client
|
|
65
|
+
* participant D as Decoration
|
|
66
|
+
* participant R as FlavourResolver
|
|
67
|
+
* participant F as DecoratorFactory
|
|
68
|
+
*
|
|
69
|
+
* C->>D: new Decoration(flavour)
|
|
70
|
+
* C->>D: for(key)
|
|
71
|
+
* C->>D: define(decorators)
|
|
72
|
+
* D->>D: register(key, flavour, decorators)
|
|
73
|
+
* D->>F: decoratorFactory(key, flavour)
|
|
74
|
+
* F->>R: resolve(target)
|
|
75
|
+
* R-->>F: resolved flavour
|
|
76
|
+
* F->>F: apply decorators
|
|
77
|
+
* F-->>C: decorated target
|
|
78
|
+
*/
|
|
79
|
+
export declare class Decoration implements IDecorationBuilder {
|
|
80
|
+
private flavour;
|
|
81
|
+
/**
|
|
82
|
+
* @description Static map of registered decorators
|
|
83
|
+
* @summary Stores all registered decorators organized by key and flavour
|
|
84
|
+
*/
|
|
85
|
+
private static decorators;
|
|
86
|
+
/**
|
|
87
|
+
* @description Function to resolve flavour from a target
|
|
88
|
+
* @summary Resolver function that determines the appropriate flavour for a given target
|
|
89
|
+
*/
|
|
90
|
+
private static flavourResolver;
|
|
91
|
+
/**
|
|
92
|
+
* @description Set of decorators for the current context
|
|
93
|
+
*/
|
|
94
|
+
private decorators?;
|
|
95
|
+
/**
|
|
96
|
+
* @description Set of additional decorators
|
|
97
|
+
*/
|
|
98
|
+
private extras?;
|
|
99
|
+
/**
|
|
100
|
+
* @description Current decorator key
|
|
101
|
+
*/
|
|
102
|
+
private key?;
|
|
103
|
+
constructor(flavour?: string);
|
|
104
|
+
/**
|
|
105
|
+
* @description Sets the key for the decoration builder
|
|
106
|
+
* @summary Initializes a new decoration chain with the specified key
|
|
107
|
+
* @param {string} key The identifier for the decorator
|
|
108
|
+
* @return {DecorationBuilderMid} Builder instance for method chaining
|
|
109
|
+
*/
|
|
110
|
+
for(key: string): DecorationBuilderMid;
|
|
111
|
+
/**
|
|
112
|
+
* @description Adds decorators to the current context
|
|
113
|
+
* @summary Internal method to add decorators with addon support
|
|
114
|
+
* @param {boolean} [addon=false] Whether the decorators are addons
|
|
115
|
+
* @param decorators Array of decorators
|
|
116
|
+
* @return {this} Current instance for chaining
|
|
117
|
+
*/
|
|
118
|
+
private decorate;
|
|
119
|
+
/**
|
|
120
|
+
* @description Defines the base decorators
|
|
121
|
+
* @summary Sets the primary decorators for the current context
|
|
122
|
+
* @param decorators Decorators to define
|
|
123
|
+
* @return Builder instance for finishing the chain
|
|
124
|
+
*/
|
|
125
|
+
define(...decorators: DecoratorData[]): DecorationBuilderEnd & DecorationBuilderBuild;
|
|
126
|
+
/**
|
|
127
|
+
* @description Extends existing decorators
|
|
128
|
+
* @summary Adds additional decorators to the current context
|
|
129
|
+
* @param decorators Additional decorators
|
|
130
|
+
* @return {DecorationBuilderBuild} Builder instance for building the decorator
|
|
131
|
+
*/
|
|
132
|
+
extend(...decorators: DecoratorData[]): DecorationBuilderBuild;
|
|
133
|
+
/**
|
|
134
|
+
* @description Factory that creates a context-aware decorator for a key/flavour
|
|
135
|
+
* @summary Produces a decorator function bound to the provided key and flavour. The resulting decorator resolves the actual
|
|
136
|
+
* decorators to apply at invocation time based on the target's resolved flavour and the registered base and extra decorators.
|
|
137
|
+
* @param {string} key The decoration key used to look up registered decorators
|
|
138
|
+
* @param {string} [f=DefaultFlavour] Optional explicit flavour to bind the factory to
|
|
139
|
+
* @return {function(object, any, TypedPropertyDescriptor<any>): any} A decorator function that applies the resolved decorators
|
|
140
|
+
* @mermaid
|
|
141
|
+
* sequenceDiagram
|
|
142
|
+
* participant U as User Code
|
|
143
|
+
* participant B as Decoration (builder)
|
|
144
|
+
* participant F as decoratorFactory(key, f)
|
|
145
|
+
* participant R as flavourResolver
|
|
146
|
+
* participant A as Applied Decorators
|
|
147
|
+
* U->>B: define()/extend() and apply()
|
|
148
|
+
* B->>F: create context decorator
|
|
149
|
+
* F->>R: resolve(target)
|
|
150
|
+
* R-->>F: flavour
|
|
151
|
+
* F->>A: collect base + extras
|
|
152
|
+
* loop each decorator
|
|
153
|
+
* A->>U: invoke decorator(target, key?, desc?)
|
|
154
|
+
* end
|
|
155
|
+
*/
|
|
156
|
+
protected decoratorFactory(key: string, f?: string): (target: object, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => {
|
|
157
|
+
target: object;
|
|
158
|
+
propertyKey: any;
|
|
159
|
+
descriptor: TypedPropertyDescriptor<any> | undefined;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* @description Creates the final decorator function
|
|
163
|
+
* @summary Builds and returns the decorator factory function
|
|
164
|
+
* @return {function(any, any?, TypedPropertyDescriptor?): any} The generated decorator function
|
|
165
|
+
*/
|
|
166
|
+
apply(): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
167
|
+
/**
|
|
168
|
+
* @description Registers decorators for a specific key and flavour
|
|
169
|
+
* @summary Internal method to store decorators in the static registry
|
|
170
|
+
* @param {string} key Decorator key
|
|
171
|
+
* @param {string} flavour Decorator flavour
|
|
172
|
+
* @param [decorators] Primary decorators
|
|
173
|
+
* @param [extras] Additional decorators
|
|
174
|
+
*/
|
|
175
|
+
private static register;
|
|
176
|
+
/**
|
|
177
|
+
* @description Sets the global flavour resolver
|
|
178
|
+
* @summary Configures the function used to determine decorator flavours
|
|
179
|
+
* @param {FlavourResolver} resolver Function to resolve flavours
|
|
180
|
+
*/
|
|
181
|
+
static setFlavourResolver(resolver: FlavourResolver): void;
|
|
182
|
+
/**
|
|
183
|
+
* @description Convenience static entry to start a decoration builder
|
|
184
|
+
* @summary Creates a new Decoration instance and initiates the builder chain with the provided key.
|
|
185
|
+
* @param {string} key The decoration key to configure
|
|
186
|
+
* @return {DecorationBuilderMid} A builder instance for chaining definitions
|
|
187
|
+
*/
|
|
188
|
+
static for(key: string): DecorationBuilderMid;
|
|
189
|
+
/**
|
|
190
|
+
* @description Starts a builder for a specific flavour
|
|
191
|
+
* @summary Convenience method to begin a Decoration builder chain bound to the given flavour identifier, allowing registration of flavour-specific decorators.
|
|
192
|
+
* @param {string} flavour The flavour name to bind to the builder
|
|
193
|
+
* @return {DecorationBuilderStart} A builder start interface to continue configuration
|
|
194
|
+
*/
|
|
195
|
+
static flavouredAs(flavour: string): DecorationBuilderStart;
|
|
196
|
+
}
|