react-obsidian 0.0.13 → 0.0.14
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 +49 -6
- package/babel.config.js +3 -2
- package/dist/src/decorators/Singleton.d.ts +1 -1
- package/dist/src/decorators/Singleton.d.ts.map +1 -1
- package/dist/src/decorators/inject/Inject.d.ts +2 -0
- package/dist/src/decorators/inject/Inject.d.ts.map +1 -0
- package/dist/src/decorators/inject/Inject.js +21 -0
- package/dist/src/decorators/inject/Inject.js.map +1 -0
- package/dist/src/decorators/inject/Injectable.d.ts +4 -0
- package/dist/src/decorators/inject/Injectable.d.ts.map +1 -0
- package/dist/src/decorators/inject/Injectable.js +13 -0
- package/dist/src/decorators/inject/Injectable.js.map +1 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/injectors/class/ClassInjector.d.ts +12 -0
- package/dist/src/injectors/class/ClassInjector.d.ts.map +1 -0
- package/dist/src/injectors/class/ClassInjector.js +58 -0
- package/dist/src/injectors/class/ClassInjector.js.map +1 -0
- package/dist/src/injectors/class/ConstructorArgs.d.ts +8 -0
- package/dist/src/injectors/class/ConstructorArgs.d.ts.map +1 -0
- package/dist/src/injectors/class/ConstructorArgs.js +25 -0
- package/dist/src/injectors/class/ConstructorArgs.js.map +1 -0
- package/dist/src/injectors/class/InjectionMetadata.d.ts +10 -0
- package/dist/src/injectors/class/InjectionMetadata.d.ts.map +1 -0
- package/dist/src/injectors/class/InjectionMetadata.js +28 -0
- package/dist/src/injectors/class/InjectionMetadata.js.map +1 -0
- package/dist/src/injectors/components/ComponentInjector.d.ts +0 -1
- package/dist/src/injectors/components/ComponentInjector.d.ts.map +1 -1
- package/dist/src/injectors/components/ComponentInjector.js +0 -1
- package/dist/src/injectors/components/ComponentInjector.js.map +1 -1
- package/dist/test/integration/fixtures/MainGraph.d.ts +1 -0
- package/dist/test/integration/fixtures/MainGraph.d.ts.map +1 -1
- package/dist/test/integration/fixtures/MainGraph.js +10 -0
- package/dist/test/integration/fixtures/MainGraph.js.map +1 -1
- package/dist/test/integration/fixtures/injectedValues.d.ts +1 -0
- package/dist/test/integration/fixtures/injectedValues.d.ts.map +1 -1
- package/dist/test/integration/fixtures/injectedValues.js +1 -0
- package/dist/test/integration/fixtures/injectedValues.js.map +1 -1
- package/dist/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/helpers/index.d.ts +3 -2
- package/dist/transformers/babel-plugin-obsidian/helpers/index.d.ts.map +1 -0
- package/dist/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/helpers/index.js +22 -4
- package/dist/transformers/babel-plugin-obsidian/helpers/index.js.map +1 -0
- package/dist/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/index.d.ts +0 -0
- package/dist/transformers/babel-plugin-obsidian/index.d.ts.map +1 -0
- package/dist/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/index.js +27 -1
- package/dist/transformers/babel-plugin-obsidian/index.js.map +1 -0
- package/example/babel.config.js +1 -1
- package/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/jest.config.js +4 -0
- package/jest.setup-after-env.js +1 -0
- package/jest.setup.ts +1 -0
- package/package.json +5 -3
- package/src/decorators/Singleton.ts +1 -1
- package/src/decorators/inject/Inject.ts +17 -0
- package/src/decorators/inject/Injectable.ts +8 -0
- package/src/index.ts +2 -2
- package/src/injectors/class/ClassInjector.ts +49 -0
- package/src/injectors/class/ConstructorArgs.ts +20 -0
- package/src/injectors/class/InjectionMetadata.ts +32 -0
- package/src/injectors/components/ComponentInjector.tsx +0 -1
- package/testkit/index.ts +1 -1
- package/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/helpers/index.ts +26 -2
- package/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/index.ts +37 -3
- package/dist/src/decorators/injectClass.d.ts +0 -7
- package/dist/src/decorators/injectClass.d.ts.map +0 -1
- package/dist/src/decorators/injectClass.js +0 -34
- package/dist/src/decorators/injectClass.js.map +0 -1
- package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.d.ts.map +0 -1
- package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.js.map +0 -1
- package/dist/transformers/babel-plugin-obsidian-provide/index.d.ts.map +0 -1
- package/dist/transformers/babel-plugin-obsidian-provide/index.js.map +0 -1
- package/src/decorators/injectClass.ts +0 -28
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ React Obsidian is guided by the principles of the Dependency Injection pattern,
|
|
|
15
15
|
npm install react-obsidian
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
See the #Prerequisites section for additional requirements.
|
|
18
|
+
See the [#Prerequisites](https://github.com/wix-incubator/react-obsidian#prerequisites) section for additional requirements.
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
@@ -32,7 +32,7 @@ Notice how the biLogger function receives an `httpClient` as an argument. This m
|
|
|
32
32
|
|
|
33
33
|
``` typescript
|
|
34
34
|
@Singleton() @Graph()
|
|
35
|
-
|
|
35
|
+
class ApplicationGraph extends ObjectGraph {
|
|
36
36
|
@Provides()
|
|
37
37
|
httpClient(): HttpClient {
|
|
38
38
|
return new HttpClient();
|
|
@@ -97,8 +97,9 @@ const Component = () => (
|
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
### Class injection
|
|
100
|
-
Obsidian supports
|
|
100
|
+
Obsidian supports injecting both class properties and constructor arguments.
|
|
101
101
|
|
|
102
|
+
#### Injecting properties
|
|
102
103
|
```typescript
|
|
103
104
|
@Injectable(ApplicationGraph)
|
|
104
105
|
class ButtonController {
|
|
@@ -110,6 +111,25 @@ class ButtonController {
|
|
|
110
111
|
}
|
|
111
112
|
```
|
|
112
113
|
|
|
114
|
+
#### Injecting constructor arguments
|
|
115
|
+
```typescript
|
|
116
|
+
@Injectable(ApplicationGraph)
|
|
117
|
+
class Presenter {
|
|
118
|
+
constructor(@Inject() public biLogger: BiLogger) { }
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
TypeScript's compiler won't let you construct the class without providing the argument `anotherString` as it's not optional.
|
|
123
|
+
If you want to be able to instantiate the class yourself without providing arguments, you'll also need to declare a constructor overload that receives optional arguments.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
@Injectable(ApplicationGraph)
|
|
127
|
+
class Presenter {
|
|
128
|
+
constructor(biLogger?: BiLogger);
|
|
129
|
+
constructor(@Inject() public biLogger: BiLogger) { }
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
113
133
|
### Obtaining dependencies from a graph
|
|
114
134
|
Dependencies can also be obtained by accessing the graph that provides them.
|
|
115
135
|
|
|
@@ -120,6 +140,24 @@ Obsidian.obtain(ApplicationGraph).biLogger();
|
|
|
120
140
|
> Note: While the function that provides the `biLogger` accepts an argument of type `HttpClient`, when obtaining dependencies directly from the graph, we don't provide dependencies ourselves as they are resolved by Obsidian.
|
|
121
141
|
|
|
122
142
|
## Advance usage
|
|
143
|
+
### Accessing props in graphs
|
|
144
|
+
If a graph is instantiated in order to inject a component, then it receives the component's props in the constructor.
|
|
145
|
+
```typescript
|
|
146
|
+
@Graph()
|
|
147
|
+
class ProfileScreenGraph extends ObjectGraph<ProfileScreenProps> {
|
|
148
|
+
private profile: UserProfile;
|
|
149
|
+
|
|
150
|
+
constructor(props: ProfileScreenProps) {
|
|
151
|
+
super(props);
|
|
152
|
+
this.profile = props.profile;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Provides()
|
|
156
|
+
profileFetcher(): ProfileFetcher {
|
|
157
|
+
return new ProfileFetcher(this.profile);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
123
161
|
### Singleton graphs and providers
|
|
124
162
|
Graphs and Providers can be marked as singletons with the `@Singleton` decorator. When a graph is marked as a singleton, when an instance of that graph is requested, Obsidian will reuse the existing instance. Graphs that are not annotated with the `@Singleton` decorator will be instantiated each time they are needed for injection.
|
|
125
163
|
|
|
@@ -208,11 +246,16 @@ Obsidian relies on reflection to resolve dependencies. Production code is typica
|
|
|
208
246
|
Add the transformer to the list of plugins in your `.babel` file.
|
|
209
247
|
```js
|
|
210
248
|
module.exports = {
|
|
211
|
-
presets: [
|
|
249
|
+
presets: [
|
|
250
|
+
'module:metro-react-native-babel-preset',
|
|
251
|
+
['@babel/preset-typescript', {'onlyRemoveTypeImports': true}]
|
|
252
|
+
],
|
|
212
253
|
plugins: [
|
|
254
|
+
react-obsidian/dist/transformers/babel-plugin-obsidian,
|
|
213
255
|
['@babel/plugin-proposal-decorators', {legacy: true}],
|
|
214
|
-
|
|
215
|
-
|
|
256
|
+
['@babel/plugin-proposal-class-properties', { legacy: true }],
|
|
257
|
+
'babel-plugin-parameter-decorator'
|
|
258
|
+
]
|
|
216
259
|
};
|
|
217
260
|
```
|
|
218
261
|
|
package/babel.config.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
presets: [
|
|
3
3
|
['@babel/preset-env', { targets: { node: 'current' } }],
|
|
4
|
-
'@babel/preset-typescript',
|
|
4
|
+
['@babel/preset-typescript', {'onlyRemoveTypeImports': true}],
|
|
5
5
|
'@babel/preset-react',
|
|
6
6
|
],
|
|
7
7
|
plugins: [
|
|
8
|
-
`${__dirname}/dist/transformers/babel-plugin-obsidian
|
|
8
|
+
`${__dirname}/dist/transformers/babel-plugin-obsidian`,
|
|
9
9
|
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
10
10
|
['@babel/plugin-proposal-class-properties', { legacy: true }],
|
|
11
|
+
'babel-plugin-parameter-decorator'
|
|
11
12
|
],
|
|
12
13
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constructable } from '
|
|
1
|
+
import { Constructable } from '../types';
|
|
2
2
|
import { ObjectGraph } from '../graph/ObjectGraph';
|
|
3
3
|
export declare function Singleton(): (constructorOrGraph: Constructable<ObjectGraph> | ObjectGraph, _property?: string | undefined, descriptor?: PropertyDescriptor | undefined) => any;
|
|
4
4
|
//# sourceMappingURL=Singleton.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Singleton.d.ts","sourceRoot":"","sources":["../../../src/decorators/Singleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Singleton.d.ts","sourceRoot":"","sources":["../../../src/decorators/Singleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,wBAAgB,SAAS,yBAED,cAAc,WAAW,CAAC,GAAG,WAAW,kFAG3D,GAAG,CAKP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Inject.d.ts","sourceRoot":"","sources":["../../../../src/decorators/inject/Inject.ts"],"names":[],"mappings":"AAGA,wBAAgB,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,YAExB,MAAM,GAAG,GAAG,iHAWvB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Inject = void 0;
|
|
7
|
+
var lodash_1 = require("lodash");
|
|
8
|
+
var InjectionMetadata_1 = __importDefault(require("../../injectors/class/InjectionMetadata"));
|
|
9
|
+
function Inject(name) {
|
|
10
|
+
return function (target, propertyKey, indexOrPropertyDescriptor) {
|
|
11
|
+
var metadata = new InjectionMetadata_1.default();
|
|
12
|
+
if (name && (0, lodash_1.isNumber)(indexOrPropertyDescriptor)) {
|
|
13
|
+
metadata.saveConstructorParamMetadata(target, name, indexOrPropertyDescriptor);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
metadata.savePropertyMetadata(target.constructor, propertyKey);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.Inject = Inject;
|
|
21
|
+
//# sourceMappingURL=Inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Inject.js","sourceRoot":"","sources":["../../../../src/decorators/inject/Inject.ts"],"names":[],"mappings":";;;;;;AAAA,iCAAkC;AAClC,8FAAwE;AAExE,SAAgB,MAAM,CAAC,IAAa;IAClC,OAAO,UACL,MAAoB,EACpB,WAAoB,EACpB,yBAAuD;QAEvD,IAAM,QAAQ,GAAG,IAAI,2BAAiB,EAAE,CAAC;QACzC,IAAI,IAAI,IAAI,IAAA,iBAAQ,EAAC,yBAAyB,CAAC,EAAE;YAC/C,QAAQ,CAAC,4BAA4B,CAAC,MAAM,EAAE,IAAK,EAAE,yBAAyB,CAAC,CAAC;SACjF;aAAM;YACL,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,WAAW,EAAE,WAAY,CAAC,CAAC;SACjE;IACH,CAAC,CAAC;AACJ,CAAC;AAbD,wBAaC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Injectable.d.ts","sourceRoot":"","sources":["../../../../src/decorators/inject/Injectable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI1C,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,GAAG,CAE3D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Injectable = void 0;
|
|
7
|
+
var GraphRegistry_1 = __importDefault(require("../../graph/registry/GraphRegistry"));
|
|
8
|
+
var ClassInjector_1 = __importDefault(require("../../injectors/class/ClassInjector"));
|
|
9
|
+
function Injectable(Graph) {
|
|
10
|
+
return new ClassInjector_1.default(GraphRegistry_1.default).inject(Graph);
|
|
11
|
+
}
|
|
12
|
+
exports.Injectable = Injectable;
|
|
13
|
+
//# sourceMappingURL=Injectable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Injectable.js","sourceRoot":"","sources":["../../../../src/decorators/inject/Injectable.ts"],"names":[],"mappings":";;;;;;AAEA,qFAA+D;AAC/D,sFAAgE;AAEhE,SAAgB,UAAU,CAAC,KAA2B;IACpD,OAAO,IAAI,uBAAa,CAAC,uBAAa,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAFD,gCAEC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export { Singleton } from './decorators/Singleton';
|
|
|
8
8
|
export { ObjectGraph } from './graph/ObjectGraph';
|
|
9
9
|
export { Graph as IGraph } from './graph/Graph';
|
|
10
10
|
export { Provides } from './decorators/provides/Provides';
|
|
11
|
-
export { Injectable } from './decorators/
|
|
12
|
-
export { Inject } from './decorators/
|
|
11
|
+
export { Injectable } from './decorators/inject/Injectable';
|
|
12
|
+
export { Inject } from './decorators/inject/Inject';
|
|
13
13
|
export { GraphMiddleware } from './graph/registry/GraphMiddleware';
|
|
14
14
|
export { GraphResolveChain as ResolveChain } from './graph/registry/GraphResolveChain';
|
|
15
15
|
export declare const Obsidian: _Obsidian;
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC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AAoC,CAAC;AACvF,eAAO,MAAM,QAAQ,WAAkB,CAAC;AAGxC,eAAO,MAAM,eAAe,iDAEnB,cAAc,YAAY,CAAC,wCACQ,CAAC;AAG7C,eAAO,MAAM,UAAU,sDAEd,cAAc,YAAY,CAAC,iDACC,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -26,10 +26,10 @@ var ObjectGraph_1 = require("./graph/ObjectGraph");
|
|
|
26
26
|
Object.defineProperty(exports, "ObjectGraph", { enumerable: true, get: function () { return ObjectGraph_1.ObjectGraph; } });
|
|
27
27
|
var Provides_1 = require("./decorators/provides/Provides");
|
|
28
28
|
Object.defineProperty(exports, "Provides", { enumerable: true, get: function () { return Provides_1.Provides; } });
|
|
29
|
-
var
|
|
30
|
-
Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return
|
|
31
|
-
var
|
|
32
|
-
Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return
|
|
29
|
+
var Injectable_1 = require("./decorators/inject/Injectable");
|
|
30
|
+
Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return Injectable_1.Injectable; } });
|
|
31
|
+
var Inject_1 = require("./decorators/inject/Inject");
|
|
32
|
+
Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return Inject_1.Inject; } });
|
|
33
33
|
var GraphMiddleware_1 = require("./graph/registry/GraphMiddleware");
|
|
34
34
|
Object.defineProperty(exports, "GraphMiddleware", { enumerable: true, get: function () { return GraphMiddleware_1.GraphMiddleware; } });
|
|
35
35
|
exports.Obsidian = new Obsidian_1.default();
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,+FAAyE;AACzE,wDAAmC;AACnC,gFAA0D;AAG1D,0CAAwB;AAExB,4CAA2C;AAAlC,8FAAA,KAAK,OAAA;AACd,oDAAmD;AAA1C,sGAAA,SAAS,OAAA;AAClB,mDAAkD;AAAzC,0GAAA,WAAW,OAAA;AAEpB,2DAA0D;AAAjD,oGAAA,QAAQ,OAAA;AACjB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,+FAAyE;AACzE,wDAAmC;AACnC,gFAA0D;AAG1D,0CAAwB;AAExB,4CAA2C;AAAlC,8FAAA,KAAK,OAAA;AACd,oDAAmD;AAA1C,sGAAA,SAAS,OAAA;AAClB,mDAAkD;AAAzC,0GAAA,WAAW,OAAA;AAEpB,2DAA0D;AAAjD,oGAAA,QAAQ,OAAA;AACjB,6DAA4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,qDAAoD;AAA3C,gGAAA,MAAM,OAAA;AACf,oEAAmE;AAA1D,kHAAA,eAAe,OAAA;AAEX,QAAA,QAAQ,GAAG,IAAI,kBAAS,EAAE,CAAC;AAExC,IAAM,iBAAiB,GAAG,IAAI,2BAAiB,EAAE,CAAC;AAC3C,IAAM,eAAe,GAAG,UAC7B,MAAkC,EAClC,KAAkC,IAC/B,OAAA,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAvC,CAAuC,CAAC;AAHhC,QAAA,eAAe,mBAGiB;AAE7C,IAAM,YAAY,GAAG,IAAI,sBAAY,EAAE,CAAC;AACjC,IAAM,UAAU,GAAG,UACxB,IAA4B,EAC5B,KAAkC,IAC/B,OAAA,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAhC,CAAgC,CAAC;AAHzB,QAAA,UAAU,cAGe"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Constructable } from '../../types';
|
|
2
|
+
import { GraphRegistry } from '../../graph/registry/GraphRegistry';
|
|
3
|
+
import { Graph } from '../../graph/Graph';
|
|
4
|
+
import InjectionMetadata from './InjectionMetadata';
|
|
5
|
+
export default class ClassInjector {
|
|
6
|
+
private graphRegistry;
|
|
7
|
+
private injectionMetadata;
|
|
8
|
+
constructor(graphRegistry: GraphRegistry, injectionMetadata?: InjectionMetadata);
|
|
9
|
+
inject(Graph: Constructable<Graph>): (Target: Constructable<any>) => any;
|
|
10
|
+
private createProxyHandler;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ClassInjector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/class/ClassInjector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,aAAa;IAE9B,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,iBAAiB;gBADjB,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,iBAA2C;IAGxE,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,YAChB,cAAc,GAAG,CAAC;IAKpC,OAAO,CAAC,kBAAkB;CA+B3B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
var InjectionMetadata_1 = __importDefault(require("./InjectionMetadata"));
|
|
16
|
+
var ClassInjector = /** @class */ (function () {
|
|
17
|
+
function ClassInjector(graphRegistry, injectionMetadata) {
|
|
18
|
+
if (injectionMetadata === void 0) { injectionMetadata = new InjectionMetadata_1.default(); }
|
|
19
|
+
this.graphRegistry = graphRegistry;
|
|
20
|
+
this.injectionMetadata = injectionMetadata;
|
|
21
|
+
}
|
|
22
|
+
ClassInjector.prototype.inject = function (Graph) {
|
|
23
|
+
var _this = this;
|
|
24
|
+
return function (Target) {
|
|
25
|
+
return new Proxy(Target, _this.createProxyHandler(Graph, _this.graphRegistry, _this.injectionMetadata));
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
ClassInjector.prototype.createProxyHandler = function (Graph, graphRegistry, injectionMetadata) {
|
|
29
|
+
return new /** @class */ (function () {
|
|
30
|
+
function Handler() {
|
|
31
|
+
}
|
|
32
|
+
Handler.prototype.construct = function (target, args, newTarget) {
|
|
33
|
+
var graph = graphRegistry.resolve(Graph);
|
|
34
|
+
var argsToInject = this.injectConstructorArgs(args, graph, target);
|
|
35
|
+
var createdObject = Reflect.construct(target, argsToInject, newTarget);
|
|
36
|
+
this.injectProperties(target, createdObject, graph);
|
|
37
|
+
return createdObject;
|
|
38
|
+
};
|
|
39
|
+
Handler.prototype.injectConstructorArgs = function (args, graph, target) {
|
|
40
|
+
var argsToInject = injectionMetadata.getConstructorArgsToInject(target);
|
|
41
|
+
if (!argsToInject.hasArgs())
|
|
42
|
+
return args;
|
|
43
|
+
return __spreadArray(__spreadArray([], args, true), new Array(Math.abs(args.length - argsToInject.size())), true).map(function (value, idx) {
|
|
44
|
+
return value !== null && value !== void 0 ? value : graph.retrieve(argsToInject.getProperty(idx));
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
Handler.prototype.injectProperties = function (target, createdObject, graph) {
|
|
48
|
+
injectionMetadata.getPropertiesToInject(target).forEach(function (key) {
|
|
49
|
+
Reflect.set(createdObject, key, graph.retrieve(key));
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
return Handler;
|
|
53
|
+
}())();
|
|
54
|
+
};
|
|
55
|
+
return ClassInjector;
|
|
56
|
+
}());
|
|
57
|
+
exports.default = ClassInjector;
|
|
58
|
+
//# sourceMappingURL=ClassInjector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassInjector.js","sourceRoot":"","sources":["../../../../src/injectors/class/ClassInjector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,0EAAoD;AAEpD;IACE,uBACU,aAA4B,EAC5B,iBAA8D;QAA9D,kCAAA,EAAA,wBAA2C,2BAAiB,EAAE;QAD9D,kBAAa,GAAb,aAAa,CAAe;QAC5B,sBAAiB,GAAjB,iBAAiB,CAA6C;IACrE,CAAC;IAEJ,8BAAM,GAAN,UAAO,KAA2B;QAAlC,iBAIC;QAHC,OAAO,UAAC,MAA0B;YAChC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,KAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAI,CAAC,aAAa,EAAE,KAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACvG,CAAC,CAAC;IACJ,CAAC;IAEO,0CAAkB,GAA1B,UACE,KAA2B,EAC3B,aAA4B,EAC5B,iBAAoC;QAEpC,OAAO;YAAI;YAwBX,CAAC;YAvBC,2BAAS,GAAT,UAAU,MAAW,EAAE,IAAW,EAAE,SAAmB;gBACrD,IAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAE3C,IAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;gBACrE,IAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;gBACzE,IAAI,CAAC,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I,IAAI,MAAM;IAId,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAIpC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;CAIhC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConstructorArgs = void 0;
|
|
4
|
+
var ConstructorArgs = /** @class */ (function () {
|
|
5
|
+
function ConstructorArgs() {
|
|
6
|
+
this.args = new Array();
|
|
7
|
+
}
|
|
8
|
+
ConstructorArgs.prototype.hasArgs = function () {
|
|
9
|
+
return this.args.length > 0;
|
|
10
|
+
};
|
|
11
|
+
ConstructorArgs.prototype.size = function () {
|
|
12
|
+
return this.args.length;
|
|
13
|
+
};
|
|
14
|
+
ConstructorArgs.prototype.add = function (paramName, index) {
|
|
15
|
+
this.args.push([paramName, index]);
|
|
16
|
+
};
|
|
17
|
+
ConstructorArgs.prototype.getProperty = function (index) {
|
|
18
|
+
if (this.args.length <= index)
|
|
19
|
+
throw new Error('IOOB while trying to get constructor args to inject');
|
|
20
|
+
return this.args[index][0];
|
|
21
|
+
};
|
|
22
|
+
return ConstructorArgs;
|
|
23
|
+
}());
|
|
24
|
+
exports.ConstructorArgs = ConstructorArgs;
|
|
25
|
+
//# sourceMappingURL=ConstructorArgs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConstructorArgs.js","sourceRoot":"","sources":["../../../../src/injectors/class/ConstructorArgs.ts"],"names":[],"mappings":";;;AAAA;IAAA;QACmB,SAAI,GAAG,IAAI,KAAK,EAAoB,CAAC;IAkBxD,CAAC;IAhBC,iCAAO,GAAP;QACE,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,8BAAI,GAAJ;QACE,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1B,CAAC;IAED,6BAAG,GAAH,UAAI,SAAiB,EAAE,KAAa;QAClC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,qCAAW,GAAX,UAAY,KAAa;QACvB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACtG,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IACH,sBAAC;AAAD,CAAC,AAnBD,IAmBC;AAnBY,0CAAe"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConstructorArgs } from './ConstructorArgs';
|
|
2
|
+
export default class InjectionMetadata {
|
|
3
|
+
private readonly injectionMetadataKey;
|
|
4
|
+
private readonly injectedConstructorArgsKey;
|
|
5
|
+
getConstructorArgsToInject(target: any): ConstructorArgs;
|
|
6
|
+
getPropertiesToInject(target: any): Set<string>;
|
|
7
|
+
saveConstructorParamMetadata(target: any, paramName: string, index: number): void;
|
|
8
|
+
savePropertyMetadata(target: any, property: string): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=InjectionMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InjectionMetadata.d.ts","sourceRoot":"","sources":["../../../../src/injectors/class/InjectionMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAuB;IAC5D,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAgC;IAE3E,0BAA0B,CAAC,MAAM,EAAE,GAAG,GAAG,eAAe;IAIxD,qBAAqB,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;IAI/C,4BAA4B,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAU1E,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM;CAOnD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var ConstructorArgs_1 = require("./ConstructorArgs");
|
|
4
|
+
var InjectionMetadata = /** @class */ (function () {
|
|
5
|
+
function InjectionMetadata() {
|
|
6
|
+
this.injectionMetadataKey = 'injectionMetadata';
|
|
7
|
+
this.injectedConstructorArgsKey = 'injectedConstructorArgsKey';
|
|
8
|
+
}
|
|
9
|
+
InjectionMetadata.prototype.getConstructorArgsToInject = function (target) {
|
|
10
|
+
var _a;
|
|
11
|
+
return (_a = Reflect.getMetadata(this.injectedConstructorArgsKey, target)) !== null && _a !== void 0 ? _a : new ConstructorArgs_1.ConstructorArgs();
|
|
12
|
+
};
|
|
13
|
+
InjectionMetadata.prototype.getPropertiesToInject = function (target) {
|
|
14
|
+
var _a;
|
|
15
|
+
return (_a = Reflect.getMetadata(this.injectionMetadataKey, target)) !== null && _a !== void 0 ? _a : new Set();
|
|
16
|
+
};
|
|
17
|
+
InjectionMetadata.prototype.saveConstructorParamMetadata = function (target, paramName, index) {
|
|
18
|
+
var argsToInject = this.getConstructorArgsToInject(target);
|
|
19
|
+
argsToInject.add(paramName, index);
|
|
20
|
+
Reflect.defineMetadata(this.injectedConstructorArgsKey, argsToInject, target);
|
|
21
|
+
};
|
|
22
|
+
InjectionMetadata.prototype.savePropertyMetadata = function (target, property) {
|
|
23
|
+
Reflect.defineMetadata(this.injectionMetadataKey, this.getPropertiesToInject(target).add(property), target);
|
|
24
|
+
};
|
|
25
|
+
return InjectionMetadata;
|
|
26
|
+
}());
|
|
27
|
+
exports.default = InjectionMetadata;
|
|
28
|
+
//# sourceMappingURL=InjectionMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InjectionMetadata.js","sourceRoot":"","sources":["../../../../src/injectors/class/InjectionMetadata.ts"],"names":[],"mappings":";;AAAA,qDAAoD;AAEpD;IAAA;QACmB,yBAAoB,GAAG,mBAAmB,CAAC;QAC3C,+BAA0B,GAAG,4BAA4B,CAAC;IA2B7E,CAAC;IAzBC,sDAA0B,GAA1B,UAA2B,MAAW;;QACpC,OAAO,MAAA,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,0BAA0B,EAAE,MAAM,CAAC,mCAAI,IAAI,iCAAe,EAAE,CAAC;IAC/F,CAAC;IAED,iDAAqB,GAArB,UAAsB,MAAW;;QAC/B,OAAO,MAAA,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,mCAAI,IAAI,GAAG,EAAE,CAAC;IAC7E,CAAC;IAED,wDAA4B,GAA5B,UAA6B,MAAW,EAAE,SAAiB,EAAE,KAAa;QACxE,IAAM,YAAY,GAAG,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC;QAC7D,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACnC,OAAO,CAAC,cAAc,CACpB,IAAI,CAAC,0BAA0B,EAC/B,YAAY,EACZ,MAAM,CACP,CAAC;IACJ,CAAC;IAED,gDAAoB,GAApB,UAAqB,MAAW,EAAE,QAAgB;QAChD,OAAO,CAAC,cAAc,CACpB,IAAI,CAAC,oBAAoB,EACzB,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAChD,MAAM,CACP,CAAC;IACJ,CAAC;IACH,wBAAC;AAAD,CAAC,AA7BD,IA6BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,
|
|
1
|
+
{"version":3,"file":"ComponentInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,MAAM,CAAC,CAAC,EACN,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAClC,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,GAChC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAMtC,OAAO,CAAC,aAAa;CAUtB"}
|
|
@@ -24,7 +24,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
var react_1 = __importStar(require("react"));
|
|
26
26
|
var hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics"));
|
|
27
|
-
require("reflect-metadata");
|
|
28
27
|
var PropsInjector_1 = __importDefault(require("./PropsInjector"));
|
|
29
28
|
var useGraph_1 = __importDefault(require("./useGraph"));
|
|
30
29
|
var ComponentInjector = /** @class */ (function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentInjector.js","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAwC;AACxC,oFAA2D;
|
|
1
|
+
{"version":3,"file":"ComponentInjector.js","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAwC;AACxC,oFAA2D;AAE3D,kEAA4C;AAC5C,wDAAkC;AAGlC;IAAA;IAoBA,CAAC;IAnBC,kCAAM,GAAN,UACE,MAAkC,EAClC,KAAiC;QAEjC,IAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClD,IAAA,iCAAoB,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,yCAAa,GAArB,UACE,MAAkC,EAClC,KAAiC;QAEjC,OAAO,UAAC,WAAuB;YAC7B,IAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;YACpC,IAAA,YAAY,GAAI,IAAA,gBAAQ,EAAC,IAAI,uBAAa,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAA1D,CAA2D;YAC9E,OAAO,8DAAG,MAAM,CAAC,YAA4B,CAAC,CAAI,CAAC;QACrD,CAAC,CAAC;IACJ,CAAC;IACH,wBAAC;AAAD,CAAC,AApBD,IAoBC"}
|
|
@@ -2,5 +2,6 @@ import { ObjectGraph } from '../../../src';
|
|
|
2
2
|
import StringProvider from './StringProvider';
|
|
3
3
|
export default class MainGraph extends ObjectGraph {
|
|
4
4
|
someString(stringProvider: StringProvider): string;
|
|
5
|
+
anotherString(): string;
|
|
5
6
|
}
|
|
6
7
|
//# sourceMappingURL=MainGraph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MainGraph.d.ts","sourceRoot":"","sources":["../../../../test/integration/fixtures/MainGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,WAAW,EAAY,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"MainGraph.d.ts","sourceRoot":"","sources":["../../../../test/integration/fixtures/MainGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,WAAW,EAAY,MAAM,cAAc,CAAC;AAE5D,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAI9C,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,WAAW;IAEhD,UAAU,CAAC,cAAc,EAAE,cAAc,GAAG,MAAM;IAKlD,aAAa,IAAI,MAAM;CAGxB"}
|
|
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
var src_1 = require("../../../src");
|
|
31
|
+
var injectedValues_1 = __importDefault(require("./injectedValues"));
|
|
31
32
|
var StringProvider_1 = __importDefault(require("./StringProvider"));
|
|
32
33
|
var Subgraph_1 = __importDefault(require("./Subgraph"));
|
|
33
34
|
var MainGraph = /** @class */ (function (_super) {
|
|
@@ -38,12 +39,21 @@ var MainGraph = /** @class */ (function (_super) {
|
|
|
38
39
|
MainGraph.prototype.someString = function (stringProvider) {
|
|
39
40
|
return stringProvider.theString;
|
|
40
41
|
};
|
|
42
|
+
MainGraph.prototype.anotherString = function () {
|
|
43
|
+
return injectedValues_1.default.anotherString;
|
|
44
|
+
};
|
|
41
45
|
__decorate([
|
|
42
46
|
(0, src_1.Provides)(),
|
|
43
47
|
__metadata("design:type", Function),
|
|
44
48
|
__metadata("design:paramtypes", [StringProvider_1.default]),
|
|
45
49
|
__metadata("design:returntype", String)
|
|
46
50
|
], MainGraph.prototype, "someString", null);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, src_1.Provides)(),
|
|
53
|
+
__metadata("design:type", Function),
|
|
54
|
+
__metadata("design:paramtypes", []),
|
|
55
|
+
__metadata("design:returntype", String)
|
|
56
|
+
], MainGraph.prototype, "anotherString", null);
|
|
47
57
|
MainGraph = __decorate([
|
|
48
58
|
(0, src_1.Graph)({ subgraphs: [Subgraph_1.default] })
|
|
49
59
|
], MainGraph);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MainGraph.js","sourceRoot":"","sources":["../../../../test/integration/fixtures/MainGraph.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA4D;AAC5D,oEAA8C;AAC9C,wDAAkC;AAGlC;IAAuC,6BAAW;IAAlD;;
|
|
1
|
+
{"version":3,"file":"MainGraph.js","sourceRoot":"","sources":["../../../../test/integration/fixtures/MainGraph.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA4D;AAC5D,oEAA8C;AAC9C,oEAA8C;AAC9C,wDAAkC;AAGlC;IAAuC,6BAAW;IAAlD;;IAUA,CAAC;IARC,8BAAU,GAAV,UAAW,cAA8B;QACvC,OAAO,cAAc,CAAC,SAAS,CAAC;IAClC,CAAC;IAGD,iCAAa,GAAb;QACE,OAAO,wBAAc,CAAC,aAAa,CAAC;IACtC,CAAC;IAPD;QADC,IAAA,cAAQ,GAAE;;yCACgB,wBAAc;;+CAExC;IAGD;QADC,IAAA,cAAQ,GAAE;;;;kDAGV;IATkB,SAAS;QAD7B,IAAA,WAAK,EAAC,EAAE,SAAS,EAAE,CAAC,kBAAQ,CAAC,EAAE,CAAC;OACZ,SAAS,CAU7B;IAAD,gBAAC;CAAA,AAVD,CAAuC,iBAAW,GAUjD;kBAVoB,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectedValues.d.ts","sourceRoot":"","sources":["../../../../test/integration/fixtures/injectedValues.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"injectedValues.d.ts","sourceRoot":"","sources":["../../../../test/integration/fixtures/injectedValues.ts"],"names":[],"mappings":";;;;;AAAA,wBAIE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectedValues.js","sourceRoot":"","sources":["../../../../test/integration/fixtures/injectedValues.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb,YAAY,EAAE,cAAc;IAC5B,kBAAkB,EAAE,qBAAqB;
|
|
1
|
+
{"version":3,"file":"injectedValues.js","sourceRoot":"","sources":["../../../../test/integration/fixtures/injectedValues.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb,YAAY,EAAE,cAAc;IAC5B,kBAAkB,EAAE,qBAAqB;IACzC,aAAa,EAAE,6BAA6B;CAC7C,CAAC"}
|
package/dist/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/helpers/index.d.ts
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ClassMethod, Decorator, Identifier, ObjectExpression, ObjectPattern } from '@babel/types';
|
|
1
|
+
import { ClassMethod, Decorator, Identifier, ObjectExpression, ObjectPattern, TSParameterProperty } from '@babel/types';
|
|
2
2
|
export declare function providerIsNotNamed(decorator: Decorator): boolean;
|
|
3
3
|
export declare function addNameToProviderArguments(node: ClassMethod, decorator: Decorator): void;
|
|
4
4
|
export declare function getDecoratorArgument(decorator: Decorator): ObjectExpression | undefined;
|
|
5
5
|
export declare function getMethodName(node: ClassMethod): string;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function getDecoratorByName(decorators: Array<Decorator> | undefined | null, decoratorName: string): Decorator | undefined;
|
|
7
7
|
export declare function getDecoratorName(decorator?: Decorator): string | undefined;
|
|
8
8
|
export declare function paramsToDestructuringAssignment(params: (Identifier | any)[]): ObjectPattern;
|
|
9
|
+
export declare function passParamNameAsInjectArgument(node: Identifier | TSParameterProperty, decorator: Decorator): void;
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/helpers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAKtB,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAWhE;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,QAOjF;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAKvF;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAGvD;AAED,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,EAC/C,aAAa,EAAE,MAAM,GACpB,SAAS,GAAG,SAAS,CAEvB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAE1E;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,EAAE,GAAG,aAAa,CAI3F;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,UAAU,GAAG,mBAAmB,EAAE,SAAS,EAAE,SAAS,QAMzG"}
|
package/dist/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/helpers/index.js
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.paramsToDestructuringAssignment = exports.getDecoratorName = exports.
|
|
3
|
+
exports.passParamNameAsInjectArgument = exports.paramsToDestructuringAssignment = exports.getDecoratorName = exports.getDecoratorByName = exports.getMethodName = exports.getDecoratorArgument = exports.addNameToProviderArguments = exports.providerIsNotNamed = void 0;
|
|
4
4
|
/* eslint-disable no-param-reassign */
|
|
5
5
|
var core_1 = require("@babel/core");
|
|
6
6
|
var lodash_1 = require("lodash");
|
|
7
|
+
var never = '';
|
|
7
8
|
function providerIsNotNamed(decorator) {
|
|
8
9
|
var argument = getDecoratorArgument(decorator);
|
|
9
10
|
if (core_1.types.isObjectExpression(argument)) {
|
|
@@ -37,10 +38,10 @@ function getMethodName(node) {
|
|
|
37
38
|
throw new Error("Tried to get class name but encountered unexpected key of type: ".concat(node.key.type));
|
|
38
39
|
}
|
|
39
40
|
exports.getMethodName = getMethodName;
|
|
40
|
-
function
|
|
41
|
-
return decorators === null || decorators === void 0 ? void 0 : decorators.find(function (decorator) { return (0, lodash_1.get)(decorator, 'expression.callee.name') ===
|
|
41
|
+
function getDecoratorByName(decorators, decoratorName) {
|
|
42
|
+
return decorators === null || decorators === void 0 ? void 0 : decorators.find(function (decorator) { return (0, lodash_1.get)(decorator, 'expression.callee.name') === decoratorName; });
|
|
42
43
|
}
|
|
43
|
-
exports.
|
|
44
|
+
exports.getDecoratorByName = getDecoratorByName;
|
|
44
45
|
function getDecoratorName(decorator) {
|
|
45
46
|
return (0, lodash_1.get)(decorator, 'expression.callee.name');
|
|
46
47
|
}
|
|
@@ -51,4 +52,21 @@ function paramsToDestructuringAssignment(params) {
|
|
|
51
52
|
.map(function (p) { return core_1.types.objectProperty(core_1.types.identifier(p.name), core_1.types.identifier(p.name)); }));
|
|
52
53
|
}
|
|
53
54
|
exports.paramsToDestructuringAssignment = paramsToDestructuringAssignment;
|
|
55
|
+
function passParamNameAsInjectArgument(node, decorator) {
|
|
56
|
+
if (core_1.types.isCallExpression(decorator.expression)) {
|
|
57
|
+
decorator.expression.arguments = [
|
|
58
|
+
core_1.types.stringLiteral(getIdentifierOrParamName(node)),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.passParamNameAsInjectArgument = passParamNameAsInjectArgument;
|
|
63
|
+
function getIdentifierOrParamName(node) {
|
|
64
|
+
if (core_1.types.isTSParameterProperty(node)) {
|
|
65
|
+
if (core_1.types.isIdentifier(node.parameter)) {
|
|
66
|
+
return node.parameter.name;
|
|
67
|
+
}
|
|
68
|
+
return never;
|
|
69
|
+
}
|
|
70
|
+
return node.name;
|
|
71
|
+
}
|
|
54
72
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/helpers/index.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,oCA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,CAAC,SAAS,GAAG;YAC/B,YAAC,CAAC,aAAa,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;SAChD,CAAC;KACH;AACH,CAAC;AAND,sEAMC;AAED,SAAS,wBAAwB,CAAC,IAAsC;IACtE,IAAI,YAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE;QACjC,IAAI,YAAC,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAClC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC5B;QACD,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC"}
|
package/dist/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/index.d.ts
RENAMED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../transformers/babel-plugin-obsidian/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAsElD,MAAM,CAAC,OAAO,UAAU,MAAM,gDAE7B"}
|
|
@@ -12,14 +12,40 @@ var internalVisitor = {
|
|
|
12
12
|
ClassMethod: {
|
|
13
13
|
enter: function (_a) {
|
|
14
14
|
var node = _a.node;
|
|
15
|
-
var decorator = (0, helpers_1.
|
|
15
|
+
var decorator = (0, helpers_1.getDecoratorByName)(node.decorators, 'Provides');
|
|
16
16
|
if ((0, helpers_1.getDecoratorName)(decorator) === 'Provides') {
|
|
17
17
|
convertProviderParamsToDestructuringAssignment(node);
|
|
18
18
|
saveUnmangledMethodNameInProviderArguments(node, decorator);
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
|
+
Identifier: {
|
|
23
|
+
enter: function (_a) {
|
|
24
|
+
var node = _a.node;
|
|
25
|
+
var decorator = (0, helpers_1.getDecoratorByName)(node.decorators, 'Inject');
|
|
26
|
+
if ((0, helpers_1.getDecoratorName)(decorator) === 'Inject') {
|
|
27
|
+
saveUnmangledParamName(node, decorator);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
TSParameterProperty: {
|
|
32
|
+
enter: function (_a) {
|
|
33
|
+
var node = _a.node;
|
|
34
|
+
var decorator = (0, helpers_1.getDecoratorByName)(node.decorators, 'Inject');
|
|
35
|
+
if ((0, helpers_1.getDecoratorName)(decorator) === 'Inject') {
|
|
36
|
+
saveUnmangledParamName(node, decorator);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
},
|
|
22
40
|
};
|
|
41
|
+
function saveUnmangledParamName(node, decorator) {
|
|
42
|
+
if (injectIsNotNamed(decorator)) {
|
|
43
|
+
(0, helpers_1.passParamNameAsInjectArgument)(node, decorator);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function injectIsNotNamed(decorator) {
|
|
47
|
+
return (0, helpers_1.getDecoratorArgument)(decorator) === undefined;
|
|
48
|
+
}
|
|
23
49
|
function convertProviderParamsToDestructuringAssignment(node) {
|
|
24
50
|
if (node.params.length === 0)
|
|
25
51
|
return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../transformers/babel-plugin-obsidian/index.ts"],"names":[],"mappings":";;AASA,qCAQmB;AAEnB,IAAM,4BAA4B,GAAc;IAC9C,OAAO,EAAE;QACP,OAAO,EAAP,UAAQ,IAAuB;YAC7B,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACjC,CAAC;KACF;CACF,CAAC;AAEF,IAAM,eAAe,GAAG;IACtB,WAAW,EAAE;QACX,KAAK,EAAL,UAAM,EAA+B;gBAA7B,IAAI,UAAA;YACV,IAAM,SAAS,GAAG,IAAA,4BAAkB,EAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YAClE,IAAI,IAAA,0BAAgB,EAAC,SAAS,CAAC,KAAK,UAAU,EAAE;gBAC9C,8CAA8C,CAA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AAI,CAAC,kBAAkB,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,0CAA0C,CAAC,IAAiB,EAAE,SAAoB;IACzF,IAAI,IAAA,4BAAkB,EAAC,SAAS,CAAC,EAAE;QACjC,IAAA,oCAA0B,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC;KAC7C;AACH,CAAC;AAED,SAAwB,MAAM;IAC5B,OAAO,4BAA4B,CAAC;AACtC,CAAC;AAFD,yBAEC"}
|
package/example/babel.config.js
CHANGED
|
@@ -3,6 +3,6 @@ module.exports = {
|
|
|
3
3
|
plugins: [
|
|
4
4
|
['@babel/plugin-proposal-decorators', {legacy: true}],
|
|
5
5
|
['@babel/plugin-proposal-class-properties', {legacy: true}],
|
|
6
|
-
[`${__dirname}/../dist/transformers/babel-plugin-obsidian
|
|
6
|
+
[`${__dirname}/../dist/transformers/babel-plugin-obsidian`],
|
|
7
7
|
],
|
|
8
8
|
};
|
package/jest.config.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('setimmediate');
|
package/jest.setup.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-obsidian",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Dependency injection framework for React and React Native applications",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"directories": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"@babel/plugin-proposal-class-properties": "7.16.x",
|
|
20
20
|
"@babel/plugin-proposal-decorators": "7.16.x",
|
|
21
21
|
"@babel/preset-env": "7.16.x",
|
|
22
|
+
"babel-plugin-parameter-decorator": "1.x.x",
|
|
22
23
|
"@babel/preset-react": "7.16.x",
|
|
23
24
|
"@babel/preset-typescript": "7.16.x",
|
|
24
25
|
"@babel/types": "7.16.x",
|
|
@@ -40,11 +41,12 @@
|
|
|
40
41
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
41
42
|
"eslint-plugin-react": "^7.26.1",
|
|
42
43
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
43
|
-
"jest": "
|
|
44
|
+
"jest": "27.x.x",
|
|
44
45
|
"lodash": "^4.17.21",
|
|
45
46
|
"react": "17.0.2",
|
|
46
47
|
"react-dom": "17.0.2",
|
|
47
|
-
"typescript": "^4.
|
|
48
|
+
"typescript": "^4.5.4",
|
|
49
|
+
"setimmediate": "^1.0.5"
|
|
48
50
|
},
|
|
49
51
|
"scripts": {
|
|
50
52
|
"prepack": "npm run lint && tsc --project tsconfig.prod.json",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isNumber } from 'lodash';
|
|
2
|
+
import InjectionMetadata from '../../injectors/class/InjectionMetadata';
|
|
3
|
+
|
|
4
|
+
export function Inject(name?: string) {
|
|
5
|
+
return (
|
|
6
|
+
target: Object | any,
|
|
7
|
+
propertyKey?: string,
|
|
8
|
+
indexOrPropertyDescriptor?: number | PropertyDescriptor,
|
|
9
|
+
) => {
|
|
10
|
+
const metadata = new InjectionMetadata();
|
|
11
|
+
if (name && isNumber(indexOrPropertyDescriptor)) {
|
|
12
|
+
metadata.saveConstructorParamMetadata(target, name!, indexOrPropertyDescriptor);
|
|
13
|
+
} else {
|
|
14
|
+
metadata.savePropertyMetadata(target.constructor, propertyKey!);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Constructable } from '../../types';
|
|
2
|
+
import { Graph } from '../../graph/Graph';
|
|
3
|
+
import graphRegistry from '../../graph/registry/GraphRegistry';
|
|
4
|
+
import ClassInjector from '../../injectors/class/ClassInjector';
|
|
5
|
+
|
|
6
|
+
export function Injectable(Graph: Constructable<Graph>): any {
|
|
7
|
+
return new ClassInjector(graphRegistry).inject(Graph);
|
|
8
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -12,8 +12,8 @@ export { Singleton } from './decorators/Singleton';
|
|
|
12
12
|
export { ObjectGraph } from './graph/ObjectGraph';
|
|
13
13
|
export { Graph as IGraph } from './graph/Graph';
|
|
14
14
|
export { Provides } from './decorators/provides/Provides';
|
|
15
|
-
export { Injectable } from './decorators/
|
|
16
|
-
export { Inject } from './decorators/
|
|
15
|
+
export { Injectable } from './decorators/inject/Injectable';
|
|
16
|
+
export { Inject } from './decorators/inject/Inject';
|
|
17
17
|
export { GraphMiddleware } from './graph/registry/GraphMiddleware';
|
|
18
18
|
export { GraphResolveChain as ResolveChain } from './graph/registry/GraphResolveChain';
|
|
19
19
|
export const Obsidian = new _Obsidian();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Constructable } from '../../types';
|
|
2
|
+
import { GraphRegistry } from '../../graph/registry/GraphRegistry';
|
|
3
|
+
import { Graph } from '../../graph/Graph';
|
|
4
|
+
import InjectionMetadata from './InjectionMetadata';
|
|
5
|
+
|
|
6
|
+
export default class ClassInjector {
|
|
7
|
+
constructor(
|
|
8
|
+
private graphRegistry: GraphRegistry,
|
|
9
|
+
private injectionMetadata: InjectionMetadata = new InjectionMetadata(),
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
inject(Graph: Constructable<Graph>) {
|
|
13
|
+
return (Target: Constructable<any>) => {
|
|
14
|
+
return new Proxy(Target, this.createProxyHandler(Graph, this.graphRegistry, this.injectionMetadata));
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private createProxyHandler(
|
|
19
|
+
Graph: Constructable<Graph>,
|
|
20
|
+
graphRegistry: GraphRegistry,
|
|
21
|
+
injectionMetadata: InjectionMetadata,
|
|
22
|
+
): ProxyHandler<any> {
|
|
23
|
+
return new class Handler implements ProxyHandler<any> {
|
|
24
|
+
construct(target: any, args: any[], newTarget: Function): any {
|
|
25
|
+
const graph = graphRegistry.resolve(Graph);
|
|
26
|
+
|
|
27
|
+
const argsToInject = this.injectConstructorArgs(args, graph, target);
|
|
28
|
+
const createdObject = Reflect.construct(target, argsToInject, newTarget);
|
|
29
|
+
this.injectProperties(target, createdObject, graph);
|
|
30
|
+
|
|
31
|
+
return createdObject;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private injectConstructorArgs(args: any[], graph: Graph, target: any): any[] {
|
|
35
|
+
const argsToInject = injectionMetadata.getConstructorArgsToInject(target);
|
|
36
|
+
if (!argsToInject.hasArgs()) return args;
|
|
37
|
+
return [...args, ...new Array(Math.abs(args.length - argsToInject.size()))].map((value, idx): any => {
|
|
38
|
+
return value ?? graph.retrieve(argsToInject.getProperty(idx));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private injectProperties(target: any, createdObject: any, graph: Graph) {
|
|
43
|
+
injectionMetadata.getPropertiesToInject(target).forEach((key) => {
|
|
44
|
+
Reflect.set(createdObject, key, graph.retrieve(key));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class ConstructorArgs {
|
|
2
|
+
private readonly args = new Array<[string, number]>();
|
|
3
|
+
|
|
4
|
+
hasArgs(): boolean {
|
|
5
|
+
return this.args.length > 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
size(): number {
|
|
9
|
+
return this.args.length;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
add(paramName: string, index: number) {
|
|
13
|
+
this.args.push([paramName, index]);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getProperty(index: number): any {
|
|
17
|
+
if (this.args.length <= index) throw new Error('IOOB while trying to get constructor args to inject');
|
|
18
|
+
return this.args[index][0];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ConstructorArgs } from './ConstructorArgs';
|
|
2
|
+
|
|
3
|
+
export default class InjectionMetadata {
|
|
4
|
+
private readonly injectionMetadataKey = 'injectionMetadata';
|
|
5
|
+
private readonly injectedConstructorArgsKey = 'injectedConstructorArgsKey';
|
|
6
|
+
|
|
7
|
+
getConstructorArgsToInject(target: any): ConstructorArgs {
|
|
8
|
+
return Reflect.getMetadata(this.injectedConstructorArgsKey, target) ?? new ConstructorArgs();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getPropertiesToInject(target: any): Set<string> {
|
|
12
|
+
return Reflect.getMetadata(this.injectionMetadataKey, target) ?? new Set();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
saveConstructorParamMetadata(target: any, paramName: string, index: number) {
|
|
16
|
+
const argsToInject = this.getConstructorArgsToInject(target);
|
|
17
|
+
argsToInject.add(paramName, index);
|
|
18
|
+
Reflect.defineMetadata(
|
|
19
|
+
this.injectedConstructorArgsKey,
|
|
20
|
+
argsToInject,
|
|
21
|
+
target,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
savePropertyMetadata(target: any, property: string) {
|
|
26
|
+
Reflect.defineMetadata(
|
|
27
|
+
this.injectionMetadataKey,
|
|
28
|
+
this.getPropertiesToInject(target).add(property),
|
|
29
|
+
target,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
3
|
-
import 'reflect-metadata';
|
|
4
3
|
import { ObjectGraph } from '../../graph/ObjectGraph';
|
|
5
4
|
import PropsInjector from './PropsInjector';
|
|
6
5
|
import useGraph from './useGraph';
|
package/testkit/index.ts
CHANGED
package/transformers/{babel-plugin-obsidian-provide → babel-plugin-obsidian}/helpers/index.ts
RENAMED
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
Identifier,
|
|
8
8
|
ObjectExpression,
|
|
9
9
|
ObjectPattern,
|
|
10
|
+
TSParameterProperty,
|
|
10
11
|
} from '@babel/types';
|
|
11
12
|
import { get } from 'lodash';
|
|
12
13
|
|
|
14
|
+
const never = '';
|
|
15
|
+
|
|
13
16
|
export function providerIsNotNamed(decorator: Decorator): boolean {
|
|
14
17
|
const argument = getDecoratorArgument(decorator);
|
|
15
18
|
if (t.isObjectExpression(argument)) {
|
|
@@ -44,8 +47,11 @@ export function getMethodName(node: ClassMethod): string {
|
|
|
44
47
|
throw new Error(`Tried to get class name but encountered unexpected key of type: ${node.key.type}`);
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
export function
|
|
48
|
-
|
|
50
|
+
export function getDecoratorByName(
|
|
51
|
+
decorators: Array<Decorator> | undefined | null,
|
|
52
|
+
decoratorName: string,
|
|
53
|
+
): Decorator | undefined {
|
|
54
|
+
return decorators?.find((decorator) => get(decorator, 'expression.callee.name') === decoratorName);
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
export function getDecoratorName(decorator?: Decorator): string | undefined {
|
|
@@ -57,3 +63,21 @@ export function paramsToDestructuringAssignment(params: (Identifier | any)[]): O
|
|
|
57
63
|
.filter((p) => t.isIdentifier(p))
|
|
58
64
|
.map((p) => t.objectProperty(t.identifier(p.name), t.identifier(p.name))));
|
|
59
65
|
}
|
|
66
|
+
|
|
67
|
+
export function passParamNameAsInjectArgument(node: Identifier | TSParameterProperty, decorator: Decorator) {
|
|
68
|
+
if (t.isCallExpression(decorator.expression)) {
|
|
69
|
+
decorator.expression.arguments = [
|
|
70
|
+
t.stringLiteral(getIdentifierOrParamName(node)),
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getIdentifierOrParamName(node: Identifier | TSParameterProperty): string {
|
|
76
|
+
if (t.isTSParameterProperty(node)) {
|
|
77
|
+
if (t.isIdentifier(node.parameter)) {
|
|
78
|
+
return node.parameter.name;
|
|
79
|
+
}
|
|
80
|
+
return never;
|
|
81
|
+
}
|
|
82
|
+
return node.name;
|
|
83
|
+
}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ClassMethod,
|
|
4
|
+
Identifier,
|
|
5
|
+
Decorator,
|
|
6
|
+
Program,
|
|
7
|
+
TSParameterProperty,
|
|
8
|
+
} from '@babel/types';
|
|
3
9
|
import { NodePath, PluginObj } from '@babel/core';
|
|
4
10
|
import {
|
|
5
11
|
addNameToProviderArguments,
|
|
6
12
|
getDecoratorName,
|
|
7
|
-
|
|
13
|
+
getDecoratorByName,
|
|
8
14
|
paramsToDestructuringAssignment,
|
|
9
15
|
providerIsNotNamed,
|
|
16
|
+
passParamNameAsInjectArgument,
|
|
17
|
+
getDecoratorArgument,
|
|
10
18
|
} from './helpers';
|
|
11
19
|
|
|
12
20
|
const providerArgumentsTransformer: PluginObj = {
|
|
@@ -20,15 +28,41 @@ const providerArgumentsTransformer: PluginObj = {
|
|
|
20
28
|
const internalVisitor = {
|
|
21
29
|
ClassMethod: {
|
|
22
30
|
enter({ node }: NodePath<ClassMethod>) {
|
|
23
|
-
const decorator =
|
|
31
|
+
const decorator = getDecoratorByName(node.decorators, 'Provides');
|
|
24
32
|
if (getDecoratorName(decorator) === 'Provides') {
|
|
25
33
|
convertProviderParamsToDestructuringAssignment(node);
|
|
26
34
|
saveUnmangledMethodNameInProviderArguments(node, decorator!);
|
|
27
35
|
}
|
|
28
36
|
},
|
|
29
37
|
},
|
|
38
|
+
Identifier: {
|
|
39
|
+
enter({ node }: NodePath<Identifier>) {
|
|
40
|
+
const decorator = getDecoratorByName(node.decorators, 'Inject');
|
|
41
|
+
if (getDecoratorName(decorator) === 'Inject') {
|
|
42
|
+
saveUnmangledParamName(node, decorator!);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
TSParameterProperty: {
|
|
47
|
+
enter({ node }: NodePath<TSParameterProperty>) {
|
|
48
|
+
const decorator = getDecoratorByName(node.decorators, 'Inject');
|
|
49
|
+
if (getDecoratorName(decorator) === 'Inject') {
|
|
50
|
+
saveUnmangledParamName(node, decorator!);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
},
|
|
30
54
|
};
|
|
31
55
|
|
|
56
|
+
function saveUnmangledParamName(node: Identifier | TSParameterProperty, decorator: Decorator) {
|
|
57
|
+
if (injectIsNotNamed(decorator)) {
|
|
58
|
+
passParamNameAsInjectArgument(node, decorator);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function injectIsNotNamed(decorator: Decorator): boolean {
|
|
63
|
+
return getDecoratorArgument(decorator) === undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
32
66
|
function convertProviderParamsToDestructuringAssignment(node: ClassMethod) {
|
|
33
67
|
if (node.params.length === 0) return;
|
|
34
68
|
const destructuredParams = paramsToDestructuringAssignment(node.params);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Constructable } from '../types';
|
|
2
|
-
import { ObjectGraph } from '../graph/ObjectGraph';
|
|
3
|
-
export declare function Injectable<T extends {
|
|
4
|
-
new (...args: any[]): any;
|
|
5
|
-
}>(Graph: Constructable<ObjectGraph>): any;
|
|
6
|
-
export declare function Inject(target: Object, propertyKey: string): void;
|
|
7
|
-
//# sourceMappingURL=injectClass.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectClass.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectClass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,KAAI,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,EAAE,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,GAAG,CAgBzG;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAGzD"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Inject = exports.Injectable = void 0;
|
|
7
|
-
var GraphRegistry_1 = __importDefault(require("../graph/registry/GraphRegistry"));
|
|
8
|
-
var injectionMetadataKey = 'injectionMetadata';
|
|
9
|
-
function Injectable(Graph) {
|
|
10
|
-
return function (Target) {
|
|
11
|
-
var proxy = {
|
|
12
|
-
construct: function (target, args, newTarget) {
|
|
13
|
-
var _a;
|
|
14
|
-
var keysToInject = (_a = Reflect.getMetadata(injectionMetadataKey, target)) !== null && _a !== void 0 ? _a : [];
|
|
15
|
-
var createdObject = Reflect.construct(target, args, newTarget);
|
|
16
|
-
var graph = GraphRegistry_1.default.resolve(Graph);
|
|
17
|
-
for (var _i = 0, keysToInject_1 = keysToInject; _i < keysToInject_1.length; _i++) {
|
|
18
|
-
var key = keysToInject_1[_i];
|
|
19
|
-
Reflect.set(createdObject, key, graph.retrieve(key));
|
|
20
|
-
}
|
|
21
|
-
return createdObject;
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
return new Proxy(Target, proxy);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
exports.Injectable = Injectable;
|
|
28
|
-
function Inject(target, propertyKey) {
|
|
29
|
-
var _a;
|
|
30
|
-
var keysToInject = (_a = Reflect.getMetadata(injectionMetadataKey, target.constructor)) !== null && _a !== void 0 ? _a : new Set();
|
|
31
|
-
Reflect.defineMetadata(injectionMetadataKey, keysToInject.add(propertyKey), target.constructor);
|
|
32
|
-
}
|
|
33
|
-
exports.Inject = Inject;
|
|
34
|
-
//# sourceMappingURL=injectClass.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectCl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,"file":"index.d.ts","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian-provide/helpers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,cAAc,CAAC;AAGtB,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAWhE;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,QAOjF;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAKvF;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAGvD;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,CAE3G;AAED,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAE1E;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,EAAE,GAAG,aAAa,CAI3F"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian-provide/helpers/index.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,oCAAyC;AASzC,iCAA6B;AAE7B,SAAgB,kBAAkB,CAAC,SAAoB;IACrD,IAAM,QAAQ,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACjD,IAAI,YAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE;QAClC,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,UAAC,CAAC;YAChC,IAAI,YAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE;gBACzB,OAAO,YAAC,CAAC,YAAY,C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OAAO,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC,UAAC,SAAS,IAAK,OAAA,IAAA,YAAG,EAAC,SAAS,EAAE,wBAAwB,CAAC,KAAK,UAAU,EAAvD,CAAuD,CAAC,CAAC;AAClG,CAAC;AAFD,oDAEC;AAED,SAAgB,gBAAgB,CAAC,SAAqB;IACpD,OAAO,IAAA,YAAG,EAAC,SAAS,EAAE,wBAAwB,CAAC,CAAC;AAClD,CAAC;AAFD,4CAEC;AAED,SAAgB,+BAA+B,CAAC,MAA4B;IAC1E,OAAO,YAAC,CAAC,aAAa,CAAC,MAAM;SAC1B,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,YAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAAC;SAChC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,YAAC,CAAC,cAAc,CAAC,YAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,YAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAA5D,CAA4D,CAAC,CAAC,CAAC;AAC/E,CAAC;AAJD,0EAIC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../transformers/babel-plugin-obsidian-provide/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AA0ClD,MAAM,CAAC,OAAO,UAAU,MAAM,gDAE7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../transformers/babel-plugin-obsidian-provide/index.ts"],"names":[],"mappings":";;AAGA,qCAMmB;AAEnB,IAAM,4BAA4B,GAAc;IAC9C,OAAO,EAAE;QACP,OAAO,EAAP,UAAQ,IAAuB;YAC7B,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACjC,CAAC;KACF;CACF,CAAC;AAEF,IAAM,eAAe,GAAG;IACtB,WAAW,EAAE;QACX,KAAK,EAAL,UAAM,EAA+B;gBAA7B,IAAI,UAAA;YACV,IAAM,SAAS,GAAG,IAAA,8BAAoB,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACxD,IAAI,IAAA,0BAAgB,EAAC,SAAS,CAAC,KAAK,UAAU,EAAE;gBAC9C,8CAA8C,CAAC,IAAI,CAAC,CAAC;gBACrD,0CAA0C,CAAC,IAAI,EAAE,SAAU,CAAC,CAAC;aAC9D;QACH,CAAC;KACF;CACF,CAAC;AAEF,SAAS,8CAA8C,CAAC,IAAiB;IACvE,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACrC,IAAM,kBAAkB,GAAG,IAAA,yCAA+B,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxE,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,0CAA0C,CAAC,IAAiB,EAAE,SAAoB;IACzF,IAAI,IAAA,4BAAkB,EAAC,SAAS,CAAC,EAAE;QACjC,IAAA,oCAA0B,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC;KAC7C;AACH,CAAC;AAED,SAAwB,MAAM;IAC5B,OAAO,4BAA4B,CAAC;AACtC,CAAC;AAFD,yBAEC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Constructable } from '../types';
|
|
2
|
-
import graphRegistry from '../graph/registry/GraphRegistry';
|
|
3
|
-
import { ObjectGraph } from '../graph/ObjectGraph';
|
|
4
|
-
|
|
5
|
-
const injectionMetadataKey = 'injectionMetadata';
|
|
6
|
-
|
|
7
|
-
export function Injectable<T extends { new(...args: any[]): any }>(Graph: Constructable<ObjectGraph>): any {
|
|
8
|
-
return (Target: T) => {
|
|
9
|
-
const proxy = {
|
|
10
|
-
construct(target: any, args: any[], newTarget: any): new() => {} {
|
|
11
|
-
const keysToInject: string[] = Reflect.getMetadata(injectionMetadataKey, target) ?? [];
|
|
12
|
-
|
|
13
|
-
const createdObject = Reflect.construct(target, args, newTarget);
|
|
14
|
-
const graph = graphRegistry.resolve(Graph);
|
|
15
|
-
for (const key of keysToInject) {
|
|
16
|
-
Reflect.set(createdObject, key, graph.retrieve(key));
|
|
17
|
-
}
|
|
18
|
-
return createdObject;
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
return new Proxy(Target, proxy);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function Inject(target: Object, propertyKey: string) {
|
|
26
|
-
const keysToInject = Reflect.getMetadata(injectionMetadataKey, target.constructor) ?? new Set();
|
|
27
|
-
Reflect.defineMetadata(injectionMetadataKey, keysToInject.add(propertyKey), target.constructor);
|
|
28
|
-
}
|