@resolid/di 0.7.0 → 0.7.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/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/package.json +24 -25
package/dist/index.d.mts
CHANGED
|
@@ -25,11 +25,11 @@ interface Resolver {
|
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/container/index.d.ts
|
|
27
27
|
type Scope = "singleton" | "transient";
|
|
28
|
-
|
|
28
|
+
interface Provider<T = unknown> {
|
|
29
29
|
token: Token<T>;
|
|
30
30
|
factory: () => T;
|
|
31
31
|
scope?: Scope;
|
|
32
|
-
}
|
|
32
|
+
}
|
|
33
33
|
declare class Container implements Resolver, Disposable {
|
|
34
34
|
private readonly _providers;
|
|
35
35
|
private readonly _singletons;
|
|
@@ -49,7 +49,7 @@ declare class Container implements Resolver, Disposable {
|
|
|
49
49
|
optional: true;
|
|
50
50
|
}): () => T | undefined;
|
|
51
51
|
get<T>(token: Token<T>, options: {
|
|
52
|
-
lazy
|
|
52
|
+
lazy: false;
|
|
53
53
|
optional?: boolean;
|
|
54
54
|
}): T | undefined;
|
|
55
55
|
dispose(): Promise<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=class extends Error{constructor(){super(`inject() must be called within a injection context`)}},t=class t{static contextStack=[];resolver;constructor(e){this.resolver=e}static current(){let t=this.contextStack[this.contextStack.length-1];if(t===void 0)throw new e;return t}run(e){t.contextStack.push(this);try{return e(this.resolver)}finally{t.contextStack.pop()}}};function n(e){return typeof e==`symbol`?e.description??String(e):e.name}var r=class{_providers=new Map;_singletons=new Map;_constructing=[];_checkCircularDependency(e){if(this._constructing.includes(e))throw Error(`Circular dependency detected ${[...this._constructing,e].map(n).join(` -> `)}`)}_resolve(e,r){this._checkCircularDependency(e);let i=this._providers.get(e);if(i===void 0){if(!r)throw Error(`No provider found for ${n(e)}`);return}let a=i.scope!==`transient`;if(a&&this._singletons.has(e))return this._singletons.get(e);this._constructing.push(e);try{let n=new t(this).run(()=>i.factory());return a&&this._singletons.set(e,n),n}finally{this._constructing.pop()}}add(e){this._providers.set(e.token,e)}get(e,t){return t?.lazy??!1?()=>this.get(e,{...t,lazy:!1}):this._resolve(e,t?.optional??!1)}async dispose(){let e=0,t=``;for(let[r,i]of this._singletons)if(typeof i.dispose==`function`)try{await i.dispose()}catch(i){e++,t+=`${n(r)}: ${i instanceof Error?i.message:i}; `}if(this._singletons.clear(),e>0)throw Error(`Failed to dispose ${e} provider(s):\n${t.slice(0,-2)}`)}};function i(n,r){try{return t.current().run(e=>e.get(n,r))}catch(t){if(t instanceof e&&r?.optional==1)return;throw t}}export{r as Container,i as inject};
|
|
1
|
+
var e=class extends Error{constructor(){super(`inject() must be called within a injection context`)}},t=class t{static contextStack=[];resolver;constructor(e){this.resolver=e}static current(){let t=this.contextStack[this.contextStack.length-1];if(t===void 0)throw new e;return t}run(e){t.contextStack.push(this);try{return e(this.resolver)}finally{t.contextStack.pop()}}};function n(e){return typeof e==`symbol`?e.description??String(e):e.name}var r=class{_providers=new Map;_singletons=new Map;_constructing=[];_checkCircularDependency(e){if(this._constructing.includes(e))throw Error(`Circular dependency detected ${[...this._constructing,e].map(n).join(` -> `)}`)}_resolve(e,r){this._checkCircularDependency(e);let i=this._providers.get(e);if(i===void 0){if(!r)throw Error(`No provider found for ${n(e)}`);return}let a=i.scope!==`transient`;if(a&&this._singletons.has(e))return this._singletons.get(e);this._constructing.push(e);try{let n=new t(this).run(()=>i.factory());return a&&this._singletons.set(e,n),n}finally{this._constructing.pop()}}add(e){this._providers.set(e.token,e)}get(e,t){return t?.lazy??!1?()=>this.get(e,{...t,lazy:!1}):this._resolve(e,t?.optional??!1)}async dispose(){let e=0,t=``;for(let[r,i]of this._singletons)if(typeof i.dispose==`function`)try{await i.dispose()}catch(i){e++,t+=`${n(r)}: ${i instanceof Error?i.message:String(i)}; `}if(this._singletons.clear(),e>0)throw Error(`Failed to dispose ${e} provider(s):\n${t.slice(0,-2)}`)}};function i(n,r){try{return t.current().run(e=>e.get(n,r))}catch(t){if(t instanceof e&&r?.optional==1)return;throw t}}export{r as Container,i as inject};
|
package/package.json
CHANGED
|
@@ -1,54 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolid/di",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "TypeScript Dependency Injection Container",
|
|
6
6
|
"keywords": [
|
|
7
|
-
"resolid",
|
|
8
7
|
"container",
|
|
9
|
-
"
|
|
10
|
-
"inversion of control",
|
|
8
|
+
"dependency injection",
|
|
11
9
|
"di",
|
|
12
|
-
"
|
|
10
|
+
"inversion of control",
|
|
11
|
+
"ioc",
|
|
12
|
+
"resolid"
|
|
13
13
|
],
|
|
14
14
|
"homepage": "https://www.resolid.tech",
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/resolid/framework.git",
|
|
18
|
-
"directory": "packages/di"
|
|
19
|
-
},
|
|
20
15
|
"license": "MIT",
|
|
21
16
|
"author": {
|
|
22
17
|
"name": "Huijie Wei",
|
|
23
18
|
"email": "hello@resolid.tech"
|
|
24
19
|
},
|
|
25
|
-
"
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/resolid/framework.git",
|
|
23
|
+
"directory": "packages/di"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
26
28
|
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"types": "./dist/index.d.mts",
|
|
27
31
|
"exports": {
|
|
28
32
|
".": {
|
|
29
33
|
"types": "./dist/index.d.mts",
|
|
30
34
|
"import": "./dist/index.mjs"
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
"main": "./dist/index.mjs",
|
|
34
|
-
"types": "./dist/index.d.mts",
|
|
35
|
-
"files": [
|
|
36
|
-
"dist"
|
|
37
|
-
],
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"tsdown": "^0.16.8",
|
|
40
|
-
"typescript": "^5.9.3"
|
|
41
|
-
},
|
|
42
|
-
"engines": {
|
|
43
|
-
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
44
37
|
},
|
|
45
38
|
"publishConfig": {
|
|
46
39
|
"access": "public",
|
|
47
40
|
"provenance": true
|
|
48
41
|
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"tsdown": "^0.21.5"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": "^22.13.0 || >=24"
|
|
47
|
+
},
|
|
49
48
|
"scripts": {
|
|
50
49
|
"build": "tsdown",
|
|
51
|
-
"lint": "
|
|
50
|
+
"lint": "oxlint",
|
|
52
51
|
"test": "vitest run",
|
|
53
52
|
"typecheck": "tsc --noEmit"
|
|
54
53
|
}
|