mutts 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -0
- package/dist/chunks/decorator-BXsign4Z.js +176 -0
- package/dist/chunks/decorator-BXsign4Z.js.map +1 -0
- package/dist/chunks/decorator-CPbZNnsX.esm.js +168 -0
- package/dist/chunks/decorator-CPbZNnsX.esm.js.map +1 -0
- package/dist/decorator.d.ts +50 -0
- package/dist/decorator.esm.js +2 -0
- package/dist/decorator.esm.js.map +1 -0
- package/dist/decorator.js +11 -0
- package/dist/decorator.js.map +1 -0
- package/dist/destroyable.d.ts +48 -0
- package/dist/destroyable.esm.js +91 -0
- package/dist/destroyable.esm.js.map +1 -0
- package/dist/destroyable.js +98 -0
- package/dist/destroyable.js.map +1 -0
- package/dist/eventful.d.ts +11 -0
- package/dist/eventful.esm.js +88 -0
- package/dist/eventful.esm.js.map +1 -0
- package/dist/eventful.js +90 -0
- package/dist/eventful.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.esm.js +7 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/indexable.d.ts +31 -0
- package/dist/indexable.esm.js +85 -0
- package/dist/indexable.esm.js.map +1 -0
- package/dist/indexable.js +89 -0
- package/dist/indexable.js.map +1 -0
- package/dist/mutts.umd.js +2 -0
- package/dist/mutts.umd.js.map +1 -0
- package/dist/mutts.umd.min.js +2 -0
- package/dist/mutts.umd.min.js.map +1 -0
- package/dist/promiseChain.d.ts +11 -0
- package/dist/promiseChain.esm.js +72 -0
- package/dist/promiseChain.esm.js.map +1 -0
- package/dist/promiseChain.js +74 -0
- package/dist/promiseChain.js.map +1 -0
- package/dist/reactive.d.ts +114 -0
- package/dist/reactive.esm.js +1455 -0
- package/dist/reactive.esm.js.map +1 -0
- package/dist/reactive.js +1472 -0
- package/dist/reactive.js.map +1 -0
- package/dist/std-decorators.d.ts +17 -0
- package/dist/std-decorators.esm.js +161 -0
- package/dist/std-decorators.esm.js.map +1 -0
- package/dist/std-decorators.js +169 -0
- package/dist/std-decorators.js.map +1 -0
- package/docs/decorator.md +300 -0
- package/docs/destroyable.md +294 -0
- package/docs/events.md +225 -0
- package/docs/indexable.md +561 -0
- package/docs/promiseChain.md +218 -0
- package/docs/reactive.md +2072 -0
- package/docs/std-decorators.md +558 -0
- package/package.json +132 -0
- package/src/decorator.test.ts +495 -0
- package/src/decorator.ts +205 -0
- package/src/destroyable.test.ts +155 -0
- package/src/destroyable.ts +158 -0
- package/src/eventful.test.ts +380 -0
- package/src/eventful.ts +69 -0
- package/src/index.ts +7 -0
- package/src/indexable.test.ts +388 -0
- package/src/indexable.ts +124 -0
- package/src/promiseChain.test.ts +201 -0
- package/src/promiseChain.ts +99 -0
- package/src/reactive/array.test.ts +923 -0
- package/src/reactive/array.ts +352 -0
- package/src/reactive/core.test.ts +1663 -0
- package/src/reactive/core.ts +866 -0
- package/src/reactive/index.ts +28 -0
- package/src/reactive/interface.test.ts +1477 -0
- package/src/reactive/interface.ts +231 -0
- package/src/reactive/map.test.ts +866 -0
- package/src/reactive/map.ts +162 -0
- package/src/reactive/set.test.ts +289 -0
- package/src/reactive/set.ts +142 -0
- package/src/std-decorators.test.ts +679 -0
- package/src/std-decorators.ts +182 -0
- package/src/utils.ts +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Modern UTility TS
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/mutts)
|
|
4
|
+
|
|
5
|
+
Basically, just a bunch of utilities that have many versions on the web, but none fitting my needs, so that I re-created every time.
|
|
6
|
+
|
|
7
|
+
With the advent of AI, I could finally manage to have something finished and complete.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install mutts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Import from Built Modules
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
// Import from built modules (recommended for production)
|
|
21
|
+
import { reactive, effect } from 'mutts'
|
|
22
|
+
import { cached } from 'mutts/std-decorators'
|
|
23
|
+
import { Destroyable, allocated } from 'mutts/destroyable'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Import from Source Files
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
// Import directly from source TypeScript files (for development/custom builds)
|
|
30
|
+
import { reactive, effect } from 'mutts/src'
|
|
31
|
+
import { cached } from 'mutts/src/std-decorators'
|
|
32
|
+
import { Destroyable, allocated } from 'mutts/src/destroyable'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Note:** When importing from source files, you'll need to configure your build system (TypeScript, Vite, Webpack, etc.) to handle TypeScript compilation and module resolution. The source files are published alongside the built modules, so you can import directly from the `src` directory.
|
|
36
|
+
|
|
37
|
+
## [Indexable](./docs/indexable.md)
|
|
38
|
+
|
|
39
|
+
A way to write classes that allow numeric indexes managed by a custom function - either given in the class by the symbols [getAt] and [setAt] either by a specification if the Indexable class.
|
|
40
|
+
|
|
41
|
+
**Key Features:**
|
|
42
|
+
- Numeric index access similar to arrays (`obj[0]`, `obj[1]`)
|
|
43
|
+
- Custom getter/setter logic via `getAt` and `setAt` symbols
|
|
44
|
+
- Proxy-based property interception
|
|
45
|
+
- Full TypeScript support with generic types
|
|
46
|
+
- Read-only or read-write indexable objects
|
|
47
|
+
- Extend existing classes with index access
|
|
48
|
+
|
|
49
|
+
**Use Cases:**
|
|
50
|
+
- Custom collection classes
|
|
51
|
+
- Data structures with numeric indexing
|
|
52
|
+
- Wrapper classes for external data sources
|
|
53
|
+
- Immutable data structures
|
|
54
|
+
- Performance-optimized access patterns
|
|
55
|
+
|
|
56
|
+
## [Standard Decorators](./docs/std-decorators.md)
|
|
57
|
+
|
|
58
|
+
A collection of standard decorators that shouldn't be implemented a 101-th time.
|
|
59
|
+
|
|
60
|
+
In extenso: cached, describe(enumerable, configurable, writable), deprecated, debounce, throttle
|
|
61
|
+
|
|
62
|
+
## [Decorator System](./docs/decorator.md)
|
|
63
|
+
|
|
64
|
+
A standardized decorator system that works with both Legacy and Modern decorator proposals. Provides a unified API for creating decorators that automatically detect and adapt to the current decorator environment.
|
|
65
|
+
|
|
66
|
+
**Key Features:**
|
|
67
|
+
- **Universal Compatibility**: Works with both Legacy and Modern decorator proposals
|
|
68
|
+
- **Runtime Detection**: Automatically detects decorator type based on function arguments
|
|
69
|
+
- **Type Safety**: Full TypeScript support with proper type inference
|
|
70
|
+
- **Unified API**: Single decorator factory that handles all decorator types
|
|
71
|
+
- **Method, Getter, Setter Support**: Handles all decorator kinds with appropriate type safety
|
|
72
|
+
|
|
73
|
+
**Use Cases:**
|
|
74
|
+
- Creating cross-compatible decorators
|
|
75
|
+
- Library development with decorator support
|
|
76
|
+
- Framework development
|
|
77
|
+
- Utility decorator creation
|
|
78
|
+
|
|
79
|
+
## [Events](./docs/events.md)
|
|
80
|
+
|
|
81
|
+
A type-safe event system built around the `Eventful` class that provides a clean API for event handling with full TypeScript support.
|
|
82
|
+
|
|
83
|
+
**Key Features:**
|
|
84
|
+
- Type-safe event definitions with generic event maps
|
|
85
|
+
- Multiple event listener support per event type
|
|
86
|
+
- Global hooks that receive all events
|
|
87
|
+
- Automatic cleanup with unsubscribe functions
|
|
88
|
+
- Support for both single events and bulk event registration
|
|
89
|
+
|
|
90
|
+
**Use Cases:**
|
|
91
|
+
- Component communication
|
|
92
|
+
- State change notifications
|
|
93
|
+
- Plugin systems
|
|
94
|
+
- Observer pattern implementations
|
|
95
|
+
|
|
96
|
+
## [PromiseChain](./docs/promiseChain.md)
|
|
97
|
+
|
|
98
|
+
A utility that transforms promises into chainable objects, allowing you to call methods directly on promise results without awaiting them first. It automatically handles promise resolution and method forwarding.
|
|
99
|
+
|
|
100
|
+
**Key Features:**
|
|
101
|
+
- Automatic promise chaining with method forwarding
|
|
102
|
+
- Transparent handling of nested promises
|
|
103
|
+
- Support for both functions and objects
|
|
104
|
+
- Maintains original promise methods (`then`, `catch`, `finally`)
|
|
105
|
+
- WeakMap-based caching to prevent duplicate wrapping
|
|
106
|
+
|
|
107
|
+
**Use Cases:**
|
|
108
|
+
- Async API chaining
|
|
109
|
+
- Promise-based data processing pipelines
|
|
110
|
+
- Reducing async/await boilerplate
|
|
111
|
+
- Functional programming with promises
|
|
112
|
+
|
|
113
|
+
## [Destroyable](./docs/destroyable.md)
|
|
114
|
+
|
|
115
|
+
A comprehensive resource management system that provides automatic cleanup for objects with proper destructor handling. Integrates with JavaScript's `FinalizationRegistry` and supports modern resource management patterns including the upcoming `using` statement.
|
|
116
|
+
|
|
117
|
+
**Key Features:**
|
|
118
|
+
- **Automatic Resource Management**: Objects are automatically cleaned up when garbage collected
|
|
119
|
+
- **Manual Destruction**: Explicit destruction with immediate cleanup
|
|
120
|
+
- **Resource Tracking**: Properties can be marked with `@allocated` to be tracked in a separate allocation object
|
|
121
|
+
- **Context Manager Integration**: Support for `Symbol.dispose` and context manager patterns
|
|
122
|
+
- **Type Safety**: Full TypeScript support with proper type inference
|
|
123
|
+
- **Destruction Safety**: Destroyed objects throw errors when accessed to prevent use-after-free bugs
|
|
124
|
+
|
|
125
|
+
**Use Cases:**
|
|
126
|
+
- Database connections and resource cleanup
|
|
127
|
+
- File handle management
|
|
128
|
+
- Network resource management
|
|
129
|
+
- Memory management for large objects
|
|
130
|
+
- Plugin systems with proper cleanup
|
|
131
|
+
- Temporary resource management
|
|
132
|
+
|
|
133
|
+
## [Reactive](./docs/reactive.md)
|
|
134
|
+
|
|
135
|
+
A comprehensive reactivity system that provides fine-grained dependency tracking and automatic re-computation. Built on JavaScript Proxies with support for deep watching, computed values, and effect management.
|
|
136
|
+
|
|
137
|
+
**Key Features:**
|
|
138
|
+
- **Core Reactivity**: Proxy-based property access tracking with `reactive()`, `effect()`, and `computed()`
|
|
139
|
+
- **Deep Watching**: Automatic tracking of nested object changes with `deepWatch()`
|
|
140
|
+
- **Reactive Collections**: Specialized reactive versions of Array, Map, Set, WeakMap, and WeakSet
|
|
141
|
+
- **Back-Reference System**: Efficient change propagation through object hierarchies
|
|
142
|
+
- **Type Safety**: Full TypeScript support with proper type inference
|
|
143
|
+
- **Performance Optimized**: Lazy back-reference creation and efficient dependency tracking
|
|
144
|
+
|
|
145
|
+
**Use Cases:**
|
|
146
|
+
- State management systems
|
|
147
|
+
- UI framework reactivity
|
|
148
|
+
- Data synchronization
|
|
149
|
+
- Real-time applications
|
|
150
|
+
- Form validation and processing
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function zip(...args) {
|
|
4
|
+
if (!args.length)
|
|
5
|
+
return [];
|
|
6
|
+
const minLength = Math.min(...args.map((arr) => arr.length));
|
|
7
|
+
const result = [];
|
|
8
|
+
for (let i = 0; i < minLength; i++) {
|
|
9
|
+
const tuple = args.map((arr) => arr[i]);
|
|
10
|
+
result.push(tuple);
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
const nativeConstructors = new Set([
|
|
15
|
+
Object,
|
|
16
|
+
Array,
|
|
17
|
+
Date,
|
|
18
|
+
Function,
|
|
19
|
+
Set,
|
|
20
|
+
Map,
|
|
21
|
+
WeakMap,
|
|
22
|
+
WeakSet,
|
|
23
|
+
Promise,
|
|
24
|
+
Error,
|
|
25
|
+
TypeError,
|
|
26
|
+
ReferenceError,
|
|
27
|
+
SyntaxError,
|
|
28
|
+
RangeError,
|
|
29
|
+
URIError,
|
|
30
|
+
EvalError,
|
|
31
|
+
Reflect,
|
|
32
|
+
Proxy,
|
|
33
|
+
RegExp,
|
|
34
|
+
String,
|
|
35
|
+
Number,
|
|
36
|
+
Boolean,
|
|
37
|
+
]);
|
|
38
|
+
function isConstructor(fn) {
|
|
39
|
+
return fn && (nativeConstructors.has(fn) || fn.toString().startsWith('class '));
|
|
40
|
+
}
|
|
41
|
+
function renamed(fct, name) {
|
|
42
|
+
return Object.defineProperties(fct, {
|
|
43
|
+
name: {
|
|
44
|
+
value: name,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids
|
|
50
|
+
// Standardized decorator system that works with both Legacy and Modern decorators
|
|
51
|
+
class DecoratorError extends Error {
|
|
52
|
+
constructor(message) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.name = 'DecoratorException';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function legacyDecorator(description) {
|
|
58
|
+
return function (target, propertyKey, descriptor, ...args) {
|
|
59
|
+
if (propertyKey === undefined) {
|
|
60
|
+
if (isConstructor(target)) {
|
|
61
|
+
if (!('class' in description))
|
|
62
|
+
throw new Error('Decorator cannot be applied to a class');
|
|
63
|
+
return description.class?.(target);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (typeof target === 'object' && ['string', 'symbol'].includes(typeof propertyKey)) {
|
|
67
|
+
if (!descriptor)
|
|
68
|
+
throw new Error('Decorator cannot be applied to a field');
|
|
69
|
+
else if (typeof descriptor === 'object' && 'configurable' in descriptor) {
|
|
70
|
+
if ('get' in descriptor || 'set' in descriptor) {
|
|
71
|
+
if (!('getter' in description || 'setter' in description))
|
|
72
|
+
throw new Error('Decorator cannot be applied to a getter or setter');
|
|
73
|
+
if ('getter' in description) {
|
|
74
|
+
const newGetter = description.getter?.(descriptor.get, propertyKey);
|
|
75
|
+
if (newGetter)
|
|
76
|
+
descriptor.get = newGetter;
|
|
77
|
+
}
|
|
78
|
+
if ('setter' in description) {
|
|
79
|
+
const newSetter = description.setter?.(descriptor.set, propertyKey);
|
|
80
|
+
if (newSetter)
|
|
81
|
+
descriptor.set = newSetter;
|
|
82
|
+
}
|
|
83
|
+
return descriptor;
|
|
84
|
+
}
|
|
85
|
+
else if (typeof descriptor.value === 'function') {
|
|
86
|
+
if (!('method' in description))
|
|
87
|
+
throw new Error('Decorator cannot be applied to a method');
|
|
88
|
+
const newMethod = description.method?.(descriptor.value, propertyKey);
|
|
89
|
+
if (newMethod)
|
|
90
|
+
descriptor.value = newMethod;
|
|
91
|
+
return descriptor;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!('default' in description))
|
|
96
|
+
throw new Error('Decorator do not have a default implementation');
|
|
97
|
+
return description.default.call(this, target, propertyKey, descriptor, ...args);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function modernDecorator(description) {
|
|
101
|
+
return function (target, context, ...args) {
|
|
102
|
+
if (!context?.kind || typeof context.kind !== 'string') {
|
|
103
|
+
if (!('default' in description))
|
|
104
|
+
throw new Error('Decorator do not have a default implementation');
|
|
105
|
+
return description.default.call(this, target, context, ...args);
|
|
106
|
+
}
|
|
107
|
+
switch (context.kind) {
|
|
108
|
+
case 'class':
|
|
109
|
+
if (!('class' in description))
|
|
110
|
+
throw new Error('Decorator cannot be applied to a class');
|
|
111
|
+
return description.class?.(target);
|
|
112
|
+
case 'field':
|
|
113
|
+
throw new Error('Decorator cannot be applied to a field');
|
|
114
|
+
case 'getter':
|
|
115
|
+
if (!('getter' in description))
|
|
116
|
+
throw new Error('Decorator cannot be applied to a getter');
|
|
117
|
+
return description.getter?.(target, context.name);
|
|
118
|
+
case 'setter':
|
|
119
|
+
if (!('setter' in description))
|
|
120
|
+
throw new Error('Decorator cannot be applied to a setter');
|
|
121
|
+
return description.setter?.(target, context.name);
|
|
122
|
+
case 'method':
|
|
123
|
+
if (!('method' in description))
|
|
124
|
+
throw new Error('Decorator cannot be applied to a method');
|
|
125
|
+
return description.method?.(target, context.name);
|
|
126
|
+
case 'accessor': {
|
|
127
|
+
if (!('getter' in description || 'setter' in description))
|
|
128
|
+
throw new Error('Decorator cannot be applied to a getter or setter');
|
|
129
|
+
const rv = {};
|
|
130
|
+
if ('getter' in description) {
|
|
131
|
+
const newGetter = description.getter?.(target.get, context.name);
|
|
132
|
+
if (newGetter)
|
|
133
|
+
rv.get = newGetter;
|
|
134
|
+
}
|
|
135
|
+
if ('setter' in description) {
|
|
136
|
+
const newSetter = description.setter?.(target.set, context.name);
|
|
137
|
+
if (newSetter)
|
|
138
|
+
rv.set = newSetter;
|
|
139
|
+
}
|
|
140
|
+
return rv;
|
|
141
|
+
}
|
|
142
|
+
//return description.accessor?.(target, context.name, target)
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Detects if the decorator is being called in modern (Modern) or legacy (Legacy) mode
|
|
148
|
+
* based on the arguments passed to the decorator function
|
|
149
|
+
*/
|
|
150
|
+
function detectDecoratorMode(_target, contextOrKey, _descriptor) {
|
|
151
|
+
// Modern decorators have a context object as the second parameter
|
|
152
|
+
// Legacy decorators have a string/symbol key as the second parameter
|
|
153
|
+
if (typeof contextOrKey === 'object' &&
|
|
154
|
+
contextOrKey !== null &&
|
|
155
|
+
typeof contextOrKey.kind === 'string') {
|
|
156
|
+
return 'modern';
|
|
157
|
+
}
|
|
158
|
+
return 'legacy';
|
|
159
|
+
}
|
|
160
|
+
const decorator = (description) => {
|
|
161
|
+
return ((target, contextOrKey, ...args) => {
|
|
162
|
+
const mode = detectDecoratorMode(target, contextOrKey, args[0]);
|
|
163
|
+
return mode === 'modern'
|
|
164
|
+
? modernDecorator(description)(target, contextOrKey, ...args)
|
|
165
|
+
: legacyDecorator(description)(target, contextOrKey, ...args);
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
exports.DecoratorError = DecoratorError;
|
|
170
|
+
exports.decorator = decorator;
|
|
171
|
+
exports.isConstructor = isConstructor;
|
|
172
|
+
exports.legacyDecorator = legacyDecorator;
|
|
173
|
+
exports.modernDecorator = modernDecorator;
|
|
174
|
+
exports.renamed = renamed;
|
|
175
|
+
exports.zip = zip;
|
|
176
|
+
//# sourceMappingURL=decorator-BXsign4Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-BXsign4Z.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\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[])\nexport function isConstructor(fn: Function): boolean {\n\treturn fn && (nativeConstructors.has(fn) || fn.toString().startsWith('class '))\n}\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","// 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\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\nexport type LegacyPropertyDecorator<T> = (\n\ttarget: T,\n\tname: string | symbol,\n\tdescriptor: PropertyDescriptor\n) => any\n\nexport type LegacyClassDecorator<T> = (target: T) => any\n\nexport type ModernMethodDecorator<T> = (target: T, context: ClassMethodDecoratorContext) => any\n\nexport type ModernGetterDecorator<T> = (target: T, context: ClassGetterDecoratorContext) => any\n\nexport type ModernSetterDecorator<T> = (target: T, context: ClassSetterDecoratorContext) => any\n\nexport type ModernAccessorDecorator<T> = (target: T, context: ClassAccessorDecoratorContext) => any\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\nexport interface DecoratorDescription<T> {\n\tmethod?: DDMethod<T>\n\tclass?: DDClass<T>\n\tgetter?: DDGetter<T>\n\tsetter?: DDSetter<T>\n\tdefault?: (...args: any[]) => any\n}\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\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\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\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\nexport const decorator: DecoratorFactory<any> = (description: DecoratorDescription<any>) => {\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? modernDecorator(description)(target, contextOrKey, ...args)\n\t\t\t: legacyDecorator(description)(target, contextOrKey, ...args)\n\t}) as any\n}\n\nexport type GenericClassDecorator<T> = LegacyClassDecorator<new (...args: any[]) => T> &\n\tModernClassDecorator<new (...args: any[]) => T>\n"],"names":[],"mappings":";;AAIM,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,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AS,mBAAmB,CAC3B,OAAY,EACZ,YAAkB,EAClB,WAAiB,EAAA;;;IAIjB,IACC,OAAO,YAAY,KAAK,QAAQ;AAChC,QAAA,YAAY,KAAK,IAAI;AACrB,QAAA,OAAO,YAAY,CAAC,IAAI,KAAK,QAAQ,EACpC;AACD,QAAA,OAAO,QAAQ;IAChB;AACA,IAAA,OAAO,QAAQ;AAChB;AAEO,MAAM,SAAS,GAA0B,CAAC,WAAsC,KAAI;IAC1F,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;AACf,cAAE,eAAe,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI;AAC5D,cAAE,eAAe,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;AAC/D,IAAA,CAAC;AACF;;;;;;;;;;"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
function zip(...args) {
|
|
2
|
+
if (!args.length)
|
|
3
|
+
return [];
|
|
4
|
+
const minLength = Math.min(...args.map((arr) => arr.length));
|
|
5
|
+
const result = [];
|
|
6
|
+
for (let i = 0; i < minLength; i++) {
|
|
7
|
+
const tuple = args.map((arr) => arr[i]);
|
|
8
|
+
result.push(tuple);
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
const nativeConstructors = new Set([
|
|
13
|
+
Object,
|
|
14
|
+
Array,
|
|
15
|
+
Date,
|
|
16
|
+
Function,
|
|
17
|
+
Set,
|
|
18
|
+
Map,
|
|
19
|
+
WeakMap,
|
|
20
|
+
WeakSet,
|
|
21
|
+
Promise,
|
|
22
|
+
Error,
|
|
23
|
+
TypeError,
|
|
24
|
+
ReferenceError,
|
|
25
|
+
SyntaxError,
|
|
26
|
+
RangeError,
|
|
27
|
+
URIError,
|
|
28
|
+
EvalError,
|
|
29
|
+
Reflect,
|
|
30
|
+
Proxy,
|
|
31
|
+
RegExp,
|
|
32
|
+
String,
|
|
33
|
+
Number,
|
|
34
|
+
Boolean,
|
|
35
|
+
]);
|
|
36
|
+
function isConstructor(fn) {
|
|
37
|
+
return fn && (nativeConstructors.has(fn) || fn.toString().startsWith('class '));
|
|
38
|
+
}
|
|
39
|
+
function renamed(fct, name) {
|
|
40
|
+
return Object.defineProperties(fct, {
|
|
41
|
+
name: {
|
|
42
|
+
value: name,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids
|
|
48
|
+
// Standardized decorator system that works with both Legacy and Modern decorators
|
|
49
|
+
class DecoratorError extends Error {
|
|
50
|
+
constructor(message) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = 'DecoratorException';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function legacyDecorator(description) {
|
|
56
|
+
return function (target, propertyKey, descriptor, ...args) {
|
|
57
|
+
if (propertyKey === undefined) {
|
|
58
|
+
if (isConstructor(target)) {
|
|
59
|
+
if (!('class' in description))
|
|
60
|
+
throw new Error('Decorator cannot be applied to a class');
|
|
61
|
+
return description.class?.(target);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (typeof target === 'object' && ['string', 'symbol'].includes(typeof propertyKey)) {
|
|
65
|
+
if (!descriptor)
|
|
66
|
+
throw new Error('Decorator cannot be applied to a field');
|
|
67
|
+
else if (typeof descriptor === 'object' && 'configurable' in descriptor) {
|
|
68
|
+
if ('get' in descriptor || 'set' in descriptor) {
|
|
69
|
+
if (!('getter' in description || 'setter' in description))
|
|
70
|
+
throw new Error('Decorator cannot be applied to a getter or setter');
|
|
71
|
+
if ('getter' in description) {
|
|
72
|
+
const newGetter = description.getter?.(descriptor.get, propertyKey);
|
|
73
|
+
if (newGetter)
|
|
74
|
+
descriptor.get = newGetter;
|
|
75
|
+
}
|
|
76
|
+
if ('setter' in description) {
|
|
77
|
+
const newSetter = description.setter?.(descriptor.set, propertyKey);
|
|
78
|
+
if (newSetter)
|
|
79
|
+
descriptor.set = newSetter;
|
|
80
|
+
}
|
|
81
|
+
return descriptor;
|
|
82
|
+
}
|
|
83
|
+
else if (typeof descriptor.value === 'function') {
|
|
84
|
+
if (!('method' in description))
|
|
85
|
+
throw new Error('Decorator cannot be applied to a method');
|
|
86
|
+
const newMethod = description.method?.(descriptor.value, propertyKey);
|
|
87
|
+
if (newMethod)
|
|
88
|
+
descriptor.value = newMethod;
|
|
89
|
+
return descriptor;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!('default' in description))
|
|
94
|
+
throw new Error('Decorator do not have a default implementation');
|
|
95
|
+
return description.default.call(this, target, propertyKey, descriptor, ...args);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function modernDecorator(description) {
|
|
99
|
+
return function (target, context, ...args) {
|
|
100
|
+
if (!context?.kind || typeof context.kind !== 'string') {
|
|
101
|
+
if (!('default' in description))
|
|
102
|
+
throw new Error('Decorator do not have a default implementation');
|
|
103
|
+
return description.default.call(this, target, context, ...args);
|
|
104
|
+
}
|
|
105
|
+
switch (context.kind) {
|
|
106
|
+
case 'class':
|
|
107
|
+
if (!('class' in description))
|
|
108
|
+
throw new Error('Decorator cannot be applied to a class');
|
|
109
|
+
return description.class?.(target);
|
|
110
|
+
case 'field':
|
|
111
|
+
throw new Error('Decorator cannot be applied to a field');
|
|
112
|
+
case 'getter':
|
|
113
|
+
if (!('getter' in description))
|
|
114
|
+
throw new Error('Decorator cannot be applied to a getter');
|
|
115
|
+
return description.getter?.(target, context.name);
|
|
116
|
+
case 'setter':
|
|
117
|
+
if (!('setter' in description))
|
|
118
|
+
throw new Error('Decorator cannot be applied to a setter');
|
|
119
|
+
return description.setter?.(target, context.name);
|
|
120
|
+
case 'method':
|
|
121
|
+
if (!('method' in description))
|
|
122
|
+
throw new Error('Decorator cannot be applied to a method');
|
|
123
|
+
return description.method?.(target, context.name);
|
|
124
|
+
case 'accessor': {
|
|
125
|
+
if (!('getter' in description || 'setter' in description))
|
|
126
|
+
throw new Error('Decorator cannot be applied to a getter or setter');
|
|
127
|
+
const rv = {};
|
|
128
|
+
if ('getter' in description) {
|
|
129
|
+
const newGetter = description.getter?.(target.get, context.name);
|
|
130
|
+
if (newGetter)
|
|
131
|
+
rv.get = newGetter;
|
|
132
|
+
}
|
|
133
|
+
if ('setter' in description) {
|
|
134
|
+
const newSetter = description.setter?.(target.set, context.name);
|
|
135
|
+
if (newSetter)
|
|
136
|
+
rv.set = newSetter;
|
|
137
|
+
}
|
|
138
|
+
return rv;
|
|
139
|
+
}
|
|
140
|
+
//return description.accessor?.(target, context.name, target)
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Detects if the decorator is being called in modern (Modern) or legacy (Legacy) mode
|
|
146
|
+
* based on the arguments passed to the decorator function
|
|
147
|
+
*/
|
|
148
|
+
function detectDecoratorMode(_target, contextOrKey, _descriptor) {
|
|
149
|
+
// Modern decorators have a context object as the second parameter
|
|
150
|
+
// Legacy decorators have a string/symbol key as the second parameter
|
|
151
|
+
if (typeof contextOrKey === 'object' &&
|
|
152
|
+
contextOrKey !== null &&
|
|
153
|
+
typeof contextOrKey.kind === 'string') {
|
|
154
|
+
return 'modern';
|
|
155
|
+
}
|
|
156
|
+
return 'legacy';
|
|
157
|
+
}
|
|
158
|
+
const decorator = (description) => {
|
|
159
|
+
return ((target, contextOrKey, ...args) => {
|
|
160
|
+
const mode = detectDecoratorMode(target, contextOrKey, args[0]);
|
|
161
|
+
return mode === 'modern'
|
|
162
|
+
? modernDecorator(description)(target, contextOrKey, ...args)
|
|
163
|
+
: legacyDecorator(description)(target, contextOrKey, ...args);
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
|
|
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-CPbZNnsX.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-CPbZNnsX.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\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[])\nexport function isConstructor(fn: Function): boolean {\n\treturn fn && (nativeConstructors.has(fn) || fn.toString().startsWith('class '))\n}\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","// 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\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\nexport type LegacyPropertyDecorator<T> = (\n\ttarget: T,\n\tname: string | symbol,\n\tdescriptor: PropertyDescriptor\n) => any\n\nexport type LegacyClassDecorator<T> = (target: T) => any\n\nexport type ModernMethodDecorator<T> = (target: T, context: ClassMethodDecoratorContext) => any\n\nexport type ModernGetterDecorator<T> = (target: T, context: ClassGetterDecoratorContext) => any\n\nexport type ModernSetterDecorator<T> = (target: T, context: ClassSetterDecoratorContext) => any\n\nexport type ModernAccessorDecorator<T> = (target: T, context: ClassAccessorDecoratorContext) => any\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\nexport interface DecoratorDescription<T> {\n\tmethod?: DDMethod<T>\n\tclass?: DDClass<T>\n\tgetter?: DDGetter<T>\n\tsetter?: DDSetter<T>\n\tdefault?: (...args: any[]) => any\n}\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\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\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\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\nexport const decorator: DecoratorFactory<any> = (description: DecoratorDescription<any>) => {\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? modernDecorator(description)(target, contextOrKey, ...args)\n\t\t\t: legacyDecorator(description)(target, contextOrKey, ...args)\n\t}) as any\n}\n\nexport type GenericClassDecorator<T> = LegacyClassDecorator<new (...args: any[]) => T> &\n\tModernClassDecorator<new (...args: any[]) => T>\n"],"names":[],"mappings":"AAIM,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,G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,EAAE,OAAO,CAAC,IAAI,CAAC;AAChE,oBAAA,IAAI,SAAS;AAAE,wBAAA,EAAE,CAAC,GAAG,GAAG,SAAS;gBAClC;AACA,gBAAA,OAAO,EAAE;YACV;;;AAGF,IAAA,CAAC;AACF;AAEA;;;AAGG;AACH,SAAS,mBAAmB,CAC3B,OAAY,EACZ,YAAkB,EAClB,WAAiB,EAAA;;;IAIjB,IACC,OAAO,YAAY,KAAK,QAAQ;AAChC,QAAA,YAAY,KAAK,IAAI;AACrB,QAAA,OAAO,YAAY,CAAC,IAAI,KAAK,QAAQ,EACpC;AACD,QAAA,OAAO,QAAQ;IAChB;AACA,IAAA,OAAO,QAAQ;AAChB;AAEO,MAAM,SAAS,GAA0B,CAAC,WAAsC,KAAI;IAC1F,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;AACf,cAAE,eAAe,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI;AAC5D,cAAE,eAAe,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;AAC/D,IAAA,CAAC;AACF;;;;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
declare class DecoratorError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
type LegacyPropertyDecorator<T> = (target: T, name: string | symbol, descriptor: PropertyDescriptor) => any;
|
|
5
|
+
type LegacyClassDecorator<T> = (target: T) => any;
|
|
6
|
+
type ModernMethodDecorator<T> = (target: T, context: ClassMethodDecoratorContext) => any;
|
|
7
|
+
type ModernGetterDecorator<T> = (target: T, context: ClassGetterDecoratorContext) => any;
|
|
8
|
+
type ModernSetterDecorator<T> = (target: T, context: ClassSetterDecoratorContext) => any;
|
|
9
|
+
type ModernAccessorDecorator<T> = (target: T, context: ClassAccessorDecoratorContext) => any;
|
|
10
|
+
type ModernClassDecorator<T> = (target: T, context: ClassDecoratorContext) => any;
|
|
11
|
+
type DDMethod<T> = (original: (this: T, ...args: any[]) => any, name: PropertyKey) => ((this: T, ...args: any[]) => any) | void;
|
|
12
|
+
type DDGetter<T> = (original: (this: T) => any, name: PropertyKey) => ((this: T) => any) | void;
|
|
13
|
+
type DDSetter<T> = (original: (this: T, value: any) => void, name: PropertyKey) => ((this: T, value: any) => void) | void;
|
|
14
|
+
type DDClass<T> = <Ctor extends new (...args: any[]) => T = new (...args: any[]) => T>(target: Ctor) => Ctor | void;
|
|
15
|
+
interface DecoratorDescription<T> {
|
|
16
|
+
method?: DDMethod<T>;
|
|
17
|
+
class?: DDClass<T>;
|
|
18
|
+
getter?: DDGetter<T>;
|
|
19
|
+
setter?: DDSetter<T>;
|
|
20
|
+
default?: (...args: any[]) => any;
|
|
21
|
+
}
|
|
22
|
+
type Decorator<T, Description extends DecoratorDescription<T>> = (Description extends {
|
|
23
|
+
method: DDMethod<T>;
|
|
24
|
+
} ? LegacyPropertyDecorator<T> & ModernMethodDecorator<T> : unknown) & (Description extends {
|
|
25
|
+
class: DDClass<new (...args: any[]) => T>;
|
|
26
|
+
} ? LegacyClassDecorator<new (...args: any[]) => T> & ModernClassDecorator<new (...args: any[]) => T> : unknown) & (Description extends {
|
|
27
|
+
getter: DDGetter<T>;
|
|
28
|
+
} ? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T> : unknown) & (Description extends {
|
|
29
|
+
setter: DDSetter<T>;
|
|
30
|
+
} ? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T> : unknown) & (Description extends {
|
|
31
|
+
default: infer Signature;
|
|
32
|
+
} ? Signature : unknown);
|
|
33
|
+
type DecoratorFactory<T> = <Description extends DecoratorDescription<T>>(description: Description) => (Description extends {
|
|
34
|
+
method: DDMethod<T>;
|
|
35
|
+
} ? LegacyPropertyDecorator<T> & ModernMethodDecorator<T> : unknown) & (Description extends {
|
|
36
|
+
class: DDClass<new (...args: any[]) => T>;
|
|
37
|
+
} ? LegacyClassDecorator<new (...args: any[]) => T> & ModernClassDecorator<new (...args: any[]) => T> : unknown) & (Description extends {
|
|
38
|
+
getter: DDGetter<T>;
|
|
39
|
+
} ? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T> : unknown) & (Description extends {
|
|
40
|
+
setter: DDSetter<T>;
|
|
41
|
+
} ? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T> : unknown) & (Description extends {
|
|
42
|
+
default: infer Signature;
|
|
43
|
+
} ? Signature : unknown);
|
|
44
|
+
declare function legacyDecorator<T = any>(description: DecoratorDescription<T>): any;
|
|
45
|
+
declare function modernDecorator<T = any>(description: DecoratorDescription<T>): any;
|
|
46
|
+
declare const decorator: DecoratorFactory<any>;
|
|
47
|
+
type GenericClassDecorator<T> = LegacyClassDecorator<new (...args: any[]) => T> & ModernClassDecorator<new (...args: any[]) => T>;
|
|
48
|
+
|
|
49
|
+
export { DecoratorError, decorator, legacyDecorator, modernDecorator };
|
|
50
|
+
export type { Decorator, DecoratorDescription, DecoratorFactory, GenericClassDecorator, LegacyClassDecorator, LegacyPropertyDecorator, ModernAccessorDecorator, ModernClassDecorator, ModernGetterDecorator, ModernMethodDecorator, ModernSetterDecorator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var decorator = require('./chunks/decorator-BXsign4Z.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.DecoratorError = decorator.DecoratorError;
|
|
8
|
+
exports.decorator = decorator.decorator;
|
|
9
|
+
exports.legacyDecorator = decorator.legacyDecorator;
|
|
10
|
+
exports.modernDecorator = decorator.modernDecorator;
|
|
11
|
+
//# sourceMappingURL=decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|