mesh-ioc 3.3.1 → 4.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 +20 -0
- package/out/main/dep.js +0 -1
- package/out/main/dep.js.map +1 -1
- package/out/main/index.d.ts +1 -0
- package/out/main/index.js +1 -0
- package/out/main/index.js.map +1 -1
- package/out/main/proxy.d.ts +3 -0
- package/out/main/proxy.js +13 -0
- package/out/main/proxy.js.map +1 -0
- package/out/main/types.d.ts +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,9 +17,21 @@ Mesh IoC solves the problem of dependency management of application services. It
|
|
|
17
17
|
- 🕵️♀️ Provides APIs for dependency analysis
|
|
18
18
|
- 🐓 🥚 Tolerates circular dependencies
|
|
19
19
|
|
|
20
|
+
## Prerequisites
|
|
21
|
+
|
|
22
|
+
Make sure `tsconfig.json` contains the following:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
"experimentalDecorators": true,
|
|
26
|
+
"emitDecoratorMetadata": true,
|
|
27
|
+
"useDefineForClassFields": false,
|
|
28
|
+
```
|
|
29
|
+
|
|
20
30
|
## API Cheatsheet
|
|
21
31
|
|
|
22
32
|
```ts
|
|
33
|
+
import { Mesh, dep } from 'mesh-ioc';
|
|
34
|
+
|
|
23
35
|
// Mesh is an IoC container that stores service bindings and instantiated objects
|
|
24
36
|
const mesh = new Mesh('someName');
|
|
25
37
|
|
|
@@ -393,6 +405,14 @@ Note: the important limitation of this approach is that `@dep` are not available
|
|
|
393
405
|
|
|
394
406
|
- Don't be too dogmatic about interface/implementation split. For example, if all class methods are its public interface, there is no point in splitting it into an "interface" and its single implementation (e.g. ` abstract Config` and `ConfigImpl`) — this provides close to zero practical value and contributes towards people disliking the OOP paradigm for its verbosity and cargo culting. Instead just bind the concrete class to itself.
|
|
395
407
|
|
|
408
|
+
## TypeScript Decorators
|
|
409
|
+
|
|
410
|
+
This library is designed to work with [TypeScript stage-2 Experimental Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) and emitted metadata to facilitate some of the features.
|
|
411
|
+
|
|
412
|
+
TypeScript 5.0 implementes [stage-3 ECMAScript decorators](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#decorators) which is largely incompatible with Mesh.
|
|
413
|
+
|
|
414
|
+
We have not yet looked at migrating to ECMAScript decorators, but it is likely that migrating to them will be a breaking change. For now, please stick with `experimentalDecorators: true` as mentioned in [prerequisited](#prerequisites).
|
|
415
|
+
|
|
396
416
|
## License
|
|
397
417
|
|
|
398
418
|
[ISC](https://en.wikipedia.org/wiki/ISC_license) © Boris Okunskiy
|
package/out/main/dep.js
CHANGED
package/out/main/dep.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dep.js","sourceRoot":"","sources":["../../src/main/dep.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAQ,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG3C,MAAM,CAAC,MAAM,WAAW,GAAkB,EAAE,CAAC;AAO7C,MAAM,UAAU,GAAG,CAAC,UAAsB,EAAE;IACxC,OAAO,UAAU,MAAW,EAAE,YAAoB;QAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;QAC1C,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,CAAa,CAAC;QACxF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,UAAU,EAAE,IAAI,CAAC;QAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC;QACpC,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,MAAM,IAAI,iBAAiB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACzD,CAAC;QACD,WAAW,CAAC,IAAI,CAAC;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AChC,IAAI,KAAK,EAAE,CAAC;oBACR,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE;wBACtC,YAAY,EAAE,IAAI;wBAClB,KAAK;qBACR,CAAC,CAAC;gBACP,CAAC;gBACD,OAAO,KAAK,CAAC;YACjB,CAAC;SACJ,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAsB;IAC/C,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;QACxD,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACrB,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/out/main/index.d.ts
CHANGED
package/out/main/index.js
CHANGED
package/out/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
});
|
|
11
|
+
return new Proxy(thisArg, handler);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +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,GAAI,OAAO,CAAC,QAAQ,CAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACjE,OAAQ,OAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC;YACrD,CAAC,CAAC;QACN,CAAC;KACJ,CAAC,CAAC;IACH,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC"}
|
package/out/main/types.d.ts
CHANGED