assemblerjs 1.1.24 → 1.1.26
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 +1 -0
- package/dist/index.d.ts +142 -0
- package/dist/index.js +15 -13
- package/dist/index.mjs +14 -13
- package/dist/index11.js +3 -3
- package/dist/index11.mjs +3 -3
- package/dist/index12.js +2 -2
- package/dist/index12.mjs +2 -2
- package/dist/index13.js +1 -1
- package/dist/index13.mjs +1 -1
- package/dist/index14.js +168 -3
- package/dist/index14.mjs +168 -3
- package/dist/index15.js +4 -22
- package/dist/index15.mjs +4 -22
- package/dist/index16.js +20 -9
- package/dist/index16.mjs +20 -9
- package/dist/index17.js +9 -87
- package/dist/index17.mjs +9 -87
- package/dist/index18.js +88 -16
- package/dist/index18.mjs +88 -16
- package/dist/index19.js +10 -10
- package/dist/index19.mjs +10 -10
- package/dist/index2.js +3 -3
- package/dist/index2.mjs +3 -3
- package/dist/index20.js +10 -10
- package/dist/index20.mjs +10 -10
- package/dist/index21.js +10 -10
- package/dist/index21.mjs +10 -10
- package/dist/index22.js +11 -26
- package/dist/index22.mjs +11 -25
- package/dist/index23.js +22 -22
- package/dist/index23.mjs +21 -21
- package/dist/index24.js +25 -19
- package/dist/index24.mjs +24 -19
- package/dist/index25.js +23 -25
- package/dist/index25.mjs +23 -21
- package/dist/index26.js +26 -46
- package/dist/index26.mjs +22 -45
- package/dist/index27.js +50 -2
- package/dist/index27.mjs +47 -2
- package/dist/index28.js +2 -19
- package/dist/index28.mjs +2 -15
- package/dist/index29.js +17 -159
- package/dist/index29.mjs +15 -158
- package/dist/index3.js +2 -2
- package/dist/index3.mjs +2 -2
- package/dist/index30.js +17 -50
- package/dist/index30.mjs +14 -50
- package/dist/index31.js +99 -71
- package/dist/index31.mjs +97 -71
- package/dist/index32.js +154 -51
- package/dist/index32.mjs +153 -51
- package/dist/index33.js +47 -28
- package/dist/index33.mjs +47 -28
- package/dist/index34.js +65 -161
- package/dist/index34.mjs +65 -161
- package/dist/index35.js +50 -58
- package/dist/index35.mjs +50 -58
- package/dist/index36.js +32 -18
- package/dist/index36.mjs +32 -15
- package/dist/index37.js +169 -16
- package/dist/index37.mjs +169 -16
- package/dist/index38.js +56 -100
- package/dist/index38.mjs +56 -98
- package/dist/index4.js +7 -7
- package/dist/index4.mjs +7 -7
- package/dist/index40.js +17 -118
- package/dist/index40.mjs +17 -118
- package/dist/index42.js +49 -29
- package/dist/index42.mjs +49 -28
- package/dist/index44.js +29 -49
- package/dist/index44.mjs +28 -49
- package/dist/index45.js +5 -5
- package/dist/index45.mjs +5 -5
- package/dist/index49.js +1 -1
- package/dist/index49.mjs +1 -1
- package/dist/index50.js +1 -1
- package/dist/index50.mjs +1 -1
- package/dist/index51.js +2 -2
- package/dist/index51.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ A modern, type-safe, and lightweight [Dependency Injection](https://en.wikipedia
|
|
|
25
25
|
- ♻️ **Lifecycle Hooks** - `onRegister`, `onInit`, `onDispose`
|
|
26
26
|
- 📡 **Built-in Event System** - Integrated EventManager
|
|
27
27
|
- 🔀 **AOP/Transversals** - Cross-cutting concerns (logging, security, caching, performance)
|
|
28
|
+
- 🎯 **Caller Tracking** - Audit logging, authorization, and request tracing with full caller context
|
|
28
29
|
- 🎨 **Custom Decorators** - Easy creation with `ParameterDecoratorFactory` and `createConstructorDecorator`
|
|
29
30
|
- 🔧 **Flexible Configuration** - Runtime configuration override
|
|
30
31
|
- 🏷️ **Tags Support** - Group and retrieve dependencies by tags
|
package/dist/index.d.ts
CHANGED
|
@@ -467,6 +467,14 @@ declare interface Buildable<T> {
|
|
|
467
467
|
configuration: Record<string, any>;
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
+
/**
|
|
471
|
+
* Metadata about a woven instance caller
|
|
472
|
+
*/
|
|
473
|
+
declare interface CallerMetadata {
|
|
474
|
+
className: string;
|
|
475
|
+
identifier?: string | symbol;
|
|
476
|
+
}
|
|
477
|
+
|
|
470
478
|
/**
|
|
471
479
|
* Injection binds a concrete class to itself as identifier
|
|
472
480
|
* and provides a configuration object that will be passed to context.
|
|
@@ -1357,6 +1365,140 @@ export declare interface TransversalMetadata {
|
|
|
1357
1365
|
instance?: any;
|
|
1358
1366
|
}
|
|
1359
1367
|
|
|
1368
|
+
/**
|
|
1369
|
+
* TransversalWeaver handles the weaving of aspects onto target instances.
|
|
1370
|
+
* It creates Proxy wrappers to intercept method calls and apply advices.
|
|
1371
|
+
*/
|
|
1372
|
+
export declare class TransversalWeaver {
|
|
1373
|
+
/**
|
|
1374
|
+
* Registry mapping woven proxy instances to their caller metadata.
|
|
1375
|
+
* Uses WeakMap to allow garbage collection of instances.
|
|
1376
|
+
*/
|
|
1377
|
+
private static callerRegistry;
|
|
1378
|
+
/**
|
|
1379
|
+
* Stack context for caller information.
|
|
1380
|
+
* Independent of Transversals - works even without any engaged aspects.
|
|
1381
|
+
* Allows tracking callers from external sources (Vue, Node, etc).
|
|
1382
|
+
*/
|
|
1383
|
+
private static callerStack;
|
|
1384
|
+
/**
|
|
1385
|
+
* Register caller metadata for a woven instance.
|
|
1386
|
+
* This allows manual registration if needed beyond automatic weaving.
|
|
1387
|
+
*
|
|
1388
|
+
* @param instance The woven instance
|
|
1389
|
+
* @param className The name of the calling class
|
|
1390
|
+
* @param identifier Optional identifier of the caller
|
|
1391
|
+
*/
|
|
1392
|
+
static registerCaller<T extends object>(instance: T, className: string, identifier?: string | symbol): void;
|
|
1393
|
+
/**
|
|
1394
|
+
* Get the caller metadata for a woven instance.
|
|
1395
|
+
*
|
|
1396
|
+
* @param instance The woven instance
|
|
1397
|
+
* @returns The caller metadata or undefined if not found
|
|
1398
|
+
*/
|
|
1399
|
+
static getCallerMetadata(instance: object): CallerMetadata | undefined;
|
|
1400
|
+
/**
|
|
1401
|
+
* Execute a function with caller context.
|
|
1402
|
+
* The caller info will be available in Transversal advices if present,
|
|
1403
|
+
* or accessible via getCurrentCaller() at any time.
|
|
1404
|
+
*
|
|
1405
|
+
* Works with or without Transversals engaged.
|
|
1406
|
+
*
|
|
1407
|
+
* @param caller The name of the calling component/class
|
|
1408
|
+
* @param identifier Optional identifier (class reference, symbol, etc)
|
|
1409
|
+
* @param fn The function to execute
|
|
1410
|
+
* @returns The result of the function (may be a Promise)
|
|
1411
|
+
*
|
|
1412
|
+
* @example
|
|
1413
|
+
* ```typescript
|
|
1414
|
+
* // From Vue component
|
|
1415
|
+
* TransversalWeaver.withCaller('MyVueComponent', () => {
|
|
1416
|
+
* await userService.save(data);
|
|
1417
|
+
* });
|
|
1418
|
+
*
|
|
1419
|
+
* // From Node with identifier
|
|
1420
|
+
* TransversalWeaver.withCaller('UserService', UserService, () => {
|
|
1421
|
+
* await dataService.process();
|
|
1422
|
+
* });
|
|
1423
|
+
* ```
|
|
1424
|
+
*/
|
|
1425
|
+
static withCaller<T>(caller: string, identifier?: string | symbol | (() => T | Promise<T>), fn?: () => T | Promise<T>): T | Promise<T>;
|
|
1426
|
+
/**
|
|
1427
|
+
* Wrap a function with caller context.
|
|
1428
|
+
* Returns a new function that will execute with the specified caller context.
|
|
1429
|
+
* Useful for creating wrapped functions that can be called multiple times.
|
|
1430
|
+
*
|
|
1431
|
+
* @param caller The name of the calling component/class
|
|
1432
|
+
* @param identifier Optional identifier (class reference, symbol, etc)
|
|
1433
|
+
* @param fn The function to wrap
|
|
1434
|
+
* @returns A wrapped function that maintains caller context on each call
|
|
1435
|
+
*
|
|
1436
|
+
* @example
|
|
1437
|
+
* ```typescript
|
|
1438
|
+
* // In Vue component
|
|
1439
|
+
* const mergeClasses = TransversalWeaver.wrapCaller(
|
|
1440
|
+
* 'LeafletMap',
|
|
1441
|
+
* 'LeafletMap.vue',
|
|
1442
|
+
* (...args: any[]) => tailwind.mergeClasses(...args)
|
|
1443
|
+
* );
|
|
1444
|
+
*
|
|
1445
|
+
* // Now each call maintains the caller context
|
|
1446
|
+
* mergeClasses('class1', 'class2'); // Advices see caller: LeafletMap
|
|
1447
|
+
* ```
|
|
1448
|
+
*/
|
|
1449
|
+
static wrapCaller<T extends (...args: any[]) => any>(caller: string, identifier?: string | symbol | T, fn?: T): T;
|
|
1450
|
+
/**
|
|
1451
|
+
* Get the current caller metadata from the context stack.
|
|
1452
|
+
* Returns undefined if no caller context is active.
|
|
1453
|
+
* Works even if no Transversal is engaged.
|
|
1454
|
+
*
|
|
1455
|
+
* @returns The current caller metadata or undefined
|
|
1456
|
+
*
|
|
1457
|
+
* @example
|
|
1458
|
+
* ```typescript
|
|
1459
|
+
* TransversalWeaver.withCaller('MyComponent', () => {
|
|
1460
|
+
* const caller = TransversalWeaver.getCurrentCaller();
|
|
1461
|
+
* console.log(caller?.className); // 'MyComponent'
|
|
1462
|
+
* });
|
|
1463
|
+
* ```
|
|
1464
|
+
*/
|
|
1465
|
+
static getCurrentCaller(): CallerMetadata | undefined;
|
|
1466
|
+
/**
|
|
1467
|
+
* Weaves transversals onto an instance.
|
|
1468
|
+
* Returns a Proxy if transversals apply, otherwise returns the original instance.
|
|
1469
|
+
*
|
|
1470
|
+
* @param instance The instance to weave transversals onto
|
|
1471
|
+
* @param concrete The concrete class of the instance
|
|
1472
|
+
* @param context The assembler context
|
|
1473
|
+
* @returns The woven instance (may be a Proxy)
|
|
1474
|
+
*/
|
|
1475
|
+
static weave<T>(instance: T, concrete: Concrete<T>, context: AssemblerContext): T;
|
|
1476
|
+
/**
|
|
1477
|
+
* Executes the advice chain (before -> around -> method -> after).
|
|
1478
|
+
* Handles both synchronous and asynchronous execution.
|
|
1479
|
+
*
|
|
1480
|
+
* @param advices The advices to execute
|
|
1481
|
+
* @param originalMethod The original method to call
|
|
1482
|
+
* @param target The target instance
|
|
1483
|
+
* @param args The method arguments
|
|
1484
|
+
* @param joinPoint The join point information
|
|
1485
|
+
* @returns The method result (may be a Promise)
|
|
1486
|
+
*/
|
|
1487
|
+
private static executeAdviceChain;
|
|
1488
|
+
/**
|
|
1489
|
+
* Builds the proceed chain for around advices.
|
|
1490
|
+
* Each advice can call proceed() to continue to the next advice or the original method.
|
|
1491
|
+
*
|
|
1492
|
+
* @param aroundAdvices The around advices to chain
|
|
1493
|
+
* @param originalMethod The original method
|
|
1494
|
+
* @param target The target instance
|
|
1495
|
+
* @param args The method arguments
|
|
1496
|
+
* @param joinPoint The join point information
|
|
1497
|
+
* @returns The result of the advice chain
|
|
1498
|
+
*/
|
|
1499
|
+
private static buildAroundChain;
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1360
1502
|
/**
|
|
1361
1503
|
* Injects an object passed with `string`, `symbol` or abstract class identifier.
|
|
1362
1504
|
* The identifier can be:
|
package/dist/index.js
CHANGED
|
@@ -14,19 +14,20 @@ const eventManager_abstract = require('./index10.js');
|
|
|
14
14
|
const decorators = require('./index11.js');
|
|
15
15
|
const affect = require('./index12.js');
|
|
16
16
|
const transversalManager = require('./index13.js');
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
17
|
+
const transversalWeaver = require('./index14.js');
|
|
18
|
+
const abstract$1 = require('./index15.js');
|
|
19
|
+
const _await = require('./index16.js');
|
|
20
|
+
const indexFactory = require('./index17.js');
|
|
21
|
+
const parameterDecoratorFactory = require('./index18.js');
|
|
22
|
+
const context = require('./index19.js');
|
|
23
|
+
const configuration = require('./index20.js');
|
|
24
|
+
const definition = require('./index21.js');
|
|
25
|
+
const dispose = require('./index22.js');
|
|
26
|
+
const use = require('./index23.js');
|
|
27
|
+
const global = require('./index24.js');
|
|
28
|
+
const optional = require('./index25.js');
|
|
29
|
+
const helpers$1 = require('./index26.js');
|
|
30
|
+
const constructorDecorator = require('./index27.js');
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
|
|
@@ -49,6 +50,7 @@ exports.Transversal = decorators.Transversal;
|
|
|
49
50
|
exports.isTransversal = decorators.isTransversal;
|
|
50
51
|
exports.Affect = affect.Affect;
|
|
51
52
|
exports.TransversalManager = transversalManager.TransversalManager;
|
|
53
|
+
exports.TransversalWeaver = transversalWeaver.TransversalWeaver;
|
|
52
54
|
exports.AbstractTransversal = abstract$1.AbstractTransversal;
|
|
53
55
|
exports.Await = _await.Await;
|
|
54
56
|
exports.createParamIndexDecorator = indexFactory.createParamIndexDecorator;
|
package/dist/index.mjs
CHANGED
|
@@ -10,16 +10,17 @@ export { AbstractEventManager } from './index10.mjs';
|
|
|
10
10
|
export { After, Around, Before, Transversal, isTransversal } from './index11.mjs';
|
|
11
11
|
export { Affect } from './index12.mjs';
|
|
12
12
|
export { TransversalManager } from './index13.mjs';
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
13
|
+
export { TransversalWeaver } from './index14.mjs';
|
|
14
|
+
export { AbstractTransversal } from './index15.mjs';
|
|
15
|
+
export { Await } from './index16.mjs';
|
|
16
|
+
export { createParamIndexDecorator } from './index17.mjs';
|
|
17
|
+
export { ParameterDecoratorFactory } from './index18.mjs';
|
|
18
|
+
export { Context } from './index19.mjs';
|
|
19
|
+
export { Configuration } from './index20.mjs';
|
|
20
|
+
export { Definition } from './index21.mjs';
|
|
21
|
+
export { Dispose } from './index22.mjs';
|
|
22
|
+
export { Use, decorateUse } from './index23.mjs';
|
|
23
|
+
export { Global, decorateGlobal } from './index24.mjs';
|
|
24
|
+
export { Optional } from './index25.mjs';
|
|
25
|
+
export { getDecoratedParametersIndexes, getParamIndexKey, getParamValueKey, getParameterIndexes, getParameterValues } from './index26.mjs';
|
|
26
|
+
export { ConstructorDecorator, createConstructorDecorator } from './index27.mjs';
|
package/dist/index11.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const constants = require('./
|
|
6
|
-
const reflection = require('./
|
|
5
|
+
const constants = require('./index29.js');
|
|
6
|
+
const reflection = require('./index30.js');
|
|
7
7
|
const decorator = require('./index2.js');
|
|
8
|
-
const schema = require('./
|
|
8
|
+
const schema = require('./index31.js');
|
|
9
9
|
|
|
10
10
|
function isTransversal(e) {
|
|
11
11
|
try {
|
package/dist/index11.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ReflectValue } from './
|
|
2
|
-
import { getCustomMetadata, defineCustomMetadata } from './
|
|
1
|
+
import { ReflectValue } from './index29.mjs';
|
|
2
|
+
import { getCustomMetadata, defineCustomMetadata } from './index30.mjs';
|
|
3
3
|
import { Assemblage } from './index2.mjs';
|
|
4
|
-
import { getDefinition } from './
|
|
4
|
+
import { getDefinition } from './index31.mjs';
|
|
5
5
|
|
|
6
6
|
function isTransversal(e) {
|
|
7
7
|
try {
|
package/dist/index12.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
require('./
|
|
6
|
-
const constants = require('./
|
|
5
|
+
require('./index28.js');
|
|
6
|
+
const constants = require('./index29.js');
|
|
7
7
|
|
|
8
8
|
function Affect(t, f) {
|
|
9
9
|
return function(o, c, n) {
|
package/dist/index12.mjs
CHANGED
package/dist/index13.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const core = require('@assemblerjs/core');
|
|
6
6
|
const pointcutMatcher = require('./index41.js');
|
|
7
7
|
const affect = require('./index12.js');
|
|
8
|
-
const schema = require('./
|
|
8
|
+
const schema = require('./index31.js');
|
|
9
9
|
|
|
10
10
|
class TransversalManager {
|
|
11
11
|
static getInstance(e) {
|
package/dist/index13.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isClass } from '@assemblerjs/core';
|
|
2
2
|
import { PointcutMatcher } from './index41.mjs';
|
|
3
3
|
import { getAffectedMethods } from './index12.mjs';
|
|
4
|
-
import { getDefinition } from './
|
|
4
|
+
import { getDefinition } from './index31.mjs';
|
|
5
5
|
|
|
6
6
|
class TransversalManager {
|
|
7
7
|
static getInstance(e) {
|
package/dist/index14.js
CHANGED
|
@@ -2,8 +2,173 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const transversalManager = require('./index13.js');
|
|
6
|
+
const affect = require('./index12.js');
|
|
7
|
+
|
|
8
|
+
class TransversalWeaver {
|
|
9
|
+
static registerCaller(t, e, r) {
|
|
10
|
+
this.callerRegistry.set(t, {
|
|
11
|
+
className: e,
|
|
12
|
+
identifier: r
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
static getCallerMetadata(t) {
|
|
16
|
+
return this.callerRegistry.get(t);
|
|
17
|
+
}
|
|
18
|
+
static withCaller(t, e, r) {
|
|
19
|
+
if (typeof e === 'function') {
|
|
20
|
+
r = e;
|
|
21
|
+
e = undefined;
|
|
22
|
+
}
|
|
23
|
+
const n = {
|
|
24
|
+
className: t,
|
|
25
|
+
identifier: e
|
|
26
|
+
};
|
|
27
|
+
this.callerStack.push(n);
|
|
28
|
+
const a = r();
|
|
29
|
+
if (a instanceof Promise) {
|
|
30
|
+
return a.finally(()=>this.callerStack.pop());
|
|
31
|
+
}
|
|
32
|
+
this.callerStack.pop();
|
|
33
|
+
return a;
|
|
34
|
+
}
|
|
35
|
+
static wrapCaller(t, e, r) {
|
|
36
|
+
if (typeof e === 'function') {
|
|
37
|
+
r = e;
|
|
38
|
+
e = undefined;
|
|
39
|
+
}
|
|
40
|
+
const n = {
|
|
41
|
+
className: t,
|
|
42
|
+
identifier: e
|
|
43
|
+
};
|
|
44
|
+
return (...t)=>{
|
|
45
|
+
this.callerStack.push(n);
|
|
46
|
+
try {
|
|
47
|
+
const e = r(...t);
|
|
48
|
+
if (e instanceof Promise) {
|
|
49
|
+
return e.finally(()=>this.callerStack.pop());
|
|
50
|
+
}
|
|
51
|
+
this.callerStack.pop();
|
|
52
|
+
return e;
|
|
53
|
+
} catch (t) {
|
|
54
|
+
this.callerStack.pop();
|
|
55
|
+
throw t;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
static getCurrentCaller() {
|
|
60
|
+
return this.callerStack[this.callerStack.length - 1];
|
|
61
|
+
}
|
|
62
|
+
static weave(r, n, a) {
|
|
63
|
+
const s = transversalManager.TransversalManager.getInstance(a);
|
|
64
|
+
const c = s.getAspectsForTarget(n);
|
|
65
|
+
const l = Object.getPrototypeOf(r);
|
|
66
|
+
const o = Object.getOwnPropertyNames(l).some((t)=>{
|
|
67
|
+
if (t === 'constructor') return false;
|
|
68
|
+
const r = Object.getOwnPropertyDescriptor(l, t);
|
|
69
|
+
if (!r) return false;
|
|
70
|
+
const n = r.value && typeof r.value === 'function';
|
|
71
|
+
const a = r.get && typeof r.get === 'function';
|
|
72
|
+
if (!n && !a) return false;
|
|
73
|
+
const s = affect.getAffectedMethods(l, t);
|
|
74
|
+
return s.length > 0;
|
|
75
|
+
});
|
|
76
|
+
if (c.length === 0 && !o) {
|
|
77
|
+
return r;
|
|
78
|
+
}
|
|
79
|
+
const i = new Proxy(r, {
|
|
80
|
+
get (t, e, r) {
|
|
81
|
+
const n = Reflect.get(t, e, r);
|
|
82
|
+
if (typeof n !== 'function') {
|
|
83
|
+
return n;
|
|
84
|
+
}
|
|
85
|
+
return function(...r) {
|
|
86
|
+
const a = String(e);
|
|
87
|
+
const l = TransversalWeaver.getCurrentCaller() ?? TransversalWeaver.callerRegistry.get(this);
|
|
88
|
+
const o = {
|
|
89
|
+
target: t,
|
|
90
|
+
methodName: a,
|
|
91
|
+
args: r,
|
|
92
|
+
caller: l?.className,
|
|
93
|
+
callerIdentifier: l?.identifier
|
|
94
|
+
};
|
|
95
|
+
const i = s.getAdvicesForJoinPoint(o, c, t, e);
|
|
96
|
+
return TransversalWeaver.executeAdviceChain(i, n, t, r, o);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
TransversalWeaver.callerRegistry.set(i, {
|
|
101
|
+
className: n.name,
|
|
102
|
+
identifier: n.name
|
|
103
|
+
});
|
|
104
|
+
return i;
|
|
105
|
+
}
|
|
106
|
+
static executeAdviceChain(t, e, r, n, a) {
|
|
107
|
+
const s = t.filter((t)=>t.type === 'before');
|
|
108
|
+
const c = t.filter((t)=>t.type === 'around');
|
|
109
|
+
const l = t.filter((t)=>t.type === 'after');
|
|
110
|
+
try {
|
|
111
|
+
for (const t of s){
|
|
112
|
+
const e = {
|
|
113
|
+
...a,
|
|
114
|
+
config: t.config
|
|
115
|
+
};
|
|
116
|
+
t.method.call(t.transversalInstance, e);
|
|
117
|
+
}
|
|
118
|
+
let t;
|
|
119
|
+
if (c.length > 0) {
|
|
120
|
+
t = this.buildAroundChain(c, e, r, n, a);
|
|
121
|
+
} else {
|
|
122
|
+
t = e.apply(r, n);
|
|
123
|
+
}
|
|
124
|
+
if (t instanceof Promise) {
|
|
125
|
+
return t.then((t)=>{
|
|
126
|
+
for (const e of l){
|
|
127
|
+
const r = {
|
|
128
|
+
...a,
|
|
129
|
+
result: t
|
|
130
|
+
};
|
|
131
|
+
e.method.call(e.transversalInstance, r);
|
|
132
|
+
}
|
|
133
|
+
return t;
|
|
134
|
+
}).catch((t)=>{
|
|
135
|
+
a.error = t;
|
|
136
|
+
throw t;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
for (const e of l){
|
|
140
|
+
const r = {
|
|
141
|
+
...a,
|
|
142
|
+
result: t,
|
|
143
|
+
config: e.config
|
|
144
|
+
};
|
|
145
|
+
e.method.call(e.transversalInstance, r);
|
|
146
|
+
}
|
|
147
|
+
return t;
|
|
148
|
+
} catch (t) {
|
|
149
|
+
a.error = t;
|
|
150
|
+
throw t;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
static buildAroundChain(t, e, r, n, a) {
|
|
154
|
+
let s = 0;
|
|
155
|
+
const c = ()=>{
|
|
156
|
+
if (s < t.length) {
|
|
157
|
+
const e = t[s++];
|
|
158
|
+
const r = {
|
|
159
|
+
...a,
|
|
160
|
+
proceed: c,
|
|
161
|
+
config: e.config
|
|
162
|
+
};
|
|
163
|
+
return e.method.call(e.transversalInstance, r);
|
|
164
|
+
} else {
|
|
165
|
+
return e.apply(r, n);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return c();
|
|
169
|
+
}
|
|
7
170
|
}
|
|
171
|
+
TransversalWeaver.callerRegistry = new WeakMap();
|
|
172
|
+
TransversalWeaver.callerStack = [];
|
|
8
173
|
|
|
9
|
-
exports.
|
|
174
|
+
exports.TransversalWeaver = TransversalWeaver;
|
package/dist/index14.mjs
CHANGED
|
@@ -1,5 +1,170 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { TransversalManager } from './index13.mjs';
|
|
2
|
+
import { getAffectedMethods } from './index12.mjs';
|
|
3
|
+
|
|
4
|
+
class TransversalWeaver {
|
|
5
|
+
static registerCaller(t, e, r) {
|
|
6
|
+
this.callerRegistry.set(t, {
|
|
7
|
+
className: e,
|
|
8
|
+
identifier: r
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
static getCallerMetadata(t) {
|
|
12
|
+
return this.callerRegistry.get(t);
|
|
13
|
+
}
|
|
14
|
+
static withCaller(t, e, r) {
|
|
15
|
+
if (typeof e === 'function') {
|
|
16
|
+
r = e;
|
|
17
|
+
e = undefined;
|
|
18
|
+
}
|
|
19
|
+
const n = {
|
|
20
|
+
className: t,
|
|
21
|
+
identifier: e
|
|
22
|
+
};
|
|
23
|
+
this.callerStack.push(n);
|
|
24
|
+
const a = r();
|
|
25
|
+
if (a instanceof Promise) {
|
|
26
|
+
return a.finally(()=>this.callerStack.pop());
|
|
27
|
+
}
|
|
28
|
+
this.callerStack.pop();
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
static wrapCaller(t, e, r) {
|
|
32
|
+
if (typeof e === 'function') {
|
|
33
|
+
r = e;
|
|
34
|
+
e = undefined;
|
|
35
|
+
}
|
|
36
|
+
const n = {
|
|
37
|
+
className: t,
|
|
38
|
+
identifier: e
|
|
39
|
+
};
|
|
40
|
+
return (...t)=>{
|
|
41
|
+
this.callerStack.push(n);
|
|
42
|
+
try {
|
|
43
|
+
const e = r(...t);
|
|
44
|
+
if (e instanceof Promise) {
|
|
45
|
+
return e.finally(()=>this.callerStack.pop());
|
|
46
|
+
}
|
|
47
|
+
this.callerStack.pop();
|
|
48
|
+
return e;
|
|
49
|
+
} catch (t) {
|
|
50
|
+
this.callerStack.pop();
|
|
51
|
+
throw t;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
static getCurrentCaller() {
|
|
56
|
+
return this.callerStack[this.callerStack.length - 1];
|
|
57
|
+
}
|
|
58
|
+
static weave(r, n, a) {
|
|
59
|
+
const s = TransversalManager.getInstance(a);
|
|
60
|
+
const c = s.getAspectsForTarget(n);
|
|
61
|
+
const l = Object.getPrototypeOf(r);
|
|
62
|
+
const o = Object.getOwnPropertyNames(l).some((t)=>{
|
|
63
|
+
if (t === 'constructor') return false;
|
|
64
|
+
const r = Object.getOwnPropertyDescriptor(l, t);
|
|
65
|
+
if (!r) return false;
|
|
66
|
+
const n = r.value && typeof r.value === 'function';
|
|
67
|
+
const a = r.get && typeof r.get === 'function';
|
|
68
|
+
if (!n && !a) return false;
|
|
69
|
+
const s = getAffectedMethods(l, t);
|
|
70
|
+
return s.length > 0;
|
|
71
|
+
});
|
|
72
|
+
if (c.length === 0 && !o) {
|
|
73
|
+
return r;
|
|
74
|
+
}
|
|
75
|
+
const i = new Proxy(r, {
|
|
76
|
+
get (t, e, r) {
|
|
77
|
+
const n = Reflect.get(t, e, r);
|
|
78
|
+
if (typeof n !== 'function') {
|
|
79
|
+
return n;
|
|
80
|
+
}
|
|
81
|
+
return function(...r) {
|
|
82
|
+
const a = String(e);
|
|
83
|
+
const l = TransversalWeaver.getCurrentCaller() ?? TransversalWeaver.callerRegistry.get(this);
|
|
84
|
+
const o = {
|
|
85
|
+
target: t,
|
|
86
|
+
methodName: a,
|
|
87
|
+
args: r,
|
|
88
|
+
caller: l?.className,
|
|
89
|
+
callerIdentifier: l?.identifier
|
|
90
|
+
};
|
|
91
|
+
const i = s.getAdvicesForJoinPoint(o, c, t, e);
|
|
92
|
+
return TransversalWeaver.executeAdviceChain(i, n, t, r, o);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
TransversalWeaver.callerRegistry.set(i, {
|
|
97
|
+
className: n.name,
|
|
98
|
+
identifier: n.name
|
|
99
|
+
});
|
|
100
|
+
return i;
|
|
101
|
+
}
|
|
102
|
+
static executeAdviceChain(t, e, r, n, a) {
|
|
103
|
+
const s = t.filter((t)=>t.type === 'before');
|
|
104
|
+
const c = t.filter((t)=>t.type === 'around');
|
|
105
|
+
const l = t.filter((t)=>t.type === 'after');
|
|
106
|
+
try {
|
|
107
|
+
for (const t of s){
|
|
108
|
+
const e = {
|
|
109
|
+
...a,
|
|
110
|
+
config: t.config
|
|
111
|
+
};
|
|
112
|
+
t.method.call(t.transversalInstance, e);
|
|
113
|
+
}
|
|
114
|
+
let t;
|
|
115
|
+
if (c.length > 0) {
|
|
116
|
+
t = this.buildAroundChain(c, e, r, n, a);
|
|
117
|
+
} else {
|
|
118
|
+
t = e.apply(r, n);
|
|
119
|
+
}
|
|
120
|
+
if (t instanceof Promise) {
|
|
121
|
+
return t.then((t)=>{
|
|
122
|
+
for (const e of l){
|
|
123
|
+
const r = {
|
|
124
|
+
...a,
|
|
125
|
+
result: t
|
|
126
|
+
};
|
|
127
|
+
e.method.call(e.transversalInstance, r);
|
|
128
|
+
}
|
|
129
|
+
return t;
|
|
130
|
+
}).catch((t)=>{
|
|
131
|
+
a.error = t;
|
|
132
|
+
throw t;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
for (const e of l){
|
|
136
|
+
const r = {
|
|
137
|
+
...a,
|
|
138
|
+
result: t,
|
|
139
|
+
config: e.config
|
|
140
|
+
};
|
|
141
|
+
e.method.call(e.transversalInstance, r);
|
|
142
|
+
}
|
|
143
|
+
return t;
|
|
144
|
+
} catch (t) {
|
|
145
|
+
a.error = t;
|
|
146
|
+
throw t;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
static buildAroundChain(t, e, r, n, a) {
|
|
150
|
+
let s = 0;
|
|
151
|
+
const c = ()=>{
|
|
152
|
+
if (s < t.length) {
|
|
153
|
+
const e = t[s++];
|
|
154
|
+
const r = {
|
|
155
|
+
...a,
|
|
156
|
+
proceed: c,
|
|
157
|
+
config: e.config
|
|
158
|
+
};
|
|
159
|
+
return e.method.call(e.transversalInstance, r);
|
|
160
|
+
} else {
|
|
161
|
+
return e.apply(r, n);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
return c();
|
|
165
|
+
}
|
|
3
166
|
}
|
|
167
|
+
TransversalWeaver.callerRegistry = new WeakMap();
|
|
168
|
+
TransversalWeaver.callerStack = [];
|
|
4
169
|
|
|
5
|
-
export {
|
|
170
|
+
export { TransversalWeaver };
|