mesh-ioc 4.0.1 → 4.1.1

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.
@@ -1,3 +1,3 @@
1
1
  import { ServiceKey } from './types.js';
2
2
  export type ServiceProxy<T> = T;
3
- export declare function dependency<T>(thisArg: any, serviceKey: ServiceKey<T>): T;
3
+ export declare function dependency<T>(thisArg: any, serviceKey: ServiceKey<T>, cache?: boolean): T;
package/out/main/proxy.js CHANGED
@@ -1,13 +1,20 @@
1
1
  import { MESH_REF } from './mesh.js';
2
- export function dependency(thisArg, serviceKey) {
3
- const handler = new Proxy({}, {
4
- get(_target, trap) {
5
- return function (_target, ...args) {
6
- const instance = thisArg[MESH_REF].resolve(serviceKey);
7
- return Reflect[trap](instance, ...args);
8
- };
9
- }
10
- });
2
+ const PROXY_TRAPS = Object.getOwnPropertyNames(Reflect);
3
+ export function dependency(thisArg, serviceKey, cache = true) {
4
+ let cachedInstance;
5
+ const handler = {};
6
+ for (const trap of PROXY_TRAPS) {
7
+ handler[trap] = function (_target, ...args) {
8
+ let instance = cachedInstance;
9
+ if (!instance) {
10
+ instance = thisArg[MESH_REF].resolve(serviceKey);
11
+ }
12
+ if (cache) {
13
+ cachedInstance = instance;
14
+ }
15
+ return Reflect[trap](instance, ...args);
16
+ };
17
+ }
11
18
  return new Proxy(thisArg, handler);
12
19
  }
13
20
  //# sourceMappingURL=proxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/main/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,WAAW,CAAC;AAK3C,MAAM,UAAU,UAAU,CAAI,OAAY,EAAE,UAAyB;IACjE,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,EAAuB,EAAE;QAC/C,GAAG,CAAC,OAAO,EAAE,IAAI;YACb,OAAO,UAAU,OAAY,EAAE,GAAG,IAAW;gBACzC,MAAM,QAAQ,GAA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",
4
4
  "description": "Powerful and Lightweight IoC Library",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -39,14 +39,14 @@
39
39
  "author": "Boris Okunskiy",
40
40
  "license": "ISC",
41
41
  "devDependencies": {
42
- "@nodescript/eslint-config": "^2.0.2",
42
+ "@fastify/pre-commit": "^2.2.1",
43
+ "@nodescript/eslint-config": "^2.1.0",
43
44
  "@types/mocha": "^10.0.10",
44
45
  "@types/node": "^22.10.2",
45
- "chalk": "^5.4.1",
46
- "eslint": "^9.17.0",
47
- "mocha": "^11.0.1",
48
- "pre-commit": "^1.2.2",
46
+ "chalk": "^5.6.2",
47
+ "eslint": "^9.39.2",
48
+ "mocha": "^11.7.5",
49
49
  "reflect-metadata": "^0.2.2",
50
- "typescript": "^5.7.2"
50
+ "typescript": "^5.9.3"
51
51
  }
52
52
  }