mutts 1.0.1 → 1.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/README.md +24 -2
- package/dist/chunks/_tslib-C-cuVLvZ.js +73 -0
- package/dist/chunks/_tslib-C-cuVLvZ.js.map +1 -0
- package/dist/chunks/_tslib-CMEnd0VE.esm.js +68 -0
- package/dist/chunks/_tslib-CMEnd0VE.esm.js.map +1 -0
- package/dist/chunks/{decorator-8qjFb7dw.js → decorator-D4DU97Zg.js} +70 -4
- package/dist/chunks/decorator-D4DU97Zg.js.map +1 -0
- package/dist/chunks/{decorator-AbRkXM5O.esm.js → decorator-GnHw1Az7.esm.js} +67 -5
- package/dist/chunks/decorator-GnHw1Az7.esm.js.map +1 -0
- package/dist/chunks/index-DBScoeCX.esm.js +1960 -0
- package/dist/chunks/index-DBScoeCX.esm.js.map +1 -0
- package/dist/chunks/index-DOTmXL89.js +1983 -0
- package/dist/chunks/index-DOTmXL89.js.map +1 -0
- package/dist/decorator.d.ts +57 -0
- package/dist/decorator.esm.js +1 -1
- package/dist/decorator.js +1 -1
- package/dist/destroyable.d.ts +42 -0
- package/dist/destroyable.esm.js +19 -1
- package/dist/destroyable.esm.js.map +1 -1
- package/dist/destroyable.js +19 -1
- package/dist/destroyable.js.map +1 -1
- package/dist/eventful.d.ts +10 -1
- package/dist/eventful.esm.js +5 -27
- package/dist/eventful.esm.js.map +1 -1
- package/dist/eventful.js +15 -37
- package/dist/eventful.js.map +1 -1
- package/dist/index.d.ts +52 -3
- package/dist/index.esm.js +3 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/dist/indexable.d.ts +26 -0
- package/dist/indexable.esm.js +6 -0
- package/dist/indexable.esm.js.map +1 -1
- package/dist/indexable.js +6 -0
- package/dist/indexable.js.map +1 -1
- package/dist/mutts.umd.js +1 -1
- package/dist/mutts.umd.js.map +1 -1
- package/dist/mutts.umd.min.js +1 -1
- package/dist/mutts.umd.min.js.map +1 -1
- package/dist/promiseChain.d.ts +10 -0
- package/dist/promiseChain.esm.js +6 -0
- package/dist/promiseChain.esm.js.map +1 -1
- package/dist/promiseChain.js +6 -0
- package/dist/promiseChain.js.map +1 -1
- package/dist/reactive.d.ts +255 -18
- package/dist/reactive.esm.js +4 -1458
- package/dist/reactive.esm.js.map +1 -1
- package/dist/reactive.js +29 -1471
- package/dist/reactive.js.map +1 -1
- package/dist/std-decorators.d.ts +35 -0
- package/dist/std-decorators.esm.js +36 -1
- package/dist/std-decorators.esm.js.map +1 -1
- package/dist/std-decorators.js +36 -1
- package/dist/std-decorators.js.map +1 -1
- package/docs/mixin.md +229 -0
- package/docs/reactive.md +7739 -882
- package/package.json +1 -1
- package/dist/chunks/decorator-8qjFb7dw.js.map +0 -1
- package/dist/chunks/decorator-AbRkXM5O.esm.js.map +0 -1
package/README.md
CHANGED
|
@@ -18,7 +18,8 @@ npm install mutts
|
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
20
|
// Import from built modules (recommended for production)
|
|
21
|
-
import { reactive, effect } from 'mutts'
|
|
21
|
+
import { reactive, effect, Reactive } from 'mutts'
|
|
22
|
+
import { mixin } from 'mutts/mixin'
|
|
22
23
|
import { cached } from 'mutts/std-decorators'
|
|
23
24
|
import { Destroyable, allocated } from 'mutts/destroyable'
|
|
24
25
|
```
|
|
@@ -27,7 +28,8 @@ import { Destroyable, allocated } from 'mutts/destroyable'
|
|
|
27
28
|
|
|
28
29
|
```typescript
|
|
29
30
|
// Import directly from source TypeScript files (for development/custom builds)
|
|
30
|
-
import { reactive, effect } from 'mutts/src'
|
|
31
|
+
import { reactive, effect, Reactive } from 'mutts/src'
|
|
32
|
+
import { mixin } from 'mutts/src/mixin'
|
|
31
33
|
import { cached } from 'mutts/src/std-decorators'
|
|
32
34
|
import { Destroyable, allocated } from 'mutts/src/destroyable'
|
|
33
35
|
```
|
|
@@ -53,6 +55,24 @@ A way to write classes that allow numeric indexes managed by a custom function -
|
|
|
53
55
|
- Immutable data structures
|
|
54
56
|
- Performance-optimized access patterns
|
|
55
57
|
|
|
58
|
+
## [Mixin](./docs/mixin.md)
|
|
59
|
+
|
|
60
|
+
A powerful mixin system that allows you to create reusable functionality that can be applied to classes either as base classes or as mixin functions. Provides automatic caching and seamless integration with other MutTs features.
|
|
61
|
+
|
|
62
|
+
**Key Features:**
|
|
63
|
+
- **Dual Usage**: Can be used as both base class (`extends MyMixin`) and mixin function (`MyMixin(SomeBase)`)
|
|
64
|
+
- **Automatic Caching**: Same base class always returns the same mixed class for performance
|
|
65
|
+
- **Type Safety**: Full TypeScript support with proper type inference
|
|
66
|
+
- **Proxy-based**: Uses JavaScript Proxies to handle both constructor and function calls
|
|
67
|
+
- **Memory Efficient**: Automatic cleanup when base classes are garbage collected
|
|
68
|
+
|
|
69
|
+
**Use Cases:**
|
|
70
|
+
- Creating reusable functionality across multiple classes
|
|
71
|
+
- Building composable class hierarchies
|
|
72
|
+
- Adding cross-cutting concerns (logging, events, reactivity)
|
|
73
|
+
- Framework development with mixin support
|
|
74
|
+
- Plugin systems and extensible architectures
|
|
75
|
+
|
|
56
76
|
## [Standard Decorators](./docs/std-decorators.md)
|
|
57
77
|
|
|
58
78
|
A collection of standard decorators that shouldn't be implemented a 101-th time.
|
|
@@ -138,6 +158,8 @@ A comprehensive reactivity system that provides fine-grained dependency tracking
|
|
|
138
158
|
- **Core Reactivity**: Proxy-based property access tracking with `reactive()`, `effect()`, and `computed()`
|
|
139
159
|
- **Deep Watching**: Automatic tracking of nested object changes with `deepWatch()`
|
|
140
160
|
- **Reactive Collections**: Specialized reactive versions of Array, Map, Set, WeakMap, and WeakSet
|
|
161
|
+
- **Class Reactivity**: `@reactive` decorator and `ReactiveBase` for class-based reactivity
|
|
162
|
+
- **Reactive Mixin**: Always-reactive classes with mixin support (`Reactive`)
|
|
141
163
|
- **Back-Reference System**: Efficient change propagation through object hierarchies
|
|
142
164
|
- **Type Safety**: Full TypeScript support with proper type inference
|
|
143
165
|
- **Performance Optimized**: Lazy back-reference creation and efficient dependency tracking
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
21
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
22
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
23
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
24
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
25
|
+
var _, done = false;
|
|
26
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
27
|
+
var context = {};
|
|
28
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
29
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
30
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
31
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
32
|
+
if (kind === "accessor") {
|
|
33
|
+
if (result === void 0) continue;
|
|
34
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
35
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
36
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
37
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
38
|
+
}
|
|
39
|
+
else if (_ = accept(result)) {
|
|
40
|
+
if (kind === "field") initializers.unshift(_);
|
|
41
|
+
else descriptor[key] = _;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
45
|
+
done = true;
|
|
46
|
+
}
|
|
47
|
+
function __runInitializers(thisArg, initializers, value) {
|
|
48
|
+
var useValue = arguments.length > 2;
|
|
49
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
50
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
51
|
+
}
|
|
52
|
+
return useValue ? value : void 0;
|
|
53
|
+
}
|
|
54
|
+
function __setFunctionName(f, name, prefix) {
|
|
55
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
56
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
57
|
+
}
|
|
58
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
59
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
60
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
61
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
65
|
+
var e = new Error(message);
|
|
66
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
exports.__classPrivateFieldGet = __classPrivateFieldGet;
|
|
70
|
+
exports.__esDecorate = __esDecorate;
|
|
71
|
+
exports.__runInitializers = __runInitializers;
|
|
72
|
+
exports.__setFunctionName = __setFunctionName;
|
|
73
|
+
//# sourceMappingURL=_tslib-C-cuVLvZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_tslib-C-cuVLvZ.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
19
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
20
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
21
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
22
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
23
|
+
var _, done = false;
|
|
24
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
25
|
+
var context = {};
|
|
26
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
27
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
28
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
29
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
30
|
+
if (kind === "accessor") {
|
|
31
|
+
if (result === void 0) continue;
|
|
32
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
33
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
34
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
35
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
36
|
+
}
|
|
37
|
+
else if (_ = accept(result)) {
|
|
38
|
+
if (kind === "field") initializers.unshift(_);
|
|
39
|
+
else descriptor[key] = _;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
43
|
+
done = true;
|
|
44
|
+
}
|
|
45
|
+
function __runInitializers(thisArg, initializers, value) {
|
|
46
|
+
var useValue = arguments.length > 2;
|
|
47
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
48
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
49
|
+
}
|
|
50
|
+
return useValue ? value : void 0;
|
|
51
|
+
}
|
|
52
|
+
function __setFunctionName(f, name, prefix) {
|
|
53
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
54
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
55
|
+
}
|
|
56
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
57
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
58
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
59
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
63
|
+
var e = new Error(message);
|
|
64
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { __classPrivateFieldGet as _, __setFunctionName as a, __esDecorate as b, __runInitializers as c };
|
|
68
|
+
//# sourceMappingURL=_tslib-CMEnd0VE.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_tslib-CMEnd0VE.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Combines multiple arrays into an array of tuples, stopping at the shortest array length
|
|
5
|
+
* @param args - Arrays to zip together
|
|
6
|
+
* @returns Array of tuples containing elements from each input array
|
|
7
|
+
*/
|
|
3
8
|
function zip(...args) {
|
|
4
9
|
if (!args.length)
|
|
5
10
|
return [];
|
|
@@ -35,9 +40,22 @@ const nativeConstructors = new Set([
|
|
|
35
40
|
Number,
|
|
36
41
|
Boolean,
|
|
37
42
|
]);
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a function is a constructor (class or constructor function)
|
|
45
|
+
* @param fn - The function to check
|
|
46
|
+
* @returns True if the function is a constructor
|
|
47
|
+
*/
|
|
38
48
|
function isConstructor(fn) {
|
|
39
|
-
return fn &&
|
|
49
|
+
return (fn &&
|
|
50
|
+
typeof fn === 'function' &&
|
|
51
|
+
(nativeConstructors.has(fn) || fn.toString?.().startsWith('class ')));
|
|
40
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Renames a function with a new name
|
|
55
|
+
* @param fct - The function to rename
|
|
56
|
+
* @param name - The new name for the function
|
|
57
|
+
* @returns The function with the new name
|
|
58
|
+
*/
|
|
41
59
|
function renamed(fct, name) {
|
|
42
60
|
return Object.defineProperties(fct, {
|
|
43
61
|
name: {
|
|
@@ -45,15 +63,47 @@ function renamed(fct, name) {
|
|
|
45
63
|
},
|
|
46
64
|
});
|
|
47
65
|
}
|
|
66
|
+
function ReflectGet(obj, prop, receiver) {
|
|
67
|
+
// Check if Node is available and obj is an instance of Node
|
|
68
|
+
if (typeof Node !== 'undefined' && obj instanceof Node)
|
|
69
|
+
return obj[prop];
|
|
70
|
+
return Reflect.get(obj, prop, receiver);
|
|
71
|
+
}
|
|
72
|
+
function ReflectSet(obj, prop, value, receiver) {
|
|
73
|
+
// Check if Node is available and obj is an instance of Node
|
|
74
|
+
if (typeof Node !== 'undefined' && obj instanceof Node) {
|
|
75
|
+
obj[prop] = value;
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
return Reflect.set(obj, prop, value, receiver);
|
|
79
|
+
}
|
|
80
|
+
function isOwnAccessor(obj, prop) {
|
|
81
|
+
const opd = Object.getOwnPropertyDescriptor(obj, prop);
|
|
82
|
+
return !!(opd?.get || opd?.set);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if an object is an object (not null, not primitive)
|
|
86
|
+
*/
|
|
87
|
+
function isObject(obj) {
|
|
88
|
+
return obj !== null && typeof obj === 'object';
|
|
89
|
+
}
|
|
48
90
|
|
|
49
91
|
// biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids
|
|
50
92
|
// Standardized decorator system that works with both Legacy and Modern decorators
|
|
93
|
+
/**
|
|
94
|
+
* Error thrown when decorator operations fail
|
|
95
|
+
*/
|
|
51
96
|
class DecoratorError extends Error {
|
|
52
97
|
constructor(message) {
|
|
53
98
|
super(message);
|
|
54
99
|
this.name = 'DecoratorException';
|
|
55
100
|
}
|
|
56
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a decorator that works with Legacy decorator proposals
|
|
104
|
+
* @param description - The decorator description object
|
|
105
|
+
* @returns A decorator function compatible with Legacy decorators
|
|
106
|
+
*/
|
|
57
107
|
function legacyDecorator(description) {
|
|
58
108
|
return function (target, propertyKey, descriptor, ...args) {
|
|
59
109
|
if (propertyKey === undefined) {
|
|
@@ -97,6 +147,11 @@ function legacyDecorator(description) {
|
|
|
97
147
|
return description.default.call(this, target, propertyKey, descriptor, ...args);
|
|
98
148
|
};
|
|
99
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Creates a decorator that works with Modern decorator proposals
|
|
152
|
+
* @param description - The decorator description object
|
|
153
|
+
* @returns A decorator function compatible with Modern decorators
|
|
154
|
+
*/
|
|
100
155
|
function modernDecorator(description) {
|
|
101
156
|
return function (target, context, ...args) {
|
|
102
157
|
if (!context?.kind || typeof context.kind !== 'string') {
|
|
@@ -157,20 +212,31 @@ function detectDecoratorMode(_target, contextOrKey, _descriptor) {
|
|
|
157
212
|
}
|
|
158
213
|
return 'legacy';
|
|
159
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Main decorator factory that automatically detects and works with both Legacy and Modern decorator proposals
|
|
217
|
+
* @param description - The decorator description object
|
|
218
|
+
* @returns A decorator that works in both Legacy and Modern environments
|
|
219
|
+
*/
|
|
160
220
|
const decorator = (description) => {
|
|
221
|
+
const modern = modernDecorator(description);
|
|
222
|
+
const legacy = legacyDecorator(description);
|
|
161
223
|
return ((target, contextOrKey, ...args) => {
|
|
162
224
|
const mode = detectDecoratorMode(target, contextOrKey, args[0]);
|
|
163
225
|
return mode === 'modern'
|
|
164
|
-
?
|
|
165
|
-
:
|
|
226
|
+
? modern(target, contextOrKey, ...args)
|
|
227
|
+
: legacy(target, contextOrKey, ...args);
|
|
166
228
|
});
|
|
167
229
|
};
|
|
168
230
|
|
|
169
231
|
exports.DecoratorError = DecoratorError;
|
|
232
|
+
exports.ReflectGet = ReflectGet;
|
|
233
|
+
exports.ReflectSet = ReflectSet;
|
|
170
234
|
exports.decorator = decorator;
|
|
171
235
|
exports.isConstructor = isConstructor;
|
|
236
|
+
exports.isObject = isObject;
|
|
237
|
+
exports.isOwnAccessor = isOwnAccessor;
|
|
172
238
|
exports.legacyDecorator = legacyDecorator;
|
|
173
239
|
exports.modernDecorator = modernDecorator;
|
|
174
240
|
exports.renamed = renamed;
|
|
175
241
|
exports.zip = zip;
|
|
176
|
-
//# sourceMappingURL=decorator-
|
|
242
|
+
//# sourceMappingURL=decorator-D4DU97Zg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-D4DU97Zg.js","sources":["../../src/utils.ts","../../src/decorator.ts"],"sourcesContent":["type ElementTypes<T extends readonly unknown[]> = {\n\t[K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K]\n}\n\n/**\n * Combines multiple arrays into an array of tuples, stopping at the shortest array length\n * @param args - Arrays to zip together\n * @returns Array of tuples containing elements from each input array\n */\nexport function zip<T extends (readonly unknown[])[]>(...args: T): ElementTypes<T>[] {\n\tif (!args.length) return []\n\tconst minLength = Math.min(...args.map((arr) => arr.length))\n\tconst result: ElementTypes<T>[] = []\n\n\tfor (let i = 0; i < minLength; i++) {\n\t\tconst tuple = args.map((arr) => arr[i]) as ElementTypes<T>\n\t\tresult.push(tuple)\n\t}\n\n\treturn result\n}\n\nconst nativeConstructors = new Set<Function>([\n\tObject,\n\tArray,\n\tDate,\n\tFunction,\n\tSet,\n\tMap,\n\tWeakMap,\n\tWeakSet,\n\tPromise,\n\tError,\n\tTypeError,\n\tReferenceError,\n\tSyntaxError,\n\tRangeError,\n\tURIError,\n\tEvalError,\n\tReflect,\n\tProxy,\n\tRegExp,\n\tString,\n\tNumber,\n\tBoolean,\n] as Function[])\n/**\n * Checks if a function is a constructor (class or constructor function)\n * @param fn - The function to check\n * @returns True if the function is a constructor\n */\nexport function isConstructor(fn: Function): boolean {\n\treturn (\n\t\tfn &&\n\t\ttypeof fn === 'function' &&\n\t\t(nativeConstructors.has(fn) || fn.toString?.().startsWith('class '))\n\t)\n}\n\n/**\n * Renames a function with a new name\n * @param fct - The function to rename\n * @param name - The new name for the function\n * @returns The function with the new name\n */\nexport function renamed<F extends Function>(fct: F, name: string): F {\n\treturn Object.defineProperties(fct, {\n\t\tname: {\n\t\t\tvalue: name,\n\t\t},\n\t})\n}\n\nexport function ReflectGet(obj: any, prop: any, receiver: any) {\n\t// Check if Node is available and obj is an instance of Node\n\tif (typeof Node !== 'undefined' && obj instanceof Node) return obj[prop]\n\treturn Reflect.get(obj, prop, receiver)\n}\n\nexport function ReflectSet(obj: any, prop: any, value: any, receiver: any) {\n\t// Check if Node is available and obj is an instance of Node\n\tif (typeof Node !== 'undefined' && obj instanceof Node) {\n\t\tobj[prop] = value\n\t\treturn value\n\t}\n\treturn Reflect.set(obj, prop, value, receiver)\n}\n\nexport function isOwnAccessor(obj: any, prop: any) {\n\tconst opd = Object.getOwnPropertyDescriptor(obj, prop)\n\treturn !!(opd?.get || opd?.set)\n}\n\n/**\n * Check if an object is an object (not null, not primitive)\n */\nexport function isObject(obj: any): obj is object {\n\treturn obj !== null && typeof obj === 'object'\n}\n","// biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids\n// Standardized decorator system that works with both Legacy and Modern decorators\n\nimport { isConstructor } from './utils'\n\n/**\n * Error thrown when decorator operations fail\n */\nexport class DecoratorError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'DecoratorException'\n\t}\n}\n//#region all decorator types\n\n// Used for get/set and method decorators\n/**\n * Legacy property decorator type for methods, getters, and setters\n */\nexport type LegacyPropertyDecorator<T> = (\n\ttarget: T,\n\tname: string | symbol,\n\tdescriptor: PropertyDescriptor\n) => any\n\n/**\n * Legacy class decorator type\n */\nexport type LegacyClassDecorator<T> = (target: T) => any\n\n/**\n * Modern method decorator type\n */\nexport type ModernMethodDecorator<T> = (target: T, context: ClassMethodDecoratorContext) => any\n\n/**\n * Modern getter decorator type\n */\nexport type ModernGetterDecorator<T> = (target: T, context: ClassGetterDecoratorContext) => any\n\n/**\n * Modern setter decorator type\n */\nexport type ModernSetterDecorator<T> = (target: T, context: ClassSetterDecoratorContext) => any\n\n/**\n * Modern accessor decorator type\n */\nexport type ModernAccessorDecorator<T> = (target: T, context: ClassAccessorDecoratorContext) => any\n\n/**\n * Modern class decorator type\n */\nexport type ModernClassDecorator<T> = (target: T, context: ClassDecoratorContext) => any\n\n//#endregion\n\ntype DDMethod<T> = (\n\toriginal: (this: T, ...args: any[]) => any,\n\tname: PropertyKey\n) => ((this: T, ...args: any[]) => any) | void\n\ntype DDGetter<T> = (original: (this: T) => any, name: PropertyKey) => ((this: T) => any) | void\n\ntype DDSetter<T> = (\n\toriginal: (this: T, value: any) => void,\n\tname: PropertyKey\n) => ((this: T, value: any) => void) | void\n\ntype DDClass<T> = <Ctor extends new (...args: any[]) => T = new (...args: any[]) => T>(\n\ttarget: Ctor\n) => Ctor | void\n/**\n * Description object for creating decorators that work with both Legacy and Modern decorator proposals\n */\nexport interface DecoratorDescription<T> {\n\t/** Handler for method decorators */\n\tmethod?: DDMethod<T>\n\t/** Handler for class decorators */\n\tclass?: DDClass<T>\n\t/** Handler for getter decorators */\n\tgetter?: DDGetter<T>\n\t/** Handler for setter decorators */\n\tsetter?: DDSetter<T>\n\t/** Default handler for any decorator type not explicitly defined */\n\tdefault?: (...args: any[]) => any\n}\n\n/**\n * Type for decorators that work with both Legacy and Modern decorator proposals\n * Automatically infers the correct decorator type based on the description\n */\nexport type Decorator<T, Description extends DecoratorDescription<T>> = (Description extends {\n\tmethod: DDMethod<T>\n}\n\t? LegacyPropertyDecorator<T> & ModernMethodDecorator<T>\n\t: unknown) &\n\t(Description extends { class: DDClass<new (...args: any[]) => T> }\n\t\t? LegacyClassDecorator<new (...args: any[]) => T> &\n\t\t\t\tModernClassDecorator<new (...args: any[]) => T>\n\t\t: unknown) &\n\t(Description extends { getter: DDGetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { setter: DDSetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { default: infer Signature } ? Signature : unknown)\n\n/**\n * Factory type for creating decorators that work with both Legacy and Modern decorator proposals\n */\nexport type DecoratorFactory<T> = <Description extends DecoratorDescription<T>>(\n\tdescription: Description\n) => (Description extends { method: DDMethod<T> }\n\t? LegacyPropertyDecorator<T> & ModernMethodDecorator<T>\n\t: unknown) &\n\t(Description extends { class: DDClass<new (...args: any[]) => T> }\n\t\t? LegacyClassDecorator<new (...args: any[]) => T> &\n\t\t\t\tModernClassDecorator<new (...args: any[]) => T>\n\t\t: unknown) &\n\t(Description extends { getter: DDGetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { setter: DDSetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { default: infer Signature } ? Signature : unknown)\n\n/**\n * Creates a decorator that works with Legacy decorator proposals\n * @param description - The decorator description object\n * @returns A decorator function compatible with Legacy decorators\n */\nexport function legacyDecorator<T = any>(description: DecoratorDescription<T>): any {\n\treturn function (\n\t\ttarget: any,\n\t\tpropertyKey?: PropertyKey,\n\t\tdescriptor?: PropertyDescriptor,\n\t\t...args: any[]\n\t) {\n\t\tif (propertyKey === undefined) {\n\t\t\tif (isConstructor(target)) {\n\t\t\t\tif (!('class' in description)) throw new Error('Decorator cannot be applied to a class')\n\t\t\t\treturn description.class?.(target)\n\t\t\t}\n\t\t} else if (typeof target === 'object' && ['string', 'symbol'].includes(typeof propertyKey)) {\n\t\t\tif (!descriptor) throw new Error('Decorator cannot be applied to a field')\n\t\t\telse if (typeof descriptor === 'object' && 'configurable' in descriptor) {\n\t\t\t\tif ('get' in descriptor || 'set' in descriptor) {\n\t\t\t\t\tif (!('getter' in description || 'setter' in description))\n\t\t\t\t\t\tthrow new Error('Decorator cannot be applied to a getter or setter')\n\t\t\t\t\tif ('getter' in description) {\n\t\t\t\t\t\tconst newGetter = description.getter?.(descriptor.get, propertyKey)\n\t\t\t\t\t\tif (newGetter) descriptor.get = newGetter\n\t\t\t\t\t}\n\t\t\t\t\tif ('setter' in description) {\n\t\t\t\t\t\tconst newSetter = description.setter?.(descriptor.set, propertyKey)\n\t\t\t\t\t\tif (newSetter) descriptor.set = newSetter\n\t\t\t\t\t}\n\t\t\t\t\treturn descriptor\n\t\t\t\t} else if (typeof descriptor.value === 'function') {\n\t\t\t\t\tif (!('method' in description)) throw new Error('Decorator cannot be applied to a method')\n\t\t\t\t\tconst newMethod = description.method?.(descriptor.value, propertyKey)\n\t\t\t\t\tif (newMethod) descriptor.value = newMethod\n\t\t\t\t\treturn descriptor\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!('default' in description))\n\t\t\tthrow new Error('Decorator do not have a default implementation')\n\t\treturn description.default.call(this, target, propertyKey, descriptor, ...args)\n\t}\n}\n\n/**\n * Creates a decorator that works with Modern decorator proposals\n * @param description - The decorator description object\n * @returns A decorator function compatible with Modern decorators\n */\nexport function modernDecorator<T = any>(description: DecoratorDescription<T>): any {\n\treturn function (target: any, context?: DecoratorContext, ...args: any[]) {\n\t\tif (!context?.kind || typeof context.kind !== 'string') {\n\t\t\tif (!('default' in description))\n\t\t\t\tthrow new Error('Decorator do not have a default implementation')\n\t\t\treturn description.default.call(this, target, context, ...args)\n\t\t}\n\t\tswitch (context.kind) {\n\t\t\tcase 'class':\n\t\t\t\tif (!('class' in description)) throw new Error('Decorator cannot be applied to a class')\n\t\t\t\treturn description.class?.(target)\n\t\t\tcase 'field':\n\t\t\t\tthrow new Error('Decorator cannot be applied to a field')\n\t\t\tcase 'getter':\n\t\t\t\tif (!('getter' in description)) throw new Error('Decorator cannot be applied to a getter')\n\t\t\t\treturn description.getter?.(target, context.name)\n\t\t\tcase 'setter':\n\t\t\t\tif (!('setter' in description)) throw new Error('Decorator cannot be applied to a setter')\n\t\t\t\treturn description.setter?.(target, context.name)\n\t\t\tcase 'method':\n\t\t\t\tif (!('method' in description)) throw new Error('Decorator cannot be applied to a method')\n\t\t\t\treturn description.method?.(target, context.name)\n\t\t\tcase 'accessor': {\n\t\t\t\tif (!('getter' in description || 'setter' in description))\n\t\t\t\t\tthrow new Error('Decorator cannot be applied to a getter or setter')\n\t\t\t\tconst rv: Partial<ClassAccessorDecoratorResult<any, any>> = {}\n\t\t\t\tif ('getter' in description) {\n\t\t\t\t\tconst newGetter = description.getter?.(target.get, context.name)\n\t\t\t\t\tif (newGetter) rv.get = newGetter\n\t\t\t\t}\n\t\t\t\tif ('setter' in description) {\n\t\t\t\t\tconst newSetter = description.setter?.(target.set, context.name)\n\t\t\t\t\tif (newSetter) rv.set = newSetter\n\t\t\t\t}\n\t\t\t\treturn rv\n\t\t\t}\n\t\t\t//return description.accessor?.(target, context.name, target)\n\t\t}\n\t}\n}\n\n/**\n * Detects if the decorator is being called in modern (Modern) or legacy (Legacy) mode\n * based on the arguments passed to the decorator function\n */\nfunction detectDecoratorMode(\n\t_target: any,\n\tcontextOrKey?: any,\n\t_descriptor?: any\n): 'modern' | 'legacy' {\n\t// Modern decorators have a context object as the second parameter\n\t// Legacy decorators have a string/symbol key as the second parameter\n\tif (\n\t\ttypeof contextOrKey === 'object' &&\n\t\tcontextOrKey !== null &&\n\t\ttypeof contextOrKey.kind === 'string'\n\t) {\n\t\treturn 'modern'\n\t}\n\treturn 'legacy'\n}\n\n/**\n * Main decorator factory that automatically detects and works with both Legacy and Modern decorator proposals\n * @param description - The decorator description object\n * @returns A decorator that works in both Legacy and Modern environments\n */\nexport const decorator: DecoratorFactory<any> = (description: DecoratorDescription<any>) => {\n\tconst modern = modernDecorator(description)\n\tconst legacy = legacyDecorator(description)\n\treturn ((target: any, contextOrKey?: any, ...args: any[]) => {\n\t\tconst mode = detectDecoratorMode(target, contextOrKey, args[0])\n\t\treturn mode === 'modern'\n\t\t\t? modern(target, contextOrKey, ...args)\n\t\t\t: legacy(target, contextOrKey, ...args)\n\t}) as any\n}\n\n/**\n * Generic class decorator type that works with both Legacy and Modern decorator proposals\n */\nexport type GenericClassDecorator<T> = LegacyClassDecorator<abstract new (...args: any[]) => T> &\n\tModernClassDecorator<abstract new (...args: any[]) => T>\n"],"names":[],"mappings":";;AAIA;;;;AAIG;AACG,SAAU,GAAG,CAAmC,GAAG,IAAO,EAAA;IAC/D,IAAI,CAAC,IAAI,CAAC,MAAM;AAAE,QAAA,OAAO,EAAE;IAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5D,MAAM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A,YAAY,KAAK,IAAI;AACrB,QAAA,OAAO,YAAY,CAAC,IAAI,KAAK,QAAQ,EACpC;AACD,QAAA,OAAO,QAAQ;IAChB;AACA,IAAA,OAAO,QAAQ;AAChB;AAEA;;;;AAIG;AACI,MAAM,SAAS,GAA0B,CAAC,WAAsC,KAAI;AAC1F,IAAA,MAAM,MAAM,GAAG,eAAe,CAAC,WAAW,CAAC;AAC3C,IAAA,MAAM,MAAM,GAAG,eAAe,CAAC,WAAW,CAAC;IAC3C,QAAQ,CAAC,MAAW,EAAE,YAAkB,EAAE,GAAG,IAAW,KAAI;AAC3D,QAAA,MAAM,IAAI,GAAG,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,IAAI,KAAK;cACb,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI;cACpC,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;AACzC,IAAA,CAAC;AACF;;;;;;;;;;;;;;"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combines multiple arrays into an array of tuples, stopping at the shortest array length
|
|
3
|
+
* @param args - Arrays to zip together
|
|
4
|
+
* @returns Array of tuples containing elements from each input array
|
|
5
|
+
*/
|
|
1
6
|
function zip(...args) {
|
|
2
7
|
if (!args.length)
|
|
3
8
|
return [];
|
|
@@ -33,9 +38,22 @@ const nativeConstructors = new Set([
|
|
|
33
38
|
Number,
|
|
34
39
|
Boolean,
|
|
35
40
|
]);
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a function is a constructor (class or constructor function)
|
|
43
|
+
* @param fn - The function to check
|
|
44
|
+
* @returns True if the function is a constructor
|
|
45
|
+
*/
|
|
36
46
|
function isConstructor(fn) {
|
|
37
|
-
return fn &&
|
|
47
|
+
return (fn &&
|
|
48
|
+
typeof fn === 'function' &&
|
|
49
|
+
(nativeConstructors.has(fn) || fn.toString?.().startsWith('class ')));
|
|
38
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Renames a function with a new name
|
|
53
|
+
* @param fct - The function to rename
|
|
54
|
+
* @param name - The new name for the function
|
|
55
|
+
* @returns The function with the new name
|
|
56
|
+
*/
|
|
39
57
|
function renamed(fct, name) {
|
|
40
58
|
return Object.defineProperties(fct, {
|
|
41
59
|
name: {
|
|
@@ -43,15 +61,47 @@ function renamed(fct, name) {
|
|
|
43
61
|
},
|
|
44
62
|
});
|
|
45
63
|
}
|
|
64
|
+
function ReflectGet(obj, prop, receiver) {
|
|
65
|
+
// Check if Node is available and obj is an instance of Node
|
|
66
|
+
if (typeof Node !== 'undefined' && obj instanceof Node)
|
|
67
|
+
return obj[prop];
|
|
68
|
+
return Reflect.get(obj, prop, receiver);
|
|
69
|
+
}
|
|
70
|
+
function ReflectSet(obj, prop, value, receiver) {
|
|
71
|
+
// Check if Node is available and obj is an instance of Node
|
|
72
|
+
if (typeof Node !== 'undefined' && obj instanceof Node) {
|
|
73
|
+
obj[prop] = value;
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
return Reflect.set(obj, prop, value, receiver);
|
|
77
|
+
}
|
|
78
|
+
function isOwnAccessor(obj, prop) {
|
|
79
|
+
const opd = Object.getOwnPropertyDescriptor(obj, prop);
|
|
80
|
+
return !!(opd?.get || opd?.set);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if an object is an object (not null, not primitive)
|
|
84
|
+
*/
|
|
85
|
+
function isObject(obj) {
|
|
86
|
+
return obj !== null && typeof obj === 'object';
|
|
87
|
+
}
|
|
46
88
|
|
|
47
89
|
// biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids
|
|
48
90
|
// Standardized decorator system that works with both Legacy and Modern decorators
|
|
91
|
+
/**
|
|
92
|
+
* Error thrown when decorator operations fail
|
|
93
|
+
*/
|
|
49
94
|
class DecoratorError extends Error {
|
|
50
95
|
constructor(message) {
|
|
51
96
|
super(message);
|
|
52
97
|
this.name = 'DecoratorException';
|
|
53
98
|
}
|
|
54
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a decorator that works with Legacy decorator proposals
|
|
102
|
+
* @param description - The decorator description object
|
|
103
|
+
* @returns A decorator function compatible with Legacy decorators
|
|
104
|
+
*/
|
|
55
105
|
function legacyDecorator(description) {
|
|
56
106
|
return function (target, propertyKey, descriptor, ...args) {
|
|
57
107
|
if (propertyKey === undefined) {
|
|
@@ -95,6 +145,11 @@ function legacyDecorator(description) {
|
|
|
95
145
|
return description.default.call(this, target, propertyKey, descriptor, ...args);
|
|
96
146
|
};
|
|
97
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Creates a decorator that works with Modern decorator proposals
|
|
150
|
+
* @param description - The decorator description object
|
|
151
|
+
* @returns A decorator function compatible with Modern decorators
|
|
152
|
+
*/
|
|
98
153
|
function modernDecorator(description) {
|
|
99
154
|
return function (target, context, ...args) {
|
|
100
155
|
if (!context?.kind || typeof context.kind !== 'string') {
|
|
@@ -155,14 +210,21 @@ function detectDecoratorMode(_target, contextOrKey, _descriptor) {
|
|
|
155
210
|
}
|
|
156
211
|
return 'legacy';
|
|
157
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Main decorator factory that automatically detects and works with both Legacy and Modern decorator proposals
|
|
215
|
+
* @param description - The decorator description object
|
|
216
|
+
* @returns A decorator that works in both Legacy and Modern environments
|
|
217
|
+
*/
|
|
158
218
|
const decorator = (description) => {
|
|
219
|
+
const modern = modernDecorator(description);
|
|
220
|
+
const legacy = legacyDecorator(description);
|
|
159
221
|
return ((target, contextOrKey, ...args) => {
|
|
160
222
|
const mode = detectDecoratorMode(target, contextOrKey, args[0]);
|
|
161
223
|
return mode === 'modern'
|
|
162
|
-
?
|
|
163
|
-
:
|
|
224
|
+
? modern(target, contextOrKey, ...args)
|
|
225
|
+
: legacy(target, contextOrKey, ...args);
|
|
164
226
|
});
|
|
165
227
|
};
|
|
166
228
|
|
|
167
|
-
export { DecoratorError as D, decorator as d, isConstructor as i, legacyDecorator as l, modernDecorator as m, renamed as r, zip as z };
|
|
168
|
-
//# sourceMappingURL=decorator-
|
|
229
|
+
export { DecoratorError as D, ReflectGet as R, ReflectSet as a, isOwnAccessor as b, isObject as c, decorator as d, isConstructor as i, legacyDecorator as l, modernDecorator as m, renamed as r, zip as z };
|
|
230
|
+
//# sourceMappingURL=decorator-GnHw1Az7.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-GnHw1Az7.esm.js","sources":["../../src/utils.ts","../../src/decorator.ts"],"sourcesContent":["type ElementTypes<T extends readonly unknown[]> = {\n\t[K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K]\n}\n\n/**\n * Combines multiple arrays into an array of tuples, stopping at the shortest array length\n * @param args - Arrays to zip together\n * @returns Array of tuples containing elements from each input array\n */\nexport function zip<T extends (readonly unknown[])[]>(...args: T): ElementTypes<T>[] {\n\tif (!args.length) return []\n\tconst minLength = Math.min(...args.map((arr) => arr.length))\n\tconst result: ElementTypes<T>[] = []\n\n\tfor (let i = 0; i < minLength; i++) {\n\t\tconst tuple = args.map((arr) => arr[i]) as ElementTypes<T>\n\t\tresult.push(tuple)\n\t}\n\n\treturn result\n}\n\nconst nativeConstructors = new Set<Function>([\n\tObject,\n\tArray,\n\tDate,\n\tFunction,\n\tSet,\n\tMap,\n\tWeakMap,\n\tWeakSet,\n\tPromise,\n\tError,\n\tTypeError,\n\tReferenceError,\n\tSyntaxError,\n\tRangeError,\n\tURIError,\n\tEvalError,\n\tReflect,\n\tProxy,\n\tRegExp,\n\tString,\n\tNumber,\n\tBoolean,\n] as Function[])\n/**\n * Checks if a function is a constructor (class or constructor function)\n * @param fn - The function to check\n * @returns True if the function is a constructor\n */\nexport function isConstructor(fn: Function): boolean {\n\treturn (\n\t\tfn &&\n\t\ttypeof fn === 'function' &&\n\t\t(nativeConstructors.has(fn) || fn.toString?.().startsWith('class '))\n\t)\n}\n\n/**\n * Renames a function with a new name\n * @param fct - The function to rename\n * @param name - The new name for the function\n * @returns The function with the new name\n */\nexport function renamed<F extends Function>(fct: F, name: string): F {\n\treturn Object.defineProperties(fct, {\n\t\tname: {\n\t\t\tvalue: name,\n\t\t},\n\t})\n}\n\nexport function ReflectGet(obj: any, prop: any, receiver: any) {\n\t// Check if Node is available and obj is an instance of Node\n\tif (typeof Node !== 'undefined' && obj instanceof Node) return obj[prop]\n\treturn Reflect.get(obj, prop, receiver)\n}\n\nexport function ReflectSet(obj: any, prop: any, value: any, receiver: any) {\n\t// Check if Node is available and obj is an instance of Node\n\tif (typeof Node !== 'undefined' && obj instanceof Node) {\n\t\tobj[prop] = value\n\t\treturn value\n\t}\n\treturn Reflect.set(obj, prop, value, receiver)\n}\n\nexport function isOwnAccessor(obj: any, prop: any) {\n\tconst opd = Object.getOwnPropertyDescriptor(obj, prop)\n\treturn !!(opd?.get || opd?.set)\n}\n\n/**\n * Check if an object is an object (not null, not primitive)\n */\nexport function isObject(obj: any): obj is object {\n\treturn obj !== null && typeof obj === 'object'\n}\n","// biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids\n// Standardized decorator system that works with both Legacy and Modern decorators\n\nimport { isConstructor } from './utils'\n\n/**\n * Error thrown when decorator operations fail\n */\nexport class DecoratorError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'DecoratorException'\n\t}\n}\n//#region all decorator types\n\n// Used for get/set and method decorators\n/**\n * Legacy property decorator type for methods, getters, and setters\n */\nexport type LegacyPropertyDecorator<T> = (\n\ttarget: T,\n\tname: string | symbol,\n\tdescriptor: PropertyDescriptor\n) => any\n\n/**\n * Legacy class decorator type\n */\nexport type LegacyClassDecorator<T> = (target: T) => any\n\n/**\n * Modern method decorator type\n */\nexport type ModernMethodDecorator<T> = (target: T, context: ClassMethodDecoratorContext) => any\n\n/**\n * Modern getter decorator type\n */\nexport type ModernGetterDecorator<T> = (target: T, context: ClassGetterDecoratorContext) => any\n\n/**\n * Modern setter decorator type\n */\nexport type ModernSetterDecorator<T> = (target: T, context: ClassSetterDecoratorContext) => any\n\n/**\n * Modern accessor decorator type\n */\nexport type ModernAccessorDecorator<T> = (target: T, context: ClassAccessorDecoratorContext) => any\n\n/**\n * Modern class decorator type\n */\nexport type ModernClassDecorator<T> = (target: T, context: ClassDecoratorContext) => any\n\n//#endregion\n\ntype DDMethod<T> = (\n\toriginal: (this: T, ...args: any[]) => any,\n\tname: PropertyKey\n) => ((this: T, ...args: any[]) => any) | void\n\ntype DDGetter<T> = (original: (this: T) => any, name: PropertyKey) => ((this: T) => any) | void\n\ntype DDSetter<T> = (\n\toriginal: (this: T, value: any) => void,\n\tname: PropertyKey\n) => ((this: T, value: any) => void) | void\n\ntype DDClass<T> = <Ctor extends new (...args: any[]) => T = new (...args: any[]) => T>(\n\ttarget: Ctor\n) => Ctor | void\n/**\n * Description object for creating decorators that work with both Legacy and Modern decorator proposals\n */\nexport interface DecoratorDescription<T> {\n\t/** Handler for method decorators */\n\tmethod?: DDMethod<T>\n\t/** Handler for class decorators */\n\tclass?: DDClass<T>\n\t/** Handler for getter decorators */\n\tgetter?: DDGetter<T>\n\t/** Handler for setter decorators */\n\tsetter?: DDSetter<T>\n\t/** Default handler for any decorator type not explicitly defined */\n\tdefault?: (...args: any[]) => any\n}\n\n/**\n * Type for decorators that work with both Legacy and Modern decorator proposals\n * Automatically infers the correct decorator type based on the description\n */\nexport type Decorator<T, Description extends DecoratorDescription<T>> = (Description extends {\n\tmethod: DDMethod<T>\n}\n\t? LegacyPropertyDecorator<T> & ModernMethodDecorator<T>\n\t: unknown) &\n\t(Description extends { class: DDClass<new (...args: any[]) => T> }\n\t\t? LegacyClassDecorator<new (...args: any[]) => T> &\n\t\t\t\tModernClassDecorator<new (...args: any[]) => T>\n\t\t: unknown) &\n\t(Description extends { getter: DDGetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { setter: DDSetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { default: infer Signature } ? Signature : unknown)\n\n/**\n * Factory type for creating decorators that work with both Legacy and Modern decorator proposals\n */\nexport type DecoratorFactory<T> = <Description extends DecoratorDescription<T>>(\n\tdescription: Description\n) => (Description extends { method: DDMethod<T> }\n\t? LegacyPropertyDecorator<T> & ModernMethodDecorator<T>\n\t: unknown) &\n\t(Description extends { class: DDClass<new (...args: any[]) => T> }\n\t\t? LegacyClassDecorator<new (...args: any[]) => T> &\n\t\t\t\tModernClassDecorator<new (...args: any[]) => T>\n\t\t: unknown) &\n\t(Description extends { getter: DDGetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { setter: DDSetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { default: infer Signature } ? Signature : unknown)\n\n/**\n * Creates a decorator that works with Legacy decorator proposals\n * @param description - The decorator description object\n * @returns A decorator function compatible with Legacy decorators\n */\nexport function legacyDecorator<T = any>(description: DecoratorDescription<T>): any {\n\treturn function (\n\t\ttarget: any,\n\t\tpropertyKey?: PropertyKey,\n\t\tdescriptor?: PropertyDescriptor,\n\t\t...args: any[]\n\t) {\n\t\tif (propertyKey === undefined) {\n\t\t\tif (isConstructor(target)) {\n\t\t\t\tif (!('class' in description)) throw new Error('Decorator cannot be applied to a class')\n\t\t\t\treturn description.class?.(target)\n\t\t\t}\n\t\t} else if (typeof target === 'object' && ['string', 'symbol'].includes(typeof propertyKey)) {\n\t\t\tif (!descriptor) throw new Error('Decorator cannot be applied to a field')\n\t\t\telse if (typeof descriptor === 'object' && 'configurable' in descriptor) {\n\t\t\t\tif ('get' in descriptor || 'set' in descriptor) {\n\t\t\t\t\tif (!('getter' in description || 'setter' in description))\n\t\t\t\t\t\tthrow new Error('Decorator cannot be applied to a getter or setter')\n\t\t\t\t\tif ('getter' in description) {\n\t\t\t\t\t\tconst newGetter = description.getter?.(descriptor.get, propertyKey)\n\t\t\t\t\t\tif (newGetter) descriptor.get = newGetter\n\t\t\t\t\t}\n\t\t\t\t\tif ('setter' in description) {\n\t\t\t\t\t\tconst newSetter = description.setter?.(descriptor.set, propertyKey)\n\t\t\t\t\t\tif (newSetter) descriptor.set = newSetter\n\t\t\t\t\t}\n\t\t\t\t\treturn descriptor\n\t\t\t\t} else if (typeof descriptor.value === 'function') {\n\t\t\t\t\tif (!('method' in description)) throw new Error('Decorator cannot be applied to a method')\n\t\t\t\t\tconst newMethod = description.method?.(descriptor.value, propertyKey)\n\t\t\t\t\tif (newMethod) descriptor.value = newMethod\n\t\t\t\t\treturn descriptor\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!('default' in description))\n\t\t\tthrow new Error('Decorator do not have a default implementation')\n\t\treturn description.default.call(this, target, propertyKey, descriptor, ...args)\n\t}\n}\n\n/**\n * Creates a decorator that works with Modern decorator proposals\n * @param description - The decorator description object\n * @returns A decorator function compatible with Modern decorators\n */\nexport function modernDecorator<T = any>(description: DecoratorDescription<T>): any {\n\treturn function (target: any, context?: DecoratorContext, ...args: any[]) {\n\t\tif (!context?.kind || typeof context.kind !== 'string') {\n\t\t\tif (!('default' in description))\n\t\t\t\tthrow new Error('Decorator do not have a default implementation')\n\t\t\treturn description.default.call(this, target, context, ...args)\n\t\t}\n\t\tswitch (context.kind) {\n\t\t\tcase 'class':\n\t\t\t\tif (!('class' in description)) throw new Error('Decorator cannot be applied to a class')\n\t\t\t\treturn description.class?.(target)\n\t\t\tcase 'field':\n\t\t\t\tthrow new Error('Decorator cannot be applied to a field')\n\t\t\tcase 'getter':\n\t\t\t\tif (!('getter' in description)) throw new Error('Decorator cannot be applied to a getter')\n\t\t\t\treturn description.getter?.(target, context.name)\n\t\t\tcase 'setter':\n\t\t\t\tif (!('setter' in description)) throw new Error('Decorator cannot be applied to a setter')\n\t\t\t\treturn description.setter?.(target, context.name)\n\t\t\tcase 'method':\n\t\t\t\tif (!('method' in description)) throw new Error('Decorator cannot be applied to a method')\n\t\t\t\treturn description.method?.(target, context.name)\n\t\t\tcase 'accessor': {\n\t\t\t\tif (!('getter' in description || 'setter' in description))\n\t\t\t\t\tthrow new Error('Decorator cannot be applied to a getter or setter')\n\t\t\t\tconst rv: Partial<ClassAccessorDecoratorResult<any, any>> = {}\n\t\t\t\tif ('getter' in description) {\n\t\t\t\t\tconst newGetter = description.getter?.(target.get, context.name)\n\t\t\t\t\tif (newGetter) rv.get = newGetter\n\t\t\t\t}\n\t\t\t\tif ('setter' in description) {\n\t\t\t\t\tconst newSetter = description.setter?.(target.set, context.name)\n\t\t\t\t\tif (newSetter) rv.set = newSetter\n\t\t\t\t}\n\t\t\t\treturn rv\n\t\t\t}\n\t\t\t//return description.accessor?.(target, context.name, target)\n\t\t}\n\t}\n}\n\n/**\n * Detects if the decorator is being called in modern (Modern) or legacy (Legacy) mode\n * based on the arguments passed to the decorator function\n */\nfunction detectDecoratorMode(\n\t_target: any,\n\tcontextOrKey?: any,\n\t_descriptor?: any\n): 'modern' | 'legacy' {\n\t// Modern decorators have a context object as the second parameter\n\t// Legacy decorators have a string/symbol key as the second parameter\n\tif (\n\t\ttypeof contextOrKey === 'object' &&\n\t\tcontextOrKey !== null &&\n\t\ttypeof contextOrKey.kind === 'string'\n\t) {\n\t\treturn 'modern'\n\t}\n\treturn 'legacy'\n}\n\n/**\n * Main decorator factory that automatically detects and works with both Legacy and Modern decorator proposals\n * @param description - The decorator description object\n * @returns A decorator that works in both Legacy and Modern environments\n */\nexport const decorator: DecoratorFactory<any> = (description: DecoratorDescription<any>) => {\n\tconst modern = modernDecorator(description)\n\tconst legacy = legacyDecorator(description)\n\treturn ((target: any, contextOrKey?: any, ...args: any[]) => {\n\t\tconst mode = detectDecoratorMode(target, contextOrKey, args[0])\n\t\treturn mode === 'modern'\n\t\t\t? modern(target, contextOrKey, ...args)\n\t\t\t: legacy(target, contextOrKey, ...args)\n\t}) as any\n}\n\n/**\n * Generic class decorator type that works with both Legacy and Modern decorator proposals\n */\nexport type GenericClassDecorator<T> = LegacyClassDecorator<abstract new (...args: any[]) => T> &\n\tModernClassDecorator<abstract new (...args: any[]) => T>\n"],"names":[],"mappings":"AAIA;;;;AAIG;AACG,SAAU,GAAG,CAAmC,GAAG,IAAO,EAAA;IAC/D,IAAI,CAAC,IAAI,CAAC,MAAM;AAAE,QAAA,OAAO,EAAE;IAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAsB,EAAE;AAEpC,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE;AACnC,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAoB;AAC1D,QAAA,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;IACnB;AAEA,IAAA,OAAO,MAAM;AACd;AAEA,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAW;IAC5C,MAAM;IACN,KAAK;IACL,IAAI;IACJ,QAAQ;IACR,GAAG;IACH,GAAG;IACH,OAAO;IACP,OAAO;IACP,OAAO;IACP,KAAK;IACL,SAAS;IACT,cAAc;IACd,WAAW;IACX,UAAU;IACV,QAAQ;IACR,SAAS;IACT,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;AACO,CAAA,CAAC;AAChB;;;;AAIG;AACG,SAAU,aAAa,CAAC,EAAY,EAAA;AACzC,IAAA,QACC,EAAE;QACF,OAAO,EAAE,KAAK,UAAU;AACxB,SAAC,kBAAkB,CAAC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